efield.cuh
1.15 KB
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
#include "rts/math/complex.h"
#include "rts/visualization/colormap.h"
namespace rts{
/* This class implements a discrete representation of an electromagnetic field
in 2D. The majority of this representation is done on the GPU.
*/
template<typename P>
class efield
{
private:
bool scalar;
//gpu pointer to the field data
rts::complex<P>* X;
rts::complex<P>* Y;
rts::complex<P>* Z;
//resolution of the discrete field
unsigned int R[2];
public:
efield(unsigned int res0, unsigned int res1, bool _scalar = false)
{
//initialize all pointers to NULL
X = Y = Z = NULL;
R[0] = res0;
R[1] = res1;
//allocate memory on the gpu
cudaMalloc(&X, sizeof(rts::complex<P>) * R[0] * R[1]);
if(!scalar)
{
cudaMalloc(&Y, sizeof(rts::complex<P>) * R[0] * R[1]);
cudaMalloc(&Z, sizeof(rts::complex<P>) * R[0] * R[1]);
}
}
//destructor
~efield()
{
if(X != NULL) cudaFree(X);
if(Y != NULL) cudaFree(Y);
if(Z != NULL) cudaFree(Z);
}
void render(std::string)
{
}
};
} //end namespace rts