https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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{
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
66void
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
94Real
99
100Real
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
131void
registerMooseObject("MooseApp", FixedPointIterationAdaptiveDT)
void ErrorVector unsigned int
const ConsoleStream _console
An instance of helper class to write streams to the Console objects.
FixedPointSolve & fixedPointSolve()
bool hasMultiApps() const
Returns whether or not the current simulation has any multiapps.
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.
Computes time step size based on a target number of fixed point iterations.
const Real _dt_initial
Initial time step size.
FixedPointIterationAdaptiveDT(const InputParameters &parameters)
virtual Real computeInitialDT() override
Computes time step size for the initial time step.
virtual void acceptStep() override
This gets called when time step is accepted.
const Real _increase_factor
Factor by which to increase time steps.
const unsigned int _target_max
Maximum fixed point iterations of window.
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 unsigned int _target_min
Minimum fixed point iterations of window.
virtual void init() override
Initialize the time stepper.
const Real _decrease_factor
Factor by which to decrease time steps.
unsigned int numFixedPointIts() const
Get the number of fixed point iterations performed Because this returns the number of fixed point ite...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void addRequiredRangeCheckedParam(const std::string &name, const std::string &parsed_function, const std::string &doc_string)
These methods add an range checked parameters.
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)
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition MooseBase.h:271
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition MooseBase.h:406
Base class for time stepping.
Definition TimeStepper.h:23
const bool & _verbose
whether a detailed diagnostic output should be printed
virtual void init()
Initialize the time stepper.
Definition TimeStepper.C:66
FEProblemBase & _fe_problem
static InputParameters validParams()
Definition TimeStepper.C:16
virtual void acceptStep()
This gets called when time step is accepted.
TransientBase & _executioner
Reference to transient executioner.