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
23{
25
27 "Solve object for a standard/generalized linear or nonlinear eigenvalue problem");
28
30
31 params.addParam<bool>(
32 "matrix_free",
33 false,
34 "Whether or not to use a matrix free fashion to form operators. "
35 "If true, shell matrices will be used and meanwhile a preconditioning matrix"
36 "may be formed as well.");
37
38 params.addParam<bool>(
39 "precond_matrix_free",
40 false,
41 "Whether or not to use a matrix free fashion for forming the preconditioning matrix. "
42 "If true, a shell matrix will be used for preconditioner.");
43
44 params.addParam<bool>("constant_matrices",
45 false,
46 "Whether or not to use constant matrices so that we can use them to form "
47 "residuals on both linear and "
48 "nonlinear iterations");
49
50 params.addParam<bool>(
51 "precond_matrix_includes_eigen",
52 false,
53 "Whether or not to include eigen kernels in the preconditioning matrix. "
54 "If true, the preconditioning matrix could be singular with the converged eigenvalue if the "
55 "full matrix is assembled and the derivative of eigenvalue with respect to the solution "
56 "vector is not considered.");
57
58 params.addPrivateParam<bool>("_use_eigen_value", true);
59
60 params.addParam<Real>("initial_eigenvalue", 1, "Initial eigenvalue");
61 params.addParam<PostprocessorName>(
62 "normalization", "Postprocessor evaluating norm of eigenvector for normalization");
63 params.addParam<Real>("normal_factor",
64 "Normalize eigenvector to make a defined norm equal to this factor");
65
66 params.addParam<bool>("auto_initialization",
67 true,
68 "If true, we will set an initial eigen vector in moose, otherwise EPS "
69 "solver will initialize eigen vector");
70
71 params.addParamNamesToGroup("matrix_free precond_matrix_free constant_matrices "
72 "precond_matrix_includes_eigen",
73 "Matrix and Matrix-Free");
74 params.addParamNamesToGroup("initial_eigenvalue auto_initialization",
75 "Eigenvector and eigenvalue initialization");
76 params.addParamNamesToGroup("normalization normal_factor", "Solution normalization");
77
78 // If Newton and Inverse Power is combined in SLEPc side
79 params.addPrivateParam<bool>("_newton_inverse_power", false);
80
81// Add slepc options and eigen problems
82#ifdef LIBMESH_HAVE_SLEPC
84
86#endif
87 return params;
88}
89
91 : FEProblemSolve(ex),
92 _eigen_problem(*getCheckedPointerParam<EigenProblem *>(
93 "_eigen_problem", "This might happen if you don't have a mesh")),
94 _normalization(isParamValid("normalization") ? &getPostprocessorValue("normalization")
95 : nullptr)
96{
97// Extract and store SLEPc options
98#ifdef LIBMESH_HAVE_SLEPC
99 mooseAssert(_problem.numSolverSystems() == 1,
100 "The Eigenvalue executioner only currently supports a single solver system.");
101
102 const auto & params = ex.parameters();
104
107 _eigen_problem.solverParams(/*solver_sys_num=*/0)._eigen_problem_type);
108
109 // pass two control parameters to eigen problem
111 getParam<unsigned int>("free_power_iterations");
113 getParam<unsigned int>("extra_power_iterations");
114
115 if (!isParamValid("normalization") && isParamValid("normal_factor"))
116 paramError("normal_factor",
117 "Cannot set scaling factor without defining normalization postprocessor.");
118
119 if (isParamValid("normalization"))
120 {
121 const auto & normpp = getParam<PostprocessorName>("normalization");
122 if (isParamValid("normal_factor"))
123 _eigen_problem.setNormalization(normpp, getParam<Real>("normal_factor"));
124 else
126 }
127
128 _eigen_problem.setInitialEigenvalue(getParam<Real>("initial_eigenvalue"));
129
130 // Set a flag to nonlinear eigen system
132 .precondMatrixIncludesEigenKernels(getParam<bool>("precond_matrix_includes_eigen"));
133#else
134 mooseError("SLEPc is required to use Eigenvalue executioner, please use '--download-slepc in "
135 "PETSc configuration'");
136#endif
137 // SLEPc older than 3.13.0 can not take initial guess from moose
138 // It may generate converge issues
139#if PETSC_RELEASE_LESS_THAN(3, 13, 0)
141 "Please use SLEPc-3.13.0 or higher. Old versions of SLEPc likely produce bad convergence");
142#endif
143
144 // To avoid petsc unused option warnings, ensure we do not set irrelevant options.
153}
154
155void
157{
158 if (isParamValid("normalization"))
159 {
160 const auto & normpp = getParam<PostprocessorName>("normalization");
161 const auto & exec = _eigen_problem.getUserObject<UserObject>(normpp).getExecuteOnEnum();
162 if (!exec.isValueSet(EXEC_LINEAR))
163 mooseError("Normalization postprocessor ", normpp, " requires execute_on = 'linear'");
164 }
165
166#ifdef LIBMESH_HAVE_SLEPC
167 // Options need to be setup once only
169 {
170 // Parent application has the default data base
171 if (!_app.isUltimateMaster())
172 LibmeshPetscCall(PetscOptionsPush(_eigen_problem.petscOptionsDatabase()));
174 _eigen_problem, _eigen_problem.solverParams(/*eigen_sys_num=*/0), _pars);
175 if (!_app.isUltimateMaster())
176 LibmeshPetscCall(PetscOptionsPop());
178 }
179#endif
180}
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:32
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)