Skip to content

Commit

Permalink
checkpoint before changing to cuda types
Browse files Browse the repository at this point in the history
  • Loading branch information
JAGJ10 committed Mar 29, 2015
1 parent 30d168a commit 06b35cb
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 255 deletions.
36 changes: 13 additions & 23 deletions PositionBasedFluids/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,29 @@
#include "common.h"

//---------------------Fluid Constants----------------------
static const int PRESSURE_ITERATIONS = 4;
static const int SOLVER_ITERATIONS = 4;
static const int blockSize = 128;

#define gridWidth 50
#define gridHeight 50
#define gridDepth 30

static const int gridSize = gridWidth * gridHeight * gridDepth;

#define NUM_PARTICLES 65536
#define NUM_FOAM 2000000
#define MAX_NEIGHBORS 50
#define MAX_PARTICLES 50
#define MAX_CONTACTS 10
#define GRID_SIZE gridSize

static const dim3 dims = int(NUM_PARTICLES / blockSize);
static const dim3 gridDims = int(ceil(gridSize / blockSize));
//static const dim3 dims = int(NUM_PARTICLES / blockSize);
//static const dim3 gridDims = int(ceil(gridSize / blockSize));

#define deltaT 0.0083f
#define PI 3.14159265358979323846f
#define GRAVITY glm::vec3(0, -9.8f, 0)
#define H 0.1f
#define KPOLY 1566681471.06084471147494f //(315.0f / (64.0f * PI * glm::pow(H, 9)))
#define SPIKY 14323944.878270580219199538f //(45.0f / (PI * glm::pow(H, 6)))
#define REST_DENSITY 6378.0f
#define EPSILON_LAMBDA 600.0f
#define EPSILON_VORTICITY 0.0001f
#define C 0.01f
#define K 0.00001f
#define deltaQMag 0.3f * H
#define wQH 1180.60572282879181f //(KPOLY * glm::pow((H * H - deltaQMag * deltaQMag), 3))
//#define GRAVITY glm::vec3(0, -9.8f, 0)
//#define H 0.1f
//#define KPOLY (315.0f / (64.0f * PI * glm::pow(H, 9)))
//#define SPIKY (45.0f / (PI * glm::pow(H, 6)))
//#define REST_DENSITY 6378.0f
//#define EPSILON_LAMBDA 600.0f
//#define EPSILON_VORTICITY 0.0001f
//#define C 0.01f
//#define K 0.00001f
//#define deltaQMag 0.3f * H
//#define wQH (KPOLY * glm::pow((H * H - deltaQMag * deltaQMag), 3))
#define lifetime 1.0f

#endif
74 changes: 12 additions & 62 deletions PositionBasedFluids/ParticleSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,20 @@ static float t = 0.0f;
static int flag = 1;
static int frameCounter = 0;

//---------------------Cloth Constants----------------------
//static const int SOLVER_ITERATIONS = 16;
//static const float kStretch = 0.75f;
//static const float kDamp = 0.05f;
//static const float kLin = 1.0f - glm::pow(1.0f - kStretch, 1.0f / SOLVER_ITERATIONS);
//static const float globalK = 0.0f; //0 means you aren't forcing it into a shape (like a plant)

