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

complex.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 Class
00025     Foam::complex
00026 
00027 Description
00028     Extension to the c++ complex library type.
00029 
00030 SourceFiles
00031     complexI.H
00032     complex.C
00033 
00034 \*---------------------------------------------------------------------------*/
00035 
00036 #ifndef complex_H
00037 #define complex_H
00038 
00039 #include <OpenFOAM/scalar.H>
00040 #include <OpenFOAM/bool.H>
00041 #include <OpenFOAM/word.H>
00042 #include <OpenFOAM/contiguous.H>
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 // Forward declaration of friend functions and operators
00050 
00051 class complex;
00052 
00053 inline scalar magSqr(const complex&);
00054 inline complex sqr(const complex&);
00055 inline scalar mag(const complex&);
00056 inline const complex& max(const complex&, const complex&);
00057 inline const complex& min(const complex&, const complex&);
00058 inline complex limit(const complex&, const complex&);
00059 inline const complex& sum(const complex&);
00060 inline complex operator+(const complex&, const complex&);
00061 inline complex operator-(const complex&);
00062 inline complex operator-(const complex&, const complex&);
00063 inline complex operator*(const complex&, const complex&);
00064 inline complex operator/(const complex&, const complex&);
00065 inline complex operator*(const scalar, const complex&);
00066 inline complex operator*(const complex&, const scalar);
00067 inline complex operator/(const complex&, const scalar);
00068 inline complex operator/(const scalar, const complex&);
00069 Istream& operator>>(Istream&, complex&);
00070 Ostream& operator<<(Ostream&, const complex&);
00071 
00072 
00073 /*---------------------------------------------------------------------------*\
00074                            Class complex Declaration
00075 \*---------------------------------------------------------------------------*/
00076 
00077 class complex
00078 {
00079     // private data
00080 
00081         //- Real and imaginary parts of the complex number
00082         scalar re, im;
00083 
00084 public:
00085 
00086     //- Component type
00087     typedef complex cmptType;
00088 
00089 
00090     // Static data members
00091 
00092         static const char* const typeName;
00093 
00094         static const complex zero;
00095         static const complex one;
00096 
00097 
00098     // Constructors
00099 
00100         //- Construct null
00101         inline complex();
00102 
00103         //- Construct given real and imaginary parts
00104         inline complex(const scalar Re, const scalar Im);
00105 
00106         //- Construct from Istream
00107         complex(Istream&);
00108 
00109 
00110     // Member functions
00111 
00112            // Access
00113 
00114                inline scalar Re() const;
00115                inline scalar Im() const;
00116 
00117            // Edit
00118 
00119                inline scalar& Re();
00120                inline scalar& Im();
00121 
00122            // Operators
00123 
00124                inline complex conjugate() const;
00125 
00126 
00127     // Member operators
00128 
00129         inline const complex& operator=(const complex&);
00130         inline void operator+=(const complex&);
00131         inline void operator-=(const complex&);
00132         inline void operator*=(const complex&);
00133         inline void operator/=(const complex&);
00134 
00135         inline const complex& operator=(const scalar);
00136         inline void operator+=(const scalar);
00137         inline void operator-=(const scalar);
00138         inline void operator*=(const scalar);
00139         inline void operator/=(const scalar);
00140 
00141         inline complex operator!() const;
00142 
00143         inline bool operator==(const complex&) const;
00144         inline bool operator!=(const complex&) const;
00145 
00146 
00147     // Friend functions
00148 
00149         friend scalar magSqr(const complex& c);
00150         friend complex sqr(const complex& c);
00151         friend scalar mag(const complex& c);
00152         friend const complex& max(const complex&, const complex&);
00153         friend const complex& min(const complex&, const complex&);
00154 
00155         friend complex limit(const complex&, const complex&);
00156 
00157         friend const complex& sum(const complex&);
00158 
00159 
00160     // Friend operators
00161 
00162         friend complex operator+(const complex&, const complex&);
00163         friend complex operator-(const complex&);
00164         friend complex operator-(const complex&, const complex&);
00165         friend complex operator*(const complex&, const complex&);
00166         friend complex operator/(const complex&, const complex&);
00167 
00168         friend complex operator*(const scalar, const complex&);
00169         friend complex operator*(const complex&, const scalar);
00170         friend complex operator/(const complex&, const scalar);
00171         friend complex operator/(const scalar, const complex&);
00172 
00173 
00174     // IOstream operators
00175 
00176         friend Istream& operator>>(Istream&, complex&);
00177         friend Ostream& operator<<(Ostream&, const complex&);
00178 
00179 };
00180 
00181 
00182 // * * * * * * * * * * * * * * Global functions  * * * * * * * * * * * * * * //
00183 
00184 //- Return a string representation of a complex
00185 word name(const complex&);
00186 
00187 
00188 //- Data associated with complex type are contiguous
00189 template<>
00190 inline bool contiguous<complex>() {return true;}
00191 
00192 
00193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00194 
00195 } // End namespace Foam
00196 
00197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00198 
00199 #include <OpenFOAM/complexI.H>
00200 
00201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00202 
00203 #endif
00204 
00205 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines