LCOV - code coverage report
Current view: top level - src/components - Component1D.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 66 78 84.6 %
Date: 2026-05-29 20:41:18 Functions: 8 9 88.9 %
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 "Component1D.h"
      11             : #include "THMMesh.h"
      12             : 
      13             : InputParameters
      14        4332 : Component1D::validParams()
      15             : {
      16        4332 :   InputParameters params = GeneratedMeshComponent::validParams();
      17        4332 :   return params;
      18             : }
      19             : 
      20        2165 : Component1D::Component1D(const InputParameters & parameters) : GeneratedMeshComponent(parameters) {}
      21             : 
      22             : void
      23        2156 : Component1D::buildMeshNodes()
      24             : {
      25             :   Point p(0, 0, 0);
      26      103010 :   for (unsigned int i = 0; i < _node_locations.size(); i++)
      27             :   {
      28      100854 :     p(0) = _node_locations[i];
      29      100854 :     addNode(p);
      30             :   }
      31        2156 : }
      32             : 
      33             : void
      34        2165 : Component1D::buildMesh()
      35             : {
      36        2165 :   buildMeshNodes();
      37             : 
      38        2165 :   MeshBase & the_mesh = mesh().getMesh();
      39             :   BoundaryInfo & boundary_info = the_mesh.get_boundary_info();
      40             : 
      41             :   // create nodeset for all nodes for this component
      42        2165 :   _nodeset_id = mesh().getNextBoundaryId();
      43        2165 :   _nodeset_name = name();
      44        2165 :   boundary_info.nodeset_name(_nodeset_id) = _nodeset_name;
      45             : 
      46             :   // Check that the number of nodes is consistent with the number of nodes in case component
      47             :   // developers screw up (typically in buildMeshNodes() call)
      48        2165 :   if (usingSecondOrderMesh())
      49             :   {
      50           0 :     if (_node_ids.size() != (2 * _n_elem + 1))
      51           0 :       mooseError(name(),
      52             :                  ": Inconsistent number of nodes and elements. You have ",
      53           0 :                  _n_elem,
      54             :                  " elements and ",
      55           0 :                  _node_ids.size(),
      56             :                  " nodes.");
      57             :   }
      58             :   else
      59             :   {
      60        2165 :     if (_node_ids.size() != _n_elem + 1)
      61           0 :       mooseError(name(),
      62             :                  ": Inconsistent number of nodes and elements. You have ",
      63           0 :                  _n_elem,
      64             :                  " elements and ",
      65           0 :                  _node_ids.size(),
      66             :                  " nodes.");
      67             :   }
      68             : 
      69      103478 :   for (auto & node_id : _node_ids)
      70             :   {
      71      101313 :     const Node * nd = the_mesh.node_ptr(node_id);
      72      101313 :     boundary_info.add_node(nd, _nodeset_id);
      73             :   }
      74             : 
      75             :   // elems
      76        2165 :   BoundaryID bc_id_inlet = mesh().getNextBoundaryId();
      77        2165 :   BoundaryID bc_id_outlet = mesh().getNextBoundaryId();
      78        2165 :   auto & binfo = mesh().getMesh().get_boundary_info();
      79      101313 :   for (unsigned int i = 0; i < _n_elem; i++)
      80             :   {
      81             :     Elem * elem = nullptr;
      82       99148 :     if (usingSecondOrderMesh())
      83           0 :       elem = addElementEdge3(_node_ids[2 * i], _node_ids[2 * i + 2], _node_ids[2 * i + 1]);
      84             :     else
      85       99148 :       elem = addElementEdge2(_node_ids[i], _node_ids[i + 1]);
      86             : 
      87             :     // BCs
      88       99148 :     if (i == 0)
      89             :     {
      90        2165 :       Point pt = _position;
      91        2165 :       _connections[Component1DConnection::IN].push_back(Connection(pt, elem, 0, bc_id_inlet, -1));
      92        2165 :       boundary_info.add_side(elem, 0, bc_id_inlet);
      93        4330 :       binfo.sideset_name(bc_id_inlet) = genName(name(), "in");
      94             :     }
      95       99148 :     if (i == (_n_elem - 1))
      96             :     {
      97        2165 :       Point pt = _position + _length * _dir;
      98        2165 :       _connections[Component1DConnection::OUT].push_back(Connection(pt, elem, 1, bc_id_outlet, 1));
      99        2165 :       boundary_info.add_side(elem, 1, bc_id_outlet);
     100        4330 :       binfo.sideset_name(bc_id_outlet) = genName(name(), "out");
     101             :     }
     102             :   }
     103             : 
     104        2165 :   if (_axial_region_names.size() > 0)
     105             :   {
     106             :     unsigned int k = 0;
     107          48 :     for (unsigned int i = 0; i < _axial_region_names.size(); i++)
     108             :     {
     109             :       const std::string & region_name = _axial_region_names[i];
     110          32 :       SubdomainID subdomain_id = mesh().getNextSubdomainId();
     111          64 :       setSubdomainInfo(subdomain_id, genName(name(), region_name));
     112             : 
     113         143 :       for (unsigned int j = 0; j < _n_elems[i]; j++, k++)
     114             :       {
     115         111 :         dof_id_type elem_id = _elem_ids[k];
     116         111 :         mesh().elemPtr(elem_id)->subdomain_id() = subdomain_id;
     117             :       }
     118             :     }
     119             :   }
     120             :   else
     121             :   {
     122        2149 :     SubdomainID subdomain_id = mesh().getNextSubdomainId();
     123        2149 :     setSubdomainInfo(subdomain_id, name());
     124             : 
     125      101186 :     for (auto && id : _elem_ids)
     126       99037 :       mesh().elemPtr(id)->subdomain_id() = subdomain_id;
     127             :   }
     128             : 
     129             :   // Update the mesh
     130        2165 :   mesh().update();
     131        2165 : }
     132             : 
     133             : bool
     134      107777 : Component1D::usingSecondOrderMesh() const
     135             : {
     136      107777 :   return false;
     137             : }
     138             : 
     139             : unsigned int
     140           0 : Component1D::getNodesetID() const
     141             : {
     142           0 :   checkSetupStatus(MESH_PREPARED);
     143             : 
     144           0 :   return _nodeset_id;
     145             : }
     146             : 
     147             : const BoundaryName &
     148         147 : Component1D::getNodesetName() const
     149             : {
     150         147 :   checkSetupStatus(MESH_PREPARED);
     151             : 
     152         147 :   return _nodeset_name;
     153             : }
     154             : 
     155             : const std::vector<Component1D::Connection> &
     156        5870 : Component1D::getConnections(Component1DConnection::EEndType end_type) const
     157             : {
     158        5870 :   checkSetupStatus(MESH_PREPARED);
     159             : 
     160             :   std::map<Component1DConnection::EEndType, std::vector<Connection>>::const_iterator it =
     161             :       _connections.find(end_type);
     162        5870 :   if (it != _connections.end())
     163        5870 :     return it->second;
     164             :   else
     165           0 :     mooseError(name(), ": Invalid end type (", end_type, ").");
     166             : }
     167             : 
     168             : std::string
     169          90 : Component1D::sortBy() const
     170             : {
     171             :   // choose the dominant direction
     172          90 :   std::string dominant_direction = "x";
     173          90 :   const Real x_abs = std::abs(_dir(0));
     174          90 :   const Real y_abs = std::abs(_dir(1));
     175          90 :   const Real z_abs = std::abs(_dir(2));
     176             :   Real max_value = x_abs;
     177          90 :   if (y_abs > max_value)
     178             :   {
     179             :     dominant_direction = "y";
     180             :     max_value = y_abs;
     181             :   }
     182          90 :   if (z_abs > max_value)
     183             :   {
     184             :     dominant_direction = "z";
     185             :     max_value = z_abs;
     186             :   }
     187          90 :   return dominant_direction;
     188             : }

Generated by: LCOV version 1.14