1 //                                               -*- C++ -*-
2 /**
3  *  @brief The class that implements the evaluation of an analytical function.
4  *
5  *  Copyright 2005-2021 Airbus-EDF-IMACS-ONERA-Phimeca
6  *
7  *  This library is free software: you can redistribute it and/or modify
8  *  it under the terms of the GNU Lesser General Public License as published by
9  *  the Free Software Foundation, either version 3 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This library is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU Lesser General Public License for more details.
16  *
17  *  You should have received a copy of the GNU Lesser General Public License
18  *  along with this library.  If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef OPENTURNS_SYMBOLICEVALUATION_HXX
23 #define OPENTURNS_SYMBOLICEVALUATION_HXX
24 
25 #include "openturns/EvaluationImplementation.hxx"
26 #include "openturns/SymbolicParser.hxx"
27 #include "openturns/Pointer.hxx"
28 #include "openturns/Evaluation.hxx"
29 
30 BEGIN_NAMESPACE_OPENTURNS
31 
32 /**
33  * @class SymbolicEvaluation
34  *
35  * The class that implement the evaluation of an analytical function.
36  */
37 class OT_API SymbolicEvaluation
38   : public EvaluationImplementation
39 {
40   CLASSNAME
41 public:
42 
43   /** Default constructor */
44   SymbolicEvaluation();
45 
46   /** Default constructor */
47   SymbolicEvaluation(const Description & inputVariablesNames,
48                      const Description & outputVariablesNames,
49                      const Description & formulas);
50 
51   /** Constructor with a single formula and multiple ouutputs */
52   SymbolicEvaluation(const Description & inputVariablesNames,
53                      const Description & outputVariablesNames,
54                      const String & formula);
55 
56   /** Virtual constructor */
57   SymbolicEvaluation * clone() const override;
58 
59   /** Comparison operator */
60   Bool operator ==(const SymbolicEvaluation & other) const;
61 
62   /** String converter */
63   String __repr__() const override;
64   String __str__(const String & offset = "") const override;
65 
66   /** Operator () */
67   using EvaluationImplementation::operator();
68   Point operator() (const Point & inP) const override;
69   Sample operator() (const Sample & inS) const override;
70 
71   /** Accessor for input point dimension */
72   UnsignedInteger getInputDimension() const override;
73 
74   /** Accessor for output point dimension */
75   UnsignedInteger getOutputDimension() const override;
76 
77   /** Get the i-th marginal function */
78   Evaluation getMarginal(const UnsignedInteger i) const override;
79 
80   /** Get the function corresponding to indices components */
81   Evaluation getMarginal(const Indices & indices) const override;
82 
83   /** Accessor to the input variables names */
84   Description getInputVariablesNames() const;
85 
86   /** Accessor to the output variables names */
87   Description getOutputVariablesNames() const;
88 
89   /** Accessor to the formulas */
90   Description getFormulas() const;
91 
92   /** Linearity accessors */
93   Bool isLinear() const override;
94   Bool isLinearlyDependent(const UnsignedInteger index) const override;
95 
96   /** Is it safe to call in parallel? */
97   Bool isParallel() const override;
98 
99   /** Invalid values check accessor */
100   void setCheckOutput(const Bool checkOutput) override;
101 
102   /** Method save() stores the object through the StorageManager */
103   void save(Advocate & adv) const override;
104 
105   /** Method load() reloads the object from the StorageManager */
106   void load(Advocate & adv) override;
107 
108 protected:
109 
110 private:
111   // initialize parser
112   void initialize();
113 
114   friend class SymbolicGradient;
115   friend class SymbolicHessian;
116 
117   Description inputVariablesNames_;
118   Description outputVariablesNames_;
119   Description formulas_;
120 
121   /** A mathematical expression parser from the muParser library */
122   mutable SymbolicParser parser_;
123 
124 }; /* class SymbolicEvaluation */
125 
126 
127 END_NAMESPACE_OPENTURNS
128 
129 #endif /* OPENTURNS_SYMBOLICEVALUATION_HXX */
130