-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHostDeviceCode.h
More file actions
115 lines (93 loc) · 2.54 KB
/
HostDeviceCode.h
File metadata and controls
115 lines (93 loc) · 2.54 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
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
#ifndef HOSTDEVICECODE_H
#define HOSTDEVICECODE_H
#include <cstdio>
#include <cstdlib>
#include <cuda_runtime.h>
#include "Common.h"
#define CudaCheck(call) { CudaCallWithCheck((call), __FILE__, __LINE__, #call); }
inline void CudaCallWithCheck(cudaError_t ReturnCode, const char* Filename, int LineNumber, const char* LineCode, bool bDoAbort = true)
{
if (ReturnCode != cudaSuccess)
{
fprintf(stderr, "[ERROR] %s (%s: %d)\n \"%s\"\n", cudaGetErrorString(ReturnCode), Filename, LineNumber, LineCode);
if (bDoAbort) exit(ReturnCode);
}
}
enum {
SYMPLECTIC_EULER = 0,
FORWARD_EULER
};
struct MSSParameters
{
float Gravity;
float FloorHeight;
float FloorStrength;
float Damping;
float YoungModulus;
float PoissonRatio;
float TotalMass;
bool bFixedTop;
float DeltaT;
uint NumParticles;
uint NumSprings;
uint IntegrationMethod;
void init()
{
Gravity = 9.81f;
FloorHeight = 0.f;
FloorStrength = 20000.f;
Damping = 0.98f;
YoungModulus = 2000.f;
PoissonRatio = 0.3f;
TotalMass = 0.15f;
bFixedTop = false;
DeltaT = 0.f;
NumParticles = 0;
NumSprings = 0;
IntegrationMethod = 0;
}
};
struct Arrays
{
// Particles
float3* Positions;
float3* Velocities;
float3* Forces;
float* ParticleMasses;
float4* ParticleColors;
// Springs
uint2* SpringConnect;
float* RestLengths;
float* Coefficients;
float4* SpringColors;
#ifdef DEBUG_VELOCITY
float3* VelocityVectors;
float4* VelocityColors;
#endif
void ClearPtrs()
{
Positions = NULL;
Velocities = NULL;
Forces = NULL;
ParticleMasses = NULL;
ParticleColors = NULL;
SpringConnect = NULL;
RestLengths = NULL;
Coefficients = NULL;
SpringColors = NULL;
}
void FreeDeviceMem()
{
if (Positions) { CudaCheck(cudaFree(Positions)); }
if (Velocities) { CudaCheck(cudaFree(Velocities)); }
if (Forces) { CudaCheck(cudaFree(Forces)); }
if (ParticleMasses) { CudaCheck(cudaFree(ParticleMasses)); }
if (ParticleColors) { CudaCheck(cudaFree(ParticleColors)); }
if (SpringConnect) { CudaCheck(cudaFree(SpringConnect)); }
if (RestLengths) { CudaCheck(cudaFree(RestLengths)); }
if (Coefficients) { CudaCheck(cudaFree(Coefficients)); }
if (SpringColors) { CudaCheck(cudaFree(SpringColors)); }
ClearPtrs();
}
};
#endif // HOSTDEVICECODE_H