LCOV - code coverage report
Current view: top level - src/loops - ComputeResidualThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 65 65 100.0 %
Date: 2025-08-08 20:01:16 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     3278015 : ComputeResidualThread::ComputeResidualThread(FEProblemBase & fe_problem,
      21     3278015 :                                              const std::set<TagID> & tags)
      22     3278015 :   : NonlinearThread(fe_problem), _tags(tags)
      23             : {
      24     3278015 : }
      25             : 
      26             : // Splitting Constructor
      27      287724 : ComputeResidualThread::ComputeResidualThread(ComputeResidualThread & x, Threads::split split)
      28      287724 :   : NonlinearThread(x, split), _tags(x._tags)
      29             : {
      30      287724 : }
      31             : 
      32     3853434 : ComputeResidualThread::~ComputeResidualThread() {}
      33             : 
      34             : void
      35   747113833 : ComputeResidualThread::compute(ResidualObject & ro)
      36             : {
      37   747113833 :   ro.computeResidual();
      38   747113783 : }
      39             : 
      40             : void
      41       20264 : ComputeResidualThread::accumulateLower()
      42             : {
      43       20264 :   _fe_problem.addResidualLower(_tid);
      44       20264 : }
      45             : 
      46             : void
      47       44637 : ComputeResidualThread::accumulateNeighbor()
      48             : {
      49       44637 :   _fe_problem.addResidualNeighbor(_tid);
      50       44637 : }
      51             : 
      52             : void
      53     2054953 : ComputeResidualThread::accumulateNeighborLower()
      54             : {
      55     2054953 :   _fe_problem.addResidualNeighbor(_tid);
      56     2054953 :   _fe_problem.addResidualLower(_tid);
      57     2054953 : }
      58             : 
      59             : void
      60   327221215 : ComputeResidualThread::accumulate()
      61             : {
      62   327221215 :   _fe_problem.cacheResidual(_tid);
      63   327221215 :   _num_cached++;
      64             : 
      65   327221215 :   if (_num_cached % 20 == 0)
      66             :   {
      67    15201949 :     Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
      68    15201949 :     _fe_problem.addCachedResidual(_tid);
      69    15201949 :   }
      70   327221215 : }
      71             : 
      72             : void
      73      287724 : ComputeResidualThread::join(const ComputeResidualThread & /*y*/)
      74             : {
      75      287724 : }
      76             : 
      77             : void
      78     4154228 : ComputeResidualThread::determineObjectWarehouses()
      79             : {
      80             :   // If users pass a empty vector or a full size of vector,
      81             :   // we take all kernels
      82     4154228 :   if (!_tags.size() || _tags.size() == _fe_problem.numVectorTags(Moose::VECTOR_TAG_RESIDUAL))
      83             :   {
      84     4096552 :     _tag_kernels = &_kernels;
      85     4096552 :     _dg_warehouse = &_dg_kernels;
      86     4096552 :     _ibc_warehouse = &_integrated_bcs;
      87     4096552 :     _ik_warehouse = &_interface_kernels;
      88     4096552 :     _hdg_warehouse = &_hdg_kernels;
      89             :   }
      90             :   // If we have one tag only,
      91             :   // We call tag based storage
      92       57676 :   else if (_tags.size() == 1)
      93             :   {
      94       34190 :     _tag_kernels = &(_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      95       34190 :     _dg_warehouse = &(_dg_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      96       34190 :     _ibc_warehouse = &(_integrated_bcs.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      97       34190 :     _ik_warehouse = &(_interface_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      98       34190 :     _hdg_warehouse = &(_hdg_kernels.getVectorTagObjectWarehouse(*(_tags.begin()), _tid));
      99             :   }
     100             :   // This one may be expensive
     101             :   else
     102             :   {
     103       23486 :     _tag_kernels = &(_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
     104       23486 :     _dg_warehouse = &(_dg_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
     105       23486 :     _ibc_warehouse = &(_integrated_bcs.getVectorTagsObjectWarehouse(_tags, _tid));
     106       23486 :     _ik_warehouse = &(_interface_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
     107       23486 :     _hdg_warehouse = &(_hdg_kernels.getVectorTagsObjectWarehouse(_tags, _tid));
     108             :   }
     109             : 
     110     4154228 :   if (_fe_problem.haveFV())
     111             :   {
     112      197479 :     _fv_kernels.clear();
     113      197479 :     _fe_problem.theWarehouse()
     114      394958 :         .query()
     115      394958 :         .template condition<AttribSysNum>(_nl.number())
     116      197479 :         .template condition<AttribSystem>("FVElementalKernel")
     117      197479 :         .template condition<AttribSubdomains>(_subdomain)
     118      197479 :         .template condition<AttribThread>(_tid)
     119      197479 :         .template condition<AttribVectorTags>(_tags)
     120      197479 :         .queryInto(_fv_kernels);
     121             :   }
     122     4154228 : }
     123             : 
     124             : void
     125     2641782 : ComputeResidualThread::computeOnInternalFace()
     126             : {
     127             :   mooseAssert(_hdg_warehouse->hasActiveBlockObjects(_subdomain, _tid),
     128             :               "We should not be called if we have no active HDG kernels");
     129     6512988 :   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     3871206 :     if (hdg_kernel->hasBlocks(_neighbor_subdomain))
     138     3871188 :       hdg_kernel->computeResidualOnSide();
     139             :   }
     140     2641782 : }

Generated by: LCOV version 1.14