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 : #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 <> 17 : Component1DConnection::EEndType 18 4278 : THM::stringToEnum(const std::string & s) 19 : { 20 4278 : return stringToEnum<Component1DConnection::EEndType>(s, Component1DConnection::_end_type_to_enum); 21 : } 22 : 23 : InputParameters 24 6848 : Component1DConnection::validParams() 25 : { 26 6848 : InputParameters params = Component::validParams(); 27 6848 : return params; 28 : } 29 : 30 3422 : Component1DConnection::Component1DConnection(const InputParameters & params) : Component(params) {} 31 : 32 : void 33 3422 : Component1DConnection::setupMesh() 34 : { 35 7700 : for (const auto & connection : _connections) 36 : { 37 4278 : const std::string & comp_name = connection._component_name; 38 : 39 : if (hasComponentByName<Component1D>(comp_name)) 40 : { 41 4276 : _boundary_names.push_back(connection._boundary_name); 42 : 43 : const Component1D & comp = getComponentByName<Component1D>(comp_name); 44 8552 : for (auto && conn : comp.getConnections(connection._end_type)) 45 : { 46 : // get info from the connection 47 4276 : _positions.push_back(conn._position); 48 4276 : _elems.push_back(conn._elem); 49 4276 : _sides.push_back(conn._side); 50 4276 : _nodes.push_back(conn._node->id()); 51 4276 : _normals.push_back(conn._normal); 52 4276 : _boundary_ids.push_back(conn._boundary_id); 53 8552 : _directions.push_back(comp.getDirection()); 54 : } 55 : } 56 : else 57 2 : 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 3422 : } 62 : 63 : void 64 3390 : Component1DConnection::init() 65 : { 66 : Component::init(); 67 : 68 3390 : if (_connections.size() > 0) 69 : { 70 : std::vector<UserObjectName> fp_names; 71 : std::vector<THM::FlowModelID> flow_model_ids; 72 7618 : for (const auto & connection : _connections) 73 : { 74 4232 : const std::string comp_name = connection._component_name; 75 : if (hasComponentByName<Component1D>(comp_name)) 76 : { 77 4230 : const Component1D & comp = getTHMProblem().getComponentByName<Component1D>(comp_name); 78 : 79 : // add to list of subdomain names 80 4230 : const std::vector<SubdomainName> & subdomain_names = comp.getSubdomainNames(); 81 4230 : _connected_subdomain_names.insert( 82 : _connected_subdomain_names.end(), subdomain_names.begin(), subdomain_names.end()); 83 : } 84 : } 85 3386 : } 86 : else 87 4 : logError("The component is not connected."); 88 3390 : } 89 : 90 : void 91 3345 : Component1DConnection::check() const 92 : { 93 : Component::check(); 94 : 95 7519 : for (const auto & comp_name : _connected_component_names) 96 4174 : checkComponentOfTypeExistsByName<Component1D>(comp_name); 97 3345 : } 98 : 99 : void 100 4282 : Component1DConnection::addConnection(const BoundaryName & boundary_name) 101 : { 102 4282 : const size_t oparenthesis_pos = boundary_name.find('('); 103 4282 : if (oparenthesis_pos != std::string::npos) 104 : { 105 2 : 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 4280 : const size_t colon_pos = boundary_name.rfind(':'); 111 : // if it has a colon, assume 'component_name:end_type' format 112 4280 : if (colon_pos != std::string::npos) 113 : { 114 4278 : const std::string connected_component_name = boundary_name.substr(0, colon_pos); 115 : const std::string str_end = 116 4278 : boundary_name.substr(colon_pos + 1, boundary_name.length() - colon_pos - 1); 117 4278 : const EEndType end_type = THM::stringToEnum<EEndType>(str_end); 118 : 119 4278 : _connections.push_back(Connection(boundary_name, connected_component_name, end_type)); 120 4278 : _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 4278 : addDependency(connected_component_name); 125 : } 126 : else 127 : { 128 2 : logError("Incorrect connection specified '", 129 : boundary_name, 130 : "'. Valid connection format is 'component_name:end_type'."); 131 : } 132 : } 133 4282 : } 134 : 135 : void 136 2778 : Component1DConnection::checkNumberOfConnections(const unsigned int & n_connections) const 137 : { 138 2778 : if (_connections.size() != n_connections) 139 6 : logError("The number of connections (", _connections.size(), ") must equal ", n_connections); 140 2778 : } 141 : 142 : const std::vector<dof_id_type> & 143 0 : Component1DConnection::getNodeIDs() const 144 : { 145 0 : checkSetupStatus(MESH_PREPARED); 146 : 147 0 : return _nodes; 148 : } 149 : 150 : const std::vector<BoundaryName> & 151 2523 : Component1DConnection::getBoundaryNames() const 152 : { 153 2523 : checkSetupStatus(MESH_PREPARED); 154 : 155 2523 : return _boundary_names; 156 : }