I have made my own version of the “particles” program that is bundled with the SDK.
The original program uses a radius for the particles of 1/64 = 0.015625.
However, I am using a radius of 1.0.
The SDK version works wonderfully. However, my simulation acts quite strange. The particles slowly fall and then when a few of them collide in midair, they shoot straight down where they become stuck into the floor. The remaining particles then bounce around the simulation like crazy as if in zero gravity. Generally speaking, I assume this is due to my much larger radius, because I copied the parameters of the SDK version exactly. The parameters are things such as spring, damping, shear, etc. The amount of energy in the simulation should decrease due to damping transference to the floor and walls. Unless in cases of particles squeezed into corners, the speed of all particles should (generally) decrease through time. I do not get this. When I get tiny collisions the particles “go mad” with speed.
Does anyone know how I should alter these parameters in order to get the same behavior as the SDK version?
Remember my particle’s radius is significantly larger.
Also, feel free to check if there is something wrong with my code.
The SDK code copied.
# /*
# m_params.particleRadius = 1.0f / 64.0f;
# m_params.spring = 0.5f;
# m_params.damping = 0.02f;
# m_params.shear = 0.1f;
# m_params.attraction = 0.0f;
# m_params.boundaryDamping = -0.5f;
# */
# __device__
# float3 collideSpheres(float3 posA, float3 posB,
# float3 velA, float3 velB,
# float radiusA, float radiusB,
# float attraction)
# {
# // calculate relative position
# float3 relPos = posB - posA;
#
# float dist = length(relPos);
# float collideDist = radiusA + radiusB;
#
# float3 force = make_float3(0.0f);
# if (dist < collideDist) {
# float3 norm = relPos / dist;
#
# // relative velocity
# float3 relVel = velB - velA;
#
# // relative tangential velocity
# float3 tanVel = relVel - (dot(relVel, norm) * norm);
#
# // spring force
# force = -params.spring*(collideDist - dist) * norm;
# // dashpot (damping) force
# force += params.damping*relVel;
# // tangential shear force
# force += params.shear*tanVel;
# // attraction
# force += attraction*relPos;
# }
#
# return force;
# }
#
#
My code.
#
#
# __device__ void DEMCollide(
# long int center,
# long int smasher,
# float3 cellpos,
# float3 cellvel )
# {
# if( center == smasher ) return; // self-interaction.
#
# //--//
# float3 smpos, smvel;
# long int smoffset;
# float D, compress;
# float3 span, cforce, norm, relvel, tangentvel;
#
# smoffset = 3 * (dvx_cellstates.PVindeces[smasher]);
# FETCHPOS(smpos,smoffset);
# span = smpos - cellpos;
# D = length(span);
# if( D > 2.0 ) return; // Not interacting.
#
# FETCHVEL(smvel,smoffset);
# norm = span / D; // unit vector pointing from center to smasher.
# relvel = smvel - cellvel; // relative velocity. This accounts for inertia.
# tangentvel = relvel - ((dot(relvel,norm)) * norm); // tangential velocity.
# compress = - ((2.0f) - D); // spring compression.
# cforce = ((dvx_params.spring)*compress) * norm; // Force is backwards from smasher.
# cforce += (dvx_params.damping) * relvel; // Collisions cause a slight drop in energy.
# cforce += (dvx_params.shear) * tangentvel; // tangential shear force
# //cforce += (dvx_params.attraction) * span; // attraction is nonzero for wet soil or fluid sim.
# AddForce( cforce ); // accumulate!
# }