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 "ComponentInitialConditionInterface.h" 11 : 12 : InputParameters 13 562 : ComponentInitialConditionInterface::validParams() 14 : { 15 562 : auto params = ActionComponent::validParams(); 16 562 : params.addParam<std::vector<VariableName>>( 17 : "initial_condition_variables", 18 : {}, 19 : "List of variables that should have an initial " 20 : "condition defined on the blocks of this ActionComponent"); 21 562 : params.addParam<std::vector<MooseFunctorName>>( 22 : "initial_condition_values", 23 : {}, 24 : "Functors that provide the initial values of the variables on this ActionComponent"); 25 : 26 562 : params.addParamNamesToGroup("initial_condition_variables initial_condition_values", 27 : "Variable initialization"); 28 562 : return params; 29 0 : } 30 : 31 184 : ComponentInitialConditionInterface::ComponentInitialConditionInterface( 32 0 : const InputParameters & params) 33 : : ActionComponent(params), 34 184 : _initial_condition_variables( 35 : getParam<std::vector<VariableName>>("initial_condition_variables")), 36 368 : _variable_ic_functors(getParam<std::vector<MooseFunctorName>>("initial_condition_values")) 37 : { 38 184 : addRequiredTask("init_component_physics"); 39 184 : addRequiredTask("check_integrity"); 40 : 41 : // Parameter checks 42 368 : checkVectorParamsNoOverlap<VariableName>({"initial_condition_variables"}); 43 184 : if (_initial_condition_variables.size() != _variable_ic_functors.size()) 44 4 : paramError("initial_condition_variables", 45 : "Should be the same size as 'initial_condition_values'"); 46 548 : } 47 : 48 : bool 49 136 : ComponentInitialConditionInterface::hasInitialCondition(const VariableName & var_name) const 50 : { 51 136 : return std::find(_initial_condition_variables.begin(), 52 : _initial_condition_variables.end(), 53 272 : var_name) != _initial_condition_variables.end(); 54 : } 55 : 56 : const MooseFunctorName & 57 102 : ComponentInitialConditionInterface::getInitialCondition(const VariableName & variable, 58 : const std::string & requestor_name) const 59 : { 60 : // Ideally all initial conditions defined by the user in the input will get requested 61 102 : _requested_ic_variables.insert(variable); 62 : 63 : // Sorted by the user in the input parameters 64 136 : for (const auto i : index_range(_initial_condition_variables)) 65 136 : if (_initial_condition_variables[i] == variable) 66 102 : return _variable_ic_functors[i]; 67 0 : paramError("initial_condition_variables", 68 0 : "Initial condition for variable '" + variable + "' requested by '" + requestor_name + 69 : "' has not been specified on this ActionComponent."); 70 : } 71 : 72 : void 73 164 : ComponentInitialConditionInterface::checkInitialConditionsAllRequested() const 74 : { 75 164 : if (_requested_ic_variables.size() != _initial_condition_variables.size()) 76 : { 77 4 : std::string list_missing = ""; 78 8 : for (const auto & ic_name : _initial_condition_variables) 79 4 : if (_requested_ic_variables.count(ic_name) == 0) 80 4 : list_missing = (list_missing == "" ? "" : ", ") + ic_name; 81 : 82 4 : paramError("initial_condition_variables", 83 4 : "Initial conditions for variables '" + list_missing + 84 : "' have been defined on this ActionComponent, but have not been requested by " 85 : "any Physics."); 86 0 : } 87 160 : }