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 "DerivativeMaterialPropertyNameInterface.h" 13 : #include "Material.h" 14 : 15 : #include <string> 16 : #include <vector> 17 : 18 : class MooseObject; 19 : 20 : /** 21 : * Material properties get fully described using this structure, including their dependent 22 : * variables and derivation state. 23 : */ 24 : template <bool is_ad> 25 : class FunctionMaterialPropertyDescriptor : public DerivativeMaterialPropertyNameInterface 26 : { 27 : public: 28 : /* 29 : * The descriptor is constructed with an expression that describes the 30 : * material property. 31 : * Examples: 32 : * 'F' A material property called 'F' with no declared variable 33 : * dependencies (i.e. vanishing derivatives) 34 : * 'F(c,phi)' A material property called 'F' with declared dependence 35 : * on 'c' and 'phi' (uses DerivativeFunctionMaterial rules to 36 : * look up the derivatives) 37 : * 'a:=D[x(t),t,t]' The second time derivative of the t-dependent material property 'x' 38 : * which will be referred to as 'a' in the function expression. 39 : * 'x_old:=Old[x]' The previous time step value of x 40 : * 'x_older:=Older[x]' The value of x two time steps ago 41 : */ 42 : FunctionMaterialPropertyDescriptor(const std::string &, MooseObject *, bool required = false); 43 : 44 : /// no default constructor 45 : FunctionMaterialPropertyDescriptor() = delete; 46 : 47 : /// copy constructor 48 : FunctionMaterialPropertyDescriptor(const FunctionMaterialPropertyDescriptor &); 49 : 50 : /// copy constructor assigning new parent 51 : FunctionMaterialPropertyDescriptor(const FunctionMaterialPropertyDescriptor &, MooseObject *); 52 : 53 : // copy assignment operator 54 : FunctionMaterialPropertyDescriptor & 55 : operator=(const FunctionMaterialPropertyDescriptor &) = default; 56 : 57 : /// construct a vector of FunctionMaterialPropertyDescriptors from a vector of strings 58 : static std::vector<FunctionMaterialPropertyDescriptor> 59 : parseVector(const std::vector<std::string> &, MooseObject *); 60 : 61 : /// get the fparser symbol name 62 5112 : const std::string & getSymbolName() const { return _fparser_name; }; 63 : 64 : /// set the fparser symbol name 65 1656 : void setSymbolName(const std::string & n) { _fparser_name = n; }; 66 : 67 : /// get the property name 68 0 : const std::string & getPropertyName() const { return _property_name; }; 69 : 70 : /// get the property value at the given quadrature point 71 : GenericReal<is_ad> value(unsigned int qp = libMesh::invalid_uint) const; 72 : 73 : /// take another derivative 74 : void addDerivative(const SymbolName & symbol); 75 : 76 : /** 77 : * Check if a material property depends on a given FParser symbol. 78 : * A dependency is indicated by either directly specifying it, or by requesting a 79 : * derivative w.r.t. that symbol using the D[x,a] syntax 80 : */ 81 : bool dependsOn(const SymbolName & symbol) const; 82 : 83 : /// builds a list of dependent symbols (exactly all symbols for which depends on returns true) 84 : std::vector<SymbolName> getDependentSymbols(); 85 : 86 : /// output the internal state of this descriptor for debugging purposes 87 : void printDebug(); 88 : 89 : /// update the cached _property_name member 90 : void updatePropertyName(); 91 : 92 : private: 93 : void parseDerivative(const std::string &); 94 : void parseDependentSymbols(const std::string &); 95 : 96 : /// property state 97 : enum class PropertyState 98 : { 99 : CURRENT, 100 : OLD, 101 : OLDER 102 : } _state; 103 : 104 : /// name used in function expression 105 : std::string _fparser_name; 106 : 107 : /// function material property base name 108 : std::string _base_name; 109 : 110 : std::vector<SymbolName> _dependent_symbols; 111 : std::vector<SymbolName> _derivative_symbols; 112 : 113 : /// material property value (this is lazily updated and cached when read through value()) 114 : mutable const GenericMaterialProperty<Real, is_ad> * _value; 115 : 116 : /// old/older material property value (this is lazily updated and cached when read through value()) 117 : mutable const MaterialProperty<Real> * _old_older_value; 118 : 119 : /// material object that owns this descriptor 120 : MooseObject * _parent; 121 : 122 : /// cache the final property name of the derivative 123 : std::string _property_name; 124 : 125 : /// is this a property that was directly specified by the user? Then it _must_ exist. 126 : bool _required; 127 : };