16 #include "libmesh/coupling_matrix.h" 17 #include "libmesh/numeric_vector.h" 25 MooseEnum pc_side(
"left right symmetric default",
"default");
27 MooseEnum ksp_norm(
"none preconditioned unpreconditioned natural default",
"unpreconditioned");
29 "ksp_norm", ksp_norm,
"Sets the norm that is used for convergence testing");
32 params.
addParam<std::vector<NonlinearVariableName>>(
34 "The variable names for the off-diagonal rows you want to add into the matrix; they will be " 35 "associated with an off-diagonal column from the same position in off_diag_column.");
36 params.
addParam<std::vector<NonlinearVariableName>>(
38 "The variable names for the off-diagonal columns you want to add into the matrix; they " 39 "will be associated with an off-diagonal row from the same position in off_diag_row.");
42 "Set to true if you want the full set of couplings between variables " 43 "simply for convenience so you don't have to set every off_diag_row " 44 "and off_diag_column combination.");
45 params.
addParam<NonlinearSystemName>(
47 "The nonlinear system whose linearization this preconditioner should be applied to.");
58 _fe_problem(*params.getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base")),
60 isParamValid(
"nl_sys") ? _fe_problem.nlSysNum(getParam<NonlinearSystemName>(
"nl_sys")) : 0),
61 _nl(_fe_problem.getNonlinearSystemBase(_nl_sys_num))
67 bool full = getParam<bool>(
"full");
71 paramError(
"off_diag_row",
"Set full=false to specify the off-diagonal rows manually");
73 paramError(
"off_diag_column",
"Set full=false to specify the off-diagonal columns manually");
81 getParam<NonlinearVariableName, NonlinearVariableName>(
"off_diag_row",
"off_diag_column");
85 "If off-diagonal rows are specified, matching off-diagonal " 86 "columns must be specified as well");
90 "If off-diagonal columns are specified, matching off-diagonal " 91 "rows must be specified as well");
96 const unsigned int from_system,
97 const unsigned int from_var,
99 const unsigned int to_system,
100 const unsigned int to_var,
103 for (
auto & node :
mesh.local_node_ptr_range())
105 unsigned int n_comp = node->n_comp(from_system, from_var);
107 mooseAssert(node->n_comp(from_system, from_var) == node->n_comp(to_system, to_var),
108 "Number of components does not match in each system");
110 for (
unsigned int i = 0; i < n_comp; i++)
112 dof_id_type from_dof = node->dof_number(from_system, from_var, i);
113 dof_id_type to_dof = node->dof_number(to_system, to_var, i);
115 to_vector.
set(to_dof, from_vector(from_dof));
119 for (
auto & elem :
as_range(
mesh.local_elements_begin(),
mesh.local_elements_end()))
121 unsigned int n_comp = elem->n_comp(from_system, from_var);
123 mooseAssert(elem->n_comp(from_system, from_var) == elem->n_comp(to_system, to_var),
124 "Number of components does not match in each system");
126 for (
unsigned int i = 0; i < n_comp; i++)
128 dof_id_type from_dof = elem->dof_number(from_system, from_var, i);
129 dof_id_type to_dof = elem->dof_number(to_system, to_var, i);
131 to_vector.
set(to_dof, from_vector(from_dof));
NonlinearSystemBase & _nl
The nonlinear system whose linearization this preconditioner should be applied to.
static void copyVarValues(MeshBase &mesh, const unsigned int from_system, const unsigned int from_var, const NumericVector< Number > &from_vector, const unsigned int to_system, const unsigned int to_var, NumericVector< Number > &to_vector)
Helper function for copying values associated with variables in vectors from two different systems...
A class for creating restricted objects.
virtual std::size_t numNonlinearSystems() const override
void setPCSide(MooseEnum pcs)
Set the side on which the preconditioner is applied to.
FEProblemBase & _fe_problem
Subproblem this preconditioner is part of.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
MoosePreconditioner(const InputParameters ¶ms)
Every object that can be built by the factory should be derived from this class.
void setCouplingMatrix(std::unique_ptr< CouplingMatrix > cm, const unsigned int nl_sys_num)
Set custom coupling matrix.
SimpleRange< IndexType > as_range(const std::pair< IndexType, IndexType > &p)
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
static InputParameters validParams()
void paramError(const std::string ¶m, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Interface for objects interacting with the PerfGraph.
InputParameters getPetscValidParams()
Returns the PETSc options that are common between Executioners and Preconditioners.
IntRange< T > make_range(T beg, T end)
virtual void set(const numeric_index_type i, const Number value)=0
static InputParameters validParams()
void setCouplingMatrix(std::unique_ptr< CouplingMatrix > cm)
Setup the coupling matrix on the finite element problem.
void setMooseKSPNormType(MooseEnum kspnorm)
Set the norm in which the linear convergence will be measured.