FEDEM Model Database  R8.0
Source code of the FEDEM model database
FFaMathExprFactory.H
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2023 SAP SE
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 // This file is part of FEDEM - https://openfedem.org
7 
13 #ifndef FFA_MATH_EXPR_FACTORY_H
14 #define FFA_MATH_EXPR_FACTORY_H
15 
17 #include <string>
18 #include <vector>
19 #include <map>
20 
21 class FFaMathExpr;
22 class FFaMathVar;
23 
24 
29 class FFaMathExprFactory : public FFaSingelton<FFaMathExprFactory>
30 {
34  virtual ~FFaMathExprFactory() {}
35 
37  friend class FFaSingelton<FFaMathExprFactory>;
38 
39 public:
41  static size_t countArgs(const std::string& expression, const char** vars,
42  std::vector<bool>* present = 0);
43 
45  int create(int id, const std::string& expression,
46  size_t nvar = 1, const char** vars = 0);
47 
49  double getValue(int id, double arg, int& error);
51  double getValue(int id, const double* arg, int& error);
52 
54  double getDiff(int id, double arg, int& error);
56  double getDiff(int id, size_t idArg, const double* arg, int& error);
57 
58 private:
59 
62  {
63  public:
64  std::string estr;
66  std::vector<FFaMathExpr*> diff;
67  std::vector<FFaMathVar*> args;
68 
70  FFaMathFunc() { expr = NULL; }
72  FFaMathFunc(const FFaMathFunc&) = delete;
74  FFaMathFunc& operator=(const FFaMathFunc&) = delete;
76  ~FFaMathFunc();
77  };
78 
79  std::map<int,FFaMathFunc> myIndexMap;
80 
82  using IMIter = std::map<int,FFaMathFunc>::iterator;
84 };
85 
86 #endif
Template for singleton classes.
Class describing a mathematical expression.
Definition: FFaMathExprFactory.H:62
FFaMathFunc()
Default constructor.
Definition: FFaMathExprFactory.H:70
FFaMathFunc(const FFaMathFunc &)=delete
The copy constructor is deleted.
std::vector< FFaMathExpr * > diff
Exression tree for function derivatives.
Definition: FFaMathExprFactory.H:66
FFaMathFunc & operator=(const FFaMathFunc &)=delete
The assignment operator is deleted.
std::string estr
Function expression as text.
Definition: FFaMathExprFactory.H:64
~FFaMathFunc()
The destructor deletes the heap-allocated members.
Definition: FFaMathExprFactory.C:19
FFaMathExpr * expr
Resolved expression tree.
Definition: FFaMathExprFactory.H:65
std::vector< FFaMathVar * > args
Function arguments.
Definition: FFaMathExprFactory.H:67
Singelton class holding all mathematical expression objects.
Definition: FFaMathExprFactory.H:30
int create(int id, const std::string &expression, size_t nvar=1, const char **vars=0)
Creates a new FFaMathFunc instance from the string expression.
Definition: FFaMathExprFactory.C:53
std::map< int, FFaMathFunc > myIndexMap
Definition: FFaMathExprFactory.H:79
double getValue(int id, double arg, int &error)
Evaluates a single-argument math expression.
Definition: FFaMathExprFactory.C:86
virtual ~FFaMathExprFactory()
The destructor is private to allow singelton destruction only.
Definition: FFaMathExprFactory.H:34
FFaMathExprFactory()
The constructor is private to allow singelton construction only.
Definition: FFaMathExprFactory.H:32
static size_t countArgs(const std::string &expression, const char **vars, std::vector< bool > *present=0)
Counts the occurances of arguments vars in expression.
Definition: FFaMathExprFactory.C:29
double getDiff(int id, double arg, int &error)
Evaluates the derivative of a single-argument math expression.
Definition: FFaMathExprFactory.C:121
Definition: FFaMathExpr.H:16
Definition: FFaMathVar.H:15
Template for singleton classes.
Definition: FFaSingelton.H:26