ParticleSystem::ParticleSystem() {
p = new Buffers;
//Initialize particles
gpuErrchk(cudaMalloc((void**)&p->particles, NUM_PARTICLES * sizeof(Particle)));
//gpuErrchk(cudaMalloc((void**)&foamParticles, NUM_FOAM * sizeof(FoamParticle)));
gpuErrchk(cudaMalloc((void**)&p->neighbors, MAX_NEIGHBORS * NUM_PARTICLES * sizeof(int)));
gpuErrchk(cudaMalloc((void**)&p->numNeighbors, NUM_PARTICLES * sizeof(int)));
gpuErrchk(cudaMalloc((void**)&p->gridCells, MAX_PARTICLES * gridSize * sizeof(int)));
gpuErrchk(cudaMalloc((void**)&p->gridCounters, gridSize * sizeof(int)));
gpuErrchk(cudaMalloc((void**)&p->contacts, MAX_CONTACTS * NUM_PARTICLES * sizeof(int)));
gpuErrchk(cudaMalloc((void**)&p->numContacts, NUM_PARTICLES * sizeof(int)));
gpuErrchk(cudaMalloc((void**)&p->deltaPs, NUM_PARTICLES * sizeof(glm::vec3)));
gpuErrchk(cudaMalloc((void**)&p->buffer1, NUM_PARTICLES * sizeof(glm::vec3)));
gpuErrchk(cudaMalloc((void**)&p->densities, NUM_PARTICLES * sizeof(float)));
gpuErrchk(cudaMalloc((void**)&p->buffer3, NUM_PARTICLES * sizeof(float)));

//Clear memory in case it's left over from last time?
gpuErrchk(cudaMemset(p->particles, 0, NUM_PARTICLES * sizeof(Particle)));
//gpuErrchk(cudaMemset(foamParticles, 0, NUM_FOAM * sizeof(FoamParticle)));
gpuErrchk(cudaMemset(p->neighbors, 0, MAX_NEIGHBORS * NUM_PARTICLES * sizeof(int)));
gpuErrchk(cudaMemset(p->numNeighbors, 0, NUM_PARTICLES * sizeof(int)));
gpuErrchk(cudaMemset(p->gridCells, 0, MAX_PARTICLES * gridSize * sizeof(int)));
gpuErrchk(cudaMemset(p->gridCounters, 0, gridSize * sizeof(int)));
gpuErrchk(cudaMemset(p->contacts, 0, MAX_CONTACTS * NUM_PARTICLES * sizeof(int)));
gpuErrchk(cudaMemset(p->numContacts, 0, NUM_PARTICLES * sizeof(int)));
gpuErrchk(cudaMemset(p->deltaPs, 0, NUM_PARTICLES * sizeof(glm::vec3)));
gpuErrchk(cudaMemset(p->buffer1, 0, NUM_PARTICLES * sizeof(glm::vec3)));
gpuErrchk(cudaMemset(p->densities, 0, NUM_PARTICLES * sizeof(float)));
gpuErrchk(cudaMemset(p->buffer3, 0, NUM_PARTICLES * sizeof(float)));

tempParticles = new Particle[NUM_PARTICLES];
s = new solver;
sp = new solverParams;

int count = 0;
for (int i = 1; i < 33; i += 1) {
for (int j = 1; j < 65; j += 1) {
for (int k = 1; k < 33; k += 1) {
tempParticles[count].invMass = 1;
tempParticles[count].newPos = glm::vec3(float(i) / 20, float(j) / 20, float(k) / 20);
tempParticles[count].oldPos = glm::vec3(float(i) / 20, float(j) / 20, float(k) / 20);
tempParticles[count].velocity = glm::vec3(0.0f);
tempParticles[count].phase = 0;
count++;
//tempParticles[count].invMass = 1;
//tempParticles[count].newPos = glm::vec3(float(i) / 20, float(j) / 20, float(k) / 20);
//tempParticles[count].oldPos = glm::vec3(float(i) / 20, float(j) / 20, float(k) / 20);
//tempParticles[count].velocity = glm::vec3(0.0f);
//tempParticles[count].phase = 0;
//count++;
}
}
}
Expand Down Expand Up @@ -157,33 +122,18 @@ ParticleSystem::ParticleSystem() {
}
}*/

gpuErrchk(cudaMemcpy(p->particles, tempParticles, NUM_PARTICLES * sizeof(Particle), cudaMemcpyHostToDevice));
//gpuErrchk(cudaMemcpy(p->particles, tempParticles, NUM_PARTICLES * sizeof(Particle), cudaMemcpyHostToDevice));
//gpuErrchk(cudaMalloc((void**)&p->dConstraints, p->numConstraints * sizeof(DistanceConstraint)));
//gpuErrchk(cudaMemcpy(p->dConstraints, tempdConstraints.data(), p->numConstraints * sizeof(DistanceConstraint), cudaMemcpyHostToDevice));
delete[] tempParticles;
//tempdConstraints.clear();
}

ParticleSystem::~ParticleSystem() {
gpuErrchk(cudaFree(p->particles));
gpuErrchk(cudaFree(p->dConstraints));
//gpuErrchk(cudaFree(foamParticles));
//gpuErrchk(cudaFree(freeList));
gpuErrchk(cudaFree(p->neighbors));
gpuErrchk(cudaFree(p->numNeighbors));
gpuErrchk(cudaFree(p->gridCells));
gpuErrchk(cudaFree(p->gridCounters));
gpuErrchk(cudaFree(p->contacts));
gpuErrchk(cudaFree(p->numContacts));
gpuErrchk(cudaFree(p->deltaPs));
gpuErrchk(cudaFree(p->buffer1));
gpuErrchk(cudaFree(p->densities));
gpuErrchk(cudaFree(p->buffer3));
delete p;
freeParams(s, sp);
}

void ParticleSystem::updateWrapper() {
update(p);
//update(p);
//Move wall
/*if (frameCounter >= 500) {
//width = (1 - abs(sin((frameCounter - 400) * (deltaT / 1.25f) * 0.5f * PI)) * 1) + 4;
Expand All @@ -202,7 +152,7 @@ void ParticleSystem::updateWrapper() {
}

void ParticleSystem::setVBOWrapper(float* fluidPositions, float* clothPositions) {
setVBO(p->particles, fluidPositions, clothPositions);
//setVBO(p->particles, fluidPositions, clothPositions);
}

void ParticleSystem::updatePositions2() {
Expand Down
Loading

0 comments on commit 06b35cb

Please sign in to comment.