protected override void Start() { this.grid = new PICGrid(-9.8f, this.gridSize.x, this.gridSize.y, 1); this.particles = new PICParticles(grid, this.type); this.AddParticle(); this.parameter.numberOfParticles.Value = this.gridSize.x * this.gridSize.y * 4; this.ResizeBuffer(this.parameter.numberOfParticles.Value); this.grid.solver = this.solver; this.grid.dataUpdate = this.dataUpdate; }
void AdvanceOneStep(PICGrid grid, PICParticles particles, float dt) { particles.TransferToGrid(); //grid.save_velocities(); grid.SolveGravity(dt); grid.BuildSDF(); grid.ExternVelocity(); grid.ApplySolidSDF(); grid.SolveIncompressible(this.method == Method.CPU, this.linearSolver == LinearSolver.Jacobi); grid.ExternVelocity(); //grid.get_velocity_update(); particles.GridToParticle(); for (int i = 0; i < 5; ++i) { particles.MoveParticle(0.2f * dt); } }
void AdvanceOneFrame(PICGrid grid, PICParticles particles, float frametime) { float t = 0; float dt; bool finished = false; while (!finished) { dt = 2 * grid.GetCFL(); if (t + dt >= frametime) { dt = frametime - t; finished = true; } else if (t + 1.5 * dt >= frametime) { dt = 0.5f * (frametime - t); } Debug.LogFormat("advancing {0} (to {1}% of frame)\n", dt, 100.0 * (t + dt) / frametime); AdvanceOneStep(grid, particles, dt); t += dt; } }