Skip to content

Commit

Permalink
incorporating changes into new strang implicit spectral time advance …
Browse files Browse the repository at this point in the history
…routine.
  • Loading branch information
JustinRayAngus committed Nov 12, 2024
1 parent 8375975 commit 72c56c2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public:
void ComputeRHS ( WarpXSolverVec& a_RHS,
const WarpXSolverVec& a_E,
amrex::Real a_time,
amrex::Real a_dt,
int a_nl_iter,
bool a_from_jacobian ) override;

Expand Down Expand Up @@ -93,8 +92,7 @@ private:
* \brief Update the E and B fields owned by WarpX
*/
void UpdateWarpXFields ( WarpXSolverVec const& a_E,
amrex::Real a_time,
amrex::Real a_dt );
amrex::Real a_time );

/**
* \brief Nonlinear solver is for the time-centered values of E. After
Expand Down
21 changes: 11 additions & 10 deletions Source/FieldSolver/ImplicitSolvers/StrangImplicitSpectralEM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void StrangImplicitSpectralEM::OneStep ( amrex::Real a_time,
// Fields have E^{n} and B^{n}
// Particles have p^{n} and x^{n}.

// Set the member time step
m_dt = a_dt;

// Save the values at the start of the time step,
m_WarpX->SaveParticlesAtImplicitStepStart();

Expand All @@ -73,20 +76,20 @@ void StrangImplicitSpectralEM::OneStep ( amrex::Real a_time,
m_Eold.Copy( FieldType::Efield_fp );
m_E.Copy(m_Eold); // initial guess for E

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

// Solve nonlinear system for E at t_{n+1/2}
// Particles will be advanced to t_{n+1/2}
m_nlsolver->Solve( m_E, m_Eold, half_time, a_dt );
m_nlsolver->Solve( m_E, m_Eold, half_time, 0.5_rt*m_dt );

// Update WarpX owned Efield_fp and Bfield_fp to t_{n+1/2}
UpdateWarpXFields( m_E, half_time, a_dt );
UpdateWarpXFields( m_E, half_time );

// Advance particles from time n+1/2 to time n+1
m_WarpX->FinishImplicitParticleUpdate();

// Advance E and B fields from time n+1/2 to time n+1
amrex::Real const new_time = a_time + a_dt;
amrex::Real const new_time = a_time + m_dt;
FinishFieldUpdate( new_time );

// Advance the fields to time n+1 source free
Expand All @@ -97,29 +100,27 @@ void StrangImplicitSpectralEM::OneStep ( amrex::Real a_time,
void StrangImplicitSpectralEM::ComputeRHS ( WarpXSolverVec& a_RHS,
WarpXSolverVec const & a_E,
amrex::Real a_time,
amrex::Real a_dt,
int a_nl_iter,
bool a_from_jacobian )
{
// Update WarpX-owned Efield_fp and Bfield_fp using current state of
// E from the nonlinear solver at time n+1/2
UpdateWarpXFields( a_E, a_time, a_dt );
UpdateWarpXFields( a_E, a_time );

// Self consistently update particle positions and velocities using the
// current state of the fields E and B. Deposit current density at time n+1/2.
m_WarpX->ImplicitPreRHSOp( a_time, a_dt, a_nl_iter, a_from_jacobian );
m_WarpX->ImplicitPreRHSOp( a_time, m_dt, a_nl_iter, a_from_jacobian );

// For Strang split implicit PSATD, the RHS = -dt*mu*c**2*J
bool const allow_type_mismatch = true;
a_RHS.Copy(FieldType::current_fp, warpx::fields::FieldType::None, allow_type_mismatch);
amrex::Real constexpr coeff = PhysConst::c * PhysConst::c * PhysConst::mu0;
a_RHS.scale(-coeff * 0.5_rt*a_dt);
a_RHS.scale(-coeff * 0.5_rt*m_dt);

}

void StrangImplicitSpectralEM::UpdateWarpXFields (WarpXSolverVec const & a_E,
amrex::Real /*a_time*/,
amrex::Real /*a_dt*/)
amrex::Real /*a_time*/ )
{

// Update Efield_fp owned by WarpX
Expand Down

0 comments on commit 72c56c2

Please sign in to comment.