00001 #include "cppdefs.h"
00002 #ifdef SOLVE3D
00003 c--# define TEST_WEIGHTS
00004
00005
00006 subroutine set_weights
00007 implicit none
00008 # include "param.h"
00009 # include "scalars.h"
00010 integer i,j, iter
00011 # ifdef M2FILTER_POWER
00012 real p,q,r, scale
00013 # else
00014 real arg
00015 # endif
00016 # ifdef TEST_WEIGHTS
00017 real zeta(4), DUon, Zt_avg1, DU_avg2, cff1,cff2,cff3
00018 # endif
00019 real*QUAD sum, shft, cff
00020
00021 # ifdef AGRIF
00022 # include "zoom.h"
00023 real t1,t2,t3,t4,t11,t12
00024 real cff10,cff1m
00025 # endif
00026
00027 nfast=0
00028 do i=1,2*ndtfast
00029 weight(1,i)=0.
00030 weight(2,i)=0.
00031 enddo
00032
00033 # ifdef M2FILTER_POWER
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 p=2.0
00049 q=4.0
00050 r=0.25
00051
00052 scale=(p+1.)*(p+q+1.)/((p+2.)*(p+q+2.)*float(ndtfast))
00053 do iter=1,16
00054 nfast=0
00055 do i=1,2*ndtfast
00056 cff=scale*float(i)
00057 weight(1,i)=cff**p - cff**(p+q) - r*cff
00058 if (i.gt.ndtfast .and. weight(1,i).lt.0.) then
00059 weight(1,i)=0.
00060 else
00061 nfast=i
00062 endif
00063 enddo
00064 sum=0.
00065 shft=0.
00066 do i=1,nfast
00067 sum=sum+weight(1,i)
00068 shft=shft+weight(1,i)*float(i)
00069 enddo
00070 scale=scale * shft/(sum*float(ndtfast))
00071 c** write(*,*) shft/sum, ndtfast
00072 enddo
00073 # elif defined M2FILTER_FLAT
00074 cff=1./float(ndtfast)
00075 do i=1,2*ndtfast
00076 arg=cff*float(i-ndtfast)
00077 if (2.*abs(arg) .lt. 1.) then
00078 weight(1,i)=1.
00079 nfast=i
00080 endif
00081 enddo
00082
00083 # elif defined M2FILTER_COSINE
00084 cff=pi/float(ndtfast)
00085 do i=1,2*ndtfast
00086 arg=cff*float(i-ndtfast)
00087 if (2.*abs(arg) .lt. pi) then
00088 weight(1,i)=(cos(arg))**2
00089 nfast=i
00090 endif
00091 enddo
00092 # else
00093 cff=pi/float(ndtfast)
00094 do i=1,2*ndtfast
00095 arg=cff*float(i-ndtfast)
00096 if (2.*abs(arg) .lt. pi) then
00097
00098 weight(1,i)=(cos(arg))**2
00099 nfast=i
00100 endif
00101 enddo
00102 # endif
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 do iter=1,ndtfast
00115 sum=0.
00116 shft=0.
00117 do i=1,nfast
00118 sum=sum+weight(1,i)
00119 shft=shft+float(i)*weight(1,i)
00120 enddo
00121 shft=shft/sum
00122 cff=float(ndtfast)-shft
00123 # ifdef TEST_WEIGHTS
00124 MPI_master_only write(*,'(A,2I4,2F22.18)')
00125 & 'centering weights:', iter, ndtfast, shft, cff
00126 # endif
00127 if (cff .gt. 1.) then
00128 nfast=nfast+1
00129 do i=nfast,2,-1
00130 weight(1,i)=weight(1,i-1)
00131 enddo
00132 weight(1,1)=0.
00133 elseif (cff .gt. 0.) then
00134 sum=1.-cff
00135 do i=nfast,2,-1
00136 weight(1,i)=sum*weight(1,i)+cff*weight(1,i-1)
00137 enddo
00138 weight(1,1)=sum*weight(1,1)
00139 elseif (cff .lt. -1.) then
00140 nfast=nfast-1
00141 do i=1,nfast,+1
00142 weight(1,i)=weight(1,i+1)
00143 enddo
00144 weight(1,nfast+1)=0.
00145 elseif (cff .lt. 0.) then
00146 sum=1.+cff
00147 do i=1,nfast-1,+1
00148 weight(1,i)=sum*weight(1,i)-cff*weight(1,i+1)
00149 enddo
00150 weight(1,nfast)=sum*weight(1,nfast)
00151 endif
00152 enddo
00153
00154 do j=1,nfast
00155 cff=weight(1,j)
00156 do i=1,j
00157 weight(2,i)=weight(2,i)+cff
00158 enddo
00159 enddo
00160 sum=0.
00161 cff=0.
00162 do i=1,nfast
00163 sum=sum+weight(1,i)
00164 cff=cff+weight(2,i)
00165 enddo
00166 sum=1./sum
00167 cff=1./cff
00168 do i=1,nfast
00169 weight(1,i)=sum*weight(1,i)
00170 weight(2,i)=cff*weight(2,i)
00171 enddo
00172
00173 # ifdef AGRIF
00174
00175 weight2 = 0.
00176
00177 weight2(nfast,:) = weight(1,:)
00178
00179
00180 do j=nfast-1,1,-1
00181
00182 cff10 = weight2(j+1,0)
00183 cff1m = weight2(j+1,j+1)
00184
00185 t1 = (1+cff10*(-1.+(j+1)))*ndtfast
00186 & +(-1+cff10)*nfast
00187 t2 = (cff10-cff1m)*(j+1)*ndtfast-
00188 & (-1.+cff10)*(-1.+cff1m+cff1m*(j+1))*nfast
00189
00190 t3 = t1/t2
00191
00192 t4 = (1.-t3*(1-cff1m))/(1.-cff10)
00193
00194 do i=0,j
00195 weight2(j,i) = t3*weight2(j+1,i)+t4*weight2(j+1,i+1)
00196 enddo
00197
00198 weight2(j,j+1:) = 0.
00199
00200 enddo
00201
00202 # endif
00203
00204
00205 # ifdef TEST_WEIGHTS
00206 MPI_master_only write(*,'(/1x,A,I3,4x,A,I3/4x,A,2(12x,A))')
00207 & 'Time Splitting weights: ndtfast =', ndtfast,
00208 & 'nfast =', nfast, 'primary', 'secondary',
00209 & 'accumulated-to-current-step'
00210 cff=0.
00211 cff1=0.
00212 cff2=0.
00213 cff3=0.
00214 sum=0.
00215 shft=0.
00216 do i=1,nfast
00217 cff=cff + weight(1,i)
00218 cff1=cff1 + weight(1,i)*float(i)
00219 cff2=cff2 + weight(1,i)*float(i*i)
00220 cff3=cff3 + weight(1,i)*float(i*i*i)
00221 sum=sum+weight(2,i)
00222 shft=shft + float(i)*weight(2,i)
00223 MPI_master_only write(*,'(I3,4F19.16)')
00224 & i, weight(1,i), weight(2,i), cff, sum
00225 enddo
00226 cff1=cff1/float(ndtfast)
00227 cff2=cff2/float(ndtfast*ndtfast)
00228 cff3=cff3/float(ndtfast*ndtfast*ndtfast)
00229 shft=(shft-0.5)/float(ndtfast)
00230
00231 MPI_master_only write(*,'(3(/A,2F14.10),F14.10/A,2I4,F8.4)')
00232 & ' Checking integrals (must be 1, 1)', cff, sum,
00233 & ' centroid (must be 1, ~0.5)', cff1, shft,
00234 & ' second and third moments (>~1, ~1)', cff2, cff3,
00235 & cff3-(3*cff2-2.),
00236 & ' ndtfast, nfast, nfast/ndtfast ',
00237 & ndtfast, nfast, float(nfast)/float(ndtfast)
00238
00239 if (cff2 .lt. 1.001) then
00240 MPI_master_only write(*,'(/1x,A/)')
00241 & 'WARNING: unstable weights, reduce parameter "r".'
00242 endif
00243
00244 MPI_master_only write(*,'(/A/A,1x,A,15x,A,7x,A/)')
00245 & 'Checking consistency of primary and secondary weights...',
00246 & 'step', 'zeta_avr1', 'dt*divVBAR_avr2',
00247 & 'zeta_avr1-dt*divVBAR_avr2'
00248
00249 do j=1,nfast
00250 next_kstp=1
00251 zeta(1)=0.
00252 zeta(2)=0.
00253 do iif=1,nfast
00254
00255
00256 if (iif.eq.j) then
00257 DUon=1.
00258 else
00259 DUon=0.
00260 endif
00261
00262 # undef FORW_BAK
00263 # ifdef FORW_BAK
00264
00265 kstp=knew
00266 knew=kstp+1
00267 if (knew.gt.4) knew=1
00268 call step2d_FB_imitator (zeta, DUon, Zt_avg1, DU_avg2)
00269
00270 # else
00271 kstp=next_kstp
00272 knew=3
00273 call step2d_imitator (zeta, DUon, Zt_avg1, DU_avg2)
00274
00275 knew=3-kstp
00276 next_kstp=knew
00277 call step2d_imitator (zeta, DUon, Zt_avg1, DU_avg2)
00278 # endif
00279 enddo
00280 write(*,'(I4,2F24.18,F24.20)') j, Zt_avg1, dt*DU_avg2,
00281 & Zt_avg1-dt*DU_avg2
00282 enddo
00283 stop
00284
00285 iif=1
00286 kstp=1
00287 knew=1
00288 return
00289 end
00290
00291
00292 subroutine step2d_FB_imitator (zeta, DUon, Zt_avg1, DU_avg2)
00293 implicit none
00294 real zeta(4), DUon, Zt_avg1, DU_avg2, zeta_new, cff1,cff2
00295 # include "param.h"
00296 # include "scalars.h"
00297
00298 zeta(knew)=zeta(kstp) + dtfast*DUon
00299
00300 cff1=weight(1,iif)
00301 cff2=weight(2,iif)
00302 if (FIRST_2D_STEP) then
00303 Zt_avg1=cff1*zeta(knew)
00304 DU_avg2=cff2*DUon
00305 else
00306 Zt_avg1=Zt_avg1+cff1*zeta(knew)
00307 DU_avg2=DU_avg2+cff2*DUon
00308 endif
00309
00310 return
00311 end
00312
00313
00314 subroutine step2d_imitator (zeta, DUon, Zt_avg1, DU_avg2)
00315 implicit none
00316 real zeta(3), DUon, Zt_avg1, DU_avg2, zeta_new
00317 # include "param.h"
00318 # include "scalars.h"
00319
00320 if (knew.eq.3) then
00321 krhs=kstp
00322 PREDICTOR_2D_STEP=.true.
00323 else
00324 krhs=3
00325 PREDICTOR_2D_STEP=.false.
00326 endif
00327
00328
00329
00330
00331
00332
00333
00334 if (PREDICTOR_2D_STEP) then
00335 if (FIRST_2D_STEP) then
00336 Zt_avg1=0.
00337 DU_avg2=0.
00338 else
00339 Zt_avg1=Zt_avg1 + weight(1,iif-1)*zeta(krhs)
00340 endif
00341 else
00342 DU_avg2=DU_avg2 + weight(2,iif)*DUon
00343 endif
00344
00345
00346
00347
00348
00349 if (PREDICTOR_2D_STEP) then
00350
00351 else
00352 zeta(knew)=zeta(kstp) + dtfast*DUon
00353 endif
00354
00355
00356
00357 if (iif.eq.nfast .and. .not.PREDICTOR_2D_STEP) then
00358 Zt_avg1=Zt_avg1 + weight(1,iif)*zeta(knew)
00359 endif
00360
00361 # else
00362 MPI_master_only write(*,'(/1x,A,I3,4x,A,I3/)')
00363 & 'Time splitting: ndtfast =', ndtfast, 'nfast =', nfast
00364
00365 # endif /* TEST_WEIGHTS */
00366 return
00367 end
00368
00369 #else
00370 subroutine set_weights_empty
00371 end
00372 #endif /* SOLVE3D */
00373