14#include "libmesh/nonlinear_implicit_system.h"
15#include "libmesh/nonlinear_solver.h"
16#include "libmesh/dof_map.h"
24 params.
addParam<std::vector<VariableName>>(
25 "variables", {},
"A subset of the variables that this time integrator should be applied to");
34 *getCheckedPointerParam<
SystemBase *>(
"_sys")),
36 _fe_problem(*getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base")),
37 _sys(*getCheckedPointerParam<
SystemBase *>(
"_sys")),
38 _du_dot_du(_sys.duDotDus()),
39 _solution(_sys.currentSolution()),
40 _solution_old(_sys.solutionState(1)),
42 "solution_sub", &const_cast<
libMesh::
Parallel::Communicator &>(this->comm()))),
44 "solution_old_sub", &const_cast<
libMesh::
Parallel::Communicator &>(this->comm()))),
45 _t_step(_fe_problem.timeStep()),
46 _dt(_fe_problem.dt()),
47 _dt_old(_fe_problem.dtOld()),
48 _n_nonlinear_iterations(0),
49 _n_linear_iterations(0),
51 _var_restriction(declareRestartableData<bool>(
52 "var_restriction", !getParam<
std::vector<VariableName>>(
"variables").empty())),
53 _local_indices(declareRestartableData<
std::vector<
dof_id_type>>(
"local_indices")),
54 _vars(declareRestartableData<
std::unordered_set<unsigned
int>>(
"vars")),
67 const auto & var_names = getParam<std::vector<VariableName>>(
"variables");
68 std::vector<unsigned int> var_num_vec;
71 std::unordered_set<unsigned int> var_nums(var_num_vec.begin(), var_num_vec.end());
72 for (
const auto & var_name : var_names)
73 if (lm_sys.has_variable(var_name))
75 const auto var_num = lm_sys.variable_number(var_name);
76 _vars.insert(var_num);
77 var_nums.erase(var_num);
87 std::vector<dof_id_type> var_dof_indices, work_vec;
88 for (
const auto var_num :
_vars)
92 lm_sys.get_dof_map().local_variable_indices(var_dof_indices, lm_sys.get_mesh(), var_num);
93 std::merge(work_vec.begin(),
95 var_dof_indices.begin(),
96 var_dof_indices.end(),
109 mooseError(
"Calling TimeIntegrator::solve() is no longer supported");
131 return nonlinear_solver->get_total_linear_iterations();
154 return _vars.count(var_num);
void ErrorVector unsigned int
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void setUDotRequested(const bool u_dot_requested)
Set boolean flag to true to store solution time derivative.
Interface class for routines and member variables for time integrators relying on linear system assem...
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Every object that can be built by the factory should be derived from this class.
static InputParameters validParams()
Interface class for routines and member variables for time integrators relying on Newton's method.
libMesh::NonlinearImplicitSystem * _nonlinear_implicit_system
libMesh nonlinear implicit system, if applicable; otherwise, nullptr
A class for creating restricted objects.
Base class for a system (of equations)
virtual libMesh::System & system()=0
Get the reference to the libMesh system.
std::vector< dof_id_type > & _local_indices
The local degree of freedom indices this time integrator is being applied to.
bool & _var_restriction
Whether the user has requested that the time integrator be applied to a subset of variables.
std::unique_ptr< NumericVector< Number > > & _solution_old_sub
void setNumIterationsLastSolve()
Record the linear and nonlinear iterations from a just finished solve.
void computeDuDotDu()
Compute _du_dot_du.
unsigned int getNumLinearIterationsLastSolve() const
Gets the number of linear iterations in the most recent solve.
std::unordered_set< unsigned int > & _vars
The variables that this time integrator integrates.
void copyVector(const NumericVector< Number > &from, NumericVector< Number > &to)
Copy from one vector into another.
const NumericVector< Number > *const & _solution
unsigned int _n_linear_iterations
Total number of linear iterations over all stages of the time step.
std::unique_ptr< NumericVector< Number > > _from_subvector
A vector that is used for creating 'from' subvectors in the copyVector() method.
bool integratesVar(const unsigned int var_num) const
unsigned int _n_nonlinear_iterations
Total number of nonlinear iterations over all stages of the time step.
static InputParameters validParams()
FEProblemBase & _fe_problem
Reference to the problem.
virtual void init()
Called only before the very first timestep (t_step = 0) Never called again (not even during recover/r...
unsigned int getNumNonlinearIterationsLastSolve() const
Gets the number of nonlinear iterations in the most recent solve.
SystemBase & _sys
Reference to the system this time integrator operates on.
virtual void solve()
Solves the time step and sets the number of nonlinear and linear iterations.
Real & _dt
The current time step size.
TimeIntegrator(const InputParameters ¶meters)
std::vector< Real > & _du_dot_du
Derivative of time derivative with respect to current solution: for the different variables.
std::unique_ptr< NumericVector< Number > > & _solution_sub
virtual Real duDotDuCoeff() const
const NumericVector< Number > & _solution_old
std::unique_ptr< NonlinearSolver< Number > > nonlinear_solver
unsigned int n_nonlinear_iterations() const
virtual std::unique_ptr< NumericVector< T > > get_subvector(const std::vector< numeric_index_type > &)
virtual void create_subvector(NumericVector< T > &, const std::vector< numeric_index_type > &, bool=true) const
static std::unique_ptr< NumericVector< T > > build(const Parallel::Communicator &comm, SolverPackage solver_package=libMesh::default_solver_package(), ParallelType parallel_type=AUTOMATIC)
virtual void restore_subvector(std::unique_ptr< NumericVector< T > >, const std::vector< numeric_index_type > &)
const Parallel::Communicator & comm() const
void get_all_variable_numbers(std::vector< unsigned int > &all_variable_numbers) const
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
auto index_range(const T &sizable)
SolverPackage default_solver_package()