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 "GenericFunctorGradientMaterial.h" 11 : #include "Function.h" 12 : 13 : registerMooseObject("MooseApp", GenericFunctorGradientMaterial); 14 : registerMooseObject("MooseApp", ADGenericFunctorGradientMaterial); 15 : 16 : template <bool is_ad> 17 : InputParameters 18 28580 : GenericFunctorGradientMaterialTempl<is_ad>::validParams() 19 : { 20 28580 : InputParameters params = FunctorMaterial::validParams(); 21 57160 : params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS}; 22 28580 : params.addClassDescription( 23 : "FunctorMaterial object for declaring properties that are populated by evaluation of " 24 : "gradients of Functors (a constant, variable, function or functor material property) " 25 : "objects."); 26 28580 : params.addParam<std::vector<std::string>>("prop_names", 27 : "The names of the properties this material will have"); 28 : 29 28580 : params.addParam<std::vector<MooseFunctorName>>("prop_values", 30 : "The corresponding names of the " 31 : "functors which gradient are going to provide " 32 : "the values for the variables"); 33 28580 : return params; 34 28580 : } 35 : 36 : template <bool is_ad> 37 26 : GenericFunctorGradientMaterialTempl<is_ad>::GenericFunctorGradientMaterialTempl( 38 : const InputParameters & parameters) 39 : : FunctorMaterial(parameters), 40 26 : _prop_names(getParam<std::vector<std::string>>("prop_names")), 41 52 : _prop_values(getParam<std::vector<MooseFunctorName>>("prop_values")) 42 : { 43 26 : unsigned int num_names = _prop_names.size(); 44 26 : unsigned int num_values = _prop_values.size(); 45 : 46 26 : if (num_names != num_values) 47 0 : mooseError("Number of prop_names must match the number of prop_values for a " 48 : "GenericFunctorGradientMaterial!"); 49 : 50 : // Check that there is no name conflict, a common mistake with this object 51 52 : for (const auto i : make_range(num_names)) 52 52 : for (const auto j : make_range(num_values)) 53 26 : if (_prop_names[i] == _prop_values[j]) 54 0 : paramError("prop_names", 55 : "prop_names should not be the same as any of the prop_values. They" 56 : " can both be functors, and functors may not have the same name."); 57 : 58 26 : _num_props = num_names; 59 26 : _functors.resize(num_names); 60 : 61 52 : for (const auto i : make_range(_num_props)) 62 26 : _functors[i] = &getFunctor<GenericReal<is_ad>>(_prop_values[i]); 63 : 64 26 : const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end()); 65 52 : for (const auto i : make_range(_num_props)) 66 26 : addFunctorProperty<GenericRealVectorValue<is_ad>>( 67 : _prop_names[i], 68 2240 : [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad> 69 2240 : { return (*_functors[i]).gradient(r, t); }, 70 : clearance_schedule); 71 26 : } 72 : 73 : template class GenericFunctorGradientMaterialTempl<false>; 74 : template class GenericFunctorGradientMaterialTempl<true>;