18 #include "libmesh/coupling_matrix.h" 27 params.
addClassDescription(
"Single matrix preconditioner (SMP) builds a preconditioner using " 28 "user defined off-diagonal parts of the Jacobian.");
30 params.
addParam<std::vector<NonlinearVariableName>>(
33 "List multiple space separated groups of comma separated variables. " 34 "Off-diagonal jacobians will be generated for all pairs within a group.");
38 "Whether to trust my coupling even if the framework wants to be paranoid and create a full " 39 "coupling matrix, which can happen when using global AD indexing for example.");
49 const auto & libmesh_system = nl.
system();
50 auto cm = std::make_unique<CouplingMatrix>(
n_vars);
52 if (!getParam<bool>(
"full"))
55 for (
unsigned int i = 0; i <
n_vars; ++i)
59 for (
const auto & off_diag :
60 getParam<NonlinearVariableName, NonlinearVariableName>(
"off_diag_row",
"off_diag_column"))
62 const auto row = libmesh_system.variable_number(off_diag.first);
63 const auto column = libmesh_system.variable_number(off_diag.second);
64 (*cm)(row, column) = 1;
69 for (
const auto & group :
getParam<std::vector<NonlinearVariableName>>(
"coupled_groups"))
71 std::vector<VariableName> vars;
77 catch (std::invalid_argument
const & e)
79 mooseError(
"No variable name match found for '", e.what(),
"'.");
83 for (
unsigned int k = j + 1; k < vars.size(); ++k)
85 const auto row = libmesh_system.variable_number(vars[j]);
86 const auto column = libmesh_system.variable_number(vars[k]);
87 (*cm)(row, column) = 1;
88 (*cm)(column, row) = 1;
94 for (
unsigned int i = 0; i <
n_vars; ++i)
95 for (
unsigned int j = 0; j <
n_vars; ++j)
100 if (getParam<bool>(
"trust_my_coupling"))
void tokenize(const std::string &str, std::vector< T > &elements, unsigned int min_len=1, const std::string &delims="/")
This function will split the passed in string on a set of delimiters appending the substrings to the ...
void trustUserCouplingMatrix()
Whether to trust the user coupling matrix even if we want to do things like be paranoid and create a ...
registerMooseObjectAliased("MooseApp", SingleMatrixPreconditioner, "SMP")
const unsigned int _nl_sys_num
The nonlinear system number whose linearization this preconditioner should be applied to...
FEProblemBase & _fe_problem
Subproblem this preconditioner is part of.
static InputParameters validParams()
Base class for MOOSE preconditioners.
virtual unsigned int nVariables() const
Get the number of variables in this system.
Nonlinear system to be solved.
void expandAllMatches(const std::vector< T > &candidates, std::vector< T > &patterns)
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
static InputParameters validParams()
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
virtual System & system() override
Get the reference to the libMesh system.
const std::vector< VariableName > & getVariableNames() const
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
Single matrix preconditioner.
SingleMatrixPreconditioner(const InputParameters ¶ms)
void setCouplingMatrix(std::unique_ptr< CouplingMatrix > cm)
Setup the coupling matrix on the finite element problem.
auto index_range(const T &sizable)