FEDEM Solver  R8.0
Source code of the dynamics solver
FFaMathExpr.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 
8 #ifndef FFA_MATH_EXPR_H
9 #define FFA_MATH_EXPR_H
10 
11 class FFaMathVar;
12 class FFaMathFunction;
13 
14 
16 {
17  typedef void (*DoublePtRefFuncType) (double*&);
18 
20  double **pvals;
21  double *ppile;
23 
24  mutable bool containfuncflag;
25 
26 public:
27  enum ROperator
28  {
34  };
35 
37 
40 
41 private:
42  double ValC;
43  const FFaMathVar* pvar;
44 
45 public:
46  FFaMathExpr();
47  FFaMathExpr(double);
48  FFaMathExpr(const FFaMathExpr&);
49  FFaMathExpr(const FFaMathExpr&&);
50  FFaMathExpr(const FFaMathVar&);
51  FFaMathExpr(const char* sp,
52  int nvarp = 0, FFaMathVar** ppvarp = 0,
53  int nfuncp = 0, FFaMathFunction** ppfuncp = 0);
54  ~FFaMathExpr();
55 
56  bool HasError(const FFaMathExpr* = 0) const;
57 
58 private:
60  DoublePtRefFuncType*pf2, double**&pv, double**pv1, double**pv2,
61  double*&pp, double*pp1, double*pp2, FFaMathFunction**&prf,
63  static void BCSimple(DoublePtRefFuncType*&pf, DoublePtRefFuncType*pf1, double**&pv,
64  double**pv1, double*&pp, double*pp1, FFaMathFunction**&prf,
66  static void BCFun(DoublePtRefFuncType*&pf, DoublePtRefFuncType*pf1, double**&pv,
67  double**pv1, double*&pp, double*pp1, FFaMathFunction**&prf,
68  FFaMathFunction**prf1, FFaMathFunction *rf);
69 
70  bool ContainVar(const FFaMathVar&) const;
71  bool ContainFunc(const FFaMathFunction&) const;
72  bool ContainFuncNoRec(const FFaMathFunction&) const;
73 
74  int NMembers() const;
75  FFaMathExpr NthMember(int) const;
76  FFaMathExpr Substitute(const FFaMathVar&, const FFaMathExpr&) const;
77 
78  void Init();
79  void BuildCode();
80  void Destroy();
81 
82 public:
85  bool operator== (const double v) const;
86  bool operator== (const FFaMathExpr&) const;
87  bool operator!= (const FFaMathExpr&) const;
88 
89  FFaMathExpr operator+ () const { return *this; }
90  FFaMathExpr operator- () const;
91  FFaMathExpr operator+ (const FFaMathExpr&) const;
92  FFaMathExpr operator- (const FFaMathExpr&) const;
93  FFaMathExpr operator* (const FFaMathExpr&) const;
94  FFaMathExpr operator/ (const FFaMathExpr&) const;
95  FFaMathExpr operator^ (const FFaMathExpr&) const;
96 
97  double Val() const;
98 
99  FFaMathExpr Diff(const FFaMathVar&) const;
100 };
101 
102 
104 {
105  double* buf;
106 
107 public:
108  double (*pfuncval)(double);
109 
110  char* name;
111  signed char type;
113  int nvars;
115 
116  FFaMathFunction();
117  FFaMathFunction(double (*)(double));
119  FFaMathFunction(const FFaMathExpr&, int, FFaMathVar**);
121 
123 
125 
126  void SetName(const char*);
127 
128  double Val(double*) const;
129 
130  bool operator==(const FFaMathFunction&) const;
131 
133 };
134 
135 #endif
Definition: FFaMathExpr.H:16
bool ContainVar(const FFaMathVar &) const
Checks for a variable in the expression.
Definition: FFaMathExpr.C:948
void(* DoublePtRefFuncType)(double *&)
Definition: FFaMathExpr.H:17
FFaMathFunction * pfunc
Definition: FFaMathExpr.H:39
void Init()
Initializes all members to zero.
Definition: FFaMathExpr.C:24
ROperator op
Definition: FFaMathExpr.H:36
bool operator==(const double v) const
Overloaded equal-to operator for double values.
Definition: FFaMathExpr.C:200
bool operator!=(const FFaMathExpr &) const
Overloaded not-equal-to operator.
Definition: FFaMathExpr.C:245
FFaMathExpr * mmb1
Definition: FFaMathExpr.H:38
int NMembers() const
Returns the number of members of an operation.
Definition: FFaMathExpr.C:1037
ROperator
Definition: FFaMathExpr.H:28
@ Opp
Definition: FFaMathExpr.H:29
@ Add
Definition: FFaMathExpr.H:29
@ Sqrt
Definition: FFaMathExpr.H:29
@ LogicalNotEqual
Definition: FFaMathExpr.H:32
@ LogicalOr
Definition: FFaMathExpr.H:31
@ Min
Definition: FFaMathExpr.H:29
@ Exp
Definition: FFaMathExpr.H:30
@ Acos
Definition: FFaMathExpr.H:30
@ Sin
Definition: FFaMathExpr.H:30
@ LogicalGreater
Definition: FFaMathExpr.H:31
@ Fun
Definition: FFaMathExpr.H:33
@ LogicalGreaterOrEqual
Definition: FFaMathExpr.H:33
@ Tg
Definition: FFaMathExpr.H:30
@ Num
Definition: FFaMathExpr.H:29
@ Mult
Definition: FFaMathExpr.H:29
@ LogicalLessOrEqual
Definition: FFaMathExpr.H:33
@ NthRoot
Definition: FFaMathExpr.H:30
@ LogicalNot
Definition: FFaMathExpr.H:33
@ Pow
Definition: FFaMathExpr.H:29
@ Ln
Definition: FFaMathExpr.H:30
@ Max
Definition: FFaMathExpr.H:29
@ E10
Definition: FFaMathExpr.H:30
@ Asin
Definition: FFaMathExpr.H:30
@ LogicalLess
Definition: FFaMathExpr.H:31
@ Log
Definition: FFaMathExpr.H:30
@ LogicalAnd
Definition: FFaMathExpr.H:31
@ Var
Definition: FFaMathExpr.H:29
@ Sub
Definition: FFaMathExpr.H:29
@ Abs
Definition: FFaMathExpr.H:30
@ Div
Definition: FFaMathExpr.H:29
@ Mod
Definition: FFaMathExpr.H:29
@ LogicalEqual
Definition: FFaMathExpr.H:32
@ ErrOp
Definition: FFaMathExpr.H:29
@ Juxt
Definition: FFaMathExpr.H:29
@ Atan
Definition: FFaMathExpr.H:30
@ Cos
Definition: FFaMathExpr.H:30
bool ContainFuncNoRec(const FFaMathFunction &) const
Checks if the operation is a sub-function.
Definition: FFaMathExpr.C:967
double * ppile
Definition: FFaMathExpr.H:21
static void BCDouble(DoublePtRefFuncType *&pf, DoublePtRefFuncType *pf1, DoublePtRefFuncType *pf2, double **&pv, double **pv1, double **pv2, double *&pp, double *pp1, double *pp2, FFaMathFunction **&prf, FFaMathFunction **prf1, FFaMathFunction **prf2, DoublePtRefFuncType f)
Sets a lot of parameters when the function has two operands.
Definition: FFaMathExpr.C:1258
FFaMathExpr Substitute(const FFaMathVar &, const FFaMathExpr &) const
Replaces the variable var with the expression rop.
Definition: FFaMathExpr.C:1087
void Destroy()
Destructor of class FFaMathExpr.
Definition: FFaMathExpr.C:902
double Val() const
Returns the value of the total expression.
Definition: FFaMathExpr.C:1228
double ** pvals
Definition: FFaMathExpr.H:20
FFaMathExpr operator-() const
Overloaded negation operator.
Definition: FFaMathExpr.C:279
static void BCFun(DoublePtRefFuncType *&pf, DoublePtRefFuncType *pf1, double **&pv, double **pv1, double *&pp, double *pp1, FFaMathFunction **&prf, FFaMathFunction **prf1, FFaMathFunction *rf)
Sets a lot of parameters when the operation is a function.
Definition: FFaMathExpr.C:1374
FFaMathFunction ** pfuncpile
Definition: FFaMathExpr.H:22
bool containfuncflag
Definition: FFaMathExpr.H:24
FFaMathExpr Diff(const FFaMathVar &) const
Differentiate the expression.
Definition: FFaMathExpr.C:1117
FFaMathExpr * mmb2
Definition: FFaMathExpr.H:38
bool HasError(const FFaMathExpr *=0) const
Checks if this expression contains errors.
Definition: FFaMathExpr.C:1011
FFaMathExpr operator/(const FFaMathExpr &) const
Overloaded division operator.
Definition: FFaMathExpr.C:392
FFaMathExpr NthMember(int) const
Returns the n'th member of an operation.
Definition: FFaMathExpr.C:1055
FFaMathExpr & operator=(const FFaMathExpr &)
Overloaded copy assignment operator.
Definition: FFaMathExpr.C:145
void BuildCode()
Builds a tree of variables, numbers, operations and functions.
Definition: FFaMathExpr.C:1421
double ValC
Definition: FFaMathExpr.H:42
static void BCSimple(DoublePtRefFuncType *&pf, DoublePtRefFuncType *pf1, double **&pv, double **pv1, double *&pp, double *pp1, FFaMathFunction **&prf, FFaMathFunction **prf1, DoublePtRefFuncType f)
Sets a lot of parameters when the function has two operands.
Definition: FFaMathExpr.C:1326
FFaMathExpr()
Default constructor of class FFaMathExpr.
Definition: FFaMathExpr.C:43
bool ContainFunc(const FFaMathFunction &) const
Recursive check for a sub-function.
Definition: FFaMathExpr.C:986
FFaMathExpr operator^(const FFaMathExpr &) const
Overloaded power operator.
Definition: FFaMathExpr.C:425
DoublePtRefFuncType * pinstr
Definition: FFaMathExpr.H:19
~FFaMathExpr()
Destructor of class FFaMathExpr.
Definition: FFaMathExpr.C:53
FFaMathExpr operator*(const FFaMathExpr &) const
Overload multiplication operator.
Definition: FFaMathExpr.C:359
const FFaMathVar * pvar
Definition: FFaMathExpr.H:43
FFaMathExpr operator+() const
Definition: FFaMathExpr.H:89
Definition: FFaMathExpr.H:104
int nvars
Definition: FFaMathExpr.H:113
signed char type
Definition: FFaMathExpr.H:111
double * buf
Definition: FFaMathExpr.H:105
double(* pfuncval)(double)
Definition: FFaMathExpr.H:108
FFaMathFunction(const FFaMathFunction &)=delete
FFaMathFunction()
An object of type FFaMathFunction is created. Constructor.
Definition: FFaMathFunction.C:19
bool operator==(const FFaMathFunction &) const
Overloaded equal-to operator.
Definition: FFaMathFunction.C:165
char * name
Definition: FFaMathExpr.H:110
~FFaMathFunction()
Destructor.
Definition: FFaMathFunction.C:97
double Val(double *) const
Returns the function value.
Definition: FFaMathFunction.C:127
FFaMathVar ** ppvar
Definition: FFaMathExpr.H:114
FFaMathFunction & operator=(const FFaMathFunction &)=delete
void SetName(const char *)
Sets the name of the function.
Definition: FFaMathFunction.C:114
FFaMathExpr operator()(const FFaMathExpr &)
Definition: FFaMathFunction.C:151
FFaMathExpr op
Definition: FFaMathExpr.H:112
Definition: FFaMathVar.H:15
integer, parameter sp
4-byte real (single)
Definition: kindModule.f90:25