https://mooseframework.inl.gov
ChainControlSetupAction.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 "ChainControlDataSystem.h"
12 #include "ChainControl.h"
13 #include "FEProblemBase.h"
14 
15 registerMooseAction("MooseApp", ChainControlSetupAction, "chain_control_setup");
16 
19 {
21  params.addClassDescription("Performs various setup tasks and checks for ChainControls.");
22  return params;
23 }
24 
26  : Action(parameters)
27 {
28 }
29 
30 void
32 {
33  // Get the ChainControlData map
34  const auto & chain_control_data_map =
36 
37  // Check that all chain control data that was retrieved was declared somewhere
38  for (const auto & item : chain_control_data_map)
39  if (!item.second->getDeclared())
40  mooseError("The chain control data '", item.first, "' was requested but never declared.");
41 
42  // Get the ChainControls
43  auto & control_warehouse = _problem->getControlWarehouse();
44 
45  // Call init() on each ChainControl
46  for (auto & control_shared_ptr : control_warehouse.getObjects())
47  {
48  auto chain_control = dynamic_cast<ChainControl *>(control_shared_ptr.get());
49  if (chain_control)
50  chain_control->init();
51  }
52 
53  // Copy initial current values back into old values.
54  // Note that if an "older" state value is ever added, this will need to be called twice.
56 
57  // Add ChainControl dependencies based on ChainControlData dependencies
58  for (auto & control_shared_ptr : control_warehouse.getObjects())
59  {
60  auto chain_control = dynamic_cast<ChainControl *>(control_shared_ptr.get());
61  if (chain_control)
62  {
63  // Get the control's dependencies on control data
64  const auto & data_dep_names = chain_control->getChainControlDataDependencies();
65  for (const auto & data_dep_name : data_dep_names)
66  {
67  // Get the name of the control object that declared the control data
68  const auto & data_dep = *chain_control_data_map.at(data_dep_name);
69  const auto control_dep_name = data_dep.getChainControl().name();
70 
71  // Add this name to the list of the control's dependencies if not present
72  auto & control_deps = chain_control->getDependencies();
73  if (std::find(control_deps.begin(), control_deps.end(), control_dep_name) ==
74  control_deps.end())
75  control_deps.push_back(control_dep_name);
76  }
77  }
78  }
79 }
static InputParameters validParams()
registerMooseAction("MooseApp", ChainControlSetupAction, "chain_control_setup")
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void copyValuesBack()
Copies current chain control data values into old values.
Base class for actions.
Definition: Action.h:33
MooseApp & getMooseApp() const
Get the MooseApp this class is associated with.
Definition: MooseBase.h:45
static InputParameters validParams()
Definition: Action.C:24
virtual void act() override
Method to add objects to the simulation or perform other setup tasks.
Performs various setup tasks and checks for ChainControls.
virtual void init()
Initialization that occurs in ChainControlSetupAction, right before the dependencies are added...
Definition: ChainControl.h:35
const std::vector< std::string > & getChainControlDataDependencies() const
Returns the ChainControls that must run before this one.
Definition: ChainControl.h:40
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
ChainControlDataSystem & getChainControlDataSystem()
Gets the system that manages the ChainControls.
Definition: MooseApp.h:868
std::shared_ptr< FEProblemBase > & _problem
Convenience reference to a problem this action works on.
Definition: Action.h:168
ChainControlSetupAction(const InputParameters &parameters)
const std::map< std::string, std::unique_ptr< ChainControlDataBase > > & getChainControlDataMap() const
Gets the map of ChainControlData names to the relevant ChainControlDataBase.
Control that additionally provides the capability to produce/consume data values, to allow control op...
Definition: ChainControl.h:21