10 #ifndef IMPACTX_DISTRIBUTION_THERMAL
11 #define IMPACTX_DISTRIBUTION_THERMAL
32 namespace distribution
36 static constexpr amrex::ParticleReal
tolerance = 1.0e-3;
37 static constexpr amrex::ParticleReal
rin = 1.0e-10;
38 static constexpr amrex::ParticleReal
rout = 10.0;
50 amrex::ParticleReal*
m_cdf1 =
nullptr;
51 amrex::ParticleReal*
m_cdf2 =
nullptr;
54 amrex::ParticleReal
m_k;
57 amrex::ParticleReal
m_w;
64 amrex::ParticleReal kin,
65 amrex::ParticleReal T1in,
66 amrex::ParticleReal T2in,
67 amrex::ParticleReal p1in,
68 amrex::ParticleReal p2in,
69 amrex::ParticleReal win
88 using namespace amrex::literals;
96 amrex::ParticleReal Erest = refpart.
mass_MeV()*1.0e6;
97 amrex::ParticleReal q_e = refpart.
charge_qe();
104 amrex::ParticleReal rmin =
rin*r_scale;
105 amrex::ParticleReal rmax =
rout*r_scale;
109 amrex::ParticleReal rt2pi =
sqrt(2.0_prt*
pi);
110 amrex::ParticleReal p_scale =
pow(r_scale*rt2pi,-3);
120 std::vector<amrex::ParticleReal> cdf1(
m_nbins+1);
121 std::vector<amrex::ParticleReal> cdf2(
m_nbins+1);
148 cdf1.begin(), cdf1.end(),
151 cdf2.begin(), cdf2.end(),
159 using namespace amrex::literals;
162 amrex::ParticleReal k =
m_k;
165 amrex::ParticleReal rscale =
sqrt(kT +
pow(a*k,2.0/3.0))/k;
172 amrex::ParticleReal in,
173 amrex::ParticleReal out,
177 using namespace amrex::literals;
180 amrex::ParticleReal
const tau = (out-in)/steps;
181 amrex::ParticleReal
const half = tau/2.0_prt;
184 amrex::ParticleReal reval = in;
187 for (
int j=0; j < steps; ++j)
209 amrex::ParticleReal
const tau,
210 amrex::ParticleReal & reval
213 using namespace amrex::literals;
216 amrex::ParticleReal
const f1 =
m_f1;
217 amrex::ParticleReal
const f2 =
m_f2;
218 amrex::ParticleReal
const phi1 =
m_phi1;
219 amrex::ParticleReal
const phi2 =
m_phi2;
220 amrex::ParticleReal
const r = reval;
224 m_phi1 = phi1 + f1/(4.0_prt*
pi*reval) - f1/(4.0_prt*
pi*
r);
225 m_phi2 = phi2 + f2/(4.0_prt*
pi*reval) - f2/(4.0_prt*
pi*
r);;
232 amrex::ParticleReal
const tau,
233 amrex::ParticleReal & reval
236 using namespace amrex::literals;
239 amrex::ParticleReal
const f1 =
m_f1;
240 amrex::ParticleReal
const f2 =
m_f2;
241 amrex::ParticleReal
const phi1 =
m_phi1;
242 amrex::ParticleReal
const phi2 =
m_phi2;
243 amrex::ParticleReal
const r = reval;
244 amrex::ParticleReal
const k =
m_k;
245 amrex::ParticleReal
const w =
m_w;
246 amrex::ParticleReal
const T1 =
m_T1;
247 amrex::ParticleReal
const T2 =
m_T2;
254 amrex::ParticleReal potential = 0.0_prt;
255 potential =
pow(k*
r,2.0)/2.0_prt + c1*phi1 + c2*phi2;
256 amrex::ParticleReal Pdensity1 =
m_p1*
exp(-potential/T1);
257 amrex::ParticleReal Pdensity2 =
m_p2*
exp(-potential/T2);
264 m_f1 = f1 + tau*4.0_prt*
pi*
pow(
r,2.0)*Pdensity1;
265 m_f2 = f2 + tau*4.0_prt*
pi*
pow(
r,2.0)*Pdensity2;
286 amrex::ParticleReal k,
287 amrex::ParticleReal kT,
288 amrex::ParticleReal kT_halo,
289 amrex::ParticleReal normalize,
290 amrex::ParticleReal normalize_halo,
291 amrex::ParticleReal halo
296 m_normalize(normalize),
297 m_normalize_halo(normalize_halo),
313 data.generate_radial_dist(bunch_charge, ref);
349 amrex::ParticleReal & AMREX_RESTRICT x,
350 amrex::ParticleReal & AMREX_RESTRICT y,
351 amrex::ParticleReal & AMREX_RESTRICT t,
352 amrex::ParticleReal & AMREX_RESTRICT px,
353 amrex::ParticleReal & AMREX_RESTRICT py,
354 amrex::ParticleReal & AMREX_RESTRICT pt,
359 using namespace amrex::literals;
362 amrex::ParticleReal ln1,
norm,u1,u2,uhalo;
363 amrex::ParticleReal g1,g2,g3,g4,g5,g6;
364 amrex::ParticleReal z,pz;
375 g1 = ln1*cos(2_prt*
pi*u2);
376 g2 = ln1*sin(2_prt*
pi*u2);
380 g3 = ln1*cos(2_prt*
pi*u2);
381 g4 = ln1*sin(2_prt*
pi*u2);
385 g5 = ln1*cos(2_prt*
pi*u2);
386 g6 = ln1*sin(2_prt*
pi*u2);
389 amrex::ParticleReal kT = (uhalo >
m_w) ?
m_T1 :
m_T2;
408 int const off =
amrex::max(0,
int(ptr - cdf - 1));
409 amrex::ParticleReal tv = (u - cdf[off]) / (cdf[off + 1] - cdf[off]);
410 amrex::ParticleReal xv = (off + tv) / amrex::ParticleReal(
m_nbins);
435 amrex::ParticleReal
const *
m_cdf1 =
nullptr;
436 amrex::ParticleReal
const *
m_cdf2 =
nullptr;
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
static constexpr auto ep0
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
static constexpr HostToDevice hostToDevice
void streamSynchronize() noexcept
constexpr std::enable_if_t< std::is_floating_point< T >::value, T > pi()
real(kind=amrex_real), parameter half
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > log(const GpuComplex< T > &a_z) noexcept
AMREX_GPU_HOST_DEVICE constexpr AMREX_FORCE_INLINE const T & max(const T &a, const T &b) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE T norm(const GpuComplex< T > &a_z) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > pow(const GpuComplex< T > &a_z, const T &a_y) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > exp(const GpuComplex< T > &a_z) noexcept
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE GpuComplex< T > sqrt(const GpuComplex< T > &a_z) noexcept
AMREX_GPU_HOST_DEVICE ItType lower_bound(ItType first, ItType last, const ValType &val)
Definition: ImpactX.cpp:33
@ t
fixed t as the independent variable
Definition: ReferenceParticle.H:30
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition: ReferenceParticle.H:79
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal mass_MeV() const
Definition: ReferenceParticle.H:94
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal charge_qe() const
Definition: ReferenceParticle.H:186
void generate_radial_dist(amrex::ParticleReal bunch_charge, RefPart const &refpart)
Definition: Thermal.H:86
amrex::ParticleReal m_bg
reference value of relativistic beta*gamma
Definition: Thermal.H:53
static amrex::Gpu::DeviceVector< amrex::ParticleReal > m_d_cdf1
Definition: Thermal.H:60
amrex::ParticleReal m_phi2
potential generated by second population
Definition: Thermal.H:44
void map1(amrex::ParticleReal const tau, amrex::ParticleReal &reval)
Definition: Thermal.H:208
amrex::ParticleReal m_phi1
potential generated by first population
Definition: Thermal.H:43
ThermalData(amrex::ParticleReal kin, amrex::ParticleReal T1in, amrex::ParticleReal T2in, amrex::ParticleReal p1in, amrex::ParticleReal p2in, amrex::ParticleReal win)
Definition: Thermal.H:63
amrex::ParticleReal m_f1
cumulative distribution of first population
Definition: Thermal.H:41
void map2(amrex::ParticleReal const tau, amrex::ParticleReal &reval)
Definition: Thermal.H:231
amrex::ParticleReal * m_cdf2
tabulated cumulative distribution (second)
Definition: Thermal.H:51
amrex::ParticleReal * m_cdf1
tabulated cumulative distribution (first)
Definition: Thermal.H:50
amrex::ParticleReal m_Cintensity
space charge intensity parameter
Definition: Thermal.H:52
static amrex::Gpu::DeviceVector< amrex::ParticleReal > m_d_cdf2
Definition: Thermal.H:61
amrex::ParticleReal m_rmin
minimum r value for tabulated cdf
Definition: Thermal.H:47
static constexpr amrex::ParticleReal rin
initial r value for numerical integration
Definition: Thermal.H:37
void integrate(amrex::ParticleReal in, amrex::ParticleReal out, int steps)
Definition: Thermal.H:171
amrex::ParticleReal m_rmax
maximum r value for tabulated cdf
Definition: Thermal.H:48
static constexpr amrex::ParticleReal tolerance
tolerance for matching condition
Definition: Thermal.H:36
static constexpr int nsteps
number of radial steps for numerical integration
Definition: Thermal.H:39
amrex::ParticleReal matched_scale_radius()
Definition: Thermal.H:157
amrex::ParticleReal m_k
linear focusing strength (1/meters)
Definition: Thermal.H:54
amrex::ParticleReal m_f2
cumulative distribution of second population
Definition: Thermal.H:42
amrex::ParticleReal m_p2
normalization constant of second population
Definition: Thermal.H:46
int m_nbins
number of radial bins for tabulated cdf
Definition: Thermal.H:49
amrex::ParticleReal m_p1
normalization constant of first population
Definition: Thermal.H:45
amrex::ParticleReal m_T1
temperature k*T of the primary (core) population
Definition: Thermal.H:55
static constexpr amrex::ParticleReal rout
final r value for numerical integration
Definition: Thermal.H:38
amrex::ParticleReal m_T2
temperature k*T of the secondary (halo) population
Definition: Thermal.H:56
amrex::ParticleReal m_w
weight of the secondary (halo) population
Definition: Thermal.H:57
Definition: Thermal.H:271
void finalize()
Definition: Thermal.H:330
Thermal(amrex::ParticleReal k, amrex::ParticleReal kT, amrex::ParticleReal kT_halo, amrex::ParticleReal normalize, amrex::ParticleReal normalize_halo, amrex::ParticleReal halo)
Definition: Thermal.H:285
amrex::ParticleReal m_bg
reference value of relativistic beta*gamma
Definition: Thermal.H:431
int m_nbins
number of radial bins for tabulated cdf
Definition: Thermal.H:430
amrex::ParticleReal m_T1
linear focusing strength (1/meters)
Definition: Thermal.H:425
void initialize(amrex::ParticleReal bunch_charge, RefPart const &ref)
Definition: Thermal.H:309
amrex::ParticleReal m_rmin
relative weight of halo population
Definition: Thermal.H:428
amrex::ParticleReal m_normalize
temperature of each particle population
Definition: Thermal.H:426
amrex::ParticleReal m_w
weight of the secondary (halo) population
Definition: Thermal.H:432
amrex::ParticleReal m_halo
normalization constant of first/second population
Definition: Thermal.H:427
amrex::ParticleReal m_rmax
maximum r value for tabulated cdf
Definition: Thermal.H:429
amrex::ParticleReal m_k
Definition: Thermal.H:424