Changeset 214 in lmdz_wrf for trunk/tools
- Timestamp:
- Jan 12, 2015, 6:56:17 PM (10 years ago)
- Location:
- trunk/tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/iniaqua.py
r213 r214 19 19 filekinds = ['CF', 'WRF'] 20 20 21 ## g.e. # iniaqua.py -d 32,32,39 -p hybdrid -o WRF -t 19791201000000 -z param 21 ## g.e. # iniaqua.py -d 32,32,39 -p hybdrid -o WRF -t 19791201000000 -z tropo 22 def fxy(dx, dy): 23 """! 24 ! $Id: fxy.F 1403 2010-07-01 09:02:53Z fairhead $ 25 ! 26 c Auteur : P. Le Van 27 c 28 c Calcul des longitudes et des latitudes pour une fonction f(x,y) 29 c a tangente sinusoidale et eventuellement avec zoom . 30 c 31 c 32 """ 33 fname ='fxy' 34 35 #c ...... calcul des latitudes et de y' ..... 36 #c 37 vrlatu = np.zeros((dy+1), dtype=np.float) 38 vyprimu = np.zeros((dy+1), dtype=np.float) 39 40 vrlatu = ffy(np.arange(dy+1)*1. + 1.) 41 vyprimu = ffy(np.arange(dy+1)*1. + 1.) 42 43 vrlatv = np.zeros((dy), dtype=np.float) 44 vrlatu1 = np.zeros((dy), dtype=np.float) 45 vrlatu2 = np.zeros((dy), dtype=np.float) 46 yprimv = np.zeros((dy), dtype=np.float) 47 vyprimu1 = np.zeros((dy), dtype=np.float) 48 vyprimu2 = np.zeros((dy), dtype=np.float) 49 50 vrlatv = ffy(np.arange(dy)*1. + 1. + 0.5) 51 vrlatu1 = ffy(np.arange(dy)*1. + 1. + 0.25) 52 vrlatu2 = ffy(np.arange(dy)*1. + 1. + 0.75) 53 54 vyprimv = fyprim(np.arange(dy)*1. + 1. + 0.5) 55 vyprimu1 = fyprim(np.arange(dy)*1. + 1. + 0.25) 56 vyprimu2 = fyprim(np.arange(dy)*1. + 1. + 0.75) 57 58 #c 59 #c ..... calcul des longitudes et de x' ..... 60 #c 61 vrlonv = np.zeros((dx+1), dtype=np.float) 62 vrlonu = np.zeros((dx+1), dtype=np.float) 63 vrlonm025 = np.zeros((dx+1), dtype=np.float) 64 vrlonp025 = np.zeros((dx+1), dtype=np.float) 65 vxprimv = np.zeros((dx+1), dtype=np.float) 66 vxprimu = np.zeros((dx+1), dtype=np.float) 67 vxprimm025 = np.zeros((dx+1), dtype=np.float) 68 vxprimo025 = np.zeros((dx+1), dtype=np.float) 69 70 vrlonv = ffy(np.arange(dx+1)*1. + 1.) 71 vrlonu = ffy(np.arange(dx+1)*1. + 1. + 0.5) 72 vrlonm025 = ffy(np.arange(dx+1)*1. + 1. - 0.25) 73 vrlonp025 = ffy(np.arange(dx+1)*1. + 1. + 0.25) 74 75 vxprimv = fxprim(np.arange(dx+1)*1. + 1.) 76 vxprimu = fxprim(np.arange(dx+1)*1. + 1. + 0.5) 77 vxprimm025 = fxprim(np.arange(dx+1)*1. + 1. - 0.25) 78 vxprimp025 = fxprim(np.arange(dx+1)*1. + 1. + 0.25) 79 80 return vrlatu, vyprimu, vrlatv, vyprimv, vrlatu1, vyprimu1, vrlatu2, vyprimu2, \ 81 vrlonu, vxprimu, vrlonv, vxprimv, vrlonm025, vxprimm025, vrlonp025, vxprimp025 82 83 # From grid/fxy_sin.h 84 # ................................................................ 85 # ................ Fonctions in line ........................... 86 # ................................................................ 87 # 88 89 def fy(rj,dy): 90 """ 91 """ 92 val = np.arcsin(1.+2.*((1.-rj)/np.float(dy))) 93 94 return val 95 96 def fyprim(rj,dy): 97 """ 98 """ 99 val = 1./np.sqrt((rj-1.)*(dy+1.-rj)) 100 101 return val 102 103 def fx(ri,dx): 104 """ 105 """ 106 val = 2.*np.pi/np.float(dx) * ( ri - 0.5*np.float(dx) - 1. ) 107 108 return val 109 110 def fxprim(ri,dx): 111 """ 112 """ 113 val = 2.*np.pi/np.float(dx) 114 115 return val 116 117 # 118 # 119 # La valeur de pi est passee par le common/const/ou /const2/ . 120 # Sinon, il faut la calculer avant d'appeler ces fonctions . 121 # 122 # ---------------------------------------------------------------- 123 # Fonctions a changer eventuellement, selon x(x) et y(y) choisis . 124 # ----------------------------------------------------------------- 125 # 126 # ..... ici, on a l'application particuliere suivante ........ 127 # 128 # ************************************** 129 # ** x = 2. * pi/iim * X ** 130 # ** y = pi/jjm * Y ** 131 # ************************************** 132 # 133 # .................................................................. 134 # .................................................................. 135 # 136 # 137 # 138 #----------------------------------------------------------------------- 139 140 def fxysinus (ddy,ddx): 141 """c 142 c Calcul des longitudes et des latitudes pour une fonction f(x,y) 143 c avec y = Asin( j ) . 144 c 145 c Auteur : P. Le Van 146 c 147 c 148 from: dyn3d/fxysinus.F 149 """ 150 fname = 'fxysinus' 151 152 # ...... calcul des latitudes et de y' ..... 153 # 154 rlatu = np.zeros((ddy+1), dtype=np.float) 155 yprimu = np.zeros((ddy+1), dtype=np.float) 156 157 for j in range(ddy+1): 158 rlatu[j] = fy( np.float(j+1), ddy) 159 yprimu[j] = fyprim( np.float(j+1), ddy) 160 161 rlatv = np.zeros((ddy), dtype=np.float) 162 rlatu1 = np.zeros((ddy), dtype=np.float) 163 rlatu2 = np.zeros((ddy), dtype=np.float) 164 yprimv = np.zeros((ddy), dtype=np.float) 165 yprimu1 = np.zeros((ddy), dtype=np.float) 166 yprimu2 = np.zeros((ddy), dtype=np.float) 167 168 for j in range(ddy): 169 rlatv[j] = fy( np.float(j) + 0.5, ddy) 170 rlatu1[j] = fy( np.float(j) + 0.25, ddy) 171 rlatu2[j] = fy( np.float(j) + 0.75, ddy) 172 173 yprimv[j] = fyprim( np.float(j) + 0.5, ddy) 174 yprimu1[j] = fyprim( np.float(j) + 0.25, ddy) 175 yprimu2[j] = fyprim( np.float(j) + 0.75, ddy) 176 177 # 178 # ..... calcul des longitudes et de x' ..... 179 # 180 rlonv = np.zeros((ddx+1), dtype=np.float) 181 rlonu = np.zeros((ddx+1), dtype=np.float) 182 rlonm025 = np.zeros((ddx+1), dtype=np.float) 183 rlonp025 = np.zeros((ddx+1), dtype=np.float) 184 xprimv = np.zeros((ddx+1), dtype=np.float) 185 xprimu = np.zeros((ddx+1), dtype=np.float) 186 xprimm025 = np.zeros((ddx+1), dtype=np.float) 187 xprimp025 = np.zeros((ddx+1), dtype=np.float) 188 189 for i in range(ddx + 1): 190 rlonv[i] = fx( np.float(i), ddx ) 191 rlonu[i] = fx( np.float(i)+ 0.5, ddx ) 192 rlonm025[i] = fx( np.float(i)- 0.25, ddx ) 193 rlonp025[i] = fx( np.float(i)+ 0.25, ddx ) 194 195 xprimv[i] = fxprim(np.float(i), ddx ) 196 xprimu[i] = fxprim(np.float(i)+ 0.5, ddx ) 197 xprimm025[i] = fxprim(np.float(i)- 0.25, ddx ) 198 xprimp025[i] = fxprim(np.float(i)+ 0.25, ddx ) 199 200 return rlatu, yprimu, rlatv, yprimv, rlatu1, yprimu1, rlatu2, yprimu2, rlonu, \ 201 xprimu, rlonv, xprimv, rlonm025, xprimm025, rlonp025, xprimp025 202 203 def fxhyp (dx, dy, xzoomdeg, grossism): 204 """ 205 c Auteur : P. Le Van 206 207 208 c Calcule les longitudes et derivees dans la grille du GCM pour une 209 c fonction f(x) a tangente hyperbolique . 210 c 211 c grossism etant le grossissement ( = 2 si 2 fois, = 3 si 3 fois,etc.) 212 c dzoom etant la distance totale de la zone du zoom 213 c tau la raideur de la transition de l'interieur a l'exterieur du zoom 214 c 215 c On doit avoir grossism x dzoom < pi ( radians ) , en longitude. 216 c ******************************************************************** 217 """ 218 fname = 'fxhyp' 219 220 nmax = 30000 221 nmax2 = 2*nmax 222 223 scal180 = True 224 225 # scal180 = .TRUE. si on veut avoir le premier point scalaire pour 226 # une grille reguliere ( grossism = 1.,tau=0.,clon=0. ) a -180. degres. 227 # sinon scal180 = .FALSE. 228 229 # ...... arguments d'entree ....... 230 # 231 # REAL xzoomdeg,dzooma,tau,grossism 232 233 # ...... arguments de sortie ...... 234 rlonm025 = np.zeros((dx+1), dtype=np.float) 235 xprimm025 = np.zeros((dx+1), dtype=np.float) 236 rlonv = np.zeros((dx+1), dtype=np.float) 237 xprimv = np.zeros((dx+1), dtype=np.float) 238 rlonu = np.zeros((dx+1), dtype=np.float) 239 xprimu = np.zeros((dx+1), dtype=np.float) 240 rlonp025 = np.zeros((dx+1), dtype=np.float) 241 xprimp025 = np.zeros((dx+1), dtype=np.float) 242 243 # .... variables locales .... 244 # 245 xlon = np.zeros((dx+1), dtype=np.float32), 246 xprimm = np.zeros((dx+1), dtype=np.float32) 247 xtild = np.zeros((nmax2), dtype=np.float32) 248 fhyp = np.zeros((nmax2), dtype=np.float32) 249 Xprimt = np.zeros((nmax2), dtype=np.float32) 250 Xf = np.zeros((nmax2), dtype=np.float32) 251 xxpr = np.zeros((nmax2), dtype=np.float32) 252 xvrai = np.zeros((dx+1), dtype=np.float32) 253 xxprim = np.zeros((dx+1), dtype=np.float32) 254 255 pi = np.pi 256 depi = 2. * np.pi 257 epsilon = 1.e-3 258 xzoom = xzoomdeg * pi/180. 259 260 if dx == 1: 261 rlonm025[1] = -pi/2. 262 rlonv[1] = 0. 263 rlonu[1] = pi 264 rlonp025[1] = pi/2. 265 rlonm025[2] = rlonm025[1] + depi 266 rlonv[2] = rlonv[1] + depi 267 rlonu[2] = rlonu[1] + depi 268 rlonp025[2] = rlonp025[1] + depi 269 270 xprimm025 = 1. 271 xprimv = 1. 272 xprimu = 1. 273 xprimp025 = 1. 274 champmin =depi 275 champmax = depi 276 return dzooma, tau, rlonm025, xprimm025, rlonv, xprimv, rlonu, xprimu, \ 277 rlonp025, xprimp025, champmin, champmax 278 279 decalx = .75 280 if grossism == 1. and scal180: 281 decalx = 1. 282 283 print 'FXHYP scal180,decalx', scal180,decalx 284 285 if dzooma > 1.: 286 dzoom = dzooma * depi 287 elif dzooma < 25.: 288 print erormsg 289 print ' ' + fname +": Le param. dzoomx pour 'fxhyp' est trop petit dzooma:",\ 290 dzooma,'!L augmenter et relancer !' 291 quit(-1) 292 else: 293 dzoom = dzooma * pi/180. 294 295 296 print ' xzoom( rad.),grossism,tau,dzoom (radians)' 297 print xzoom,grossism,tau,dzoom 298 299 xtild = - pi + np.range(namx2) * depi /nmax2 300 301 for i in range(nmax,nmax2): 302 fa = tau* ( dzoom/2. - xtild[i] ) 303 fb = xtild[i] * ( pi - xtild[i] ) 304 305 if 200.* fb < - fa: 306 fhyp[i] = -1. 307 elif 200. * fb < fa: 308 fhyp[i] = 1. 309 else: 310 if np.abs(fa) < 1.e-13 and np.abs(fb) < 1.e-13: 311 if 200.*fb + fa < 1.e-10: 312 fhyp[i] = -1. 313 elif 200.*fb - fa < 1.e-10: 314 fhyp[i] = 1. 315 else: 316 fhyp[i] = np.tanh(fa/fb) 317 if xtild[i] == 0.: fhyp[i] = 1. 318 if xtild[i] == pi: fhyp[i] = -1. 319 320 ## .... Calcul de beta .... 321 322 ffdx = 0. 323 324 for i in range(nmax+1,nmax2): 325 xmoy = 0.5 * ( xtild[i-1] + xtild[i] ) 326 fa = tau*( dzoom/2. - xmoy ) 327 fb = xmoy*( pi - xmoy ) 328 329 if 200.* fb < -fa: 330 fxm = -1. 331 elif 200. * fb < fa: 332 fxm = 1. 333 else: 334 if np.abs(fa) < 1.e-13 and np.abs(fb) < 1.e-13: 335 if 200.*fb + fa < 1.e-10: 336 fxm = -1. 337 elif 200.*fb - fa < 1.e-10: 338 fxm = 1. 339 else: 340 fxm = np.tanh( fa/fb ) 341 342 if xmoy == 0.: fxm = 1. 343 if xmoy == pi: fxm = -1. 344 345 ffdx = ffdx + fxm * ( xtild[i] - xtild[i-1] ) 346 347 beta = ( grossism * ffdx - pi ) / ( ffdx - pi ) 348 349 if 2.*beta - grossism < 0.: 350 print warnmsg 351 print ' ' + fname + ': ** Attention ! La valeur beta calculee dans la ' + \ 352 'routine fxhyp est mauvaise ! ' 353 print ' Modifier les valeurs de grossismx ,tau ou dzoomx et relancer ! ***' 354 quit(-1) 355 356 # 357 # ..... calcul de Xprimt ..... 358 # 359 360 for i in range(nmax, nmax2): 361 Xprimt[i] = beta + ( grossism - beta ) * fhyp[i] 362 363 for i in range(nmax+1, nmax2): 364 Xprimt[nmax2-i] = Xprimt[i] 365 366 # ..... Calcul de Xf ........ 367 368 Xf[0] = - pi 369 370 for i in range(nmax+1, nmax2): 371 xmoy = 0.5 * ( xtild[i-1] + xtild[i] ) 372 fa = tau* ( dzoom/2. - xmoy ) 373 fb = xmoy * ( pi - xmoy ) 374 375 if 200.* fb < -fa: 376 fxm = -1. 377 elif 200. * fb < fa: 378 fxm = 1. 379 else: 380 fxm = np.tanh( fa/fb ) 381 382 if xmoy == 0.: fxm = 1. 383 if xmoy == pi: fxm = -1. 384 xxpr[i] = beta + ( grossism - beta ) * fxm 385 386 for i in range(nmax+1, nmax2): 387 xxpr[nmax2-i+1] = xxpr[i] 388 389 for i in range(nmax2): 390 Xf[i] = Xf[i-1] + xxpr[i] * ( xtild[i] - xtild[i-1] ) 391 392 # ***************************************************************** 393 # 394 395 # ..... xuv = 0. si calcul aux pts scalaires ........ 396 # ..... xuv = 0.5 si calcul aux pts U ........ 397 398 for ik in range(4): 399 if ik == 0: 400 xuv = -0.25 401 elif ik == 1: 402 xuv = 0. 403 elif ik == 2: 404 xuv = 0.50 405 elif ik == 4: 406 xuv = 0.25 407 408 xo1 = 0. 409 410 ii1=1 411 ii2=dx 412 if ik == 0 and grossism == 1.: 413 ii1 = 2 414 ii2 = dx+1 415 416 for i in range(ii1, ii2): 417 xlon2 = - pi + (np.float(i) + xuv - decalx) * depi / np.float32(dx) 418 419 Xfi = xlon2 420 421 ended = False 422 for it in range(nmax2,0,-1): 423 if Xfi > Xf[it]: 424 ended = True 425 break 426 if not ended: it = 0 427 428 # ...... Calcul de Xf(xi) ...... 429 # 430 xi = xtild[it] 431 432 if it == nmax2: 433 it = nmax2 -1 434 Xf[it+1] = pi 435 436 # ..................................................................... 437 # 438 # Appel de la routine qui calcule les coefficients a0,a1,a2,a3 d'un 439 # polynome de degre 3 qui passe par les points (Xf(it),xtild(it) ) 440 # et (Xf(it+1),xtild(it+1) ) 441 442 a0, a1, a2, a3 = coefpoly( Xf[it], Xf[it+1], Xprimt[it], Xprimt[it+1], \ 443 xtild[it], xtild[it+1]) 444 445 Xf1 = Xf[it] 446 Xprimin = a1 + 2.* a2 * xi + 3.*a3 * xi *xi 447 448 for iteri in range(300): 449 xi = xi - ( Xf1 - Xfi )/ Xprimin 450 451 ended = False 452 if np.abs(xi-xo1) < epsilon: 453 ended = True 454 break 455 xo1 = xi 456 xi2 = xi * xi 457 Xf1 = a0 + a1 * xi + a2 * xi2 + a3 * xi2 * xi 458 Xprimin = a1 + 2.* a2 * xi + 3.* a3 * xi2 459 460 if not ended: 461 print errmsg 462 print ' ' + fname + ': Pas de solution ***** ',i,xlon2,iteri 463 quit(-1) 464 465 xxprim[i] = depi/ ( np.float32(dx) * Xprimin ) 466 xvrai[i] = xi + xzoom 467 468 if ik == 0 and grossism == 1: 469 xvrai[0] = xvrai[dx+1] - depi 470 xxprim[0] = xxprim[dx+1] 471 472 xlon[0:dx+1] = xvrai[0:dx+1] 473 xprimm[0:dx+1] = xxprim[0:dx+1] 474 475 for i in range(dx-1): 476 if xvrai[i+1] < xvrai[i]: 477 print errormsg 478 print ' ' + fname + ': PBS. avec rlonu(',i+1,') plus petit que rlonu(', \ 479 i,')' 480 quit(-1) 481 482 # 483 # ... Reorganisation des longitudes pour les avoir entre - pi et pi .. 484 # ........................................................................ 485 486 champmin = 1.e12 487 champmax = -1.e12 488 for i in range(dx): 489 champmin = np.min( [champmin,xvrai[i]] ) 490 champmax = np.max( [champmax,xvrai[i]] ) 491 492 # if champmin >= -pi-0.10 and champmax <= pi+0.10: 493 # GO TO 1600 494 495 # 496 # HERE -- here 497 # 498 # ELSE 499 # WRITE(6,*) 'Reorganisation des longitudes pour avoir entre - pi', 500 # , ' et pi ' 501 #c 502 # IF( xzoom.LE.0.) THEN 503 # IF( ik.EQ. 1 ) THEN 504 # DO i = 1, iim 505 # IF( xvrai(i).GE. - pi ) GO TO 80 506 # ENDDO 507 # WRITE(6,*) ' PBS. 1 ! Xvrai plus petit que - pi ! ' 508 # STOP 8 509 # 80 CONTINUE 510 # is2 = i 511 # ENDIF 512 # 513 # IF( is2.NE. 1 ) THEN 514 # DO ii = is2 , iim 515 # xlon (ii-is2+1) = xvrai(ii) 516 # xprimm(ii-is2+1) = xxprim(ii) 517 # ENDDO 518 # DO ii = 1 , is2 -1 519 # xlon (ii+iim-is2+1) = xvrai(ii) + depi 520 # xprimm(ii+iim-is2+1) = xxprim(ii) 521 # ENDDO 522 # ENDIF 523 # ELSE 524 # IF( ik.EQ.1 ) THEN 525 # DO i = iim,1,-1 526 # IF( xvrai(i).LE. pi ) GO TO 90 527 # ENDDO 528 # WRITE(6,*) ' PBS. 2 ! Xvrai plus grand que pi ! ' 529 # STOP 9 530 # 90 CONTINUE 531 # is2 = i 532 # ENDIF 533 # idif = iim -is2 534 # DO ii = 1, is2 535 # xlon (ii+idif) = xvrai(ii) 536 # xprimm(ii+idif) = xxprim(ii) 537 # ENDDO 538 # DO ii = 1, idif 539 # xlon (ii) = xvrai (ii+is2) - depi 540 # xprimm(ii) = xxprim(ii+is2) 541 # ENDDO 542 # ENDIF 543 # ENDIF 544 #c 545 #c ......... Fin de la reorganisation ............................ 546 547 # 1600 CONTINUE 548 549 550 # xlon ( iip1) = xlon(1) + depi 551 # xprimm( iip1 ) = xprimm (1 ) 552 553 # DO i = 1, iim+1 554 # xvrai(i) = xlon(i)*180./pi 555 # ENDDO 556 557 # IF( ik.EQ.1 ) THEN 558 #c WRITE(6,*) ' XLON aux pts. V-0.25 apres ( en deg. ) ' 559 #c WRITE(6,18) 560 #c WRITE(6,68) xvrai 561 #c WRITE(6,*) ' XPRIM k ',ik 562 #c WRITE(6,566) xprimm 563 564 # DO i = 1,iim +1 565 # rlonm025(i) = xlon( i ) 566 # xprimm025(i) = xprimm(i) 567 # ENDDO 568 # ELSE IF( ik.EQ.2 ) THEN 569 #c WRITE(6,18) 570 #c WRITE(6,*) ' XLON aux pts. V apres ( en deg. ) ' 571 #c WRITE(6,68) xvrai 572 #c WRITE(6,*) ' XPRIM k ',ik 573 #c WRITE(6,566) xprimm 574 575 # DO i = 1,iim + 1 576 # rlonv(i) = xlon( i ) 577 # xprimv(i) = xprimm(i) 578 # ENDDO 579 580 # ELSE IF( ik.EQ.3) THEN 581 #c WRITE(6,18) 582 #c WRITE(6,*) ' XLON aux pts. U apres ( en deg. ) ' 583 #c WRITE(6,68) xvrai 584 #c WRITE(6,*) ' XPRIM ik ',ik 585 #c WRITE(6,566) xprimm 586 587 # DO i = 1,iim + 1 588 # rlonu(i) = xlon( i ) 589 # xprimu(i) = xprimm(i) 590 # ENDDO 591 592 # ELSE IF( ik.EQ.4 ) THEN 593 #c WRITE(6,18) 594 #c WRITE(6,*) ' XLON aux pts. V+0.25 apres ( en deg. ) ' 595 #c WRITE(6,68) xvrai 596 #c WRITE(6,*) ' XPRIM ik ',ik 597 #c WRITE(6,566) xprimm 598 599 # DO i = 1,iim + 1 600 # rlonp025(i) = xlon( i ) 601 # xprimp025(i) = xprimm(i) 602 # ENDDO 603 604 # ENDIF 605 606 #5000 CONTINUE 607 #c 608 # WRITE(6,18) 609 #c 610 #c ........... fin de la boucle do 5000 ............ 611 612 # DO i = 1, iim 613 # xlon(i) = rlonv(i+1) - rlonv(i) 614 # ENDDO 615 # champmin = 1.e12 616 # champmax = -1.e12 617 # DO i = 1, iim 618 # champmin = MIN( champmin, xlon(i) ) 619 # champmax = MAX( champmax, xlon(i) ) 620 # ENDDO 621 # champmin = champmin * 180./pi 622 # champmax = champmax * 180./pi 623 624 #18 FORMAT(/) 625 #24 FORMAT(2x,'Parametres xzoom,gross,tau ,dzoom pour fxhyp ',4f8.3) 626 #68 FORMAT(1x,7f9.2) 627 #566 FORMAT(1x,7f9.4) 628 629 return dzooma, tau, rlonm025, xprimm025, rlonv, xprimv, rlonu, xprimu, \ 630 rlonp025, xprimp025, champmin, champmax 631 632 633 def fxyhyper (ddy, ddx, yzoom, grossy, dzoomy, tauy, xzoom, grossx, dzoomx, taux, \ 634 rlatu, yprimu, rlatv, yprimv, rlatu1, yprimu1, rlatu2, yprimu2, 635 rlonu, xprimu, rlonv, xprimv, rlonm025, xprimm025, rlonp025, xprimp025): 636 """c 637 c Auteur : P. Le Van . 638 c 639 c d'apres formulations de R. Sadourny . 640 c 641 c 642 c Ce spg calcule les latitudes( routine fyhyp ) et longitudes( fxhyp ) 643 c par des fonctions a tangente hyperbolique . 644 c 645 c Il y a 3 parametres ,en plus des coordonnees du centre du zoom (xzoom 646 c et yzoom ) : 647 c 648 c a) le grossissement du zoom : grossy ( en y ) et grossx ( en x ) 649 c b) l' extension du zoom : dzoomy ( en y ) et dzoomx ( en x ) 650 c c) la raideur de la transition du zoom : taux et tauy 651 c 652 c N.B : Il vaut mieux avoir : grossx * dzoomx < pi ( radians ) 653 c ****** 654 c et grossy * dzoomy < pi/2 ( radians ) 655 c 656 """ 657 fname = 'fxyhyper' 658 659 # CALL fyhyp ( yzoom, grossy, dzoomy,tauy , 660 # , rlatu, yprimu,rlatv,yprimv,rlatu2,yprimu2,rlatu1,yprimu1 , 661 # , dymin,dymax ) 662 663 # CALL fxhyp(xzoom,grossx,dzoomx,taux,rlonm025,xprimm025,rlonv, 664 # , xprimv,rlonu,xprimu,rlonp025,xprimp025 , dxmin,dxmax ) 665 666 667 for i in range(ddx+1): 668 if rlonp025[i] < rlonv[i]: 669 print errormsg 670 print ' ' + fname + ' Attention ! rlonp025 < rlonv',i 671 quit(-1) 672 673 if rlonv[i] < rlonm025[i]: 674 print errormsg 675 print ' ' + fname + ' Attention ! rlonm025 > rlonv',i 676 quit(-1) 677 678 if rlonp025[i] > rlonu[i]: 679 print errormsg 680 print ' ' + fname + ' Attention ! rlonp025 > rlonu',i 681 quit(-1) 682 683 print ' *** TEST DE COHERENCE OK POUR FX **** ' 684 685 686 for j in range(ddy): 687 if rlatu1[j] <= rlatu2[j]: 688 print errormsg 689 print ' ' + fname + 'Attention ! rlatu1 < rlatu2',rlatu1[j],rlatu2[j],j 690 quit(-1) 691 692 if rlatu2[j] <= rlatu[j+1]: 693 print errormsg 694 print ' ' + fname + 'Attention ! rlatu2 < rlatup1',rlatu2[j],rlatu[j+1],j 695 quit(-1) 696 697 if rlatu[j] <= rlatu1[j]: 698 print errormsg 699 print ' ' + fname + 'Attention ! rlatu < rlatu1',rlatu[j],rlatu1[j],j 700 quit(-1) 701 702 if rlatv[j] <= rlatu2[j]: 703 print errormsg 704 print ' ' + fname + 'Attention ! rlatv < rlatu2 ',rlatv[j],rlatu2[j],j 705 quit(-1) 706 707 if rlatv[j] >= rlatu1[j]: 708 print errormsg 709 print ' ' + fname + 'Attention ! rlatv > rlatu1 ',rlatv[j],rlatu1[j],j 710 quit(-1) 711 712 if rlatv[j] >= rlatu[j]: 713 print errormsg 714 print ' ' + fname + 'Attention ! rlatv > rlatu ',rlatv[j],rlatu[j],j 715 quit(-1) 716 717 print ' *** TEST DE COHERENCE OK POUR FY **** ' 718 719 print ' Latitudes ' 720 print ' *********** ' 721 722 print 'Au centre du zoom, la longueur de la maille est d environ', dymin , \ 723 'degres alors que la maille en dehors de la zone du zoom est d environ', \ 724 dymax, 'degres' 725 print ' Si cette derniere est trop lache , modifiez les parametres grossism , ' +\ 726 'tau , dzoom pour Y et repasser ! ' 727 728 print ' Longitudes ' 729 print ' ************ ' 730 print 'Au centre du zoom, la longueur de la maille est d environ', dxmin , \ 731 'degres alors que la maille en dehors de la zone du zoom est d environ', \ 732 dxmax, 'degres' 733 print ' Si cette derniere est trop lache , modifiez les parametres grossism , ' +\ 734 'tau , dzoom pour Y et repasser ! ' 735 736 return 737 738 def inigeom(dy,dx): 739 """c 740 c Auteur : P. Le Van 741 c 742 c ............ Version du 01/04/2001 ........................ 743 c 744 c Calcul des elongations cuij1,.cuij4 , cvij1,..cvij4 aux memes en- 745 c endroits que les aires aireij1,..aireij4 . 746 747 c Choix entre f(y) a derivee sinusoid. ou a derivee tangente hyperbol. 748 c 749 c 750 """ 751 fname = 'inigeom' 752 753 cvu = np.zeros((dy+1,dx+1), dtype=np.float) 754 cuv = np.zeros((dy, dx+1), dtype=np.float) 755 756 cuij1 = np.zeros((dy+1,dx+1), dtype=np.float) 757 cuij2 = np.zeros((dy+1,dx+1), dtype=np.float) 758 cuij3 = np.zeros((dy+1,dx+1), dtype=np.float) 759 cuij4 = np.zeros((dy+1,dx+1), dtype=np.float) 760 cvij1 = np.zeros((dy+1,dx+1), dtype=np.float) 761 cvij2 = np.zeros((dy+1,dx+1), dtype=np.float) 762 cvij3 = np.zeros((dy+1,dx+1), dtype=np.float) 763 cvij4 = np.zeros((dy+1,dx+1), dtype=np.float) 764 aireij1 = np.zeros((dy+1,dx+1), dtype=np.float) 765 aireij2 = np.zeros((dy+1,dx+1), dtype=np.float) 766 aireij3 = np.zeros((dy+1,dx+1), dtype=np.float) 767 aireij4 = np.zeros((dy+1,dx+1), dtype=np.float) 768 769 aire = np.zeros((dy+1,dx+1), dtype=np.float) 770 aireu = np.zeros((dy+1,dx+1), dtype=np.float) 771 airev = np.zeros((dy+1,dx+1), dtype=np.float) 772 unsaire = np.zeros((dy+1,dx+1), dtype=np.float) 773 unsair_gam1 = np.zeros((dy+1,dx+1), dtype=np.float) 774 unsair_gam2 = np.zeros((dy+1,dx+1), dtype=np.float) 775 airesurg = np.zeros((dy+1,dx+1), dtype=np.float) 776 unsairez = np.zeros((dy+1,dx+1), dtype=np.float) 777 unsairz_gam = np.zeros((dy+1,dx+1), dtype=np.float) 778 fext = np.zeros((dy+1,dx+1), dtype=np.float) 779 780 alpha1 = np.zeros((dy+1,dx+1), dtype=np.float) 781 alpha2 = np.zeros((dy+1,dx+1), dtype=np.float) 782 alpha3 = np.zeros((dy+1,dx+1), dtype=np.float) 783 alpha4 = np.zeros((dy+1,dx+1), dtype=np.float) 784 alpha1p2 = np.zeros((dy+1,dx+1), dtype=np.float) 785 alpha1p4 = np.zeros((dy+1,dx+1), dtype=np.float) 786 alpha2p3 = np.zeros((dy+1,dx+1), dtype=np.float) 787 alpha3p4 = np.zeros((dy+1,dx+1), dtype=np.float) 788 789 rlonvv = np.zeros((dx+1), dtype=np.float) 790 rlatuu = np.zeros((dy+1), dtype=np.float) 791 rlatu1 = np.zeros((dy), dtype=np.float) 792 yprimu1 = np.zeros((dy), dtype=np.float) 793 rlatu2 = np.zeros((dy), dtype=np.float) 794 yprimu2 = np.zeros((dy), dtype=np.float) 795 yprimv = np.zeros((dy), dtype=np.float) 796 yprimu = np.zeros((dy+1), dtype=np.float) 797 798 rlonm025 = np.zeros((dx+1), dtype=np.float) 799 xprimm025 = np.zeros((dx+1), dtype=np.float) 800 rlonp025 = np.zeros((dx+1), dtype=np.float) 801 xprimp025 = np.zeros((dx+1), dtype=np.float) 802 803 cu = np.zeros((dy+1,dx+1), dtype=np.float) 804 cv = np.zeros((dy+1,dx+1), dtype=np.float) 805 unscu2 = np.zeros((dy+1,dx+1), dtype=np.float) 806 unscv2 = np.zeros((dy+1,dx+1), dtype=np.float) 807 cuvsurcv = np.zeros((dy+1,dx+1), dtype=np.float) 808 cuvsurcuv = np.zeros((dy+1,dx+1), dtype=np.float) 809 cvsurcv = np.zeros((dy+1,dx+1), dtype=np.float) 810 cvsurcuv = np.zeros((dy+1,dx+1), dtype=np.float) 811 cuvscvgam1 = np.zeros((dy+1,dx+1), dtype=np.float) 812 cuvscvgam2 = np.zeros((dy+1,dx+1), dtype=np.float) 813 cvscuvgam = np.zeros((dy+1,dx+1), dtype=np.float) 814 cvusurcu = np.zeros((dy+1,dx+1), dtype=np.float) 815 cusurcvu = np.zeros((dy+1,dx+1), dtype=np.float) 816 cvuscugam1 = np.zeros((dy+1,dx+1), dtype=np.float) 817 cvuscugam2 = np.zeros((dy+1,dx+1), dtype=np.float) 818 cuscvugam = np.zeros((dy+1,dx+1), dtype=np.float) 819 airvscu2 = np.zeros((dy+1,dx+1), dtype=np.float) 820 aivscu2gam = np.zeros((dy+1,dx+1), dtype=np.float) 821 airuscv2 = np.zeros((dy+1,dx+1), dtype=np.float) 822 aiuscv2gam = np.zeros((dy+1,dx+1), dtype=np.float) 823 824 constang = np.zeros((dy+1,dx+1), dtype=np.float) 825 # 826 # 827 # ------------------------------------------------------------------ 828 # - - 829 # - calcul des coeff. ( cu, cv , 1./cu**2, 1./cv**2 ) - 830 # - - 831 # ------------------------------------------------------------------ 832 # 833 # les coef. ( cu, cv ) permettent de passer des vitesses naturelles 834 # aux vitesses covariantes et contravariantes , ou vice-versa ... 835 # 836 # 837 # on a : u (covariant) = cu * u (naturel) , u(contrav)= u(nat)/cu 838 # v (covariant) = cv * v (naturel) , v(contrav)= v(nat)/cv 839 # 840 # on en tire : u(covariant) = cu * cu * u(contravariant) 841 # v(covariant) = cv * cv * v(contravariant) 842 # 843 # 844 # on a l'application ( x(X) , y(Y) ) avec - im/2 +1 < X < im/2 845 # = = 846 # et - jm/2 < Y < jm/2 847 # = = 848 # 849 # ................................................... 850 # ................................................... 851 # . x est la longitude du point en radians . 852 # . y est la latitude du point en radians . 853 # . . 854 # . on a : cu(i,j) = rad * COS(y) * dx/dX . 855 # . cv( j ) = rad * dy/dY . 856 # . aire(i,j) = cu(i,j) * cv(j) . 857 # . . 858 # . y, dx/dX, dy/dY calcules aux points concernes . 859 # . . 860 # ................................................... 861 # ................................................... 862 # 863 # 864 # 865 # , 866 # cv , bien que dependant de j uniquement,sera ici indice aussi en i 867 # pour un adressage plus facile en ij . 868 # 869 # 870 # 871 # ************** aux points u et v , ***************** 872 # xprimu et xprimv sont respectivement les valeurs de dx/dX 873 # yprimu et yprimv . . . . . . . . . . . dy/dY 874 # rlatu et rlatv . . . . . . . . . . .la latitude 875 # cvu et cv . . . . . . . . . . . cv 876 # 877 # ************** aux points u, v, scalaires, et z **************** 878 # cu, cuv, cuscal, cuz sont respectiv. les valeurs de cu 879 # 880 # 881 # 882 # Exemple de distribution de variables sur la grille dans le 883 # domaine de travail ( X,Y ) . 884 # ................................................................ 885 # DX=DY= 1 886 # 887 # 888 # + represente un point scalaire ( p.exp la pression ) 889 # > represente la composante zonale du vent 890 # V represente la composante meridienne du vent 891 # o represente la vorticite 892 # 893 # ---- , car aux poles , les comp.zonales covariantes sont nulles 894 # 895 # 896 # 897 # i -> 898 # 899 # 1 2 3 4 5 6 7 8 900 # j 901 # v 1 + ---- + ---- + ---- + ---- + ---- + ---- + ---- + -- 902 # 903 # V o V o V o V o V o V o V o V o 904 # 905 # 2 + > + > + > + > + > + > + > + > 906 # 907 # V o V o V o V o V o V o V o V o 908 # 909 # 3 + > + > + > + > + > + > + > + > 910 # 911 # V o V o V o V o V o V o V o V o 912 # 913 # 4 + > + > + > + > + > + > + > + > 914 # 915 # V o V o V o V o V o V o V o V o 916 # 917 # 5 + ---- + ---- + ---- + ---- + ---- + ---- + ---- + -- 918 # 919 # 920 # Ci-dessus, on voit que le nombre de pts.en longitude est egal 921 # a IM = 8 922 # De meme , le nombre d'intervalles entre les 2 poles est egal 923 # a JM = 4 924 # 925 # Les points scalaires ( + ) correspondent donc a des valeurs 926 # entieres de i ( 1 a IM ) et de j ( 1 a JM +1 ) . 927 # 928 # Les vents U ( > ) correspondent a des valeurs semi- 929 # entieres de i ( 1+ 0.5 a IM+ 0.5) et entieres de j ( 1 a JM+1) 930 # 931 # Les vents V ( V ) correspondent a des valeurs entieres 932 # de i ( 1 a IM ) et semi-entieres de j ( 1 +0.5 a JM +0.5) 933 # 934 # 935 # 936 937 if nitergdiv != 2: 938 gamdi_gdiv = coefdis/ ( np.float(nitergdiv) -2. ) 939 else: 940 gamdi_gdiv = 0. 941 942 if nitergrot != 2: 943 gamdi_grot = coefdis/ ( np.float(nitergrot) -2. ) 944 else: 945 gamdi_grot = 0. 946 947 if niterh != 2: 948 gamdi_h = coefdis/ ( np.float(niterh) -2. ) 949 else: 950 gamdi_h = 0. 951 952 print 'gamdi_gd:',gamdi_gdiv,gamdi_grot,gamdi_h,coefdis,nitergdiv,nitergrot,niterh 953 954 # ---------------------------------------------------------------- 955 # 956 if not fxyhypb: 957 if ysinus: 958 print ' *** Inigeom , Y = Sinus ( Latitude ) *** ' 959 960 # .... utilisation de f(x,y ) avec y = sinus de la latitude ..... 961 962 rlatu, yprimu, rlatv, yprimv, rlatu1, yprimu1, rlatu2, yprimu2, rlonu, \ 963 xprimu, rlonv, xprimv, rlonm025, xprimm025, rlonp025, xprimp025 = \ 964 fxysinus(dx, dy) 965 else: 966 print '*** Inigeom , Y = Latitude , der. sinusoid . ***' 967 968 # .... utilisation de f(x,y) a tangente sinusoidale , y etant la latit. ... 969 970 pxo = clon *np.pi /180. 971 pyo = 2.* clat* np.pi /180. 972 # 973 # .... determination de transx ( pour le zoom ) par Newton-Raphson ... 974 # 975 itmax = 10 976 eps = .1e-7 977 978 xo1 = 0. 979 for iter in range(itmax): 980 x1 = xo1 981 f = x1+ alphax*np.sin(x1-pxo) 982 df = 1.+ alphax*np.cos(x1-pxo) 983 x1 = x1 - f/df 984 xdm = np.abs( x1- xo1 ) 985 if xdm > eps: xo1 = x1 986 987 transx = xo1 988 989 itmay = 10 990 eps = .1e-7 991 992 yo1 = 0. 993 for iter in range(itmay): 994 y1 = yo1 995 f = y1 + alphay*np.sin(y1-pyo) 996 df = 1. + alphay*np.cos(y1-pyo) 997 y1 = y1 -f/df 998 ydm = np.abs(y1-yo1) 999 if ydm > eps: yo1 = y1 1000 1001 transy = yo1 1002 1003 rlatu, yprimu, rlatv, yprimv, rlatu1, yprimu1, rlatu2, yprimu2, rlonu, \ 1004 xprimu, rlonv, xprimv, rlonm025, xprimm025, rlonp025, xprimp025 = \ 1005 fxy(dx,dy) 1006 else: 1007 # 1008 # .... Utilisation de fxyhyper , f(x,y) a derivee tangente hyperbol. 1009 # ..................................................................... 1010 1011 print '*** Inigeom , Y = Latitude , der.tg. hyperbolique ***' 1012 1013 #!!!!! Lluis 1014 #!! HERE, how to do all this without zoom!? 1015 #! 1016 1017 # CALL fxyhyper( clat, grossismy, dzoomy, tauy , 1018 # , clon, grossismx, dzoomx, taux , 1019 # , rlatu,yprimu,rlatv, yprimv,rlatu1, yprimu1,rlatu2,yprimu2 , 1020 # , rlonu,xprimu,rlonv,xprimv,rlonm025,xprimm025,rlonp025,xprimp025 ) 1021 1022 # ------------------------------------------------------------------- 1023 1024 rlatu[0] = np.arcsin(1.) 1025 rlatu[dy] = -rlatu[0] 1026 1027 # .... calcul aux poles .... 1028 1029 yprimu[0] = 0. 1030 yprimu[dy] = 0. 1031 1032 un4rad2 = 0.25 * rad * rad 1033 1034 # 1035 # -------------------------------------------------------------------- 1036 # -------------------------------------------------------------------- 1037 # - - 1038 # - calcul des aires ( aire,aireu,airev, 1./aire, 1./airez ) - 1039 # - et de fext , force de coriolis extensive . - 1040 # - - 1041 # -------------------------------------------------------------------- 1042 # -------------------------------------------------------------------- 1043 # 1044 # 1045 # 1046 # A 1 point scalaire P (i,j) de la grille, reguliere en (X,Y) , sont 1047 # affectees 4 aires entourant P , calculees respectivement aux points 1048 # ( i + 1/4, j - 1/4 ) : aireij1 (i,j) 1049 # ( i + 1/4, j + 1/4 ) : aireij2 (i,j) 1050 # ( i - 1/4, j + 1/4 ) : aireij3 (i,j) 1051 # ( i - 1/4, j - 1/4 ) : aireij4 (i,j) 1052 # 1053 # , 1054 # Les cotes de chacun de ces 4 carres etant egaux a 1/2 suivant (X,Y). 1055 # Chaque aire centree en 1 point scalaire P(i,j) est egale a la somme 1056 # des 4 aires aireij1,aireij2,aireij3,aireij4 qui sont affectees au 1057 # point (i,j) . 1058 # On definit en outre les coefficients alpha comme etant egaux a 1059 # (aireij / aire), c.a.d par exp. alpha1(i,j)=aireij1(i,j)/aire(i,j) 1060 # 1061 # De meme, toute aire centree en 1 point U est egale a la somme des 1062 # 4 aires aireij1,aireij2,aireij3,aireij4 entourant le point U . 1063 # Idem pour airev, airez . 1064 # 1065 # On a ,pour chaque maille : dX = dY = 1 1066 # 1067 # 1068 # . V 1069 # 1070 # aireij4 . . aireij1 1071 # 1072 # U . . P . U 1073 # 1074 # aireij3 . . aireij2 1075 # 1076 # . V 1077 # 1078 # 1079 # 1080 # 1081 # 1082 # .................................................................... 1083 # 1084 # Calcul des 4 aires elementaires aireij1,aireij2,aireij3,aireij4 1085 # qui entourent chaque aire(i,j) , ainsi que les 4 elongations elemen 1086 # taires cuij et les 4 elongat. cvij qui sont calculees aux memes 1087 # endroits que les aireij . 1088 # 1089 # .................................................................... 1090 # 1091 # ....... do 35 : boucle sur les jjm + 1 latitudes ..... 1092 # 1093 # 1094 for j in range(dy+1): 1095 if j == 1: 1096 yprm = yprimu1[j] 1097 rlatm = rlatu1[j] 1098 1099 coslatm = np.cos( rlatm ) 1100 radclatm = 0.5* rad * coslatm 1101 1102 for i in range(dx): 1103 xprp = xprimp025[i] 1104 xprm = xprimm025[i] 1105 aireij2[0,i] = un4rad2 * coslatm * xprp * yprm 1106 aireij3[0,i] = un4rad2 * coslatm * xprm * yprm 1107 cuij2[0,i] = radclatm * xprp 1108 cuij3[0,i] = radclatm * xprm 1109 cvij2[0,i] = 0.5* rad * yprm 1110 cvij3[0,i] = cvij2[0,i] 1111 1112 for i in range(dx): 1113 aireij1[0,i] = 0. 1114 aireij4[0,i] = 0. 1115 cuij1[0,i] = 0. 1116 cuij4[0,i] = 0. 1117 cvij1[0,i] = 0. 1118 cvij4[0,i] = 0. 1119 1120 elif j == dy: 1121 yprp = yprimu2[j-1] 1122 rlatp = rlatu2[j-1] 1123 1124 coslatp = np.cos( rlatp ) 1125 radclatp = 0.5* rad * coslatp 1126 1127 for i in range(dx): 1128 xprp = xprimp025[i] 1129 xprm = xprimm025[i] 1130 aireij1[dy,i] = un4rad2 * coslatp * xprp * yprp 1131 aireij4[dy,i] = un4rad2 * coslatp * xprm * yprp 1132 cuij1[dy,i] = radclatp * xprp 1133 cuij4[dy,i] = radclatp * xprm 1134 cvij1[dy,i] = 0.5 * rad* yprp 1135 cvij4[dy,i] = cvij1[dy,i] 1136 1137 for i in range(dx): 1138 aireij2[dy,i] = 0. 1139 aireij3[dy,i] = 0. 1140 cvij2[dy,i] = 0. 1141 cvij3[dy,i] = 0. 1142 cuij2[dy,i] = 0. 1143 cuij3[dy,i] = 0. 1144 1145 else: 1146 1147 rlatp = rlatu2[j-1] 1148 yprp = yprimu2[j-1] 1149 rlatm = rlatu1[j] 1150 yprm = yprimu1[j] 1151 1152 coslatm = np.cos( rlatm ) 1153 coslatp = np.cos( rlatp ) 1154 radclatp = 0.5* rad * coslatp 1155 radclatm = 0.5* rad * coslatm 1156 1157 for i in range(dx): 1158 xprp = xprimp025[i] 1159 xprm = xprimm025[i] 1160 1161 ai14 = un4rad2 * coslatp * yprp 1162 ai23 = un4rad2 * coslatm * yprm 1163 aireij1[j,i] = ai14 * xprp 1164 aireij2[j,i] = ai23 * xprp 1165 aireij3[j,i] = ai23 * xprm 1166 aireij4[j,i] = ai14 * xprm 1167 cuij1[j,i] = radclatp * xprp 1168 cuij2[j,i] = radclatm * xprp 1169 cuij3[j,i] = radclatm * xprm 1170 cuij4[j,i] = radclatp * xprm 1171 cvij1[j,i] = 0.5* rad * yprp 1172 cvij2[j,i] = 0.5* rad * yprm 1173 cvij3[j,i] = cvij2[j,i] 1174 cvij4[j,i] = cvij1[j,i] 1175 1176 # 1177 # ........ periodicite ............ 1178 # 1179 cvij1[j,dx] = cvij1[j,0] 1180 cvij2[j,dx] = cvij2[j,0] 1181 cvij3[j,dx] = cvij3[j,0] 1182 cvij4[j,dx] = cvij4[j,0] 1183 cuij1[j,dx] = cuij1[j,0] 1184 cuij2[j,dx] = cuij2[j,0] 1185 cuij3[j,dx] = cuij3[j,0] 1186 cuij4[j,dx] = cuij4[j,0] 1187 aireij1[j,dx] = aireij1[j,0] 1188 aireij2[j,dx] = aireij2[j,0] 1189 aireij3[j,dx] = aireij3[j,0] 1190 aireij4[j,dx] = aireij4[j,0] 1191 1192 # 1193 # .............................................................. 1194 # 1195 for j in range(dy+1): 1196 for i in range(dx): 1197 aire[j,i] = aireij1[j,i] + aireij2[j,i] + aireij3[j,i] + aireij4[j,i] 1198 alpha1[j,i] = aireij1[j,i] / aire[j,i] 1199 alpha2[j,i] = aireij2[j,i] / aire[j,i] 1200 alpha3[j,i] = aireij3[j,i] / aire[j,i] 1201 alpha4[j,i] = aireij4[j,i] / aire[j,i] 1202 alpha1p2[j,i] = alpha1 [j,i] + alpha2 [j,i] 1203 alpha1p4[j,i] = alpha1 [j,i] + alpha4 [j,i] 1204 alpha2p3[j,i] = alpha2 [j,i] + alpha3 [j,i] 1205 alpha3p4[j,i] = alpha3 [j,i] + alpha4 [j,i] 1206 1207 aire[j,dx] = aire[j,0] 1208 alpha1[j,dx] = alpha1[j,0] 1209 alpha2[j,dx] = alpha2[j,0] 1210 alpha3[j,dx] = alpha3[j,0] 1211 alpha4[j,dx] = alpha4[j,0] 1212 alpha1p2[j,dx] = alpha1p2[j,0] 1213 alpha1p4[j,dx] = alpha1p4[j,0] 1214 alpha2p3[j,dx] = alpha2p3[j,0] 1215 alpha3p4[j,dx] = alpha3p4[j,0] 1216 1217 for j in range(dy+1): 1218 for i in range(dx): 1219 aireu[j,i] = aireij1[j,i] + aireij2[j,i] + aireij4[j,i+1] + aireij3[j,i+1] 1220 unsaire[j,i] = 1./ aire[j,i] 1221 unsair_gam1[j,i] = unsaire[j,i]** ( - gamdi_gdiv ) 1222 unsair_gam2[j,i] = unsaire[j,i]** ( - gamdi_h ) 1223 airesurg[j,i] = aire[j,i]/ g 1224 1225 aireu[j,dx] = aireu[j,0] 1226 unsaire[j,dx] = unsaire[j,0] 1227 unsair_gam1[j,dx] = unsair_gam1[j,0] 1228 unsair_gam2[j,dx] = unsair_gam2[j,0] 1229 airesurg[j,dx] = airesurg[j,0] 1230 1231 1232 for j in range(dy): 1233 for i in range(dx): 1234 airev[j,i] = aireij2[j,i]+ aireij3[j,i]+ aireij1[j,i] + aireij4[j+1,i] 1235 1236 for i in range(dx): 1237 airez = aireij2[j,i]+aireij1[j+1,i]+aireij3[j,i+1] + aireij4[j+1,i+1] 1238 unsairez[j,i] = 1./ airez 1239 unsairz_gam[j,i]= unsairez[j,i]** ( - gamdi_grot ) 1240 fext[j,i] = airez * np.sin(rlatv[j])* 2.* omeg 1241 1242 airev[j,dx] = airev[j,0] 1243 unsairez[j,dx] = unsairez[j,0] 1244 fext[j,dx] = fext[j,0] 1245 unsairz_gam[j,dx] = unsairz_gam[j,0] 1246 1247 1248 # 1249 # ..... Calcul des elongations cu,cv, cvu ......... 1250 # 1251 for j in range(dy): 1252 for i in range(dx): 1253 cv[j,i] = 0.5 *( cvij2[j,i]+cvij3[j,i]+cvij1[j+1,i]+cvij4[j+1,i]) 1254 cvu[j,i]= 0.5 *( cvij1[j,i]+cvij4[j,i]+cvij2[j,i]+cvij3[j,i] ) 1255 cuv[j,i]= 0.5 *( cuij2[j,i]+cuij3[j,i]+cuij1[j+1,i]+cuij4[j+1,i]) 1256 unscv2[j,i] = 1./ ( cv[j,i]*cv[j,i] ) 1257 1258 for i in range(dx): 1259 cuvsurcv [j,i] = airev[j,i] * unscv2[j,i] 1260 cvsurcuv [j,i] = 1./cuvsurcv[j,i] 1261 cuvscvgam1[j,i] = cuvsurcv [j,i] ** ( - gamdi_gdiv ) 1262 cuvscvgam2[j,i] = cuvsurcv [j,i] ** ( - gamdi_h ) 1263 cvscuvgam[j,i] = cvsurcuv [j,i] ** ( - gamdi_grot ) 1264 1265 cv[j,dx] = cv[j,0] 1266 cvu[j,dx] = cvu[j,0] 1267 unscv2[j,dx] = unscv2[j,0] 1268 cuv[j,dx] = cuv[j,0] 1269 cuvsurcv[j,dx] = cuvsurcv[j,0] 1270 cvsurcuv[j,dx] = cvsurcuv[j,0] 1271 cuvscvgam1[j,dx] = cuvscvgam1[j,0] 1272 cuvscvgam2[j,dx] = cuvscvgam2[j,0] 1273 cvscuvgam[j,dx] = cvscuvgam[j,0] 1274 1275 1276 for j in range(1,dy): 1277 for i in range(dx): 1278 cu[j,i] = 0.5*(cuij1[j,i]+cuij4[j,i+1]+cuij2[j,i]+cuij3[j,i+1]) 1279 unscu2[j,i] = 1./ ( cu[j,i] * cu[j,i] ) 1280 cvusurcu[j,i] = aireu[j,i] * unscu2[j,i] 1281 cusurcvu[j,i] = 1./ cvusurcu[j,i] 1282 cvuscugam1[j,i] = cvusurcu[j,i] ** ( - gamdi_gdiv ) 1283 cvuscugam2[j,i] = cvusurcu[j,i] ** ( - gamdi_h ) 1284 cuscvugam[j,i] = cusurcvu[j,i] ** ( - gamdi_grot ) 1285 1286 cu[j,dx] = cu[j,0] 1287 unscu2[j,dx] = unscu2[j,0] 1288 cvusurcu[j,dx] = cvusurcu[j,0] 1289 cusurcvu[j,dx] = cusurcvu[j,0] 1290 cvuscugam1[j,dx] = cvuscugam1[j,0] 1291 cvuscugam2[j,dx] = cvuscugam2[j,0] 1292 cuscvugam[j,dx] = cuscvugam[j,0] 1293 1294 # 1295 # .... calcul aux poles .... 1296 # 1297 for i in range(dx+1): 1298 cu[0, i] = 0. 1299 unscu2[0, i] = 0. 1300 cvu[0, i] = 0. 1301 1302 cu[dy,i] = 0. 1303 unscu2[dy,i] = 0. 1304 cvu[dy,i] = 0. 1305 1306 # 1307 # .............................................................. 1308 # 1309 for j in range(dy): 1310 for i in range(dx): 1311 airvscu2[j,i] = airev[j,i]/ ( cuv[j,i] * cuv[j,i] ) 1312 aivscu2gam[j,i] = airvscu2[j,i]** ( - gamdi_grot ) 1313 1314 airvscu2[j,dx] = airvscu2[j,0] 1315 aivscu2gam[j,dx] = aivscu2gam[j,0] 1316 1317 for j in range(dy): 1318 for i in range(dx): 1319 airuscv2[j,i] = aireu[j,i]/ ( cvu[j,i] * cvu[j,i] ) 1320 aiuscv2gam[j,i] = airuscv2[j,i]** ( - gamdi_grot ) 1321 1322 airuscv2[j,dx] = airuscv2[j,0] 1323 aiuscv2gam[j,dx] = aiuscv2gam[j,0] 1324 1325 # 1326 # calcul des aires aux poles : 1327 # ----------------------------- 1328 # 1329 apoln = SSUM(dx,aire[0,0],1) 1330 apols = SSUM(dx,aire[dy,0],1) 1331 unsapolnga1 = 1./ ( apoln ** ( - gamdi_gdiv ) ) 1332 unsapolsga1 = 1./ ( apols ** ( - gamdi_gdiv ) ) 1333 unsapolnga2 = 1./ ( apoln ** ( - gamdi_h ) ) 1334 unsapolsga2 = 1./ ( apols ** ( - gamdi_h ) ) 1335 1336 # 1337 #----------------------------------------------------------------------- 1338 # gtitre='Coriolis version ancienne' 1339 # gfichier='fext1' 1340 # CALL writestd(fext,iip1*jjm) 1341 # 1342 # changement F. Hourdin calcul conservatif pour fext 1343 # constang contient le produit a * cos ( latitude ) * omega 1344 # 1345 for i in range(dx): 1346 constang[0,i] = 0. 1347 1348 for j in range(dy-1): 1349 for i in range(dx): 1350 constang[j+1,i] = rad*omeg*cu[j+1,i]*np.cos(rlatu[j+1]) 1351 1352 for i in range(dx): 1353 constang[dy,i] = 0. 1354 1355 # 1356 # periodicite en longitude 1357 # 1358 for j in range(dy): 1359 fext[j,dx] = fext[j,0] 1360 1361 for j in range(dy+1): 1362 constang[j,dx] = constang[j,0] 1363 1364 # fin du changement 1365 1366 # 1367 #----------------------------------------------------------------------- 1368 # 1369 print ' *** Coordonnees de la grille *** ' 1370 print ' LONGITUDES aux pts. V ( degres ) ' 1371 1372 for i in range(dx+1): 1373 rlonvv[i] = rlonv[i]*180./np.pi 1374 1375 print rlonvv 1376 1377 print ' LATITUDES aux pts. V ( degres ) ' 1378 1379 for i in range(dy): 1380 rlatuu[i] = rlatv[i]*180./np.pi 1381 1382 print rlatuu[dy] 1383 1384 for i in range(dx+1): 1385 rlonvv[i]=rlonu[i]*180./np.pi 1386 1387 print ' LONGITUDES aux pts. U ( degres ) ' 1388 print rlonvv 1389 1390 1391 print ' LATITUDES aux pts. U ( degres ) ' 1392 for i in range(dy+1): 1393 rlatuu[i]=rlatu[i]*180./np.pi 1394 1395 print rlatuu[0:dy+2] 1396 1397 return aire 22 1398 23 1399 def SSUM(n,sx,incx): … … 30 1406 ix = 0 31 1407 32 for i in range(n): 33 ssumv=ssumv+sx[ix] 34 ix=ix+incx 1408 if len(sx.shape) != 0: 1409 for i in range(n): 1410 ssumv=ssumv+sx[ix] 1411 ix=ix+incx 1412 else: 1413 ssumv=ssumv+sx 35 1414 36 1415 return ssumv … … 50 1429 return sy 51 1430 52 def exner_hyb (dx, dy, dz, psv, pv, a lphav, betav):1431 def exner_hyb (dx, dy, dz, psv, pv, aire): 53 1432 """c 54 1433 c Auteurs : P.Le Van , Fr. Hourdin . … … 83 1462 pk = np.zeros((dz, dy, dx), dtype=np.float) 84 1463 pkf = np.zeros((dz, dy, dx), dtype=np.float) 1464 1465 ppn = np.zeros((dy, dx), dtype=np.float) 1466 pps = np.zeros((dy, dx), dtype=np.float) 1467 1468 ip1jm = (dx+1)*dy 85 1469 86 1470 if dz == 1: … … 101 1485 unpl2k = 1.+ 2.* kappa 102 1486 103 for ij in range(ngrid): 104 pks[ij] = cpp * ( ps[ij]/preff ) ** kappa 105 106 for ij in range(iim): 107 ppn[ij] = aire[ij] * pks[ij] 108 pps[ij] = aire[ij+ip1jm] * pks[ij+ip1jm] 1487 for j in range(dy): 1488 for i in range(dx): 1489 pks[j,i] = cpp * ( ps[j,i]/preff ) ** kappa 1490 1491 for j in range(dy): 1492 for i in range(dx): 1493 ppn[j,i] = aire[j,i] * pks[j,i] 1494 pps[j,i] = aire[j,i+ip1jm] * pks[ij+ip1jm] 109 1495 110 1496 xpn = SSUM(iim,ppn,1) /apoln … … 152 1538 # CALL filtreg ( pkf, jmp1, llm, 2, 1, .TRUE., 1 ) 153 1539 154 return pksv, pkv, pkfv 1540 return pksv, pkv, pkfv, aplhav, betav 155 1541 156 1542 def exner_milieu ( ngrid, ps, p,beta, pks, pk, pkf ): … … 187 1573 ppn = np.zeros((iim), dtype=np.float) 188 1574 ppn = np.zeros((iim), dtype=np.float) 1575 1576 ip1jm = (dx+1)*dy 189 1577 190 1578 firstcall = True … … 204 1592 quit(-1) 205 1593 206 207 1594 firstcall = False 208 209 1595 210 1596 #### Specific behaviour for Shallow Water (1 vertical layer) case: 211 1597 if llm == 1: 212 1598 213 1599 # Compute pks(:),pk(:),pkf(:) 214 1600 … … 216 1602 pks[ij] = (cpp/preff) * ps[ij] 217 1603 pk[ij,1] = .5*pks[ij] 218 219 1604 220 1605 pkf = SCOPY( ngrid * llm, pk, 1, pkf, 1 ) … … 291 1676 fname = 'pression' 292 1677 293 press = np.zeros((dz, dy, dx), dtype=np.float) 294 1678 press = np.zeros((dz+1, dy, dx), dtype=np.float) 1679 1680 print 'shape psv:',psv.shape,'press:',press.shape,'ap:',apv.shape,'bp:',bpv.shape 295 1681 for l in range(dz+1): 296 press[l,:,:] = apv[l] + bpv[l]*psv [:,:]1682 press[l,:,:] = apv[l] + bpv[l]*psv 297 1683 298 1684 return press … … 368 1754 dsig = np.zeros((dz), dtype=np.float) 369 1755 dpres = np.zeros((dz), dtype=np.float) 370 ap = np.zeros((dz+1), dtype=np.float)371 bp = np.zeros((dz+1), dtype=np.float)1756 apv = np.zeros((dz+1), dtype=np.float) 1757 bpv = np.zeros((dz+1), dtype=np.float) 372 1758 373 1759 # default scaleheight is 8km for earth … … 412 1798 sig[dz-1]=0. 413 1799 414 bp [0:dz] = np.exp(1.-1./sig[0:dz]**2)415 bp [llmp1-1] = 0.416 417 ap = pa * (sig - bp)1800 bpv[0:dz] = np.exp(1.-1./sig[0:dz]**2) 1801 bpv[llmp1-1] = 0. 1802 1803 apv = pa * (sig - bp) 418 1804 419 1805 elif vert_sampling == 'tropo': … … 427 1813 sig[l] = sig[l+1] + dsig[l] 428 1814 429 bp [0]=1.430 bp [1:dz] = np.exp(1.-1./sig[1:dz]**2)431 bp [llmp1-1] = 0.432 433 ap [0] = 0.434 ap [1:dz+1] = pa*(sig[1:dz+1]-bp[1:dz+1])1815 bpv[0]=1. 1816 bpv[1:dz] = np.exp(1.-1./sig[1:dz]**2) 1817 bpv[llmp1-1] = 0. 1818 1819 apv[0] = 0. 1820 apv[1:dz+1] = pa*(sig[1:dz+1]-bpv[1:dz+1]) 435 1821 436 1822 elif vert_sampling == 'strato': … … 455 1841 sig[l] = sig[l+1] + dsig[l] 456 1842 457 bp [0] = 1.458 bp [1:dz] = np.exp(1.-1./sig[1:dz]**2)459 bp [llmp1-1] = 0.460 461 ap [0] = 0.462 ap [1:dz+1] = pa*(sig[1:dz+1] - bp[1:dz+1])1843 bpv[0] = 1. 1844 bpv[1:dz] = np.exp(1.-1./sig[1:dz]**2) 1845 bpv[llmp1-1] = 0. 1846 1847 apv[0] = 0. 1848 apv[1:dz+1] = pa*(sig[1:dz+1] - bpv[1:dz+1]) 463 1849 464 1850 elif vert_sampling == 'read': … … 475 1861 for l in range(dz+1): 476 1862 values = ncvar.readuce_space(sfobj.readline()) 477 ap [l] = np.float(values[0])478 bp [l] = np.float(values[0])1863 apv[l] = np.float(values[0]) 1864 bpv[l] = np.float(values[0]) 479 1865 480 1866 sfobj.close() 481 if ap [0] == 0. or ap[dz+1] == 0. or bp[0] == 1. or bp[dz+1] == 0.:1867 if apv[0] == 0. or apv[dz+1] == 0. or bpv[0] == 1. or bpv[dz+1] == 0.: 482 1868 print errormsg 483 1869 print ' ' + fname + ': bad ap or bp values !!' 484 1870 print ' k ap bp ___________' 485 1871 for k in range(dz+1): 486 print k, ap [k], bp[k]1872 print k, apv[k], bpv[k] 487 1873 488 1874 else: … … 497 1883 print ' ' + fname + ': k BP AP ________' 498 1884 for k in range(dz+1): 499 print k, bp [k], ap[k]1885 print k, bpv[k], apv[k] 500 1886 501 1887 print 'Niveaux de pressions approximatifs aux centres des' … … 505 1891 506 1892 for l in range(dz): 507 dpres[l] = bp [l] - bp[l+1]508 pnivs[l] = 0.5*( ap [l]+bp[l]*preff + ap[l+1]+bp[l+1]*preff )1893 dpres[l] = bpv[l] - bpv[l+1] 1894 pnivs[l] = 0.5*( apv[l]+bpv[l]*preff + apv[l+1]+bpv[l+1]*preff ) 509 1895 print ' PRESNIVS(', l, ')=', pnivs[l], ' Z ~ ', \ 510 1896 np.log(preff/pnivs[l])*scaleheight, ' DZ ~ ', \ 511 scaleheight*np.log((ap [l]+bp[l]*preff)/\512 np.max([ap [l+1]+bp[l+1]*preff, 1.e-10]))1897 scaleheight*np.log((apv[l]+bpv[l]*preff)/ \ 1898 np.max([apv[l+1]+bpv[l+1]*preff, 1.e-10])) 513 1899 514 1900 print ' ' + fname + ': PRESNIVS [Pa]:', pnivs 515 1901 516 return pnivs 1902 return pnivs, apv, bpv 517 1903 518 1904 … … 536 1922 s = np.zeros((dz), dtype=np.float) 537 1923 sig = np.zeros((dz+1), dtype=np.float) 538 ap = np.zeros((dz+1), dtype=np.float)539 bp = np.zeros((dz+1), dtype=np.float)1924 apv = np.zeros((dz+1), dtype=np.float) 1925 bpv = np.zeros((dz+1), dtype=np.float) 540 1926 541 1927 # Ouverture possible de fichiers typiquement E.T. … … 635 2021 for l in range(dz): 636 2022 newsig = sig_hybrid(sig[l],pa,preff) 637 bp [l] = np.exp(1.-1./(newsig**2))638 ap [l] = pa * (newsig - bp[l] )2023 bpv[l] = np.exp(1.-1./(newsig**2)) 2024 apv[l] = pa * (newsig - bp[l] ) 639 2025 640 2026 bp[llmp1-1] = 0. … … 647 2033 # Pour ne pas passer en coordonnees hybrides 648 2034 for l in range(dz): 649 ap [l] = 0.650 bp [l] = sig[l]651 652 ap [llmp1-1] = 0.2035 apv[l] = 0. 2036 bpv[l] = sig[l] 2037 2038 apv[llmp1-1] = 0. 653 2039 654 2040 bp[llmp1-1] = 0. … … 666 2052 667 2053 for l in range(dz-1): 668 aps[0:dz-1] = 0.5*( ap [0:dz-1]+ap[1:dz])669 bps[0:dz-1] = 0.5*( bp [0:dz-1]+bp[1:dz])2054 aps[0:dz-1] = 0.5*( apv[0:dz-1]+apv[1:dz]) 2055 bps[0:dz-1] = 0.5*( bpv[0:dz-1]+bpv[1:dz]) 670 2056 671 2057 if hybrid: 672 2058 aps[dz-1] = aps[dz-2]**2 / aps[dz-3] 673 bps[dz-1] = 0.5*(bp [dz-1] + bp[dz])2059 bps[dz-1] = 0.5*(bpv[dz-1] + bpv[dz]) 674 2060 else: 675 2061 bps[dz-1] = bps[dz-2]**2 / bps[dz-3] … … 1063 2449 # For extra-terrestrial planets 1064 2450 #presnivs, pseudoalt = presnivs_calc_noterre(opts.znivs, dimz) 1065 presnivs = presnivs_calc(opts.znivs, dimz)2451 presnivs, ap, bp = presnivs_calc(opts.znivs, dimz) 1066 2452 lon, lat = global_lonlat(dimy,dimx) 1067 2453 lonu, latu = global_lonlat(dimy,dimx+1) … … 1119 2505 # 3. Initialize fields (if necessary) 1120 2506 # surface pressure 1121 ps = np.zeros((dimy, dimx), dtype=np.float)1122 2507 1123 2508 if iflag_phys > 2: … … 1125 2510 # "Specify the initial dry mass to be equivalent to 1126 2511 # a global mean surface pressure (101325 minus 245) Pa." 1127 ps = 101080.2512 ps = np.ones((dimy, dimx), dtype=np.float)*101080. 1128 2513 else: 1129 2514 # use reference surface pressure 1130 ps = preff2515 ps = np.ones((dimy, dimx), dtype=np.float)*preff 1131 2516 1132 2517 # ground geopotential … … 1135 2520 p = pression(dimx, dimy, dimz, ap, bp, ps) 1136 2521 2522 aire = inigeom(dimx, dimy) 2523 1137 2524 if opts.pexner == 'hybdrid': 1138 pks, pk, pkf = exner_hyb(ip1jmp1, ps, p, alpha, beta)2525 pks, pk, pkf, alpha, beta = exner_hyb(dimx, dimy, dimz, ps, p, aire) 1139 2526 else: 1140 pks, pk, pkf = exner_milieu(ip1jmp1, ps, p, beta)2527 pks, pk, pkf = exner_milieu(ip1jmp1, dimx, dimy, dimz, ps, p, beta) 1141 2528 1142 2529 masse = massdair(p) -
trunk/tools/lmdz_const.py
r212 r214 66 66 a = 6371229. 67 67 r1sa = np.float(np.float64(1.)/np.float64(a)) 68 #rad = 6371220 69 rad = a*1. 70 omeg = 7.272205e-05 71 68 72 # 69 73 # ----------------------------------------------------------------- … … 92 96 kappa = rd/cpd 93 97 etv = rv/rd-1. 98 cpp = cpd*1. 94 99 # 95 100 # ---------------------------------------------------------------- … … 153 158 type_unsddu=3 154 159 type_unsddv=4 160 161 # Zoom related 162 # 163 fxyhypb = False 164 nitergdiv = 1 165 nitergrot = 2 166 niterh = 2 167 coefdis = 0. 168 ysinus = True
Note: See TracChangeset
for help on using the changeset viewer.