LCOV - code coverage report
Current view: top level - src/timesteppers - FixedPointIterationAdaptiveDT.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 61 62 98.4 %
Date: 2025-07-17 01:28:37 Functions: 6 6 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "FixedPointIterationAdaptiveDT.h"
      11             : #include "FEProblemBase.h"
      12             : #include "Transient.h"
      13             : #include "Convergence.h"
      14             : 
      15             : registerMooseObject("MooseApp", FixedPointIterationAdaptiveDT);
      16             : 
      17             : InputParameters
      18       14337 : FixedPointIterationAdaptiveDT::validParams()
      19             : {
      20       14337 :   InputParameters params = TimeStepper::validParams();
      21       14337 :   params.addClassDescription(
      22             :       "Computes time step size based on a target number of fixed point iterations");
      23       14337 :   params.addRequiredRangeCheckedParam<Real>(
      24             :       "dt_initial", "dt_initial > 0", "The initial time step size");
      25       14337 :   params.addRequiredRangeCheckedParam<unsigned int>(
      26             :       "target_iterations", "target_iterations > 0", "The target number of fixed point iterations");
      27       14337 :   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       43011 :   params.addRangeCheckedParam<Real>(
      35             :       "increase_factor",
      36       28674 :       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       43011 :   params.addRangeCheckedParam<Real>(
      42             :       "decrease_factor",
      43       28674 :       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       14337 :   return params;
      50           0 : }
      51             : 
      52          36 : FixedPointIterationAdaptiveDT::FixedPointIterationAdaptiveDT(const InputParameters & parameters)
      53             :   : TimeStepper(parameters),
      54          36 :     _dt_initial(getParam<Real>("dt_initial")),
      55          36 :     _target_center(getParam<unsigned int>("target_iterations")),
      56          36 :     _target_window(getParam<unsigned int>("target_window")),
      57          36 :     _target_min(_target_center - _target_window),
      58          36 :     _target_max(_target_center + _target_window),
      59          36 :     _increase_factor(getParam<Real>("increase_factor")),
      60          36 :     _decrease_factor(getParam<Real>("decrease_factor")),
      61          36 :     _dt_old(declareRestartableData<Real>("dt_old", 0.0)),
      62          72 :     _fp_its(declareRestartableData<unsigned int>("fp_its", 0))
      63             : {
      64          36 : }
      65             : 
      66             : void
      67          32 : FixedPointIterationAdaptiveDT::init()
      68             : {
      69          32 :   TimeStepper::init();
      70             : 
      71          32 :   if (!_fe_problem.hasMultiApps())
      72           4 :     mooseError("This time stepper can only be used if there are MultiApps in the problem.");
      73             : 
      74             :   // If using DefaultMultiAppFixedPointConvergence, check min/max iterations
      75          28 :   auto & conv = _fe_problem.getConvergence(_fe_problem.getMultiAppFixedPointConvergenceName());
      76          28 :   if (conv.isParamValid("fixed_point_min_its") && conv.isParamValid("fixed_point_max_its"))
      77             :   {
      78          28 :     const auto min_its = conv.getParam<unsigned int>("fixed_point_min_its");
      79          28 :     const auto max_its = conv.getParam<unsigned int>("fixed_point_max_its");
      80          28 :     if (_target_max > max_its || _target_min < min_its)
      81           4 :       mooseError("The specified target iteration window, [",
      82           4 :                  _target_min,
      83             :                  ",",
      84           4 :                  _target_max,
      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          24 : }
      93             : 
      94             : Real
      95          44 : FixedPointIterationAdaptiveDT::computeInitialDT()
      96             : {
      97          44 :   return _dt_initial;
      98             : }
      99             : 
     100             : Real
     101          88 : FixedPointIterationAdaptiveDT::computeDT()
     102             : {
     103          88 :   Real dt = _dt_old;
     104             : 
     105          88 :   if (_fp_its > _target_max)
     106             :   {
     107          33 :     dt *= _decrease_factor;
     108          33 :     if (_verbose)
     109          33 :       _console << "Decreasing dt (" << _dt_old << ") to " << dt
     110          33 :                << " since number of fixed point iterations (" << _fp_its << ") is > " << _target_max
     111          33 :                << "." << std::endl;
     112             :   }
     113          55 :   else if (_fp_its < _target_min)
     114             :   {
     115          11 :     dt *= _increase_factor;
     116          11 :     if (_verbose)
     117          11 :       _console << "Increasing dt (" << _dt_old << ") to " << dt
     118          11 :                << " since number of fixed point iterations (" << _fp_its << ") is < " << _target_min
     119          11 :                << "." << std::endl;
     120             :   }
     121          44 :   else if (_verbose)
     122             :   {
     123          44 :     _console << "Keeping dt (" << _dt_old << ") since number of fixed point iterations (" << _fp_its
     124          44 :              << ") is >= " << _target_min << " and <= " << _target_max << "." << std::endl;
     125             :   }
     126          88 :   _console << std::flush;
     127             : 
     128          88 :   return dt;
     129             : }
     130             : 
     131             : void
     132         110 : FixedPointIterationAdaptiveDT::acceptStep()
     133             : {
     134         110 :   TimeStepper::acceptStep();
     135             : 
     136         110 :   _fp_its = _executioner.fixedPointSolve().numFixedPointIts();
     137         110 :   _dt_old = _dt;
     138         110 : }

Generated by: LCOV version 1.14