LCOV - code coverage report
Current view: top level - src/kernels - MatGradSquareCoupled.C (source / functions) Hit Total Coverage
Test: idaholab/moose phase_field: #31405 (292dce) with base fef103 Lines: 30 33 90.9 %
Date: 2025-09-04 07:55:36 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 "MatGradSquareCoupled.h"
      11             : 
      12             : registerMooseObject("PhaseFieldApp", MatGradSquareCoupled);
      13             : 
      14             : InputParameters
      15          23 : MatGradSquareCoupled::validParams()
      16             : {
      17          23 :   InputParameters params = Kernel::validParams();
      18          23 :   params.addClassDescription("Gradient square of a coupled variable.");
      19          46 :   params.addCoupledVar("elec_potential", "Electric potential");
      20          46 :   params.addCoupledVar("args", "Vector of variable arguments to prefactor");
      21          46 :   params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024");
      22          46 :   params.addParam<MaterialPropertyName>(
      23             :       "prefactor",
      24             :       "prefactor",
      25             :       "Material property providing a prefactor of electric potential contribution");
      26          23 :   return params;
      27           0 : }
      28             : 
      29          12 : MatGradSquareCoupled::MatGradSquareCoupled(const InputParameters & parameters)
      30             :   : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters),
      31          12 :     _grad_elec_potential(coupledGradient("elec_potential")),
      32          12 :     _elec_potential_var(coupled("elec_potential")),
      33          24 :     _prefactor(getMaterialProperty<Real>("prefactor")),
      34          12 :     _dprefactor_dphi(getMaterialPropertyDerivative<Real>("prefactor", _var.name())),
      35          24 :     _dprefactor_darg(_n_args)
      36             : {
      37          24 :   for (unsigned int i = 0; i < _n_args; ++i)
      38          12 :     _dprefactor_darg[i] = &getMaterialPropertyDerivative<Real>("prefactor", i);
      39          12 : }
      40             : 
      41             : void
      42          12 : MatGradSquareCoupled::initialSetup()
      43             : {
      44          36 :   validateNonlinearCoupling<Real>("prefactor");
      45          12 : }
      46             : 
      47             : Real
      48     1317600 : MatGradSquareCoupled::computeQpResidual()
      49             : {
      50     1317600 :   return -_prefactor[_qp] * _grad_elec_potential[_qp] * _grad_elec_potential[_qp] * _test[_i][_qp];
      51             : }
      52             : 
      53             : Real
      54      849600 : MatGradSquareCoupled::computeQpJacobian()
      55             : {
      56      849600 :   return -_dprefactor_dphi[_qp] * _grad_elec_potential[_qp] * _grad_elec_potential[_qp] *
      57      849600 :          _phi[_j][_qp] * _test[_i][_qp];
      58             : }
      59             : 
      60             : Real
      61      849600 : MatGradSquareCoupled::computeQpOffDiagJacobian(unsigned int jvar)
      62             : {
      63             :   const unsigned int cvar = mapJvarToCvar(jvar);
      64             : 
      65      849600 :   if (jvar == _elec_potential_var)
      66      849600 :     return -2 * _prefactor[_qp] * _grad_elec_potential[_qp] * _grad_phi[_j][_qp] * _test[_i][_qp] -
      67      849600 :            (*_dprefactor_darg[cvar])[_qp] * _grad_elec_potential[_qp] * _grad_elec_potential[_qp] *
      68      849600 :                _phi[_j][_qp] * _test[_i][_qp];
      69             : 
      70           0 :   return -(*_dprefactor_darg[cvar])[_qp] * _grad_elec_potential[_qp] * _grad_elec_potential[_qp] *
      71           0 :          _phi[_j][_qp] * _test[_i][_qp];
      72             : }

Generated by: LCOV version 1.14