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