www.mooseframework.org
FieldSplitPreconditioner.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
3 //*
4 //* All rights reserved, see COPYRIGHT for full restrictions
5 //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
6 //*
7 //* Licensed under LGPL 2.1, please see LICENSE for details
8 //* https://www.gnu.org/licenses/lgpl-2.1.html
9 
10 #include "libmesh/petsc_macro.h"
11 #if defined(LIBMESH_HAVE_PETSC) && !PETSC_VERSION_LESS_THAN(3, 3, 0)
13 
14 // MOOSE includes
15 #include "FEProblem.h"
16 #include "MooseEnum.h"
17 #include "MooseVariableFE.h"
18 #include "NonlinearSystem.h"
19 #include "PetscSupport.h"
20 
21 #include "libmesh/libmesh_common.h"
22 #include "libmesh/petsc_nonlinear_solver.h"
23 #include "libmesh/coupling_matrix.h"
24 
26 
27 template <>
30 {
32 
33  params.addParam<std::vector<std::string>>(
34  "off_diag_row",
35  "The off diagonal row you want to add into the matrix, it will be associated "
36  "with an off diagonal column from the same position in off_diag_colum.");
37  params.addParam<std::vector<std::string>>("off_diag_column",
38  "The off diagonal column you want to add into the "
39  "matrix, it will be associated with an off diagonal "
40  "row from the same position in off_diag_row.");
41  // We should use full coupling Jacobian matrix by default
42  params.addParam<bool>("full",
43  true,
44  "Set to true if you want the full set of couplings. Simply "
45  "for convenience so you don't have to set every off_diag_row "
46  "and off_diag_column combination.");
47  params.addRequiredParam<std::vector<std::string>>(
48  "topsplit", "entrance to splits, the top split will specify how splits will go.");
49  return params;
50 }
51 
53  : MoosePreconditioner(parameters),
54  _top_split(getParam<std::vector<std::string>>("topsplit")),
55  _nl(_fe_problem.getNonlinearSystemBase())
56 {
57  // number of variables
58  unsigned int n_vars = _nl.nVariables();
59  // if we want to construct a full Jacobian?
60  // it is recommended to have a full Jacobian for using
61  // the fieldSplit preconditioner
62  bool full = getParam<bool>("full");
63  // how variables couple
64  std::unique_ptr<CouplingMatrix> cm = libmesh_make_unique<CouplingMatrix>(n_vars);
65  if (!full)
66  {
67  // put 1s on diagonal
68  for (unsigned int i = 0; i < n_vars; i++)
69  (*cm)(i, i) = 1;
70 
71  // off-diagonal entries
72  std::vector<std::vector<unsigned int>> off_diag(n_vars);
73  for (unsigned int i = 0; i < getParam<std::vector<std::string>>("off_diag_row").size(); i++)
74  {
75  unsigned int row =
76  _nl.getVariable(0, getParam<std::vector<std::string>>("off_diag_row")[i]).number();
77  unsigned int column =
78  _nl.getVariable(0, getParam<std::vector<std::string>>("off_diag_column")[i]).number();
79  (*cm)(row, column) = 1;
80  }
81  }
82  else
83  {
84  for (unsigned int i = 0; i < n_vars; i++)
85  for (unsigned int j = 0; j < n_vars; j++)
86  (*cm)(i, j) = 1; // full coupling
87  }
88  _fe_problem.setCouplingMatrix(std::move(cm));
89 
90  // turn on a flag
92 
93  // set a top splitting
95 
96  // apply prefix and store PETSc options
98 }
99 
100 #endif
Implements a preconditioner designed to map onto PETSc&#39;s PCFieldSplit.
NonlinearSystemBase & getNonlinearSystemBase()
unsigned int number() const
Get variable number coming from libMesh.
FieldSplitPreconditioner(const InputParameters &parameters)
Constructor.
void setDecomposition(const std::vector< std::string > &decomposition)
If called with a single string, it is used as the name of a the top-level decomposition split...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void setCouplingMatrix(std::unique_ptr< CouplingMatrix > cm)
Set custom coupling matrix.
void useFieldSplitPreconditioner(bool use=true)
If called with true this system will use a field split preconditioner matrix.
FEProblemBase & _fe_problem
Subproblem this preconditioner is part of.
InputParameters validParams< MoosePreconditioner >()
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:191
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...
Base class for MOOSE preconditioners.
NonlinearSystemBase & _nl
The nonlinear system this FSP is associated with (convenience reference)
virtual unsigned int nVariables() const
Get the number of variables in this system.
Definition: SystemBase.C:692
MooseVariableFEBase & getVariable(THREAD_ID tid, const std::string &var_name)
Gets a reference to a variable of with specified name.
Definition: SystemBase.C:105
InputParameters validParams< FieldSplitPreconditioner >()
std::vector< std::string > _top_split
top split
registerMooseObjectAliased("MooseApp", FieldSplitPreconditioner, "FSP")
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...