Skip to content

Commit

Permalink
Fixed a bug where centering coefficients used in Magentostatic solver…
Browse files Browse the repository at this point in the history
… were not being initialized when doing an energy-conserving field gather.

Signed-off-by: S. Eric Clark <[email protected]>
  • Loading branch information
clarkse committed Sep 24, 2024
1 parent 0337ee1 commit 4535779
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
15 changes: 7 additions & 8 deletions Source/FieldSolver/MagnetostaticSolver/MagnetostaticSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,15 +170,14 @@ WarpX::computeVectorPotential (ablastr::fields::MultiLevelVectorField const& cur
amrex::Vector<amrex::Array<amrex::MultiFab*,3>> sorted_curr;
amrex::Vector<amrex::Array<amrex::MultiFab*,3>> sorted_A;
for (int lev = 0; lev <= finest_level; ++lev) {
sorted_curr.emplace_back(amrex::Array<amrex::MultiFab*,3> ({curr[lev][Direction{0}],
curr[lev][Direction{1}],
curr[lev][Direction{2}]}));
sorted_A.emplace_back(amrex::Array<amrex::MultiFab*,3> ({A[lev][Direction{0}],
A[lev][Direction{1}],
A[lev][Direction{2}]}));
sorted_curr.emplace_back(amrex::Array<amrex::MultiFab*,3> ({curr[lev][0].get(),
curr[lev][1].get(),
curr[lev][2].get()}));
sorted_A.emplace_back(amrex::Array<amrex::MultiFab*,3> ({A[lev][0].get(),
A[lev][1].get(),
A[lev][2].get()}));
}

#if defined(AMREX_USE_EB)
const ablastr::fields::MultiLevelVectorField Bfield_fp = m_fields.get_mr_levels_alldirs(FieldType::Bfield_fp, finest_level);
const std::optional<MagnetostaticSolver::EBCalcBfromVectorPotentialPerLevel> post_A_calculation(
{
Expand All @@ -187,13 +186,13 @@ WarpX::computeVectorPotential (ablastr::fields::MultiLevelVectorField const& cur
m_fields.get_mr_levels_alldirs(FieldType::vector_potential_grad_buf_b_stag, finest_level)
});

#if defined(AMREX_USE_EB)
amrex::Vector<amrex::EBFArrayBoxFactory const *> factories;
for (int lev = 0; lev <= finest_level; ++lev) {
factories.push_back(&WarpX::fieldEBFactory(lev));
}
const std::optional<amrex::Vector<amrex::EBFArrayBoxFactory const *> > eb_farray_box_factory({factories});
#else
const std::optional<MagnetostaticSolver::EBCalcBfromVectorPotentialPerLevel> post_A_calculation;
const std::optional<amrex::Vector<amrex::FArrayBoxFactory const *> > eb_farray_box_factory;
#endif

Expand Down
5 changes: 3 additions & 2 deletions Source/WarpX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1388,8 +1388,9 @@ WarpX::ReadParameters ()
// Instead, if warpx.grid_type=collocated, the momentum-conserving and
// energy conserving field gathering algorithms are equivalent (forces
// gathered from the collocated grid) and no fields centering occurs.
if (WarpX::field_gathering_algo == GatheringAlgo::MomentumConserving &&
WarpX::grid_type != GridType::Collocated)
if ((WarpX::field_gathering_algo == GatheringAlgo::MomentumConserving
&& WarpX::grid_type != GridType::Collocated)
|| WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic)
{
utils::parser::queryWithParser(
pp_warpx, "field_centering_nox", field_centering_nox);
Expand Down

0 comments on commit 4535779

Please sign in to comment.