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