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 "PhysicsComponentInterface.h" 11 : #include "ComponentInitialConditionInterface.h" 12 : 13 : InputParameters 14 676 : PhysicsComponentInterface::validParams() 15 : { 16 676 : InputParameters params = PhysicsBase::validParams(); 17 : // we likely do not need all these parameters. But developers could expect them 18 676 : return params; 19 : } 20 : 21 278 : PhysicsComponentInterface::PhysicsComponentInterface(const InputParameters & parameters) 22 278 : : PhysicsBase(parameters) 23 : { 24 278 : addRequiredPhysicsTask("add_ic"); 25 278 : } 26 : 27 : void 28 2098 : PhysicsComponentInterface::actOnAdditionalTasks() 29 : { 30 : // TODO: find a way to force this routine to be called by derived classes 31 2098 : if (_current_task == "add_ic") 32 234 : addInitialConditionsFromComponents(); 33 1864 : else if (_current_task == "add_bc" || _current_task == "add_fv_bc") 34 226 : addBoundaryConditionsFromComponents(); 35 2090 : } 36 : 37 : void 38 128 : PhysicsComponentInterface::addComponent(const ActionComponent & comp) 39 : { 40 : // Adds the component's blocks to the block restriction at least 41 128 : PhysicsBase::addComponent(comp); 42 : 43 : // Move initial conditions from components to the Physics 44 128 : if (const auto comp_ic = dynamic_cast<const ComponentInitialConditionInterface *>(&comp)) 45 : { 46 256 : for (const auto & var_name : solverVariableNames()) 47 128 : if (comp_ic->hasInitialCondition(var_name)) 48 96 : addInitialCondition(comp.name(), var_name, comp_ic->getInitialCondition(var_name, name())); 49 128 : for (const auto & var_name : auxVariableNames()) 50 0 : if (comp_ic->hasInitialCondition(var_name)) 51 0 : addInitialCondition(comp.name(), var_name, comp_ic->getInitialCondition(var_name, name())); 52 : } 53 : 54 : // Move boundary conditions from components to the Physics 55 128 : if (const auto comp_bc = dynamic_cast<const ComponentBoundaryConditionInterface *>(&comp)) 56 : { 57 256 : for (const auto & var_name : solverVariableNames()) 58 128 : if (comp_bc->hasBoundaryCondition(var_name)) 59 120 : for (const auto & boundary : comp_bc->getBoundaryConditionBoundaries(var_name)) 60 : { 61 : ComponentBoundaryConditionInterface::BoundaryConditionType bc_type; 62 : const auto boundary_functor = 63 68 : comp_bc->getBoundaryCondition(var_name, boundary, name(), bc_type); 64 68 : addBoundaryCondition(comp.name(), var_name, boundary, boundary_functor, bc_type); 65 120 : } 66 128 : for (const auto & var_name : auxVariableNames()) 67 0 : if (comp_bc->hasBoundaryCondition(var_name)) 68 0 : for (const auto & boundary : comp_bc->getBoundaryConditionBoundaries(var_name)) 69 : { 70 : ComponentBoundaryConditionInterface::BoundaryConditionType bc_type; 71 : const auto boundary_functor = 72 0 : comp_bc->getBoundaryCondition(var_name, boundary, name(), bc_type); 73 0 : addBoundaryCondition(comp.name(), var_name, boundary, boundary_functor, bc_type); 74 0 : } 75 : } 76 128 : } 77 : 78 : void 79 96 : PhysicsComponentInterface::addInitialCondition(const ComponentName & component_name, 80 : const VariableName & var_name, 81 : const MooseFunctorName & ic_value) 82 : { 83 96 : _components_initial_conditions[component_name][var_name] = ic_value; 84 96 : } 85 : 86 : void 87 68 : PhysicsComponentInterface::addBoundaryCondition( 88 : const ComponentName & component_name, 89 : const VariableName & var_name, 90 : const BoundaryName & boundary_name, 91 : const MooseFunctorName & bc_value, 92 : const ComponentBoundaryConditionInterface::BoundaryConditionType & bc_type) 93 : { 94 136 : _components_boundary_conditions[component_name][std::make_pair(var_name, boundary_name)] = 95 204 : std::make_pair(bc_value, bc_type); 96 68 : } 97 : 98 : void 99 8 : PhysicsComponentInterface::addInitialConditionsFromComponents() 100 : { 101 8 : if (_components_initial_conditions.size()) 102 : { 103 4 : std::vector<ComponentName> all_components(_components_initial_conditions.size()); 104 8 : for (const auto & comp : _components_initial_conditions) 105 4 : all_components.push_back(comp.first); 106 4 : mooseError("Component(s) '", 107 4 : Moose::stringify(all_components), 108 : "' requested to add the following initial conditions for this Physics. This Physics " 109 : "however does not implement the 'addInitialConditionsFromComponents' " 110 : "routine, so it cannot create these initial conditions"); 111 0 : } 112 4 : } 113 : 114 : void 115 96 : PhysicsComponentInterface::addBoundaryConditionsFromComponents() 116 : { 117 96 : if (_components_boundary_conditions.size()) 118 : { 119 4 : std::vector<ComponentName> all_components(_components_boundary_conditions.size()); 120 8 : for (const auto & comp : _components_boundary_conditions) 121 4 : all_components.push_back(comp.first); 122 4 : mooseError("Component(s) '", 123 4 : Moose::stringify(all_components), 124 : "' requested to add boundary conditions for the variable of this Physics. This " 125 : "Physics however does not implement the 'addBoundaryConditionsFromComponents' " 126 : "routine, so it cannot create these boundary conditions"); 127 0 : } 128 92 : }