// advect - Program to solve the advection equation // using the various hyperbolic PDE schemes #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 number of grid points: "; int N; cin >> N; double L = 1.; // System size double h = L/N; // Grid spacing double c = 1; // Wave speed cout << "Time for wave to move one grid spacing is " << h/c << endl; cout << "Enter time step: "; double tau; cin >> tau; double coeff = -c*tau/(2.*h); // Coefficient used by all schemes double coefflw = 2*coeff*coeff; // Coefficient used by L-W scheme cout << "Wave circles system in " << L/(c*tau) << " steps" << endl; cout << "Enter number of steps: "; int nStep; cin >> nStep; //* Set initial and boundary conditions. const double pi = 3.141592654; double sigma = 0.1; // Width of the Gaussian pulse double k_wave = pi/sigma; // Wave number of the cosine Matrix x(N), a(N), a_new(N); int i,j; for( i=1; i<=N; i++ ) { x(i) = (i-0.5)*h - L/2; // Coordinates of grid points // Initial condition is a Gaussian-cosine pulse a(i) = cos(k_wave*x(i)) * exp(-x(i)*x(i)/(2*sigma*sigma)); } // Use periodic boundary conditions int *ip, *im; ip = new int [N+1]; im = new int [N+1]; for( i=2; i