LCOV - code coverage report
Current view: top level - src/kernels - ArrayDiffusion.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 30 41 73.2 %
Date: 2025-07-17 01:28:37 Functions: 6 6 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 "ArrayDiffusion.h"
      11             : 
      12             : registerMooseObject("MooseApp", ArrayDiffusion);
      13             : 
      14             : InputParameters
      15       15794 : ArrayDiffusion::validParams()
      16             : {
      17       15794 :   InputParameters params = ArrayKernel::validParams();
      18       15794 :   params.addRequiredParam<MaterialPropertyName>(
      19             :       "diffusion_coefficient",
      20             :       "The name of the diffusivity, can be scalar, vector, or matrix material property.");
      21       15794 :   params.addClassDescription(
      22             :       "The array Laplacian operator ($-\\nabla \\cdot \\nabla u$), with the weak "
      23             :       "form of $(\\nabla \\phi_i, \\nabla u_h)$.");
      24       15794 :   return params;
      25           0 : }
      26             : 
      27         784 : ArrayDiffusion::ArrayDiffusion(const InputParameters & parameters)
      28             :   : ArrayKernel(parameters),
      29        1568 :     _d(hasMaterialProperty<Real>("diffusion_coefficient")
      30         784 :            ? &getMaterialProperty<Real>("diffusion_coefficient")
      31             :            : nullptr),
      32        1568 :     _d_array(hasMaterialProperty<RealEigenVector>("diffusion_coefficient")
      33         784 :                  ? &getMaterialProperty<RealEigenVector>("diffusion_coefficient")
      34             :                  : nullptr),
      35        1568 :     _d_2d_array(hasMaterialProperty<RealEigenMatrix>("diffusion_coefficient")
      36         784 :                     ? &getMaterialProperty<RealEigenMatrix>("diffusion_coefficient")
      37         784 :                     : nullptr)
      38             : {
      39         784 :   if (!_d && !_d_array && !_d_2d_array)
      40             :   {
      41           0 :     MaterialPropertyName mat = getParam<MaterialPropertyName>("diffusion_coefficient");
      42           0 :     mooseError("Property " + mat + " is of unsupported type for ArrayDiffusion");
      43           0 :   }
      44         784 : }
      45             : 
      46             : void
      47     7728776 : ArrayDiffusion::initQpResidual()
      48             : {
      49     7728776 :   if (_d_array)
      50             :   {
      51             :     mooseAssert((*_d_array)[_qp].size() == _var.count(),
      52             :                 "diffusion_coefficient size is inconsistent with the number of components of array "
      53             :                 "variable");
      54             :   }
      55           0 :   else if (_d_2d_array)
      56             :   {
      57             :     mooseAssert((*_d_2d_array)[_qp].cols() == _var.count(),
      58             :                 "diffusion_coefficient size is inconsistent with the number of components of array "
      59             :                 "variable");
      60             :     mooseAssert((*_d_2d_array)[_qp].rows() == _var.count(),
      61             :                 "diffusion_coefficient size is inconsistent with the number of components of array "
      62             :                 "variable");
      63             :   }
      64     7728776 : }
      65             : 
      66             : void
      67    40750160 : ArrayDiffusion::computeQpResidual(RealEigenVector & residual)
      68             : {
      69             :   // WARNING: the noalias() syntax is an Eigen optimization tactic, it avoids creating
      70             :   // a temporary object for the matrix multiplication on the right-hand-side. However,
      71             :   // it should be used with caution because it could cause unintended results,
      72             :   // developers should NOT use it if the vector on the left-hand-side appears on the
      73             :   // right-hand-side, for instance:
      74             :   //   vector = matrix * vector;
      75             :   // See http://eigen.tuxfamily.org/dox/group__TopicAliasing.html for more details.
      76    40750160 :   if (_d)
      77           0 :     residual.noalias() = (*_d)[_qp] * _grad_u[_qp] * _array_grad_test[_i][_qp];
      78    40750160 :   else if (_d_array)
      79    40750160 :     residual.noalias() = (*_d_array)[_qp].asDiagonal() * _grad_u[_qp] * _array_grad_test[_i][_qp];
      80             :   else
      81           0 :     residual.noalias() = (*_d_2d_array)[_qp] * _grad_u[_qp] * _array_grad_test[_i][_qp];
      82    40750160 : }
      83             : 
      84             : RealEigenVector
      85    26200856 : ArrayDiffusion::computeQpJacobian()
      86             : {
      87    26200856 :   if (_d)
      88           0 :     return RealEigenVector::Constant(_var.count(),
      89           0 :                                      _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d)[_qp]);
      90    26200856 :   else if (_d_array)
      91    52401712 :     return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_array)[_qp];
      92             :   else
      93           0 :     return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_2d_array)[_qp].diagonal();
      94             : }
      95             : 
      96             : RealEigenMatrix
      97    16600072 : ArrayDiffusion::computeQpOffDiagJacobian(const MooseVariableFEBase & jvar)
      98             : {
      99    16600072 :   if (jvar.number() == _var.number() && _d_2d_array)
     100           0 :     return _grad_phi[_j][_qp] * _grad_test[_i][_qp] * (*_d_2d_array)[_qp];
     101             :   else
     102    16600072 :     return ArrayKernel::computeQpOffDiagJacobian(jvar);
     103             : }

Generated by: LCOV version 1.14