www.mooseframework.org
InversePowerMethod.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 "InversePowerMethod.h"
16 
17 template <>
20 {
22  params.addParam<PostprocessorName>(
23  "xdiff", "", "To evaluate |x-x_previous| for power iterations");
24  params.addParam<unsigned int>(
25  "max_power_iterations", 300, "The maximum number of power iterations");
26  params.addParam<unsigned int>("min_power_iterations", 1, "Minimum number of power iterations");
27  params.addParam<Real>("eig_check_tol", 1e-6, "Eigenvalue convergence tolerance");
28  params.addParam<Real>("sol_check_tol",
29  std::numeric_limits<Real>::max(),
30  "Convergence tolerance on |x-x_previous| when provided");
31  params.addParam<Real>("pfactor", 1e-2, "Reduce residual norm per power iteration by this factor");
32  params.addParam<bool>(
33  "Chebyshev_acceleration_on", true, "If Chebyshev acceleration is turned on");
34  params.addParam<Real>("k0", 1.0, "Initial guess of the eigenvalue");
35  return params;
36 }
37 
39  : EigenExecutionerBase(parameters),
40  _solution_diff_name(getParam<PostprocessorName>("xdiff")),
41  _min_iter(getParam<unsigned int>("min_power_iterations")),
42  _max_iter(getParam<unsigned int>("max_power_iterations")),
43  _eig_check_tol(getParam<Real>("eig_check_tol")),
44  _sol_check_tol(getParam<Real>("sol_check_tol")),
45  _pfactor(getParam<Real>("pfactor")),
46  _cheb_on(getParam<bool>("Chebyshev_acceleration_on"))
47 {
48  if (!_app.isRecovering() && !_app.isRestarting())
49  _eigenvalue = getParam<Real>("k0");
50 
51  addAttributeReporter("eigenvalue", _eigenvalue, "initial timestep_end");
52 
53  if (_max_iter < _min_iter)
54  mooseError("max_power_iterations<min_power_iterations!");
55  if (_eig_check_tol < 0.0)
56  mooseError("eig_check_tol<0!");
57  if (_pfactor < 0.0)
58  mooseError("pfactor<0!");
59 }
60 
61 void
63 {
64  if (_app.isRecovering())
65  {
66  _console << "\nCannot recover InversePowerMethod solves!\nExiting...\n" << std::endl;
67  return;
68  }
69 
71 
72  // Write the initial.
73  // Note: We need to tempararily change the system time to make the output system work properly.
74  _problem.timeStep() = 0;
75  Real t = _problem.time();
78  _problem.time() = t;
79 }
80 
81 void
83 {
84  if (_app.isRecovering())
85  return;
86 
87  preExecute();
88 
89  takeStep();
90 
91  postExecute();
92 }
93 
94 void
96 {
97  // save the initial guess and mark a new time step
99 
100  preSolve();
101  Real initial_res;
103  _max_iter,
104  _pfactor,
105  _cheb_on,
107  true,
110  _eigenvalue,
111  initial_res);
112  postSolve();
113 
114  if (lastSolveConverged())
115  {
116  printEigenvalue();
119  }
120 }
const unsigned int & _min_iter
minimum number of power iterations
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
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
virtual Real & time() const
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
const Real & _pfactor
tolerance on each power iteration (always one nonlinear iteration)
virtual void onTimestepEnd() override
InversePowerMethod(const InputParameters &parameters)
Object is evaluated at the end of every time step.
Definition: MooseTypes.h:100
virtual void takeStep()
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.
InputParameters validParams< InversePowerMethod >()
const bool & _cheb_on
indicating if Chebyshev acceleration is turned on
virtual void execute() override
Pure virtual execute function MUST be overridden by children classes.
const unsigned int & _max_iter
maximum number of power iterations
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.
This class provides reusable routines for eigenvalue executioners.
virtual int & timeStep() const
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
const Real & _sol_check_tol
convergence tolerance on solution difference
virtual void preSolve()
Override this for actions that should take place before execution.
Definition: Executioner.C:145
Real & _eigenvalue
Storage for the eigenvalue computed by the executioner.
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:108
virtual void printEigenvalue()
Print eigenvalue.
std::string _solution_diff_name
name of the postprocessor for evaluating |x-xprevious|; empty means that no postprocessor is provided...
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...
void mooseError(Args &&...args) const
Definition: MooseObject.h:80
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.
const Real & _eig_check_tol
convergence tolerance on eigenvalue
virtual void outputStep(ExecFlagType type)
Output the current step.
virtual void init() override
Initialize the executioner.