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 
86 
91  virtual SNES getSNES() override;
92 
96  virtual EPS getEPS();
97 
99 
105  void checkIntegrity();
106 
114  std::pair<Real, Real> getConvergedEigenvalue(dof_id_type n) const;
115 
124  std::pair<Real, Real> getConvergedEigenpair(dof_id_type n) const;
125 
131  const std::vector<std::pair<Real, Real>> & getAllConvergedEigenvalues() const
132  {
133  return _eigen_values;
134  }
135 
139  TagID eigenVectorTag() const { return _Bx_tag; }
140 
144  TagID nonEigenVectorTag() const { return _Ax_tag; }
145 
149  TagID eigenMatrixTag() const { return _B_tag; }
150 
154  TagID nonEigenMatrixTag() const { return _A_tag; }
155 
156  std::set<TagID> defaultVectorTags() const override;
157  std::set<TagID> defaultMatrixTags() const override;
158 
162  void precondMatrixIncludesEigenKernels(bool precond_matrix_includes_eigen)
163  {
164  _precond_matrix_includes_eigen = precond_matrix_includes_eigen;
165  }
166 
168 
169  TagID precondMatrixTag() const { return _precond_tag; }
170 
172 
174 
175  virtual void turnOffJacobian() override;
176 
177  void residualAndJacobianTogether() override;
178 
184 
185  virtual void postInit() override;
186  virtual void reinit() override;
187 
188 protected:
189  virtual void postAddResidualObject(ResidualObject & object) override;
190 
191  void computeScalingJacobian() override;
192  void computeScalingResidual() override;
193 
196  std::unique_ptr<SlepcEigenSolverConfiguration> _solver_configuration;
197  std::vector<std::pair<Real, Real>> _eigen_values;
207  // Libmesh preconditioner
209 
213 };
214 
215 #else
216 
218 {
219 public:
220  NonlinearEigenSystem(EigenProblem & problem, const std::string & name);
221 
226  bool converged() { return false; }
227 
228  void checkIntegrity() {}
229 };
230 
231 #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:210
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.
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:1330
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 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.
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 void attachPreconditioner(libMesh::Preconditioner< Number > *preconditioner) override
Attach a customized preconditioner that requires physics knowledge.
uint8_t dof_id_type