LCOV - code coverage report
Current view: top level - src/loops - ComputeLinearFVElementalThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33416 (b10b36) with base 9fbd27 Lines: 99 111 89.2 %
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 "ComputeLinearFVElementalThread.h"
      11             : #include "LinearSystem.h"
      12             : #include "LinearFVKernel.h"
      13             : #include "LinearFVElementalKernel.h"
      14             : #include "FEProblemBase.h"
      15             : 
      16       25792 : ComputeLinearFVElementalThread::ComputeLinearFVElementalThread(FEProblemBase & fe_problem,
      17             :                                                                const unsigned int system_num,
      18             :                                                                const std::set<TagID> & vector_tags,
      19       25792 :                                                                const std::set<TagID> & matrix_tags)
      20       25792 :   : _fe_problem(fe_problem),
      21       25792 :     _system_number(system_num),
      22       25792 :     _vector_tags(vector_tags),
      23       25792 :     _matrix_tags(matrix_tags),
      24       25792 :     _subdomain(Moose::INVALID_BLOCK_ID),
      25       25792 :     _old_subdomain(Moose::INVALID_BLOCK_ID),
      26       25792 :     _system_contrib_objects_ready(false)
      27             : {
      28       25792 : }
      29             : 
      30             : // Splitting Constructor
      31           0 : ComputeLinearFVElementalThread::ComputeLinearFVElementalThread(ComputeLinearFVElementalThread & x,
      32           0 :                                                                Threads::split /*split*/)
      33           0 :   : _fe_problem(x._fe_problem),
      34           0 :     _system_number(x._system_number),
      35           0 :     _vector_tags(x._vector_tags),
      36           0 :     _matrix_tags(x._matrix_tags),
      37           0 :     _subdomain(x._subdomain),
      38           0 :     _old_subdomain(x._old_subdomain),
      39           0 :     _system_contrib_objects_ready(x._system_contrib_objects_ready)
      40             : {
      41           0 : }
      42             : 
      43             : void
      44       25792 : ComputeLinearFVElementalThread::operator()(const ElemInfoRange & range)
      45             : {
      46       25792 :   ParallelUniqueId puid;
      47       25792 :   _tid = puid.id;
      48             : 
      49       25792 :   _old_subdomain = Moose::INVALID_BLOCK_ID;
      50             : 
      51       25792 :   setupSystemContributionObjects();
      52       25792 :   printGeneralExecutionInformation();
      53             : 
      54             :   // Iterate over all the elements in the range
      55    33095322 :   for (const auto & elem_info : range)
      56             :   {
      57    33069530 :     _subdomain = elem_info->subdomain_id();
      58    33069530 :     if (_subdomain != _old_subdomain)
      59             :     {
      60       25956 :       fetchBlockSystemContributionObjects();
      61       25956 :       printBlockExecutionInformation();
      62             :     }
      63             : 
      64    33069530 :     const Real elem_volume = elem_info->volume() * elem_info->coordFactor();
      65             : 
      66             :     // Time to add the contributions from the kernels
      67    34097268 :     for (auto kernel : _fv_kernels)
      68             :     {
      69     1027738 :       kernel->setCurrentElemInfo(elem_info);
      70     1027738 :       kernel->setCurrentElemVolume(elem_volume);
      71     1027738 :       kernel->addMatrixContribution();
      72     1027738 :       kernel->addRightHandSideContribution();
      73             :     }
      74             :   }
      75       25792 : }
      76             : 
      77             : void
      78           0 : ComputeLinearFVElementalThread::join(const ComputeLinearFVElementalThread & /*y*/)
      79             : {
      80           0 : }
      81             : 
      82             : void
      83       25792 : ComputeLinearFVElementalThread::setupSystemContributionObjects()
      84             : {
      85             :   // The reason why we need to grab vectors and matrices separately is that
      86             :   // we want to grab a union instead of an intersection.
      87       25792 :   std::vector<LinearFVElementalKernel *> kernels_after_vectors;
      88       25792 :   _fe_problem.theWarehouse()
      89       25792 :       .query()
      90       25792 :       .template condition<AttribSysNum>(_system_number)
      91       25792 :       .template condition<AttribSystem>("LinearFVElementalKernel")
      92       51584 :       .template condition<AttribKokkos>(false)
      93       25792 :       .template condition<AttribThread>(_tid)
      94       25792 :       .template condition<AttribVectorTags>(_vector_tags)
      95       25792 :       .queryInto(kernels_after_vectors);
      96             : 
      97       25792 :   std::vector<LinearFVElementalKernel *> kernels_after_matrices;
      98       25792 :   _fe_problem.theWarehouse()
      99       25792 :       .query()
     100       25792 :       .template condition<AttribSysNum>(_system_number)
     101       25792 :       .template condition<AttribSystem>("LinearFVElementalKernel")
     102       51584 :       .template condition<AttribKokkos>(false)
     103       25792 :       .template condition<AttribThread>(_tid)
     104       25792 :       .template condition<AttribMatrixTags>(_matrix_tags)
     105       25792 :       .queryInto(kernels_after_matrices);
     106             : 
     107             :   // We fetch the union of the available objects
     108       25792 :   std::vector<LinearFVElementalKernel *> kernels;
     109       25792 :   MooseUtils::getUnion(kernels_after_vectors, kernels_after_matrices, kernels);
     110             : 
     111             :   // As a last step, we make sure the kernels know which vectors/matrices they need to contribute to
     112       35742 :   for (auto & kernel : kernels)
     113        9950 :     kernel->linkTaggedVectorsAndMatrices(_vector_tags, _matrix_tags);
     114             : 
     115       25792 :   _system_contrib_objects_ready = true;
     116       25792 : }
     117             : 
     118             : void
     119       25956 : ComputeLinearFVElementalThread::fetchBlockSystemContributionObjects()
     120             : {
     121             :   mooseAssert(_system_contrib_objects_ready,
     122             :               "The system contribution objects need to be set up before we fetch the "
     123             :               "block-restricted objects!");
     124             : 
     125             :   // Here we just filter based on subdomain ID on top of everything else
     126       25956 :   std::vector<LinearFVElementalKernel *> kernels_after_vector;
     127       25956 :   _fe_problem.theWarehouse()
     128       25956 :       .query()
     129       25956 :       .template condition<AttribSysNum>(_system_number)
     130       25956 :       .template condition<AttribSystem>("LinearFVElementalKernel")
     131       51912 :       .template condition<AttribKokkos>(false)
     132       25956 :       .template condition<AttribThread>(_tid)
     133       25956 :       .template condition<AttribVectorTags>(_vector_tags)
     134       25956 :       .template condition<AttribSubdomains>(_subdomain)
     135       25956 :       .queryInto(kernels_after_vector);
     136             : 
     137       25956 :   std::vector<LinearFVElementalKernel *> kernels_after_matrix;
     138       25956 :   _fe_problem.theWarehouse()
     139       25956 :       .query()
     140       25956 :       .template condition<AttribSysNum>(_system_number)
     141       25956 :       .template condition<AttribSystem>("LinearFVElementalKernel")
     142       51912 :       .template condition<AttribKokkos>(false)
     143       25956 :       .template condition<AttribThread>(_tid)
     144       25956 :       .template condition<AttribMatrixTags>(_matrix_tags)
     145       25956 :       .template condition<AttribSubdomains>(_subdomain)
     146       25956 :       .queryInto(kernels_after_matrix);
     147             : 
     148             :   // We populate the list of kernels with the union of the two vectors
     149       25956 :   MooseUtils::getUnion(kernels_after_vector, kernels_after_matrix, _fv_kernels);
     150             : 
     151       25956 :   _old_subdomain = _subdomain;
     152       25956 : }
     153             : 
     154             : void
     155       25792 : ComputeLinearFVElementalThread::printGeneralExecutionInformation() const
     156             : {
     157       25792 :   if (!_fe_problem.shouldPrintExecution(_tid))
     158       25786 :     return;
     159           6 :   auto & console = _fe_problem.console();
     160           6 :   auto execute_on = _fe_problem.getCurrentExecuteOnFlag();
     161           6 :   console << "[DBG] Beginning linear finite volume elemental objects loop on " << execute_on
     162           6 :           << std::endl;
     163             : 
     164           6 :   mooseDoOnce(console << "[DBG] Loop on elements (ElemInfo), objects ordered on each face: "
     165             :                       << std::endl;
     166             :               console << "[DBG] - linear finite volume kernels" << std::endl;);
     167           6 : }
     168             : 
     169             : void
     170       25956 : ComputeLinearFVElementalThread::printBlockExecutionInformation() const
     171             : {
     172       25956 :   if (!_fe_problem.shouldPrintExecution(_tid) || _fv_kernels.empty())
     173       25944 :     return;
     174             : 
     175          12 :   auto & console = _fe_problem.console();
     176          12 :   console << "[DBG] Linear FV elemental kernels on block "
     177          12 :           << _fe_problem.mesh().getSubdomainName(_subdomain);
     178             : 
     179             :   // Print the list of objects
     180          12 :   std::vector<MooseObject *> kernels_to_print;
     181          30 :   for (const auto & kernel : _fv_kernels)
     182          18 :     kernels_to_print.push_back(dynamic_cast<MooseObject *>(kernel));
     183             : 
     184          48 :   console << ConsoleUtils::formatString(ConsoleUtils::mooseObjectVectorToString(kernels_to_print),
     185          12 :                                         "[DBG]")
     186          12 :           << std::endl;
     187          12 : }

Generated by: LCOV version 1.14