WarpX
ElasticCollisionPerez.H
Go to the documentation of this file.
1 /* Copyright 2019 Yinjian Zhao
2  *
3  * This file is part of WarpX.
4  *
5  * License: BSD-3-Clause-LBNL
6  */
7 #ifndef WARPX_PARTICLES_COLLISION_ELASTIC_COLLISION_PEREZ_H_
8 #define WARPX_PARTICLES_COLLISION_ELASTIC_COLLISION_PEREZ_H_
9 
11 #include "ComputeTemperature.H"
12 #include "Utils/WarpXConst.H"
13 
14 #include <AMReX_Random.H>
15 
16 
37 template <typename T_index, typename T_R>
38 AMREX_GPU_HOST_DEVICE AMREX_INLINE
40  T_index const I1s, T_index const I1e,
41  T_index const I2s, T_index const I2e,
42  T_index *I1, T_index *I2,
43  T_R *u1x, T_R *u1y, T_R *u1z,
44  T_R *u2x, T_R *u2y, T_R *u2z,
45  T_R const *w1, T_R const *w2,
46  T_R const q1, T_R const q2,
47  T_R const m1, T_R const m2,
48  T_R const T1, T_R const T2,
49  T_R const dt, T_R const L, T_R const dV,
50  amrex::RandomEngine const& engine)
51 {
52 
53  int NI1 = I1e - I1s;
54  int NI2 = I2e - I2s;
55 
56  // get local T1t and T2t
57  T_R T1t; T_R T2t;
58  if ( T1 <= T_R(0.0) && L <= T_R(0.0) )
59  {
60  T1t = ComputeTemperature(I1s,I1e,I1,u1x,u1y,u1z,m1);
61  }
62  else { T1t = T1; }
63  if ( T2 <= T_R(0.0) && L <= T_R(0.0) )
64  {
65  T2t = ComputeTemperature(I2s,I2e,I2,u2x,u2y,u2z,m2);
66  }
67  else { T2t = T2; }
68 
69  // local density
70  T_R n1 = T_R(0.0);
71  T_R n2 = T_R(0.0);
72  T_R n12 = T_R(0.0);
73  for (int i1=I1s; i1<static_cast<int>(I1e); ++i1) { n1 += w1[ I1[i1] ]; }
74  for (int i2=I2s; i2<static_cast<int>(I2e); ++i2) { n2 += w2[ I2[i2] ]; }
75  n1 = n1 / dV; n2 = n2 / dV;
76  {
77  int i1 = I1s; int i2 = I2s;
78  for (int k = 0; k < amrex::max(NI1,NI2); ++k)
79  {
80  n12 += amrex::min( w1[ I1[i1] ], w2[ I2[i2] ] );
81  ++i1; if ( i1 == static_cast<int>(I1e) ) { i1 = I1s; }
82  ++i2; if ( i2 == static_cast<int>(I2e) ) { i2 = I2s; }
83  }
84  n12 = n12 / dV;
85  }
86 
87  // compute Debye length lmdD
88  T_R lmdD;
89  lmdD = T_R(1.0)/std::sqrt( n1*q1*q1/(T1t*PhysConst::ep0) +
90  n2*q2*q2/(T2t*PhysConst::ep0) );
91  T_R rmin = std::pow( T_R(4.0) * MathConst::pi / T_R(3.0) *
92  amrex::max(n1,n2), T_R(-1.0/3.0) );
93  lmdD = amrex::max(lmdD, rmin);
94 
95  // call UpdateMomentumPerezElastic()
96  {
97  int i1 = I1s; int i2 = I2s;
98  for (int k = 0; k < amrex::max(NI1,NI2); ++k)
99  {
101  u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ],
102  u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ],
103  n1, n2, n12,
104  q1, m1, w1[ I1[i1] ], q2, m2, w2[ I2[i2] ],
105  dt, L, lmdD,
106  engine);
107  ++i1; if ( i1 == static_cast<int>(I1e) ) { i1 = I1s; }
108  ++i2; if ( i2 == static_cast<int>(I2e) ) { i2 = I2s; }
109  }
110  }
111 
112 }
113 
114 #endif // WARPX_PARTICLES_COLLISION_ELASTIC_COLLISION_PEREZ_H_
AMREX_GPU_HOST_DEVICE AMREX_INLINE void UpdateMomentumPerezElastic(T_R &u1x, T_R &u1y, T_R &u1z, T_R &u2x, T_R &u2y, T_R &u2z, T_R const n1, T_R const n2, T_R const n12, T_R const q1, T_R const m1, T_R const w1, T_R const q2, T_R const m2, T_R const w2, T_R const dt, T_R const L, T_R const lmdD, amrex::RandomEngine const &engine)
Definition: UpdateMomentumPerezElastic.H:30
AMREX_GPU_HOST_DEVICE AMREX_INLINE void ElasticCollisionPerez(T_index const I1s, T_index const I1e, T_index const I2s, T_index const I2e, T_index *I1, T_index *I2, T_R *u1x, T_R *u1y, T_R *u1z, T_R *u2x, T_R *u2y, T_R *u2z, T_R const *w1, T_R const *w2, T_R const q1, T_R const q2, T_R const m1, T_R const m2, T_R const T1, T_R const T2, T_R const dt, T_R const L, T_R const dV, amrex::RandomEngine const &engine)
Prepare information for and call UpdateMomentumPerezElastic().
Definition: ElasticCollisionPerez.H:39
AMREX_GPU_HOST_DEVICE T_R ComputeTemperature(T_index const Is, T_index const Ie, T_index const *I, T_R const *ux, T_R const *uy, T_R const *uz, T_R const m)
Definition: ComputeTemperature.H:15