SebLague / Fluid-Sim

A simple 2D and 3D fluid simulation
https://www.youtube.com/watch?v=rSKMYc1CQHE
MIT License
644 stars 109 forks source link

different cells map to the same key #6

Open flabowski opened 11 months ago

flabowski commented 11 months ago

Hei, is there a reason you are working with hashes rather than a flattened cell index? As I understand, the domain (the box that contains the particles) is always finite and there are never indefinitely many cells. Instead of (cell.x hashK1) + (cell.y hashK2) + (cell.z * hashK3) you could compute the flattened index and use it as a unique cell id: cell_key = cell.z * (n_x * n_y) +cell.y *n_x + cell.x. With n_x = ceil(domain_size.x/smoothingRadius). Not sure what your domain is called, is it boundsSize? So instead of

    int3 cell = GetCell3D(PredictedPositions[index], smoothingRadius);
    uint hash = HashCell3D(cell);
    uint key = KeyFromHash(hash, numParticles);

you could do something like:

    int3 cell = GetCell3D(PredictedPositions[index], smoothingRadius);
    uint key = FlatIndex(cell, domain_size);

No reason to call KeyFromHash anymore, because all cell_key's are already smaller than tableSize (tableSize=n_x*n_y*n_z, which is smaller than numParticles).

kailando commented 6 months ago

...