1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
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 void complex::operator=(const complex& c)
86 inline void complex::operator+=(const complex& c)
93 inline void complex::operator-=(const complex& c)
100 inline void complex::operator*=(const complex& c)
106 inline void complex::operator/=(const complex& c)
112 inline void complex::operator=(const scalar s)
119 inline void complex::operator+=(const scalar s)
125 inline void complex::operator-=(const scalar s)
131 inline void complex::operator*=(const scalar s)
138 inline void complex::operator/=(const scalar s)
145 inline complex complex::operator!() const
151 inline bool complex::operator==(const complex& c) const
153 return (equal(re, c.re) && equal(im, c.im));
157 inline bool complex::operator!=(const complex& c) const
159 return !operator==(c);
163 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
166 inline scalar magSqr(const complex& c)
168 return (c.re*c.re + c.im*c.im);
172 inline complex sqr(const complex& c)
178 inline scalar mag(const complex& c)
180 return sqrt(magSqr(c));
184 inline const complex& max(const complex& c1, const complex& c2)
186 if (mag(c1) > mag(c2))
197 inline const complex& min(const complex& c1, const complex& c2)
199 if (mag(c1) < mag(c2))
210 inline complex limit(const complex& c1, const complex& c2)
212 return complex(limit(c1.re, c2.re), limit(c1.im, c2.im));
216 inline const complex& sum(const complex& c)
225 inline complex transform(const Tensor<scalar>&, const complex c)
231 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
233 inline complex operator+(const complex& c1, const complex& c2)
243 inline complex operator-(const complex& c)
253 inline complex operator-(const complex& c1, const complex& c2)
263 inline complex operator*(const complex& c1, const complex& c2)
267 c1.re*c2.re - c1.im*c2.im,
268 c1.im*c2.re + c1.re*c2.im
273 inline complex operator/(const complex& c1, const complex& c2)
275 scalar sqrC2 = magSqr(c2);
279 (c1.re*c2.re + c1.im*c2.im)/sqrC2,
280 (c1.im*c2.re - c1.re*c2.im)/sqrC2
285 inline complex operator*(const scalar s, const complex& c)
287 return complex(s*c.re, s*c.im);
291 inline complex operator*(const complex& c, const scalar s)
293 return complex(s*c.re, s*c.im);
297 inline complex operator/(const complex& c, const scalar s)
299 return complex(c.re/s, c.im/s);
303 inline complex operator/(const scalar s, const complex& c)
305 return complex(s/c.re, s/c.im);
309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
311 } // End namespace Foam
313 // ************************************************************************* //