https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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"
16
18
21{
23
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
48void
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
71void
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
80void
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;
90 return;
91 }
92
93 // Outputs initial conditions set by users
94 // It is consistent with Steady
95 _time_step = 0;
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
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)
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}
registerMooseObject("MooseApp", Eigenvalue)
const ExecFlagType EXEC_PRE_MULTIAPP_SETUP
Definition Moose.C:56
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
const ExecFlagType EXEC_FINAL
Definition Moose.C:48
unsigned int getSteps() const
Pull out the number of steps previously set by calling init()
Definition Adaptivity.h:119
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual void initialSetup() override
Method that should be executed once, before any solve calls.
static InputParameters validParams()
Problem for solving eigenvalue problems.
virtual void execute(const ExecFlagType &exec_type) override
Convenience function for performing execution of MOOSE systems.
void initEigenvector(const Real initial_value)
For nonlinear eigen solver, a good initial value can help convergence.
Eigenvalue executioner is used to drive the eigenvalue calculations.
Definition Eigenvalue.h:29
virtual void init() override
Initialize the executioner.
Definition Eigenvalue.C:49
Real & _time
Definition Eigenvalue.h:66
EigenProblem & _eigen_problem
Definition Eigenvalue.h:59
static InputParameters validParams()
Definition Eigenvalue.C:20
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
Definition Eigenvalue.h:42
EigenProblemSolve _eigen_problem_solve
inner-most solve object to perform Newton solve with SLEPc
Definition Eigenvalue.h:62
int & _time_step
Definition Eigenvalue.h:65
bool _last_solve_converged
Definition Eigenvalue.h:71
Real _system_time
Definition Eigenvalue.h:64
virtual void checkIntegrity()
Eigenvalue executioner does not allow time kernels.
Definition Eigenvalue.C:72
virtual void execute() override
Pure virtual execute function MUST be overridden by children classes.
Definition Eigenvalue.C:81
PerfID _final_timer
Definition Eigenvalue.h:68
Eigenvalue(const InputParameters &parameters)
Constructor.
Definition Eigenvalue.C:33
Executioners are objects that do the actual work of solving your problem.
Definition Executioner.h:37
static InputParameters validParams()
Definition Executioner.C:26
virtual void preExecute()
Override this for actions that should take place before execution.
Definition Executioner.h:73
virtual void postExecute()
Override this for actions that should take place after execution.
Definition Executioner.h:78
std::unique_ptr< FixedPointSolve > _fixed_point_solve
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep.
virtual void postExecute()
Method called at the end of the simulation.
bool execMultiApps(ExecFlagType type, bool auto_advance=true)
Execute the MultiApps associated with the ExecFlagType.
void timestepSetup() override
virtual void computeIndicators()
void finalizeMultiApps()
NonlinearSystemBase & getNonlinearSystemBase(const unsigned int sys_num)
virtual bool adaptMesh()
Adaptivity & adaptivity()
virtual void computeMarkers()
void initialSetup() override
virtual void outputStep(ExecFlagType type)
Output the current step.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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.
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.
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition MooseApp.C:1675
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition MooseApp.C:1669
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:271
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
virtual bool containsTimeKernel() override
If the system has a kernel that corresponds to a time derivative.