LCOV - code coverage report
Current view: top level - src/loops - ComputeLinearFVFaceThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 127 139 91.4 %
Date: 2026-05-29 20:35:17 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       26160 : 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       26160 :                                                      const std::set<TagID> & matrix_tags)
      21       26160 :   : _fe_problem(fe_problem),
      22       26160 :     _system_number(system_num),
      23       26160 :     _mode(mode),
      24       26160 :     _vector_tags(vector_tags),
      25       26160 :     _matrix_tags(matrix_tags),
      26       26160 :     _system_contrib_objects_ready(false)
      27             : {
      28       26160 : }
      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       26160 : ComputeLinearFVFaceThread::operator()(const FaceInfoRange & range)
      44             : {
      45       26160 :   ParallelUniqueId puid;
      46       26160 :   _tid = puid.id;
      47             : 
      48       26160 :   _old_subdomain = Moose::INVALID_BLOCK_ID;
      49       26160 :   _old_neighbor_subdomain = Moose::INVALID_BLOCK_ID;
      50             : 
      51       26160 :   setupSystemContributionObjects();
      52       26160 :   printGeneralExecutionInformation();
      53             : 
      54             :   // Iterate over all the elements in the range
      55    58422672 :   for (const auto & face_info : range)
      56             :   {
      57    58396512 :     _subdomain = face_info->elem().subdomain_id();
      58    58396512 :     _neighbor_subdomain =
      59    58396512 :         face_info->neighborPtr() ? face_info->neighbor().subdomain_id() : _subdomain;
      60    58396512 :     if (_subdomain != _old_subdomain || _neighbor_subdomain != _old_neighbor_subdomain)
      61             :     {
      62       32085 :       fetchBlockSystemContributionObjects();
      63       32085 :       printBlockExecutionInformation();
      64             :     }
      65             : 
      66    58396512 :     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   116822661 :     for (auto & kernel : _fv_flux_kernels)
      71             :     {
      72    58426149 :       kernel->setupFaceData(face_info);
      73    58426149 :       kernel->setCurrentFaceArea(face_area);
      74    58426149 :       kernel->addMatrixContribution();
      75    58426149 :       kernel->addRightHandSideContribution();
      76             :     }
      77             :   }
      78       26160 : }
      79             : 
      80             : void
      81           0 : ComputeLinearFVFaceThread::join(const ComputeLinearFVFaceThread & /*y*/)
      82             : {
      83           0 : }
      84             : 
      85             : void
      86       26160 : 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       26160 :   std::vector<LinearFVFluxKernel *> kernels_after_vectors;
      91       26160 :   _fe_problem.theWarehouse()
      92       52320 :       .query()
      93       26160 :       .template condition<AttribSysNum>(_system_number)
      94       26160 :       .template condition<AttribSystem>("LinearFVFluxKernel")
      95       26160 :       .template condition<AttribThread>(_tid)
      96       26160 :       .template condition<AttribVectorTags>(_vector_tags)
      97       26160 :       .queryInto(kernels_after_vectors);
      98             : 
      99       26160 :   std::vector<LinearFVFluxKernel *> kernels_after_matrices;
     100       26160 :   _fe_problem.theWarehouse()
     101       52320 :       .query()
     102       26160 :       .template condition<AttribSysNum>(_system_number)
     103       26160 :       .template condition<AttribSystem>("LinearFVFluxKernel")
     104       26160 :       .template condition<AttribThread>(_tid)
     105       26160 :       .template condition<AttribMatrixTags>(_matrix_tags)
     106       26160 :       .queryInto(kernels_after_matrices);
     107             : 
     108             :   // We fetch the union of the available objects
     109       26160 :   std::vector<LinearFVFluxKernel *> kernels;
     110       26160 :   MooseUtils::getUnion(kernels_after_vectors, kernels_after_matrices, kernels);
     111             : 
     112             :   // As a last step, we make sure the kernels know which vectors/matrices they need to contribute to
     113       52566 :   for (auto & kernel : kernels)
     114       26406 :     kernel->linkTaggedVectorsAndMatrices(_vector_tags, _matrix_tags);
     115             : 
     116       26160 :   _system_contrib_objects_ready = true;
     117       26160 : }
     118             : 
     119             : void
     120       32085 : ComputeLinearFVFaceThread::fetchBlockSystemContributionObjects()
     121             : {
     122             :   mooseAssert(_system_contrib_objects_ready,
     123             :               "The system contribution objects need to be set up before we fetch the "
     124             :               "block-restricted objects!");
     125             : 
     126       32085 :   _fv_flux_kernels.clear();
     127             : 
     128       32085 :   if (_subdomain != _old_subdomain)
     129             :   {
     130             :     // We just filter based on subdomain ID on top of everything else
     131       26358 :     std::vector<LinearFVFluxKernel *> kernels_after_vector;
     132       26358 :     _fe_problem.theWarehouse()
     133       52716 :         .query()
     134       26358 :         .template condition<AttribSysNum>(_system_number)
     135       26358 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     136       26358 :         .template condition<AttribThread>(_tid)
     137       26358 :         .template condition<AttribVectorTags>(_vector_tags)
     138       26358 :         .template condition<AttribSubdomains>(_subdomain)
     139       26358 :         .queryInto(kernels_after_vector);
     140       26358 :     std::vector<LinearFVFluxKernel *> kernels_after_matrix;
     141       26358 :     _fe_problem.theWarehouse()
     142       52716 :         .query()
     143       26358 :         .template condition<AttribSysNum>(_system_number)
     144       26358 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     145       26358 :         .template condition<AttribThread>(_tid)
     146       26358 :         .template condition<AttribMatrixTags>(_matrix_tags)
     147       26358 :         .template condition<AttribSubdomains>(_subdomain)
     148       26358 :         .queryInto(kernels_after_matrix);
     149             : 
     150             :     // We populate the list of kernels with the union of the two vectors
     151       26358 :     MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_flux_kernels_elem);
     152       26358 :     _old_subdomain = _subdomain;
     153       26358 :   }
     154       32085 :   _fv_flux_kernels.insert(_fv_flux_kernels_elem.begin(), _fv_flux_kernels_elem.end());
     155             : 
     156       32085 :   if (_neighbor_subdomain != _old_neighbor_subdomain)
     157             :   {
     158             :     // Here we just filter based on subdomain ID on top of everything else
     159       32007 :     std::vector<LinearFVFluxKernel *> kernels_after_vector;
     160       32007 :     _fe_problem.theWarehouse()
     161       64014 :         .query()
     162       32007 :         .template condition<AttribSysNum>(_system_number)
     163       32007 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     164       32007 :         .template condition<AttribThread>(_tid)
     165       32007 :         .template condition<AttribVectorTags>(_vector_tags)
     166       32007 :         .template condition<AttribSubdomains>(_neighbor_subdomain)
     167       32007 :         .queryInto(kernels_after_vector);
     168       32007 :     std::vector<LinearFVFluxKernel *> kernels_after_matrix;
     169       32007 :     _fe_problem.theWarehouse()
     170       64014 :         .query()
     171       32007 :         .template condition<AttribSysNum>(_system_number)
     172       32007 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     173       32007 :         .template condition<AttribThread>(_tid)
     174       32007 :         .template condition<AttribMatrixTags>(_matrix_tags)
     175       32007 :         .template condition<AttribSubdomains>(_neighbor_subdomain)
     176       32007 :         .queryInto(kernels_after_matrix);
     177             : 
     178             :     // We populate the list of kernels with the union of the two vectors
     179       32007 :     MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_flux_kernels_neighbor);
     180       32007 :     _old_neighbor_subdomain = _neighbor_subdomain;
     181       32007 :   }
     182       32085 :   _fv_flux_kernels.insert(_fv_flux_kernels_neighbor.begin(), _fv_flux_kernels_neighbor.end());
     183       32085 : }
     184             : 
     185             : void
     186       26160 : ComputeLinearFVFaceThread::printGeneralExecutionInformation() const
     187             : {
     188       26160 :   if (!_fe_problem.shouldPrintExecution(_tid))
     189       26154 :     return;
     190           6 :   auto & console = _fe_problem.console();
     191           6 :   auto execute_on = _fe_problem.getCurrentExecuteOnFlag();
     192           6 :   console << "[DBG] Beginning linear finite volume flux objects loop on " << execute_on
     193           6 :           << std::endl;
     194           6 :   mooseDoOnce(console << "[DBG] Loop on faces (FaceInfo), objects ordered on each face: "
     195             :                       << std::endl;
     196             :               console << "[DBG] - linear finite volume flux kernels" << std::endl);
     197           6 : }
     198             : 
     199             : void
     200       32085 : ComputeLinearFVFaceThread::printBlockExecutionInformation() const
     201             : {
     202       32085 :   if (!_fe_problem.shouldPrintExecution(_tid) || _fv_flux_kernels.empty())
     203       32076 :     return;
     204             : 
     205             :   // Print the location of the execution
     206           9 :   auto & console = _fe_problem.console();
     207           9 :   console << "[DBG] Linear flux kernels on block "
     208           9 :           << _fe_problem.mesh().getSubdomainName(_subdomain);
     209           9 :   if (_neighbor_subdomain != Moose::INVALID_BLOCK_ID)
     210           9 :     console << " and neighbor " << _fe_problem.mesh().getSubdomainName(_neighbor_subdomain)
     211           9 :             << std::endl;
     212             :   else
     213           0 :     console << " with no neighbor block" << std::endl;
     214             : 
     215             :   // Print the list of objects
     216           9 :   std::vector<MooseObject *> kernels_to_print;
     217          21 :   for (const auto & kernel : _fv_flux_kernels)
     218          12 :     kernels_to_print.push_back(dynamic_cast<MooseObject *>(kernel));
     219          36 :   console << ConsoleUtils::formatString(ConsoleUtils::mooseObjectVectorToString(kernels_to_print),
     220           9 :                                         "[DBG]")
     221           9 :           << std::endl;
     222           9 : }

Generated by: LCOV version 1.14