Skip to content

Commit f172beb

Browse files
committed
openPMD: Skip 0-positions for deselected comps
1 parent a100076 commit f172beb

File tree

2 files changed

+40
-33
lines changed

2 files changed

+40
-33
lines changed

Source/Diagnostics/WarpXOpenPMD.H

+5-1
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,13 @@ private:
218218
/** This function sets up the entries for storing the particle positions and global IDs
219219
*
220220
* @param[in] currSpecies Corresponding openPMD species
221+
* @param[in] positionComponents user-selected components of the particle position
221222
* @param[in] np Number of particles
222223
* @param[in] isBTD Is this a back-transformed diagnostics output?
223224
*/
224225
void SetupPos (
225226
openPMD::ParticleSpecies& currSpecies,
227+
std::vector<std::string> const & positionComponents,
226228
const unsigned long long& np,
227229
bool isBTD = false);
228230

@@ -231,12 +233,14 @@ private:
231233
* Sets the entries for storing particle position offset, constant records (charge, mass) and ED-PIC attributes.
232234
*
233235
* @param[in] currSpecies Corresponding openPMD species
236+
* @param[in] positionComponents user-selected components of the particle position
234237
* @param[in] np Number of particles
235238
* @param[in] charge Charge of the particles (note: fix for ions)
236239
* @param[in] mass Mass of the particles
237240
*/
238241
void SetConstParticleRecordsEDPIC (
239242
openPMD::ParticleSpecies& currSpecies,
243+
std::vector<std::string> const & positionComponents,
240244
const unsigned long long& np,
241245
amrex::ParticleReal charge,
242246
amrex::ParticleReal mass);
@@ -284,8 +288,8 @@ private:
284288
* @param[in] name species name
285289
* @param[in] iteration timestep
286290
* @param[in] write_real_comp The real attribute ids, from WarpX
287-
* @param[in] real_comp_names The real attribute names, from WarpX
288291
* @param[in] write_int_comp The int attribute ids, from WarpX
292+
* @param[in] real_comp_names The real attribute names, from WarpX
289293
* @param[in] int_comp_names The int attribute names, from WarpX
290294
* @param[in] charge Charge of the particles (note: fix for ions)
291295
* @param[in] mass Mass of the particles

Source/Diagnostics/WarpXOpenPMD.cpp

+35-32
Original file line numberDiff line numberDiff line change
@@ -213,32 +213,29 @@ namespace detail
213213
return make_pair(record_name, component_name);
214214
}
215215

