Skip to content

Commit 6886e82

Browse files
Include temperature deposition shape factor (#1355)
Co-authored-by: Maxence Thévenet <maxence.thevenet@desy.de>
1 parent 62bc15a commit 6886e82

7 files changed

Lines changed: 87 additions & 31 deletions

File tree

docs/source/run/parameters.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,11 @@ Field diagnostics
11651165
will be deposited into individual fields accessible as ``w``, ``ux_<plasma name>`` or
11661166
``ux^2_<plasma name>`` (similarly for ``uy`` and ``uz``) in ``diagnostic.field_data``.
11671167

1168+
* ``hipace.temperature_depos_order`` (`int`) optional (default `2`)
1169+
When ``hipace.deposit_temp_individual`` is turned on,
1170+
this option specifies the shape order of the deposited fields.
1171+
Currently, 0,1,2,3 are implemented.
1172+
11681173
In-situ diagnostics
11691174
^^^^^^^^^^^^^^^^^^^
11701175

src/Hipace.H

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ public:
242242
inline static bool m_deposit_rho_individual = false;
243243
/** Whether to deposit temperature for every individual plasma for diagnostics */
244244
inline static bool m_deposit_temp_individual = false;
245+
/** Order of the temperature deposition shape factor */
246+
inline static int m_temperature_depos_order = 2;
245247
/** Whether to interpolate the neutralizing background to MR levels 1 and 2 instead of depositing it */
246248
inline static bool m_interpolate_neutralizing_background = false;
247249
/** Whether to use tiling for particle operations */

src/Hipace.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ Hipace::ReadParameters ()
130130
queryWithParser(pph, "deposit_rho_individual", m_deposit_rho_individual);
131131
m_deposit_temp_individual = m_diags.needsTempIndividual();
132132
queryWithParser(pph, "deposit_temp_individual", m_deposit_temp_individual);
133+
queryWithParser(pph, "temperature_depos_order", m_temperature_depos_order);
133134
queryWithParser(pph, "interpolate_neutralizing_background",
134135
m_interpolate_neutralizing_background);
135136
bool do_mfi_sync = false;

src/fields/Fields.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ Fields::AllocData (
6363

6464
// Need 1 extra guard cell transversally for transverse derivative
6565
int nguards_xy = (Hipace::m_depos_order_xy + 1) / 2 + 1;
66+
// Check the temperature deposition order, if enabled
67+
if (Hipace::m_deposit_temp_individual &&
68+
Hipace::m_temperature_depos_order > Hipace::m_depos_order_xy) {
69+
nguards_xy = (Hipace::m_temperature_depos_order + 1) / 2 + 1;
70+
}
6671
m_slices_nguards = amrex::IntVect{nguards_xy, nguards_xy, 0};
6772

6873
m_explicit = Hipace::m_explicit;

src/particles/deposition/PlasmaDepositCurrent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ DepositCurrent (PlasmaParticleContainer& plasma, Fields & fields,
131131
[=] AMREX_GPU_DEVICE (int ip, auto ptd,
132132
auto /*depos_order*/,
133133
auto /*can_ionize*/,
134-
auto /*use_laserr*/)
134+
auto /*use_laser*/)
135135
{
136136
// only deposit plasma currents on or below their according MR level
137137
return ptd.id(ip).is_valid() && (lev == 0 || ptd.cpu(ip) >= lev);

src/particles/deposition/TemperatureDeposition.cpp

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,60 @@ DepositTemperature (PlasmaParticleContainer& plasma,
5454
// extract laser properties and boolean for the presence of the laser and for ionization
5555
const PhysConst pc = get_phys_const();
5656
const int aabs = Hipace::m_use_laser ? Comps[WhichSlice::This]["aabs"] : -1;
57-
const bool can_ionize = plasma.m_can_ionize;
58-
const bool use_laser = Hipace::m_use_laser;
5957
const amrex::Real laser_norm = (plasma.m_charge/pc.q_e) * (pc.m_e/plasma.m_mass)
6058
* (plasma.m_charge/pc.q_e) * (pc.m_e/plasma.m_mass);
6159

6260
// Loop over particles
63-
SharedMemoryDeposition<3, 3, true>(
64-
int(pti.numParticles()),
61+
amrex::AnyCTO(
62+
// use compile-time options
63+
amrex::TypeList<
64+
amrex::CompileTimeOptions<0, 1, 2, 3>, // depos_order
65+
amrex::CompileTimeOptions<false, true>, // can_ionize
66+
amrex::CompileTimeOptions<false, true> // use_laser
67+
>{}, {
68+
Hipace::m_temperature_depos_order,
69+
plasma.m_can_ionize,
70+
Hipace::m_use_laser
71+
},
72+
// call deposition function
73+
// The three functions passed as arguments to this lambda
74+
// are defined below as the next arguments.
75+
[&](auto is_valid, auto get_start_cell, auto deposit){
76+
constexpr auto ctos = deposit.GetOptions();
77+
constexpr int depos_order = ctos[0];
78+
constexpr int use_laser = ctos[2];
79+
constexpr int stencil_size = depos_order + 1;
80+
81+
if constexpr (use_laser) {
82+
SharedMemoryDeposition<stencil_size, stencil_size, true>(
83+
int(pti.numParticles()), is_valid, get_start_cell, deposit, isl_fab.array(),
84+
isl_fab.box(), pti.GetParticleTile().getParticleTileData(),
85+
amrex::GpuArray<int, 1>{aabs},
86+
amrex::GpuArray<int, 7>{w, ux, uy, uz, uxsq, uysq, uzsq});
87+
} else {
88+
SharedMemoryDeposition<stencil_size, stencil_size, true>(
89+
int(pti.numParticles()), is_valid, get_start_cell, deposit, isl_fab.array(),
90+
isl_fab.box(), pti.GetParticleTile().getParticleTileData(),
91+
amrex::GpuArray<int, 0>{},
92+
amrex::GpuArray<int, 7>{w, ux, uy, uz, uxsq, uysq, uzsq});
93+
}
94+
},
6595
// is_valid
6696
// return whether the particle is valid and should deposit
67-
[=] AMREX_GPU_DEVICE (int ip, auto ptd)
97+
[=] AMREX_GPU_DEVICE (int ip, auto ptd,
98+
auto /*depos_order*/,
99+
auto /*can_ionize*/,
100+
auto /*use_laser*/)
68101
{
69102
// only deposit on or below their according MR level
70103
return ptd.id(ip).is_valid() && (lev == 0 || ptd.cpu(ip) >= lev);
71104
},
72-
[=] AMREX_GPU_DEVICE (int ip, auto ptd) -> amrex::IntVectND<2>
105+
// get_start_cell
106+
// return the lowest cell index that the particle deposits into
107+
[=] AMREX_GPU_DEVICE (int ip, auto ptd,
108+
auto depos_order,
109+
auto /*can_ionize*/,
110+
auto /*use_laser*/) -> amrex::IntVectND<2>
73111
{
74112
const amrex::Real xp = ptd.pos(0, ip);
75113
const amrex::Real yp = ptd.pos(1, ip);
@@ -78,17 +116,21 @@ DepositTemperature (PlasmaParticleContainer& plasma,
78116
const amrex::Real ymid = (yp - y_pos_offset) * dy_inv;
79117

80118
auto [shape_x, i] =
81-
compute_single_shape_factor<false, 0>(xmid, 0);
119+
compute_single_shape_factor<false, depos_order>(xmid, 0);
82120

83121
auto [shape_y, j] =
84-
compute_single_shape_factor<false, 0>(ymid, 0);
122+
compute_single_shape_factor<false, depos_order>(ymid, 0);
85123

86124
return {i-1, j-1};
87125
},
126+
// do_deposit
88127
// deposit of weight, momentum (ux, uy, uz) and their squares (uxsq, uysq, uzsq)
89128
[=] AMREX_GPU_DEVICE (int ip, auto ptd,
90-
Array3<amrex::Real> arr,
91-
auto cache_idx, auto depos_idx) noexcept
129+
Array3<amrex::Real> arr,
130+
auto cache_idx, auto depos_idx,
131+
auto depos_order,
132+
auto can_ionize,
133+
auto use_laser) noexcept
92134
{
93135
const amrex::Real xp = ptd.pos(0, ip);
94136
const amrex::Real yp = ptd.pos(1, ip);
@@ -101,7 +143,7 @@ DepositTemperature (PlasmaParticleContainer& plasma,
101143
ptd.idata(PlasmaIdx::ion_lev)[ip] * ptd.idata(PlasmaIdx::ion_lev)[ip];
102144
}
103145
doLaserGatherShapeN<2>(xp, yp, Aabssqp, arr, cache_idx[0],
104-
dx_inv, dy_inv, x_pos_offset, y_pos_offset);
146+
dx_inv, dy_inv, x_pos_offset, y_pos_offset);
105147
Aabssqp *= laser_norm_ion;
106148
}
107149

@@ -116,25 +158,24 @@ DepositTemperature (PlasmaParticleContainer& plasma,
116158
const amrex::Real xmid = (xp - x_pos_offset) * dx_inv;
117159
const amrex::Real ymid = (yp - y_pos_offset) * dy_inv;
118160

119-
// --- Compute shape factors
120-
// x direction
121-
auto [shape_x, i] = compute_single_shape_factor<false, 0>(xmid, 0);
122-
// y direction
123-
auto [shape_y, j] = compute_single_shape_factor<false, 0>(ymid, 0);
124-
125-
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[0]), wp);
126-
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[1]), wp*uxp);
127-
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[2]), wp*uyp);
128-
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[3]), wp*uzp);
129-
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[4]), wp*uxp*uxp);
130-
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[5]), wp*uyp*uyp);
131-
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[6]), wp*uzp*uzp);
132-
},
133-
isl_fab.array(),
134-
isl_fab.box(), pti.GetParticleTile().getParticleTileData(),
135-
amrex::GpuArray<int, 1>{aabs},
136-
amrex::GpuArray<int, 7>{w, ux, uy, uz, uxsq, uysq, uzsq}
137-
);
161+
for (int iy=0; iy <= depos_order; ++iy) {
162+
for (int ix=0; ix <= depos_order; ++ix) {
163+
// --- Compute shape factors
164+
// x direction
165+
auto [shape_x, i] = compute_single_shape_factor<false, depos_order>(xmid, ix);
166+
// y direction
167+
auto [shape_y, j] = compute_single_shape_factor<false, depos_order>(ymid, iy);
168+
169+
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[0]), shape_x*shape_y*wp);
170+
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[1]), shape_x*shape_y*wp*uxp);
171+
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[2]), shape_x*shape_y*wp*uyp);
172+
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[3]), shape_x*shape_y*wp*uzp);
173+
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[4]), shape_x*shape_y*wp*uxp*uxp);
174+
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[5]), shape_x*shape_y*wp*uyp*uyp);
175+
amrex::Gpu::Atomic::Add(arr.ptr(i, j, depos_idx[6]), shape_x*shape_y*wp*uzp*uzp);
176+
}
177+
}
178+
});
138179
Array3<amrex::Real> field_arr = isl_fab.array();
139180

140181
// Normalize the components of momentum (ux, uy, uz) and their squares (uxsq, uysq, uzsq)

tests/laser_ionization.1Rank.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ mpiexec -n 1 $HIPACE_EXECUTABLE $HIPACE_EXAMPLE_DIR/inputs_laser_ionization \
3030
my_constants.a0 = 0.00885126 \
3131
plasmas.do_push = 0 \
3232
hipace.file_prefix=$TEST_NAME/linear \
33+
hipace.temperature_depos_order = 0 \
3334
plasmas.insitu_file_prefix = $TEST_NAME/insitu_linear
3435

3536
mpiexec -n 1 $HIPACE_EXECUTABLE $HIPACE_EXAMPLE_DIR/inputs_laser_ionization \
3637
my_constants.a0 = 0.00787934 \
3738
lasers.polarization = circular \
3839
plasmas.do_push = 0 \
3940
hipace.file_prefix=$TEST_NAME/circular \
41+
hipace.temperature_depos_order = 0 \
4042
plasmas.insitu_file_prefix = $TEST_NAME/insitu_circular
4143

4244
# Compare the result with theory

0 commit comments

Comments
 (0)