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" 30 template <
typename Base>
38 "topsplit",
"Entrance to splits, the top split will specify how splits will go.");
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.");
48 template <
typename Base>
52 _nl(this->_fe_problem.getNonlinearSystemBase(this->_nl_sys_num)),
53 _decomposition_split(this->template getParam<
std::string>(
"topsplit"))
56 mooseError(
"The field split preconditioner can only be used with PETSc");
63 bool full = this->
template getParam<bool>(
"full");
66 std::unique_ptr<CouplingMatrix> cm = std::make_unique<CouplingMatrix>(
n_vars);
69 if (this->isParamValid(
"off_diag_row") && this->isParamValid(
"off_diag_column"))
72 const auto off_diag_rows =
73 this->
template getParam<std::vector<NonlinearVariableName>>(
"off_diag_row");
74 const auto off_diag_columns =
75 this->
template getParam<std::vector<NonlinearVariableName>>(
"off_diag_column");
78 for (
unsigned int i = 0; i <
n_vars; i++)
82 std::vector<std::vector<unsigned int>> off_diag(
n_vars);
83 if (off_diag_rows.size() * off_diag_columns.size() != 0 &&
84 off_diag_rows.size() == off_diag_columns.size())
89 (*cm)(row, column) = 1;
95 for (
unsigned int i = 0; i <
n_vars; i++)
96 for (
unsigned int j = 0; j <
n_vars; j++)
99 this->setCouplingMatrix(std::move(cm));
105 template <
typename Base>
111 DMCreateMoose(_nl.comm().get(), _nl, dofMap(), system(), _decomposition_split,
dm));
112 LibmeshPetscCallA(_nl.comm().get(),
113 PetscObjectSetOptionsPrefix((PetscObject)*
dm, prefix().c_str()));
114 LibmeshPetscCall(DMSetFromOptions(*
dm));
115 LibmeshPetscCall(DMSetUp(*
dm));
137 DM
dm = LIBMESH_PETSC_NULLPTR;
143 auto *
const petsc_solver =
145 SNES snes = petsc_solver->snes(
prefix().c_str());
147 LibmeshPetscCall(SNESGetDM(snes, &
dm));
150 LibmeshPetscCall(PetscObjectTypeCompare((PetscObject)
dm, DMMOOSE, &ismoose));
155 LibmeshPetscCall(SNESSetDM(snes,
dm));
156 LibmeshPetscCall(DMDestroy(&
dm));
182 LibmeshPetscCall(SNESGetKSP(snes, &ksp));
FieldSplitPreconditionerTempl(const InputParameters ¶meters)
virtual const libMesh::System & system() const override
NonlinearSystemBase & _nl
The nonlinear system this FSP is associated with (convenience reference)
static InputParameters validParams()
Constructor.
virtual void setupDM() override
setup the data management data structure that manages the field split
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
unsigned int number() const
Get variable number coming from libMesh.
FieldSplitPreconditioner(const InputParameters ¶meters)
PetscErrorCode PetscOptionItems *PetscErrorCode DM dm
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver()=0
The following methods are specializations for using the libMesh::Parallel::packed_range_* routines fo...
InputParameters validParams()
virtual KSP getKSP() override
Base class for MOOSE preconditioners.
virtual unsigned int nVariables() const
Get the number of variables in this system.
SolverPackage default_solver_package()
virtual libMesh::DofMap & dofMap()
Gets writeable reference to the dof map.
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.
virtual const libMesh::DofMapBase & dofMap() const override
Implements a preconditioner designed to map onto PETSc's PCFieldSplit.
std::shared_ptr< Split > getSplit(const std::string &name)
Retrieves a split by name.
virtual std::string prefix() const override
std::string _decomposition_split
The decomposition split.
void createMooseDM(DM *dm)
creates the MOOSE data management object
static InputParameters validParams()
std::string prefix() const
registerMooseObjectAliased("MooseApp", FieldSplitPreconditioner, "FSP")
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
PetscErrorCode DMMooseRegisterAll()
void useFieldSplitPreconditioner(FieldSplitPreconditionerBase *fsp)
If called with a non-null object true this system will use a field split preconditioner matrix...
auto index_range(const T &sizable)
virtual libMesh::System & system() override
Get the reference to the libMesh system.