LCOV - code coverage report
Current view: top level - src/interfaces - FunctorInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 419b9d Lines: 57 57 100.0 %
Date: 2025-08-08 20:01:16 Functions: 10 10 100.0 %
Legend: Lines: hit not hit

          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     8702053 : FunctorInterface::validParams()
      15             : {
      16     8702053 :   return emptyInputParameters();
      17             : }
      18             : 
      19      203125 : FunctorInterface::FunctorInterface(const MooseObject * const moose_object)
      20      406250 :   : _fi_params(moose_object->parameters()),
      21      203125 :     _fi_name(_fi_params.get<std::string>("_object_name")),
      22      203125 :     _fi_subproblem(_fi_params.get<SubProblem *>("_subproblem")),
      23      406250 :     _fi_tid(_fi_params.get<THREAD_ID>("_tid"))
      24             : {
      25      203125 : }
      26             : 
      27             : std::string
      28       38040 : FunctorInterface::deduceFunctorName(const std::string & name, const InputParameters & params)
      29             : {
      30       38040 :   if (params.isParamValid(name))
      31             :   {
      32       27288 :     if (params.have_parameter<MooseFunctorName>(name))
      33       26662 :       return params.get<MooseFunctorName>(name);
      34             :     // variables, functor material properties, functions, and post-processors are also functors
      35         626 :     else if (params.have_parameter<MaterialPropertyName>(name))
      36         619 :       return params.get<MaterialPropertyName>(name);
      37           7 :     else if (params.have_parameter<VariableName>(name))
      38           1 :       return params.get<VariableName>(name);
      39           6 :     else if (params.have_parameter<std::vector<VariableName>>(name))
      40             :     {
      41           2 :       const auto & var_names = params.get<std::vector<VariableName>>(name);
      42           2 :       if (var_names.size() != 1)
      43           1 :         mooseError("We only support a single variable name for retrieving a functor");
      44           1 :       return var_names[0];
      45             :     }
      46           4 :     else if (params.have_parameter<NonlinearVariableName>(name))
      47           1 :       return params.get<NonlinearVariableName>(name);
      48           3 :     else if (params.have_parameter<FunctionName>(name))
      49           1 :       return params.get<FunctionName>(name);
      50           2 :     else if (params.have_parameter<PostprocessorName>(name))
      51           1 :       return params.get<PostprocessorName>(name);
      52             :     else
      53           1 :       mooseError("Invalid parameter type for retrieving a functor");
      54             :   }
      55             :   else
      56       10752 :     return name;
      57             : }
      58             : 
      59             : std::string
      60       38030 : FunctorInterface::deduceFunctorName(const std::string & name) const
      61             : {
      62       38030 :   return deduceFunctorName(name, _fi_params);
      63             : }
      64             : 
      65             : template <>
      66             : const Moose::Functor<Real> *
      67       14280 : FunctorInterface::defaultFunctor(const std::string & name)
      68             : {
      69       14280 :   std::istringstream ss(name);
      70             :   Real real_value;
      71             : 
      72             :   // check if the string parsed cleanly into a Real number
      73       14280 :   if (ss >> real_value && ss.eof())
      74             :   {
      75        5192 :     _default_real_functors.emplace_back(std::make_unique<Moose::Functor<Real>>(
      76       10384 :         std::make_unique<Moose::ConstantFunctor<Real>>(real_value)));
      77        5192 :     auto & default_property = _default_real_functors.back();
      78        5192 :     return default_property.get();
      79             :   }
      80             : 
      81        9088 :   return nullptr;
      82       14280 : }
      83             : 
      84             : template <>
      85             : const Moose::Functor<ADReal> *
      86       20183 : FunctorInterface::defaultFunctor(const std::string & name)
      87             : {
      88       20183 :   std::istringstream ss(name);
      89             :   Real real_value;
      90             : 
      91             :   // check if the string parsed cleanly into a Real number
      92       20183 :   if (ss >> real_value && ss.eof())
      93             :   {
      94        7152 :     _default_ad_real_functors.emplace_back(std::make_unique<Moose::Functor<ADReal>>(
      95       14304 :         std::make_unique<Moose::ConstantFunctor<ADReal>>(real_value)));
      96        7152 :     auto & default_property = _default_ad_real_functors.back();
      97        7152 :     return default_property.get();
      98             :   }
      99             : 
     100       13031 :   return nullptr;
     101       20183 : }
     102             : 
     103             : bool
     104         550 : FunctorInterface::isFunctor(const std::string & name, const SubProblem & subproblem) const
     105             : {
     106             :   // Check if the supplied parameter is a valid input parameter key
     107         550 :   std::string functor_name = deduceFunctorName(name);
     108             : 
     109        1100 :   return subproblem.hasFunctor(functor_name, _fi_tid);
     110         550 : }
     111             : 
     112             : bool
     113         550 : FunctorInterface::isFunctor(const std::string & name) const
     114             : {
     115             :   mooseAssert(_fi_subproblem, "This must be non-null");
     116         550 :   return isFunctor(name, *_fi_subproblem);
     117             : }
     118             : 
     119             : Moose::ElemArg
     120     2497614 : FunctorInterface::makeElemArg(const Elem * const elem, const bool correct_skewness) const
     121             : {
     122     2497614 :   return {elem, correct_skewness};
     123             : }

Generated by: LCOV version 1.14