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 66081 : AutoCheckpointAction::validParams() 17 : { 18 66081 : InputParameters params = Action::validParams(); 19 : 20 132162 : params.addClassDescription( 21 : "Action to create shortcut syntax-specified checkpoints and automatic checkpoints."); 22 : 23 198243 : params.addParam<bool>("checkpoint", "Create checkpoint files using the default options."); 24 : 25 66081 : return params; 26 0 : } 27 : 28 66031 : AutoCheckpointAction::AutoCheckpointAction(const InputParameters & params) : Action(params) {} 29 : 30 : void 31 60372 : AutoCheckpointAction::act() 32 : { 33 : // if there's already a checkpoint object, we don't need to worry about creating a new one 34 60372 : const auto checkpoints = _app.getOutputWarehouse().getOutputs<Checkpoint>(); 35 60372 : const auto num_checkpoints = checkpoints.size(); 36 : 37 120744 : const bool user_specified_checkpoint_behavior = isParamValid("checkpoint"); 38 : const bool user_requested_checkpoint = 39 60782 : user_specified_checkpoint_behavior && getParam<bool>("checkpoint"); 40 : const bool user_requested_no_checkpoint = 41 60782 : user_specified_checkpoint_behavior && (getParam<bool>("checkpoint") == false); 42 : 43 60372 : if (num_checkpoints > 1) 44 3 : checkpoints[0]->mooseError("Multiple Checkpoint objects are not allowed and there is more than " 45 : "one Checkpoint defined in the 'Outputs' block."); 46 60369 : if (num_checkpoints == 1 && user_requested_checkpoint) 47 6 : paramError("checkpoint", 48 : "Shortcut checkpoint syntax cannot be used with another Checkpoint object in the " 49 : "'Outputs' block"); 50 : 51 120115 : if (num_checkpoints == 0 && 52 59749 : (user_requested_checkpoint || (_app.isUltimateMaster() && !user_requested_no_checkpoint))) 53 : { 54 : // If there isn't an existing checkpoint, init a new one 55 144228 : auto cp_params = _factory.getValidParams("Checkpoint"); 56 : 57 48076 : cp_params.set<bool>("_built_by_moose") = true; 58 48076 : if (!user_requested_checkpoint) 59 : // This is our auto-created wall-time based checkpoint, so disable the time step interval by 60 : // default 61 95396 : cp_params.set<unsigned int>("time_step_interval", /*allow_override_by_common_output=*/true) = 62 47698 : std::numeric_limits<unsigned int>::max(); 63 : 64 192304 : _problem->addOutput("Checkpoint", "checkpoint", cp_params); 65 48076 : } 66 : 67 : // Check for special half transient test harness case 68 60366 : if (_app.testCheckpointHalfTransient() && _app.isUltimateMaster()) 69 : { 70 : // For half transient, we want to simulate a user-created checkpoint so 71 : // time_step_interval works correctly. 72 3214 : const auto checkpoint = _app.getOutputWarehouse().getOutputs<Checkpoint>()[0]; 73 3214 : checkpoint->_time_step_interval = 1; 74 : } 75 60366 : }