-
Notifications
You must be signed in to change notification settings - Fork 1
/
tools.f90
1180 lines (1079 loc) · 36.8 KB
/
tools.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
!################################################################################
!This file is part of Incompact3d.
!
!Incompact3d
!Copyright (c) 2012 Eric Lamballais and Sylvain Laizet
!
! Incompact3d is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation.
!
! Incompact3d is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with the code. If not, see <http://www.gnu.org/licenses/>.
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! We kindly request that you cite Incompact3d in your publications and
! presentations. The following citations are suggested:
!
! 1-Laizet S. & Lamballais E., 2009, High-order compact schemes for
! incompressible flows: a simple and efficient method with the quasi-spectral
! accuracy, J. Comp. Phys., vol 228 (15), pp 5989-6015
!
! 2-Laizet S. & Li N., 2011, Incompact3d: a powerful tool to tackle turbulence
! problems with up to 0(10^5) computational cores, Int. J. of Numerical
! Methods in Fluids, vol 67 (11), pp 1735-1757
!################################################################################
!*******************************************************************
!
subroutine test_scalar_min_max(phi)
!
!*******************************************************************
USE decomp_2d
USE decomp_2d_poisson
USE variables
USE param
USE var
USE MPI
use derivX, only : alsaixt, asixt, bsixt, csixt
use derivY, only : alsajyt, asjyt, bsjyt, csjyt
implicit none
integer :: i,j,k
real(mytype) :: phimax,phimin,cfl
real(mytype) :: phimax1,phimin1
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: phi
integer :: code
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: phi_obj
real(mytype) :: x, y, z
real(mytype) :: mysx, mysy, mysz
integer, dimension(3) :: mymax
real(mytype) :: tx, ty, w
real(mytype) :: ta,tl,tb,tc
phimax=-1609.
phimin=1609.
do k=1,xsize(3)
do j=1,xsize(2)
do i=1,xsize(1)
if (phi(i,j,k).gt.phimax) phimax=phi(i,j,k)
if (phi(i,j,k).lt.phimin) phimin=phi(i,j,k)
enddo
enddo
enddo
call MPI_REDUCE(phimax,phimax1,1,real_type,MPI_MAX,0,MPI_COMM_WORLD,code)
call MPI_REDUCE(phimin,phimin1,1,real_type,MPI_MIN,0,MPI_COMM_WORLD,code)
if (nrank==0) then
print *,'PHI max=',phimax1
print *,'PHI min=',phimin1
endif
if (itype.eq.6) then
do k=1,xsize(3)
z=(k-1+xstart(3)-1)*dz
mysz=sin(twopi*z)
do j=1,xsize(2)
y=yp(j)
mysy=sin(twopi*y)
do i=1,xsize(1)
x=(i-1+xstart(1)-1)*dx
mysx=sin(twopi*x)
phi_obj(i,j,k)= mysx*mysy
enddo
enddo
enddo
! Expression valid only for AB2 time-scheme
if (t.gt.0.d0) then
tx=dt*(twopi**2)*xnu/(2.d0*sc)
ty=dt*(twopi**2)*xnu/(2.d0*sc)
w=twopi*dx
tx = tx * &
( (2.d0*asixt*dx2*(1.d0-cos(w)) + &
2.d0*bsixt*dx2*(1.d0-cos(2.d0*w)) + &
2.d0*csixt*dx2*(1.d0-cos(3.d0*w)) &
) / (1.d0+2.d0*alsaixt*cos(w)) &
)/(w**2)
w=twopi*dy
ty = ty * &
( (2.d0*asjyt*dy2*(1.d0-cos(w)) + &
2.d0*bsjyt*dy2*(1.d0-cos(2.d0*w)) + &
2.d0*csjyt*dy2*(1.d0-cos(3.d0*w)) &
) / (1.d0+2.d0*alsajyt*cos(w)) &
)/(w**2)
if (iimplicit.eq.0) then
tc=sqrt( 9.d0*((tx+ty)**2)-2.d0*(tx+ty)+1.d0 )
tc=tc-3.d0*tx-3.d0*ty+1.d0
tc=tc/2.d0
else
if (istret.eq.0) then
tc=sqrt( (3.d0*tx+ty-1)**2+4.d0*tx*(1.d0+ty) )
tc=tc-3.d0*tx-ty+1.d0
tc=tc/2.d0/(ty+1.d0)
else
tc=1.d0
endif
endif
do i=1,itime
phi_obj=phi_obj*tc
enddo
if ((iimplicit.eq.1).and.(istret.ne.0)) then
ta=dt*(twopi**2)*xnu/(2.d0*sc)
tl=(6.d0*ta+1.d0)/(2.d0*ta+1.d0)
do j=1,xsize(2)
tb=dt*twopi*xnu*pp4y(j-1+xstart(2))/(2.d0*sc)
tc=( (1.d0+ta)*(1.d0-4.d0*ta+ta*tl)+(tb**2)*(2.d0-tl) )/( (1.d0+ta)**2+tb**2 )
phi_obj(:,j,:)=phi_obj(:,j,:)*tc
enddo
endif
endif
! Norme L_infinie
phimax=maxval(abs(phi-phi_obj))
call MPI_ALLREDUCE(phimax,phimax1,1,real_type,MPI_MAX,MPI_COMM_WORLD,i)
if (nrank.eq.0) print *,'Norme T infinie = ',phimax1
mymax=maxloc(abs(phi-phi_obj))
if (phimax.eq.phimax1) print *,' at ',mymax+xstart,' on ',nrank
! Norme L2
phimax=sum((phi-phi_obj)**2)
call MPI_REDUCE(phimax,phimax1,1,real_type,MPI_SUM,0,MPI_COMM_WORLD,i)
if (nrank.eq.0) phimax1=phimax1/(nx*nz*ny)
if (nrank.eq.0) print *,'Norme T2 (**1/2)= ',sqrt(phimax1)
endif
return
end subroutine test_scalar_min_max
!*******************************************************************
!
subroutine test_speed_min_max(ux,uy,uz)
!
!*******************************************************************
USE decomp_2d
USE decomp_2d_poisson
USE variables
USE param
USE var
USE MPI
use derivX, only : alsaix, asix, bsix, csix
use derivY, only : alsajy, asjy, bsjy, csjy
implicit none
integer :: i,j,k
real(mytype) :: uxmax,uymax,uzmax,uxmin,uymin,uzmin,cfl
real(mytype) :: uxmax1,uymax1,uzmax1,uxmin1,uymin1,uzmin1
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: ux,uy,uz
integer :: code
real(mytype),dimension(xsize(1),xsize(2),xsize(3)) :: ux_obj,uy_obj,uz_obj
real(mytype) :: x, y, z
real(mytype) :: mysx, mycx, mysy, mycy
integer, dimension(3) :: mymax
real(mytype) :: tx, ty, w
real(mytype) :: ta,tl,tb,tc
uxmax=-1609.
uymax=-1609.
uzmax=-1609.
uxmin=1609.
uymin=1609.
uzmin=1609.
do k=1,xsize(3)
do j=1,xsize(2)
do i=1,xsize(1)
if (ux(i,j,k).gt.uxmax) uxmax=ux(i,j,k)
if (uy(i,j,k).gt.uymax) uymax=uy(i,j,k)
if (uz(i,j,k).gt.uzmax) uzmax=uz(i,j,k)
if (ux(i,j,k).lt.uxmin) uxmin=ux(i,j,k)
if (uy(i,j,k).lt.uymin) uymin=uy(i,j,k)
if (uz(i,j,k).lt.uzmin) uzmin=uz(i,j,k)
enddo
enddo
enddo
call MPI_REDUCE(uxmax,uxmax1,1,real_type,MPI_MAX,0,MPI_COMM_WORLD,code)
call MPI_REDUCE(uymax,uymax1,1,real_type,MPI_MAX,0,MPI_COMM_WORLD,code)
call MPI_REDUCE(uzmax,uzmax1,1,real_type,MPI_MAX,0,MPI_COMM_WORLD,code)
call MPI_REDUCE(uxmin,uxmin1,1,real_type,MPI_MIN,0,MPI_COMM_WORLD,code)
call MPI_REDUCE(uymin,uymin1,1,real_type,MPI_MIN,0,MPI_COMM_WORLD,code)
call MPI_REDUCE(uzmin,uzmin1,1,real_type,MPI_MIN,0,MPI_COMM_WORLD,code)
if (nrank==0) then
print *,'U,V,W max=',uxmax1,uymax1,uzmax1
print *,'U,V,W min=',uxmin1,uymin1,uzmin1
endif
if ((itype.eq.6).or.(itype.eq.7)) then
if (itype.eq.6) then
do k=1,xsize(3)
z=(k-1+xstart(3)-1)*dz
do j=1,xsize(2)
y=yp(j)
mysy=sin(twopi*y)
mycy=cos(twopi*y)
do i=1,xsize(1)
x=(i-1+xstart(1)-1)*dx
mysx=sin(twopi*x)
mycx=cos(twopi*x)
ux_obj(i,j,k)= mysx*mycy
uy_obj(i,j,k)=-mysy*mycx
uz_obj(i,j,k)=0.d0
enddo
enddo
enddo
! Expression valid only for AB2 time-scheme
if (t.gt.0.d0) then
tx=dt*(twopi**2)*xnu/2.d0
ty=dt*(twopi**2)*xnu/2.d0
w=twopi*dx
tx = tx * &
( (2.d0*asix*dx2*(1.d0-cos(w)) + &
2.d0*bsix*dx2*(1.d0-cos(2.d0*w)) + &
2.d0*csix*dx2*(1.d0-cos(3.d0*w)) &
) / (1.d0+2.d0*alsaix*cos(w)) &
)/(w**2)
w=twopi*dy
ty = ty * &
( (2.d0*asjy*dy2*(1.d0-cos(w)) + &
2.d0*bsjy*dy2*(1.d0-cos(2.d0*w)) + &
2.d0*csjy*dy2*(1.d0-cos(3.d0*w)) &
) / (1.d0+2.d0*alsajy*cos(w)) &
)/(w**2)
if (iimplicit.eq.0) then
tc=sqrt( 9.d0*((tx+ty)**2)-2.d0*(tx+ty)+1.d0 )
tc=tc-3.d0*tx-3.d0*ty+1.d0
tc=tc/2.d0
else
if (istret.eq.0) then
tc=sqrt( (3.d0*tx+ty-1)**2+4.d0*tx*(1.d0+ty) )
tc=tc-3.d0*tx-ty+1.d0
tc=tc/2.d0/(ty+1.d0)
else
tc=1.d0
endif
endif
do i=1,itime
ux_obj=ux_obj*tc
uy_obj=uy_obj*tc
uz_obj=uz_obj*tc
enddo
if ((iimplicit.eq.1).and.(istret.ne.0)) then
ta=dt*(twopi**2)*xnu/2.d0
tl=(6.d0*ta+1.d0)/(2.d0*ta+1.d0)
do j=1,xsize(2)
tb=dt*twopi*xnu*pp4y(j-1+xstart(2))/2.d0
tc=( (1.d0+ta)*(1.d0-4.d0*ta+ta*tl)+(tb**2)*(2.d0-tl) )/( (1.d0+ta)**2+tb**2 )
ux_obj(:,j,:)=ux_obj(:,j,:)*tc
uy_obj(:,j,:)=uy_obj(:,j,:)*tc
uz_obj(:,j,:)=uz_obj(:,j,:)*tc
enddo
endif
endif
else
do k=1,xsize(3)
z=(k-1+xstart(3)-1)*dz
do j=1,xsize(2)
y=yp(j)
do i=1,xsize(1)
x=(i-1+xstart(1)-1)*dx
ux_obj(i,j,k)= 8.*(x**4-2.*x**3+x**2)*(4.*y**3-2.*y)
uy_obj(i,j,k)=-8.*(4.*x**3-6.*x**2+2.*x)*(y**4-y**2)
uz_obj(i,j,k)=0.
enddo
enddo
enddo
endif
! Norme L_infinie vitesse
uxmax=maxval(abs(ux-ux_obj))
call MPI_ALLREDUCE(uxmax,uxmax1,1,real_type,MPI_MAX,MPI_COMM_WORLD,i)
mymax=maxloc(abs(ux-ux_obj))
if (nrank.eq.0) print *,'Norme Lix infinie = ',uxmax1
if (uxmax.eq.uxmax1) print *,' at ',mymax(1),mymax(2),mymax(3)
uymax=maxval(abs(uy-uy_obj))
call MPI_ALLREDUCE(uymax,uymax1,1,real_type,MPI_MAX,MPI_COMM_WORLD,i)
mymax=maxloc(abs(uy-uy_obj))
if (nrank.eq.0) print *,'Norme Liy infinie = ',uymax1
if (uymax.eq.uymax1) print *,' at ',mymax(1),mymax(2),mymax(3)
uzmax=maxval(abs(uz-uz_obj))
call MPI_ALLREDUCE(uzmax,uzmax1,1,real_type,MPI_MAX,MPI_COMM_WORLD,i)
mymax=maxloc(abs(uz-uz_obj))
if (nrank.eq.0) print *,'Norme Liz infinie = ',uzmax1
if (uzmax.eq.uzmax1) print *,' at ',mymax(1),mymax(2),mymax(3)
uxmax=maxval(abs(ux-ux_obj)+abs(uy-uy_obj)+abs(uz-uz_obj))
call MPI_ALLREDUCE(uxmax,uxmax1,1,real_type,MPI_MAX,MPI_COMM_WORLD,i)
mymax=maxloc(abs(ux-ux_obj)+abs(uy-uy_obj)+abs(uz-uz_obj))
if (nrank.eq.0) print *,'Norme Liw infinie = ',uxmax1
if (uxmax.eq.uxmax1) print *,' at ',mymax(1),mymax(2),mymax(3)
! Norme L2 vitesse
uxmax=sum((ux-ux_obj)**2)/(nx*ny*nz)
call MPI_REDUCE(uxmax,uxmax1,1,real_type,MPI_SUM,0,MPI_COMM_WORLD,i)
if (nrank.eq.0) print *,'Norme L2x (**1/2) = ',sqrt(uxmax1)
uymax=sum((uy-uy_obj)**2)/(nx*ny*nz)
call MPI_REDUCE(uymax,uymax1,1,real_type,MPI_SUM,0,MPI_COMM_WORLD,i)
if (nrank.eq.0) print *,'Norme L2y (**1/2) = ',sqrt(uymax1)
uzmax=sum((uz-uz_obj)**2)/(nx*ny*nz)
call MPI_REDUCE(uzmax,uzmax1,1,real_type,MPI_SUM,0,MPI_COMM_WORLD,i)
if (nrank.eq.0) print *,'Norme L2z (**1/2) = ',sqrt(uzmax1)
if (nrank.eq.0) print *,'Norme L2w (**1/2) = ',sqrt(uxmax1+uymax1+uzmax1)
endif
return
end subroutine test_speed_min_max
!*******************************************************************
!
subroutine restart(ux1,uy1,uz1,ep1,pp3,phi1,gx1,gy1,gz1,px1,py1,pz1,phis1,&
hx1,hy1,hz1,phiss1,phG,irestart)
!
!*******************************************************************
USE decomp_2d
USE decomp_2d_io
USE variables
USE param
USE MPI
implicit none
TYPE(DECOMP_INFO) :: phG
integer :: i,j,k,irestart,nzmsize,fh,ierror,code
real(mytype), dimension(xsize(1),xsize(2),xsize(3)) :: ux1,uy1,uz1,ep1
real(mytype), dimension(xsize(1),xsize(2),xsize(3)) :: gx1,gy1,gz1
real(mytype), dimension(xsize(1),xsize(2),xsize(3)) :: hx1,hy1,hz1
real(mytype), dimension(xsize(1),xsize(2),xsize(3)) :: px1,py1,pz1
real(mytype), dimension(xsize(1),xsize(2),xsize(3)) :: phi1, phis1, phiss1
real(mytype), dimension(phG%zst(1):phG%zen(1),phG%zst(2):phG%zen(2),phG%zst(3):phG%zen(3)) :: pp3
integer (kind=MPI_OFFSET_KIND) :: filesize, disp
real(mytype) :: xdt
integer, dimension(2) :: dims, dummy_coords
logical, dimension(2) :: dummy_periods
if (iscalar==0) then
if (nscheme.ne.4) then
if (irestart==1) then !write
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'sauve.dat', &
MPI_MODE_CREATE+MPI_MODE_WRONLY, MPI_INFO_NULL, &
fh, ierror)
filesize = 0_MPI_OFFSET_KIND
call MPI_FILE_SET_SIZE(fh,filesize,ierror) ! guarantee overwriting
disp = 0_MPI_OFFSET_KIND
call decomp_2d_write_var(fh,disp,1,ux1)
call decomp_2d_write_var(fh,disp,1,uy1)
call decomp_2d_write_var(fh,disp,1,uz1)
call decomp_2d_write_var(fh,disp,1,gx1)
call decomp_2d_write_var(fh,disp,1,gy1)
call decomp_2d_write_var(fh,disp,1,gz1)
call decomp_2d_write_var(fh,disp,1,px1)
call decomp_2d_write_var(fh,disp,1,py1)
call decomp_2d_write_var(fh,disp,1,pz1)
call decomp_2d_write_var(fh,disp,1,pp3,phG)
call MPI_FILE_CLOSE(fh,ierror)
else
if (nrank==0) print *,'RESTART'
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'sauve.dat', &
MPI_MODE_RDONLY, MPI_INFO_NULL, &
fh, ierror)
disp = 0_MPI_OFFSET_KIND
call decomp_2d_read_var(fh,disp,1,ux1)
call decomp_2d_read_var(fh,disp,1,uy1)
call decomp_2d_read_var(fh,disp,1,uz1)
call decomp_2d_read_var(fh,disp,1,gx1)
call decomp_2d_read_var(fh,disp,1,gy1)
call decomp_2d_read_var(fh,disp,1,gz1)
call decomp_2d_read_var(fh,disp,1,px1)
call decomp_2d_read_var(fh,disp,1,py1)
call decomp_2d_read_var(fh,disp,1,pz1)
call decomp_2d_read_var(fh,disp,1,pp3,phG)
call MPI_FILE_CLOSE(fh,ierror)
endif
else !AB3
if (irestart==1) then !write
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'sauve.dat', &
MPI_MODE_CREATE+MPI_MODE_WRONLY, MPI_INFO_NULL, &
fh, ierror)
filesize = 0_MPI_OFFSET_KIND
call MPI_FILE_SET_SIZE(fh,filesize,ierror) ! guarantee overwriting
disp = 0_MPI_OFFSET_KIND
call decomp_2d_write_var(fh,disp,1,ux1)
call decomp_2d_write_var(fh,disp,1,uy1)
call decomp_2d_write_var(fh,disp,1,uz1)
call decomp_2d_write_var(fh,disp,1,gx1)
call decomp_2d_write_var(fh,disp,1,gy1)
call decomp_2d_write_var(fh,disp,1,gz1)
call decomp_2d_write_var(fh,disp,1,hx1)
call decomp_2d_write_var(fh,disp,1,hy1)
call decomp_2d_write_var(fh,disp,1,hz1)
call decomp_2d_write_var(fh,disp,1,px1)
call decomp_2d_write_var(fh,disp,1,py1)
call decomp_2d_write_var(fh,disp,1,pz1)
call decomp_2d_write_var(fh,disp,1,pp3,phG)
call MPI_FILE_CLOSE(fh,ierror)
else
if (nrank==0) print *,'RESTART'
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'sauve.dat', &
MPI_MODE_RDONLY, MPI_INFO_NULL, &
fh, ierror)
disp = 0_MPI_OFFSET_KIND
call decomp_2d_read_var(fh,disp,1,ux1)
call decomp_2d_read_var(fh,disp,1,uy1)
call decomp_2d_read_var(fh,disp,1,uz1)
call decomp_2d_read_var(fh,disp,1,gx1)
call decomp_2d_read_var(fh,disp,1,gy1)
call decomp_2d_read_var(fh,disp,1,gz1)
call decomp_2d_read_var(fh,disp,1,hx1)
call decomp_2d_read_var(fh,disp,1,hy1)
call decomp_2d_read_var(fh,disp,1,hz1)
call decomp_2d_read_var(fh,disp,1,px1)
call decomp_2d_read_var(fh,disp,1,py1)
call decomp_2d_read_var(fh,disp,1,pz1)
call decomp_2d_read_var(fh,disp,1,pp3,phG)
call MPI_FILE_CLOSE(fh,ierror)
endif
endif
else !SCALAR
if (nscheme.ne.4) then
if (irestart==1) then !write
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'sauve.dat', &
MPI_MODE_CREATE+MPI_MODE_WRONLY, MPI_INFO_NULL, &
fh, ierror)
filesize = 0_MPI_OFFSET_KIND
call MPI_FILE_SET_SIZE(fh,filesize,ierror) ! guarantee overwriting
disp = 0_MPI_OFFSET_KIND
call decomp_2d_write_var(fh,disp,1,ux1)
call decomp_2d_write_var(fh,disp,1,uy1)
call decomp_2d_write_var(fh,disp,1,uz1)
call decomp_2d_write_var(fh,disp,1,gx1)
call decomp_2d_write_var(fh,disp,1,gy1)
call decomp_2d_write_var(fh,disp,1,gz1)
call decomp_2d_write_var(fh,disp,1,px1)
call decomp_2d_write_var(fh,disp,1,py1)
call decomp_2d_write_var(fh,disp,1,pz1)
call decomp_2d_write_var(fh,disp,1,pp3,phG)
call decomp_2d_write_var(fh,disp,1,phi1)
call decomp_2d_write_var(fh,disp,1,phis1)
call MPI_FILE_CLOSE(fh,ierror)
else
if (nrank==0) print *,'RESTART'
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'sauve.dat', &
MPI_MODE_RDONLY, MPI_INFO_NULL, &
fh, ierror)
disp = 0_MPI_OFFSET_KIND
call decomp_2d_read_var(fh,disp,1,ux1)
call decomp_2d_read_var(fh,disp,1,uy1)
call decomp_2d_read_var(fh,disp,1,uz1)
call decomp_2d_read_var(fh,disp,1,gx1)
call decomp_2d_read_var(fh,disp,1,gy1)
call decomp_2d_read_var(fh,disp,1,gz1)
call decomp_2d_read_var(fh,disp,1,px1)
call decomp_2d_read_var(fh,disp,1,py1)
call decomp_2d_read_var(fh,disp,1,pz1)
call decomp_2d_read_var(fh,disp,1,pp3,phG)
call decomp_2d_read_var(fh,disp,1,phi1)
call decomp_2d_read_var(fh,disp,1,phis1)
call MPI_FILE_CLOSE(fh,ierror)
endif
else !SCALAR + AB3
if (irestart==1) then !write
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'sauve.dat', &
MPI_MODE_CREATE+MPI_MODE_WRONLY, MPI_INFO_NULL, &
fh, ierror)
filesize = 0_MPI_OFFSET_KIND
call MPI_FILE_SET_SIZE(fh,filesize,ierror) ! guarantee overwriting
disp = 0_MPI_OFFSET_KIND
call decomp_2d_write_var(fh,disp,1,ux1)
call decomp_2d_write_var(fh,disp,1,uy1)
call decomp_2d_write_var(fh,disp,1,uz1)
call decomp_2d_write_var(fh,disp,1,gx1)
call decomp_2d_write_var(fh,disp,1,gy1)
call decomp_2d_write_var(fh,disp,1,gz1)
call decomp_2d_write_var(fh,disp,1,hx1)
call decomp_2d_write_var(fh,disp,1,hy1)
call decomp_2d_write_var(fh,disp,1,hz1)
call decomp_2d_write_var(fh,disp,1,px1)
call decomp_2d_write_var(fh,disp,1,py1)
call decomp_2d_write_var(fh,disp,1,pz1)
call decomp_2d_write_var(fh,disp,1,pp3,phG)
call decomp_2d_write_var(fh,disp,1,phi1)
call decomp_2d_write_var(fh,disp,1,phis1)
call decomp_2d_write_var(fh,disp,1,phiss1)
call MPI_FILE_CLOSE(fh,ierror)
else
if (nrank==0) print *,'RESTART'
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'sauve.dat', &
MPI_MODE_RDONLY, MPI_INFO_NULL, &
fh, ierror)
disp = 0_MPI_OFFSET_KIND
call decomp_2d_read_var(fh,disp,1,ux1)
call decomp_2d_read_var(fh,disp,1,uy1)
call decomp_2d_read_var(fh,disp,1,uz1)
call decomp_2d_read_var(fh,disp,1,gx1)
call decomp_2d_read_var(fh,disp,1,gy1)
call decomp_2d_read_var(fh,disp,1,gz1)
call decomp_2d_read_var(fh,disp,1,hx1)
call decomp_2d_read_var(fh,disp,1,hy1)
call decomp_2d_read_var(fh,disp,1,hz1)
call decomp_2d_read_var(fh,disp,1,px1)
call decomp_2d_read_var(fh,disp,1,py1)
call decomp_2d_read_var(fh,disp,1,pz1)
call decomp_2d_read_var(fh,disp,1,pp3,phG)
call decomp_2d_read_var(fh,disp,1,phi1)
call decomp_2d_read_var(fh,disp,1,phis1)
call decomp_2d_read_var(fh,disp,1,phiss1)
call MPI_FILE_CLOSE(fh,ierror)
endif
endif
endif
if (irestart==0) then
! reconstruction of the dp/dx, dp/dy and dp/dz from px1,py1 and pz1
! Temporal scheme (1:AB2, 2: RK3, 3:RK4, 4:AB3)
if (nscheme==1) xdt=adt(1)+bdt(1)
if (nscheme==2) xdt=(3./4.)*dt + (-5./12.)*dt
if (nscheme==3) xdt=0.041717869325*dt
if (nscheme==4) xdt=adt(1)+bdt(1)+cdt(1)
do k=1,xsize(3)
do j=1,xsize(2)
dpdyx1(j,k)=py1(1,j,k)/xdt
dpdzx1(j,k)=pz1(1,j,k)/xdt
dpdyxn(j,k)=py1(nx,j,k)/xdt
dpdzxn(j,k)=pz1(nx,j,k)/xdt
enddo
enddo
if (xsize(3)==1) then
do j=1,xsize(2)
do i=1,xsize(1)
dpdxz1(i,j)=px1(i,j,1)/xdt
dpdyz1(i,j)=py1(i,j,1)/xdt
enddo
enddo
endif
if (xsize(3)==nz) then
do j=1,xsize(2)
do i=1,xsize(1)
dpdxzn(i,j)=px1(i,j,nz)/xdt
dpdyzn(i,j)=py1(i,j,nz)/xdt
enddo
enddo
endif
! determine the processor grid in use
call MPI_CART_GET(DECOMP_2D_COMM_CART_X, 2, &
dims, dummy_periods, dummy_coords, code)
if (dims(1)==1) then
do k=1,xsize(3)
do i=1,xsize(1)
dpdxy1(i,k)=px1(i,1,k)/xdt
dpdzy1(i,k)=pz1(i,1,k)/xdt
enddo
enddo
do k=1,xsize(3)
do i=1,xsize(1)
dpdxyn(i,k)=px1(i,xsize(2),k)/xdt
dpdzyn(i,k)=pz1(i,xsize(2),k)/xdt
enddo
enddo
else
!find j=1 and j=ny
if (xstart(2)==1) then
do k=1,xsize(3)
do i=1,xsize(1)
dpdxy1(i,k)=px1(i,1,k)/xdt
dpdzy1(i,k)=pz1(i,1,k)/xdt
enddo
enddo
endif
! print *,nrank,xstart(2),ny-(nym/p_row)
if (ny-(nym/dims(1))==xstart(2)) then
do k=1,xsize(3)
do i=1,xsize(1)
dpdxyn(i,k)=px1(i,xsize(2),k)/xdt
dpdzyn(i,k)=pz1(i,xsize(2),k)/xdt
enddo
enddo
endif
endif
if (nrank==0) print *,'reconstruction pressure gradients done!'
endif
if (irestart==0) then
if (ivirt==2) then
call MPI_FILE_OPEN(MPI_COMM_WORLD, 'epsilon.dat', &
MPI_MODE_RDONLY, MPI_INFO_NULL, &
fh, ierror)
disp = 0_MPI_OFFSET_KIND
call decomp_2d_read_var(fh,disp,1,ep1)
call MPI_FILE_CLOSE(fh,ierror)
if (nrank==0) print *,'read epsilon file done from restart'
endif
endif
end subroutine restart
!
!*******************************************************************
subroutine stretching()
!
!*******************************************************************
!
USE decomp_2d
USE decomp_2d_poisson
USE variables
USE param
USE var
USE MPI
implicit none
real(mytype) :: yinf,den,xnum,xcx,den1,den2,den3,den4,xnum1,cst
integer :: j
yinf=-yly/2.
den=2.*beta*yinf
xnum=-yinf-sqrt(pi*pi*beta*beta+yinf*yinf)
alpha=abs(xnum/den)
xcx=1./beta/alpha
if (alpha.ne.0.) then
if (istret.eq.1) yp(1)=0.
if (istret.eq.2) yp(1)=0.
if (istret.eq.1) yeta(1)=0.
if (istret.eq.2) yeta(1)=-1./2.
if (istret.eq.3) yp(1)=0.
if (istret.eq.3) yeta(1)=-1./2.
do j=2,ny!-1
if (istret==1) then
if (ncly.eq.0) yeta(j)=(j-1.)*(1./ny)
if ((ncly.eq.1).or.(ncly.eq.2)) yeta(j)=(j-1.)*(1./(ny-1.))
endif
if (istret==2) then
if (ncly.eq.0) yeta(j)=(j-1.)*(1./ny)-0.5
if ((ncly.eq.1).or.(ncly.eq.2)) yeta(j)=(j-1.)*(1./(ny-1.))-0.5
endif
if (istret==3) then
if (ncly.eq.0) yeta(j)=((j-1.)*(1./2./ny)-0.5)
if ((ncly.eq.1).or.(ncly.eq.2)) yeta(j)=((j-1.)*(1./2./(ny-1.))-0.5)
endif
den1=sqrt(alpha*beta+1.)
xnum=den1/sqrt(alpha/pi)/sqrt(beta)/sqrt(pi)
den=2.*sqrt(alpha/pi)*sqrt(beta)*pi*sqrt(pi)
den3=((sin(pi*yeta(j)))*(sin(pi*yeta(j)))/beta/pi)+alpha/pi
den4=2.*alpha*beta-cos(2.*pi*yeta(j))+1.
if ((ncly.ne.0).and.(j==ny).and.(istret==1)) then
xnum1=0.
else
xnum1=(atan(xnum*tan(pi*yeta(j))))*den4/den1/den3/den
endif
cst=sqrt(beta)*pi/(2.*sqrt(alpha)*sqrt(alpha*beta+1.))
if (istret==1) then
if (yeta(j).lt.0.5) yp(j)=xnum1-cst-yinf
if (yeta(j).eq.0.5) yp(j)=0.-yinf
if (yeta(j).gt.0.5) yp(j)=xnum1+cst-yinf
endif
if (istret==2) then
if (yeta(j).lt.0.5) yp(j)=xnum1-cst+yly
if (yeta(j).eq.0.5) yp(j)=0.+yly
if (yeta(j).gt.0.5) yp(j)=xnum1+cst+yly
endif
if (istret==3) then
if (yeta(j).lt.0.5) yp(j)=(xnum1-cst+yly)*2.
if (yeta(j).eq.0.5) yp(j)=(0.+yly)*2.
if (yeta(j).gt.0.5) yp(j)=(xnum1+cst+yly)*2.
endif
enddo
endif
!if (nrank==0) then
!do j=1,ny
!print *,j,yp(j),yeta(j)
!enddo
!endif
!stop
if (alpha.eq.0.) then
yp(1)=-1.e10
do j=2,ny
yeta(j)=(j-1.)*(1./ny)
yp(j)=-beta*cos(pi*yeta(j))/sin(yeta(j)*pi)
enddo
endif
if (alpha.ne.0.) then
do j=1,ny
if (istret==1) then
if (ncly.eq.0) yetai(j)=(j-0.5)*(1./ny)
if ((ncly.eq.1).or.(ncly.eq.2)) yetai(j)=(j-0.5)*(1./(ny-1.))
endif
if (istret==2) then
if (ncly.eq.0) yetai(j)=(j-0.5)*(1./ny)-0.5
if ((ncly.eq.1).or.(ncly.eq.2)) yetai(j)=(j-0.5)*(1./(ny-1.))-0.5
endif
if (istret==3) then
if (ncly.eq.0) yetai(j)=(j-0.5)*(1./2./ny)-0.5
if ((ncly.eq.1).or.(ncly.eq.2)) yetai(j)=(j-0.5)*(1./2./(ny-1.))-0.5
endif
den1=sqrt(alpha*beta+1.)
xnum=den1/sqrt(alpha/pi)/sqrt(beta)/sqrt(pi)
den=2.*sqrt(alpha/pi)*sqrt(beta)*pi*sqrt(pi)
den3=((sin(pi*yetai(j)))*(sin(pi*yetai(j)))/beta/pi)+alpha/pi
den4=2.*alpha*beta-cos(2.*pi*yetai(j))+1.
xnum1=(atan(xnum*tan(pi*yetai(j))))*den4/den1/den3/den
cst=sqrt(beta)*pi/(2.*sqrt(alpha)*sqrt(alpha*beta+1.))
if (istret==1) then
if (yetai(j).lt.0.5) ypi(j)=xnum1-cst-yinf
if (yetai(j).eq.0.5) ypi(j)=0.-yinf
if (yetai(j).gt.0.5) ypi(j)=xnum1+cst-yinf
endif
if (istret==2) then
if (yetai(j).lt.0.5) ypi(j)=xnum1-cst+yly
if (yetai(j).eq.0.5) ypi(j)=0.+yly
if (yetai(j).gt.0.5) ypi(j)=xnum1+cst+yly
endif
if (istret==3) then
if (yetai(j).lt.0.5) ypi(j)=(xnum1-cst+yly)*2.
if (yetai(j).eq.0.5) ypi(j)=(0.+yly)*2.
if (yetai(j).gt.0.5) ypi(j)=(xnum1+cst+yly)*2.
endif
enddo
endif
if (alpha.eq.0.) then
ypi(1)=-1.e10
do j=2,ny
yetai(j)=(j-1.)*(1./ny)
ypi(j)=-beta*cos(pi*yetai(j))/sin(yetai(j)*pi)
enddo
endif
do j=1,ny
ppy(j)=yly*(alpha/pi+(1./pi/beta)*sin(pi*yeta(j))* &
sin(pi*yeta(j)))
pp2y(j)=ppy(j)*ppy(j)
pp4y(j)=(-2./beta*cos(pi*yeta(j))*sin(pi*yeta(j)))
enddo
do j=1,ny
ppyi(j)=yly*(alpha/pi+(1./pi/beta)*sin(pi*yetai(j))* &
sin(pi*yetai(j)))
pp2yi(j)=ppyi(j)*ppyi(j)
pp4yi(j)=(-2./beta*cos(pi*yetai(j))*sin(pi*yetai(j)))
enddo
if (nrank==0) then
open(10,file='yp.dat', form='formatted')
do j=1,ny
write(10,*)yp(j)
enddo
close(10)
endif
end subroutine stretching
!*****************************************************************
!
subroutine inversion5_v1(aaa,eee,spI)
!
!*****************************************************************
USE decomp_2d
USE decomp_2d_poisson
USE variables
USE param
USE var
USE MPI
implicit none
! decomposition object for spectral space
TYPE(DECOMP_INFO) :: spI
#ifdef DOUBLE_PREC
real(mytype), parameter :: epsilon = 1.e-16
#else
real(mytype), parameter :: epsilon = 1.e-8
#endif
complex(mytype),dimension(spI%yst(1):spI%yen(1),ny/2,spI%yst(3):spI%yen(3),5) :: aaa
complex(mytype),dimension(spI%yst(1):spI%yen(1),spI%yst(2):spI%yen(2),spI%yst(3):spI%yen(3)) :: eee
integer :: i,j,k,m,mi,jc
integer,dimension(2) :: ja,jb
complex(mytype),dimension(spI%yst(1):spI%yen(1),spI%yst(3):spI%yen(3)) :: sr
complex(mytype),dimension(spI%yst(1):spI%yen(1),spI%yst(3):spI%yen(3)) :: a1,b1
real(mytype) :: tmp1,tmp2,tmp3,tmp4
do i=1,2
ja(i)=4-i
jb(i)=5-i
enddo
do m=1,ny/2-2
do i=1,2
mi=m+i
do k=spI%yst(3),spI%yen(3)
do j=spI%yst(1),spI%yen(1)
if (real(aaa(j,m,k,3), kind=mytype).ne.0.) tmp1=real(aaa(j,mi,k,3-i), kind=mytype)/real(aaa(j,m,k,3), kind=mytype)
if (aimag(aaa(j,m,k,3)).ne.0.)tmp2=aimag(aaa(j,mi,k,3-i))/aimag(aaa(j,m,k,3))
sr(j,k)=cmplx(tmp1,tmp2, kind=mytype)
eee(j,mi,k)=cmplx(real(eee(j,mi,k), kind=mytype)-tmp1*real(eee(j,m,k), kind=mytype),&
aimag(eee(j,mi,k))-tmp2*aimag(eee(j,m,k)), kind=mytype)
enddo
enddo
do jc=ja(i),jb(i)
do k=spI%yst(3),spI%yen(3)
do j=spI%yst(1),spI%yen(1)
aaa(j,mi,k,jc)=cmplx(real(aaa(j,mi,k,jc), kind=mytype)-real(sr(j,k), kind=mytype)*real(aaa(j,m,k,jc+i), kind=mytype),&
aimag(aaa(j,mi,k,jc))-aimag(sr(j,k))*aimag(aaa(j,m,k,jc+i)), kind=mytype)
enddo
enddo
enddo
enddo
enddo
do k=spI%yst(3),spI%yen(3)
do j=spI%yst(1),spI%yen(1)
if (abs(real(aaa(j,ny/2-1,k,3), kind=mytype)).gt.epsilon) then
tmp1=real(aaa(j,ny/2,k,2), kind=mytype)/real(aaa(j,ny/2-1,k,3), kind=mytype)
else
tmp1=0.
endif
if (abs(aimag(aaa(j,ny/2-1,k,3))).gt.epsilon) then
tmp2=aimag(aaa(j,ny/2,k,2))/aimag(aaa(j,ny/2-1,k,3))
else
tmp2=0.
endif
sr(j,k)=cmplx(tmp1,tmp2, kind=mytype)
b1(j,k)=cmplx(real(aaa(j,ny/2,k,3), kind=mytype)-tmp1*real(aaa(j,ny/2-1,k,4), kind=mytype),&
aimag(aaa(j,ny/2,k,3))-tmp2*aimag(aaa(j,ny/2-1,k,4)), kind=mytype)
if (abs(real(b1(j,k), kind=mytype)).gt.epsilon) then
tmp1=real(sr(j,k), kind=mytype)/real(b1(j,k), kind=mytype)
tmp3=real(eee(j,ny/2,k), kind=mytype)/real(b1(j,k), kind=mytype)-tmp1*real(eee(j,ny/2-1,k), kind=mytype)
else
tmp1=0.
tmp3=0.
endif
if (abs(aimag(b1(j,k))).gt.epsilon) then
tmp2=aimag(sr(j,k))/aimag(b1(j,k))
tmp4=aimag(eee(j,ny/2,k))/aimag(b1(j,k))-tmp2*aimag(eee(j,ny/2-1,k))
else
tmp2=0.
tmp4=0.
endif
a1(j,k)=cmplx(tmp1,tmp2, kind=mytype)
eee(j,ny/2,k)=cmplx(tmp3,tmp4, kind=mytype)
if (abs(real(aaa(j,ny/2-1,k,3), kind=mytype)).gt.epsilon) then
tmp1=1./real(aaa(j,ny/2-1,k,3), kind=mytype)
else
tmp1=0.
endif
if (abs(aimag(aaa(j,ny/2-1,k,3))).gt.epsilon) then
tmp2=1./aimag(aaa(j,ny/2-1,k,3))
else
tmp2=0.
endif
b1(j,k)=cmplx(tmp1,tmp2, kind=mytype)
a1(j,k)=cmplx(real(aaa(j,ny/2-1,k,4), kind=mytype)*real(b1(j,k), kind=mytype),&
aimag(aaa(j,ny/2-1,k,4))*aimag(b1(j,k)), kind=mytype)
eee(j,ny/2-1,k)=cmplx(real(eee(j,ny/2-1,k))*real(b1(j,k))-real(a1(j,k))*real(eee(j,ny/2,k)),&
aimag(eee(j,ny/2-1,k))*aimag(b1(j,k))-aimag(a1(j,k))*aimag(eee(j,ny/2,k)), kind=mytype)
enddo
enddo
do i=ny/2-2,1,-1
do k=spI%yst(3),spI%yen(3)
do j=spI%yst(1),spI%yen(1)
if (abs(real(aaa(j,i,k,3), kind=mytype)).gt.epsilon) then
tmp1=1./real(aaa(j,i,k,3), kind=mytype)
else
tmp1=0.
endif
if (abs(aimag(aaa(j,i,k,3))).gt.epsilon) then
tmp2=1./aimag(aaa(j,i,k,3))
else
tmp2=0.
endif
sr(j,k)=cmplx(tmp1,tmp2, kind=mytype)
a1(j,k)=cmplx(real(aaa(j,i,k,4), kind=mytype)*real(sr(j,k), kind=mytype),&
aimag(aaa(j,i,k,4))*aimag(sr(j,k)), kind=mytype)
b1(j,k)=cmplx(real(aaa(j,i,k,5), kind=mytype)*real(sr(j,k), kind=mytype),&
aimag(aaa(j,i,k,5))*aimag(sr(j,k)), kind=mytype)
eee(j,i,k)=cmplx(real(eee(j,i,k), kind=mytype)*real(sr(j,k), kind=mytype)-&
real(a1(j,k), kind=mytype)*real(eee(j,i+1,k), kind=mytype)-&
real(b1(j,k), kind=mytype)*real(eee(j,i+2,k), kind=mytype),&
aimag(eee(j,i,k))*aimag(sr(j,k))-&
aimag(a1(j,k))*aimag(eee(j,i+1,k))-aimag(b1(j,k))*aimag(eee(j,i+2,k)), kind=mytype)
enddo
enddo
enddo
return
end subroutine inversion5_v1
!*****************************************************************
!
subroutine inversion5_v2(aaa,eee,spI)
!
!*****************************************************************
USE decomp_2d
USE decomp_2d_poisson
USE variables
USE param
USE var
USE MPI
implicit none
! decomposition object for spectral space
TYPE(DECOMP_INFO) :: spI
#ifdef DOUBLE_PREC
real(mytype), parameter :: epsilon = 1.e-16
#else
real(mytype), parameter :: epsilon = 1.e-8
#endif
complex(mytype),dimension(spI%yst(1):spI%yen(1),nym,spI%yst(3):spI%yen(3),5) :: aaa
complex(mytype),dimension(spI%yst(1):spI%yen(1),nym,spI%yst(3):spI%yen(3)) :: eee
integer :: i,j,k,m,mi,jc
integer,dimension(2) :: ja,jb
complex(mytype),dimension(spI%yst(1):spI%yen(1),spI%yst(3):spI%yen(3)) :: sr
complex(mytype),dimension(spI%yst(1):spI%yen(1),spI%yst(3):spI%yen(3)) :: a1,b1
real(mytype) :: tmp1,tmp2,tmp3,tmp4
do i=1,2
ja(i)=4-i
jb(i)=5-i
enddo
do m=1,nym-2
do i=1,2
mi=m+i
do k=spI%yst(3),spI%yen(3)
do j=spI%yst(1),spI%yen(1)
if (real(aaa(j,m,k,3), kind=mytype).ne.0.) tmp1=real(aaa(j,mi,k,3-i), kind=mytype)/real(aaa(j,m,k,3), kind=mytype)
if (aimag(aaa(j,m,k,3)).ne.0.)tmp2=aimag(aaa(j,mi,k,3-i))/aimag(aaa(j,m,k,3))
sr(j,k)=cmplx(tmp1,tmp2, kind=mytype)
eee(j,mi,k)=cmplx(real(eee(j,mi,k), kind=mytype)-tmp1*real(eee(j,m,k), kind=mytype),&
aimag(eee(j,mi,k))-tmp2*aimag(eee(j,m,k)), kind=mytype)
enddo
enddo
do jc=ja(i),jb(i)
do k=spI%yst(3),spI%yen(3)
do j=spI%yst(1),spI%yen(1)
aaa(j,mi,k,jc)=cmplx(real(aaa(j,mi,k,jc), kind=mytype)-real(sr(j,k), kind=mytype)*real(aaa(j,m,k,jc+i), kind=mytype),&
aimag(aaa(j,mi,k,jc))-aimag(sr(j,k))*aimag(aaa(j,m,k,jc+i)), kind=mytype)
enddo
enddo
enddo
enddo
enddo
do k=spI%yst(3),spI%yen(3)
do j=spI%yst(1),spI%yen(1)
if (abs(real(aaa(j,nym-1,k,3), kind=mytype)).gt.epsilon) then
tmp1=real(aaa(j,nym,k,2), kind=mytype)/real(aaa(j,nym-1,k,3), kind=mytype)
else
tmp1=0.