Skip to content

Commit

Permalink
Fix undefined behavior issue in WarpX initialization (ECP-WarpX#4615)
Browse files Browse the repository at this point in the history
* fix out of bound issue found with sanitizer

* fixed bug
  • Loading branch information
lucafedeli88 authored Jan 23, 2024
1 parent 9d35f5e commit 4ab88c5
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,26 +288,29 @@ WarpX::WarpX ()
t_old.resize(nlevs_max, std::numeric_limits<Real>::lowest());
dt.resize(nlevs_max, std::numeric_limits<Real>::max());

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

// Storing injection position for all species, regardless of whether
// they are continuously injected, since it makes looping over the
// elements of current_injection_position easier elsewhere in the code.
if (moving_window_v > 0._rt)
{
// Inject particles continuously from the right end of the box
pc.m_current_injection_position = geom[0].ProbHi(moving_window_dir);
}
else if (moving_window_v < 0._rt)
// Loop over species (particles and lasers)
// and set current injection position per species
if (do_moving_window){
const int n_containers = mypc->nContainers();
for (int i=0; i<n_containers; i++)
{
// Inject particles continuously from the left end of the box
pc.m_current_injection_position = geom[0].ProbLo(moving_window_dir);
WarpXParticleContainer& pc = mypc->GetParticleContainer(i);

// Storing injection position for all species, regardless of whether
// they are continuously injected, since it makes looping over the
// elements of current_injection_position easier elsewhere in the code.
if (moving_window_v > 0._rt)
{
// Inject particles continuously from the right end of the box
pc.m_current_injection_position = geom[0].ProbHi(moving_window_dir);
}
else if (moving_window_v < 0._rt)
{
// Inject particles continuously from the left end of the box
pc.m_current_injection_position = geom[0].ProbLo(moving_window_dir);
}
}
}

Expand Down

0 comments on commit 4ab88c5

Please sign in to comment.