00001 module mf
00002
00003
00004 use global
00005
00006 use model
00007
00008
00009 contains
00010
00011
00012
00013 function matVec(v)
00014
00015 implicit none
00016
00017 real(8) v(:)
00018
00019 real(8) matVec(size(v))
00020
00021 real(8) myEps
00022
00023
00024 matVec=0.d0
00025
00026 if (dot_product(v,v).le.epsilon(0.d0)) return
00027
00028
00029
00030 myEps=dsqrt(epsilon(0.d0))
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 tempy=y
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 myEps=epsValue(tempy(setVec),v)
00051
00052
00053
00054
00055
00056
00057
00058 tempy(setVec)=tempy(setVec)+myeps*v
00059
00060
00061
00062 matVec= ( discrete(1) - discrete(0) ) /myEps
00063
00064
00065 tempy(setVec)=y(setVec)
00066 tempy=y
00067
00068
00069
00070
00071
00072 end function matVec
00073
00074
00075
00076 function epsValue(x,v) result(eps)
00077 implicit none
00078
00079 integer i,n
00080
00081 real(8) x(:),v(:)
00082
00083 real(8),allocatable :: typVec(:)
00084
00085 real(8) eps,myeps1,myeps2
00086
00087 real(8) normX,normV
00088
00089 real(8) typSize
00090
00091 real(8) dotXv
00092
00093 real(8) sum
00094
00095 real(8) sigma
00096
00097 integer myCase
00098
00099 real(8) myValue
00100
00101
00102 myCase=2
00103
00104
00105 n=size(v)
00106
00107
00108
00109 myeps1=dsqrt(epsilon(0.d0))
00110
00111 myeps2=epsilon(0.0)
00112
00113 sigma=1e-14
00114
00115
00116
00117
00118
00119
00120
00121 normX=dsqrt(dot_product(X,X))
00122
00123 normV=dsqrt(dot_product(v,v))
00124
00125
00126
00127
00128
00129 dotXv=dot_product(X,v)
00130
00131
00132 select case(myCase)
00133
00134
00135 case (1)
00136
00137
00138
00139 myValue=0.000001d0
00140
00141
00142
00143
00144
00145 allocate(typVec(n))
00146
00147 call typicalSize(X,n,typSize)
00148
00149 typVec=typSize
00150
00151
00152
00153 eps=myValue*max(dabs(dotXv),dot_product(typVec,dabs(v)))/normV
00154
00155
00156
00157
00158
00159
00160 eps=dabs(eps)
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 case(2)
00175
00176 allocate(typVec(n))
00177
00178 call typicalSize(X,n,typSize)
00179
00180 typVec=typSize
00181
00182
00183
00184 eps=myeps1*max(dabs(dotXv),dot_product(typVec,dabs(v)))/normV
00185
00186
00187
00188 eps=dabs(eps)
00189
00190 if (isnan(eps)) then
00191
00192 print*,'isNan'
00193 stop
00194 print*,normV,dotXv,normX,dot_product(typVec,dabs(v)),eps
00195 print*,v
00196 stop
00197
00198 end if
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216 case(3)
00217
00218 eps=myeps1
00219
00220
00221 case(4)
00222
00223 eps=myeps2
00224
00225 case(5)
00226
00227 eps=dsqrt(sigma)/normV
00228
00229 case(6)
00230
00231 eps=dsqrt(sigma)*normX/normV
00232
00233
00234 case(7)
00235
00236 sum=0.d0
00237
00238 do i=1,n
00239
00240 sum=X(i)+sum
00241
00242 end do
00243
00244 sum=sum/(n*1.d0)
00245
00246 sum=sum+1.d0
00247
00248 eps=dsqrt(sigma)*sum
00249
00250
00251 case(8)
00252
00253
00254 end select
00255
00256
00257
00258
00259
00260 end function epsValue
00261
00262
00263
00264 subroutine typicalSize(X,n,typSize)
00265 implicit none
00266 integer n
00267 real(8) X(n)
00268 real(8) minTyp
00269 real(8) maxTyp
00270 real(8) typSize
00271
00272 typSize=0.d0
00273
00274
00275 if (minval(dabs(X)).eq.0.d0) then
00276 minTyp=0.d0
00277 else
00278 minTyp=dlog10(minval(dabs(X)))
00279 end if
00280
00281 if (maxval(dabs(X)).eq.0.d0) then
00282 maxTyp=0.d0
00283 else
00284 maxTyp=dlog10(maxval(dabs(X)))
00285 end if
00286
00287
00288
00289
00290
00291
00292 typSize=10.d0**((minTyp+maxTyp)*0.5d0)
00293 typSize=dabs(typSize)
00294
00295 end subroutine typicalSize
00296
00297
00298
00299 subroutine colorJacobianCRS(val,col_ind,row_ptr,dof,symbolic,valSize,indSize,diagVecInd,returnNumberOfColors,numberOfColors)
00300
00301 implicit none
00302
00303 integer dof
00304
00305 real(8):: myF(dof)
00306
00307 real(8) val(:)
00308
00309 integer col_ind(:),row_ptr(:)
00310
00311 integer symbolic,valSize,indSize,ptrSize
00312
00313 integer colorVector(dof,3)
00314 real(8):: eps
00315 real(8), allocatable :: Fcolors(:,:)
00316 integer:: i, j, k, z
00317
00318 integer unk
00319
00320 integer stencil
00321 integer numberOfColors
00322 integer,allocatable :: colors(:)
00323
00324 integer diagonalColor
00325 integer aa
00326
00327
00328
00329 integer,pointer :: direction_stencil(:)
00330 integer,allocatable :: newcolors(:)
00331
00332
00333
00334
00335 integer minvalue,minindex,mymod,column
00336
00337
00338
00339 integer crsColSum,TotalcrsColSum
00340
00341 real(8),allocatable :: crsColVal(:)
00342 integer,allocatable :: crsColInd(:),sortedCrsColInd(:)
00343 integer startIndex,endIndex
00344 integer nonZeroIndex
00345 integer, allocatable :: nonZeroVec(:)
00346
00347 integer diagVecInd(dof),diagVecIndDesignator,diagVecIndVal
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 integer, pointer :: myDofmatrix(:,:,:,:)
00358
00359 integer diagI,diagJ
00360
00361 integer dofOfmyDofmatrix
00362
00363 real(8) myEps
00364
00365
00366
00367
00368 integer,pointer :: nx,ny
00369
00370 integer myP,myD
00371
00372 integer,pointer :: localSetVec(:)
00373
00374 integer myZ
00375
00376 integer colorCorrector
00377
00378 integer returnNumberOfColors
00379
00380 integer zDof
00381
00382 integer,pointer :: minI,minJ,maxI,maxJ
00383
00384 eps=dsqrt(epsilon(0.d0))
00385
00386
00387
00388
00389
00390 stencil=5
00391
00392
00393
00394 diagVecIndDesignator=0
00395 diagVecIndVal=0
00396
00397
00398
00399
00400
00401
00402
00403
00404 colorVector=0
00405
00406 pVec=>myModel%pVec
00407
00408 endIndex=0
00409 colorFunctionIndex=0
00410 colorValMax=0
00411
00412 do myP=1,size(pVec)
00413
00414 currentPhysics=pVec(myP)
00415
00416
00417
00418 dVec=>myModel%physics(currentPhysics)%dVec
00419
00420 do myD=1,size(dVec)
00421
00422 currentDomain=dVec(myD)
00423
00424
00425
00426 myModel%physics(currentPhysics)%domain(currentDomain)%colorMin=colorValMax+1
00427
00428 nx=>myModel%physics(currentPhysics)%domain(currentDomain)%nx
00429 ny=>myModel%physics(currentPhysics)%domain(currentDomain)%ny
00430
00431 minI=>myModel%physics(currentPhysics)%domain(currentDomain)%minI
00432 maxI=>myModel%physics(currentPhysics)%domain(currentDomain)%maxI
00433 minJ=>myModel%physics(currentPhysics)%domain(currentDomain)%minJ
00434 maxJ=>myModel%physics(currentPhysics)%domain(currentDomain)%maxJ
00435
00436 localSetVec=>myModel%physics(currentPhysics)%domain(currentDomain)%setVec
00437
00438
00439 unk=myModel%physics(currentPhysics)%domain(currentDomain)%setDof
00440
00441 startIndex=endIndex+1
00442
00443 endIndex=endIndex+size(localSetVec)
00444
00445
00446
00447
00448
00449
00450
00451 myModel%physics(currentPhysics)%domain(currentDomain)%colorStartIndex=startIndex
00452 myModel%physics(currentPhysics)%domain(currentDomain)%colorEndIndex=endIndex
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463 colorVector(startIndex:endIndex,:)=ColoringFunction(maxI-minI+1,maxJ-minJ+1,stencil,size(localSetVec),unk)
00464
00465
00466 tempy=y
00467
00468 colorFunctionIndex=endIndex
00469
00470 colorValMax=maxVal(colorVector(:,1))
00471
00472 myModel%physics(currentPhysics)%domain(currentDomain)%colorMax=colorValMax
00473
00474 end do
00475
00476 end do
00477
00478
00479
00480 numberOfColors=colorValMax
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 if (returnNumberOfColors.eq.1) return
00493
00494
00495
00496
00497
00498
00499 allocate(crsColVal(numberOfColors),crsColInd(numberOfColors))
00500 crsColVal=0.d0
00501 crsColInd=0
00502 TotalcrsColSum=0
00503
00504
00505
00506
00507
00508
00509
00510 allocate(Fcolors(dof,numberOfColors),colors(stencil))
00511 Fcolors=0.d0
00512
00513
00514
00515
00516 do i=1,stencil
00517 colors(i)=i
00518 end do
00519
00520
00521
00522
00523 Fcolors=ColoringEvaluation(colorVector,numberOfColors,dof);
00524
00525
00526
00527 tempy=y
00528 myF=discrete(1)
00529
00530 tempy=y
00531
00532 if (test.eq.1) then
00533
00534
00535
00536
00537 end if
00538
00539
00540
00541 allocate(direction_stencil(stencil),newcolors(stencil))
00542
00543
00544 direction_stencil=0
00545 newcolors=0
00546
00547
00548 do myP=1,size(pVec)
00549
00550 currentPhysics=pVec(myP)
00551
00552
00553
00554
00555
00556 dVec=>myModel%physics(currentPhysics)%dVec
00557
00558 do myD=1,size(dVec)
00559
00560 currentDomain=dVec(myD)
00561
00562
00563
00564
00565
00566
00567 myDofmatrix=>myModel%physics(currentPhysics)%domain(currentDomain)%dofMatrix
00568
00569 startIndex=myModel%physics(currentPhysics)%domain(currentDomain)%colorStartIndex
00570
00571 endIndex=myModel%physics(currentPhysics)%domain(currentDomain)%colorEndIndex
00572
00573 colorMin=>myModel%physics(currentPhysics)%domain(currentDomain)%colorMin
00574
00575 colorMax=>myModel%physics(currentPhysics)%domain(currentDomain)%colorMax
00576
00577
00578
00579
00580
00581
00582
00583 do i=startIndex,endIndex
00584
00585
00586
00587
00588 diagonalColor=colorVector(i,1);
00589
00590
00591
00592
00593 diagI=colorVector(i,2)
00594 diagJ=colorVector(i,3)
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610 crsColVal=0.d0
00611 crsColInd=0
00612 crsColSum=1
00613
00614
00615
00616
00617 newcolors(1:stencil)=cshift(colors(1:stencil),(diagonalColor-1));
00618
00619 colorCorrector=colorMin-1
00620
00621
00622
00623 do z=colorMin,colorMax
00624
00625
00626
00627
00628
00629 if (dabs(Fcolors(i,z)-myF(i)) .le. epsilon(0.d0)) then
00630 cycle
00631 end if
00632
00633
00634 zDof=(colorMax-colorMin+1)/stencil
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656
00657
00658
00659
00660
00661
00662
00663
00664
00665 myZ=mod(z,stencil)
00666
00667 if(myZ.eq.0) myZ=stencil
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684 minvalue=minval(iabs(newcolors-myZ))
00685
00686
00687
00688
00689 minindex=minloc(iabs(newcolors-myZ),dim=1)
00690
00691
00692
00693
00694 minindex=minIndex-colorCorrector
00695
00696 minindex=minindex+stencil*(z-myZ)/stencil
00697
00698
00699 mymod=mod(minindex,stencil)
00700
00701
00702
00703
00704
00705
00706
00707
00708
00709 dofOfmyDofmatrix=((minindex-mymod)/stencil+min(mymod,1))
00710
00711
00712
00713
00714 select case (mymod)
00715
00716 case(1)
00717
00718 column=myDofmatrix(diagI,diagJ,dofOfmyDofmatrix,relative)
00719
00720 case(2)
00721
00722 column=myDofmatrix(diagI+1,diagJ,dofOfmyDofmatrix,relative)
00723
00724 case(3)
00725
00726 column=myDofmatrix(diagI,diagJ+1,dofOfmyDofmatrix,relative)
00727
00728 case(4)
00729
00730 column=myDofmatrix(diagI,diagJ-1,dofOfmyDofmatrix,relative)
00731
00732 case(0)
00733
00734 column=myDofmatrix(diagI-1,diagJ,dofOfmyDofmatrix,relative)
00735
00736
00737 end select
00738
00739
00740
00741 if (column.eq.0) then
00742
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752 end if
00753
00754
00755
00756
00757 crsColVal(crsColSum)=(Fcolors(i,z)-myF(i))/eps
00758
00759 crsColInd(crsColSum)=column
00760
00761
00762
00763 if (i.eq.column) then
00764
00765 diagVecIndDesignator=crsColSum
00766
00767
00768
00769
00770
00771 end if
00772
00773
00774
00775
00776 crsColSum=crsColSum+1
00777
00778
00779
00780
00781 end do
00782
00783
00784 nonZeroIndex=0
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799 nonZeroIndex=crsColSum-1
00800
00801
00802 allocate(nonZeroVec(nonZeroIndex),sortedCrsColInd(nonZeroIndex))
00803 nonZeroVec=0
00804 sortedCrsColInd=0
00805
00806 nonZeroVec(1:nonZeroIndex)=crsColInd(1:nonZeroIndex)
00807
00808
00809
00810
00811 call qsortd(nonZeroVec,sortedCrsColInd,nonZeroIndex)
00812
00813
00814 startIndex=TotalcrsColSum+1
00815
00816 TotalcrsColSum=crsColSum-1+TotalcrsColSum
00817
00818
00819
00820
00821
00822
00823
00824 endIndex=TotalcrsColSum
00825
00826
00827 diagVecIndDesignator=minloc(abs(sortedCrsColInd-diagVecIndDesignator),dim=1)
00828
00829
00830
00831
00832
00833 diagVecIndVal=diagVecIndDesignator+startIndex-1
00834
00835
00836
00837
00838 diagVecInd(i)=diagVecIndVal
00839
00840
00841
00842
00843
00844
00845
00846
00847 do z=1,nonZeroIndex
00848
00849 if ((startIndex+z-1).gt.size(val)) then
00850
00851 print*,'woink'
00852 print*,startIndex+z-1,i,z,size(val)
00853 stop
00854
00855 end if
00856
00857
00858
00859 val(startIndex+z-1)=crsColVal(sortedCrsColInd(z))
00860 col_ind(startIndex+z-1)=crsColInd(sortedCrsColInd(z))
00861
00862
00863
00864 end do
00865
00866
00867
00868 row_ptr(i)=startIndex
00869
00870
00871
00872 deallocate(nonZeroVec,sortedCrsColInd)
00873
00874
00875
00876 end do
00877
00878 end do
00879
00880
00881 end do
00882
00883
00884
00885
00886
00887 row_ptr(dof+1)=TotalcrsColSum+1
00888
00889
00890
00891 if (symbolic.eq.1) then
00892
00893 valSize=TotalcrsColSum
00894 indSize=TotalcrsColSum
00895
00896 end if
00897
00898
00899
00900
00901
00902
00903
00904 end subroutine colorJacobianCRS
00905
00906
00907
00908
00909
00910
00911
00912
00913
00914 function ColoringFunction(nx,ny,stencil,dof,unk)
00915 implicit none
00916
00917 integer nx,ny,unk,stencil,dof
00918
00919 integer ColoringFunction(dof,3)
00920
00921 integer AA(Ny,Nx),Hcolors(stencil),Vcolors(stencil)
00922
00923 integer i,j,k,t,Vindex,Hindex,row,myColor,index
00924
00925 integer iStart,iEnd
00926 integer jStart,jEnd
00927
00928
00929 integer,pointer :: myDofMatrix(:,:,:,:)
00930
00931 integer myGhostCells
00932
00933 integer,pointer :: dofVec(:)
00934
00935 integer myT
00936
00937 ColoringFunction=0
00938
00939
00940
00941 AA=0
00942
00943
00944
00945
00946
00947
00948
00949 do i=1,stencil
00950 Hcolors(i)=i
00951 end do
00952
00953
00954 select case(stencil)
00955
00956 case(5)
00957
00958
00959
00960
00961
00962
00963
00964
00965
00966
00967
00968
00969
00970 Vcolors(1)=1
00971 Vcolors(2)=3
00972 Vcolors(3)=5
00973 Vcolors(4)=2
00974 Vcolors(5)=4
00975
00976 do i=1,Ny
00977
00978 if (mod(i,stencil).eq.0) then
00979 Vindex=stencil
00980 else
00981 Vindex=mod(i,stencil)
00982 end if
00983
00984 row=Ny-i+1
00985
00986 myColor=Vcolors(Vindex)
00987
00988 AA(row,1)=myColor
00989
00990 AA(row,1)=AA(row,1)+colorValMax
00991
00992 do j=2,Nx
00993
00994 Hindex=myColor-1+j;
00995
00996 if (mod(Hindex,stencil).eq.0) then
00997 Hindex=stencil
00998 else
00999 Hindex=mod(Hindex,stencil)
01000 end if
01001
01002 AA(row,j)=Hcolors(Hindex)+colorValMax
01003
01004 end do
01005
01006 end do
01007
01008 case default
01009 print*,'!-----------------------------------------------'
01010 print*,'no coloring for this stencil is defined!!!!!'
01011 stop
01012 end select
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040
01041
01042
01043
01044
01045 if (dFX.ne.dFV) then
01046
01047
01048 istart=1
01049 jStart=1
01050
01051 iEnd=Nx
01052 jend=Ny
01053
01054 myGhostCells=0
01055
01056
01057 else
01058
01059
01060
01061
01062 istart=1-ghostCells
01063 jstart=1-ghostCells
01064
01065 iend=Nx-ghostCells
01066 jend=Ny-ghostCells
01067
01068
01069 myGhostCells=ghostCells
01070
01071
01072
01073
01074 end if
01075
01076
01077 myDofmatrix=>myModel%physics(currentPhysics)%domain(currentDomain)%dofmatrix
01078
01079 dofVec=>myModel%physics(currentPhysics)%domain(currentDomain)%dofVec
01080
01081 setDof=>myModel%physics(currentPhysics)%domain(currentDomain)%setDof
01082
01083 do j=jStart,jEnd
01084
01085 do i=iStart,iEnd
01086
01087 do myT=1,setDof
01088
01089 t=dofVec(myT)
01090
01091 if (myDofmatrix(i,j,t,relative).ne.0 ) then
01092
01093 ColoringFunction(myDofmatrix(i,j,t,relative)-colorFunctionIndex,1)=AA(Ny-myGhostCells+1-j,i+myGhostCells)+(t-1)*stencil
01094
01095 ColoringFunction(myDofmatrix(i,j,t,relative)-colorFunctionIndex,2)=i
01096 ColoringFunction(myDofmatrix(i,j,t,relative)-colorFunctionIndex,3)=j
01097
01098 end if
01099
01100 end do
01101
01102 end do
01103
01104 end do
01105
01106
01107
01108
01109
01110
01111 end function ColoringFunction
01112
01113
01114
01115 function ColoringEvaluation(colorVector,numberOfColors,dof);
01116 implicit none
01117
01118 integer i,j,index
01119
01120 integer nx,ny,unk,stencil,dof,numberOfColors
01121
01122 integer colorVector(dof)
01123
01124 real(8) eps
01125
01126 real(8) ColoringEvaluation(dof,numberOfColors)
01127
01128 real(8) myEps
01129
01130 real(8) typSize,myX(1)
01131
01132 ColoringEvaluation=0.d0
01133
01134
01135
01136 eps=epsilon(0.0)
01137 eps=dsqrt(epsilon(0.d0))
01138
01139
01140
01141
01142
01143
01144 do i=1,numberOfColors
01145 ColoringEvaluation(:,i)=tempy(setVec)
01146 end do
01147
01148
01149
01150
01151
01152
01153
01154
01155
01156
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178 do i=1,dof
01179
01180 index=colorVector(i);
01181
01182
01183
01184 ColoringEvaluation(i,index)= ColoringEvaluation(i,index)+eps;
01185
01186
01187
01188
01189 end do
01190
01191
01192
01193
01194
01195
01196 do i=1,numberOfColors
01197
01198 tempy(setVec)=ColoringEvaluation(:,i)
01199
01200 ColoringEvaluation(:,i)=discrete(1)
01201
01202 tempy=y
01203
01204
01205 end do
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217 end function ColoringEvaluation
01218
01219
01220
01221
01222 function crsMatVecMult(val,col_ind,row_ptr,vec)
01223
01224 implicit none
01225
01226 real(8) val(:),vec(:)
01227
01228 integer col_ind(:),row_ptr(:)
01229
01230 real(8) crsMatVecMult(size(Vec))
01231
01232 integer i,j
01233
01234 crsMatVecMult=0.d0
01235
01236 do i=1,size(Vec)
01237
01238
01239
01240 do j=row_ptr(i),row_ptr(i+1)-1
01241
01242
01243
01244 crsMatVecMult(i)=crsMatVecMult(i)+val(j)*vec(col_ind(j))
01245
01246 end do
01247
01248 end do
01249
01250
01251
01252 end function crsMatVecMult
01253
01254
01255
01256 function LUyX(val,col_ind,row_ptr,dof,diag_ptr,valSize,Vec)
01257
01258 implicit none
01259
01260 integer i,j
01261
01262 integer dof,valsize
01263
01264 real(8) Vec(dof),pivots(dof),z(dof)
01265
01266 real(8) val(valSize)
01267
01268 real(8) LUyX(dof)
01269
01270 integer col_ind(valSize),diag_ptr(dof),row_ptr(dof+1)
01271
01272 real(8) sum
01273
01274 LUyX=0.d0
01275
01276 z=0.d0
01277
01278 do i=1,dof
01279
01280 pivots(i)=val(diag_ptr(i))
01281 pivots(i)=1.d0/pivots(i)
01282
01283 end do
01284
01285
01286
01287
01288
01289 do i=1,dof
01290
01291 sum=0.d0
01292
01293 do j=row_ptr(i),diag_ptr(i)-1
01294
01295
01296 sum=sum+val(j)*z(col_ind(j))
01297
01298 end do
01299
01300
01301 z(i)=vec(i)-sum
01302
01303
01304 end do
01305
01306
01307
01308
01309
01310
01311
01312 do i=dof,1,-1
01313
01314 sum=0.d0
01315
01316 do j=diag_ptr(i)+1,row_ptr(i+1)-1
01317
01318 sum=sum+val(j)*LUyX(col_ind(j))
01319
01320 end do
01321
01322
01323 LUyX(i)=(z(i) - sum)*pivots(i)
01324
01325
01326 end do
01327
01328
01329
01330
01331 end function LUyX
01332
01333
01334
01335 function giveDirections(value)
01336 implicit none
01337 character giveDirections
01338 integer value
01339
01340 select case(value)
01341
01342 case(1)
01343
01344 givedirections='C'
01345
01346 case(2)
01347
01348 givedirections='E'
01349
01350 case(3)
01351
01352 givedirections='N'
01353
01354 case(4)
01355
01356 givedirections='S'
01357
01358 case(0)
01359
01360 givedirections='W'
01361
01362 end select
01363
01364 end function
01365
01366
01367
01368
01369
01370
01371
01372
01373
01374
01375
01376
01377
01378
01379 SUBROUTINE qsortd(x,ind,n)
01380
01381
01382
01383
01384 IMPLICIT NONE
01385 INTEGER, PARAMETER :: dp = SELECTED_REAL_KIND(12, 60)
01386 INTEGER, INTENT(IN) :: n
01387
01388
01389
01390
01391 integer, INTENT(IN) :: x(n)
01392 INTEGER, INTENT(OUT) :: ind(n)
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430
01431
01432 INTEGER :: iu(21), il(21)
01433 INTEGER :: m, i, j, k, l, ij, it, itt, indx
01434 REAL :: r
01435 REAL (dp) :: t
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446
01447
01448
01449
01450 IF (n <= 0) RETURN
01451
01452
01453
01454
01455
01456 DO i = 1, n
01457
01458 ind(i) = i
01459 END DO
01460
01461
01462 m = 1
01463 i = 1
01464 j = n
01465 r = .375
01466
01467
01468
01469 20 IF (i >= j) GO TO 70
01470 IF (r <= .5898437) THEN
01471 r = r + .0390625
01472 ELSE
01473 r = r - .21875
01474 END IF
01475
01476
01477
01478 30 k = i
01479
01480
01481
01482 ij = i + r*(j-i)
01483 it = ind(ij)
01484 t = x(it)
01485
01486
01487
01488
01489 indx = ind(i)
01490 IF (x(indx) > t) THEN
01491 ind(ij) = indx
01492 ind(i) = it
01493 it = indx
01494 t = x(it)
01495 END IF
01496
01497
01498
01499 l = j
01500
01501
01502
01503
01504 indx = ind(j)
01505 IF (x(indx) >= t) GO TO 50
01506 ind(ij) = indx
01507 ind(j) = it
01508 it = indx
01509 t = x(it)
01510
01511
01512
01513
01514 indx = ind(i)
01515 IF (x(indx) <= t) GO TO 50
01516 ind(ij) = indx
01517 ind(i) = it
01518 it = indx
01519 t = x(it)
01520 GO TO 50
01521
01522
01523
01524 40 itt = ind(l)
01525 ind(l) = ind(k)
01526 ind(k) = itt
01527
01528
01529
01530
01531 50 l = l - 1
01532 indx = ind(l)
01533 IF (x(indx) > t) GO TO 50
01534
01535
01536
01537 60 k = k + 1
01538 indx = ind(k)
01539 IF (x(indx) < t) GO TO 60
01540
01541
01542
01543 IF (k <= l) GO TO 40
01544
01545
01546
01547
01548 IF (l-i > j-k) THEN
01549 il(m) = i
01550 iu(m) = l
01551 i = k
01552 m = m + 1
01553 GO TO 80
01554 END IF
01555
01556 il(m) = k
01557 iu(m) = j
01558 j = l
01559 m = m + 1
01560 GO TO 80
01561
01562
01563
01564 70 m = m - 1
01565 IF (m == 0) RETURN
01566 i = il(m)
01567 j = iu(m)
01568
01569 80 IF (j-i >= 11) GO TO 30
01570 IF (i == 1) GO TO 20
01571 i = i - 1
01572
01573
01574
01575 90 i = i + 1
01576 IF (i == j) GO TO 70
01577 indx = ind(i+1)
01578 t = x(indx)
01579 it = indx
01580 indx = ind(i)
01581 IF (x(indx) <= t) GO TO 90
01582 k = i
01583
01584 100 ind(k+1) = ind(k)
01585 k = k - 1
01586 indx = ind(k)
01587 IF (t < x(indx)) GO TO 100
01588
01589 ind(k+1) = it
01590 GO TO 90
01591 END SUBROUTINE qsortd
01592
01593
01594
01595
01596
01597
01598
01599
01600
01601
01602
01603
01604
01605
01606
01607 end module mf