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 : // MOOSE includes 11 : #include "ActionComponent.h" 12 : #include "ActionFactory.h" 13 : 14 : InputParameters 15 3534 : ActionComponent::validParams() 16 : { 17 3534 : InputParameters params = Action::validParams(); 18 7068 : params.addClassDescription("Base class for components that are defined using actions."); 19 14136 : params.addParam<bool>("verbose", false, "Whether the component setup should be verbose"); 20 : 21 : // These parameters should not appear. Let's suppress them for now 22 7068 : params.suppressParameter<std::vector<std::string>>("active"); 23 3534 : params.suppressParameter<std::vector<std::string>>("inactive"); 24 : 25 3534 : return params; 26 0 : } 27 : 28 544 : ActionComponent::ActionComponent(const InputParameters & params) 29 : : Action(params), 30 : InputParametersChecksUtils<ActionComponent>(this), 31 544 : _dimension(libMesh::invalid_uint), 32 1088 : _verbose(getParam<bool>("verbose")), 33 1088 : _connected_components(std::make_shared<std::set<ActionComponent *>>()) 34 : { 35 544 : _connected_components->insert(this); 36 544 : } 37 : 38 : void 39 1009 : ActionComponent::act() 40 : { 41 : // This is inspired by the PhysicsBase definition of act(). We register components to the 42 : // task they use, and the base class calls the appropriate virtual member functions 43 1009 : mooseDoOnce(checkRequiredTasks()); 44 : 45 : // These tasks are conceptually what we imagine a mostly-geometrical component should do 46 1009 : if (_current_task == "add_mesh_generator") 47 538 : addMeshGenerators(); 48 471 : else if (_current_task == "add_positions") 49 0 : addPositionsObject(); 50 471 : else if (_current_task == "add_user_object") 51 0 : addUserObjects(); 52 471 : else if (_current_task == "setup_component") 53 0 : setupComponent(); 54 : // If we define the Physics in a Physics block. See PhysicsComponentBase 55 471 : else if (_current_task == "init_component_physics") 56 162 : addPhysics(); 57 : // These tasks are there to match what the current combined Physics + Component do 58 : // These combined components will likely still exist in the future, when it makes more 59 : // sense to include the physics than to split it off into its own block 60 309 : else if (_current_task == "add_variable") 61 0 : addSolverVariables(); 62 : // Useful for declaring materials on a component, which helps keep the input of local material 63 : // properties on the component 64 309 : else if (_current_task == "add_material") 65 159 : addMaterials(); 66 150 : else if (_current_task == "check_integrity") 67 150 : checkIntegrity(); 68 : else 69 : // For a new task that isn't registered to ActionComponent in the framework 70 0 : actOnAdditionalTasks(); 71 1003 : } 72 : 73 : void 74 238 : ActionComponent::checkRequiredTasks() const 75 : { 76 238 : const auto registered_tasks = _action_factory.getTasksByAction(type()); 77 : 78 : // Check for missing tasks 79 1190 : for (const auto & required_task : _required_tasks) 80 952 : if (!registered_tasks.count(required_task)) 81 0 : mooseWarning( 82 0 : "Task '" + required_task + 83 0 : "' has been declared as required by a Component parent class of derived class '" + 84 0 : type() + 85 : "' but this task is not registered to the derived class. Registered tasks for " 86 0 : "this Component are: " + 87 0 : Moose::stringify(registered_tasks)); 88 238 : } 89 : 90 : void 91 126 : ActionComponent::addConnectedComponent(ActionComponent & component) 92 : { 93 : // Already in the same group 94 126 : if (_connected_components == component._connected_components) 95 18 : return; 96 : 97 : // Hold a reference to the other group before we re-point its members 98 108 : auto other_group = component._connected_components; 99 108 : _connected_components->insert(other_group->begin(), other_group->end()); 100 : 101 : // Every former member of the other group now shares this group's set 102 216 : for (auto * member : *other_group) 103 108 : member->_connected_components = _connected_components; 104 108 : }