LCOV - code coverage report
Current view: top level - src/kernels - ArrayCoupledForce.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33390 (250e9c) with base 846a5c Lines: 32 35 91.4 %
Date: 2026-07-31 18:15:22 Functions: 4 4 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 "ArrayCoupledForce.h"
      11             : 
      12             : #include "MooseVariable.h"
      13             : 
      14             : registerMooseObject("MooseApp", ArrayCoupledForce);
      15             : 
      16             : InputParameters
      17        3596 : ArrayCoupledForce::validParams()
      18             : {
      19        3596 :   InputParameters params = ArrayKernel::validParams();
      20       14384 :   params.addRequiredCoupledVar("v", "The coupled variable which provides the force");
      21       14384 :   params.addParam<bool>("is_v_array", false, "Whether v is an array variable or not");
      22       14384 :   params.addRequiredParam<RealEigenVector>(
      23             :       "coef", "Coefficient ($\\sigma$) multiplier for the coupled force term.");
      24        3596 :   params.addClassDescription(
      25             :       "Implements a source term proportional to the value of a coupled standard or array "
      26             :       "variable. Weak form: $(\\vec{u}^\\ast, -\\vec{\\sigma} v)$.");
      27        3596 :   return params;
      28           0 : }
      29             : 
      30         264 : ArrayCoupledForce::ArrayCoupledForce(const InputParameters & parameters)
      31             :   : ArrayKernel(parameters),
      32         264 :     _is_v_array(getParam<bool>("is_v_array")),
      33         528 :     _v_var(coupled("v")),
      34         489 :     _v(_is_v_array ? nullptr : &coupledValue("v")),
      35         303 :     _v_array(_is_v_array ? &coupledArrayValue("v") : nullptr),
      36         792 :     _coef(getParam<RealEigenVector>("coef"))
      37             : {
      38         264 :   if (_var.number() == _v_var)
      39           0 :     paramError("v",
      40             :                "Coupled variable 'v' needs to be different from 'variable' with "
      41             :                "ArrayCoupledForce, consider using ArrayReaction or something similar");
      42         342 :   if (_is_v_array && getArrayVar("v", 0)->count() != _count)
      43           0 :     paramError("v",
      44             :                "Needs to be either a standard variable or an array variable with the same "
      45             :                "number of components as 'variable'");
      46         264 : }
      47             : 
      48             : void
      49    14639140 : ArrayCoupledForce::computeQpResidual(RealEigenVector & residual)
      50             : {
      51    14639140 :   if (_is_v_array)
      52    13640768 :     residual = -_coef.cwiseProduct((*_v_array)[_qp]) * _test[_i][_qp];
      53             :   else
      54      998372 :     residual = -_coef * (*_v)[_qp] * _test[_i][_qp];
      55    14639140 : }
      56             : 
      57             : RealEigenMatrix
      58     1540872 : ArrayCoupledForce::computeQpOffDiagJacobian(const MooseVariableFEBase & jvar)
      59             : {
      60     1540872 :   if (jvar.number() == _v_var)
      61             :   {
      62       49536 :     RealEigenVector v = _coef * (-_phi[_j][_qp] * _test[_i][_qp]);
      63       49536 :     if (_is_v_array)
      64             :     {
      65         384 :       RealEigenMatrix t = RealEigenMatrix::Zero(_var.count(), _var.count());
      66         384 :       t.diagonal() = v;
      67         384 :       return t;
      68         384 :     }
      69             :     else
      70       49152 :       return v;
      71       49536 :   }
      72             :   else
      73     1491336 :     return RealEigenMatrix::Zero(_var.count(), jvar.count());
      74             : }

Generated by: LCOV version 1.14