In: Physics
Examine whether the Verlet and velocity Verlet numerical schemes are time reversible. To show the time reversibility one may use a numerical example i.e. one may iterate the equations 3-4 times with an example you select (hint: start with an initial position and velocity of your choice and iterate the algorithm 3-4 times) or one may show it more rigorously with the manipulation of the Verlet and velocity-Verlet formulae.
struct Body 2 { 3 Vec3d pos { 0.0, 0.0, 0.0 }; 4 Vec3d vel { 2.0, 0.0, 0.0 }; // 2m/s along x-axis 5 Vec3d acc { 0.0, 0.0, 0.0 }; // no acceleration at first 6 double mass = 1.0; // 1kg 7 double drag = 0.1; // rho*C*Area - simplified drag for this example 8 9 /** 10 * Update pos and vel using "Velocity Verlet" integration 11 * @param dt DeltaTime / time step [eg: 0.01] 12 */ 13 void update(double dt) 14 { 15 Vec3d new_pos = pos + vel*dt + acc*(dt*dt*0.5); 16 Vec3d new_acc = apply_forces(); // only needed if acceleration is not constant 17 Vec3d new_vel = vel + (acc+new_acc)*(dt*0.5); 18 pos = new_pos; 19 vel = new_vel; 20 acc = new_acc; 21 } 22 23 Vec3d apply_forces() const 24 { 25 Vec3d grav_acc = Vec3d{0.0, 0.0, -9.81 }; // 9.81m/s^2 down in the Z-axis 26 Vec3d drag_force = 0.5 * drag * (vel * abs(vel)); // D = 0.5 * (rho * C * Area * vel^2) 27 Vec3d drag_acc = drag_force / mass; // a = F/m 28 return grav_acc - drag_acc; 29 } 30 };