LCOV - code coverage report
Current view: top level - src/components - Component1DConnection.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 57 60 95.0 %
Date: 2025-07-30 13:02:48 Functions: 9 10 90.0 %
Legend: Lines: hit not hit

          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        8281 : THM::stringToEnum(const std::string & s)
      19             : {
      20        8281 :   return stringToEnum<Component1DConnection::EEndType>(s, Component1DConnection::_end_type_to_enum);
      21             : }
      22             : 
      23             : InputParameters
      24       12986 : Component1DConnection::validParams()
      25             : {
      26       12986 :   InputParameters params = Component::validParams();
      27       12986 :   return params;
      28             : }
      29             : 
      30        6491 : Component1DConnection::Component1DConnection(const InputParameters & params) : Component(params) {}
      31             : 
      32             : void
      33        6491 : Component1DConnection::setupMesh()
      34             : {
      35       14772 :   for (const auto & connection : _connections)
      36             :   {
      37        8281 :     const std::string & comp_name = connection._component_name;
      38             : 
      39             :     if (hasComponentByName<Component1D>(comp_name))
      40             :     {
      41        8279 :       _boundary_names.push_back(connection._boundary_name);
      42             : 
      43             :       const Component1D & comp = getComponentByName<Component1D>(comp_name);
      44       16558 :       for (auto && conn : comp.getConnections(connection._end_type))
      45             :       {
      46             :         // get info from the connection
      47        8279 :         _positions.push_back(conn._position);
      48        8279 :         _elems.push_back(conn._elem);
      49        8279 :         _sides.push_back(conn._side);
      50        8279 :         _nodes.push_back(conn._node->id());
      51        8279 :         _normals.push_back(conn._normal);
      52        8279 :         _boundary_ids.push_back(conn._boundary_id);
      53       16558 :         _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        6491 : }
      62             : 
      63             : void
      64        6451 : Component1DConnection::init()
      65             : {
      66        6451 :   Component::init();
      67             : 
      68        6451 :   if (_connections.size() > 0)
      69             :   {
      70             :     std::vector<UserObjectName> fp_names;
      71             :     std::vector<THM::FlowModelID> flow_model_ids;
      72       14670 :     for (const auto & connection : _connections)
      73             :     {
      74        8223 :       const std::string comp_name = connection._component_name;
      75             :       if (hasComponentByName<Component1D>(comp_name))
      76             :       {
      77        8221 :         const Component1D & comp = getTHMProblem().getComponentByName<Component1D>(comp_name);
      78             : 
      79             :         // add to list of subdomain names
      80        8221 :         const std::vector<SubdomainName> & subdomain_names = comp.getSubdomainNames();
      81        8221 :         _connected_subdomain_names.insert(
      82             :             _connected_subdomain_names.end(), subdomain_names.begin(), subdomain_names.end());
      83             :       }
      84             :     }
      85        6447 :   }
      86             :   else
      87           4 :     logError("The component is not connected.");
      88        6451 : }
      89             : 
      90             : void
      91        6356 : Component1DConnection::check() const
      92             : {
      93        6356 :   Component::check();
      94             : 
      95       14454 :   for (const auto & comp_name : _connected_component_names)
      96        8098 :     checkComponentOfTypeExistsByName<Component1D>(comp_name);
      97        6356 : }
      98             : 
      99             : void
     100        8285 : Component1DConnection::addConnection(const BoundaryName & boundary_name)
     101             : {
     102        8285 :   const size_t oparenthesis_pos = boundary_name.find('(');
     103        8285 :   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        8283 :     const size_t colon_pos = boundary_name.rfind(':');
     111             :     // if it has a colon, assume 'component_name:end_type' format
     112        8283 :     if (colon_pos != std::string::npos)
     113             :     {
     114        8281 :       const std::string connected_component_name = boundary_name.substr(0, colon_pos);
     115             :       const std::string str_end =
     116        8281 :           boundary_name.substr(colon_pos + 1, boundary_name.length() - colon_pos - 1);
     117        8281 :       const EEndType end_type = THM::stringToEnum<EEndType>(str_end);
     118             : 
     119        8281 :       _connections.push_back(Connection(boundary_name, connected_component_name, end_type));
     120        8281 :       _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        8281 :       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        8285 : }
     134             : 
     135             : void
     136        5292 : Component1DConnection::checkNumberOfConnections(const unsigned int & n_connections) const
     137             : {
     138        5292 :   if (_connections.size() != n_connections)
     139           6 :     logError("The number of connections (", _connections.size(), ") must equal ", n_connections);
     140        5292 : }
     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        4748 : Component1DConnection::getBoundaryNames() const
     152             : {
     153        4748 :   checkSetupStatus(MESH_PREPARED);
     154             : 
     155        4748 :   return _boundary_names;
     156             : }

Generated by: LCOV version 1.14