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 "ParsedMaterialHelper.h" 13 : #include "DerivativeMaterialPropertyNameInterface.h" 14 : 15 : #include "libmesh/fparser_ad.hh" 16 : 17 : #define usingDerivativeParsedMaterialHelperMembers(T) \ 18 : usingParsedMaterialHelperMembers(T); \ 19 : using typename DerivativeParsedMaterialHelperTempl<T>::Derivative; \ 20 : using typename DerivativeParsedMaterialHelperTempl<T>::MaterialPropertyDerivativeRule; \ 21 : using DerivativeParsedMaterialHelperTempl<T>::_derivative_order; \ 22 : using DerivativeParsedMaterialHelperTempl<T>::_derivatives 23 : 24 : /** 25 : * Helper class to perform the auto derivative taking. 26 : */ 27 : template <bool is_ad> 28 : class DerivativeParsedMaterialHelperTempl : public ParsedMaterialHelper<is_ad> 29 : { 30 : protected: 31 : usingParsedMaterialHelperMembers(is_ad); 32 : 33 : public: 34 : typedef DerivativeMaterialPropertyNameInterface::SymbolName SymbolName; 35 : 36 : DerivativeParsedMaterialHelperTempl( 37 : const InputParameters & parameters, 38 : const VariableNameMappingMode map_mode = VariableNameMappingMode::USE_PARAM_NAMES, 39 : const std::optional<std::string> & function_param_name = {}); 40 : 41 : static InputParameters validParams(); 42 : 43 : protected: 44 : struct Derivative; 45 : struct MaterialPropertyDerivativeRule; 46 : 47 : void initQpStatefulProperties() override; 48 : void computeQpProperties() override; 49 : 50 : void functionsPostParse() override; 51 : void assembleDerivatives(); 52 : 53 : void 54 : recurseMatProps(unsigned int var, unsigned int order, const MatPropDescriptorList & parent_mpd); 55 : 56 : void 57 : recurseDerivative(unsigned int var, unsigned int order, const Derivative & parent_derivative); 58 : 59 : /// maximum derivative order 60 : unsigned int _derivative_order; 61 : 62 : /// The requested derivatives of the free energy (sorted by order) 63 : std::vector<Derivative> _derivatives; 64 : 65 : /// variable base name for the dynamically material property derivatives 66 : const std::string _dmatvar_base; 67 : 68 : /// next available variable number for automatically created material property derivative variables 69 : unsigned int _dmatvar_index; 70 : 71 : /** 72 : * list of all indices into _variable_names to take derivatives, w.r.t. By default this always 73 : * includes 0.._nargs-1, which are the coupled variables 74 : */ 75 : std::vector<std::size_t> _derivative_symbol_table; 76 : 77 : private: 78 : // for bulk registration of material property derivatives 79 : std::vector<MaterialPropertyDerivativeRule> _bulk_rules; 80 : }; 81 : 82 : template <bool is_ad> 83 : struct DerivativeParsedMaterialHelperTempl<is_ad>::Derivative 84 : { 85 : GenericMaterialProperty<Real, is_ad> * _mat_prop; 86 : SymFunctionPtr _F; 87 : std::vector<SymbolName> _darg_names; 88 : }; 89 : 90 : template <bool is_ad> 91 : struct DerivativeParsedMaterialHelperTempl<is_ad>::MaterialPropertyDerivativeRule 92 : { 93 1818 : MaterialPropertyDerivativeRule(std::string p, std::string v, std::string c) 94 1818 : : _parent(p), _var(v), _child(c) 95 : { 96 1818 : } 97 : 98 : std::string _parent; 99 : std::string _var; 100 : std::string _child; 101 : }; 102 : 103 : typedef DerivativeParsedMaterialHelperTempl<false> DerivativeParsedMaterialHelper; 104 : typedef DerivativeParsedMaterialHelperTempl<true> ADDerivativeParsedMaterialHelper;