LCOV - code coverage report
Current view: top level - include/functions - THMParsedFunctionWrapper.h (source / functions) Hit Total Coverage
Test: idaholab/moose thermal_hydraulics: #30301 (3b550b) with base 2ad78d Lines: 2 2 100.0 %
Date: 2025-07-30 13:02:48 Functions: 0 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             : #pragma once
      11             : 
      12             : #include "MooseError.h"
      13             : #include "MooseTypes.h"
      14             : #include "ControlData.h"
      15             : #include "libmesh/parsed_function.h"
      16             : #include <string>
      17             : #include <vector>
      18             : 
      19             : class Simulation;
      20             : class FEProblemBase;
      21             : class Function;
      22             : 
      23             : /**
      24             :  * A wrapper class for creating and evaluating parsed functions via the
      25             :  * libMesh::ParsedFunction interface for fparser. It has the same capability as
      26             :  * MooseParsedFunctionWrapper but adds ability to use control data values
      27             :  */
      28             : class THMParsedFunctionWrapper
      29             : {
      30             : public:
      31             :   /**
      32             :    * Class constructor
      33             :    * @param sim Reference to the Simulation object (provides access to ControlData)
      34             :    * @param feproblem Reference to the FEProblemBase object (provides access to Postprocessors)
      35             :    * @param function_str A string that contains the function to evaluate
      36             :    * @param vars A vector of variable names contained within the function
      37             :    * @param vals A vector of variable initial values, matching the variables defined in \c vars
      38             :    */
      39             :   THMParsedFunctionWrapper(Simulation & sim,
      40             :                            FEProblemBase & feproblem,
      41             :                            const std::string & function_str,
      42             :                            const std::vector<std::string> & vars,
      43             :                            const std::vector<std::string> & vals,
      44             :                            const THREAD_ID tid = 0);
      45             : 
      46             :   /**
      47             :    * Perform the evaluation of the libMesh::ParsedFunction
      48             :    */
      49             :   Real evaluate(Real t, const Point & p);
      50             : 
      51             :   /**
      52             :    * Get list of Real-valued control data objects
      53             :    */
      54         122 :   const std::vector<ControlData<Real> *> getRealControlData() { return _cd_real_vals; }
      55             : 
      56             :   /**
      57             :    * Get list of boolean-valued control data objects
      58             :    */
      59         122 :   const std::vector<ControlData<bool> *> getBoolControlData() { return _cd_bool_vals; }
      60             : 
      61             : private:
      62             :   /// Reference to the Simulation object
      63             :   Simulation & _sim;
      64             : 
      65             :   /// Reference to the FEProblemBase object
      66             :   FEProblemBase & _feproblem;
      67             : 
      68             :   /// Reference to the string containing the function to evaluate
      69             :   const std::string & _function_str;
      70             : 
      71             :   /// List of variables supplied from the user
      72             :   const std::vector<std::string> & _vars;
      73             : 
      74             :   /// List of the values for the variables supplied by the user
      75             :   const std::vector<std::string> & _vals_input;
      76             : 
      77             :   /// Storage for the initial values of _vars variables used by the libMesh::ParsedFunction object
      78             :   std::vector<Real> _initial_vals;
      79             : 
      80             :   /// Pointer to the libMesh::ParsedFunction object
      81             :   std::unique_ptr<libMesh::ParsedFunction<Real>> _function_ptr;
      82             : 
      83             :   /// Stores _addr variable indices for each ControlData<Real> value
      84             :   std::vector<unsigned int> _cd_real_index;
      85             : 
      86             :   /// Vector of pointers to Real control data values this parsed function is using
      87             :   std::vector<ControlData<Real> *> _cd_real_vals;
      88             : 
      89             :   /// Stores _addr variable indices for each ControlData<bool> value
      90             :   std::vector<unsigned int> _cd_bool_index;
      91             : 
      92             :   /// Vector of pointers to bool control data values this parsed function is using
      93             :   std::vector<ControlData<bool> *> _cd_bool_vals;
      94             : 
      95             :   /// Stores _addr variable indices for each scalar variable value
      96             :   std::vector<unsigned int> _scalar_index;
      97             : 
      98             :   /// Vector of pointers to scalar variables values
      99             :   std::vector<const VariableValue *> _scalar_vals;
     100             : 
     101             :   /// Stores _addr variable indices for each Function
     102             :   std::vector<unsigned int> _function_index;
     103             : 
     104             :   /// Vector of Functions this parsed function is using
     105             :   std::vector<const Function *> _functions;
     106             : 
     107             :   /// Pointers to the variables that store the values of _vars inside the libMesh::ParsedFunction object
     108             :   std::vector<Real *> _addr;
     109             : 
     110             :   /// The thread id passed from owning object
     111             :   const THREAD_ID _tid;
     112             : 
     113             :   /**
     114             :    * Initialization method that prepares the _vars and _initial_vals for use
     115             :    * by the libMesh::ParsedFunction object allocated in the constructor
     116             :    */
     117             :   void initialize();
     118             : 
     119             :   /**
     120             :    * Updates scalar values for use in the libMesh::ParsedFunction
     121             :    */
     122             :   void update();
     123             : 
     124             :   /**
     125             :    * Updates function values for use in the libMesh::ParsedFunction
     126             :    */
     127             :   void updateFunctionValues(Real t, const Point & pt);
     128             : 
     129             :   /**
     130             :    * Updates control data values for use in the libMesh::ParsedFunction
     131             :    */
     132             :   void updateControlDataValues();
     133             : };

Generated by: LCOV version 1.14