forked from bakerb845/fem25
-
Notifications
You must be signed in to change notification settings - Fork 0
/
locrec2d.f
1186 lines (1183 loc) · 41.6 KB
/
locrec2d.f
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
SUBROUTINE LOCREC2D(MDIM,MEN,MGNOD, NNPG,NREC,NLXI,NLETA,
; LVERB, NELEM,NGNOD,NDIM, CNNPG,LFSURF,IENG,LM,
; XIPTS,ETAPTS,XREC,ZREC,XLOCS,ZLOCS,
; MRDOF,IERR)
!
! This pairs the receivers with a degree of freedom based on
! collocation to the nearest degree of freedom and the receivers
! (x,z) position
!
!.... variable declarations
IMPLICIT REAL*8 (A-H,O-Z)
CHARACTER(2), INTENT(IN) :: CNNPG(NNPG)
REAL*8, INTENT(IN) :: XREC(NREC), ZREC(NREC),
; XLOCS(NNPG),ZLOCS(NNPG), XIPTS(NLXI),ETAPTS(NLETA)
INTEGER*4, INTENT(IN) :: LM(MDIM,MEN,*), IENG(MGNOD,*),
; MDIM,MEN,MGNOD, NNPG,NREC,NLXI,NLETA,
; NELEM,NGNOD,NDIM
LOGICAL*4, INTENT(IN) :: LFSURF(NREC), LVERB
INTEGER*4, INTENT(OUT) :: MRDOF(MDIM,*), IERR
!.... local variables
REAL*8, ALLOCATABLE :: DMIN(:), SF(:)
REAL*8 V1(3),V2(3), BIG,X,Z,XI,ETA,DIST,DET, TOL
LOGICAL*4 LCFREE, LSFREE, LFS
PARAMETER(LNULL =-5)
PARAMETER(TOL = 2.22D-7)
!
!----------------------------------------------------------------------!
!
!.... null out the DOFs and intiialize distance to something big
IERR = 0
BIG = HUGE(1.D0)
LCFREE = .FALSE.
ALLOCATE(DMIN(NREC))
DO 1 IREC=1,NREC
DMIN(IREC) = BIG
DO 2 I=1,NDIM
MRDOF(I,IREC) = LNULL
2 CONTINUE
IF (LFSURF(IREC)) LCFREE = .TRUE.
1 CONTINUE
ALLOCATE(SF(NGNOD))
!
!.... loop on geometry
DO 11 IELEM=1,NELEM
KEEP = 0
ILOC1 = 0
ILOC2 = 0
LSFREE = .FALSE.
IF (LCFREE) THEN !need to check if element is on free surface
DO 101 IA=1,NGNOD
ILOC = IENG(IA,IELEM)
IF (CNNPG(ILOC).EQ.'FS') THEN !free surface?
ILOC1 = ILOC
LSFREE = .TRUE.
KEEP = KEEP + 1
DO 102 JA=1,NGNOD
JLOC = IENG(JA,IELEM)
IF (JLOC.NE.ILOC .AND. CNNPG(JLOC).EQ.'FS') THEN
ILOC2 = JLOC
KEEP = KEEP + 1
GOTO 40
ENDIF !two nodes on free surface
102 CONTINUE !loop on anchor nodes
GOTO 40
ENDIF !end check if node is on free surface
101 CONTINUE !loop on anchor nodes
40 CONTINUE !break ahead
ENDIF
V1(1:3) = 0.D0
IF (KEEP.EQ.2) THEN
V1(1) = XLOCS(ILOC2) - XLOCS(ILOC1)
V1(2) = 0.D0
V1(3) = ZLOCS(ILOC2) - ZLOCS(ILOC1)
ENDIF
!
!....... begin loop on geometry of element
DO 12 ILETA=1,NLETA
ETA = ETAPTS(ILETA)
DO 13 ILXI=1,NLXI
IAE = (ILETA - 1)*NLXI + ILXI
XI = XIPTS(ILXI)
CALL CSF2DND(NGNOD,XI,ETA, SF, IERR)
IF (IERR.NE.0) THEN
WRITE(*,*) 'locrec2d: Error calling csf2dnd'
GOTO 100
ENDIF
X = 0.D0
Z = 0.D0
DO 14 IA=1,NGNOD
ILOC = IENG(IA,IELEM)
X = X + SF(IA)*XLOCS(ILOC)
Z = Z + SF(IA)*ZLOCS(ILOC)
14 CONTINUE !loop on anchor ndoes
LFS = .FALSE.
IF (LCFREE) THEN !check if node is at free surface
IF (ILXI .EQ.1 .OR. ILXI .EQ.NLXI .OR.
; ILETA.EQ.1 .OR. ILETA.EQ.NLETA) THEN!element side?
IF (KEEP.EQ.1) THEN !check same point
IF (DABS(X - XLOCS(ILOC1)).LT.TOL .AND.
; DABS(Z - ZLOCS(ILOC1)).LT.TOL) LFS = .TRUE.
ELSEIF (KEEP.EQ.2) THEN !check along line
V2(1) = X - XLOCS(ILOC1) !line cant be parallel
V2(2) = 0.D0
V2(3) = Z - ZLOCS(ILOC1)
DET = V1(1)*V2(3) - V1(3)*V2(1)
IF (DABS(DET).LT.TOL) LFS = .TRUE.
ENDIF !end check on keep
ENDIF !end check on element side
ENDIF !end check on whether or not to calculate f.s.
!
!............. check we have all DOFs at nodal point
IF (MINVAL(LM(1:NDIM,IAE,IELEM)).GT.0) THEN
DO 15 IREC=1,NREC
DIST = (X - XREC(IREC))**2 + (Z - ZREC(IREC))**2
IF (LFSURF(IREC)) THEN !take closest pt at FS
IF (DIST.LT.DMIN(IREC).AND.LFS) THEN
DO 16 I=1,NDIM
MRDOF(I,IREC) = LM(I,IAE,IELEM)
16 CONTINUE
DMIN(IREC) = DIST
ENDIF
ELSE !just take closest point
IF (DIST.LT.DMIN(IREC)) THEN
DO 17 I=1,NDIM
MRDOF(I,IREC) = LM(I,IAE,IELEM)
17 CONTINUE
DMIN(IREC) = DIST
ENDIF
ENDIF
15 CONTINUE !loop on receivers
ENDIF !end check on point being a complete DOF
13 CONTINUE !loop on xi points
12 CONTINUE !loop on eta points
11 CONTINUE !loop on elements
!
!.... quality control, check if receivers were initialized
DO 21 IREC=1,NREC
IF (MINVAL(MRDOF(1:NDIM,IREC)).EQ.LNULL) THEN
WRITE(*,*) 'locrec2d: Error locating receiver',IREC
IERR = 2
ENDIF
IF (LVERB) THEN
IF (IREC.EQ.1) WRITE(*,*)
IF (IREC.EQ.1) WRITE(*,905)
WRITE(*,906) IREC,DSQRT(DMIN(IREC))
IF (IREC.EQ.NREC) WRITE(*,*)
ENDIF
21 CONTINUE !loop on receivers
100 CONTINUE !break ahead for error
DEALLOCATE(SF)
DEALLOCATE(DMIN)
905 FORMAT(' locrec: Distance of recievers to collocation points:')
906 FORMAT(' Receiver:',I4,' distance ',F12.2, '(m)')
RETURN
END
! !
!======================================================================!
! !
SUBROUTINE REC_SPACE1D(NREC,XREC, DX,IERR)
!
! Calculates the receiver spacing along a line. It is assumed
! the receivers are in ascending or descending order
!
! INPUT MEANING
! ----- -------
! NREC number of receivers
! XREC receiver x locations (in ascending/descending order)
!
! OUTPUT MEANING
! ------ -------
! DX normalized distance between receivers
! IERR error flag
!
!.... variable declarations
implicit none
REAL*8, INTENT(IN) :: XREC(NREC)
INTEGER*4, INTENT(IN) :: NREC
REAL*8, INTENT(OUT) :: DX(NREC-1)
INTEGER*4, INTENT(OUT) :: IERR
!.... local variables
REAL*8 DXMIN, XDIR
INTEGER*4 IREC
!
!----------------------------------------------------------------------!
!
!.... initialize
IERR = 0
DX(1:NREC-1) = 0.D0
IF (NREC.EQ.1) THEN
WRITE(*,*) 'offset1d: Error only one receiver!'
IERR = 1
RETURN
ENDIF
!
!.... calculate offsets
XDIR = XREC(2) - XREC(1)
DXMIN = HUGE(1.D0)
DO 1 IREC=1,NREC-1
DX(IREC) = DABS(XREC(IREC+1) - XREC(IREC))
DXMIN = DMIN1(DXMIN,DX(IREC))
IF (DX(IREC).LT.1.D-10) THEN
WRITE(*,*) 'offset1d: Error duplicate receiver locations!'
DX(1:NREC-1) = 0.D0
IERR = 1
RETURN
ENDIF
IF (IREC.GT.1) THEN
IF (XREC(IREC).GT.XREC(IREC-1) .AND. XDIR.LT.0.D0 .OR.
; XREC(IREC).LT.XREC(IREC-1) .AND. XDIR.GT.0.D0) THEN
WRITE(*,*) 'offset1d: Error xrec not in order!'
DX(1:NREC-1) = 0.D0
IERR = 1
RETURN
ENDIF
ENDIF
1 CONTINUE
!
!.... normalize
DO 2 IREC=1,NREC-1
DX(IREC) = DX(IREC)/DXMIN
2 CONTINUE
RETURN
END
! !
!========================================================================================!
! !
SUBROUTINE LAPLACE_1D(LDC,NREC,DX, COVD,IERR)
!
! This applies a 1D laplacian differencing scheme to each
! component of motion. So that we may respect varying offsets
! we use a finite element scheme which in the case of a constnat
! dx reduces to a second order differencing matrix [-1 2 -1].
! The matrix can then multiply the Jacobian or residuals
!
! INPUT MEANING
! ----- -------
! DX offset (likely normalized)
! LDC leading dimension
! NREC number of receivers
!
! OUTPUT MEANING
! ------ -------
! COVD data covariance matrix (1d FEM lapalace discretization)
! IERR error flag
!
!.... variable declarations
REAL*8, INTENT(IN) :: DX(NREC-1)
INTEGER*4, INTENT(IN) :: LDC,NREC
REAL*8, INTENT(OUT) :: COVD(LDC,ldc)
INTEGER*4, INTENT(OUT) :: IERR
!.... local variables
INTEGER*4, ALLOCATABLE :: LM(:,:,:), ID(:,:), IEN(:,:)
REAL*8 K(2,2)
INTEGER*4 NNPG,NELEM,NDOF, IELEM,INPG,IA,JA,IDOF,JDOF,I,J
REAL*8, PARAMETER :: TWO = 2.D0
REAL*8, PARAMETER :: HALF = 0.5D0
INTEGER*4, PARAMETER :: NDIM = 3
INTEGER*4, PARAMETER :: NGNOD = 2
!
!----------------------------------------------------------------------!
!
!.... generate a graph
NELEM = NREC - 1
ALLOCATE(IEN(NGNOD,NELEM))
INPG = 0
DO 1 IELEM=1,NELEM
DO 2 IA=1,NGNOD
INPG = INPG + 1
IEN(IA,IELEM) = INPG
2 CONTINUE
INPG = INPG - 1
1 CONTINUE
NNPG = INPG + 1
IF (NNPG.NE.NREC) THEN
WRITE(*,*) 'laplace_1d: nnpg initialization error'
IERR = 1
RETURN
ENDIF
NDOF = NDIM*NNPG
ALLOCATE(ID(NDIM,NNPG))
IDOF = 0
DO 3 INPG=1,NNPG
DO 4 I=1,NDIM
IDOF = IDOF + 1
ID(I,INPG) = IDOF
4 CONTINUE
3 CONTINUE
IF (IDOF.NE.NDOF) THEN
WRITE(*,*) 'laplace_1d: idof initialization error'
IERR = 1
RETURN
ENDIF
ALLOCATE(LM(3,NGNOD,NELEM))
DO 5 IELEM=1,NELEM
DO 6 IA=1,NGNOD
DO 7 I=1,NDIM
LM(I,IA,IELEM) = ID(I,IEN(IA,IELEM))
7 CONTINUE
6 CONTINUE
5 CONTINUE
DEALLOCATE(ID)
DEALLOCATE(IEN)
!
!.... loop on elements
K(1,1) = HALF
K(1,2) =-HALF
K(2,1) =-HALF
K(2,2) = HALF
COVD(1:LDC,1:2*NREC*NDIM) = 0.D0
DO 8 IELEM=1,NELEM
DO 9 IA=1,NGNOD
DO 10 I=1,NDIM
IDOF = LM(I,IA,IELEM)
DO 11 JA=1,NGNOD
DO 12 J=1,NDIM
JDOF = LM(J,JA,IELEM)
IF (I.EQ.J) THEN
COVD(IDOF,JDOF) = COVD(IDOF,JDOF)
; + TWO/DX(IELEM)*K(IA,JA)
COVD(NDOF+IDOF,NDOF+JDOF)
; = COVD(NDOF+IDOF,NDOF+JDOF)+TWO/DX(IELEM)*K(IA,JA)
ENDIF
12 CONTINUE
11 CONTINUE
10 CONTINUE
9 CONTINUE
8 CONTINUE
DEALLOCATE(LM)
RETURN
END
! !
!======================================================================!
! !
SUBROUTINE LAPLACE_1DV2(LDC,MDIM,NREC,LDWGHT, DX, OBS, COVD,IERR)
!
! Builds the data roughening matrix
! [ Re{L_w} 0 0 0 0 0 ]
! [ 0 Re{L_v} 0 0 0 0 ]
! [ 0 0 Re{L_u} 0 0 0 ]
! [ 0 0 0 Im{L_w} 0 0 ]
! [ 0 0 0 0 Im{L_v} 0 ]
! [ 0 0 0 0 0 Im{L_u} ]
!
! where each submatrix is ordered so that only receivers
! with observations are listed first, then, back filled with
! 0's
!
! INPUT MEANING
! ----- -------
! DX normalized distances between receivers in x
! LDC leading dimension
! LDWGHT True -> weight by receiver distance
! MDIM leading dimension
! NREC number of receviers
! OBS observations for frequency source pair
!
! OUTPUT MEANING
! ------ -------
! COVD data covariance matrix
! IERR error flag
!
!.... variable declarations
IMPLICIT NONE
COMPLEX*8, INTENT(IN) :: OBS(MDIM,*)
REAL*8, INTENT(IN) :: DX(NREC-1)
INTEGER*4, INTENT(IN) :: LDC,MDIM,NREC
LOGICAL*4, INTENT(IN) :: LDWGHT
REAL*8, INTENT(OUT) :: COVD(LDC,*)
INTEGER*4, INTENT(OUT) :: IERR
!.... local variables
REAL*8, ALLOCATABLE :: DXLOC(:)
INTEGER*4, ALLOCATABLE :: LM(:,:), IEN(:,:), ID(:)
LOGICAL*4, ALLOCATABLE :: LACTIVE(:)
REAL*8 K(2,2), XSUM
INTEGER*4 NDOF,NELEM,NNPG, IREC,JREC,INPG,IELEM,JELEM, IA,JA,
; IDOF,JDOF, IROW1,IROW2,JCOL1,JCOL2, I
REAL*8, PARAMETER :: TWO = 2.D0
REAL*8, PARAMETER :: ONE = 1.D0
REAL*8, PARAMETER :: HALF = 0.5D0
INTEGER*4, PARAMETER :: NDIM = 3
INTEGER*4, PARAMETER :: NGNOD = 2
!
!----------------------------------------------------------------------!
!
!.... initialize and check for early return
IERR = 0
COVD(1:LDC,1:2*NREC*NDIM) = 0.D0
IF (MAXVAL(CABS(OBS(1:NDIM,1:NREC))) == 0.0) THEN
WRITE(*,*) 'laplace_1dv2: This is a dead frequency!'
RETURN
ENDIF
K(1,1) = HALF
K(1,2) =-HALF
K(2,1) =-HALF
K(2,2) = HALF
IDOF = 0
!
!.... loop on components
DO 100 I=NDIM,1,-1
ALLOCATE(LACTIVE(NREC))
NELEM =-1
DO 1 IREC=1,NREC
LACTIVE(IREC) = .FALSE.
IF (CABS(OBS(I,IREC)) > 0.0) THEN
NELEM = NELEM + 1
LACTIVE(IREC) = .TRUE.
ENDIF
1 CONTINUE
IF (NELEM ==-1) GOTO 105 !dead component
!
!....... generate local dx vector
ALLOCATE(DXLOC(NELEM))
DXLOC(1:NELEM) = 0.D0
IF (LDWGHT) THEN
IELEM = 0
DO 2 IREC=1,NREC !IELEM=1,NELEM
IF (LACTIVE(IREC) .AND. IELEM + 1 <= NELEM) THEN
IELEM = IELEM + 1
XSUM = 0.D0
JELEM = IREC - 1
DO 3 JREC=IREC,NREC-1
JELEM = JELEM + 1
XSUM = XSUM + DX(JELEM)
IF (LACTIVE(JREC+1)) GOTO 30
3 CONTINUE
30 CONTINUE
DXLOC(IELEM) = XSUM
IF (XSUM == 0.D0) THEN
WRITE(*,*) 'laplace_1d: xsum error',IREC,JREC
IERR = 1
RETURN
ENDIF
ENDIF
2 CONTINUE
ELSE
DXLOC(1:NELEM) = ONE
ENDIF
DEALLOCATE(LACTIVE)
IF (MINVAL(DXLOC) == 0.D0) THEN
WRITE(*,*) 'laplace_1d: dxloc init error'
IERR = 1
RETURN
ENDIF
!
!....... generate a graph
ALLOCATE(IEN(NGNOD,NELEM))
INPG = 0
DO 4 IELEM=1,NELEM
DO 5 IA=1,NGNOD
INPG = INPG + 1
IEN(IA,IELEM) = INPG
5 CONTINUE
INPG = INPG - 1
4 CONTINUE
NNPG = INPG + 1
IF (NNPG /= NELEM + 1) THEN
WRITE(*,*) 'laplace_1d: nnpg initialization error',NNPG
IERR = 1
RETURN
ENDIF
NDOF = NNPG
ALLOCATE(ID(NNPG))
INPG = 0
DO 6 IREC=1,NREC !INPG=1,NNPG
IF (CABS(OBS(I,IREC)) > 0.0) THEN
INPG = INPG + 1
IDOF = IDOF + 1
ID(INPG) = IDOF
ENDIF
6 CONTINUE
ALLOCATE(LM(NGNOD,NELEM))
DO 7 IELEM=1,NELEM
DO 8 IA=1,NGNOD
LM(IA,IELEM) = ID(IEN(IA,IELEM))
8 CONTINUE
7 CONTINUE
DEALLOCATE(ID)
DEALLOCATE(IEN)
!
!....... loop on elements
DO 21 IELEM=1,NELEM
DO 22 IA=1,NGNOD
IDOF = LM(IA,IELEM)
IF (IDOF == 0) GOTO 220
DO 23 JA=1,NGNOD
JDOF = LM(JA,IELEM)
IF (JDOF == 0) GOTO 230
IROW1 = IDOF
IROW2 = NDIM*NREC + IDOF
JCOL1 = JDOF
JCOL2 = NDIM*NREC + JDOF
COVD(IROW1,JCOL1) = COVD(IROW1,JCOL1)
; + TWO/DXLOC(IELEM)*K(IA,JA)
COVD(IROW2,JCOL2) = COVD(IROW2,JCOL2)
; + TWO/DXLOC(IELEM)*K(IA,JA)
230 CONTINUE !not a dof
23 CONTINUE
220 CONTINUE !not a dof
22 CONTINUE
21 CONTINUE
105 CONTINUE !dead component
IF (ALLOCATED(LACTIVE)) DEALLOCATE(LACTIVE)
IF (ALLOCATED(DXLOC)) DEALLOCATE(DXLOC)
IF (ALLOCATED(LM)) DEALLOCATE(LM)
100 CONTINUE !loop on components
RETURN
END
! !
!======================================================================!
! !
SUBROUTINE PERM_OBS(MDIM,NDIM,NREC, OBS,
; IPERM_REC,IERR)
!
! Generates a permutation list for the observations. We want the
! data stored stored active observations for the vertical component
! then null vertical receivers, then active receivers for
! the v component then null receivers, and finally the active
! u receivers then null receivers
COMPLEX*8, INTENT(IN) :: OBS(MDIM,*)
INTEGER*4, INTENT(IN) :: MDIM,NDIM,NREC
INTEGER*4, INTENT(OUT) :: IPERM_REC(NDIM*NREC), IERR
!
!----------------------------------------------------------------------!
!
!.... set the observations
IPERM_REC(1:NDIM*NREC) = 0
IOBS = 0
DO 1 I=NDIM,1,-1
DO 2 IREC=1,NREC
IF (CABS(OBS(I,IREC)) > 0.0) THEN
INDX = (IREC - 1)*NDIM + I
IOBS = IOBS + 1
IPERM_REC(INDX) = IOBS
ENDIF
2 CONTINUE
DO 3 IREC=1,NREC
IF (CABS(OBS(I,IREC)) == 0.0) THEN
INDX = (IREC - 1)*NDIM + I
IOBS = IOBS + 1
IPERM_REC(INDX) = IOBS
ENDIF
3 CONTINUE
1 CONTINUE
IF (MINVAL(IPERM_REC) == 0) THEN
WRITE(*,*) 'perm_obs: Error setting permutation vector!'
IERR = 1
ELSE
IERR = 0
ENDIF
RETURN
END
! !
!======================================================================!
! !
SUBROUTINE LAPLACE_DIST1D(ICTXT,NPROW,NPCOL, LDC,NREC,MCL,NCL,
; DESCC, DX, COVD,IERR)
!
! This applies a 1D laplacian differencing scheme to each component
! of motion. So that we may respect varying offsets we use a
! finite element scheme which in the case of a constnat dx reduces
! to a second order differencing matrix [-1 2 -1]. The matrix can
! then multiply the Jacobian or residuals
!
! INPUT MEANING
! ----- -------
! DX offset (likely normalized)
! LDC leading dimension
! MCL number of local rows in distributed data covariance
! matrix
! NCLO number of local columns in distributed data covariance
! matrix
! NREC number of receivers
!
! OUTPUT MEANING
! ------ -------
! COVD data covariance matrix (1d FEM lapalace discretization)
! IERR error flag
!
!.... variable declarations
IMPLICIT NONE
REAL*8, INTENT(IN) :: DX(NREC-1)
INTEGER*4, INTENT(IN) :: DESCC(9), LDC,MCL,NCL,NREC,
; NPROW,NPCOL,ICTXT
REAL*8, INTENT(OUT) :: COVD(LDC,*)
INTEGER*4, INTENT(OUT) :: IERR
!.... local variables
INTEGER*4, ALLOCATABLE :: LM(:,:,:), ID(:,:), IEN(:,:)
REAL*8 K(2,2)
INTEGER*4 NNPG,NELEM,NDOF, IELEM,INPG,IA,JA,IDOF,JDOF,I,J
INTEGER*4 MYROW,MYCOL, IAROW,IACOL, IIA,JJA, IROW,JCOL
REAL*8, PARAMETER :: TWO = 2.D0
REAL*8, PARAMETER :: HALF = 0.5D0
INTEGER*4, PARAMETER :: NDIM = 3
INTEGER*4, PARAMETER :: NGNOD = 2
!
!----------------------------------------------------------------------!
!
!.... recall BLACS information
CALL BLACS_GRIDINFO(ICTXT, NPROW, NPCOL, MYROW, MYCOL)
!.... generate a graph
NELEM = NREC - 1
ALLOCATE(IEN(NGNOD,NELEM))
INPG = 0
DO 1 IELEM=1,NELEM
DO 2 IA=1,NGNOD
INPG = INPG + 1
IEN(IA,IELEM) = INPG
2 CONTINUE
INPG = INPG - 1
1 CONTINUE
NNPG = INPG + 1
IF (NNPG.NE.NREC) THEN
WRITE(*,*) 'laplace_dist1d: nnpg initialization error'
IERR = 1
RETURN
ENDIF
NDOF = NDIM*NNPG
ALLOCATE(ID(NDIM,NNPG))
IDOF = 0
DO 3 INPG=1,NNPG
DO 4 I=1,NDIM
IDOF = IDOF + 1
ID(I,INPG) = IDOF
4 CONTINUE
3 CONTINUE
IF (IDOF.NE.NDOF) THEN
WRITE(*,*) 'laplace_dist1d: idof initialization error'
IERR = 1
RETURN
ENDIF
ALLOCATE(LM(3,NGNOD,NELEM))
DO 5 IELEM=1,NELEM
DO 6 IA=1,NGNOD
DO 7 I=1,NDIM
LM(I,IA,IELEM) = ID(I,IEN(IA,IELEM))
7 CONTINUE
6 CONTINUE
5 CONTINUE
DEALLOCATE(ID)
DEALLOCATE(IEN)
!
!.... loop on elements
K(1,1) = HALF
K(1,2) =-HALF
K(2,1) =-HALF
K(2,2) = HALF
COVD(1:MCL,1:NCL) = 0.D0
DO 8 IELEM=1,NELEM
DO 9 IA=1,NGNOD
DO 10 I=1,NDIM
IDOF = LM(I,IA,IELEM)
DO 11 JA=1,NGNOD
DO 12 J=1,NDIM
JDOF = LM(J,JA,IELEM)
IF (I == J) THEN
IROW = IDOF
JCOL = JDOF
CALL INFOG2L(IROW,JCOL,DESCC, NPROW,NPCOL,
; MYROW,MYCOL, IIA,JJA, IAROW,IACOL)
IF (MYROW == IAROW .AND. MYCOL == IACOL) THEN
COVD(IIA,JJA) = COVD(IIA,JJA)
; + TWO/DX(IELEM)*K(IA,JA)
ENDIF
IROW = NDOF + IDOF
JCOL = NDOF + JDOF
CALL INFOG2L(IROW,JCOL,DESCC, NPROW,NPCOL,
; MYROW,MYCOL, IIA,JJA, IAROW,IACOL)
IF (MYROW == IAROW .AND. MYCOL == IACOL) THEN
COVD(IIA,JJA) = COVD(IIA,JJA)
; + TWO/DX(IELEM)*K(IA,JA)
ENDIF
ENDIF
12 CONTINUE
11 CONTINUE
10 CONTINUE
9 CONTINUE
8 CONTINUE
DEALLOCATE(LM)
RETURN
END
! !
!========================================================================================!
! !
SUBROUTINE LAPLACE_DIST1DV2(ICTXT,NPROW,NPCOL,
; LDC,MDIM,NREC,MCL,NCL,DESCC, LDWGHT, DX,
; OBS,COVD,IERR)
!
! This applies a 1D laplacian differencing scheme to each component of motion.
! So that we may respect varying offsets we use a finite element scheme which in
! the case of a constnat dx reduces to a second order differencing matrix [-1 2 -1].
! The matrix can then multiply the Jacobian or residuals
!
! INPUT MEANING
! ----- -------
! DESCC covariance matrix descriptor
! DX offset (likely normalized)
! LDC leading dimension
! LDWGHT true use distance weighting
! MCL number of local rows in distributed data covariance matrix
! MDIM leading dimension
! NCL number of local columns in distributed data covariance matrix
! NREC number of receivers
! OBS observations for frequency source pair
!
! OUTPUT MEANING
! ------ -------
! COVD data covariance matrix (1d FEM lapalace discretization)
! IERR error flag
!
!.... variable declarations
IMPLICIT NONE
COMPLEX*8, INTENT(IN) :: OBS(MDIM,*)
REAL*8, INTENT(IN) :: DX(NREC-1)
INTEGER*4, INTENT(IN) :: DESCC(9), LDC,MDIM,MCL,NCL,NREC,
; NPROW,NPCOL,ICTXT
LOGICAL*4, INTENT(IN) :: LDWGHT
REAL*8, INTENT(OUT) :: COVD(LDC,*)
INTEGER*4, INTENT(OUT) :: IERR
!.... local variables
REAL*8, ALLOCATABLE :: DXLOC(:)
INTEGER*4, ALLOCATABLE :: LM(:,:), ID(:), IEN(:,:)
LOGICAL*4, ALLOCATABLE :: LACTIVE(:)
REAL*8 K(2,2), XSUM
INTEGER*4 NNPG,NELEM,NDOF, IELEM,JELEM,INPG,IA,JA,IDOF,JDOF,I,
; IREC,JREC
INTEGER*4 MYROW,MYCOL, IAROW,IACOL, IIA,JJA, IROW,JCOL
REAL*8, PARAMETER :: TWO = 2.D0
REAL*8, PARAMETER :: ONE = 1.D0
REAL*8, PARAMETER :: HALF = 0.5D0
INTEGER*4, PARAMETER :: NDIM = 3
INTEGER*4, PARAMETER :: NGNOD = 2
!
!----------------------------------------------------------------------------------------!
!
!.... recall BLACS information
CALL BLACS_GRIDINFO(ICTXT, NPROW, NPCOL, MYROW, MYCOL)
!
!.... initialize and check for early return
IERR = 0
COVD(1:MCL,1:NCL) = 0.D0
IF (MAXVAL(CABS(OBS(1:NDIM,1:NREC))) == 0.0) THEN
WRITE(*,*) 'laplace_1dv2: This is a dead frequency!'
RETURN
ENDIF
K(1,1) = HALF
K(1,2) =-HALF
K(2,1) =-HALF
K(2,2) = HALF
IDOF = 0
!
!.... loop on components
DO 100 I=NDIM,1,-1
ALLOCATE(LACTIVE(NREC))
NELEM =-1
DO 1 IREC=1,NREC
LACTIVE(IREC) = .FALSE.
IF (CABS(OBS(I,IREC)) > 0.0) THEN
NELEM = NELEM + 1
LACTIVE(IREC) = .TRUE.
ENDIF
1 CONTINUE
IF (NELEM ==-1) GOTO 105 !dead component
!
!....... generate local dx vector
ALLOCATE(DXLOC(NELEM))
DXLOC(1:NELEM) = 0.D0
IF (LDWGHT) THEN
IELEM = 0
DO 2 IREC=1,NREC !IELEM=1,NELEM
IF (LACTIVE(IREC) .AND. IELEM + 1 <= NELEM) THEN
IELEM = IELEM + 1
XSUM = 0.D0
JELEM = IREC - 1
DO 3 JREC=IREC,NREC-1
JELEM = JELEM + 1
XSUM = XSUM + DX(JELEM)
IF (LACTIVE(JREC+1)) GOTO 30
3 CONTINUE
30 CONTINUE
DXLOC(IELEM) = XSUM
IF (XSUM == 0.D0) THEN
WRITE(*,*) 'laplace_dist1d: xsum error',IREC,JREC
IERR = 1
RETURN
ENDIF
ENDIF
2 CONTINUE
ELSE
DXLOC(1:NELEM) = ONE
ENDIF
DEALLOCATE(LACTIVE)
IF (MINVAL(DXLOC) == 0.D0) THEN
WRITE(*,*) 'laplace_dist1d: dxloc init error'
IERR = 1
RETURN
ENDIF
!
!....... generate a graph
ALLOCATE(IEN(NGNOD,NELEM))
INPG = 0
DO 4 IELEM=1,NELEM
DO 5 IA=1,NGNOD
INPG = INPG + 1
IEN(IA,IELEM) = INPG
5 CONTINUE
INPG = INPG - 1
4 CONTINUE
NNPG = INPG + 1
IF (NNPG /= NELEM + 1) THEN
WRITE(*,*) 'laplace_dist1d: nnpg initialization error',NNPG
IERR = 1
RETURN
ENDIF
NDOF = NNPG
ALLOCATE(ID(NNPG))
INPG = 0
DO 6 IREC=1,NREC !INPG=1,NNPG
IF (CABS(OBS(I,IREC)) > 0.0) THEN
INPG = INPG + 1
IDOF = IDOF + 1
ID(INPG) = IDOF
ENDIF
6 CONTINUE
ALLOCATE(LM(NGNOD,NELEM))
DO 7 IELEM=1,NELEM
DO 8 IA=1,NGNOD
LM(IA,IELEM) = ID(IEN(IA,IELEM))
8 CONTINUE
7 CONTINUE
DEALLOCATE(ID)
DEALLOCATE(IEN)
DO 21 IELEM=1,NELEM
DO 22 IA=1,NGNOD
IDOF = LM(IA,IELEM)
IF (IDOF == 0) GOTO 220
DO 23 JA=1,NGNOD
JDOF = LM(JA,IELEM)
IF (JDOF == 0) GOTO 230
IROW = IDOF
JCOL = JDOF
CALL INFOG2L(IROW,JCOL,DESCC, NPROW,NPCOL,MYROW,MYCOL,
; IIA,JJA, IAROW,IACOL)
IF (MYROW == IAROW .AND. MYCOL == IACOL)
; COVD(IIA,JJA) = COVD(IIA,JJA) + TWO/DX(IELEM)*K(IA,JA)
IROW = NDIM*NREC + IDOF
JCOL = NDIM*NREC + JDOF
CALL INFOG2L(IROW,JCOL,DESCC, NPROW,NPCOL,MYROW,MYCOL,
; IIA,JJA, IAROW,IACOL)
IF (MYROW == IAROW .AND. MYCOL == IACOL)
; COVD(IIA,JJA) = COVD(IIA,JJA) + TWO/DX(IELEM)*K(IA,JA)
230 CONTINUE !not a dof; break ahead
23 CONTINUE !loop on anchor nodes
220 CONTINUE
22 CONTINUE
21 CONTINUE
105 CONTINUE !dead component
IF (ALLOCATED(LACTIVE)) DEALLOCATE(LACTIVE)
IF (ALLOCATED(DXLOC)) DEALLOCATE(DXLOC)
IF (ALLOCATED(LM)) DEALLOCATE(LM)
100 CONTINUE !loop on components
RETURN
END
! !
!======================================================================!
! !
SUBROUTINE EXRESP25D(MDIM,MREC,NDOF, NSRC,NREC,NDIM, FREQ,
; PY, YREC, SOL, MRDOF,
; RECV,EST)
!
! Extract the response at all receivers for all sources for this
! frequency. Additionally we apply the phase shifter ala
! Kennett e^{i(omega t - kx x - ky y - kz z)} is wave propagating
! forward in time, with local conventions +x right, +z up, then
! we'd like our y to be +90 degrees from x, so we phase shift
! at e^{+i omega py y} e^{i(omega t - kx x - kz z)}
!
! INPUT MEANING
! ----- -------
! FREQ current frequency in Hz
! MDIM max spatial dimension; leading dimension
! MRDOF holds the receivers DOF numbers
! MREC max number of recievers; leading dimension
! NDIM number of components in solution
! NDOF number of degrees of freedom
! NREC number of receivers to extract at
! NSRC number of sources to extract
! PY apparent slownesses at sources
! RECV receiver reseponse function
! SOL solution of AX = B
! YREC y position of recievers
!
! OUTPUT MEANING
! ------ -------
! EST estimated response from wavefield at receiver location
!
!.... varibale declarations
COMPLEX*8, INTENT(IN) :: RECV(MDIM,*), SOL(NDOF*NSRC)
REAL*8, INTENT(IN) :: YREC(NREC), PY(NSRC),FREQ
INTEGER*4, INTENT(IN) :: MRDOF(MDIM,*), MDIM,MREC,NDOF,
; NSRC,NREC,NDIM
COMPLEX*8, INTENT(OUT) :: EST(MDIM,MREC,*)
COMPLEX*8 CFACT
REAL*8 TWOPI, OMEGA
PARAMETER(TWOPI = 6.2831853071795862D0)
!
!----------------------------------------------------------------------!
!
OMEGA = TWOPI*FREQ
DO 1 ISRC=1,NSRC
LOFF = (ISRC - 1)*NDOF
DO 2 IREC=1,NREC
CFACT = CEXP(CMPLX(0.D0,+OMEGA*PY(ISRC)*YREC(IREC)))
DO 3 I=1,NDIM
IF (MRDOF(I,IREC).NE.0) THEN
ILOC = LOFF + MRDOF(I,IREC)
EST(I,IREC,ISRC) = RECV(I,IREC)*SOL(ILOC)*CFACT
ELSE
EST(I,IREC,ISRC) = CMPLX(0.0,0.0)
ENDIF
3 CONTINUE
2 CONTINUE
1 CONTINUE
RETURN
END
! !
!======================================================================!
! !
SUBROUTINE EXRESP_MP_2(MDIM,MREC,NDOF, NSRC,NREC,NDIM, FREQ,
; PY, YREC, SOL, MRDOF,
; RECV,EST)
!
! Extracts the magnitude and phase in terms of [Mag,phase]
COMPLEX*8, INTENT(IN) :: RECV(MDIM,*), SOL(NDOF*NSRC)
REAL*8, INTENT(IN) :: YREC(NREC), PY(NSRC),FREQ
INTEGER*4, INTENT(IN) :: MRDOF(MDIM,*), MDIM,MREC,NDOF,
; NSRC,NREC,NDIM
COMPLEX*8, INTENT(OUT) :: EST(MDIM,MREC,*)
COMPLEX*8 CFACT, ESTT
REAL*8 TWOPI, OMEGA
REAL*4 SPHASE
PARAMETER(TWOPI = 6.2831853071795862D0)
OMEGA = TWOPI*FREQ
DO 1 ISRC=1,NSRC
LOFF = (ISRC - 1)*NDOF
DO 2 IREC=1,NREC
CFACT = CEXP(CMPLX(0.D0,+OMEGA*PY(ISRC)*YREC(IREC)))
DO 3 I=1,NDIM
IF (MRDOF(I,IREC).NE.0) THEN
ILOC = LOFF + MRDOF(I,IREC)
ESTT = RECV(I,IREC)*SOL(ILOC)*CFACT
EST(I,IREC,ISRC) = CMPLX(CABS(ESTT),SPHASE(ESTT))
ELSE
EST(I,IREC,ISRC) = CMPLX(0.0,0.0)
ENDIF
3 CONTINUE
2 CONTINUE
1 CONTINUE
RETURN
END
! !
!======================================================================!
! !
SUBROUTINE EXRESP_MP(MDIM,MREC,NDOF, NSRC,NREC,NFS, FREQ,
; PY, YREC, USOL, CSIDE,
; MRDOF,IDOF_FS,RECV,
; EST, IERR)
!
! Extracts the magntude and unwrapped phase response.
! Additionally we apply the phase shifter ala
! Kennett e^{i(omega t - kx x - ky y - kz z)} is wave propagating
! forward in time, with local conventions +x right, +z up, then
! we'd like our y to be +90 degrees from x, so we phase shift
! at e^{+i py y} e^{i(omega t - kx x - kz z)}
!
! INPUT MEANING
! ----- -------
! CSIDE side source is approaching from
! FREQ current frequency in Hz
! IDOF_FS holds DOF numbers at fine nodes at free surface
! MDIM max spatial dimension; leading dimension
! MRDOF holds the receivers DOF numbers
! MREC max number of recievers; leading dimension
! NDOF number of degrees of freedom
! NFS number of fine nodes at free surface
! NREC number of receivers to extract at
! NSRC number of sources to extract
! PY apparent slownesses at sources
! RECV receiver reseponse function
! SOL solution of AX = B
! YREC y position of recievers
!
! OUTPUT MEANING
! ------ -------
! EST estimated response from wavefield at receiver location
! IERR error flag, couldn't find receiver
!
!.... variable declarations