// traffic - Program to solve the generalized Burger // equation for the traffic at a stop light problem #include "NumMeth.h" void main() { //* Select numerical parameters (time step, grid spacing, etc.). cout << "Choose a numerical method: 1) FTCS, 2) Lax, 3) Lax-Wendroff : "; int method; cin >> method; cout << "Enter the number of grid points: "; int N; cin >> N; double L = 400; // System size (meters) double h = L/N; // Grid spacing for periodic boundary conditions double v_max = 25; // Maximum car speed (m/s) cout << "Suggested timestep is " << h/v_max << endl; cout << "Enter time step (tau): "; double tau; cin >> tau; cout << "Last car starts moving after " << (L/4)/(v_max*tau) << " steps" << endl; cout << "Enter number of steps: "; int nStep; cin >> nStep; double coeff = tau/(2*h); // Coefficient used by all schemes double coefflw = tau*tau/(2*h*h); // Coefficient used by Lax-Wendroff double cp, cm; // Variables used by Lax-Wendroff //* Set initial and boundary conditions double rho_max = 1.0; // Maximum density double Flow_max = 0.25*rho_max*v_max; // Maximum Flow // Initial condition is a square pulse from x = -L/4 to x = 0 Matrix rho(N), rho_new(N); int i,j, iBack = N/4, iFront = N/2 - 1; for( i=1; i<=N; i++ ) if( iBack <= i && i <= iFront ) rho(i) = rho_max; else rho(i) = 0.0; rho(iFront+1) = rho_max/2; // Try running without this line // Use periodic boundary conditions int *ip, *im; ip = new int [N+1]; im = new int [N+1]; for( i=2; i