www.mooseframework.org
NonlinearEigen.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 "NonlinearEigen.h"
11 
13 
14 template <>
17 {
19  params.addParam<unsigned int>("free_power_iterations", 4, "The number of free power iterations");
20  params.addParam<Real>("source_abs_tol", 1e-06, "Absolute tolernance on residual norm");
21  params.addParam<Real>(
22  "source_rel_tol", 1e-50, "Relative tolernance on residual norm after free power iterations");
23  params.addParam<Real>(
24  "pfactor",
25  1e-2,
26  "The factor of residual to be reduced per free power iteration or per nonlinear step");
27  params.addParam<Real>("k0", 1.0, "Initial guess of the eigenvalue");
28  params.addParam<bool>(
29  "output_after_power_iterations", true, "True to output solution after free power iterations");
30  return params;
31 }
32 
34  : EigenExecutionerBase(parameters),
35  _free_iter(getParam<unsigned int>("free_power_iterations")),
36  _abs_tol(getParam<Real>("source_abs_tol")),
37  _rel_tol(getParam<Real>("source_rel_tol")),
38  _pfactor(getParam<Real>("pfactor")),
39  _output_after_pi(getParam<bool>("output_after_power_iterations"))
40 {
41  if (!_app.isRecovering() && !_app.isRestarting())
42  _eigenvalue = getParam<Real>("k0");
43 
44  addAttributeReporter("eigenvalue", _eigenvalue, "initial timestep_end");
45 }
46 
47 void
49 {
50  if (_app.isRecovering())
51  {
52  _console << "\nCannot recover NonlinearEigen solves!\nExiting...\n" << std::endl;
53  return;
54  }
55 
57 
58  // Write the initial.
59  // Note: We need to tempararily change the system time to make the output system work properly.
60  _problem.timeStep() = 0;
61  Real t = _problem.time();
64  _problem.time() = t;
65 
66  if (_free_iter > 0)
67  {
68  // save the initial guess
70 
71  // free power iterations
72  _console << " Free power iteration starts" << std::endl;
73 
74  Real initial_res;
76  _free_iter,
77  _pfactor,
78  false,
79  std::numeric_limits<Real>::min(),
80  true,
81  "",
82  std::numeric_limits<Real>::max(),
84  initial_res);
85 
88 
89  if (_output_after_pi)
90  {
91  // output initial guess created by free power iterations
92  _problem.timeStep()++;
93  Real t = _problem.time();
96  _problem.time() = t;
97  }
98  }
99 }
100 
101 void
103 {
104  if (_app.isRecovering())
105  return;
106 
107  preExecute();
108 
109  takeStep();
110 
111  postExecute();
112 }
113 
114 void
116 {
117  _console << " Nonlinear iteration starts" << std::endl;
118 
119  preSolve();
123 
125  postSolve();
126 
127  if (lastSolveConverged())
128  {
129  printEigenvalue();
130 
133  }
134 }
const unsigned int & _free_iter
virtual void preExecute()
Override this for actions that should take place before execution.
Definition: Executioner.h:62
registerMooseObject("MooseApp", NonlinearEigen)
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:74
virtual Real & time() const
virtual void init() override
Initialize the executioner.
virtual void preSolve()
Override this for actions that should take place before execution, called by PicardSolve.
Definition: Executioner.h:72
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
const Real & _abs_tol
virtual void takeStep()
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void onTimestepEnd() override
const ExecFlagType EXEC_TIMESTEP_END
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition: MooseApp.C:865
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...
virtual 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.
const ExecFlagType EXEC_TIMESTEP_BEGIN
This class provides reusable routines for eigenvalue executioners.
virtual bool nonlinearSolve(Real rel_tol, Real abs_tol, Real pfactor, Real &k)
Perform nonlinear solve with the initial guess of the solution.
InputParameters validParams< NonlinearEigen >()
virtual int & timeStep() const
const Real & _pfactor
Real & _eigenvalue
Storage for the eigenvalue computed by the executioner.
virtual void postSolve()
Override this for actions that should take place after execution, called by PicardSolve.
Definition: Executioner.h:77
const Real & _rel_tol
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:177
virtual void printEigenvalue()
Print eigenvalue.
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...
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
bool _last_solve_converged
virtual void postExecute() override
Override this for actions that should take place after the main solve.
virtual void init() override
Initialize the executioner.
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition: MooseApp.C:859
virtual void outputStep(ExecFlagType type)
Output the current step.
virtual bool 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.
const ExecFlagType EXEC_INITIAL