LCOV - code coverage report
Current view: top level - src/userobjects - FlowChannelHeatStructureCouplerUserObject.C (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #32971 (54bef8) with base c6cf66 Lines: 46 48 95.8 %
Date: 2026-05-29 20:41:18 Functions: 7 7 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 "FlowChannelHeatStructureCouplerUserObject.h"
      11             : #include "THMUtils.h"
      12             : 
      13             : InputParameters
      14         320 : FlowChannelHeatStructureCouplerUserObject::validParams()
      15             : {
      16         320 :   InputParameters params = ElementUserObject::validParams();
      17         320 :   params += ADFunctorInterface::validParams();
      18         640 :   params.addRequiredParam<MeshAlignment *>("_mesh_alignment", "Mesh alignment object");
      19         320 :   params.addClassDescription(
      20             :       "Base class for caching quantities computed between flow channels and heat structures.");
      21         320 :   return params;
      22           0 : }
      23             : 
      24         173 : FlowChannelHeatStructureCouplerUserObject::FlowChannelHeatStructureCouplerUserObject(
      25         173 :     const InputParameters & parameters)
      26             :   : ElementUserObject(parameters),
      27             :     ADFunctorInterface(this),
      28         173 :     _fc_elem_id(0),
      29         173 :     _hs_elem_id(0),
      30         173 :     _fc_qp(0),
      31         173 :     _hs_qp(0),
      32         346 :     _mesh_alignment(*getParam<MeshAlignment *>("_mesh_alignment"))
      33             : {
      34         173 :   _mesh_alignment.buildCoupledElemQpIndexMap(_assembly);
      35         173 : }
      36             : 
      37             : void
      38       11005 : FlowChannelHeatStructureCouplerUserObject::initialize()
      39             : {
      40       11005 :   const auto map_ptrs = getCachedQuantityMaps();
      41       33015 :   for (const auto map_ptr : map_ptrs)
      42             :     map_ptr->clear();
      43       11005 : }
      44             : 
      45             : void
      46       56503 : FlowChannelHeatStructureCouplerUserObject::execute()
      47             : {
      48       56503 :   unsigned int n_qpts = _qrule->n_points();
      49             : 
      50       56503 :   _fc_elem_id = _current_elem->id();
      51       56503 :   _hs_elem_id = _mesh_alignment.getCoupledElemID(_fc_elem_id);
      52             : 
      53       56503 :   const auto map_ptrs = getCachedQuantityMaps();
      54      169509 :   for (const auto map_ptr : map_ptrs)
      55             :   {
      56      113006 :     (*map_ptr)[_fc_elem_id].resize(n_qpts);
      57      113006 :     (*map_ptr)[_hs_elem_id].resize(n_qpts);
      58             :   }
      59             : 
      60      169509 :   for (_fc_qp = 0; _fc_qp < n_qpts; _fc_qp++)
      61             :   {
      62      113006 :     _hs_qp = _mesh_alignment.getCoupledElemQpIndex(_fc_elem_id, _fc_qp);
      63      113006 :     computeQpCachedQuantities();
      64             :   }
      65       56503 : }
      66             : 
      67             : void
      68        1475 : FlowChannelHeatStructureCouplerUserObject::threadJoin(const UserObject & uo)
      69             : {
      70             :   const auto & fc_hs_uo = static_cast<const FlowChannelHeatStructureCouplerUserObject &>(uo);
      71             : 
      72        1475 :   const auto map_ptrs = getCachedQuantityMaps();
      73        1475 :   const auto other_map_ptrs = fc_hs_uo.getCachedQuantityMaps();
      74             : 
      75        4425 :   for (unsigned int i = 0; i < map_ptrs.size(); ++i)
      76        5086 :     for (auto & it : *other_map_ptrs[i])
      77        2136 :       (*map_ptrs[i])[it.first] = it.second;
      78        1475 : }
      79             : 
      80             : void
      81        9530 : FlowChannelHeatStructureCouplerUserObject::finalize()
      82             : {
      83        9530 :   const auto map_ptrs = getCachedQuantityMaps();
      84       28590 :   for (const auto map_ptr : map_ptrs)
      85       19060 :     THM::allGatherADVectorMap(comm(), *map_ptr);
      86        9530 : }
      87             : 
      88             : const std::vector<ADReal> &
      89     1104260 : FlowChannelHeatStructureCouplerUserObject::getCachedQuantity(
      90             :     dof_id_type elem_id,
      91             :     const std::map<dof_id_type, std::vector<ADReal>> & elem_id_to_values,
      92             :     const std::string & description) const
      93             : {
      94             :   Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
      95             : 
      96             :   auto it = elem_id_to_values.find(elem_id);
      97     1104260 :   if (it != elem_id_to_values.end())
      98     1104260 :     return it->second;
      99             :   else
     100           0 :     mooseError(name(),
     101             :                ": The ",
     102             :                description,
     103             :                " for element ",
     104             :                elem_id,
     105             :                " was requested but not computed.");
     106             : }

Generated by: LCOV version 1.14