LCOV - code coverage report
Current view: top level - src/times - TimeIntervalTimes.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 32 35 91.4 %
Date: 2025-07-17 01:28:37 Functions: 2 2 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             : #include "TimeIntervalTimes.h"
      11             : #include "MooseUtils.h"
      12             : #include "Transient.h"
      13             : 
      14             : registerMooseObject("MooseApp", TimeIntervalTimes);
      15             : 
      16             : InputParameters
      17       14333 : TimeIntervalTimes::validParams()
      18             : {
      19       14333 :   InputParameters params = Times::validParams();
      20       14333 :   params.addClassDescription("Times between a start time and end time with a fixed time interval.");
      21       14333 :   params.addRequiredRangeCheckedParam<Real>(
      22             :       "time_interval", "time_interval > 0", "Time interval between times");
      23       14333 :   params.addParam<Real>("start_time",
      24             :                         "Start time. If not provided, the simulation start time is used.");
      25       14333 :   params.addParam<Real>("end_time", "End time. If not provided, the simulation end time is used.");
      26       42999 :   params.addParam<bool>(
      27             :       "always_include_end_time",
      28       28666 :       true,
      29             :       "If true, includes the end time even if the last time interval would be partial");
      30             : 
      31             :   // Times are known for all processes already
      32       14333 :   params.set<bool>("auto_broadcast") = false;
      33             : 
      34       14333 :   return params;
      35           0 : }
      36             : 
      37          36 : TimeIntervalTimes::TimeIntervalTimes(const InputParameters & parameters) : Times(parameters)
      38             : {
      39             :   // Get start time
      40             :   Real start_time;
      41          36 :   if (isParamValid("start_time"))
      42          12 :     start_time = getParam<Real>("start_time");
      43             :   else
      44             :   {
      45          24 :     if (auto transient = dynamic_cast<TransientBase *>(_app.getExecutioner()))
      46          20 :       start_time = transient->getStartTime();
      47             :     else
      48           4 :       mooseError("If the parameter 'start_time' is not provided, the executioner type must be "
      49             :                  "'Transient'.");
      50             :   }
      51             : 
      52             :   // Get end time
      53             :   Real end_time;
      54          32 :   if (isParamValid("end_time"))
      55          12 :     end_time = getParam<Real>("end_time");
      56             :   else
      57             :   {
      58          20 :     if (auto transient = dynamic_cast<TransientBase *>(_app.getExecutioner()))
      59          20 :       end_time = transient->endTime();
      60             :     else
      61           0 :       mooseError(
      62             :           "If the parameter 'end_time' is not provided, the executioner type must be 'Transient'.");
      63             :   }
      64             : 
      65          32 :   if (MooseUtils::absoluteFuzzyLessEqual(end_time, start_time))
      66           0 :     mooseError("The end time must be greater than the start time.");
      67             : 
      68          32 :   const auto time_interval = getParam<Real>("time_interval");
      69          32 :   const bool always_include_end_time = getParam<bool>("always_include_end_time");
      70             : 
      71          32 :   _times.push_back(start_time);
      72             :   while (true)
      73             :   {
      74          96 :     const auto proposed_new_time = _times.back() + time_interval;
      75          96 :     if (MooseUtils::absoluteFuzzyGreaterThan(proposed_new_time, end_time))
      76             :     {
      77          32 :       if (always_include_end_time && !MooseUtils::absoluteFuzzyEqual(_times.back(), end_time))
      78          10 :         _times.push_back(end_time);
      79          32 :       break;
      80             :     }
      81             :     else
      82          64 :       _times.push_back(proposed_new_time);
      83          64 :   }
      84          32 : }

Generated by: LCOV version 1.14