13.07.2014 Views

pdf 260K - Madagascar

pdf 260K - Madagascar

pdf 260K - Madagascar

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

8<br />

PROGRAMMING PART (EXTRA CREDIT)<br />

For extra credit, you can modify the wave modeling program to include anisotropic<br />

wave propagation effects. The program below (slightly modified from the original<br />

version by Paul Sava) implements wave modeling with equation<br />

∂ 2 P<br />

∂t 2<br />

= V 2 (x) ∇ 2 P + F (x, t) = V 2 (x)<br />

( ∂ 2 P<br />

∂x 2 1<br />

+ ∂2 P<br />

∂x 2 2<br />

)<br />

+ F (x, t) , (15)<br />

where F (x, t) is the source term. The implementation uses finite-difference discretization<br />

(second-order in time and fourth-order in space). Stepping in time involves the<br />

following computations:<br />

P t+∆t = [ V 2 (x) ∇ 2 P t + F (x, t) ] ∆t 2 + 2P t − P t−∆t , (16)<br />

where P represents the propagating wavefield discretized at different time steps.<br />

1 /∗ 2−D f i n i t e −d i f f e r e n c e a c o u s t i c wave propagation ∗/<br />

2 #include <br />

3<br />

4 #i f d e f OPENMP<br />

5 #include <br />

6 #endif<br />

7<br />

10<br />

8 static int n1 , n2 ;<br />

9 static float c0 , c11 , c21 , c12 , c22 ;<br />

11 static void l a p l a c i a n ( float ∗∗ uin /∗ [ n2 ] [ n1 ] ∗/ ,<br />

12 float ∗∗ uout /∗ [ n2 ] [ n1 ] ∗/ )<br />

13 /∗ Laplacian operator , 4 th−order f i n i t e −d i f f e r e n c e ∗/<br />

14 {<br />

15 int i1 , i 2 ;<br />

16<br />

17 #i f d e f OPENMP<br />

18 #pragma omp p a r a l l e l for \<br />

19 p r i v a t e ( i2 , i 1 ) \<br />

20 shared ( n2 , n1 , uout , uin , c11 , c12 , c21 , c22 , c0 )<br />

21 #endif<br />

22 for ( i 2 =2; i 2 < n2 −2; i 2++) {<br />

23 for ( i 1 =2; i 1 < n1 −2; i 1++) {<br />

24 uout [ i 2 ] [ i 1 ] =<br />

25 c11 ∗( uin [ i 2 ] [ i1 −1]+uin [ i 2 ] [ i 1 +1]) +<br />

26 c12 ∗( uin [ i 2 ] [ i1 −2]+uin [ i 2 ] [ i 1 +2]) +<br />

27 c21 ∗( uin [ i2 −1][ i 1 ]+ uin [ i 2 +1][ i 1 ] ) +<br />

28 c22 ∗( uin [ i2 −2][ i 1 ]+ uin [ i 2 +2][ i 1 ] ) +<br />

29 c0 ∗ uin [ i 2 ] [ i 1 ] ;<br />

30 }

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!