https://mooseframework.inl.gov
Loading...
Searching...
No Matches
EigenProblemSolve.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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// MOOSE includes
11#include "EigenProblem.h"
12#include "Factory.h"
13#include "MooseApp.h"
15#include "PetscSupport.h"
16#include "SlepcSupport.h"
17#include "UserObject.h"
18
19#include "libmesh/petsc_solver_exception.h"
20
21// Needed for LIBMESH_CHECK_ERR
23
26{
28
30 "Solve object for a standard/generalized linear or nonlinear eigenvalue problem");
31
33
34 params.addParam<bool>(
35 "matrix_free",
36 false,
37 "Whether or not to use a matrix free fashion to form operators. "
38 "If true, shell matrices will be used and meanwhile a preconditioning matrix"
39 "may be formed as well.");
40
41 params.addParam<bool>(
42 "precond_matrix_free",
43 false,
44 "Whether or not to use a matrix free fashion for forming the preconditioning matrix. "
45 "If true, a shell matrix will be used for preconditioner.");
46
47 params.addParam<bool>("constant_matrices",
48 false,
49 "Whether or not to use constant matrices so that we can use them to form "
50 "residuals on both linear and "
51 "nonlinear iterations");
52
53 params.addParam<bool>(
54 "precond_matrix_includes_eigen",
55 false,
56 "Whether or not to include eigen kernels in the preconditioning matrix. "
57 "If true, the preconditioning matrix could be singular with the converged eigenvalue if the "
58 "full matrix is assembled and the derivative of eigenvalue with respect to the solution "
59 "vector is not considered.");
60
61 params.addPrivateParam<bool>("_use_eigen_value", true);
62
63 params.addParam<Real>("initial_eigenvalue", 1, "Initial eigenvalue");
64 params.addParam<PostprocessorName>(
65 "normalization", "Postprocessor evaluating norm of eigenvector for normalization");
66 params.addParam<Real>("normal_factor",
67 "Normalize eigenvector to make a defined norm equal to this factor");
68
69 params.addParam<bool>("auto_initialization",
70 true,
71 "If true, we will set an initial eigen vector in moose, otherwise EPS "
72 "solver will initialize eigen vector");
73
74 params.addParamNamesToGroup("matrix_free precond_matrix_free constant_matrices "
75 "precond_matrix_includes_eigen",
76 "Matrix and Matrix-Free");
77 params.addParamNamesToGroup("initial_eigenvalue auto_initialization",
78 "Eigenvector and eigenvalue initialization");
79 params.addParamNamesToGroup("normalization normal_factor", "Solution normalization");
80
81 // If Newton and Inverse Power is combined in SLEPc side
82 params.addPrivateParam<bool>("_newton_inverse_power", false);
83
84// Add slepc options and eigen problems
85#ifdef LIBMESH_HAVE_SLEPC
87
89#endif
90 return params;
91}
92
94 : FEProblemSolve(ex),
95 _eigen_problem(*getCheckedPointerParam<EigenProblem *>(
96 "_eigen_problem", "This might happen if you don't have a mesh")),
97 _normalization(isParamValid("normalization") ? &getPostprocessorValue("normalization")
98 : nullptr)
99{
100// Extract and store SLEPc options
101#ifdef LIBMESH_HAVE_SLEPC
102 mooseAssert(_problem.numSolverSystems() == 1,
103 "The Eigenvalue executioner only currently supports a single solver system.");
104
105 const auto & params = ex.parameters();
107
110 _eigen_problem.solverParams(/*solver_sys_num=*/0)._eigen_problem_type);
111
112 // pass two control parameters to eigen problem
114 getParam<unsigned int>("free_power_iterations");
116 getParam<unsigned int>("extra_power_iterations");
117
118 if (!isParamValid("normalization") && isParamValid("normal_factor"))
119 paramError("normal_factor",
120 "Cannot set scaling factor without defining normalization postprocessor.");
121
122 if (isParamValid("normalization"))
123 {
124 const auto & normpp = getParam<PostprocessorName>("normalization");
125 if (isParamValid("normal_factor"))
126 _eigen_problem.setNormalization(normpp, getParam<Real>("normal_factor"));
127 else
129 }
130
131 _eigen_problem.setInitialEigenvalue(getParam<Real>("initial_eigenvalue"));
132
133 // Set a flag to nonlinear eigen system
135 .precondMatrixIncludesEigenKernels(getParam<bool>("precond_matrix_includes_eigen"));
136#else
137 mooseError("SLEPc is required to use Eigenvalue executioner, please use '--download-slepc in "
138 "PETSc configuration'");
139#endif
140 // SLEPc older than 3.13.0 can not take initial guess from moose
141 // It may generate converge issues
142#if PETSC_RELEASE_LESS_THAN(3, 13, 0)
144 "Please use SLEPc-3.13.0 or higher. Old versions of SLEPc likely produce bad convergence");
145#endif
146
147 // To avoid petsc unused option warnings, ensure we do not set irrelevant options.
156}
157
158void
160{
161 if (isParamValid("normalization"))
162 {
163 const auto & normpp = getParam<PostprocessorName>("normalization");
164 const auto & exec = _eigen_problem.getUserObject<UserObject>(normpp).getExecuteOnEnum();
165 if (!exec.isValueSet(EXEC_LINEAR))
166 mooseError("Normalization postprocessor ", normpp, " requires execute_on = 'linear'");
167 }
168
169#ifdef LIBMESH_HAVE_SLEPC
170 // Options need to be setup once only
172 {
173 // Parent application has the default data base
174 if (!_app.isUltimateMaster())
175 LibmeshPetscCall(PetscOptionsPush(_eigen_problem.petscOptionsDatabase()));
177 _eigen_problem, _eigen_problem.solverParams(/*eigen_sys_num=*/0), _pars);
178 if (!_app.isUltimateMaster())
179 LibmeshPetscCall(PetscOptionsPop());
181 }
182#endif
183}
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const ExecFlagType EXEC_LINEAR
Definition Moose.C:31
EigenProblem & _eigen_problem
EigenProblemSolve(Executioner &ex)
virtual void initialSetup() override
Method that should be executed once, before any solve calls.
static InputParameters validParams()
Problem for solving eigenvalue problems.
void setNormalization(const PostprocessorName &pp, const Real value=std::numeric_limits< Real >::max())
Set postprocessor and normalization factor 'Postprocessor' is often used to compute an integral of ph...
void setInitialEigenvalue(const Real initial_eigenvalue)
Set an initial eigenvalue for initial normalization.
NonlinearEigenSystem & getNonlinearEigenSystem(const unsigned int nl_sys_num)
void setEigenproblemType(Moose::EigenProblemType eigen_problem_type)
Set eigen problem type.
Executioners are objects that do the actual work of solving your problem.
Definition Executioner.h:37
static InputParameters validParams()
Definition Executioner.C:26
PetscOptions & petscOptionsDatabase()
T & getUserObject(const std::string &name, unsigned int tid=0) const
Get the user object by its name.
virtual std::size_t numSolverSystems() const override
bool & petscOptionsInserted()
If PETSc options are already inserted.
SolverParams & solverParams(unsigned int solver_sys_num=0)
Get the solver parameters.
Moose::PetscSupport::PetscOptions & getPetscOptions()
Retrieve a writable reference the PETSc options (used by PetscSupport)
static InputParameters validParams()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...
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 addPrivateParam(const std::string &name, const T &value)
These method add a parameter to the InputParameters object which can be retrieved like any other para...
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.
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition MooseApp.h:866
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457
const InputParameters & _pars
The object's parameters.
Definition MooseBase.h:384
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
void precondMatrixIncludesEigenKernels(bool precond_matrix_includes_eigen)
If the preconditioning matrix includes eigen kernels.
FEProblemBase & _problem
Reference to FEProblem.
Definition SolveObject.h:47
unsigned int _free_power_iterations
unsigned int _extra_power_iterations
Moose::EigenProblemType _eigen_problem_type
bool _eigen_matrix_free
Base class for user-specific data.
Definition UserObject.h:20
void dontAddLinearConvergedReason(FEProblemBase &fe_problem)
Function to ensure that -ksp_converged_reason is not added to the PetscOptions storage object to be l...
void dontAddPetscFlag(const std::string &flag, PetscOptions &petsc_options)
Function to ensure that a particular petsc option is not added to the PetscOptions storage object to ...
void dontAddNonlinearConvergedReason(FEProblemBase &fe_problem)
Function to ensure that -snes_converged_reason is not added to the PetscOptions storage object to be ...
void slepcSetOptions(EigenProblem &eigen_problem, SolverParams &solver_params, const InputParameters &params)
Push all SLEPc/PETSc options into SLEPc/PETSc side.
InputParameters getSlepcEigenProblemValidParams()
Retrieve valid params that allow users to specify eigen problem configuration.
InputParameters getSlepcValidParams(InputParameters &params)
void setEigenProblemSolverParams(EigenProblem &eigen_problem, const InputParameters &params)
Retrieve eigen problem params from 'params', and then set these params into SolverParams.
void storeSolveType(FEProblemBase &fe_problem, const InputParameters &params)
Set solve type into eigen problem (solverParams)