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 : #include "GenericFunctorMaterial.h" 11 : #include "Function.h" 12 : #include "MathUtils.h" 13 : 14 : registerMooseObject("MooseApp", GenericFunctorMaterial); 15 : registerMooseObject("MooseApp", ADGenericFunctorMaterial); 16 : registerMooseObjectRenamed("MooseApp", 17 : GenericConstantFunctorMaterial, 18 : "06/30/2022 24:00", 19 : GenericFunctorMaterial); 20 : registerMooseObjectRenamed("MooseApp", 21 : ADGenericConstantFunctorMaterial, 22 : "06/30/2022 24:00", 23 : ADGenericFunctorMaterial); 24 : registerMooseObjectRenamed("MooseApp", 25 : GenericFunctionFunctorMaterial, 26 : "06/30/2022 24:00", 27 : GenericFunctorMaterial); 28 : registerMooseObjectRenamed("MooseApp", 29 : ADGenericFunctionFunctorMaterial, 30 : "06/30/2022 24:00", 31 : ADGenericFunctorMaterial); 32 : 33 : template <bool is_ad> 34 : InputParameters 35 89196 : GenericFunctorMaterialTempl<is_ad>::validParams() 36 : { 37 89196 : InputParameters params = FunctorMaterial::validParams(); 38 178392 : params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS}; 39 89196 : params.addClassDescription( 40 : "FunctorMaterial object for declaring properties that are populated by evaluation of a " 41 : "Functor (a constant, variable, function or functor material property) objects."); 42 89196 : params.addParam<std::vector<std::string>>("prop_names", 43 : "The names of the properties this material will have"); 44 89196 : params.addParam<std::vector<MooseFunctorName>>("prop_values", 45 : "The corresponding names of the " 46 : "functors that are going to provide " 47 : "the values for the variables"); 48 267588 : params.addParam<bool>("define_dot_functors", 49 178392 : true, 50 : "Whether to define additional functors for the time derivative and the " 51 : "time derivative of the gradient"); 52 89196 : return params; 53 89196 : } 54 : 55 : template <bool is_ad> 56 1855 : GenericFunctorMaterialTempl<is_ad>::GenericFunctorMaterialTempl(const InputParameters & parameters) 57 : : FunctorMaterial(parameters), 58 1855 : _prop_names(getParam<std::vector<std::string>>("prop_names")), 59 3710 : _prop_values(getParam<std::vector<MooseFunctorName>>("prop_values")) 60 : { 61 1855 : unsigned int num_names = _prop_names.size(); 62 1855 : unsigned int num_values = _prop_values.size(); 63 : 64 1855 : if (num_names != num_values) 65 0 : mooseError("Number of prop_names must match the number of prop_values for a " 66 : "GenericFunctorMaterial!"); 67 : 68 : // Check that there is no name conflict, a common mistake with this object 69 3837 : for (const auto i : make_range(num_names)) 70 4252 : for (const auto j : make_range(num_values)) 71 2270 : if (_prop_names[i] == _prop_values[j]) 72 4 : paramError("prop_names", 73 : "prop_names should not be the same as any of the prop_values. They" 74 : " can both be functors, and functors may not have the same name."); 75 : 76 1851 : _num_props = num_names; 77 1851 : _functors.resize(num_names); 78 : 79 3833 : for (const auto i : make_range(_num_props)) 80 1982 : _functors[i] = &getFunctor<GenericReal<is_ad>>(_prop_values[i]); 81 : 82 1851 : const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end()); 83 3829 : for (const auto i : make_range(_num_props)) 84 : { 85 1982 : addFunctorProperty<GenericReal<is_ad>>( 86 : _prop_names[i], 87 2565098 : [this, i](const auto & r, const auto & t) -> GenericReal<is_ad> 88 2565098 : { return (*_functors[i])(r, t); }, 89 : clearance_schedule); 90 1978 : if (getParam<bool>("define_dot_functors")) 91 : { 92 1978 : addFunctorProperty<GenericReal<is_ad>>( 93 1978 : MathUtils::timeDerivName(_prop_names[i]), 94 960 : [this, i](const auto & r, const auto & t) -> GenericReal<is_ad> 95 960 : { return _functors[i]->dot(r, t); }, 96 : clearance_schedule); 97 1978 : addFunctorProperty<GenericRealVectorValue<is_ad>>( 98 1978 : MathUtils::gradName(MathUtils::timeDerivName(_prop_names[i])), 99 960 : [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad> 100 960 : { return _functors[i]->gradDot(r, t); }, 101 : clearance_schedule); 102 : } 103 : } 104 1847 : } 105 : 106 : template class GenericFunctorMaterialTempl<false>; 107 : template class GenericFunctorMaterialTempl<true>;