-
Notifications
You must be signed in to change notification settings - Fork 49
/
seismic_CPML_2D_poroelastic_fourth_order.f90
1258 lines (1028 loc) · 44 KB
/
seismic_CPML_2D_poroelastic_fourth_order.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!
! SEISMIC_CPML Version 1.1.1, November 2009.
!
! Copyright Universite de Pau et des Pays de l'Adour, CNRS and INRIA, France.
! Contributors: Roland Martin, roland DOT martin aT get DOT obs-mip DOT fr
! and Dimitri Komatitsch, komatitsch aT lma DOT cnrs-mrs DOT fr
!
! This software is a computer program whose purpose is to solve
! the poroelastic elastic wave equation
! using a finite-difference method with Convolutional Perfectly Matched
! Layer (C-PML) conditions and Biot model with and without viscous dissipation.
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 3 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License along
! with this program; if not, write to the Free Software Foundation, Inc.,
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
!
! The full text of the license is available in file "LICENSE".
program seismic_CPML_2D_poroelastic_fourth
! 2D poroelastic finite-difference code in velocity and stress formulation
! with Convolution-PML (C-PML) absorbing conditions
! with and without viscous dissipation
! Roland Martin, University of Pau, France, October 2009.
! based on the elastic code of Komatitsch and Martin, 2007.
! The fourth-order staggered-grid formulation of Madariaga (1976) and Virieux (1986) is used:
!
! ^ y
! |
! |
!
! +-------------------+
! | |
! | |
! | |
! | |
! | v_y |
! sigma_xy +---------+ |
! | | |
! | | |
! | | |
! | | |
! | | |
! +---------+---------+ ---> x
! v_x sigma_xx
! sigma_yy
!
! The C-PML implementation is based in part on formulas given in Roden and Gedney (2000).
! If you use this code for your own research, please cite some (or all) of these
! articles:
!
! @ARTICLE{MaKoEz08,
! author = {Roland Martin and Dimitri Komatitsch and Abdela\^aziz Ezziani},
! title = {An unsplit convolutional perfectly matched layer improved at grazing
! incidence for seismic wave equation in poroelastic media},
! journal = {Geophysics},
! year = {2008},
! volume = {73},
! pages = {T51-T61},
! number = {4},
! doi = {10.1190/1.2939484}}
!
! @ARTICLE{MaKo09,
! author = {Roland Martin and Dimitri Komatitsch},
! title = {An unsplit convolutional perfectly matched layer technique improved
! at grazing incidence for the viscoelastic wave equation},
! journal = {Geophysical Journal International},
! year = {2009},
! volume = {179},
! pages = {333-344},
! number = {1},
! doi = {10.1111/j.1365-246X.2009.04278.x}}
!
! @ARTICLE{MaKoGe08,
! author = {Roland Martin and Dimitri Komatitsch and Stephen D. Gedney},
! title = {A variational formulation of a stabilized unsplit convolutional perfectly
! matched layer for the isotropic or anisotropic seismic wave equation},
! journal = {Computer Modeling in Engineering and Sciences},
! year = {2008},
! volume = {37},
! pages = {274-304},
! number = {3}}
!
! @ARTICLE{KoMa07,
! author = {Dimitri Komatitsch and Roland Martin},
! title = {An unsplit convolutional {P}erfectly {M}atched {L}ayer improved
! at grazing incidence for the seismic wave equation},
! journal = {Geophysics},
! year = {2007},
! volume = {72},
! number = {5},
! pages = {SM155-SM167},
! doi = {10.1190/1.2757586}}
!
! The original CPML technique for Maxwell's equations is described in:
!
! @ARTICLE{RoGe00,
! author = {J. A. Roden and S. D. Gedney},
! title = {Convolution {PML} ({CPML}): {A}n Efficient {FDTD} Implementation
! of the {CFS}-{PML} for Arbitrary Media},
! journal = {Microwave and Optical Technology Letters},
! year = {2000},
! volume = {27},
! number = {5},
! pages = {334-339},
! doi = {10.1002/1098-2760(20001205)27:5 < 334::AID-MOP14>3.0.CO;2-A}}
! To display the results as color images in the selected 2D cut plane, use:
!
! " display image*.gif " or " gimp image*.gif "
!
! or
!
! " montage -geometry +0+3 -rotate 90 -tile 1x21 image*Vx*.gif allfiles_Vx.gif
! "
! " montage -geometry +0+3 -rotate 90 -tile 1x21 image*Vy*.gif allfiles_Vy.gif
! "
! then " display allfiles_Vx.gif " or " gimp allfiles_Vx.gif "
! then " display allfiles_Vy.gif " or " gimp allfiles_Vy.gif "
! To display the 2D results as PostScript vector plots with small arrows, use:
!
! " gs vect*.ps "
!
! IMPORTANT : all our CPML codes work fine in single precision as well (which is significantly faster).
! If you want you can thus force automatic conversion to single precision at compile time
! or change all the declarations and constants in the code from double precision to single.
implicit none
! total number of grid points in each direction of the grid
integer, parameter :: NX = 140
integer, parameter :: NY = 620
! size of a grid cell
double precision, parameter :: DELTAX = 0.5D0
double precision, parameter :: DELTAY = DELTAX
! flags to add PML layers to the edges of the grid
logical, parameter :: USE_PML_LEFT = .true.
logical, parameter :: USE_PML_RIGHT = .true.
logical, parameter :: USE_PML_BOTTOM = .true.
logical, parameter :: USE_PML_TOP = .true.
! thickness of the PML layer in grid points
integer, parameter :: NPOINTS_PML = 10
! heterogeneous model and height of the interface
logical, parameter :: HETEROGENEOUS_MODEL = .true.
double precision, parameter :: INTERFACE_HEIGHT =105.D0+NPOINTS_PML*DELTAY
integer, parameter:: JINTERFACE=INT(INTERFACE_HEIGHT/DELTAY)+1
double precision :: co,c1,c2,vtemp
! model mud saturated with water, see article by Martin and Komatitsch
double precision, parameter :: etaokappa_bottom=0.d0
double precision, parameter :: rmu_bottom = 5.25D09
double precision, parameter :: phi_bottom =0.25d0
double precision, parameter :: a_bottom = 2.49d0
double precision, parameter :: rhos_bottom = 2588.d0
double precision, parameter :: rhof_bottom = 952.4d0
double precision, parameter :: rho_bottom =2179.1d0
double precision, parameter :: rsm_bottom =9486.d0
double precision, parameter :: alpha_bottom=0.89d0
double precision, parameter :: rbM_bottom =7.71d09
double precision, parameter :: rlambdao_bottom = 6.2D08
double precision, parameter :: rlambdac_bottom =rlambdao_bottom+alpha_bottom**2*rbM_bottom
double precision, parameter :: ro11_b=rho_bottom+phi_bottom*rhof_bottom*(a_bottom-2.d0)
double precision, parameter :: ro12_b=phi_bottom*rhof_bottom*(1.d0-a_bottom)
double precision, parameter :: ro22_b=a_bottom*phi_bottom*rhof_bottom
double precision, parameter :: lambda_b=rlambdao_bottom+rbM_bottom*(alpha_bottom-phi_bottom)**2
double precision, parameter :: R_b=rbM_bottom*phi_bottom**2
double precision, parameter :: ga_b=rbM_bottom*phi_bottom*(alpha_bottom-phi_bottom)
double precision, parameter :: S_b=lambda_b+2*rmu_bottom
double precision, parameter :: c1_b=S_b*R_b-ga_b**2
double precision, parameter :: b1_b=-S_b*ro22_b-R_b*ro11_b+2*ga_b*ro12_b
double precision, parameter :: a1_b=ro11_b*ro22_b-ro12_b**2
double precision, parameter :: delta_b=b1_b**2-4.d0*a1_b*c1_b
double precision:: cp_bottom
double precision:: cps_bottom
double precision:: cs_bottom
double precision, parameter :: etaokappa_top=3.33D06
double precision, parameter :: rmu_top = 2.4D09
double precision, parameter :: phi_top =0.1d0
double precision, parameter :: a_top = 2.42d0
double precision, parameter :: rhos_top = 2250.d0
double precision, parameter :: rhof_top = 1040.d0
double precision, parameter :: rho_top = 2129.d0
double precision, parameter :: rsm_top =25168.d0
double precision, parameter :: alpha_top=0.58d0
double precision, parameter :: rbM_top = 7.34d09
double precision, parameter :: rlambdao_top =6.D08
double precision, parameter :: rlambdac_top =rlambdao_top+alpha_top**2*rbM_top
double precision, parameter :: ro11_t=rho_top+phi_top*rhof_top*(a_top-2.d0)
double precision, parameter :: ro12_t=phi_top*rhof_top*(1.d0-a_top)
double precision, parameter :: ro22_t=a_top*phi_top*rhof_top
double precision, parameter :: lambda_t=rlambdao_top+rbM_top*(alpha_top-phi_top)**2
double precision, parameter :: R_t=rbM_top*phi_top**2
double precision, parameter :: ga_t=rbM_top*phi_top*(alpha_top-phi_top)
double precision, parameter :: S_t=lambda_t+2*rmu_top
double precision, parameter :: c1_t=S_t*R_t-ga_t**2
double precision, parameter :: b1_t=-S_t*ro22_t-R_t*ro11_t+2*ga_t*ro12_t
double precision, parameter :: a1_t=ro11_t*ro22_t-ro12_t**2
double precision, parameter :: delta_t=b1_t**2-4.d0*a1_t*c1_t
double precision:: cp_top
double precision:: cps_top
double precision:: cs_top
! total number of time steps
integer, parameter :: NSTEP = 100000
! time step in seconds
double precision, parameter :: DELTAT = 1.d-04
! parameters for the source
double precision, parameter :: f0 = 80.d0
double precision, parameter :: t0 = 1.d0/f0
double precision, parameter :: factor =1.d02
! source
integer, parameter :: ISOURCE = NX/2+1
integer, parameter :: JSOURCE = NY/2 +1
integer, parameter :: IDEB = NX / 2 + 1
integer, parameter :: JDEB = NY / 2 + 1
double precision, parameter :: xsource = DELTAX * ISOURCE
double precision, parameter :: ysource = DELTAY * JSOURCE
! angle of source force clockwise with respect to vertical (Y) axis
double precision, parameter :: ANGLE_FORCE = 0.d0
! receivers
integer, parameter :: NREC = 2
double precision, parameter :: ydeb = NPOINTS_PML*DELTAY+10.D0 ! first receiver x in meters
double precision, parameter :: yfin = NY*DELTAY-NPOINTS_PML*DELTAY-10.d0 ! first receiver x in meters
double precision, parameter :: xdeb =xsource ! first receiver y in meters
double precision, parameter :: xfin =xdeb ! first receiver y in meters
! display information on the screen from time to time
integer, parameter :: IT_DISPLAY = 200
! value of PI
double precision, parameter :: PI = 3.141592653589793238462643d0
! conversion from degrees to radians
double precision, parameter :: DEGREES_TO_RADIANS = PI / 180.d0
! zero
double precision, parameter :: ZERO = 0.d0
! large value for maximum
double precision, parameter :: HUGEVAL = 1.d+30
! velocity threshold above which we consider that the code became unstable
double precision, parameter :: STABILITY_THRESHOLD = 1.d+25
! main arrays
double precision, dimension(0:NX+1,0:NY+1) :: vx,vy,sigmaxx,sigma2,alp_sigma2,sigmayy,sigmaxy,vnorm
double precision, dimension(0:NX+1,0:NY+1) :: vxf,vyf
double precision, dimension(0:NX+1,0:NY+1) :: rho,rhof,rsm,rmu,rlambdac,rbM,alpha,etaokappa,rlambdao
! to interpolate material parameters at the right location in the staggered grid cell
double precision rho_half_x_half_y,rhof_half_x_half_y,rsm_half_x_half_y,etaokappa_half_x_half_y
! for evolution of total energy in the medium
double precision epsilon_xx,epsilon_yy,epsilon_xy
double precision, dimension(NSTEP) :: total_energy_kinetic,total_energy_potential
double precision c33_half_y
! power to compute d0 profile
double precision, parameter :: NPOWER = 2.d0
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-11
double precision, parameter :: K_MAX_PML = 1.d0
double precision, parameter :: ALPHA_MAX_PML = 2.d0*PI*(f0/2.d0) ! from Festa and Vilotte
! 2D arrays for the memory variables
double precision, dimension(0:NX+1,0:NY+1) :: gamma11,gamma22
double precision, dimension(0:NX+1,0:NY+1) :: gamma12_1
double precision, dimension(0:NX+1,0:NY+1) :: xi_1,xi_2
double precision, dimension(0:NX+1,0:NY+1) :: &
memory_dx_vx1,memory_dx_vx2,memory_dy_vx,memory_dx_vy,memory_dy_vy1,memory_dy_vy2, &
memory_dx_sigmaxx,memory_dx_sigmayy,memory_dx_sigmaxy, &
memory_dx_sigma2vx,memory_dx_sigma2vxf,memory_dy_sigma2vy,memory_dy_sigma2vyf, &
memory_dy_sigmaxx,memory_dy_sigmayy,memory_dy_sigmaxy
! 1D arrays for the damping profiles
double precision, dimension(NX) :: d_x,K_x,alpha_x,a_x,b_x,d_x_half_x,K_x_half_x,alpha_x_half_x,a_x_half_x,b_x_half_x
double precision, dimension(NY) :: d_y,K_y,alpha_y,a_y,b_y,d_y_half_y,K_y_half_y,alpha_y_half_y,a_y_half_y,b_y_half_y
double precision thickness_PML_x,thickness_PML_y,xoriginleft,xoriginright,yoriginbottom,yorigintop
double precision Rcoef,d0_x,d0_y,xval,yval,abscissa_in_PML,abscissa_normalized
double precision value_dx_vx1,value_dx_vx2,value_dx_vy,value_dx_sigmaxx,value_dx_sigmaxy
double precision value_dy_vy1,value_dy_vy2,value_dy_vx,value_dy_sigmaxx,value_dy_sigmaxy
double precision value_dx_sigma2vxf,value_dy_sigma2vyf
! for the source
double precision a,t,source_term
! for receivers
double precision xspacerec,yspacerec,distval,dist
integer, dimension(NREC) :: ix_rec,iy_rec
double precision, dimension(NREC) :: xrec,yrec
! for seismograms
double precision, dimension(NSTEP,NREC) :: sisvx,sisvy,sisp
integer i,j,it,irec
double precision Courant_number_bottom,Courant_number_top,velocnorm_all,max_amplitude
double precision Dispersion_number_bottom,Dispersion_number_top
!---
!--- program starts here
!---
cp_bottom=(-b1_b+sqrt(delta_b))/(2.d0*a1_b);
cps_bottom=(-b1_b-sqrt(delta_b))/(2.d0*a1_b);
cp_bottom=sqrt(cp_bottom)
cps_bottom=sqrt(cps_bottom)
cs_bottom=sqrt(rmu_bottom/(ro11_b-ro12_b**2/ro22_b))
cp_top=(-b1_t+sqrt(delta_t))/(2.d0*a1_t);
cps_top=(-b1_t-sqrt(delta_t))/(2.d0*a1_t);
cp_top=sqrt(cp_top)
cps_top=sqrt(cps_top)
cs_top=sqrt(rmu_top/(ro11_t-ro12_t**2/ro22_t))
print *,'cp_bottom= ',cp_bottom
print *,'cps_bottom=',cps_bottom
print *,'cs_bottom= ',cs_bottom
print *,'cp_top= ',cp_top
print *,'cps_top=',cps_top
print *,'cs_top= ',cs_top
print *,'rho_bottom= ',rho_bottom
print *,'rsm_bottom= ',rsm_bottom
print *,'rho_top= ',rho_top
print *,'rsm_top= ',rsm_top
print *,'rmu_bottom= ',rmu_bottom
print *,'rlambdac_bottom= ',rlambdac_bottom
print *,'rlambdao_bottom= ',rlambdao_bottom
print *,'alpha_bottom= ',alpha_bottom
print *,'rbM_bottom= ',rbM_bottom
print *,'etaokappa_bottom= ',etaokappa_bottom
print *,'rmu_top= ',rmu_top
print *,'rlambdac_top= ',rlambdac_top
print *,'rlambdao_top= ',rlambdao_top
print *,'alpha_top= ',alpha_top
print *,'rbM_top= ',rbM_top
print *,'etaokappa_top= ',etaokappa_top
print *, 'DELTAT CPML=', DELTAT
print *,'2D poroelastic finite-difference code in velocity and stress formulation with C-PML'
print *
! display size of the model
print *
print *,'NX = ',NX
print *,'NY = ',NY
print *
print *,'size of the model along X = ',(NX - 1) * DELTAX
print *,'size of the model along Y = ',(NY - 1) * DELTAY
print *
print *,'Total number of grid points = ',NX * NY
print *
!--- define profile of absorption in PML region
! thickness of the PML layer in meters
thickness_PML_x = NPOINTS_PML * DELTAX
thickness_PML_y = NPOINTS_PML * DELTAY
! reflection coefficient (INRIA report section 6.1) http://hal.inria.fr/docs/00/07/32/19/PDF/RR-3471.pdf
Rcoef = 0.001d0
! check that NPOWER is okay
if (NPOWER < 1) stop 'NPOWER must be greater than 1'
! compute d0 from INRIA report section 6.1 http://hal.inria.fr/docs/00/07/32/19/PDF/RR-3471.pdf
if (HETEROGENEOUS_MODEL) then
d0_x = - (NPOWER + 1) * max(cp_bottom,cp_top) * log(Rcoef) / (2.d0 * thickness_PML_x)
d0_y = - (NPOWER + 1) * max(cp_bottom,cp_top) * log(Rcoef) / (2.d0 * thickness_PML_y)
else
d0_x = - (NPOWER + 1) * cp_bottom * log(Rcoef) / (2.d0 * thickness_PML_x)
d0_y = - (NPOWER + 1) * cp_bottom * log(Rcoef) / (2.d0 * thickness_PML_y)
endif
print *,'d0_x = ',d0_x
print *,'d0_y = ',d0_y
d_x(:) = ZERO
d_x_half_x(:) = ZERO
d_y(:) = ZERO
d_y_half_y(:) = ZERO
K_x(:) = 1.d0
K_x_half_x(:) = 1.d0
K_y(:) = 1.d0
K_y_half_y(:) = 1.d0
alpha_x(:) = ZERO
alpha_x_half_x(:) = ZERO
alpha_y(:) = ZERO
alpha_y_half_y(:) = ZERO
a_x(:) = ZERO
a_x_half_x(:) = ZERO
a_y(:) = ZERO
a_y_half_y(:) = ZERO
! origin of the PML layer (position of right edge minus thickness, in meters)
xoriginleft = thickness_PML_x
xoriginright = (NX-1)*DELTAX - thickness_PML_x
do i = 1,NX
! abscissa of current grid point along the damping profile
xval = DELTAX * dble(i-1)
!!!! ---------- left edge
if (USE_PML_LEFT) then
! define damping profile at the grid points
abscissa_in_PML = xoriginleft - xval
if (abscissa_in_PML >= ZERO) then
abscissa_normalized = abscissa_in_PML / thickness_PML_x
d_x(i) = d0_x * abscissa_normalized**NPOWER
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-2
K_x(i) = 1.d0 + (K_MAX_PML - 1.d0) * abscissa_normalized**NPOWER
alpha_x(i) = ALPHA_MAX_PML * (1.d0 - abscissa_normalized)
endif
! define damping profile at half the grid points
abscissa_in_PML = xoriginleft - (xval + DELTAX/2.d0)
if (abscissa_in_PML >= ZERO) then
abscissa_normalized = abscissa_in_PML / thickness_PML_x
d_x_half_x(i) = d0_x * abscissa_normalized**NPOWER
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-2
K_x_half_x(i) = 1.d0 + (K_MAX_PML - 1.d0) * abscissa_normalized**NPOWER
alpha_x_half_x(i) = ALPHA_MAX_PML * (1.d0 - abscissa_normalized)
endif
endif
!!!! ---------- right edge
if (USE_PML_RIGHT) then
! define damping profile at the grid points
abscissa_in_PML = xval - xoriginright
if (abscissa_in_PML >= ZERO) then
abscissa_normalized = abscissa_in_PML / thickness_PML_x
d_x(i) = d0_x * abscissa_normalized**NPOWER
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-2
K_x(i) = 1.d0 + (K_MAX_PML - 1.d0) * abscissa_normalized**NPOWER
alpha_x(i) = ALPHA_MAX_PML * (1.d0 - abscissa_normalized)
endif
! define damping profile at half the grid points
abscissa_in_PML = xval + DELTAX/2.d0 - xoriginright
if (abscissa_in_PML >= ZERO) then
abscissa_normalized = abscissa_in_PML / thickness_PML_x
d_x_half_x(i) = d0_x * abscissa_normalized**NPOWER
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-2
K_x_half_x(i) = 1.d0 + (K_MAX_PML - 1.d0) * abscissa_normalized**NPOWER
alpha_x_half_x(i) = ALPHA_MAX_PML * (1.d0 - abscissa_normalized)
endif
endif
! just in case, for -5 at the end
if (alpha_x(i) < ZERO) alpha_x(i) = ZERO
if (alpha_x_half_x(i) < ZERO) alpha_x_half_x(i) = ZERO
b_x(i) = exp(- (d_x(i) / K_x(i) + alpha_x(i)) * DELTAT)
b_x_half_x(i) = exp(- (d_x_half_x(i) / K_x_half_x(i) + alpha_x_half_x(i)) * DELTAT)
! this to avoid division by zero outside the PML
if (abs(d_x(i)) > 1.d-6) a_x(i) = d_x(i) * (b_x(i) - 1.d0) /&
(K_x(i) * (d_x(i) + K_x(i) * alpha_x(i)))
if (abs(d_x_half_x(i)) > 1.d-6) a_x_half_x(i) = d_x_half_x(i)&
* (b_x_half_x(i) - 1.d0) / (K_x_half_x(i) * (d_x_half_x(i) + K_x_half_x(i) * alpha_x_half_x(i)))
enddo
!!!!!!!!!!!!! added Y damping profile
! origin of the PML layer (position of right edge minus thickness, in meters)
yoriginbottom = thickness_PML_y
yorigintop = NY*DELTAY - thickness_PML_y
do j = 1,NY
! abscissa of current grid point along the damping profile
yval = DELTAY * dble(j-1)
!!!! ---------- bottom edge
if (USE_PML_BOTTOM) then
! define damping profile at the grid points
abscissa_in_PML = yoriginbottom - yval
if (abscissa_in_PML >= ZERO) then
abscissa_normalized = abscissa_in_PML / thickness_PML_y
d_y(j) = d0_y * abscissa_normalized**NPOWER
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-2
K_y(j) = 1.d0 + (K_MAX_PML - 1.d0) * abscissa_normalized**NPOWER
alpha_y(j) = ALPHA_MAX_PML * (1.d0 - abscissa_normalized)
endif
! define damping profile at half the grid points
abscissa_in_PML = yoriginbottom - (yval + DELTAY/2.d0)
if (abscissa_in_PML >= ZERO) then
abscissa_normalized = abscissa_in_PML / thickness_PML_y
d_y_half_y(j) = d0_y * abscissa_normalized**NPOWER
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-2
K_y_half_y(j) = 1.d0 + (K_MAX_PML - 1.d0) * abscissa_normalized**NPOWER
alpha_y_half_y(j) = ALPHA_MAX_PML * (1.d0 - abscissa_normalized)
endif
endif
!!!! ---------- top edge
if (USE_PML_TOP) then
! define damping profile at the grid points
abscissa_in_PML = yval - yorigintop
if (abscissa_in_PML >= ZERO) then
abscissa_normalized = abscissa_in_PML / thickness_PML_y
d_y(j) = d0_y * abscissa_normalized**NPOWER
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-2
K_y(j) = 1.d0 + (K_MAX_PML - 1.d0) * abscissa_normalized**NPOWER
alpha_y(j) = ALPHA_MAX_PML * (1.d0 - abscissa_normalized)
endif
! define damping profile at half the grid points
abscissa_in_PML = yval + DELTAY/2.d0 - yorigintop
if (abscissa_in_PML >= ZERO) then
abscissa_normalized = abscissa_in_PML / thickness_PML_y
d_y_half_y(j) = d0_y * abscissa_normalized**NPOWER
! from Stephen Gedney's unpublished class notes for class EE699, lecture 8, slide 8-2
K_y_half_y(j) = 1.d0 + (K_MAX_PML - 1.d0) * abscissa_normalized**NPOWER
alpha_y_half_y(j) = ALPHA_MAX_PML * (1.d0 - abscissa_normalized)
endif
endif
! just in case, for -5 at the end
! if (alpha_y(j) < ZERO) alpha_y(j) = ZERO
! if (alpha_y_half_y(j) < ZERO) alpha_y_half_y(j) = ZERO
b_y(j) = exp(- (d_y(j) / K_y(j) + alpha_y(j)) * DELTAT)
b_y_half_y(j) = exp(- (d_y_half_y(j) / K_y_half_y(j) + alpha_y_half_y(j)) * DELTAT)
! this to avoid division by zero outside the PML
if (abs(d_y(j)) > 1.d-6) a_y(j) = d_y(j) * (b_y(j) - 1.d0) &
/ (K_y(j) * (d_y(j) + K_y(j) * alpha_y(j)))
if (abs(d_y_half_y(j)) > 1.d-6) a_y_half_y(j) = d_y_half_y(j)&
* (b_y_half_y(j) - 1.d0) / (K_y_half_y(j) * (d_y_half_y(j) + K_y_half_y(j) * alpha_y_half_y(j)))
enddo
! compute the Lame parameters and density
do j = 0,NY+1
do i = 0,NX+1
if (HETEROGENEOUS_MODEL .and. DELTAY*dble(j-1) > INTERFACE_HEIGHT) then
rho(i,j)= rho_top
rhof(i,j) = rhof_top
rsm(i,j) = rsm_top
rmu(i,j)= rmu_top
rlambdac(i,j) = rlambdac_top
rbM(i,j) = rbM_top
alpha(i,j)=alpha_top
etaokappa(i,j)=etaokappa_top
rlambdao(i,j) = rlambdao_top
else
rho(i,j)= rho_bottom
rhof(i,j) = rhof_bottom
rsm(i,j) = rsm_bottom
rmu(i,j)= rmu_bottom
rlambdac(i,j) = rlambdac_bottom
rbM(i,j) = rbM_bottom
alpha(i,j)=alpha_bottom
etaokappa(i,j)=etaokappa_bottom
rlambdao(i,j) = rlambdao_bottom
endif
enddo
enddo
! print position of the source
print *
print *,'Position of the source:'
print *
print *,'x = ',xsource
print *,'y = ',ysource
print *
! define location of receivers
print *
print *,'There are ',nrec,' receivers'
print *
xspacerec = (xfin-xdeb) / dble(NREC-1)
yspacerec = (yfin-ydeb) / dble(NREC-1)
do irec=1,nrec
xrec(irec) = xdeb + dble(irec-1)*xspacerec
yrec(irec) = ydeb + dble(irec-1)*yspacerec
enddo
! find closest grid point for each receiver
do irec=1,nrec
dist = HUGEVAL
do j = 1,NY
do i = 1,NX
distval = sqrt((DELTAX*dble(i-1) - xrec(irec))**2 + (DELTAY*dble(j-1) - yrec(irec))**2)
if (distval < dist) then
dist = distval
ix_rec(irec) = i
iy_rec(irec) = j
endif
enddo
enddo
print *,'receiver ',irec,' x_target,y_target = ',xrec(irec),yrec(irec)
print *,'closest grid point found at distance ',dist,' in i,j = ',ix_rec(irec),iy_rec(irec)
print *
enddo
! check the Courant stability condition for the explicit time scheme
! R. Courant et K. O. Friedrichs et H. Lewy (1928)
Courant_number_bottom = cp_bottom * DELTAT / min(DELTAX,DELTAY)
Dispersion_number_bottom=min(cs_bottom,cps_bottom)/(2.5d0*f0*max(DELTAX,DELTAY))
print *,'Courant number at the bottom is ',Courant_number_bottom
print *,'Dispersion number at the bottom is ',Dispersion_number_bottom
print *
if (Courant_number_bottom > 1.d0/sqrt(2.d0)) stop 'time step is too large, simulation will be unstable'
if (HETEROGENEOUS_MODEL) then
Courant_number_top = max(cp_top,cp_bottom) * DELTAT / min(DELTAX,DELTAY)
Dispersion_number_top=min(cs_top,cs_bottom,cps_bottom,cps_top)/(2.5d0*f0*max(DELTAX,DELTAY))
print *,'Courant number at the top is ',Courant_number_top
print *
print *,'Dispersion number at the top is ',Dispersion_number_top
if (Courant_number_top > 6.d0/7.d0/sqrt(2.d0)) stop 'time step is too large, simulation will be unstable'
endif
! suppress old files
! call system('rm -f Vx_*.dat Vy_*.dat vect*.ps image*.pnm image*.gif')
! initialize arrays
vx(:,:) = ZERO
vy(:,:) = ZERO
sigmaxx(:,:) = ZERO
sigmayy(:,:) = ZERO
sigmaxy(:,:) = ZERO
sigma2(:,:) = ZERO
alp_sigma2(:,:) = ZERO
gamma11(:,:)=0.d0
gamma22(:,:)=0.d0
gamma12_1(:,:)=0.d0
gamma12_1(:,:)=0.d0
xi_1(:,:)=0.d0
xi_2(:,:)=0.d0
vxf(:,:) = ZERO
vyf(:,:) = ZERO
memory_dx_vx1(:,:)=0.d0
memory_dx_vx2(:,:)=0.d0
memory_dy_vx(:,:)=0.d0
memory_dx_vy(:,:)=0.d0
memory_dy_vy1(:,:)=0.d0
memory_dy_vy2(:,:)=0.d0
memory_dx_sigmaxx(:,:)=0.d0
memory_dx_sigmayy(:,:)=0.d0
memory_dx_sigmaxy(:,:)=0.d0
memory_dx_sigma2vx(:,:)=0.d0
memory_dx_sigma2vxf(:,:)=0.d0
memory_dy_sigmaxx(:,:)=0.d0
memory_dy_sigmayy(:,:)=0.d0
memory_dy_sigmaxy(:,:)=0.d0
memory_dy_sigma2vy(:,:)=0.d0
memory_dy_sigma2vyf(:,:)=0.d0
! initialize seismograms
sisvx(:,:) = ZERO
sisvy(:,:) = ZERO
sisp(:,:) = ZERO
! initialize total energy
total_energy_kinetic(:) = ZERO
total_energy_potential(:) = ZERO
!---
!--- beginning of time loop
!---
do it = 1,NSTEP
!----------------------
! compute stress sigma
!----------------------
!-----------------------------------
! update memory variables for C-PML
!-----------------------------------
do j = 2,NY
do i = 1,NX-1
! memory of sigmaxx
value_dx_sigmaxx =(27.d0*vx(i+1,j)-27.d0*vx(i,j)-vx(i+2,j)+vx(i-1,j))/DELTAX/24.D0
value_dy_sigmaxx =(27.d0*vy(i,j)-27.d0*vy(i,j-1)-vy(i,j+1)+vy(i,j-2))/DELTAY/24.D0
memory_dx_sigmaxx(i,j) = b_x_half_x(i) * memory_dx_sigmaxx(i,j) + a_x_half_x(i) * value_dx_sigmaxx
memory_dy_sigmaxx(i,j) = b_y(j) * memory_dy_sigmaxx(i,j) + a_y(j) * value_dy_sigmaxx
gamma11(i,j) = gamma11(i,j)+DELTAT*(value_dx_sigmaxx / K_x_half_x(i) + memory_dx_sigmaxx(i,j))
gamma22(i,j) = gamma22(i,j)+DELTAT*(value_dy_sigmaxx / K_y(j) + memory_dy_sigmaxx(i,j))
! sigma2
value_dx_sigma2vxf=(27.d0*vxf(i+1,j)-27.d0* vxf(i,j)-vxf(i+2,j)+vxf(i-1,j)) / DELTAX/24.D0
value_dy_sigma2vyf=(27.d0*vyf(i,j)-27.d0*vyf(i,j-1)-vyf(i,j+1)+vyf(i,j-2)) / DELTAY/24.D0
memory_dx_sigma2vxf(i,j) = b_x_half_x(i) * memory_dx_sigma2vxf(i,j) + a_x_half_x(i) * value_dx_sigma2vxf
memory_dy_sigma2vyf(i,j) = b_y(j) * memory_dy_sigma2vyf(i,j) + a_y(j) * value_dy_sigma2vyf
xi_1(i,j) = xi_1(i,j) -(value_dx_sigma2vxf/ K_x_half_x(i) + memory_dx_sigma2vxf(i,j))*DELTAT
xi_2(i,j) = xi_2(i,j) -(value_dy_sigma2vyf/K_y(j)+memory_dy_sigma2vyf(i,j))*DELTAT
sigma2(i,j)=-alpha(i,j)*rbM(i,j)*(gamma11(i,j)+gamma22(i,j))+rbM(i,j)*(xi_1(i,j)+xi_2(i,j))
enddo
enddo
! add the source (point source located at a given grid point)
a = pi*pi*f0*f0
t = dble(it-1)*DELTAT
! Gaussian
source_term = factor * exp(-a*(t-t0)**2)/(-2.d0*a)
! first derivative of a Gaussian
! source_term = factor * 2.d0*a*(t-t0)*exp(-a*(t-t0)**2)
! source_term = factor *(t-t0)*exp(-a*(t-t0)**2)
! Ricker source time function (second derivative of a Gaussian)
! source_term = factor * (1.d0 - 2.d0*a*(t-t0)**2)*exp(-a*(t-t0)**2)
! define location of the source
i = ISOURCE
j = JSOURCE
! add the source term
sigma2(i,j) = sigma2(i,j) + source_term*rbM(i,j)
do j = 1,NY-1
do i = 2,NX
! interpolate material parameters at the right location in the staggered grid cell
c33_half_y = 2.d0/(1.d0/rmu(i,j)+1.d0/rmu(i,j+1))
c33_half_y = rmu(i,j+1)
value_dx_sigmaxy = (27.d0*vy(i,j) - 27.d0*vy(i-1,j)-vy(i+1,j)+vy(i-2,j)) / DELTAX/24.D0
value_dy_sigmaxy = (27.d0*vx(i,j+1) - 27.d0*vx(i,j)-vx(i,j+2)+vx(i,j-1)) / DELTAY/24.D0
memory_dx_sigmaxy(i,j) = b_x(i) * memory_dx_sigmaxy(i,j) + a_x(i) * value_dx_sigmaxy
memory_dy_sigmaxy(i,j) = b_y_half_y(j) * memory_dy_sigmaxy(i,j) + a_y_half_y(j) * value_dy_sigmaxy
sigmaxy(i,j) = sigmaxy(i,j) + &
c33_half_y/1.d0 * (value_dx_sigmaxy / K_x(i) + memory_dx_sigmaxy(i,j) + &
value_dy_sigmaxy / K_y(j) + memory_dy_sigmaxy(i,j)) * DELTAT
enddo
enddo
do j = 2,NY
do i = 1,NX-1
sigmaxx(i,j)=(rlambdao(i,j)+2.d0*rmu(i,j))*gamma11(i,j)+rlambdao(i,j)*gamma22(i,j) -alpha(i,j)*sigma2(i,j)
sigmayy(i,j)=rlambdao(i,j)*gamma11(i,j)+(rlambdao(i,j)+2.d0*rmu(i,j))*gamma22(i,j) -alpha(i,j)*sigma2(i,j)
enddo
enddo
!------------------
! compute velocity
!------------------
!-----------------------------------
! update memory variables for C-PML
!-----------------------------------
do j = 2,NY
do i = 2,NX
co=(rho(i,j)*rsm(i,j)-rhof(i,j)*rhof(i,j))/DELTAT
c1=co+rho(i,j)*etaokappa(i,j)*0.5d0
c2=co-rho(i,j)*etaokappa(i,j)*0.5d0
vtemp=vxf(i,j)
value_dx_vx1 = (27.d0*sigmaxx(i,j) - 27.d0*sigmaxx(i-1,j)&
-sigmaxx(i+1,j)+sigmaxx(i-2,j)) / DELTAX/24.D0
value_dx_vx2 = (27.d0*sigma2(i,j) - 27.d0*sigma2(i-1,j)-sigma2(i+1,j)+sigma2(i-2,j)) / DELTAX/24.D0
value_dy_vx = (27.d0*sigmaxy(i,j) - 27.d0*sigmaxy(i,j-1)-sigmaxy(i,j+1)+sigmaxy(i,j-2)) / DELTAY/24.D0
memory_dx_vx1(i,j) = b_x(i) * memory_dx_vx1(i,j) + a_x(i) * value_dx_vx1
memory_dx_vx2(i,j) = b_x(i) * memory_dx_vx2(i,j) + a_x(i) * value_dx_vx2
memory_dy_vx(i,j) = b_y(j) * memory_dy_vx(i,j) + a_y(j) * value_dy_vx
vxf(i,j) = (c2*vxf(i,j) + &
(-rhof(i,j)*(value_dx_vx1/ K_x(i) + memory_dx_vx1(i,j) &
+ value_dy_vx / K_y(j) + memory_dy_vx(i,j)) &
-rho(i,j)*(value_dx_vx2/ K_x(i) + memory_dx_vx2(i,j)) &
)) /c1
vtemp=(vtemp+vxf(i,j))*0.5d0
vx(i,j) = vx(i,j) + &
(rsm(i,j)*(value_dx_vx1/ K_x(i) + memory_dx_vx1(i,j)+ &
value_dy_vx / K_y(j) + memory_dy_vx(i,j))+&
rhof(i,j)*(value_dx_vx2/ K_x(i) + memory_dx_vx2(i,j)) + &
rhof(i,j)*etaokappa(i,j)*vtemp)&
/co
enddo
enddo
do j = 1,NY-1
do i = 1,NX-1
rho_half_x_half_y = rho(i,j+1)
rsm_half_x_half_y = rsm(i,j+1)
rhof_half_x_half_y = rhof(i,j+1)
etaokappa_half_x_half_y = etaokappa(i,j+1)
co=(rho_half_x_half_y*rsm_half_x_half_y-rhof_half_x_half_y**2)/DELTAT
c1=co+rho_half_x_half_y*etaokappa_half_x_half_y*0.5d0
c2=co-rho_half_x_half_y*etaokappa_half_x_half_y*0.5d0
vtemp=vyf(i,j)
value_dx_vy = (27.d0*sigmaxy(i+1,j) - 27.d0*sigmaxy(i,j)-sigmaxy(i+2,j)+sigmaxy(i-1,j)) / DELTAX/24.D0
value_dy_vy1 = (27.d0*sigmayy(i,j+1)- 27.d0*sigmayy(i,j)&
-sigmayy(i,j+2)+sigmayy(i,j-1)) / DELTAY/24.D0
value_dy_vy2 = (27.d0*sigma2(i,j+1) - 27.d0*sigma2(i,j)-sigma2(i,j+2)+sigma2(i,j-1)) / DELTAY/24.D0
memory_dx_vy(i,j) = b_x_half_x(i) * memory_dx_vy(i,j) + a_x_half_x(i) * value_dx_vy
memory_dy_vy1(i,j) = b_y_half_y(j) * memory_dy_vy1(i,j) + a_y_half_y(j) * value_dy_vy1
memory_dy_vy2(i,j) = b_y_half_y(j) * memory_dy_vy2(i,j) + a_y_half_y(j) * value_dy_vy2
vyf(i,j) = (c2*vyf(i,j) + &
(-rhof_half_x_half_y*(value_dx_vy / K_x_half_x(i) + memory_dx_vy(i,j) &
+value_dy_vy1 / K_y_half_y(j) + memory_dy_vy1(i,j))&
-rho_half_x_half_y*(value_dy_vy2 / K_y_half_y(j) + memory_dy_vy2(i,j)))&
) /c1
vtemp=(vtemp+vyf(i,j))*0.5d0
vy(i,j) = vy(i,j) + &
(rsm_half_x_half_y*(value_dx_vy / K_x_half_x(i) + memory_dx_vy(i,j)&
+ value_dy_vy1 / K_y_half_y(j) + memory_dy_vy1(i,j))&
+ rhof_half_x_half_y*(value_dy_vy2 / K_y_half_y(j) + memory_dy_vy2(i,j))&
+ rhof_half_x_half_y*etaokappa_half_x_half_y*vtemp)&
/co
enddo
enddo
! Dirichlet conditions (rigid boundaries) on the edges or at the bottom of the PML layers
vx(1,:) = ZERO
vx(NX,:) = ZERO
vx(:,1) = ZERO
vx(:,NY) = ZERO
vy(1,:) = ZERO
vy(NX,:) = ZERO
vy(:,1) = ZERO
vy(:,NY) = ZERO
vxf(1,:) = ZERO
vxf(NX,:) = ZERO
vxf(:,1) = ZERO
vxf(:,NY) = ZERO
vyf(1,:) = ZERO
vyf(NX,:) = ZERO
vyf(:,1) = ZERO
vyf(:,NY) = ZERO
! store seismograms
do irec = 1,NREC
! x component
sisvx(it,irec) = vx(ix_rec(irec),iy_rec(irec))
! y component
sisvy(it,irec) = vy(ix_rec(irec),iy_rec(irec))
! fluid pressure
sisp(it,irec) = sigma2(ix_rec(irec),iy_rec(irec))
enddo
! compute total energy
! compute kinetic energy first, defined as 1/2 rho ||v||^2
! in principle we should use rho_half_x_half_y instead of rho for vy
! in order to interpolate density at the right location in the staggered grid cell
! but in a homogeneous medium we can safely ignore it
total_energy_kinetic(it) = 0.5d0 * &
sum(rho(NPOINTS_PML:NX-NPOINTS_PML+1,NPOINTS_PML:NY-NPOINTS_PML+1)&
*(vx(NPOINTS_PML:NX-NPOINTS_PML+1,NPOINTS_PML:NY-NPOINTS_PML+1)**2&
+vy(NPOINTS_PML:NX-NPOINTS_PML+1,NPOINTS_PML:NY-NPOINTS_PML+1)**2))&
*DELTAX * DELTAY+&
0.5d0*sum(rsm(NPOINTS_PML:NX-NPOINTS_PML+1,NPOINTS_PML:NY-NPOINTS_PML+1)&
*(vxf(NPOINTS_PML:NX-NPOINTS_PML+1,NPOINTS_PML:NY-NPOINTS_PML+1)**2&
+vyf(NPOINTS_PML:NX-NPOINTS_PML+1,NPOINTS_PML:NY-NPOINTS_PML+1)**2))&
*DELTAX*DELTAY
! add potential energy, defined as 1/2 epsilon_ij sigma_ij
! in principle we should interpolate the medium parameters at the right location
! in the staggered grid cell but in a homogeneous medium we can safely ignore it
total_energy_potential(it) = ZERO
do j = NPOINTS_PML,NY-NPOINTS_PML+1
do i = NPOINTS_PML,NX-NPOINTS_PML+1
epsilon_xx = ((rlambdao(i,j) + 2.d0*rmu(i,j)) * sigmaxx(i,j) - rlambdao(i,j) * sigmayy(i,j)) / &
(4.d0 * rmu(i,j) * (rlambdao(i,j) + rmu(i,j)))
epsilon_yy = ((rlambdao(i,j) + 2.d0*rmu(i,j)) * sigmayy(i,j) - rlambdao(i,j) * sigmaxx(i,j)) / &
(4.d0 * rmu(i,j) * (rlambdao(i,j) + rmu(i,j)))
epsilon_xy = sigmaxy(i,j) / (2.d0 * rmu(i,j))
total_energy_potential(it) = total_energy_potential(it) + &
0.5d0 * (epsilon_xx * sigmaxx(i,j) + epsilon_yy * sigmayy(i,j) + 2.d0 * epsilon_xy * sigmaxy(i,j)&
+sigma2(i,j)**2/rbM(i,j)&
+2.d0*rhof(i,j)*(vx(i,j)*vxf(i,j)+vy(i,j)*vyf(i,j)))*DELTAX * DELTAY
enddo
enddo
! output information
if (mod(it,IT_DISPLAY) == 0 .or. it == 5) then
! print maximum of norm of velocity
velocnorm_all = maxval(sqrt(vx(:,:)**2 + vy(:,:)**2))
print *,'Time step # ',it,' out of ',NSTEP
print *,'Time: ',sngl((it-1)*DELTAT),' seconds'
print *,'Max norm velocity vector V (m/s) = ',velocnorm_all
print *,'total energy = ',total_energy_kinetic(it) + total_energy_potential(it)
print *
! check stability of the code, exit if unstable
if (velocnorm_all > STABILITY_THRESHOLD) stop 'code became unstable and blew up'
vnorm(:,:)=sqrt(vx(:,:)**2+vy(:,:)**2)
call create_color_image(vx,NX+2,NY+2,it,ISOURCE,JSOURCE,ix_rec,iy_rec,nrec, &
NPOINTS_PML,USE_PML_LEFT,USE_PML_RIGHT,USE_PML_BOTTOM, &
USE_PML_TOP,1,max_amplitude,JINTERFACE)
call create_color_image(vy,NX+2,NY+2,it,ISOURCE,JSOURCE,ix_rec,iy_rec,nrec, &
NPOINTS_PML,USE_PML_LEFT,USE_PML_RIGHT,USE_PML_BOTTOM, &
USE_PML_TOP,2,max_amplitude,JINTERFACE)
! save temporary partial seismograms to monitor the behavior of the simulation
! while it is running
call write_seismograms(sisvx,sisvy,sisp,NSTEP,NREC,DELTAT,t0)
endif
enddo ! end of time loop
! save seismograms
call write_seismograms(sisvx,sisvy,sisp,NSTEP,NREC,DELTAT,t0)
! save total energy
open(unit=20,file='energy.dat',status='unknown')
do it = 1,NSTEP
write(20,*) sngl(dble(it-1)*DELTAT), sngl(total_energy_kinetic(it) + total_energy_potential(it))
enddo
close(20)
! create script for Gnuplot for total energy
open(unit=20,file='plot_energy',status='unknown')
write(20,*) 'set term x11'
write(20,*) '# set term postscript landscape monochrome dashed "Helvetica" 22'
write(20,*) '# set xrange [0:7]'
write(20,*) '# set yrange [-4:4.5]'
write(20,*)
write(20,*) 'set xlabel "Time (s)"'