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 "ADACInterface.h" 11 : 12 : registerMooseObject("PhaseFieldApp", ADACInterface); 13 : 14 : InputParameters 15 339 : ADACInterface::validParams() 16 : { 17 339 : InputParameters params = ADKernel::validParams(); 18 339 : params.addClassDescription("Gradient energy Allen-Cahn Kernel"); 19 678 : params.addParam<MaterialPropertyName>("mob_name", "L", "The mobility used with the kernel"); 20 678 : params.addParam<MaterialPropertyName>("kappa_name", "kappa_op", "The kappa used with the kernel"); 21 678 : params.addCoupledVar("args", "Vector of nonlinear variable arguments this object depends on"); 22 678 : params.deprecateCoupledVar("args", "coupled_variables", "02/27/2024"); 23 : 24 678 : params.addParam<bool>("variable_L", 25 678 : true, 26 : "The mobility is a function of any MOOSE variable (if " 27 : "this is set to false L must be constant over the " 28 : "entire domain!)"); 29 339 : return params; 30 0 : } 31 : 32 180 : ADACInterface::ADACInterface(const InputParameters & parameters) 33 : : ADKernel(parameters), 34 180 : _prop_L(getADMaterialProperty<Real>("mob_name")), 35 360 : _name_L(getParam<MaterialPropertyName>("mob_name")), 36 360 : _kappa(getADMaterialProperty<Real>("kappa_name")), 37 360 : _variable_L(getParam<bool>("variable_L")), 38 360 : _dLdop(_variable_L 39 214 : ? &getADMaterialProperty<Real>(derivativePropertyNameFirst(_name_L, _var.name())) 40 : : nullptr), 41 180 : _nvar(Coupleable::_coupled_standard_moose_vars.size()), 42 180 : _dLdarg(_nvar), 43 360 : _gradarg(_nvar) 44 : { 45 : // Get mobility and kappa derivatives and coupled variable gradients 46 180 : if (_variable_L) 47 34 : for (unsigned int i = 0; i < _nvar; ++i) 48 : { 49 17 : MooseVariable * ivar = _coupled_standard_moose_vars[i]; 50 : const VariableName iname = ivar->name(); 51 17 : if (iname == _var.name()) 52 : { 53 0 : if (isCoupled("args")) 54 0 : paramError( 55 : "args", 56 : "The kernel variable should not be specified in the coupled `args` parameter."); 57 : else 58 0 : paramError( 59 : "coupled_variables", 60 : "The kernel variable should not be specified in the coupled `coupled_variables` " 61 : "parameter."); 62 : } 63 : 64 34 : _dLdarg[i] = &getADMaterialProperty<Real>(derivativePropertyNameFirst(_name_L, iname)); 65 17 : _gradarg[i] = &(ivar->adGradSln()); 66 : } 67 180 : } 68 : 69 : ADReal 70 161910480 : ADACInterface::computeQpResidual() 71 : { 72 : // nabla_Lpsi is the product rule gradient \f$ \nabla (L\psi) \f$ 73 161910480 : ADRealVectorValue nabla_Lpsi = _prop_L[_qp] * _grad_test[_i][_qp]; 74 : 75 161910480 : if (_variable_L) 76 : { 77 2592000 : ADRealVectorValue grad_L = _grad_u[_qp] * (*_dLdop)[_qp]; 78 5184000 : for (unsigned int i = 0; i < _nvar; ++i) 79 5184000 : grad_L += (*_gradarg[i])[_qp] * (*_dLdarg[i])[_qp]; 80 : 81 5184000 : nabla_Lpsi += grad_L * _test[_i][_qp]; 82 : } 83 : 84 161910480 : return _grad_u[_qp] * _kappa[_qp] * nabla_Lpsi; 85 : }