10#include "libmesh/petsc_macro.h"
24#include "libmesh/libmesh_common.h"
25#include "libmesh/petsc_nonlinear_solver.h"
26#include "libmesh/coupling_matrix.h"
28template <
typename Base>
36 "topsplit",
"Entrance to splits, the top split will specify how splits will go.");
40 "Set to true if you want the full set of couplings between variables "
41 "simply for convenience so you don't have to set every off_diag_row "
42 "and off_diag_column combination.");
46template <
typename Base>
50 _nl(this->_fe_problem.getNonlinearSystemBase(this->_nl_sys_num)),
51 _decomposition_split(this->template getParam<
std::string>(
"topsplit"))
54 mooseError(
"The field split preconditioner can only be used with PETSc");
61 bool full = this->
template getParam<bool>(
"full");
64 std::unique_ptr<CouplingMatrix> cm = std::make_unique<CouplingMatrix>(n_vars);
67 if (this->isParamValid(
"off_diag_row") && this->isParamValid(
"off_diag_column"))
70 const auto off_diag_rows =
71 this->
template getParam<std::vector<NonlinearVariableName>>(
"off_diag_row");
72 const auto off_diag_columns =
73 this->
template getParam<std::vector<NonlinearVariableName>>(
"off_diag_column");
76 for (
unsigned int i = 0; i <
n_vars; i++)
80 std::vector<std::vector<unsigned int>> off_diag(n_vars);
81 if (off_diag_rows.size() * off_diag_columns.size() != 0 &&
82 off_diag_rows.size() == off_diag_columns.size())
83 for (
const auto i : index_range(off_diag_rows))
87 (*cm)(row, column) = 1;
93 for (
unsigned int i = 0; i <
n_vars; i++)
94 for (
unsigned int j = 0; j <
n_vars; j++)
97 this->setCouplingMatrix(std::move(cm));
103template <
typename Base>
109 DMCreateMoose(_nl.comm().get(), _nl, dofMap(), system(), _decomposition_split,
dm));
110 LibmeshPetscCallA(_nl.comm().get(),
111 PetscObjectSetOptionsPrefix((PetscObject)*
dm, prefix().c_str()));
112 LibmeshPetscCall(DMSetFromOptions(*
dm));
113 LibmeshPetscCall(DMSetUp(*
dm));
135 DM
dm = LIBMESH_PETSC_NULLPTR;
141 auto *
const petsc_solver =
143 SNES snes = petsc_solver->snes(
prefix().c_str());
145 LibmeshPetscCall(SNESGetDM(snes, &
dm));
148 LibmeshPetscCall(PetscObjectTypeCompare((PetscObject)
dm, DMMOOSE, &ismoose));
153 LibmeshPetscCall(SNESSetDM(snes,
dm));
154 LibmeshPetscCall(DMDestroy(&
dm));
180 LibmeshPetscCall(SNESGetKSP(snes, &ksp));
registerMooseObjectAliased("MooseApp", FieldSplitPreconditioner, "FSP")
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
PetscErrorCode PetscOptionItems *PetscErrorCode DM dm
PetscErrorCode DMCreateMoose(MPI_Comm comm, NonlinearSystemBase &nl, const libMesh::DofMapBase &dof_map, const libMesh::System &system, const std::string &dm_name, DM *dm)
Create a MOOSE DM.
PetscErrorCode DMMooseRegisterAll()
Implements a preconditioner designed to map onto PETSc's PCFieldSplit.
FieldSplitPreconditionerTempl(const InputParameters ¶meters)
static InputParameters validParams()
Constructor.
std::string _decomposition_split
The decomposition split.
NonlinearSystemBase & _nl
The nonlinear system this FSP is associated with (convenience reference)
void createMooseDM(DM *dm)
creates the MOOSE data management object
virtual void setupDM() override
setup the data management data structure that manages the field split
virtual const libMesh::System & system() const override
virtual std::string prefix() const override
static InputParameters validParams()
FieldSplitPreconditioner(const InputParameters ¶meters)
virtual const libMesh::DofMapBase & dofMap() const override
virtual KSP getKSP() override
Base class for MOOSE preconditioners.
unsigned int number() const
Get variable number coming from libMesh.
void useFieldSplitPreconditioner(FieldSplitPreconditionerBase *fsp)
If called with a non-null object true this system will use a field split preconditioner matrix.
std::shared_ptr< Split > getSplit(const std::string &name)
Retrieves a split by name.
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver()=0
virtual libMesh::System & system() override
Get the reference to the libMesh system.
std::string prefix() const
virtual unsigned int nVariables() const
Get the number of variables in this system.
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
virtual libMesh::DofMap & dofMap()
Gets writeable reference to the dof map.
SolverPackage default_solver_package()