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;
75 MooseUtils::expandAllMatches(all_vars,
vars);
77 catch (std::invalid_argument
const & e)
79 mooseError(
"No variable name match found for '", e.what(),
"'.");
82 for (
const auto j : index_range(
vars))
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"))
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 ...
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
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...
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 ...