Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ParticleContainer: Delay Shape Init #145

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ImpactX.H
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ namespace impactx

/** Resize the mesh, based on the extent of the bunch of particle
*
* This only changes thes physical extent of the mesh, but not the
* This only changes the physical extent of the mesh, but not the
* number of grid cells.
*/
void ResizeMesh ();
Expand Down
5 changes: 5 additions & 0 deletions src/ImpactX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ namespace impactx

void ImpactX::initGrids ()
{
// this is the earliest point that we need to know the particle shape,
// so that we can initialize the guard size of our MultiFabs
m_particle_container->SetParticleShape();

// init blocks / grids & MultiFabs
AmrCore::InitFromScratch(0.0);
amrex::Print() << "boxArray(0) " << boxArray(0) << std::endl;

Expand Down
3 changes: 2 additions & 1 deletion src/particles/ChargeDeposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ namespace impactx
ablastr::particles::deposit_charge<ImpactXParticleContainer>
(pti, wp, charge, ion_lev, &rho_at_level,
local_rho_fab,
m_particle_shape, dx, xyzmin, n_rz_azimuthal_modes);
m_particle_shape.value(),
dx, xyzmin, n_rz_azimuthal_modes);
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions src/particles/ImpactXParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <AMReX_IntVect.H>
#include <AMReX_Vector.H>

#include <optional>
#include <tuple>
#include <unordered_map>

Expand Down Expand Up @@ -147,7 +148,15 @@ namespace impactx
/** Get particle shape
*/
int
GetParticleShape () const { return m_particle_shape; }
GetParticleShape () const { return m_particle_shape.value(); }

/** Set Particle Shape from amrex::ParmParse inputs
*
* Note: this can only be called once. All later calls are a logic error.
* The reason for that is that subsequent calls would need to change
* the guard size of all our MultiFabs, which is not implemented.
*/
void SetParticleShape ();

/** Compute the min and max of the particle position in each dimension
*
Expand Down Expand Up @@ -187,7 +196,7 @@ namespace impactx
RefPart m_refpart;

//! the particle shape
int m_particle_shape = 0;
std::optional<int> m_particle_shape;

}; // ImpactXParticleContainer

Expand Down
22 changes: 16 additions & 6 deletions src/particles/ImpactXParticleContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,31 @@
#include <AMReX_ParmParse.H>
#include <AMReX_ParticleTile.H>

#include <stdexcept>


namespace impactx
{
ImpactXParticleContainer::ImpactXParticleContainer (amrex::AmrCore* amr_core)
: amrex::ParticleContainer<0, 0, RealSoA::nattribs, IntSoA::nattribs>(amr_core->GetParGDB())
{
SetParticleSize();
}

// particle shapes
amrex::ParmParse pp_algo("algo");
pp_algo.get("particle_shape", m_particle_shape);
if (m_particle_shape < 1 || m_particle_shape > 3)
void ImpactXParticleContainer::SetParticleShape ()
{
if (m_particle_shape.has_value()) {
throw std::logic_error(
"ImpactXParticleContainer::SetParticleShape This was already called before and cannot be changed.");
} else
{
amrex::Abort("algo.particle_shape can be only 1, 2, or 3");
amrex::ParmParse pp_algo("algo");
int v = 0;
pp_algo.get("particle_shape", v);
m_particle_shape = v;
if (m_particle_shape.value() < 1 || m_particle_shape.value() > 3) {
amrex::Abort("algo.particle_shape can be only 1, 2, or 3");
}
}
}

Expand All @@ -55,7 +66,6 @@ namespace impactx
AMREX_ALWAYS_ASSERT(x.size() == py.size());
AMREX_ALWAYS_ASSERT(x.size() == pz.size());


// number of particles to add
int const np = x.size();

Expand Down