LCOV - code coverage report
Current view: top level - src/components - Component1D.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 58 70 82.9 %
Date: 2025-07-30 13:02:48 Functions: 7 8 87.5 %
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        8380 : Component1D::validParams()
      15             : {
      16        8380 :   InputParameters params = GeneratedMeshComponent::validParams();
      17        8380 :   return params;
      18             : }
      19             : 
      20        4189 : Component1D::Component1D(const InputParameters & parameters) : GeneratedMeshComponent(parameters) {}
      21             : 
      22             : void
      23        4170 : Component1D::buildMeshNodes()
      24             : {
      25             :   Point p(0, 0, 0);
      26      120463 :   for (unsigned int i = 0; i < _node_locations.size(); i++)
      27             :   {
      28      116293 :     p(0) = _node_locations[i];
      29      116293 :     addNode(p);
      30             :   }
      31        4170 : }
      32             : 
      33             : void
      34        4189 : Component1D::buildMesh()
      35             : {
      36        4189 :   buildMeshNodes();
      37             : 
      38        4189 :   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        4189 :   _nodeset_id = mesh().getNextBoundaryId();
      43        4189 :   _nodeset_name = name();
      44        4189 :   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        4189 :   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        4189 :     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      121451 :   for (auto & node_id : _node_ids)
      70             :   {
      71      117262 :     const Node * nd = the_mesh.node_ptr(node_id);
      72      117262 :     boundary_info.add_node(nd, _nodeset_id);
      73             :   }
      74             : 
      75             :   // elems
      76        4189 :   BoundaryID bc_id_inlet = mesh().getNextBoundaryId();
      77        4189 :   BoundaryID bc_id_outlet = mesh().getNextBoundaryId();
      78        4189 :   auto & binfo = mesh().getMesh().get_boundary_info();
      79      117262 :   for (unsigned int i = 0; i < _n_elem; i++)
      80             :   {
      81             :     Elem * elem = nullptr;
      82      113073 :     if (usingSecondOrderMesh())
      83           0 :       elem = addElementEdge3(_node_ids[2 * i], _node_ids[2 * i + 2], _node_ids[2 * i + 1]);
      84             :     else
      85      113073 :       elem = addElementEdge2(_node_ids[i], _node_ids[i + 1]);
      86             : 
      87             :     // BCs
      88      113073 :     if (i == 0)
      89             :     {
      90        4189 :       Point pt = _position;
      91        4189 :       _connections[Component1DConnection::IN].push_back(Connection(pt, elem, 0, bc_id_inlet, -1));
      92        4189 :       boundary_info.add_side(elem, 0, bc_id_inlet);
      93        8378 :       binfo.sideset_name(bc_id_inlet) = genName(name(), "in");
      94             :     }
      95      113073 :     if (i == (_n_elem - 1))
      96             :     {
      97        4189 :       Point pt = _position + _length * _dir;
      98        4189 :       _connections[Component1DConnection::OUT].push_back(Connection(pt, elem, 1, bc_id_outlet, 1));
      99        4189 :       boundary_info.add_side(elem, 1, bc_id_outlet);
     100        8378 :       binfo.sideset_name(bc_id_outlet) = genName(name(), "out");
     101             :     }
     102             :   }
     103             : 
     104        4189 :   if (_axial_region_names.size() > 0)
     105             :   {
     106             :     unsigned int k = 0;
     107          84 :     for (unsigned int i = 0; i < _axial_region_names.size(); i++)
     108             :     {
     109             :       const std::string & region_name = _axial_region_names[i];
     110          56 :       SubdomainID subdomain_id = mesh().getNextSubdomainId();
     111         112 :       setSubdomainInfo(subdomain_id, genName(name(), region_name));
     112             : 
     113         273 :       for (unsigned int j = 0; j < _n_elems[i]; j++, k++)
     114             :       {
     115         217 :         dof_id_type elem_id = _elem_ids[k];
     116         217 :         mesh().elemPtr(elem_id)->subdomain_id() = subdomain_id;
     117             :       }
     118             :     }
     119             :   }
     120             :   else
     121             :   {
     122        4161 :     SubdomainID subdomain_id = mesh().getNextSubdomainId();
     123        4161 :     setSubdomainInfo(subdomain_id, name());
     124             : 
     125      117017 :     for (auto && id : _elem_ids)
     126      112856 :       mesh().elemPtr(id)->subdomain_id() = subdomain_id;
     127             :   }
     128             : 
     129             :   // Update the mesh
     130        4189 :   mesh().update();
     131        4189 : }
     132             : 
     133             : bool
     134      129734 : Component1D::usingSecondOrderMesh() const
     135             : {
     136      129734 :   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         288 : Component1D::getNodesetName() const
     149             : {
     150         288 :   checkSetupStatus(MESH_PREPARED);
     151             : 
     152         288 :   return _nodeset_name;
     153             : }
     154             : 
     155             : const std::vector<Component1D::Connection> &
     156       11621 : Component1D::getConnections(Component1DConnection::EEndType end_type) const
     157             : {
     158       11621 :   checkSetupStatus(MESH_PREPARED);
     159             : 
     160             :   std::map<Component1DConnection::EEndType, std::vector<Connection>>::const_iterator it =
     161             :       _connections.find(end_type);
     162       11621 :   if (it != _connections.end())
     163       11621 :     return it->second;
     164             :   else
     165           0 :     mooseError(name(), ": Invalid end type (", end_type, ").");
     166             : }

Generated by: LCOV version 1.14