LCOV - code coverage report
Current view: top level - src/loops - ComputeJacobianThread.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 71 77 92.2 %
Date: 2025-07-17 01:28:37 Functions: 14 16 87.5 %
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 "ComputeJacobianThread.h"
      11             : 
      12             : #include "DGKernelBase.h"
      13             : #include "FEProblem.h"
      14             : #include "IntegratedBCBase.h"
      15             : #include "InterfaceKernelBase.h"
      16             : #include "HDGKernel.h"
      17             : #include "MooseVariableFE.h"
      18             : #include "NonlinearSystem.h"
      19             : #include "SwapBackSentinel.h"
      20             : #include "TimeDerivative.h"
      21             : #include "FVElementalKernel.h"
      22             : #include "MaterialBase.h"
      23             : #include "ConsoleUtils.h"
      24             : #include "Assembly.h"
      25             : 
      26             : #include "libmesh/threads.h"
      27             : 
      28      477534 : ComputeJacobianThread::ComputeJacobianThread(FEProblemBase & fe_problem,
      29      477534 :                                              const std::set<TagID> & tags)
      30      477534 :   : NonlinearThread(fe_problem), _tags(tags)
      31             : {
      32      477534 : }
      33             : 
      34             : // Splitting Constructor
      35       46377 : ComputeJacobianThread::ComputeJacobianThread(ComputeJacobianThread & x, Threads::split split)
      36       46377 :   : NonlinearThread(x, split), _tags(x._tags)
      37             : {
      38       46377 : }
      39             : 
      40      563921 : ComputeJacobianThread::~ComputeJacobianThread() {}
      41             : 
      42             : void
      43    78383499 : ComputeJacobianThread::compute(KernelBase & kernel)
      44             : {
      45    78383499 :   if (kernel.isImplicit())
      46             :   {
      47    78265131 :     kernel.prepareShapes(kernel.variable().number());
      48    78265131 :     kernel.computeJacobian();
      49    78265112 :     if (_fe_problem.checkNonlocalCouplingRequirement() && !_fe_problem.computingScalingJacobian())
      50           4 :       mooseError("Nonlocal kernels only supported for non-diagonal coupling. Please specify an SMP "
      51             :                  "preconditioner, with appropriate row-column coupling or specify full = true.");
      52             :   }
      53    78383476 : }
      54             : 
      55             : void
      56           0 : ComputeJacobianThread::compute(FVElementalKernel & fvkernel)
      57             : {
      58           0 :   if (fvkernel.isImplicit())
      59           0 :     fvkernel.computeJacobian();
      60           0 : }
      61             : 
      62             : void
      63      124728 : ComputeJacobianThread::compute(IntegratedBCBase & bc)
      64             : {
      65      124728 :   if (bc.shouldApply() && bc.isImplicit())
      66             :   {
      67      124728 :     bc.prepareShapes(bc.variable().number());
      68      124728 :     bc.computeJacobian();
      69      124728 :     if (_fe_problem.checkNonlocalCouplingRequirement() && !_fe_problem.computingScalingJacobian())
      70           4 :       mooseError("Nonlocal boundary conditions only supported for non-diagonal coupling. Please "
      71             :                  "specify an SMP preconditioner, with appropriate row-column coupling or specify "
      72             :                  "full = true.");
      73             :   }
      74      124724 : }
      75             : 
      76             : void
      77       98064 : ComputeJacobianThread::compute(DGKernelBase & dg, const Elem * neighbor)
      78             : {
      79       98064 :   if (dg.isImplicit())
      80             :   {
      81       98064 :     dg.prepareShapes(dg.variable().number());
      82       98064 :     dg.prepareNeighborShapes(dg.variable().number());
      83       98064 :     if (dg.hasBlocks(neighbor->subdomain_id()))
      84       98064 :       dg.computeJacobian();
      85             :   }
      86       98064 : }
      87             : 
      88             : void
      89        2956 : ComputeJacobianThread::compute(InterfaceKernelBase & intk)
      90             : {
      91        2956 :   if (intk.isImplicit())
      92             :   {
      93        2956 :     intk.prepareShapes(intk.variable().number());
      94        2956 :     intk.prepareNeighborShapes(intk.neighborVariable().number());
      95        2956 :     intk.computeJacobian();
      96             :   }
      97        2956 : }
      98             : 
      99             : void
     100      599784 : ComputeJacobianThread::determineObjectWarehouses()
     101             : {
     102             :   // If users pass a empty vector or a full size of vector,
     103             :   // we take all kernels
     104      599784 :   if (!_tags.size() || _tags.size() == _fe_problem.numMatrixTags())
     105             :   {
     106      585928 :     _tag_kernels = &_kernels;
     107      585928 :     _dg_warehouse = &_dg_kernels;
     108      585928 :     _ibc_warehouse = &_integrated_bcs;
     109      585928 :     _ik_warehouse = &_interface_kernels;
     110      585928 :     _hdg_warehouse = &_hdg_kernels;
     111             :   }
     112             :   // If we have one tag only,
     113             :   // We call tag based storage
     114       13856 :   else if (_tags.size() == 1)
     115             :   {
     116       12634 :     _tag_kernels = &(_kernels.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid));
     117       12634 :     _dg_warehouse = &(_dg_kernels.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid));
     118       12634 :     _ibc_warehouse = &(_integrated_bcs.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid));
     119       12634 :     _ik_warehouse = &(_interface_kernels.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid));
     120       12634 :     _hdg_warehouse = &(_hdg_kernels.getMatrixTagObjectWarehouse(*(_tags.begin()), _tid));
     121             :   }
     122             :   // This one may be expensive, and hopefully we do not use it so often
     123             :   else
     124             :   {
     125        1222 :     _tag_kernels = &(_kernels.getMatrixTagsObjectWarehouse(_tags, _tid));
     126        1222 :     _dg_warehouse = &(_dg_kernels.getMatrixTagsObjectWarehouse(_tags, _tid));
     127        1222 :     _ibc_warehouse = &(_integrated_bcs.getMatrixTagsObjectWarehouse(_tags, _tid));
     128        1222 :     _ik_warehouse = &(_interface_kernels.getMatrixTagsObjectWarehouse(_tags, _tid));
     129        1222 :     _hdg_warehouse = &(_hdg_kernels.getMatrixTagsObjectWarehouse(_tags, _tid));
     130             :   }
     131      599784 : }
     132             : 
     133             : void
     134        4384 : ComputeJacobianThread::accumulateLower()
     135             : {
     136        4384 :   _fe_problem.addJacobianLowerD(_tid);
     137        4384 : }
     138             : 
     139             : void
     140      112490 : ComputeJacobianThread::accumulateNeighborLower()
     141             : {
     142      112490 :   _fe_problem.addJacobianNeighborLowerD(_tid);
     143      112490 : }
     144             : 
     145             : void
     146        8132 : ComputeJacobianThread::accumulateNeighbor()
     147             : {
     148        8132 :   _fe_problem.addJacobianNeighbor(_tid);
     149        8132 : }
     150             : 
     151             : void
     152    49346259 : ComputeJacobianThread::postElement(const Elem * /*elem*/)
     153             : {
     154    49346259 :   _fe_problem.cacheJacobian(_tid);
     155    49346259 :   _num_cached++;
     156             : 
     157    49346259 :   if (_num_cached % 20 == 0 || _fe_problem.assembly(_tid, _nl.number()).hasStaticCondensation())
     158     2536712 :     _fe_problem.addCachedJacobian(_tid);
     159    49346259 : }
     160             : 
     161             : void
     162       40018 : ComputeJacobianThread::join(const ComputeJacobianThread & /*y*/)
     163             : {
     164       40018 : }
     165             : 
     166             : void
     167           0 : ComputeJacobianThread::computeOnInternalFace()
     168             : {
     169             :   mooseAssert(_hdg_warehouse->hasActiveBlockObjects(_subdomain, _tid),
     170             :               "We should not be called if we have no active HDG kernels");
     171             :   mooseAssert(false, "HDGKernels must compute the full Jacobian");
     172           0 : }

Generated by: LCOV version 1.14