867 def step(self, state, timestep, timestep_number):
868 """Advance the state by one PHYEX timestep"""
871 if self.
tkemin is not None:
873 state[
'tke'] = numpy.maximum(self.
tkemin, state[
'tke'])
874 self.
budget_record(state, before,
'driver',
'TKEMIN', [
'tke'], timestep)
877 state0 = {k: v.copy()
for (k, v)
in state.items()}
883 if self.
grid.ascending:
884 dzz = numpy.diff(z_flux)
885 if dzz[-1] == numpy.inf:
888 dzz = -numpy.diff(z_flux)
889 if dzz[0] == numpy.inf:
894 if cmicro
not in (
'ICE3',
'ICE4',
'LIMA'):
897 lima = cmicro ==
'LIMA'
901 exner = (pressure / 1.E5) ** (self.
cst.Rd / self.
cst.Cpd)
903 theta = state[
'T'] / exner
904 temperature = state[
'T']
906 theta = state[
'Theta']
907 temperature = exner * theta
910 for var
in (
'qv',
'qc',
'qr',
'qi',
'qs',
'qg',
'qh'):
912 gas_constant = self.
cst.Rd + state[
'qv'] * (self.
cst.Rv - self.
cst.Rd)
913 for var
in (
'qc',
'qr',
'qi',
'qs',
'qg',
'qh'):
914 gas_constant += - state[var] * self.
cst.Rd
915 rho = pressure / (gas_constant * temperature)
917 rv = state[
'qv'] / qdm
918 rc = state[
'qc'] / qdm
919 rr = state[
'qr'] / qdm
920 ri = state[
'qi'] / qdm
921 rs = state[
'qs'] / qdm
922 rg = state[
'qg'] / qdm
923 rh = state[
'qh'] / qdm
926 for var
in (
'rv',
'rc',
'rr',
'ri',
'rs',
'rg',
'rh'):
936 div = 1 + state[
'rv']
937 for var
in (
'rc',
'rr',
'ri',
'rs',
'rg',
'rh'):
940 gas_constant = (self.
cst.Rd + state[
'rv'] * self.
cst.Rv) / div
941 rho = pressure / (gas_constant * temperature)
942 rhodref = pressure / ((self.
cst.Rd + rv * self.
cst.Rv) * theta * exner)
948 us = state[
'u'] / timestep
949 vs = state[
'v'] / timestep
950 ws = state[
'w'] / timestep
951 tkes = state[
'tke'] / timestep
959 thetas = theta / timestep
961 dqv = numpy.zeros((nkt, ))
962 dqc = numpy.zeros((nkt, ))
963 dqr = numpy.zeros((nkt, ))
964 dqi = numpy.zeros((nkt, ))
965 dqs = numpy.zeros((nkt, ))
966 dqg = numpy.zeros((nkt, ))
967 dqh = numpy.zeros((nkt, ))
969 dtemperature = numpy.zeros((nkt, ))
972 sigqsat = numpy.ones((nijt, )) * self.
full_phyex_namel[
'NAM_NEBn'][
'VSIGQSAT']
973 mfconv = numpy.zeros((nkt, ))
974 sv = numpy.array([state[var]
for var
in self.
scalar_variables]).reshape((ksv, nkt))
976 dthrad = numpy.zeros((nkt, ))
987 src = numpy.zeros((nkt, ))
988 elif cmicro
in (
'ICE3',
'ICE4',
'LIMA'):
994 rrsin, rssin, rgsin, rhsin = rrs.copy(), rss.copy(), rgs.copy(), rhs.copy()
996 thsin = thetas.copy()
997 ((rvs, rcs, rrs, ris, rss, rgs, rhs), thetas, src, hlc_hrc, hlc_hcf, hli_hri,
999 state, timestep, [rv, rc, rr, ri, rs, rg, rh], [rvs, rcs, rrs, ris, rss, rgs, rhs],
1000 theta, thetas, sv, svs, rhodref, rhodj, exner, pressure, z_mass, sigqsat, mfconv,
1001 dthrad, w_act
if lima
else None)
1003 theta = thetas * timestep
1004 temperature = theta * exner
1009 rr, rs, rg, rh = rrs * timestep, rss * timestep, rgs * timestep, rhs * timestep
1019 gas_constant = self.
cst.Rd + state[
'qv'] * (self.
cst.Rv - self.
cst.Rd)
1020 for var
in (
'qc',
'qr',
'qi',
'qs',
'qg',
'qh'):
1022 gas_constant += - state[var] * self.
cst.Rd
1023 rho = pressure / (gas_constant * temperature)
1025 dqv += (rvs - rvsin) * qdm
1026 dqc += (rcs - rcsin) * qdm
1027 dqi += (ris - risin) * qdm
1029 dqr += (rrs - rrsin) * qdm
1030 dqs += (rss - rssin) * qdm
1031 dqg += (rgs - rgsin) * qdm
1032 dqh += (rhs - rhsin) * qdm
1034 div = 1. + state[
'rv']
1035 for var
in (
'rc',
'rr',
'ri',
'rs',
'rg',
'rh'):
1038 gas_constant = (self.
cst.Rd + state[
'rv'] * self.
cst.Rv) / div
1039 rho = pressure / (gas_constant * temperature)
1040 rhodref = pressure / ((self.
cst.Rd + rv * self.
cst.Rv) * theta * exner)
1043 dtemperature += (thetas - thsin) * exner
1047 state[
'qv'] = state0[
'qv'] + dqv * timestep
1048 state[
'qc'] = state0[
'qc'] + dqc * timestep
1049 state[
'qr'] = state0[
'qr'] + dqr * timestep
1050 state[
'qi'] = state0[
'qi'] + dqi * timestep
1051 state[
'qs'] = state0[
'qs'] + dqs * timestep
1052 state[
'qg'] = state0[
'qg'] + dqg * timestep
1053 state[
'qh'] = state0[
'qh'] + dqh * timestep
1055 state[
'rv'] = rvs * timestep
1056 state[
'rc'] = rcs * timestep
1057 state[
'rr'] = rrs * timestep
1058 state[
'ri'] = ris * timestep
1059 state[
'rs'] = rss * timestep
1060 state[
'rg'] = rgs * timestep
1061 state[
'rh'] = rhs * timestep
1063 state[
'T'] = state0[
'T'] + dtemperature * timestep
1065 state[
'Theta'] = thetas * timestep
1069 if self.
grid.ascending:
1070 dzz = numpy.diff(z_flux)
1071 if dzz[-1] == numpy.inf:
1074 dzz = -numpy.diff(z_flux)
1075 if dzz[0] == numpy.inf:
1078 raise Phyex1DError(
'Wrong CMICRO scheme choice for adjustment')
1085 if self.
case.radiation ==
'on':
1089 result = self.
_ecrad(state, timestep, timestep_number, temperature, rv, rc,
1091 order = -1
if self.
grid.ascending
else 1
1092 result = {k: v[0, ::order]
if len(v.shape) == 2
else v
1093 for (k, v)
in result.items()}
1094 for var
in (
'lw_up',
'lw_dn',
'sw_up',
'sw_dn'):
1095 state[var] = result[var]
1096 cp = qdm * (self.
cst.Cpd +
1098 self.
cst.Cl * (rc + rr) +
1099 self.
cst.Ci * (ri + rs + rg + rh))
1100 dt_rad_lw = -numpy.diff((state[
'lw_dn'] - state[
'lw_up'])[::order])[::order] / \
1102 dt_rad_sw = -numpy.diff((state[
'sw_dn'] - state[
'sw_up'])[::order])[::order] / \
1104 state[
'dt_rad_lw'] = dt_rad_lw
1105 state[
'dt_rad_sw'] = dt_rad_sw
1107 self.
budget_add(state,
'bu_rad_TH_LW', dt_rad_lw / exner)
1108 self.
budget_add(state,
'bu_rad_TH_SW', dt_rad_sw / exner)
1110 dtemperature += dt_rad_lw + dt_rad_sw
1112 thetas += (dt_rad_lw + dt_rad_sw) / exner
1121 klevgrd = 0
if self.
grid.ascending
else -1
1122 zgrd = z_mass[klevgrd] - state.get(
'Zs', 0.)
1125 t_grd = state[
'T'][klevgrd]
1127 t_grd = state[
'Theta'][klevgrd] * exner[klevgrd]
1129 qv_grd = state[
'qv'][klevgrd]
1131 qv_grd = state[
'rv'][klevgrd] * qdm[klevgrd]
1134 need_heat = self.
case.surface_forcing_temp
in (
'none',
'ts')
1135 need_moisture = self.
case.surface_forcing_moisture
in (
'none',
'beta',
'mrsos')
1136 need_momentum = self.
case.surface_forcing_wind
in (
'none', )
1137 need_scheme = need_heat
or need_moisture
or need_momentum
1139 def ustar2fluxes(ustar, u, v):
1141 Convert ustar into momentum fluxes
1142 :param ustar: ustar value
1143 :param u, v: wind components
1146 alpha = numpy.arctan2(v, u)
1147 return - ustar**2 * numpy.cos(alpha), - ustar**2 * numpy.sin(alpha)
1149 surface_temperature = state[
'Ts']
if 'Ts' in state
else t_grd
1150 if surface_temperature > self.
cst.Tt:
1151 latent_heat = self.
cst.LvTt - (self.
cst.Cpv - self.
cst.Cl) * \
1152 (surface_temperature - self.
cst.Tt)
1154 latent_heat = self.
cst.LsTt - (self.
cst.Cpv - self.
cst.Ci) * \
1155 (surface_temperature - self.
cst.Tt)
1164 sshf_scheme = numpy.float64(0.)
1165 swf_scheme = numpy.float64(0.)
1166 sfu_scheme = numpy.float64(0.)
1167 sfv_scheme = numpy.float64(0.)
1168 elif not need_scheme:
1173 state, t_grd, qv_grd, exner[klevgrd], rho[klevgrd],
1174 state[
'u'][klevgrd], state[
'v'][klevgrd], zgrd)
1175 sfu_scheme, sfv_scheme = ustar2fluxes(ustar, state[
'u'][klevgrd],
1176 state[
'v'][klevgrd])
1179 state, timestep * timestep_number, t_grd, qv_grd, rho[klevgrd],
1180 state[
'u'][klevgrd], state[
'v'][klevgrd], zgrd)
1181 sfu_scheme, sfv_scheme = ustar2fluxes(ustar, state[
'u'][klevgrd],
1182 state[
'v'][klevgrd])
1186 if self.
case.surface_forcing_temp ==
'none':
1187 if sshf_scheme
is None:
1188 raise Phyex1DError(
"Surface scheme didn't compute sshf")
1190 elif self.
case.surface_forcing_temp ==
'kinematic':
1191 raise NotImplementedError(
'surface_forcing_temp=kinematic')
1192 elif self.
case.surface_forcing_temp ==
'surface_flux':
1193 sshf = state[
'sshf']
1194 elif self.
case.surface_forcing_temp ==
'ts':
1197 raise Phyex1DError(
'Wrong surface_forcing_temp option')
1199 if self.
case.surface_forcing_moisture ==
'none':
1200 if swf_scheme
is None:
1201 raise Phyex1DError(
"Surface scheme didn't compute swf")
1203 elif self.
case.surface_forcing_moisture ==
'kinematic':
1204 raise NotImplementedError(
'surface_forcing_moisture=kinematic')
1205 elif self.
case.surface_forcing_moisture ==
'surface_flux':
1207 swf = state[
'slhf'] / latent_heat
1208 elif self.
case.surface_forcing_moisture ==
'beta':
1209 if swf_scheme
is None:
1210 raise Phyex1DError(
"Surface scheme didn't compute swf")
1212 elif self.
case.surface_forcing_moisture ==
'mrsos':
1213 raise NotImplementedError(
'surface_forcing_moisture=mrsos')
1215 raise Phyex1DError(
'Wrong surface_forcing_moisture option')
1220 sfrv = swf / rhodref[0
if self.
grid.ascending
else -1]
1221 cp = qdm * (self.
cst.Cpd + self.
cst.Cpv * rv + self.
cst.Cl * (rc + rr) +
1222 self.
cst.Ci * (ri + rs + rg + rh))
1223 sfth = sshf / (self.
cst.Cpd * rho[0
if self.
grid.ascending
else -1])
1226 if self.
case.surface_forcing_wind ==
'none':
1229 elif self.
case.surface_forcing_wind ==
'z0':
1230 windgrd = numpy.sqrt(state[
'u'][klevgrd]**2 + state[
'v'][klevgrd]**2)
1232 ustar = beta_surface.mo_ustar(float(windgrd), float(zgrd),
1233 float(state[
'z0']), float(sfth), float(sfrv),
1234 float(theta[klevgrd]), float(rv[klevgrd]))
1236 ustar = windgrd * self.
cst.Karman / numpy.log(zgrd / state[
'z0'])
1237 sfu, sfv = ustar2fluxes(ustar, state[
'u'][klevgrd], state[
'v'][klevgrd])
1238 elif self.
case.surface_forcing_wind ==
'ustar':
1239 sfu, sfv = ustar2fluxes(state[
'ustar'], state[
'u'][klevgrd], state[
'v'][klevgrd])
1241 raise Phyex1DError(
'Wrong surface_forcing_wind option')
1243 state[
'sfrv'] = sfrv
1245 state[
'slhf'] = swf * latent_heat
1246 state[
'sfth'] = sfth
1247 state[
'sshf'] = sshf
1255 flxzthvmf = flxzumf = flxzvmf = sigs_mf = numpy.zeros((nkt, ))
1257 (du_mf, dv_mf, dtke_mf, dthl_mf, drt_mf, dsv_mf, sigs_mf,
1258 flxzthvmf, flxzumf, flxzvmf) = self.
_shallow(
1259 state, timestep, [rv, rc, rr, ri, rs, rg, rh], theta, sv, svs, rhodj, rhodref,
1260 pressure, exner, dzz, z_flux, sfth, sfrv)
1269 dtemperature += dthl_mf * exner
1285 (us, vs, ws, thetas, prs, svs, tkes, sigs_turb, dthetal_turb,
1286 drt_turb) = self.
_turb(
1287 state, timestep, [rv, rc, rr, ri, rs, rg, rh], [rvs, rcs, rrs, ris, rss, rgs, rhs],
1288 theta, us, vs, ws, thetas, svs, tkes, sv, src, rhodj, pressure, dzz, z_flux,
1289 sfth, sfrv, sfu, sfv, flxzthvmf, flxzumf, flxzvmf)
1294 dtemperature += dthetal_turb * exner
1296 print(
'We must take into account tendencies on rc and ri. Here and in arome')
1297 dqv += drt_turb * qdm
1307 state[
'sigs'] = numpy.sqrt(sigs_mf**2 + sigs_turb**2)
1318 elif cmicro
in (
'ICE3',
'ICE4',
'LIMA'):
1328 thsin = thetas.copy()
1330 (thetas, prs, svs, hlc_hrc, hlc_hcf, hli_hri, hli_hcf) = self.
_microphysics(
1331 state, timestep, [rv, rc, rr, ri, rs, rg, rh], [rvs, rcs, rrs, ris, rss, rgs, rhs],
1332 theta, thetas, sv, svs, rhodref, rhodj, exner, pressure, dzz, dthrad,
1333 w_act
if lima
else None, hlc_hrc, hlc_hcf, hli_hri, hli_hcf)
1346 dqv += (prs[0] - rvsin) * qdm
1347 dqc += (prs[1] - rcsin) * qdm
1348 dqr += (prs[2] - rrsin) * qdm
1349 dqi += (prs[3] - risin) * qdm
1350 dqs += (prs[4] - rssin) * qdm
1351 dqg += (prs[5] - rgsin) * qdm
1353 dqh += (prs[6] - rhsin) * qdm
1356 dtemperature += (thetas - thsin) * exner
1358 raise Phyex1DError(
'Wrong CMICRO scheme choice for microphysics')
1366 state[
'qv'] = state0[
'qv'] + dqv * timestep
1367 state[
'qc'] = state0[
'qc'] + dqc * timestep
1368 state[
'qr'] = state0[
'qr'] + dqr * timestep
1369 state[
'qi'] = state0[
'qi'] + dqi * timestep
1370 state[
'qs'] = state0[
'qs'] + dqs * timestep
1371 state[
'qg'] = state0[
'qg'] + dqg * timestep
1372 state[
'qh'] = state0[
'qh'] + dqh * timestep
1374 state[
'rv'] = rvs * timestep
1375 state[
'rc'] = rcs * timestep
1376 state[
'rr'] = rrs * timestep
1377 state[
'ri'] = ris * timestep
1378 state[
'rs'] = rss * timestep
1379 state[
'rg'] = rgs * timestep
1380 state[
'rh'] = rhs * timestep
1382 state[
'T'] = state0[
'T'] + dtemperature * timestep
1384 state[
'Theta'] = thetas * timestep
1385 state[
'u'] = us * timestep
1386 state[
'v'] = vs * timestep
1387 state[
'tke'] = tkes * timestep
1389 state[var] = svs[ivar] * timestep