LCOV - code coverage report
Current view: top level - src/loops - ComputeLinearFVFaceThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33380 (547b29) with base 8581c3 Lines: 127 139 91.4 %
Date: 2026-07-20 19:36:28 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       25500 : 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       25500 :                                                      const std::set<TagID> & matrix_tags)
      21       25500 :   : _fe_problem(fe_problem),
      22       25500 :     _system_number(system_num),
      23       25500 :     _mode(mode),
      24       25500 :     _vector_tags(vector_tags),
      25       25500 :     _matrix_tags(matrix_tags),
      26       25500 :     _system_contrib_objects_ready(false)
      27             : {
      28       25500 : }
      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       25500 : ComputeLinearFVFaceThread::operator()(const FaceInfoRange & range)
      44             : {
      45       25500 :   ParallelUniqueId puid;
      46       25500 :   _tid = puid.id;
      47             : 
      48       25500 :   _old_subdomain = Moose::INVALID_BLOCK_ID;
      49       25500 :   _old_neighbor_subdomain = Moose::INVALID_BLOCK_ID;
      50             : 
      51       25500 :   setupSystemContributionObjects();
      52       25500 :   printGeneralExecutionInformation();
      53             : 
      54             :   // Iterate over all the elements in the range
      55    57679989 :   for (const auto & face_info : range)
      56             :   {
      57    57654489 :     _subdomain = face_info->elem().subdomain_id();
      58    57654489 :     _neighbor_subdomain =
      59    57654489 :         face_info->neighborPtr() ? face_info->neighbor().subdomain_id() : _subdomain;
      60    57654489 :     if (_subdomain != _old_subdomain || _neighbor_subdomain != _old_neighbor_subdomain)
      61             :     {
      62       28474 :       fetchBlockSystemContributionObjects();
      63       28474 :       printBlockExecutionInformation();
      64             :     }
      65             : 
      66    57654489 :     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   115324019 :     for (auto & kernel : _fv_flux_kernels)
      71             :     {
      72    57669530 :       kernel->setupFaceData(face_info);
      73    57669530 :       kernel->setCurrentFaceArea(face_area);
      74    57669530 :       kernel->addMatrixContribution();
      75    57669530 :       kernel->addRightHandSideContribution();
      76             :     }
      77             :   }
      78       25500 : }
      79             : 
      80             : void
      81           0 : ComputeLinearFVFaceThread::join(const ComputeLinearFVFaceThread & /*y*/)
      82             : {
      83           0 : }
      84             : 
      85             : void
      86       25500 : 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       25500 :   std::vector<LinearFVFluxKernel *> kernels_after_vectors;
      91       25500 :   _fe_problem.theWarehouse()
      92       51000 :       .query()
      93       25500 :       .template condition<AttribSysNum>(_system_number)
      94       25500 :       .template condition<AttribSystem>("LinearFVFluxKernel")
      95       25500 :       .template condition<AttribThread>(_tid)
      96       25500 :       .template condition<AttribVectorTags>(_vector_tags)
      97       25500 :       .queryInto(kernels_after_vectors);
      98             : 
      99       25500 :   std::vector<LinearFVFluxKernel *> kernels_after_matrices;
     100       25500 :   _fe_problem.theWarehouse()
     101       51000 :       .query()
     102       25500 :       .template condition<AttribSysNum>(_system_number)
     103       25500 :       .template condition<AttribSystem>("LinearFVFluxKernel")
     104       25500 :       .template condition<AttribThread>(_tid)
     105       25500 :       .template condition<AttribMatrixTags>(_matrix_tags)
     106       25500 :       .queryInto(kernels_after_matrices);
     107             : 
     108             :   // We fetch the union of the available objects
     109       25500 :   std::vector<LinearFVFluxKernel *> kernels;
     110       25500 :   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       51123 :   for (auto & kernel : kernels)
     114       25623 :     kernel->linkTaggedVectorsAndMatrices(_vector_tags, _matrix_tags);
     115             : 
     116       25500 :   _system_contrib_objects_ready = true;
     117       25500 : }
     118             : 
     119             : void
     120       28474 : 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       28474 :   _fv_flux_kernels.clear();
     127             : 
     128       28474 :   if (_subdomain != _old_subdomain)
     129             :   {
     130             :     // We just filter based on subdomain ID on top of everything else
     131       25604 :     std::vector<LinearFVFluxKernel *> kernels_after_vector;
     132       25604 :     _fe_problem.theWarehouse()
     133       51208 :         .query()
     134       25604 :         .template condition<AttribSysNum>(_system_number)
     135       25604 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     136       25604 :         .template condition<AttribThread>(_tid)
     137       25604 :         .template condition<AttribVectorTags>(_vector_tags)
     138       25604 :         .template condition<AttribSubdomains>(_subdomain)
     139       25604 :         .queryInto(kernels_after_vector);
     140       25604 :     std::vector<LinearFVFluxKernel *> kernels_after_matrix;
     141       25604 :     _fe_problem.theWarehouse()
     142       51208 :         .query()
     143       25604 :         .template condition<AttribSysNum>(_system_number)
     144       25604 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     145       25604 :         .template condition<AttribThread>(_tid)
     146       25604 :         .template condition<AttribMatrixTags>(_matrix_tags)
     147       25604 :         .template condition<AttribSubdomains>(_subdomain)
     148       25604 :         .queryInto(kernels_after_matrix);
     149             : 
     150             :     // We populate the list of kernels with the union of the two vectors
     151       25604 :     MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_flux_kernels_elem);
     152       25604 :     _old_subdomain = _subdomain;
     153       25604 :   }
     154       28474 :   _fv_flux_kernels.insert(_fv_flux_kernels_elem.begin(), _fv_flux_kernels_elem.end());
     155             : 
     156       28474 :   if (_neighbor_subdomain != _old_neighbor_subdomain)
     157             :   {
     158             :     // Here we just filter based on subdomain ID on top of everything else
     159       28430 :     std::vector<LinearFVFluxKernel *> kernels_after_vector;
     160       28430 :     _fe_problem.theWarehouse()
     161       56860 :         .query()
     162       28430 :         .template condition<AttribSysNum>(_system_number)
     163       28430 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     164       28430 :         .template condition<AttribThread>(_tid)
     165       28430 :         .template condition<AttribVectorTags>(_vector_tags)
     166       28430 :         .template condition<AttribSubdomains>(_neighbor_subdomain)
     167       28430 :         .queryInto(kernels_after_vector);
     168       28430 :     std::vector<LinearFVFluxKernel *> kernels_after_matrix;
     169       28430 :     _fe_problem.theWarehouse()
     170       56860 :         .query()
     171       28430 :         .template condition<AttribSysNum>(_system_number)
     172       28430 :         .template condition<AttribSystem>("LinearFVFluxKernel")
     173       28430 :         .template condition<AttribThread>(_tid)
     174       28430 :         .template condition<AttribMatrixTags>(_matrix_tags)
     175       28430 :         .template condition<AttribSubdomains>(_neighbor_subdomain)
     176       28430 :         .queryInto(kernels_after_matrix);
     177             : 
     178             :     // We populate the list of kernels with the union of the two vectors
     179       28430 :     MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_flux_kernels_neighbor);
     180       28430 :     _old_neighbor_subdomain = _neighbor_subdomain;
     181       28430 :   }
     182       28474 :   _fv_flux_kernels.insert(_fv_flux_kernels_neighbor.begin(), _fv_flux_kernels_neighbor.end());
     183       28474 : }
     184             : 
     185             : void
     186       25500 : ComputeLinearFVFaceThread::printGeneralExecutionInformation() const
     187             : {
     188       25500 :   if (!_fe_problem.shouldPrintExecution(_tid))
     189       25494 :     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       28474 : ComputeLinearFVFaceThread::printBlockExecutionInformation() const
     201             : {
     202       28474 :   if (!_fe_problem.shouldPrintExecution(_tid) || _fv_flux_kernels.empty())
     203       28465 :     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