https://mooseframework.inl.gov
Component1DConnection.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 
10 #include "Component1DConnection.h"
11 #include "Component1D.h"
12 
13 const std::map<std::string, Component1DConnection::EEndType>
14  Component1DConnection::_end_type_to_enum{{"IN", IN}, {"OUT", OUT}};
15 
16 template <>
18 THM::stringToEnum(const std::string & s)
19 {
20  return stringToEnum<Component1DConnection::EEndType>(s, Component1DConnection::_end_type_to_enum);
21 }
22 
25 {
27  return params;
28 }
29 
31 
32 void
34 {
35  for (const auto & connection : _connections)
36  {
37  const std::string & comp_name = connection._component_name;
38 
39  if (hasComponentByName<Component1D>(comp_name))
40  {
41  _boundary_names.push_back(connection._boundary_name);
42 
43  const Component1D & comp = getComponentByName<Component1D>(comp_name);
44  for (auto && conn : comp.getConnections(connection._end_type))
45  {
46  // get info from the connection
47  _positions.push_back(conn._position);
48  _elems.push_back(conn._elem);
49  _sides.push_back(conn._side);
50  _nodes.push_back(conn._node->id());
51  _normals.push_back(conn._normal);
52  _boundary_ids.push_back(conn._boundary_id);
53  _directions.push_back(comp.getDirection());
54  }
55  }
56  else
57  logError("Trying to connect to a component '",
58  comp_name,
59  "', but there is no such component in the simulation. Please check your spelling.");
60  }
61 }
62 
63 void
65 {
67 
68  if (_connections.size() > 0)
69  {
70  std::vector<UserObjectName> fp_names;
71  std::vector<THM::FlowModelID> flow_model_ids;
72  for (const auto & connection : _connections)
73  {
74  const std::string comp_name = connection._component_name;
75  if (hasComponentByName<Component1D>(comp_name))
76  {
77  const Component1D & comp = getTHMProblem().getComponentByName<Component1D>(comp_name);
78 
79  // add to list of subdomain names
80  const std::vector<SubdomainName> & subdomain_names = comp.getSubdomainNames();
82  _connected_subdomain_names.end(), subdomain_names.begin(), subdomain_names.end());
83  }
84  }
85  }
86  else
87  logError("The component is not connected.");
88 }
89 
90 void
92 {
94 
95  for (const auto & comp_name : _connected_component_names)
96  checkComponentOfTypeExistsByName<Component1D>(comp_name);
97 }
98 
99 void
100 Component1DConnection::addConnection(const BoundaryName & boundary_name)
101 {
102  const size_t oparenthesis_pos = boundary_name.find('(');
103  if (oparenthesis_pos != std::string::npos)
104  {
105  logError("You are using the old connection format 'comp_name(end)'. Please update your input "
106  "file to the new one 'comp_name:end'.");
107  }
108  else
109  {
110  const size_t colon_pos = boundary_name.rfind(':');
111  // if it has a colon, assume 'component_name:end_type' format
112  if (colon_pos != std::string::npos)
113  {
114  const std::string connected_component_name = boundary_name.substr(0, colon_pos);
115  const std::string str_end =
116  boundary_name.substr(colon_pos + 1, boundary_name.length() - colon_pos - 1);
117  const EEndType end_type = THM::stringToEnum<EEndType>(str_end);
118 
119  _connections.push_back(Connection(boundary_name, connected_component_name, end_type));
120  _connected_component_names.push_back(connected_component_name);
121 
122  // Add dependency because the connected component's setupMesh() must be called
123  // before this component's setupMesh().
124  addDependency(connected_component_name);
125  }
126  else
127  {
128  logError("Incorrect connection specified '",
129  boundary_name,
130  "'. Valid connection format is 'component_name:end_type'.");
131  }
132  }
133 }
134 
135 void
136 Component1DConnection::checkNumberOfConnections(const unsigned int & n_connections) const
137 {
138  if (_connections.size() != n_connections)
139  logError("The number of connections (", _connections.size(), ") must equal ", n_connections);
140 }
141 
142 const std::vector<dof_id_type> &
144 {
146 
147  return _nodes;
148 }
149 
150 const std::vector<BoundaryName> &
152 {
154 
155  return _boundary_names;
156 }
virtual void init() override
Initializes the component.
static InputParameters validParams()
virtual const std::vector< dof_id_type > & getNodeIDs() const
Gets the list of boundary nodes connected to this component.
Component1DConnection::EEndType stringToEnum(const std::string &s)
std::vector< unsigned short int > _sides
Boundary sides of connected components.
THMProblem & getTHMProblem() const
Gets the THM problem.
Definition: Component.C:135
void addDependency(const std::string &dependency)
Adds a component name to the list of dependencies.
Definition: Component.C:129
std::vector< SubdomainName > _connected_subdomain_names
Vector of subdomain names of the connected components.
const std::vector< BoundaryName > & getBoundaryNames() const
Gets the boundary names for this component.
virtual RealVectorValue getDirection() const
Structure for holding data for a connection.
std::vector< Connection > _connections
Vector of connections of this component.
std::vector< BoundaryName > _boundary_names
Boundary names of connected components.
void addConnection(const BoundaryName &boundary_name)
Adds a connection for this component.
static InputParameters validParams()
Definition: Component.C:18
std::vector< dof_id_type > _nodes
Boundary node IDs from connected components.
void logError(Args &&... args) const
Logs an error.
Definition: Component.h:215
virtual void check() const
Check the component integrity.
Definition: Component.h:301
std::vector< std::string > _connected_component_names
Vector of connected component names.
std::vector< unsigned int > _boundary_ids
Boundary IDs of connected components.
std::vector< Point > _positions
Physical positions of connected components.
void checkNumberOfConnections(const unsigned int &n_connections) const
Checks that the number of connections is equal to the supplied value.
virtual void init()
Initializes the component.
Definition: Component.h:290
Base class for 1D components.
Definition: Component1D.h:18
const T & getComponentByName(const std::string &name) const
Get component by its name.
Definition: Simulation.h:504
Base class for THM components.
Definition: Component.h:27
Component1DConnection(const InputParameters &params)
std::vector< const Elem * > _elems
Boundary elements of connected components.
virtual const std::vector< Connection > & getConnections(Component1DConnection::EEndType end_type) const
Gets the vector of connections of an end type for this component.
Definition: Component1D.C:156
virtual void check() const override
Check the component integrity.
void checkSetupStatus(const EComponentSetupStatus &status) const
Throws an error if the supplied setup status of this component has not been reached.
Definition: Component.C:117
virtual void setupMesh() override
Performs mesh setup such as creating mesh or naming mesh sets.
virtual const std::vector< SubdomainName > & getSubdomainNames() const
Gets the subdomain names for this component.
Definition: Component.C:307
std::vector< Real > _normals
Outward normals associated with connected components.
std::vector< RealVectorValue > _directions
Directions of connected components.
static const std::map< std::string, EEndType > _end_type_to_enum
Map of end type string to enum.