Commit c81a69dd authored by Dion Häfner's avatar Dion Häfner

pull in changes from mobi branch

parent e73ca620
......@@ -184,3 +184,85 @@ def tempsalt_sources(vs):
vs.int_drhodS[..., vs.tau] * vs.salt_source)
vs.P_diss_sources[...] = 0.
dissipation_on_wgrid(vs, vs.P_diss_sources, aloc=aloc)
@veros_method
def biharmonic(vs, tr, f, dtr):
"""
Biharmonic mixing of tracer tr, results saved as dtr
This is essentially just a copy of tempsalt_biharmonic generalized
"""
flux_east = np.zeros_like(tr, dtype=vs.default_float_type)
flux_north = np.zeros_like(tr, dtype=vs.default_float_type)
del2 = np.zeros((vs.nx + 4, vs.ny + 4, vs.nz), dtype=vs.default_float_type)
flux_east[:-1, :, :] = -f * (tr[1:, :, :] - tr[:-1, :, :]) \
/ (vs.cost[np.newaxis, :, np.newaxis] * vs.dxu[:-1, np.newaxis, np.newaxis]) \
* vs.maskU[:-1, :, :]
flux_north[:, :-1, :] = -f * (tr[:, 1:, :] - tr[:, :-1, :]) \
/ vs.dyu[np.newaxis, :-1, np.newaxis] * vs.maskV[:, :-1, :] \
* vs.cosu[np.newaxis, :-1, np.newaxis]
flux_east[:, -1, :] = 0.
flux_north[:, -1, :] = 0.
del2[1:, 1:, :] = vs.maskT[1:, 1:, :] * (flux_east[1:, 1:, :] - flux_east[:-1, 1:, :]) \
/ (vs.cost[np.newaxis, 1:, np.newaxis] * vs.dxt[1:, np.newaxis, np.newaxis]) \
+ (flux_north[1:, 1:, :] - flux_north[1:, :-1, :]) \
/ (vs.cost[np.newaxis, 1:, np.newaxis] * vs.dyt[np.newaxis, 1:, np.newaxis])
utilities.enforce_boundaries(vs, del2)
flux_east[:-1, :, :] = f * (del2[1:, :, :] - del2[:-1, :, :]) \
/ (vs.cost[np.newaxis, :, np.newaxis] * vs.dxu[:-1, np.newaxis, np.newaxis]) \
* vs.maskU[:-1, :, :]
flux_north[:, :-1, :] = f * (del2[:, 1:, :] - del2[:, :-1, :]) \
/ vs.dyu[np.newaxis, :-1, np.newaxis] * vs.maskV[:, :-1, :] \
* vs.cosu[np.newaxis, :-1, np.newaxis]
flux_east[-1, :, :] = 0.
flux_north[:, -1, :] = 0.
dtr[1:, 1:, :] = vs.maskT[1:, 1:, :] * (flux_east[1:, 1:, :] - flux_east[:-1, 1:, :]) \
/ (vs.cost[np.newaxis, 1:, np.newaxis] * vs.dxt[1:, np.newaxis, np.newaxis]) \
+ (flux_north[1:, 1:, :] - flux_north[1:, :-1, :]) \
/ (vs.cost[np.newaxis, 1:, np.newaxis] * vs.dyt[np.newaxis, 1:, np.newaxis])
dtr[...] *= vs.maskT
# if vs.enable_conserve_energy: TODO should we do something here?
@veros_method
def horizontal_diffusion(vs, tr, dtr_hmix):
"""
Diffusion of tracer tr
"""
# aloc = np.zeros((vs.nx + 4, vs.ny + 4, vs.nz), dtype=vs.default_float_type)
flux_east = np.zeros_like(tr, dtype=vs.default_float_type)
flux_north = np.zeros_like(tr, dtype=vs.default_float_type)
# horizontal diffusion of tracer
flux_east[:-1, :, :] = vs.K_h * (tr[1:, :, :] - tr[:-1, :, :]) \
/ (vs.cost[np.newaxis, :, np.newaxis] * vs.dxu[:-1, np.newaxis, np.newaxis])\
* vs.maskU[:-1, :, :]
flux_east[-1, :, :] = 0.
flux_north[:, :-1, :] = vs.K_h * (tr[:, 1:, :] - tr[:, :-1, :]) \
/ vs.dyu[np.newaxis, :-1, np.newaxis] * vs.maskV[:, :-1, :]\
* vs.cosu[np.newaxis, :-1, np.newaxis]
flux_north[:, -1, :] = 0.
if vs.enable_hor_friction_cos_scaling:
flux_east[...] *= vs.cost[np.newaxis, :, np.newaxis] ** vs.hor_friction_cosPower
flux_north[...] *= vs.cosu[np.newaxis, :, np.newaxis] ** vs.hor_friction_cosPower
dtr_hmix[1:, 1:, :] = ((flux_east[1:, 1:, :] - flux_east[:-1, 1:, :])
/ (vs.cost[np.newaxis, 1:, np.newaxis] * vs.dxt[1:, np.newaxis, np.newaxis])
+ (flux_north[1:, 1:, :] - flux_north[1:, :-1, :])
/ (vs.cost[np.newaxis, 1:, np.newaxis] * vs.dyt[np.newaxis, 1:, np.newaxis]))\
* vs.maskT[1:, 1:, :]
# if vs.enable_conserve_energy:
# dissipation_on_wgrid(vs, vs.P_diss_hmix, int_drhodX=vs.int_drhodT[..., vs.tau])
......@@ -97,6 +97,45 @@ def _calc_implicit_part(vs, tr):
tr[2:-2, 2:-2, :, vs.taup1] = utilities.where(vs, water_mask, sol, tr[2:-2, 2:-2, :, vs.taup1])
@veros_method
def isoneutral_diffusion_decoupled(vs, tr, dtracer_iso, iso=True, skew=False):
"""
Like isoneutral_diffusion but for general tracers
"""
if iso:
K_iso = vs.K_iso
else:
K_iso = np.zeros_like(vs.K_iso)
if skew:
K_skew = vs.K_gm
else:
K_skew = np.zeros_like(vs.K_gm)
_calc_tracer_fluxes(vs, tr, K_iso, K_skew)
"""
add explicit part
"""
aloc = _calc_explicit_part(vs)
dtracer_iso[...] += aloc[...]
tr[2:-2, 2:-2, :, vs.taup1] += vs.dt_tracer * aloc[2:-2, 2:-2, :]
"""
add implicit part
"""
if iso:
aloc[...] = tr[:, :, :, vs.taup1]
_calc_implicit_part(vs, tr)
dtracer_iso[...] += (tr[:, :, :, vs.taup1] - aloc) / vs.dt_tracer
"""
dissipation by isopycnal mixing
"""
# TODO add dissipation by isopycnal mixing
# NOTE drhodS, drhodT are calculated in isoneutral.py. The rest in there is additional stuff
@veros_method
def isoneutral_diffusion(vs, tr, istemp, iso=True, skew=False):
"""
......
from veros.setup.bgc_global_4deg.bgc_global_four_degree import GlobalFourDegreeBGC
forcing:
url: https://sid.erda.dk/share_redirect/gsdZADr8to/global_4deg/forcing_4deg_global.nc
md5: ef3be0a58782771c8ee5a6d0206b87f5
ecmwf:
url: https://sid.erda.dk/share_redirect/gsdZADr8to/global_4deg/ecmwf_4deg_monthly_nc4.nc
md5: d1b4e0e199d7a5883cf7c88d3d6bcb27
corev2:
url: https://sid.erda.dk/share_redirect/gsdZADr8to/COREv2_NYF/CNYFv2/monthly_average/ncar_rad.15JUNE2009.monthly_avg_4deg.nc
md5: 328a1bcf37b2b14671c8526e462cc1c1
This diff is collapsed.
npzd:
selected_rules:
- "group_npzd_basic"
- "group_carbon_implicit_caco3"
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment