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

Generated by: LCOV version 1.14