WarpX
Loading...
Searching...
No Matches
NewtonSolver< Vec, Ops > Class Template Reference

Newton method to solve nonlinear equation of form: F(U) = U - b - R(U) = 0. U is the solution vector, b is a constant, and R(U) is some nonlinear function of U, which is computed in the ComputeRHS() Ops function. More...

#include <NewtonSolver.H>

Inheritance diagram for NewtonSolver< Vec, Ops >:
NonlinearSolver< Vec, Ops >

Public Member Functions

 NewtonSolver ()=default
 
 ~NewtonSolver () override=default
 
 NewtonSolver (const NewtonSolver &)=delete
 
NewtonSolveroperator= (const NewtonSolver &)=delete
 
 NewtonSolver (NewtonSolver &&) noexcept=delete
 
NewtonSolveroperator= (NewtonSolver &&) noexcept=delete
 
void Define (const Vec &a_U, Ops *a_ops) override
 Read user-provided parameters that control the nonlinear solver. Allocate intermediate data containers needed by the solver. For Newton, setup the linear solver for computing the Newton step.
 
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.
 
void GetSolverParams (amrex::Real &a_rtol, amrex::Real &a_atol, int &a_maxits) override
 Return the convergence parameters used by the nonlinear solver.
 
void CurTime (amrex::Real a_time) const
 
void CurTimeStep (amrex::Real a_dt) const
 
void PrintParams () const override
 Print parameters used by the nonlinear solver.
 
- Public Member Functions inherited from NonlinearSolver< Vec, Ops >
 NonlinearSolver ()=default
 
virtual ~NonlinearSolver ()=default
 
 NonlinearSolver (const NonlinearSolver &)=delete
 
NonlinearSolveroperator= (const NonlinearSolver &)=delete
 
 NonlinearSolver (NonlinearSolver &&) noexcept=delete
 
NonlinearSolveroperator= (NonlinearSolver &&) noexcept=delete
 
bool IsDefined () const
 Check if the nonlinear solver has been defined.
 
virtual bool UsePreconditioner ()
 Whether a preconditioner is used by the nonlinear solver.
 
void Verbose (bool a_verbose)
 Allow caller to dynamically change the verbosity flag. For example, one may want to only print solver information every 100 steps.
 

Private Member Functions

void ParseParameters ()
 
void EvalResidual (Vec &a_F, const Vec &a_U, const Vec &a_b, amrex::Real a_time, int a_iter) const
 Compute the nonlinear residual: F(U) = U - b - R(U).
 

Private Attributes

Vec m_dU
 Intermediate Vec containers used by the solver.
 
Vec m_F
 
Vec m_R
 
Ops * m_ops = nullptr
 Pointer to Ops class.
 
bool m_require_convergence = true
 Flag to determine whether convergence is required.
 
amrex::Real m_rtol = 1.0e-6
 Relative tolerance for the Newton solver.
 
amrex::Real m_atol = 0.
 Absolute tolerance for the Newton solver.
 
int m_maxits = 100
 Maximum iterations for the Newton solver.
 
int m_total_iters = 0
 Total nonlinear iterations for the diagnostic file.
 
amrex::Real m_linsol_rtol = 1.0e-4
 Relative tolerance for linear solver.
 
amrex::Real m_linsol_atol = 0.
 Absolute tolerance for linear solver.
 
int m_linsol_maxits = 1000
 Maximum iterations for linear solver.
 
int m_total_linsol_iters = 0
 Total linear iterations for the diagnostic file.
 
int m_linsol_verbose_int = 2
 Verbosity flag for linear solver.
 
int m_linsol_restart_length = 30
 Restart iteration for linear solver.
 
PreconditionerType m_pc_type = PreconditionerType::none
 Preconditioner type.
 
amrex::Real m_cur_time
 
amrex::Real m_dt
 
std::unique_ptr< JacobianFunctionMF< Vec, Ops > > m_linear_function
 The linear function used by linear solver to compute A*v. In the contect of JFNK, A = dF/dU (i.e., system Jacobian)
 