216-
/** Return the component labels for particle positions
216+
/** Return the user-selected components for particle positions
217+
*
218+
* @param[in] write_real_comp The real attribute ids, from WarpX
219+
* @param[in] real_comp_names The real attribute names, from WarpX
217220
*/
218221
inline std::vector< std::string >
219-
getParticlePositionComponentLabels (bool ignore_dims=false)
222+
getParticlePositionComponentLabels (
223+
amrex::Vector<int> const & write_real_comp,
224+
amrex::Vector<std::string> const & real_comp_names)
220225
{
221-
using vs = std::vector< std::string >;
222-
auto positionComponents = vs{"x", "y", "z"};
223-
if (!ignore_dims) {
224-
#if defined(WARPX_DIM_1D_Z)
225-
positionComponents = vs{"z"};
226-
#elif defined(WARPX_DIM_XZ)
227-
positionComponents = vs{"x", "z"};
228-
#elif defined(WARPX_DIM_RZ)
229-
// note: although we internally store particle positions
230-
// for AMReX in r,z and a theta attribute, we
231-
// actually need them for algorithms (e.g. push)
232-
// and I/O in Cartesian.
233-
// Other attributes like momentum are consequently
234-
// stored in x,y,z internally.
235-
positionComponents = vs{"x", "y", "z"};
236-
#elif defined(WARPX_DIM_3D)
237-
positionComponents = vs{"x", "y", "z"};
238-
#else
239-
# error Unknown WarpX dimensionality.
240-
#endif
226+
std::vector< std::string > positionComponents;
227+
228+
int idx = 0;
229+
for (auto const & comp : real_comp_names ) {
230+
if (write_real_comp[idx]) {
231+
if (comp == "position_x" || comp == "position_y" || comp == "position_z") {
232+
std::string const last_letter{comp.back()};
233+
positionComponents.push_back(last_letter);
234+
}
235+
}
236+
idx++;
241237
}
238+
242239
return positionComponents;
243240
}
244241

@@ -705,16 +702,18 @@ WarpXOpenPMDPlot::DumpToFile (ParticleContainer* pc,
705702
doParticleSetup = is_first_flush_with_particles || is_last_flush_and_never_particles;
706703
}
707704

705+
auto const positionComponents = detail::getParticlePositionComponentLabels(write_real_comp, real_comp_names);
706+
708707
// this setup stage also implicitly calls "makeEmpty" if needed (i.e., is_last_flush_and_never_particles)
709708
// for BTD, we call this multiple times as we may resize in subsequent dumps if number of particles in the buffer > 0
710709
if (doParticleSetup || is_resizing_flush) {
711-
SetupPos(currSpecies, NewParticleVectorSize, isBTD);
710+
SetupPos(currSpecies, positionComponents, NewParticleVectorSize, isBTD);
712711
SetupRealProperties(pc, currSpecies, write_real_comp, real_comp_names, write_int_comp, int_comp_names,
713712
NewParticleVectorSize, isBTD);
714713
}
715714

716715
if (is_last_flush_to_step) {
717-
SetConstParticleRecordsEDPIC(currSpecies, NewParticleVectorSize, charge, mass);
716+
SetConstParticleRecordsEDPIC(currSpecies, positionComponents, NewParticleVectorSize, charge, mass);
718717
}
719718

720719
// open files from all processors, in case some will not contribute below
@@ -978,6 +977,7 @@ WarpXOpenPMDPlot::SaveRealProperty (ParticleIter& pti,
978977
void
979978
WarpXOpenPMDPlot::SetupPos (
980979
openPMD::ParticleSpecies& currSpecies,
980+
std::vector<std::string> const & positionComponents,
981981
const unsigned long long& np,
982982
bool const isBTD)
983983
{
@@ -986,7 +986,6 @@ WarpXOpenPMDPlot::SetupPos (
986986
auto realType = openPMD::Dataset(openPMD::determineDatatype<amrex::ParticleReal>(), {np}, options);
987987
auto idType = openPMD::Dataset(openPMD::determineDatatype< uint64_t >(), {np}, options);
988988

989-
auto const positionComponents = detail::getParticlePositionComponentLabels();
990989
for( auto const& comp : positionComponents ) {
991990
currSpecies["position"][comp].resetDataset( realType );
992991
}
@@ -998,6 +997,7 @@ WarpXOpenPMDPlot::SetupPos (
998997
void
999998
WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
1000999
openPMD::ParticleSpecies& currSpecies,
1000+
std::vector<std::string> const & positionComponents,
10011001
const unsigned long long& np,
10021002
amrex::ParticleReal const charge,
10031003
amrex::ParticleReal const mass)
@@ -1006,7 +1006,6 @@ WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
10061006
const auto *const scalar = openPMD::RecordComponent::SCALAR;
10071007

10081008
// define record shape to be number of particles
1009-
auto const positionComponents = detail::getParticlePositionComponentLabels(true);
10101009
for( auto const& comp : positionComponents ) {
10111010
currSpecies["positionOffset"][comp].resetDataset( realType );
10121011
}
@@ -1037,16 +1036,20 @@ WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
10371036
#endif
10381037

10391038
// meta data
1040-
currSpecies["position"].setUnitDimension( detail::getUnitDimension("position") );
1041-
currSpecies["positionOffset"].setUnitDimension( detail::getUnitDimension("positionOffset") );
1039+
if (!positionComponents.empty()) {
1040+
currSpecies["position"].setUnitDimension( detail::getUnitDimension("position") );
1041+
currSpecies["positionOffset"].setUnitDimension( detail::getUnitDimension("positionOffset") );
1042+
}
10421043
currSpecies["charge"].setUnitDimension( detail::getUnitDimension("charge") );
10431044
currSpecies["mass"].setUnitDimension( detail::getUnitDimension("mass") );
10441045

10451046
// meta data for ED-PIC extension
1046-
currSpecies["position"].setAttribute( "macroWeighted", 0u );
1047-
currSpecies["position"].setAttribute( "weightingPower", 0.0 );
1048-
currSpecies["positionOffset"].setAttribute( "macroWeighted", 0u );
1049-
currSpecies["positionOffset"].setAttribute( "weightingPower", 0.0 );
1047+
if (!positionComponents.empty()) {
1048+
currSpecies["position"].setAttribute( "macroWeighted", 0u );
1049+
currSpecies["position"].setAttribute( "weightingPower", 0.0 );
1050+
currSpecies["positionOffset"].setAttribute( "macroWeighted", 0u );
1051+
currSpecies["positionOffset"].setAttribute( "weightingPower", 0.0 );
1052+
}
10501053
currSpecies["id"].setAttribute( "macroWeighted", 0u );
10511054
currSpecies["id"].setAttribute( "weightingPower", 0.0 );
10521055
currSpecies["charge"].setAttribute( "macroWeighted", 0u );

0 commit comments

Comments
 (0)