OpenFOAM logo
Open Source CFD Toolkit

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-2005 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     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 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048 
00049 /*---------------------------------------------------------------------------*\
00050                            Class complex Declaration
00051 \*---------------------------------------------------------------------------*/
00052 
00053 class complex
00054 {
00055     // private data
00056 
00057         //- Real and imaginary parts of the complex number
00058         scalar re, im;
00059 
00060 public:
00061 
00062     //- Component type
00063     typedef complex cmptType;
00064 
00065 
00066     // Static data members
00067 
00068         static const char* const typeName;
00069 
00070         static const complex zero;
00071         static const complex one;
00072 
00073 
00074     // Constructors
00075 
00076         //- Construct null
00077         inline complex();
00078 
00079         //- Construct given real and imaginary parts
00080         inline complex(const scalar Re, const scalar Im);
00081 
00082         //- Construct from Istream
00083         complex(Istream&);
00084 
00085 
00086     // Member functions
00087 
00088            // Access
00089 
00090                inline scalar Re() const;
00091                inline scalar Im() const;
00092 
00093            // Edit
00094 
00095                inline scalar& Re();
00096                inline scalar& Im();
00097 
00098            // Operators
00099 
00100                inline complex conjugate() const;
00101 
00102 
00103     // Member operators
00104 
00105         inline void operator=(const complex&);
00106         inline void operator+=(const complex&);
00107         inline void operator-=(const complex&);
00108         inline void operator*=(const complex&);
00109         inline void operator/=(const complex&);
00110 
00111         inline void operator=(const scalar);
00112         inline void operator+=(const scalar);
00113         inline void operator-=(const scalar);
00114         inline void operator*=(const scalar);
00115         inline void operator/=(const scalar);
00116 
00117         inline complex operator!() const;
00118 
00119         inline bool operator==(const complex&) const;
00120         inline bool operator!=(const complex&) const;
00121 
00122 
00123     // Friend functions
00124 
00125         inline friend scalar magSqr(const complex& c);
00126         inline friend complex sqr(const complex& c);
00127         inline friend scalar mag(const complex& c);
00128         inline friend const complex& max(const complex& c1, const complex& c2);
00129         inline friend const complex& min(const complex& c1, const complex& c2);
00130 
00131         inline friend complex limit(const complex& c1, const complex& c2);
00132 
00133         inline friend const complex& sum(const complex& c);
00134 
00135 
00136     // Friend operators
00137 
00138         inline friend complex operator+(const complex&, const complex&);
00139         inline friend complex operator-(const complex&);
00140         inline friend complex operator-(const complex&, const complex&);
00141         inline friend complex operator*(const complex&, const complex&);
00142         inline friend complex operator/(const complex&, const complex&);
00143 
00144         inline friend complex operator*(const scalar, const complex&);
00145         inline friend complex operator*(const complex&, const scalar);
00146         inline friend complex operator/(const complex&, const scalar);
00147         inline friend complex operator/(const scalar, const complex&);
00148 
00149 
00150     // IOstream operators
00151 
00152         friend Istream& operator>>(Istream& is, complex&);
00153         friend Ostream& operator<<(Ostream& os, const complex& C);
00154 
00155 };
00156 
00157 
00158 // * * * * * * * * * * * * * * Global functions  * * * * * * * * * * * * * * //
00159 
00160 //- Return a string representation of a complex
00161 word name(const complex&);
00162 
00163 
00164 //- Allow binary writing for arrays of complex
00165 inline bool writeBinary(const complex*)
00166 {
00167     return true;
00168 }
00169 
00170 
00171 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00172 
00173 } // End namespace Foam
00174 
00175 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00176 
00177 #include "complexI.H"
00178 
00179 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00180 
00181 #endif
00182 
00183 // ************************************************************************* //
For further information go to www.openfoam.org