Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
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 {
23 public:
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 
99  void postScaleEigenVector();
100 
104  void scaleEigenvector(const Real scaling_factor);
105 
109  void setEigenproblemType(Moose::EigenProblemType eigen_problem_type);
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 
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 
239 protected:
242  std::shared_ptr<NonlinearEigenSystem> _nl_eigen;
243 
249  unsigned int _active_eigen_index;
250 
266  PostprocessorName _normalization;
271  bool & _first_solve;
274 
275 private:
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 
298 inline NonlinearEigenSystem &
299 EigenProblem::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 
306 inline NonlinearEigenSystem &
308 {
309  return *_nl_eigen;
310 }
311 
312 #endif
Nonlinear eigenvalue system to be solved.
bool isGeneralizedEigenvalueProblem() const
Definition: EigenProblem.h:42
bool constantMatrices() const
Whether or not matrices are constant.
Definition: EigenProblem.h:207
bool wereMatricesFormed() const
Whether or not constant matrices were already formed.
Definition: EigenProblem.h:217
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.
Definition: EigenProblem.C:294
static InputParameters validParams()
Definition: EigenProblem.C:35
void onLinearSolver(bool ols)
Set a flag to indicate whether or not we are in a linear solver iteration.
Definition: EigenProblem.h:202
bool _matrices_formed
Whether or not matrices had been formed.
Definition: EigenProblem.h:260
virtual void initPetscOutputAndSomeSolverSettings() override
Hook up monitors for SNES and KSP.
Definition: EigenProblem.C:686
PostprocessorName _normalization
Postprocessor used to compute a factor from eigenvector.
Definition: EigenProblem.h:266
unsigned int activeEigenvalueIndex() const
Which eigenvalue is active.
Definition: EigenProblem.h:176
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...
Definition: EigenProblem.C:239
unsigned int TagID
Definition: MooseTypes.h:206
bool outputInverseEigenvalue() const
Whether or not to output eigenvalue inverse.
Definition: EigenProblem.h:187
void setBxNorm(const PostprocessorName &bx_norm)
Set the Bx norm postprocessor programatically.
Definition: EigenProblem.h:237
bool _on_linear_solver
Whether or not we are in linear solver.
Definition: EigenProblem.h:258
void initEigenvector(const Real initial_value)
For nonlinear eigen solver, a good initial value can help convergence.
Definition: EigenProblem.C:420
bool _has_normalization
Whether or not we normalize eigenvector.
Definition: EigenProblem.h:264
EigenProblem(const InputParameters &parameters)
Definition: EigenProblem.C:57
virtual void execute(const ExecFlagType &exec_type) override
Convenience function for performing execution of MOOSE systems.
Definition: EigenProblem.C:164
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
unsigned int _n_eigen_pairs_required
Definition: EigenProblem.h:240
bool negativeSignEigenKernel() const
A flag indicates if a negative sign is used in eigen kernels.
Definition: EigenProblem.h:57
void adjustEigenVector(const Real value, bool scaling)
Adjust eigen vector by either scaling the existing values or setting new values The operations are ap...
Definition: EigenProblem.C:388
void doFreeNonlinearPowerIterations(unsigned int free_power_iterations)
Do some free/extra power iterations.
Definition: EigenProblem.C:517
bool _output_inverse_eigenvalue
Whether or not output eigenvalue as its inverse. By default, we output regular eigenvalue.
Definition: EigenProblem.h:256
void inverse(const std::vector< std::vector< Real >> &m, std::vector< std::vector< Real >> &m_inv)
Inverse the dense square matrix m using LAPACK routines.
Definition: MatrixTools.C:23
bool _negative_sign_eigen_kernel
Whether or not use negative sign for Bx.
Definition: EigenProblem.h:246
bool _constant_matrices
Whether or not require constant matrices.
Definition: EigenProblem.h:262
void setNEigenPairsRequired(unsigned int n_eigen_pairs)
Definition: EigenProblem.h:38
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
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...
Definition: EigenProblem.C:432
bool isNonlinearEigenvalueSolver(unsigned int eigen_sys_num) const
Definition: EigenProblem.C:675
auto max(const L &left, const R &right)
std::shared_ptr< NonlinearEigenSystem > _nl_eigen
Definition: EigenProblem.h:242
bool _generalized_eigenvalue_problem
Definition: EigenProblem.h:241
bool _do_free_power_iteration
Whether or not we are doing free power iteration.
Definition: EigenProblem.h:254
Real formNorm()
Form the Bx norm.
Definition: EigenProblem.C:692
bool & _first_solve
A flag to indicate if it is the first time calling the solve.
Definition: EigenProblem.h:271
unsigned int getNEigenPairsRequired() const
Definition: EigenProblem.h:37
std::vector< std::shared_ptr< NonlinearSystemBase > > _nl
The nonlinear systems.
void constantMatrices(bool cm)
Set a flag to indicate whether or not we use constant matrices.
Definition: EigenProblem.h:212
virtual Real computeResidualL2Norm() override
Compute the residual of Ax - Bx.
Definition: EigenProblem.C:362
void setNormalization(const PostprocessorName &pp, const Real value=std::numeric_limits< Real >::max())
Set postprocessor and normalization factor &#39;Postprocessor&#39; is often used to compute an integral of ph...
Definition: EigenProblem.C:629
virtual void init() override
Definition: EigenProblem.C:637
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).
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. ...
Definition: EigenProblem.C:326
void computeMatricesTags(const NumericVector< Number > &soln, const std::vector< SparseMatrix< Number > *> &jacobians, const std::set< TagID > &tags)
Form several matrices simultaneously.
Definition: EigenProblem.C:206
Real _initial_eigenvalue
A value used for initial normalization.
Definition: EigenProblem.h:273
unsigned int _active_eigen_index
Which eigenvalue is used to compute residual.
Definition: EigenProblem.h:249
NonlinearEigenSystem & getCurrentNonlinearEigenSystem()
Definition: EigenProblem.h:307
void outputInverseEigenvalue(bool inverse)
Set a flag to indicate whether or not to output eigenvalue inverse.
Definition: EigenProblem.h:192
NonlinearEigenSystem & getNonlinearEigenSystem(const unsigned int nl_sys_num)
Definition: EigenProblem.h:299
void scaleEigenvector(const Real scaling_factor)
Scale eigenvector.
Definition: EigenProblem.C:414
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
bool onLinearSolver() const
Whether or not we are in a linear solver iteration.
Definition: EigenProblem.h:197
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
void postScaleEigenVector()
Normalize eigen vector.
Definition: EigenProblem.C:448
virtual std::string solverTypeString(unsigned int solver_sys_num=0) override
Return solver type as a human readable string.
Definition: EigenProblem.C:700
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const InputParameters & parameters() const
Get the parameters of the object.
Real _normal_factor
Postprocessor target value.
Definition: EigenProblem.h:269
void doFreePowerIteration(bool do_power)
Set a flag to indicate whether or not we are doing free power iterations.
Definition: EigenProblem.h:84
void setInitialEigenvalue(const Real initial_eigenvalue)
Set an initial eigenvalue for initial normalization.
Definition: EigenProblem.h:69
std::optional< PostprocessorName > _bx_norm_name
The name of the Postprocessor providing the Bx norm.
Definition: EigenProblem.h:289
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:21
bool bxNormProvided() const
Whether a Bx norm postprocessor has been provided.
Definition: EigenProblem.h:232
void wereMatricesFormed(bool mf)
Set a flag to indicate whether or not constant matrices were already formed.
Definition: EigenProblem.h:222
virtual void checkProblemIntegrity() override
Method called to perform a series of sanity checks before a simulation is run.
Definition: EigenProblem.C:500
EigenProblemType
Type of the eigen problem.
Definition: MooseTypes.h:864
bool doFreePowerIteration() const
Whether or not we are doing free power iteration.
Definition: EigenProblem.h:79
void setEigenproblemType(Moose::EigenProblemType eigen_problem_type)
Set eigen problem type.
virtual void solve(const unsigned int nl_sys_num) override
Definition: EigenProblem.C:540
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.
Definition: EigenProblem.C:258
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.
Definition: EigenProblem.C:175
virtual bool solverSystemConverged(const unsigned int solver_sys_num) override
Definition: EigenProblem.C:666