www.mooseframework.org
EigenProblem.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 #include "libmesh/libmesh_config.h"
11 
12 #include "EigenProblem.h"
13 #include "Assembly.h"
14 #include "AuxiliarySystem.h"
15 #include "DisplacedProblem.h"
16 #include "NonlinearEigenSystem.h"
17 #include "SlepcSupport.h"
18 #include "RandomData.h"
19 #include "OutputWarehouse.h"
20 #include "Function.h"
21 
22 // libMesh includes
23 #include "libmesh/system.h"
24 #include "libmesh/eigen_solver.h"
25 #include "libmesh/enum_eigen_solver_type.h"
26 
28 
29 template <>
32 {
34  return params;
35 }
36 
38  : FEProblemBase(parameters),
39  // By default, we want to compute an eigenvalue only (smallest or largest)
40  _n_eigen_pairs_required(1),
41  _generalized_eigenvalue_problem(false),
42  _nl_eigen(std::make_shared<NonlinearEigenSystem>(*this, "eigen0")),
43  _compute_jacobian_tag_timer(registerTimedSection("computeJacobianTag", 3)),
44  _compute_jacobian_ab_timer(registerTimedSection("computeJacobianAB", 3)),
45  _compute_residual_tag_timer(registerTimedSection("computeResidualTag", 3)),
46  _compute_residual_ab_timer(registerTimedSection("computeResidualAB", 3)),
47  _solve_timer(registerTimedSection("solve", 1))
48 {
49 #if LIBMESH_HAVE_SLEPC
50  _nl = _nl_eigen;
51  _aux = std::make_shared<AuxiliarySystem>(*this, "aux0");
52 
54 
56 
57  _eq.parameters.set<EigenProblem *>("_eigen_problem") = this;
58 
59 #else
60  mooseError("Need to install SLEPc to solve eigenvalue problems, please reconfigure\n");
61 #endif /* LIBMESH_HAVE_SLEPC */
62 
63  // Create extra vectors and matrices if any
65 }
66 
67 #if LIBMESH_HAVE_SLEPC
68 void
70 {
71  switch (eigen_problem_type)
72  {
74  _nl_eigen->sys().set_eigenproblem_type(libMesh::HEP);
76  break;
77 
79  _nl_eigen->sys().set_eigenproblem_type(libMesh::NHEP);
81  break;
82 
84  _nl_eigen->sys().set_eigenproblem_type(libMesh::GHEP);
86  break;
87 
89  _nl_eigen->sys().set_eigenproblem_type(libMesh::GHIEP);
91  break;
92 
94  _nl_eigen->sys().set_eigenproblem_type(libMesh::GNHEP);
96  break;
97 
99  mooseError("libMesh does not support EPT_POS_GEN_NON_HERMITIAN currently \n");
100  break;
101 
104  break;
105 
106  default:
107  mooseError("Unknown eigen solver type \n");
108  }
109 }
110 
111 void
112 EigenProblem::computeJacobianTag(const NumericVector<Number> & soln,
113  SparseMatrix<Number> & jacobian,
114  TagID tag)
115 {
116  TIME_SECTION(_compute_jacobian_tag_timer);
117 
118  _fe_matrix_tags.clear();
119 
120  _fe_matrix_tags.insert(tag);
121 
122  _nl_eigen->setSolution(soln);
123 
124  _nl_eigen->disassociateAllTaggedMatrices();
125 
126  _nl_eigen->associateMatrixToTag(jacobian, tag);
127 
129 
130  _nl_eigen->disassociateMatrixFromTag(jacobian, tag);
131 }
132 
133 void
134 EigenProblem::computeJacobianAB(const NumericVector<Number> & soln,
135  SparseMatrix<Number> & jacobianA,
136  SparseMatrix<Number> & jacobianB,
137  TagID tagA,
138  TagID tagB)
139 {
140  TIME_SECTION(_compute_jacobian_ab_timer);
141 
142  _fe_matrix_tags.clear();
143 
144  _fe_matrix_tags.insert(tagA);
145  _fe_matrix_tags.insert(tagB);
146 
147  _nl_eigen->setSolution(soln);
148 
149  _nl_eigen->disassociateAllTaggedMatrices();
150  _nl_eigen->associateMatrixToTag(jacobianA, tagA);
151  _nl_eigen->associateMatrixToTag(jacobianB, tagB);
152 
154 
155  _nl_eigen->disassociateMatrixFromTag(jacobianA, tagA);
156  _nl_eigen->disassociateMatrixFromTag(jacobianB, tagB);
157 }
158 
159 void
160 EigenProblem::computeResidualTag(const NumericVector<Number> & soln,
161  NumericVector<Number> & residual,
162  TagID tag)
163 {
164  TIME_SECTION(_compute_residual_tag_timer);
165 
166  _fe_vector_tags.clear();
167 
168  _fe_vector_tags.insert(tag);
169 
170  _nl_eigen->setSolution(soln);
171 
172  _nl_eigen->disassociateAllTaggedVectors();
173 
174  _nl_eigen->associateVectorToTag(residual, tag);
175 
177 
178  _nl_eigen->disassociateVectorFromTag(residual, tag);
179 }
180 
181 void
182 EigenProblem::computeResidualAB(const NumericVector<Number> & soln,
183  NumericVector<Number> & residualA,
184  NumericVector<Number> & residualB,
185  TagID tagA,
186  TagID tagB)
187 {
188  TIME_SECTION(_compute_residual_ab_timer);
189 
190  _fe_vector_tags.clear();
191 
192  _fe_vector_tags.insert(tagA);
193 
194  _fe_vector_tags.insert(tagB);
195 
196  _nl_eigen->setSolution(soln);
197 
198  _nl_eigen->disassociateAllTaggedVectors();
199 
200  _nl_eigen->associateVectorToTag(residualA, tagA);
201 
202  _nl_eigen->associateVectorToTag(residualB, tagB);
203 
205 
206  _nl_eigen->disassociateVectorFromTag(residualA, tagA);
207 
208  _nl_eigen->disassociateVectorFromTag(residualB, tagB);
209 }
210 
211 #endif
212 
213 void
215 {
217  _nl_eigen->checkIntegrity();
218 }
219 
220 void
222 {
223  if (_solve)
224  {
225  TIME_SECTION(_solve_timer);
226 
227  _nl->solve();
228  _nl->update();
229  }
230 
231  // sync solutions in displaced problem
232  if (_displaced_problem)
233  _displaced_problem->syncSolutions();
234 }
235 
236 bool
238 {
239  return _nl_eigen->converged();
240 }
241 
242 bool
244 {
249 }
Nonlinear eigenvalue system to be solved.
Generalized Non-Hermitian.
Definition: MooseTypes.h:622
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:160
Newton-based eigen solver.
Definition: MooseTypes.h:609
virtual bool isNonlinearEigenvalueSolver()
Definition: EigenProblem.C:243
Generalized Hermitian indefinite.
Definition: MooseTypes.h:621
Moose::EigenSolveType _eigen_solve_type
Definition: SolverParams.h:24
SolverParams & solverParams()
Get the solver parameters.
unsigned int TagID
Definition: MooseTypes.h:162
std::shared_ptr< NonlinearSystemBase > _nl
Matrix-free Newton-based eigen solver.
Definition: MooseTypes.h:610
virtual void solve() override
Definition: EigenProblem.C:221
PerfID _compute_residual_ab_timer
Definition: EigenProblem.h:93
virtual void initNullSpaceVectors(const InputParameters &parameters, NonlinearSystemBase &nl)
EigenProblem(const InputParameters &parameters)
Definition: EigenProblem.C:37
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Matrix-free nonlinear inverse power.
Definition: MooseTypes.h:608
use whatever SLPEC has by default
Definition: MooseTypes.h:624
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
Generalized Non-Hermitian with positive (semi-)definite B.
Definition: MooseTypes.h:623
Specialization of SubProblem for solving nonlinear equations plus auxiliary equations.
virtual void computeResidualTags(const std::set< TagID > &tags)
Form multiple residual vectors and each is associated with one tag.
std::shared_ptr< NonlinearEigenSystem > _nl_eigen
Definition: EigenProblem.h:87
bool _generalized_eigenvalue_problem
Definition: EigenProblem.h:86
virtual void newAssemblyArray(NonlinearSystemBase &nl)
PerfID _compute_jacobian_tag_timer
Timers.
Definition: EigenProblem.h:90
void createTagVectors()
Create extra tagged vectors and matrices.
PerfID _solve_timer
Definition: EigenProblem.h:94
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:65
std::shared_ptr< AuxiliarySystem > _aux
virtual void computeResidualAB(const NumericVector< Number > &soln, NumericVector< Number > &residualA, NumericVector< Number > &residualB, TagID tagA, TagID tagB)
Form two vetors, whre each is associateed with one tag, through one element-loop. ...
Definition: EigenProblem.C:182
registerMooseObject("MooseApp", EigenProblem)
virtual void checkProblemIntegrity()
Method called to perform a series of sanity checks before a simulation is run.
Nonlinear inverse power.
Definition: MooseTypes.h:607
bool _solve
Whether or not to actually solve the nonlinear system.
std::set< TagID > _fe_matrix_tags
InputParameters validParams< EigenProblem >()
Definition: EigenProblem.C:31
PerfID _compute_jacobian_ab_timer
Definition: EigenProblem.h:91
InputParameters validParams< FEProblemBase >()
Non-Hermitian.
Definition: MooseTypes.h:619
virtual bool converged() override
Definition: EigenProblem.C:237
std::set< TagID > _fe_vector_tags
std::shared_ptr< DisplacedProblem > _displaced_problem
EquationSystems _eq
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:25
virtual void checkProblemIntegrity() override
Method called to perform a series of sanity checks before a simulation is run.
Definition: EigenProblem.C:214
EigenProblemType
Type of the eigen problem.
Definition: MooseTypes.h:616
void setEigenproblemType(Moose::EigenProblemType eigen_problem_type)
Definition: EigenProblem.C:69
Generalized Hermitian.
Definition: MooseTypes.h:620
virtual void computeJacobianAB(const NumericVector< Number > &soln, SparseMatrix< Number > &jacobianA, SparseMatrix< Number > &jacobianB, TagID tagA, TagID tagB)
Form two Jacobian matrices, whre each is associateed with one tag, through one element-loop.
Definition: EigenProblem.C:134
virtual void computeJacobianTags(const std::set< TagID > &tags)
Form multiple matrices, and each is associated with a tag.
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:112
PerfID _compute_residual_tag_timer
Definition: EigenProblem.h:92