00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 namespace Foam
00033 {
00034
00035
00036
00037 inline complex::complex()
00038 {}
00039
00040
00041 inline complex::complex(const scalar Re, const scalar Im)
00042 :
00043 re(Re),
00044 im(Im)
00045 {}
00046
00047
00048
00049
00050 inline scalar complex::Re() const
00051 {
00052 return re;
00053 }
00054
00055
00056 inline scalar complex::Im() const
00057 {
00058 return im;
00059 }
00060
00061
00062 inline scalar& complex::Re()
00063 {
00064 return re;
00065 }
00066
00067
00068 inline scalar& complex::Im()
00069 {
00070 return im;
00071 }
00072
00073
00074 inline complex complex::conjugate() const
00075 {
00076 return complex(re, -im);
00077 }
00078
00079
00080
00081
00082 inline void complex::operator=(const complex& c)
00083 {
00084 re = c.re;
00085 im = c.im;
00086 }
00087
00088
00089 inline void complex::operator+=(const complex& c)
00090 {
00091 re += c.re;
00092 im += c.im;
00093 }
00094
00095
00096 inline void complex::operator-=(const complex& c)
00097 {
00098 re -= c.re;
00099 im -= c.im;
00100 }
00101
00102
00103 inline void complex::operator*=(const complex& c)
00104 {
00105 *this = (*this)*c;
00106 }
00107
00108
00109 inline void complex::operator/=(const complex& c)
00110 {
00111 *this = *this/c;
00112 }
00113
00114
00115 inline void complex::operator=(const scalar s)
00116 {
00117 re = s;
00118 im = 0.0;
00119 }
00120
00121
00122 inline void complex::operator+=(const scalar s)
00123 {
00124 re += s;
00125 }
00126
00127
00128 inline void complex::operator-=(const scalar s)
00129 {
00130 re -= s;
00131 }
00132
00133
00134 inline void complex::operator*=(const scalar s)
00135 {
00136 re *= s;
00137 im *= s;
00138 }
00139
00140
00141 inline void complex::operator/=(const scalar s)
00142 {
00143 re /= s;
00144 im /= s;
00145 }
00146
00147
00148 inline complex complex::operator!() const
00149 {
00150 return conjugate();
00151 }
00152
00153
00154 inline bool complex::operator==(const complex& c) const
00155 {
00156 return (equal(re, c.re) && equal(im, c.im));
00157 }
00158
00159
00160 inline bool complex::operator!=(const complex& c) const
00161 {
00162 return !operator==(c);
00163 }
00164
00165
00166
00167
00168
00169 inline scalar magSqr(const complex& c)
00170 {
00171 return (c.re*c.re + c.im*c.im);
00172 }
00173
00174
00175 inline complex sqr(const complex& c)
00176 {
00177 return c * c;
00178 }
00179
00180
00181 inline scalar mag(const complex& c)
00182 {
00183 return sqrt(magSqr(c));
00184 }
00185
00186
00187 inline const complex& max(const complex& c1, const complex& c2)
00188 {
00189 if (mag(c1) > mag(c2))
00190 {
00191 return c1;
00192 }
00193 else
00194 {
00195 return c2;
00196 }
00197 }
00198
00199
00200 inline const complex& min(const complex& c1, const complex& c2)
00201 {
00202 if (mag(c1) < mag(c2))
00203 {
00204 return c1;
00205 }
00206 else
00207 {
00208 return c2;
00209 }
00210 }
00211
00212
00213 inline complex limit(const complex& c1, const complex& c2)
00214 {
00215 return complex(limit(c1.re, c2.re), limit(c1.im, c2.im));
00216 }
00217
00218
00219 inline const complex& sum(const complex& c)
00220 {
00221 return c;
00222 }
00223
00224
00225 template<class Cmpt>
00226 class Tensor;
00227
00228 inline complex transform(const Tensor<scalar>&, const complex c)
00229 {
00230 return c;
00231 }
00232
00233
00234
00235
00236 inline complex operator+(const complex& c1, const complex& c2)
00237 {
00238 return complex
00239 (
00240 c1.re+c2.re,
00241 c1.im+c2.im
00242 );
00243 }
00244
00245
00246 inline complex operator-(const complex& c)
00247 {
00248 return complex
00249 (
00250 -c.re,
00251 -c.im
00252 );
00253 }
00254
00255
00256 inline complex operator-(const complex& c1, const complex& c2)
00257 {
00258 return complex
00259 (
00260 c1.re-c2.re,
00261 c1.im-c2.im
00262 );
00263 }
00264
00265
00266 inline complex operator*(const complex& c1, const complex& c2)
00267 {
00268 return complex
00269 (
00270 c1.re*c2.re - c1.im*c2.im,
00271 c1.im*c2.re + c1.re*c2.im
00272 );
00273 }
00274
00275
00276 inline complex operator/(const complex& c1, const complex& c2)
00277 {
00278 scalar sqrC2 = magSqr(c2);
00279
00280 return complex
00281 (
00282 (c1.re*c2.re + c1.im*c2.im)/sqrC2,
00283 (c1.im*c2.re - c1.re*c2.im)/sqrC2
00284 );
00285 }
00286
00287
00288 inline complex operator*(const scalar s, const complex& c)
00289 {
00290 return complex(s*c.re, s*c.im);
00291 }
00292
00293
00294 inline complex operator*(const complex& c, const scalar s)
00295 {
00296 return complex(s*c.re, s*c.im);
00297 }
00298
00299
00300 inline complex operator/(const complex& c, const scalar s)
00301 {
00302 return complex(c.re/s, c.im/s);
00303 }
00304
00305
00306 inline complex operator/(const scalar s, const complex& c)
00307 {
00308 return complex(s/c.re, s/c.im);
00309 }
00310
00311
00312
00313
00314 }
00315
00316