LCOV - code coverage report
Current view: top level - src/interfaces - FunctorInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 57 57 100.0 %
Date: 2025-07-17 01:28:37 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     8647639 : FunctorInterface::validParams()
      15             : {
      16     8647639 :   return emptyInputParameters();
      17             : }
      18             : 
      19      189192 : FunctorInterface::FunctorInterface(const MooseObject * const moose_object)
      20      378384 :   : _fi_params(moose_object->parameters()),
      21      189192 :     _fi_name(_fi_params.get<std::string>("_object_name")),
      22      189192 :     _fi_subproblem(_fi_params.get<SubProblem *>("_subproblem")),
      23      378384 :     _fi_tid(_fi_params.get<THREAD_ID>("_tid"))
      24             : {
      25      189192 : }
      26             : 
      27             : std::string
      28       33999 : FunctorInterface::deduceFunctorName(const std::string & name, const InputParameters & params)
      29             : {
      30       33999 :   if (params.isParamValid(name))
      31             :   {
      32       24329 :     if (params.have_parameter<MooseFunctorName>(name))
      33       23731 :       return params.get<MooseFunctorName>(name);
      34             :     // variables, functor material properties, functions, and post-processors are also functors
      35         598 :     else if (params.have_parameter<MaterialPropertyName>(name))
      36         591 :       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        9670 :     return name;
      57             : }
      58             : 
      59             : std::string
      60       33989 : FunctorInterface::deduceFunctorName(const std::string & name) const
      61             : {
      62       33989 :   return deduceFunctorName(name, _fi_params);
      63             : }
      64             : 
      65             : template <>
      66             : const Moose::Functor<Real> *
      67       12370 : FunctorInterface::defaultFunctor(const std::string & name)
      68             : {
      69       12370 :   std::istringstream ss(name);
      70             :   Real real_value;
      71             : 
      72             :   // check if the string parsed cleanly into a Real number
      73       12370 :   if (ss >> real_value && ss.eof())
      74             :   {
      75        4170 :     _default_real_functors.emplace_back(std::make_unique<Moose::Functor<Real>>(
      76        8340 :         std::make_unique<Moose::ConstantFunctor<Real>>(real_value)));
      77        4170 :     auto & default_property = _default_real_functors.back();
      78        4170 :     return default_property.get();
      79             :   }
      80             : 
      81        8200 :   return nullptr;
      82       12370 : }
      83             : 
      84             : template <>
      85             : const Moose::Functor<ADReal> *
      86       18273 : FunctorInterface::defaultFunctor(const std::string & name)
      87             : {
      88       18273 :   std::istringstream ss(name);
      89             :   Real real_value;
      90             : 
      91             :   // check if the string parsed cleanly into a Real number
      92       18273 :   if (ss >> real_value && ss.eof())
      93             :   {
      94        6321 :     _default_ad_real_functors.emplace_back(std::make_unique<Moose::Functor<ADReal>>(
      95       12642 :         std::make_unique<Moose::ConstantFunctor<ADReal>>(real_value)));
      96        6321 :     auto & default_property = _default_ad_real_functors.back();
      97        6321 :     return default_property.get();
      98             :   }
      99             : 
     100       11952 :   return nullptr;
     101       18273 : }
     102             : 
     103             : bool
     104         524 : FunctorInterface::isFunctor(const std::string & name, const SubProblem & subproblem) const
     105             : {
     106             :   // Check if the supplied parameter is a valid input parameter key
     107         524 :   std::string functor_name = deduceFunctorName(name);
     108             : 
     109        1048 :   return subproblem.hasFunctor(functor_name, _fi_tid);
     110         524 : }
     111             : 
     112             : bool
     113         524 : FunctorInterface::isFunctor(const std::string & name) const
     114             : {
     115             :   mooseAssert(_fi_subproblem, "This must be non-null");
     116         524 :   return isFunctor(name, *_fi_subproblem);
     117             : }
     118             : 
     119             : Moose::ElemArg
     120     2427758 : FunctorInterface::makeElemArg(const Elem * const elem, const bool correct_skewness) const
     121             : {
     122     2427758 :   return {elem, correct_skewness};
     123             : }

Generated by: LCOV version 1.14