Skip to content

Commit 3932e46

Browse files
moved theta to implicit solve base class. time and dt passed to nonlinear solver is time at beginning of time step and the full time step.
1 parent 2057116 commit 3932e46

8 files changed

+19
-15
lines changed

Source/FieldSolver/ImplicitSolvers/ImplicitSolver.H

+7
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ public:
9696
[[nodiscard]] amrex::Array<amrex::LinOpBCType,AMREX_SPACEDIM> GetLinOpBCLo () const;
9797
[[nodiscard]] amrex::Array<amrex::LinOpBCType,AMREX_SPACEDIM> GetLinOpBCHi () const;
9898

99+
[[nodiscard]] amrex::Real GetTheta () const { return m_theta; }
100+
99101
protected:
100102

101103
/**
@@ -115,6 +117,11 @@ protected:
115117
*/
116118
mutable amrex::Real m_dt = 0.0;
117119

120+
/**
121+
* \brief Time-biasing parameter for fields used on RHS to advance system.
122+
*/
123+
amrex::Real m_theta = 0.5;
124+
118125
/**
119126
* \brief Nonlinear solver type and object
120127
*/

Source/FieldSolver/ImplicitSolvers/SemiImplicitEM.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public:
6363

6464
void ComputeRHS ( WarpXSolverVec& a_RHS,
6565
const WarpXSolverVec& a_E,
66-
amrex::Real half_time,
66+
amrex::Real start_time,
6767
int a_nl_iter,
6868
bool a_from_jacobian ) override;
6969

Source/FieldSolver/ImplicitSolvers/SemiImplicitEM.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void SemiImplicitEM::OneStep ( amrex::Real start_time,
8080
// Solve nonlinear system for Eg at t_{n+1/2}
8181
// Particles will be advanced to t_{n+1/2}
8282
m_E.Copy(m_Eold); // initial guess for Eg^{n+1/2}
83-
m_nlsolver->Solve( m_E, m_Eold, half_time, 0.5_rt*m_dt, a_step );
83+
m_nlsolver->Solve( m_E, m_Eold, start_time, m_dt, a_step );
8484

8585
// Update WarpX owned Efield_fp to t_{n+1/2}
8686
m_WarpX->SetElectricFieldAndApplyBCs( m_E, half_time );
@@ -103,12 +103,13 @@ void SemiImplicitEM::OneStep ( amrex::Real start_time,
103103

104104
void SemiImplicitEM::ComputeRHS ( WarpXSolverVec& a_RHS,
105105
const WarpXSolverVec& a_E,
106-
amrex::Real half_time,
106+
amrex::Real start_time,
107107
int a_nl_iter,
108108
bool a_from_jacobian )
109109
{
110110
// Update WarpX-owned Efield_fp using current state of Eg from
111111
// the nonlinear solver at time n+theta
112+
const amrex::Real half_time = start_time + 0.5_rt*m_dt;
112113
m_WarpX->SetElectricFieldAndApplyBCs( a_E, half_time );
113114

114115
// Update particle positions and velocities using the current state

Source/FieldSolver/ImplicitSolvers/StrangImplicitSpectralEM.H

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public:
6464

6565
void ComputeRHS ( WarpXSolverVec& a_RHS,
6666
const WarpXSolverVec& a_E,
67-
amrex::Real half_time,
67+
amrex::Real start_time,
6868
int a_nl_iter,
6969
bool a_from_jacobian ) override;
7070

Source/FieldSolver/ImplicitSolvers/StrangImplicitSpectralEM.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void StrangImplicitSpectralEM::OneStep ( amrex::Real start_time,
8181

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

8686
// Update WarpX owned Efield_fp and Bfield_fp to t_{n+1/2}
8787
UpdateWarpXFields( m_E, half_time );
@@ -101,12 +101,13 @@ void StrangImplicitSpectralEM::OneStep ( amrex::Real start_time,
101101

102102
void StrangImplicitSpectralEM::ComputeRHS ( WarpXSolverVec& a_RHS,
103103
WarpXSolverVec const & a_E,
104-
amrex::Real half_time,
104+
amrex::Real start_time,
105105
int a_nl_iter,
106106
bool a_from_jacobian )
107107
{
108108
// Update WarpX-owned Efield_fp and Bfield_fp using current state of
109109
// E from the nonlinear solver at time n+1/2
110+
const amrex::Real half_time = start_time + 0.5_rt*m_dt;
110111
UpdateWarpXFields( a_E, half_time );
111112

112113
// Self consistently update particle positions and velocities using the

Source/FieldSolver/ImplicitSolvers/ThetaImplicitEM.H

-5
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,6 @@ public:
8686

8787
private:
8888

89-
/**
90-
* \brief Time-biasing parameter for fields used on RHS to advance system
91-
*/
92-
amrex::Real m_theta = 0.5;
93-
9489
/**
9590
* \brief Solver vectors to be used in the nonlinear solver to solve for the
9691
* electric field E. The main logic for determining which variables should be

Source/FieldSolver/ImplicitSolvers/ThetaImplicitEM.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void ThetaImplicitEM::OneStep ( const amrex::Real start_time,
106106
// Solve nonlinear system for Eg at t_{n+theta}
107107
// Particles will be advanced to t_{n+1/2}
108108
m_E.Copy(m_Eold); // initial guess for Eg^{n+theta}
109-
m_nlsolver->Solve( m_E, m_Eold, start_time, m_theta*m_dt, a_step );
109+
m_nlsolver->Solve( m_E, m_Eold, start_time, m_dt, a_step );
110110

111111
// Update WarpX owned Efield_fp and Bfield_fp to t_{n+theta}
112112
UpdateWarpXFields( m_E, start_time );

Source/NonlinearSolvers/CurlCurlMLMGPC.H

+3-3
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,8 @@ void CurlCurlMLMGPC<T,Ops>::Update (const T& a_U)
272272
amrex::ignore_unused(a_U);
273273

274274
// set the coefficients alpha and beta for curl-curl op
275-
// (m_dt here is actually theta<=0.5 times simulation dt)
276-
const RT alpha = (this->m_dt*PhysConst::c) * (this->m_dt*PhysConst::c);
275+
const RT thetaDt = m_ops->GetTheta()*this->m_dt;
276+
const RT alpha = (thetaDt*PhysConst::c) * (thetaDt*PhysConst::c);
277277
const RT beta = RT(1.0);
278278

279279
// currently not implemented in 1D
@@ -283,7 +283,7 @@ void CurlCurlMLMGPC<T,Ops>::Update (const T& a_U)
283283

284284
if (m_verbose) {
285285
amrex::Print() << "Updating " << amrex::getEnumNameString(PreconditionerType::pc_curl_curl_mlmg)
286-
<< ": theta*dt = " << this->m_dt << ", "
286+
<< ": theta*dt = " << thetaDt << ", "
287287
<< " coefficients: "
288288
<< "alpha = " << alpha << ", "
289289
<< "beta = " << beta << "\n";

0 commit comments

Comments
 (0)