7#ifndef PICARD_SOLVER_H_
8#define PICARD_SOLVER_H_
26template<
class Vec,
class Ops>
41 void Define ( const Vec& a_U,
42 Ops* a_ops ) override;
44 void Solve ( Vec& a_U,
48 int a_step) const override;
52 int& a_maxits )
override
108template <
class Vec,
class Ops>
114 "Picard nonlinear solver object is already defined!");
131 std::filesystem::path
const diagnostic_dir = diagnostic_path.parent_path();
132 if (!diagnostic_dir.empty()) {
133 std::filesystem::create_directories(diagnostic_dir);
136 std::ofstream diagnostic_file{this->
m_diagnostic_file, std::ofstream::out | std::ofstream::trunc};
138 diagnostic_file <<
"#";
139 diagnostic_file <<
"[" << c++ <<
"]step()";
140 diagnostic_file <<
" ";
141 diagnostic_file <<
"[" << c++ <<
"]time(s)";
142 diagnostic_file <<
" ";
143 diagnostic_file <<
"[" << c++ <<
"]iters";
144 diagnostic_file <<
" ";
145 diagnostic_file <<
"[" << c++ <<
"]total_iters";
146 diagnostic_file <<
" ";
147 diagnostic_file <<
"[" << c++ <<
"]norm_abs";
148 diagnostic_file <<
" ";
149 diagnostic_file <<
"[" << c++ <<
"]norm_rel";
150 diagnostic_file <<
"\n";
151 diagnostic_file.close();
156template <
class Vec,
class Ops>
169template <
class Vec,
class Ops>
179 "PicardSolver::Solve() called on undefined object");
180 using namespace amrex::literals;
187 amrex::Real norm_abs = 0.;
188 amrex::Real norm0 = 1._rt;
189 amrex::Real norm_rel = 0.;
198 m_ops->ComputeRHS(
m_R, a_U, a_time, iter,
false );
206 if (norm_abs > 0.) { norm0 = norm_abs; }
207 else { norm0 = 1._rt; }
209 norm_rel = norm_abs/norm0;
214 amrex::Print() <<
"Picard: iter = " << std::setw(3) << iter <<
", norm = "
215 << std::scientific << std::setprecision(5) << norm_abs <<
" (abs.), "
216 << std::scientific << std::setprecision(5) << norm_rel <<
" (rel.)" <<
"\n";
221 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
222 <<
". Satisfied absolute tolerance " <<
m_atol <<
"\n";
229 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
230 <<
". Satisfied relative tolerance " <<
m_rtol <<
"\n";
237 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
238 <<
". Maximum iteration reached: iter = " <<
m_maxits <<
"\n";
249 std::stringstream convergenceMsg;
250 convergenceMsg <<
"Picard solver failed to converge after " << iter <<
251 " iterations. Relative norm is " << norm_rel <<
252 " and the relative tolerance is " <<
m_rtol <<
253 ". Absolute norm is " << norm_abs <<
254 " and the absolute tolerance is " <<
m_atol;
264 ((a_step+1)%this->m_diagnostic_interval==0 || a_step==0)) {
265 std::ofstream diagnostic_file{this->
m_diagnostic_file, std::ofstream::out | std::ofstream::app};
266 diagnostic_file << std::setprecision(14);
267 diagnostic_file << a_step+1;
268 diagnostic_file <<
" ";
269 diagnostic_file << a_time + a_dt;
270 diagnostic_file <<
" ";
271 diagnostic_file << iter;
272 diagnostic_file <<
" ";
274 diagnostic_file <<
" ";
275 diagnostic_file << norm_abs;
276 diagnostic_file <<
" ";
277 diagnostic_file << norm_rel;
278 diagnostic_file <<
"\n";
279 diagnostic_file.close();
#define WARPX_ABORT_WITH_MESSAGE(MSG)
Definition TextMsg.H:15
#define WARPX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition TextMsg.H:13
bool m_is_defined
Definition NonlinearSolver.H:88
std::string m_diagnostic_file
Definition NonlinearSolver.H:90
NonlinearSolver()=default
int m_diagnostic_interval
Definition NonlinearSolver.H:91
bool m_verbose
Definition NonlinearSolver.H:89
PicardSolver & operator=(const PicardSolver &)=delete
void ParseParameters()
Definition PicardSolver.H:157
PicardSolver(const PicardSolver &)=delete
bool m_require_convergence
Flag to determine whether convergence is required.
Definition PicardSolver.H:82
Vec m_R
Definition PicardSolver.H:72
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:50
~PicardSolver() override=default
amrex::Real m_rtol
Relative tolerance for the Picard nonlinear solver.
Definition PicardSolver.H:87
Ops * m_ops
Pointer to Ops class.
Definition PicardSolver.H:77
int m_maxits
Maximum iterations for the Picard nonlinear solver.
Definition PicardSolver.H:97
amrex::Real m_atol
Absolute tolerance for the Picard nonlinear solver.
Definition PicardSolver.H:92
void Solve(Vec &a_U, const Vec &a_b, amrex::Real a_time, amrex::Real a_dt, int a_step) 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:170
Vec m_Usave
Intermediate Vec containers used by the solver.
Definition PicardSolver.H:72
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:109
int m_total_iters
Total iterations for the diagnostic file.
Definition PicardSolver.H:102
void PrintParams() const override
Print parameters used by the nonlinear solver.
Definition PicardSolver.H:59
int query(std::string_view 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:320
bool IOProcessor() noexcept
bool FileExists(const std::string &filename)