Skip to content

Commit 94d48fd

Browse files
authored
ParticleHistogram2D change openPMD access type (#4659)
* Change openPMD access type Changed openPMD access type for file creation in ParticleHistogram2D from APPEND to CREATE to avoid warnings on execution. Additionally: - make paths compatible with Windows - allow to set the runtime option `file_min_digits` * Add file_min_digits parameter to docs
1 parent 9c082da commit 94d48fd

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

Docs/source/usage/parameters.rst

+3
Original file line numberDiff line numberDiff line change
@@ -3104,6 +3104,9 @@ Reduced Diagnostics
31043104
A species name must be provided,
31053105
such that the diagnostics are done for this species.
31063106

3107+
* ``<reduced_diags_name>.file_min_digits`` (`int`) optional (default `6`)
3108+
The minimum number of digits used for the iteration number appended to the diagnostic file names.
3109+
31073110
* ``<reduced_diags_name>.histogram_function_abs(t,x,y,z,ux,uy,uz,w)`` (`string`)
31083111
A histogram function must be provided for the abscissa axis.
31093112
`t` represents the physical time in seconds during the simulation.

Source/Diagnostics/ReducedDiags/ParticleHistogram2D.H

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public:
3535
/// File type
3636
std::string m_openpmd_backend {"default"};
3737

38+
/// minimum number of digits for file suffix (file-based only supported now for now) */
39+
int m_file_min_digits = 6;
40+
3841
/// number of bins on the abscissa and ordinate
3942
int m_bin_num_abs;
4043
int m_bin_num_ord;

Source/Diagnostics/ReducedDiags/ParticleHistogram2D.cpp

+15-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ ParticleHistogram2D::ParticleHistogram2D (std::string rd_name)
6060
ParmParse pp_rd_name(rd_name);
6161

6262
pp_rd_name.query("openpmd_backend", m_openpmd_backend);
63+
pp_rd_name.query("file_min_digits", m_file_min_digits);
6364
// pick first available backend if default is chosen
6465
if( m_openpmd_backend == "default" ) {
6566
m_openpmd_backend = WarpXOpenPMDFileType();
@@ -260,10 +261,22 @@ void ParticleHistogram2D::WriteToFile (int step) const
260261
// only IO processor writes
261262
if ( !ParallelDescriptor::IOProcessor() ) { return; }
262263

264+
// TODO: support different filename templates
265+
std::string filename = "openpmd";
266+
// TODO: support also group-based encoding
267+
const std::string fileSuffix = std::string("_%0") + std::to_string(m_file_min_digits) + std::string("T");
268+
filename = filename.append(fileSuffix).append(".").append(m_openpmd_backend);
269+
270+
std::string filepath = m_path + m_rd_name + "/" + filename;
271+
// transform paths for Windows
272+
#ifdef _WIN32
273+
filepath = openPMD::auxiliary::replace_all(filepath, "/", "\\");
274+
#endif
275+
263276
// Create the OpenPMD series
264277
auto series = io::Series(
265-
m_path + m_rd_name + "/openpmd_%06T." + m_openpmd_backend,
266-
io::Access::APPEND);
278+
filepath,
279+
io::Access::CREATE);
267280
auto i = series.iterations[step + 1];
268281
// record
269282
auto f_mesh = i.meshes["data"];

0 commit comments

Comments
 (0)