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 550 : ComponentInitialConditionInterface::validParams() 14 : { 15 550 : auto params = ActionComponent::validParams(); 16 550 : 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 550 : 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 550 : params.addParamNamesToGroup("initial_condition_variables initial_condition_values", 27 : "Variable initialization"); 28 550 : return params; 29 0 : } 30 : 31 172 : ComponentInitialConditionInterface::ComponentInitialConditionInterface( 32 0 : const InputParameters & params) 33 : : ActionComponent(params), 34 172 : _initial_condition_variables( 35 : getParam<std::vector<VariableName>>("initial_condition_variables")), 36 344 : _variable_ic_functors(getParam<std::vector<MooseFunctorName>>("initial_condition_values")) 37 : { 38 172 : addRequiredTask("init_component_physics"); 39 172 : addRequiredTask("check_integrity"); 40 : 41 : // Parameter checks 42 344 : checkVectorParamsNoOverlap<VariableName>({"initial_condition_variables"}); 43 172 : 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 512 : } 47 : 48 : bool 49 128 : ComponentInitialConditionInterface::hasInitialCondition(const VariableName & var_name) const 50 : { 51 128 : return std::find(_initial_condition_variables.begin(), 52 : _initial_condition_variables.end(), 53 256 : var_name) != _initial_condition_variables.end(); 54 : } 55 : 56 : const MooseFunctorName & 57 96 : 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 96 : _requested_ic_variables.insert(variable); 62 : 63 : // Sorted by the user in the input parameters 64 128 : for (const auto i : index_range(_initial_condition_variables)) 65 128 : if (_initial_condition_variables[i] == variable) 66 96 : 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 152 : ComponentInitialConditionInterface::checkInitialConditionsAllRequested() const 74 : { 75 152 : 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 148 : }