https://mooseframework.inl.gov
Loading...
Searching...
No Matches
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
11#include "FEProblem.h"
12#include "Checkpoint.h"
13registerMooseAction("MooseApp", AutoCheckpointAction, "auto_checkpoint_action");
14
17{
19
21 "Action to create shortcut syntax-specified checkpoints and automatic checkpoints.");
22
23 params.addParam<bool>("checkpoint", "Create checkpoint files using the default options.");
24
25 return params;
26}
27
29
30void
32{
33 // if there's already a checkpoint object, we don't need to worry about creating a new one
34 const auto checkpoints = _app.getOutputWarehouse().getOutputs<Checkpoint>();
35 const auto num_checkpoints = checkpoints.size();
36
37 const bool user_specified_checkpoint_behavior = isParamValid("checkpoint");
38 const bool user_requested_checkpoint =
39 user_specified_checkpoint_behavior && getParam<bool>("checkpoint");
40 const bool user_requested_no_checkpoint =
41 user_specified_checkpoint_behavior && (getParam<bool>("checkpoint") == false);
42
43 if (num_checkpoints > 1)
44 checkpoints[0]->mooseError("Multiple Checkpoint objects are not allowed and there is more than "
45 "one Checkpoint defined in the 'Outputs' block.");
46 if (num_checkpoints == 1 && user_requested_checkpoint)
47 paramError("checkpoint",
48 "Shortcut checkpoint syntax cannot be used with another Checkpoint object in the "
49 "'Outputs' block");
50
51 if (num_checkpoints == 0 &&
52 (user_requested_checkpoint || (_app.isUltimateMaster() && !user_requested_no_checkpoint)))
53 {
54 // If there isn't an existing checkpoint, init a new one
55 auto cp_params = _factory.getValidParams("Checkpoint");
56
57 cp_params.set<bool>("_built_by_moose") = true;
58 if (!user_requested_checkpoint)
59 // This is our auto-created wall-time based checkpoint, so disable the time step interval by
60 // default
61 cp_params.set<unsigned int>("time_step_interval", /*allow_override_by_common_output=*/true) =
62 std::numeric_limits<unsigned int>::max();
63
64 _problem->addOutput("Checkpoint", "checkpoint", cp_params);
65 }
66
67 // Check for special half transient test harness case
69 {
70 // For half transient, we want to simulate a user-created checkpoint so
71 // time_step_interval works correctly.
72 const auto checkpoint = _app.getOutputWarehouse().getOutputs<Checkpoint>()[0];
73 checkpoint->_time_step_interval = 1;
74 }
75}
registerMooseAction("MooseApp", AutoCheckpointAction, "auto_checkpoint_action")
Base class for actions.
Definition Action.h:38
static InputParameters validParams()
Definition Action.C:26
MooseApp & _app
The MOOSE application this is associated with.
Definition MooseBase.h:375
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition Action.h:178
AutoCheckpointAction(const InputParameters &params)
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
static InputParameters validParams()
Writes out three things:
Definition Checkpoint.h:49
InputParameters getValidParams(const std::string &name) const
Get valid parameters for the object.
Definition Factory.C:68
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
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 addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump.
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
OutputWarehouse & getOutputWarehouse()
Get the OutputWarehouse objects.
Definition MooseApp.C:2409
bool isUltimateMaster() const
Whether or not this app is the ultimate master app.
Definition MooseApp.h:866
bool testCheckpointHalfTransient() const
Whether or not this simulation should only run half its transient (useful for testing recovery)
Definition MooseApp.h:524
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:457
bool isParamValid(const std::string &name) const
Test if the supplied parameter is valid.
Definition MooseBase.h:199
std::vector< T * > getOutputs(const std::vector< OutputName > &names)
Return a vector of objects by names.
unsigned int _time_step_interval
The output time step interval.
Definition Output.h:235
Factory & _factory
The Factory associated with the MooseApp.