https://mooseframework.inl.gov
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 
48 bool
49 ComponentInitialConditionInterface::hasInitialCondition(const VariableName & var_name) const
50 {
51  return std::find(_initial_condition_variables.begin(),
53  var_name) != _initial_condition_variables.end();
54 }
55 
56 const 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 
72 void
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 }
ComponentInitialConditionInterface(const InputParameters &params)
const std::vector< MooseFunctorName > _variable_ic_functors
Functor values for the initial conditions of the variables.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Base class for components that are defined using an action.
static InputParameters validParams()
std::set< VariableName > _requested_ic_variables
Requested variables. If the IC for a variable was never requested, error.
bool hasInitialCondition(const VariableName &variable) const
Whether the component has an initial condition parameter set for the requested variable.
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 ...
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...
const std::vector< VariableName > _initial_condition_variables
Names of the variables to set an initial condition on.
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.
auto index_range(const T &sizable)
void checkInitialConditionsAllRequested() const
Checks that all initial conditions were requested.