https://mooseframework.inl.gov
StochasticToolsAction.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 "StochasticToolsAction.h"
11 #include "ActionWarehouse.h"
12 #include "ActionFactory.h"
13 #include "MooseEnum.h"
14 #include "SetupMeshAction.h"
15 #include "CreateProblemAction.h"
16 
17 registerMooseAction("StochasticToolsApp", StochasticToolsAction, "auto_create_mesh");
18 registerMooseAction("StochasticToolsApp", StochasticToolsAction, "auto_create_problem");
19 registerMooseAction("StochasticToolsApp", StochasticToolsAction, "auto_create_executioner");
20 
23 {
25  params.addClassDescription(
26  "Action for performing some common functions for running stochastic simulations.");
27  params.addParam<bool>(
28  "auto_create_mesh",
29  true,
30  "Automatically setup the Mesh block for a master application without a simulation.");
31  params.addParam<bool>(
32  "auto_create_problem",
33  true,
34  "Automatically setup the Problem block for a master application without a simulation.");
35  params.addParam<bool>(
36  "auto_create_executioner",
37  true,
38  "Automatically setup the Executioner block for a master application without a simulation.");
39  return params;
40 }
41 
43 
44 void
46 {
47  // [Mesh]
48  if (_current_task == "auto_create_mesh" && getParam<bool>("auto_create_mesh") &&
49  !_awh.hasActions("setup_mesh"))
50  {
51  // Build the Action parameters
52  InputParameters action_params = _action_factory.getValidParams("SetupMeshAction");
53  action_params.set<std::string>("type") = "GeneratedMesh";
54 
55  // Associate errors with "auto_create_mesh"
56  associateWithParameter("auto_create_mesh", action_params);
57 
58  // Create The Action
59  auto action = std::static_pointer_cast<MooseObjectAction>(
60  _action_factory.create("SetupMeshAction", "Mesh", action_params));
61 
62  // Set the object parameters
63  InputParameters & params = action->getObjectParams();
64  params.set<MooseEnum>("dim") = "1";
65  params.set<unsigned int>("nx") = 1;
66 
67  // Add Action to the warehouse
68  _awh.addActionBlock(action);
69  }
70 
71  // [Problem]
72  else if (_current_task == "auto_create_problem" && getParam<bool>("auto_create_problem"))
73  {
74  if (_awh.hasActions("create_problem"))
75  {
76  for (const auto & act : _awh.getActionListByName("create_problem"))
77  {
78  auto * action = dynamic_cast<CreateProblemAction *>(act);
79  if (action)
80  {
81  InputParameters & params = action->getObjectParams();
82 
83  if (!params.isParamSetByUser("solve"))
84  params.set<bool>("solve") = false;
85 
86  if (!params.isParamSetByUser("kernel_coverage_check"))
87  params.set<MooseEnum>("kernel_coverage_check") = "false";
88 
89  if (!params.isParamSetByUser("skip_nl_system_check"))
90  params.set<bool>("skip_nl_system_check") = true;
91  }
92  }
93  }
94  else
95  {
96  // Build the Action parameters
97  InputParameters action_params = _action_factory.getValidParams("CreateProblemAction");
98 
99  // Associate errors with "auto_create_problem"
100  associateWithParameter("auto_create_problem", action_params);
101 
102  // Create the action
103  auto action = std::static_pointer_cast<MooseObjectAction>(
104  _action_factory.create("CreateProblemAction", "Problem", action_params));
105 
106  // Set the object parameters
107  InputParameters & params = action->getObjectParams();
108  params.set<bool>("solve") = false;
109  params.set<MooseEnum>("kernel_coverage_check") = "false";
110  params.set<bool>("skip_nl_system_check") = true;
111 
112  // Add Action to the warehouse
113  _awh.addActionBlock(action);
114  }
115  }
116 
117  // [Executioner]
118  else if (_current_task == "auto_create_executioner" &&
119  getParam<bool>("auto_create_executioner") && !_awh.hasActions("setup_executioner"))
120  {
121  // Build the Action parameters
122  InputParameters action_params = _action_factory.getValidParams("CreateExecutionerAction");
123  action_params.set<std::string>("type") = "Steady";
124 
125  // Associate errors with "auto_create_executioner"
126  associateWithParameter("auto_create_executioner", action_params);
127 
128  // Create the action
129  auto action = std::static_pointer_cast<MooseObjectAction>(
130  _action_factory.create("CreateExecutionerAction", "Executioner", action_params));
131 
132  // Add Action to the warehouse
133  _awh.addActionBlock(action);
134  }
135 }
ActionWarehouse & _awh
virtual void act() override
void addParam(const std::string &name, const std::initializer_list< typename T::value_type > &value, const std::string &doc_string)
InputParameters getValidParams(const std::string &name)
Helper for performing common tasks for stochastic simulations.
T & set(const std::string &name, bool quiet_mode=false)
registerMooseAction("StochasticToolsApp", StochasticToolsAction, "auto_create_mesh")
void addActionBlock(std::shared_ptr< Action > blk)
const std::list< Action *> & getActionListByName(const std::string &task) const
std::shared_ptr< Action > create(const std::string &action, const std::string &action_name, InputParameters &parameters)
static InputParameters validParams()
static InputParameters validParams()
const std::string & _current_task
ActionFactory & _action_factory
bool isParamSetByUser(const std::string &name) const
bool hasActions(const std::string &task) const
void associateWithParameter(const std::string &param_name, InputParameters &params) const
void addClassDescription(const std::string &doc_string)
StochasticToolsAction(const InputParameters &params)