LinearSolverType m_linear_solver_type = LinearSolverType::amrex_gmres
 Choice of linear solver.
 
std::unique_ptr< LinearSolver< Vec, JacobianFunctionMF< Vec, Ops > > > m_linear_solver
 The linear solver object.
 

Additional Inherited Members

- Protected Attributes inherited from NonlinearSolver< Vec, Ops >
bool m_is_defined = false
 
bool m_verbose = true
 
std::string m_diagnostic_file
 
int m_diagnostic_interval = 1
 
bool m_usePC = false
 

Detailed Description

template<class Vec, class Ops>
class NewtonSolver< Vec, Ops >

Newton method to solve nonlinear equation of form: F(U) = U - b - R(U) = 0. U is the solution vector, b is a constant, and R(U) is some nonlinear function of U, which is computed in the ComputeRHS() Ops function.

Constructor & Destructor Documentation

◆ NewtonSolver() [1/3]

template<class Vec, class Ops>
NewtonSolver< Vec, Ops >::NewtonSolver ( )
default

◆ ~NewtonSolver()

template<class Vec, class Ops>
NewtonSolver< Vec, Ops >::~NewtonSolver ( )
overridedefault

◆ NewtonSolver() [2/3]

template<class Vec, class Ops>
NewtonSolver< Vec, Ops >::NewtonSolver ( const NewtonSolver< Vec, Ops > & )
delete

◆ NewtonSolver() [3/3]

template<class Vec, class Ops>
NewtonSolver< Vec, Ops >::NewtonSolver ( NewtonSolver< Vec, Ops > && )
deletenoexcept

Member Function Documentation

◆ CurTime()

template<class Vec, class Ops>
void NewtonSolver< Vec, Ops >::CurTime ( amrex::Real a_time) const
inline

◆ CurTimeStep()

template<class Vec, class Ops>
void NewtonSolver< Vec, Ops >::CurTimeStep ( amrex::Real a_dt) const
inline

◆ Define()

template<class Vec, class Ops>
void NewtonSolver< Vec, Ops >::Define ( const Vec & ,
Ops *  )
overridevirtual

Read user-provided parameters that control the nonlinear solver. Allocate intermediate data containers needed by the solver. For Newton, setup the linear solver for computing the Newton step.

Implements NonlinearSolver< Vec, Ops >.

◆ EvalResidual()

template<class Vec, class Ops>
void NewtonSolver< Vec, Ops >::EvalResidual ( Vec & a_F,
const Vec & a_U,
const Vec & a_b,
amrex::Real a_time,
int a_iter ) const
private

Compute the nonlinear residual: F(U) = U - b - R(U).

◆ GetSolverParams()

template<class Vec, class Ops>
void NewtonSolver< Vec, Ops >::GetSolverParams ( amrex::Real & ,
amrex::Real & ,
int &  )
inlineoverridevirtual

Return the convergence parameters used by the nonlinear solver.

Implements NonlinearSolver< Vec, Ops >.

◆ operator=() [1/2]

template<class Vec, class Ops>
NewtonSolver & NewtonSolver< Vec, Ops >::operator= ( const NewtonSolver< Vec, Ops > & )
delete

◆ operator=() [2/2]

template<class Vec, class Ops>
NewtonSolver & NewtonSolver< Vec, Ops >::operator= ( NewtonSolver< Vec, Ops > && )
deletenoexcept

◆ ParseParameters()

template<class Vec, class Ops>
void NewtonSolver< Vec, Ops >::ParseParameters ( )
private

◆ PrintParams()

template<class Vec, class Ops>
void NewtonSolver< Vec, Ops >::PrintParams ( ) const
inlineoverridevirtual

Print parameters used by the nonlinear solver.

Implements NonlinearSolver< Vec, Ops >.

◆ Solve()

template<class Vec, class Ops>
void NewtonSolver< Vec, Ops >::Solve ( Vec & ,
const Vec & ,
amrex::Real ,
amrex::Real ,
int  ) const
overridevirtual

Solve the specified nonlinear equation for U. Picard: U = b + R(U). Newton: F(U) = U - b - R(U) = 0.

