LCOV - code coverage report
Current view: top level - src/loops - ComputeLinearFVFaceThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33416 (b10b36) with base 9fbd27 Lines: 133 145 91.7 %
Date: 2026-07-23 16:15:30 Functions: 6 8 75.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 "ComputeLinearFVFaceThread.h"
      11             : #include "LinearSystem.h"
      12             : #include "LinearFVKernel.h"
      13             : #include "LinearFVFluxKernel.h"
      14             : #include "FEProblemBase.h"
      15             : 
      16       25792 : ComputeLinearFVFaceThread::ComputeLinearFVFaceThread(FEProblemBase & fe_problem,
      17             :                                                      const unsigned int system_num,
      18             :                                                      const Moose::FV::LinearFVComputationMode mode,
      19             :                                                      const std::set<TagID> & vector_tags,
      20       25792 :                                                      const std::set<TagID> & matrix_tags)
      21       25792 :   : _fe_problem(fe_problem),
      22       25792 :     _system_number(system_num),
      23       25792 :     _mode(mode),
      24       25792 :     _vector_tags(vector_tags),
      25       25792 :     _matrix_tags(matrix_tags),
      26       25792 :     _system_contrib_objects_ready(false)
      27             : {
      28       25792 : }
      29             : 
      30             : // Splitting Constructor
      31           0 : ComputeLinearFVFaceThread::ComputeLinearFVFaceThread(ComputeLinearFVFaceThread & x,
      32           0 :                                                      Threads::split /*split*/)
      33           0 :   : _fe_problem(x._fe_problem),
      34           0 :     _system_number(x._system_number),
      35           0 :     _mode(x._mode),
      36           0 :     _vector_tags(x._vector_tags),
      37           0 :     _matrix_tags(x._matrix_tags),
      38           0 :     _system_contrib_objects_ready(x._system_contrib_objects_ready)
      39             : {
      40           0 : }
      41             : 
      42             : void
      43       25792 : ComputeLinearFVFaceThread::operator()(const FaceInfoRange & range)
      44             : {
      45       25792 :   ParallelUniqueId puid;
      46       25792 :   _tid = puid.id;
      47             : 
      48       25792 :   _old_subdomain = Moose::INVALID_BLOCK_ID;
      49       25792 :   _old_neighbor_subdomain = Moose::INVALID_BLOCK_ID;
      50             : 
      51       25792 :   setupSystemContributionObjects();
      52       25792 :   printGeneralExecutionInformation();
      53             : 
      54             :   // Iterate over all the elements in the range
      55    55399022 :   for (const auto & face_info : range)
      56             :   {
      57    55373230 :     _subdomain = face_info->elem().subdomain_id();
      58    55373230 :     _neighbor_subdomain =
      59    55373230 :         face_info->neighborPtr() ? face_info->neighbor().subdomain_id() : _subdomain;
      60    55373230 :     if (_subdomain != _old_subdomain || _neighbor_subdomain != _old_neighbor_subdomain)
      61             :     {
      62       29322 :       fetchBlockSystemContributionObjects();
      63       29322 :       printBlockExecutionInformation();
      64             :     }
      65             : 
      66    55373230 :     const Real face_area = face_info->faceArea() * face_info->faceCoord();
      67             : 
      68             :     // Time to execute the kernels that contribute to the matrix and
      69             :     // right hand side
      70   110718760 :     for (auto & kernel : _fv_flux_kernels)
      71             :     {
      72    55345530 :       kernel->setupFaceData(face_info);
      73    55345530 :       kernel->setCurrentFaceArea(face_area);
      74    55345530 :       kernel->addMatrixContribution();
      75    55345530 :       kernel->addRightHandSideContribution();
      76             :     }
      77             :   }
      78       25792 : }
      79             : 
      80             : void
      81           0 : ComputeLinearFVFaceThread::join(const ComputeLinearFVFaceThread & /*y*/)
      82             : {
      83           0 : }
      84             : 
      85             : void
      86       25792 : ComputeLinearFVFaceThread::setupSystemContributionObjects()
      87             : {
      88             :   // The reason why we need to grab vectors and matrices separately is that
      89             :   // we want to grab a union instead of an intersection.
      90       25792 :   std::vector<LinearFVFluxKernel *> kernels_after_vectors;
      91       25792 :   _fe_problem.theWarehouse()
      92       25792 :       .query()
      93       25792 :       .template condition<AttribSysNum>(_system_number)
      94       25792 :       .template condition<AttribSystem>("LinearFVFluxKernel")
      95       51584 :       .template condition<AttribKokkos>(false)
      96       25792 :       .template condition<AttribThread>(_tid)
      97       25792 :       .template condition<AttribVectorTags>(_vector_tags)
      98       25792 :       .queryInto(kernels_after_vectors);
      99             : 
     100       25792 :   std::vector<LinearFVFluxKernel *> kernels_after_matrices;
     101       25792 :   _fe_problem.theWarehouse()
     102       25792 :       .query()
     103       25792 :       .template condition<AttribSysNum>(_system_number)
     104       25792 :       .template condition<AttribSystem>("LinearFVFluxKernel")
     105       51584 :       .template condition<AttribKokkos>(false)
     106       25792 :       .template condition<AttribThread>(_tid)
     107       25792 :       .template condition<AttribMatrixTags>(_matrix_tags)
     108       25792 :       .queryInto(kernels_after_matrices);
     109             : 
     110             :   // We fetch the union of the available objects
     111       25792 :   std::vector<LinearFVFluxKernel *> kernels;
     112       25792 :   MooseUtils::getUnion(kernels_after_vectors, kernels_after_matrices, kernels);
     113             : 
     114             :   // As a last step, we make sure the kernels know which vectors/matrices they need to contribute to
     115       51415 :   for (auto & kernel : kernels)
     116       25623 :     kernel->linkTaggedVectorsAndMatrices(_vector_tags, _matrix_tags);
     117             : 
     118       25792 :   _system_contrib_objects_ready = true;
     119       25792 : }
     120             : 
     121             : void
     122       29322 : ComputeLinearFVFaceThread::fetchBlockSystemContributionObjects()
     123             : {
     124             :   mooseAssert(_system_contrib_objects_ready,
     125             :               "The system contribution objects need to be set up before we fetch the "
     126             :               "block-restricted objects!");
     127             : 
     128       29322 :   _fv_flux_kernels.clear();
     129             : 
     130       29322 :   if (_subdomain != _old_subdomain)
     131             :   {
     132             :     // We just filter based on subdomain ID on top of everything else
     133       25956 :     std::vector<LinearFVFluxKernel *> kernels_after_vector;
     134       25956 :     _fe_problem.theWarehouse()
     135       25956 :         .query()
     136       25956 :         .template condition<AttribSysNum>(_system_number)
     137       25956 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     138       51912 :         .template condition<AttribKokkos>(false)
     139       25956 :         .template condition<AttribThread>(_tid)
     140       25956 :         .template condition<AttribVectorTags>(_vector_tags)
     141       25956 :         .template condition<AttribSubdomains>(_subdomain)
     142       25956 :         .queryInto(kernels_after_vector);
     143       25956 :     std::vector<LinearFVFluxKernel *> kernels_after_matrix;
     144       25956 :     _fe_problem.theWarehouse()
     145       25956 :         .query()
     146       25956 :         .template condition<AttribSysNum>(_system_number)
     147       25956 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     148       51912 :         .template condition<AttribKokkos>(false)
     149       25956 :         .template condition<AttribThread>(_tid)
     150       25956 :         .template condition<AttribMatrixTags>(_matrix_tags)
     151       25956 :         .template condition<AttribSubdomains>(_subdomain)
     152       25956 :         .queryInto(kernels_after_matrix);
     153             : 
     154             :     // We populate the list of kernels with the union of the two vectors
     155       25956 :     MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_flux_kernels_elem);
     156       25956 :     _old_subdomain = _subdomain;
     157       25956 :   }
     158       29322 :   _fv_flux_kernels.insert(_fv_flux_kernels_elem.begin(), _fv_flux_kernels_elem.end());
     159             : 
     160       29322 :   if (_neighbor_subdomain != _old_neighbor_subdomain)
     161             :   {
     162             :     // Here we just filter based on subdomain ID on top of everything else
     163       29278 :     std::vector<LinearFVFluxKernel *> kernels_after_vector;
     164       29278 :     _fe_problem.theWarehouse()
     165       29278 :         .query()
     166       29278 :         .template condition<AttribSysNum>(_system_number)
     167       29278 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     168       58556 :         .template condition<AttribKokkos>(false)
     169       29278 :         .template condition<AttribThread>(_tid)
     170       29278 :         .template condition<AttribVectorTags>(_vector_tags)
     171       29278 :         .template condition<AttribSubdomains>(_neighbor_subdomain)
     172       29278 :         .queryInto(kernels_after_vector);
     173       29278 :     std::vector<LinearFVFluxKernel *> kernels_after_matrix;
     174       29278 :     _fe_problem.theWarehouse()
     175       29278 :         .query()
     176       29278 :         .template condition<AttribSysNum>(_system_number)
     177       29278 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     178       58556 :         .template condition<AttribKokkos>(false)
     179       29278 :         .template condition<AttribThread>(_tid)
     180       29278 :         .template condition<AttribMatrixTags>(_matrix_tags)
     181       29278 :         .template condition<AttribSubdomains>(_neighbor_subdomain)
     182       29278 :         .queryInto(kernels_after_matrix);
     183             : 
     184             :     // We populate the list of kernels with the union of the two vectors
     185       29278 :     MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_flux_kernels_neighbor);
     186       29278 :     _old_neighbor_subdomain = _neighbor_subdomain;
     187       29278 :   }
     188       29322 :   _fv_flux_kernels.insert(_fv_flux_kernels_neighbor.begin(), _fv_flux_kernels_neighbor.end());
     189       29322 : }
     190             : 
     191             : void
     192       25792 : ComputeLinearFVFaceThread::printGeneralExecutionInformation() const
     193             : {
     194       25792 :   if (!_fe_problem.shouldPrintExecution(_tid))
     195       25786 :     return;
     196           6 :   auto & console = _fe_problem.console();
     197           6 :   auto execute_on = _fe_problem.getCurrentExecuteOnFlag();
     198           6 :   console << "[DBG] Beginning linear finite volume flux objects loop on " << execute_on
     199           6 :           << std::endl;
     200           6 :   mooseDoOnce(console << "[DBG] Loop on faces (FaceInfo), objects ordered on each face: "
     201             :                       << std::endl;
     202             :               console << "[DBG] - linear finite volume flux kernels" << std::endl);
     203           6 : }
     204             : 
     205             : void
     206       29322 : ComputeLinearFVFaceThread::printBlockExecutionInformation() const
     207             : {
     208       29322 :   if (!_fe_problem.shouldPrintExecution(_tid) || _fv_flux_kernels.empty())
     209       29313 :     return;
     210             : 
     211             :   // Print the location of the execution
     212           9 :   auto & console = _fe_problem.console();
     213           9 :   console << "[DBG] Linear flux kernels on block "
     214           9 :           << _fe_problem.mesh().getSubdomainName(_subdomain);
     215           9 :   if (_neighbor_subdomain != Moose::INVALID_BLOCK_ID)
     216           9 :     console << " and neighbor " << _fe_problem.mesh().getSubdomainName(_neighbor_subdomain)
     217           9 :             << std::endl;
     218             :   else
     219           0 :     console << " with no neighbor block" << std::endl;
     220             : 
     221             :   // Print the list of objects
     222           9 :   std::vector<MooseObject *> kernels_to_print;
     223          21 :   for (const auto & kernel : _fv_flux_kernels)
     224          12 :     kernels_to_print.push_back(dynamic_cast<MooseObject *>(kernel));
     225          36 :   console << ConsoleUtils::formatString(ConsoleUtils::mooseObjectVectorToString(kernels_to_print),
     226           9 :                                         "[DBG]")
     227           9 :           << std::endl;
     228           9 : }

Generated by: LCOV version 1.14