-
Notifications
You must be signed in to change notification settings - Fork 92
/
prestore.f90
3726 lines (2843 loc) · 142 KB
/
prestore.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
MODULE PRESTORE
USE DECLARATION
USE DERIVATIVES
USE LIBRARY
USE BASIS
USE TRANSFORM
USE LOCAL
USE LAPCK
USE DG_FUNCTIONS
IMPLICIT NONE
CONTAINS
SUBROUTINE PRESTORE_1(N)
!> @brief
!> This subroutine calls other subroutines to prestore the pseudoinverse reconstruction least square matrices
IMPLICIT NONE
INTEGER,INTENT(IN)::N
INTEGER::KMAXE,i
KMAXE=XMPIELRANK(N)
if (dimensiona.eq.3)then
!$OMP PARALLEL DEFAULT(SHARED)
!$OMP DO schedule(STATIC)
DO I=1,KMAXE
CALL LOCALISE_STENCIL(N,I)
CALL LOCALISE_STEN2(N,I)
call CHECKGRADS(N,I)
CALL FIND_ROT_ANGLES(N,I)
CALL PRESTORE_RECONSTRUCTION3(N,I)
iconsidered=i
if ((dg.eq.1).OR.(ADDA.EQ.1))then
CALL PRESTORE_DG1
end if
END DO
!$OMP END DO
!$OMP END PARALLEL
else
!$OMP PARALLEL DEFAULT(SHARED)
!$OMP DO
DO I=1,KMAXE
CALL LOCALISE_STENCIL2d(N,I)
CALL LOCALISE_STEN2d(N,I)
call CHECKGRADS2d(N,I)
CALL FIND_ROT_ANGLES2D(N,I)
CALL PRESTORE_RECONSTRUCTION2(N,I)
ICONSIDERED=I
if ((dg.eq.1).OR.(ADDA.EQ.1))then
CALL PRESTORE_DG1
end if
END DO
!$OMP END DO
!$OMP END PARALLEL
!takis this needs to be within a omp parallel region!
end if
END SUBROUTINE PRESTORE_1
SUBROUTINE PRESTORE_RECONSTRUCTION3(N,iconsi)
!> @brief
!> This subroutine prestores the pseudoinverse reconstruction least square matrices
IMPLICIT NONE
INTEGER,INTENT(IN)::N,iconsi
INTEGER::I,J,K,llco,ll,ii,igf,IGF2,IFD2,idum,idum2,iq,jq,lq,IHGT,IHGJ,iqp,iqp2,NND,k0,g0,lcou,lcc,iqqq,ICOND1,ICOND2
real::ssss,gggg,UPTEMP,LOTEMP,X_STENCIL,Y_STENCIL,Z_STENCIL,DIST_STEN,DIST_STEN2
real, dimension(IELEM(N,Iconsi)%inumneighbours-1, ielem(n,iconsi)%idegfree):: stencil
real, dimension(20,IELEM(N,Iconsi)%inumneighbours-1, ielem(n,iconsi)%idegfree):: stencilS
real, dimension(ielem(n,iconsi)%idegfree, ielem(n,iconsi)%idegfree):: invmat
REAL,DIMENSION(7,IELEM(N,Iconsi)%inumneighbours-1)::WLSQR
i=iconsi
IDUM=0;
if (ielem(n,i)%interior.eq.1)then
DO j=1,IELEM(N,I)%IFCA
if (ielem(n,i)%ibounds(J).gt.0)then
if (ibound(n,ielem(n,i)%ibounds(j))%icode.eq.4)then
IDUM=1
end if
END IF
END DO
end if
ICONSIDERED=I
INTBS=zero
JXX=1;IXX=i;LXX1=1
number_of_dog=ielem(n,i)%idegfree
kxx=ielem(n,i)%iorder
ELTYPE=ielem(n,i)%ishape
compwrt=0
INTBS=CALINTBASIS(N,IXX,JXX,KXX,LXX1)
INTEG_BASIS(I)%VALUE(1:ielem(n,i)%IDEGFREE)=INTBS(1:ielem(n,i)%IDEGFREE)
IF (IWENO.EQ.1)THEN
CALL INDICATORMATRIX(N,I)
END IF
if (ees.eq.5)then
INTBS=zero
JXX=1;IXX=i;LXX1=1
number_of_dog=idegfree2
kxx=IORDER2
ELTYPE=ielem(n,i)%ishape
compwrt=1
INTBS=CALINTBASIS(N,IXX,JXX,KXX,LXX1)
INTEG_BASIS(I)%VALUEc(1:number_of_dog)=INTBS(1:number_of_dog)
ICONSIDERED=I
IF (IWENO.EQ.1)THEN
CALL INDICATORMATRIX2(N,I)
compwrt=0
END IF
end if
LLCO=IELEM(N,I)%ADMIS
IMAX=IELEM(N,I)%inumneighbours-1
INUM=IELEM(N,I)%inumneighbours
IDEG=IELEM(N,I)%iDEGFREE
INUMO=ielem(n,i)%iorder
imax2=numneighbours2-1
inum2=numneighbours2
ideg2=iDEGFREE2
inumo2=iorder2
DIST_STEN=ZERO
DIST_STEN=-tolbig; DIST_STEN2=tolbig
DO LL=1,ielem(n,i)%iNUMNEIGHBOURS
if (ilocal_elem(1)%VOLUME(1,LL).lt.DIST_STEN2)then
DIST_STEN2=ilocal_elem(1)%VOLUME(1,LL)
end if
if (ilocal_elem(1)%VOLUME(1,LL).gt.DIST_STEN)then
DIST_STEN=ilocal_elem(1)%VOLUME(1,LL)
end if
end do
IELEM(N,I)%STENCIL_DIST=MAX((DIST_STEN/DIST_STEN2),(DIST_STEN2/DIST_STEN))
DO LL=1,LLCO !ADMIS
! !-------------------FOR DEBUGGING ONLY -----------------------------------------!
! !
! !-------------------FOR DEBUGGING ONLY -----------------------------------------!
if((ees.ne.5).or.(ll.eq.1))then
IMAX=IELEM(N,I)%inumneighbours-1
INUM=IELEM(N,I)%inumneighbours
IDEG=IELEM(N,I)%iDEGFREE
INUMO=ielem(n,i)%iorder
compwrt=0
number_of_dog=IDEG
else
imax=numneighbours2-1
inum=numneighbours2
ideg=iDEGFREE2
inumo=IORDER2
number_of_dog=IDEG
compwrt=1
end if
DO K=1,imax
ixx=i
kxx=INUMO
X_STENCIL=(ilocal_elem(1)%XXC(ll,k+1)-ilocal_elem(1)%XXC(ll,1))**2
Y_STENCIL=(ilocal_elem(1)%YYC(ll,k+1)-ilocal_elem(1)%YYC(ll,1))**2
Z_STENCIL=(ilocal_elem(1)%ZZC(ll,k+1)-ilocal_elem(1)%ZZC(ll,1))**2
DIST_STEN2=SQRT(X_STENCIL+Y_STENCIL+Z_STENCIL)
IF (WEIGHT_LSQR.EQ.1)THEN
WLSQR(ll,K)=1.0D0/((DIST_STEN2))
ELSE
WLSQR(ll,K)=1.0D0
END IF
!ILOCAL_RECON3(I)%WEIGHTL(LL,K)=WLSQR(K)
!DIST_STEN=MAX(DIST_STEN,DIST_STEN2)
!IELEM(N,I)%STENCIL_DIST=WLSQR(K)
if (fastest.eq.1)then
x1 = ilocal_elem(1)%XXC(ll,k+1)-ilocal_elem(1)%XXC(ll,1)
y1 = ilocal_elem(1)%YYC(ll,k+1)-ilocal_elem(1)%YYC(ll,1)
z1 = ilocal_elem(1)%ZZC(ll,k+1)-ilocal_elem(1)%ZZC(ll,1)
IF (GREENGO.EQ.0)THEN
if (idum.eq.1)then
if((ees.ne.5).or.(ll.eq.1))then
ILOCAL_RECON3(I)%STENCILS(LL,K,1:ielem(n,i)%idegfree)=WLSQR(ll,K)*basis_rec(N,x1,y1,z1,ielem(n,i)%iorder,IXX,ielem(n,i)%idegfree)
ilocal_recon3(i)%WEIGHTL(ll,k)=WLSQR(ll,K)
else
compwrt=1
ILOCAL_RECON3(I)%STENCILSc(LL,K,1:IDEG)=WLSQR(ll,K)*basis_rec(N,x1,y1,z1,INUMO,IXX,IDEG)
ilocal_recon3(i)%WEIGHTL(ll,k)=WLSQR(ll,K)
compwrt=0
end if
else
if((ees.ne.5).or.(ll.eq.1))then
compwrt=0
STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*basis_rec(N,x1,y1,z1,INUMO,IXX,IDEG)
else
compwrt=1
STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*basis_rec(N,x1,y1,z1,INUMO,IXX,IDEG)
compwrt=0
end if
end if
ELSE
if((ees.ne.5).or.(ll.eq.1))then
compwrt=0
STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*basis_rec(N,x1,y1,z1,INUMO,IXX,IDEG)
else
compwrt=1
STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*basis_rec(N,x1,y1,z1,INUMO,IXX,IDEG)
compwrt=0
end if
END IF
else
IXX=i;jxx=k+1;lxx1=ll
ELTYPE=ilocal_elem(1)%ishape(ll,k+1)
IF (GREENGO.EQ.0)THEN
if (idum.eq.1)then
if((ees.ne.5).or.(ll.eq.1))then
compwrt=0
ILOCAL_RECON3(I)%STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,IDEG)
ilocal_recon3(i)%WEIGHTL(ll,k)=WLSQR(ll,K)
else
compwrt=1
ILOCAL_RECON3(I)%STENCILSc(LL,K,1:IDEG)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,IDEG)
ilocal_recon3(i)%WEIGHTL(ll,k)=WLSQR(ll,K)
compwrt=0
end if
else
if((ees.ne.5).or.(ll.eq.1))then
compwrt=0
STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,IDEG)
else
compwrt=1
STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,IDEG)
compwrt=0
end if
end if
ELSE
if((ees.ne.5).or.(ll.eq.1))then
compwrt=0
STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,IDEG)
else
compwrt=1
STENCILS(LL,K,1:IDEG)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,IDEG)
compwrt=0
end if
END IF
end if
END DO !IMAXEDEGFREE
IF ((GREENGO.EQ.0))THEN
if (idum.eq.1)then
! DO IQ=1,ideg
! DO JQ=1,iDEG
invmat=zero
LSCQM=zero
! END DO !IDEGFREE
! END DO !IMAXDEGFREE
DO IQ=1,IDEG
DO JQ=1,IDEG
DO LQ=1,IMAX
if((ees.ne.5).or.(ll.eq.1))then
LSCQM(JQ,IQ)=LSCQM(JQ,IQ)&
+((ILOCAL_RECON3(I)%STENCILS(LL,LQ,JQ)*ILOCAL_RECON3(I)%STENCILS(LL,LQ,IQ)))
else
LSCQM(JQ,IQ)=LSCQM(JQ,IQ)&
+((ILOCAL_RECON3(I)%STENCILSc(LL,LQ,JQ)*ILOCAL_RECON3(I)%STENCILSc(LL,LQ,IQ)))
end if
END DO
END DO
END DO
else
! DO IQ=1,ideg
! DO JQ=1,iDEG
invmat=zero
LSCQM=zero
! END DO !IDEGFREE
! END DO !IMAXDEGFREE
DO IQ=1,IDEG
DO JQ=1,IDEG
DO LQ=1,IMAX
LSCQM(JQ,IQ)=LSCQM(JQ,IQ)&
+((STENCILS(LL,LQ,JQ)*STENCILS(LL,LQ,IQ)))
END DO
END DO
END DO
end if
ELSE
! DO IQ=1,ideg
! DO JQ=1,iDEG
invmat=zero
LSCQM=zero
! END DO !IDEGFREE
! END DO !IMAXDEGFREE
DO IQ=1,IDEG
DO JQ=1,IDEG
DO LQ=1,IMAX
LSCQM(JQ,IQ)=LSCQM(JQ,IQ)&
+((STENCILS(LL,LQ,JQ)*STENCILS(LL,LQ,IQ)))
END DO
END DO
END DO
END IF
QFF(:,:)=zero; RFF(:,:)=zero; QTFF(:,:)=zero; RFF(:,:)=zero; INVRFF(:,:)=zero
CALL QRDECOMPOSITION(LSCQM,QFF,RFF,IDEG)
CALL TRANSPOSEMATRIX(QFF,QTFF,IDEG)
IVGT=IDEG+1
CALL INVERT(RFF,INVRFF,IVGT)
invmat(1:IDEg,1:ideg)=MATMUL(INVRFF(1:ideg,1:IDEG),QTFF(1:IDEG,1:IDEG))
!
!
!
!
IF (GREENGO.EQ.0)THEN
if (idum.eq.1)then
if((ees.ne.5).or.(ll.eq.1))then
stencil(1:imax,1:ideg)=ILOCAL_RECON3(I)%STENCILS(LL,1:imax,1:ideg)
else
stencil(1:imax,1:ideg)=ILOCAL_RECON3(I)%STENCILSc(LL,1:imax,1:ideg)
end if
else
stencil(1:imax,1:ideg)=STENCILS(LL,1:imax,1:ideg)
end if
ELSE
stencil(1:imax,1:ideg)=STENCILS(LL,1:imax,1:ideg)
END IF
if((ees.ne.5).or.(ll.eq.1))then
! call gemm( &
! invmat, &
! stencil, &
! ILOCAL_RECON3(I)%invmat_stencilt(:,:,LL), &
! 'N', & ! transposition flag for invmat
! 'T' & ! transposition flag for stencil
! )
call DGEMM ('N','T',IDEG,IMAX,IDEG,ALPHA,invmat(1:ideg,1:ideg),IDEG,&
stencil(1:imax,1:ideg),IMAX,BETA,ILOCAL_RECON3(i)%invmat_stencilt(1:IDEG,1:IMAX,LL),IDEG)
do iq=1,imax
ILOCAL_RECON3(I)%invmat_stencilt(:,iq,LL)=ILOCAL_RECON3(I)%invmat_stencilt(:,iq,LL)&
*ilocal_elem(1)%VOLUME(ll,iq+1)*WLSQR(ll,iq)
end do
else
! call gemm( &
! invmat(1:ideg,1:ideg), &
! stencil(1:imax,1:ideg), &
! ILOCAL_RECON3(I)%invmat_stenciltc(1:IDEG,1:IMAX,LL), &
! 'N', & ! transposition flag for invmat
! 'T' & ! transposition flag for stencil
! )
call DGEMM ('N','T',IDEG,IMAX,IDEG,ALPHA,invmat(1:ideg,1:ideg),IDEG,&
stencil(1:imax,1:ideg),IMAX,BETA,ILOCAL_RECON3(i)%invmat_stenciltc(1:IDEG,1:IMAX,LL),IDEG)
do iq=1,imax
ILOCAL_RECON3(I)%invmat_stenciltc(:,iq,LL)=ILOCAL_RECON3(I)%invmat_stenciltc(:,iq,LL)&
*ilocal_elem(1)%VOLUME(ll,iq+1)*WLSQR(ll,iq)
end do
end if
if (ielem(n,i)%ggs.ne.1)then !ggs
IF (ITESTCASE.EQ.4)THEN !TEST
IF (LL.EQ.1)THEN !stencils
!
if (idum.eq.1)then !for wall only
!
DO IHGT=1,3; DO IHGJ=1,3
AINVJT(IHGT,IHGJ)=ILOCAL_RECON3(I)%INVCCJAC(IHGJ,IHGT)
END DO; END DO
idum2=0
BASEFACEVAL=zero
BASEFACGVAL=zero
PERMUTATION=zero
PERMUTATIONg=zero
DO j=1,IELEM(N,I)%IFCA !for all faces
if (ielem(n,i)%ibounds(J).gt.0)then !for bounded only
if (ibound(n,ielem(n,i)%ibounds(j))%icode.eq.4)then !!for bounded only 2
facex=J;iconsidered=i
CALL coordinates_face_inner(N,Iconsidered,facex)
CORDS(1:3)=zero
CORDS(1:3)=CORDINATES3(N,NODES_LIST,N_NODE)
AY=cords(2)
AX=cords(1)
AZ=cords(3)
VEXT(1,1)=AX;VEXT(1,2)=AY;VEXT(1,3)=AZ
VEXT(1,1:3)=MATMUL(ILOCAL_RECON3(I)%INVCCJAC(:,:),VEXT(1,1:3)-ILOCAL_RECON3(I)%VEXT_REF(1:3))
AX=VEXT(1,1);AY=VEXT(1,2);AZ=VEXT(1,3)
ANGLE1=IELEM(N,I)%FACEANGLEX(j)
ANGLE2=IELEM(N,I)%FACEANGLEY(j)
NX=(COS(ANGLE1)*SIN(ANGLE2))
NY=(SIN(ANGLE1)*SIN(ANGLE2))
NZ=(COS(ANGLE2))
NNX=(NX*AINVJT(1,1))+(NY*AINVJT(2,1))+(NZ*AINVJT(3,1))
NNY=(NX*AINVJT(1,2))+(NY*AINVJT(2,2))+(NZ*AINVJT(3,2))
NNZ=(NX*AINVJT(1,3))+(NY*AINVJT(2,3))+(NZ*AINVJT(3,3))
DO IQ=1, IDEG
IF (POLY.EQ.1) THEN
XDER(IQ)=DFX(AX,AY,AZ,IQ); YDER(IQ)=DFY(AX,AY,AZ,IQ); ZDER(IQ)=DFZ(AX,AY,AZ,IQ)
END IF
IF (POLY.EQ.2) THEN
XDER(IQ)=DLX(AX,AY,AZ,IQ); YDER(IQ)=DLY(AX,AY,AZ,IQ); ZDER(IQ)=DLZ(AX,AY,AZ,IQ)
END IF
IF (POLY.EQ.4) THEN
XDER(IQ)=TL3DX(AX,AY,AZ,IQ); YDER(IQ)=TL3DY(AX,AY,AZ,IQ); ZDER(IQ)=TL3DZ(AX,AY,AZ,IQ)
END IF
END DO
BASEFACEVAL(1:ielem(n,i)%IDEGFREE)=BASIS_REC(N,AX,AY,AZ,ielem(n,i)%Iorder,I,ielem(n,i)%IDEGFREE)
if (thermal.eq.0)then
BASEFACGVAL(1:ielem(n,i)%IDEGFREE)=((NNX*XDER(1:ielem(n,i)%IDEGFREE))+(NNY*YDER(1:ielem(n,i)%IDEGFREE))+(NNZ*ZDER(1:ielem(n,i)%IDEGFREE)))
ELSE
BASEFACGVAL(1:ielem(n,i)%IDEGFREE)=BASIS_REC(N,AX,AY,AZ,ielem(n,i)%Iorder,I,ielem(n,i)%IDEGFREE)
end if
DO IQ=1,IDEG
ILOCAL_RECON3(I)%WALLCOEFF(IQ)=BASEFACEVAL(IQ)
ILOCAL_RECON3(I)%WALLCOEFG(IQ)=BASEFACGVAL(IQ)
PERMUTATION(IQ)=IQ
PERMUTATIONG(IQ)=IQ
END DO
end if!for bounded only 2
end if!for bounded only
end do!for all faces
GGGG=-TOLBIG
G0=0
DO IQ=1,IDEG
IF (ABS(BASEFACGVAL(IQ)) >GGGG)THEN
GGGG=ABS(BASEFACGVAL(IQ))
G0=IQ
END IF
END DO
SSSS=-TOLBIG
K0=0
DO IQ=1,IDEG
IF (ABS(BASEFACEVAL(IQ)) >SSSS)THEN
SSSS=ABS(BASEFACEVAL(IQ))
K0=IQ
END IF
END DO
!
! now swap basis functions and thus coefficients
PERMUTATION(1)=K0; PERMUTATION(K0)=1; SSSS=BASEFACEVAL(1)
BASEFACEVAL(1)=BASEFACEVAL(K0); BASEFACEVAL(K0)=SSSS
PERMUTATIONG(1)=G0; PERMUTATION(G0)=1; GGGG=BASEFACGVAL(1)
BASEFACGVAL(1)=BASEFACGVAL(G0); BASEFACGVAL(G0)=GGGG
! ILOCAL_RECON3(II)%K0=K0
! ILOCAL_RECON3(II)%G0=G0
ILOCAL_RECON3(I)%K0=K0
ILOCAL_RECON3(I)%G0=G0
LSQM = ZERO
DO LQ=1,IMAX
LCOU=0
DO IQ=1,IDEG
IF (IQ.EQ.G0) CYCLE
LCOU=LCOU+1
LSQM(LQ,LCOU)=ILOCAL_RECON3(I)%STENCILS(LL,LQ,IQ)&
-ILOCAL_RECON3(I)%STENCILS(LL,LQ,G0)*ILOCAL_RECON3(I)%WALLCOEFG(IQ)/ILOCAL_RECON3(I)%WALLCOEFG(G0)
END DO
END DO
ILOCAL_RECON3(I)%TEMPSQ(1:IMAX,1:IDEG-1)=LSQM(1:IMAX,1:IDEG-1)
VELLSQMAT=ZERO
DO IQ=1,IDEG-1; DO JQ=1,IDEG-1; DO LCC=1,IMAX
!now store the least square matrix
VELLSQMAT(JQ,IQ)= VELLSQMAT(JQ,IQ)+(LSQM(LCC,JQ)*LSQM(LCC,IQ))
END DO; END DO; END DO
LSCQM=ZERO
LSCQM(1:IDEG-1,1:IDEG-1)=VELLSQMAT(1:IDEG-1,1:IDEG-1)
Qff=ZERO; Rff=ZERO; QTff=ZERO; INVRff=ZERO
IVGT=IDEG
CALL QRDECOMPOSITION(LSCQM,Qff,Rff,IVGT-1)
CALL TRANSPOSEMATRIX(Qff,QTff,IVGT-1)
CALL INVERT(Rff,INVRff,IVGT)
! final inverted R^(-1)*Q^(-1)
ILOCAL_RECON3(I)%TEMPSQMAT(1:IDEG-1,1:IDEG-1) =&
MATMUL(INVRff(1:IDEG-1,1:IDEG-1),QTff(1:IDEG-1,1:IDEG-1))
! definy the matrix defining the least-square reconstruction in this case for velocity
LSQM = ZERO
DO LQ=1,IMAX
LCOU=0
DO IQ=1,IDEG
IF (IQ.EQ.K0) CYCLE
LCOU=LCOU+1
LSQM(LQ,LCOU)=ILOCAL_RECON3(I)%STENCILS(LL,LQ,IQ)&
-ILOCAL_RECON3(I)%STENCILS(LL,LQ,K0)*ILOCAL_RECON3(I)%WALLCOEFF(IQ)/ILOCAL_RECON3(I)%WALLCOEFF(K0)
END DO
END DO
ILOCAL_RECON3(I)%VELLSQ(1:IMAX,1:IDEG-1)=LSQM(1:IMAX,1:IDEG-1)
VELLSQMAT=ZERO
DO IQ=1,IDEG-1; DO JQ=1,IDEG-1; DO LCC=1,IMAX
!now store the least square matrix
VELLSQMAT(JQ,IQ)= VELLSQMAT(JQ,IQ)+(LSQM(LCC,JQ)*LSQM(LCC,IQ))
END DO; END DO; END DO
LSCQM=ZERO
LSCQM(1:IDEG-1,1:IDEG-1)=VELLSQMAT(1:IDEG-1,1:IDEG-1)
Qff=ZERO; Rff=ZERO; QTff=ZERO; INVRff=ZERO
IVGT=IDEG
CALL QRDECOMPOSITION(LSCQM,Qff,Rff,IVGT-1)
CALL TRANSPOSEMATRIX(Qff,QTff,IVGT-1)
CALL INVERT(Rff,INVRff,IVGT)
! final inverted R^(-1)*Q^(-1)
ILOCAL_RECON3(I)%VELINVLSQMAT(1:IDEG-1,1:IDEG-1) = &
MATMUL(INVRff(1:IDEG-1,1:IDEG-1),QTff(1:IDEG-1,1:IDEG-1))
end if!for wall only
end if!stencils
end if!for test
end if!ggs
end do
END SUBROUTINE PRESTORE_RECONSTRUCTION3
subroutine walls_higher(n)
!> @brief
!> This subroutine allocates the memory for wall bounded cells for their constrained least squares reconstruction
implicit none
integer,intent(in)::n
integer::i,j,k,imax,ideg,inumo,inum,kmaxe,idum,idum2
KMAXE=XMPIELRANK(N)
DO I=1,KMAXE
ielem(n,i)%walls=0
IMAX=IELEM(N,I)%inumneighbours-1
INUM=IELEM(N,I)%inumneighbours
IDEG=IELEM(N,I)%iDEGFREE
INUMO=ielem(n,i)%iorder
if (ielem(n,i)%ggs.ne.1)then
IDUM=0;idum2=0
if (ielem(n,i)%interior.eq.1)then
DO j=1,IELEM(N,I)%IFCA
if (ielem(n,i)%ibounds(J).gt.0)then
if (ibound(n,ielem(n,i)%ibounds(j))%icode.eq.4)then
IDUM=1
if (dimensiona.eq.3)then
if (ielem(n,i)%types_faces(j).eq.5)then
idum2=idum2+qp_quad_n
else
idum2=idum2+QP_TRIANGLE_n
end if
else
idum2=idum2+qp_line_n
end if
end if
END IF
END DO
end if
if (idum.eq.1)then
allocate(ielem(n,i)%num_of_wall_gqp(1))
ielem(n,i)%num_of_wall_gqp(1)=idum2
ielem(n,i)%walls=1
IF (FASTEST.NE.1)THEN
ALLOCATE (ILOCAL_RECON3(I)%VELINVLSQMAT(IDEG-1,IDEG-1))
ALLOCATE (ILOCAL_RECON3(I)%WALLCOEFF(ideg))
ALLOCATE (ILOCAL_RECON3(I)%VELLSQ(IMAX,IDEG-1))
ALLOCATE (ILOCAL_RECON3(I)%TEMPSQMAT(IDEG-1,IDEG-1))
ALLOCATE (ILOCAL_RECON3(I)%WALLCOEFG(ideg))
ALLOCATE (ILOCAL_RECON3(I)%TEMPSQ(IMAX,IDEg-1))
ILOCAL_RECON3(I)%VELINVLSQMAT=zero
ILOCAL_RECON3(I)%WALLCOEFF=zero
ILOCAL_RECON3(I)%WALLCOEFG=zero
ILOCAL_RECON3(I)%TEMPSQMAT=zero
END IF
end if
end if
END DO
end subroutine walls_higher
SUBROUTINE PRESTORE_RECONSTRUCTION2(N,iconsi)
!> @brief
!> This subroutine prestores the pseudoinverse reconstruction least square matrices in 2d
IMPLICIT NONE
INTEGER,INTENT(IN)::N,iconsi
INTEGER::I,J,K,llco,ll,ii,igf,IGF2,IFD2,idum,idum2,iq,jq,lq,IHGT,IHGJ,iqp,iqp2,NND,k0,g0,lcou,lcc,ICOND1,ICOND2,ai,aj
real::ssss,gggg,UPTEMP,LOTEMP,DIST_STEN2,X_STENCIL,Y_STENCIL,DIST_STEN,maxai,minai
real, dimension(IELEM(N,Iconsi)%inumneighbours-1, ielem(n,iconsi)%idegfree):: stencil
real, dimension(7,IELEM(N,Iconsi)%inumneighbours-1, ielem(n,iconsi)%idegfree):: stencilS
real, dimension(ielem(n,iconsi)%idegfree, ielem(n,iconsi)%idegfree):: invmat
REAL,DIMENSION(7,IELEM(N,Iconsi)%inumneighbours-1)::WLSQR
i=iconsi
IDUM=0;
if (ielem(n,i)%interior.eq.1)then
DO j=1,IELEM(N,I)%IFCA
if (ielem(n,i)%ibounds(J).gt.0)then
if (ibound(n,ielem(n,i)%ibounds(j))%icode.eq.4)then
IDUM=1
end if
END IF
END DO
end if
ICONSIDERED=I
INTBS=zero
JXX=1;IXX=i;LXX1=1
number_of_dog=ielem(n,i)%idegfree
kxx=ielem(n,i)%iorder
ELTYPE=ielem(n,i)%ishape
compwrt=0
INTBS=CALINTBASIS(N,IXX,JXX,KXX,LXX1)
INTEG_BASIS(I)%VALUE(1:ielem(n,i)%IDEGFREE)=INTBS(1:ielem(n,i)%IDEGFREE)
ICONSIDERED=I
IF (IWENO.EQ.1)THEN
CALL INDICATORMATRIX(N,I)
END IF
if (ees.eq.5)then
INTBS=zero
JXX=1;IXX=i;LXX1=1
number_of_dog=idegfree2
kxx=IORDER2
ELTYPE=ielem(n,i)%ishape
compwrt=1
INTBS=CALINTBASIS(N,IXX,JXX,KXX,LXX1)
INTEG_BASIS(I)%VALUEc(1:number_of_dog)=INTBS(1:number_of_dog)
IF (IWENO.EQ.1)THEN
CALL INDICATORMATRIX2(N,I)
compwrt=0
END IF
end if
LLCO=IELEM(N,I)%ADMIS
IMAX=IELEM(N,I)%inumneighbours-1
INUM=IELEM(N,I)%inumneighbours
IDEG=IELEM(N,I)%iDEGFREE
INUMO=ielem(n,i)%iorder
imax2=numneighbours2-1
inum2=numneighbours2
ideg2=iDEGFREE2
inumo2=iorder2
DIST_STEN=ZERO
DO LL=1,LLCO !ADMIS
! !-------------------FOR DEBUGGING ONLY -----------------------------------------!
! !-------------------FOR DEBUGGING ONLY -----------------------------------------!
if((ees.ne.5).OR.(ll.eq.1))then
IMAX=IELEM(N,I)%inumneighbours-1
INUM=IELEM(N,I)%inumneighbours
IDEG=IELEM(N,I)%iDEGFREE
INUMO=ielem(n,i)%iorder
compwrt=0
else
imax=numneighbours2-1
inum=numneighbours2
ideg=iDEGFREE2
inumo=IORDER2
compwrt=1
end if
DO K=1,imax
ixx=i
kxx=INUMO
! WLSQR(K)=ilocal_elem(1)%XXC(ll,k+1)
IF (WEIGHT_LSQR.EQ.1)THEN
WLSQR(LL,K)=1.0D0/((SQRT(((ilocal_elem(1)%XXC(ll,k+1)-ilocal_elem(1)%XXC(ll,1))**2)+((ilocal_elem(1)%YYC(ll,k+1)-ilocal_elem(1)%YYC(ll,1))**2))))
ELSE
WLSQR(LL,K)=1.0D0
END IF
X_STENCIL=(ilocal_elem(1)%XXC(ll,k+1)-ilocal_elem(1)%XXC(ll,1))**2
Y_STENCIL=(ilocal_elem(1)%YYC(ll,k+1)-ilocal_elem(1)%YYC(ll,1))**2
DIST_STEN2=SQRT(X_STENCIL+Y_STENCIL)
DIST_STEN=MAX(DIST_STEN,DIST_STEN2)
IF (WEIGHT_LSQR.EQ.1)THEN
WLSQR(ll,K)=1.0D0/SQRT(X_STENCIL+Y_STENCIL)
ELSE
WLSQR(ll,K)=1.0D0
END IF
IELEM(N,I)%STENCIL_DIST=DIST_STEN/(ilocal_elem(1)%VOLUME(1,1)**(1/2))
if (fastest.eq.1)then
x1 = ilocal_elem(1)%XXC(ll,k+1)-ilocal_elem(1)%XXC(ll,1)
y1 = ilocal_elem(1)%YYC(ll,k+1)-ilocal_elem(1)%YYC(ll,1)
if((ees.ne.5).OR.(ll.eq.1))then
compwrt=0
ILOCAL_RECON3(I)%STENCILS(LL,K,1:ielem(n,i)%idegfree)=WLSQR(ll,K)*basis_rec2d(N,x1,y1,ielem(n,i)%iorder,IXX,ielem(n,i)%idegfree)
ilocal_recon3(i)%WEIGHTL(ll,k)=WLSQR(ll,K)
else
compwrt=1
ILOCAL_RECON3(I)%STENCILSc(LL,K,1:ideg)=WLSQR(ll,K)*basis_rec2d(N,x1,y1,inumo,IXX,ideg)
ilocal_recon3(i)%WEIGHTL(ll,k)=WLSQR(ll,K)
compwrt=0
end if
else
IXX=i;jxx=k+1;lxx1=ll
ELTYPE=ilocal_elem(1)%ishape(ll,k+1)
IF (GREENGO.EQ.0)THEN
if (idum.eq.1)then
if((ees.ne.5).OR.(ll.eq.1))then
compwrt=0
ILOCAL_RECON3(I)%STENCILS(LL,K,1:ielem(n,i)%idegfree)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,ielem(n,i)%idegfree)
ilocal_recon3(i)%WEIGHTL(ll,k)=WLSQR(ll,K)
else
compwrt=1
ILOCAL_RECON3(I)%STENCILSc(LL,K,1:ideg)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,ideg)
ilocal_recon3(i)%WEIGHTL(ll,k)=WLSQR(ll,K)
compwrt=0
end if
else
if((ees.ne.5).OR.(ll.eq.1))then
compwrt=0
else
compwrt=1
end if
STENCILS(LL,K,1:ideg)=WLSQR(ll,K)*COMPBASEL(N,ELTYPE,ideg)
compwrt=0
end if