Skip to content

Commit

Permalink
openPMD: Skip 0-positions for deselected comps
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed May 6, 2024
1 parent a100076 commit 5dfee18
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 33 deletions.
6 changes: 5 additions & 1 deletion Source/Diagnostics/WarpXOpenPMD.H
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,13 @@ private:
/** This function sets up the entries for storing the particle positions and global IDs
*
* @param[in] currSpecies Corresponding openPMD species
* @param[in] positionComponents user-selected components of the particle position
* @param[in] np Number of particles
* @param[in] isBTD Is this a back-transformed diagnostics output?
*/
void SetupPos (
openPMD::ParticleSpecies& currSpecies,
std::vector<std::string> const & positionComponents,
const unsigned long long& np,
bool isBTD = false);

Expand All @@ -231,12 +233,14 @@ private:
* Sets the entries for storing particle position offset, constant records (charge, mass) and ED-PIC attributes.
*
* @param[in] currSpecies Corresponding openPMD species
* @param[in] positionComponents user-selected components of the particle position
* @param[in] np Number of particles
* @param[in] charge Charge of the particles (note: fix for ions)
* @param[in] mass Mass of the particles
*/
void SetConstParticleRecordsEDPIC (
openPMD::ParticleSpecies& currSpecies,
std::vector<std::string> const & positionComponents,
const unsigned long long& np,
amrex::ParticleReal charge,
amrex::ParticleReal mass);
Expand Down Expand Up @@ -284,8 +288,8 @@ private:
* @param[in] name species name
* @param[in] iteration timestep
* @param[in] write_real_comp The real attribute ids, from WarpX
* @param[in] real_comp_names The real attribute names, from WarpX
* @param[in] write_int_comp The int attribute ids, from WarpX
* @param[in] real_comp_names The real attribute names, from WarpX
* @param[in] int_comp_names The int attribute names, from WarpX
* @param[in] charge Charge of the particles (note: fix for ions)
* @param[in] mass Mass of the particles
Expand Down
66 changes: 34 additions & 32 deletions Source/Diagnostics/WarpXOpenPMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,32 +213,28 @@ namespace detail
return make_pair(record_name, component_name);
}

