https://mooseframework.inl.gov
Loading...
Searching...
No Matches
EigenProblem.h
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#pragma once
11
12// MOOSE Includes
13#include "FEProblemBase.h"
14#include "Eigenvalue.h"
15
17
22{
23public:
25
27
28 virtual std::string solverTypeString(unsigned int solver_sys_num = 0) override;
29
30#ifdef LIBMESH_HAVE_SLEPC
31 virtual void solve(const unsigned int nl_sys_num) override;
32
33 virtual void init() override;
34
35 virtual bool solverSystemConverged(const unsigned int solver_sys_num) override;
36
37 unsigned int getNEigenPairsRequired() const { return _n_eigen_pairs_required; }
38 void setNEigenPairsRequired(unsigned int n_eigen_pairs)
39 {
40 _n_eigen_pairs_required = n_eigen_pairs;
41 }
43 bool isNonlinearEigenvalueSolver(unsigned int eigen_sys_num) const;
44 // silences warning in debug mode about the other computeJacobian signature being hidden
46
47 NonlinearEigenSystem & getNonlinearEigenSystem(const unsigned int nl_sys_num);
49
50 virtual void checkProblemIntegrity() override;
51
58
63 void setNormalization(const PostprocessorName & pp,
64 const Real value = std::numeric_limits<Real>::max());
65
69 void setInitialEigenvalue(const Real initial_eigenvalue)
70 {
71 _initial_eigenvalue = initial_eigenvalue;
72 }
73
80
84 void doFreePowerIteration(bool do_power) { _do_free_power_iteration = do_power; }
85
93 void preScaleEigenVector(const std::pair<Real, Real> & eig);
94
100
104 void scaleEigenvector(const Real scaling_factor);
105
110
115 virtual Real computeResidualL2Norm() override;
116
120 virtual void computeJacobianTag(const NumericVector<Number> & soln,
121 SparseMatrix<Number> & jacobian,
122 TagID tag) override;
123
127 void computeMatricesTags(const NumericVector<Number> & soln,
128 const std::vector<SparseMatrix<Number> *> & jacobians,
129 const std::set<TagID> & tags);
130
135 void computeJacobianAB(const NumericVector<Number> & soln,
136 SparseMatrix<Number> & jacobianA,
137 SparseMatrix<Number> & jacobianB,
138 TagID tagA,
139 TagID tagB);
140
141 virtual void computeJacobianBlocks(std::vector<JacobianBlock *> & blocks,
142 const unsigned int nl_sys_num) override;
143
147 virtual void computeResidualTag(const NumericVector<Number> & soln,
148 NumericVector<Number> & residual,
149 TagID tag) override;
150
155 void computeResidualAB(const NumericVector<Number> & soln,
156 NumericVector<Number> & residualA,
157 NumericVector<Number> & residualB,
158 TagID tagA,
159 TagID tagB);
160
165 virtual void execute(const ExecFlagType & exec_type) override;
166
171 void initEigenvector(const Real initial_value);
172
176 unsigned int activeEigenvalueIndex() const { return _active_eigen_index; }
177
181 virtual void initPetscOutputAndSomeSolverSettings() override;
182
188
192 void outputInverseEigenvalue(bool inverse) { _output_inverse_eigenvalue = inverse; }
193
197 bool onLinearSolver() const { return _on_linear_solver; }
198
202 void onLinearSolver(bool ols) { _on_linear_solver = ols; }
203
207 bool constantMatrices() const { return _constant_matrices; }
208
212 void constantMatrices(bool cm) { _constant_matrices = cm; }
213
217 bool wereMatricesFormed() const { return _matrices_formed; }
218
222 void wereMatricesFormed(bool mf) { _matrices_formed = mf; }
223
227 Real formNorm();
228
232 bool bxNormProvided() const { return _bx_norm_name.has_value(); }
233
237 void setBxNorm(const PostprocessorName & bx_norm) { _bx_norm_name = bx_norm; }
238
239protected:
242 std::shared_ptr<NonlinearEigenSystem> _nl_eigen;
243
250
266 PostprocessorName _normalization;
274
275private:
279 void doFreeNonlinearPowerIterations(unsigned int free_power_iterations);
280
285 void adjustEigenVector(const Real value, bool scaling);
286
289 std::optional<PostprocessorName> _bx_norm_name;
290
291#endif
292
293 using FEProblemBase::_nl;
294};
295
296#ifdef LIBMESH_HAVE_SLEPC
297
299EigenProblem::getNonlinearEigenSystem(const unsigned int nl_sys_num)
300{
301 if (nl_sys_num > 0)
302 mooseError("eigen problems do not currently support multiple nonlinear eigen systems");
303 return *_nl_eigen;
304}
305
311
312#endif
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
unsigned int TagID
Definition MooseTypes.h:238
char ** blocks
Problem for solving eigenvalue problems.
bool negativeSignEigenKernel() const
A flag indicates if a negative sign is used in eigen kernels.
virtual std::string solverTypeString(unsigned int solver_sys_num=0) override
Return solver type as a human readable string.
void outputInverseEigenvalue(bool inverse)
Set a flag to indicate whether or not to output eigenvalue inverse.
void computeMatricesTags(const NumericVector< Number > &soln, const std::vector< SparseMatrix< Number > * > &jacobians, const std::set< TagID > &tags)
Form several matrices simultaneously.
bool onLinearSolver() const
Whether or not we are in a linear solver iteration.
static InputParameters validParams()
void wereMatricesFormed(bool mf)
Set a flag to indicate whether or not constant matrices were already formed.
bool & _first_solve
A flag to indicate if it is the first time calling the solve.
virtual void computeJacobianBlocks(std::vector< JacobianBlock * > &blocks, const unsigned int nl_sys_num) override
Computes several Jacobian blocks simultaneously, summing their contributions into smaller preconditio...
virtual bool solverSystemConverged(const unsigned int solver_sys_num) override
void constantMatrices(bool cm)
Set a flag to indicate whether or not we use constant matrices.
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.
unsigned int _active_eigen_index
Which eigenvalue is used to compute residual.
bool constantMatrices() const
Whether or not matrices are constant.
void computeResidualAB(const NumericVector< Number > &soln, NumericVector< Number > &residualA, NumericVector< Number > &residualB, TagID tagA, TagID tagB)
Form two vetors, where each is associated with one tag, through one element-loop.
virtual void checkProblemIntegrity() override
Method called to perform a series of sanity checks before a simulation is run.
NonlinearEigenSystem & getNonlinearEigenSystem(const unsigned int nl_sys_num)
virtual void execute(const ExecFlagType &exec_type) override
Convenience function for performing execution of MOOSE systems.
void setBxNorm(const PostprocessorName &bx_norm)
Set the Bx norm postprocessor programatically.
std::shared_ptr< NonlinearEigenSystem > _nl_eigen
std::optional< PostprocessorName > _bx_norm_name
The name of the Postprocessor providing the Bx norm.
bool _negative_sign_eigen_kernel
Whether or not use negative sign for Bx.
bool bxNormProvided() const
Whether a Bx norm postprocessor has been provided.
bool doFreePowerIteration() const
Whether or not we are doing free power iteration.
bool _constant_matrices
Whether or not require constant matrices.
Real _normal_factor
Postprocessor target value.
unsigned int _n_eigen_pairs_required
NonlinearEigenSystem & getCurrentNonlinearEigenSystem()
void initEigenvector(const Real initial_value)
For nonlinear eigen solver, a good initial value can help convergence.
unsigned int activeEigenvalueIndex() const
Which eigenvalue is active.
virtual void solve(const unsigned int nl_sys_num) override
Real _initial_eigenvalue
A value used for initial normalization.
void scaleEigenvector(const Real scaling_factor)
Scale eigenvector.
virtual void computeJacobianTag(const NumericVector< Number > &soln, SparseMatrix< Number > &jacobian, TagID tag) override
Form a Jacobian matrix for all kernels and BCs with a given tag.
unsigned int getNEigenPairsRequired() const
bool _has_normalization
Whether or not we normalize eigenvector.
virtual Real computeResidualL2Norm() override
Compute the residual of Ax - \lambda Bx.
bool isNonlinearEigenvalueSolver(unsigned int eigen_sys_num) const
void doFreePowerIteration(bool do_power)
Set a flag to indicate whether or not we are doing free power iterations.
virtual void init() override
bool _on_linear_solver
Whether or not we are in linear solver.
bool outputInverseEigenvalue() const
Whether or not to output eigenvalue inverse.
bool _generalized_eigenvalue_problem
void computeJacobianAB(const NumericVector< Number > &soln, SparseMatrix< Number > &jacobianA, SparseMatrix< Number > &jacobianB, TagID tagA, TagID tagB)
Form two Jacobian matrices, where each is associated with one tag, through one element-loop.
Real formNorm()
Form the Bx norm.
void onLinearSolver(bool ols)
Set a flag to indicate whether or not we are in a linear solver iteration.
PostprocessorName _normalization
Postprocessor used to compute a factor from eigenvector.
bool _matrices_formed
Whether or not matrices had been formed.
bool wereMatricesFormed() const
Whether or not constant matrices were already formed.
void postScaleEigenVector()
Normalize eigen vector.
void preScaleEigenVector(const std::pair< Real, Real > &eig)
Eigenvector need to be scaled back if it was scaled in an earlier stage Scaling eigen vector does not...
void adjustEigenVector(const Real value, bool scaling)
Adjust eigen vector by either scaling the existing values or setting new values The operations are ap...
void setNEigenPairsRequired(unsigned int n_eigen_pairs)
bool _output_inverse_eigenvalue
Whether or not output eigenvalue as its inverse. By default, we output regular eigenvalue.
void doFreeNonlinearPowerIterations(unsigned int free_power_iterations)
Do some free/extra power iterations.
bool _do_free_power_iteration
Whether or not we are doing free power iteration.
bool isGeneralizedEigenvalueProblem() const
virtual void initPetscOutputAndSomeSolverSettings() override
Hook up monitors for SNES and KSP.
virtual void computeResidualTag(const NumericVector< Number > &soln, NumericVector< Number > &residual, TagID tag) override
Form a vector for all kernels and BCs with a given tag.
void setEigenproblemType(Moose::EigenProblemType eigen_problem_type)
Set eigen problem type.
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void computeJacobian(const NumericVector< libMesh::Number > &soln, libMesh::SparseMatrix< libMesh::Number > &jacobian, const unsigned int nl_sys_num)
Form a Jacobian matrix with the default tag (system).
std::vector< std::shared_ptr< NonlinearSystemBase > > _nl
The nonlinear systems.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
const InputParameters & parameters() const
Get the parameters of the object.
Definition MooseBase.h:131
Class for containing MooseEnum item information.
Nonlinear eigenvalue system to be solved.
EigenProblemType
Type of the eigen problem.
Definition MooseTypes.h:925