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 : #pragma once 11 : 12 : #include "Component.h" 13 : 14 : /** 15 : * Base class for 1D component junctions and boundaries 16 : */ 17 : class Component1DConnection : public Component 18 : { 19 : public: 20 : Component1DConnection(const InputParameters & params); 21 : 22 : /// End type 23 : enum EEndType 24 : { 25 : IN, ///< inlet 26 : OUT ///< outlet 27 : }; 28 : /// Map of end type string to enum 29 : static const std::map<std::string, EEndType> _end_type_to_enum; 30 : 31 : /// Structure for holding data for a connection 32 20102 : struct Connection 33 : { 34 : /// The name of the boundary this connection is attached to 35 : const BoundaryName _boundary_name; 36 : 37 : /// Name of the component in the connection 38 : const std::string _component_name; 39 : 40 : /// End type for the connection 41 : const EEndType _end_type; 42 : 43 8281 : Connection(const BoundaryName & boundary_name, 44 : const std::string & component_name, 45 : const EEndType & end_type) 46 8281 : : _boundary_name(boundary_name), _component_name(component_name), _end_type(end_type) 47 : { 48 8281 : } 49 : }; 50 : 51 : /** 52 : * Returns the vector of connections of this component 53 : * 54 : * @returns vector of connections of this component 55 : */ 56 : const std::vector<Connection> & getConnections() const { return _connections; } 57 : 58 : /** 59 : * Returns a list of names of components that are connected to this component 60 : * 61 : * @returns list of names of components that are connected to this component 62 : */ 63 : const std::vector<std::string> & getConnectedComponentNames() const 64 : { 65 6451 : return _connected_component_names; 66 : } 67 : 68 : /** 69 : * Gets the vector of connected subdomain names 70 : */ 71 : const std::vector<SubdomainName> & getConnectedSubdomainNames() const 72 : { 73 : return _connected_subdomain_names; 74 : } 75 : 76 : /** 77 : * Gets the list of boundary nodes connected to this component 78 : * 79 : * @return list of connected boundary nodes 80 : */ 81 : virtual const std::vector<dof_id_type> & getNodeIDs() const; 82 : 83 : /** 84 : * Gets the boundary names for this component 85 : * 86 : * @return boundary names for this component 87 : */ 88 : const std::vector<BoundaryName> & getBoundaryNames() const; 89 : 90 : protected: 91 : virtual void setupMesh() override; 92 : virtual void init() override; 93 : virtual void check() const override; 94 : 95 : /** 96 : * Adds a connection for this component 97 : * 98 : * Components using this interface must call this function on all of their 99 : * connection strings. 100 : * 101 : * @param[in] boundary_name The name of the boundary 102 : */ 103 : void addConnection(const BoundaryName & boundary_name); 104 : 105 : /** 106 : * Checks that the number of connections is equal to the supplied value 107 : * 108 : * @param[in] n_connections enforced number of connections 109 : */ 110 : void checkNumberOfConnections(const unsigned int & n_connections) const; 111 : 112 : /** 113 : * Checks that the size of a vector parameter equals the number of connections 114 : * 115 : * @tparam T type of element in the vector parameter 116 : * @param[in] param vector parameter name 117 : */ 118 : template <typename T> 119 : void checkSizeEqualsNumberOfConnections(const std::string & param) const; 120 : 121 : /** 122 : * Checks that all connections have the same of a certain type of object 123 : * 124 : * @tparam T type of object to check 125 : * @param[in] objects list of objects corresponding to each connection 126 : * @param[in] description description of the obect to check 127 : */ 128 : template <typename T> 129 : void checkAllConnectionsHaveSame(const std::vector<T> & objects, 130 : const std::string & description) const; 131 : 132 : /// Physical positions of connected components 133 : std::vector<Point> _positions; 134 : /// Boundary elements of connected components 135 : std::vector<const Elem *> _elems; 136 : /// Boundary sides of connected components 137 : std::vector<unsigned short int> _sides; 138 : /// Boundary node IDs from connected components 139 : std::vector<dof_id_type> _nodes; 140 : /// Boundary IDs of connected components 141 : std::vector<unsigned int> _boundary_ids; 142 : /// Boundary names of connected components 143 : std::vector<BoundaryName> _boundary_names; 144 : /// Outward normals associated with connected components 145 : std::vector<Real> _normals; 146 : /// Directions of connected components 147 : std::vector<RealVectorValue> _directions; 148 : 149 : /// Vector of connections of this component 150 : std::vector<Connection> _connections; 151 : /// Vector of connected component names 152 : std::vector<std::string> _connected_component_names; 153 : /// Vector of subdomain names of the connected components 154 : std::vector<SubdomainName> _connected_subdomain_names; 155 : 156 : public: 157 : static InputParameters validParams(); 158 : }; 159 : 160 : template <typename T> 161 : void 162 0 : Component1DConnection::checkSizeEqualsNumberOfConnections(const std::string & param) const 163 : { 164 : const auto & value = getParam<std::vector<T>>(param); 165 0 : if (value.size() != _connections.size()) 166 0 : logError("The number of entries in '", 167 : param, 168 : "' (", 169 0 : value.size(), 170 : ") must equal the number of connections (", 171 0 : _connections.size(), 172 : ")"); 173 0 : } 174 : 175 : template <typename T> 176 : void 177 3078 : Component1DConnection::checkAllConnectionsHaveSame(const std::vector<T> & objects, 178 : const std::string & description) const 179 : { 180 9708 : for (const auto & obj : objects) 181 6630 : if (obj != objects[0]) 182 0 : logError("All connections must have the same ", description); 183 3078 : } 184 : 185 : namespace THM 186 : { 187 : template <> 188 : Component1DConnection::EEndType stringToEnum(const std::string & s); 189 : }