HDK coding densities and volumes

   802   0   2
User Avatar
Member
40 posts
Joined: Oct. 2012
Offline
Hey Guys,
I am implementing Shen and Chen paper on Lattice Boltzmann Multi phase method into houdini. I have a custom grid and array of densities and velocities i have already calculated in the grid.
I want to visualize this in houdini. If someone could guide me to code this density array into a voxel based system.
Currently to visualize I am randomly adding particles to each grid based on the density and just using particleFluidSurface to make it into a mesh.
I do not like the result as it just looks like noise to me.
I know my data is right but the random point spreading is not visualizing the density right.

TLDR
So what I want to do is
1) transfer my custom voxel grid( c++ array) into HDK voxel grid
2) transfer my density and velocity calculations (c++ arrays) into that HDK voxel grid.

If anyone could help that would be great. I am attaching my hdk visualization code but I know its not the right way to do it.

void LBMFluid::Emit(UT_Vector3D pos, double density)
{
GA_Offset srcptoff = GA_INVALID_OFFSET;
GA_Offset vtxoff = my_gpp->giveBirth();
GA_Offset ptoff = gdp->vertexPoint(vtxoff);
gdp->setPos3(ptoff,pos);

myLife.set(ptoff,0,0);
myLife.set(ptoff,1,1);
mydensity.set(ptoff,0,density);
}

void LBMFluid::visualize(int NX, int NY, int NZ, fpreal now, vector <double> rho)
{
int pSize = my_gpp->getNumParticles();
//cleanup stage
for(GA_Size i = 0; i < pSize ; i++)
{
GA_Offset ptoff = my_gpp->vertexPoint(i);
int life = myLife.get(ptoff,0);
int death = myLife.get(ptoff,1);
if (life >=death)
{
my_gpp->deadParticle(i);
}
}
my_gpp->deleteDead();
gdp->destroyUnusedPoints();
//adding new points
for (int k = 0 ; k < NZ-1 ; k++)
{
for(int j = 0; j < NY-1; j++)
{
for(int i = 0; i < NX-1; i++)
{
int N = i + NX*j + NY*NY*k;
int size = (int)(rho * MAXPART(now) + 0.5);//rounding num particles
// cout << “Densities” << endl;
// cout << "Grid: " << size << endl;
for ( int n = 0 ; n < size; n++)
{
double x = i + ((double)rand()/RAND_MAX);
double y = j + ((double)rand()/RAND_MAX);
double z = k + ((double)rand()/RAND_MAX);
UT_Vector3D pos = UT_Vector3D(x,y,z);
Emit(pos,rho);

}
}
}
}

}
  • Quick Links