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 : VariableNameMappingMode map_mode = VariableNameMappingMode::USE_PARAM_NAMES); 39 : 40 : static InputParameters validParams(); 41 : 42 : protected: 43 : struct Derivative; 44 : struct MaterialPropertyDerivativeRule; 45 : 46 : void initQpStatefulProperties() override; 47 : void computeQpProperties() override; 48 : 49 : void functionsPostParse() override; 50 : void assembleDerivatives(); 51 : 52 : void 53 : recurseMatProps(unsigned int var, unsigned int order, const MatPropDescriptorList & parent_mpd); 54 : 55 : void 56 : recurseDerivative(unsigned int var, unsigned int order, const Derivative & parent_derivative); 57 : 58 : /// maximum derivative order 59 : unsigned int _derivative_order; 60 : 61 : /// The requested derivatives of the free energy (sorted by order) 62 : std::vector<Derivative> _derivatives; 63 : 64 : /// variable base name for the dynamically material property derivatives 65 : const std::string _dmatvar_base; 66 : 67 : /// next available variable number for automatically created material property derivative variables 68 : unsigned int _dmatvar_index; 69 : 70 : /** 71 : * list of all indices into _variable_names to take derivatives, w.r.t. By default this always 72 : * includes 0.._nargs-1, which are the coupled variables 73 : */ 74 : std::vector<std::size_t> _derivative_symbol_table; 75 : 76 : private: 77 : // for bulk registration of material property derivatives 78 : std::vector<MaterialPropertyDerivativeRule> _bulk_rules; 79 : }; 80 : 81 : template <bool is_ad> 82 : struct DerivativeParsedMaterialHelperTempl<is_ad>::Derivative 83 : { 84 : GenericMaterialProperty<Real, is_ad> * _mat_prop; 85 : SymFunctionPtr _F; 86 : std::vector<SymbolName> _darg_names; 87 : }; 88 : 89 : template <bool is_ad> 90 : struct DerivativeParsedMaterialHelperTempl<is_ad>::MaterialPropertyDerivativeRule 91 : { 92 1656 : MaterialPropertyDerivativeRule(std::string p, std::string v, std::string c) 93 1656 : : _parent(p), _var(v), _child(c) 94 : { 95 1656 : } 96 : 97 : std::string _parent; 98 : std::string _var; 99 : std::string _child; 100 : }; 101 : 102 : typedef DerivativeParsedMaterialHelperTempl<false> DerivativeParsedMaterialHelper; 103 : typedef DerivativeParsedMaterialHelperTempl<true> ADDerivativeParsedMaterialHelper;