Hyperbolic Equation Simulation of Lax-Wendroff Method with Parallel Program

700 Words3 Pages
Topic : Hyperbolic equation simulation of Lax-Wendroff method with Parallel Program Introduction Consider a wave is propagating in a closed-end tube. The wave has a triangular shape which is to be used as the initial condition at t=0.0. u 20 0 20 30 60 x ( Initial Condition ) Formula for the Lax-Wendroff method : u( x, t +Δt) = u ( x, t) + ∂u∂t Δt + ∂2u∂t2 (Δt)22! + o (Δt )3 ; Apply: ∂u∂t = - a∂u∂x (a=speed of sound); uin+1 = uin – a Δt ui+1n- ui-1n 2Δx + 12 a2 (Δx) 2 ui+1n-2uin+ ui-1n Δx2; Codes: #include "mpi.h" #include <stdio.h> #include <math.h> #include <string.h> #include<stdlib.h> int main(int argc, char *argv[]) { const int max = 160; double u1[max + 2]; //u(i;n) double uin[max]; //Initial Condition double uend[max]; //End Condition double dt = 0.000125; double x = 0.5; double ct = 200.0*dt / x; //Courant number, , speed of sound equal to 200 double u0 = 0.0; int n = 0.15*max / 160 / dt; // time steps int i, m, k; int numprocs, myid; double startTime, endTime; /* Initialize MPI and get number of processes and my number or rank*/ MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); MPI_Comm_rank(MPI_COMM_WORLD, &myid); int r = max / numprocs; double *uha, *ut; //Initial velocity diffusion in each processe uha = (double*)malloc((r + 1)*sizeof(double)); //Velocity diffusion after time dt ut = (double*)malloc(r*sizeof(double)); uha[r] = 0.0; // One grid in front of uha /* Processor zero sets the number of intervals and starts its clock*/ if (myid == 0) { startTime = MPI_Wtime(); //Initial Condition for (i = 0; i <= max; i++) u1[i] = 0; for (i = max / 8; i <= max / 4; i++){ u1[i] =

More about Hyperbolic Equation Simulation of Lax-Wendroff Method with Parallel Program

Open Document