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 14341 : FixedPointIterationAdaptiveDT::validParams() 19 : { 20 14341 : InputParameters params = TimeStepper::validParams(); 21 14341 : params.addClassDescription( 22 : "Computes time step size based on a target number of fixed point iterations"); 23 14341 : params.addRequiredRangeCheckedParam<Real>( 24 : "dt_initial", "dt_initial > 0", "The initial time step size"); 25 14341 : params.addRequiredRangeCheckedParam<unsigned int>( 26 : "target_iterations", "target_iterations > 0", "The target number of fixed point iterations"); 27 14341 : 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 43023 : params.addRangeCheckedParam<Real>( 35 : "increase_factor", 36 28682 : 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 43023 : params.addRangeCheckedParam<Real>( 42 : "decrease_factor", 43 28682 : 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 14341 : return params; 50 0 : } 51 : 52 38 : FixedPointIterationAdaptiveDT::FixedPointIterationAdaptiveDT(const InputParameters & parameters) 53 : : TimeStepper(parameters), 54 38 : _dt_initial(getParam<Real>("dt_initial")), 55 38 : _target_center(getParam<unsigned int>("target_iterations")), 56 38 : _target_window(getParam<unsigned int>("target_window")), 57 38 : _target_min(_target_center - _target_window), 58 38 : _target_max(_target_center + _target_window), 59 38 : _increase_factor(getParam<Real>("increase_factor")), 60 38 : _decrease_factor(getParam<Real>("decrease_factor")), 61 38 : _dt_old(declareRestartableData<Real>("dt_old", 0.0)), 62 76 : _fp_its(declareRestartableData<unsigned int>("fp_its", 0)) 63 : { 64 38 : } 65 : 66 : void 67 34 : FixedPointIterationAdaptiveDT::init() 68 : { 69 34 : TimeStepper::init(); 70 : 71 34 : 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 30 : auto & conv = _fe_problem.getConvergence(_fe_problem.getMultiAppFixedPointConvergenceName()); 76 30 : if (conv.isParamValid("fixed_point_min_its") && conv.isParamValid("fixed_point_max_its")) 77 : { 78 30 : const auto min_its = conv.getParam<unsigned int>("fixed_point_min_its"); 79 30 : const auto max_its = conv.getParam<unsigned int>("fixed_point_max_its"); 80 30 : 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 26 : } 93 : 94 : Real 95 48 : FixedPointIterationAdaptiveDT::computeInitialDT() 96 : { 97 48 : return _dt_initial; 98 : } 99 : 100 : Real 101 96 : FixedPointIterationAdaptiveDT::computeDT() 102 : { 103 96 : Real dt = _dt_old; 104 : 105 96 : if (_fp_its > _target_max) 106 : { 107 36 : dt *= _decrease_factor; 108 36 : if (_verbose) 109 36 : _console << "Decreasing dt (" << _dt_old << ") to " << dt 110 36 : << " since number of fixed point iterations (" << _fp_its << ") is > " << _target_max 111 36 : << "." << std::endl; 112 : } 113 60 : else if (_fp_its < _target_min) 114 : { 115 12 : dt *= _increase_factor; 116 12 : if (_verbose) 117 12 : _console << "Increasing dt (" << _dt_old << ") to " << dt 118 12 : << " since number of fixed point iterations (" << _fp_its << ") is < " << _target_min 119 12 : << "." << std::endl; 120 : } 121 48 : else if (_verbose) 122 : { 123 48 : _console << "Keeping dt (" << _dt_old << ") since number of fixed point iterations (" << _fp_its 124 48 : << ") is >= " << _target_min << " and <= " << _target_max << "." << std::endl; 125 : } 126 96 : _console << std::flush; 127 : 128 96 : return dt; 129 : } 130 : 131 : void 132 120 : FixedPointIterationAdaptiveDT::acceptStep() 133 : { 134 120 : TimeStepper::acceptStep(); 135 : 136 120 : _fp_its = _executioner.fixedPointSolve().numFixedPointIts(); 137 120 : _dt_old = _dt; 138 120 : }