Skip to content

Commit

Permalink
Split Bfield advance in two for SemiImplicit_EM evolve (#5483)
Browse files Browse the repository at this point in the history
This PR splits the BField advance for the SemiImplicit_EM evolve scheme
into two half dt advances, consistent with the explicit evolve scheme.
This makes it such that the B field at write time is at the same
instance in time as the electric field, as stated in the documentation.
  • Loading branch information
JustinRayAngus authored Nov 25, 2024
1 parent 4739e10 commit a1a677e
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"lev=0": {
"Bx": 3559.0541122456157,
"By": 1685.942868827529,
"Bx": 3625.566538877196,
"By": 1684.1769211109035,
"Bz": 0.0,
"Ex": 796541204346.5195,
"Ey": 961740397927.6577,
Expand Down
12 changes: 8 additions & 4 deletions Source/FieldSolver/ImplicitSolvers/SemiImplicitEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void SemiImplicitEM::OneStep ( amrex::Real a_time,
// Set the member time step
m_dt = a_dt;

// Fields have Eg^{n}, Bg^{n-1/2}
// Fields have Eg^{n}, Bg^{n}
// Particles have up^{n} and xp^{n}.

// Save up and xp at the start of the time step
Expand All @@ -70,9 +70,9 @@ void SemiImplicitEM::OneStep ( amrex::Real a_time,
// Save Eg at the start of the time step
m_Eold.Copy( FieldType::Efield_fp );

// Advance WarpX owned Bfield_fp to t_{n+1/2}
m_WarpX->EvolveB(m_dt, DtType::Full);
m_WarpX->ApplyMagneticFieldBCs();
// Advance WarpX owned Bfield_fp from t_{n} to t_{n+1/2}
m_WarpX->EvolveB(0.5_rt*m_dt, DtType::FirstHalf);
m_WarpX->FillBoundaryB(m_WarpX->getngEB(), true);

const amrex::Real half_time = a_time + 0.5_rt*m_dt;

Expand All @@ -92,6 +92,10 @@ void SemiImplicitEM::OneStep ( amrex::Real a_time,
m_E.linComb( 2._rt, m_E, -1._rt, m_Eold );
m_WarpX->SetElectricFieldAndApplyBCs( m_E );

// Advance WarpX owned Bfield_fp from t_{n+1/2} to t_{n+1}
m_WarpX->EvolveB(0.5_rt*m_dt, DtType::SecondHalf);
m_WarpX->FillBoundaryB(m_WarpX->getngEB(), true);

}

void SemiImplicitEM::ComputeRHS ( WarpXSolverVec& a_RHS,
Expand Down
10 changes: 2 additions & 8 deletions Source/FieldSolver/ImplicitSolvers/WarpXImplicitOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ WarpX::UpdateMagneticFieldAndApplyBCs( ablastr::fields::MultiLevelVectorField co
amrex::MultiFab::Copy(*Bfp[2], *a_Bn[lev][2], 0, 0, ncomps, a_Bn[lev][2]->nGrowVect());
}
EvolveB(a_thetadt, DtType::Full);
ApplyMagneticFieldBCs();
FillBoundaryB(guard_cells.ng_alloc_EB, WarpX::sync_nodal_points);
}

void
Expand All @@ -111,14 +111,8 @@ WarpX::FinishMagneticFieldAndApplyBCs( ablastr::fields::MultiLevelVectorField co
using warpx::fields::FieldType;

FinishImplicitField(m_fields.get_mr_levels_alldirs(FieldType::Bfield_fp, 0), a_Bn, a_theta);
ApplyMagneticFieldBCs();
}

void
WarpX::ApplyMagneticFieldBCs()
{
FillBoundaryB(guard_cells.ng_alloc_EB, WarpX::sync_nodal_points);
ApplyBfieldBoundary(0, PatchType::fine, DtType::Full);
FillBoundaryB(guard_cells.ng_alloc_EB, WarpX::sync_nodal_points);
}

void
Expand Down
1 change: 0 additions & 1 deletion Source/WarpX.H
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ public:
void SetElectricFieldAndApplyBCs ( const WarpXSolverVec& a_E );
void UpdateMagneticFieldAndApplyBCs ( ablastr::fields::MultiLevelVectorField const& a_Bn,
amrex::Real a_thetadt );
void ApplyMagneticFieldBCs ();
void SpectralSourceFreeFieldAdvance ();
void FinishMagneticFieldAndApplyBCs ( ablastr::fields::MultiLevelVectorField const& a_Bn,
amrex::Real a_theta );
Expand Down

0 comments on commit a1a677e

Please sign in to comment.