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 : #pragma once 11 : 12 : #include "Kernel.h" 13 : #include "JvarMapInterface.h" 14 : #include "DerivativeMaterialInterface.h" 15 : 16 : /** 17 : * This kernel is used for testing derivatives of a material property. 18 : */ 19 : template <typename T> 20 : class MaterialDerivativeTestKernelBase 21 : : public DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>> 22 : { 23 : public: 24 : static InputParameters validParams(); 25 : 26 : MaterialDerivativeTestKernelBase(const InputParameters & parameters); 27 : 28 : protected: 29 : /// number of nonlinear variables 30 : const unsigned int _n_vars; 31 : 32 : /// select material property derivative to test derivatives of 33 : std::vector<SymbolName> _derivative; 34 : 35 : /// material property for which to test derivatives 36 : const MaterialProperty<T> & _p; 37 : 38 : /// material properties for the off-diagonal derivatives of the tested property 39 : std::vector<const MaterialProperty<T> *> _p_off_diag_derivatives; 40 : 41 : /// material property for the diagonal derivative of the tested property 42 : const MaterialProperty<T> & _p_diag_derivative; 43 : }; 44 : 45 : template <typename T> 46 11 : MaterialDerivativeTestKernelBase<T>::MaterialDerivativeTestKernelBase( 47 : const InputParameters & parameters) 48 : : DerivativeMaterialInterface<JvarMapKernelInterface<Kernel>>(parameters), 49 22 : _n_vars(_coupled_moose_vars.size()), 50 11 : _derivative(getParam<std::vector<SymbolName>>("derivative")), 51 11 : _p(this->template getMaterialPropertyDerivative<T>("material_property", _derivative)), 52 11 : _p_off_diag_derivatives(_n_vars), 53 11 : _p_diag_derivative(this->template getMaterialPropertyDerivative<T>( 54 33 : "material_property", MooseUtils::concatenate(_derivative, SymbolName(_var.name())))) 55 : { 56 33 : for (unsigned int m = 0; m < _n_vars; ++m) 57 22 : _p_off_diag_derivatives[m] = &this->template getMaterialPropertyDerivative<T>( 58 : "material_property", 59 44 : MooseUtils::concatenate(_derivative, SymbolName(_coupled_moose_vars[m]->name()))); 60 11 : } 61 : 62 : template <typename T> 63 : InputParameters 64 42816 : MaterialDerivativeTestKernelBase<T>::validParams() 65 : { 66 42816 : InputParameters params = Kernel::validParams(); 67 42816 : params.addClassDescription("Class used for testing derivatives of a material property."); 68 42816 : params.addRequiredParam<MaterialPropertyName>( 69 : "material_property", "Name of material property for which derivatives are to be tested."); 70 42816 : params.addRequiredCoupledVar("args", "List of variables the material property depends on"); 71 42816 : params.deprecateCoupledVar("args", "coupled_variables", "02/07/2024"); 72 42816 : params.addParam<std::vector<SymbolName>>( 73 : "derivative", 74 : {}, 75 : "Select derivative to test derivatives of (leave empty for checking " 76 : "derivatives of the original material property)"); 77 42816 : return params; 78 0 : }