OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

complexI.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 \*---------------------------------------------------------------------------*/
00026 
00027 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00028 
00029 namespace Foam
00030 {
00031 
00032 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00033 
00034 inline complex::complex()
00035 {}
00036 
00037 
00038 inline complex::complex(const scalar Re, const scalar Im)
00039 :
00040     re(Re),
00041     im(Im)
00042 {}
00043 
00044 
00045 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00046 
00047 inline scalar complex::Re() const
00048 {
00049     return re;
00050 }
00051 
00052 
00053 inline scalar complex::Im() const
00054 {
00055     return im;
00056 }
00057 
00058 
00059 inline scalar& complex::Re()
00060 {
00061     return re;
00062 }
00063 
00064 
00065 inline scalar& complex::Im()
00066 {
00067     return im;
00068 }
00069 
00070 
00071 inline complex complex::conjugate() const
00072 {
00073     return complex(re, -im);
00074 }
00075 
00076 
00077 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00078 
00079 inline const complex& complex::operator=(const complex& c)
00080 {
00081     re = c.re;
00082     im = c.im;
00083     return *this;
00084 }
00085 
00086 
00087 inline void complex::operator+=(const complex& c)
00088 {
00089     re += c.re;
00090     im += c.im;
00091 }
00092 
00093 
00094 inline void complex::operator-=(const complex& c)
00095 {
00096     re -= c.re;
00097     im -= c.im;
00098 }
00099 
00100 
00101 inline void complex::operator*=(const complex& c)
00102 {
00103     *this = (*this)*c;
00104 }
00105 
00106 
00107 inline void complex::operator/=(const complex& c)
00108 {
00109     *this = *this/c;
00110 }
00111 
00112 
00113 inline const complex& complex::operator=(const scalar s)
00114 {
00115     re = s;
00116     im = 0.0;
00117     return *this;
00118 }
00119 
00120 
00121 inline void complex::operator+=(const scalar s)
00122 {
00123     re += s;
00124 }
00125 
00126 
00127 inline void complex::operator-=(const scalar s)
00128 {
00129     re -= s;
00130 }
00131 
00132 
00133 inline void complex::operator*=(const scalar s)
00134 {
00135     re *= s;
00136     im *= s;
00137 }
00138 
00139 
00140 inline void complex::operator/=(const scalar s)
00141 {
00142     re /= s;
00143     im /= s;
00144 }
00145 
00146 
00147 inline complex complex::operator!() const
00148 {
00149     return conjugate();
00150 }
00151 
00152 
00153 inline bool complex::operator==(const complex& c) const
00154 {
00155     return (equal(re, c.re) && equal(im, c.im));
00156 }
00157 
00158 
00159 inline bool complex::operator!=(const complex& c) const
00160 {
00161     return !operator==(c);
00162 }
00163 
00164 
00165 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00166 
00167 
00168 inline scalar magSqr(const complex& c)
00169 {
00170     return (c.re*c.re + c.im*c.im);
00171 }
00172 
00173 
00174 inline complex sqr(const complex& c)
00175 {
00176     return c * c;
00177 }
00178 
00179 
00180 inline scalar mag(const complex& c)
00181 {
00182     return sqrt(magSqr(c));
00183 }
00184 
00185 
00186 inline const complex& max(const complex& c1, const complex& c2)
00187 {
00188     if (mag(c1) > mag(c2))
00189     {
00190         return c1;
00191     }
00192     else
00193     {
00194         return c2;
00195     }
00196 }
00197 
00198 
00199 inline const complex& min(const complex& c1, const complex& c2)
00200 {
00201     if (mag(c1) < mag(c2))
00202     {
00203         return c1;
00204     }
00205     else
00206     {
00207         return c2;
00208     }
00209 }
00210 
00211 
00212 inline complex limit(const complex& c1, const complex& c2)
00213 {
00214     return complex(limit(c1.re, c2.re), limit(c1.im, c2.im));
00215 }
00216 
00217 
00218 inline const complex& sum(const complex& c)
00219 {
00220     return c;
00221 }
00222 
00223 
00224 template<class Cmpt>
00225 class Tensor;
00226 
00227 inline complex transform(const Tensor<scalar>&, const complex c)
00228 {
00229     return c;
00230 }
00231 
00232 
00233 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00234 
00235 inline complex operator+(const complex& c1, const complex& c2)
00236 {
00237     return complex
00238     (
00239         c1.re + c2.re,
00240         c1.im + c2.im
00241     );
00242 }
00243 
00244 
00245 inline complex operator-(const complex& c)
00246 {
00247     return complex
00248     (
00249         -c.re,
00250         -c.im
00251     );
00252 }
00253 
00254 
00255 inline complex operator-(const complex& c1, const complex& c2)
00256 {
00257     return complex
00258     (
00259         c1.re - c2.re,
00260         c1.im - c2.im
00261     );
00262 }
00263 
00264 
00265 inline complex operator*(const complex& c1, const complex& c2)
00266 {
00267     return complex
00268     (
00269         c1.re*c2.re - c1.im*c2.im,
00270         c1.im*c2.re + c1.re*c2.im
00271     );
00272 }
00273 
00274 
00275 inline complex operator/(const complex& c1, const complex& c2)
00276 {
00277     scalar sqrC2 = magSqr(c2);
00278 
00279     return complex
00280     (
00281         (c1.re*c2.re + c1.im*c2.im)/sqrC2,
00282         (c1.im*c2.re - c1.re*c2.im)/sqrC2
00283     );
00284 }
00285 
00286 
00287 inline complex operator*(const scalar s, const complex& c)
00288 {
00289     return complex(s*c.re, s*c.im);
00290 }
00291 
00292 
00293 inline complex operator*(const complex& c, const scalar s)
00294 {
00295     return complex(s*c.re, s*c.im);
00296 }
00297 
00298 
00299 inline complex operator/(const complex& c, const scalar s)
00300 {
00301     return complex(c.re/s, c.im/s);
00302 }
00303 
00304 
00305 inline complex operator/(const scalar s, const complex& c)
00306 {
00307     return complex(s/c.re, s/c.im);
00308 }
00309 
00310 
00311 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00312 
00313 } // End namespace Foam
00314 
00315 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd