def colp_tendency_jacobson(GR, COLP, UWIND, VWIND, \ dCOLPdt, UFLX, VFLX, FLXDIV): for k in range(0, GR.nz): UFLX[:,:,k][GR.iisjj] = \ (COLP[GR.iisjj_im1] + COLP[GR.iisjj])/2 *\ UWIND[:,:,k][GR.iisjj] * GR.dy VFLX[:,:,k][GR.iijjs] = \ (COLP[GR.iijjs_jm1] + COLP[GR.iijjs])/2 *\ VWIND[:,:,k][GR.iijjs] * GR.dxjs[GR.iijjs] # TODO 1 NECESSARY UFLX = exchange_BC(GR, UFLX) VFLX = exchange_BC(GR, VFLX) for k in range(0, GR.nz): FLXDIV[:,:,k][GR.iijj] = \ ( + UFLX[:,:,k][GR.iijj_ip1] - UFLX[:,:,k][GR.iijj] \ + VFLX[:,:,k][GR.iijj_jp1] - VFLX[:,:,k][GR.iijj] ) \ * GR.dsigma[k] / GR.A[GR.iijj] if i_colp_tendency: dCOLPdt[GR.iijj] = -np.sum(FLXDIV[GR.iijj], axis=2) if COLP_dif_coef > 0: num_diff = COLP_dif_coef * \ ( + COLP[GR.iijj_im1] \ + COLP[GR.iijj_ip1] \ + COLP[GR.iijj_jm1] \ + COLP[GR.iijj_jp1] \ - 2*COLP[GR.iijj ] ) dCOLPdt[GR.iijj] = dCOLPdt[GR.iijj] + num_diff return (dCOLPdt, UFLX, VFLX, FLXDIV)
def diag_geopotential_jacobson(GR, PHI, PHIVB, HSURF, POTT, COLP, PVTF, PVTFVB): PVTF, PVTFVB = diag_pvt_factor(GR, COLP, PVTF, PVTFVB) #phi_vb = HSURF[GR.iijj]*con_g PHIVB[:, :, GR.nzs - 1][GR.iijj] = HSURF[GR.iijj] * con_g PHI[:,:,GR.nz-1][GR.iijj] = PHIVB[:,:,GR.nzs-1][GR.iijj] - con_cp* \ ( POTT[:,:,GR.nz-1][GR.iijj] * \ ( PVTF [:,:,GR.nz-1 ][GR.iijj] \ - PVTFVB[:,:,GR.nzs-1][GR.iijj] ) ) for k in range(GR.nz - 2, -1, -1): kp1 = k + 1 dphi = con_cp * POTT[:,:,kp1][GR.iijj] * \ (PVTFVB[:,:,kp1][GR.iijj] - PVTF[:,:,kp1][GR.iijj]) #phi_vb = PHI[:,:,kp1][GR.iijj] - dphi PHIVB[:, :, kp1][GR.iijj] = PHI[:, :, kp1][GR.iijj] - dphi # phi_k dphi = con_cp * POTT[:,:,k][GR.iijj] * \ (PVTF[:,:,k][GR.iijj] - PVTFVB[:,:,kp1][GR.iijj]) #PHI[:,:,k][GR.iijj] = phi_vb - dphi PHI[:, :, k][GR.iijj] = PHIVB[:, :, kp1][GR.iijj] - dphi dphi = con_cp * POTT[:,:,0][GR.iijj] * \ (PVTFVB[:,:,0][GR.iijj] - PVTF[:,:,0][GR.iijj]) PHIVB[:, :, 0][GR.iijj] = PHI[:, :, 0][GR.iijj] - dphi # TODO 5 NECESSARY PVTF = exchange_BC(GR, PVTF) PVTFVB = exchange_BC(GR, PVTFVB) PHI = exchange_BC(GR, PHI) return (PHI, PHIVB, PVTF, PVTFVB)
def horizontal_advection_VWIND(GR, VWIND, UFLX, VFLX, RFLX, QFLX, SFLX, TFLX, k): RFLX[:,:,k][GR.iijj] = 1/12 * ( VFLX[:,:,k][GR.iijj_im1 ] + \ VFLX[:,:,k][GR.iijj_im1_jp1] +\ 2*( VFLX[:,:,k][GR.iijj ] + \ VFLX[:,:,k][GR.iijj_jp1 ] ) +\ VFLX[:,:,k][GR.iijj_ip1 ] + \ VFLX[:,:,k][GR.iijj_ip1_jp1] ) RFLX = exchange_BC(GR, RFLX) QFLX[:,:,k][GR.iisjjs] = 1/12 * ( UFLX[:,:,k][GR.iisjjs_im1_jm1] + \ UFLX[:,:,k][GR.iisjjs_im1 ] +\ 2*( UFLX[:,:,k][GR.iisjjs_jm1 ] + \ UFLX[:,:,k][GR.iisjjs ] ) +\ UFLX[:,:,k][GR.iisjjs_ip1_jm1] + \ UFLX[:,:,k][GR.iisjjs_ip1 ] ) QFLX = exchange_BC(GR, QFLX) SFLX[:,:,k][GR.iisjj] = 1/24 * ( VFLX[:,:,k][GR.iisjj_im1 ] + \ VFLX[:,:,k][GR.iisjj_im1_jp1] +\ VFLX[:,:,k][GR.iisjj ] + \ VFLX[:,:,k][GR.iisjj_jp1 ] +\ UFLX[:,:,k][GR.iisjj_im1 ] + \ 2*UFLX[:,:,k][GR.iisjj ] +\ UFLX[:,:,k][GR.iisjj_ip1 ] ) SFLX = exchange_BC(GR, SFLX) TFLX[:,:,k][GR.iisjj] = 1/24 * ( VFLX[:,:,k][GR.iisjj_im1 ] + \ VFLX[:,:,k][GR.iisjj_im1_jp1] +\ VFLX[:,:,k][GR.iisjj ] + \ VFLX[:,:,k][GR.iisjj_jp1 ] +\ - UFLX[:,:,k][GR.iisjj_im1 ] - \ 2*UFLX[:,:,k][GR.iisjj ] +\ - UFLX[:,:,k][GR.iisjj_ip1 ] ) TFLX = exchange_BC(GR, TFLX) horAdv_VWIND = + RFLX [:,:,k][GR.iijjs_jm1 ] * \ ( VWIND[:,:,k][GR.iijjs_jm1 ] + VWIND[:,:,k][GR.iijjs ] )/2 \ - RFLX [:,:,k][GR.iijjs ] * \ ( VWIND[:,:,k][GR.iijjs ] + VWIND[:,:,k][GR.iijjs_jp1 ] )/2 \ \ + QFLX [:,:,k][GR.iijjs ] * \ ( VWIND[:,:,k][GR.iijjs_im1 ] + VWIND[:,:,k][GR.iijjs ] )/2 \ - QFLX [:,:,k][GR.iijjs_ip1 ] * \ ( VWIND[:,:,k][GR.iijjs ] + VWIND[:,:,k][GR.iijjs_ip1 ] )/2 \ \ + SFLX [:,:,k][GR.iijjs_jm1 ] * \ ( VWIND[:,:,k][GR.iijjs_im1_jm1] + VWIND[:,:,k][GR.iijjs ] )/2 \ - SFLX [:,:,k][GR.iijjs_ip1 ] * \ ( VWIND[:,:,k][GR.iijjs ] + VWIND[:,:,k][GR.iijjs_ip1_jp1] )/2 \ \ + TFLX [:,:,k][GR.iijjs_ip1_jm1] * \ ( VWIND[:,:,k][GR.iijjs_ip1_jm1] + VWIND[:,:,k][GR.iijjs ] )/2 \ - TFLX [:,:,k][GR.iijjs ] * \ ( VWIND[:,:,k][GR.iijjs ] + VWIND[:,:,k][GR.iijjs_im1_jp1] )/2 return (horAdv_VWIND)
def horizontal_advection_UWIND(GR, UWIND, UFLX, VFLX, BFLX, CFLX, DFLX, EFLX, k): BFLX[:,:,k][GR.iijj] = 1/12 * ( UFLX[:,:,k][GR.iijj_jm1 ] + \ UFLX[:,:,k][GR.iijj_ip1_jm1 ] + \ 2*( UFLX[:,:,k][GR.iijj ] + \ UFLX[:,:,k][GR.iijj_ip1 ] ) + \ UFLX[:,:,k][GR.iijj_jp1 ] + \ UFLX[:,:,k][GR.iijj_ip1_jp1 ] ) BFLX = exchange_BC(GR, BFLX) CFLX[:,:,k][GR.iisjjs] = 1/12 * ( VFLX[:,:,k][GR.iisjjs_im1_jm1] + \ VFLX[:,:,k][GR.iisjjs_jm1 ] +\ 2*( VFLX[:,:,k][GR.iisjjs_im1 ] + \ VFLX[:,:,k][GR.iisjjs ] ) +\ VFLX[:,:,k][GR.iisjjs_im1_jp1] + \ VFLX[:,:,k][GR.iisjjs_jp1 ] ) CFLX = exchange_BC(GR, CFLX) DFLX[:,:,k][GR.iijjs] = 1/24 * ( VFLX[:,:,k][GR.iijjs_jm1 ] + \ 2*VFLX[:,:,k][GR.iijjs ] +\ VFLX[:,:,k][GR.iijjs_jp1 ] + \ UFLX[:,:,k][GR.iijjs_jm1 ] +\ UFLX[:,:,k][GR.iijjs ] + \ UFLX[:,:,k][GR.iijjs_ip1_jm1 ] +\ UFLX[:,:,k][GR.iijjs_ip1 ] ) DFLX = exchange_BC(GR, DFLX) EFLX[:,:,k][GR.iijjs] = 1/24 * ( VFLX[:,:,k][GR.iijjs_jm1 ] + \ 2*VFLX[:,:,k][GR.iijjs ] +\ VFLX[:,:,k][GR.iijjs_jp1 ] - \ UFLX[:,:,k][GR.iijjs_jm1 ] +\ - UFLX[:,:,k][GR.iijjs ] - \ UFLX[:,:,k][GR.iijjs_ip1_jm1 ] +\ - UFLX[:,:,k][GR.iijjs_ip1 ] ) EFLX = exchange_BC(GR, EFLX) horAdv_UWIND = + BFLX [:,:,k][GR.iisjj_im1 ] * \ ( UWIND[:,:,k][GR.iisjj_im1 ] + UWIND[:,:,k][GR.iisjj ] )/2 \ - BFLX [:,:,k][GR.iisjj ] * \ ( UWIND[:,:,k][GR.iisjj ] + UWIND[:,:,k][GR.iisjj_ip1 ] )/2 \ \ + CFLX [:,:,k][GR.iisjj ] * \ ( UWIND[:,:,k][GR.iisjj_jm1 ] + UWIND[:,:,k][GR.iisjj ] )/2 \ - CFLX [:,:,k][GR.iisjj_jp1 ] * \ ( UWIND[:,:,k][GR.iisjj ] + UWIND[:,:,k][GR.iisjj_jp1 ] )/2 \ \ + DFLX [:,:,k][GR.iisjj_im1 ] * \ ( UWIND[:,:,k][GR.iisjj_im1_jm1] + UWIND[:,:,k][GR.iisjj ] )/2 \ - DFLX [:,:,k][GR.iisjj_jp1 ] * \ ( UWIND[:,:,k][GR.iisjj ] + UWIND[:,:,k][GR.iisjj_ip1_jp1] )/2 \ \ + EFLX [:,:,k][GR.iisjj ] * \ ( UWIND[:,:,k][GR.iisjj_ip1_jm1] + UWIND[:,:,k][GR.iisjj ] )/2 \ - EFLX [:,:,k][GR.iisjj_im1_jp1] * \ ( UWIND[:,:,k][GR.iisjj ] + UWIND[:,:,k][GR.iisjj_im1_jp1] )/2 return (horAdv_UWIND)
def height_tendency_jacobson(GR, HGHT, UWIND, VWIND, UFLX, VFLX): UFLX[GR.iisjj] = \ (HGHT[GR.iisjj_im1] + HGHT[GR.iisjj])/2 * UWIND[GR.iisjj] * GR.dy UFLX = exchange_BC(GR, UFLX) VFLX[GR.iijjs] = \ (HGHT[GR.iijjs_jm1] + HGHT[GR.iijjs])/2 * VWIND[GR.iijjs] * GR.dxjs[GR.iijjs] VFLX = exchange_BC(GR, VFLX) fluxdiv = ( - (UFLX[GR.iijj_ip1] - UFLX[GR.iijj]) - \ (VFLX[GR.iijj_jp1] - VFLX[GR.iijj]) ) \ / GR.A[GR.iijj] dHGHTdt = fluxdiv if i_pseudo_radiation: radiation = - outRate*HGHT[GR.iijj] + inpRate*np.cos(GR.lat_rad[GR.iijj]) dHGHTdt += radiation return(dHGHTdt, UFLX, VFLX)
def RK_time_step(GR, COLP0, UWIND0, VWIND0, POTT0, QV0, QC0, \ COLP1, UWIND1, VWIND1, POTT1, QV1, QC1, \ dCOLP, dUFLX, dVFLX, dPOTT, dQV, dQC, factor): COLPA_is_0, COLPA_js_0 = interp_COLPA(GR, COLP0) COLP1[GR.iijj] = COLP0[GR.iijj] + dCOLP / factor COLP1 = exchange_BC(GR, COLP1) COLPA_is_1, COLPA_js_1 = interp_COLPA(GR, COLP1) for k in range(0, GR.nz): UWIND1[:,:,k][GR.iisjj] = UWIND0[:,:,k][GR.iisjj] * \ COLPA_is_0/COLPA_is_1 + dUFLX[:,:,k]/factor/COLPA_is_1 VWIND1[:,:,k][GR.iijjs] = VWIND0[:,:,k][GR.iijjs] * \ COLPA_js_0/COLPA_js_1 + dVFLX[:,:,k]/factor/COLPA_js_1 POTT1[:,:,k][GR.iijj] = POTT0[:,:,k][GR.iijj] * \ COLP0[GR.iijj]/COLP1[GR.iijj] + \ dPOTT[:,:,k]/factor/COLP1[GR.iijj] QV1[:,:,k][GR.iijj] = QV0[:,:,k][GR.iijj] * \ COLP0[GR.iijj]/COLP1[GR.iijj] + \ dQV[:,:,k]/factor/COLP1[GR.iijj] QC1[:,:,k][GR.iijj] = QC0[:,:,k][GR.iijj] * \ COLP0[GR.iijj]/COLP1[GR.iijj] + \ dQC[:,:,k]/factor/COLP1[GR.iijj] QV1[QV1 < 0] = 0 QC1[QC1 < 0] = 0 # TODO 4 NECESSARY UWIND1 = exchange_BC(GR, UWIND1) VWIND1 = exchange_BC(GR, VWIND1) POTT1 = exchange_BC(GR, POTT1) QV1 = exchange_BC(GR, QV1) QC1 = exchange_BC(GR, QC1) return (COLP1, UWIND1, VWIND1, POTT1, QV1, QC1)
def height_tendency_upstream(GR, HGHT, UWIND, VWIND, UFLX, VFLX): UFLX[GR.iisjj] = \ GR.dy * (np.maximum(UWIND[GR.iisjj],0) * HGHT[GR.iisjj_im1] + \ np.minimum(UWIND[GR.iisjj],0) * HGHT[GR.iisjj]) UFLX = exchange_BC(GR, UFLX) VFLX[GR.iijjs] = \ GR.dxjs[GR.iijjs] * ( np.maximum(VWIND[GR.iijjs],0) * HGHT[GR.iijjs_jm1] + \ np.minimum(VWIND[GR.iijjs],0) * HGHT[GR.iijjs] ) VFLX = exchange_BC(GR, VFLX) fluxdiv = ( - (UFLX[GR.iijj_ip1] - UFLX[GR.iijj]) - \ (VFLX[GR.iijj_jp1] - VFLX[GR.iijj]) ) \ / GR.A[GR.iijj] dHGHTdt = fluxdiv if i_pseudo_radiation: radiation = - outRate*HGHT[GR.iijj] + inpRate*np.cos(GR.lat_rad[GR.iijj]) dHGHTdt += radiation return(dHGHTdt)
def initialize_fields(GR, subgrids, CF): if i_load_from_restart: CF, RAD, SURF, MIC, TURB = load_restart_fields(GR) else: #################################################################### # SET INITIAL FIELD VALUES #################################################################### # need to have non-nan-values because values from half-level 0 and GR.nzs # are used in calculation. CF.POTTVB[:] = 0 CF.WWIND[:] = 0 # LOAD TOPOGRAPHY (HSURF) CF.HSURF = load_topo_old(GR, CF.HSURF) if not i_use_topo: CF.HSURF[GR.iijj] = 0. CF.HSURF = exchange_BC(GR, CF.HSURF) # INITIALIZE PROFILE GR, CF.COLP, CF.PSURF, CF.POTT, CF.TAIR \ = load_profile_old(GR, subgrids, CF.COLP, CF.HSURF, CF.PSURF, CF.PVTF, \ CF.PVTFVB, CF.POTT, CF.TAIR) # INITIAL CONDITIONS CF.COLP = gaussian2D(GR, CF.COLP, COLP_gaussian_pert, np.pi*3/4, 0, \ gaussian_dlon, gaussian_dlat) CF.COLP = random2D(GR, CF.COLP, COLP_random_pert) for k in range(0, GR.nz): CF.UWIND[:, :, k][GR.iisjj] = u0 CF.UWIND[:,:,k] = gaussian2D(GR, CF.UWIND[:,:,k], UWIND_gaussian_pert, \ np.pi*3/4, 0, gaussian_dlon, gaussian_dlat) CF.UWIND[:, :, k] = random2D(GR, CF.UWIND[:, :, k], UWIND_random_pert) CF.VWIND[:, :, k][GR.iijjs] = v0 CF.VWIND[:,:,k] = gaussian2D(GR, CF.VWIND[:,:,k], VWIND_gaussian_pert, \ np.pi*3/4, 0, gaussian_dlon, gaussian_dlat) CF.VWIND[:, :, k] = random2D(GR, CF.VWIND[:, :, k], VWIND_random_pert) CF.POTT[:,:,k] = gaussian2D(GR, CF.POTT[:,:,k], POTT_gaussian_pert, \ np.pi*3/4, 0, gaussian_dlon, gaussian_dlat) CF.POTT[:, :, k] = random2D(GR, CF.POTT[:, :, k], POTT_random_pert) # BOUNDARY EXCHANGE OF INITIAL CONDITIONS CF.COLP = exchange_BC(GR, CF.COLP) CF.UWIND = exchange_BC(GR, CF.UWIND) CF.VWIND = exchange_BC(GR, CF.VWIND) CF.POTT = exchange_BC(GR, CF.POTT) # PRIMARY DIAGNOSTIC FIELDS #diagnose_fields_jacobson(GR, CF, on_host=True) diagnose_fields_initializaiton(GR, CF) # SECONDARY DIAGNOSTIC FIELDS CF.PAIR, CF.TAIR, CF.TAIRVB, CF.RHO, CF.WIND = \ diagnose_secondary_fields(GR, CF.COLP, CF.PAIR, CF.PHI, CF.POTT, CF.POTTVB, CF.TAIR, CF.TAIRVB, CF.RHO,\ CF.PVTF, CF.PVTFVB, CF.UWIND, CF.VWIND, CF.WIND) #################################################################### # INITIALIZE NON-ATMOSPHERIC COMPONENTS #################################################################### # SURF MODEL if i_surface_scheme: SURF = surface(GR, CF) else: SURF = None #################################################################### # INITIALIZE PROCESSES #################################################################### # MOISTURE & MICROPHYSICS if i_microphysics: MIC = microphysics(GR, CF, i_microphysics, CF.TAIR, CF.PAIR) else: MIC = None # RADIATION if i_radiation: if SURF is None: raise ValueError('Soil model must be used for i_radiation > 0') RAD = radiation(GR, i_radiation) rad_njobs_orig = RAD.njobs_rad RAD.njobs_rad = 4 RAD.calc_radiation(GR, CF) RAD.njobs_rad = rad_njobs_orig else: RAD = None # TURBULENCE if i_turbulence: raise NotImplementedError('Baustelle') TURB = turbulence(GR, i_turbulence) else: TURB = None return (CF, RAD, SURF, MIC, TURB)
def tendencies_jacobson(GR, GR_NEW, F, subgrids, NF): ############################## ############################## GR.timer.start('cont') if i_run_new_style == 1: if comp_mode == 1: NF.old_to_new(F, host=True) Tendencies.continuity(HOST, GR_NEW, **NF.get(Tendencies.fields_continuity, target=HOST)) NF.new_to_old(F, host=True) elif comp_mode == 2: NF.old_to_new(F, host=False) Tendencies.continuity(DEVICE, GR_NEW, **NF.get(Tendencies.fields_continuity, target=DEVICE)) NF.new_to_old(F, host=False) else: # PROGNOSE COLP if comp_mode == 1: F.dCOLPdt, F.UFLX, F.VFLX, F.FLXDIV = colp_tendency_jacobson_c(GR, F.COLP, F.UWIND, F.VWIND, F.dCOLPdt, F.UFLX, F.VFLX, F.FLXDIV) F.dCOLPdt = np.asarray(F.dCOLPdt) F.UFLX = np.asarray(F.UFLX) F.VFLX = np.asarray(F.VFLX) F.FLXDIV = np.asarray(F.FLXDIV) F.COLP_NEW[GR.iijj] = F.COLP_OLD[GR.iijj] + GR.dt*F.dCOLPdt[GR.iijj] elif comp_mode == 2: F.dCOLPdt, F.UFLX, F.VFLX, F.FLXDIV = \ colp_tendency_jacobson_gpu(GR, GR.griddim, GR.blockdim, GR.stream, F.dCOLPdt, F.UFLX, F.VFLX, F.FLXDIV, F.COLP, F.UWIND, F.VWIND, GR.dy, GR.dxjsd, GR.Ad, GR.dsigmad) time_step_2D[GR.griddim, GR.blockdim, GR.stream]\ (F.COLP_NEW, F.COLP_OLD, F.dCOLPdt, GR.dt) GR.stream.synchronize() # DIAGNOSE WWIND if comp_mode == 1: F.WWIND = vertical_wind_jacobson_c(GR, F.COLP_NEW, F.dCOLPdt, F.FLXDIV, F.WWIND) F.WWIND = np.asarray(F.WWIND) F.COLP_NEW = exchange_BC(GR, F.COLP_NEW) F.WWIND = exchange_BC(GR, F.WWIND) elif comp_mode == 2: vertical_wind_jacobson_gpu[GR.griddim_ks, GR.blockdim_ks, GR.stream]\ (F.WWIND, F.dCOLPdt, F.FLXDIV, F.COLP_NEW, GR.sigma_vbd) GR.stream.synchronize() F.COLP_NEW = exchange_BC_gpu(F.COLP_NEW, GR.zonal, GR.merid, GR.griddim_xy, GR.blockdim_xy, GR.stream, array2D=True) F.WWIND = exchange_BC_gpu(F.WWIND, GR.zonalvb, GR.meridvb, GR.griddim_ks, GR.blockdim_ks, GR.stream) GR.timer.stop('cont') ############################## ############################## ############################## ############################## GR.timer.start('wind') # PROGNOSE WIND if comp_mode == 1: if i_run_new_style == 1: NF.old_to_new(F, host=True) Tendencies.momentum(HOST, GR_NEW, **NF.get(Tendencies.fields_momentum, target=HOST)) NF.new_to_old(F, host=True) else: F.dUFLXdt, F.dVFLXdt = wind_tendency_jacobson_c(GR, njobs, F.UWIND, F.VWIND, F.WWIND, F.UFLX, F.dUFLXdt, F.VFLX, F.dVFLXdt, F.BFLX, F.CFLX, F.DFLX, F.EFLX, F.RFLX, F.QFLX, F.SFLX, F.TFLX, F.WWIND_UWIND, F.WWIND_VWIND, F.COLP, F.COLP_NEW, F.PHI, F.POTT, F.PVTF, F.PVTFVB) F.dUFLXdt = np.asarray(F.dUFLXdt) F.dVFLXdt = np.asarray(F.dVFLXdt) elif comp_mode == 2: if i_run_new_style == 1: NF.old_to_new(F, host=False) Tendencies.momentum(DEVICE, GR_NEW, **NF.get(Tendencies.fields_momentum, target=DEVICE)) NF.new_to_old(F, host=False) else: F.dUFLXdt, F.dVFLXdt = wind_tendency_jacobson_gpu(GR, F.UWIND, F.VWIND, F.WWIND, F.UFLX, F.dUFLXdt, F.VFLX, F.dVFLXdt, F.BFLX, F.CFLX, F.DFLX, F.EFLX, F.RFLX, F.QFLX, F.SFLX, F.TFLX, F.WWIND_UWIND, F.WWIND_VWIND, F.COLP, F.COLP_NEW, F.PHI, F.POTT, F.PVTF, F.PVTFVB) GR.timer.stop('wind') ############################## ############################## ############################## ############################## GR.timer.start('temp') # PROGNOSE POTT if comp_mode == 1: if i_run_new_style == 1: NF.old_to_new(F, host=True) Tendencies.temperature(HOST, GR_NEW, **NF.get(Tendencies.fields_temperature, target=HOST)) NF.new_to_old(F, host=True) else: F.dPOTTdt = temperature_tendency_jacobson_c(GR, njobs, F.POTT, F.POTTVB, F.COLP, F.COLP_NEW, F.UFLX, F.VFLX, F.WWIND, F.dPOTTdt_RAD, F.dPOTTdt_MIC) F.dPOTTdt = np.asarray(F.dPOTTdt) elif comp_mode == 2: if i_run_new_style == 0: F.COLP = cp.expand_dims(F.COLP, axis=2) F.COLP_NEW = cp.expand_dims(F.COLP_NEW, axis=2) NF.old_to_new(F, host=False) Tendencies.temperature(DEVICE, GR_NEW, **NF.get(Tendencies.fields_temperature, target=DEVICE)) NF.new_to_old(F, host=False) if i_run_new_style == 0: F.COLP = F.COLP.squeeze() F.COLP_NEW = F.COLP_NEW.squeeze() GR.timer.stop('temp')
[SGR.SGRmap_out_iijj]) MIC.QC[SGR.GRmap_in_iijj] = np.asarray(results[job_ind][1]['QC'] \ [SGR.SGRmap_out_iijj]) for job_ind in range(0, njobs): SGR = subgrids[job_ind] for proc in processes: proc.join() #quit() time1 = time.time() print(time1 - time0) UFLX = exchange_BC(GR, UFLX) VFLX = exchange_BC(GR, VFLX) COLP = exchange_BC(GR, COLP) WWIND = exchange_BC(GR, WWIND) UWIND = exchange_BC(GR, UWIND) VWIND = exchange_BC(GR, VWIND) POTT = exchange_BC(GR, POTT) MIC.QV = exchange_BC(GR, MIC.QV) MIC.QC = exchange_BC(GR, MIC.QC) PHI = exchange_BC(GR, PHI) #print(UFLX[:,:,1].T) #print(VFLX[:,:,1].T) #print() #print(UFLX.shape)
def RK4(GR, HGHT, TRACER, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP, VFLXMP, UUFLX, UVFLX, VUFLX, VVFLX, HSURF, i_spatial_discretization): if i_spatial_discretization == 'UPWIND': ########## level 1 dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind( GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP, VFLXMP, UUFLX, UVFLX, VUFLX, VVFLX) # has to happen after masspoint_flux_tendency function UFLXMP_OLD = copy.deepcopy(UFLXMP) VFLXMP_OLD = copy.deepcopy(VFLXMP) HGHT_OLD = copy.deepcopy(HGHT) TRACER_OLD = copy.deepcopy(TRACER) UFLXMP_INT = copy.deepcopy(UFLXMP) VFLXMP_INT = copy.deepcopy(VFLXMP) HGHT_INT = copy.deepcopy(HGHT) TRACER_INT = copy.deepcopy(TRACER) dUFLXMP = GR.dt * dUFLXMPdt dVFLXMP = GR.dt * dVFLXMPdt dHGHT = GR.dt * dHGHTdt dTRACER = GR.dt * dTRACERdt UFLXMP_INT[GR.iijj] = UFLXMP_OLD[GR.iijj] + dUFLXMP / 2 VFLXMP_INT[GR.iijj] = VFLXMP_OLD[GR.iijj] + dVFLXMP / 2 HGHT_INT[GR.iijj] = HGHT_OLD[GR.iijj] + dHGHT / 2 TRACER_INT[GR.iijj] = TRACER_OLD[GR.iijj] + dTRACER / 2 UFLXMP_INT = exchange_BC(GR, UFLXMP_INT) VFLXMP_INT = exchange_BC(GR, VFLXMP_INT) HGHT_INT = exchange_BC(GR, HGHT_INT) TRACER_INT = exchange_BC(GR, TRACER_INT) UFLXMP[GR.iijj] = UFLXMP_OLD[GR.iijj] + dUFLXMP / 6 VFLXMP[GR.iijj] = VFLXMP_OLD[GR.iijj] + dVFLXMP / 6 HGHT[GR.iijj] = HGHT_OLD[GR.iijj] + dHGHT / 6 TRACER[GR.iijj] = TRACER_OLD[GR.iijj] + dTRACER / 6 UWIND, VWIND = diagnose_fields_upwind(GR, HGHT_INT, TRACER_INT, UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF) ########## level 2 dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind( GR, HGHT_INT, TRACER_INT, HSURF, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP_INT, VFLXMP_INT, UUFLX, UVFLX, VUFLX, VVFLX) dUFLXMP = GR.dt * dUFLXMPdt dVFLXMP = GR.dt * dVFLXMPdt dHGHT = GR.dt * dHGHTdt dTRACER = GR.dt * dTRACERdt UFLXMP_INT[GR.iijj] = UFLXMP_OLD[GR.iijj] + dUFLXMP / 2 VFLXMP_INT[GR.iijj] = VFLXMP_OLD[GR.iijj] + dVFLXMP / 2 HGHT_INT[GR.iijj] = HGHT_OLD[GR.iijj] + dHGHT / 2 TRACER_INT[GR.iijj] = TRACER_OLD[GR.iijj] + dTRACER / 2 UFLXMP_INT = exchange_BC(GR, UFLXMP_INT) VFLXMP_INT = exchange_BC(GR, VFLXMP_INT) HGHT_INT = exchange_BC(GR, HGHT_INT) TRACER_INT = exchange_BC(GR, TRACER_INT) UFLXMP[GR.iijj] = UFLXMP[GR.iijj] + dUFLXMP / 3 VFLXMP[GR.iijj] = VFLXMP[GR.iijj] + dVFLXMP / 3 HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 3 TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 3 UWIND, VWIND = diagnose_fields_upwind(GR, HGHT_INT, TRACER_INT, UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF) ########## level 3 dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind( GR, HGHT_INT, TRACER_INT, HSURF, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP_INT, VFLXMP_INT, UUFLX, UVFLX, VUFLX, VVFLX) dUFLXMP = GR.dt * dUFLXMPdt dVFLXMP = GR.dt * dVFLXMPdt dHGHT = GR.dt * dHGHTdt dTRACER = GR.dt * dTRACERdt UFLXMP_INT[GR.iijj] = UFLXMP_OLD[GR.iijj] + dUFLXMP VFLXMP_INT[GR.iijj] = VFLXMP_OLD[GR.iijj] + dVFLXMP HGHT_INT[GR.iijj] = HGHT_OLD[GR.iijj] + dHGHT TRACER_INT[GR.iijj] = TRACER_OLD[GR.iijj] + dTRACER UFLXMP_INT = exchange_BC(GR, UFLXMP_INT) VFLXMP_INT = exchange_BC(GR, VFLXMP_INT) HGHT_INT = exchange_BC(GR, HGHT_INT) TRACER_INT = exchange_BC(GR, TRACER_INT) UFLXMP[GR.iijj] = UFLXMP[GR.iijj] + dUFLXMP / 3 VFLXMP[GR.iijj] = VFLXMP[GR.iijj] + dVFLXMP / 3 HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 3 TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 3 UWIND, VWIND = diagnose_fields_upwind(GR, HGHT_INT, TRACER_INT, UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF) ########## level 4 dHGHTdt, dUFLXMPdt, dVFLXMPdt, dTRACERdt = tendencies_upwind( GR, HGHT_INT, TRACER_INT, HSURF, UWIND, VWIND, WIND, UFLX, VFLX, UFLXMP_INT, VFLXMP_INT, UUFLX, UVFLX, VUFLX, VVFLX) dUFLXMP = GR.dt * dUFLXMPdt dVFLXMP = GR.dt * dVFLXMPdt dHGHT = GR.dt * dHGHTdt dTRACER = GR.dt * dTRACERdt UFLXMP[GR.iijj] = UFLXMP[GR.iijj] + dUFLXMP / 6 VFLXMP[GR.iijj] = VFLXMP[GR.iijj] + dVFLXMP / 6 HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 6 TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 6 UFLXMP = exchange_BC(GR, UFLXMP) VFLXMP = exchange_BC(GR, VFLXMP) HGHT = exchange_BC(GR, HGHT) TRACER = exchange_BC(GR, TRACER) UWIND, VWIND = diagnose_fields_upwind(GR, HGHT, TRACER, UWIND, VWIND, UFLXMP, VFLXMP, HSURF) elif i_spatial_discretization == 'JACOBSON': ########## level 1 dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson( GR, HGHT, TRACER, HSURF, UWIND, VWIND, WIND, UFLX, VFLX) # has to happen after masspoint_flux_tendency function UWIND_START = copy.deepcopy(UWIND) VWIND_START = copy.deepcopy(VWIND) HGHT_START = copy.deepcopy(HGHT) TRACER_START = copy.deepcopy(TRACER) UWIND_INT = copy.deepcopy(UWIND) VWIND_INT = copy.deepcopy(VWIND) HGHT_INT = copy.deepcopy(HGHT) TRACER_INT = copy.deepcopy(TRACER) dUFLX = GR.dt * dUFLXdt dVFLX = GR.dt * dVFLXdt dHGHT = GR.dt * dHGHTdt dTRACER = GR.dt * dTRACERdt # TIME STEPPING HGHTA_is_START, HGHTA_js_START = interp_HGHTA(GR, HGHT_START) HGHT_INT[GR.iijj] = HGHT_START[GR.iijj] + dHGHT / 2 HGHT_INT = exchange_BC(GR, HGHT_INT) HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT_INT) UWIND_INT[GR.iisjj] = UWIND_START[GR.iisjj] * HGHTA_is_START/HGHTA_is_NEW \ + dUFLX/2/HGHTA_is_NEW VWIND_INT[GR.iijjs] = VWIND_START[GR.iijjs] * HGHTA_js_START/HGHTA_js_NEW \ + dVFLX/2/HGHTA_js_NEW UWIND_INT = exchange_BC(GR, UWIND_INT) VWIND_INT = exchange_BC(GR, VWIND_INT) TRACER_INT[GR.iijj] = TRACER_START[GR.iijj] + dTRACER / 2 TRACER_INT = exchange_BC(GR, TRACER_INT) HGHTA_is_START, HGHTA_js_START = interp_HGHTA(GR, HGHT_START) HGHT[GR.iijj] = HGHT_START[GR.iijj] + dHGHT / 6 HGHT = exchange_BC(GR, HGHT) HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT) UWIND[GR.iisjj] = UWIND_START[GR.iisjj] * HGHTA_is_START/HGHTA_is_NEW \ + dUFLX/6/HGHTA_is_NEW VWIND[GR.iijjs] = VWIND_START[GR.iijjs] * HGHTA_js_START/HGHTA_js_NEW \ + dVFLX/6/HGHTA_js_NEW UWIND = exchange_BC(GR, UWIND) VWIND = exchange_BC(GR, VWIND) TRACER[GR.iijj] = TRACER_START[GR.iijj] + dTRACER / 6 TRACER = exchange_BC(GR, TRACER) #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT_INT, TRACER_INT, # UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF) ########## level 2 dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson( GR, HGHT_INT, TRACER_INT, HSURF, UWIND_INT, VWIND_INT, WIND, UFLX, VFLX) dUFLX = GR.dt * dUFLXdt dVFLX = GR.dt * dVFLXdt dHGHT = GR.dt * dHGHTdt dTRACER = GR.dt * dTRACERdt HGHT_INT[GR.iijj] = HGHT_START[GR.iijj] + dHGHT / 2 HGHT_INT = exchange_BC(GR, HGHT_INT) HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT_INT) UWIND_INT[GR.iisjj] = UWIND_START[GR.iisjj] * HGHTA_is_START/HGHTA_is_NEW \ + dUFLX/2/HGHTA_is_NEW VWIND_INT[GR.iijjs] = VWIND_START[GR.iijjs] * HGHTA_js_START/HGHTA_js_NEW \ + dVFLX/2/HGHTA_js_NEW UWIND_INT = exchange_BC(GR, UWIND_INT) VWIND_INT = exchange_BC(GR, VWIND_INT) TRACER_INT[GR.iijj] = TRACER_START[GR.iijj] + dTRACER / 2 TRACER_INT = exchange_BC(GR, TRACER_INT) HGHT_OLD = copy.deepcopy(HGHT) HGHTA_is_OLD, HGHTA_js_OLD = interp_HGHTA(GR, HGHT_OLD) HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 3 HGHT = exchange_BC(GR, HGHT) HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT) UWIND[GR.iisjj] = UWIND[GR.iisjj] * HGHTA_is_OLD/HGHTA_is_NEW \ + dUFLX/3/HGHTA_is_NEW VWIND[GR.iijjs] = VWIND[GR.iijjs] * HGHTA_js_OLD/HGHTA_js_NEW \ + dVFLX/3/HGHTA_js_NEW UWIND = exchange_BC(GR, UWIND) VWIND = exchange_BC(GR, VWIND) TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 3 TRACER = exchange_BC(GR, TRACER) #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT_INT, TRACER_INT, # UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF) ########## level 3 dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson( GR, HGHT_INT, TRACER_INT, HSURF, UWIND_INT, VWIND_INT, WIND, UFLX, VFLX) dUFLX = GR.dt * dUFLXdt dVFLX = GR.dt * dVFLXdt dHGHT = GR.dt * dHGHTdt dTRACER = GR.dt * dTRACERdt HGHT_INT[GR.iijj] = HGHT_START[GR.iijj] + dHGHT HGHT_INT = exchange_BC(GR, HGHT_INT) HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT_INT) UWIND_INT[GR.iisjj] = UWIND_START[GR.iisjj] * HGHTA_is_START/HGHTA_is_NEW \ + dUFLX/HGHTA_is_NEW VWIND_INT[GR.iijjs] = VWIND_START[GR.iijjs] * HGHTA_js_START/HGHTA_js_NEW \ + dVFLX/HGHTA_js_NEW UWIND_INT = exchange_BC(GR, UWIND_INT) VWIND_INT = exchange_BC(GR, VWIND_INT) TRACER_INT[GR.iijj] = TRACER_START[GR.iijj] + dTRACER TRACER_INT = exchange_BC(GR, TRACER_INT) HGHT_OLD = copy.deepcopy(HGHT) HGHTA_is_OLD, HGHTA_js_OLD = interp_HGHTA(GR, HGHT_OLD) HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 3 HGHT = exchange_BC(GR, HGHT) HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT) UWIND[GR.iisjj] = UWIND[GR.iisjj] * HGHTA_is_OLD/HGHTA_is_NEW \ + dUFLX/3/HGHTA_is_NEW VWIND[GR.iijjs] = VWIND[GR.iijjs] * HGHTA_js_OLD/HGHTA_js_NEW \ + dVFLX/3/HGHTA_js_NEW UWIND = exchange_BC(GR, UWIND) VWIND = exchange_BC(GR, VWIND) TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 3 TRACER = exchange_BC(GR, TRACER) #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT_INT, TRACER_INT, # UWIND, VWIND, UFLXMP_INT, VFLXMP_INT, HSURF) ########## level 4 dHGHTdt, dUFLXdt, dVFLXdt, dTRACERdt = tendencies_jacobson( GR, HGHT_INT, TRACER_INT, HSURF, UWIND_INT, VWIND_INT, WIND, UFLX, VFLX) dUFLX = GR.dt * dUFLXdt dVFLX = GR.dt * dVFLXdt dHGHT = GR.dt * dHGHTdt dTRACER = GR.dt * dTRACERdt HGHT_OLD = copy.deepcopy(HGHT) HGHTA_is_OLD, HGHTA_js_OLD = interp_HGHTA(GR, HGHT_OLD) HGHT[GR.iijj] = HGHT[GR.iijj] + dHGHT / 6 HGHT = exchange_BC(GR, HGHT) HGHTA_is_NEW, HGHTA_js_NEW = interp_HGHTA(GR, HGHT) UWIND[GR.iisjj] = UWIND[GR.iisjj] * HGHTA_is_OLD/HGHTA_is_NEW \ + dUFLX/6/HGHTA_is_NEW VWIND[GR.iijjs] = VWIND[GR.iijjs] * HGHTA_js_OLD/HGHTA_js_NEW \ + dVFLX/6/HGHTA_js_NEW UWIND = exchange_BC(GR, UWIND) VWIND = exchange_BC(GR, VWIND) TRACER[GR.iijj] = TRACER[GR.iijj] + dTRACER / 6 TRACER = exchange_BC(GR, TRACER) #UWIND, VWIND = diagnose_fields_jacobson(GR, HGHT, TRACER, # UWIND, VWIND, UFLXMP, VFLXMP, HSURF) return (HGHT, TRACER, UWIND, VWIND, UFLX, VFLX, UFLXMP, VFLXMP, UUFLX, UVFLX, VUFLX, VVFLX, HSURF)
def __init__(self): # GRID DEFINITION IN DEGREES self.lon0_deg = lon0_deg self.lon1_deg = lon1_deg self.lat0_deg = lat0_deg self.lat1_deg = lat1_deg self.dlon_deg = dlon_deg self.dlat_deg = dlat_deg # GRID DEFINITION IN RADIANS self.lon0_rad = self.lon0_deg/180*np.pi self.lon1_rad = self.lon1_deg/180*np.pi self.lat0_rad = self.lat0_deg/180*np.pi self.lat1_rad = self.lat1_deg/180*np.pi self.dlon_rad = self.dlon_deg/180*np.pi self.dlat_rad = self.dlat_deg/180*np.pi # NUMBER OF GRID POINTS IN EACH DIMENSION self.nx = int((self.lon1_deg - self.lon0_deg)/self.dlon_deg) self.nxs = self.nx + 1 self.ny = int((self.lat1_deg - self.lat0_deg)/self.dlat_deg) self.nys = self.ny + 1 self.nb = nb # INDEX ARRAYS self.ii = np.arange((self.nb),(self.nx+self.nb)) self.jj = np.arange((self.nb),(self.ny+self.nb)) self.iis = np.arange((self.nb),(self.nxs+self.nb)) self.jjs = np.arange((self.nb),(self.nys+self.nb)) self.iijj = np.ix_(self.ii ,self.jj ) self.iijj_im1 = np.ix_(self.ii-1 ,self.jj ) self.iijj_im1_jp1 = np.ix_(self.ii-1 ,self.jj+1) self.iijj_ip1 = np.ix_(self.ii+1 ,self.jj ) self.iijj_ip1_jm1 = np.ix_(self.ii+1 ,self.jj-1) self.iijj_ip1_jp1 = np.ix_(self.ii+1 ,self.jj+1) self.iijj_jm1 = np.ix_(self.ii ,self.jj-1) self.iijj_jp1 = np.ix_(self.ii ,self.jj+1) self.iisjj = np.ix_(self.iis ,self.jj ) self.iisjj_jm1 = np.ix_(self.iis ,self.jj-1) self.iisjj_jp1 = np.ix_(self.iis ,self.jj+1) self.iisjj_im1 = np.ix_(self.iis-1,self.jj ) self.iisjj_im1_jm1 = np.ix_(self.iis-1,self.jj-1) self.iisjj_im1_jp1 = np.ix_(self.iis-1,self.jj+1) self.iisjj_ip1 = np.ix_(self.iis+1,self.jj ) self.iisjj_ip1_jm1 = np.ix_(self.iis+1,self.jj-1) self.iisjj_ip1_jp1 = np.ix_(self.iis+1,self.jj+1) self.iijjs = np.ix_(self.ii ,self.jjs ) self.iijjs_im1 = np.ix_(self.ii-1,self.jjs ) self.iijjs_ip1 = np.ix_(self.ii+1,self.jjs ) self.iijjs_jm1 = np.ix_(self.ii ,self.jjs-1) self.iijjs_im1_jm1 = np.ix_(self.ii-1,self.jjs-1) self.iijjs_im1_jp1 = np.ix_(self.ii-1,self.jjs+1) self.iijjs_ip1_jm1 = np.ix_(self.ii+1,self.jjs-1) self.iijjs_ip1_jp1 = np.ix_(self.ii+1,self.jjs+1) self.iijjs_jp1 = np.ix_(self.ii ,self.jjs+1) self.iisjjs = np.ix_(self.iis ,self.jjs ) self.iisjjs_im1 = np.ix_(self.iis-1,self.jjs ) self.iisjjs_im1_jm1 = np.ix_(self.iis-1,self.jjs-1) self.iisjjs_im1_jp1 = np.ix_(self.iis-1,self.jjs+1) self.iisjjs_ip1 = np.ix_(self.iis+1,self.jjs ) self.iisjjs_ip1_jm1 = np.ix_(self.iis+1,self.jjs-1) self.iisjjs_jm1 = np.ix_(self.iis ,self.jjs-1) self.iisjjs_jp1 = np.ix_(self.iis ,self.jjs+1) # 2D MATRIX OF LONGITUDES AND LATITUDES IN DEGREES self.lon_deg = np.full( (self.nx+2*self.nb,self.ny+2*self.nb), np.nan) self.lat_deg = np.full( (self.nx+2*self.nb,self.ny+2*self.nb), np.nan) self.lonis_deg = np.full( (self.nxs+2*self.nb,self.ny+2*self.nb), np.nan) self.latis_deg = np.full( (self.nxs+2*self.nb,self.ny+2*self.nb), np.nan) self.lonjs_deg = np.full( (self.nx+2*self.nb,self.nys+2*self.nb), np.nan) self.latjs_deg = np.full( (self.nx+2*self.nb,self.nys+2*self.nb), np.nan) for j in range(self.nb, self.ny+self.nb): self.lon_deg[self.ii,j] = self.lon0_deg + \ (self.ii-self.nb+0.5)*self.dlon_deg self.lonis_deg[self.iis,j] = self.lon0_deg + \ (self.iis-self.nb)*self.dlon_deg for j_s in range(self.nb, self.nys+self.nb): self.lonjs_deg[self.ii,j_s] = self.lon0_deg + \ (self.ii-self.nb+0.5)*self.dlon_deg for i in range(self.nb, self.nx+self.nb): self.lat_deg[i,self.jj] = self.lat0_deg + \ (self.jj-self.nb+0.5)*self.dlat_deg self.latjs_deg[i,self.jjs] = self.lat0_deg + \ (self.jjs-self.nb)*self.dlat_deg for i_s in range(self.nb, self.nxs+self.nb): self.latis_deg[i_s,self.jj] = self.lat0_deg + \ (self.jj-self.nb+0.5)*self.dlat_deg # 2D MATRIX OF LONGITUDES AND LATITUDES IN RADIANS self.lon_rad = self.lon_deg/180*np.pi self.lat_rad = self.lat_deg/180*np.pi self.lonis_rad = self.lonis_deg/180*np.pi self.latis_rad = self.latis_deg/180*np.pi self.lonjs_rad = self.lonjs_deg/180*np.pi self.latjs_rad = self.latjs_deg/180*np.pi # 2D MATRIX OF GRID SPACING IN METERS self.dx = np.full( (self.nx+2*self.nb,self.ny+2*self.nb), np.nan) self.dxjs = np.full( (self.nx+2*self.nb,self.nys+2*self.nb), np.nan) self.dxis = np.full( (self.nxs+2*self.nb,self.ny+2*self.nb), np.nan) self.dx[self.iijj] = np.cos( self.lat_rad[self.iijj] )*self.dlon_rad*con_rE self.dxjs[self.iijjs] = np.cos( self.latjs_rad[self.iijjs] )*self.dlon_rad*con_rE self.dx = exchange_BC_rigid_y(self, self.dx) self.dxjs = exchange_BC_rigid_y(self, self.dxjs) #self.dxis[self.iisjj] = np.cos( self.latis_rad[self.iisjj] )*self.dlon_rad*con_rE self.dy = self.dlat_rad*con_rE if not i_curved_earth: maxdx = np.max(self.dx[self.iijj]) self.dx[self.iijj] = maxdx self.dxjs[self.iijjs] = maxdx self.dxis[self.iisjj] = maxdx self.A = np.full( (self.nx+2*self.nb,self.ny+2*self.nb), np.nan) for i in self.ii: for j in self.jj: #lon0 = self.lonis_rad[i,j] #lon1 = self.lonis_rad[i+1,j] #lat0 = self.latjs_rad[i,j] #lat1 = self.latjs_rad[i,j+1] #self.A[i,j] = lat_lon_recangle_area(lon0,lon1,lat0,lat1, i_curved_earth) self.A[i,j] = lat_lon_recangle_area(self.lat_rad[i,j], self.dlon_rad, self.dlat_rad, i_curved_earth) self.A = exchange_BC(self, self.A) print('fraction of earth covered: ' + str(np.round(np.sum(self.A[self.iijj])/(4*np.pi*con_rE**2),2))) print('fraction of cylinder covered: ' + str(np.round(np.sum(self.A[self.iijj])/(2*np.pi**2*con_rE**2),2))) # CORIOLIS FORCE self.corf = np.full( (self.nx+2*self.nb,self.ny+2*self.nb), np.nan) self.corf_is = np.full( (self.nxs+2*self.nb,self.ny+2*self.nb), np.nan) self.corf_js = np.full( (self.nx+2*self.nb,self.nys+2*self.nb), np.nan) self.corf[self.iijj] = 2*con_omega*np.sin(self.lat_rad[self.iijj]) self.corf_is[self.iisjj] = 2*con_omega*np.sin(self.latis_rad[self.iisjj]) self.corf_js[self.iijjs] = 2*con_omega*np.sin(self.latjs_rad[self.iijjs]) # TIME STEP mindx = np.nanmin(self.dx) self.CFL = CFL self.i_out_nth_hour = i_out_nth_hour self.i_sim_n_days = i_sim_n_days self.dt = int(self.CFL*mindx/340) while i_out_nth_hour*3600 % self.dt > 0: self.dt -= 1 self.nts = i_sim_n_days*3600*24/self.dt self.ts = 0 self.i_out_nth_ts = int(self.i_out_nth_hour*3600 / self.dt)