Skip to content

Commit

Permalink
Fix errors in I/O (#818)
Browse files Browse the repository at this point in the history
* create openPMD series only once per rank

* reset series each time it had been written

* Update src/diagnostics/OpenPMDWriter.cpp

Fix nlev

* merge if statement

Co-authored-by: Maxence Thevenet <maxence.thevenet@desy.de>
  • Loading branch information
SeverinDiederichs and MaxThevenet authored Nov 21, 2022
1 parent e378d94 commit c96a1fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Hipace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,11 @@ Hipace::Evolve ()
m_predcorr_avg_B_error = 0.;

m_physical_time += m_dt;
}

#ifdef HIPACE_USE_OPENPMD
if (m_output_period > 0) m_openpmd_writer.reset();
m_openpmd_writer.reset(step);
#endif
}
}

void
Expand Down
6 changes: 4 additions & 2 deletions src/diagnostics/OpenPMDWriter.H
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ public:
const amrex::Vector<BoxSorter>& a_box_sorter_vec, amrex::Vector<amrex::Geometry> const& geom3D,
const OpenPMDWriterCallType call_type);

/** \brief Resets the openPMD series of all levels */
void reset ();
/** \brief Resets the openPMD series of all levels
* \param[in] output_step current iteration
*/
void reset (const int output_step);

/** Prefix/path for the output files */
std::string m_file_prefix;
Expand Down
29 changes: 12 additions & 17 deletions src/diagnostics/OpenPMDWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,18 @@ OpenPMDWriter::InitDiagnostics (const int output_step, const int output_period,
if (output_period < 0 ||
(!(output_step == max_step) && output_step % output_period != 0)) return;

if (nlev > 1) {
for (int lev=0; lev<nlev; ++lev) {
std::string filename = m_file_prefix + "/lev_" + std::to_string(lev) + "/openpmd_%06T."
+ m_openpmd_backend;

m_outputSeries.push_back(std::make_unique< openPMD::Series >(
filename, openPMD::Access::CREATE) );
m_last_output_dumped.push_back(-1);
}
} else {
std::string filename = m_file_prefix + "/openpmd_%06T." + m_openpmd_backend;

m_outputSeries.push_back(std::make_unique< openPMD::Series >(
filename, openPMD::Access::CREATE) );
m_last_output_dumped.push_back(-1);
}
m_outputSeries.resize(nlev);
m_last_output_dumped.resize(nlev);

for (int lev=0; lev<nlev; ++lev) {
std::string filename = m_file_prefix +
(nlev>1 ? "/lev_" + std::to_string(lev) : "") +
"/openpmd_%06T." + m_openpmd_backend;

m_outputSeries[lev] = std::make_unique< openPMD::Series >(
filename, openPMD::Access::CREATE);
m_last_output_dumped[lev] = -1;
}

// TODO: meta-data: author, mesh path, extensions, software
}
Expand Down Expand Up @@ -411,9 +405,10 @@ OpenPMDWriter::SaveRealProperty (BeamParticleContainer& pc,
}
}

void OpenPMDWriter::reset ()
void OpenPMDWriter::reset (const int output_step)
{
for (int lev = 0; lev<m_outputSeries.size(); ++lev) {
if (output_step != m_last_output_dumped[lev]) continue;
m_outputSeries[lev].reset();
}
}
Expand Down

0 comments on commit c96a1fc

Please sign in to comment.