LCOV - code coverage report
Current view: top level - src/loops - ComputeResidualThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 65 65 100.0 %
Date: 2025-07-17 01:28:37 Functions: 12 12 100.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 "ComputeResidualThread.h"
      11             : #include "NonlinearSystemBase.h"
      12             : #include "KernelBase.h"
      13             : #include "DGKernelBase.h"
      14             : #include "IntegratedBCBase.h"
      15             : #include "FVElementalKernel.h"
      16             : #include "InterfaceKernelBase.h"
      17             : #include "HDGKernel.h"
      18             : #include "libmesh/threads.h"
      19             : 
      20     3040556 : ComputeResidualThread::ComputeResidualThread(FEProblemBase & fe_problem,
      21     3040556 :                                              const std::set<TagID> & tags)
      22     3040556 :   : NonlinearThread(fe_problem), _tags(tags)
      23             : {
      24     3040556 : }
      25             : 
      26             : // Splitting Constructor
      27      288180 : ComputeResidualThread::ComputeResidualThread(ComputeResidualThread & x, Threads::split split)
      28      288180 :   : NonlinearThread(x, split), _tags(x._tags)
      29             : {
      30      288180 : }
      31             : 
      32     3616884 : ComputeResidualThread::~ComputeResidualThread() {}
      33             : 
      34             : void
      35   673659098 : ComputeResidualThread::compute(ResidualObject & ro)
      36             : {
      37   673659098 :   ro.computeResidual();
      38   673659052 : }
      39             : 
      40             : void
      41       17732 : ComputeResidualThread::accumulateLower()
      42             : {
      43       17732 :   _fe_problem.addResidualLower(_tid);
      44       17732 : }
      45             : 
      46             : void
      47       43276 : ComputeResidualThread::accumulateNeighbor()
      48             : {
      49       43276 :   _fe_problem.addResidualNeighbor(_tid);
      50       43276 : }
      51             : 
      52             : void
      53     1975649 : ComputeResidualThread::accumulateNeighborLower()
      54             : {
      55     1975649 :   _fe_problem.addResidualNeighbor(_tid);
      56     1975649 :   _fe_problem.addResidualLower(_tid);
      57     1975649 : }
      58             : 
      59             : void
      60   294964944 : ComputeResidualThread::accumulate()
      61             : {
      62   294964944 :   _fe_problem.cacheResidual(_tid);
      63   294964944 :   _num_cached++;
      64             : 
      65   294964944 :   if (_num_cached % 20 == 0)
      66             :   {
      67    13623076 :     Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
      68    13623076 :     _fe_problem.addCachedResidual(_tid);
      69    13623076 :   }
      70   294964944 : }
      71             : 
      72             : void
      73      288179 : ComputeResidualThread::join(const ComputeResidualThread & /*y*/)
      74             : {
      75      288179 : }
      76             : 
      77             : void
      78     3878510 : ComputeResidualThread::determineObjectWarehouses()
      79             : {
      80             :   // If users pass a empty vector or a full size of vector,
      81             :   // we take all kernels
      82     3878510 :   if (!_tags.size() || _tags.size() == _fe_problem.numVectorTags(Moose::VECTOR_TAG_RESIDUAL))
      83             :   {
      84     3825431 :     _tag_kernels = &_kernels;
      85     3825431 :     _dg_warehouse = &_dg_kernels;
      86     3825431 :     _ibc_warehouse = &_integrated_bcs;
      87     3825431 :     _ik_warehouse = &_interface_kernels;
      88     3825431 :     _hdg_warehouse = &_hdg_kernels;
      89             :   }
      90             :   // If we have one tag only,
      91             :   // We call tag based storage
      92       53079 :   else if (_tags.size() == 1)
      93             :   {
      94       30864 :     _tag_kernels = &(_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      95       30864 :     _dg_warehouse = &(_dg_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      96       30864 :     _ibc_warehouse = &(_integrated_bcs.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      97       30864 :     _ik_warehouse = &(_interface_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      98       30864 :     _hdg_warehouse = &(_hdg_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      99             :   }
     100             :   // This one may be expensive
     101             :   else
     102             :   {
     103       22215 :     _tag_kernels = &(_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
     104       22215 :     _dg_warehouse = &(_dg_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
     105       22215 :     _ibc_warehouse = &(_integrated_bcs.getVectorTagsObjectWarehouse(_tags, _tid));
     106       22215 :     _ik_warehouse = &(_interface_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
     107       22215 :     _hdg_warehouse = &(_hdg_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
     108             :   }
     109             : 
     110     3878510 :   if (_fe_problem.haveFV())
     111             :   {
     112      189114 :     _fv_kernels.clear();
     113      189114 :     _fe_problem.theWarehouse()
     114      378228 :         .query()
     115      378228 :         .template condition<AttribSysNum>(_nl.number())
     116      189114 :         .template condition<AttribSystem>("FVElementalKernel")
     117      189114 :         .template condition<AttribSubdomains>(_subdomain)
     118      189114 :         .template condition<AttribThread>(_tid)
     119      189114 :         .template condition<AttribVectorTags>(_tags)
     120      189114 :         .queryInto(_fv_kernels);
     121             :   }
     122     3878510 : }
     123             : 
     124             : void
     125     2622936 : ComputeResidualThread::computeOnInternalFace()
     126             : {
     127             :   mooseAssert(_hdg_warehouse->hasActiveBlockObjects(_subdomain, _tid),
     128             :               "We should not be called if we have no active HDG kernels");
     129     6475296 :   for (const auto & hdg_kernel : _hdg_warehouse->getActiveBlockObjects(_subdomain, _tid))
     130             :   {
     131             :     mooseAssert(
     132             :         hdg_kernel->hasBlocks(_subdomain),
     133             :         "We queried the warehouse for active blocks on this subdomain, so this better be active");
     134             :     mooseAssert(
     135             :         _neighbor_subdomain != Moose::INVALID_BLOCK_ID,
     136             :         "We should have set a valid neighbor subdomain ID if we made it in side this method");
     137     3852360 :     if (hdg_kernel->hasBlocks(_neighbor_subdomain))
     138     3852344 :       hdg_kernel->computeResidualOnSide();
     139             :   }
     140     2622936 : }

Generated by: LCOV version 1.14