-
Notifications
You must be signed in to change notification settings - Fork 3
/
pve_iso_pml.c
1472 lines (1271 loc) · 61 KB
/
pve_iso_pml.c
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
/*
* pve_iso_pml.c
*
* Created by Bernard Giroux on 11-03-07.
*
* PoroViscoElastic wave propagation in 2D isotropic media, for one attenuation
* mechanism, on a staggered grid
*
* Bernard Giroux
* INRS-ETE
*
*
* Code specs: - language: ANSI C99
* - compiled with intel compiler 11.1 on a mac running OSX 10.6
* - external libraries: fftw ( http://www.fftw.org ),
* netCDF ( http://www.unidata.ucar.edu/software/netcdf/ )
*
*/
/*
* Copyright (c) 2011, Bernard Giroux
* All rights reserved.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the University of California, Berkeley nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
*
* Reference papers
*
@ARTICLE{carcione99b,
author = {Jos\'{e} M. Carcione and Hans B. Helle},
title = {Numerical Solution of the Poroviscoelastic Wave Equation on a Staggered Mesh},
journal = {Journal of Computational Physics},
year = {1999},
volume = {154},
pages = {520 - 527},
number = {2},
doi = {10.1006/jcph.1999.6321}
}
@ARTICLE{carcione96d,
author = {Jos\'{e} M. Carcione},
title = {Wave propagation in anisotropic, saturated porous media: Plane-wave
theory and numerical simulation},
journal = {Journal of the Acoustical Society of America},
year = {1996},
volume = {99},
pages = {2655-2666},
number = {5},
doi = {10.1121/1.414809}
}
@ARTICLE{carcione95b,
author = {Jos\'e M. Carcione and Gerardo Quiroga-Goode},
title = {Some aspects of the physics and numerical modeling of {B}iot compressional waves},
journal = {Journal of Computational Acoustics},
year = {1995},
volume = {3},
pages = {261--280},
number = {4},
doi = {10.1142/S0218396X95000136}
}
@ARTICLE{martin10,
author = {R. Martin and D. Komatitsch and S. D. Gedney and E. Bruthiaux},
title = {A High-Order Time and Space Formulation of the Unsplit Perfectly
Matched Layer for the Seismic Wave Equation Using Auxiliary Differential
Equations (ADE-PML)},
journal = {CMES: Computer Modeling in Engineering \& Sciences},
year = {2010},
volume = {56},
pages = {17--42},
doi = {10.3970/cmes.2010.056.017},
owner = {giroux},
timestamp = {2011.03.08}
}
note: the above paper has a sign error in eq 32: should read + before c_{1,i}
and another error in eq 33: \theta at the numerator should be (1-\theta).
*
*
*/
/*
------------------------------------------------------------------------------
Usage
pve_iso [options] -p parameter_file.dat
options are:
-h Print this message
-v verbose mode (type twice for increased verbosity)
-c checkpoint_file.dat Restart run using data in checkpoint_file.dat (-p argument ignored)
Format of parameter file:
One line per parameter, first word is the value of the parameter, next is a
keyword comprised between a # and a comma, and a comment can be added after the
comma, i.e we have on each line
value # keyword, optional comment
Example showing available keywords:
--- beginning of file ---
model.dat # model, model file
source.dat # source, source file
output.dat # output, description of output records
run1 # basename, common for all output files
1.2 # time, length of time window in s (default is 1.2)
0.1 # dt, time step in ms (default is 0.1)
0 # segy, save traces in segy format (0 or 1, 0 by default)
1 # abs, apply absorbing boundary (0 or 1, 0 by default)
20 # nl, number of absorbing layers (20 by default)
1 # plstr, plot absorbing strips in snapshots (0 or 1, 0 by default)
7 # kappa_max, PML parameter (1 by default)
1 # alpha_max, PML parameter. If 0, alpha = 1 everywhere in the PML; if 1 alpha_max = pi*f0
0.001 # Rc, theoretical coefficient of reflection of PML layer (1e-5 by default)
1 # saveEnergy, save E as fct of time
0/500/0/500 # EnergyROI, region of interest for saving E
1000 # chkpt_inc, checkpoint saving increment (0 by default, no checkpoint saving)
--- end of file ---
------------------------------------------------------------------------------
Format of model file
--- beginning of file ---
2 2 <- nx and nz, number of nodes in x & z
1.0 1.0 <- dx and dz, grid step size in x & z, in meters
0.0 0.0 <- origin of the grid, in meters
isotropic <- keyword for type of model (isotropic, anisotropic_vti)
K_m(1,1) K_s(1,1) K_f(1,1) phi(1,1) mu(1,1) rho_s(1,1) rho_f(1,1) T(1,1) eta(1,1) kappa(1,1) Q(1,1) f0(1,1)
K_m(1,2) K_s(1,2) K_f(1,2) phi(1,2) mu(1,2) rho_s(1,2) rho_f(1,2) T(1,2) eta(1,2) kappa(1,2) Q(1,2) f0(1,2)
K_m(2,1) K_s(2,1) K_f(2,1) phi(2,1) mu(2,1) rho_s(2,1) rho_f(2,1) T(2,1) eta(2,1) kappa(2,1) Q(2,1) f0(2,1)
K_m(2,2) K_s(2,2) K_f(2,2) phi(2,2) mu(2,2) rho_s(2,2) rho_f(2,2) T(2,2) eta(2,2) kappa(2,2) Q(2,2) f0(2,2)
...
K_m(nx,nz) K_s(nx,nz) K_f(nx,nz) phi(nx,nz) mu(nx,nz) rho_s(nx,nz) rho_f(nx,nz) T(nx,nz) eta(nx,nz) kappa(nx,nz) Q(nx,nz) f0(nx,nz)
--- end of file ---
Variable Description Units
K_m bulk modulus of drained matrix [ GPa ]
K_s bulk modulus of the solid [ GPa ]
K_f bulk modulus of the fluid [ GPa ]
phi porosity [ - ]
mu shear modulus of the matrix [ GPa ]
rho_s solid density [ kg/m^3 ]
rho_f fluid density [ kg/m^3 ]
T tortuosity [ - ]
eta fluid viscosity [ cP ]
kappa permeability [ mD ]
Q seismic quality factor [ - ]
f0 relaxation frequency [ Hz ]
note: 1 cP = 1e-3 Pa.s ; 1 mD = 9.869233e-10 m^2
*** Worthy option ***
Layered models can be input by giving values for just a vertical profile; they
will be duplicated automatically. For example:
--- beginning of file ---
2 2 <- nx and nz, number of nodes in x & z
1.0 1.0 <- dx and dz, grid step size in x & z, in meters
0.0 0.0 <- origin of the grid, in meters
isotropic <- keyword for type of model (isotropic, anisotropic_vti)
K_m(1,1) K_s(1,1) K_f(1,1) phi(1,1) mu(1,1) rho_s(1,1) rho_f(1,1) T(1,1) eta(1,1) kappa(1,1) Q(1,1) f0(1,1)
K_m(1,2) K_s(1,2) K_f(1,2) phi(1,2) mu(1,2) rho_s(1,2) rho_f(1,2) T(1,2) eta(1,2) kappa(1,2) Q(1,2) f0(1,2)
...
K_m(1,nz) K_s(1,nz) K_f(1,nz) phi(1,nz) mu(1,nz) rho_s(1,nz) rho_f(1,nz) T(1,nz) eta(1,nz) kappa(1,nz) Q(1,nz) f0(1,nz)
--- end of file ---
------------------------------------------------------------------------------
Format of source file
--- beginning of file ---
2 <- number of source points
1 <- Number of pts in source template, can be 1 or 9 (Lin et Thylén, 2009)
Sx <- Source component of 1st source point
10.0 <- Strength in MPa at 1st source point
50.0 <- Frequency in Hz at 1st source point
50.0 45.0 <- x z coordinates at 1st source point in meters
Sf <- Source component of 2nd source point
1.0 <- Strength in MPa at 2nd source point
50.0 <- Frequency in Hz at 2nd source point
50.0 45.0 <- x z coordinates at 2nd source point in meters
--- end of file ---
Components can be Sx, Sz, Sxz, Sf or Bulk
@ARTICLE{lin09,
author = {Zhili Lin and Lars Thylén},
title = {An analytical derivation of the optimum source patterns for the pseudospectral
time-domain method},
journal = {Journal of Computational Physics},
year = {2009},
volume = {228},
pages = {7375 - 7387},
number = {19},
doi = {10.1016/j.jcp.2009.06.033}
}
------------------------------------------------------------------------------
Format of file defining the outputs
--- beginning of file ---
2 <- number of records
Vx <- particle velocity component of 1st record
Trace <- type of 1st record
10.0 20.0 <- X Z coordinates at 1st record point in meters
0.0 <- start time of 1st recording, in seconds
2.0 <- time sampling of 1st record, in miliseconds
Qx <- particle velocity component of 2nd record
Snapshot <- type of 2nd record
0.0 <- start time of snapshot(s) (2nd recording), in seconds
2.0 <- time sampling of snapshot(s) 2nd record, in miliseconds.
Give 0.0 or less for just one snapshot at time given above.
--- end of file ---
Trace files are ascii files and snapshots are binary grid files in netCDF format (COARDS-compliant).
Files names are
basename_NO.trc for traces, where NO is the record number
basename_NO_TIME.nc for snapshots, where NO is record number and TIME is the record time
Trace files are two columns, first for time and second for velocity component.
Velocity components in traces are _not_ interpolated at exact X and Z coordinates,
but rather taken at the closest grid point.
Snapshot grids can be viewed in matlab, with Paraview ( http://www.paraview.org/ ) or by
using GMT routines ( http://www.soest.hawaii.edu/gmt/ ) to create plots.
Units of particle velocity are mm/s, time in s and distances in m.
*/
#include <sys/stat.h>
#include <errno.h>
#include <complex.h>
#include <math.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "io_utils.h"
#include "pml.h"
#include "propagate.h"
#include "structs.h"
#include "src.h"
int verbose=0;
char *parFormat =
"Format of parameter file:\n\
\n\
One line per parameter, first word is the value of the parameter,\n\
next is a keyword comprise between a # and a comma, and a comment\n\
can be added after the comma, i.e we have on each line\n\n\
value # keyword, optional comment\n\n\
Example showing available keywords:\n\
--- beginning of file ---\n\
model.dat # model, model file\n\
source.dat # source, source file\n\
output.dat # output, description of output records\n\
run1 # basename, common for all output files\n\
1.2 # time, length of time window in s (default is 1.2)\n\
0.1 # dt, time step in ms (default is 0.1)\n\
0 # segy, save traces in segy format (0 or 1, 0 by default)\n\
1 # shotpoint, Shotpoint number for segy file (1 by default)\n\
0 # simulateCMP, for 1D model save SEGY as a CMP\n\
0 # check_model, compute phase vel and attenuation (0, 1 (display) or 2 (store), 0 by default)\n\
1 # abs, apply absorbing boundary (0 or 1, 0 by default)\n\
20 # nl, number of absorbing layers (20 by default)\n\
1 # plstr, plot absorbing strips in snapshots (0 or 1, 0 by default)\n\
7 # kappa_max, PML parameter (1 by default)\n\
1 # alpha_max, PML parameter. If 0, alpha = 1 everywhere in the PML; if 1 alpha_max = pi*f0\n\
0.001 # Rc, theoretical coeff of reflection of PML layer (1e-5 by default)\n\
1 # saveEnergy, save E as fct of time\n\
0/500/0/500 # EnergyROI, region of interest for saving E\n\
1000 # chkpt_inc, checkpoint saving increment (0 by default, no checkpoint saving)\n\
--- end of file ---\n";
char *modelFormat =
"Format of model file\n\
\n\
--- beginning of file ---\n\
2 2 <- nx and nz, number of nodes in x & z\n\
1.0 1.0 <- dx and dz, grid step size in x & z, in meters\n\
0.0 0.0 <- origin of the grid, in meters\n\
isotropic <- keyword for type of model (isotropic, anisotropic_vti)\n\
K_m(1,1) K_s(1,1) K_f(1,1) phi(1,1) mu(1,1) rho_s(1,1) rho_f(1,1) T(1,1) eta(1,1) kappa(1,1) Q(1,1) f0(1,1)\n\
K_m(1,2) K_s(1,2) K_f(1,2) phi(1,2) mu(1,2) rho_s(1,2) rho_f(1,2) T(1,2) eta(1,2) kappa(1,2) Q(1,2) f0(1,2)\n\
K_m(2,1) K_s(2,1) K_f(2,1) phi(2,1) mu(2,1) rho_s(2,1) rho_f(2,1) T(2,1) eta(2,1) kappa(2,1) Q(2,1) f0(2,1)\n\
K_m(2,2) K_s(2,2) K_f(2,2) phi(2,2) mu(2,2) rho_s(2,2) rho_f(2,2) T(2,2) eta(2,2) kappa(2,2) Q(2,2) f0(2,2)\n\
...\n\
K_m(nx,nz) K_s(nx,nz) K_f(nx,nz) phi(nx,nz) mu(nx,nz) rho_s(nx,nz) rho_f(nx,nz) T(nx,nz) eta(nx,nz) kappa(nx,nz) Q(nx,nz) f0(nx,nz)\n\
--- end of file ---\n\
\n\
Variable Description Units\n\
\n\
K_m bulk modulus of drained matrix [ GPa ]\n\
K_s bulk modulus of the solid [ GPa ]\n\
K_f bulk modulus of the fluid [ GPa ]\n\
phi porosity [ - ]\n\
mu shear modulus of the matrix [ GPa ]\n\
rho_s solid density [ kg/m^3 ]\n\
rho_f fluid density [ kg/m^3 ]\n\
T tortuosity [ - ]\n\
eta fluid viscosity [ cP ]\n\
kappa permeability [ mD ]\n\
Q seismic quality factor [ - ]\n\
f0 relaxation frequency [ Hz ]\n\
\n\
note: 1 cP = 1e-3 Pa.s ; 1 mD = 9.869233e-10 m^2\n\
\n\
*** Worthy option ***\n\
\n\
Layered models can be input by giving values for just a vertical profile; they\n\
will be duplicated automatically. For example:\n\
\n\
--- beginning of file ---\n\
2 2 <- nx and nz, number of nodes in x & z\n\
1.0 1.0 <- dx and dz, grid step size in x & z, in meters\n\
0.0 0.0 <- origin of the grid, in meters\n\
isotropic <- keyword for type of model (isotropic, anisotropic_vti)\n\
K_m(1,1) K_s(1,1) K_f(1,1) phi(1,1) mu(1,1) rho_s(1,1) rho_f(1,1) T(1,1) eta(1,1) kappa(1,1) Q(1,1) f0(1,1)\n\
K_m(1,2) K_s(1,2) K_f(1,2) phi(1,2) mu(1,2) rho_s(1,2) rho_f(1,2) T(1,2) eta(1,2) kappa(1,2) Q(1,2) f0(1,2)\n\
...\n\
K_m(1,nz) K_s(1,nz) K_f(1,nz) phi(1,nz) mu(1,nz) rho_s(1,nz) rho_f(1,nz) T(1,nz) eta(1,nz) kappa(1,nz) Q(1,nz) f0(1,nz)\n\
--- end of file ---\n";
char *srcFormat =
"Format of source file\n\
\n\
--- beginning of file ---\n\
2 <- number of source points\n\
1 <- Number of pts in source template, can be 1 or 9 (Lin et Thylén, 2009)\n\
\n\
Sz <- Source component of 1st source point\n\
10.0 <- Strength in MPa at 1st source point\n\
50.0 <- Frequency in Hz at 1st source point\n\
50.0 45.0 <- x z coordinates at 1st source point in meters\n\
\n\
Sx <- Source component of 2nd source point\n\
1.0 <- Strength in MPa at 2nd source point\n\
50.0 <- Frequency in Hz at 2nd source point\n\
50.0 45.0 <- x z coordinates at 2nd source point in meters\n\
--- end of file ---\n\
\n\
Components can be Sx, Sz, Sxz, Sf or Bulk\n\
\n\
@ARTICLE{lin09,\n\
author = {Zhili Lin and Lars Thylén},\n\
title = {An analytical derivation of the optimum source patterns for the\n\
pseudospectral time-domain method},\n\
journal = {Journal of Computational Physics},\n\
year = {2009},\n\
volume = {228},\n\
pages = {7375 - 7387},\n\
number = {19},\n\
doi = {10.1016/j.jcp.2009.06.033}\n\
}\n";
char *rcvFormat =
"Format of file defining the outputs\n\
\n\
--- beginning of file ---\n\
2 <- number of records\n\
\n\
Vz <- particle velocity component of 1st record\n\
Trace <- type of 1st record\n\
10.0 20.0 <- X Z coordinates at 1st record point in meters\n\
0.0 <- start time of 1st recording, in seconds\n\
2.0 <- time sampling of 1st record, in miliseconds\n\
\n\
Qz <- particle velocity component of 2nd record\n\
Snapshot <- type of 2nd record\n\
0.0 <- start time of snapshot(s) (2nd recording), in seconds\n\
2.0 <- time sampling of snapshot(s) 2nd record, in miliseconds.\n\
Give 0.0 or less for just one snapshot at time given above.\n\
--- end of file ---\n\
\n\
Trace files are ascii files and snapshots are binary grid files in netCDF format\n\
(COARDS-compliant).\n\
\n\
Files names are\n\
\n\
basename_NO.trc for traces, where NO is the record number\n\
basename_NO_TIME.nc for snapshots, where NO is record number and TIME is\n\
the record time\n\
\n\
Trace files are two columns, first for time and second for velocity component.\n\
Velocity components in traces are _not_ interpolated at exact X and Z\n\
coordinates, but rather taken at the closest grid point.\n\
Snapshot can be viewed in matlab, with Paraview ( http://www.paraview.org/ )\n\
or by using GMT routines ( http://www.soest.hawaii.edu/gmt/ ) to create plots.\n\
\n\
Units of particle velocity are mm/s, time in s and distances in m.\n";
int main (int argc, char *argv[]) {
struct inputParams params;
struct computationVariables c;
struct fac_pml fp1, fp23, fp4;
struct mem_pml mem[3];
struct materialProperties mp;
struct fftw_data fd;
struct sourceParams src;
struct outputParams out;
struct saveEnergy se;
// -------------------------------------------------------------------------
//
// variables
//
// -------------------------------------------------------------------------
const double pi = 4.0*atan(1.0);
// const double L = 1.0; // number of attenuation mechanisms
const char *typeSrc[] = { "Sx", "Sy", "Sz", "Sxy", "Sxz", "Syz", "Bulk", "Sf", "Bulk_s" };
const char *component[] = { "Vx", "Vy", "Vz", "qx", "qz", "tau_xx", "tau_zz", "tau_xz", "p", "tau_xy", "tau_yz", "divergence", "curl" };
//
// time variables
//
size_t nsteps=0;
//
// Grid properties
//
struct grid g;
//
// Source parameters
//
double f0=0.0; // nominal frequency
//
// Motion variables
//
double *tau_xx; // stress in x on plane normal to x
double *tau_zz; // stress in z on plane normal to z
double *tau_xz; // stress in x on plane normal to z
double *p; // fluid pressure
double *v_x; // solid particle velocity along x
double *v_z; // solid particle velocity along z
double *q_x; // fluid particle velocity (relative to solid) along x
double *q_z; // fluid particle velocity (relative to solid) along z
double *vs_x; // solid particle velocity along x
double *vs_z; // solid particle velocity along z
double *qs_x; // fluid particle velocity (relative to solid) along x
double *qs_z; // fluid particle velocity (relative to solid) along z
double *div;
double *curl;
params.hasDiv = 0;
params.hasCurl = 0;
double *tau_xxtmp;
double *tau_zztmp;
double *tau_xztmp;
double *ptmp;
// double *e; // memory variable (one att. mechanism),
double *m; // term in Darcy's law
double *rho; // composite density [ kg/m^3 ]
double *coeff_v_i; // coefficients for analytical solution of the stiff system
double *coeff_v_j;
double *coeff_q_i;
double *coeff_q_j;
double *W;
double *Ws;
double *Wtmp;
double *delta;
size_t itstart = 0;
params.ab = &g.ab;
set_defaults(&g, ¶ms);
process_args(argc, argv, ¶ms);
if ( params.checkpoint == 1 ) {
if ( verbose ) {
fprintf(stdout, "\n *** pve_vti - PoroViscoElastic wave propagation in 2D isotropic media ***\n\n");
fprintf(stdout, " Starting with checkpoint file %s\n\n", params.checkpointfile);
}
read_checkpoint1(params.checkpointfile, &itstart, &g, ¶ms);
itstart++;
if ( verbose ) {
if ( verbose > 1 ) {
fprintf(stdout, " Model file: \t%s\n", params.modelfile);
fprintf(stdout, " Source file:\t%s\n", params.sourcefile);
fprintf(stdout, " Output file:\t%s\n", params.outputfile);
fprintf(stdout, " Time window:\t%lg (s)\n", params.duration);
fprintf(stdout, " Time step: \t%lg (ms)\n", params.dt * 1.e3);
fprintf(stdout, " Model parameters: \t\tX\t\tZ\n");
fprintf(stdout, " grid points \t\t%zd\t\t%zd\n", g.nx, g.nz);
fprintf(stdout, " grid spacing\t\t%lg\t\t%lg\n", g.dx, g.dz);
fprintf(stdout, " grid origin \t\t%lg\t\t%lg\n", g.x0, g.z0);
fprintf(stdout, " pml padding\t\t%zd\t\t%zd\n", g.ab.np, g.ab.np);
fprintf(stdout, " pml - Rc \t\t%lg\n", g.ab.Rc);
fprintf(stdout, " pml - kappa_max\t\t%lg\n", g.ab.kappa_max);
}
fprintf(stdout, "Allocating memory ... ");
fflush(stdout);
}
} else {
strcpy(out.basename, params.basename);
if ( verbose ) {
fprintf(stdout, "\n *** pve_iso - PoroViscoElastic wave propagation in 2D isotropic media ***\n\n");
if ( verbose > 1 ) {
fprintf(stdout, " Model file: \t%s\n", params.modelfile);
fprintf(stdout, " Source file:\t%s\n", params.sourcefile);
fprintf(stdout, " Output file:\t%s\n", params.outputfile);
fprintf(stdout, " Time window:\t%lg (s)\n", params.duration);
fprintf(stdout, " Time step: \t%lg (ms)\n", params.dt * 1.e3);
if ( params.chkpt_inc > 0 )
fprintf(stdout, " Checkpointing every %d iterations applied\n", params.chkpt_inc );
}
fprintf(stdout, "Reading size of model ... ");
}
read_grid_params(params.modelfile, &g);
if ( verbose ) {
fprintf(stdout, "done.\n");
if ( verbose > 1 ) {
fprintf(stdout, " Model parameters: \t\tX\t\tZ\n");
fprintf(stdout, " grid points \t\t%zd\t\t%zd\n", g.nx, g.nz);
fprintf(stdout, " grid spacing\t\t%lg\t\t%lg\n", g.dx, g.dz);
fprintf(stdout, " grid origin \t\t%lg\t\t%lg\n", g.x0, g.z0);
fprintf(stdout, " pml padding\t\t%zd\t\t%zd\n", g.ab.np, g.ab.np);
fprintf(stdout, " pml - Rc \t\t%lg\n", g.ab.Rc);
fprintf(stdout, " pml - kappa_max\t\t%lg\n", g.ab.kappa_max);
if ( g.ab.median ) fprintf(stdout, " pml - median smoothing applied\n");
}
fprintf(stdout, "Allocating memory ... ");
fflush(stdout);
}
}
c.dt = params.dt;
//
// Memory allocation
//
size_t nnodes = g.nx2 * g.nz2;
if ( NULL == ( mp.K_m = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.K_s = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.K_f = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.phi = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.mu = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.rho_s = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.rho_f = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.T = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.eta = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.kappa = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.Q = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( mp.f0 = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.epsilon = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.E = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.M = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.alpha = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.varphi = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.tau_s = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.rho_i = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.rho_j = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.rho_f_i = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.rho_f_j = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.nk_i = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.nk_j = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.mu_ij = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.m_i = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( c.m_j = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( m = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( rho = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( coeff_v_i = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( coeff_v_j = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( coeff_q_i = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( coeff_q_j = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( W = (double *) malloc( 9*nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( Ws = (double *) malloc( 9*nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( Wtmp = (double *) malloc( 9*nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( delta = (double *) malloc( 9*nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
alloc_cpml(&fp1, &fp23, &fp4, mem, &g);
c.mu = &(mp.mu[0]);
if ( params.checkpoint == 1 ) {
if ( verbose ) {
fprintf(stdout, "done.\nReading main variables from checkpoint file ... ");
fflush(stdout);
}
read_checkpoint2(params.checkpointfile, &g, ¶ms, &src, &out, &se,
&fp1, &fp23, &fp4, mem, &c, coeff_v_i, coeff_v_j,
coeff_q_i, coeff_q_j, W, Ws, Wtmp, delta);
if ( verbose ) {
fprintf(stdout, "done.\n");
fflush(stdout);
}
} else {
if ( params.chkpt_inc > 0 ) params.checkpoint = 1;
//
// Read in model
//
if ( verbose ) {
fprintf(stdout, "done.\nReading properties of materials ... ");
fflush(stdout);
}
read_model(params.modelfile, &g, &mp);
#ifdef DEBUG
write_field_nc(mp.K_m, "K_m", "GPa", &g, &out, params.plotStrips);
write_field_nc(mp.K_s, "K_s", "GPa", &g, &out, params.plotStrips);
write_field_nc(mp.K_f, "K_f", "GPa", &g, &out, params.plotStrips);
write_field_nc(mp.phi, "phi", "-", &g, &out, params.plotStrips);
write_field_nc(mp.mu , "mu", "GPa", &g, &out, params.plotStrips);
write_field_nc(mp.rho_s, "rho_s", "kg/m3", &g, &out, params.plotStrips);
write_field_nc(mp.rho_f, "rho_f", "kg/m3", &g, &out, params.plotStrips);
write_field_nc(mp.T , "Tortuosity", "-", &g, &out, params.plotStrips);
write_field_nc(mp.eta, "eta", "cP", &g, &out, params.plotStrips);
write_field_nc(mp.kappa, "kappa", "mD", &g, &out, params.plotStrips);
write_field_nc(mp.Q, "Q", "-", &g, &out, params.plotStrips);
write_field_nc(mp.f0, "f0", "Hz", &g, &out, params.plotStrips);
#endif
//
// Read in source params
//
if ( verbose ) {
fprintf(stdout, "done.\nReading source parameters ... ");
fflush(stdout);
}
read_source(params.sourcefile, &g, &src);
f0 = src.s[0].f;
compute_src_fct(&src, params.dt, 0.5);
normalize_src_fct(&src, &g);
//
// Read in output params
//
if ( verbose ) {
fprintf(stdout, "done.\n");
if ( verbose > 1 ) {
fprintf(stdout, "Source has %zd component(s)\n", src.nsrc);
double fac =1.;
if ( src.nTemplate == 9 ) {
fac = 2.;
fprintf(stdout, " Each component uses a %zd points template\n", src.nTemplate);
}
for ( size_t ns=0; ns<src.nsrc*src.nTemplate; ns+=src.nTemplate ) {
size_t nos = 1+(ns/src.nTemplate);
fprintf(stdout, " %zd - type: \t%s\n", nos, typeSrc[src.s[ns].type]);
fprintf(stdout, " %zd - frequency: \t%lg Hz\n", nos, src.s[ns].f);
fprintf(stdout, " %zd - strength: \t%lg MPa\n", nos, src.s[ns].A*fac);
fprintf(stdout, " %zd - coordinates:\t(%lg, %lg)\n", nos, src.s[ns].x, src.s[ns].z);
}
}
fprintf(stdout, "Reading output parameters ... ");
fflush(stdout);
}
read_output(params.outputfile, &g, &out);
check_dt_trc(&out, params.dt);
if ( params.segy == 1 ) {
for ( size_t n=0; n<out.nrec; ++n ) {
if ( out.r[n].type == TRACE ) {
size_t nsamples = round( params.duration / out.r[n].dt );
if ( NULL == ( out.r[n].data = (float *) malloc( nsamples * sizeof(float) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
}
}
}
if ( verbose ) {
fprintf(stdout, "done.\n");
if ( verbose > 1 ) {
fprintf(stdout, "There will be %zd record(s) on output\n", out.nrec);
if ( params.segy == 1 ) {
fprintf(stdout, " Traces will be saved in SEG Y format in segy/%s.segy\n", params.basename);
}
fprintf(stdout, " Snapshots will ");
if ( !params.plotStrips ) fprintf(stdout, "not ");
fprintf(stdout, "include absorbing strips.\n");
for ( size_t nr=0; nr<out.nrec; ++nr ) {
if ( out.r[nr].type == TRACE ) {
fprintf(stdout, " %zd - Trace of %s at (%lg, %lg), ",
nr+1, component[out.r[nr].comp], out.r[nr].x, out.r[nr].z);
fprintf(stdout, "starting at %lg s & sampled at %lg ms\n",
out.r[nr].t0, 1.e3*out.r[nr].dt);
}
else if ( out.r[nr].type == SNAPSHOT ) {
if ( out.r[nr].dt <= 0.0 )
fprintf(stdout, " %zd - Snapshot of %s at time %lg s\n",
nr+1, component[out.r[nr].comp], out.r[nr].t0);
else
fprintf(stdout, " %zd - Snapshot of %s, starting at %lg s & sampled at %lg ms\n",
nr+1, component[out.r[nr].comp], out.r[nr].t0, 1.e3*out.r[nr].dt);
}
if ( out.r[nr].comp == DIV ) params.hasDiv = 1;
if ( out.r[nr].comp == CURL ) params.hasCurl = 1;
}
}
}
if ( params.saveEnergy == 1 ) {
struct stat sb;
if ( stat("E", &sb) < 0 ) {
if ( errno == ENOENT ) {
mkdir("E", S_IRWXU);
}
}
char fname[80];
sprintf(fname, "E/%s_E.dat", params.basename );
se.fid = fopen( fname, "w+" );
if ( verbose ) {
fprintf(stdout, "Saving kinetic energy as fct of time in %s\n", fname);
if (params.roiExmin<g.x0 || params.roiExmax>(g.x0+(g.nx-1)*g.dx) ||
params.roiEzmin<g.z0 || params.roiEzmax>(g.z0+(g.nz-1)*g.dz)) {
fprintf(stderr, "Region of interest for saving energy not fitting in the modeling grid\n");
abort();
}
fprintf(stdout, " Region of interest is %lg/%lg/%lg/%lg\n",
params.roiExmin, params.roiExmax, params.roiEzmin, params.roiEzmax);
}
se.i1E = lround( (params.roiExmin-g.x0)/g.dx );
se.i2E = lround( (params.roiExmax-g.x0)/g.dx );
se.j1E = lround( (params.roiEzmin-g.z0)/g.dz );
se.j2E = lround( (params.roiEzmax-g.z0)/g.dz );
}
if ( verbose ) fprintf(stdout, "Computing CPML parameters ... ");
double alpha_max = pi*src.s[0].f;
if ( g.ab.alpha_max == 0 ) alpha_max = 0.0;
compute_cpml(&fp1, &fp23, &fp4, &g, params.dt, alpha_max, params.iwipe);
if ( verbose ) {
fprintf(stdout, "done.\nPreprocessing data ... ");
fflush(stdout);
}
//
// Scale input data
//
for ( size_t n=0; n<nnodes; ++n ) {
mp.K_m[n] *= 1000.; // now in MPa
mp.K_s[n] *= 1000.; // now in MPa
mp.K_f[n] *= 1000.; // now in MPa
mp.mu[n] *= 1000.; // now in MPa
mp.eta[n] *= 1.013249965828145e6; // eta/kappa will be in Mega. kg/m^3/s
mp.rho_s[n] *= 1.e-6; // density are now in Gg/m^3 (Mega. kg/m^3)
mp.rho_f[n] *= 1.e-6;
}
//
// Compute elastic & other physical params
//
for ( size_t n=0; n<nnodes; ++n ) {
double tau0 = 1./(2. * pi * mp.f0[n]);
c.E[n] = mp.K_m[n] + 4./3.*mp.mu[n]; // eq (6)
double D = mp.K_s[n] * (1. + mp.phi[n]*(mp.K_s[n]/mp.K_f[n] - 1. )); // eq (8)
c.M[n] = mp.K_s[n]*mp.K_s[n] / (D - mp.K_m[n]); // eq (7)
c.alpha[n] = 1. - mp.K_m[n]/mp.K_s[n]; // eq (9)
m[n] = mp.T[n]*mp.rho_f[n] / mp.phi[n];
if ( mp.Q[n] < 1.e4 ) {
double tau_e = tau0/mp.Q[n] * (sqrt(mp.Q[n]*mp.Q[n] + 1.) + 1.);
c.tau_s[n] = tau0/mp.Q[n] * (sqrt(mp.Q[n]*mp.Q[n] + 1.) - 1.);
c.varphi[n] = tau_e/c.tau_s[n] - 1.; // eq (19)
} else {
c.tau_s[n] = tau0;
c.varphi[n] = 0.0;
}
rho[n] = (1.-mp.phi[n])*mp.rho_s[n] + mp.phi[n]*mp.rho_f[n];
}
// smoothing absorbing region with median filter of increasing size (3x3 up to 9x9)
if ( g.ab.median == 1 ) {
pml_median_average( c.mu, &g );
pml_median_average( c.E, &g );
pml_median_average( c.M, &g );
pml_median_average( c.alpha, &g );
pml_median_average( c.varphi, &g );
pml_median_average( c.tau_s, &g );
pml_median_average( rho, &g );
pml_median_average( mp.rho_f, &g );
pml_median_average( mp.eta, &g );
pml_median_average( mp.kappa, &g );
pml_median_average( m, &g );
}
double c_p_m[6] = { 0., 0., 0., 1.e9, 1.e9, 1.e9 };
double c_p_p[6] = { 0., 0., 0., 1.e9, 1.e9, 1.e9 };
double c_s[6] = { 0., 0., 0., 1.e9, 1.e9, 1.e9 };
double a_p_m[6] = { 0., 0., 0., 1.e9, 1.e9, 1.e9 };
double a_p_p[6] = { 0., 0., 0., 1.e9, 1.e9, 1.e9 };
double a_s[6] = { 0., 0., 0., 1.e9, 1.e9, 1.e9 };
if ( params.check_model > 0 ) {
// check phase velocities and attenuation
double *Vp_p, *Vp_m, *Vs, *Ap_p, *Ap_m, *As;
if ( NULL == ( Vp_p = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( Vp_m = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( Vs = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( Ap_p = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( Ap_m = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
if ( NULL == ( As = (double *) malloc( nnodes * sizeof(double) ))) { fprintf(stderr, "Error: cannot allocate memory\n"); abort(); }
for ( size_t n=0; n<nnodes; ++n ) {
double tau0 = 1./(2. * pi * mp.f0[n]);
double tau_e = tau0;
if ( mp.Q[n] < 1.e4 ) {
tau_e = tau0/mp.Q[n] * (sqrt(mp.Q[n]*mp.Q[n] + 1.) + 1.);
}
double f = 1.0; // low frequency, 1 Hz
double omega = 2.*pi*f;
complex double rho_bar = mp.T[n]/mp.phi[n]*mp.rho_f[n] - I/omega * (mp.eta[n]/mp.kappa[n]);
complex double rho_c = rho[n] - mp.rho_f[n]*mp.rho_f[n]/rho_bar;
complex double M_c = c.M[n] / ( 1. + c.varphi[n] ) * (1. + I*omega*tau_e)/(1. + I*omega*c.tau_s[n]);
complex double A = M_c*(rho[n]-2.*c.alpha[n]*mp.rho_f[n]) +
rho_bar*(c.E[n] + c.alpha[n]*c.alpha[n]*M_c);
complex double tmp = csqrt( A*A - 4.*M_c*c.E[n]*rho_c*rho_bar);
complex double V_p_m = csqrt( ( A - tmp ) / (2.*rho_c*rho_bar) );
complex double V_p_p = csqrt( ( A + tmp ) / (2.*rho_c*rho_bar) );
complex double V_s = csqrt( mp.mu[n] / rho_c );
double t = 1. / ( creal(1./V_p_m) );
c_p_m[0] = t>c_p_m[0] ? t : c_p_m[0];
c_p_m[3] = t<c_p_m[3] ? t : c_p_m[3];
t = 1. / ( creal(1./V_p_p) );
c_p_p[0] = t>c_p_p[0] ? t : c_p_p[0];
c_p_p[3] = t<c_p_p[3] ? t : c_p_p[3];
t = 1. / ( creal(1./V_s) );
c_s[0] = t>c_s[0] ? t : c_s[0];
c_s[3] = t<c_s[3] ? t : c_s[3];
t = 17.372*pi*cimag(V_p_m)/creal(V_p_m);
a_p_m[0] = t>a_p_m[0] ? t : a_p_m[0];
a_p_m[3] = t<a_p_m[3] ? t : a_p_m[3];
t = 17.372*pi*cimag(V_p_p)/creal(V_p_p);
a_p_p[0] = t>a_p_p[0] ? t : a_p_p[0];
a_p_p[3] = t<a_p_p[3] ? t : a_p_p[3];
t = 17.372*pi*cimag(V_s)/creal(V_s);
a_s[0] = t>a_s[0] ? t : a_s[0];
a_s[3] = t<a_s[3] ? t : a_s[3];
f = f0; // src frequency
omega = 2.*pi*f;
rho_bar = mp.T[n]/mp.phi[n]*mp.rho_f[n] - I/omega * mp.eta[n]/mp.kappa[n];
rho_c = rho[n] - mp.rho_f[n]*mp.rho_f[n]/rho_bar;
M_c = c.M[n] / ( 1. + c.varphi[n] ) * (1. + I*omega*tau_e)/(1. + I*omega*c.tau_s[n]);
A = M_c*(rho[n]-2.*c.alpha[n]*mp.rho_f[n]) +
rho_bar*(c.E[n] + c.alpha[n]*c.alpha[n]*M_c);
tmp = csqrt( A*A - 4.*M_c*c.E[n]*rho_c*rho_bar);
V_p_m = csqrt( ( A - tmp ) / (2.*rho_c*rho_bar) );
V_p_p = csqrt( ( A + tmp ) / (2.*rho_c*rho_bar) );
V_s = csqrt( mp.mu[n] / rho_c );
Vp_m[n] = 1. / ( creal(1./V_p_m) );
Vp_p[n] = 1. / ( creal(1./V_p_p) );
Vs[n] = 1. / ( creal(1./V_s) );;
t = Vp_m[n];
c_p_m[1] = t>c_p_m[1] ? t : c_p_m[1];
c_p_m[4] = t<c_p_m[4] ? t : c_p_m[4];
t = Vp_p[n];
c_p_p[1] = t>c_p_p[1] ? t : c_p_p[1];
c_p_p[4] = t<c_p_p[4] ? t : c_p_p[4];
t = Vs[n];
c_s[1] = t>c_s[1] ? t : c_s[1];
c_s[4] = t<c_s[4] ? t : c_s[4];
Ap_m[n] = 17.372*pi*cimag(V_p_m)/creal(V_p_m);
Ap_p[n] = 17.372*pi*cimag(V_p_p)/creal(V_p_p);
As[n] = 17.372*pi*cimag(V_s)/creal(V_s);
t = Ap_m[n];
a_p_m[1] = t>a_p_m[1] ? t : a_p_m[1];
a_p_m[4] = t<a_p_m[4] ? t : a_p_m[4];
t = Ap_p[n];
a_p_p[1] = t>a_p_p[1] ? t : a_p_p[1];
a_p_p[4] = t<a_p_p[4] ? t : a_p_p[4];
t = As[n];
a_s[1] = t>a_s[1] ? t : a_s[1];
a_s[4] = t<a_s[4] ? t : a_s[4];
f = 1./c.dt; // high frequency
omega = 2.*pi*f;
rho_bar = mp.T[n]/mp.phi[n]*mp.rho_f[n] - I/omega * mp.eta[n]/mp.kappa[n];
rho_c = rho[n] - mp.rho_f[n]*mp.rho_f[n]/rho_bar;
M_c = c.M[n] / ( 1. + c.varphi[n] ) * (1. + I*omega*tau_e)/(1. + I*omega*c.tau_s[n]);
A = M_c*(rho[n]-2.*c.alpha[n]*mp.rho_f[n]) +
rho_bar*(c.E[n] + c.alpha[n]*c.alpha[n]*M_c);
tmp = csqrt( A*A - 4.*M_c*c.E[n]*rho_c*rho_bar);
V_p_m = csqrt( ( A - tmp ) / (2.*rho_c*rho_bar) );
V_p_p = csqrt( ( A + tmp ) / (2.*rho_c*rho_bar) );
V_s = csqrt( mp.mu[n] / rho_c );
t = 1. / ( creal(1./V_p_m) );
c_p_m[2] = t>c_p_m[2] ? t : c_p_m[2];
c_p_m[5] = t<c_p_m[5] ? t : c_p_m[5];
t = 1. / ( creal(1./V_p_p) );
c_p_p[2] = t>c_p_p[2] ? t : c_p_p[2];
c_p_p[5] = t<c_p_p[5] ? t : c_p_p[5];
t = 1. / ( creal(1./V_s) );
c_s[2] = t>c_s[2] ? t : c_s[2];
c_s[5] = t<c_s[5] ? t : c_s[5];
t = 17.372*pi*cimag(V_p_m)/creal(V_p_m);
a_p_m[2] = t>a_p_m[2] ? t : a_p_m[2];
a_p_m[5] = t<a_p_m[5] ? t : a_p_m[5];
t = 17.372*pi*cimag(V_p_p)/creal(V_p_p);
a_p_p[2] = t>a_p_p[2] ? t : a_p_p[2];
a_p_p[5] = t<a_p_p[5] ? t : a_p_p[5];
t = 17.372*pi*cimag(V_s)/creal(V_s);
a_s[2] = t>a_s[2] ? t : a_s[2];
a_s[5] = t<a_s[5] ? t : a_s[5];
}
if ( params.check_model > 1 ) {
if ( verbose > 1 ) {
fprintf(stdout, " Saving phase velocity and attenuation @ src frequency ...");
fflush(stdout);
}
write_field_nc(Vp_m, "vel_slowP", "m/s", &g, &out, 1);
write_field_nc(Vp_p, "vel_fastP", "m/s", &g, &out, 1);
write_field_nc(Vs, "vel_S", "m/s", &g, &out, 1);
write_field_nc(Ap_m, "att_slowP", "1/m", &g, &out, 1);
write_field_nc(Ap_p, "att_fastP", "1/m", &g, &out, 1);
write_field_nc(As, "att_S", "1/m", &g, &out, 1);
}
free( Vp_p );
free( Vp_m );