Skip to content

Commit

Permalink
Merge branch 'hackathon-field-register' of github.com:ax3l/WarpX into…
Browse files Browse the repository at this point in the history
… hackathon-field-register
  • Loading branch information
RemiLehe committed Sep 12, 2024
2 parents 088f413 + 92829f6 commit 27de140
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 122 deletions.
36 changes: 18 additions & 18 deletions Source/Diagnostics/FlushFormats/FlushFormatCheckpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ FlushFormatCheckpoint::WriteToFile (

if (WarpX::fft_do_time_averaging)
{
VisMF::Write(warpx.getField(FieldType::Efield_avg_fp, lev, 0),
VisMF::Write(*warpx.m_fields.get("Efield_avg_fp", Direction{0}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ex_avg_fp"));
VisMF::Write(warpx.getField(FieldType::Efield_avg_fp, lev, 1),
VisMF::Write(*warpx.m_fields.get("Efield_avg_fp", Direction{1}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ey_avg_fp"));
VisMF::Write(warpx.getField(FieldType::Efield_avg_fp, lev, 2),
VisMF::Write(*warpx.m_fields.get("Efield_avg_fp", Direction{2}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ez_avg_fp"));

VisMF::Write(warpx.getField(FieldType::Bfield_avg_fp, lev, 0),
VisMF::Write(*warpx.m_fields.get("Bfield_avg_fp", Direction{0}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Bx_avg_fp"));
VisMF::Write(warpx.getField(FieldType::Bfield_avg_fp, lev, 1),
VisMF::Write(*warpx.m_fields.get("Bfield_avg_fp", Direction{1}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "By_avg_fp"));
VisMF::Write(warpx.getField(FieldType::Bfield_avg_fp, lev, 2),
VisMF::Write(*warpx.m_fields.get("Bfield_avg_fp", Direction{2}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Bz_avg_fp"));
}

Expand All @@ -110,33 +110,33 @@ FlushFormatCheckpoint::WriteToFile (

if (lev > 0)
{
VisMF::Write(warpx.getField(FieldType::Efield_cp, lev, 0),
VisMF::Write(*warpx.m_fields.get("Efield_cp", Direction{0}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ex_cp"));
VisMF::Write(warpx.getField(FieldType::Efield_cp, lev, 1),
VisMF::Write(*warpx.m_fields.get("Efield_cp", Direction{1}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ey_cp"));
VisMF::Write(warpx.getField(FieldType::Efield_cp, lev, 2),
VisMF::Write(*warpx.m_fields.get("Efield_cp", Direction{2}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ez_cp"));
VisMF::Write(warpx.getField(FieldType::Bfield_cp, lev, 0),
VisMF::Write(*warpx.m_fields.get("Bfield_cp", Direction{0}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Bx_cp"));
VisMF::Write(warpx.getField(FieldType::Bfield_cp, lev, 1),
VisMF::Write(*warpx.m_fields.get("Bfield_cp", Direction{1}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "By_cp"));
VisMF::Write(warpx.getField(FieldType::Bfield_cp, lev, 2),
VisMF::Write(*warpx.m_fields.get("Bfield_cp", Direction{2}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Bz_cp"));

if (WarpX::fft_do_time_averaging)
{
VisMF::Write(warpx.getField(FieldType::Efield_avg_cp, lev, 0),
VisMF::Write(*warpx.m_fields.get("Efield_avg_cp", Direction{0}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ex_avg_cp"));
VisMF::Write(warpx.getField(FieldType::Efield_avg_cp, lev, 1),
VisMF::Write(*warpx.m_fields.get("Efield_avg_cp", Direction{1}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ey_avg_cp"));
VisMF::Write(warpx.getField(FieldType::Efield_avg_cp, lev, 2),
VisMF::Write(*warpx.m_fields.get("Efield_avg_cp", Direction{2}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Ez_avg_cp"));

VisMF::Write(warpx.getField(FieldType::Bfield_avg_cp, lev, 0),
VisMF::Write(*warpx.m_fields.get("Bfield_avg_cp", Direction{0}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Bx_avg_cp"));
VisMF::Write(warpx.getField(FieldType::Bfield_avg_cp, lev, 1),
VisMF::Write(*warpx.m_fields.get("Bfield_avg_cp", Direction{1}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "By_avg_cp"));
VisMF::Write(warpx.getField(FieldType::Bfield_avg_cp, lev, 2),
VisMF::Write(*warpx.m_fields.get("Bfield_avg_cp", Direction{2}, lev),
amrex::MultiFabFileFullPrefix(lev, checkpointname, default_level_prefix, "Bz_avg_cp"));
}

Expand Down
12 changes: 6 additions & 6 deletions Source/Diagnostics/FlushFormats/FlushFormatPlotfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,22 +615,22 @@ FlushFormatPlotfile::WriteAllRawFields(
// Averaged fields on fine patch
if (WarpX::fft_do_time_averaging)
{
WriteRawMF(warpx.getField(FieldType::Efield_avg_fp, lev, 0) , dm, raw_pltname, default_level_prefix,
WriteRawMF(*warpx.m_fields.get("Efield_avg_fp", Direction{0}, lev) , dm, raw_pltname, default_level_prefix,
"Ex_avg_fp", lev, plot_raw_fields_guards);

WriteRawMF(warpx.getField(FieldType::Efield_avg_fp, lev, 1) , dm, raw_pltname, default_level_prefix,
WriteRawMF(*warpx.m_fields.get("Efield_avg_fp", Direction{1}, lev) , dm, raw_pltname, default_level_prefix,
"Ey_avg_fp", lev, plot_raw_fields_guards);

WriteRawMF(warpx.getField(FieldType::Efield_avg_fp, lev, 2) , dm, raw_pltname, default_level_prefix,
WriteRawMF(*warpx.m_fields.get("Efield_avg_fp", Direction{2}, lev) , dm, raw_pltname, default_level_prefix,
"Ez_avg_fp", lev, plot_raw_fields_guards);

WriteRawMF(warpx.getField(FieldType::Bfield_avg_fp, lev, 0) , dm, raw_pltname, default_level_prefix,
WriteRawMF(*warpx.m_fields.get("Bfield_avg_fp", Direction{0}, lev) , dm, raw_pltname, default_level_prefix,
"Bx_avg_fp", lev, plot_raw_fields_guards);

WriteRawMF(warpx.getField(FieldType::Bfield_avg_fp, lev, 1) , dm, raw_pltname, default_level_prefix,
WriteRawMF(*warpx.m_fields.get("Bfield_avg_fp", Direction{1}, lev) , dm, raw_pltname, default_level_prefix,
"By_avg_fp", lev, plot_raw_fields_guards);

WriteRawMF(warpx.getField(FieldType::Bfield_avg_fp, lev, 2) , dm, raw_pltname, default_level_prefix,
WriteRawMF(*warpx.m_fields.get("Bfield_avg_fp", Direction{2}, lev) , dm, raw_pltname, default_level_prefix,
"Bz_avg_fp", lev, plot_raw_fields_guards);
}

Expand Down
20 changes: 4 additions & 16 deletions Source/FieldSolver/Fields.H
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,14 @@ namespace warpx::fields
None,
Efield_fp,
Bfield_fp,
current_fp,
current_fp_nodal,
phi_fp,
vector_potential_fp,
Efield_cp,
Bfield_cp,
current_cp,
edge_lengths,
face_areas,
Efield_avg_fp,
Bfield_avg_fp,
Efield_avg_cp,
Bfield_avg_cp
phi_fp
};

constexpr FieldType ArrayFieldTypes[] = {
FieldType::Efield_fp, FieldType::Bfield_fp,
FieldType::current_fp, FieldType::current_fp_nodal, FieldType::vector_potential_fp,
FieldType::Efield_cp, FieldType::Bfield_cp, FieldType::current_cp,
FieldType::Efield_avg_fp, FieldType::Bfield_avg_fp, FieldType::Efield_avg_cp, FieldType::Bfield_avg_cp};
FieldType::Efield_fp,
FieldType::Bfield_fp,
FieldType::vector_potential_fp };

inline bool
isFieldArray (const FieldType field_type)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,10 @@ void HybridPICModel::InitData ()
auto edge_lengths = std::array<std::unique_ptr<amrex::MultiFab>, 3>();
#ifdef AMREX_USE_EB
if (EB::enabled()) {
auto const & edge_lengths_x = warpx.getField(FieldType::edge_lengths, lev, 0);
auto const & edge_lengths_y = warpx.getField(FieldType::edge_lengths, lev, 1);
auto const & edge_lengths_z = warpx.getField(FieldType::edge_lengths, lev, 2);
using ablastr::fields::Direction;
auto const & edge_lengths_x = *warpx.m_fields.get("edge_lengths", Direction{0}, lev);
auto const & edge_lengths_y = *warpx.m_fields.get("edge_lengths", Direction{1}, lev);
auto const & edge_lengths_z = *warpx.m_fields.get("edge_lengths", Direction{2}, lev);

edge_lengths = std::array< std::unique_ptr<amrex::MultiFab>, 3 >{
std::make_unique<amrex::MultiFab>(
Expand Down
44 changes: 2 additions & 42 deletions Source/WarpX.H
Original file line number Diff line number Diff line change
Expand Up @@ -460,45 +460,19 @@ public:
static std::map<std::string, amrex::MultiFab *> multifab_map;
static std::map<std::string, amrex::iMultiFab *> imultifab_map;

/**
* \brief
* Get a pointer to the field data.
*
* \param field_type[in] the field type
* \param lev[in] the mesh refinement level
* \param direction[in] the field component (0 by default)
*
* \return the pointer to an amrex::MultiFab containing the field data
*/
[[nodiscard]] amrex::MultiFab*
getFieldPointer (warpx::fields::FieldType field_type, int lev, int direction = 0) const;

/**
* \brief
* Get a constant reference to the field data.
*
* \param field_type[in] the field type
* \param lev[in] the mesh refinement level
* \param direction[in] the field component (0 by default)
*
* \return a constant refernce to an amrex::MultiFab containing the field data
*/
[[nodiscard]] const amrex::MultiFab&
getField(warpx::fields::FieldType field_type, int lev, int direction = 0) const;

/**
* \brief
* Get pointer to the amrex::MultiFab containing the dotMask for the specified field
*/
[[nodiscard]] const amrex::iMultiFab*
getFieldDotMaskPointer (warpx::fields::FieldType field_type, int lev, int dir);
getFieldDotMaskPointer (warpx::fields::FieldType field_type, int lev, int dir) const;

/**
* \brief
* Set the dotMask container
*/
void SetDotMask( std::unique_ptr<amrex::iMultiFab>& field_dotMask,
std::string field_name, int lev, int dir );
std::string field_name, int lev, int dir ) const;

[[nodiscard]] bool DoPML () const {return do_pml;}
[[nodiscard]] bool DoFluidSpecies () const {return do_fluid_species;}
Expand Down Expand Up @@ -1489,20 +1463,6 @@ private:
amrex::Vector<std::unique_ptr<amrex::iMultiFab> > current_buffer_masks;
amrex::Vector<std::unique_ptr<amrex::iMultiFab> > gather_buffer_masks;

/**
* \brief
* Get a pointer to the field data. Does not check if the pointer
* is not nullptr.
*
* \param field_type[in] the field type
* \param lev[in] the mesh refinement level
* \param direction[in] the field component (0 by default)
*
* \return the pointer to an amrex::MultiFab containing the field data
*/
[[nodiscard]] amrex::MultiFab*
getFieldPointerUnchecked (warpx::fields::FieldType field_type, int lev, int direction = 0) const;

// PML
int do_pml = 0;
int do_silver_mueller = 0;
Expand Down
40 changes: 3 additions & 37 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3430,40 +3430,6 @@ WarpX::AliasInitMultiFab (
multifab_map[name_with_suffix] = mf.get();
}

amrex::MultiFab*
WarpX::getFieldPointerUnchecked (const FieldType field_type, const int lev, const int direction) const
{
// This function does *not* check if the returned field pointer is != nullptr

amrex::MultiFab* field_pointer = nullptr;

amrex::ignore_unused(lev, direction);

switch(field_type)
{
default:
WARPX_ABORT_WITH_MESSAGE("Invalid field type");
break;
}

return field_pointer;
}

amrex::MultiFab*
WarpX::getFieldPointer (const FieldType field_type, const int lev, const int direction) const
{
auto* const field_pointer = getFieldPointerUnchecked(field_type, lev, direction);
WARPX_ALWAYS_ASSERT_WITH_MESSAGE(
field_pointer != nullptr, "Requested field is not initialized!");
return field_pointer;
}

const amrex::MultiFab&
WarpX::getField(FieldType field_type, const int lev, const int direction) const
{
return *getFieldPointer(field_type, lev, direction);
}

amrex::DistributionMapping
WarpX::MakeDistributionMap (int lev, amrex::BoxArray const& ba)
{
Expand Down Expand Up @@ -3491,7 +3457,7 @@ WarpX::MakeDistributionMap (int lev, amrex::BoxArray const& ba)
}

const amrex::iMultiFab*
WarpX::getFieldDotMaskPointer ( FieldType field_type, int lev, int dir )
WarpX::getFieldDotMaskPointer ( FieldType field_type, int lev, int dir ) const
{
switch(field_type)
{
Expand All @@ -3514,13 +3480,13 @@ WarpX::getFieldDotMaskPointer ( FieldType field_type, int lev, int dir )
}

void WarpX::SetDotMask( std::unique_ptr<amrex::iMultiFab>& field_dotMask,
std::string field_name, int lev, int dir )
std::string field_name, int lev, int dir ) const
{
// Define the dot mask for this field_type needed to properly compute dotProduct()
// for field values that have shared locations on different MPI ranks
if (field_dotMask != nullptr) { return; }

ablastr::fields::VectorField const& this_field = m_fields.get_alldirs(field_name,lev);
ablastr::fields::ConstVectorField const& this_field = m_fields.get_alldirs(field_name,lev);
const amrex::BoxArray& this_ba = this_field[dir]->boxArray();
const amrex::MultiFab tmp( this_ba, this_field[dir]->DistributionMap(),
1, 0, amrex::MFInfo().SetAlloc(false) );
Expand Down

0 comments on commit 27de140

Please sign in to comment.