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) 2011-2016 OpenFOAM Foundation
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 "scalar.H"
40 #include "bool.H"
41 #include "word.H"
42 #include "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 void 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 void 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 "complexI.H"
200 
201 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
202 
203 #endif
204 
205 // ************************************************************************* //
complex operator!() const
Definition: complexI.H:144
complex()
Construct null.
Definition: complexI.H:33
static const complex one
Definition: complex.H:94
friend complex operator+(const complex &, const complex &)
Definition: complexI.H:232
friend const complex & sum(const complex &)
Definition: complexI.H:215
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
dimensionedSymmTensor sqr(const dimensionedVector &dv)
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
void operator-=(const complex &)
Definition: complexI.H:92
friend complex sqr(const complex &c)
Definition: complexI.H:171
Template function to specify if the data of a type are contiguous.
dimensionedScalar operator/(const scalar s1, const dimensionedScalar &ds2)
friend Istream & operator>>(Istream &, complex &)
friend scalar mag(const complex &c)
Definition: complexI.H:177
tmp< fvMatrix< Type > > operator*(const DimensionedField< scalar, volMesh > &, const fvMatrix< Type > &)
friend complex operator-(const complex &)
Definition: complexI.H:242
friend const complex & min(const complex &, const complex &)
Definition: complexI.H:196
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
void operator=(const complex &)
Definition: complexI.H:78
complex limit(const complex &, const complex &)
Definition: complexI.H:209
scalar Im() const
Definition: complexI.H:52
friend Ostream & operator<<(Ostream &, const complex &)
bool operator!=(const complex &) const
Definition: complexI.H:156
A class for handling words, derived from string.
Definition: word.H:59
Istream & operator>>(Istream &, directionInfo &)
complex conjugate() const
Definition: complexI.H:70
tmp< fvMatrix< Type > > operator-(const fvMatrix< Type > &)
complex cmptType
Component type.
Definition: complex.H:86
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
dimensioned< scalar > magSqr(const dimensioned< Type > &)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
bool contiguous< complex >()
Data associated with complex type are contiguous.
Definition: complex.H:189
void operator/=(const complex &)
Definition: complexI.H:105
friend const complex & max(const complex &, const complex &)
Definition: complexI.H:183
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
friend scalar magSqr(const complex &c)
Definition: complexI.H:165
friend complex limit(const complex &, const complex &)
Definition: complexI.H:209
friend complex operator/(const complex &, const complex &)
Definition: complexI.H:272
static const complex zero
Definition: complex.H:93
bool operator==(const complex &) const
Definition: complexI.H:150
const dimensionedScalar c
Speed of light in a vacuum.
Ostream & operator<<(Ostream &, const ensightPart &)
static const char *const typeName
Definition: complex.H:91
friend complex operator*(const complex &, const complex &)
Definition: complexI.H:262
dimensioned< scalar > mag(const dimensioned< Type > &)
scalar Re() const
Definition: complexI.H:46
Extension to the c++ complex library type.
Definition: complex.H:76
void operator+=(const complex &)
Definition: complexI.H:85
System bool.
Namespace for OpenFOAM.
void operator*=(const complex &)
Definition: complexI.H:99