LCOV - code coverage report
Current view: top level - src/kernels - KernelGrad.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: b79a48 Lines: 36 45 80.0 %
Date: 2025-11-12 20:01:28 Functions: 5 5 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 "KernelGrad.h"
      11             : #include "Assembly.h"
      12             : #include "SystemBase.h"
      13             : #include "libmesh/quadrature.h"
      14             : 
      15             : InputParameters
      16       32118 : KernelGrad::validParams()
      17             : {
      18       32118 :   return Kernel::validParams();
      19             : }
      20             : 
      21        1860 : KernelGrad::KernelGrad(const InputParameters & parameters) : Kernel(parameters) {}
      22             : 
      23             : void
      24     2769021 : KernelGrad::computeResidual()
      25             : {
      26     2769021 :   prepareVectorTag(_assembly, _var.number());
      27     2769021 :   const unsigned int n_test = _test.size();
      28    13407652 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      29             :   {
      30    10638631 :     RealGradient value = precomputeQpResidual() * _JxW[_qp] * _coord[_qp];
      31    64737036 :     for (_i = 0; _i < n_test; _i++) // target for auto vectorization
      32    54098405 :       _local_re(_i) += value * _grad_test[_i][_qp];
      33             :   }
      34     2769021 :   accumulateTaggedLocalResidual();
      35             : 
      36     2769021 :   if (_has_save_in)
      37           0 :     for (const auto & var : _save_in)
      38           0 :       var->sys().solution().add_vector(_local_re, var->dofIndices());
      39     2769021 : }
      40             : 
      41             : void
      42      517961 : KernelGrad::computeJacobian()
      43             : {
      44      517961 :   prepareMatrixTag(_assembly, _var.number(), _var.number());
      45             : 
      46      517961 :   const unsigned int n_test = _test.size();
      47     2217053 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      48     9062228 :     for (_j = 0; _j < _phi.size(); _j++)
      49             :     {
      50     7363136 :       RealGradient value = precomputeQpJacobian() * _JxW[_qp] * _coord[_qp];
      51    58461386 :       for (_i = 0; _i < n_test; _i++) // target for auto vectorization
      52    51098250 :         _local_ke(_i, _j) += value * _grad_test[_i][_qp];
      53             :     }
      54             : 
      55      517961 :   accumulateTaggedLocalMatrix();
      56             : 
      57      517961 :   if (_has_diag_save_in)
      58             :   {
      59           0 :     const unsigned int rows = _local_ke.m();
      60           0 :     DenseVector<Number> diag(rows);
      61           0 :     for (unsigned int i = 0; i < rows; i++) // target for auto vectorization
      62           0 :       diag(i) = _local_ke(i, i);
      63             : 
      64           0 :     for (const auto & var : _diag_save_in)
      65           0 :       var->sys().solution().add_vector(diag, var->dofIndices());
      66           0 :   }
      67      517961 : }
      68             : 
      69             : void
      70      142082 : KernelGrad::computeOffDiagJacobian(const unsigned int jvar_num)
      71             : {
      72      142082 :   const auto & jvar = getVariable(jvar_num);
      73             : 
      74      142082 :   if (jvar_num == _var.number())
      75      141082 :     computeJacobian();
      76             :   else
      77             :   {
      78        1000 :     prepareMatrixTag(_assembly, _var.number(), jvar_num);
      79             : 
      80             :     // This (undisplaced) jvar could potentially yield the wrong phi size if this object is acting
      81             :     // on the displaced mesh
      82        1000 :     auto phi_size = jvar.dofIndices().size();
      83             : 
      84        5000 :     for (_j = 0; _j < phi_size; _j++)
      85       20000 :       for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      86       80000 :         for (_i = 0; _i < _test.size(); _i++)
      87       64000 :           _local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpOffDiagJacobian(jvar_num);
      88             : 
      89        1000 :     accumulateTaggedLocalMatrix();
      90             :   }
      91      142082 : }

Generated by: LCOV version 1.14