www.mooseframework.org
NonlinearEigen.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
15 #include "NonlinearEigen.h"
16 
17 template <>
20 {
22  params.addParam<unsigned int>("free_power_iterations", 4, "The number of free power iterations");
23  params.addParam<Real>("source_abs_tol", 1e-06, "Absolute tolernance on residual norm");
24  params.addParam<Real>(
25  "source_rel_tol", 1e-50, "Relative tolernance on residual norm after free power iterations");
26  params.addParam<Real>(
27  "pfactor",
28  1e-2,
29  "The factor of residual to be reduced per free power iteration or per nonlinear step");
30  params.addParam<Real>("k0", 1.0, "Initial guess of the eigenvalue");
31  params.addParam<bool>(
32  "output_after_power_iterations", true, "True to output solution after free power iterations");
33  return params;
34 }
35 
37  : EigenExecutionerBase(parameters),
38  _free_iter(getParam<unsigned int>("free_power_iterations")),
39  _abs_tol(getParam<Real>("source_abs_tol")),
40  _rel_tol(getParam<Real>("source_rel_tol")),
41  _pfactor(getParam<Real>("pfactor")),
42  _output_after_pi(getParam<bool>("output_after_power_iterations"))
43 {
44  if (!_app.isRecovering() && !_app.isRestarting())
45  _eigenvalue = getParam<Real>("k0");
46 
47  addAttributeReporter("eigenvalue", _eigenvalue, "initial timestep_end");
48 }
49 
50 void
52 {
53  if (_app.isRecovering())
54  {
55  _console << "\nCannot recover NonlinearEigen solves!\nExiting...\n" << std::endl;
56  return;
57  }
58 
60 
61  // Write the initial.
62  // Note: We need to tempararily change the system time to make the output system work properly.
63  _problem.timeStep() = 0;
64  Real t = _problem.time();
67  _problem.time() = t;
68 
69  if (_free_iter > 0)
70  {
71  // save the initial guess
73 
74  // free power iterations
75  _console << " Free power iteration starts" << std::endl;
76 
77  Real initial_res;
79  _free_iter,
80  _pfactor,
81  false,
82  std::numeric_limits<Real>::min(),
83  true,
84  "",
85  std::numeric_limits<Real>::max(),
87  initial_res);
88 
91 
92  if (_output_after_pi)
93  {
94  // output initial guess created by free power iterations
95  _problem.timeStep()++;
96  Real t = _problem.time();
99  _problem.time() = t;
100  }
101  }
102 }
103 
104 void
106 {
107  if (_app.isRecovering())
108  return;
109 
110  preExecute();
111 
112  takeStep();
113 
114  postExecute();
115 }
116 
117 void
119 {
120  _console << " Nonlinear iteration starts" << std::endl;
121 
122  preSolve();
126 
128  postSolve();
129 
130  if (lastSolveConverged())
131  {
132  printEigenvalue();
133 
136  }
137 }
const unsigned int & _free_iter
InputParameters validParams< EigenExecutionerBase >()
virtual void addAttributeReporter(const std::string &name, Real &attribute, const std::string execute_on="")
Adds a postprocessor to report a Real class attribute.
Definition: Executioner.C:180
virtual void init() override
Initialize the executioner.
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:608
Object is evaluated only once at the beginning of the simulation.
Definition: MooseTypes.h:94
const Real & _abs_tol
virtual Real & time() const
virtual void takeStep()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void onTimestepEnd() override
Object is evaluated at the end of every time step.
Definition: MooseTypes.h:100
NonlinearEigen(const InputParameters &parameters)
virtual void timestepSetup()
virtual void advanceState()
Advance all of the state holding vectors / datastructures so that we can move to the next timestep...
void execute(const ExecFlagType &exec_type)
Convenience function for performing execution of MOOSE systems.
virtual void execute() override
Pure virtual execute function MUST be overridden by children classes.
virtual void inversePowerIteration(unsigned int min_iter, unsigned int max_iter, Real pfactor, bool cheb_on, Real tol_eig, bool echo, PostprocessorName xdiff, Real tol_x, Real &k, Real &initial_res)
Perform inverse power iterations with the initial guess of the solution.
virtual void nonlinearSolve(Real rel_tol, Real abs_tol, Real pfactor, Real &k)
Perform nonlinear solve with the initial guess of the solution.
This class provides reusable routines for eigenvalue executioners.
virtual int & timeStep() const
InputParameters validParams< NonlinearEigen >()
virtual void preExecute()
Override this for actions that should take place before execution.
Definition: Executioner.C:135
virtual bool lastSolveConverged()
Whether or not the last solve converged.
Definition: Executioner.C:174
virtual void preSolve()
Override this for actions that should take place before execution.
Definition: Executioner.C:145
const Real & _pfactor
Real & _eigenvalue
Storage for the eigenvalue computed by the executioner.
const Real & _rel_tol
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
virtual void printEigenvalue()
Print eigenvalue.
Object is evaluated at the beginning of every time step.
Definition: MooseTypes.h:102
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition: MooseApp.C:614
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
virtual void postSolve()
Override this for actions that should take place after execution.
Definition: Executioner.C:150
virtual void postExecute() override
Override this for actions that should take place after the main solve.
virtual void init() override
Initialize the executioner.
virtual void outputStep(ExecFlagType type)
Output the current step.