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 "GenericVectorFunctorMaterial.h" 11 : #include "MathUtils.h" 12 : 13 : registerMooseObject("MooseApp", GenericVectorFunctorMaterial); 14 : registerMooseObject("MooseApp", ADGenericVectorFunctorMaterial); 15 : registerMooseObjectRenamed("MooseApp", 16 : GenericConstantVectorFunctorMaterial, 17 : "06/30/2022 24:00", 18 : GenericVectorFunctorMaterial); 19 : registerMooseObjectRenamed("MooseApp", 20 : ADGenericConstantVectorFunctorMaterial, 21 : "06/30/2022 24:00", 22 : ADGenericVectorFunctorMaterial); 23 : 24 : template <bool is_ad> 25 : InputParameters 26 12654 : GenericVectorFunctorMaterialTempl<is_ad>::validParams() 27 : { 28 12654 : InputParameters params = FunctorMaterial::validParams(); 29 37962 : params.set<ExecFlagEnum>("execute_on") = {EXEC_ALWAYS}; 30 25308 : params.addClassDescription( 31 : "FunctorMaterial object for declaring vector properties that are populated by " 32 : "evaluation of functor (constants, functions, variables, matprops) object."); 33 50616 : params.addRequiredParam<std::vector<std::string>>( 34 : "prop_names", "The names of the properties this material will have"); 35 37962 : params.addRequiredParam<std::vector<MooseFunctorName>>( 36 : "prop_values", 37 : "The corresponding names of the " 38 : "functors that are going to provide " 39 : "the values for the vector material properties"); 40 12654 : return params; 41 12654 : } 42 : 43 : template <bool is_ad> 44 212 : GenericVectorFunctorMaterialTempl<is_ad>::GenericVectorFunctorMaterialTempl( 45 : const InputParameters & parameters) 46 : : FunctorMaterial(parameters), 47 212 : _prop_names(getParam<std::vector<std::string>>("prop_names")), 48 848 : _prop_values(getParam<std::vector<MooseFunctorName>>("prop_values")) 49 : { 50 212 : unsigned int num_names = _prop_names.size(); 51 212 : unsigned int num_values = _prop_values.size(); 52 : 53 212 : if (num_names * LIBMESH_DIM != num_values) 54 0 : mooseError("Number of prop_names times three must match the number of prop_values for a " 55 : "GenericVectorFunctorMaterial!"); 56 : 57 : // Check that there is no name conflict, a common mistake with this object 58 424 : for (const auto i : make_range(num_names)) 59 866 : for (const auto j : make_range(num_values)) 60 654 : if (_prop_names[i] == _prop_values[j]) 61 6 : paramError("prop_names", 62 : "prop_names should not be the same as any of the prop_values. They" 63 : " can both be functors, and functors may not have the same name."); 64 : 65 209 : _num_props = num_names; 66 209 : _functors.resize(num_values); 67 : 68 836 : for (const auto i : make_range(num_values)) 69 627 : _functors[i] = &getFunctor<GenericReal<is_ad>>(_prop_values[i]); 70 : 71 209 : const std::set<ExecFlagType> clearance_schedule(_execute_enum.begin(), _execute_enum.end()); 72 418 : for (const auto i : make_range(_num_props)) 73 : { 74 209 : addFunctorProperty<GenericRealVectorValue<is_ad>>( 75 : _prop_names[i], 76 404420 : [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad> 77 : { 78 404420 : return {(*_functors[LIBMESH_DIM * i])(r, t), 79 404420 : (*_functors[LIBMESH_DIM * i + 1])(r, t), 80 504656 : (*_functors[LIBMESH_DIM * i + 2])(r, t)}; 81 : }, 82 : clearance_schedule); 83 209 : addFunctorProperty<GenericRealVectorValue<is_ad>>( 84 209 : MathUtils::timeDerivName(_prop_names[i]), 85 0 : [this, i](const auto & r, const auto & t) -> GenericRealVectorValue<is_ad> 86 : { 87 0 : return {_functors[LIBMESH_DIM * i]->dot(r, t), 88 0 : _functors[LIBMESH_DIM * i + 1]->dot(r, t), 89 0 : _functors[LIBMESH_DIM * i + 2]->dot(r, t)}; 90 : }, 91 : clearance_schedule); 92 : } 93 209 : } 94 : 95 : template class GenericVectorFunctorMaterialTempl<false>; 96 : template class GenericVectorFunctorMaterialTempl<true>;