https://mooseframework.inl.gov
Eigenvalue.C
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 // MOOSE includes
11 #include "Eigenvalue.h"
12 #include "EigenProblem.h"
13 #include "Factory.h"
14 #include "MooseApp.h"
15 #include "NonlinearEigenSystem.h"
16 
17 registerMooseObject("MooseApp", Eigenvalue);
18 
21 {
23 
24  params.addClassDescription(
25  "Eigenvalue solves a standard/generalized linear or nonlinear eigenvalue problem");
26 
28  params.addParam<Real>("time", 0.0, "System time");
29 
30  return params;
31 }
32 
34  : Executioner(parameters),
35  _eigen_problem(*getCheckedPointerParam<EigenProblem *>(
36  "_eigen_problem", "This might happen if you don't have a mesh")),
37  _eigen_problem_solve(*this),
38  _system_time(getParam<Real>("time")),
39  _time_step(_eigen_problem.timeStep()),
40  _time(_eigen_problem.time()),
41  _final_timer(registerTimedSection("final", 1))
42 {
45 }
46 
47 #ifdef LIBMESH_HAVE_SLEPC
48 void
50 {
51  // Does not allow time kernels
53 
54  // Provide vector of ones to solver
55  // "auto_initialization" is on by default and we init the vector values associated
56  // with eigen-variables as ones. If "auto_initialization" is turned off by users,
57  // it is up to users to provide an initial guess. If "auto_initialization" is off
58  // and users does not provide an initial guess, slepc will automatically generate
59  // a random vector as the initial guess. The motivation to offer this option is
60  // that we have to initialize ONLY eigen variables in multiphysics simulation.
61  // auto_initialization can be overriden by initial conditions.
62  if (getParam<bool>("auto_initialization") && !_app.isRestarting())
64 
67  _fixed_point_solve->initialSetup();
69 }
70 
71 void
73 {
74  // check to make sure that we don't have any time kernels in eigenvalue simulation
76  mooseError("You have specified time kernels in your eigenvalue simulation");
77 }
78 #endif
79 
80 void
82 {
83 #ifdef LIBMESH_HAVE_SLEPC
84  // Recovering makes sense for only transient simulations since the solution from
85  // the previous time steps is required.
86  if (_app.isRecovering())
87  {
88  _console << "\nCannot recover eigenvalue solves!\nExiting...\n" << std::endl;
89  _last_solve_converged = true;
90  return;
91  }
92 
93  // Outputs initial conditions set by users
94  // It is consistent with Steady
95  _time_step = 0;
96  _time = _time_step;
99 
100  preExecute();
101 
102  // The following code of this function is copied from "Steady"
103  // "Eigenvalue" implementation can be considered a one-time-step simulation to
104  // have the code compatible with the rest moose world.
106 
107  // First step in any eigenvalue state solve is always 1 (preserving backwards compatibility)
108  _time_step = 1;
109 
110 #ifdef LIBMESH_ENABLE_AMR
111 
112  // Define the refinement loop
113  auto steps = _eigen_problem.adaptivity().getSteps();
114  for (const auto r_step : make_range(steps + 1))
115  {
116 #endif // LIBMESH_ENABLE_AMR
118 
120  if (!lastSolveConverged())
121  {
122  _console << "Aborting as solve did not converge" << std::endl;
123  break;
124  }
125 
126  // Compute markers and indicators only when we do have at least one adaptivity step
127  if (steps)
128  {
131  }
132  // need to keep _time in sync with _time_step to get correct output
133  _time = _time_step;
136 
137 #ifdef LIBMESH_ENABLE_AMR
138  if (r_step < steps)
139  {
141  }
142 
143  _time_step++;
144  }
145 #endif
146 
147  {
148  TIME_SECTION(_final_timer)
153  _time = _time_step;
156  }
157 
158  postExecute();
159 
160 #else
161  mooseError("SLEPc is required for eigenvalue executioner, please use --download-slepc when "
162  "configuring PETSc ");
163 #endif
164 }
void finalizeMultiApps()
virtual void preExecute()
Override this for actions that should take place before execution.
Definition: Executioner.h:73
void timestepSetup() override
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
Definition: Eigenvalue.h:42
static InputParameters validParams()
Definition: Eigenvalue.C:20
virtual void init() override
Initialize the executioner.
Definition: Eigenvalue.C:49
EigenProblemSolve _eigen_problem_solve
inner-most solve object to perform Newton solve with SLEPc
Definition: Eigenvalue.h:62
Eigenvalue executioner is used to drive the eigenvalue calculations.
Definition: Eigenvalue.h:28
virtual void postExecute()
Method called at the end of the simulation.
virtual void initialSetup() override
Method that should be executed once, before any solve calls.
void initEigenvector(const Real initial_value)
For nonlinear eigen solver, a good initial value can help convergence.
Definition: EigenProblem.C:421
virtual void computeMarkers()
virtual void execute(const ExecFlagType &exec_type) override
Convenience function for performing execution of MOOSE systems.
Definition: EigenProblem.C:165
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Real & _time
Definition: Eigenvalue.h:66
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:36
static InputParameters validParams()
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition: MooseApp.C:1499
bool _last_solve_converged
Definition: Eigenvalue.h:71
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep...
virtual bool containsTimeKernel() override
If the system has a kernel that corresponds to a time derivative.
static InputParameters validParams()
Definition: Executioner.C:26
virtual void execute() override
Pure virtual execute function MUST be overridden by children classes.
Definition: Eigenvalue.C:81
virtual void checkIntegrity()
Eigenvalue executioner does not allow time kernels.
Definition: Eigenvalue.C:72
Eigenvalue(const InputParameters &parameters)
Constructor.
Definition: Eigenvalue.C:33
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Definition: Moose.C:54
virtual void computeIndicators()
virtual void postExecute()
Override this for actions that should take place after execution.
Definition: Executioner.h:78
void initialSetup() override
Executioners are objects that do the actual work of solving your problem.
Definition: Executioner.h:30
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:385
registerMooseObject("MooseApp", Eigenvalue)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
int & _time_step
Definition: Eigenvalue.h:65
Real _system_time
Definition: Eigenvalue.h:64
unsigned int getSteps() const
Pull out the number of steps previously set by calling init()
Definition: Adaptivity.h:119
IntRange< T > make_range(T beg, T end)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:281
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
PerfID _final_timer
Definition: Eigenvalue.h:68
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
EigenProblem & _eigen_problem
Definition: Eigenvalue.h:59
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
Problem for solving eigenvalue problems.
Definition: EigenProblem.h:21
Adaptivity & adaptivity()
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:1493
const ExecFlagType EXEC_FINAL
Definition: Moose.C:46
std::unique_ptr< FixedPointSolve > _fixed_point_solve
Definition: Executioner.h:172
virtual void outputStep(ExecFlagType type)
Output the current step.
virtual bool adaptMesh()
const ExecFlagType EXEC_INITIAL
Definition: Moose.C:30