https://mooseframework.inl.gov
FixedPointIterationAdaptiveDT.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 
11 #include "FEProblemBase.h"
12 #include "Transient.h"
13 #include "Convergence.h"
14 
16 
19 {
21  params.addClassDescription(
22  "Computes time step size based on a target number of fixed point iterations");
24  "dt_initial", "dt_initial > 0", "The initial time step size");
25  params.addRequiredRangeCheckedParam<unsigned int>(
26  "target_iterations", "target_iterations > 0", "The target number of fixed point iterations");
27  params.addRequiredRangeCheckedParam<unsigned int>(
28  "target_window",
29  "target_window >= 0",
30  "The number of iterations added to and subtracted from 'target_iterations' to determine the "
31  "iteration window; the time step size will increase if the iterations were below "
32  "'target_iterations' - 'target_window' and will decrease if the iterations were above "
33  "'target_iterations' + 'target_window'.");
34  params.addRangeCheckedParam<Real>(
35  "increase_factor",
36  1.2,
37  "increase_factor >= 1",
38  "Factor by which the previous time step size will increase if the previous "
39  "number of fixed point iterations was below the target window minimum "
40  "('target_iterations' - 'target_window').");
41  params.addRangeCheckedParam<Real>(
42  "decrease_factor",
43  0.8,
44  "decrease_factor <= 1",
45  "Factor by which the previous time step size will decrease if the previous "
46  "number of fixed point iterations was above the target window maximum "
47  "('target_iterations' + 'target_window').");
48 
49  return params;
50 }
51 
53  : TimeStepper(parameters),
54  _dt_initial(getParam<Real>("dt_initial")),
55  _target_center(getParam<unsigned int>("target_iterations")),
56  _target_window(getParam<unsigned int>("target_window")),
57  _target_min(_target_center - _target_window),
58  _target_max(_target_center + _target_window),
59  _increase_factor(getParam<Real>("increase_factor")),
60  _decrease_factor(getParam<Real>("decrease_factor")),
61  _dt_old(declareRestartableData<Real>("dt_old", 0.0)),
62  _fp_its(declareRestartableData<unsigned int>("fp_its", 0))
63 {
64 }
65 
66 void
68 {
70 
72  mooseError("This time stepper can only be used if there are MultiApps in the problem.");
73 
74  // If using DefaultMultiAppFixedPointConvergence, check min/max iterations
76  if (conv.isParamValid("fixed_point_min_its") && conv.isParamValid("fixed_point_max_its"))
77  {
78  const auto min_its = conv.getParam<unsigned int>("fixed_point_min_its");
79  const auto max_its = conv.getParam<unsigned int>("fixed_point_max_its");
80  if (_target_max > max_its || _target_min < min_its)
81  mooseError("The specified target iteration window, [",
83  ",",
85  "], must be within the minimum and maximum number of fixed point iterations "
86  "specified for the Executioner, [",
87  min_its,
88  ",",
89  max_its,
90  "].");
91  }
92 }
93 
94 Real
96 {
97  return _dt_initial;
98 }
99 
100 Real
102 {
103  Real dt = _dt_old;
104 
105  if (_fp_its > _target_max)
106  {
107  dt *= _decrease_factor;
108  if (_verbose)
109  _console << "Decreasing dt (" << _dt_old << ") to " << dt
110  << " since number of fixed point iterations (" << _fp_its << ") is > " << _target_max
111  << "." << std::endl;
112  }
113  else if (_fp_its < _target_min)
114  {
115  dt *= _increase_factor;
116  if (_verbose)
117  _console << "Increasing dt (" << _dt_old << ") to " << dt
118  << " since number of fixed point iterations (" << _fp_its << ") is < " << _target_min
119  << "." << std::endl;
120  }
121  else if (_verbose)
122  {
123  _console << "Keeping dt (" << _dt_old << ") since number of fixed point iterations (" << _fp_its
124  << ") is >= " << _target_min << " and <= " << _target_max << "." << std::endl;
125  }
126  _console << std::flush;
127 
128  return dt;
129 }
130 
131 void
133 {
135 
137  _dt_old = _dt;
138 }
TransientBase & _executioner
Reference to transient executioner.
Definition: TimeStepper.h:122
static InputParameters validParams()
Definition: TimeStepper.C:16
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
These methods add an range checked parameters.
const Real _decrease_factor
Factor by which to decrease time steps.
virtual Real computeInitialDT() override
Computes time step size for the initial time step.
Base class for time stepping.
Definition: TimeStepper.h:22
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
virtual void init() override
Initialize the time stepper.
unsigned int numFixedPointIts() const
Get the number of fixed point iterations performed Because this returns the number of fixed point ite...
const bool & _verbose
whether a detailed diagnostic output should be printed
Definition: TimeStepper.h:137
FEProblemBase & _fe_problem
Definition: TimeStepper.h:120
virtual void acceptStep()
This gets called when time step is accepted.
Definition: TimeStepper.C:175
const unsigned int _target_max
Maximum fixed point iterations of window.
virtual Convergence & getConvergence(const std::string &name, const THREAD_ID tid=0) const
Gets a Convergence object.
const ConvergenceName & getMultiAppFixedPointConvergenceName() const
Gets the MultiApp fixed point convergence object name.
registerMooseObject("MooseApp", FixedPointIterationAdaptiveDT)
Computes time step size based on a target number of fixed point iterations.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
unsigned int & _fp_its
Number of fixed point iterations in previous solve.
virtual Real computeDT() override
Computes time step size after the initial time step.
const Real _increase_factor
Factor by which to increase time steps.
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
FixedPointSolve & fixedPointSolve()
Definition: Executioner.h:124
const unsigned int _target_min
Minimum fixed point iterations of window.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
const Real _dt_initial
Initial time step size.
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 addRangeCheckedParam(const std::string &name, const T &value, const std::string &parsed_function, const std::string &doc_string)
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
bool hasMultiApps() const
Returns whether or not the current simulation has any multiapps.
virtual void init()
Initialize the time stepper.
Definition: TimeStepper.C:65
Real & _dt
Definition: TimeStepper.h:128
virtual void acceptStep() override
This gets called when time step is accepted.
void ErrorVector unsigned int
FixedPointIterationAdaptiveDT(const InputParameters &parameters)