https://mooseframework.inl.gov
Loading...
Searching...
No Matches
InversePowerMethod.C
Go to the documentation of this file.
1//* This file is part of the MOOSE framework
2//* https://mooseframework.inl.gov
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#include "FEProblemBase.h"
12
14
17{
19 params.addClassDescription("Inverse power method for eigenvalue 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.set<Real>("l_tol", true) = 1e-2;
30 params.addParam<bool>(
31 "Chebyshev_acceleration_on", true, "If Chebyshev acceleration is turned on");
32 return params;
33}
34
36 : EigenExecutionerBase(parameters),
37 _solution_diff_name(getParam<PostprocessorName>("xdiff")),
38 _min_iter(getParam<unsigned int>("min_power_iterations")),
39 _max_iter(getParam<unsigned int>("max_power_iterations")),
40 _eig_check_tol(getParam<Real>("eig_check_tol")),
41 _sol_check_tol(getParam<Real>("sol_check_tol")),
42 _l_tol(getParam<Real>("l_tol")),
43 _cheb_on(getParam<bool>("Chebyshev_acceleration_on"))
44{
45 if (_max_iter < _min_iter)
46 mooseError("max_power_iterations<min_power_iterations!");
47 if (_eig_check_tol < 0.0)
48 mooseError("eig_check_tol<0!");
49 if (_l_tol < 0.0)
50 paramError("l_tol", "l_tol<0!");
51
53 "'InversePowerMethod' executioner is deprecated in favor of 'Eigenvalue' executioner.\n",
54 "Few parameters such as 'bx_norm', 'k0', 'xdiff', 'max_power_iterations', "
55 "'min_power_iterations', 'eig_check_tol', 'sol_check_tol', and 'output_before_normalization' "
56 "are no longer supported.\n",
57 "However, 'Eigenvalue' executioner supports more solving options by interfacing SLEPc.\n");
58}
59
60void
62{
63 if (_app.isRecovering())
64 {
65 _console << "\nCannot recover InversePowerMethod solves!\nExiting...\n" << std::endl;
66 return;
67 }
68
70
71 // Write the initial.
72 // Note: We need to tempararily change the system time to make the output system work properly.
73 _problem.timeStep() = 0;
74 Real t = _problem.time();
77 _problem.time() = t;
78}
79
80void
82{
83 if (_app.isRecovering())
84 {
86 return;
87 }
88
89 preExecute();
90
91 takeStep();
92
94}
95
96void
98{
99 // save the initial guess and mark a new time step
101
102 preSolve();
103 Real initial_res;
105 _max_iter,
106 _l_tol,
107 _cheb_on,
109 true,
113 initial_res);
114 postSolve();
115
116 if (lastSolveConverged())
117 {
121 }
122}
registerMooseObject("MooseApp", InversePowerMethod)
void mooseInfo(Args &&... args)
Emit an informational message with the given stringified, concatenated args.
Definition MooseError.h:401
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application.
Definition MooseError.h:311
const ExecFlagType EXEC_TIMESTEP_END
Definition Moose.C:36
const ExecFlagType EXEC_INITIAL
Definition Moose.C:30
void ErrorVector unsigned int
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
This class provides reusable routines for eigenvalue executioners.
virtual void postExecute() override
Override this for actions that should take place after the main solve.
static InputParameters validParams()
Constructor.
PostprocessorValue & _eigenvalue
Storage for the eigenvalue computed by the executioner.
virtual void printEigenvalue()
Print eigenvalue.
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.
virtual void preExecute()
Override this for actions that should take place before execution.
Definition Executioner.h:73
virtual void postSolve()
Override this for actions that should take place after execution, called by FixedPointSolve.
Definition Executioner.h:88
virtual void preSolve()
Override this for actions that should take place before execution, called by FixedPointSolve.
Definition Executioner.h:83
virtual void onTimestepEnd() override
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 Real & time() const
virtual int & timeStep() const
virtual void outputStep(ExecFlagType type)
Output the current step.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object.
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.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
bool _last_solve_converged
flag to indicate if inverse power iteration converged
const unsigned int & _max_iter
maximum number of power iterations
virtual void execute() override
Pure virtual execute function MUST be overridden by children classes.
static InputParameters validParams()
const Real & _l_tol
tolerance on each power iteration (always one nonlinear iteration)
const PostprocessorName & _solution_diff_name
name of the postprocessor for evaluating |x-xprevious|; empty means that no postprocessor is provided...
const unsigned int & _min_iter
minimum number of power iterations
InversePowerMethod(const InputParameters &parameters)
const Real & _sol_check_tol
convergence tolerance on solution difference
virtual bool lastSolveConverged() const override
Whether or not the last solve converged.
const Real & _eig_check_tol
convergence tolerance on eigenvalue
virtual void takeStep()
const bool & _cheb_on
indicating if Chebyshev acceleration is turned on
virtual void init() override
Initialize the executioner.
bool isRecovering() const
Whether or not this is a "recover" calculation.
Definition MooseApp.C:1669
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 ...
Definition MooseBase.h:457
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375