@@ -213,32 +213,29 @@ namespace detail
213
213
return make_pair (record_name, component_name);
214
214
}
215
215
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
217
220
*/
218
221
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)
220
225
{
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++;
241
237
}
238
+
242
239
return positionComponents;
243
240
}
244
241
@@ -705,16 +702,18 @@ WarpXOpenPMDPlot::DumpToFile (ParticleContainer* pc,
705
702
doParticleSetup = is_first_flush_with_particles || is_last_flush_and_never_particles;
706
703
}
707
704
705
+ auto const positionComponents = detail::getParticlePositionComponentLabels (write_real_comp, real_comp_names);
706
+
708
707
// this setup stage also implicitly calls "makeEmpty" if needed (i.e., is_last_flush_and_never_particles)
709
708
// for BTD, we call this multiple times as we may resize in subsequent dumps if number of particles in the buffer > 0
710
709
if (doParticleSetup || is_resizing_flush) {
711
- SetupPos (currSpecies, NewParticleVectorSize, isBTD);
710
+ SetupPos (currSpecies, positionComponents, NewParticleVectorSize, isBTD);
712
711
SetupRealProperties (pc, currSpecies, write_real_comp, real_comp_names, write_int_comp, int_comp_names,
713
712
NewParticleVectorSize, isBTD);
714
713
}
715
714
716
715
if (is_last_flush_to_step) {
717
- SetConstParticleRecordsEDPIC (currSpecies, NewParticleVectorSize, charge, mass);
716
+ SetConstParticleRecordsEDPIC (currSpecies, positionComponents, NewParticleVectorSize, charge, mass);
718
717
}
719
718
720
719
// open files from all processors, in case some will not contribute below
@@ -978,6 +977,7 @@ WarpXOpenPMDPlot::SaveRealProperty (ParticleIter& pti,
978
977
void
979
978
WarpXOpenPMDPlot::SetupPos (
980
979
openPMD::ParticleSpecies& currSpecies,
980
+ std::vector<std::string> const & positionComponents,
981
981
const unsigned long long & np,
982
982
bool const isBTD)
983
983
{
@@ -986,7 +986,6 @@ WarpXOpenPMDPlot::SetupPos (
986
986
auto realType = openPMD::Dataset (openPMD::determineDatatype<amrex::ParticleReal>(), {np}, options);
987
987
auto idType = openPMD::Dataset (openPMD::determineDatatype< uint64_t >(), {np}, options);
988
988
989
- auto const positionComponents = detail::getParticlePositionComponentLabels ();
990
989
for ( auto const & comp : positionComponents ) {
991
990
currSpecies[" position" ][comp].resetDataset ( realType );
992
991
}
@@ -998,6 +997,7 @@ WarpXOpenPMDPlot::SetupPos (
998
997
void
999
998
WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
1000
999
openPMD::ParticleSpecies& currSpecies,
1000
+ std::vector<std::string> const & positionComponents,
1001
1001
const unsigned long long & np,
1002
1002
amrex::ParticleReal const charge,
1003
1003
amrex::ParticleReal const mass)
@@ -1006,7 +1006,6 @@ WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
1006
1006
const auto *const scalar = openPMD::RecordComponent::SCALAR;
1007
1007
1008
1008
// define record shape to be number of particles
1009
- auto const positionComponents = detail::getParticlePositionComponentLabels (true );
1010
1009
for ( auto const & comp : positionComponents ) {
1011
1010
currSpecies[" positionOffset" ][comp].resetDataset ( realType );
1012
1011
}
@@ -1037,16 +1036,20 @@ WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
1037
1036
#endif
1038
1037
1039
1038
// 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
+ }
1042
1043
currSpecies[" charge" ].setUnitDimension ( detail::getUnitDimension (" charge" ) );
1043
1044
currSpecies[" mass" ].setUnitDimension ( detail::getUnitDimension (" mass" ) );
1044
1045
1045
1046
// 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
+ }
1050
1053
currSpecies[" id" ].setAttribute ( " macroWeighted" , 0u );
1051
1054
currSpecies[" id" ].setAttribute ( " weightingPower" , 0.0 );
1052
1055
currSpecies[" charge" ].setAttribute ( " macroWeighted" , 0u );
0 commit comments