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 15 : MatGradSquareCoupled::validParams() 16 : { 17 15 : InputParameters params = Kernel::validParams(); 18 15 : params.addClassDescription("Gradient square of a coupled variable."); 19 30 : params.addCoupledVar("elec_potential", "Electric potential"); 20 30 : params.addCoupledVar("coupled_variables", "Vector of variable arguments to prefactor"); 21 30 : params.addParam<MaterialPropertyName>( 22 : "prefactor", 23 : "prefactor", 24 : "Material property providing a prefactor of electric potential contribution"); 25 15 : return params; 26 0 : } 27 : 28 8 : MatGradSquareCoupled::MatGradSquareCoupled(const InputParameters & parameters) 29 : : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters), 30 8 : _grad_elec_potential(coupledGradient("elec_potential")), 31 8 : _elec_potential_var(coupled("elec_potential")), 32 16 : _prefactor(getMaterialProperty<Real>("prefactor")), 33 8 : _dprefactor_dphi(getMaterialPropertyDerivative<Real>("prefactor", _var.name())), 34 16 : _dprefactor_darg(_n_args) 35 : { 36 16 : for (unsigned int i = 0; i < _n_args; ++i) 37 8 : _dprefactor_darg[i] = &getMaterialPropertyDerivative<Real>("prefactor", i); 38 8 : } 39 : 40 : void 41 8 : MatGradSquareCoupled::initialSetup() 42 : { 43 24 : validateNonlinearCoupling<Real>("prefactor"); 44 8 : } 45 : 46 : Real 47 1011600 : MatGradSquareCoupled::computeQpResidual() 48 : { 49 1011600 : return -_prefactor[_qp] * _grad_elec_potential[_qp] * _grad_elec_potential[_qp] * _test[_i][_qp]; 50 : } 51 : 52 : Real 53 720000 : MatGradSquareCoupled::computeQpJacobian() 54 : { 55 720000 : return -_dprefactor_dphi[_qp] * _grad_elec_potential[_qp] * _grad_elec_potential[_qp] * 56 720000 : _phi[_j][_qp] * _test[_i][_qp]; 57 : } 58 : 59 : Real 60 720000 : MatGradSquareCoupled::computeQpOffDiagJacobian(unsigned int jvar) 61 : { 62 : const unsigned int cvar = mapJvarToCvar(jvar); 63 : 64 720000 : if (jvar == _elec_potential_var) 65 720000 : return -2 * _prefactor[_qp] * _grad_elec_potential[_qp] * _grad_phi[_j][_qp] * _test[_i][_qp] - 66 720000 : (*_dprefactor_darg[cvar])[_qp] * _grad_elec_potential[_qp] * _grad_elec_potential[_qp] * 67 720000 : _phi[_j][_qp] * _test[_i][_qp]; 68 : 69 0 : return -(*_dprefactor_darg[cvar])[_qp] * _grad_elec_potential[_qp] * _grad_elec_potential[_qp] * 70 0 : _phi[_j][_qp] * _test[_i][_qp]; 71 : }