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

Generalized particle restart to allow restarting other particle containers #1862

Merged
merged 5 commits into from
Oct 8, 2024
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
4 changes: 4 additions & 0 deletions Source/ERF.H
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,10 @@ private:
/*! Initialize tracer and hydro particles */
void initializeTracers ( amrex::ParGDBBase*,
const amrex::Vector<std::unique_ptr<amrex::MultiFab>>& );

/*! Restart tracer and hydro particles */
void restartTracers ( amrex::ParGDBBase*, const std::string& );

/*! Evolve tracers and hydro particles */
void evolveTracers( int,
amrex::Real,
Expand Down
8 changes: 8 additions & 0 deletions Source/ERF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,14 @@ ERF::InitData_post ()
}
}

#ifdef ERF_USE_PARTICLES
if (Microphysics::modelType(solverChoice.moisture_type) == MoistureModelType::Lagrangian) {
for (int lev = 0; lev <= finest_level; lev++) {
dynamic_cast<LagrangianMicrophysics&>(*micro).initParticles(z_phys_nd[lev]);
}
}
#endif

} else { // Restart from a checkpoint

restart();
Expand Down
5 changes: 4 additions & 1 deletion Source/IO/ERF_Checkpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,10 @@ ERF::ReadCheckpointFile ()
}

#ifdef ERF_USE_PARTICLES
particleData.Restart((ParGDBBase*)GetParGDB(),restart_chkfile);
restartTracers((ParGDBBase*)GetParGDB(),restart_chkfile);
if (Microphysics::modelType(solverChoice.moisture_type) == MoistureModelType::Lagrangian) {
dynamic_cast<LagrangianMicrophysics&>(*micro).restartParticles((ParGDBBase*)GetParGDB(),restart_chkfile);
}
#endif

#ifdef ERF_USE_NETCDF
Expand Down
12 changes: 12 additions & 0 deletions Source/Microphysics/ERF_LagrangianMicrophysics.H
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,18 @@ public:
return m_moist_model->Qstate_Size();
}

/*! \brief initialize particles in particle container */
inline void initParticles ( std::unique_ptr<amrex::MultiFab>& z_phys_nd /*!< Nodal z heights */ )
{
m_moist_model->InitParticles(z_phys_nd);
}

/*! \brief restart particles in particle container */
inline void restartParticles ( amrex::ParGDBBase* a_gdb, const std::string& a_fname)
{
m_moist_model->RestartParticles(a_gdb, a_fname);
}

/*! \brief get the particle container from the moisture model */
inline ERFPC* getParticleContainer () const
{
Expand Down
9 changes: 9 additions & 0 deletions Source/Microphysics/Null/ERF_NullMoistLagrangian.H
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#ifdef ERF_USE_PARTICLES

#include <AMReX_AmrParGDB.H>
#include "ERF_NullMoist.H"

/* forward declaration */
Expand All @@ -24,6 +25,14 @@ public:
/*! \brief Default destructor */
virtual ~NullMoistLagrangian () = default;

/*! \brief Initialize particles */
virtual
void InitParticles ( std::unique_ptr<amrex::MultiFab>& ) { }

/*! \brief Restart particles */
virtual
void RestartParticles ( amrex::ParGDBBase*, const std::string& ) { }

/*! \brief get the particle container */
virtual ERFPC* getParticleContainer ()
{
Expand Down
35 changes: 35 additions & 0 deletions Source/Particles/ERFTracers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,41 @@ void ERF::initializeTracers ( ParGDBBase* a_gdb,
return;
}

/*! Restart tracer and hydro particles */
void ERF::restartTracers ( ParGDBBase* a_gdb,
const std::string& a_fname )
{
auto& namelist_unalloc( particleData.getNamesUnalloc() );

for (auto it = namelist_unalloc.begin(); it != namelist_unalloc.end(); ++it) {

std::string species_name( *it );

if (species_name == ERFParticleNames::tracers) {

AMREX_ASSERT(m_use_tracer_particles);
ERFPC* pc = new ERFPC(a_gdb, ERFParticleNames::tracers);
pc->Restart(a_fname, ERFParticleNames::tracers);
amrex::Print() << "Restarted " << pc->TotalNumberOfParticles() << " tracer particles.\n";
particleData.pushBack(ERFParticleNames::tracers, pc);

} else if (species_name == ERFParticleNames::hydro) {

AMREX_ASSERT(m_use_hydro_particles);
ERFPC* pc = new ERFPC(a_gdb, ERFParticleNames::hydro);
pc->Restart(a_fname, ERFParticleNames::hydro);
amrex::Print() << "Restarted " << pc->TotalNumberOfParticles() << " hydro particles.\n";
particleData.pushBack(ERFParticleNames::hydro, pc);

}
}

if (m_use_tracer_particles) namelist_unalloc.remove( ERFParticleNames::tracers );
if (m_use_hydro_particles) namelist_unalloc.remove( ERFParticleNames::hydro );

return;
}

/*! Evolve tracers and hydro particles for one time step*/
void ERF::evolveTracers ( int a_lev,
Real a_dt_lev,
Expand Down
14 changes: 0 additions & 14 deletions Source/Particles/ERF_ParticleData.H
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,6 @@ class ParticleData
}
}

/*! Read from restart file */
void Restart ( amrex::ParGDBBase* a_gdb, const std::string& a_fname )
{
BL_PROFILE("ParticleData::Restart()");
AMREX_ASSERT(isEmpty());
for (auto it = m_namelist_unalloc.begin(); it != m_namelist_unalloc.end(); ++it) {
std::string species_name( *it );
ERFPC* pc = new ERFPC( a_gdb, species_name );
pc->Restart(a_fname, species_name );
pushBack( species_name, pc );
}
m_namelist_unalloc.clear();
}

/*! Get mesh plot quantities from each particle container */
void GetMeshPlotVarNames ( amrex::Vector<std::string>& a_names ) const
{
Expand Down
Loading