Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
ComponentBoundaryConditionInterface.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 
17  // Support two common types of boundary conditions
18  params.addParam<std::vector<VariableName>>(
19  "fixed_value_bc_variables",
20  {},
21  "List of variables that have fixed value boundary condition(s) defined on this component");
22  params.addParam<std::vector<std::vector<BoundaryName>>>(
23  "fixed_value_bc_boundaries",
24  {},
25  "Boundaries on which to apply the fixed value boundary condition(s). Outer ordering is "
26  "variables, inner order is surfaces");
27  params.addParam<std::vector<std::vector<MooseFunctorName>>>(
28  "fixed_value_bc_values",
29  {},
30  "Functors that provide the fixed value boundary condition(s) values. Outer ordering is "
31  "variables, inner order is surfaces");
32 
33  params.addParam<std::vector<VariableName>>(
34  "flux_bc_variables",
35  {},
36  "List of variables that have flux boundary condition(s) defined on this component");
37  params.addParam<std::vector<std::vector<BoundaryName>>>(
38  "flux_bc_boundaries",
39  {},
40  "Boundaries on which to apply the flux boundary condition(s). Outer ordering is "
41  "variables, inner order is surfaces");
42  params.addParam<std::vector<std::vector<MooseFunctorName>>>(
43  "flux_bc_values",
44  {},
45  "Functors that provide the flux boundary condition(s) values. Outer ordering is "
46  "variables, inner order is surfaces");
47 
48  params.addParamNamesToGroup(
49  "fixed_value_bc_variables fixed_value_bc_boundaries fixed_value_bc_values flux_bc_variables "
50  " flux_bc_boundaries flux_bc_values",
51  "Variable boundary conditions");
52  return params;
53 }
54 
56  const InputParameters & params)
57  : ActionComponent(params),
58  _fixed_value_bc_variables(getParam<std::vector<VariableName>>("fixed_value_bc_variables")),
59  _flux_bc_variables(getParam<std::vector<VariableName>>("flux_bc_variables"))
60 {
61  addRequiredTask("init_component_physics");
62  addRequiredTask("check_integrity");
63 
64  // Check for unique elements
65  checkVectorParamsNoOverlap<VariableName>({"fixed_value_bc_variables"});
66  checkVectorParamsNoOverlap<VariableName>({"flux_bc_variables"});
67 
68  // Check parameter sizes
69  const auto & fixed_value_boundaries =
70  getParam<std::vector<std::vector<BoundaryName>>>("fixed_value_bc_boundaries");
71  const auto & fixed_value_values =
72  getParam<std::vector<std::vector<MooseFunctorName>>>("fixed_value_bc_values");
73  checkVectorParamsSameLength<VariableName, std::vector<BoundaryName>>("fixed_value_bc_variables",
74  "fixed_value_bc_boundaries");
75  checkVectorParamsSameLength<VariableName, std::vector<MooseFunctorName>>(
76  "fixed_value_bc_variables", "fixed_value_bc_values");
77  checkTwoDVectorParamsSameLength<BoundaryName, MooseFunctorName>("fixed_value_bc_boundaries",
78  "fixed_value_bc_values");
79  const auto & flux_boundaries =
80  getParam<std::vector<std::vector<BoundaryName>>>("flux_bc_boundaries");
81  const auto & flux_values = getParam<std::vector<std::vector<MooseFunctorName>>>("flux_bc_values");
82  checkVectorParamsSameLength<VariableName, std::vector<BoundaryName>>("flux_bc_variables",
83  "flux_bc_boundaries");
84  checkVectorParamsSameLength<VariableName, std::vector<MooseFunctorName>>("flux_bc_variables",
85  "flux_bc_values");
86  checkTwoDVectorParamsSameLength<BoundaryName, MooseFunctorName>("flux_bc_boundaries",
87  "flux_bc_values");
88 
89  // NOTE: We could add a check that for a (variable,boundary) pair, we do not have a fixed value
90  // and a flux BC defined at the same time
91  // TODO: add another check that the boundaries are part of the component
92  // This is not possible yet, components do not keep the list of their boundaries
93 
94  // Form maps for the variable-boundary-value from the input vectors
95  for (const auto i : index_range(_fixed_value_bc_variables))
96  {
97  const auto & var_name = _fixed_value_bc_variables[i];
98  for (const auto j : index_range(fixed_value_boundaries[i]))
99  _fixed_value_bcs[var_name][fixed_value_boundaries[i][j]] = fixed_value_values[i][j];
100  }
101  for (const auto i : index_range(_flux_bc_variables))
102  {
103  const auto & var_name = _flux_bc_variables[i];
104  for (const auto j : index_range(flux_boundaries[i]))
105  _flux_bcs[var_name][flux_boundaries[i][j]] = flux_values[i][j];
106  }
107 }
108 
109 bool
111 {
112  // if there exists at least one BC of that type for that variable
113  const bool has_fixed_value = _fixed_value_bcs.count(var_name);
114  const bool has_flux = _flux_bcs.count(var_name);
115 
116  return has_fixed_value || has_flux;
117 }
118 
119 bool
121  const BoundaryName & boundary) const
122 {
123  // if there exists at least one BC of that type for that variable
124  const bool has_fixed_value = _fixed_value_bcs.count(var_name);
125  const bool has_flux = _flux_bcs.count(var_name);
126 
127  // Now check for that specific boundary
128  if (has_fixed_value && libmesh_map_find(_fixed_value_bcs, var_name).count(boundary))
129  return true;
130  else if (has_flux && libmesh_map_find(_flux_bcs, var_name).count(boundary))
131  return true;
132  else
133  return false;
134 }
135 
136 MooseFunctorName
138  const BoundaryName & boundary,
139  const std::string & requestor_name,
140  BoundaryConditionType & bc_type) const
141 {
142  // Ideally all boundary conditions defined by the user in the input will get requested
143  _requested_bc_variables.insert(std::make_pair(var_name, boundary));
144 
145  // if there exists at least one BC of that type for that variable
146  const bool has_fixed_value = _fixed_value_bcs.count(var_name);
147  const bool has_flux = _flux_bcs.count(var_name);
148 
149  // Now check for that specific boundary
150  if (has_fixed_value && libmesh_map_find(_fixed_value_bcs, var_name).count(boundary))
151  {
152  bc_type = FIXED_VALUE;
153  return libmesh_map_find(libmesh_map_find(_fixed_value_bcs, var_name), boundary);
154  }
155  else if (has_flux && libmesh_map_find(_flux_bcs, var_name).count(boundary))
156  {
157  bc_type = FLUX;
158  return libmesh_map_find(libmesh_map_find(_flux_bcs, var_name), boundary);
159  }
160  else
161  paramError("fixed_value_bc_variables",
162  "Boundary condition for variable '" + var_name + "' on boundary '" + boundary +
163  "' requested by '" + requestor_name +
164  "' has not been specified on this ActionComponent.");
165 }
166 
167 std::vector<BoundaryName>
169  const VariableName & var_name) const
170 {
171  // if there exists at least one BC of that type for that variable
172  const bool has_fixed_value = _fixed_value_bcs.count(var_name);
173  const bool has_flux = _flux_bcs.count(var_name);
174 
175  std::vector<BoundaryName> boundaries;
176 
177  if (has_fixed_value)
178  for (const auto & boundary_pair : libmesh_map_find(_fixed_value_bcs, var_name))
179  boundaries.push_back(boundary_pair.first);
180 
181  if (has_flux)
182  for (const auto & boundary_pair : libmesh_map_find(_flux_bcs, var_name))
183  boundaries.push_back(boundary_pair.first);
184 
185  return boundaries;
186 }
187 
188 void
190 {
191  std::string list_missing = "";
192 
193  for (const auto & var_pair : _fixed_value_bcs)
194  for (const auto & bc_pair : var_pair.second)
195  if (std::find(_requested_bc_variables.begin(),
197  std::make_pair(VariableName(var_pair.first), BoundaryName(bc_pair.first))) ==
199  list_missing += "\n- " + var_pair.first + " on " + bc_pair.first;
200 
201  for (const auto & var_pair : _flux_bcs)
202  for (const auto & bc_pair : var_pair.second)
203  if (std::find(_requested_bc_variables.begin(),
205  std::make_pair(VariableName(var_pair.first), BoundaryName(bc_pair.first))) ==
207  list_missing += "\n- " + var_pair.first + " on " + bc_pair.first;
208 
209  if (!list_missing.empty())
210  mooseError("Boundary conditions for variables and boundaries:" + list_missing +
211  "\n have been defined on this ActionComponent, but have not been requested by "
212  "any Physics.");
213 }
const std::vector< VariableName > _flux_bc_variables
Names of the variables to set a flux BC on.
MooseFunctorName getBoundaryCondition(const VariableName &variable, const BoundaryName &boundary, const std::string &requestor_name, BoundaryConditionType &bc_type) const
Get the name of the functor providing the boundary condition for the requested variable and boundary...
std::map< std::string, std::map< std::string, std::string > > _flux_bcs
Maps of the flux boundary conditions.
ComponentBoundaryConditionInterface(const InputParameters &params)
const std::vector< VariableName > _fixed_value_bc_variables
Names of the variables to set a fixed value BC on.
std::set< std::pair< VariableName, BoundaryName > > _requested_bc_variables
Requested variables. If the IC for a variable was never requested, error.
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::map< std::string, std::map< std::string, std::string > > _fixed_value_bcs
Maps of the fixed value boundary conditions.
bool hasBoundaryCondition(const VariableName &variable) const
Whether the component has a boundary condition parameter specified 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...
if(!dmm->_nl) SETERRQ(PETSC_COMM_WORLD
std::vector< BoundaryName > getBoundaryConditionBoundaries(const VariableName &variable) const
Get the name of the boundaries on which the variable should have a boundary condition.
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
void checkBoundaryConditionsAllRequested() const
Checks that all initial conditions were requested.
for(PetscInt i=0;i< nvars;++i)
auto index_range(const T &sizable)