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 28584 : MatBodyForceTempl<is_ad, Parent>::validParams() 18 : { 19 28584 : InputParameters params = Parent::validParams(); 20 28584 : params.addClassDescription("Kernel that defines a body force modified by a material property"); 21 28584 : params.addRequiredParam<MaterialPropertyName>("material_property", 22 : "Material property defining the body force"); 23 28584 : return params; 24 0 : } 25 : 26 : template <bool is_ad, class Parent> 27 28 : MatBodyForceTempl<is_ad, Parent>::MatBodyForceTempl(const InputParameters & parameters) 28 : : Parent(parameters), 29 28 : _property(this->template getGenericMaterialProperty<Real, is_ad>("material_property")) 30 : { 31 28 : } 32 : 33 : template <bool is_ad, class Parent> 34 : GenericReal<is_ad> 35 1622016 : MatBodyForceTempl<is_ad, Parent>::computeQpResidual() 36 : { 37 1622016 : return Parent::computeQpResidual() * _property[_qp]; 38 : } 39 : 40 14 : MatBodyForce::MatBodyForce(const InputParameters & parameters) 41 : : MatBodyForceParent(parameters), 42 14 : _dpropertydv(getMaterialPropertyDerivative<Real>("material_property", _var.name())), 43 28 : _dpropertydarg(_n_args) 44 : { 45 : // Get derivatives of property wrt coupled variables 46 28 : for (unsigned int i = 0; i < _n_args; ++i) 47 14 : _dpropertydarg[i] = &getMaterialPropertyDerivative<Real>("material_property", i); 48 14 : } 49 : 50 : void 51 14 : MatBodyForce::initialSetup() 52 : { 53 14 : validateNonlinearCoupling<Real>("material_property"); 54 14 : } 55 : 56 : Real 57 1769472 : MatBodyForce::computeQpJacobian() 58 : { 59 1769472 : return _dpropertydv[_qp] * BodyForce::computeQpResidual() * _phi[_j][_qp]; 60 : } 61 : 62 : Real 63 1769472 : MatBodyForce::computeQpOffDiagJacobian(unsigned int jvar) 64 : { 65 1769472 : const unsigned int cvar = mapJvarToCvar(jvar); 66 1769472 : 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>;