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 
10 #include "ComputeTemperature.H"
13 #include "Utils/WarpXConst.H"
14 
15 #include <AMReX_Random.H>
16 
17 
37 template <typename T_index, typename T_R, typename SoaData_type>
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  SoaData_type soa_1, SoaData_type soa_2,
44  T_R const q1, T_R const q2,
45  T_R const m1, T_R const m2,
46  T_R const T1, T_R const T2,
47  T_R const dt, T_R const L, T_R const dV,
48  amrex::RandomEngine const& engine)
49 {
50  int NI1 = I1e - I1s;
51  int NI2 = I2e - I2s;
52 
53  T_R * const AMREX_RESTRICT w1 = soa_1.m_rdata[PIdx::w];
54  T_R * const AMREX_RESTRICT u1x = soa_1.m_rdata[PIdx::ux];
55  T_R * const AMREX_RESTRICT u1y = soa_1.m_rdata[PIdx::uy];
56  T_R * const AMREX_RESTRICT u1z = soa_1.m_rdata[PIdx::uz];
57 
58  T_R * const AMREX_RESTRICT w2 = soa_2.m_rdata[PIdx::w];
59  T_R * const AMREX_RESTRICT u2x = soa_2.m_rdata[PIdx::ux];
60  T_R * const AMREX_RESTRICT u2y = soa_2.m_rdata[PIdx::uy];
61  T_R * const AMREX_RESTRICT u2z = soa_2.m_rdata[PIdx::uz];
62 
63  // get local T1t and T2t
64  T_R T1t; T_R T2t;
65  if ( T1 <= T_R(0.0) && L <= T_R(0.0) )
66  {
67  T1t = ComputeTemperature(I1s,I1e,I1,u1x,u1y,u1z,m1);
68  }
69  else { T1t = T1; }
70  if ( T2 <= T_R(0.0) && L <= T_R(0.0) )
71  {
72  T2t = ComputeTemperature(I2s,I2e,I2,u2x,u2y,u2z,m2);
73  }
74  else { T2t = T2; }
75 
76  // local density
77  T_R n1 = T_R(0.0);
78  T_R n2 = T_R(0.0);
79  T_R n12 = T_R(0.0);
80  for (int i1=I1s; i1<static_cast<int>(I1e); ++i1) { n1 += w1[ I1[i1] ]; }
81  for (int i2=I2s; i2<static_cast<int>(I2e); ++i2) { n2 += w2[ I2[i2] ]; }
82  n1 = n1 / dV; n2 = n2 / dV;
83  {
84  int i1 = I1s; int i2 = I2s;
85  for (int k = 0; k < amrex::max(NI1,NI2); ++k)
86  {
87  n12 += amrex::min( w1[ I1[i1] ], w2[ I2[i2] ] );
88  ++i1; if ( i1 == static_cast<int>(I1e) ) { i1 = I1s; }
89  ++i2; if ( i2 == static_cast<int>(I2e) ) { i2 = I2s; }
90  }
91  n12 = n12 / dV;
92  }
93 
94  // compute Debye length lmdD
95  T_R lmdD;
96  if ( T1t < T_R(0.0) || T2t < T_R(0.0) ) {
97  lmdD = T_R(0.0);
98  }
99  else {
100  lmdD = T_R(1.0)/std::sqrt( n1*q1*q1/(T1t*PhysConst::ep0) +
101  n2*q2*q2/(T2t*PhysConst::ep0) );
102  }
103  T_R rmin = std::pow( T_R(4.0) * MathConst::pi / T_R(3.0) *
104  amrex::max(n1,n2), T_R(-1.0/3.0) );
105  lmdD = amrex::max(lmdD, rmin);
106 
107  // call UpdateMomentumPerezElastic()
108  {
109  int i1 = I1s; int i2 = I2s;
110  for (int k = 0; k < amrex::max(NI1,NI2); ++k)
111  {
113  u1x[ I1[i1] ], u1y[ I1[i1] ], u1z[ I1[i1] ],
114  u2x[ I2[i2] ], u2y[ I2[i2] ], u2z[ I2[i2] ],
115  n1, n2, n12,
116  q1, m1, w1[ I1[i1] ], q2, m2, w2[ I2[i2] ],
117  dt, L, lmdD,
118  engine);
119  ++i1; if ( i1 == static_cast<int>(I1e) ) { i1 = I1s; }
120  ++i2; if ( i2 == static_cast<int>(I2e) ) { i2 = I2s; }
121  }
122  }
123 
124 }
125 
126 #endif // WARPX_PARTICLES_COLLISION_ELASTIC_COLLISION_PEREZ_H_
Definition: WarpXParticleContainer_fwd.H:28
Definition: WarpXParticleContainer_fwd.H:28
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
Definition: WarpXParticleContainer_fwd.H:28
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, SoaData_type soa_1, SoaData_type soa_2, 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
Definition: WarpXParticleContainer_fwd.H:27
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