https://mooseframework.inl.gov
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
FieldSplitPreconditionerTempl< Base > Class Template Referenceabstract

Implements a preconditioner designed to map onto PETSc's PCFieldSplit. More...

#include <FieldSplitPreconditioner.h>

Inheritance diagram for FieldSplitPreconditionerTempl< Base >:
[legend]

Public Member Functions

 FieldSplitPreconditionerTempl (const InputParameters &parameters)
 
virtual void setupDM ()=0
 setup the data management data structure that manages the field split
 
virtual KSP getKSP ()=0
 

Static Public Member Functions

static InputParameters validParams ()
 Constructor.
 

Protected Member Functions

virtual const libMesh::DofMapBasedofMap () const =0
 
virtual const libMesh::Systemsystem () const =0
 
virtual std::string prefix () const =0
 
void createMooseDM (DM *dm)
 creates the MOOSE data management object
 

Protected Attributes

NonlinearSystemBase_nl
 The nonlinear system this FSP is associated with (convenience reference)
 
std::string _decomposition_split
 The decomposition split.
 

Detailed Description

template<typename Base>
class FieldSplitPreconditionerTempl< Base >

Implements a preconditioner designed to map onto PETSc's PCFieldSplit.

Definition at line 48 of file FieldSplitPreconditioner.h.

Constructor & Destructor Documentation

◆ FieldSplitPreconditionerTempl()

template<typename Base >
FieldSplitPreconditionerTempl< Base >::FieldSplitPreconditionerTempl ( const InputParameters parameters)

Definition at line 47 of file FieldSplitPreconditioner.C.

49 : Base(parameters),
50 _nl(this->_fe_problem.getNonlinearSystemBase(this->_nl_sys_num)),
51 _decomposition_split(this->template getParam<std::string>("topsplit"))
52{
54 mooseError("The field split preconditioner can only be used with PETSc");
55
56 // number of variables
57 unsigned int n_vars = _nl.nVariables();
58 // if we want to construct a full Jacobian?
59 // it is recommended to have a full Jacobian for using
60 // the fieldSplit preconditioner
61 bool full = this->template getParam<bool>("full");
62
63 // how variables couple
64 std::unique_ptr<CouplingMatrix> cm = std::make_unique<CouplingMatrix>(n_vars);
65 if (!full)
66 {
67 if (this->isParamValid("off_diag_row") && this->isParamValid("off_diag_column"))
68 {
69
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");
74
75 // put 1s on diagonal
76 for (unsigned int i = 0; i < n_vars; i++)
77 (*cm)(i, i) = 1;
78
79 // off-diagonal entries
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))
84 {
85 unsigned int row = _nl.getVariable(0, off_diag_rows[i]).number();
86 unsigned int column = _nl.getVariable(0, off_diag_columns[i]).number();
87 (*cm)(row, column) = 1;
88 }
89 }
90 }
91 else
92 {
93 for (unsigned int i = 0; i < n_vars; i++)
94 for (unsigned int j = 0; j < n_vars; j++)
95 (*cm)(i, j) = 1; // full coupling
96 }
97 this->setCouplingMatrix(std::move(cm));
98
99 // turn on a flag
101}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int n_vars
std::string _decomposition_split
The decomposition split.
NonlinearSystemBase & _nl
The nonlinear system this FSP is associated with (convenience reference)
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.
virtual unsigned int nVariables() const
Get the number of variables in this system.
Definition SystemBase.C:890
MooseVariableFieldBase & getVariable(THREAD_ID tid, const std::string &var_name) const
Gets a reference to a variable of with specified name.
Definition SystemBase.C:89
auto index_range(const T &sizable)
SolverPackage default_solver_package()

Member Function Documentation

◆ createMooseDM()

template<typename Base >
void FieldSplitPreconditionerTempl< Base >::createMooseDM ( DM *  dm)
protected

creates the MOOSE data management object

Definition at line 105 of file FieldSplitPreconditioner.C.

106{
107 LibmeshPetscCallA(
108 _nl.comm().get(),
110 LibmeshPetscCallA(_nl.comm().get(),
111 PetscObjectSetOptionsPrefix((PetscObject)*dm, prefix().c_str()));
112 LibmeshPetscCall(DMSetFromOptions(*dm));
113 LibmeshPetscCall(DMSetUp(*dm));
114}
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.
virtual std::string prefix() const =0
virtual const libMesh::DofMapBase & dofMap() const =0
virtual const libMesh::System & system() const =0
const Parallel::Communicator & comm() const

◆ dofMap()

template<typename Base >
virtual const libMesh::DofMapBase & FieldSplitPreconditionerTempl< Base >::dofMap ( ) const
protectedpure virtual
Returns
The degree of freedom map to use for decomposition

Implemented in FieldSplitPreconditioner, and StaticCondensationFieldSplitPreconditioner.

◆ getKSP()

virtual KSP FieldSplitPreconditionerBase::getKSP ( )
pure virtualinherited
Returns
The KSP object associated with the field split preconditioner

Implemented in FieldSplitPreconditioner, and StaticCondensationFieldSplitPreconditioner.

◆ prefix()

template<typename Base >
virtual std::string FieldSplitPreconditionerTempl< Base >::prefix ( ) const
protectedpure virtual
Returns
The prefix to pass to PETSc for the DM

Implemented in FieldSplitPreconditioner, and StaticCondensationFieldSplitPreconditioner.

◆ setupDM()

virtual void FieldSplitPreconditionerBase::setupDM ( )
pure virtualinherited

setup the data management data structure that manages the field split

Implemented in FieldSplitPreconditioner, and StaticCondensationFieldSplitPreconditioner.

Referenced by NonlinearSystemBase::setupDM().

◆ system()

template<typename Base >
virtual const libMesh::System & FieldSplitPreconditionerTempl< Base >::system ( ) const
protectedpure virtual

◆ validParams()

template<typename Base >
InputParameters FieldSplitPreconditionerTempl< Base >::validParams ( )
static

Constructor.

Initializes SplitBasedPreconditioner data structures

Definition at line 30 of file FieldSplitPreconditioner.C.

31{
32 InputParameters params = Base::validParams();
33 params.addClassDescription("Preconditioner designed to map onto PETSc's PCFieldSplit.");
34
35 params.addRequiredParam<std::string>(
36 "topsplit", "Entrance to splits, the top split will specify how splits will go.");
37 // We should use full coupling Jacobian matrix by default
38 params.addParam<bool>("full",
39 true,
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.");
43 return params;
44}
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.

Referenced by FieldSplitPreconditioner::validParams(), and StaticCondensationFieldSplitPreconditioner::validParams().

Member Data Documentation

◆ _decomposition_split

template<typename Base >
std::string FieldSplitPreconditionerTempl< Base >::_decomposition_split
protected

The decomposition split.

Definition at line 85 of file FieldSplitPreconditioner.h.

◆ _nl

template<typename Base >
NonlinearSystemBase& FieldSplitPreconditionerTempl< Base >::_nl
protected

The nonlinear system this FSP is associated with (convenience reference)

Definition at line 80 of file FieldSplitPreconditioner.h.


The documentation for this class was generated from the following files: