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 "Executioner.h" 13 : #include "TimeIntegrator.h" 14 : 15 : // System includes 16 : #include <string> 17 : #include <fstream> 18 : #include <optional> 19 : 20 : class TimeStepper; 21 : class FEProblemBase; 22 : 23 : /** 24 : * Base class for transient executioners that use a FixedPointSolve solve object for multiapp-main 25 : * app iterations 26 : */ 27 : class TransientBase : public Executioner 28 : { 29 : public: 30 : static InputParameters defaultSteadyStateConvergenceParams(); 31 : static InputParameters validParams(); 32 : 33 : TransientBase(const InputParameters & parameters); 34 : 35 : virtual void init() override; 36 : 37 : virtual void execute() override; 38 : 39 : /** 40 : * Do whatever is necessary to advance one step. 41 : */ 42 : virtual void takeStep(Real input_dt = -1.0); 43 : 44 : /** 45 : * @return The fully constrained dt for this timestep 46 : */ 47 : virtual Real computeConstrainedDT(); 48 : virtual void estimateTimeError(); 49 : 50 : /** 51 : * @return The the computed dt to use for this timestep. 52 : */ 53 : virtual Real getDT(); 54 : 55 : /** 56 : * Transient loop will continue as long as this keeps returning true. 57 : */ 58 : virtual bool keepGoing(); 59 : 60 : /** 61 : * Whether or not the last solve converged. 62 : */ 63 : virtual bool lastSolveConverged() const override; 64 : 65 : virtual void preExecute() override; 66 : 67 : virtual void postExecute() override; 68 : 69 : void computeDT(); 70 : 71 : virtual void preStep(); 72 : 73 : virtual void postStep(); 74 : 75 : /** 76 : * This is where the solve step is actually incremented. 77 : */ 78 : virtual void incrementStepOrReject(); 79 : 80 : virtual void endStep(Real input_time = -1.0); 81 : 82 : /** 83 : * Can be used to set the next "target time" which is a time to nail perfectly. 84 : * Useful for driving MultiApps. 85 : */ 86 : virtual void setTargetTime(Real target_time); 87 : 88 : /** 89 : * Get the current time. 90 : */ 91 222721 : virtual Real getTime() const { return _time; }; 92 : 93 : /** 94 : * Get the current target time 95 : * @return target time 96 : */ 97 0 : virtual Real getTargetTime() { return _target_time; } 98 : 99 : /** 100 : * Set the current time. 101 : */ 102 0 : virtual void setTime(Real t) { _time = t; }; 103 : 104 : /** 105 : * Set the old time. 106 : */ 107 0 : virtual void setTimeOld(Real t) { _time_old = t; }; 108 : 109 : /** 110 : * Compute the relative L2 norm of the change in the solution. 111 : * 112 : * @param[in] check_aux Whether to use the aux variables instead of solution variables 113 : * @param[in] normalize_by_dt Whether to divide by time step size 114 : */ 115 : Real computeSolutionChangeNorm(bool check_aux, bool normalize_by_dt) const; 116 : 117 : /** 118 : * The relative L2 norm of the difference between solution and old solution vector. 119 : * 120 : * @param[in] check_aux Whether to use the aux variables instead of solution variables 121 : */ 122 : virtual Real relativeSolutionDifferenceNorm(bool check_aux) const = 0; 123 : 124 : /** 125 : * Pointer to the TimeStepper 126 : * @return Pointer to the time stepper for this Executioner 127 : */ 128 20 : TimeStepper * getTimeStepper() { return _time_stepper; } 129 : const TimeStepper * getTimeStepper() const { return _time_stepper; } 130 : 131 : /** 132 : * Set the timestepper to use. 133 : * 134 : * @param ts The TimeStepper to use 135 : */ 136 : void setTimeStepper(TimeStepper & ts); 137 : 138 : /** 139 : * Get the name of the timestepper. 140 : */ 141 : virtual std::string getTimeStepperName() const override; 142 : 143 : /** 144 : * Get the time integrators (time integration scheme) used 145 : * Note that because some systems might be steady state simulations, there could be less 146 : * time integrators than systems 147 : * @return string with the time integration scheme name 148 : */ 149 : virtual std::set<TimeIntegrator *> getTimeIntegrators() const = 0; 150 : 151 : /** 152 : * Get the name of the time integrator (time integration scheme) used 153 : * @return string with the time integration scheme name 154 : */ 155 : virtual std::vector<std::string> getTimeIntegratorNames() const override; 156 : 157 : /** 158 : * Get the time scheme used 159 : * @return MooseEnum with the time scheme 160 : */ 161 : Moose::TimeIntegratorType getTimeScheme() const { return _time_scheme; } 162 : 163 : /** 164 : * Get the set of sync times 165 : * @return The reference to the set of sync times 166 : */ 167 : std::set<Real> & syncTimes() { return _sync_times; } 168 : 169 : /** 170 : * Get the maximum dt 171 : * @return The maximum dt 172 : */ 173 30856 : Real & dtMax() { return _dtmax; } 174 : 175 : /** 176 : * Get the minimal dt 177 : * @return The minimal dt 178 : */ 179 30856 : Real & dtMin() { return _dtmin; } 180 : 181 : /** 182 : * Return the start time 183 : * @return The start time 184 : */ 185 364 : Real getStartTime() const { return _start_time; } 186 : 187 : /** 188 : * Get the end time 189 : * @return The end time 190 : */ 191 40 : Real getEndTime() const { return _end_time; } 192 : 193 : /** 194 : * Get a modifiable reference to the end time 195 : * @return The end time 196 : */ 197 102403 : Real & endTime() { return _end_time; } 198 : 199 : /** 200 : * Get the timestep tolerance 201 : * @return The timestep tolerance 202 : */ 203 243913 : Real & timestepTol() { return _timestep_tolerance; } 204 : 205 : /** 206 : * Set the timestep tolerance 207 : * @param tolerance timestep tolerance 208 : */ 209 0 : virtual void setTimestepTolerance(const Real & tolerance) { _timestep_tolerance = tolerance; } 210 : 211 : /** 212 : * Is the current step at a sync point (sync times, time interval, target time, etc)? 213 : * @return Bool indicataing whether we are at a sync point 214 : */ 215 5015 : bool atSyncPoint() { return _at_sync_point; } 216 : 217 : /** 218 : * Get the unconstrained dt 219 : * @return Value of dt before constraints were applied 220 : */ 221 540 : Real unconstrainedDT() { return _unconstrained_dt; } 222 : 223 : void parentOutputPositionChanged() override; 224 : 225 : /** 226 : * Set the number of time steps 227 : * @param num_steps number of time steps 228 : */ 229 0 : virtual void forceNumSteps(const unsigned int num_steps) { _num_steps = num_steps; } 230 : 231 : /// Return the solve object wrapped by time stepper 232 253335 : virtual SolveObject * timeStepSolveObject() { return _fixed_point_solve.get(); } 233 : 234 : /// Determines whether the problem has converged to steady state 235 : bool convergedToSteadyState() const; 236 : 237 : protected: 238 : /// Here for backward compatibility 239 : FEProblemBase & _problem; 240 : 241 : /// Reference to auxiliary system base for faster access 242 : AuxiliarySystem & _aux; 243 : 244 : Moose::TimeIntegratorType _time_scheme; 245 : TimeStepper * _time_stepper; 246 : 247 : /// Current timestep. 248 : int & _t_step; 249 : /// Current time 250 : Real & _time; 251 : /// Previous time 252 : Real & _time_old; 253 : /// Current delta t... or timestep size. 254 : Real & _dt; 255 : Real & _dt_old; 256 : 257 : Real & _unconstrained_dt; 258 : bool & _at_sync_point; 259 : 260 : /// Whether or not the last solve converged 261 : bool & _last_solve_converged; 262 : 263 : /// Whether step should be repeated due to xfem modifying the mesh 264 : bool _xfem_repeat_step; 265 : 266 : Real _end_time; 267 : Real _dtmin; 268 : Real _dtmax; 269 : unsigned int _num_steps; 270 : int _n_startup_steps; 271 : 272 : /** 273 : * Steady state detection variables: 274 : */ 275 : const bool _steady_state_detection; 276 : const Real _steady_state_start_time; 277 : 278 : std::set<Real> & _sync_times; 279 : 280 : bool _abort; 281 : /// This parameter controls how the system will deal with _dt <= _dtmin 282 : /// If true, the time stepper is expected to throw an error 283 : /// If false, the executioner will continue through EXEC_FINAL 284 : const bool _error_on_dtmin; 285 : 286 : ///if to use time interval output 287 : bool & _time_interval; 288 : Real _next_interval_output_time; 289 : Real _time_interval_output_interval; 290 : 291 : Real _start_time; 292 : Real _timestep_tolerance; 293 : Real & _target_time; 294 : bool _use_multiapp_dt; 295 : 296 : void setupTimeIntegrator(); 297 : 298 : private: 299 : /// Constrain the timestep dt_cur by looking at the timesteps for the MultiApps on execute_on 300 : void constrainDTFromMultiApp(Real & dt_cur, 301 : std::ostringstream & diag, 302 : const ExecFlagType & execute_on) const; 303 : 304 : /// The timestep we fail and repeat if --test-restep is enabled 305 : std::optional<int> _test_restep_step; 306 : /// If the time is greater than this then we fail and repeat if --test-restep is enabled 307 : std::optional<Real> _test_restep_time; 308 : /// Whether or not the last timestep we solved is being repeated with --test-restep 309 : bool _testing_restep; 310 : };