Skip to content

Commit

Permalink
fix double counting of E-field in relativistic solves
Browse files Browse the repository at this point in the history
  • Loading branch information
roelof-groenewald committed Sep 11, 2024
1 parent 2a08c8c commit ad79681
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
51 changes: 27 additions & 24 deletions Source/FieldSolver/ElectrostaticSolvers/ElectrostaticSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,35 +137,38 @@ ElectrostaticSolver::computePhi (const amrex::Vector<std::unique_ptr<amrex::Mult
auto & warpx = WarpX::GetInstance();
if (EB::enabled())
{
// EB: use AMReX to directly calculate the electric field since with EB's the
// simple finite difference scheme in WarpX::computeE sometimes fails

// TODO: maybe make this a helper function or pass Efield_fp directly
amrex::Vector<
amrex::Array<amrex::MultiFab *, AMREX_SPACEDIM>
> e_field;
for (int lev = 0; lev < num_levels; ++lev) {
e_field.push_back(
if (WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrame ||
WarpX::electrostatic_solver_id == ElectrostaticSolverAlgo::LabFrameElectroMagnetostatic)
{
// EB: use AMReX to directly calculate the electric field since with EB's the
// simple finite difference scheme in WarpX::computeE sometimes fails

// TODO: maybe make this a helper function or pass Efield_fp directly
amrex::Vector<
amrex::Array<amrex::MultiFab *, AMREX_SPACEDIM>
> e_field;
for (int lev = 0; lev < num_levels; ++lev) {
e_field.push_back(
#if defined(WARPX_DIM_1D_Z)
amrex::Array<amrex::MultiFab*, 1>{
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2)
}
amrex::Array<amrex::MultiFab*, 1>{
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2)
}
#elif defined(WARPX_DIM_XZ) || defined(WARPX_DIM_RZ)
amrex::Array<amrex::MultiFab*, 2>{
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 0),
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2)
}
amrex::Array<amrex::MultiFab*, 2>{
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 0),
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2)
}
#elif defined(WARPX_DIM_3D)
amrex::Array<amrex::MultiFab *, 3>{
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 0),
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 1),
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2)
}
amrex::Array<amrex::MultiFab *, 3>{
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 0),
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 1),
warpx.getFieldPointer(warpx::fields::FieldType::Efield_fp, lev, 2)
}
#endif
);
);
}
post_phi_calculation = EBCalcEfromPhiPerLevel(e_field);
}
post_phi_calculation = EBCalcEfromPhiPerLevel(e_field);

#ifdef AMREX_USE_EB
amrex::Vector<
amrex::EBFArrayBoxFactory const *
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ RelativisticExplicitES::ComputeSpaceChargeField (
// Note that the fields calculated here does not include the E field
// due to simulation boundary potentials
for (auto const& species : mpc) {
if ((species->initialize_self_fields) || always_run_solve) {
if (always_run_solve || (species->initialize_self_fields)) {
AddSpaceChargeField(charge_buf, *species.get(), Efield_fp, Bfield_fp);
}
}

// Add the field due to the boundary potentials
if ((m_poisson_boundary_handler->m_boundary_potential_specified)
|| always_run_solve) {
if (always_run_solve || (m_poisson_boundary_handler->m_boundary_potential_specified))
{
AddBoundaryField(Efield_fp);
}
}
Expand Down

0 comments on commit ad79681

Please sign in to comment.