1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM 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 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 inline complex::complex()
38 inline complex::complex(const scalar Re, const scalar Im)
45 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
47 inline scalar complex::Re() const
53 inline scalar complex::Im() const
59 inline scalar& complex::Re()
65 inline scalar& complex::Im()
71 inline complex complex::conjugate() const
73 return complex(re, -im);
77 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
79 inline const complex& complex::operator=(const complex& c)
87 inline void complex::operator+=(const complex& c)
94 inline void complex::operator-=(const complex& c)
101 inline void complex::operator*=(const complex& c)
107 inline void complex::operator/=(const complex& c)
113 inline const complex& complex::operator=(const scalar s)
121 inline void complex::operator+=(const scalar s)
127 inline void complex::operator-=(const scalar s)
133 inline void complex::operator*=(const scalar s)
140 inline void complex::operator/=(const scalar s)
147 inline complex complex::operator!() const
153 inline bool complex::operator==(const complex& c) const
155 return (equal(re, c.re) && equal(im, c.im));
159 inline bool complex::operator!=(const complex& c) const
161 return !operator==(c);
165 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
168 inline scalar magSqr(const complex& c)
170 return (c.re*c.re + c.im*c.im);
174 inline complex sqr(const complex& c)
180 inline scalar mag(const complex& c)
182 return sqrt(magSqr(c));
186 inline const complex& max(const complex& c1, const complex& c2)
188 if (mag(c1) > mag(c2))
199 inline const complex& min(const complex& c1, const complex& c2)
201 if (mag(c1) < mag(c2))
212 inline complex limit(const complex& c1, const complex& c2)
214 return complex(limit(c1.re, c2.re), limit(c1.im, c2.im));
218 inline const complex& sum(const complex& c)
227 inline complex transform(const Tensor<scalar>&, const complex c)
233 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
235 inline complex operator+(const complex& c1, const complex& c2)
245 inline complex operator-(const complex& c)
255 inline complex operator-(const complex& c1, const complex& c2)
265 inline complex operator*(const complex& c1, const complex& c2)
269 c1.re*c2.re - c1.im*c2.im,
270 c1.im*c2.re + c1.re*c2.im
275 inline complex operator/(const complex& c1, const complex& c2)
277 scalar sqrC2 = magSqr(c2);
281 (c1.re*c2.re + c1.im*c2.im)/sqrC2,
282 (c1.im*c2.re - c1.re*c2.im)/sqrC2
287 inline complex operator*(const scalar s, const complex& c)
289 return complex(s*c.re, s*c.im);
293 inline complex operator*(const complex& c, const scalar s)
295 return complex(s*c.re, s*c.im);
299 inline complex operator/(const complex& c, const scalar s)
301 return complex(c.re/s, c.im/s);
305 inline complex operator/(const scalar s, const complex& c)
307 scalar sqrC2 = magSqr(c);
309 // Bug fix, Hua Shan. 2/Apr/2010
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
320 } // End namespace Foam
322 // ************************************************************************* //