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);
56 const bool full = getParam<bool>(
"full") ||
58 getParam<std::vector<NonlinearVariableName>>(
"coupled_groups").empty() &&
64 for (
unsigned int i = 0; i <
n_vars; ++i)
68 for (
const auto & off_diag :
69 getParam<NonlinearVariableName, NonlinearVariableName>(
"off_diag_row",
"off_diag_column"))
71 const auto row = libmesh_system.variable_number(off_diag.first);
72 const auto column = libmesh_system.variable_number(off_diag.second);
73 (*cm)(row, column) = 1;
78 for (
const auto & group : getParam<std::vector<NonlinearVariableName>>(
"coupled_groups"))
80 std::vector<VariableName>
vars;
84 MooseUtils::expandAllMatches(all_vars,
vars);
86 catch (std::invalid_argument
const & e)
88 mooseError(
"No variable name match found for '", e.what(),
"'.");
91 for (
const auto j : index_range(
vars))
92 for (
unsigned int k = j + 1; k <
vars.size(); ++k)
94 const auto row = libmesh_system.variable_number(
vars[j]);
95 const auto column = libmesh_system.variable_number(
vars[k]);
96 (*cm)(row, column) = 1;
97 (*cm)(column, row) = 1;
103 for (
unsigned int i = 0; i <
n_vars; ++i)
104 for (
unsigned int j = 0; j <
n_vars; ++j)
109 if (getParam<bool>(
"trust_my_coupling"))
registerMooseObjectAliased("MooseApp", SingleMatrixPreconditioner, "SMP")
void trustUserCouplingMatrix()
Whether to trust the user coupling matrix even if we want to do things like be paranoid and create a ...
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
bool isParamSetByUser(const std::string &name) const
Test if the supplied parameter is set by a user, as opposed to not set or set to default.
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...
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Base class for MOOSE preconditioners.
FEProblemBase & _fe_problem
Subproblem this preconditioner is part of.
void setCouplingMatrix(std::unique_ptr< libMesh::CouplingMatrix > cm)
Setup the coupling matrix on the finite element problem.
static InputParameters validParams()
const unsigned int _nl_sys_num
The nonlinear system number whose linearization this preconditioner should be applied to.
Nonlinear system to be solved.
virtual libMesh::System & system() override
Get the reference to the libMesh system.
Single matrix preconditioner.
static InputParameters validParams()
SingleMatrixPreconditioner(const InputParameters ¶ms)
virtual unsigned int nVariables() const
Get the number of variables in this system.
const std::vector< VariableName > & getVariableNames() const
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 ...
@ ST_LINEAR
Solving a linear problem.
@ ST_NEWTON
Full Newton Solve.