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 "Material.h" 13 : #include "DerivativeMaterialInterface.h" 14 : 15 : #define usingFunctionMaterialBaseMembers(T) \ 16 : usingMaterialMembers; \ 17 : using FunctionMaterialBase<T>::_args; \ 18 : using FunctionMaterialBase<T>::_F_name; \ 19 : using FunctionMaterialBase<T>::_nargs; \ 20 : using FunctionMaterialBase<T>::_arg_names; \ 21 : using FunctionMaterialBase<T>::_arg_numbers; \ 22 : using FunctionMaterialBase<T>::_arg_param_names; \ 23 : using FunctionMaterialBase<T>::_arg_param_numbers; \ 24 : using FunctionMaterialBase<T>::_arg_constant_defaults; \ 25 : using FunctionMaterialBase<T>::_prop_F; \ 26 : using FunctionMaterialBase<T>::_communicator 27 : 28 : /** 29 : * Material base class, central to all Materials that provide a Function as a 30 : * material property value. 31 : */ 32 : template <bool is_ad = false> 33 : class FunctionMaterialBase : public DerivativeMaterialInterface<Material> 34 : { 35 : public: 36 : static InputParameters validParams(); 37 : 38 : FunctionMaterialBase(const InputParameters & parameters); 39 : 40 : protected: 41 : /** 42 : * FunctionMaterialBase keeps an internal list of all the variables the derivatives are taken 43 : * w.r.t. 44 : * We provide the MOOSE variable bames in _arg_names, the libMesh variable numbers in 45 : * _arg_numbers, and the 46 : * input file parameter names in _arg_param_names. All are indexed by the argument index. 47 : * This method returns the argument index for a given the libMesh variable number. 48 : * 49 : * This mapping is necessary for internal classes which maintain lists of derivatives indexed by 50 : * argument index 51 : * and need to pull from those lists from the computeDF, computeD2F, and computeD3F methods, which 52 : * receive 53 : * libMesh variable numbers as parameters. 54 : */ 55 0 : unsigned int argIndex(unsigned int i_var) const 56 : { 57 0 : const unsigned int idx = libMeshVarNumberRemap(i_var); 58 : mooseAssert(idx < _arg_index.size() && _arg_numbers[_arg_index[idx]] == i_var, 59 : "Requesting argIndex() for a derivative w.r.t. a variable not coupled to."); 60 0 : return _arg_index[idx]; 61 : } 62 : 63 : /// Coupled variables for function arguments 64 : std::vector<const GenericVariableValue<is_ad> *> _args; 65 : 66 : /** 67 : * Name of the function value material property and used as a base name to 68 : * concatenate the material property names for the derivatives. 69 : */ 70 : std::string _F_name; 71 : 72 : /// Flag that indicates if exactly one linear variable is coupled per input file coupling parameter 73 : bool _mapping_is_unique; 74 : 75 : /// Number of coupled arguments. 76 : unsigned int _nargs; 77 : 78 : /// String vector of all argument names. 79 : std::vector<std::string> _arg_names; 80 : 81 : /// Vector of all argument MOOSE variable numbers. 82 : std::vector<unsigned int> _arg_numbers; 83 : 84 : /// String vector of the input file coupling parameter name for each argument. 85 : std::vector<std::string> _arg_param_names; 86 : std::vector<int> _arg_param_numbers; 87 : 88 : /// coupled variables with default values 89 : std::vector<std::string> _arg_constant_defaults; 90 : 91 : /// Material property to store the function value. 92 : GenericMaterialProperty<Real, is_ad> * _prop_F; 93 : 94 : private: 95 : /// map the variable numbers to an even/odd interspersed pattern 96 3372 : unsigned int libMeshVarNumberRemap(unsigned int var) const 97 : { 98 3372 : const int b = static_cast<int>(var); 99 3372 : return b >= 0 ? b << 1 : (-b << 1) - 1; 100 : } 101 : 102 : /// helper function for coupling ad/regular variable values 103 : const GenericVariableValue<is_ad> & coupledGenericValue(const std::string & var_name, 104 : unsigned int comp = 0); 105 : 106 : /// Vector to look up the internal coupled variable index into _arg_* through the libMesh variable number 107 : std::vector<unsigned int> _arg_index; 108 : };