LCOV - code coverage report
Current view: top level - src/interfaces - FunctorInterface.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #33416 (b10b36) with base 9fbd27 Lines: 64 64 100.0 %
Date: 2026-07-23 16:15:30 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     2498543 : FunctorInterface::validParams()
      15             : {
      16     2498543 :   return emptyInputParameters();
      17             : }
      18             : 
      19      202277 : FunctorInterface::FunctorInterface(const MooseObject * const moose_object)
      20      404554 :   : _fi_params(moose_object->parameters()),
      21      202277 :     _fi_name(moose_object->name()),
      22      202277 :     _fi_subproblem(_fi_params.get<SubProblem *>("_subproblem")),
      23      404554 :     _fi_tid(_fi_params.get<THREAD_ID>("_tid"))
      24             : {
      25      202277 : }
      26             : 
      27             : #ifdef MOOSE_KOKKOS_ENABLED
      28      121236 : FunctorInterface::FunctorInterface(const FunctorInterface & object,
      29      121236 :                                    const Moose::Kokkos::FunctorCopy &)
      30      121236 :   : _fi_params(object._fi_params),
      31      121236 :     _fi_name(object._fi_name),
      32      121236 :     _fi_subproblem(object._fi_subproblem),
      33      121236 :     _fi_tid(object._fi_tid)
      34             : {
      35      121236 : }
      36             : #endif
      37             : 
      38             : std::string
      39       32288 : FunctorInterface::deduceFunctorName(const std::string & name, const InputParameters & params)
      40             : {
      41       32288 :   if (params.isParamValid(name))
      42             :   {
      43       22973 :     if (params.have_parameter<MooseFunctorName>(name))
      44       22474 :       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        9315 :     return name;
      68             : }
      69             : 
      70             : std::string
      71       32268 : FunctorInterface::deduceFunctorName(const std::string & name) const
      72             : {
      73       32268 :   return deduceFunctorName(name, _fi_params);
      74             : }
      75             : 
      76             : template <>
      77             : const Moose::Functor<Real> *
      78       11382 : FunctorInterface::defaultFunctor(const std::string & name)
      79             : {
      80       11382 :   std::istringstream ss(name);
      81             :   Real real_value;
      82             : 
      83             :   // check if the string parsed cleanly into a Real number
      84       11382 :   if (ss >> real_value && ss.eof())
      85             :   {
      86        4796 :     _default_real_functors.emplace_back(std::make_unique<Moose::Functor<Real>>(
      87        9592 :         std::make_unique<Moose::ConstantFunctor<Real>>(real_value)));
      88        4796 :     auto & default_property = _default_real_functors.back();
      89        4796 :     return default_property.get();
      90             :   }
      91             : 
      92        6586 :   return nullptr;
      93       11382 : }
      94             : 
      95             : template <>
      96             : const Moose::Functor<ADReal> *
      97       17572 : FunctorInterface::defaultFunctor(const std::string & name)
      98             : {
      99       17572 :   std::istringstream ss(name);
     100             :   Real real_value;
     101             : 
     102             :   // check if the string parsed cleanly into a Real number
     103       17572 :   if (ss >> real_value && ss.eof())
     104             :   {
     105        6318 :     _default_ad_real_functors.emplace_back(std::make_unique<Moose::Functor<ADReal>>(
     106       12636 :         std::make_unique<Moose::ConstantFunctor<ADReal>>(real_value)));
     107        6318 :     auto & default_property = _default_ad_real_functors.back();
     108        6318 :     return default_property.get();
     109             :   }
     110             : 
     111       11254 :   return nullptr;
     112       17572 : }
     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     1762873 : FunctorInterface::makeElemArg(const Elem * const elem, const bool correct_skewness) const
     132             : {
     133     1762873 :   return {elem, correct_skewness};
     134             : }

Generated by: LCOV version 1.14