complex.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 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 
134  inline void operator=(const scalar);
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 
140  inline complex operator!() const;
141 
142  inline bool operator==(const complex&) const;
143  inline bool operator!=(const complex&) const;
144 
145 
146  // Friend Functions
147 
148  friend scalar magSqr(const complex& c);
149  friend complex sqr(const complex& c);
150  friend scalar mag(const complex& c);
151  friend const complex& max(const complex&, const complex&);
152  friend const complex& min(const complex&, const complex&);
153 
154  friend complex limit(const complex&, const complex&);
155 
156  friend const complex& sum(const complex&);
157 
158 
159  // Friend operators
160 
161  friend complex operator+(const complex&, const complex&);
162  friend complex operator-(const complex&);
163  friend complex operator-(const complex&, const complex&);
164  friend complex operator*(const complex&, const complex&);
165  friend complex operator/(const complex&, const complex&);
166 
167  friend complex operator*(const scalar, const complex&);
168  friend complex operator*(const complex&, const scalar);
169  friend complex operator/(const complex&, const scalar);
170  friend complex operator/(const scalar, const complex&);
171 
172 
173  // IOstream Operators
174 
175  friend Istream& operator>>(Istream&, complex&);
176  friend Ostream& operator<<(Ostream&, const complex&);
177 
178 };
179 
180 
181 // * * * * * * * * * * * * * * Global functions * * * * * * * * * * * * * * //
182 
183 //- Return a string representation of a complex
184 word name(const complex&);
185 
186 
187 //- Data associated with complex type are contiguous
188 template<>
189 inline bool contiguous<complex>() {return true;}
190 
191 
192 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
193 
194 } // End namespace Foam
195 
196 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
197 
198 #include "complexI.H"
199 
200 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201 
202 #endif
203 
204 // ************************************************************************* //
complex()
Construct null.
Definition: complexI.H:33
bool operator==(const complex &) const
Definition: complexI.H:143
static const complex one
Definition: complex.H:94
friend complex operator+(const complex &, const complex &)
Definition: complexI.H:225
friend const complex & sum(const complex &)
Definition: complexI.H:208
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
scalar Im() const
Definition: complexI.H:52
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:85
friend complex sqr(const complex &c)
Definition: complexI.H:164
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:170
friend complex operator-(const complex &)
Definition: complexI.H:235
friend const complex & min(const complex &, const complex &)
Definition: complexI.H:189
dimensioned< Type > sum(const DimensionedField< Type, GeoMesh > &df)
complex limit(const complex &, const complex &)
Definition: complexI.H:202
friend Ostream & operator<<(Ostream &, const complex &)
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
void operator=(const scalar)
Definition: complexI.H:104
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 operator!() const
Definition: complexI.H:137
complex cmptType
Component type.
Definition: complex.H:86
tmp< fvMatrix< Type > > operator+(const fvMatrix< Type > &, const fvMatrix< Type > &)
bool operator!=(const complex &) const
Definition: complexI.H:149
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:188
void operator/=(const complex &)
Definition: complexI.H:98
friend const complex & max(const complex &, const complex &)
Definition: complexI.H:176
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:158
friend complex limit(const complex &, const complex &)
Definition: complexI.H:202
friend complex operator/(const complex &, const complex &)
Definition: complexI.H:265
static const complex zero
Definition: complex.H:93
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:255
dimensioned< scalar > mag(const dimensioned< Type > &)
Extension to the c++ complex library type.
Definition: complex.H:76
scalar Re() const
Definition: complexI.H:46
void operator+=(const complex &)
Definition: complexI.H:78
System bool.
Namespace for OpenFOAM.
void operator*=(const complex &)
Definition: complexI.H:92