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 
16 {
18  params.addClassDescription("Inverse power method for eigenvalue problems.");
19  params.addParam<PostprocessorName>(
20  "xdiff", "", "To evaluate |x-x_previous| for power iterations");
21  params.addParam<unsigned int>(
22  "max_power_iterations", 300, "The maximum number of power iterations");
23  params.addParam<unsigned int>("min_power_iterations", 1, "Minimum number of power iterations");
24  params.addParam<Real>("eig_check_tol", 1e-6, "Eigenvalue convergence tolerance");
25  params.addParam<Real>("sol_check_tol",
27  "Convergence tolerance on |x-x_previous| when provided");
28  params.set<Real>("l_tol", true) = 1e-2;
29  params.addParam<bool>(
30  "Chebyshev_acceleration_on", true, "If Chebyshev acceleration is turned on");
31  return params;
32 }
33 
35  : EigenExecutionerBase(parameters),
36  _solution_diff_name(getParam<PostprocessorName>("xdiff")),
37  _min_iter(getParam<unsigned int>("min_power_iterations")),
38  _max_iter(getParam<unsigned int>("max_power_iterations")),
39  _eig_check_tol(getParam<Real>("eig_check_tol")),
40  _sol_check_tol(getParam<Real>("sol_check_tol")),
41  _l_tol(getParam<Real>("l_tol")),
42  _cheb_on(getParam<bool>("Chebyshev_acceleration_on"))
43 {
44  if (_max_iter < _min_iter)
45  mooseError("max_power_iterations<min_power_iterations!");
46  if (_eig_check_tol < 0.0)
47  mooseError("eig_check_tol<0!");
48  if (_l_tol < 0.0)
49  paramError("l_tol", "l_tol<0!");
50 
51  mooseInfo(
52  "'InversePowerMethod' executioner is deprecated in favor of 'Eigenvalue' executioner.\n",
53  "Few parameters such as 'bx_norm', 'k0', 'xdiff', 'max_power_iterations', "
54  "'min_power_iterations', 'eig_check_tol', 'sol_check_tol', and 'output_before_normalization' "
55  "are no longer supported.\n",
56  "However, 'Eigenvalue' executioner supports more solving options by interfacing SLEPc.\n");
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  _l_tol,
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:73
const unsigned int & _min_iter
minimum number of power iterations
virtual Real & time() const
void mooseInfo(Args &&... args) const
virtual void preSolve()
Override this for actions that should take place before execution, called by PicardSolve.
Definition: Executioner.h:83
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void onTimestepEnd() override
const ExecFlagType EXEC_TIMESTEP_END
Definition: Moose.C:32
PostprocessorValue & _eigenvalue
Storage for the eigenvalue computed by the executioner.
InversePowerMethod(const InputParameters &parameters)
virtual void takeStep()
auto max(const L &left, const R &right)
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.
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
static InputParameters validParams()
const PostprocessorName & _solution_diff_name
name of the postprocessor for evaluating |x-xprevious|; empty means that no postprocessor is provided...
const Real & _l_tol
tolerance on each power iteration (always one nonlinear iteration)
This class provides reusable routines for eigenvalue executioners.
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:69
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
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
registerMooseObject("MooseApp", InversePowerMethod)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
virtual void postSolve()
Override this for actions that should take place after execution, called by PicardSolve.
Definition: Executioner.h:88
virtual void printEigenvalue()
Print eigenvalue.
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
static InputParameters validParams()
Constructor.
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:1167
void ErrorVector unsigned int
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
Definition: Moose.C:28