10#ifndef IMPACTX_DISTRIBUTION_THERMAL
11#define IMPACTX_DISTRIBUTION_THERMAL
37 static constexpr amrex::ParticleReal
tolerance = 1.0e-3;
38 static constexpr amrex::ParticleReal
rin = 1.0e-10;
39 static constexpr amrex::ParticleReal
rout = 10.0;
51 amrex::ParticleReal*
m_cdf1 =
nullptr;
52 amrex::ParticleReal*
m_cdf2 =
nullptr;
55 amrex::ParticleReal
m_k;
58 amrex::ParticleReal
m_w;
61 static inline std::unique_ptr<amrex::Gpu::DeviceVector<amrex::ParticleReal>>
m_d_cdf1;
62 static inline std::unique_ptr<amrex::Gpu::DeviceVector<amrex::ParticleReal>>
m_d_cdf2;
65 amrex::ParticleReal kin,
66 amrex::ParticleReal T1in,
67 amrex::ParticleReal T2in,
68 amrex::ParticleReal p1in,
69 amrex::ParticleReal p2in,
70 amrex::ParticleReal win
89 using namespace amrex::literals;
98 amrex::ParticleReal Erest = refpart.
mass_MeV()*1.0e6;
99 amrex::ParticleReal q_e = refpart.
charge_qe();
106 amrex::ParticleReal rmin =
rin*r_scale;
107 amrex::ParticleReal rmax =
rout*r_scale;
111 amrex::ParticleReal rt2pi = std::sqrt(2.0_prt*
pi);
112 amrex::ParticleReal p_scale = powi<-3>(r_scale*rt2pi);
122 std::vector<amrex::ParticleReal> cdf1(
m_nbins+1);
123 std::vector<amrex::ParticleReal> cdf2(
m_nbins+1);
141 for (
int n = 0; n <
m_nbins; ++n) {
147 m_d_cdf1 = std::make_unique<amrex::Gpu::DeviceVector<amrex::ParticleReal>>(
m_nbins+1);
148 m_d_cdf2 = std::make_unique<amrex::Gpu::DeviceVector<amrex::ParticleReal>>(
m_nbins+1);
150 cdf1.begin(), cdf1.end(),
153 cdf2.begin(), cdf2.end(),
161 using namespace amrex::literals;
164 amrex::ParticleReal k =
m_k;
166 amrex::ParticleReal a =
m_Cintensity/(4_prt*
pi*5_prt*std::sqrt(5_prt));
167 amrex::ParticleReal rscale = std::sqrt(kT + std::pow(a*k,2_prt/3_prt))/k;
174 amrex::ParticleReal in,
175 amrex::ParticleReal out,
179 using namespace amrex::literals;
182 amrex::ParticleReal
const tau = (out-in)/steps;
183 amrex::ParticleReal
const half =
tau*0.5_prt;
186 amrex::ParticleReal reval = in;
189 for (
int j=0; j < steps; ++j)
211 amrex::ParticleReal
const tau,
212 amrex::ParticleReal & reval
215 using namespace amrex::literals;
218 amrex::ParticleReal
const f1 =
m_f1;
219 amrex::ParticleReal
const f2 =
m_f2;
220 amrex::ParticleReal
const phi1 =
m_phi1;
221 amrex::ParticleReal
const phi2 =
m_phi2;
222 amrex::ParticleReal
const r = reval;
226 m_phi1 = phi1 + f1/(4.0_prt*
pi*reval) - f1/(4.0_prt*
pi*r);
227 m_phi2 = phi2 + f2/(4.0_prt*
pi*reval) - f2/(4.0_prt*
pi*r);;
234 amrex::ParticleReal
const tau,
235 amrex::ParticleReal & reval
238 using namespace amrex::literals;
241 amrex::ParticleReal
const f1 =
m_f1;
242 amrex::ParticleReal
const f2 =
m_f2;
243 amrex::ParticleReal
const phi1 =
m_phi1;
244 amrex::ParticleReal
const phi2 =
m_phi2;
245 amrex::ParticleReal
const r = reval;
246 amrex::ParticleReal
const k =
m_k;
247 amrex::ParticleReal
const w =
m_w;
248 amrex::ParticleReal
const T1 =
m_T1;
249 amrex::ParticleReal
const T2 =
m_T2;
252 amrex::ParticleReal
const c1 = (1_prt-w) *
m_Cintensity;
256 amrex::ParticleReal potential = 0_prt;
257 potential = std::pow(k*r,2)*0.5_prt + c1*phi1 + c2*phi2;
258 amrex::ParticleReal Pdensity1 =
m_p1 * std::exp(-potential/T1);
259 amrex::ParticleReal Pdensity2 =
m_p2 * std::exp(-potential/T2);
266 m_f1 = f1 +
tau*4_prt*
pi * std::pow(r,2)*Pdensity1;
267 m_f2 = f2 +
tau*4_prt*
pi * std::pow(r,2)*Pdensity2;
288 amrex::ParticleReal k,
289 amrex::ParticleReal kT,
290 amrex::ParticleReal kT_halo,
291 amrex::ParticleReal normalize,
292 amrex::ParticleReal normalize_halo,
293 amrex::ParticleReal halo
361 using namespace amrex::literals;
364 amrex::ParticleReal ln1,norm,u1,u2,uhalo;
365 amrex::ParticleReal g1,g2,g3,g4,g5,g6;
366 amrex::ParticleReal z,pz;
376 ln1 = std::sqrt(-2_prt*std::log(u1));
377 g1 = ln1 * std::cos(2_prt*
pi*u2);
378 g2 = ln1 * std::sin(2_prt*
pi*u2);
381 ln1 = std::sqrt(-2_prt*std::log(u1));
382 g3 = ln1 * std::cos(2_prt*
pi*u2);
383 g4 = ln1 * std::sin(2_prt*
pi*u2);
386 ln1 = std::sqrt(-2_prt*std::log(u1));
387 g5 = ln1 * std::cos(2_prt*
pi*u2);
388 g6 = ln1 * std::sin(2_prt*
pi*u2);
391 amrex::ParticleReal kT = (uhalo >
m_w) ?
m_T1 :
m_T2;
392 px = std::sqrt(kT)*g4;
393 py = std::sqrt(kT)*g5;
394 pz = std::sqrt(kT)*g6;
397 norm = std::sqrt(g1*g1+g2*g2+g3*g3);
410 int const off =
amrex::max(0,
int(ptr - cdf - 1));
411 amrex::ParticleReal tv = (u - cdf[off]) / (cdf[off + 1] - cdf[off]);
412 amrex::ParticleReal xv = (off + tv) / amrex::ParticleReal(
m_nbins);
437 amrex::ParticleReal
const *
m_cdf1 =
nullptr;
438 amrex::ParticleReal
const *
m_cdf2 =
nullptr;
#define AMREX_FORCE_INLINE
#define AMREX_GPU_HOST_DEVICE
static constexpr auto ep0
static constexpr amrex::Real tau
static constexpr amrex::Real pi
void copyAsync(HostToDevice, InIter begin, InIter end, OutIter result) noexcept
static constexpr HostToDevice hostToDevice
void streamSynchronize() noexcept
constexpr T powi(T x) noexcept
__host__ __device__ ItType lower_bound(ItType first, ItType last, const ValType &val)
__host__ __device__ constexpr const T & max(const T &a, const T &b) noexcept
Definition CovarianceMatrixMath.H:25
@ t
fixed t as the independent variable
Definition ImpactXParticleContainer.H:38
Definition ReferenceParticle.H:31
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal beta_gamma() const
Definition ReferenceParticle.H:110
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal mass_MeV() const
Definition ReferenceParticle.H:126
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE amrex::ParticleReal charge_qe() const
Definition ReferenceParticle.H:220
void generate_radial_dist(amrex::ParticleReal bunch_charge, RefPart const &refpart)
Definition Thermal.H:87
amrex::ParticleReal m_bg
reference value of relativistic beta*gamma
Definition Thermal.H:54
amrex::ParticleReal m_phi2
potential generated by second population
Definition Thermal.H:45
void map1(amrex::ParticleReal const tau, amrex::ParticleReal &reval)
Definition Thermal.H:210
amrex::ParticleReal m_phi1
potential generated by first population
Definition Thermal.H:44
ThermalData(amrex::ParticleReal kin, amrex::ParticleReal T1in, amrex::ParticleReal T2in, amrex::ParticleReal p1in, amrex::ParticleReal p2in, amrex::ParticleReal win)
Definition Thermal.H:64
amrex::ParticleReal m_f1
cumulative distribution of first population
Definition Thermal.H:42
void map2(amrex::ParticleReal const tau, amrex::ParticleReal &reval)
Definition Thermal.H:233
amrex::ParticleReal * m_cdf2
tabulated cumulative distribution (second)
Definition Thermal.H:52
amrex::ParticleReal * m_cdf1
tabulated cumulative distribution (first)
Definition Thermal.H:51
amrex::ParticleReal m_Cintensity
space charge intensity parameter
Definition Thermal.H:53
static std::unique_ptr< amrex::Gpu::DeviceVector< amrex::ParticleReal > > m_d_cdf2
Definition Thermal.H:62
amrex::ParticleReal m_rmin
minimum r value for tabulated cdf
Definition Thermal.H:48
static constexpr amrex::ParticleReal rin
initial r value for numerical integration
Definition Thermal.H:38
void integrate(amrex::ParticleReal in, amrex::ParticleReal out, int steps)
Definition Thermal.H:173
static std::unique_ptr< amrex::Gpu::DeviceVector< amrex::ParticleReal > > m_d_cdf1
Definition Thermal.H:61
amrex::ParticleReal m_rmax
maximum r value for tabulated cdf
Definition Thermal.H:49
static constexpr amrex::ParticleReal tolerance
tolerance for matching condition
Definition Thermal.H:37
static constexpr int nsteps
number of radial steps for numerical integration
Definition Thermal.H:40
amrex::ParticleReal matched_scale_radius()
Definition Thermal.H:159
amrex::ParticleReal m_k
linear focusing strength (1/meters)
Definition Thermal.H:55
amrex::ParticleReal m_f2
cumulative distribution of second population
Definition Thermal.H:43
amrex::ParticleReal m_p2
normalization constant of second population
Definition Thermal.H:47
int m_nbins
number of radial bins for tabulated cdf
Definition Thermal.H:50
amrex::ParticleReal m_p1
normalization constant of first population
Definition Thermal.H:46
amrex::ParticleReal m_T1
temperature k*T of the primary (core) population
Definition Thermal.H:56
static constexpr amrex::ParticleReal rout
final r value for numerical integration
Definition Thermal.H:39
amrex::ParticleReal m_T2
temperature k*T of the secondary (halo) population
Definition Thermal.H:57
amrex::ParticleReal m_w
weight of the secondary (halo) population
Definition Thermal.H:58
void finalize()
Definition Thermal.H:332
Thermal(amrex::ParticleReal k, amrex::ParticleReal kT, amrex::ParticleReal kT_halo, amrex::ParticleReal normalize, amrex::ParticleReal normalize_halo, amrex::ParticleReal halo)
Definition Thermal.H:287
amrex::ParticleReal m_bg
reference value of relativistic beta*gamma
Definition Thermal.H:432
int m_nbins
number of radial bins for tabulated cdf
Definition Thermal.H:431
amrex::ParticleReal m_T1
linear focusing strength (1/meters)
Definition Thermal.H:426
void initialize(amrex::ParticleReal bunch_charge, RefPart const &ref)
Definition Thermal.H:311
AMREX_GPU_HOST_DEVICE AMREX_FORCE_INLINE void operator()(amrex::ParticleReal &AMREX_RESTRICT x, amrex::ParticleReal &AMREX_RESTRICT y, amrex::ParticleReal &AMREX_RESTRICT t, amrex::ParticleReal &AMREX_RESTRICT px, amrex::ParticleReal &AMREX_RESTRICT py, amrex::ParticleReal &AMREX_RESTRICT pt, amrex::RandomEngine const &engine) const
Definition Thermal.H:350
amrex::ParticleReal m_rmin
relative weight of halo population
Definition Thermal.H:429
amrex::ParticleReal m_normalize
temperature of each particle population
Definition Thermal.H:427
amrex::ParticleReal m_T2
Definition Thermal.H:426
amrex::ParticleReal m_w
weight of the secondary (halo) population
Definition Thermal.H:433
amrex::ParticleReal const * m_cdf1
Definition Thermal.H:437
amrex::ParticleReal m_halo
normalization constant of first/second population
Definition Thermal.H:428
amrex::ParticleReal const * m_cdf2
non-owning pointer to device core CDF
Definition Thermal.H:438
amrex::ParticleReal m_rmax
maximum r value for tabulated cdf
Definition Thermal.H:430
amrex::ParticleReal m_normalize_halo
Definition Thermal.H:427
amrex::ParticleReal m_k
Definition Thermal.H:425