www.mooseframework.org
InversePowerMethod.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 "InversePowerMethod.h"
11 
13 
14 template <>
17 {
19  params.addClassDescription("Inverse power method for Eigen value problems.");
20  params.addParam<PostprocessorName>(
21  "xdiff", "", "To evaluate |x-x_previous| for power iterations");
22  params.addParam<unsigned int>(
23  "max_power_iterations", 300, "The maximum number of power iterations");
24  params.addParam<unsigned int>("min_power_iterations", 1, "Minimum number of power iterations");
25  params.addParam<Real>("eig_check_tol", 1e-6, "Eigenvalue convergence tolerance");
26  params.addParam<Real>("sol_check_tol",
27  std::numeric_limits<Real>::max(),
28  "Convergence tolerance on |x-x_previous| when provided");
29  params.addParam<Real>("pfactor", 1e-2, "Reduce residual norm per power iteration by this factor");
30  params.addParam<bool>(
31  "Chebyshev_acceleration_on", true, "If Chebyshev acceleration is turned on");
32  params.addParam<Real>("k0", 1.0, "Initial guess of the eigenvalue");
33  return params;
34 }
35 
37  : EigenExecutionerBase(parameters),
38  _solution_diff_name(getParam<PostprocessorName>("xdiff")),
39  _min_iter(getParam<unsigned int>("min_power_iterations")),
40  _max_iter(getParam<unsigned int>("max_power_iterations")),
41  _eig_check_tol(getParam<Real>("eig_check_tol")),
42  _sol_check_tol(getParam<Real>("sol_check_tol")),
43  _pfactor(getParam<Real>("pfactor")),
44  _cheb_on(getParam<bool>("Chebyshev_acceleration_on"))
45 {
46  if (!_app.isRecovering() && !_app.isRestarting())
47  _eigenvalue = getParam<Real>("k0");
48 
49  addAttributeReporter("eigenvalue", _eigenvalue, "initial timestep_end");
50 
51  if (_max_iter < _min_iter)
52  mooseError("max_power_iterations<min_power_iterations!");
53  if (_eig_check_tol < 0.0)
54  mooseError("eig_check_tol<0!");
55  if (_pfactor < 0.0)
56  mooseError("pfactor<0!");
57 }
58 
59 void
61 {
62  if (_app.isRecovering())
63  {
64  _console << "\nCannot recover InversePowerMethod solves!\nExiting...\n" << std::endl;
65  return;
66  }
67 
69 
70  // Write the initial.
71  // Note: We need to tempararily change the system time to make the output system work properly.
72  _problem.timeStep() = 0;
73  Real t = _problem.time();
76  _problem.time() = t;
77 }
78 
79 void
81 {
82  if (_app.isRecovering())
83  return;
84 
85  preExecute();
86 
87  takeStep();
88 
89  postExecute();
90 }
91 
92 void
94 {
95  // save the initial guess and mark a new time step
97 
98  preSolve();
99  Real initial_res;
101  _max_iter,
102  _pfactor,
103  _cheb_on,
105  true,
108  _eigenvalue,
109  initial_res);
110  postSolve();
111 
112  if (lastSolveConverged())
113  {
114  printEigenvalue();
117  }
118 }
virtual void preExecute()
Override this for actions that should take place before execution.
Definition: Executioner.h:62
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:74
virtual Real & time() const
virtual void preSolve()
Override this for actions that should take place before execution, called by PicardSolve.
Definition: Executioner.h:72
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
const ExecFlagType EXEC_TIMESTEP_END
void mooseError(Args &&... args) const
Definition: MooseObject.h:147
bool isRestarting() const
Whether or not this is a "restart" calculation.
Definition: MooseApp.C:865
InversePowerMethod(const InputParameters &parameters)
virtual void takeStep()
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.
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
const PostprocessorName & _solution_diff_name
name of the postprocessor for evaluating |x-xprevious|; empty means that no postprocessor is provided...
This class provides reusable routines for eigenvalue executioners.
virtual int & timeStep() const
const Real & _sol_check_tol
convergence tolerance on solution difference
bool _last_solve_converged
flag to indicate if inverse power iteration converged
Real & _eigenvalue
Storage for the eigenvalue computed by the executioner.
registerMooseObject("MooseApp", InversePowerMethod)
virtual void postSolve()
Override this for actions that should take place after execution, called by PicardSolve.
Definition: Executioner.h:77
MooseApp & _app
The MooseApp this object is associated with.
Definition: MooseObject.h:177
virtual void printEigenvalue()
Print eigenvalue.
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
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...
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.
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
const Real & _eig_check_tol
convergence tolerance on eigenvalue
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.
virtual void init() override
Initialize the executioner.
const ExecFlagType EXEC_INITIAL