void ComputeVelocityGridSliceThreaded(System.Object info) { ThreadInfo threadInfo = (ThreadInfo)info; uint izStart = (uint)threadInfo.begin; uint izEnd = (uint)threadInfo.end; VortonSim vortonSim = threadInfo.vortonSim; int numLayers = vortonSim.mInfluenceTree.GetDepth(); Vector3 vMinCorner = vortonSim.mVelGrid.GetMinCorner(); float nudge = 1.0f - 2.0f * global.GlobalVar.FLT_EPSILON; Vector3 vSpacing = vortonSim.mVelGrid.GetCellSpacing() * nudge; uint[] dims = { vortonSim.mVelGrid.GetNumPoints(0) , vortonSim.mVelGrid.GetNumPoints(1) , vortonSim.mVelGrid.GetNumPoints(2) }; uint numXY = dims[0] * dims[1]; uint[] idx = new uint[3]; for (idx[2] = izStart; idx[2] < izEnd; ++idx[2]) { // For subset of z index values... Vector3 vPosition; // Compute the z-coordinate of the world-space position of this gridpoint. vPosition.z = vMinCorner.z + (float)(idx[2]) * vSpacing.z; // Precompute the z contribution to the offset into the velocity grid. uint offsetZ = idx[2] * numXY; for (idx[1] = 0; idx[1] < dims[1]; ++idx[1]) { // For every gridpoint along the y-axis... // Compute the y-coordinate of the world-space position of this gridpoint. vPosition.y = vMinCorner.y + (float)(idx[1]) * vSpacing.y; // Precompute the y contribution to the offset into the velocity grid. uint offsetYZ = idx[1] * dims[0] + offsetZ; for (idx[0] = 0; idx[0] < dims[0]; ++idx[0]) { // For every gridpoint along the x-axis... // Compute the x-coordinate of the world-space position of this gridpoint. vPosition.x = vMinCorner.x + (float)(idx[0]) * vSpacing.x; // Compute the offset into the velocity grid. uint offsetXYZ = idx[0] + offsetYZ; // Compute the fluid flow velocity at this gridpoint, due to all vortons. uint[] zeros = { 0, 0, 0 }; // Starter indices for recursive algorithm vortonSim.mVelGrid[offsetXYZ] = vortonSim.ComputeVelocity(vPosition, zeros, numLayers - 1); } } } threadInfo.handle.Set(); }
/* * Initialize a fluid-and-body simulation * * This routine will remove particles that are embedded * inside rigid bodies. * * This method assumes the vortons have been initialized, * i.e. that their initial positions, vorticities and * radius have all been set. */ void Initialize() { numVortonsMax = numCellsPerDim * numCellsPerDim * numCellsPerDim; mVortonSim = new VortonSim(viscosity, density, useMultiThreads); //mVortonSim.Clear(); //IVorticityDistribution vorticityDistribution = gameObject.GetComponentInChildren<IVorticityDistribution>(); //AssignVorticity(2.0f * magnitude, (uint)numVortonsMax, vorticityDistribution); // distribute numVortonsMax between all vortices of the simulation. GameObject[] vortices = GameObject.FindGameObjectsWithTag("Vortex"); for (int i = 0; i < vortices.Length; ++i) { AssignVorticity(2.0f * magnitude, (uint)(numVortonsMax / vortices.Length), vortices[i].GetComponent <IVorticityDistribution>()); } // Create particle system if (gameObject.GetComponent <ParticleSystem>() == null) { particleSystem = gameObject.AddComponent <ParticleSystem>(); } particleSystem.startSpeed = 0; var em = particleSystem.emission; em.enabled = false; // Fetch all particles on the scene //tracers = new List<ParticleSystem.Particle>(); GameObject[] tracersGOs = GameObject.FindGameObjectsWithTag("Tracers"); for (int i = 0; i < tracersGOs.Length; ++i) { mVortonSim.mTracers.AddRange(tracersGOs[i].GetComponent <Tracers>().tracers); } //RemoveEmbeddedParticles(); mVortonSim.Initialize(); //TO-DO: Here we should pass the list of all tracers //RemoveEmbeddedParticles(); }
private void AdvectTracersSliceThreaded(System.Object info) { ThreadInfo threadInfo = (ThreadInfo)info; float timeStep = threadInfo.timeStep; int itStart = threadInfo.begin; int itEnd = threadInfo.end; VortonSim vortonSim = threadInfo.vortonSim; ManualResetEvent handle = threadInfo.handle; for (int offset = itStart; offset < itEnd; ++offset) { // For each passive tracer in this slice... Vector3 velocity = ((Vector)vortonSim.mVelGrid.Interpolate(vortonSim.mTracers[offset].position)).v; myParticle newTracer = new myParticle(); newTracer.position = vortonSim.mTracers[offset].position + velocity * timeStep; newTracer.velocity = velocity; // Cache for use in collisions vortonSim.mTracersAux[offset] = newTracer; } handle.Set(); }
/* Initialize a fluid-and-body simulation This routine will remove particles that are embedded inside rigid bodies. This method assumes the vortons have been initialized, i.e. that their initial positions, vorticities and radius have all been set. */ void Initialize() { numVortonsMax = numCellsPerDim * numCellsPerDim * numCellsPerDim; mVortonSim = new VortonSim(viscosity, density, useMultiThreads); //mVortonSim.Clear(); //IVorticityDistribution vorticityDistribution = gameObject.GetComponentInChildren<IVorticityDistribution>(); //AssignVorticity(2.0f * magnitude, (uint)numVortonsMax, vorticityDistribution); // distribute numVortonsMax between all vortices of the simulation. GameObject[] vortices = GameObject.FindGameObjectsWithTag("Vortex"); for (int i = 0; i < vortices.Length; ++i) { AssignVorticity(2.0f * magnitude, (uint)(numVortonsMax / vortices.Length), vortices[i].GetComponent<IVorticityDistribution>()); } // Create particle system if(gameObject.GetComponent<ParticleSystem>() == null) particleSystem = gameObject.AddComponent<ParticleSystem>(); particleSystem.startSpeed = 0; var em = particleSystem.emission; em.enabled = false; // Fetch all particles on the scene //tracers = new List<ParticleSystem.Particle>(); GameObject[] tracersGOs = GameObject.FindGameObjectsWithTag("Tracers"); for (int i = 0; i < tracersGOs.Length; ++i) { mVortonSim.mTracers.AddRange(tracersGOs[i].GetComponent<Tracers>().tracers); } //RemoveEmbeddedParticles(); mVortonSim.Initialize(); //TO-DO: Here we should pass the list of all tracers //RemoveEmbeddedParticles(); }