FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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-2010 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
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your 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, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00027 
00028 namespace Foam
00029 {
00030 
00031 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00032 
00033 inline complex::complex()
00034 {}
00035 
00036 
00037 inline complex::complex(const scalar Re, const scalar Im)
00038 :
00039     re(Re),
00040     im(Im)
00041 {}
00042 
00043 
00044 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00045 
00046 inline scalar complex::Re() const
00047 {
00048     return re;
00049 }
00050 
00051 
00052 inline scalar complex::Im() const
00053 {
00054     return im;
00055 }
00056 
00057 
00058 inline scalar& complex::Re()
00059 {
00060     return re;
00061 }
00062 
00063 
00064 inline scalar& complex::Im()
00065 {
00066     return im;
00067 }
00068 
00069 
00070 inline complex complex::conjugate() const
00071 {
00072     return complex(re, -im);
00073 }
00074 
00075 
00076 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00077 
00078 inline const complex& complex::operator=(const complex& c)
00079 {
00080     re = c.re;
00081     im = c.im;
00082     return *this;
00083 }
00084 
00085 
00086 inline void complex::operator+=(const complex& c)
00087 {
00088     re += c.re;
00089     im += c.im;
00090 }
00091 
00092 
00093 inline void complex::operator-=(const complex& c)
00094 {
00095     re -= c.re;
00096     im -= c.im;
00097 }
00098 
00099 
00100 inline void complex::operator*=(const complex& c)
00101 {
00102     *this = (*this)*c;
00103 }
00104 
00105 
00106 inline void complex::operator/=(const complex& c)
00107 {
00108     *this = *this/c;
00109 }
00110 
00111 
00112 inline const complex& complex::operator=(const scalar s)
00113 {
00114     re = s;
00115     im = 0.0;
00116     return *this;
00117 }
00118 
00119 
00120 inline void complex::operator+=(const scalar s)
00121 {
00122     re += s;
00123 }
00124 
00125 
00126 inline void complex::operator-=(const scalar s)
00127 {
00128     re -= s;
00129 }
00130 
00131 
00132 inline void complex::operator*=(const scalar s)
00133 {
00134     re *= s;
00135     im *= s;
00136 }
00137 
00138 
00139 inline void complex::operator/=(const scalar s)
00140 {
00141     re /= s;
00142     im /= s;
00143 }
00144 
00145 
00146 inline complex complex::operator!() const
00147 {
00148     return conjugate();
00149 }
00150 
00151 
00152 inline bool complex::operator==(const complex& c) const
00153 {
00154     return (equal(re, c.re) && equal(im, c.im));
00155 }
00156 
00157 
00158 inline bool complex::operator!=(const complex& c) const
00159 {
00160     return !operator==(c);
00161 }
00162 
00163 
00164 // * * * * * * * * * * * * * * * Friend Functions  * * * * * * * * * * * * * //
00165 
00166 
00167 inline scalar magSqr(const complex& c)
00168 {
00169     return (c.re*c.re + c.im*c.im);
00170 }
00171 
00172 
00173 inline complex sqr(const complex& c)
00174 {
00175     return c * c;
00176 }
00177 
00178 
00179 inline scalar mag(const complex& c)
00180 {
00181     return sqrt(magSqr(c));
00182 }
00183 
00184 
00185 inline const complex& max(const complex& c1, const complex& c2)
00186 {
00187     if (mag(c1) > mag(c2))
00188     {
00189         return c1;
00190     }
00191     else
00192     {
00193         return c2;
00194     }
00195 }
00196 
00197 
00198 inline const complex& min(const complex& c1, const complex& c2)
00199 {
00200     if (mag(c1) < mag(c2))
00201     {
00202         return c1;
00203     }
00204     else
00205     {
00206         return c2;
00207     }
00208 }
00209 
00210 
00211 inline complex limit(const complex& c1, const complex& c2)
00212 {
00213     return complex(limit(c1.re, c2.re), limit(c1.im, c2.im));
00214 }
00215 
00216 
00217 inline const complex& sum(const complex& c)
00218 {
00219     return c;
00220 }
00221 
00222 
00223 template<class Cmpt>
00224 class Tensor;
00225 
00226 inline complex transform(const Tensor<scalar>&, const complex c)
00227 {
00228     return c;
00229 }
00230 
00231 
00232 // * * * * * * * * * * * * * * * Friend Operators  * * * * * * * * * * * * * //
00233 
00234 inline complex operator+(const complex& c1, const complex& c2)
00235 {
00236     return complex
00237     (
00238         c1.re + c2.re,
00239         c1.im + c2.im
00240     );
00241 }
00242 
00243 
00244 inline complex operator-(const complex& c)
00245 {
00246     return complex
00247     (
00248         -c.re,
00249         -c.im
00250     );
00251 }
00252 
00253 
00254 inline complex operator-(const complex& c1, const complex& c2)
00255 {
00256     return complex
00257     (
00258         c1.re - c2.re,
00259         c1.im - c2.im
00260     );
00261 }
00262 
00263 
00264 inline complex operator*(const complex& c1, const complex& c2)
00265 {
00266     return complex
00267     (
00268         c1.re*c2.re - c1.im*c2.im,
00269         c1.im*c2.re + c1.re*c2.im
00270     );
00271 }
00272 
00273 
00274 inline complex operator/(const complex& c1, const complex& c2)
00275 {
00276     scalar sqrC2 = magSqr(c2);
00277 
00278     return complex
00279     (
00280         (c1.re*c2.re + c1.im*c2.im)/sqrC2,
00281         (c1.im*c2.re - c1.re*c2.im)/sqrC2
00282     );
00283 }
00284 
00285 
00286 inline complex operator*(const scalar s, const complex& c)
00287 {
00288     return complex(s*c.re, s*c.im);
00289 }
00290 
00291 
00292 inline complex operator*(const complex& c, const scalar s)
00293 {
00294     return complex(s*c.re, s*c.im);
00295 }
00296 
00297 
00298 inline complex operator/(const complex& c, const scalar s)
00299 {
00300     return complex(c.re/s, c.im/s);
00301 }
00302 
00303 
00304 inline complex operator/(const scalar s, const complex& c)
00305 {
00306     return complex(s/c.re, s/c.im);
00307 }
00308 
00309 
00310 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00311 
00312 } // End namespace Foam
00313 
00314 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines