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 "GenericFunctionMaterial.h" 11 : #include "Function.h" 12 : 13 : registerMooseObject("MooseApp", GenericFunctionMaterial); 14 : registerMooseObject("MooseApp", ADGenericFunctionMaterial); 15 : 16 : template <bool is_ad> 17 : InputParameters 18 31260 : GenericFunctionMaterialTempl<is_ad>::validParams() 19 : { 20 31260 : InputParameters params = Material::validParams(); 21 31260 : params.addClassDescription("Material object for declaring properties that are populated by " 22 : "evaluation of Function object."); 23 31260 : params.addParam<std::vector<std::string>>("prop_names", 24 : "The names of the properties this material will have"); 25 31260 : params.addParam<std::vector<FunctionName>>("prop_values", 26 : "The corresponding names of the " 27 : "functions that are going to provide " 28 : "the values for the variables"); 29 31260 : return params; 30 0 : } 31 : 32 : template <bool is_ad> 33 2091 : GenericFunctionMaterialTempl<is_ad>::GenericFunctionMaterialTempl( 34 : const InputParameters & parameters) 35 : : Material(parameters), 36 2091 : _prop_names(getParam<std::vector<std::string>>("prop_names")), 37 4182 : _prop_values(getParam<std::vector<FunctionName>>("prop_values")) 38 : { 39 2091 : unsigned int num_names = _prop_names.size(); 40 2091 : unsigned int num_values = _prop_values.size(); 41 : 42 2091 : if (num_names != num_values) 43 0 : mooseError( 44 : "Number of prop_names must match the number of prop_values for a GenericFunctionMaterial!"); 45 : 46 2091 : _num_props = num_names; 47 : 48 2091 : _properties.resize(num_names); 49 2091 : _functions.resize(num_names); 50 : 51 4992 : for (unsigned int i = 0; i < _num_props; i++) 52 : { 53 2901 : _properties[i] = &declareGenericProperty<Real, is_ad>(_prop_names[i]); 54 2901 : _functions[i] = &getFunctionByName(_prop_values[i]); 55 : } 56 2091 : } 57 : 58 : template <bool is_ad> 59 : void 60 652228 : GenericFunctionMaterialTempl<is_ad>::initQpStatefulProperties() 61 : { 62 652228 : computeQpFunctions(); 63 652228 : } 64 : 65 : template <bool is_ad> 66 : void 67 9921026 : GenericFunctionMaterialTempl<is_ad>::computeQpProperties() 68 : { 69 9921026 : computeQpFunctions(); 70 9921026 : } 71 : 72 : template <bool is_ad> 73 : void 74 10573254 : GenericFunctionMaterialTempl<is_ad>::computeQpFunctions() 75 : { 76 21163532 : for (unsigned int i = 0; i < _num_props; i++) 77 10590278 : (*_properties[i])[_qp] = (*_functions[i]).value(_t, _q_point[_qp]); 78 10573254 : } 79 : 80 : template class GenericFunctionMaterialTempl<false>; 81 : template class GenericFunctionMaterialTempl<true>;