20 #ifndef LIBMESH_NONLINEAR_SOLVER_H 21 #define LIBMESH_NONLINEAR_SOLVER_H 24 #include "libmesh/libmesh_common.h" 25 #include "libmesh/reference_counted_object.h" 26 #include "libmesh/nonlinear_implicit_system.h" 27 #include "libmesh/libmesh.h" 28 #include "libmesh/parallel_object.h" 38 template <
typename T>
class SparseMatrix;
39 template <
typename T>
class NumericVector;
40 template <
typename T>
class Preconditioner;
41 class SolverConfiguration;
76 static std::unique_ptr<NonlinearSolver<T>>
build(
sys_type & s,
94 virtual void init (
const char *
name =
nullptr) = 0;
103 const unsigned int) = 0;
257 bool & changed_search_direction,
258 bool & changed_new_soln,
451 template <
typename T>
456 residual_object (nullptr),
457 fd_residual_object (nullptr),
458 mffd_residual_object (nullptr),
460 jacobian_object (nullptr),
462 residual_and_jacobian_object (nullptr),
464 bounds_object (nullptr),
466 nullspace_object (nullptr),
467 transpose_nullspace (nullptr),
468 transpose_nullspace_object (nullptr),
469 nearnullspace (nullptr),
470 nearnullspace_object (nullptr),
471 user_presolve (nullptr),
473 postcheck_object (nullptr),
474 precheck_object (nullptr),
475 max_nonlinear_iterations(0),
476 max_function_evaluations(0),
477 absolute_residual_tolerance(0),
478 relative_residual_tolerance(0),
479 divergence_tolerance(0),
480 absolute_step_tolerance(0),
481 relative_step_tolerance(0),
482 max_linear_iterations(0),
483 initial_linear_tolerance(0),
484 minimum_linear_tolerance(0),
486 _reuse_preconditioner(false),
487 _exact_constraint_enforcement(true),
488 _reuse_preconditioner_max_linear_its(0),
491 _preconditioner (nullptr),
492 _solver_configuration(nullptr)
498 template <
typename T>
502 this->NonlinearSolver::clear ();
509 #endif // LIBMESH_NONLINEAR_SOLVER_H std::string name(const ElemQuality q)
This function returns a string containing some name for q.
unsigned int _reuse_preconditioner_max_linear_its
Number of linear iterations to retain the preconditioner.
virtual void clear()
Release all memory and clear data structures.
virtual void init(const char *name=nullptr)=0
Initialize data structures if not done so already.
void(* residual)(const NumericVector< Number > &X, NumericVector< Number > &R, sys_type &S)
Function that computes the residual R(X) of the nonlinear system at the input iterate X...
virtual bool reuse_preconditioner() const
Get the reuse_preconditioner flag.
NonlinearImplicitSystem::ComputeResidualandJacobian * residual_and_jacobian_object
Object that computes either the residual or the Jacobian of the nonlinear system at the input itera...
sys_type & _system
A reference to the system we are solving.
virtual void set_exact_constraint_enforcement(bool enable)
Enable (or disable; it is true by default) exact enforcement of constraints at the solver level...
bool exact_constraint_enforcement()
bool converged
After a call to solve this will reflect whether or not the nonlinear solve was successful.
unsigned int max_function_evaluations
Maximum number of function evaluations.
Preconditioner< T > * _preconditioner
Holds the Preconditioner object to be used for the linear solves.
void(* user_presolve)(sys_type &S)
Customizable function pointer which users can attach to the solver.
void attach_preconditioner(Preconditioner< T > *preconditioner)
Attaches a Preconditioner object to be used during the linear solves.
Provides a uniform interface to vector storage schemes for different linear algebra libraries...
This base class can be inherited from to provide interfaces to nonlinear solvers from different packa...
unsigned int max_linear_iterations
Each linear solver step should exit after max_linear_iterations is exceeded.
The libMesh namespace provides an interface to certain functionality in the library.
SolverConfiguration * _solver_configuration
Optionally store a SolverOptions object that can be used to set parameters like solver type...
Abstract base class to be used to calculate the bounds on the degrees of freedom of a nonlinear syste...
virtual std::pair< unsigned int, Real > solve(SparseMatrix< T > &, NumericVector< T > &, NumericVector< T > &, const double, const unsigned int)=0
Solves the nonlinear system.
NonlinearImplicitSystem::ComputeResidual * residual_object
Object that computes the residual R(X) of the nonlinear system at the input iterate X...
void(* jacobian)(const NumericVector< Number > &X, SparseMatrix< Number > &J, sys_type &S)
Function that computes the Jacobian J(X) of the nonlinear system at the input iterate X...
SolverPackage default_solver_package()
const sys_type & system() const
virtual void set_reuse_preconditioner_max_linear_its(unsigned int i)
Set the reuse_preconditioner_max_linear_its parameter.
bool _is_initialized
Flag indicating if the data structures have been initialized.
Abstract base class to be used to calculate the residual of a nonlinear system.
NonlinearImplicitSystem::ComputeJacobian * jacobian_object
Object that computes the Jacobian J(X) of the nonlinear system at the input iterate X...
void set_solver_configuration(SolverConfiguration &solver_configuration)
Set the solver configuration object.
This class provides a uniform interface for preconditioners.
virtual int get_total_linear_iterations()=0
Get the total number of linear iterations done in the last solve.
Abstract base class to be used to calculate the Jacobian of a nonlinear system.
double minimum_linear_tolerance
The tolerance for linear solves is kept above this minimum.
bool _is_initialized
Flag that tells if init() has been called.
NonlinearImplicitSystem::ComputeBounds * bounds_object
Object that computes the bounds vectors and .
bool _exact_constraint_enforcement
Whether we should enforce exact constraints globally during a solve.
virtual ~NonlinearSolver()
Destructor.
virtual unsigned int reuse_preconditioner_max_linear_its() const
Get the reuse_preconditioner_max_linear_its parameter.
Manages consistently variables, degrees of freedom, coefficient vectors, matrices and non-linear solv...
void(* transpose_nullspace)(std::vector< NumericVector< Number > *> &sp, sys_type &S)
Function that computes a basis for the transpose Jacobian's nullspace – when solving a degenerate pr...
virtual unsigned get_current_nonlinear_iteration_number() const =0
This class stores solver configuration data, e.g.
Abstract base class to be used to calculate the residual and Jacobian simultaneously of a nonlinear s...
This class implements reference counting.
void(* nullspace)(std::vector< NumericVector< Number > *> &sp, sys_type &S)
Function that computes a basis for the Jacobian's nullspace – the kernel or the "zero energy modes" ...
An object whose state is distributed along a set of processors.
void(* nearnullspace)(std::vector< NumericVector< Number > *> &sp, sys_type &S)
Function that computes a basis for the Jacobian's near nullspace – the set of "low energy modes" – ...
virtual void set_reuse_preconditioner(bool reuse)
Set the reuse preconditioner flag.
double divergence_tolerance
The NonlinearSolver should exit if the residual becomes greater than the initial residual times the d...
NonlinearImplicitSystem::ComputePostCheck * postcheck_object
A callable object that is executed after each nonlinear iteration.
double absolute_step_tolerance
The NonlinearSolver should exit after the full nonlinear step norm is reduced to either less than abs...
virtual void print_converged_reason()
Prints a useful message about why the latest nonlinear solve con(di)verged.
static std::unique_ptr< NonlinearSolver< T > > build(sys_type &s, const SolverPackage solver_package=libMesh::default_solver_package())
Builds a NonlinearSolver using the nonlinear solver package specified by solver_package.
NonlinearSolver(sys_type &s)
Constructor.
bool _reuse_preconditioner
Whether we should reuse the linear preconditioner.
void(* bounds)(NumericVector< Number > &XL, NumericVector< Number > &XU, sys_type &S)
Function that computes the lower and upper bounds XL and XU on the solution of the nonlinear system...
NonlinearImplicitSystem::ComputeResidual * mffd_residual_object
Object that computes the residual R(X) of the nonlinear system at the input iterate X for the purpose...
double absolute_residual_tolerance
The NonlinearSolver should exit after the residual is reduced to either less than absolute_residual_t...
void(* postcheck)(const NumericVector< Number > &old_soln, NumericVector< Number > &search_direction, NumericVector< Number > &new_soln, bool &changed_search_direction, bool &changed_new_soln, sys_type &S)
Function that performs a "check" on the Newton search direction and solution after each nonlinear ste...
NonlinearImplicitSystem::ComputeVectorSubspace * nearnullspace_object
A callable object that computes a basis for the Jacobian's near nullspace – the set of "low energy m...
SolverPackage
Defines an enum for various linear solver packages.
NonlinearImplicitSystem::ComputePreCheck * precheck_object
NonlinearImplicitSystem sys_type
The type of system.
double initial_linear_tolerance
Any required linear solves will at first be done with this tolerance; the NonlinearSolver may tighten...
Abstract base class to be used for applying user modifications to the solution vector and/or Newton u...
unsigned int max_nonlinear_iterations
Maximum number of non-linear iterations.
NonlinearImplicitSystem::ComputeVectorSubspace * transpose_nullspace_object
A callable object that computes a basis for the transpose Jacobian's nullspace – when solving a dege...
double relative_step_tolerance
void ErrorVector unsigned int
double relative_residual_tolerance
virtual void force_new_preconditioner()
Immediately force a new preconditioner.
void(* matvec)(const NumericVector< Number > &X, NumericVector< Number > *R, SparseMatrix< Number > *J, sys_type &S)
Function that computes either the residual or the Jacobian of the nonlinear system at the input ite...
NonlinearImplicitSystem::ComputeResidual * fd_residual_object
Object that computes the residual R(X) of the nonlinear system at the input iterate X for the purpose...
Abstract base class to be used for applying user modifications to the Newton search direction before...
Callable abstract base class to be used as a callback to provide the solver with a basis for the syst...
NonlinearImplicitSystem::ComputeVectorSubspace * nullspace_object
A callable object that computes a basis for the Jacobian's nullspace – the kernel or the "zero energ...