LCOV - code coverage report
Current view: top level - src/userobjects - ADFlowJunctionUserObject.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 37 49 75.5 %
Date: 2025-07-30 13:02:48 Functions: 5 5 100.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 "ADFlowJunctionUserObject.h"
      11             : #include "MooseMesh.h"
      12             : 
      13             : InputParameters
      14        3333 : ADFlowJunctionUserObject::validParams()
      15             : {
      16        3333 :   InputParameters params = SideUserObject::validParams();
      17             : 
      18        6666 :   params.addRequiredParam<std::vector<Real>>(
      19             :       "normals", "Flow channel outward normals or junction inward normals");
      20        6666 :   params.addParam<std::vector<processor_id_type>>(
      21             :       "processor_ids", {}, "Processor IDs owning each connected flow channel element");
      22             : 
      23        3333 :   params.addClassDescription("Provides common interfaces for flow junction user objects");
      24             : 
      25        3333 :   return params;
      26           0 : }
      27             : 
      28        1822 : ADFlowJunctionUserObject::ADFlowJunctionUserObject(const InputParameters & parameters)
      29             :   : SideUserObject(parameters),
      30             : 
      31        1822 :     _bnd_ids_vector(_mesh.getBoundaryIDs(boundaryNames(), false)),
      32        1822 :     _n_bnd_ids(_bnd_ids_vector.size()),
      33        3644 :     _normal(getParam<std::vector<Real>>("normals")),
      34        3644 :     _dir(getMaterialProperty<RealVectorValue>("direction")),
      35        1822 :     _n_connections(_normal.size()),
      36        7288 :     _processor_ids(getParam<std::vector<processor_id_type>>("processor_ids"))
      37             : {
      38        1822 :   if (comm().size() > 1)
      39             :   {
      40        1100 :     if (_processor_ids.size() != _n_connections)
      41           0 :       mooseError("The number of entries in the 'processor_ids' parameter must equal the number of "
      42             :                  "connections (",
      43           0 :                  _n_connections,
      44             :                  ").");
      45             :   }
      46             :   else
      47         722 :     _processor_ids.resize(_n_connections, 0.);
      48        1822 : }
      49             : 
      50             : void
      51       73760 : ADFlowJunctionUserObject::finalize()
      52             : {
      53       73760 : }
      54             : 
      55             : unsigned int
      56      338512 : ADFlowJunctionUserObject::getBoundaryIDIndex()
      57             : {
      58      338512 :   auto elem_side = std::make_pair(_current_elem, _current_side);
      59      338512 :   auto it = _elem_side_to_bnd_id_index.find(elem_side);
      60      338512 :   if (it == _elem_side_to_bnd_id_index.end())
      61             :   {
      62             :     // Get the boundary IDs associated with this (elem,side). In general, there
      63             :     // may be more than one boundary ID associated with an (elem,side), but
      64             :     // there should be exactly one of these boundary IDs that is seen by this
      65             :     // user object.
      66             :     const std::vector<BoundaryID> elem_side_bnd_ids =
      67        2104 :         _mesh.getBoundaryIDs(_current_elem, _current_side);
      68             : 
      69             :     // Loop over the boundary IDs for this (elem,side) pair and over the
      70             :     // boundary IDs for this side user object; there should be exactly one match.
      71             :     bool found_matching_boundary_id = false;
      72             :     unsigned int boundary_id_index = 0;
      73        6312 :     for (unsigned int i = 0; i < elem_side_bnd_ids.size(); i++)
      74       13452 :       for (unsigned int j = 0; j < _n_bnd_ids; j++)
      75        9244 :         if (elem_side_bnd_ids[i] == _bnd_ids_vector[j])
      76             :         {
      77        2104 :           if (found_matching_boundary_id)
      78           0 :             mooseError(name(), ": Multiple matches for boundary ID were found");
      79             :           else
      80             :           {
      81             :             found_matching_boundary_id = true;
      82             :             boundary_id_index = j;
      83             :           }
      84             :         }
      85             : 
      86        2104 :     if (!found_matching_boundary_id)
      87             :     {
      88           0 :       std::stringstream ss;
      89           0 :       ss << name() << ": No matching boundary ID was found for (elem,side) = ("
      90           0 :          << _current_elem->id() << "," << _current_side << ").";
      91           0 :       mooseError(ss.str());
      92           0 :     }
      93             : 
      94             :     // Check that this boundary ID index was not already found by an earlier (elem,side)
      95        2104 :     for (auto it_other = _elem_side_to_bnd_id_index.begin();
      96        2852 :          it_other != _elem_side_to_bnd_id_index.end();
      97             :          it_other++)
      98             :     {
      99         748 :       if (it_other->second == boundary_id_index)
     100           0 :         mooseError(name(), ": Multiple (elem,side) pairs had the same boundary ID index");
     101             :     }
     102             : 
     103             :     // Store boundary index for future use
     104        2104 :     _elem_side_to_bnd_id_index[elem_side] = boundary_id_index;
     105             : 
     106             :     return boundary_id_index;
     107             :   }
     108             :   else
     109             :   {
     110             :     // get the boundary ID that is already stored in the map
     111      336408 :     return _elem_side_to_bnd_id_index[elem_side];
     112             :   }
     113             : }
     114             : 
     115             : void
     116      407005 : ADFlowJunctionUserObject::checkValidConnectionIndex(const unsigned int & connection_index) const
     117             : {
     118      407005 :   if (connection_index >= _n_connections)
     119           0 :     mooseError(name(),
     120             :                ": The connection index '",
     121             :                connection_index,
     122             :                "' is invalid; the range of valid indices is (0, ",
     123           0 :                _n_connections - 1,
     124             :                ").");
     125      407005 : }

Generated by: LCOV version 1.14