FreeFOAM The Cross-Platform CFD Toolkit
complex.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::complex
26 
27 Description
28  Extension to the c++ complex library type.
29 
30 SourceFiles
31  complexI.H
32  complex.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef complex_H
37 #define complex_H
38 
39 #include <OpenFOAM/scalar.H>
40 #include <OpenFOAM/bool.H>
41 #include <OpenFOAM/word.H>
42 #include <OpenFOAM/contiguous.H>
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward declaration of friend functions and operators
50 
51 class complex;
52 
53 inline scalar magSqr(const complex&);
54 inline complex sqr(const complex&);
55 inline scalar mag(const complex&);
56 inline const complex& max(const complex&, const complex&);
57 inline const complex& min(const complex&, const complex&);
58 inline complex limit(const complex&, const complex&);
59 inline const complex& sum(const complex&);
60 inline complex operator+(const complex&, const complex&);
61 inline complex operator-(const complex&);
62 inline complex operator-(const complex&, const complex&);
63 inline complex operator*(const complex&, const complex&);
64 inline complex operator/(const complex&, const complex&);
65 inline complex operator*(const scalar, const complex&);
66 inline complex operator*(const complex&, const scalar);
67 inline complex operator/(const complex&, const scalar);
68 inline complex operator/(const scalar, const complex&);
69 Istream& operator>>(Istream&, complex&);
70 Ostream& operator<<(Ostream&, const complex&);
71 
72 
73 /*---------------------------------------------------------------------------*\
74  Class complex Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 class complex
78 {
79  // private data
80 
81  //- Real and imaginary parts of the complex number
82  scalar re, im;
83 
84 public:
85 
86  //- Component type
87  typedef complex cmptType;
88 
89 
90  // Static data members
91 
92  static const char* const typeName;
93 
94  static const complex zero;
95  static const complex one;
96 
97 
98  // Constructors
99 
100  //- Construct null
101  inline complex();
102 
103  //- Construct given real and imaginary parts
104  inline complex(const scalar Re, const scalar Im);
105 
106  //- Construct from Istream
107  complex(Istream&);
108 
109 
110  // Member functions
111 
112  // Access
113 
114  inline scalar Re() const;
115  inline scalar Im() const;
116 
117  // Edit
118 
119  inline scalar& Re();
120  inline scalar& Im();
121 
122  // Operators
123 
124  inline complex conjugate() const;
125 
126 
127  // Member operators
128 
129  inline const complex& operator=(const complex&);
130  inline void operator+=(const complex&);
131  inline void operator-=(const complex&);
132  inline void operator*=(const complex&);
133  inline void operator/=(const complex&);
134 
135  inline const complex& operator=(const scalar);
136  inline void operator+=(const scalar);
137  inline void operator-=(const scalar);
138  inline void operator*=(const scalar);
139  inline void operator/=(const scalar);
140 
141  inline complex operator!() const;
142 
143  inline bool operator==(const complex&) const;
144  inline bool operator!=(const complex&) const;
145 
146 
147  // Friend functions
148 
149  friend scalar magSqr(const complex& c);
150  friend complex sqr(const complex& c);
151  friend scalar mag(const complex& c);
152  friend const complex& max(const complex&, const complex&);
153  friend const complex& min(const complex&, const complex&);
154 
155  friend complex limit(const complex&, const complex&);
156 
157  friend const complex& sum(const complex&);
158 
159 
160  // Friend operators
161 
162  friend complex operator+(const complex&, const complex&);
163  friend complex operator-(const complex&);
164  friend complex operator-(const complex&, const complex&);
165  friend complex operator*(const complex&, const complex&);
166  friend complex operator/(const complex&, const complex&);
167 
168  friend complex operator*(const scalar, const complex&);
169  friend complex operator*(const complex&, const scalar);
170  friend complex operator/(const complex&, const scalar);
171  friend complex operator/(const scalar, const complex&);
172 
173 
174  // IOstream operators
175 
176  friend Istream& operator>>(Istream&, complex&);
177  friend Ostream& operator<<(Ostream&, const complex&);
178 
179 };
180 
181 
182 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
183 
184 //- Return a string representation of a complex
185 word name(const complex&);
186 
187 
188 //- Data associated with complex type are contiguous
189 template<>
190 inline bool contiguous<complex>() {return true;}
191 
192 
193 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
194 
195 } // End namespace Foam
196 
197 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
198 
199 #include <OpenFOAM/complexI.H>
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #endif
204 
205 // ************************ vim: set sw=4 sts=4 et: ************************ //