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

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