LCOV - code coverage report
Current view: top level - include/loops - GatherRCDataFaceThread.h (source / functions) Hit Total Coverage
Test: idaholab/moose navier_stokes: #31405 (292dce) with base fef103 Lines: 67 68 98.5 %
Date: 2025-09-04 07:54:44 Functions: 8 8 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             : #pragma once
      11             : 
      12             : #include "ComputeFVFluxThread.h"
      13             : #include "INSFVMomentumResidualObject.h"
      14             : #include "INSFVAttributes.h"
      15             : #include "TheWarehouse.h"
      16             : 
      17             : /**
      18             :  * A class that gathers 'a' coefficient data from flux kernels, boundary conditions, and interface
      19             :  * kernels contributing to the Navier-Stokes momentum residuals. We loop over each active, local
      20             :  * face and call the gatherRCData method on each kernel with the current face as an argument
      21             :  */
      22             : template <typename RangeType>
      23             : class GatherRCDataFaceThread : public ThreadedFaceLoop<RangeType>
      24             : {
      25             : public:
      26             :   using Parent = ThreadedFaceLoop<RangeType>;
      27             :   using Parent::join;
      28             : 
      29             :   GatherRCDataFaceThread(FEProblemBase & fe_problem,
      30             :                          const unsigned int nl_sys_number,
      31             :                          const std::vector<unsigned int> & vars,
      32             :                          bool on_displaced);
      33             : 
      34             :   // Splitting Constructor
      35             :   GatherRCDataFaceThread(GatherRCDataFaceThread & x, Threads::split split);
      36             : 
      37             :   void onFace(const FaceInfo & fi) override final;
      38             :   void onBoundary(const FaceInfo & fi, BoundaryID boundary) override final;
      39             :   void subdomainChanged() override final;
      40             :   void neighborSubdomainChanged() override final;
      41             : 
      42             : private:
      43             :   /**
      44             :    * Called at the end of either \p subdomainChanged or \p neighborSubdomainChanged, this method
      45             :    * computes the final \p _fv_flux_kernels set
      46             :    */
      47             :   void finalizeContainers();
      48             : 
      49             :   /**
      50             :    * This determines all the momentum residual objects for all the variables
      51             :    * @param ros The output of this method; all the momentum residual objects for all the variables
      52             :    * @param queries Candidate MooseObjects for momentum residual object consideration that have been
      53             :    * pre-filtered based on attributes such as thread ID, boundary ID, subdomain ID, etc.
      54             :    */
      55             :   template <typename... Attribs>
      56             :   void getVarROs(std::vector<INSFVMomentumResidualObject *> & ros,
      57             :                  TheWarehouse::QueryCache<Attribs...> & queries);
      58             : 
      59             :   /// The velocity variable numbers
      60             :   const std::vector<unsigned int> & _vars;
      61             : 
      62             :   /// The collection of flux kernels that contribute to the momentum equation residuals
      63             :   std::set<INSFVMomentumResidualObject *> _fv_flux_kernels;
      64             : 
      65             :   /// The subset of flux kernels that contribute to the momentum equation residual from the
      66             :   /// element side of the face
      67             :   std::set<INSFVMomentumResidualObject *> _elem_sub_fv_flux_kernels;
      68             : 
      69             :   /// The subset of flux kernels that contribute to the momentum equation residual from the
      70             :   /// neighbor side of the face
      71             :   std::set<INSFVMomentumResidualObject *> _neigh_sub_fv_flux_kernels;
      72             : };
      73             : 
      74             : template <typename RangeType>
      75       92432 : GatherRCDataFaceThread<RangeType>::GatherRCDataFaceThread(FEProblemBase & fe_problem,
      76             :                                                           const unsigned int nl_sys_number,
      77             :                                                           const std::vector<unsigned int> & vars,
      78             :                                                           bool on_displaced)
      79      184864 :   : ThreadedFaceLoop<RangeType>(fe_problem, nl_sys_number, {}, on_displaced), _vars(vars)
      80             : {
      81       92432 : }
      82             : 
      83             : template <typename RangeType>
      84       16319 : GatherRCDataFaceThread<RangeType>::GatherRCDataFaceThread(GatherRCDataFaceThread & x,
      85             :                                                           Threads::split split)
      86       16319 :   : ThreadedFaceLoop<RangeType>(x, split), _vars(x._vars)
      87             : {
      88       16319 : }
      89             : 
      90             : template <typename RangeType>
      91             : template <typename... Attribs>
      92             : void
      93    15427529 : GatherRCDataFaceThread<RangeType>::getVarROs(std::vector<INSFVMomentumResidualObject *> & ros,
      94             :                                              TheWarehouse::QueryCache<Attribs...> & queries)
      95             : {
      96    77457179 :   for (const auto var_num : _vars)
      97             :   {
      98             :     // We don't want to do cascading var num attributes or else the second time around we won't get
      99             :     // any results out of the query (e.g. an object cannot have a variable that simultaneously has
     100             :     // both var number 0 and 1)
     101    31014825 :     auto copied_queries = queries;
     102             :     std::vector<INSFVMomentumResidualObject *> var_ros;
     103    62029650 :     copied_queries.template condition<AttribVar>(static_cast<int>(var_num)).queryInto(var_ros);
     104    50237569 :     for (auto * const var_ro : var_ros)
     105    19222744 :       ros.push_back(var_ro);
     106             :   }
     107    15427529 : }
     108             : 
     109             : template <typename RangeType>
     110             : void
     111    48392118 : GatherRCDataFaceThread<RangeType>::onFace(const FaceInfo & fi)
     112             : {
     113   258098100 :   for (auto * const k : _fv_flux_kernels)
     114   209705982 :     k->gatherRCData(fi);
     115    48392118 : }
     116             : 
     117             : template <typename RangeType>
     118             : void
     119     3910908 : GatherRCDataFaceThread<RangeType>::onBoundary(const FaceInfo & fi, BoundaryID bnd_id)
     120             : {
     121             :   {
     122             :     std::vector<INSFVMomentumResidualObject *> bcs;
     123             :     // cannot bind to lvalue reference otherwise the temporary is destroyed and we are left with a
     124             :     // dangling reference
     125     7821816 :     auto queries = this->_fe_problem.theWarehouse()
     126             :                        .query()
     127     7821816 :                        .template condition<AttribSystem>("FVFluxBC")
     128     3910908 :                        .template condition<AttribSysNum>(this->_nl_system_num)
     129     3910908 :                        .template condition<AttribDisplaced>(this->_on_displaced)
     130     3910908 :                        .template condition<AttribThread>(this->_tid)
     131     3910908 :                        .template condition<AttribBoundaries>(bnd_id);
     132     3910908 :     getVarROs(bcs, queries);
     133             : 
     134     5575336 :     for (auto * const bc : bcs)
     135     1664428 :       bc->gatherRCData(fi);
     136     3910908 :   }
     137             : 
     138             :   {
     139             :     std::vector<INSFVMomentumResidualObject *> iks;
     140             :     // cannot bind to lvalue reference otherwise the temporary is destroyed and we are left with a
     141             :     // dangling reference
     142     7821816 :     auto queries = this->_fe_problem.theWarehouse()
     143             :                        .query()
     144     7821816 :                        .template condition<AttribSystem>("FVInterfaceKernel")
     145     3910908 :                        .template condition<AttribSysNum>(this->_nl_system_num)
     146     3910908 :                        .template condition<AttribDisplaced>(this->_on_displaced)
     147     3910908 :                        .template condition<AttribThread>(this->_tid)
     148     3910908 :                        .template condition<AttribBoundaries>(bnd_id);
     149     3910908 :     getVarROs(iks, queries);
     150             : 
     151     3910908 :     for (auto * const ik : iks)
     152           0 :       ik->gatherRCData(fi);
     153     3910908 :   }
     154     3910908 : }
     155             : 
     156             : template <typename RangeType>
     157             : void
     158      381673 : GatherRCDataFaceThread<RangeType>::subdomainChanged()
     159             : {
     160      381673 :   ThreadedFaceLoop<RangeType>::subdomainChanged();
     161             : 
     162             :   // Clear kernels
     163             :   _fv_flux_kernels.clear();
     164             :   _elem_sub_fv_flux_kernels.clear();
     165             : 
     166             :   std::vector<INSFVMomentumResidualObject *> kernels;
     167             :   // cannot bind to lvalue reference otherwise the temporary is destroyed and we are left with a
     168             :   // dangling reference
     169      763346 :   auto queries = this->_fe_problem.theWarehouse()
     170             :                      .query()
     171      763346 :                      .template condition<AttribSysNum>(this->_nl_system_num)
     172      381673 :                      .template condition<AttribSystem>("FVFluxKernel")
     173      381673 :                      .template condition<AttribDisplaced>(this->_on_displaced)
     174      381673 :                      .template condition<AttribSubdomains>(this->_subdomain)
     175      381673 :                      .template condition<AttribThread>(this->_tid);
     176      381673 :   getVarROs(kernels, queries);
     177             : 
     178             :   _elem_sub_fv_flux_kernels =
     179      381673 :       std::set<INSFVMomentumResidualObject *>(kernels.begin(), kernels.end());
     180             : 
     181      381673 :   finalizeContainers();
     182      381673 : }
     183             : 
     184             : template <typename RangeType>
     185             : void
     186     7224040 : GatherRCDataFaceThread<RangeType>::neighborSubdomainChanged()
     187             : {
     188     7224040 :   ThreadedFaceLoop<RangeType>::neighborSubdomainChanged();
     189             : 
     190             :   // Clear kernels
     191             :   _fv_flux_kernels.clear();
     192             :   _neigh_sub_fv_flux_kernels.clear();
     193             : 
     194             :   std::vector<INSFVMomentumResidualObject *> kernels;
     195             :   // cannot bind to lvalue reference otherwise the temporary is destroyed and we are left with a
     196             :   // dangling reference
     197    14448080 :   auto queries = this->_fe_problem.theWarehouse()
     198             :                      .query()
     199    14448080 :                      .template condition<AttribSysNum>(this->_nl_system_num)
     200     7224040 :                      .template condition<AttribSystem>("FVFluxKernel")
     201     7224040 :                      .template condition<AttribDisplaced>(this->_on_displaced)
     202     7224040 :                      .template condition<AttribSubdomains>(this->_neighbor_subdomain)
     203     7224040 :                      .template condition<AttribThread>(this->_tid);
     204     7224040 :   getVarROs(kernels, queries);
     205             : 
     206             :   _neigh_sub_fv_flux_kernels =
     207     7224040 :       std::set<INSFVMomentumResidualObject *>(kernels.begin(), kernels.end());
     208             : 
     209     7224040 :   finalizeContainers();
     210     7224040 : }
     211             : 
     212             : template <typename RangeType>
     213             : void
     214     7605713 : GatherRCDataFaceThread<RangeType>::finalizeContainers()
     215             : {
     216             :   const bool same_kernels = _elem_sub_fv_flux_kernels == _neigh_sub_fv_flux_kernels;
     217     7605713 :   if (same_kernels)
     218             :     _fv_flux_kernels = _elem_sub_fv_flux_kernels;
     219             :   else
     220     3618372 :     std::set_union(_elem_sub_fv_flux_kernels.begin(),
     221             :                    _elem_sub_fv_flux_kernels.end(),
     222             :                    _neigh_sub_fv_flux_kernels.begin(),
     223             :                    _neigh_sub_fv_flux_kernels.end(),
     224     3618372 :                    std::inserter(_fv_flux_kernels, _fv_flux_kernels.begin()));
     225     7605713 : }

Generated by: LCOV version 1.14