forked from richa-batra/ParticleRobotSimulations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticlebot.h
142 lines (109 loc) · 3.34 KB
/
particlebot.h
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
#ifndef __PARTICLEBOT_H__
#define __PARTICLEBOT_H__
#include <helper_functions.h>
#include "particlebot_kernel.cuh"
#include "vector_functions.h"
#include <curand.h>
#include <curand_kernel.h>
#include <cstdio>
// Particlebot system class
class Particlebot
{
public:
Particlebot(SimParams params);
~Particlebot();
void update(float deltaTime, float sort_interval);
void reset();
float *getArray(ParticlebotArray array);
void setArray(ParticlebotArray array, const float *data, int start, int count);
unsigned int getCurrentReadBuffer() const
{
return posVbo;
}
unsigned int getColorBuffer() const
{
return colorVBO;
}
unsigned int getRadBuffer() const
{
return radVbo;
}
void *getCudaPosVBO() const
{
return (void *)cudaPosVBO;
}
void *getCudaColorVBO() const
{
return (void *)cudaColorVBO;
}
void *getCudaRadVBO() const
{
return (void *)cudaRadVBO;
}
void dumpParticlebot(uint start, uint count, FILE *fp,
float dump_interval, uint testing, float light_x,
float light_y);
void loadFromFile(uint start, uint count, FILE *fp,
float dump_interval);
float2 getWorldOrigin()
{
return params.worldOrigin;
}
float2 getCellSize()
{
return params.cellSize;
}
protected: // methods
Particlebot() {}
uint createVBO(uint size);
void _initialize();
void _finalize();
void initGrid(uint2 size, float spacing, float jitter,
uint numParticles);
void initHexGrid(uint numParticles, float spacing);
protected: // data
// CPU data
float *hPos; // particle positions
float *hVel; // particle velocities
float *hRad; // particle radii
int *hDead;
uint *hCellStart;
uint *hCellEnd;
// GPU data
float *dPos;
float *dVel;
float *dAbsForce_a;
float *dAbsForce_r;
int *dDead;
curandState *dState;
float *dRad; // particle radii
float *dfreq;
float *hfreq;
float *dphase;
float *hphase;
float *dSortedPos;
float *tempPos1;
float *tempPos2;
float *dSortedVel;
float *dSortedRad;
// grid data for sorting method
uint *dGridParticleHash; // grid hash value for each particle
uint *dGridParticleIndex;// particle index for each particle
uint *dCellStart; // index of start of each cell in sorted list
uint *dCellEnd; // index of end of cell
uint posVbo; // vertex buffer object for particle positions
uint colorVBO; // vertex buffer object for colors
uint radVbo; // vertex buffer object for particle radii
float time;
float *cudaPosVBO; // these are the CUDA deviceMem Pos
float *cudaColorVBO; // these are the CUDA deviceMem Color
float *cudaRadVBO; // these are the CUDA deviceMem Radii, only used if not using opengl and dumping data to disk instead
struct cudaGraphicsResource *cuda_posvbo_resource; // handles OpenGL-CUDA exchange
struct cudaGraphicsResource *cuda_colorvbo_resource; // handles OpenGL-CUDA exchange
struct cudaGraphicsResource *cuda_radvbo_resource; // handles OpenGL-CUDA exchange
//struct cudaGraphicsResource *m_cuda_timevbo_resource; // handles OpenGL-CUDA exchange
// params
SimParams params;
uint2 particlebotConfigSize;
};
#endif