LCOV - code coverage report
Current view: top level - src/kernels - MatBodyForce.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 24 25 96.0 %
Date: 2025-07-17 01:28:37 Functions: 10 10 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 "MatBodyForce.h"
      11             : 
      12             : registerMooseObject("MooseApp", MatBodyForce);
      13             : registerMooseObject("MooseApp", ADMatBodyForce);
      14             : 
      15             : template <bool is_ad, class Parent>
      16             : InputParameters
      17       28580 : MatBodyForceTempl<is_ad, Parent>::validParams()
      18             : {
      19       28580 :   InputParameters params = Parent::validParams();
      20       28580 :   params.addClassDescription("Kernel that defines a body force modified by a material property");
      21       28580 :   params.addRequiredParam<MaterialPropertyName>("material_property",
      22             :                                                 "Material property defining the body force");
      23       28580 :   return params;
      24           0 : }
      25             : 
      26             : template <bool is_ad, class Parent>
      27          26 : MatBodyForceTempl<is_ad, Parent>::MatBodyForceTempl(const InputParameters & parameters)
      28             :   : Parent(parameters),
      29          26 :     _property(this->template getGenericMaterialProperty<Real, is_ad>("material_property"))
      30             : {
      31          26 : }
      32             : 
      33             : template <bool is_ad, class Parent>
      34             : GenericReal<is_ad>
      35     1441792 : MatBodyForceTempl<is_ad, Parent>::computeQpResidual()
      36             : {
      37     1441792 :   return Parent::computeQpResidual() * _property[_qp];
      38             : }
      39             : 
      40          13 : MatBodyForce::MatBodyForce(const InputParameters & parameters)
      41             :   : MatBodyForceParent(parameters),
      42          13 :     _dpropertydv(getMaterialPropertyDerivative<Real>("material_property", _var.name())),
      43          26 :     _dpropertydarg(_n_args)
      44             : {
      45             :   // Get derivatives of property wrt coupled variables
      46          26 :   for (unsigned int i = 0; i < _n_args; ++i)
      47          13 :     _dpropertydarg[i] = &getMaterialPropertyDerivative<Real>("material_property", i);
      48          13 : }
      49             : 
      50             : void
      51          13 : MatBodyForce::initialSetup()
      52             : {
      53          13 :   validateNonlinearCoupling<Real>("material_property");
      54          13 : }
      55             : 
      56             : Real
      57     1572864 : MatBodyForce::computeQpJacobian()
      58             : {
      59     1572864 :   return _dpropertydv[_qp] * BodyForce::computeQpResidual() * _phi[_j][_qp];
      60             : }
      61             : 
      62             : Real
      63     1572864 : MatBodyForce::computeQpOffDiagJacobian(unsigned int jvar)
      64             : {
      65     1572864 :   const unsigned int cvar = mapJvarToCvar(jvar);
      66     1572864 :   return (*_dpropertydarg[cvar])[_qp] * BodyForce::computeQpResidual() * _phi[_j][_qp];
      67             : }
      68             : 
      69             : template class MatBodyForceTempl<false,
      70             :                                  DerivativeMaterialInterface<JvarMapKernelInterface<BodyForce>>>;
      71             : template class MatBodyForceTempl<true, ADBodyForce>;

Generated by: LCOV version 1.14