void MACStableFluids::init() { /* for(int j=0; j<u.NJ(); ++j) for(int i=0; i<u.NI(); ++i) u(i,j) = std::sin(3.14159 * i / float(u.NI())); for(int j=0; j<v.NJ(); ++j) for(int i=0; i<v.NI(); ++i) v(i,j) = std::sin(3.14159 * j / float(u.NJ())); */ for(int i=2; i<u.NI()/3-2; ++i) for(int j=2; j<u.NJ()/3-2; ++j) { v(3*i,3*j,u.NK()/2)=10; v(3*i+1,3*j,u.NK()/2)=-10; u(3*i+1,3*j-1,u.NK()/2)=-10; u(3*i+1,3*j,u.NK()/2)=10; } u(u.NI()/2, u.NJ()/2,u.NK()/2 )=10; for(int i=0; i<size<NGrid>(); ++i) { float x=randhashf(i*3,0,1); float y=randhashf(i*3+1,0,1); float z=randhashf(i*3+2,0,1); particles.push_back(Vector3(x,y,z)); } }
//8 particles per cell void FluidSim::set_liquid(float (*phi)(const Vec3f&)) { //surface.reset_phi(phi, dx, Vec3f(0.5f*dx,0.5f*dx,0.5f*dx), ni, nj, nk); //initialize particles int seed = 0; for(int k = 0; k < nk; ++k) for(int j = 0; j < nj; ++j) for(int i = 0; i < ni; ++i) { Vec3f pos(i*dx,j*dx,k*dx); float a = randhashf(seed++); float b = randhashf(seed++); float c = randhashf(seed++); pos += dx * Vec3f(a,b,c); if(phi(pos) <= -particle_radius) { float solid_phi = interpolate_value(pos/dx, nodal_solid_phi); if(solid_phi >= 0){ particles.push_back(pos); particlesVel.push_back(Vec3f(0,0,0)); particlesCell.push_back(Vec3f(floor(pos[0]/dx+0.5),floor(pos[1]/dx+0.5),floor(pos[2]/dx+0.5))); particlesMass.push_back(0.1); //Kg particlesDensity.push_back(0); particlesVolume.push_back(0); particlesDeformation.push_back(Eigen::Matrix3f::Identity()); //3x3 init with identity plasticDeformationGradient.push_back(Eigen::Matrix3f::Identity()); elasticDeformationGradient.push_back(Eigen::Matrix3f::Identity()); } } } ParticleToGrid(); ParticleVolumeDensity(); }
void FluidSim::set_liquid(float (*phi)(const Vec3f&)) { //surface.reset_phi(phi, dx, Vec3f(0.5f*dx,0.5f*dx,0.5f*dx), ni, nj, nk); //initialize particles int seed = 0; for(int k = 0; k < nk; ++k) for(int j = 0; j < nj; ++j) for(int i = 0; i < ni; ++i) { Vec3f pos(i*dx,j*dx,k*dx); float a = randhashf(seed++); float b = randhashf(seed++); float c = randhashf(seed++); pos += dx * Vec3f(a,b,c); if(phi(pos) <= -particle_radius) { float solid_phi = interpolate_value(pos/dx, nodal_solid_phi); if(solid_phi >= 0) particles.push_back(pos); } } }
FlowNoise2:: FlowNoise2(unsigned int seed, float spin_variation) : Noise2(seed) { seed+=n; for(unsigned int i=0; i<n; ++i){ original_basis[i]=basis[i]; spin_rate[i]=2.0f*(float)M_PI*randhashf(seed++, 1-0.5f*spin_variation, 1+0.5f*spin_variation); } }
static Vec<N,float> sample_sphere(unsigned int &seed) { Vec<N,float> v; float m2; do{ for(unsigned int i=0; i<N; ++i){ v[i]=randhashf(seed++,-1,1); } m2=mag2(v); }while(m2>1 || m2==0); return v/std::sqrt(m2); }