LCOV - code coverage report
Current view: top level - src/kernels - KernelValue.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 36 52 69.2 %
Date: 2025-07-17 01:28:37 Functions: 5 7 71.4 %
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 "KernelValue.h"
      11             : #include "Assembly.h"
      12             : #include "SystemBase.h"
      13             : #include "libmesh/quadrature.h"
      14             : 
      15             : InputParameters
      16       28586 : KernelValue::validParams()
      17             : {
      18       28586 :   return Kernel::validParams();
      19             : }
      20             : 
      21          30 : KernelValue::KernelValue(const InputParameters & parameters) : Kernel(parameters) {}
      22             : 
      23             : void
      24       57778 : KernelValue::computeResidual()
      25             : {
      26       57778 :   prepareVectorTag(_assembly, _var.number());
      27             : 
      28       57778 :   const unsigned int n_test = _test.size();
      29      288890 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      30             :   {
      31      231112 :     Real value = precomputeQpResidual() * _JxW[_qp] * _coord[_qp];
      32     1155560 :     for (_i = 0; _i < n_test; _i++) // target for auto vectorization
      33      924448 :       _local_re(_i) += value * _test[_i][_qp];
      34             :   }
      35             : 
      36       57778 :   accumulateTaggedLocalResidual();
      37             : 
      38       57778 :   if (_has_save_in)
      39             :   {
      40           0 :     Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
      41           0 :     for (const auto & var : _save_in)
      42           0 :       var->sys().solution().add_vector(_local_re, var->dofIndices());
      43           0 :   }
      44       57778 : }
      45             : 
      46             : void
      47       29232 : KernelValue::computeJacobian()
      48             : {
      49       29232 :   prepareMatrixTag(_assembly, _var.number(), _var.number());
      50             : 
      51       29232 :   const unsigned int n_test = _test.size();
      52      146160 :   for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      53      584640 :     for (_j = 0; _j < _phi.size(); _j++)
      54             :     {
      55      467712 :       Real value = precomputeQpJacobian() * _JxW[_qp] * _coord[_qp];
      56     2338560 :       for (_i = 0; _i < n_test; _i++) // target for auto vectorization
      57     1870848 :         _local_ke(_i, _j) += value * _test[_i][_qp];
      58             :     }
      59             : 
      60       29232 :   accumulateTaggedLocalMatrix();
      61             : 
      62       29232 :   if (_has_diag_save_in)
      63             :   {
      64           0 :     unsigned int rows = _local_ke.m();
      65           0 :     DenseVector<Number> diag(rows);
      66           0 :     for (unsigned int i = 0; i < rows; i++) // target for auto vectorization
      67           0 :       diag(i) = _local_ke(i, i);
      68             : 
      69           0 :     Threads::spin_mutex::scoped_lock lock(Threads::spin_mtx);
      70           0 :     for (const auto & var : _diag_save_in)
      71           0 :       var->sys().solution().add_vector(diag, var->dofIndices());
      72           0 :   }
      73       29232 : }
      74             : 
      75             : void
      76       51200 : KernelValue::computeOffDiagJacobian(const unsigned int jvar_num)
      77             : {
      78       51200 :   const auto & jvar = getVariable(jvar_num);
      79             : 
      80       51200 :   if (jvar_num == _var.number())
      81       25600 :     computeJacobian();
      82             :   else
      83             :   {
      84       25600 :     prepareMatrixTag(_assembly, _var.number(), jvar_num);
      85             :     // This (undisplaced) jvar could potentially yield the wrong phi size if this object is acting
      86             :     // on the displaced mesh
      87       25600 :     auto phi_size = jvar.dofIndices().size();
      88             : 
      89      128000 :     for (_j = 0; _j < phi_size; _j++)
      90      512000 :       for (_qp = 0; _qp < _qrule->n_points(); _qp++)
      91     2048000 :         for (_i = 0; _i < _test.size(); _i++)
      92     1638400 :           _local_ke(_i, _j) += _JxW[_qp] * _coord[_qp] * computeQpOffDiagJacobian(jvar_num);
      93       25600 :     accumulateTaggedLocalMatrix();
      94             :   }
      95       51200 : }
      96             : 
      97             : Real
      98           0 : KernelValue::computeQpResidual()
      99             : {
     100           0 :   mooseError("Override precomputeQpResidual() in your KernelValue derived class!");
     101             : }
     102             : 
     103             : Real
     104           0 : KernelValue::precomputeQpJacobian()
     105             : {
     106           0 :   return 0.0;
     107             : }

Generated by: LCOV version 1.14