00001 subroutine newtonSet
00002
00003 use global
00004
00005 use model
00006
00007 use krylov
00008
00009 use demonaParameters
00010
00011 implicit none
00012
00013 real(8),allocatable :: deltax(:),F0(:),resVec(:),setF0(:)
00014
00015 real(8) normF,normFrms
00016
00017 integer newtonIter
00018
00019
00020 real(8) newtonTolerance
00021
00022 real(8) inexactLinearTolerance
00023
00024 integer linearIterations
00025
00026 integer i
00027
00028
00029
00030 integer indSize
00031 integer ptrSize
00032 integer valSize,valSizeMax
00033
00034 real(8), allocatable :: JacVal(:),luval(:)
00035 integer, allocatable :: JacColInd(:),JacRowPtr(:),iw(:),uptr(:)
00036
00037 integer numberofcolors
00038
00039
00040
00041
00042
00043
00044
00045
00046 newtonTolerance=1e-5
00047 inexactLinearTolerance=1e-5
00048
00049
00050 newtonSuccess=0
00051
00052 Open (2,File='newtonResidual.dat',Status='unknown')
00053
00054
00055
00056
00057
00058
00059
00060 allocate(F0(globalcurrentsetlength))
00061
00062 allocate(setF0(globalcurrentsetlength))
00063
00064
00065
00066
00067
00068 F0=discrete(0)
00069 setF0=discrete(0)
00070
00071
00072
00073
00074
00075
00076 normF=dsqrt(dot_product(F0,F0))
00077
00078 print*,'initial norm:',normF
00079
00080 write(2,'(F20.12,1X)')normF
00081
00082
00083 if (normF.le.newtonTolerance) then
00084
00085 print*,'zero initial norm'
00086 print*,'newton return'
00087 newtonSuccess=1
00088
00089 return
00090
00091
00092 end if
00093
00094
00095 call symbolic(valsizeMax)
00096 ptrSize=globalcurrentsetlength+1
00097
00098
00099 totalLinearIterations=0
00100
00101
00102
00103 tempy=y
00104
00105
00106
00107
00108
00109 do newtonIter=1,maxNewtonIter
00110
00111
00112 if (allocated(deltax)) deallocate(deltax)
00113 if (allocated(resVec)) deallocate(resVec)
00114
00115 allocate(deltax(globalcurrentsetlength))
00116 allocate(resVec(globalcurrentsetlength))
00117
00118
00119 deltax=0.d0
00120 resVec=0.d0
00121
00122
00123 print*,'newton iter and dof=',newtonIter,globalcurrentsetlength
00124
00125
00126
00127 inexactLinearTolerance=newtonTolerance
00128 inexactLinearTolerance=1e-1*normF
00129
00130 deltax=0.d0
00131
00132
00133
00134 if (allocated(JacVal)) deallocate(JacVal)
00135 if (allocated(JacColInd)) deallocate(JacColInd)
00136 if (allocated(uptr)) deallocate(uptr)
00137 if (allocated(JacRowPtr)) deallocate(JacRowPtr)
00138
00139
00140
00141 allocate(JacVal(valSizeMax),JacColInd(valSizeMax),JacRowPtr(ptrSize),uptr(globalcurrentsetlength))
00142
00143
00144 JacVal=0.d0
00145 JacColInd=0
00146 uptr=0
00147 JacRowPtr=0
00148
00149 tempy=y
00150
00151 call colorJacobianCRS(JacVal,JacColInd,JacRowPtr,globalcurrentsetlength,1,valSize,indSize,uptr,0,numberOfColors)
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 call basicilu0CRS(jacval(1:valsize),JacColInd(1:valsize),JacRowPtr,globalcurrentsetlength,valSize,uptr)
00164
00165
00166
00167
00168
00169 JacVal(1:valsize)=JacVal(1:valsize)+epsilon(0.d0)
00170 JacVal(1:valsize)=JacVal(1:valsize)-epsilon(0.d0)
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185 call gmres(-F0,deltax,200,20,inexactLinearTolerance,resVec,JacVal(1:valsize),jaccolInd(1:valsize),jacrowPtr,uptr,valsize,LinearIterations,2)
00186
00187 tempy(setVec)=tempy(setVec)+deltax
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203 F0=discrete(1)
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214 normF=dsqrt(dot_product(F0,F0))
00215
00216 normFrms=normF/dsqrt(size(F0)*1.d0)
00217 print*,'norm=',normF
00218 print*,'rms norm=',normFrms
00219
00220
00221 totalLinearIterations=totalLinearIterations+LinearIterations
00222
00223
00224 y=tempy
00225 write(2,'(F20.12,1X)')normF
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235 if (normF.le.newtonTolerance) then
00236
00237
00238
00239 print*,'newton converged at iter',newtonIter
00240 print*,'residual:',normF
00241 print*,'total linear iterations:',totalLinearIterations
00242
00243
00244
00245
00246
00247
00248
00249
00250 exit
00251
00252
00253 end if
00254
00255
00256
00257
00258
00259
00260 if (newtonIter.eq.7) then
00261
00262
00263
00264
00265
00266
00267
00268
00269 end if
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 if ((resSet.eqv.yes).and.(newtonIter.gt.0)) then
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293 call setRule(F0,size(F0),normF,normFrms)
00294
00295 call currentSet
00296
00297
00298
00299
00300
00301 deallocate(deltax,resvec)
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334 end if
00335
00336
00337
00338
00339
00340
00341
00342
00343 end do
00344
00345 close(2)
00346
00347
00348
00349
00350
00351
00352
00353 910 FORMAT((E18.10))
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363 end subroutine newtonSet