7#ifndef PICARD_SOLVER_H_
8#define PICARD_SOLVER_H_
26template<
class Vec,
class Ops>
41 void Define (const 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");
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";
222 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
223 <<
". Satisfied absolute tolerance " <<
m_atol <<
"\n";
231 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
232 <<
". Satisfied relative tolerance " <<
m_rtol <<
"\n";
239 amrex::Print() <<
"Picard: exiting at iter = " << std::setw(3) << iter
240 <<
". Maximum iteration reached: iter = " <<
m_maxits <<
"\n";
251 std::stringstream convergenceMsg;
252 convergenceMsg <<
"Picard solver failed to converge after " << iter <<
253 " iterations. Relative norm is " << norm_rel <<
254 " and the relative tolerance is " <<
m_rtol <<
255 ". Absolute norm is " << norm_abs <<
256 " and the absolute tolerance is " <<
m_atol;
265 ((a_step+1)%this->m_diagnostic_interval==0 || a_step==0)) {
266 std::ofstream diagnostic_file{this->
m_diagnostic_file, std::ofstream::out | std::ofstream::app};
267 diagnostic_file << std::setprecision(14);
268 diagnostic_file << a_step+1;
269 diagnostic_file <<
" ";
270 diagnostic_file << a_time + a_dt;
271 diagnostic_file <<
" ";
272 diagnostic_file << iter;
273 diagnostic_file <<
" ";
275 diagnostic_file <<
" ";
276 diagnostic_file << norm_abs;
277 diagnostic_file <<
" ";
278 diagnostic_file << norm_rel;
279 diagnostic_file <<
"\n";
280 diagnostic_file.close();
#define WARPX_ALWAYS_ASSERT_WITH_MESSAGE(EX, MSG)
Definition TextMsg.H:13
bool m_is_defined
Definition NonlinearSolver.H:95
std::string m_diagnostic_file
Definition NonlinearSolver.H:97
NonlinearSolver()=default
int m_diagnostic_interval
Definition NonlinearSolver.H:98
bool m_verbose
Definition NonlinearSolver.H:96
int m_exit_status
Definition NonlinearSolver.H:101
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
bool IOProcessor() noexcept
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 FileExists(const std::string &filename)