Skip to content

Commit

Permalink
updated with changes in amrex/openpmd-io, bring setOpenPMDUnit() in w…
Browse files Browse the repository at this point in the history
…arpXWriter.H
  • Loading branch information
guj committed Feb 14, 2024
1 parent 72d1d67 commit eb65868
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
33 changes: 14 additions & 19 deletions Source/Diagnostics/FlushFormats/FlushFormatPlotPlus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void FlushFormatPlotPlus::BTDWriter(const std::string& prefix,
amrex::Vector<amrex::Geometry>& geom,
const double time,
const amrex::Vector<ParticleDiag>& particle_diags,
const bool use_pinned_pc,
const bool /*use_pinned_pc */,
bool isLastBTDFlush,
const amrex::Vector<int>& totalParticlesFlushedAlready
) const
Expand Down Expand Up @@ -161,8 +161,8 @@ void FlushFormatPlotPlus::BTDWriter(const std::string& prefix,
static_cast<Real>(time)
);
}

// write particles
//for (auto& part_diag : particle_diags) {
for (unsigned whichDiag = 0, n = particle_diags.size(); whichDiag < n; ++whichDiag)
{
const ParticleDiag& part_diag = particle_diags[whichDiag];
Expand All @@ -174,18 +174,17 @@ void FlushFormatPlotPlus::BTDWriter(const std::string& prefix,

CopyPtls(tmp, time, pc, pinned_pc, part_diag);

tmp.CountParticles();
tmp.CountParticles();

btdWriter -> AssignPtlOffset(totalParticlesFlushedAlready[whichDiag]);
btdWriter -> AssignPtlOffset(totalParticlesFlushedAlready[whichDiag]);

Vector<std::string> real_names;
Vector<std::string> int_names;
Vector<int> int_flags;
Vector<int> real_flags;
GetNames(part_diag, real_names, int_names, int_flags, real_flags);
Vector<std::string> real_names;
Vector<std::string> int_names;
Vector<int> int_flags;
Vector<int> real_flags;
GetNames(part_diag, real_names, int_names, int_flags, real_flags);

//m_Writer->WriteParticles(tmp, part_diag.getSpeciesName(), real_names, int_names, real_flags, int_flags,
m_Writer->m_UserHandler->m_Writer->DumpParticles(tmp,
m_Writer->m_UserHandler->m_Writer->DumpParticles(tmp,
part_diag.getSpeciesName(),
real_flags,
int_flags,
Expand All @@ -200,7 +199,6 @@ void FlushFormatPlotPlus::BTDWriter(const std::string& prefix,
btdWriter->SavePosId_RZ(pti, currSpecies, offset);
});

//openpmd_api::WriteParticles(tmp, part_diag.getSpeciesName(), real_names, int_names, real_flags, int_flags);
}
}

Expand Down Expand Up @@ -276,15 +274,13 @@ void FlushFormatPlotPlus::DefaultWriter(const std::string& prefix,
PinnedMemoryParticleContainer* pinned_pc = part_diag.getPinnedParticleContainer();
PinnedMemoryParticleContainer tmp;
if (use_pinned_pc) {
tmp = pinned_pc->make_alike<amrex::PinnedArenaAllocator>();

CopyPtls(tmp, time, pc, pinned_pc, part_diag);
tmp = pinned_pc->make_alike<amrex::PinnedArenaAllocator>();
CopyPtls(tmp, time, pc, pinned_pc, part_diag);
} else {
tmp = pc->make_alike<amrex::PinnedArenaAllocator>();
CopyPtls(tmp, time, pc, pc, part_diag);
tmp = pc->make_alike<amrex::PinnedArenaAllocator>();
CopyPtls(tmp, time, pc, pc, part_diag);
}


tmp.CountParticles();

Vector<std::string> real_names;
Expand All @@ -307,7 +303,6 @@ void FlushFormatPlotPlus::DefaultWriter(const std::string& prefix,
{
warpxWriter->SavePosId_RZ(pti, currSpecies, offset);
});

}
}

Expand Down
32 changes: 31 additions & 1 deletion Source/Diagnostics/FlushFormats/warpxWriter.H
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,39 @@ private:
std::vector<bool> m_fieldPMLdirections;

std::vector< std::string > getFieldAxisLabels ( const amrex::openpmd_api::AMReX_VarNameParser& varName ) const;
inline void setOpenPMDUnit ( openPMD::Mesh mesh, std::string const& field_name ) const;
};


inline void AMReX_warpxWriter::setOpenPMDUnit ( openPMD::Mesh mesh, std::string const& field_name ) const
{
if (field_name[0] == 'E'){ // Electric field
mesh.setUnitDimension({
{openPMD::UnitDimension::L, 1},
{openPMD::UnitDimension::M, 1},
{openPMD::UnitDimension::T, -3},
{openPMD::UnitDimension::I, -1},
});
} else if (field_name[0] == 'B'){ // Magnetic field
mesh.setUnitDimension({
{openPMD::UnitDimension::M, 1},
{openPMD::UnitDimension::I, -1},
{openPMD::UnitDimension::T, -2}
});
} else if (field_name[0] == 'j'){ // current
mesh.setUnitDimension({
{openPMD::UnitDimension::L, -2},
{openPMD::UnitDimension::I, 1},
});
} else if (field_name.substr(0,3) == "rho"){ // charge density
mesh.setUnitDimension({
{openPMD::UnitDimension::L, -3},
{openPMD::UnitDimension::I, 1},
{openPMD::UnitDimension::T, 1},
});
}
}

void AMReX_warpxWriter::SetupMeshComp (openPMD::Mesh& mesh,
const amrex::Geometry& full_geom,
amrex::MultiFab const& mf,
Expand Down Expand Up @@ -102,7 +132,7 @@ void AMReX_warpxWriter::SetupMeshComp (openPMD::Mesh& mesh,

mesh_comp.resetDataset(dataset);

amrex::openpmd_api::helper::setOpenPMDUnit( mesh, varName.m_FieldName );
setOpenPMDUnit( mesh, varName.m_FieldName );

auto relative_cell_pos = amrex::openpmd_api::helper::getRelativeCellPosition(mf); // AMReX Fortran index order
std::reverse( relative_cell_pos.begin(), relative_cell_pos.end() ); // now in C order
Expand Down

0 comments on commit eb65868

Please sign in to comment.