GEOS
SymbolicFunction.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2016-2024 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2024 Total, S.A
7  * Copyright (c) 2018-2024 The Board of Trustees of the Leland Stanford Junior University
8  * Copyright (c) 2023-2024 Chevron
9  * Copyright (c) 2019- GEOS/GEOSX Contributors
10  * All rights reserved
11  *
12  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
13  * ------------------------------------------------------------------------------------------------------------
14  */
15 
16 #ifndef GEOS_FUNCTIONS_SYMBOLICFUNCTION_HPP_
17 #define GEOS_FUNCTIONS_SYMBOLICFUNCTION_HPP_
18 
19 #include "FunctionBase.hpp"
20 
21 #include <mathpresso/mathpresso.h>
22 
23 namespace geos
24 {
25 
32 {
33 public:
35  SymbolicFunction( const string & name,
36  dataRepository::Group * const parent );
37 
41  virtual ~SymbolicFunction() override;
42 
47  static string catalogName() { return "SymbolicFunction"; }
48 
52  virtual void initializeFunction() override;
53 
61  inline void evaluate( dataRepository::Group const & group,
62  real64 const time,
64  arrayView1d< real64 > const & result ) const override final
65  {
66  FunctionBase::evaluateT< SymbolicFunction >( group, time, set, result );
67  }
68 
74  inline real64 evaluate( real64 const * const input ) const override final
75  {
76  return parserExpression.evaluate( reinterpret_cast< void * >( const_cast< real64 * >(input) ) );
77  }
78 
79 
84  void setSymbolicVariableNames( string_array variableNames ) { m_variableNames = std::move( variableNames ); }
85 
90  void setSymbolicExpression( string expression ) { m_expression = std::move( expression ); }
91 
92 
93 
94 private:
95  // Symbolic math driver objects
96  mathpresso::Context parserContext;
97  mathpresso::Expression parserExpression;
98 
100  string_array m_variableNames;
101 
103  string m_expression;
104 };
105 
106 
107 } /* namespace geos */
108 
109 #endif /* GEOS_FUNCTIONS_SYMBOLICFUNCTION_HPP_ */
virtual void initializeFunction() override
Initialize the table function.
virtual ~SymbolicFunction() override
The destructor.
real64 evaluate(real64 const *const input) const override final
Method to evaluate a function.
void setSymbolicExpression(string expression)
Set the symbolic expression.
static string catalogName()
The catalog name interface.
void setSymbolicVariableNames(string_array variableNames)
Set the symbolic variable names.
void evaluate(dataRepository::Group const &group, real64 const time, SortedArrayView< localIndex const > const &set, arrayView1d< real64 > const &result) const override final
Method to evaluate a function on a target object.
SymbolicFunction(const string &name, dataRepository::Group *const parent)
Constructor.
ArrayView< T, 1 > arrayView1d
Alias for 1D array view.
Definition: DataTypes.hpp:180
array1d< string > string_array
A 1-dimensional array of geos::string types.
Definition: DataTypes.hpp:392
std::set< T > set
A set of local indices.
Definition: DataTypes.hpp:263
double real64
64-bit floating point type.
Definition: DataTypes.hpp:99
LvArray::SortedArrayView< T, localIndex, LvArray::ChaiBuffer > SortedArrayView
A sorted array view of local indices.
Definition: DataTypes.hpp:271