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 "ArrayTimeDerivative.h" 11 : 12 : registerMooseObject("MooseApp", ArrayTimeDerivative); 13 : 14 : InputParameters 15 3506 : ArrayTimeDerivative::validParams() 16 : { 17 3506 : InputParameters params = ArrayTimeKernel::validParams(); 18 7012 : params.addClassDescription("Array time derivative operator with the weak form of $(\\psi_i, " 19 : "\\frac{\\partial u_h}{\\partial t})$."); 20 10518 : params.addParam<MaterialPropertyName>("time_derivative_coefficient", 21 : "The name of the time derivative coefficient. " 22 : "Can be scalar, vector, or matrix material property."); 23 3506 : return params; 24 0 : } 25 : 26 229 : ArrayTimeDerivative::ArrayTimeDerivative(const InputParameters & parameters) 27 : : ArrayTimeKernel(parameters), 28 229 : _has_coefficient(isParamValid("time_derivative_coefficient")), 29 411 : _coeff(_has_coefficient && hasMaterialProperty<Real>("time_derivative_coefficient") 30 320 : ? &getMaterialProperty<Real>("time_derivative_coefficient") 31 : : nullptr), 32 640 : _coeff_array(_has_coefficient && 33 411 : hasMaterialProperty<RealEigenVector>("time_derivative_coefficient") 34 502 : ? &getMaterialProperty<RealEigenVector>("time_derivative_coefficient") 35 : : nullptr), 36 640 : _coeff_2d_array(_has_coefficient && 37 411 : hasMaterialProperty<RealEigenMatrix>("time_derivative_coefficient") 38 320 : ? &getMaterialProperty<RealEigenMatrix>("time_derivative_coefficient") 39 229 : : nullptr) 40 : { 41 229 : if (!_coeff && !_coeff_array && !_coeff_2d_array && _has_coefficient) 42 : { 43 0 : MaterialPropertyName mat = getParam<MaterialPropertyName>("time_derivative_coefficient"); 44 0 : mooseError("Property " + mat + " is of unsupported type for ArrayTimeDerivative"); 45 0 : } 46 229 : } 47 : 48 : void 49 37436164 : ArrayTimeDerivative::computeQpResidual(RealEigenVector & residual) 50 : { 51 37436164 : if (!_has_coefficient) 52 23428656 : residual = _u_dot[_qp] * _test[_i][_qp]; 53 14007508 : else if (_coeff) 54 0 : residual = (*_coeff)[_qp] * _u_dot[_qp] * _test[_i][_qp]; 55 14007508 : else if (_coeff_array) 56 : { 57 : mooseAssert((*_coeff_array)[_qp].size() == _var.count(), 58 : "time_derivative_coefficient size is inconsistent with the number of components " 59 : "in array variable"); 60 : // WARNING: use noalias() syntax with caution. See ArrayDiffusion.C for more details. 61 14007508 : residual.noalias() = (*_coeff_array)[_qp].asDiagonal() * _u_dot[_qp] * _test[_i][_qp]; 62 : } 63 : else 64 : { 65 : mooseAssert((*_coeff_2d_array)[_qp].cols() == _var.count(), 66 : "time_derivative_coefficient size is inconsistent with the number of components " 67 : "in array variable"); 68 : mooseAssert((*_coeff_2d_array)[_qp].rows() == _var.count(), 69 : "time_derivative_coefficient size is inconsistent with the number of components " 70 : "in array variable"); 71 : // WARNING: use noalias() syntax with caution. See ArrayDiffusion.C for more details. 72 0 : residual.noalias() = (*_coeff_2d_array)[_qp] * _u_dot[_qp] * _test[_i][_qp]; 73 : } 74 37436164 : } 75 : 76 : RealEigenVector 77 23782816 : ArrayTimeDerivative::computeQpJacobian() 78 : { 79 23782816 : Real tmp = _test[_i][_qp] * _phi[_j][_qp] * _du_dot_du[_qp]; 80 23782816 : if (!_has_coefficient) 81 14547728 : return RealEigenVector::Constant(_var.count(), tmp); 82 9235088 : else if (_coeff) 83 0 : return RealEigenVector::Constant(_var.count(), tmp * (*_coeff)[_qp]); 84 9235088 : else if (_coeff_array) 85 18470176 : return tmp * (*_coeff_array)[_qp]; 86 : else 87 0 : return tmp * (*_coeff_2d_array)[_qp].diagonal(); 88 : } 89 : 90 : RealEigenMatrix 91 15234080 : ArrayTimeDerivative::computeQpOffDiagJacobian(const MooseVariableFEBase & jvar) 92 : { 93 15234080 : if (jvar.number() == _var.number() && _coeff_2d_array) 94 0 : return _phi[_j][_qp] * _test[_i][_qp] * _du_dot_du[_qp] * (*_coeff_2d_array)[_qp]; 95 : else 96 15234080 : return ArrayKernel::computeQpOffDiagJacobian(jvar); 97 : }