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