Skip to content

Commit

Permalink
Temporary implicit attributes are not written to the checkpoint file
Browse files Browse the repository at this point in the history
As a bonus, the parallel communication is also turned off
  • Loading branch information
dpgrote committed Dec 14, 2024
1 parent f6f93cd commit 6c67ea0
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 37 deletions.
23 changes: 20 additions & 3 deletions Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,31 +185,48 @@ FlushFormatCheckpoint::CheckpointParticles (

Vector<std::string> real_names;
Vector<std::string> int_names;
Vector<int> write_real_comps;
Vector<int> write_int_comps;

// note: positions skipped here, since we reconstruct a plotfile SoA from them
real_names.push_back("weight");
write_real_comps.push_back(1);
real_names.push_back("momentum_x");
write_real_comps.push_back(1);
real_names.push_back("momentum_y");
write_real_comps.push_back(1);
real_names.push_back("momentum_z");
write_real_comps.push_back(1);

#ifdef WARPX_DIM_RZ
real_names.push_back("theta");
#endif

int const compile_time_comps = static_cast<int>(real_names.size());

// get the names of the real comps
// note: skips the mandatory AMREX_SPACEDIM positions for pure SoA
real_names.resize(pc->NumRealComps() - AMREX_SPACEDIM);
write_real_comps.resize(pc->NumRealComps() - AMREX_SPACEDIM);
auto runtime_rnames = pc->getParticleRuntimeComps();
for (auto const& x : runtime_rnames) {
real_names[x.second + PIdx::nattribs - AMREX_SPACEDIM] = x.first;
int const i = x.second + PIdx::nattribs - AMREX_SPACEDIM;
real_names[i] = x.first;
write_real_comps[i] = pc->h_redistribute_real_comp[i + compile_time_comps];
}

// and the int comps
int_names.resize(pc->NumIntComps());
write_int_comps.resize(pc->NumIntComps());
auto runtime_inames = pc->getParticleRuntimeiComps();
for (auto const& x : runtime_inames) { int_names[x.second+0] = x.first; }
for (auto const& x : runtime_inames) {
int const i = x.second + 0;
int_names[i] = x.first;
write_int_comps[i] = pc->h_redistribute_int_comp[i+AMREX_SPACEDIM];
}

pc->Checkpoint(dir, part_diag.getSpeciesName(), true,
pc->Checkpoint(dir, part_diag.getSpeciesName(),
write_real_comps, write_int_comps,
real_names, int_names);
}
}
Expand Down
24 changes: 5 additions & 19 deletions Source/Diagnostics/WarpXIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -400,30 +400,16 @@ WarpX::InitFromCheckpoint ()

if (EB::enabled()) { InitializeEBGridData(maxLevel()); }

// Initialize particles
mypc->AllocData();
mypc->Restart(restart_chkfile);

if (m_implicit_solver) {

m_implicit_solver->Define(this);
m_implicit_solver->GetParticleSolverParams( max_particle_its_in_implicit_scheme,
particle_tol_in_implicit_scheme );

// Add space to save the positions and velocities at the start of the time steps
for (auto const& pc : *mypc) {
#if (AMREX_SPACEDIM >= 2)
pc->NewRealComp("x_n");
#endif
#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ)
pc->NewRealComp("y_n");
#endif
pc->NewRealComp("z_n");
pc->NewRealComp("ux_n");
pc->NewRealComp("uy_n");
pc->NewRealComp("uz_n");
}

m_implicit_solver->CreateParticleAttributes();
}

// Initialize particles
mypc->AllocData();
mypc->Restart(restart_chkfile);

}
2 changes: 2 additions & 0 deletions Source/FieldSolver/ImplicitSolvers/ImplicitSolver.H
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public:
a_particle_tol = m_particle_tolerance;
}

void CreateParticleAttributes () const;

/**
* \brief Advance fields and particles by one time step using the specified implicit algorithm
*/
Expand Down
22 changes: 22 additions & 0 deletions Source/FieldSolver/ImplicitSolvers/ImplicitSolver.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,30 @@
#include "ImplicitSolver.H"
#include "WarpX.H"
#include "Particles/MultiParticleContainer.H"

using namespace amrex;

void ImplicitSolver::CreateParticleAttributes () const
{
// Set comm to false to that the attributes are not communicated
// nor written to the checkpoint files
int const comm = 0;

// Add space to save the positions and velocities at the start of the time steps
for (auto const& pc : m_WarpX->GetPartContainer()) {
#if (AMREX_SPACEDIM >= 2)
pc->NewRealComp("x_n", comm);
#endif
#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ)
pc->NewRealComp("y_n", comm);
#endif
pc->NewRealComp("z_n", comm);
pc->NewRealComp("ux_n", comm);
pc->NewRealComp("uy_n", comm);
pc->NewRealComp("uz_n", comm);
}
}

const Geometry& ImplicitSolver::GetGeometry (const int a_lvl) const
{
AMREX_ASSERT((a_lvl >= 0) && (a_lvl < m_num_amr_levels));
Expand Down
16 changes: 1 addition & 15 deletions Source/Initialization/WarpXInitData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,21 +684,7 @@ WarpX::InitFromScratch ()
m_implicit_solver->Define(this);
m_implicit_solver->GetParticleSolverParams( max_particle_its_in_implicit_scheme,
particle_tol_in_implicit_scheme );

// Add space to save the positions and velocities at the start of the time steps
for (auto const& pc : *mypc) {
#if (AMREX_SPACEDIM >= 2)
pc->NewRealComp("x_n");
#endif
#if defined(WARPX_DIM_3D) || defined(WARPX_DIM_RZ)
pc->NewRealComp("y_n");
#endif
pc->NewRealComp("z_n");
pc->NewRealComp("ux_n");
pc->NewRealComp("uy_n");
pc->NewRealComp("uz_n");
}

m_implicit_solver->CreateParticleAttributes();
}

mypc->AllocData();
Expand Down

0 comments on commit 6c67ea0

Please sign in to comment.