示例#1
0
void PoiseuilleFlowSystem::update(){
	assert(IsInitialized);

	float *dPos;

	if (IsOpenGL) 
		dPos = (float *) mapGLBufferObject(&cuda_posvbo_resource);
	else 
		dPos = (float *) cudaPosVBO;    		
	
	calculatePoiseuilleHash(dHash, dIndex, dPos, numParticles);

	sortParticles(dHash, dIndex, numParticles);

	reorderPoiseuilleData(
		dCellStart,
		dCellEnd,
		dSortedPos,		
		dSortedVel,
		dHash,
		dIndex,
		dPos,		
		dVelLeapFrog,
		numParticles,
		numGridCells);
	
	calculatePoiseuilleDensity(		
		dMeasures,
		dSortedPos,	
		dSortedVel,
		dIndex,
		dCellStart,
		dCellEnd,
		numParticles,
		numGridCells);

	calculatePoiseuilleAcceleration(
		dAcceleration,
		dMeasures,		
		dSortedPos,			
		dSortedVel,
		dIndex,
		dCellStart,
		dCellEnd,
		numParticles,
		numGridCells);    

	integratePoiseuilleSystem(
		dPos,
		dVel,	
		dVelLeapFrog,
		dAcceleration,
		numParticles);
	
	if (IsOpenGL) {
		unmapGLBufferObject(cuda_posvbo_resource);
	}
	elapsedTime+= params.deltaTime;
}
示例#2
0
void Particles::Update()
{
	assert(initFlag);
	float *dPos;
	dPos = (float *)mapGLBufferObject(&m_cuda_posvbo_resource);

	setParameters(&mparams);
	integrateSystem(dPos, velGpu, mparams.timeStep, numParticles);
	calcHash(gridParticleHash, gridParticleIndex,dPos,numParticles);
	sortParticles(gridParticleHash,gridParticleIndex,numParticles);
	reorderDataAndFindCellStart(cellStart,cellEnd,sortedPos,sortedVel,gridParticleHash,gridParticleIndex,dPos,velGpu,numParticles,mparams.wholeNumCells);
	simFluid(velGpu, sortedPos, sortedVel, gridParticleIndex, cellStart, cellEnd, numParticles, solidPosGpu, solidVelGpu, buoyancyGpu, buoyancyAngGpu);
	unmapGLBufferObject(m_cuda_posvbo_resource);
}
示例#3
0
void ParticleMesh::renderer()
{

	glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_vertexVbo);
	glVertexPointer(3, GL_FLOAT, 0, 0);
	glEnableClientState(GL_VERTEX_ARRAY);

	/*glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_colorVBO);
	glColorPointer(3, GL_FLOAT, 0, 0);
	glEnableClientState(GL_COLOR_ARRAY);*/

	glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_NorVBO);
	glNormalPointer(GL_FLOAT, 0, 0);
	glEnableClientState(GL_NORMAL_ARRAY);





	glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER, m_indexVBO);
	/*if (m_colorVBO)
	{
		glBindBufferARB(GL_ARRAY_BUFFER_ARB, m_colorVBO);
		glColorPointer(4, GL_FLOAT, 0, 0);
		glEnableClientState(GL_COLOR_ARRAY);
	}*/
	


	

	const void * device = mapGLBufferObject(&m_cuda_vertexvbo_resource);
	//copyArrayFromDevice(mp_vertexXYZ, ddata, &cuda_vbo_resource, m_numParticles * 4 * sizeof(float));
	cudaMemcpy(mp_vertexXYZ, device, m_totalConnectedPoints * 3 * sizeof(float), cudaMemcpyDeviceToHost);
	unmapGLBufferObject(m_cuda_vertexvbo_resource);


	

	
	
	glDrawElements(GL_TRIANGLES, m_totalFaces * 3, GL_UNSIGNED_INT, 0);
	glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisable(GL_COLOR_MATERIAL);
}
示例#4
0
void FluidSystem::depthSort()
{
	float *dPos;
	m_dPos = (float *)mapGLBufferObject(&m_cuda_posvbo_resource);

	m_indices.map();

	// calculate depth

	calcDepth(m_dPos, m_sortKeys.getDevicePtr(), m_indices.getDevicePtr(), m_sortVector, m_numParticles);

	// radix sort

	//sortParticlesKey(m_sortKeys.getDevicePtr(), m_indices.getDevicePtr(), m_numParticles);

	unmapGLBufferObject(m_cuda_posvbo_resource);
	m_indices.unmap();
}
// step the simulation
void
ParticleSystem::update(float deltaTime)
{
    assert(m_bInitialized);

    float *dPos;

    if (m_bUseOpenGL)
    {
        dPos = (float *) mapGLBufferObject(&m_cuda_posvbo_resource);
    }
    else
    {
        dPos = (float *) m_cudaPosVBO;
    }

    // update constants
    setParameters(&m_params);

    // integrate
    integrateSystem(
        dPos,
        m_dVel,
        deltaTime,
        m_numParticles);

    // calculate grid hash
    calcHash(
        m_dGridParticleHash,
        m_dGridParticleIndex,
        dPos,
        m_numParticles);

    // sort particles based on hash
    sortParticles(m_dGridParticleHash, m_dGridParticleIndex, m_numParticles);

    // reorder particle arrays into sorted order and
    // find start and end of each cell
    reorderDataAndFindCellStart(
        m_dCellStart,
        m_dCellEnd,
        m_dSortedPos,
        m_dSortedVel,
        m_dGridParticleHash,
        m_dGridParticleIndex,
        dPos,
        m_dVel,
        m_numParticles,
        m_numGridCells);

    // process collisions
    collide(
        m_dVel,
        m_dSortedPos,
        m_dSortedVel,
        m_dGridParticleIndex,
        m_dCellStart,
        m_dCellEnd,
        m_numParticles,
        m_numGridCells);

    // note: do unmap at end here to avoid unnecessary graphics/CUDA context switch
    if (m_bUseOpenGL)
    {
        unmapGLBufferObject(m_cuda_posvbo_resource);
    }
}
示例#6
0
void FluidSystem::update(float deltaTime) //整个particle或流体的update
{
    assert(m_bInitialized);

    float *dPos;
    if (m_bUseOpenGL)
    {
		m_dPos = (float *)mapGLBufferObject(&m_cuda_posvbo_resource);
		m_dVel = (float *)mapGLBufferObject(&m_cuda_velvbo_resource);

    }
    else
    {
		m_dPos = (float *)m_cudaPosVBO;
		m_dVel = (float *)m_cudaVelVBO;
    }
/////////////////////////////////////////////////////calculate time
	cudaEvent_t start, stop;
	cudaEventCreate(&start);
	cudaEventCreate(&stop);
	// Start record
	cudaEventRecord(start, 0);
///////////////////////////////////////////////////////////////////////

    setParameters(&m_params);

    integrateSystem(
		m_dPos,
        m_dVel,
		m_dDen,
		m_dPre,
        deltaTime,
        m_numParticles,
		buoyancyForce);

	//calculateBuoyancy();

	cudaEvent_t start1, stop1;
	cudaEventCreate(&start1);
	cudaEventCreate(&stop1);
	// Start record
	cudaEventRecord(start1, 0);

    calcHash(
        m_dGridParticleHash,
        m_dGridParticleIndex,
		m_dPos,
        m_numParticles);

    sortParticles(m_dGridParticleHash, m_dGridParticleIndex, m_numParticles);

    reorderDataAndFindCellStart(
        m_dCellStart,
        m_dCellEnd,
        m_dSortedPos,
        m_dSortedVel,
        m_dGridParticleHash,
        m_dGridParticleIndex,
		m_dPos,
        m_dVel,
        m_numParticles,
        m_numGridCells,
		m_dSortedDen,
		m_dSortedPre,
		m_dDen,   //old density
		m_dPre,//old pressure
		m_dSortedColorf,
		m_dColorf);

	cudaEventRecord(stop1, 0);
	cudaEventSynchronize(stop1);
	float elapsedTime1;
	cudaEventElapsedTime(&elapsedTime1, start1, stop1); // that's our time!

	std::cout <<"neighbour " <<elapsedTime1 << endl;

	// Clean up:
	cudaEventDestroy(start1);
	cudaEventDestroy(stop1);

	/*colorfield(
		m_dSortedPos,
		m_dGridParticleIndex,
		m_dCellStart,
		m_dCellEnd,
		m_numParticles,
		m_numGridCells,
		m_dColorf,
		m_dSortedColorf);*/
	//
	copyArrayFromDevice(m_hDen, m_dDen, 0, sizeof(float) * m_numParticles);


	/*glBindBufferARB(GL_ARRAY_BUFFER, m_colorVBO);
	float *data = (float *)glMapBufferARB(GL_ARRAY_BUFFER, GL_WRITE_ONLY);
	float *ptr = data;

	for (uint i = 0; i<m_numParticles; i++)
	{
		float t = i / (float)m_numParticles;
		if (  m_hDen[i]<2.5f){
			colorRamp(1, 1, 1, ptr);
			ptr += 3;
			*ptr++ = 0.1f;
		}
		else
		{
			colorRamp(0, 1, 1, ptr);
			ptr += 3;
			*ptr++ = 0.1f;
		}

	}

	glUnmapBufferARB(GL_ARRAY_BUFFER);*/


	cudaEvent_t start2, stop2;
	cudaEventCreate(&start2);
	cudaEventCreate(&stop2);
	// Start record
	cudaEventRecord(start2, 0);

	calculateDensity(m_dSortedPos,
		m_dGridParticleIndex,
		m_dCellStart,
		m_dCellEnd,
		m_numParticles,
		m_dDen);

    collide(
        m_dVel, //new velocity
        m_dSortedPos,
        m_dSortedVel,
        m_dGridParticleIndex,
        m_dCellStart,
        m_dCellEnd,
        m_numParticles,
        m_numGridCells,
		m_dDen, //new density
		m_dPre, //new pressure
		m_dSortedDen,
		m_dSortedPre,
		m_dPos,
		buoyancyForce);

	cudaEventRecord(stop2, 0);
	cudaEventSynchronize(stop2);
	float elapsedTime2;
	cudaEventElapsedTime(&elapsedTime2, start2, stop2); // that's our time!

	std::cout << "renew " << elapsedTime2 << endl;

	// Clean up:
	cudaEventDestroy(start2);
	cudaEventDestroy(stop2);
	////////////////////////////////////////////////////////////stop calculate time
	cudaEventRecord(stop, 0);
	cudaEventSynchronize(stop);
	float elapsedTime;
	cudaEventElapsedTime(&elapsedTime, start, stop); // that's our time!

	std::cout << "whole " << elapsedTime << endl;

	// Clean up:
	cudaEventDestroy(start);
	cudaEventDestroy(stop);
	//////////////////////////////////////////////////////////

    if (m_bUseOpenGL)
    {
        unmapGLBufferObject(m_cuda_posvbo_resource);
		unmapGLBufferObject(m_cuda_velvbo_resource);
    }
}