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. The single matrix preconditioner "
45 "defaults this to true for NEWTON and LINEAR solves if no coupling is "
47 params.
addParam<NonlinearSystemName>(
49 "The nonlinear system whose linearization this preconditioner should be applied to.");
60 _fe_problem(*params.getCheckedPointerParam<
FEProblemBase *>(
"_fe_problem_base")),
62 isParamValid(
"nl_sys") ? _fe_problem.nlSysNum(getParam<NonlinearSystemName>(
"nl_sys")) : 0),
63 _nl(_fe_problem.getNonlinearSystemBase(_nl_sys_num))
69 bool full = getParam<bool>(
"full");
73 paramError(
"off_diag_row",
"Set full=false to specify the off-diagonal rows manually");
75 paramError(
"off_diag_column",
"Set full=false to specify the off-diagonal columns manually");
83 getParam<NonlinearVariableName, NonlinearVariableName>(
"off_diag_row",
"off_diag_column");
87 "If off-diagonal rows are specified, matching off-diagonal "
88 "columns must be specified as well");
92 "If off-diagonal columns are specified, matching off-diagonal "
93 "rows must be specified as well");
101 const unsigned int from_system,
102 const unsigned int from_var,
103 const NumericVector<Number> & from_vector,
104 const unsigned int to_system,
105 const unsigned int to_var,
106 NumericVector<Number> & to_vector)
108 for (
auto & node :
mesh.local_node_ptr_range())
110 unsigned int n_comp = node->n_comp(from_system, from_var);
112 mooseAssert(node->n_comp(from_system, from_var) == node->n_comp(to_system, to_var),
113 "Number of components does not match in each system");
115 for (
unsigned int i = 0; i < n_comp; i++)
117 dof_id_type from_dof = node->dof_number(from_system, from_var, i);
118 dof_id_type to_dof = node->dof_number(to_system, to_var, i);
120 to_vector.set(to_dof, from_vector(from_dof));
124 for (
auto & elem : as_range(
mesh.local_elements_begin(),
mesh.local_elements_end()))
126 unsigned int n_comp = elem->n_comp(from_system, from_var);
128 mooseAssert(elem->n_comp(from_system, from_var) == elem->n_comp(to_system, to_var),
129 "Number of components does not match in each system");
131 for (
unsigned int i = 0; i < n_comp; i++)
133 dof_id_type from_dof = elem->dof_number(from_system, from_var, i);
134 dof_id_type to_dof = elem->dof_number(to_system, to_var, i);
136 to_vector.set(to_dof, from_vector(from_dof));
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
void setCouplingMatrix(std::unique_ptr< libMesh::CouplingMatrix > cm, const unsigned int nl_sys_num)
Set custom coupling matrix.
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 ...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Every object that can be built by the factory should be derived from this class.
static InputParameters validParams()
FEProblemBase & _fe_problem
Subproblem this preconditioner is part of.
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.
void setCouplingMatrix(std::unique_ptr< libMesh::CouplingMatrix > cm)
Setup the coupling matrix on the finite element problem.
static InputParameters validParams()
virtual void initialSetup()
Perform some setup tasks such as storing the PETSc options.
MoosePreconditioner(const InputParameters ¶ms)
const unsigned int _nl_sys_num
The nonlinear system number whose linearization this preconditioner should be applied to.
NonlinearSystemBase & _nl
The nonlinear system whose linearization this preconditioner should be applied to.
Interface for objects interacting with the PerfGraph.
A class for creating restricted objects.
void setPCSide(MooseEnum pcs)
Set the side on which the preconditioner is applied to.
void setMooseKSPNormType(MooseEnum kspnorm)
Set the norm in which the linear convergence will be measured.
std::string prefix() const
InputParameters getPetscValidParams()
Returns the PETSc options that are common between Executioners and Preconditioners.
void setSolveTypeFromParams(FEProblemBase &fe_problem, const InputParameters ¶ms)
Sets the FE problem's solve type from the input params.
void storePetscOptions(FEProblemBase &fe_problem, const std::string &prefix, const ParallelParamObject ¶m_object)
Stores the PETSc options supplied from the parameter object on the problem.