https://mooseframework.inl.gov
AutoCheckpointAction.C
Go to the documentation of this file.
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 
17 {
19 
20  params.addClassDescription(
21  "Action to create shortcut syntax-specified checkpoints and automatic checkpoints.");
22 
23  params.addParam<bool>("checkpoint", false, "Create checkpoint files using the default options.");
24  params.addParam<bool>("wall_time_checkpoint",
25  true,
26  "Enables the output of checkpoints based on elapsed wall time.");
27 
28  return params;
29 }
30 
32 
33 void
35 {
36  // if there's already a checkpoint object, we don't need to worry about creating a new one
37  const auto checkpoints = _app.getOutputWarehouse().getOutputs<Checkpoint>();
38  const auto num_checkpoints = checkpoints.size();
39 
40  const bool shortcut_syntax = getParam<bool>("checkpoint");
41 
42  if (num_checkpoints > 1)
43  checkpoints[0]->mooseError("Multiple Checkpoint objects are not allowed and there is more than "
44  "one Checkpoint defined in the 'Outputs' block.");
45  if (num_checkpoints == 1 && shortcut_syntax)
46  paramError("checkpoint",
47  "Shortcut checkpoint syntax cannot be used with another Checkpoint object in the "
48  "'Outputs' block");
49 
50  if (num_checkpoints == 0)
51  {
52  // If there isn't an existing checkpoint, init a new one
53  auto cp_params = _factory.getValidParams("Checkpoint");
54 
55  cp_params.set<bool>("_built_by_moose") = true;
56  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  if (!shortcut_syntax)
61  cp_params.set<CheckpointType>("checkpoint_type") = CheckpointType::SYSTEM_CREATED;
62 
63  // We only want checkpoints in subapps if the user requests them
64  if (shortcut_syntax || _app.isUltimateMaster())
65  _problem->addOutput("Checkpoint", "checkpoint", cp_params);
66  }
67 
68  // Check for special half transient test harness case
70  {
71  // For half transient, we want to simulate a user-created checkpoint so
72  // time_step_interval works correctly.
73  const auto checkpoint = _app.getOutputWarehouse().getOutputs<Checkpoint>()[0];
75  checkpoint->_time_step_interval = 1;
76  }
77 }
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition: MooseApp.h:813
CheckpointType
Enumerated type for determining what type of checkpoint this is.
Definition: Checkpoint.h:28
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition: MooseBase.h:435
Factory & _factory
The Factory associated with the MooseApp.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition: Factory.C:68
std::vector< T * > getOutputs(const std::vector< OutputName > &names)
Return a vector of objects by names.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for actions.
Definition: Action.h:33
AutoCheckpointAction(const InputParameters &params)
static InputParameters validParams()
Definition: Action.C:26
Writes out three things:
Definition: Checkpoint.h:63
static InputParameters validParams()
bool testCheckpointHalfTransient() const
Whether or not this simulation should only run half its transient (useful for testing recovery) ...
Definition: MooseApp.h:511
MooseApp & _app
The MOOSE application this is associated with.
Definition: MooseBase.h:353
registerMooseAction("MooseApp", AutoCheckpointAction, "auto_checkpoint_action")
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type and optionally a file path to the top-level block p...
Definition: MooseBase.h:267
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:171
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an optional parameter and a documentation string to the InputParameters object...
void setAutosaveFlag(CheckpointType flag)
Sets the autosave flag manually if the object has already been initialized.
Definition: Checkpoint.h:89
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition: MooseApp.C:2442