Skip to content

Commit

Permalink
Use FieldType Instead of Strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Sep 21, 2024
1 parent 09fd65f commit 9279342
Show file tree
Hide file tree
Showing 55 changed files with 1,346 additions and 1,247 deletions.
150 changes: 75 additions & 75 deletions Source/BoundaryConditions/PML.cpp

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions Source/BoundaryConditions/PML_RZ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <memory>

using namespace amrex::literals;
using namespace warpx::fields;
using warpx::fields::FieldType;
using ablastr::fields::Direction;

PML_RZ::PML_RZ (int lev, amrex::BoxArray const& grid_ba, amrex::DistributionMapping const& grid_dm,
Expand All @@ -48,22 +48,22 @@ PML_RZ::PML_RZ (int lev, amrex::BoxArray const& grid_ba, amrex::DistributionMapp
bool const remake = false;
bool const redistribute_on_remake = false;

amrex::MultiFab const& Er_fp = *warpx.m_fields.get("Efield_fp",Direction{0},lev);
amrex::MultiFab const& Et_fp = *warpx.m_fields.get("Efield_fp",Direction{1},lev);
amrex::MultiFab const& Er_fp = *warpx.m_fields.get(FieldType::Efield_fp,Direction{0},lev);
amrex::MultiFab const& Et_fp = *warpx.m_fields.get(FieldType::Efield_fp,Direction{1},lev);
amrex::BoxArray const ba_Er = amrex::convert(grid_ba, Er_fp.ixType().toIntVect());
amrex::BoxArray const ba_Et = amrex::convert(grid_ba, Et_fp.ixType().toIntVect());
warpx.m_fields.alloc_init("pml_E_fp", Direction{0}, lev, ba_Er, grid_dm, Er_fp.nComp(), Er_fp.nGrowVect(), 0.0_rt,
warpx.m_fields.alloc_init(FieldType::pml_E_fp, Direction{0}, lev, ba_Er, grid_dm, Er_fp.nComp(), Er_fp.nGrowVect(), 0.0_rt,
remake, redistribute_on_remake);
warpx.m_fields.alloc_init("pml_E_fp", Direction{1}, lev, ba_Et, grid_dm, Et_fp.nComp(), Et_fp.nGrowVect(), 0.0_rt,
warpx.m_fields.alloc_init(FieldType::pml_E_fp, Direction{1}, lev, ba_Et, grid_dm, Et_fp.nComp(), Et_fp.nGrowVect(), 0.0_rt,
remake, redistribute_on_remake);

amrex::MultiFab const& Br_fp = *warpx.m_fields.get("Bfield_fp",Direction{0},lev);
amrex::MultiFab const& Bt_fp = *warpx.m_fields.get("Bfield_fp",Direction{1},lev);
amrex::MultiFab const& Br_fp = *warpx.m_fields.get(FieldType::Bfield_fp,Direction{0},lev);
amrex::MultiFab const& Bt_fp = *warpx.m_fields.get(FieldType::Bfield_fp,Direction{1},lev);
amrex::BoxArray const ba_Br = amrex::convert(grid_ba, Br_fp.ixType().toIntVect());
amrex::BoxArray const ba_Bt = amrex::convert(grid_ba, Bt_fp.ixType().toIntVect());
warpx.m_fields.alloc_init("pml_B_fp", Direction{0}, lev, ba_Br, grid_dm, Br_fp.nComp(), Br_fp.nGrowVect(), 0.0_rt,
warpx.m_fields.alloc_init(FieldType::pml_B_fp, Direction{0}, lev, ba_Br, grid_dm, Br_fp.nComp(), Br_fp.nGrowVect(), 0.0_rt,
remake, redistribute_on_remake);
warpx.m_fields.alloc_init("pml_B_fp", Direction{1}, lev, ba_Bt, grid_dm, Bt_fp.nComp(), Bt_fp.nGrowVect(), 0.0_rt,
warpx.m_fields.alloc_init(FieldType::pml_B_fp, Direction{1}, lev, ba_Bt, grid_dm, Bt_fp.nComp(), Bt_fp.nGrowVect(), 0.0_rt,
remake, redistribute_on_remake);

}
Expand All @@ -77,8 +77,8 @@ PML_RZ::ApplyDamping (amrex::MultiFab* Et_fp, amrex::MultiFab* Ez_fp,
amrex::Real const dr = m_geom->CellSize(0);
amrex::Real const cdt_over_dr = PhysConst::c*dt/dr;

amrex::MultiFab* pml_Et = fields.get("pml_E_fp", Direction{1}, 0);
amrex::MultiFab* pml_Bt = fields.get("pml_B_fp", Direction{1}, 0);
amrex::MultiFab* pml_Et = fields.get(FieldType::pml_E_fp, Direction{1}, 0);
amrex::MultiFab* pml_Bt = fields.get(FieldType::pml_B_fp, Direction{1}, 0);

#ifdef AMREX_USE_OMP
#pragma omp parallel if (amrex::Gpu::notInLaunchRegion())
Expand Down Expand Up @@ -132,8 +132,8 @@ PML_RZ::ApplyDamping (amrex::MultiFab* Et_fp, amrex::MultiFab* Ez_fp,
void
PML_RZ::FillBoundaryE (ablastr::fields::MultiFabRegister& fields, PatchType patch_type, std::optional<bool> nodal_sync)
{
amrex::MultiFab * pml_Er = fields.get("pml_E_fp", Direction{0}, 0);
amrex::MultiFab * pml_Et = fields.get("pml_E_fp", Direction{1}, 0);
amrex::MultiFab * pml_Er = fields.get(FieldType::pml_E_fp, Direction{0}, 0);
amrex::MultiFab * pml_Et = fields.get(FieldType::pml_E_fp, Direction{1}, 0);

if (patch_type == PatchType::fine && pml_Er->nGrowVect().max() > 0)
{
Expand All @@ -148,8 +148,8 @@ PML_RZ::FillBoundaryB (ablastr::fields::MultiFabRegister& fields, PatchType patc
{
if (patch_type == PatchType::fine)
{
amrex::MultiFab * pml_Br = fields.get("pml_B_fp", Direction{0}, 0);
amrex::MultiFab * pml_Bt = fields.get("pml_B_fp", Direction{1}, 0);
amrex::MultiFab * pml_Br = fields.get(FieldType::pml_B_fp, Direction{0}, 0);
amrex::MultiFab * pml_Bt = fields.get(FieldType::pml_B_fp, Direction{1}, 0);

amrex::Periodicity const& period = m_geom->periodicity();
const amrex::Vector<amrex::MultiFab*> mf = {pml_Br, pml_Bt};
Expand All @@ -160,22 +160,22 @@ PML_RZ::FillBoundaryB (ablastr::fields::MultiFabRegister& fields, PatchType patc
void
PML_RZ::CheckPoint (ablastr::fields::MultiFabRegister& fields, std::string const& dir) const
{
if (fields.has("pml_E_fp", Direction{0}, 0)) {
amrex::VisMF::AsyncWrite(*fields.get("pml_E_fp", Direction{0}, 0), dir+"_Er_fp");
amrex::VisMF::AsyncWrite(*fields.get("pml_E_fp", Direction{1}, 0), dir+"_Et_fp");
amrex::VisMF::AsyncWrite(*fields.get("pml_B_fp", Direction{0}, 0), dir+"_Br_fp");
amrex::VisMF::AsyncWrite(*fields.get("pml_B_fp", Direction{1}, 0), dir+"_Bt_fp");
if (fields.has(FieldType::pml_E_fp, Direction{0}, 0)) {
amrex::VisMF::AsyncWrite(*fields.get(FieldType::pml_E_fp, Direction{0}, 0), dir+"_Er_fp");
amrex::VisMF::AsyncWrite(*fields.get(FieldType::pml_E_fp, Direction{1}, 0), dir+"_Et_fp");
amrex::VisMF::AsyncWrite(*fields.get(FieldType::pml_B_fp, Direction{0}, 0), dir+"_Br_fp");
amrex::VisMF::AsyncWrite(*fields.get(FieldType::pml_B_fp, Direction{1}, 0), dir+"_Bt_fp");
}
}

void
PML_RZ::Restart (ablastr::fields::MultiFabRegister& fields, std::string const& dir)
{
if (fields.has("pml_E_fp", Direction{0}, 0)) {
amrex::VisMF::Read(*fields.get("pml_E_fp", Direction{0}, 0), dir+"_Er_fp");
amrex::VisMF::Read(*fields.get("pml_E_fp", Direction{1}, 0), dir+"_Et_fp");
amrex::VisMF::Read(*fields.get("pml_B_fp", Direction{0}, 0), dir+"_Br_fp");
amrex::VisMF::Read(*fields.get("pml_B_fp", Direction{1}, 0), dir+"_Bt_fp");
if (fields.has(FieldType::pml_E_fp, Direction{0}, 0)) {
amrex::VisMF::Read(*fields.get(FieldType::pml_E_fp, Direction{0}, 0), dir+"_Er_fp");
amrex::VisMF::Read(*fields.get(FieldType::pml_E_fp, Direction{1}, 0), dir+"_Et_fp");
amrex::VisMF::Read(*fields.get(FieldType::pml_B_fp, Direction{0}, 0), dir+"_Br_fp");
amrex::VisMF::Read(*fields.get(FieldType::pml_B_fp, Direction{1}, 0), dir+"_Bt_fp");
}
}

Expand All @@ -196,10 +196,10 @@ PML_RZ::PushPMLPSATDSinglePatchRZ (
ablastr::fields::MultiFabRegister& fields)
{
SpectralFieldIndex const& Idx = solver.m_spectral_index;
amrex::MultiFab * pml_Er = fields.get("pml_E_fp", Direction{0}, 0);
amrex::MultiFab * pml_Et = fields.get("pml_E_fp", Direction{1}, 0);
amrex::MultiFab * pml_Br = fields.get("pml_B_fp", Direction{0}, 0);
amrex::MultiFab * pml_Bt = fields.get("pml_B_fp", Direction{1}, 0);
amrex::MultiFab * pml_Er = fields.get(FieldType::pml_E_fp, Direction{0}, 0);
amrex::MultiFab * pml_Et = fields.get(FieldType::pml_E_fp, Direction{1}, 0);
amrex::MultiFab * pml_Br = fields.get(FieldType::pml_B_fp, Direction{0}, 0);
amrex::MultiFab * pml_Bt = fields.get(FieldType::pml_B_fp, Direction{1}, 0);

// Perform forward Fourier transforms
solver.ForwardTransform(lev, *pml_Er, Idx.Er_pml, *pml_Et, Idx.Et_pml);
Expand Down
37 changes: 21 additions & 16 deletions Source/BoundaryConditions/WarpXEvolvePML.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# include "BoundaryConditions/PML_RZ.H"
#endif
#include "EmbeddedBoundary/Enabled.H"
#include "Fields.H"
#include "PML_current.H"
#include "Utils/WarpXProfilerWrapper.H"
#include "WarpX_PML_kernels.H"
Expand Down Expand Up @@ -66,10 +67,11 @@ WarpX::DampPML (const int lev, PatchType patch_type)
#if (defined WARPX_DIM_RZ) && (defined WARPX_USE_FFT)
if (pml_rz[lev]) {
using ablastr::fields::Direction;
pml_rz[lev]->ApplyDamping( m_fields.get("Efield_fp",Direction{1},lev),
m_fields.get("Efield_fp",Direction{2},lev),
m_fields.get("Bfield_fp",Direction{1},lev),
m_fields.get("Bfield_fp",Direction{2},lev),
using warpx::fields::FieldType;
pml_rz[lev]->ApplyDamping( m_fields.get(FieldType::Efield_fp,Direction{1},lev),
m_fields.get(FieldType::Efield_fp,Direction{2},lev),
m_fields.get(FieldType::Bfield_fp,Direction{1},lev),
m_fields.get(FieldType::Bfield_fp,Direction{2},lev),
dt[lev], m_fields);
}
#endif
Expand All @@ -86,8 +88,10 @@ WarpX::DampPML_Cartesian (const int lev, PatchType patch_type)

if (pml[lev]->ok())
{
const auto& pml_E = (patch_type == PatchType::fine) ? m_fields.get_alldirs("pml_E_fp", lev) : m_fields.get_alldirs("pml_E_cp", lev);
const auto& pml_B = (patch_type == PatchType::fine) ? m_fields.get_alldirs("pml_B_fp", lev) : m_fields.get_alldirs("pml_B_cp", lev);
using warpx::fields::FieldType;

const auto& pml_E = (patch_type == PatchType::fine) ? m_fields.get_alldirs(FieldType::pml_E_fp, lev) : m_fields.get_alldirs(FieldType::pml_E_cp, lev);
const auto& pml_B = (patch_type == PatchType::fine) ? m_fields.get_alldirs(FieldType::pml_B_fp, lev) : m_fields.get_alldirs(FieldType::pml_B_cp, lev);
const auto& sigba = (patch_type == PatchType::fine) ? pml[lev]->GetMultiSigmaBox_fp() : pml[lev]->GetMultiSigmaBox_cp();

const amrex::IntVect Ex_stag = pml_E[0]->ixType().toIntVect();
Expand All @@ -99,16 +103,16 @@ WarpX::DampPML_Cartesian (const int lev, PatchType patch_type)
const amrex::IntVect Bz_stag = pml_B[2]->ixType().toIntVect();

amrex::IntVect F_stag;
if (m_fields.has("pml_F_fp", lev)) {
if (m_fields.has(FieldType::pml_F_fp, lev)) {
amrex::MultiFab* pml_F = (patch_type == PatchType::fine) ?
m_fields.get("pml_F_fp", lev) : m_fields.get("pml_F_cp", lev);
m_fields.get(FieldType::pml_F_fp, lev) : m_fields.get(FieldType::pml_F_cp, lev);
F_stag = pml_F->ixType().toIntVect();
}

amrex::IntVect G_stag;
if (m_fields.has("pml_G_fp", lev)) {
if (m_fields.has(FieldType::pml_G_fp, lev)) {
amrex::MultiFab* pml_G = (patch_type == PatchType::fine) ?
m_fields.get("pml_G_fp", lev) : m_fields.get("pml_G_cp", lev);
m_fields.get(FieldType::pml_G_fp, lev) : m_fields.get(FieldType::pml_G_cp, lev);
G_stag = pml_G->ixType().toIntVect();
}

Expand Down Expand Up @@ -199,9 +203,9 @@ WarpX::DampPML_Cartesian (const int lev, PatchType patch_type)
// For warpx_damp_pml_F(), mfi.nodaltilebox is used in the ParallelFor loop and here we
// use mfi.tilebox. However, it does not matter because in damp_pml, where nodaltilebox
// is used, only a simple multiplication is performed.
if (m_fields.has("pml_F_fp", lev)) {
if (m_fields.has(FieldType::pml_F_fp, lev)) {
amrex::MultiFab* pml_F = (patch_type == PatchType::fine) ?
m_fields.get("pml_F_fp", lev) : m_fields.get("pml_F_cp", lev);
m_fields.get(FieldType::pml_F_fp, lev) : m_fields.get(FieldType::pml_F_cp, lev);
const Box& tnd = mfi.nodaltilebox();
auto const& pml_F_fab = pml_F->array(mfi);
amrex::ParallelFor(tnd, [=] AMREX_GPU_DEVICE (int i, int j, int k)
Expand All @@ -212,9 +216,9 @@ WarpX::DampPML_Cartesian (const int lev, PatchType patch_type)
}

// Damp G when WarpX::do_divb_cleaning = true
if (m_fields.has("pml_G_fp", lev)) {
if (m_fields.has(FieldType::pml_G_fp, lev)) {
amrex::MultiFab* pml_G = (patch_type == PatchType::fine) ?
m_fields.get("pml_G_fp", lev) : m_fields.get("pml_G_cp", lev);
m_fields.get(FieldType::pml_G_fp, lev) : m_fields.get(FieldType::pml_G_cp, lev);

const Box& tb = mfi.tilebox(G_stag);
auto const& pml_G_fab = pml_G->array(mfi);
Expand Down Expand Up @@ -254,8 +258,9 @@ WarpX::DampJPML (int lev, PatchType patch_type)

if (pml[lev]->ok())
{
using warpx::fields::FieldType;

const auto& pml_j = (patch_type == PatchType::fine) ? m_fields.get_alldirs("pml_j_fp", lev) : m_fields.get_alldirs("pml_j_cp", lev);
const auto& pml_j = (patch_type == PatchType::fine) ? m_fields.get_alldirs(FieldType::pml_j_fp, lev) : m_fields.get_alldirs(FieldType::pml_j_cp, lev);
const auto& sigba = (patch_type == PatchType::fine) ? pml[lev]->GetMultiSigmaBox_fp()
: pml[lev]->GetMultiSigmaBox_cp();

Expand Down Expand Up @@ -284,7 +289,7 @@ WarpX::DampJPML (int lev, PatchType patch_type)
// Skip the field update if this gridpoint is inside the embedded boundary
amrex::Array4<amrex::Real> eb_lxfab, eb_lyfab, eb_lzfab;
if (EB::enabled()) {
const auto &pml_edge_lenghts = m_fields.get_alldirs("pml_edge_lengths", lev);
const auto &pml_edge_lenghts = m_fields.get_alldirs(FieldType::pml_edge_lengths, lev);

eb_lxfab = pml_edge_lenghts[0]->array(mfi);
eb_lyfab = pml_edge_lenghts[1]->array(mfi);
Expand Down
Loading

0 comments on commit 9279342

Please sign in to comment.