LCOV - code coverage report
Current view: top level - src/kokkos/functions - KokkosParsedFunction.K (source / functions) Hit Total Coverage
Test: idaholab/moose framework: #32971 (54bef8) with base c6cf66 Lines: 49 53 92.5 %
Date: 2026-05-29 20:35:17 Functions: 4 4 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 "KokkosParsedFunction.h"
      11             : 
      12             : #include "FEProblemBase.h"
      13             : 
      14             : registerKokkosFunction("MooseApp", KokkosParsedFunction);
      15             : 
      16             : InputParameters
      17        2150 : KokkosParsedFunction::validParams()
      18             : {
      19        2150 :   InputParameters params = FunctionBase::validParams();
      20        2150 :   params += MooseParsedFunctionBase::validParams();
      21       12900 :   params.addCustomTypeParam<std::string>(
      22             :       "expression", "FunctionExpression", "The user defined function.");
      23        6468 :   params.addParam<bool>(
      24        4264 :       "print_rpn", false, "Print parsed Reverse Polish Notation (RPN) for debugging.");
      25             : 
      26        2150 :   params.addClassDescription("Function created by parsing a string");
      27             : 
      28        2150 :   return params;
      29           0 : }
      30             : 
      31          66 : KokkosParsedFunction::KokkosParsedFunction(const InputParameters & parameters)
      32             :   : FunctionBase(parameters),
      33             :     MooseParsedFunctionBase(parameters),
      34          18 :     _expression(verifyFunction(getParam<std::string>("expression"))),
      35          18 :     _builder(std::make_unique<Moose::Kokkos::RPNBuilder>(_expression, &_console)),
      36          90 :     _problem(*parameters.getCheckedPointerParam<FEProblemBase *>("_fe_problem_base"))
      37             : {
      38          26 :   _builder->addDefaultVariables();
      39             : 
      40          26 :   std::vector<std::string> symbol_names;
      41             : 
      42          78 :   if (isParamValid("symbol_names"))
      43          51 :     symbol_names = getParam<std::vector<std::string>>("symbol_names");
      44             : 
      45          60 :   for (const auto & name : symbol_names)
      46          34 :     _builder->addVariable(name);
      47             : 
      48          26 :   _builder->build();
      49             : 
      50          78 :   if (getParam<bool>("print_rpn"))
      51             :   {
      52          17 :     _console << std::endl
      53           9 :              << "Reverse Polish Notation (RPN) of KokkosParsedFunction " << name() << ":"
      54           9 :              << std::endl;
      55          17 :     _builder->printRPN(_console);
      56             :   }
      57          26 : }
      58             : 
      59       11285 : KokkosParsedFunction::KokkosParsedFunction(const KokkosParsedFunction & function)
      60             :   : FunctionBase(function),
      61             :     MooseParsedFunctionBase(function.parameters()),
      62       10229 :     _expression(function._expression),
      63       10229 :     _evaluator(function._evaluator),
      64       20458 :     _problem(function._problem)
      65             : {
      66       11285 : }
      67             : 
      68             : void
      69          26 : KokkosParsedFunction::initialSetup()
      70             : {
      71          26 :   std::vector<std::string> symbol_names;
      72          26 :   std::vector<std::string> symbol_values;
      73             : 
      74          78 :   if (isParamValid("symbol_names"))
      75          51 :     symbol_names = getParam<std::vector<std::string>>("symbol_names");
      76          78 :   if (isParamValid("symbol_values"))
      77          51 :     symbol_values = getParam<std::vector<std::string>>("symbol_values");
      78             : 
      79          26 :   _symbol_values.reserve(symbol_values.size());
      80          26 :   _symbol_functions.reserve(symbol_values.size());
      81             : 
      82          60 :   for (const auto i : make_range(symbol_names.size()))
      83             :   {
      84          34 :     if (hasPostprocessorByName(symbol_values[i]))
      85          17 :       _builder->associateScalar(symbol_names[i], &getPostprocessorValueByName(symbol_values[i]));
      86          17 :     else if (_problem.hasKokkosFunction(symbol_values[i]))
      87             :     {
      88           0 :       _symbol_functions.push_back(_problem.getKokkosFunction(symbol_values[i]));
      89           0 :       _builder->associateFunction(symbol_names[i], &_symbol_functions.back());
      90             :     }
      91          17 :     else if (MooseUtils::parsesToReal(symbol_values[i]))
      92             :     {
      93          17 :       _symbol_values.push_back(MooseUtils::convert<Real>(symbol_values[i]));
      94          17 :       _builder->associateScalar(symbol_names[i], &_symbol_values.back());
      95             :     }
      96             :     else
      97           0 :       paramError("symbol_values", "Symbols cannot be scalar variables for now.");
      98             :   }
      99             : 
     100          26 :   _builder->finalize();
     101             : 
     102             :   // Should be called after finalization
     103          26 :   _evaluator.init(*_builder);
     104          26 : }

Generated by: LCOV version 1.14