PHYEX 0.9.5
PHYsique EXternalisée
Loading...
Searching...
No Matches
phyex.py
Go to the documentation of this file.
1"""
2Implementation of PHYEX physics schemes
3"""
4# pylint: disable=no-member
5
6import copy
7import datetime
8import importlib.util
9import logging
10import os
11import sys
12import tempfile
13
14import ephem
15import f90nml
16import numpy
17from ctypesForFortran import MISSING
18
19from . import Phyex1DError
20from . import user_dir
21from . import wasp
22from . import beta_surface
23from .grid import FLUX
24from .physics_base import PhysicsBase
25from .namelist import find_namelist
26
27
29 """
30 PHYEX-based physics scheme
31
32 This class handles the initialisation / setup of PHYEX and ECRAD.
33 """
34
35 # Number of levels added at the top and at the bottom of the columns given to the turbulence
36 _NVEXT_TURB = 1
37
38 OPTIONS_HELP = {
39 'pyecrad': 'path to the pyecrad package directory (or its __init__.py file) to use '
40 'instead of the installed pyecrad package',
41 'namel': 'namelist name or file name (with a .namel extension)',
42 'dx': 'mesh size along x (m), for scale aware parametrizations',
43 'dy': 'mesh size along y (m), for scale aware parametrizations',
44 'budgets': 'True to add the budgets (contribution of each process, per scheme) '
45 'to the output (as bu_<scheme>_<variable>_<process> variables)',
46 }
47
48 def __init__(self, dt, method, name, tag, case, grid, prognostic_variables,
49 pyecrad=None, namel='default', dx=0., dy=0., attrs=None, budgets=False):
50 super().__init__(dt, method, name, tag, case, grid, prognostic_variables)
51 self.budgets = budgets
52 self._kbudgets = len(self.BUDGET_VARIABLES) if budgets else 0
53 self._pyphyex = None
54 self.pyecrad = pyecrad
55 self._pyecrad = None
56 self.namel = namel
57 self.full_phyex_namel = None
58 self.dx = dx
59 self.dy = dy
60 if self.namel is not None and not isinstance(namel, dict):
61 # file name, or namelist name searched in the user's directory, then in the package
62 namelist_file = find_namelist(self.namel)
63 if namelist_file is None:
64 raise Phyex1DError(f"Namelist {self.namel} not found (in {user_dir('namelists')} "
65 "and in the package)")
66
67 with open(namelist_file, 'r', encoding='UTF-8') as f:
68 self.namel = f90nml.read(f)
69
70 def setup(self, init_state, duration):
71 """Initialise PHYEX and ECRAD"""
72 try:
73 # Low-level module of the pyphyex package
74 from pyphyex import lowlevel as pyphyex # pylint: disable=import-outside-toplevel
75 except ModuleNotFoundError:
76 logging.error("The low-level module of the pyphyex package has not been found. " +
77 "This module is built with the PHYEX package " +
78 "(available on github). Details on the compilation " +
79 "process can be found in the PHYEX documentation.")
80 raise
81 self._pyphyex = pyphyex
82
83 def set_default(nml):
84 """
85 Set default values for schemes
86 """
87 if 'PHYEX' not in nml:
88 nml['PHYEX'] = {}
89 nml['PHYEX']['CMICRO'] = nml['PHYEX'].get('CMICRO', 'ICE3')
90 nml['PHYEX']['CSCONV'] = nml['PHYEX'].get('CSCONV', 'EDKF')
91 nml['PHYEX']['CTURB'] = nml['PHYEX'].get('CTURB', 'TKEL')
92 nml['PHYEX']['RAD'] = nml['PHYEX'].get('RAD', 'ECRAD')
93 nml['PHYEX']['SURFACE'] = nml['PHYEX'].get('SURFACE', 'WASP')
94 # BETA surface scheme: origin of beta and of the roughness lengths
95 nml['PHYEX']['BETA_TYPE'] = nml['PHYEX'].get('BETA_TYPE', 'CASE')
96 nml['PHYEX']['Z0_TYPE'] = nml['PHYEX'].get('Z0_TYPE', 'CASE')
97 # Stability correction (BETA scheme and momentum flux computed from z0)
98 nml['PHYEX']['LSTAB'] = nml['PHYEX'].get('LSTAB', False)
99 # LIMA: CCN activation scheme (as CACTCCN in Meso-NH)
100 nml['PHYEX']['CACTCCN'] = nml['PHYEX'].get('CACTCCN', 'NONE')
101
102 with tempfile.NamedTemporaryFile() as namel:
103 nml = f90nml.read(namel.name)
104 if self.namel is not None:
105 for k, v in self.namel.items():
106 nml[k] = v
107 set_default(nml)
108 nml.uppercase = True
109 nml.write(namel.name, force=True)
110 # First call to really initialize
111 try:
112 zdzmin = self.grid.get_altitude('FLUX', init_state, self.prognostic_variables).min()
113 except (KeyError, Phyex1DError):
114 logging.warning('Unable to compute true minimal thickness, use 20m instead')
115 zdzmin = 20.
116 numnml = 20
117 # DIMPHYEX_t components (D is flattened into NIT, NKT, NKL, NVEXT)
118 nkt = self.grid.len - 1 if self.grid.position in FLUX else self.grid.len
119 nijt, nkl, nvext = 1, 1 if self.grid.ascending else -1, 0
120 # First call to really initialize
121 self._pyphyex.PYINI_PHYEX(
122 nijt, nkt, nkl, nvext,
123 'PHX1D', 33, namel.name, False, numnml, 0, 1, self._dt, zdzmin,
124 nml['PHYEX']['CMICRO'], nml['PHYEX']['CSCONV'],
125 nml['PHYEX']['CTURB'],
126 LDCHANGEMODEL=True, LDDEFAULTVAL=True, LDREADNAM=True,
127 LDCHECK=True, KPRINT=0, LDINIT=True)
128 os.remove(f'fort.{numnml}')
129 numnml = 21
130 # Second call to only write the namelist
131 self._pyphyex.PYINI_PHYEX(
132 nijt, nkt, nkl, nvext,
133 'PHX1D', 33, namel.name, False, numnml, 0, 1, self._dt, zdzmin,
134 nml['PHYEX']['CMICRO'], nml['PHYEX']['CSCONV'],
135 nml['PHYEX']['CTURB'],
136 LDCHANGEMODEL=False, LDDEFAULTVAL=False, LDREADNAM=False,
137 LDCHECK=False, KPRINT=1, LDINIT=False)
138 self.full_phyex_namel = f90nml.read(f'fort.{numnml}')
139 # The PHYEX group (scheme choices of the 1D model) is not a PHYEX namelist
140 self.full_phyex_namel['PHYEX'] = copy.deepcopy(nml['PHYEX'])
141 set_default(self.full_phyex_namel)
142 # Minimum value for TKE (only with the TKE turbulence scheme)
143 self.tkemin = self.full_phyex_namel['NAM_TURBn']['XTKEMIN'] \
144 if self.full_phyex_namel['PHYEX']['CTURB'] == 'TKEL' else None
145 os.remove(f'fort.{numnml}')
146
147 # Number of water species, LIMA scalar variables
148 cmicro = self.full_phyex_namel['PHYEX']['CMICRO']
149 if cmicro == 'LIMA':
150 self.krr = 7 if self.full_phyex_namel['NAM_PARAM_LIMA'].get('NMOM_H', 0) >= 1 else 6
151 nsv = self._pyphyex.PYLIMA_NSV_OFFLINE_GET_SIZE()
152 names = [str(name).strip() for name in
153 self._pyphyex.PYLIMA_NSV_OFFLINE_GET_NAMES(nsv)] if nsv > 0 else []
154 self.lima_names = names
155 self.scalar_variables = ['lima_' + name for name in names]
156 else:
157 self.krr = {'ICE3': 6, 'ICE4': 7}.get(cmicro, 6)
158 self.lima_names = []
159 self.scalar_variables = []
160
161 # Budget configuration (always set because the configuration is kept by the library
162 # from one experiment to the other)
163 active = [self.budgets] * len(self.BUDGET_VARIABLES)
164 if self.krr < 7:
165 active[self.BUDGET_VARIABLES.index('RH')] = False
166 self._pyphyex.PYBUDGET_OFFLINE_CONF(len(active), numpy.array(active))
167 self._budget_active = [var for var, act in zip(self.BUDGET_VARIABLES, active) if act]
168
169 # ECRAD SETUP
170 if nml['PHYEX']['RAD'] == 'ECRAD' and self.case.radiation == 'on':
171 try:
172 if self.pyecrad is None:
173 # installed pyecrad package
174 import pyecrad # pylint: disable=import-outside-toplevel
175 else:
176 # We import the pyecrad package by path
177 package_dir = os.path.abspath(self.pyecrad)
178 if not os.path.isdir(package_dir):
179 package_dir = os.path.dirname(package_dir)
180 spec = importlib.util.spec_from_file_location(
181 'pyecrad', os.path.join(package_dir, '__init__.py'),
182 submodule_search_locations=[package_dir])
183 pyecrad = importlib.util.module_from_spec(spec)
184 sys.modules['pyecrad'] = pyecrad
185 spec.loader.exec_module(pyecrad)
186 except ModuleNotFoundError:
187 logging.error("The module pyecrad has not been found.")
188 raise
189
190 # The namelist must contain the "radiation" group (data files are taken
191 # from the pyecrad package if they are installed with it)
192 self._pyecrad = pyecrad.Ecrad(nml)
193
194 def build_init_state(self, init_state):
195 """
196 Build the initial state
197 When budgets are activated, the budget variables are only known after a call to
198 the parametrisations; a first time step is done (on a copy of the initial state) to
199 get them.
200 """
201 init_state = super().build_init_state(init_state)
202 if self.full_phyex_namel['PHYEX']['CMICRO'] == 'LIMA':
203 self._lima_init_state(init_state)
204 if self.budgets:
205 self._budget_keys = None
206 probe = self.execute(copy.deepcopy(init_state), self._dt, 1)
207 self._budget_keys = sorted(k for k in probe if k.startswith('bu_'))
208 for key in self._budget_keys:
209 init_state[key] = numpy.zeros(init_state['P'].shape)
210 return init_state
211
212 def _init_aerosol_concentration(self, rhodref, z_mass):
213 """
214 Initial values of the LIMA scalar variables (aerosols only, other variables are null)
215 The free aerosol concentrations (CCN and IFN) are initialised as in Meso-NH
216 (INIT_AEROSOL_CONCENTRATION, case without ORILAM, dust and sea salt), from the
217 XCCN_CONC, LCCN_HOM, XIFN_CONC and LIFN_HOM parameters of the NAM_PARAM_LIMA namelist.
218 :param rhodref: dry air density profile (kg/m3)
219 :param z_mass: altitude profile (m)
220 :return: array (number of LIMA variables, number of levels)
221 """
222 nml = self.full_phyex_namel['NAM_PARAM_LIMA']
223 names = self.lima_names
224
225 def value(key, index=None, default=None):
226 """Value of a namelist key (index-th element for an array)"""
227 val = nml.get(key, default)
228 if index is not None:
229 val = val[index] if isinstance(val, list) else val
230 return val
231
232 def profile(conc, factor, homogeneous, low_conc):
233 """
234 Aerosol concentration profile (#/kg)
235 :param conc: reference concentration (in #/cm3 for CCN, #/L for IFN)
236 :param factor: conversion factor into #/m3
237 :param homogeneous: True for a homogeneous concentration
238 :param low_conc: concentration (same units as conc) above 10 km
239 """
240 if homogeneous:
241 return conc * factor / rhodref
242 return numpy.where(z_mass <= 1000., conc * factor / rhodref,
243 numpy.where(z_mass <= 10000.,
244 conc * factor / rhodref *
245 numpy.exp(-numpy.log(conc / low_conc) * z_mass / 10000.),
246 low_conc * factor / rhodref))
247
248 sv = numpy.zeros((len(names), len(rhodref)))
249 # CCN
250 if value('NMOM_C', default=0) >= 2 and value('LACTI', default=False):
251 for imode in range(value('NMOD_CCN', default=0)):
252 name = f'CCN_FREE{imode + 1:02d}'
253 if name in names:
254 sv[names.index(name)] = profile(value('XCCN_CONC', imode), 1.E6,
255 value('LCCN_HOM', default=True), 0.01)
256 # IFN
257 if value('NMOM_I', default=0) >= 2 and value('LNUCL', default=False) and \
258 not value('LMEYERS', default=False):
259 for imode in range(value('NMOD_IFN', default=0)):
260 name = f'IFN_FREE{imode + 1:02d}'
261 if name in names:
262 sv[names.index(name)] = profile(value('XIFN_CONC', imode), 1.E3,
263 value('LIFN_HOM', default=True), 1.)
264 return sv
265
266 def _lima_init_state(self, init_state):
267 """
268 Initial values of the LIMA variables: aerosol concentrations as in Meso-NH
269 (INIT_AEROSOL_CONCENTRATION), then hydrometeor concentrations deduced from the mixing
270 ratios (SET_CONC_LIMA); ice and precipitation fractions set to 0
271 :param init_state: initial state, completed by the LIMA variables
272 """
273 pressure = self.grid.get_pressure('MASS', init_state, self.prognostic_variables)
274 z_mass = self.grid.get_altitude('MASS', init_state, self.prognostic_variables)
275 rmix = [init_state[var] for var in ('rv', 'rc', 'rr', 'ri', 'rs', 'rg', 'rh')[:self.krr]]
276 rhodref = pressure / ((self.cst.Rd + init_state['rv'] * self.cst.Rv) * init_state['T'])
277 sv = self._init_aerosol_concentration(rhodref, z_mass)
278 if len(self.lima_names) > 0:
279 x = numpy.newaxis
280 _, sv = self._pyphyex.PYSET_CONC_LIMA(
281 len(self.lima_names), 1, len(pressure), 1 if self.grid.ascending else -1, 0,
282 self.krr, 1, 'INI2', rhodref[:, x], numpy.array(rmix)[:, :, x], sv[:, :, x],
283 ODLBC=False) # optional logicals must be present (pybinding limitation)
284 sv = sv[:, :, 0]
285 for ivar, var in enumerate(self.scalar_variables):
286 init_state[var] = sv[ivar]
287 for var in ('ICEFR', 'PRCFR'):
288 init_state[var] = numpy.zeros(pressure.shape)
289
290 def _lima_activation_velocity(self, state, time, z_mass, pressure):
291 """
292 Vertical velocity used by LIMA for the activation of the aerosols, computed as in Meso-NH
293 (XWT_ACT_NUC in MODEL_n): vertical velocity, plus the prescribed large-scale vertical
294 velocity, plus (2/3 TKE)**0.5 if LACTTKE (with a turbulence scheme)
295 :param state: state dictionary
296 :param time: current time (s)
297 :param z_mass, pressure: altitude and pressure profiles
298 """
299 w_act = numpy.array(state['w'], copy=True)
300 if self.case.forc_wa == 1:
301 coord = z_mass if self.grid.kind in ('H', 'hybridH') else pressure
302 with self.case:
303 interp = self.case.get_interpolator('wa', self.grid)
304 w_act += interp(numpy.column_stack(([time] * len(coord), coord)))
305 if self.full_phyex_namel['PHYEX']['CTURB'] != 'NONE' and \
306 self.full_phyex_namel['NAM_PARAM_LIMA'].get('LACTTKE', True):
307 w_act += (2. / 3. * numpy.maximum(state['tke'], 0.))**0.5
308 return w_act
309
310 def _wasp_surface_fluxes(self, state, t1, q1, exner1, rho1, u1, v1, zgrd):
311 """
312 Surface fluxes computed by the WASP scheme (see the wasp module), from a prescribed
313 surface temperature
314 :param state: state dictionary (surface temperature, surface pressure)
315 :param t1, q1, exner1, rho1: temperature (K), specific humidity (kg/kg), Exner function
316 and density (kg/m3) at the first level
317 :param u1, v1: wind components at the first level (m/s)
318 :param zgrd: height of the first level above the surface (m)
319 :return: (sensible heat flux (W/m2), water vapour flux (kg/m2/s), friction velocity (m/s))
320 """
321 if self.case.surface_forcing_temp == 'none':
322 raise Phyex1DError('surface_forcing_temp == none needs a prognostic surface '
323 'temperature, not available with WASP')
324 if self.case.surface_forcing_moisture == 'beta':
325 raise Phyex1DError("surface_forcing_moisture == beta is not handled by WASP, "
326 "use SURFACE='BETA'")
327 ts_name = 'Ts' if self.case.surface_type == 'ocean' else 'Tskin'
328 if ts_name not in state:
329 raise Phyex1DError(f'WASP needs the surface temperature ({ts_name}), '
330 'not found in the case description')
331 wind = numpy.sqrt(u1**2 + v1**2)
332 exner_surf = (state['Ps'] / 1.E5) ** (self.cst.Rd / self.cst.Cpd)
333 # TODO, filled precip in precipitation rate (kg/s/m2)
334 precip = 0.
335 wave_height = 0.
336 wave_peak_period = 0.
337 return wasp.WASP_FLUX(t1, q1, exner1, rho1, wind, zgrd, zgrd, state[ts_name],
338 exner_surf, state['Ps'], precip, wave_height, wave_peak_period)
339
340 def _beta_surface_fluxes(self, state, time, t1, q1, rho1, u1, v1, zgrd):
341 """
342 Surface fluxes computed by the BETA scheme (see the beta_surface module)
343 :param state: state dictionary (surface temperature, surface pressure, z0, z0h)
344 :param time: current time (s)
345 :param t1, q1, rho1: temperature (K), specific humidity (kg/kg) and density (kg/m3) at
346 the first level
347 :param u1, v1: wind components at the first level (m/s)
348 :param zgrd: height of the first level above the surface (m)
349 :return: (sensible heat flux (W/m2), water vapour flux (kg/m2/s), friction velocity (m/s))
350 """
351 nml = self.full_phyex_namel['PHYEX']
352 if self.case.surface_forcing_temp == 'none':
353 raise Phyex1DError('surface_forcing_temp == none needs a prognostic surface '
354 'temperature, not available with the BETA scheme')
355 ts_name = 'Ts' if self.case.surface_type == 'ocean' else 'Tskin'
356 if ts_name not in state:
357 raise Phyex1DError(f'The BETA scheme needs the surface temperature ({ts_name}), '
358 'not found in the case description')
359
360 # Evaporation efficiency
361 if nml['BETA_TYPE'] == 'CONSTANT':
362 if 'BETA' not in nml:
363 raise Phyex1DError("BETA_TYPE='CONSTANT' needs the BETA key in the PHYEX "
364 "namelist group")
365 beta = float(nml['BETA'])
366 elif nml['BETA_TYPE'] == 'CASE':
367 with self.case:
368 if self.case.contains('beta'):
369 beta = float(self.case.get_interpolator('beta', self.grid)([time])[0])
370 elif self.case.surface_forcing_moisture == 'beta':
371 raise Phyex1DError("surface_forcing_moisture == beta but no beta variable "
372 "in the case description")
373 elif self.case.surface_type in ('ocean', 'seaice', 'landice'):
374 beta = 1.
375 else:
376 raise Phyex1DError("beta must be given for a land surface (beta variable of "
377 "the case description, or BETA_TYPE='CONSTANT' and BETA "
378 "in the PHYEX namelist group)")
379 else:
380 raise Phyex1DError(f"Wrong BETA_TYPE: {nml['BETA_TYPE']}")
381
382 # Roughness lengths
383 if nml['Z0_TYPE'] == 'CASE':
384 if 'z0' not in state:
385 raise Phyex1DError("Z0_TYPE='CASE' but no z0 in the case description")
386 z0 = float(state['z0'])
387 z0h = float(state['z0h']) if 'z0h' in state else None
388 elif nml['Z0_TYPE'] == 'CONSTANT':
389 if 'Z0' not in nml:
390 raise Phyex1DError("Z0_TYPE='CONSTANT' needs the Z0 key in the PHYEX namelist "
391 "group")
392 z0 = float(nml['Z0'])
393 z0h = float(nml['Z0H']) if 'Z0H' in nml else None
394 elif nml['Z0_TYPE'] == 'CHARNOCK':
395 z0 = 'CHARNOCK'
396 z0h = float(nml['Z0H']) if 'Z0H' in nml else None
397 else:
398 raise Phyex1DError(f"Wrong Z0_TYPE: {nml['Z0_TYPE']}")
399
400 result = beta_surface.beta_fluxes(
401 float(t1), float(q1), float(rho1), float(u1), float(v1), float(zgrd),
402 float(state[ts_name]), float(state['Ps']), beta, z0, z0h, bool(nml['LSTAB']))
403 # numpy values (and not python floats) because they can be put in the state
404 return tuple(numpy.float64(value) for value in result)
405
406 def _adjustment(self, state, timestep, rmix, rsrc, theta, thetas, sv, svs, rhodref, rhodj,
407 exner, pressure, z_mass, sigqsat, mfconv, dthrad, w_act):
408 """
409 Saturation adjustment: LIMA_ADJUST_SPLIT for LIMA, ICE_ADJUST otherwise
410 :param state: state dictionary (CF, and ICEFR for LIMA, are updated)
411 :param timestep: timestep (s)
412 :param rmix: list of the 7 mixing ratios (rv, rc, rr, ri, rs, rg, rh)
413 :param rsrc: list of the 7 mixing ratio sources (s-1)
414 :param theta, thetas: potential temperature and its source
415 :param sv, svs: LIMA scalar variables and their sources (number of variables, levels)
416 :param rhodref, rhodj, exner, pressure, z_mass: dry density, dry density times volume,
417 Exner function, pressure, altitude
418 :param sigqsat, mfconv, dthrad: PHYEX arguments
419 :param w_act: vertical velocity for the activation (LIMA only)
420 :return: (list of the 7 mixing ratio sources, thetas, src, hlc_hrc, hlc_hcf, hli_hri,
421 hli_hcf, sv, svs)
422 """
423 rv, rc, rr, ri, rs, rg, rh = rmix
424 rvs, rcs, rrs, ris, rss, rgs, rhs = rsrc
425 krr = self.krr
426 ksv = len(self.scalar_variables)
427 nijt, nkt = 1, len(pressure)
428 x = numpy.newaxis
429 empty_soa = numpy.zeros((0, nkt, nijt)) # no secondary organic aerosols
430 if self.full_phyex_namel['PHYEX']['CMICRO'] == 'LIMA':
431 nml = self.full_phyex_namel
432 prm = numpy.array([rv, rc, rr, ri, rs, rg, rh][:krr])[:, :, x]
433 prs = numpy.array([rvs, rcs, rrs, ris, rss, rgs, rhs][:krr])[:, :, x]
434 result = self._pyphyex.PYLIMA_ADJUST_SPLIT(
435 ksv, nijt, nkt, 1 if self.grid.ascending else -1, 0, self._kbudgets, krr,
436 nml['NAM_NEBn']['CCONDENS'], nml['NAM_NEBn']['CLAMBDA3'], 0, 0, 0,
437 False, False, False,
438 nml['NAM_NEBn']['LSUBG_COND'], nml['NAM_NEBn']['LSIGMAS'], timestep,
439 sigqsat, rhodref[:, x], rhodj[:, x], exner[:, x], state['sigs'][:, x],
440 False, mfconv[:, x], pressure[:, x], z_mass[:, x], dthrad[:, x],
441 w_act[:, x], prm, prs, sv[:, :, x], svs[:, :, x],
442 nml['PHYEX']['CACTCCN'], sv[:, :, x].copy(), empty_soa, empty_soa,
443 thetas[:, x], True,
444 state['rc_MF'][:, x], state['ri_MF'][:, x], state['CF_MF'][:, x],
445 PWEIGHT_MF_CLOUD=state['WEIGHT_MF_CLOUD'][:, x],
446 PHLC_HRC_MF=state['HLC_HRC_MF'][:, x],
447 PHLC_HCF_MF=state['HLC_HCF_MF'][:, x],
448 PHLI_HRI_MF=state['HLI_HRI_MF'][:, x],
449 PHLI_HCF_MF=state['HLI_HCF_MF'][:, x])
450 (prs, svs, _, thetas, src, cldfr, icefr,
451 hlc_hrc, hlc_hcf, hli_hri, hli_hcf) = result
452 prs, svs = prs[:, :, 0], svs[:, :, 0]
453 thetas, src, hlc_hrc, hlc_hcf, hli_hri, hli_hcf = \
454 (array[:, 0] for array in (thetas, src, hlc_hrc, hlc_hcf, hli_hri, hli_hcf))
455 state['CF'], state['ICEFR'] = cldfr[:, 0], icefr[:, 0]
456 rvs, rcs, rrs, ris, rss, rgs = prs[:6]
457 if krr == 7:
458 rhs = prs[6]
459 sv = svs * timestep
460 else:
461 result = self._pyphyex.PYICE_ADJUST(
462 nijt, nkt, 1 if self.grid.ascending else -1, 0,
463 krr, 'DEPO', timestep,
464 sigqsat, rhodj[:, x],
465 exner[:, x], rhodref[:, x], state['sigs'][:, x], False,
466 mfconv[:, x], pressure[:, x], z_mass[:, x], exner[:, x],
467 state['CF_MF'][:, x], state['rc_MF'][:, x],
468 state['ri_MF'][:, x], state['WEIGHT_MF_CLOUD'][:, x], rv[:, x],
469 rc[:, x], rvs[:, x], rcs[:, x],
470 theta[:, x], thetas[:, x],
471 True, rr[:, x], ri[:, x],
472 ris[:, x], rs[:, x], rg[:, x], self._kbudgets,
473 PRH=rh[:, x] if krr == 7 else MISSING,
474 PHLC_HRC_MF=state['HLC_HRC_MF'][:, x],
475 PHLC_HCF_MF=state['HLC_HCF_MF'][:, x],
476 PHLI_HRI_MF=state['HLI_HRI_MF'][:, x],
477 PHLI_HCF_MF=state['HLI_HCF_MF'][:, x])
478 result = [array[:, 0] for array in result]
479 (_, _, _, _, _, rvs, rcs, thetas, src, state['CF'], ris, _, _, _, _,
480 hlc_hrc, hlc_hcf, hli_hri, hli_hcf) = result
481 return ([rvs, rcs, rrs, ris, rss, rgs, rhs], thetas, src, hlc_hrc, hlc_hcf, hli_hri,
482 hli_hcf, sv, svs)
483
484 def _ecrad(self, state, timestep, timestep_number, temperature, rv, rc, ri, qdm):
485 """
486 Call to ecRad
487 :param state: state dictionary
488 :param timestep: timestep (s)
489 :param timestep_number: current time step number
490 :param temperature, rv, rc, ri: temperature and mixing ratio profiles
491 :param qdm: dry air fraction
492 :return: the ecRad result (pyecrad exec method), arrays being dimensioned
493 (ncol, nlev) with the top of atmosphere first
494 """
495 nijt, nkt = 1, len(temperature)
496 order = -1 if self.grid.ascending else 1
497 pressure_flux = self.grid.get_pressure('FLUX', state, self.prognostic_variables)
498 temperature_flux = numpy.ndarray(pressure_flux.shape)
499 temperature_flux[1:-1] = .5 * (temperature[1:] + temperature[:-1])
500 tskin = state['Ts' if self.case.surface_type == 'ocean' else 'Tskin']
501 if self.grid.ascending:
502 temperature_flux[0] = tskin
503 temperature_flux[-1] = temperature[-1]
504 else:
505 temperature_flux[-1] = tskin
506 temperature_flux[0] = temperature[0]
507
508 x = numpy.newaxis
509 solar_irradiance = state.get('SolarIrradiance', 1366.)
510 spectral_solar_cycle_multiplier = 0.
511 if 'sza' in state:
512 cos_solar_zenith_angle = numpy.ones((nijt, )) * state['sza']
513 else:
514 obs = ephem.Observer()
515 obs.lat = str(state['lat'])
516 obs.long = str(state['lon'])
517 obs.date = datetime.datetime.fromisoformat(self.case.start_date) + \
518 datetime.timedelta(seconds=timestep * timestep_number)
519 sun = ephem.Sun(obs)
520 sun.compute(obs)
521 cos_solar_zenith_angle = numpy.ones((nijt, )) * \
522 numpy.cos(numpy.pi / 2. - sun.alt)
523 fractional_std = numpy.ones((nkt, )) * 1. # could be computed by the cloud scheme
524 q_liquid = rc * qdm
525 # Simple distinction between land (10um) and ocean (13um) by Zhang and Rossow
526 re_liquid = (10. if self.case.surface_type == 'ocean' else 13.)
527 re_liquid = numpy.ones((nkt, )) * re_liquid * 1.E-6 # convert in m
528 q_ice = ri * qdm
529 # Liou and Ou
530 temperature_c = numpy.minimum(temperature - self.cst.Tt, -0.1)
531 re_ice = 326.3 + temperature_c * \
532 (12.42 + temperature_c * (0.197 + temperature_c * 0.0012))
533 re_ice = numpy.minimum(numpy.maximum(re_ice, 40), 130) * 1.E-6
534 overlap_param = numpy.ones((nkt - 1, )) # 1 for max
535 tskin = numpy.ones((nijt, )) * tskin
536 sw_albedo = numpy.ones((nijt, )) * state.get('albedo', 1.) # albedo diffuse
537 sw_albedo_direct = sw_albedo.copy() # albedo direct
538 lw_emissivity = numpy.ones((nijt, )) * state.get('emissivity', 1.) # emissivity
539 q = rv * qdm
540
541 # pyecrad arrays are dimensioned (ncol, nlev), top of atmosphere first
542 return self._pyecrad.exec(
543 pressure_flux[x, ::order], temperature_flux[x, ::order],
544 cos_solar_zenith_angle, tskin, sw_albedo, lw_emissivity,
545 cloud_fraction=state['CF'][x, ::order],
546 fractional_std=fractional_std[x, ::order],
547 q_liquid=q_liquid[x, ::order], re_liquid=re_liquid[x, ::order],
548 q_ice=q_ice[x, ::order], re_ice=re_ice[x, ::order],
549 overlap_param=overlap_param[x, ::order],
550 sw_albedo_direct=sw_albedo_direct,
551 solar_irradiance=solar_irradiance,
552 spectral_solar_cycle_multiplier=spectral_solar_cycle_multiplier,
553 h2o=q[x, ::order], h2o_unit=self._pyecrad.IMassMixingRatio)
554
555 def _shallow(self, state, timestep, rmix, theta, sv, svs, rhodj, rhodref, pressure, exner,
556 dzz, z_flux, sfth, sfrv):
557 """
558 Shallow convection (EDKF mass-flux scheme, SHALLOW_MF)
559 :param state: state dictionary (u, v, tke, and the mass-flux cloud variables rc_MF,
560 ri_MF, CF_MF, HLC_*_MF, HLI_*_MF and WEIGHT_MF_CLOUD, which are updated)
561 :param timestep: timestep (s)
562 :param rmix: list of the 7 mixing ratios (rv, rc, rr, ri, rs, rg, rh)
563 :param theta: potential temperature
564 :param sv, svs: scalar variables and their sources (number of variables, levels)
565 :param rhodj, rhodref, pressure, exner: dry density times volume, dry density, pressure,
566 Exner function
567 :param dzz, z_flux: layer thicknesses and altitudes of the flux levels
568 :param sfth, sfrv: surface fluxes of potential temperature and of vapour mixing ratio
569 :return: (du_mf, dv_mf, dtke_mf, dthl_mf, drt_mf, dsv_mf, sigs_mf, flxzthvmf, flxzumf,
570 flxzvmf): tendencies, subgrid standard deviation of s and fluxes used by the
571 turbulence scheme
572 """
573 krr = self.krr
574 ksv = len(self.scalar_variables)
575 nijt, nkt = 1, len(pressure)
576 # Updraft properties
577 pthl_up = numpy.zeros((nkt, ))
578 prt_up = numpy.zeros((nkt, ))
579 prv_up = numpy.zeros((nkt, ))
580 prc_up = numpy.zeros((nkt, ))
581 pri_up = numpy.zeros((nkt, ))
582 pu_up = numpy.zeros((nkt, ))
583 pv_up = numpy.zeros((nkt, ))
584 ptke_up = numpy.zeros((nkt, ))
585 pthv_up = numpy.zeros((nkt, ))
586 pw_up = numpy.zeros((nkt, ))
587 pfrac_up = numpy.zeros((nkt, ))
588 pemf = numpy.zeros((nkt, ))
589 ptaufunc = numpy.zeros((nkt, ))
590
591 # Other arrays
592 rm = numpy.array(rmix)
593 if self.grid.ascending:
594 z_flux_trunc = z_flux[:-1]
595 else:
596 z_flux_trunc = z_flux[1:]
597
598 x = numpy.newaxis
599 result = self._pyphyex.PYSHALLOW_MF(
600 nijt, nkt, 1 if self.grid.ascending else -1,
601 0, krr, 2, 3, ksv, False, 0, 0,
602 timestep, dzz[:, x], z_flux_trunc[:, x], rhodj[:, x],
603 rhodref[:, x], pressure[:, x], exner[:, x],
604 numpy.ones((nijt, )) * sfth, numpy.ones((nijt, )) * sfrv, theta[:, x],
605 rm[:krr, :, x], state['u'][:, x], state['v'][:, x], state['tke'][:, x],
606 sv[:, :, x], pthl_up[:, x], prt_up[:, x], prv_up[:, x], prc_up[:, x],
607 pri_up[:, x], pu_up[:, x], pv_up[:, x], ptke_up[:, x], pthv_up[:, x],
608 pw_up[:, x], pfrac_up[:, x], pemf[:, x], ptaufunc[:, x],
609 self.dx, self.dy, PRSVS=svs[:, :, x], KBUDGETS=self._kbudgets)
610 result = [array[..., 0] for array in result]
611 (du_mf, dv_mf, dtke_mf, dthl_mf, drt_mf, dsv_mf, sigs_mf,
612 state['rc_MF'], state['ri_MF'], state['CF_MF'], state['HLC_HRC_MF'],
613 state['HLC_HCF_MF'], state['HLI_HRI_MF'], state['HLI_HCF_MF'],
614 state['WEIGHT_MF_CLOUD'],
615 flxzthvmf, _, _, flxzumf, flxzvmf, _) = result[:21]
616 return (du_mf, dv_mf, dtke_mf, dthl_mf, drt_mf, dsv_mf, sigs_mf, flxzthvmf, flxzumf,
617 flxzvmf)
618
619 def _turb(self, state, timestep, rmix, rsrc, theta, us, vs, ws, thetas, svs, tkes, sv,
620 src, rhodj, pressure, dzz, z_flux, sfth, sfrv, sfu, sfv, flxzthvmf, flxzumf,
621 flxzvmf):
622 """
623 Turbulence (TURB)
624 :param state: state dictionary (u, v, w, tke and Zs are used)
625 :param timestep: timestep (s)
626 :param rmix: list of the 7 mixing ratios (rv, rc, rr, ri, rs, rg, rh)
627 :param rsrc: list of the 7 mixing ratio sources (rvs, rcs, rrs, ris, rss, rgs, rhs)
628 :param theta: potential temperature
629 :param us, vs, ws, thetas, svs, tkes: sources of wind, potential temperature, scalar
630 variables (number of variables, levels) and TKE
631 :param sv: scalar variables (number of variables, levels)
632 :param src: second-order flux s'r'c/2Sigma_s2
633 :param rhodj, pressure: dry density times volume, pressure
634 :param dzz, z_flux: layer thicknesses and altitudes of the flux levels
635 :param sfth, sfrv, sfu, sfv: surface fluxes of potential temperature, of vapour mixing
636 ratio and of momentum
637 :param flxzthvmf, flxzumf, flxzvmf: fluxes computed by the mass-flux scheme
638 :return: (us, vs, ws, thetas, prs, svs, tkes, sigs_turb, dthetal_turb, drt_turb):
639 updated sources (prs: array of the krr mixing ratio sources), subgrid standard
640 deviation of s and tendencies of the liquid potential temperature and of the
641 total mixing ratio
642 """
643 krr = self.krr
644 ksv = len(self.scalar_variables)
645 nijt, nkt = 1, len(pressure)
646 rv = rmix[0]
647 sfsv = numpy.zeros((ksv, ))
648 hlbcx = hlbcy = numpy.array(['cycl', 'cycl'], dtype=('S', 4))
649 kgradientsleo, kgradientsgog, khalo, ksplit = 0, 0, 1, 1
650 ocloudmodiflm = False
651 ksv_lgbeg, ksv_lgend = 0, 0
652 # indexes (from 1) of the LIMA concentrations of precipitating species (0 if absent)
653 ksv_lima_nr, ksv_lima_ns, ksv_lima_ng, ksv_lima_nh = (
654 self.scalar_variables.index('lima_' + name) + 1
655 if 'lima_' + name in self.scalar_variables else 0
656 for name in ('NR', 'NS', 'NG', 'NH'))
657 o2d, onomixlg, oflat, ocouples = False, False, False, False
658 oblowsnow, oibm, oflyer, ocompute_src = False, False, True, True
659 rsnow = 1.
660 oocean, odeepoc, odiag_in_run = False, False, False
661 hturblen_cl, helec = 'DELT', 'NONE'
662 dxx = dyy = dzx = dzy = numpy.ndarray((nkt, ))
663 dircosxw = dircosyw = dircoszw = cosslope = 1.
664 sinslope = 0.
665 hgradleo = numpy.ndarray((kgradientsleo, nkt))
666 hgradgog = numpy.ndarray((kgradientsgog, nkt))
667 lengthm, lengthh = numpy.zeros((nkt, )), numpy.zeros((nkt, ))
668 mfmoist = numpy.zeros((nkt, ))
669 cei = numpy.zeros((nkt, ))
670 cei_min, cei_max = 0.001E-06, 0.01E-06
671 coef_ampl_sat = 5.
672 bl_depth, sbl_depth = 0., 0.
673 prm = numpy.array(rmix)
674 prs = numpy.array(rsrc)
675 thvref = theta * (1 + rv * self.cst.Rv / self.cst.Rd) / (1 + prm.sum(axis=0))
676 nvext_turb = self._NVEXT_TURB
677 krrl = 2
678 krri = 3 if krr == 6 else 4
679 psea_ucu = psea_vcu = 0.
680
681 def x(array, reverse=False):
682 """Extend vertical dimension and add horizontal one"""
683 if not reverse:
684 try:
685 len(array)
686 if len(array.shape) == 1:
687 new = numpy.ndarray((array.shape[0] + 2, ))
688 new[1:-1] = array
689 new[0] = new[1]
690 new[-1] = new[-2]
691 return new[:, numpy.newaxis]
692 if len(array.shape) == 2:
693 new = numpy.ndarray((array.shape[0], array.shape[1] + 2))
694 new[:, 1:-1] = array
695 new[:, 0] = new[:, 1]
696 new[:, -1] = new[:, -2]
697 return new[:, :, numpy.newaxis]
698 except TypeError:
699 return numpy.ones((nijt, )) * array
700 raise ValueError(type(array), str(array))
701 else:
702 if len(array.shape) == 3:
703 return array[:, 1:-1, 0]
704 if len(array.shape) == 2:
705 return array[1:-1, 0]
706
707 us = us * rhodj
708 vs = vs * rhodj
709 ws = ws * rhodj
710 thetas = thetas * rhodj
711 tkes = tkes * rhodj
712 prs = prs * rhodj[numpy.newaxis, :]
713 svs = svs * rhodj
714 if self.grid.ascending:
715 z_flux_trunc = z_flux[:-1]
716 else:
717 z_flux_trunc = z_flux[1:]
718
719 result = self._pyphyex.PYTURB(
720 nijt, nkt + 2 * nvext_turb, 1 if self.grid.ascending else -1, nvext_turb,
721 krr, krrl, krri, hlbcx, hlbcy, kgradientsleo, kgradientsgog,
722 khalo, ksplit, ocloudmodiflm, ksv, ksv_lgbeg, ksv_lgend,
723 ksv_lima_nr, ksv_lima_ns, ksv_lima_ng, ksv_lima_nh,
724 o2d, onomixlg, oflat, ocouples, oblowsnow, oibm, oflyer,
725 ocompute_src, rsnow, oocean, odeepoc, odiag_in_run,
726 hturblen_cl, self.full_phyex_namel['PHYEX']['CMICRO'], helec, timestep, 999,
727 x(dxx), x(dyy), x(dzz), x(dzx), x(dzy), x(z_flux_trunc),
728 x(dircosxw), x(dircosyw), x(dircoszw), x(cosslope), x(sinslope),
729 x(rhodj), x(thvref), x(hgradleo), x(hgradgog), x(state['Zs']),
730 x(sfth), x(sfrv), sfsv[:, numpy.newaxis], x(sfu), x(sfv),
731 x(psea_ucu), x(psea_vcu),
732 x(pressure), x(state['u']), x(state['v']), x(state['w']),
733 x(state['tke']), x(sv), x(src), x(lengthm), x(lengthh), x(mfmoist),
734 x(bl_depth), x(sbl_depth), x(cei), cei_min, cei_max, coef_ampl_sat,
735 x(theta), x(prm[:krr, ...]), x(us), x(vs), x(ws), x(thetas),
736 x(prs[:krr, ...]), x(svs), x(tkes),
737 x(flxzthvmf), x(flxzumf), x(flxzvmf),
738 self._kbudgets, missingOUT=['PEDR', 'PLEM', 'PDPMF', 'PTPMF',
739 'PTR', 'PDISS', 'PIBM_XMUT', 'PCURRENT_TKE_DISS'])
740
741 result = [x(array, reverse=True) for array in result]
742 (_, _, _, _, us, vs, ws, thetas, prs, svs, tkes, sigs_turb, _,
743 _, _, _, _, _, _, _, _, dthetal_turb, drt_turb, _) = result
744
745 us = us / rhodj
746 vs = vs / rhodj
747 ws = ws / rhodj
748 thetas = thetas / rhodj
749 tkes = tkes / rhodj
750 dthetal_turb = dthetal_turb / rhodj
751 drt_turb = drt_turb / rhodj
752 prs = prs / rhodj[numpy.newaxis, :]
753 svs = svs / rhodj
754 return (us, vs, ws, thetas, prs, svs, tkes, sigs_turb, dthetal_turb, drt_turb)
755
756 def _microphysics(self, state, timestep, rmix, rsrc, theta, thetas, sv, svs, rhodref,
757 rhodj, exner, pressure, dzz, dthrad, w_act, hlc_hrc, hlc_hcf, hli_hri,
758 hli_hcf):
759 """
760 Microphysics (LIMA or RAIN_ICE)
761 :param state: state dictionary (ni, CF and sigs are used; ni, and CF, ICEFR and PRCFR
762 with LIMA, are updated)
763 :param timestep: timestep (s)
764 :param rmix: list of the 7 mixing ratios (rv, rc, rr, ri, rs, rg, rh)
765 :param rsrc: list of the 7 mixing ratio sources (rvs, rcs, rrs, ris, rss, rgs, rhs)
766 :param theta, thetas: potential temperature and its source
767 :param sv, svs: scalar variables and their sources (number of variables, levels)
768 :param rhodref, rhodj, exner, pressure: dry density, dry density times volume, Exner
769 function, pressure
770 :param dzz: layer thicknesses
771 :param dthrad: radiative tendency (LIMA only)
772 :param w_act: vertical velocity used for the activation (LIMA only)
773 :param hlc_hrc, hlc_hcf, hli_hri, hli_hcf: subgrid cloud (high/low content) variables
774 :return: (thetas, prs, svs, hlc_hrc, hlc_hcf, hli_hri, hli_hcf), prs being the array
775 of the krr mixing ratio sources (number of variables, levels)
776 """
777 krr = self.krr
778 ksv = len(self.scalar_variables)
779 nijt, nkt = 1, len(pressure)
780 lima = self.full_phyex_namel['PHYEX']['CMICRO'] == 'LIMA'
781 empty_soa = numpy.zeros((0, nkt, nijt)) # no secondary organic aerosols
782 x = numpy.newaxis
783
784 prm = numpy.array([r[:, x] for r in rmix[:krr]])
785 prs = numpy.array([r[:, x] for r in rsrc[:krr]])
786 dummy = rsrc[3].copy() * 0.
787
788 if lima:
789 # reference virtual potential temperature at the first level
790 klevgrd = 0 if self.grid.ascending else -1
791 rall = sum(r[klevgrd] for r in rmix)
792 thvrefzikb = theta[klevgrd] * (1. + rmix[0][klevgrd] * self.cst.Rv / self.cst.Rd) / \
793 (1. + rall)
794 result = self._pyphyex.PYLIMA(
795 ksv, nijt, nkt, 1 if self.grid.ascending else -1, 0,
796 self.full_phyex_namel['PHYEX']['CACTCCN'], self._kbudgets, krr, timestep,
797 False, rhodref[:, x], exner[:, x], dzz[:, x], thvrefzikb, rhodj[:, x],
798 pressure[:, x], 0, 0, 0, False, False, False, dthrad[:, x],
799 theta[:, x], prm, sv[:, :, x], state['ni'][:, x], w_act[:, x],
800 sv[:, :, x].copy(), empty_soa, empty_soa,
801 thetas[:, x], prs, svs[:, :, x],
802 state['CF'][:, x], state['ICEFR'][:, x], state['PRCFR'][:, x],
803 PHLC_HCF=hlc_hcf[:, x], PHLC_HRC=hlc_hrc[:, x],
804 PHLI_HCF=hli_hcf[:, x], PHLI_HRI=hli_hri[:, x])
805 (state['ni'], _, thetas, prs, svs, _, _, _, _, _, _, _, _,
806 cldfr, icefr, prcfr, _, hlc_hcf, hlc_hrc, hli_hcf, hli_hri) = result
807 state['CF'], state['ICEFR'], state['PRCFR'] = \
808 cldfr[:, 0], icefr[:, 0], prcfr[:, 0]
809 svs = svs[:, :, 0]
810 else:
811 result = self._pyphyex.PYRAIN_ICE(
812 nijt, nkt, 1 if self.grid.ascending else -1, 0, False, False,
813 MISSING, timestep, krr, exner[:, x], dzz[:, x], rhodj[:, x],
814 rhodref[:, x], exner[:, x], pressure[:, x], state['ni'][:, x],
815 state['CF'][:, x],
816 dummy[:, x], dummy[:, x], dummy[:, x], dummy[:, x],
817 hlc_hrc[:, x], hlc_hcf[:, x], hli_hri[:, x], hli_hcf[:, x],
818 theta[:, x], prm, thetas[:, x], prs, state['sigs'][:, x],
819 self._kbudgets, MISSING, MISSING, MISSING, MISSING, MISSING, MISSING,
820 MISSING, MISSING, MISSING, MISSING, MISSING, MISSING, MISSING, MISSING,
821 MISSING, MISSING, MISSING, MISSING, MISSING,
822 MISSING, MISSING)
823
824 (state['ni'], hlc_hrc, hlc_hcf, hli_hri, hli_hcf,
825 thetas, prs, _, _, _, _, _, _, _, _, _, ) = result
826 state['ni'] = state['ni'][:, 0]
827 return (thetas[:, 0], prs[:, :, 0], svs, hlc_hrc[:, 0], hlc_hcf[:, 0], hli_hri[:, 0],
828 hli_hcf[:, 0])
829
830 def read_budgets(self, state, scheme, nijt, nkt, rhodj, nvext=0):
831 """
832 Read (and reset) the budgets stored by the PHYEX library and put them in the state
833 :param state: state dictionary to fill with the bu_<scheme>_<variable>_<process>
834 variables (tendencies in s-1, e.g. K s-1 for TH which is a potential
835 temperature budget, kg kg-1 s-1 for mixing ratios)
836 :param scheme: name of the scheme (used in the variable names)
837 :param nijt, nkt: dimensions used in the call to the scheme
838 :param rhodj: rhodj (dry density times volume), the budgets are divided by this field
839 :param nvext: number of extra levels added at both ends of the column for the call
840 """
841 if not self.budgets:
842 return
843 nbud = self._pyphyex.PYBUDGET_OFFLINE_GET_SIZE()
844 if nbud == 0:
845 return
846 kbudget, names = self._pyphyex.PYBUDGET_OFFLINE_GET_NAMES(nbud)
847 tend = self._pyphyex.PYBUDGET_OFFLINE_GET(nijt, nkt, nbud) # shape (nbud, nkt, nijt)
848 for ibud in range(nbud):
849 key = f'bu_{scheme}_{self.BUDGET_VARIABLES[kbudget[ibud] - 1]}_{names[ibud].strip()}'
850 self.budget_add(state, key, tend[ibud, nvext:nkt - nvext, 0] / rhodj)
851
852 def finalize(self):
853 """Close PHYEX resources"""
854 super().finalize()
855 if self._pyphyex is not None:
856 self._pyphyex.close()
857 if self._pyecrad is not None:
858 self._pyecrad.close()
859
860
862 """
863 Implementation of a PHYEX timestep using the AROME way
864 This class is not intended to be used directly
865 """
866
867 def step(self, state, timestep, timestep_number):
868 """Advance the state by one PHYEX timestep"""
869
870 # Minimum value for TKE
871 if self.tkemin is not None:
872 before = self.budget_fields(state)
873 state['tke'] = numpy.maximum(self.tkemin, state['tke'])
874 self.budget_record(state, before, 'driver', 'TKEMIN', ['tke'], timestep)
875
876 # Save initial state and control
877 state0 = {k: v.copy() for (k, v) in state.items()}
878
879 # Preparation: grid and other dimensions
880 pressure = self.grid.get_pressure('MASS', state, self.prognostic_variables)
881 z_mass = self.grid.get_altitude('MASS', state, self.prognostic_variables)
882 z_flux = self.grid.get_altitude('FLUX', state, self.prognostic_variables)
883 if self.grid.ascending:
884 dzz = numpy.diff(z_flux)
885 if dzz[-1] == numpy.inf:
886 dzz[-1] = dzz[-2]
887 else:
888 dzz = -numpy.diff(z_flux)
889 if dzz[0] == numpy.inf:
890 dzz[0] = dzz[1]
891 nijt = 1
892 nkt = len(pressure)
893 cmicro = self.full_phyex_namel['PHYEX']['CMICRO']
894 if cmicro not in ('ICE3', 'ICE4', 'LIMA'):
895 raise Phyex1DError('Unknown microphysics scheme')
896 krr = self.krr
897 lima = cmicro == 'LIMA'
898 ksv = len(self.scalar_variables)
899
900 # Preparation: conversions
901 exner = (pressure / 1.E5) ** (self.cst.Rd / self.cst.Cpd)
902 if 'T' in self.prognostic_variables:
903 theta = state['T'] / exner
904 temperature = state['T']
905 else:
906 theta = state['Theta']
907 temperature = exner * theta
908 if 'qv' in self.prognostic_variables:
909 qdm = 1.
910 for var in ('qv', 'qc', 'qr', 'qi', 'qs', 'qg', 'qh'):
911 qdm -= state[var]
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)
916 rhodref = rho * qdm
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
924 else:
925 qdm = 1.
926 for var in ('rv', 'rc', 'rr', 'ri', 'rs', 'rg', 'rh'):
927 qdm += state[var]
928 qdm = 1. / qdm
929 rv = state['rv']
930 rc = state['rc']
931 rr = state['rr']
932 ri = state['ri']
933 rs = state['rs']
934 rg = state['rg']
935 rh = state['rh']
936 div = 1 + state['rv']
937 for var in ('rc', 'rr', 'ri', 'rs', 'rg', 'rh'):
938 if var in self.prognostic_variables:
939 div += state[var]
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)
943
944 # Preparation: derived fields
945 rhodj = dzz * rho
946
947 # Preparation: tendencies
948 us = state['u'] / timestep
949 vs = state['v'] / timestep
950 ws = state['w'] / timestep
951 tkes = state['tke'] / timestep
952 rvs = rv / timestep
953 rcs = rc / timestep
954 rrs = rr / timestep
955 ris = ri / timestep
956 rss = rs / timestep
957 rgs = rg / timestep
958 rhs = rh / timestep
959 thetas = theta / timestep
960 if 'qv' in self.prognostic_variables:
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, ))
968 if 'T' in self.prognostic_variables:
969 dtemperature = numpy.zeros((nkt, ))
970
971 # Preparation: misc fields
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))
975 svs = sv / timestep
976 dthrad = numpy.zeros((nkt, )) # radiative tendency (not used by LIMA in the 1D model)
977 if lima:
978 w_act = self._lima_activation_velocity(state, timestep * timestep_number, z_mass,
979 pressure)
980
981
986 if self.full_phyex_namel['PHYEX']['CMICRO'] == 'NONE':
987 src = numpy.zeros((nkt, ))
988 elif cmicro in ('ICE3', 'ICE4', 'LIMA'):
989 if 'qv' in self.prognostic_variables:
990 rvsin = rvs.copy()
991 rcsin = rcs.copy()
992 risin = ris.copy()
993 if lima:
994 rrsin, rssin, rgsin, rhsin = rrs.copy(), rss.copy(), rgs.copy(), rhs.copy()
995 if 'T' in self.prognostic_variables:
996 thsin = thetas.copy()
997 ((rvs, rcs, rrs, ris, rss, rgs, rhs), thetas, src, hlc_hrc, hlc_hcf, hli_hri,
998 hli_hcf, sv, svs) = self._adjustment(
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)
1002 self.read_budgets(state, 'adjust', nijt, nkt, rhodj)
1003 theta = thetas * timestep
1004 temperature = theta * exner
1005 rv = rvs * timestep
1006 rc = rcs * timestep
1007 ri = ris * timestep
1008 if lima:
1009 rr, rs, rg, rh = rrs * timestep, rss * timestep, rgs * timestep, rhs * timestep
1010
1011 if 'qv' in self.prognostic_variables:
1012 qv = rv * qdm
1013 qc = rc * qdm
1014 qr = rr * qdm
1015 qi = ri * qdm
1016 qs = rs * qdm
1017 qg = rg * qdm
1018 qh = rh * qdm
1019 gas_constant = self.cst.Rd + state['qv'] * (self.cst.Rv - self.cst.Rd)
1020 for var in ('qc', 'qr', 'qi', 'qs', 'qg', 'qh'):
1021 if var in self.prognostic_variables:
1022 gas_constant += - state[var] * self.cst.Rd
1023 rho = pressure / (gas_constant * temperature)
1024 rhodref = rho * qdm
1025 dqv += (rvs - rvsin) * qdm
1026 dqc += (rcs - rcsin) * qdm
1027 dqi += (ris - risin) * qdm
1028 if lima:
1029 dqr += (rrs - rrsin) * qdm
1030 dqs += (rss - rssin) * qdm
1031 dqg += (rgs - rgsin) * qdm
1032 dqh += (rhs - rhsin) * qdm
1033 else:
1034 div = 1. + state['rv']
1035 for var in ('rc', 'rr', 'ri', 'rs', 'rg', 'rh'):
1036 if var in self.prognostic_variables:
1037 div += state[var]
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)
1041
1042 if 'T' in self.prognostic_variables:
1043 dtemperature += (thetas - thsin) * exner
1044
1045 # Update state to be able to recompute pressure and altitude
1046 if 'qv' in self.prognostic_variables:
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
1054 else:
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
1062 if 'T' in self.prognostic_variables:
1063 state['T'] = state0['T'] + dtemperature * timestep
1064 else:
1065 state['Theta'] = thetas * timestep
1066 pressure = self.grid.get_pressure('MASS', state, self.prognostic_variables)
1067 z_mass = self.grid.get_altitude('MASS', state, self.prognostic_variables)
1068 z_flux = self.grid.get_altitude('FLUX', state, self.prognostic_variables)
1069 if self.grid.ascending:
1070 dzz = numpy.diff(z_flux)
1071 if dzz[-1] == numpy.inf:
1072 dzz[-1] = dzz[-2]
1073 else:
1074 dzz = -numpy.diff(z_flux)
1075 if dzz[0] == numpy.inf:
1076 dzz[0] = dzz[1]
1077 else:
1078 raise Phyex1DError('Wrong CMICRO scheme choice for adjustment')
1079
1080
1085 if self.case.radiation == 'on':
1086 if self.full_phyex_namel['PHYEX']['RAD'] == 'NONE':
1087 pass
1088 elif self.full_phyex_namel['PHYEX']['RAD'] == 'ECRAD':
1089 result = self._ecrad(state, timestep, timestep_number, temperature, rv, rc,
1090 ri, qdm)
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 +
1097 self.cst.Cpv * rv +
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] / \
1101 (rho * cp * dzz)
1102 dt_rad_sw = -numpy.diff((state['sw_dn'] - state['sw_up'])[::order])[::order] / \
1103 (rho * cp * dzz)
1104 state['dt_rad_lw'] = dt_rad_lw
1105 state['dt_rad_sw'] = dt_rad_sw
1106 if self.budgets:
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)
1109 if 'T' in self.prognostic_variables:
1110 dtemperature += dt_rad_lw + dt_rad_sw
1111 else:
1112 thetas += (dt_rad_lw + dt_rad_sw) / exner
1113 else:
1114 raise Phyex1DError('Wrong RAD scheme choice')
1115
1116
1121 klevgrd = 0 if self.grid.ascending else -1
1122 zgrd = z_mass[klevgrd] - state.get('Zs', 0.) # height of the first level above the surface
1123 # temperature and specific humidity (needed by the surface schemes) at the first level
1124 if 'T' in self.prognostic_variables:
1125 t_grd = state['T'][klevgrd]
1126 else:
1127 t_grd = state['Theta'][klevgrd] * exner[klevgrd]
1128 if 'qv' in self.prognostic_variables:
1129 qv_grd = state['qv'][klevgrd]
1130 else:
1131 qv_grd = state['rv'][klevgrd] * qdm[klevgrd]
1132 # Fluxes that must be computed by the surface scheme (the others are prescribed by the
1133 # case or computed by the driver)
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
1138
1139 def ustar2fluxes(ustar, u, v):
1140 """
1141 Convert ustar into momentum fluxes
1142 :param ustar: ustar value
1143 :param u, v: wind components
1144 :return: w'u', w'v'
1145 """
1146 alpha = numpy.arctan2(v, u)
1147 return - ustar**2 * numpy.cos(alpha), - ustar**2 * numpy.sin(alpha)
1148
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)
1153 else:
1154 latent_heat = self.cst.LsTt - (self.cst.Cpv - self.cst.Ci) * \
1155 (surface_temperature - self.cst.Tt)
1156
1157 # Surface schemes output must be: sshf (W m-2) and swf (kg m-2 s-1)
1158 sshf_scheme = None
1159 swf_scheme = None
1160 sfu_scheme = None
1161 sfv_scheme = None
1162 if self.full_phyex_namel['PHYEX']['SURFACE'] == 'NONE':
1163 # numpy values (and not python floats) because they can be put in the state
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:
1169 pass
1170 elif self.full_phyex_namel['PHYEX']['SURFACE'] == 'WASP':
1171 # WASP computes the three fluxes; only the fluxes that are needed are used (see below)
1172 sshf_scheme, swf_scheme, ustar = self._wasp_surface_fluxes(
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])
1177 elif self.full_phyex_namel['PHYEX']['SURFACE'] == 'BETA':
1178 sshf_scheme, swf_scheme, ustar = self._beta_surface_fluxes(
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])
1183 else:
1184 raise Phyex1DError('Wrong SURFACE scheme choice')
1185
1186 if self.case.surface_forcing_temp == 'none':
1187 if sshf_scheme is None:
1188 raise Phyex1DError("Surface scheme didn't compute sshf")
1189 sshf = sshf_scheme
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':
1195 sshf = sshf_scheme
1196 else:
1197 raise Phyex1DError('Wrong surface_forcing_temp option')
1198
1199 if self.case.surface_forcing_moisture == 'none':
1200 if swf_scheme is None:
1201 raise Phyex1DError("Surface scheme didn't compute swf")
1202 swf = swf_scheme
1203 elif self.case.surface_forcing_moisture == 'kinematic':
1204 raise NotImplementedError('surface_forcing_moisture=kinematic')
1205 elif self.case.surface_forcing_moisture == 'surface_flux':
1206 # W m-2 --> kg m-2 s-1
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")
1211 swf = swf_scheme
1212 elif self.case.surface_forcing_moisture == 'mrsos':
1213 raise NotImplementedError('surface_forcing_moisture=mrsos')
1214 else:
1215 raise Phyex1DError('Wrong surface_forcing_moisture option')
1216
1217
1218 # The turbulence scheme waits for w'r' and w'th'
1219 # for the water flux, we want w'r' (division by rhod) and not w'q' (division by rho)
1220 sfrv = swf / rhodref[0 if self.grid.ascending else -1] # kg m-2 s-1 --> kg/kg m s-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]) # W m-2 --> K m s-1
1224
1225 # Momentum fluxes (after the heat and moisture fluxes, used by the stability correction)
1226 if self.case.surface_forcing_wind == 'none':
1227 sfu = sfu_scheme
1228 sfv = sfv_scheme
1229 elif self.case.surface_forcing_wind == 'z0':
1230 windgrd = numpy.sqrt(state['u'][klevgrd]**2 + state['v'][klevgrd]**2)
1231 if self.full_phyex_namel['PHYEX']['LSTAB']:
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]))
1235 else:
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])
1240 else:
1241 raise Phyex1DError('Wrong surface_forcing_wind option')
1242
1243 state['sfrv'] = sfrv # kg/kg m s-1 (w'r' mixing ratio)
1244 state['swf'] = swf # kg m-2 s-1
1245 state['slhf'] = swf * latent_heat # W m-2 using Lv or Ls depending on temperature °C sign
1246 state['sfth'] = sfth # K m s-1 (w'th' theta)
1247 state['sshf'] = sshf # W m-2
1248
1249
1254 if self.full_phyex_namel['PHYEX']['CSCONV'] == 'NONE':
1255 flxzthvmf = flxzumf = flxzvmf = sigs_mf = numpy.zeros((nkt, ))
1256 elif self.full_phyex_namel['PHYEX']['CSCONV'] == 'EDKF':
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)
1261 self.read_budgets(state, 'shallow', nijt, nkt, rhodj)
1262 us += du_mf
1263 vs += dv_mf
1264 tkes += dtke_mf
1265 svs += dsv_mf
1266 if 'Theta' in self.prognostic_variables:
1267 thetas += dthl_mf
1268 else:
1269 dtemperature += dthl_mf * exner
1270 if 'rv' in self.prognostic_variables:
1271 rvs += drt_mf
1272 else:
1273 dqv += drt_mf * qdm
1274 else:
1275 raise Phyex1DError('Wrong CSCONV scheme choice')
1276
1277
1282 if self.full_phyex_namel['PHYEX']['CTURB'] == 'NONE':
1283 pass
1284 elif self.full_phyex_namel['PHYEX']['CTURB'] == 'TKEL':
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)
1290 self.read_budgets(state, 'turb', nijt, nkt + 2 * self._NVEXT_TURB, rhodj,
1291 self._NVEXT_TURB)
1292
1293 if 'T' in self.prognostic_variables:
1294 dtemperature += dthetal_turb * exner
1295 if 'qv' in self.prognostic_variables:
1296 print('We must take into account tendencies on rc and ri. Here and in arome')
1297 dqv += drt_turb * qdm
1298 else:
1299 rvs = prs[0]
1300 rcs = prs[1]
1301 rrs = prs[2]
1302 ris = prs[3]
1303 rss = prs[4]
1304 rgs = prs[5]
1305 if krr == 7:
1306 rhs = prs[6]
1307 state['sigs'] = numpy.sqrt(sigs_mf**2 + sigs_turb**2)
1308 else:
1309 raise Phyex1DError('Wrong CTURB scheme choice')
1310
1311
1316 if self.full_phyex_namel['PHYEX']['CMICRO'] == 'NONE':
1317 pass
1318 elif cmicro in ('ICE3', 'ICE4', 'LIMA'):
1319 if 'qv' in self.prognostic_variables:
1320 rvsin = rvs.copy()
1321 rcsin = rcs.copy()
1322 rrsin = rrs.copy()
1323 risin = ris.copy()
1324 rssin = rss.copy()
1325 rgsin = rgs.copy()
1326 rhsin = rhs.copy()
1327 if 'T' in self.prognostic_variables:
1328 thsin = thetas.copy()
1329
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)
1334 self.read_budgets(state, 'micro', nijt, nkt, rhodj)
1335
1336 rvs = prs[0]
1337 rcs = prs[1]
1338 rrs = prs[2]
1339 ris = prs[3]
1340 rss = prs[4]
1341 rgs = prs[5]
1342 if krr == 7:
1343 rhs = prs[6]
1344
1345 if 'qv' in self.prognostic_variables:
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
1352 if krr == 7:
1353 dqh += (prs[6] - rhsin) * qdm
1354
1355 if 'T' in self.prognostic_variables:
1356 dtemperature += (thetas - thsin) * exner
1357 else:
1358 raise Phyex1DError('Wrong CMICRO scheme choice for microphysics')
1359
1360
1365 if 'qv' in self.prognostic_variables:
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
1373 else:
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
1381 if 'T' in self.prognostic_variables:
1382 state['T'] = state0['T'] + dtemperature * timestep
1383 else:
1384 state['Theta'] = thetas * timestep
1385 state['u'] = us * timestep
1386 state['v'] = vs * timestep
1387 state['tke'] = tkes * timestep
1388 for ivar, var in enumerate(self.scalar_variables):
1389 state[var] = svs[ivar] * timestep
1390 return state
1391
1392
1394 """
1395 AROME physics with T and q as prognostic variables
1396 """
1397
1398 def __init__(self, dt, method, name, tag, case, grid, pyecrad=None,
1399 namel='default', dx=0., dy=0., attrs=None, budgets=False):
1400 """
1401 :param dt: timestep (s)
1402 :param method: 'step-by-step' or 'one-step'
1403 :param name: full name of the execution
1404 :param tag: tag to identify the execution
1405 :param case: Case instance describing the case
1406 :param grid: Grid object instance
1407 :param pyecrad: path to the pyecrad.py file
1408 :param namel: namelist to use: as a file name or a dictionnary
1409 :param dx, dy: mesh size
1410 :param attrs: dictionnary holding caes attributes to override
1411 :param budgets: True to add the budgets to the output
1412 """
1413 super().__init__(dt, method, name, tag, case, grid,
1414 ['T', 'qv', 'qc', 'qi', 'qr', 'qs', 'qg', 'qh', 'u', 'v', 'w', 'tke'],
1415 pyecrad, namel, dx, dy, attrs, budgets)
1416
1417
1419 """
1420 AROME physics with Theta and r as prognostic variables
1421 """
1422
1423 def __init__(self, dt, method, name, tag, case, grid, pyecrad=None,
1424 namel='default', dx=0., dy=0., attrs=None, budgets=False):
1425 """
1426 :param dt: timestep (s)
1427 :param method: 'step-by-step' or 'one-step'
1428 :param name: full name of the execution
1429 :param tag: tag to identify the execution
1430 :param case: Case instance describing the case
1431 :param grid: Grid object instance
1432 :param pyecrad: path to the pyecrad.py file
1433 :param namel: namelist to use: as a file name or a dictionnary
1434 :param dx, dy: mesh size
1435 :param attrs: dictionnary holding caes attributes to override
1436 :param budgets: True to add the budgets to the output
1437 """
1438 super().__init__(dt, method, name, tag, case, grid,
1439 ['Theta', 'rv', 'rc', 'ri', 'rr', 'rs', 'rg', 'rh', 'u', 'v', 'w', 'tke'],
1440 pyecrad, namel, dx, dy, attrs, budgets)
1441
1442
1444 """
1445 Only the forcing with T and q as prognostic variables
1446 """
1447
1448 def __init__(self, dt, method, name, tag, case, grid, pyecrad=None,
1449 namel='default', dx=0., dy=0., attrs=None):
1450 """
1451 :param dt: timestep (s)
1452 :param method: 'step-by-step' or 'one-step'
1453 :param name: full name of the execution
1454 :param tag: tag to identify the execution
1455 :param case: Case instance describing the case
1456 :param grid: Grid object instance
1457 :param pyecrad: path to the pyecrad.py file
1458 :param namel: namelist to use: as a file name or a dictionnary
1459 :param dx, dy: mesh size
1460 :param attrs: dictionnary holding caes attributes to override
1461 """
1462 super().__init__(dt, method, name, tag, case, grid,
1463 ['T', 'qv', 'qc', 'qi', 'qr', 'qs', 'qg', 'qh', 'u', 'v', 'w', 'tke'],
1464 pyecrad, namel, dx, dy, attrs)
1465
1466
1468 """
1469 Only the forcing with Theta and r as prognostic variables
1470 """
1471
1472 def __init__(self, dt, method, name, tag, case, grid, pyecrad=None,
1473 namel='default', dx=0., dy=0., attrs=None):
1474 """
1475 :param dt: timestep (s)
1476 :param method: 'step-by-step' or 'one-step'
1477 :param name: full name of the execution
1478 :param tag: tag to identify the execution
1479 :param case: Case instance describing the case
1480 :param grid: Grid object instance
1481 :param pyecrad: path to the pyecrad.py file
1482 :param namel: namelist to use: as a file name or a dictionnary
1483 :param dx, dy: mesh size
1484 :param attrs: dictionnary holding caes attributes to override
1485 """
1486 super().__init__(dt, method, name, tag, case, grid,
1487 ['Theta', 'rv', 'rc', 'ri', 'rr', 'rs', 'rg', 'rh', 'u', 'v', 'w', 'tke'],
1488 pyecrad, namel, dx, dy, attrs)
_wasp_surface_fluxes(self, state, t1, q1, exner1, rho1, u1, v1, zgrd)
Definition phyex.py:310
build_init_state(self, init_state)
Definition phyex.py:194
setup(self, init_state, duration)
Definition phyex.py:70
_turb(self, state, timestep, rmix, rsrc, theta, us, vs, ws, thetas, svs, tkes, sv, src, rhodj, pressure, dzz, z_flux, sfth, sfrv, sfu, sfv, flxzthvmf, flxzumf, flxzvmf)
Definition phyex.py:621
_lima_activation_velocity(self, state, time, z_mass, pressure)
Definition phyex.py:290
_beta_surface_fluxes(self, state, time, t1, q1, rho1, u1, v1, zgrd)
Definition phyex.py:340
_shallow(self, state, timestep, rmix, theta, sv, svs, rhodj, rhodref, pressure, exner, dzz, z_flux, sfth, sfrv)
Definition phyex.py:556
_microphysics(self, state, timestep, rmix, rsrc, theta, thetas, sv, svs, rhodref, rhodj, exner, pressure, dzz, dthrad, w_act, hlc_hrc, hlc_hcf, hli_hri, hli_hcf)
Definition phyex.py:758
read_budgets(self, state, scheme, nijt, nkt, rhodj, nvext=0)
Definition phyex.py:830
_lima_init_state(self, init_state)
Definition phyex.py:266
__init__(self, dt, method, name, tag, case, grid, prognostic_variables, pyecrad=None, namel='default', dx=0., dy=0., attrs=None, budgets=False)
Definition phyex.py:49
_init_aerosol_concentration(self, rhodref, z_mass)
Definition phyex.py:212
_ecrad(self, state, timestep, timestep_number, temperature, rv, rc, ri, qdm)
Definition phyex.py:484
_adjustment(self, state, timestep, rmix, rsrc, theta, thetas, sv, svs, rhodref, rhodj, exner, pressure, z_mass, sigqsat, mfconv, dthrad, w_act)
Definition phyex.py:407
__init__(self, dt, method, name, tag, case, grid, pyecrad=None, namel='default', dx=0., dy=0., attrs=None, budgets=False)
Definition phyex.py:1399
__init__(self, dt, method, name, tag, case, grid, pyecrad=None, namel='default', dx=0., dy=0., attrs=None, budgets=False)
Definition phyex.py:1424
step(self, state, timestep, timestep_number)
Definition phyex.py:867
__init__(self, dt, method, name, tag, case, grid, pyecrad=None, namel='default', dx=0., dy=0., attrs=None)
Definition phyex.py:1449
__init__(self, dt, method, name, tag, case, grid, pyecrad=None, namel='default', dx=0., dy=0., attrs=None)
Definition phyex.py:1473
budget_add(self, state, key, value)
budget_record(self, state, before, scheme, process, variables, timestep)
execute(self, previous_state, timestep, timestep_number)