3f56f1f9
dmayerich
initial commit
|
1
2
3
4
5
6
7
8
9
10
|
#include "fieldslice.h"
#include "dataTypes.h"
#include "cufft.h"
#include <iostream>
#include <stdlib.h>
using namespace std;
fieldslice::fieldslice(unsigned int x_size, unsigned int y_size)
|
51b6469a
dmayerich
added look-up tables
|
11
12
13
|
{
x_hat = y_hat = z_hat = NULL;
|
3f56f1f9
dmayerich
initial commit
|
14
15
16
17
18
19
|
//save the slice resolution
R[0] = x_size;
R[1] = x_size;
scalarField = true;
|
51b6469a
dmayerich
added look-up tables
|
20
|
init_gpu();
|
3f56f1f9
dmayerich
initial commit
|
21
22
23
24
25
26
27
|
}
void fieldslice::toAngularSpectrum()
{
cufftHandle plan;
|
e70a251f
dmayerich
fixed double prec...
|
28
|
cufftResult result;
|
3f56f1f9
dmayerich
initial commit
|
29
30
|
//create a CUFFT plan handle
|
e70a251f
dmayerich
fixed double prec...
|
31
32
33
34
35
36
37
|
#ifdef PRECISION_SINGLE
result = cufftPlan2d(&plan, R[0], R[1], CUFFT_C2C);
#elif defined PRECISION_DOUBLE
result = cufftPlan2d(&plan, R[0], R[1], CUFFT_Z2Z);
#endif
if(result != CUFFT_SUCCESS)
|
3f56f1f9
dmayerich
initial commit
|
38
39
40
41
42
43
|
{
cout<<"Error creating CUFFT plan for computing the angular spectrum."<<endl;
exit(1);
}
#ifdef PRECISION_SINGLE
|
e70a251f
dmayerich
fixed double prec...
|
44
|
result = cufftExecC2C(plan, (cufftComplex*)x_hat, (cufftComplex*)x_hat, CUFFT_FORWARD);
|
3f56f1f9
dmayerich
initial commit
|
45
|
#elif defined PRECISION_DOUBLE
|
e70a251f
dmayerich
fixed double prec...
|
46
|
result = cufftExecZ2Z(plan, (cufftDoubleComplex*)x_hat, (cufftDoubleComplex*)x_hat, CUFFT_FORWARD);
|
3f56f1f9
dmayerich
initial commit
|
47
|
#endif
|
e70a251f
dmayerich
fixed double prec...
|
48
|
if(result != CUFFT_SUCCESS)
|
3f56f1f9
dmayerich
initial commit
|
49
50
51
52
53
54
55
56
57
58
59
60
61
|
{
cout<<"Error executing the CUFFT forward FFT to compute the angular spectrum."<<endl;
exit(1);
}
cufftDestroy(plan);
}
void fieldslice::fromAngularSpectrum()
{
cufftHandle plan;
|
e70a251f
dmayerich
fixed double prec...
|
62
|
cufftResult result;
|
3f56f1f9
dmayerich
initial commit
|
63
64
|
//create a CUFFT plan handle
|
e70a251f
dmayerich
fixed double prec...
|
65
66
67
68
69
70
71
|
#ifdef PRECISION_SINGLE
result = cufftPlan2d(&plan, R[0], R[1], CUFFT_C2C);
#elif defined PRECISION_DOUBLE
result = cufftPlan2d(&plan, R[0], R[1], CUFFT_Z2Z);
#endif
if(result != CUFFT_SUCCESS)
|
3f56f1f9
dmayerich
initial commit
|
72
73
74
75
76
77
|
{
cout<<"Error creating CUFFT plan for computing the angular spectrum."<<endl;
exit(1);
}
#ifdef PRECISION_SINGLE
|
e70a251f
dmayerich
fixed double prec...
|
78
|
result = cufftExecC2C(plan, (cufftComplex*)x_hat, (cufftComplex*)x_hat, CUFFT_INVERSE);
|
3f56f1f9
dmayerich
initial commit
|
79
|
#elif defined PRECISION_DOUBLE
|
e70a251f
dmayerich
fixed double prec...
|
80
|
result = cufftExecZ2Z(plan, (cufftDoubleComplex*)x_hat, (cufftDoubleComplex*)x_hat, CUFFT_INVERSE);
|
3f56f1f9
dmayerich
initial commit
|
81
|
#endif
|
e70a251f
dmayerich
fixed double prec...
|
82
|
if(result != CUFFT_SUCCESS)
|
3f56f1f9
dmayerich
initial commit
|
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
{
cout<<"Error executing the CUFFT forward FFT to compute the angular spectrum."<<endl;
exit(1);
}
//divide the field by the number of values in the field
ScaleField( 1.0 / (R[0] * R[1]));
cufftDestroy(plan);
}
fieldslice::fieldslice()
{
R[0] = R[1] = 0;
x_hat = y_hat = z_hat = NULL;
}
fieldslice::~fieldslice()
{
|
51b6469a
dmayerich
added look-up tables
|
106
|
kill_gpu();
|
3f56f1f9
dmayerich
initial commit
|
107
|
}
|