[1] | 1 | |
---|
| 2 | /*************************************************************************** |
---|
| 3 | module classe solsor_dynspg_flt.h - description |
---|
| 4 | ***************************************************************************/ |
---|
| 5 | // Mohamed Berrada |
---|
| 6 | // locean-ipsl.upmc, Paris, April 23, 2009 |
---|
| 7 | //=========================================================================== |
---|
| 8 | // methode forward |
---|
| 9 | forward () |
---|
| 10 | { |
---|
| 11 | if(Yt==TU) |
---|
| 12 | return; |
---|
| 13 | else{ |
---|
[38] | 14 | if(Yi==0 && Yj==0){ |
---|
[1] | 15 | int t,jn,jj,ji, icount = 0,ncut=0,niter=0,ishift; |
---|
| 16 | niter=0;ncut=0; |
---|
| 17 | if(Yt==TU+1 && neuler==0) |
---|
| 18 | t=0; |
---|
| 19 | else |
---|
| 20 | t=1; |
---|
| 21 | //--------------------- |
---|
| 22 | //initialisation de gcx |
---|
| 23 | for(jj=0;jj<NY;jj++) |
---|
| 24 | for(ji=0;ji<NX;ji++){ |
---|
| 25 | // gcxb(ji,jj)=gcx(ji,jj); |
---|
| 26 | gcx(ji,jj)=YS_gcx_dynspg_flt(0,ji,jj,Yt); |
---|
| 27 | } |
---|
| 28 | //if(Yt==6) printf("------------------gcx(ji,jj,0,t) =%lf\n",gcx(28,2) ); |
---|
| 29 | //--------------------- |
---|
| 30 | //boundarie conditions -- ceci doit etre a l'interieur de loop nmax mais cas special |
---|
| 31 | for(jj=0;jj<NY;jj++){// ! East-West boundaries |
---|
| 32 | gcx(0,jj)=0.;gcx(NX-1,jj)=0.; |
---|
| 33 | } |
---|
| 34 | for(ji=0;ji<NX;ji++){// ! North-South boundaries |
---|
| 35 | gcx(ji,0)=0.;gcx(ji,NY-1)=0.; |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | double ztmp,zres,zres2,res=0.; |
---|
| 39 | //--------------------- |
---|
| 40 | //boucle |
---|
| 41 | //xsolmat_init(); |
---|
| 42 | for(jn=1;jn<=nmax;jn++){ |
---|
| 43 | // cas special ! applied the lateral boundary conditions |
---|
| 44 | // CALL lbc_lnk_e( gcx, c_solver_pt, 1. ) ; //c_solver_pt='T' |
---|
| 45 | // ! Residus |
---|
| 46 | // ! Guess black update |
---|
| 47 | |
---|
| 48 | for(jj=1;jj<NY-1;jj++){ |
---|
| 49 | ishift = jj%2; |
---|
| 50 | for(ji=1+ishift;ji<NX-1;ji+=2){ |
---|
| 51 | ztmp = YS_gcb_dynspg_flt(0,ji,jj,Yt) |
---|
| 52 | - gcp(ji,jj,0,t) * gcx(ji ,jj-1) |
---|
| 53 | - gcp(ji,jj,1,t) * gcx(ji-1,jj ) |
---|
| 54 | - gcp(ji,jj,2,t) * gcx(ji+1,jj ) |
---|
| 55 | - gcp(ji,jj,3,t) * gcx(ji ,jj+1); |
---|
| 56 | // ! Estimate of the residual |
---|
| 57 | zres = ztmp - gcx(ji,jj); |
---|
| 58 | gcr(ji,jj) = zres * gcdmat(ji,jj,t) * zres; |
---|
| 59 | // ! Guess update |
---|
| 60 | gcx(ji,jj) = sor * ztmp + (1.-sor) * gcx(ji,jj); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | icount = icount + 1; |
---|
| 64 | |
---|
| 65 | //cas special ! applied the lateral boundary conditions |
---|
| 66 | // CALL lbc_lnk_e( gcx, c_solver_pt, 1. ) ; |
---|
| 67 | |
---|
| 68 | // ! Guess red update |
---|
| 69 | for(jj=1;jj<NY-1;jj++){ |
---|
| 70 | ishift = (jj-1)%2; |
---|
| 71 | for(ji=1+ishift;ji<NX-1;ji+=2){ |
---|
| 72 | ztmp = YS_gcb_dynspg_flt(0,ji,jj,Yt) |
---|
| 73 | - gcp(ji,jj,0,t) * gcx(ji ,jj-1) |
---|
| 74 | - gcp(ji,jj,1,t) * gcx(ji-1,jj ) |
---|
| 75 | - gcp(ji,jj,2,t) * gcx(ji+1,jj ) |
---|
| 76 | - gcp(ji,jj,3,t) * gcx(ji ,jj+1); |
---|
| 77 | // ! Estimate of the residual |
---|
| 78 | zres = ztmp - gcx(ji,jj); |
---|
| 79 | gcr(ji,jj) = zres * gcdmat(ji,jj,t) * zres; |
---|
| 80 | // ! Guess update |
---|
| 81 | gcx(ji,jj) = sor * ztmp + (1.-sor) * gcx(ji,jj); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | // if(jn>=nmax-1) xtest("gcx__",gcx(28,3),28,3,0,Yt); |
---|
| 85 | icount = icount + 1; |
---|
| 86 | // ! test of convergence |
---|
| 87 | if( jn > nmin && (jn-nmin)%nmod == 0 ) { |
---|
| 88 | zres2=0.; |
---|
| 89 | for(jj=1;jj<NY-1;jj++) |
---|
| 90 | for(ji=1;ji<NX-1;ji++) |
---|
| 91 | if(zres2<gcr(ji,jj)) zres2=gcr(ji,jj); |
---|
| 92 | // zres2 = MAXVAL( gcr(2:nlci-1,2:nlcj-1) ); |
---|
| 93 | // ! test of convergence |
---|
| 94 | if( zres2 < resmax || jn == nmax ){ |
---|
| 95 | res = sqrt( zres2 ); |
---|
| 96 | niter = jn; tniter[Yt]=jn; |
---|
| 97 | ncut = 999; |
---|
| 98 | // printf("FOR=======tniter(%d)=%d\n",Yt,tniter[Yt]); |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | // if(jn>=nmax-1) xtest("gcx____",gcx(28,3),28,3,0,Yt); |
---|
| 102 | |
---|
| 103 | // ! indicator of non-convergence or explosion |
---|
| 104 | // IF( jn == nmax .OR. SQRT(epsr)/eps > 1.e+20 ) kindic = -2 |
---|
| 105 | if( ncut == 999 ) break; |
---|
| 106 | } |
---|
| 107 | // cout<<"niter="<<niter<<endl; |
---|
| 108 | // printf("res=%24.16e\n",res); |
---|
| 109 | // CALL lbc_lnk_e( gcx, c_solver_pt, 1. );// ! boundary conditions |
---|
| 110 | /* FILE* fp; |
---|
| 111 | fp=fopen("testh.pof","w"); |
---|
| 112 | for(int i=0;i<NX;i++) |
---|
| 113 | for(int j=0;j<NY;j++){ |
---|
| 114 | fprintf(fp,"%4d %4d %4d %24.16e\n",Yt+1,i,j,gcr(i,j)); |
---|
| 115 | } |
---|
| 116 | fclose(fp);*/ |
---|
| 117 | /* xtest("gcx",gcx(28,3),28,3,0,Yt); |
---|
| 118 | xtest("gcb",YS_gcb_dynspg_flt(0,28,3,Yt),28,3,0,Yt); */ |
---|
| 119 | } |
---|
| 120 | } |
---|
| 121 | // |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | //=========================================================================== |
---|
| 125 | // methode backward |
---|
| 126 | |
---|
| 127 | backward () |
---|
| 128 | { |
---|
| 129 | |
---|
| 130 | if(Ycurward==BACKWARD){ |
---|
| 131 | if(Yt==TU) |
---|
| 132 | return; |
---|
| 133 | else{ |
---|
[38] | 134 | if(Yi==0 && Yj==0){ |
---|
[1] | 135 | double G_ztmp; |
---|
| 136 | int t,jn,jj,ji, ishift,istart; |
---|
| 137 | if(Yt==TU+1 && neuler==0) |
---|
| 138 | t=0; |
---|
| 139 | else |
---|
| 140 | t=1; |
---|
| 141 | //--------------------- |
---|
| 142 | for(ji=0;ji<NX;ji++){ |
---|
| 143 | for(jj=0;jj<NY;jj++){ |
---|
| 144 | YG_gcx_dynspg_flt(0,ji,jj,Yt)=0.; |
---|
| 145 | YG_gcb_dynspg_flt(0,ji,jj,Yt)=0.; |
---|
| 146 | } |
---|
| 147 | } |
---|
| 148 | for(jj=0;jj<NY;jj++){ |
---|
| 149 | G_gcx(0,jj)=0.;G_gcx(NX-1,jj)=0.; |
---|
| 150 | G_gcx0(0,jj)=0.;G_gcx0(NX-1,jj)=0.; |
---|
| 151 | } |
---|
| 152 | for(ji=0;ji<NX;ji++){ |
---|
| 153 | G_gcx(ji,0)=0.;G_gcx(ji,NY-1)=0.; |
---|
| 154 | G_gcx0(ji,0)=0.;G_gcx0(ji,NY-1)=0.; |
---|
| 155 | } |
---|
| 156 | |
---|
| 157 | for(ji=1;ji<NX-1;ji++) |
---|
| 158 | for(jj=1;jj<NY-1;jj++){ |
---|
| 159 | // YG_gcx2(0,ji,jj,Yt)=Ytb_gcx(ji,jj); |
---|
| 160 | G_gcx(ji,jj)=YG_gcx2(0,ji,jj,Yt); |
---|
| 161 | G_gcx0(ji,jj)=0.; |
---|
| 162 | } |
---|
| 163 | |
---|
| 164 | for(jn=tniter[Yt];jn>=1;jn--){ |
---|
| 165 | // printf("BACK1=======YG_gcx_dynspg_flt(%d)=%23.16e\n",Yt,G_gcx(9,9)); |
---|
| 166 | // printf("BACK2=======YG_gcb_dynspg_flt(%d)=%23.16e\n",Yt,YG_gcb_dynspg_flt(0,9,9,Yt)); |
---|
| 167 | |
---|
| 168 | // BACK ! Guess red update |
---|
| 169 | for(jj=NY-2;jj>=1;jj--){ |
---|
| 170 | ishift = (jj-1)%2; |
---|
| 171 | istart=NX-2-(ishift-1)%2*(NX%2-1)%2-ishift*NX%2; |
---|
| 172 | for(ji=istart;ji>=1;ji-=2){ |
---|
| 173 | G_ztmp=G_gcx(ji,jj)*sor; |
---|
| 174 | G_gcx0(ji,jj)=G_gcx(ji,jj)*(1.-sor); |
---|
| 175 | YG_gcb_dynspg_flt(0,ji,jj,Yt)+=G_ztmp; |
---|
| 176 | G_gcx0(ji ,jj-1)+=- G_ztmp*gcp(ji,jj,0,t) ; |
---|
| 177 | G_gcx0(ji-1,jj )+=- G_ztmp*gcp(ji,jj,1,t) ; |
---|
| 178 | G_gcx0(ji+1,jj )+=- G_ztmp*gcp(ji,jj,2,t) ; |
---|
| 179 | G_gcx0(ji ,jj+1)+=- G_ztmp*gcp(ji,jj,3,t) ; |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | // BACK ! Guess black update |
---|
| 184 | |
---|
| 185 | for(jj=NY-2;jj>=1;jj--){ |
---|
| 186 | ishift = jj%2; |
---|
| 187 | istart=NX-2-(ishift-1)%2*(NX%2-1)%2-ishift*NX%2; |
---|
| 188 | for(ji=istart;ji>=1;ji-=2){ |
---|
| 189 | G_ztmp=(G_gcx(ji,jj)+G_gcx0(ji,jj))*sor; |
---|
| 190 | G_gcx0(ji,jj)=(G_gcx(ji,jj)+G_gcx0(ji,jj))*(1.-sor); |
---|
| 191 | YG_gcb_dynspg_flt(0,ji,jj,Yt)+=G_ztmp; |
---|
| 192 | G_gcx0(ji ,jj-1)+=- G_ztmp*gcp(ji,jj,0,t) ; |
---|
| 193 | G_gcx0(ji-1,jj )+=- G_ztmp*gcp(ji,jj,1,t) ; |
---|
| 194 | G_gcx0(ji+1,jj )+=- G_ztmp*gcp(ji,jj,2,t) ; |
---|
| 195 | G_gcx0(ji ,jj+1)+=-G_ztmp* gcp(ji,jj,3,t) ; |
---|
| 196 | } |
---|
| 197 | } |
---|
| 198 | for(jj=0;jj<NY;jj++) |
---|
| 199 | for(ji=0;ji<NX;ji++){ |
---|
| 200 | G_gcx(ji,jj)=G_gcx0(ji,jj); |
---|
| 201 | G_gcx0(ji,jj)=0.; |
---|
| 202 | } |
---|
| 203 | for(jj=0;jj<NY;jj++){ |
---|
| 204 | G_gcx0(0,jj)=0.;G_gcx0(NX-1,jj)=0.; |
---|
| 205 | } |
---|
| 206 | for(ji=0;ji<NX;ji++){ |
---|
| 207 | G_gcx0(ji,0)=0.;G_gcx0(ji,NY-1)=0.; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | |
---|
| 211 | } |
---|
| 212 | for(jj=1;jj<NY-1;jj++) |
---|
| 213 | for(ji=1;ji<NX-1;ji++){ |
---|
| 214 | YG_gcx_dynspg_flt(0,ji,jj,Yt)+=G_gcx(ji,jj); |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | |
---|
| 218 | |
---|
| 219 | } |
---|
| 220 | } |
---|
| 221 | |
---|
| 222 | } |
---|
| 223 | else if(Ycurward==LINWARD){ |
---|
| 224 | if(Yt==TU) |
---|
| 225 | return; |
---|
| 226 | else{ |
---|
| 227 | if(Yi==0){ |
---|
| 228 | int t,jn,jj,ji, ishift; |
---|
| 229 | if(Yt==TU+1 && neuler==0) |
---|
| 230 | t=0; |
---|
| 231 | else |
---|
| 232 | t=1; |
---|
| 233 | //--------------------- |
---|
| 234 | //initialisation de gcx |
---|
| 235 | for(jj=0;jj<NY;jj++) |
---|
| 236 | for(ji=0;ji<NX;ji++){ |
---|
| 237 | Ytb_gcx(ji,jj)=YG_gcx_dynspg_flt(0,ji,jj,Yt); |
---|
| 238 | } |
---|
| 239 | //--------------------- |
---|
| 240 | //boundarie conditions -- ceci doit etre a l'interieur de loop nmax mais cas special |
---|
| 241 | for(jj=0;jj<NY;jj++){// ! East-West boundaries |
---|
| 242 | Ytb_gcx(0,jj)=0.;Ytb_gcx(NX-1,jj)=0.; |
---|
| 243 | } |
---|
| 244 | for(ji=0;ji<NX;ji++){// ! North-South boundaries |
---|
| 245 | Ytb_gcx(ji,0)=0.;Ytb_gcx(ji,NY-1)=0.; |
---|
| 246 | } |
---|
| 247 | |
---|
| 248 | double Ytb_ztmp; |
---|
| 249 | //--------------------- |
---|
| 250 | //boucle |
---|
| 251 | //xsolmat_init(); |
---|
| 252 | // printf("LIN=======tniter(%d)=%d\n",Yt,tniter[Yt]); |
---|
| 253 | for(jn=1;jn<=tniter[Yt];jn++){ |
---|
| 254 | // cas special ! applied the lateral boundary conditions |
---|
| 255 | // CALL lbc_lnk_e( gcx, c_solver_pt, 1. ) ; //c_solver_pt='T' |
---|
| 256 | // ! Residus |
---|
| 257 | // ! Guess black update |
---|
| 258 | |
---|
| 259 | for(jj=1;jj<NY-1;jj++){ |
---|
| 260 | ishift = jj%2;//MOD( jj, 2 ); |
---|
| 261 | for(ji=1+ishift;ji<NX-1;ji+=2){ |
---|
| 262 | Ytb_ztmp = YG_gcb_dynspg_flt(0,ji,jj,Yt) |
---|
| 263 | - gcp(ji,jj,0,t) * Ytb_gcx(ji ,jj-1) |
---|
| 264 | - gcp(ji,jj,1,t) * Ytb_gcx(ji-1,jj ) |
---|
| 265 | - gcp(ji,jj,2,t) * Ytb_gcx(ji+1,jj ) |
---|
| 266 | - gcp(ji,jj,3,t) * Ytb_gcx(ji ,jj+1); |
---|
| 267 | // ! Guess update |
---|
| 268 | Ytb_gcx(ji,jj) = sor * Ytb_ztmp + (1.-sor) * Ytb_gcx(ji,jj); |
---|
| 269 | } |
---|
| 270 | } |
---|
| 271 | |
---|
| 272 | //cas special ! applied the lateral boundary conditions |
---|
| 273 | // CALL lbc_lnk_e( gcx, c_solver_pt, 1. ) ; |
---|
| 274 | |
---|
| 275 | // ! Guess red update |
---|
| 276 | for(jj=1;jj<NY-1;jj++){ |
---|
| 277 | ishift = (jj-1)%2; |
---|
| 278 | for(ji=1+ishift;ji<NX-1;ji+=2){ |
---|
| 279 | Ytb_ztmp = YG_gcb_dynspg_flt(0,ji,jj,Yt) |
---|
| 280 | - gcp(ji,jj,0,t) * Ytb_gcx(ji ,jj-1) |
---|
| 281 | - gcp(ji,jj,1,t) * Ytb_gcx(ji-1,jj ) |
---|
| 282 | - gcp(ji,jj,2,t) * Ytb_gcx(ji+1,jj ) |
---|
| 283 | - gcp(ji,jj,3,t) * Ytb_gcx(ji ,jj+1); |
---|
| 284 | // ! Guess update |
---|
| 285 | Ytb_gcx(ji,jj) = sor * Ytb_ztmp + (1.-sor) * Ytb_gcx(ji,jj); |
---|
| 286 | } |
---|
| 287 | } |
---|
| 288 | |
---|
| 289 | } |
---|
| 290 | for(ji=1;ji<NX-1;ji++) |
---|
| 291 | for(jj=1;jj<NY-1;jj++) |
---|
| 292 | YG_gcx2(0,ji,jj,Yt)=Ytb_gcx(ji,jj); |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | // |
---|
| 296 | return; |
---|
| 297 | } |
---|
| 298 | // |
---|
| 299 | } |
---|
| 300 | |
---|
| 301 | //=========================================================================== |
---|
| 302 | //********************** FIN DU MODULE solsor_dynspg_flt ***************** |
---|