complexI.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 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 namespace Foam
29 {
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
34 {}
35 
36 
37 inline complex::complex(const scalar Re, const scalar Im)
38 :
39  re(Re),
40  im(Im)
41 {}
42 
43 
44 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
45 
46 inline scalar complex::Re() const
47 {
48  return re;
49 }
50 
51 
52 inline scalar complex::Im() const
53 {
54  return im;
55 }
56 
57 
58 inline scalar& complex::Re()
59 {
60  return re;
61 }
62 
63 
64 inline scalar& complex::Im()
65 {
66  return im;
67 }
68 
69 
71 {
72  return complex(re, -im);
73 }
74 
75 
76 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
77 
78 inline void complex::operator=(const complex& c)
79 {
80  re = c.re;
81  im = c.im;
82 }
83 
84 
85 inline void complex::operator+=(const complex& c)
86 {
87  re += c.re;
88  im += c.im;
89 }
90 
91 
92 inline void complex::operator-=(const complex& c)
93 {
94  re -= c.re;
95  im -= c.im;
96 }
97 
98 
99 inline void complex::operator*=(const complex& c)
100 {
101  *this = (*this)*c;
102 }
103 
104 
105 inline void complex::operator/=(const complex& c)
106 {
107  *this = *this/c;
108 }
109 
110 
111 inline void complex::operator=(const scalar s)
112 {
113  re = s;
114  im = 0.0;
115 }
116 
117 
118 inline void complex::operator+=(const scalar s)
119 {
120  re += s;
121 }
122 
123 
124 inline void complex::operator-=(const scalar s)
125 {
126  re -= s;
127 }
128 
129 
130 inline void complex::operator*=(const scalar s)
131 {
132  re *= s;
133  im *= s;
134 }
135 
136 
137 inline void complex::operator/=(const scalar s)
138 {
139  re /= s;
140  im /= s;
141 }
142 
143 
145 {
146  return conjugate();
147 }
148 
149 
150 inline bool complex::operator==(const complex& c) const
151 {
152  return (equal(re, c.re) && equal(im, c.im));
153 }
154 
155 
156 inline bool complex::operator!=(const complex& c) const
157 {
158  return !operator==(c);
159 }
160 
161 
162 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
163 
164 
165 inline scalar magSqr(const complex& c)
166 {
167  return (c.re*c.re + c.im*c.im);
168 }
169 
170 
171 inline complex sqr(const complex& c)
172 {
173  return c * c;
174 }
175 
176 
177 inline scalar mag(const complex& c)
178 {
179  return sqrt(magSqr(c));
180 }
181 
182 
183 inline const complex& max(const complex& c1, const complex& c2)
184 {
185  if (mag(c1) > mag(c2))
186  {
187  return c1;
188  }
189  else
190  {
191  return c2;
192  }
193 }
194 
195 
196 inline const complex& min(const complex& c1, const complex& c2)
197 {
198  if (mag(c1) < mag(c2))
199  {
200  return c1;
201  }
202  else
203  {
204  return c2;
205  }
206 }
207 
208 
209 inline complex limit(const complex& c1, const complex& c2)
210 {
211  return complex(limit(c1.re, c2.re), limit(c1.im, c2.im));
212 }
213 
214 
215 inline const complex& sum(const complex& c)
216 {
217  return c;
218 }
219 
220 
221 template<class Cmpt>
222 class Tensor;
223 
224 inline complex transform(const Tensor<scalar>&, const complex c)
225 {
226  return c;
227 }
228 
229 
230 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
231 
232 inline complex operator+(const complex& c1, const complex& c2)
233 {
234  return complex
235  (
236  c1.re + c2.re,
237  c1.im + c2.im
238  );
239 }
240 
241 
242 inline complex operator-(const complex& c)
243 {
244  return complex
245  (
246  -c.re,
247  -c.im
248  );
249 }
250 
251 
252 inline complex operator-(const complex& c1, const complex& c2)
253 {
254  return complex
255  (
256  c1.re - c2.re,
257  c1.im - c2.im
258  );
259 }
260 
261 
262 inline complex operator*(const complex& c1, const complex& c2)
263 {
264  return complex
265  (
266  c1.re*c2.re - c1.im*c2.im,
267  c1.im*c2.re + c1.re*c2.im
268  );
269 }
270 
271 
272 inline complex operator/(const complex& c1, const complex& c2)
273 {
274  scalar sqrC2 = magSqr(c2);
275 
276  return complex
277  (
278  (c1.re*c2.re + c1.im*c2.im)/sqrC2,
279  (c1.im*c2.re - c1.re*c2.im)/sqrC2
280  );
281 }
282 
283 
284 inline complex operator*(const scalar s, const complex& c)
285 {
286  return complex(s*c.re, s*c.im);
287 }
288 
289 
290 inline complex operator*(const complex& c, const scalar s)
291 {
292  return complex(s*c.re, s*c.im);
293 }
294 
295 
296 inline complex operator/(const complex& c, const scalar s)
297 {
298  return complex(c.re/s, c.im/s);
299 }
300 
301 
302 inline complex operator/(const scalar s, const complex& c)
303 {
304  return complex(s/c.re, s/c.im);
305 }
306 
307 
308 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
309 
310 } // End namespace Foam
311 
312 // ************************************************************************* //
complex operator!() const
Definition: complexI.H:144
complex()
Construct null.
Definition: complexI.H:33
friend complex operator+(const complex &, const complex &)
Definition: complexI.H:232
friend const complex & sum(const complex &)
Definition: complexI.H:215
const dimensionedScalar c2
Second radiation constant: default SI units: [m.K].
void operator-=(const complex &)
Definition: complexI.H:92
dimensionedScalar sqrt(const dimensionedScalar &ds)
friend complex sqr(const complex &c)
Definition: complexI.H:171
friend scalar mag(const complex &c)
Definition: complexI.H:177
friend complex operator-(const complex &)
Definition: complexI.H:242
friend const complex & min(const complex &, const complex &)
Definition: complexI.H:196
void operator=(const complex &)
Definition: complexI.H:78
scalar Im() const
Definition: complexI.H:52
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
bool operator!=(const complex &) const
Definition: complexI.H:156
complex conjugate() const
Definition: complexI.H:70
void operator/=(const complex &)
Definition: complexI.H:105
friend const complex & max(const complex &, const complex &)
Definition: complexI.H:183
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
bool equal(const T &s1, const T &s2)
Definition: doubleFloat.H:62
bool operator==(const complex &) const
Definition: complexI.H:150
const dimensionedScalar c
Speed of light in a vacuum.
const dimensionedScalar c1
First radiation constant: default SI units: [W/m2].
friend complex operator*(const complex &, const complex &)
Definition: complexI.H:262
scalar Re() const
Definition: complexI.H:46
Extension to the c++ complex library type.
Definition: complex.H:76
Templated 3D tensor derived from MatrixSpace adding construction from 9 components, element access using xx(), xy() etc. member functions and the inner-product (dot-product) and outer-product of two Vectors (tensor-product) operators.
Definition: complexI.H:222
void operator+=(const complex &)
Definition: complexI.H:85
Namespace for OpenFOAM.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:465
void operator*=(const complex &)
Definition: complexI.H:99