1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | 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/>.
24 \*---------------------------------------------------------------------------*/
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 inline complex::complex()
37 inline complex::complex(const scalar Re, const scalar Im)
44 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
46 inline scalar complex::Re() const
52 inline scalar complex::Im() const
58 inline scalar& complex::Re()
64 inline scalar& complex::Im()
70 inline complex complex::conjugate() const
72 return complex(re, -im);
76 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
78 inline const complex& 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 const complex& complex::operator=(const scalar s)
120 inline void complex::operator+=(const scalar s)
126 inline void complex::operator-=(const scalar s)
132 inline void complex::operator*=(const scalar s)
139 inline void complex::operator/=(const scalar s)
146 inline complex complex::operator!() const
152 inline bool complex::operator==(const complex& c) const
154 return (equal(re, c.re) && equal(im, c.im));
158 inline bool complex::operator!=(const complex& c) const
160 return !operator==(c);
164 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
167 inline scalar magSqr(const complex& c)
169 return (c.re*c.re + c.im*c.im);
173 inline complex sqr(const complex& c)
179 inline scalar mag(const complex& c)
181 return sqrt(magSqr(c));
185 inline const complex& max(const complex& c1, const complex& c2)
187 if (mag(c1) > mag(c2))
198 inline const complex& min(const complex& c1, const complex& c2)
200 if (mag(c1) < mag(c2))
211 inline complex limit(const complex& c1, const complex& c2)
213 return complex(limit(c1.re, c2.re), limit(c1.im, c2.im));
217 inline const complex& sum(const complex& c)
226 inline complex transform(const Tensor<scalar>&, const complex c)
232 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
234 inline complex operator+(const complex& c1, const complex& c2)
244 inline complex operator-(const complex& c)
254 inline complex operator-(const complex& c1, const complex& c2)
264 inline complex operator*(const complex& c1, const complex& c2)
268 c1.re*c2.re - c1.im*c2.im,
269 c1.im*c2.re + c1.re*c2.im
274 inline complex operator/(const complex& c1, const complex& c2)
276 scalar sqrC2 = magSqr(c2);
280 (c1.re*c2.re + c1.im*c2.im)/sqrC2,
281 (c1.im*c2.re - c1.re*c2.im)/sqrC2
286 inline complex operator*(const scalar s, const complex& c)
288 return complex(s*c.re, s*c.im);
292 inline complex operator*(const complex& c, const scalar s)
294 return complex(s*c.re, s*c.im);
298 inline complex operator/(const complex& c, const scalar s)
300 return complex(c.re/s, c.im/s);
304 inline complex operator/(const scalar s, const complex& c)
306 scalar sqrC2 = magSqr(c);
308 // Bug fix, Hua Shan. 2/Apr/2010
317 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 } // End namespace Foam
321 // ************************************************************************* //