void ParticleChain::simulate(float timeStep) { mTimestepAccu += timeStep; while (mTimestepAccu >= timeStep) { mTimestepAccu -= mTimestep; addExternalForces(); simulateStep(); } }
//-------------------------------------------------------------------------------------------------- // run void BasicSPH::run(double time) { double oldTimeStep = _dt; // Run simulation! double timeLeft = time; while (timeLeft > 0.0) { // Run simulation steps buildNeighbors(); computeDensityAndPressure(); addExternalForces(); computeArtificialViscosityForces(); computePressureForces(); // Compute time step if (_useAdaptiveTimeStep) computeTimeStep(); // Limit timestep to the time left in the simulation if (timeLeft < _dt) { _dt = timeLeft; } // Update particles integrate(); // Update time timeLeft -= _dt; std::cout << "Substep done! With timestep = " << _dt << std::endl; } // Restore old time step _dt = oldTimeStep; }