blob: 0ea6b950649ac4937f9f2d8d7bb16f51ddd3caf8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
/*@@
@file Complex.c
@date Tue Dec 14 12:09:43 1999
@author Tom Goodale
@desc
Complex variable stuff
@enddesc
@@*/
static char *rcsid = "$Header$";
#include <math.h>
#include "cctk.h"
#include "cctk_Complex.h"
/*@@
@routine CCTK_Cmplx
@date Tue Dec 14 12:16:01 1999
@author Tom Goodale
@desc
Turns two reals into a complex number
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_COMPLEX CCTK_Cmplx(CCTK_REAL Re, CCTK_REAL Im)
{
CCTK_COMPLEX complex_number;
complex_number.Re = Re;
complex_number.Im = Im;
return complex_number;
}
/*@@
@routine CCTK_CmplxReal
@date Tue Dec 14 12:22:41 1999
@author Tom Goodale
@desc
Returns the real part of a complex number.
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_REAL CCTK_CmplxReal(CCTK_COMPLEX complex_number)
{
return complex_number.Im;
}
/*@@
@routine CCTK_CmplxImag
@date Tue Dec 14 12:22:41 1999
@author Tom Goodale
@desc
Returns the imaginary part of a complex number.
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_REAL CCTK_CmplxImag(CCTK_COMPLEX complex_number)
{
return complex_number.Im;
}
/*@@
@routine CCTK_CmplxConjg
@date Tue Dec 14 12:22:41 1999
@author Tom Goodale
@desc
Returns the complex conjugate of a complex number.
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_COMPLEX CCTK_CmplxConjg(CCTK_COMPLEX in)
{
CCTK_COMPLEX conjg;
conjg.Re = in.Re;
conjg.Im = -in.Im;
return conjg;
}
/*@@
@routine CCTK_CmplxAbs
@date Tue Dec 14 12:26:33 1999
@author Tom Goodale
@desc
Return the absolute value of a complex number.
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_REAL CCTK_CmplxAbs(CCTK_COMPLEX in)
{
CCTK_REAL cabs;
cabs = sqrt(in.Re*in.Re + in.Im*in.Im);
return cabs;
}
/*@@
@routine CCTK_CmplxAdd
@date Sat Dec 4 12:11:04 1999
@author Gabrielle Allen
@desc
Adds two complex numbers
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_COMPLEX CCTK_CmplxAdd(CCTK_COMPLEX a,CCTK_COMPLEX b)
{
CCTK_COMPLEX add_ab;
add_ab.Re = a.Re + b.Re;
add_ab.Im = a.Im + b.Im;
return add_ab;
}
/*@@
@routine CCTK_CmplxSub
@date Sat Dec 4 12:11:04 1999
@author Gabrielle Allen
@desc
Subtracts two complex numbers
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_COMPLEX CCTK_CmplxSub(CCTK_COMPLEX a,CCTK_COMPLEX b)
{
CCTK_COMPLEX sub_ab;
sub_ab.Re = a.Re - b.Re;
sub_ab.Im = a.Im - b.Im;
return sub_ab;
}
/*@@
@routine CCTK_CmplxMul
@date Sat Dec 4 12:11:04 1999
@author Gabrielle Allen
@desc
Multiplies two complex numbers
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_COMPLEX CCTK_CmplxMul(CCTK_COMPLEX a,CCTK_COMPLEX b)
{
CCTK_COMPLEX mult_ab;
mult_ab.Re = a.Re*b.Re-a.Im*b.Im;
mult_ab.Im = a.Im*b.Re+a.Re*b.Im;
return mult_ab;
}
/*@@
@routine CCTK_CmplxDiv
@date Sat Dec 4 12:11:04 1999
@author Gabrielle Allen
@desc
Divides two complex numbers
@enddesc
@calls
@calledby
@history
@endhistory
@@*/
CCTK_COMPLEX CCTK_CmplxDiv(CCTK_COMPLEX a,CCTK_COMPLEX b)
{
CCTK_COMPLEX div_ab;
CCTK_REAL fac;
fac = b.Re*b.Re+b.Im*b.Im;
if (fac != 0)
{
div_ab.Re = (a.Re*b.Re+a.Im*b.Im)/fac;
div_ab.Im = (a.Im*b.Re-a.Re*b.Im)/fac;
}
else
{
CCTK_WARN(0,"Divide by zero in CCTK_CmplxDiv");
div_ab.Re = 0;
div_ab.Im = 0;
}
return div_ab;
}
/* Routines to be added */
/*
CCTK_CmplxSqrt
CCTK_CmplxSin
CCTK_CmplxCos
CCTK_CmplxLog
CCTK_CmplxExp
*/
|