LCOV - code coverage report
Current view: top level - include/timesteppers - CompositionDT.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 2 2 100.0 %
Date: 2025-07-17 01:28:37 Functions: 1 1 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             : #pragma once
      11             : 
      12             : #include "TimeStepper.h"
      13             : #include "TimeSequenceStepperBase.h"
      14             : 
      15             : /**
      16             :  * A TimeStepper that takes time steppers as inputs and computes the minimum time step size among
      17             :  * all time steppers as output. If any time sequence stepper(s) is supplied for input, CompositionDT
      18             :  * will compare the computed minimum time step size with the one needs to hit the time point, then
      19             :  * select the smaller value as output. An optional parameter lower_bound is provided
      20             :  * to set a lower bound for the computed time step size.
      21             :  *
      22             :  * The composition rules are listed with priority rank:
      23             :  * 1. The time points from time sequence stepper(s) must be hit;
      24             :  * 2. The time step size can not go below the lower_bound;
      25             :  * 3. Take the minimum value of all input time steppers.
      26             :  */
      27             : class CompositionDT : public TimeStepper
      28             : {
      29             : public:
      30             :   /**
      31             :    * @returns The parameters that are unique to CompositionDT
      32             :    *
      33             :    * This is separate so that ComposeTimeStepperAction can also
      34             :    * add these parameters.
      35             :    */
      36             :   static InputParameters compositionDTParams();
      37             :   static InputParameters validParams();
      38             : 
      39             :   CompositionDT(const InputParameters & parameters);
      40             : 
      41             :   /**
      42             :    * Comparator for sorting by the value of dt for the TimeStepper sets which stored the pairs of
      43             :    * the dt and TimeStepper
      44             :    */
      45             :   struct CompareFirst
      46             :   {
      47        2728 :     bool operator()(const std::pair<Real, TimeStepper *> & a,
      48             :                     const std::pair<Real, TimeStepper *> & b) const
      49             :     {
      50        2728 :       return a.first < b.first;
      51             :     }
      52             :   };
      53             :   /**
      54             :    * Find the composed time step size by selecting the minimum value and compare it
      55             :    * with the lower bound if provided
      56             :    * @param dts stores time step size(s) from input time stepper(s)
      57             :    * @param bound_dts stores time step size(s) from input lower bound time stepper(s)
      58             :    */
      59             :   Real produceCompositionDT(std::set<std::pair<Real, TimeStepper *>, CompareFirst> & dts,
      60             :                             std::set<std::pair<Real, TimeStepper *>, CompareFirst> & bound_dts);
      61             : 
      62             :   // Find the time point to hit at current time step
      63             :   Real getSequenceSteppersNextTime();
      64             : 
      65             :   /**
      66             :    * Initialize all the input time stepper(s). Called at the very beginning of
      67             :    * Executioner::execute()
      68             :    */
      69             :   virtual void init() override final;
      70             :   virtual void preExecute() override final;
      71             :   virtual void preSolve() override final;
      72             :   virtual void postSolve() override final;
      73             :   virtual void postExecute() override final;
      74             :   virtual void preStep() override final;
      75             :   virtual void postStep() override final;
      76             :   virtual bool constrainStep(Real & dt) override final;
      77             : 
      78             :   /**
      79             :    * Functions called after the current DT is computed
      80             :    */
      81             : 
      82             :   /**
      83             :    * Take a time step with _current_time_stepper step() function
      84             :    */
      85             :   virtual void step() override final;
      86             : 
      87             :   /**
      88             :    * This gets called when time step is accepted for all input time steppers
      89             :    */
      90             :   virtual void acceptStep() override final;
      91             : 
      92             :   /**
      93             :    * This gets called when time step is rejected for all input time steppers
      94             :    */
      95             :   virtual void rejectStep() override final;
      96             : 
      97             :   /**
      98             :    * The _current_time_stepper is used to check whether convergence was reached on the time step
      99             :    */
     100             :   virtual bool converged() const override final;
     101             : 
     102             : protected:
     103             :   virtual Real computeDT() override final;
     104             :   virtual Real computeInitialDT() override final;
     105             : 
     106             : private:
     107             :   template <typename Lambda>
     108             :   void actOnTimeSteppers(Lambda && act);
     109             : 
     110             :   /**
     111             :    * Internal method for querying TheWarehouse for the currently active timesteppers.
     112             :    */
     113             :   std::vector<TimeStepper *> getTimeSteppers();
     114             : 
     115             :   // The time step size computed by the Composition TimeStepper
     116             :   Real _dt;
     117             : 
     118             :   // Whether or not has an initial time step size
     119             :   const bool _has_initial_dt;
     120             : 
     121             :   // The initial time step size
     122             :   const Real _initial_dt;
     123             : 
     124             :   // The time stepper(s) input as lower bound of the time stepper size
     125             :   const std::set<std::string> _lower_bound;
     126             : 
     127             :   // The time stepper selected for use every time step, based on minimum time step size
     128             :   TimeStepper * _current_time_stepper;
     129             : 
     130             :   // The time stepper selected every time step as providing the lower bound
     131             :   TimeStepper * _largest_bound_time_stepper;
     132             : 
     133             :   // The time sequence stepper selected every time step as the one with the closest time to hit
     134             :   TimeSequenceStepperBase * _closest_time_sequence_stepper;
     135             : };

Generated by: LCOV version 1.14