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 : #pragma once 11 : 12 : #include "MooseObject.h" 13 : #include "Restartable.h" 14 : #include "ScalarCoupleable.h" 15 : 16 : class FEProblemBase; 17 : class TransientBase; 18 : 19 : /** 20 : * Base class for time stepping 21 : */ 22 : class TimeStepper : public MooseObject, public Restartable, public ScalarCoupleable 23 : { 24 : public: 25 : static InputParameters validParams(); 26 : 27 : TimeStepper(const InputParameters & parameters); 28 : virtual ~TimeStepper(); 29 : 30 : /** 31 : * Initialize the time stepper. Called at the very beginning of Executioner::execute() 32 : */ 33 : virtual void init(); 34 : 35 : virtual void preExecute(); 36 238547 : virtual void preSolve() {} 37 235014 : virtual void postSolve() {} 38 29030 : virtual void postExecute() {} 39 173726 : virtual void preStep() {} 40 194155 : virtual void postStep() {} 41 : 42 : /** 43 : * Called before a new step is started. 44 : * This is when the actual computation of the current DT will be done. 45 : * Because of that this MUST be called only once per step! 46 : * 47 : * After calling this function use getCurrentDT() to get the DT 48 : * that was computed. 49 : */ 50 : void computeStep(); 51 : 52 : /** 53 : * Called after computeStep() is called. 54 : * @return true if any type of sync point was hit, false otherwise 55 : */ 56 : virtual bool constrainStep(Real & dt); 57 : 58 : /** 59 : * Take a time step 60 : */ 61 : virtual void step(); 62 : 63 : /** 64 : * This gets called when time step is accepted 65 : */ 66 : virtual void acceptStep(); 67 : 68 : /** 69 : * This gets called when time step is rejected 70 : */ 71 : virtual void rejectStep(); 72 : 73 : /// Gets the number of failures and returns them. 74 : unsigned int numFailures() const; 75 : 76 : /** 77 : * If the time step converged 78 : * @return true if converged, otherwise false 79 : */ 80 : virtual bool converged() const; 81 : 82 : /** 83 : * Get the current_dt 84 : */ 85 381786 : Real getCurrentDT() { return _current_dt; } 86 : 87 : virtual void forceTimeStep(Real dt); 88 : 89 : /** 90 : * Set the number of time steps 91 : * @param num_steps number of time steps 92 : */ 93 : virtual void forceNumSteps(const unsigned int num_steps); 94 : 95 : ///@{ 96 : /** 97 : * Add a sync time 98 : * \todo {Remove after old output system is removed; sync time are handled by OutputWarehouse} 99 : */ 100 : void addSyncTime(Real sync_time); 101 : void addSyncTime(const std::set<Real> & times); 102 : ///@} 103 : 104 : /// Whether we are currently solving a failed time step 105 : /// Note: you should first try to use the restartableSystem for logic to handle failed time steps 106 2952 : bool justFailedTimeStep() const { return _currently_restepping; } 107 : 108 : protected: 109 : /** 110 : * Computes time step size for the initial time step 111 : */ 112 : virtual Real computeInitialDT() = 0; 113 : 114 : /** 115 : * Computes time step size after the initial time step 116 : */ 117 : virtual Real computeDT() = 0; 118 : 119 : /** 120 : * Computes time step size after a failed time step 121 : */ 122 : virtual Real computeFailedDT(); 123 : 124 : FEProblemBase & _fe_problem; 125 : /// Reference to transient executioner 126 : TransientBase & _executioner; 127 : 128 : /// Values from executioner 129 : Real & _time; 130 : Real & _time_old; 131 : int & _t_step; 132 : Real & _dt; 133 : Real & _dt_min; 134 : Real & _dt_max; 135 : Real & _end_time; 136 : std::set<Real> & _sync_times; 137 : 138 : Real & _timestep_tolerance; 139 : 140 : /// whether a detailed diagnostic output should be printed 141 : const bool & _verbose; 142 : 143 : /// Whether or not the previous solve converged. 144 : bool _converged; 145 : 146 : /// Cutback factor if a time step fails to converge 147 : const Real _cutback_factor_at_failure; 148 : 149 : /// If true then the next dt will be computed by computeInitialDT() 150 : bool _reset_dt; 151 : 152 : /// True if dt has been reset 153 : bool _has_reset_dt; 154 : 155 : /// If we are currently solving a failed step 156 : bool _currently_restepping; 157 : 158 : /// Cumulative amount of steps that have failed 159 : unsigned int _failure_count; 160 : 161 : private: 162 : /// Size of the current time step as computed by the Stepper. Note that the actual dt that was taken might be smaller if the Executioner constrained it. 163 : Real & _current_dt; 164 : };