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 69018 : ChainControlSetupAction::validParams() 19 : { 20 69018 : InputParameters params = Action::validParams(); 21 69018 : params.addClassDescription("Performs various setup tasks and checks for ChainControls."); 22 69018 : return params; 23 0 : } 24 : 25 69018 : ChainControlSetupAction::ChainControlSetupAction(const InputParameters & parameters) 26 69018 : : Action(parameters) 27 : { 28 69018 : } 29 : 30 : void 31 62643 : ChainControlSetupAction::act() 32 : { 33 : // Get the ChainControlData map 34 : const auto & chain_control_data_map = 35 62643 : getMooseApp().getChainControlDataSystem().getChainControlDataMap(); 36 : 37 : // Check that all chain control data that was retrieved was declared somewhere 38 63210 : for (const auto & item : chain_control_data_map) 39 567 : if (!item.second->getDeclared()) 40 0 : mooseError("The chain control data '", 41 0 : item.first, 42 : "' was requested but never declared.\nChain control data:\n", 43 0 : getMooseApp().getChainControlDataSystem().outputChainControlMap()); 44 : 45 : // Get the ChainControls 46 62643 : auto & control_warehouse = _problem->getControlWarehouse(); 47 : 48 : // Call init() on each ChainControl 49 64280 : for (auto & control_shared_ptr : control_warehouse.getObjects()) 50 : { 51 1641 : auto chain_control = dynamic_cast<ChainControl *>(control_shared_ptr.get()); 52 1641 : if (chain_control) 53 585 : 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. 58 62639 : getMooseApp().getChainControlDataSystem().copyValuesBack(); 59 : 60 : // Add ChainControl dependencies based on ChainControlData dependencies 61 64264 : for (auto & control_shared_ptr : control_warehouse.getObjects()) 62 : { 63 1625 : auto chain_control = dynamic_cast<ChainControl *>(control_shared_ptr.get()); 64 1625 : if (chain_control) 65 : { 66 : // Get the control's dependencies on control data 67 569 : const auto & data_dep_names = chain_control->getChainControlDataDependencies(); 68 921 : for (const auto & data_dep_name : data_dep_names) 69 : { 70 : // Get the name of the control object that declared the control data 71 352 : const auto & data_dep = *chain_control_data_map.at(data_dep_name); 72 352 : 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 352 : auto & control_deps = chain_control->getDependencies(); 76 352 : if (std::find(control_deps.begin(), control_deps.end(), control_dep_name) == 77 704 : control_deps.end()) 78 352 : control_deps.push_back(control_dep_name); 79 352 : } 80 : } 81 : } 82 62639 : }