1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
5 \\ / A nd | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation, either version 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
28 Forward automatic derivative of the first order. Supports multi-variable
29 derivative, where the number of independent variables is specified at
30 compile-time. Replaces scalar in calculations
36 \*---------------------------------------------------------------------------*/
47 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
52 // * * * * * * Forward declaration of template friend fuctions * * * * * * * //
54 template<int nVars> class FadOne;
57 inline FadOne<nVars> operator+(const FadOne<nVars>&, const FadOne<nVars>&);
60 inline FadOne<nVars> operator+(const double, const FadOne<nVars>&);
63 inline FadOne<nVars> operator+(const FadOne<nVars>&, const double);
66 inline FadOne<nVars> operator-(const FadOne<nVars>&);
69 inline FadOne<nVars> operator-(const FadOne<nVars>&, const FadOne<nVars>&);
72 inline FadOne<nVars> operator-(const double, const FadOne<nVars>&);
75 inline FadOne<nVars> operator-(const FadOne<nVars>&, const double);
78 inline FadOne<nVars> operator*(const FadOne<nVars>&, const FadOne<nVars>&);
81 inline FadOne<nVars> operator*(const double, const FadOne<nVars>&);
84 inline FadOne<nVars> operator*(const FadOne<nVars>&, const double);
87 inline FadOne<nVars> operator/(const FadOne<nVars>&, const FadOne<nVars>&);
90 inline FadOne<nVars> operator/(const double, const FadOne<nVars>&);
93 inline FadOne<nVars> operator/(const FadOne<nVars>&, const double);
96 inline bool operator<(const FadOne<nVars>&, const FadOne<nVars>&);
99 inline bool operator<=(const FadOne<nVars>&, const FadOne<nVars>&);
102 inline bool operator>(const FadOne<nVars>&, const FadOne<nVars>&);
105 inline bool operator>=(const FadOne<nVars>&, const FadOne<nVars>&);
108 inline bool operator==(const FadOne<nVars>&, const FadOne<nVars>&);
111 inline bool operator!=(const FadOne<nVars>&, const FadOne<nVars>&);
114 Istream& operator>>(Istream&, FadOne<nVars>&);
117 Ostream& operator<<(Ostream&, const FadOne<nVars>&);
120 /*---------------------------------------------------------------------------*\
121 Class FadOne Declaration
122 \*---------------------------------------------------------------------------*/
129 //- Length of data list
130 static const label Length = nVars + 1;
132 //- Value and derivatives
133 double data_[Length];
136 // Private Member Functions
142 typedef FadOne<nVars> cmptType;
149 dim = 3, // Dimensionality of space
150 rank = 0, // Rank od Scalar is 0
151 nComponents = 1 // Number of components in FadOne is 1
154 // Static data members
156 static const char* const typeName;
157 static const char* componentNames[];
158 static const FadOne<nVars> zero;
159 static const FadOne<nVars> one;
167 //- Construct from value
168 explicit inline FadOne(const double& v);
170 //- Construct from Istream
171 explicit inline FadOne(Istream&);
173 //- Construct as copy
174 inline FadOne(const FadOne<nVars>&);
177 // Destructor - default
183 inline const double& value() const;
184 inline double& value();
186 //- Return derivative
187 inline const double& deriv(const label i) const;
188 inline double& deriv(const label i);
193 inline void operator=(const double&);
194 inline void operator=(const FadOne<nVars>&);
196 inline void operator+=(const double&);
197 inline void operator+=(const FadOne<nVars>&);
198 inline void operator-=(const double&);
199 inline void operator-=(const FadOne<nVars>&);
200 inline void operator*=(const double&);
201 inline void operator*=(const FadOne<nVars>&);
202 inline void operator/=(const double&);
203 inline void operator/=(const FadOne<nVars>&);
211 friend FadOne<nVars> operator+ <nVars>
213 const FadOne<nVars>&,
217 friend FadOne<nVars> operator+ <nVars>
223 friend FadOne<nVars> operator+ <nVars>
225 const FadOne<nVars>&,
229 friend FadOne<nVars> operator- <nVars>(const FadOne<nVars>&);
231 friend FadOne<nVars> operator- <nVars>
233 const FadOne<nVars>&,
237 friend FadOne<nVars> operator- <nVars>
243 friend FadOne<nVars> operator- <nVars>
245 const FadOne<nVars>&,
249 friend FadOne<nVars> operator* <nVars>
251 const FadOne<nVars>&,
255 friend FadOne<nVars> operator* <nVars>
261 friend FadOne<nVars> operator* <nVars>
263 const FadOne<nVars>&,
267 friend FadOne<nVars> operator/ <nVars>
269 const FadOne<nVars>&,
273 friend FadOne<nVars> operator/ <nVars>
279 friend FadOne<nVars> operator/ <nVars>
281 const FadOne<nVars>&,
285 friend bool operator< <nVars>
287 const FadOne<nVars>&,
291 friend bool operator<= <nVars>
293 const FadOne<nVars>&,
297 friend bool operator> <nVars>
299 const FadOne<nVars>&,
303 friend bool operator>= <nVars>
305 const FadOne<nVars>&,
309 friend bool operator== <nVars>
311 const FadOne<nVars>&,
315 friend bool operator!= <nVars>
317 const FadOne<nVars>&,
322 // IOstream Operators
324 friend Istream& operator>> <nVars>(Istream&, FadOne<nVars>&);
325 friend Ostream& operator<< <nVars>(Ostream&, const FadOne<nVars>&);
329 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
331 } // End namespace Foam
333 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
337 #include "FadOneFunctions.H"
338 #include "FadOneFunctionsI.H"
340 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
344 // ************************************************************************* //