https://mooseframework.inl.gov
Loading...
Searching...
No Matches
ComponentInitialConditionInterface.C
Go to the documentation of this file.
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
11
14{
15 auto params = ActionComponent::validParams();
16 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 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 params.addParamNamesToGroup("initial_condition_variables initial_condition_values",
27 "Variable initialization");
28 return params;
29}
30
32 const InputParameters & params)
33 : ActionComponent(params),
34 _initial_condition_variables(
35 getParam<std::vector<VariableName>>("initial_condition_variables")),
36 _variable_ic_functors(getParam<std::vector<MooseFunctorName>>("initial_condition_values"))
37{
38 addRequiredTask("init_component_physics");
39 addRequiredTask("check_integrity");
40
41 // Parameter checks
42 checkVectorParamsNoOverlap<VariableName>({"initial_condition_variables"});
44 paramError("initial_condition_variables",
45 "Should be the same size as 'initial_condition_values'");
46}
47
48bool
50{
51 return std::find(_initial_condition_variables.begin(),
53 var_name) != _initial_condition_variables.end();
54}
55
56const MooseFunctorName &
58 const std::string & requestor_name) const
59{
60 // Ideally all initial conditions defined by the user in the input will get requested
61 _requested_ic_variables.insert(variable);
62
63 // Sorted by the user in the input parameters
64 for (const auto i : index_range(_initial_condition_variables))
65 if (_initial_condition_variables[i] == variable)
66 return _variable_ic_functors[i];
67 paramError("initial_condition_variables",
68 "Initial condition for variable '" + variable + "' requested by '" + requestor_name +
69 "' has not been specified on this ActionComponent.");
70}
71
72void
74{
76 {
77 std::string list_missing = "";
78 for (const auto & ic_name : _initial_condition_variables)
79 if (_requested_ic_variables.count(ic_name) == 0)
80 list_missing = (list_missing == "" ? "" : ", ") + ic_name;
81
82 paramError("initial_condition_variables",
83 "Initial conditions for variables '" + list_missing +
84 "' have been defined on this ActionComponent, but have not been requested by "
85 "any Physics.");
86 }
87}
Base class for components that are defined using an action.
void addRequiredTask(const std::string &task)
Add a new required task for all physics deriving from this class NOTE: This does not register the tas...
static InputParameters validParams()
bool hasInitialCondition(const VariableName &variable) const
Whether the component has an initial condition parameter set for the requested variable.
const std::vector< VariableName > _initial_condition_variables
Names of the variables to set an initial condition on.
std::set< VariableName > _requested_ic_variables
Requested variables. If the IC for a variable was never requested, error.
const MooseFunctorName & getInitialCondition(const VariableName &variable, const std::string &requestor_name) const
Get the name of the functor providing the initial condition for the requested variable.
ComponentInitialConditionInterface(const InputParameters &params)
const std::vector< MooseFunctorName > _variable_ic_functors
Functor values for the initial conditions of the variables.
void checkInitialConditionsAllRequested() const
Checks that all initial conditions were requested.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system.
void paramError(const std::string &param, Args... args) const
Emits an error prefixed with the file and line number of the given param (from the input file) along ...
Definition MooseBase.h:457