7 #ifndef PICARD_SOLVER_H_
8 #define PICARD_SOLVER_H_
24 template<
class Vec,
class Ops>
39 void Define ( const Vec& a_U,
40 Ops* a_ops ) override;
42 void Solve ( Vec& a_U,
45 amrex::Real a_dt ) const override;
49 int& a_maxits )
override
100 template <
class Vec,
class Ops>
106 "Picard nonlinear solver object is already defined!");
115 this->m_is_defined =
true;
119 template <
class Vec,
class Ops>
123 pp_picard.
query(
"verbose", this->m_verbose);
124 pp_picard.
query(
"absolute_tolerance", m_atol);
125 pp_picard.
query(
"relative_tolerance", m_rtol);
126 pp_picard.
query(
"max_iterations", m_maxits);
127 pp_picard.
query(
"require_convergence", m_require_convergence);
131 template <
class Vec,
class Ops>
135 amrex::Real a_dt )
const
140 "PicardSolver::Solve() called on undefined object");
141 using namespace amrex::literals;
148 amrex::Real norm_abs = 0.;
149 amrex::Real norm0 = 1._rt;
150 amrex::Real norm_rel = 0.;
153 for (iter = 0; iter < m_maxits;) {
159 m_ops->ComputeRHS( m_R, a_U, a_time, a_dt, iter,
false );
165 norm_abs = m_Usave.norm2();
167 if (norm_abs > 0.) { norm0 = norm_abs; }
168 else { norm0 = 1._rt; }
170 norm_rel = norm_abs/norm0;
174 if (this->m_verbose || iter == m_maxits) {
175 amrex::Print() <<
"Picard: iter = " << std::setw(3) << iter <<
", norm = "
176 << std::scientific << std::setprecision(5) << norm_abs <<
" (abs.), "
177 << std::scientific << std::setprecision(5) << norm_rel <<
" (rel.)" <<
"\n";
180 if (norm_abs < m_atol) {
181 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
182 <<
". Satisfied absolute tolerance " << m_atol << std::endl;
186 if (norm_rel < m_rtol) {
187 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
188 <<
". Satisfied relative tolerance " << m_rtol << std::endl;
192 if (iter >= m_maxits) {
193 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
194 <<
". Maximum iteration reached: iter = " << m_maxits << std::endl;
200 if (m_rtol > 0. && iter == m_maxits) {
201 std::stringstream convergenceMsg;
202 convergenceMsg <<
"Picard solver failed to converge after " << iter <<
203 " iterations. Relative norm is " << norm_rel <<
204 " and the relative tolerance is " << m_rtol <<
205 ". Absolute norm is " << norm_abs <<
206 " and the absolute tolerance is " << m_atol;
207 if (this->m_verbose) {
amrex::Print() << convergenceMsg.str() << std::endl; }
208 if (m_require_convergence) {
#define WARPX_ABORT_WITH_MESSAGE(MSG)
Definition: TextMsg.H:15
#define WARPX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition: TextMsg.H:13
Top-level class for the nonlinear solver.
Definition: NonlinearSolver.H:28
Picard fixed-point iteration method to solve nonlinear equation of form: U = b + R(U)....
Definition: PicardSolver.H:26
void ParseParameters()
Definition: PicardSolver.H:120
PicardSolver(const PicardSolver &)=delete
bool m_require_convergence
Flag to determine whether convergence is required.
Definition: PicardSolver.H:79
Vec m_R
Definition: PicardSolver.H:69
void GetSolverParams(amrex::Real &a_rtol, amrex::Real &a_atol, int &a_maxits) override
Return the convergence parameters used by the nonlinear solver.
Definition: PicardSolver.H:47
amrex::Real m_rtol
Relative tolerance for the Picard nonlinear solver.
Definition: PicardSolver.H:84
Ops * m_ops
Pointer to Ops class.
Definition: PicardSolver.H:74
int m_maxits
Maximum iterations for the Picard nonlinear solver.
Definition: PicardSolver.H:94
amrex::Real m_atol
Absolute tolerance for the Picard nonlinear solver.
Definition: PicardSolver.H:89
PicardSolver & operator=(const PicardSolver &)=delete
Vec m_Usave
Intermediate Vec containers used by the solver.
Definition: PicardSolver.H:69
PicardSolver(PicardSolver &&) noexcept=delete
void Define(const Vec &a_U, Ops *a_ops) override
Read user-provided parameters that control the nonlinear solver. Allocate intermediate data container...
Definition: PicardSolver.H:101
void Solve(Vec &a_U, const Vec &a_b, amrex::Real a_time, amrex::Real a_dt) const override
Solve the specified nonlinear equation for U. Picard: U = b + R(U). Newton: F(U) = U - b - R(U) = 0.
Definition: PicardSolver.H:132
void PrintParams() const override
Print parameters used by the nonlinear solver.
Definition: PicardSolver.H:56
int query(const char *name, bool &ref, int ival=FIRST) const
void WMRecordWarning(const std::string &topic, const std::string &text, const WarnPriority &priority=WarnPriority::medium)
Helper function to abbreviate the call to WarnManager::GetInstance().RecordWarning (recording a warni...
Definition: WarnManager.cpp:318