Skip to content

Commit 4ab88c5

Browse files
authored
Fix undefined behavior issue in WarpX initialization (#4615)
* fix out of bound issue found with sanitizer * fixed bug
1 parent 9d35f5e commit 4ab88c5

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

Source/WarpX.cpp

+20-17
Original file line numberDiff line numberDiff line change
@@ -288,26 +288,29 @@ WarpX::WarpX ()
288288
t_old.resize(nlevs_max, std::numeric_limits<Real>::lowest());
289289
dt.resize(nlevs_max, std::numeric_limits<Real>::max());
290290

291-
// Loop over species (particles and lasers)
292-
// and set current injection position per species
293291
mypc = std::make_unique<MultiParticleContainer>(this);
294-
const int n_containers = mypc->nContainers();
295-
for (int i=0; i<n_containers; i++)
296-
{
297-
WarpXParticleContainer& pc = mypc->GetParticleContainer(i);
298292

299-
// Storing injection position for all species, regardless of whether
300-
// they are continuously injected, since it makes looping over the
301-
// elements of current_injection_position easier elsewhere in the code.
302-
if (moving_window_v > 0._rt)
303-
{
304-
// Inject particles continuously from the right end of the box
305-
pc.m_current_injection_position = geom[0].ProbHi(moving_window_dir);
306-
}
307-
else if (moving_window_v < 0._rt)
293+
// Loop over species (particles and lasers)
294+
// and set current injection position per species
295+
if (do_moving_window){
296+
const int n_containers = mypc->nContainers();
297+
for (int i=0; i<n_containers; i++)
308298
{
309-
// Inject particles continuously from the left end of the box
310-
pc.m_current_injection_position = geom[0].ProbLo(moving_window_dir);
299+
WarpXParticleContainer& pc = mypc->GetParticleContainer(i);
300+
301+
// Storing injection position for all species, regardless of whether
302+
// they are continuously injected, since it makes looping over the
303+
// elements of current_injection_position easier elsewhere in the code.
304+
if (moving_window_v > 0._rt)
305+
{
306+
// Inject particles continuously from the right end of the box
307+
pc.m_current_injection_position = geom[0].ProbHi(moving_window_dir);
308+
}
309+
else if (moving_window_v < 0._rt)
310+
{
311+
// Inject particles continuously from the left end of the box
312+
pc.m_current_injection_position = geom[0].ProbLo(moving_window_dir);
313+
}
311314
}
312315
}
313316

0 commit comments

Comments
 (0)