https://mooseframework.inl.gov
NonlinearEigenSystem.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 #include "libmesh/libmesh_config.h"
13 
14 #include "NonlinearSystemBase.h"
16 
17 #include "libmesh/condensed_eigen_system.h"
18 
19 // forward declarations
20 class EigenProblem;
21 class KernelBase;
22 class ResidualObject;
23 
24 #ifdef LIBMESH_HAVE_SLEPC
25 
26 #include <slepceps.h>
27 
28 namespace Moose
29 {
30 void assemble_matrix(EquationSystems & es, const std::string & system_name);
31 }
32 
37 {
38 public:
39  NonlinearEigenSystem(EigenProblem & problem, const std::string & name);
40 
41  virtual void solve() override;
42 
46  virtual void stopSolve(const ExecFlagType & exec_flag,
47  const std::set<TagID> & vector_tags_to_close) override;
48 
53  virtual unsigned int getCurrentNonlinearIterationNumber() override;
54 
55  virtual void setupFiniteDifferencedPreconditioner() override;
56 
62  virtual bool converged() override;
63 
64  virtual NumericVector<Number> & RHS() override;
65 
66  /*
67  * A residual vector at MOOSE side for AX
68  */
70 
71  /*
72  * A residual vector at MOOSE side for BX
73  */
75 
76  void attachSLEPcCallbacks();
77 
83  unsigned int getNumConvergedEigenvalues() const { return _eigen_sys.get_n_converged(); };
84 
85  virtual unsigned int nNonlinearIterations() const override;
86  virtual unsigned int nLinearIterations() const override;
87  virtual Real finalNonlinearResidual() const override;
88 
90 
95  virtual SNES getSNES() override;
96 
100  virtual EPS getEPS();
101 
103 
109  void checkIntegrity();
110 
118  std::pair<Real, Real> getConvergedEigenvalue(dof_id_type n) const;
119 
128  std::pair<Real, Real> getConvergedEigenpair(dof_id_type n) const;
129 
135  const std::vector<std::pair<Real, Real>> & getAllConvergedEigenvalues() const
136  {
137  return _eigen_values;
138  }
139 
143  TagID eigenVectorTag() const { return _Bx_tag; }
144 
148  TagID nonEigenVectorTag() const { return _Ax_tag; }
149 
153  TagID eigenMatrixTag() const { return _B_tag; }
154 
158  TagID nonEigenMatrixTag() const { return _A_tag; }
159 
160  std::set<TagID> defaultVectorTags() const override;
161  std::set<TagID> defaultMatrixTags() const override;
162 
166  void precondMatrixIncludesEigenKernels(bool precond_matrix_includes_eigen)
167  {
168  _precond_matrix_includes_eigen = precond_matrix_includes_eigen;
169  }
170 
172 
173  TagID precondMatrixTag() const { return _precond_tag; }
174 
176 
178 
179  virtual void turnOffJacobian() override;
180 
181  void residualAndJacobianTogether() override;
182 
188 
189  virtual void postInit() override;
190  virtual void reinit() override;
191 
192 protected:
193  virtual void postAddResidualObject(ResidualObject & object) override;
194 
195  void computeScalingJacobian() override;
196  void computeScalingResidual() override;
197 
200  std::unique_ptr<SlepcEigenSolverConfiguration> _solver_configuration;
201  std::vector<std::pair<Real, Real>> _eigen_values;
211  // Libmesh preconditioner
213 
217 };
218 
219 #else
220 
222 {
223 public:
224  NonlinearEigenSystem(EigenProblem & problem, const std::string & name);
225 
230  bool converged() { return false; }
231 
232  void checkIntegrity() {}
233 };
234 
235 #endif
Nonlinear eigenvalue system to be solved.
NumericVector< Number > & residualVectorAX()
std::unique_ptr< SlepcEigenSolverConfiguration > _solver_configuration
void precondMatrixIncludesEigenKernels(bool precond_matrix_includes_eigen)
If the preconditioning matrix includes eigen kernels.
unsigned int TagID
Definition: MooseTypes.h:238
virtual void postAddResidualObject(ResidualObject &object) override
Called after any ResidualObject-derived objects are added to the system.
TagID nonEigenVectorTag() const
Vector tag ID of left hand side.
virtual libMesh::NonlinearSolver< Number > * nonlinearSolver() override
virtual void reinit() override
Reinitialize the system when the degrees of freedom in this system have changed.
TagID eigenVectorTag() const
Vector tag ID of right hand side.
void initializeCondensedMatrices()
Initialize the condensed matrices.
virtual Real finalNonlinearResidual() const override
Return the final nonlinear residual.
std::set< TagID > defaultVectorTags() const override
Get the default vector tags associated with this system.
NumericVector< Number > & _work_rhs_vector_AX
virtual void postInit() override
const std::vector< std::pair< Real, Real > > & getAllConvergedEigenvalues() const
Get the number of converged eigenvalues.
bool converged()
Returns the convergence state.
NonlinearEigenSystem(EigenProblem &problem, const std::string &name)
NumericVector< Number > & _work_rhs_vector_BX
unsigned int getNumConvergedEigenvalues() const
Get the number of converged eigenvalues.
Nonlinear system to be solved.
virtual const std::string & name() const
Definition: SystemBase.C:1342
virtual EPS getEPS()
Retrieve EPS (SLEPc eigen solver)
bool precondMatrixIncludesEigenKernels() const
libMesh::Preconditioner< Number > * _preconditioner
virtual void stopSolve(const ExecFlagType &exec_flag, const std::set< TagID > &vector_tags_to_close) override
Quit the current solve as soon as possible.
NumericVector< Number > & residualVectorBX()
This is the common base class for the three main kernel types implemented in MOOSE, Kernel, VectorKernel and ArrayKernel.
Definition: KernelBase.h:23
virtual void turnOffJacobian() override
Turn off the Jacobian (must be called before equation system initialization)
std::pair< Real, Real > getConvergedEigenpair(dof_id_type n) const
Return the Nth converged eigenvalue and copies the respective eigen vector to the solution vector...
virtual bool converged() override
Returns the convergence state.
void assemble_matrix(EquationSystems &es, const std::string &system_name)
virtual unsigned int nNonlinearIterations() const override
Return the number of non-linear iterations.
virtual void setupFiniteDifferencedPreconditioner() override
void computeScalingResidual() override
Compute a "residual" for automatic scaling purposes.
dof_id_type _num_constrained_dofs
The number of degrees of freedom constrained at the libMesh level, e.g.
virtual unsigned int getCurrentNonlinearIterationNumber() override
Returns the current nonlinear iteration number.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
This is the common base class for objects that give residual contributions.
Class for containing MooseEnum item information.
Definition: MooseEnumItem.h:18
libMesh::CondensedEigenSystem & sys()
void residualAndJacobianTogether() override
Call this method if you want the residual and Jacobian to be computed simultaneously.
virtual SNES getSNES() override
Retrieve snes from slepc eigen solver.
TagID eigenMatrixTag() const
Matrix tag ID of right hand side.
void computeScalingJacobian() override
Compute a "Jacobian" for automatic scaling purposes.
std::pair< Real, Real > getConvergedEigenvalue(dof_id_type n) const
Return the Nth converged eigenvalue.
TagID nonEigenMatrixTag() const
Matrix tag ID of left hand side.
MOOSE now contains C++17 code, so give a reasonable error message stating what the user can do to add...
unsigned int get_n_converged() const
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:21
std::vector< std::pair< Real, Real > > _eigen_values
virtual NumericVector< Number > & RHS() override
unsigned int _n_eigen_pairs_required
virtual void solve() override
Solve the system (using libMesh magic)
libMesh::CondensedEigenSystem & _eigen_sys
std::set< TagID > defaultMatrixTags() const override
Get the default matrix tags associted with this system.
libMesh::Preconditioner< Number > * preconditioner() const
void checkIntegrity()
For eigenvalue problems (including standard and generalized), inhomogeneous (Dirichlet or Neumann) bo...
virtual unsigned int nLinearIterations() const override
Return the number of linear iterations.
virtual void attachPreconditioner(libMesh::Preconditioner< Number > *preconditioner) override
Attach a customized preconditioner that requires physics knowledge.
uint8_t dof_id_type