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 "FunctionMaterialBase.h" 11 : 12 : template <bool is_ad> 13 : InputParameters 14 91319 : FunctionMaterialBase<is_ad>::validParams() 15 : { 16 91319 : InputParameters params = Material::validParams(); 17 91319 : params.addClassDescription("Material providing a functionalized/parsed material property"); 18 : 19 91319 : params.addDeprecatedParam<std::string>( 20 : "f_name", "Name of the parsed material property", "f_name is deprecated, use property_name"); 21 : // TODO Make required once deprecation is handled, see #19119 22 91319 : params.addParam<std::string>("property_name", "F", "Name of the parsed material property"); 23 91319 : return params; 24 0 : } 25 : 26 : template <bool is_ad> 27 4395 : FunctionMaterialBase<is_ad>::FunctionMaterialBase(const InputParameters & parameters) 28 : : DerivativeMaterialInterface<Material>(parameters), 29 4395 : _F_name(getRenamedParam<std::string>("f_name", "property_name")), 30 8790 : _prop_F(&declareGenericProperty<Real, is_ad>(_F_name)) 31 : { 32 : // fetch names and numbers of all coupled variables 33 4395 : _mapping_is_unique = true; 34 4395 : for (std::set<std::string>::const_iterator it = _pars.coupledVarsBegin(); 35 9312 : it != _pars.coupledVarsEnd(); 36 4917 : ++it) 37 : { 38 : // find the variable in the list of coupled variables 39 4917 : auto vars = _coupled_vars.find(*it); 40 : 41 : // no MOOSE variable was provided for this coupling, add to a list of variables set to constant 42 : // default values 43 4917 : if (vars == _coupled_vars.end()) 44 : { 45 1779 : if (_pars.hasDefaultCoupledValue(*it)) 46 0 : _arg_constant_defaults.push_back(*it); 47 1779 : continue; 48 : } 49 : 50 : // check if we have a 1:1 mapping between parameters and variables 51 3138 : if (vars->second.size() != 1) 52 195 : _mapping_is_unique = false; 53 : 54 : // iterate over all components 55 6510 : for (unsigned int j = 0; j < vars->second.size(); ++j) 56 : { 57 : // make sure each nonlinear variable is coupled in only once 58 3372 : if (std::find(_arg_names.begin(), _arg_names.end(), vars->second[j]->name()) != 59 6744 : _arg_names.end()) 60 0 : mooseError("A nonlinear variable can only be coupled in once."); 61 : 62 : // insert the map values 63 : // unsigned int number = vars->second[j]->number(); 64 3372 : unsigned int number = coupled(*it, j); 65 3372 : _arg_names.push_back(vars->second[j]->name()); 66 3372 : _arg_numbers.push_back(number); 67 3372 : _arg_param_names.push_back(*it); 68 3372 : if (_mapping_is_unique) 69 2943 : _arg_param_numbers.push_back(-1); 70 : else 71 429 : _arg_param_numbers.push_back(j); 72 : 73 : // populate number -> arg index lookup table 74 3372 : unsigned int idx = libMeshVarNumberRemap(number); 75 3372 : if (idx >= _arg_index.size()) 76 3372 : _arg_index.resize(idx + 1, -1); 77 : 78 3372 : _arg_index[idx] = _args.size(); 79 : 80 : // get variable value 81 3372 : _args.push_back(&coupledGenericValue(*it, j)); 82 : } 83 : } 84 : 85 4395 : _nargs = _arg_names.size(); 86 4395 : } 87 : 88 : template <bool is_ad> 89 : const GenericVariableValue<is_ad> & 90 1809 : FunctionMaterialBase<is_ad>::coupledGenericValue(const std::string & var_name, unsigned int comp) 91 : { 92 1809 : return coupledValue(var_name, comp); 93 : } 94 : 95 : template <> 96 : const GenericVariableValue<true> & 97 1563 : FunctionMaterialBase<true>::coupledGenericValue(const std::string & var_name, unsigned int comp) 98 : { 99 1563 : return adCoupledValue(var_name, comp); 100 : } 101 : 102 : // explicit instantiation 103 : template class FunctionMaterialBase<false>; 104 : template class FunctionMaterialBase<true>;