LCOV - code coverage report
Current view: top level - src/interfaces - FunctorInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 99787a Lines: 64 64 100.0 %
Date: 2025-10-14 20:01:24 Functions: 11 11 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     9986614 : FunctorInterface::validParams()
      15             : {
      16     9986614 :   return emptyInputParameters();
      17             : }
      18             : 
      19      214866 : FunctorInterface::FunctorInterface(const MooseObject * const moose_object)
      20      429732 :   : _fi_params(moose_object->parameters()),
      21      214866 :     _fi_name(moose_object->name()),
      22      214866 :     _fi_subproblem(_fi_params.get<SubProblem *>("_subproblem")),
      23      429732 :     _fi_tid(_fi_params.get<THREAD_ID>("_tid"))
      24             : {
      25      214866 : }
      26             : 
      27             : #ifdef MOOSE_KOKKOS_ENABLED
      28       37959 : FunctorInterface::FunctorInterface(const FunctorInterface & object,
      29       37959 :                                    const Moose::Kokkos::FunctorCopy &)
      30       37959 :   : _fi_params(object._fi_params),
      31       37959 :     _fi_name(object._fi_name),
      32       37959 :     _fi_subproblem(object._fi_subproblem),
      33       37959 :     _fi_tid(object._fi_tid)
      34             : {
      35       37959 : }
      36             : #endif
      37             : 
      38             : std::string
      39       39033 : FunctorInterface::deduceFunctorName(const std::string & name, const InputParameters & params)
      40             : {
      41       39033 :   if (params.isParamValid(name))
      42             :   {
      43       27944 :     if (params.have_parameter<MooseFunctorName>(name))
      44       27310 :       return params.get<MooseFunctorName>(name);
      45             :     // variables, functor material properties, functions, and post-processors are also functors
      46         634 :     else if (params.have_parameter<MaterialPropertyName>(name))
      47         620 :       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       11089 :     return name;
      68             : }
      69             : 
      70             : std::string
      71       39013 : FunctorInterface::deduceFunctorName(const std::string & name) const
      72             : {
      73       39013 :   return deduceFunctorName(name, _fi_params);
      74             : }
      75             : 
      76             : template <>
      77             : const Moose::Functor<Real> *
      78       14753 : FunctorInterface::defaultFunctor(const std::string & name)
      79             : {
      80       14753 :   std::istringstream ss(name);
      81             :   Real real_value;
      82             : 
      83             :   // check if the string parsed cleanly into a Real number
      84       14753 :   if (ss >> real_value && ss.eof())
      85             :   {
      86        5384 :     _default_real_functors.emplace_back(std::make_unique<Moose::Functor<Real>>(
      87       10768 :         std::make_unique<Moose::ConstantFunctor<Real>>(real_value)));
      88        5384 :     auto & default_property = _default_real_functors.back();
      89        5384 :     return default_property.get();
      90             :   }
      91             : 
      92        9369 :   return nullptr;
      93       14753 : }
      94             : 
      95             : template <>
      96             : const Moose::Functor<ADReal> *
      97       20685 : FunctorInterface::defaultFunctor(const std::string & name)
      98             : {
      99       20685 :   std::istringstream ss(name);
     100             :   Real real_value;
     101             : 
     102             :   // check if the string parsed cleanly into a Real number
     103       20685 :   if (ss >> real_value && ss.eof())
     104             :   {
     105        7320 :     _default_ad_real_functors.emplace_back(std::make_unique<Moose::Functor<ADReal>>(
     106       14640 :         std::make_unique<Moose::ConstantFunctor<ADReal>>(real_value)));
     107        7320 :     auto & default_property = _default_ad_real_functors.back();
     108        7320 :     return default_property.get();
     109             :   }
     110             : 
     111       13365 :   return nullptr;
     112       20685 : }
     113             : 
     114             : bool
     115         550 : FunctorInterface::isFunctor(const std::string & name, const SubProblem & subproblem) const
     116             : {
     117             :   // Check if the supplied parameter is a valid input parameter key
     118         550 :   std::string functor_name = deduceFunctorName(name);
     119             : 
     120        1100 :   return subproblem.hasFunctor(functor_name, _fi_tid);
     121         550 : }
     122             : 
     123             : bool
     124         550 : FunctorInterface::isFunctor(const std::string & name) const
     125             : {
     126             :   mooseAssert(_fi_subproblem, "This must be non-null");
     127         550 :   return isFunctor(name, *_fi_subproblem);
     128             : }
     129             : 
     130             : Moose::ElemArg
     131     2510620 : FunctorInterface::makeElemArg(const Elem * const elem, const bool correct_skewness) const
     132             : {
     133     2510620 :   return {elem, correct_skewness};
     134             : }

Generated by: LCOV version 1.14