00001 subroutine newton
00002
00003 use global
00004
00005 use model
00006
00007 use krylov
00008
00009 use demonaParameters
00010
00011 use DFPORT
00012
00013 implicit none
00014
00015 real(8),allocatable :: deltax(:),F0(:),resVec(:)
00016
00017 real(8) normF
00018
00019 integer newtonIter
00020
00021
00022 real(8) newtonTolerance
00023
00024 real(8) inexactLinearTolerance
00025
00026 integer linearIterations
00027
00028 real(8) newtonConvergenceTolerance
00029
00030
00031
00032
00033
00034 real(8) eta
00035
00036
00037
00038
00039 integer myJacInterval
00040
00041
00042
00043
00044 integer indSize
00045 integer ptrSize
00046 integer valSize,valSizeMax
00047
00048 real(8), allocatable :: JacVal(:),luval(:)
00049 integer, allocatable :: JacColInd(:),JacRowPtr(:),iw(:),uptr(:)
00050
00051
00052 integer numberOfColors
00053
00054
00055
00056 real(8) lambda
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 myJacInterval=jacInterval
00067
00068 if (freezedJacobian.eqv.on) then
00069
00070
00071 myJacInterval=maxNewtonIter
00072
00073 if (gsSolver.eqv.no) print*,'freezed jacobian'
00074
00075 end if
00076
00077
00078
00079 newtonTolerance=1e-5
00080 inexactLinearTolerance=1e-5
00081
00082
00083 eta=1e-2
00084
00085
00086
00087
00088
00089
00090
00091 allocate(deltax(globalcurrentsetlength))
00092 allocate(F0(globalcurrentsetlength))
00093 allocate(resVec(globalcurrentsetlength))
00094
00095 deltax=0.d0
00096
00097
00098
00099
00100 F0=discrete(0)
00101
00102 totalLinearIterations=0
00103
00104
00105
00106
00107
00108
00109
00110 normF=dsqrt(dot_product(F0,F0))
00111
00112
00113
00114 newtonConvergenceTolerance=newtonTolerance
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130 if (gsSolver.eqv.no) print*,'initial norm:',normF
00131
00132
00133 if (normF.eq.0.d0) then
00134
00135 if (gsSolver.eqv.no) print*,'zero initial norm'
00136 if (gsSolver.eqv.no) print*,'newton return'
00137 return
00138
00139
00140 end if
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150 call symbolic(valsizeMax)
00151 ptrSize=globalcurrentsetlength+1
00152
00153
00154
00155 do newtonIter=1,maxNewtonIter
00156
00157
00158 if (mod(newtonIter+myJacInterval-1,myJacInterval).eq.0) then
00159
00160 if (normF.le.JacSkipTol*newtonConvergenceTolerance) then
00161
00162 if(jacSkip.eqv.on) then
00163 print*,'almost the same jacobian probably'
00164 print*,'its evaluation is skipped.'
00165 goto 1
00166 end if
00167
00168 end if
00169
00170
00171 if (allocated(JacVal)) deallocate(JacVal)
00172 if (allocated(JacColInd)) deallocate(JacColInd)
00173 if (allocated(uptr)) deallocate(uptr)
00174 if (allocated(JacRowPtr)) deallocate(JacRowPtr)
00175
00176
00177
00178 allocate(JacVal(valSizeMax),JacColInd(valSizeMax),JacRowPtr(ptrSize),uptr(globalcurrentsetlength))
00179
00180
00181 JacVal=0.d0
00182 JacColInd=0
00183 uptr=0
00184 JacRowPtr=0
00185
00186 tempy=y
00187
00188 call colorJacobianCRS(JacVal,JacColInd,JacRowPtr,globalcurrentsetlength,1,valSize,indSize,uptr,0,numberOfColors)
00189
00190 tempy=y
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 call basicilu0CRS(jacval,JacColInd(1:valsize),JacRowPtr,globalcurrentsetlength,valSize,uptr)
00201
00202
00203
00204
00205
00206 end if
00207
00208 1 continue
00209
00210
00211 if (gsSolver.eqv.no) print*,'newton iter=',newtonIter
00212
00213 inexactLinearTolerance=1e-5
00214
00215 if (inexactNewton.eqv.On) inexactLinearTolerance=eta*normF
00216
00217 deltax=0.d0
00218
00219
00220 call gmres(-F0,deltax,500,20,inexactLinearTolerance,resVec,JacVal(1:valsize),jaccolInd(1:valsize),jacrowPtr,uptr,valsize,LinearIterations,2)
00221
00222
00223 lambda=1.d0
00224
00225
00226 tempy(setVec)=tempy(setVec)+lambda*deltax
00227
00228
00229 F0=discrete(1)
00230
00231 normF=dsqrt(dot_product(F0,F0))
00232
00233 totalLinearIterations=totalLinearIterations+LinearIterations
00234
00235 if (gsSolver.eqv.no) print*,normF
00236
00237 if (normF.le.newtonConvergenceTolerance) then
00238
00239
00240 if (gsSolver.eqv.no) print*,'newton converged at iter',newtonIter
00241 if (gsSolver.eqv.no) print*,'residual:',normF
00242 if (gsSolver.eqv.no) print*,'total linear iterations:',totalLinearIterations
00243
00244 y=tempy
00245
00246 exit
00247
00248
00249 end if
00250
00251
00252
00253
00254 y=tempy
00255
00256
00257 if (resSet.eqv.yes) then
00258
00259 call setRule
00260
00261 call set
00262
00263
00264 end if
00265
00266
00267 end do
00268
00269
00270
00271 end subroutine newton