void System<DataType,Integrator,Potential,Communicator>::simulate(int numIters, std::ostream & output) { // MPI Comms. // clearBuffers() ; appendTransitionsToBuffers() ; appendInteractionsToBuffers() ; communicateInteractionsTransitions() ; // Initialise the forces. // updateForces() ; // Prime the velocity based on the integration policy. // for (unsigned int i = 0 ; i < positions.size() ; i+=2) { Integrator::initialise(&positions[i], &velocities[i], &forces[i]) ; } // Update velocities and positions based on the integration policy. // for (int i = 0; i < numIters ; ++i) { updateVelocities() ; updatePositions() ; // MPI Comms. clearBuffers() ; appendTransitionsToBuffers() ; appendInteractionsToBuffers() ; communicateInteractionsTransitions() ; updateForces() ; printSystem(output,i) ; output << std::endl << std::endl ; } } /* ----- end of member function simulate ----- */
void fKinematicController::update(float dt){ updateVelocities(dt); _lastPos = getPosition(); move(_velocity.x * dt, _velocity.y * dt); rotate(_angularVelocity * dt); _touching = NONE; }
/** * Orchestrates physics for each tick */ void System::tickSimulation() { updatePositions(); collideAndClean(); fireProjectiles(); applyForces(); updateVelocities(); }
void ShallowWater::computeOneStep() { Array2D<float> tempvX; Array2D<float> tempvY; m_n = advect(m_n); tempvX = advect(m_vX); tempvY = advect(m_vY); m_vX = tempvX; m_vY = tempvY; updateHeight(); plus(m_n, m_g, m_h); updateVelocities(); reflectingBoundaries(); }
// run the solver... int main(int argc, char *argv[]) { printf("Init\n"); // allocate memory vel_x.resize(SIZE*SIZE); vel_y.resize(SIZE*SIZE); temp.resize(SIZE*SIZE); eta.resize(SIZE*SIZE); // initialize grid for (int i=0;i<SIZE;i++) for (int j=0;j<SIZE;j++) { const int index = i+j*SIZE; vel_x[index] = vel_y[index] = temp[index] = 0.; // default water height 1 eta[index] = 1.; } // init an off-center initial wave for (int i=3*SIZE/6; i<4*SIZE/6; i++) for (int j=3*SIZE/6; j<4*SIZE/6; j++) { const int index = i + j*SIZE; //eta[index] = 1.1; } printf("Starting simulation...\n"); Real simulationTime = 0.; int simulationStep = 0; while (simulationTime < END_TIME) { printf("Step %d ",simulationStep); advectArray( eta ,0 ); advectArray( vel_x ,1 ); advectArray( vel_y ,2 ); updateHeight(); updateVelocities(); setBoundary(); addRandomDrop(); simulationTime += dt; simulationStep++; // should we write an image for this step? if ( (simulationStep % IMAGESTEPS)== 0) { writeImage( simulationStep ); } printf("\n"); } printf("SWS-simulation done!\n"); return 0; }