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 "FunctorInterface.h" 11 : #include "MooseFunctor.h" 12 : 13 : InputParameters 14 2466205 : FunctorInterface::validParams() 15 : { 16 2466205 : return emptyInputParameters(); 17 : } 18 : 19 198788 : FunctorInterface::FunctorInterface(const MooseObject * const moose_object) 20 397576 : : _fi_params(moose_object->parameters()), 21 198788 : _fi_name(moose_object->name()), 22 198788 : _fi_subproblem(_fi_params.get<SubProblem *>("_subproblem")), 23 397576 : _fi_tid(_fi_params.get<THREAD_ID>("_tid")) 24 : { 25 198788 : } 26 : 27 : #ifdef MOOSE_KOKKOS_ENABLED 28 121180 : FunctorInterface::FunctorInterface(const FunctorInterface & object, 29 121180 : const Moose::Kokkos::FunctorCopy &) 30 121180 : : _fi_params(object._fi_params), 31 121180 : _fi_name(object._fi_name), 32 121180 : _fi_subproblem(object._fi_subproblem), 33 121180 : _fi_tid(object._fi_tid) 34 : { 35 121180 : } 36 : #endif 37 : 38 : std::string 39 31310 : FunctorInterface::deduceFunctorName(const std::string & name, const InputParameters & params) 40 : { 41 31310 : if (params.isParamValid(name)) 42 : { 43 22380 : if (params.have_parameter<MooseFunctorName>(name)) 44 21881 : return params.get<MooseFunctorName>(name); 45 : // variables, functor material properties, functions, and post-processors are also functors 46 499 : else if (params.have_parameter<MaterialPropertyName>(name)) 47 485 : return params.get<MaterialPropertyName>(name); 48 14 : else if (params.have_parameter<VariableName>(name)) 49 2 : return params.get<VariableName>(name); 50 12 : else if (params.have_parameter<std::vector<VariableName>>(name)) 51 : { 52 4 : const auto & var_names = params.get<std::vector<VariableName>>(name); 53 4 : if (var_names.size() != 1) 54 2 : mooseError("We only support a single variable name for retrieving a functor"); 55 2 : return var_names[0]; 56 : } 57 8 : else if (params.have_parameter<NonlinearVariableName>(name)) 58 2 : return params.get<NonlinearVariableName>(name); 59 6 : else if (params.have_parameter<FunctionName>(name)) 60 2 : return params.get<FunctionName>(name); 61 4 : else if (params.have_parameter<PostprocessorName>(name)) 62 2 : return params.get<PostprocessorName>(name); 63 : else 64 2 : mooseError("Invalid parameter type for retrieving a functor"); 65 : } 66 : else 67 8930 : return name; 68 : } 69 : 70 : std::string 71 31290 : FunctorInterface::deduceFunctorName(const std::string & name) const 72 : { 73 31290 : return deduceFunctorName(name, _fi_params); 74 : } 75 : 76 : template <> 77 : const Moose::Functor<Real> * 78 11001 : FunctorInterface::defaultFunctor(const std::string & name) 79 : { 80 11001 : std::istringstream ss(name); 81 : Real real_value; 82 : 83 : // check if the string parsed cleanly into a Real number 84 11001 : if (ss >> real_value && ss.eof()) 85 : { 86 4706 : _default_real_functors.emplace_back(std::make_unique<Moose::Functor<Real>>( 87 9412 : std::make_unique<Moose::ConstantFunctor<Real>>(real_value))); 88 4706 : auto & default_property = _default_real_functors.back(); 89 4706 : return default_property.get(); 90 : } 91 : 92 6295 : return nullptr; 93 11001 : } 94 : 95 : template <> 96 : const Moose::Functor<ADReal> * 97 16990 : FunctorInterface::defaultFunctor(const std::string & name) 98 : { 99 16990 : std::istringstream ss(name); 100 : Real real_value; 101 : 102 : // check if the string parsed cleanly into a Real number 103 16990 : if (ss >> real_value && ss.eof()) 104 : { 105 6328 : _default_ad_real_functors.emplace_back(std::make_unique<Moose::Functor<ADReal>>( 106 12656 : std::make_unique<Moose::ConstantFunctor<ADReal>>(real_value))); 107 6328 : auto & default_property = _default_ad_real_functors.back(); 108 6328 : return default_property.get(); 109 : } 110 : 111 10662 : return nullptr; 112 16990 : } 113 : 114 : bool 115 506 : FunctorInterface::isFunctor(const std::string & name, const SubProblem & subproblem) const 116 : { 117 : // Check if the supplied parameter is a valid input parameter key 118 506 : std::string functor_name = deduceFunctorName(name); 119 : 120 1012 : return subproblem.hasFunctor(functor_name, _fi_tid); 121 506 : } 122 : 123 : bool 124 506 : FunctorInterface::isFunctor(const std::string & name) const 125 : { 126 : mooseAssert(_fi_subproblem, "This must be non-null"); 127 506 : return isFunctor(name, *_fi_subproblem); 128 : } 129 : 130 : Moose::ElemArg 131 1861084 : FunctorInterface::makeElemArg(const Elem * const elem, const bool correct_skewness) const 132 : { 133 1861084 : return {elem, correct_skewness}; 134 : }