LCOV - code coverage report
Current view: top level - src/loops - ComputeResidualAndJacobianThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 53 65 81.5 %
Date: 2025-07-17 01:28:37 Functions: 10 12 83.3 %
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 "ComputeResidualAndJacobianThread.h"
      11             : #include "NonlinearSystem.h"
      12             : #include "Problem.h"
      13             : #include "FEProblem.h"
      14             : #include "KernelBase.h"
      15             : #include "IntegratedBCBase.h"
      16             : #include "DGKernelBase.h"
      17             : #include "InterfaceKernelBase.h"
      18             : #include "Material.h"
      19             : #include "TimeKernel.h"
      20             : #include "SwapBackSentinel.h"
      21             : #include "FVTimeKernel.h"
      22             : #include "HDGKernel.h"
      23             : 
      24             : #include "libmesh/threads.h"
      25             : 
      26        3345 : ComputeResidualAndJacobianThread::ComputeResidualAndJacobianThread(
      27             :     FEProblemBase & fe_problem,
      28             :     const std::set<TagID> & vector_tags,
      29        3345 :     const std::set<TagID> & matrix_tags)
      30        3345 :   : NonlinearThread(fe_problem), _vector_tags(vector_tags), _matrix_tags(matrix_tags)
      31             : {
      32        3345 : }
      33             : 
      34             : // Splitting Constructor
      35         339 : ComputeResidualAndJacobianThread::ComputeResidualAndJacobianThread(
      36         339 :     ComputeResidualAndJacobianThread & x, Threads::split split)
      37         339 :   : NonlinearThread(x, split), _vector_tags(x._vector_tags), _matrix_tags(x._matrix_tags)
      38             : {
      39         339 : }
      40             : 
      41        4023 : ComputeResidualAndJacobianThread::~ComputeResidualAndJacobianThread() {}
      42             : 
      43             : void
      44       84880 : ComputeResidualAndJacobianThread::compute(ResidualObject & ro)
      45             : {
      46       84880 :   ro.computeResidualAndJacobian();
      47       84880 : }
      48             : 
      49             : void
      50         240 : ComputeResidualAndJacobianThread::accumulateLower()
      51             : {
      52         240 :   _fe_problem.addResidualLower(_tid);
      53         240 :   _fe_problem.addJacobianLowerD(_tid);
      54         240 : }
      55             : 
      56             : void
      57           0 : ComputeResidualAndJacobianThread::accumulateNeighborLower()
      58             : {
      59           0 :   _fe_problem.addResidualNeighbor(_tid);
      60           0 :   _fe_problem.addResidualLower(_tid);
      61           0 :   _fe_problem.addJacobianNeighborLowerD(_tid);
      62           0 : }
      63             : 
      64             : void
      65          62 : ComputeResidualAndJacobianThread::accumulateNeighbor()
      66             : {
      67          62 :   _fe_problem.addResidualNeighbor(_tid);
      68          62 :   _fe_problem.addJacobianNeighbor(_tid);
      69          62 : }
      70             : 
      71             : void
      72       97837 : ComputeResidualAndJacobianThread::accumulate()
      73             : {
      74       97837 :   _fe_problem.cacheResidual(_tid);
      75       97837 :   _fe_problem.cacheJacobian(_tid);
      76       97837 :   _num_cached++;
      77             : 
      78       97837 :   if (_num_cached % 20 == 0)
      79             :   {
      80        3868 :     Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
      81        3868 :     _fe_problem.addCachedResidual(_tid);
      82        3868 :     _fe_problem.addCachedJacobian(_tid);
      83        3868 :   }
      84       97837 : }
      85             : 
      86             : void
      87         339 : ComputeResidualAndJacobianThread::join(const ComputeResidualAndJacobianThread & /*y*/)
      88             : {
      89         339 : }
      90             : 
      91             : void
      92        5767 : ComputeResidualAndJacobianThread::determineObjectWarehouses()
      93             : {
      94             :   // We need to filter out vector tags that don't belong to the current nonlinear system
      95        5767 :   const auto & residual_vector_tags = _fe_problem.getVectorTags(Moose::VECTOR_TAG_RESIDUAL);
      96             : 
      97             :   // We would only like to consider the tags that belong to the current system
      98        5767 :   std::set<TagID> filtered_residual_tags;
      99        5767 :   _fe_problem.selectVectorTagsFromSystem(_nl, residual_vector_tags, filtered_residual_tags);
     100             : 
     101        5767 :   if (_vector_tags.size() && _vector_tags.size() != filtered_residual_tags.size())
     102           0 :     mooseError("Can only currently compute the residual and Jacobian together if we are computing "
     103             :                "the full suite of residual tags");
     104             : 
     105        5767 :   if (_matrix_tags.size() && _matrix_tags.size() != _fe_problem.numMatrixTags())
     106           0 :     mooseError("Can only currently compute the residual and Jacobian together if we are computing "
     107             :                "the full suite of Jacobian tags");
     108             : 
     109        5767 :   _tag_kernels = &_kernels;
     110        5767 :   _dg_warehouse = &_dg_kernels;
     111        5767 :   _ibc_warehouse = &_integrated_bcs;
     112        5767 :   _ik_warehouse = &_interface_kernels;
     113        5767 :   _hdg_warehouse = &_hdg_kernels;
     114             : 
     115        5767 :   if (_fe_problem.haveFV())
     116             :   {
     117        1535 :     _fv_kernels.clear();
     118        1535 :     _fe_problem.theWarehouse()
     119        3070 :         .query()
     120        3070 :         .template condition<AttribSysNum>(_nl.number())
     121        1535 :         .template condition<AttribSystem>("FVElementalKernel")
     122        1535 :         .template condition<AttribSubdomains>(_subdomain)
     123        1535 :         .template condition<AttribThread>(_tid)
     124        1535 :         .queryInto(_fv_kernels);
     125             :   }
     126        5767 : }
     127             : 
     128             : void
     129           0 : ComputeResidualAndJacobianThread::computeOnInternalFace()
     130             : {
     131             :   mooseAssert(_hdg_warehouse->hasActiveBlockObjects(_subdomain, _tid),
     132             :               "We should not be called if we have no active HDG kernels");
     133           0 :   for (const auto & hdg_kernel : _hdg_warehouse->getActiveBlockObjects(_subdomain, _tid))
     134           0 :     if (hdg_kernel->hasBlocks(_subdomain))
     135           0 :       hdg_kernel->computeResidualAndJacobianOnSide();
     136           0 : }

Generated by: LCOV version 1.14