21#include "libmesh/nonlinear_implicit_system.h"
22#include "libmesh/diff_solver.h"
23#include "libmesh/equation_systems.h"
24#include "libmesh/libmesh_logging.h"
25#include "libmesh/nonlinear_solver.h"
26#include "libmesh/sparse_matrix.h"
27#include "libmesh/static_condensation.h"
28#include "libmesh/static_condensation_preconditioner.h"
34 const std::string & name_in,
35 const unsigned int number_in) :
37 Parent (es, name_in, number_in),
40 _n_nonlinear_iterations (0),
41 _final_nonlinear_residual (1.e20),
42 _operator_matrix (nullptr)
48 es.
parameters.
set<
unsigned int>(
"linear solver maximum iterations") = 10000;
50 es.
parameters.
set<
unsigned int>(
"nonlinear solver maximum iterations") = 50;
51 es.
parameters.
set<
unsigned int>(
"nonlinear solver maximum function evaluations") = 10000;
60 es.
parameters.
set<
unsigned int>(
"reuse preconditioner maximum linear iterations") = 1;
127 parameters.
get<
unsigned int>(
"nonlinear solver maximum iterations") :
128 es.
parameters.
get<
unsigned int>(
"nonlinear solver maximum iterations");
130 const unsigned int maxfuncs =
parameters.
have_parameter<
unsigned int>(
"nonlinear solver maximum function evaluations") ?
131 parameters.
get<
unsigned int>(
"nonlinear solver maximum function evaluations") :
132 es.
parameters.
get<
unsigned int>(
"nonlinear solver maximum function evaluations");
164 const unsigned int reuse_preconditioner_max_linear_its =
166 parameters.
get<
unsigned int>(
"reuse preconditioner maximum linear iterations") :
167 es.
parameters.
get<
unsigned int>(
"reuse preconditioner maximum linear iterations");
181 nonlinear_solver->set_reuse_preconditioner_max_linear_its(reuse_preconditioner_max_linear_its);
186 diff_solver->absolute_residual_tolerance = abs_resid_tol;
187 diff_solver->relative_residual_tolerance = rel_resid_tol;
188 diff_solver->absolute_step_tolerance = abs_step_tol;
189 diff_solver->relative_step_tolerance = rel_step_tol;
191 diff_solver->initial_linear_tolerance = linear_tol;
192 diff_solver->minimum_linear_tolerance = linear_min_tol;
201 LOG_SCOPE(
"solve()",
"System");
252 return std::make_pair(this->
diff_solver->max_linear_iterations,
253 this->diff_solver->relative_residual_tolerance);
255 this->nonlinear_solver->relative_residual_tolerance);
272 "ERROR: cannot specify both a function and object to compute the Jacobian!");
275 "ERROR: cannot specify both a function and object to compute the Residual!");
278 "ERROR: cannot specify both a function and object to compute the combined Residual & Jacobian!");
296 libmesh_error_msg(
"Error! Unable to compute residual and/or Jacobian!");
322 libmesh_error_msg(
"Error! Unable to compute residual and/or Jacobian!");
This is the EquationSystems class.
Parameters parameters
Data structure holding arbitrary parameters.
NumericVector< Number > * rhs
The system matrix.
Manages consistently variables, degrees of freedom, coefficient vectors, and matrices for implicit sy...
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const
SparseMatrix< Number > * matrix
The system matrix.
virtual void clear() override
Clear all the data structures associated with the system.
virtual void create_static_condensation() override
Request that static condensation be performed for this system.
void setup_static_condensation_preconditioner(T &solver)
Sets up the static condensation preconditioner for the supplied solver.
void set_solver_parameters()
Copies system parameters into nonlinear solver parameters.
virtual void solve() override
Assembles & solves the nonlinear system R(x) = 0.
virtual std::pair< unsigned int, Real > get_linear_solve_parameters() const override
virtual void reinit() override
Reinitializes the member data fields associated with the system, so that, e.g., assemble() may be use...
unsigned get_current_nonlinear_iteration_number() const
If called during the solve(), for example by the user-specified residual or Jacobian function,...
NonlinearImplicitSystem(EquationSystems &es, const std::string &name, const unsigned int number)
Constructor.
unsigned int _n_nonlinear_iterations
The number of nonlinear iterations required to solve the nonlinear system R(x)=0.
virtual void assembly(bool get_residual, bool get_jacobian, bool apply_heterogeneous_constraints=false, bool apply_no_constraints=false) override
Assembles a residual in rhs and/or a jacobian in matrix, as requested.
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
The NonlinearSolver defines the default interface used to solve the nonlinear_implicit system.
virtual ~NonlinearImplicitSystem()
SparseMatrix< Number > * _operator_matrix
An optional matrix to use as the actual Jacobian operator (what is Amat in PETSc lingo for the linear...
std::unique_ptr< DiffSolver > diff_solver
The DiffSolver defines an optional interface used to solve the nonlinear_implicit system.
Real _final_nonlinear_residual
The final residual for the nonlinear system R(x)
virtual void create_static_condensation() override
Request that static condensation be performed for this system.
virtual void clear() override
Clear all the data structures associated with the system.
This base class can be inherited from to provide interfaces to nonlinear solvers from different packa...
bool have_parameter(std::string_view) const
T & set(const std::string &)
const T & get(std::string_view) const
virtual void reinit()
Reinitializes degrees of freedom and other required data on the current mesh.
std::unique_ptr< NumericVector< Number > > current_local_solution
All the values I need to compute my contribution to the simulation at hand.
bool prefix_with_name() const
std::unique_ptr< NumericVector< Number > > solution
Data structure to hold solution values.
virtual void update()
Update the local values to reflect the solution on neighboring processors.
bool has_static_condensation() const
Parameters parameters
Parameters for the system. If a parameter is not provided, it should be retrieved from the EquationSy...
std::string prefix() const
const EquationSystems & get_equation_systems() const
The libMesh namespace provides an interface to certain functionality in the library.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real