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

Generated by: LCOV version 1.14