LCOV - code coverage report
Current view: top level - src/actions - AutoCheckpointAction.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 30 31 96.8 %
Date: 2025-08-08 20:01:16 Functions: 3 3 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 "AutoCheckpointAction.h"
      11             : #include "FEProblem.h"
      12             : #include "Checkpoint.h"
      13             : registerMooseAction("MooseApp", AutoCheckpointAction, "auto_checkpoint_action");
      14             : 
      15             : InputParameters
      16       67073 : AutoCheckpointAction::validParams()
      17             : {
      18       67073 :   InputParameters params = Action::validParams();
      19             : 
      20       67073 :   params.addClassDescription(
      21             :       "Action to create shortcut syntax-specified checkpoints and automatic checkpoints.");
      22             : 
      23       67073 :   params.addParam<bool>("checkpoint", false, "Create checkpoint files using the default options.");
      24      201219 :   params.addParam<bool>("wall_time_checkpoint",
      25      134146 :                         true,
      26             :                         "Enables the output of checkpoints based on elapsed wall time.");
      27             : 
      28       67073 :   return params;
      29           0 : }
      30             : 
      31       66869 : AutoCheckpointAction::AutoCheckpointAction(const InputParameters & params) : Action(params) {}
      32             : 
      33             : void
      34       61249 : AutoCheckpointAction::act()
      35             : {
      36             :   // if there's already a checkpoint object, we don't need to worry about creating a new one
      37       61249 :   const auto checkpoints = _app.getOutputWarehouse().getOutputs<Checkpoint>();
      38       61249 :   const auto num_checkpoints = checkpoints.size();
      39             : 
      40       61249 :   const bool shortcut_syntax = getParam<bool>("checkpoint");
      41             : 
      42       61249 :   if (num_checkpoints > 1)
      43           4 :     checkpoints[0]->mooseError("Multiple Checkpoint objects are not allowed and there is more than "
      44             :                                "one Checkpoint defined in the 'Outputs' block.");
      45       61245 :   if (num_checkpoints == 1 && shortcut_syntax)
      46           4 :     paramError("checkpoint",
      47             :                "Shortcut checkpoint syntax cannot be used with another Checkpoint object in the "
      48             :                "'Outputs' block");
      49             : 
      50       61241 :   if (num_checkpoints == 0)
      51             :   {
      52             :     // If there isn't an existing checkpoint, init a new one
      53       60961 :     auto cp_params = _factory.getValidParams("Checkpoint");
      54             : 
      55       60961 :     cp_params.set<bool>("_built_by_moose") = true;
      56       60961 :     cp_params.set<bool>("wall_time_checkpoint") = getParam<bool>("wall_time_checkpoint");
      57             : 
      58             :     // We need to keep track of what type of checkpoint we are creating. system created means the
      59             :     // default value of 1 for time_step_interval is ignored.
      60       60961 :     if (!shortcut_syntax)
      61       60568 :       cp_params.set<CheckpointType>("checkpoint_type") = CheckpointType::SYSTEM_CREATED;
      62             : 
      63             :     // We only want checkpoints in subapps if the user requests them
      64       60961 :     if (shortcut_syntax || _app.isUltimateMaster())
      65       48686 :       _problem->addOutput("Checkpoint", "checkpoint", cp_params);
      66       60961 :   }
      67             : 
      68             :   // Check for special half transient test harness case
      69       61241 :   if (_app.testCheckpointHalfTransient() && _app.isUltimateMaster())
      70             :   {
      71             :     // For half transient, we want to simulate a user-created checkpoint so
      72             :     // time_step_interval works correctly.
      73        2837 :     const auto checkpoint = _app.getOutputWarehouse().getOutputs<Checkpoint>()[0];
      74        2837 :     checkpoint->setAutosaveFlag(CheckpointType::USER_CREATED);
      75        2837 :     checkpoint->_time_step_interval = 1;
      76             :   }
      77       61241 : }

Generated by: LCOV version 1.14