GEOSX
SymbolicFunction.hpp
1 /*
2  * ------------------------------------------------------------------------------------------------------------
3  * SPDX-License-Identifier: LGPL-2.1-only
4  *
5  * Copyright (c) 2018-2020 Lawrence Livermore National Security LLC
6  * Copyright (c) 2018-2020 The Board of Trustees of the Leland Stanford Junior University
7  * Copyright (c) 2018-2020 Total, S.A
8  * Copyright (c) 2019- GEOSX Contributors
9  * All rights reserved
10  *
11  * See top level LICENSE, COPYRIGHT, CONTRIBUTORS, NOTICE, and ACKNOWLEDGEMENTS files for details.
12  * ------------------------------------------------------------------------------------------------------------
13  */
14 #ifndef GEOSX_MANAGERS_FUNCTIONS_SYMBOLICFUNCTION_HPP_
15 #define GEOSX_MANAGERS_FUNCTIONS_SYMBOLICFUNCTION_HPP_
16 
17 #include "FunctionBase.hpp"
18 
19 #include <mathpresso/mathpresso.h>
20 
21 namespace geosx
22 {
23 
30 {
31 public:
33  SymbolicFunction( const std::string & name,
34  dataRepository::Group * const parent );
35 
39  virtual ~SymbolicFunction() override;
40 
45  static string CatalogName() { return "SymbolicFunction"; }
46 
50  virtual void InitializeFunction() override;
51 
59  inline void Evaluate( dataRepository::Group const * const group,
60  real64 const time,
62  real64_array & result ) const override final
63  {
64  FunctionBase::EvaluateT< SymbolicFunction >( group, time, set, result );
65  }
66 
72  inline real64 Evaluate( real64 const * const input ) const override final
73  {
74  return parserExpression.evaluate( reinterpret_cast< void * >( const_cast< real64 * >(input) ) );
75  }
76 
77 
82  void setSymbolicVariableNames( string_array variableNames ) { m_variableNames = variableNames; }
83 
88  void setSymbolicExpression( string expression ) { m_expression = expression; }
89 
90 
91 
92 private:
93  // Symbolic math driver objects
94  mathpresso::Context parserContext;
95  mathpresso::Expression parserExpression;
96 
98  string_array m_variableNames;
99 
101  string m_expression;
102 };
103 
104 
105 } /* namespace geosx */
106 
107 #endif /* GEOSX_MANAGERS_FUNCTIONS_SYMBOLICFUNCTION_HPP_ */
void Evaluate(dataRepository::Group const *const group, real64 const time, SortedArrayView< localIndex const > const &set, real64_array &result) const override final
Method to evaluate a function on a target object.
void setSymbolicVariableNames(string_array variableNames)
Set the symbolic variable names.
virtual void InitializeFunction() override
Initialize the table function.
double real64
64-bit floating point type.
Definition: DataTypes.hpp:136
virtual ~SymbolicFunction() override
The destructor.
void setSymbolicExpression(string expression)
Set the symbolic expression.
static string CatalogName()
The catalog name interface.
std::string string
String type.
Definition: DataTypes.hpp:131
SymbolicFunction(const std::string &name, dataRepository::Group *const parent)
Constructor.
real64 Evaluate(real64 const *const input) const override final
Method to evaluate a function.
This class provides a fixed dimensional resizeable array interface in addition to an interface simila...
Definition: Array.hpp:55