void LifeControlsWidget::onStep(){ if(play){ play = false; playBtn->setText("Play"); } else{ simulateStep(); } }
void ParticleChain::simulate(float timeStep) { mTimestepAccu += timeStep; while (mTimestepAccu >= timeStep) { mTimestepAccu -= mTimestep; addExternalForces(); simulateStep(); } }
void Simulator::simulate() { if ( !world ){ throw std::logic_error("Failed to start simulation: world not set"); } while(! isStopRequested() ){ simulateStep( dt ); simulatedSteps ++; simulatedTime += dt; if (simulationDelay) boost::this_thread::sleep(boost::posix_time::milliseconds( simulationDelay )); } stopRequest = false;//stop request fulfilled }
int mainLoop(int passengerThreshold, int maxLevels, int maxWaiters, int maxPassengers, int elevatorSteps,int sleepMS, int doorTime){ int newPassenger = 1; initElevator(maxLevels, maxPassengers, elevatorSteps, doorTime); initPassengers(maxWaiters, maxPassengers, maxLevels); while(running){ simulateStep(); newPassenger += (autoNew) ? 1 : 0; if(newPassenger > passengerThreshold){ createRandom(1); newPassenger = 1; } usleep(sleepMS * microToMilli); } return running; //should be "0" }
void VisualizerFMU::updateScene(const double time) { mpTimeManager->updateTick(); //for real-time measurement mpTimeManager->setSimTime(mpTimeManager->getVisTime()); double nextStep = mpTimeManager->getVisTime() + mpTimeManager->getHVisual(); double vis1 = mpTimeManager->getRealTime(); while (mpTimeManager->getSimTime() < nextStep) { //std::cout<<"simulate "<<omvManager->_simTime<<" to "<<nextStep<<std::endl; mpTimeManager->setSimTime(simulateStep(mpTimeManager->getSimTime())); } mpTimeManager->updateTick(); //for real-time measurement mpTimeManager->setRealTimeFactor(mpTimeManager->getHVisual() / (mpTimeManager->getRealTime() - vis1)); updateVisAttributes(mpTimeManager->getVisTime()); }
void LifeControlsWidget::simAndDisplay(){ simulateStep(); if(play){ QTimer::singleShot(delay, this, SLOT(simAndDisplay())); } }
void VisualizerFMU::simulate(TimeManager& omvm) { while (omvm.getSimTime() < omvm.getRealTime() + omvm.getHVisual() && omvm.getSimTime() < omvm.getEndTime()) omvm.setSimTime(simulateStep(omvm.getSimTime())); }
int main(int argc, char **argv) { #ifdef USE_MPI MPI_Init(&argc, &argv); #endif if (argc != 5) { LOG_ERROR("I want width, height, zombies, iterations.\n"); #ifdef USE_MPI MPI_Finalize(); #endif exit(1); } int width = atoi(argv[1]); int height = atoi(argv[2]); int people = (int) (width * height * INITIAL_DENSITY); int zombies = atoi(argv[3]); int iters = atoi(argv[4]); initRandom(0); WorldPtr input, output; double ratio = divideWorld(&width, &height, &input, &output); // there should not be any output prior to this point #ifdef REDIRECT initRedirectToFiles(input); #endif LOG_DEBUG("World size is %d x %d at position [%d, %d] of %d x %d\n", input->localWidth, input->localHeight, input->globalX, input->globalY, input->globalColumns, input->globalRows); if (input->globalX == 0 && input->globalY == 0) { randomDistribution(input, people * ratio, zombies, 0); } else { // no zombies elsewhere randomDistribution(input, people * ratio, 0, 0); } #ifndef NIMAGES printWorld(input, false); #endif Timer timer = startTimer(); Stats cumulative = NO_STATS; for (int i = 0; i < iters; i++) { simulateStep(input, output); output->stats.clock = cumulative.clock = output->clock; Stats stats = output->stats; mergeStats(&cumulative, stats, false); printStatistics(output, cumulative); WorldPtr temp = input; input = output; output = temp; input->stats = stats; } double elapsedTime = getElapsedTime(timer); #ifdef _OPENMP int numThreads = omp_get_max_threads(); #else int numThreads = 1; #endif LOG_TIME("Simulation took %f milliseconds with %d threads\n", elapsedTime, numThreads); // this is a clean up // we destroy both worlds destroyWorld(input); destroyWorld(output); destroyRandom(); #ifdef REDIRECT finishRedirectToFiles(); #endif #ifdef USE_MPI MPI_Finalize(); #endif }