Implements NonlinearSolver< Vec, Ops >.

Member Data Documentation

◆ m_atol

template<class Vec, class Ops>
amrex::Real NewtonSolver< Vec, Ops >::m_atol = 0.
private

Absolute tolerance for the Newton solver.

◆ m_cur_time

template<class Vec, class Ops>
amrex::Real NewtonSolver< Vec, Ops >::m_cur_time
mutableprivate

◆ m_dt

template<class Vec, class Ops>
amrex::Real NewtonSolver< Vec, Ops >::m_dt
private

◆ m_dU

template<class Vec, class Ops>
Vec NewtonSolver< Vec, Ops >::m_dU
mutableprivate

Intermediate Vec containers used by the solver.

◆ m_F

template<class Vec, class Ops>
Vec NewtonSolver< Vec, Ops >::m_F
private

◆ m_linear_function

template<class Vec, class Ops>
std::unique_ptr<JacobianFunctionMF<Vec,Ops> > NewtonSolver< Vec, Ops >::m_linear_function
private

The linear function used by linear solver to compute A*v. In the contect of JFNK, A = dF/dU (i.e., system Jacobian)

◆ m_linear_solver

template<class Vec, class Ops>
std::unique_ptr<LinearSolver<Vec,JacobianFunctionMF<Vec,Ops> > > NewtonSolver< Vec, Ops >::m_linear_solver
private

The linear solver object.

◆ m_linear_solver_type

template<class Vec, class Ops>
LinearSolverType NewtonSolver< Vec, Ops >::m_linear_solver_type = LinearSolverType::amrex_gmres
private

Choice of linear solver.

◆ m_linsol_atol

template<class Vec, class Ops>
amrex::Real NewtonSolver< Vec, Ops >::m_linsol_atol = 0.
private

Absolute tolerance for linear solver.

◆ m_linsol_maxits

template<class Vec, class Ops>
int NewtonSolver< Vec, Ops >::m_linsol_maxits = 1000
private

Maximum iterations for linear solver.

◆ m_linsol_restart_length

template<class Vec, class Ops>
int NewtonSolver< Vec, Ops >::m_linsol_restart_length = 30
private

Restart iteration for linear solver.

◆ m_linsol_rtol

template<class Vec, class Ops>
amrex::Real NewtonSolver< Vec, Ops >::m_linsol_rtol = 1.0e-4
private

Relative tolerance for linear solver.

◆ m_linsol_verbose_int

template<class Vec, class Ops>
int NewtonSolver< Vec, Ops >::m_linsol_verbose_int = 2
private

Verbosity flag for linear solver.

◆ m_maxits

template<class Vec, class Ops>
int NewtonSolver< Vec, Ops >::m_maxits = 100
private

Maximum iterations for the Newton solver.

◆ m_ops

template<class Vec, class Ops>
Ops* NewtonSolver< Vec, Ops >::m_ops = nullptr
private

Pointer to Ops class.

◆ m_pc_type

template<class Vec, class Ops>
PreconditionerType NewtonSolver< Vec, Ops >::m_pc_type = PreconditionerType::none
private

◆ m_R

template<class Vec, class Ops>
Vec NewtonSolver< Vec, Ops >::m_R
private

◆ m_require_convergence

template<class Vec, class Ops>
bool NewtonSolver< Vec, Ops >::m_require_convergence = true
private

Flag to determine whether convergence is required.

◆ m_rtol

template<class Vec, class Ops>
amrex::Real NewtonSolver< Vec, Ops >::m_rtol = 1.0e-6
private

Relative tolerance for the Newton solver.

◆ m_total_iters

template<class Vec, class Ops>
int NewtonSolver< Vec, Ops >::m_total_iters = 0
mutableprivate

Total nonlinear iterations for the diagnostic file.

◆ m_total_linsol_iters

template<class Vec, class Ops>
int NewtonSolver< Vec, Ops >::m_total_linsol_iters = 0
mutableprivate

Total linear iterations for the diagnostic file.


The documentation for this class was generated from the following file: