Line data Source code
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 "ChainControlSetupAction.h" 11 : #include "ChainControlDataSystem.h" 12 : #include "ChainControl.h" 13 : #include "FEProblemBase.h" 14 : 15 : registerMooseAction("MooseApp", ChainControlSetupAction, "chain_control_setup"); 16 : 17 : InputParameters 18 61934 : ChainControlSetupAction::validParams() 19 : { 20 61934 : InputParameters params = Action::validParams(); 21 61934 : params.addClassDescription("Performs various setup tasks and checks for ChainControls."); 22 61934 : return params; 23 0 : } 24 : 25 61934 : ChainControlSetupAction::ChainControlSetupAction(const InputParameters & parameters) 26 61934 : : Action(parameters) 27 : { 28 61934 : } 29 : 30 : void 31 56059 : ChainControlSetupAction::act() 32 : { 33 : // Get the ChainControlData map 34 : const auto & chain_control_data_map = 35 56059 : getMooseApp().getChainControlDataSystem().getChainControlDataMap(); 36 : 37 : // Check that all chain control data that was retrieved was declared somewhere 38 56491 : for (const auto & item : chain_control_data_map) 39 432 : if (!item.second->getDeclared()) 40 0 : mooseError("The chain control data '", item.first, "' was requested but never declared."); 41 : 42 : // Get the ChainControls 43 56059 : auto & control_warehouse = _problem->getControlWarehouse(); 44 : 45 : // Call init() on each ChainControl 46 57368 : for (auto & control_shared_ptr : control_warehouse.getObjects()) 47 : { 48 1313 : auto chain_control = dynamic_cast<ChainControl *>(control_shared_ptr.get()); 49 1313 : if (chain_control) 50 426 : 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. 55 56055 : getMooseApp().getChainControlDataSystem().copyValuesBack(); 56 : 57 : // Add ChainControl dependencies based on ChainControlData dependencies 58 57352 : for (auto & control_shared_ptr : control_warehouse.getObjects()) 59 : { 60 1297 : auto chain_control = dynamic_cast<ChainControl *>(control_shared_ptr.get()); 61 1297 : if (chain_control) 62 : { 63 : // Get the control's dependencies on control data 64 410 : const auto & data_dep_names = chain_control->getChainControlDataDependencies(); 65 642 : for (const auto & data_dep_name : data_dep_names) 66 : { 67 : // Get the name of the control object that declared the control data 68 232 : const auto & data_dep = *chain_control_data_map.at(data_dep_name); 69 232 : 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 232 : auto & control_deps = chain_control->getDependencies(); 73 232 : if (std::find(control_deps.begin(), control_deps.end(), control_dep_name) == 74 464 : control_deps.end()) 75 232 : control_deps.push_back(control_dep_name); 76 232 : } 77 : } 78 : } 79 56055 : }