Exemplo n.º 1
0
void SPHSystem::compDensPressure()
{
	Particle *p;
	Particle *np;
	Vec2i cellPos;
	Vec2i nearPos;
	uint hash;
	for(uint k=0; k<numParticle; k++)
	{
		p = &(particles[k]);
		p->dens = 0.0f;
		p->pres = 0.0f;
		cellPos = calcCellPos(p->pos);
		for(int i=-1; i<=1; i++)
		{
			for(int j=-1; j<=1; j++)
			{
				nearPos.x = cellPos.x + i;
				nearPos.y = cellPos.y + j;
				hash = calcCellHash(nearPos);
				if(hash == 0xffffffff) continue;
				np = cells[hash].head;
				while(np != NULL)
				{
					Vec2f distVec = np->pos - p->pos;
					float dist2 = distVec.LengthSquared();
					
					if(dist2<INF || dist2>=kernel*kernel)
					{
						np = np->next;
						continue;
					}

					p->dens = p->dens + mass * poly6(dist2);
					np = np->next;
				}
			}
		}
		p->dens = p->dens + mass*poly6(0.0f);
		p->pres = (pow(p->dens / restDensity, 7) - 1) * stiffness;
	}
}
Exemplo n.º 2
0
void comp(float * b, float const * a, int N) {
  for (int i=0; i<N; ++i) {
    b[i] = poly6(a[i]);
  }
}