/* * Stretch and tilt vortons using velocity field * timeStep - amount of time by which to advance simulation * uFrame - frame counter * * see J. T. Beale, A convergent three-dimensional vortex method with * grid-free stretching, Math. Comp. 46 (1986), 401-24, April. * * This routine assumes CreateInfluenceTree has already executed. * */ void StretchAndTiltVortons(float timeStep) { if ((0.0f == mVelGrid.GetExtent().x) || (0.0f == mVelGrid.GetExtent().y) || (0.0f == mVelGrid.GetExtent().z)) { // Domain is 2D, so stretching & tilting does not occur. return; } // Compute all gradients of all components of velocity. UniformGrid <Matrix3x3> velocityJacobianGrid = new UniformGrid <Matrix3x3>(mVelGrid); velocityJacobianGrid.Init(); UniformGridMath.ComputeJacobian(ref velocityJacobianGrid, mVelGrid); int numVortons = mVortons.Count; for (int offset = 0; offset < numVortons; ++offset) { // For each vorton... Matrix3x3 velJac = (Matrix3x3)velocityJacobianGrid.Interpolate(mVortons[offset].position); Vector3 stretchTilt = mVortons[offset].vorticity * velJac; // Usual way to compute stretching & tilting mVortons[offset].vorticity += /* fudge factor for stability */ 0.5f * stretchTilt * timeStep; } }
public void DebugDrawInfluenceGrid() { if (mInfluenceTree != null && mInfluenceTree.mLayers.Count != 0) { for (int u = 0; u < mInfluenceTree.mLayers.Count; ++u) { //if (u != 0) continue; UniformGrid <Vorton> grid = mInfluenceTree.mLayers[u]; //Gizmos.color = new Vector4(1, 1 - 1 / ((float)u + 1), 1 - 1 / ((float)u + 1), 1.1f - 1 / ((float)u + 1)); Vector3 cellExtent = grid.GetCellExtent(); Vector3 gridExtent = grid.GetExtent(); Vector3 numCells = new Vector3(grid.GetNumCells(0), grid.GetNumCells(1), grid.GetNumCells(2)); Vector3 gridOrigin = grid.GetMinCorner(); for (int i = 0; i < numCells.x; ++i) { for (int j = 0; j < numCells.y; ++j) { for (int k = 0; k < numCells.z; ++k) { if (mInfluenceTree[0][0] == null) { break; } uint[] indices = { (uint)i, (uint)j, (uint)k }; uint offset = mInfluenceTree[(uint)u].OffsetFromIndices(indices); float vorticity = mInfluenceTree[(uint)u][offset].vorticity.magnitude; Gizmos.color = new Vector4(vorticity, u / mInfluenceTree.mLayers.Count, u / mInfluenceTree.mLayers.Count, vorticity); Gizmos.DrawWireCube(gridOrigin + new Vector3(cellExtent.x * i + cellExtent.x / 2, cellExtent.y * j + cellExtent.y / 2, cellExtent.z * k + cellExtent.z / 2), cellExtent); } } } } } }