/** Return the component labels for particle positions
/** Return the selected components for particle positions
*
* @param[in] write_real_comp The real attribute ids, from WarpX
* @param[in] real_comp_names The real attribute names, from WarpX
*/
inline std::vector< std::string >
getParticlePositionComponentLabels (bool ignore_dims=false)
getParticlePositionComponentLabels (
amrex::Vector<int> const & write_real_comp,
amrex::Vector<std::string> const & real_comp_names)
{
using vs = std::vector< std::string >;
auto positionComponents = vs{"x", "y", "z"};
if (!ignore_dims) {
#if defined(WARPX_DIM_1D_Z)
positionComponents = vs{"z"};
#elif defined(WARPX_DIM_XZ)
positionComponents = vs{"x", "z"};
#elif defined(WARPX_DIM_RZ)
// note: although we internally store particle positions
// for AMReX in r,z and a theta attribute, we
// actually need them for algorithms (e.g. push)
// and I/O in Cartesian.
// Other attributes like momentum are consequently
// stored in x,y,z internally.
positionComponents = vs{"x", "y", "z"};
#elif defined(WARPX_DIM_3D)
positionComponents = vs{"x", "y", "z"};
#else
# error Unknown WarpX dimensionality.
#endif
std::vector< std::string > positionComponents;

int idx = 0;
for (auto const & comp : real_comp_names ) {
if (write_real_comp[idx]) {
if (comp == "x" || comp == "y" || comp == "z") {
positionComponents.push_back(comp);
}
}
idx++;
}

return positionComponents;
}

Expand Down Expand Up @@ -705,16 +701,18 @@ WarpXOpenPMDPlot::DumpToFile (ParticleContainer* pc,
doParticleSetup = is_first_flush_with_particles || is_last_flush_and_never_particles;
}

auto const positionComponents = detail::getParticlePositionComponentLabels(write_real_comp, real_comp_names);

// this setup stage also implicitly calls "makeEmpty" if needed (i.e., is_last_flush_and_never_particles)
// for BTD, we call this multiple times as we may resize in subsequent dumps if number of particles in the buffer > 0
if (doParticleSetup || is_resizing_flush) {
SetupPos(currSpecies, NewParticleVectorSize, isBTD);
SetupPos(currSpecies, positionComponents, NewParticleVectorSize, isBTD);
SetupRealProperties(pc, currSpecies, write_real_comp, real_comp_names, write_int_comp, int_comp_names,
NewParticleVectorSize, isBTD);
}

if (is_last_flush_to_step) {
SetConstParticleRecordsEDPIC(currSpecies, NewParticleVectorSize, charge, mass);
SetConstParticleRecordsEDPIC(currSpecies, positionComponents, NewParticleVectorSize, charge, mass);
}

// open files from all processors, in case some will not contribute below
Expand Down Expand Up @@ -978,6 +976,7 @@ WarpXOpenPMDPlot::SaveRealProperty (ParticleIter& pti,
void
WarpXOpenPMDPlot::SetupPos (
openPMD::ParticleSpecies& currSpecies,
std::vector<std::string> const & positionComponents,
const unsigned long long& np,
bool const isBTD)
{
Expand All @@ -986,7 +985,6 @@ WarpXOpenPMDPlot::SetupPos (
auto realType = openPMD::Dataset(openPMD::determineDatatype<amrex::ParticleReal>(), {np}, options);
auto idType = openPMD::Dataset(openPMD::determineDatatype< uint64_t >(), {np}, options);

auto const positionComponents = detail::getParticlePositionComponentLabels();
for( auto const& comp : positionComponents ) {
currSpecies["position"][comp].resetDataset( realType );
}
Expand All @@ -998,6 +996,7 @@ WarpXOpenPMDPlot::SetupPos (
void
WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
openPMD::ParticleSpecies& currSpecies,
std::vector<std::string> const & positionComponents,
const unsigned long long& np,
amrex::ParticleReal const charge,
amrex::ParticleReal const mass)
Expand All @@ -1006,7 +1005,6 @@ WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
const auto *const scalar = openPMD::RecordComponent::SCALAR;

// define record shape to be number of particles
auto const positionComponents = detail::getParticlePositionComponentLabels(true);
for( auto const& comp : positionComponents ) {
currSpecies["positionOffset"][comp].resetDataset( realType );
}
Expand Down Expand Up @@ -1037,16 +1035,20 @@ WarpXOpenPMDPlot::SetConstParticleRecordsEDPIC (
#endif

// meta data
currSpecies["position"].setUnitDimension( detail::getUnitDimension("position") );
currSpecies["positionOffset"].setUnitDimension( detail::getUnitDimension("positionOffset") );
if (!positionComponents.empty()) {
currSpecies["position"].setUnitDimension( detail::getUnitDimension("position") );
currSpecies["positionOffset"].setUnitDimension( detail::getUnitDimension("positionOffset") );
}
currSpecies["charge"].setUnitDimension( detail::getUnitDimension("charge") );
currSpecies["mass"].setUnitDimension( detail::getUnitDimension("mass") );

// meta data for ED-PIC extension
currSpecies["position"].setAttribute( "macroWeighted", 0u );
currSpecies["position"].setAttribute( "weightingPower", 0.0 );
currSpecies["positionOffset"].setAttribute( "macroWeighted", 0u );
currSpecies["positionOffset"].setAttribute( "weightingPower", 0.0 );
if (!positionComponents.empty()) {
currSpecies["position"].setAttribute( "macroWeighted", 0u );
currSpecies["position"].setAttribute( "weightingPower", 0.0 );
currSpecies["positionOffset"].setAttribute( "macroWeighted", 0u );
currSpecies["positionOffset"].setAttribute( "weightingPower", 0.0 );
}
currSpecies["id"].setAttribute( "macroWeighted", 0u );
currSpecies["id"].setAttribute( "weightingPower", 0.0 );
currSpecies["charge"].setAttribute( "macroWeighted", 0u );
Expand Down

0 comments on commit 5dfee18

Please sign in to comment.