-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update function #543
Comments
Can you show what you tried? |
[image: image.png]
This is what I wrote. I was trying to introduce a density perturbation at
the surface but, the changes don't show up. I had to setup a for loop
instead.
I'm new to python so I might just be writing something wrong but can you
help?
thank you.
…On Thu, 12 Oct 2023 at 21:02, Dion Häfner ***@***.***> wrote:
Can you show what you tried?
—
Reply to this email directly, view it on GitHub
<#543 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCKFKIHV3GTEPM4WMJODJTDX7AESTAVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONJZHA3DAOJYGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Please paste your code here instead of uploading an image. |
Yeah, sure! Here it is. I'm just modifying the ACC Model code on the veros
website to familiarise myself with it.
from veros import VerosSetup, veros_routine
from veros.variables import allocate, Variable
from veros.distributed import global_min, global_max
from veros.core.operators import numpy as npx, update, at
class EQ(VerosSetup):
@veros_routine
def set_parameter(self, state):
settings = state.settings
settings.identifier = "r11"
settings.nx, settings.ny, settings.nz = 20, 20, 15
settings.dt_mom = 4800
settings.dt_tracer = 86400 / 2.0
settings.runlen = 86400 * 365
settings.x_origin = 20.0
settings.y_origin = -21.0
settings.coord_degree = True
settings.enable_cyclic_x = True
settings.enable_neutral_diffusion = True
settings.K_iso_0 = 1000.0
settings.K_iso_steep = 500.0
settings.iso_dslope = 0.005
settings.iso_slopec = 0.01
settings.enable_skew_diffusion = True
settings.enable_hor_friction = True
settings.A_h = (2 * settings.degtom) ** 3 * 2e-11
settings.enable_hor_friction_cos_scaling = True
settings.hor_friction_cosPower = 1
settings.enable_bottom_friction = True
settings.r_bot = 1e-5
settings.enable_implicit_vert_friction = True
settings.enable_tke = True
settings.c_k = 0.1
settings.c_eps = 0.7
settings.alpha_tke = 30.0
settings.mxl_min = 1e-8
settings.tke_mxl_choice = 2
settings.kappaM_min = 2e-4
settings.kappaH_min = 2e-5
settings.enable_kappaH_profile = True
settings.K_gm_0 = 1000.0
settings.enable_eke = True
settings.eke_k_max = 1e4
settings.eke_c_k = 0.4
settings.eke_c_eps = 0.5
settings.eke_cross = 2.0
settings.eke_crhin = 1.0
settings.eke_lmin = 100.0
settings.enable_eke_superbee_advection = True
settings.enable_eke_isopycnal_diffusion = True
settings.enable_idemix = False
settings.eq_of_state_type = 3
var_meta = state.var_meta
var_meta.update(
t_star=Variable("t_star", ("yt",), "deg C", "Reference surface
temperature"),
t_rest=Variable("t_rest", ("xt", "yt"), "1/s", "Surface
temperature restoring time scale"),
)
@veros_routine
def set_grid(self, state):
vs = state.variables
ddz = npx.array(
[50.0, 70.0, 100.0, 140.0, 190.0, 240.0, 290.0, 340.0, 390.0,
440.0, 490.0, 540.0, 590.0, 640.0, 690.0]
)
vs.dxt = update(vs.dxt, at[...], 2.0)
vs.dyt = update(vs.dyt, at[...], 2.0)
vs.dzt = update(vs.dzt, at[...], ddz[::-1] / 2.5)
@veros_routine
def set_coriolis(self, state):
vs = state.variables
settings = state.settings
vs.coriolis_t = update(
vs.coriolis_t, at[...], 2 * settings.omega * npx.sin(vs.yt[None,
:] / 180.0 * settings.pi)
)
@veros_routine
def set_topography(self, state):
vs = state.variables
x, y = npx.meshgrid(vs.xt, vs.yt, indexing="ij")
vs.kbot = npx.logical_or(x > 1.0, y < -20).astype("int")
@veros_routine
def set_initial_conditions(self, state):
vs = state.variables
settings = state.settings
# initial conditions
vs.temp = update(vs.temp, at[...], ((1 - vs.zt[None, None, :] / vs
.zw[0]) * 15 * vs.maskT)[..., None])
vs.salt = update(vs.salt, at[...], 35.0 * vs.maskT[..., None])
print(vs.salt.flags)
vs.salt.setflags(write=1)
# this is the for loop i was talking about
y=6
for x in range(-2,0):
for z in range(-2,0):
vs.salt[x][y][z] = 35.3
# this is my attempt at using the update function
vs.salt = update(vs.salt, at[-2:0, 6:7, -2,0], 35.0)
# wind stress forcing
yt_min = global_min(vs.yt.min())
yu_min = global_min(vs.yu.min())
yt_max = global_max(vs.yt.max())
yu_max = global_max(vs.yu.max())
# surface heatflux forcing
vs.t_star = allocate(state.dimensions, ("yt",), fill=15)
vs.t_star = npx.where(vs.yt < -20, 15 * (vs.yt - yt_min) / (-20 -
yt_min), vs.t_star)
vs.t_star = npx.where(vs.yt > 20, 15 * (1 - (vs.yt - 20) / (yt_max -
20)), vs.t_star)
vs.t_rest = vs.dzt[npx.newaxis, -1] / (30.0 * 86400.0) * vs.maskT[:,
:, -1]
if settings.enable_tke:
vs.forc_tke_surface = update(
vs.forc_tke_surface,
at[2:-2, 2:-2],
npx.sqrt(
(0.5 * (vs.surface_taux[2:-2, 2:-2] + vs.surface_taux[1:
-3, 2:-2]) / settings.rho_0) ** 2
+ (0.5 * (vs.surface_tauy[2:-2, 2:-2] + vs.surface_tauy[
2:-2, 1:-3]) / settings.rho_0) ** 2
)
** (1.5),
)
if settings.enable_idemix:
vs.forc_iw_bottom = 1e-6 * vs.maskW[:, :, -1]
vs.forc_iw_surface = 1e-7 * vs.maskW[:, :, -1]
@veros_routine
def set_forcing(self, state):
vs = state.variables
vs.forc_temp_surface = vs.t_rest * (vs.t_star - vs.temp[:, :, -1, vs
.tau])
@veros_routine
def set_diagnostics(self, state):
settings = state.settings
diagnostics = state.diagnostics
diagnostics["snapshot"].output_frequency = 86400 * 10
diagnostics["averages"].output_variables = (
"salt",
"temp",
"u",
"v",
"w",
"psi",
"surface_taux",
"surface_tauy"
)
diagnostics["averages"].output_frequency = 365 * 86400.0
diagnostics["averages"].sampling_frequency = settings.dt_tracer * 10
diagnostics["overturning"].output_frequency = 365 * 86400.0 / 48.0
diagnostics["overturning"].sampling_frequency = settings.dt_tracer *
10
diagnostics["tracer_monitor"].output_frequency = 365 * 86400.0 /
12.0
diagnostics["energy"].output_frequency = 365 * 86400.0 / 48
diagnostics["energy"].sampling_frequency = settings.dt_tracer * 10
@veros_routine
def after_timestep(self, state):
pass
…On Sun, Oct 15, 2023 at 5:59 PM Dion Häfner ***@***.***> wrote:
Please paste your code here instead of uploading an image.
—
Reply to this email directly, view it on GitHub
<#543 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCKFKIHTIP7Y2Z4SWA5SFFLX7PJJFAVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRTGM3TIMZQGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
The first slice here is empty since it goes backwards (from the second-last element to the start of the array): vs.salt = update(vs.salt, at[-2:0, 6:7, -2,0], 35.0) This has nothing to do with the >>> import numpy as np
>>> arr = np.arange(100)
>>> arr[-2:0]
array([], dtype=int64)
>>> arr[-2:]
array([98, 99]) Notice how |
Oh okay.
Thank you so much!
…On Mon, Oct 16, 2023 at 2:09 PM Dion Häfner ***@***.***> wrote:
The first slice here is empty since it goes backwards (from the
second-last element to the start of the array):
vs.salt = update(vs.salt, at[-2:0, 6:7, -2,0], 35.0)
This has nothing to do with the update function and everything to do with
how NumPy applies slices. A simpler example:
>>> import numpy as np>>> arr = np.arange(100)>>> arr[-2:0]array([], dtype=int64)>>> arr[-2:]array([98, 99])
Notice how arr[-2:0] is empty, so your updates don't apply to anything.
Use arr[-2:] instead.
—
Reply to this email directly, view it on GitHub
<#543 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCKFKIDSEPFG5UJXG4S2QRDX7TXCHAVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRTHE4TONZXGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi!
I'm still not seeing a change after doing what you suggested.
…On Mon, Oct 16, 2023 at 2:40 PM Dion Häfner ***@***.***> wrote:
Closed #543 <#543> as completed.
—
Reply to this email directly, view it on GitHub
<#543 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCKFKIBKXXNTCFOHARMBM4DX7T2Y7AVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJQGY3DENBYGYZTQOA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Works fine on my end: # this is my attempt at using the update function
vs.salt = update(vs.salt, at[-2:, 6:7, -2,0], 35.0)
print(vs.salt[-2:, 6:7, -2,0]) Prints
|
Okay cool.
Figured that out.
I have another question though. I was trying to increase the grid size of
the model from 40*40 to 100*100.
And I got a latitudnal filtering error. How do I fix that?
…On Mon, 16 Oct 2023 at 20:21, Dion Häfner ***@***.***> wrote:
Works fine on my end:
# this is my attempt at using the update functionvs.salt = update(vs.salt, at[-2:, 6:7, -2,0], 35.0)print(vs.salt[-2:, 6:7, -2,0])
Prints
[[35.]
[35.]]
—
Reply to this email directly, view it on GitHub
<#543 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCKFKIFNPM6B7GC74RQZRZLX7VCVJAVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONRUGY2TINJWGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
If you increase the number of grid cells, you will have to reduce the grid spacing to get the same total extent of the grid (to not make the globe twice as large), and reduce the time step to ensure convergence. For example, if we double the number of grid cells: @veros_routine
def set_parameter(self, state):
...
settings.nx, settings.ny, settings.nz = 60, 84, 15 You also need to halve the grid spacing: @veros_routine
def set_grid(self, state):
...
vs.dxt = update(vs.dxt, at[...], 1.0)
vs.dyt = update(vs.dyt, at[...], 1.0) and change the time step: @veros_routine
def set_parameter(self, state):
...
settings.dt_tracer = 86400 / 4.0 |
Oh cool! I’ll try that.
Also, is there any way to make ssh a time varying function like salinity
and temperature.
…On Thu, 19 Oct 2023 at 17:04, Dion Häfner ***@***.***> wrote:
If you increase the number of grid cells, you will have to reduce the grid
spacing to get the same total extent of the grid (to not make the globe
twice as large), and reduce the time step to ensure convergence.
For example, if we double the number of grid cells:
@veros_routinedef set_parameter(self, state):
...
settings.nx, settings.ny, settings.nz = 60, 84, 15
You also need to halve the grid spacing:
@veros_routinedef set_grid(self, state):
...
vs.dxt = update(vs.dxt, at[...], 1.0)
vs.dyt = update(vs.dyt, at[...], 1.0)
and change the time step:
@veros_routinedef set_parameter(self, state):
...
settings.dt_tracer = 86400 / 4.0
—
Reply to this email directly, view it on GitHub
<#543 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCKFKIDA7GELIOP36ZVPTHLYAEF3RAVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZQG4YDIMJYGQ>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
You can update ssh in |
Okay I’ll do that.
Thank you so much.
…On Fri, 27 Oct 2023 at 16:16, Dion Häfner ***@***.***> wrote:
You can update ssh in set_forcing to whatever value you want. This
function is called in every timestep.
—
Reply to this email directly, view it on GitHub
<#543 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCKFKIESWAU3XWBL7QOJPFTYBOGHBAVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBSGY4TSNRUGE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi Dion,
Just wanted to confirm that ssh will eveolve like other paramters like
salinity and temperature with time if I do this. I wanted to put a ssh
anomaly in the middle of a square basin and see it evolve in time.
On Fri, 27 Oct 2023 at 16:27, Kashika Singh <
***@***.***> wrote:
… Okay I’ll do that.
Thank you so much.
On Fri, 27 Oct 2023 at 16:16, Dion Häfner ***@***.***>
wrote:
> You can update ssh in set_forcing to whatever value you want. This
> function is called in every timestep.
>
> —
> Reply to this email directly, view it on GitHub
> <#543 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/BCKFKIESWAU3XWBL7QOJPFTYBOGHBAVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBSGY4TSNRUGE>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
I see. The following should work: def set_parameters(state):
...
settings.enable_streamfunction = False # enable SSH
def set_initial_conditions(state):
...
# add an SSH anomaly of 10m somewhere in the domain
vs.psi = update(vs.psi, at[10:20, 10:20, :], 10.0 * settings.grav) SSH is time varying by default, but you need to disable the streamfunction solver to enable it. |
I tried this, and while the anomaly does show up, it is not time-varying. I
just get an average value. Is there a way to include psi or ssh in the
snapshots folder?
[image: image.png]
…On Mon, Nov 6, 2023 at 4:19 PM Dion Häfner ***@***.***> wrote:
I see. The following should work:
def set_parameters(state):
...
settings.enable_streamfunction = False # enable SSH
def set_initial_conditions(state):
...
# add an SSH anomaly of 10m somewhere in the domain
vs.psi = update(vs.psi, at[10:20, 10:20, :], 10.0 * settings.grav)
SSH is time varying by default, but you need to disable the streamfunction
solver to enable it.
—
Reply to this email directly, view it on GitHub
<#543 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/BCKFKIGERJUWZOAPVWK7BPTYDC6DFAVCNFSM6AAAAAA55ZC53SVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOJUGU2DOMBZGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Please read the docs: https://veros.readthedocs.io/en/latest/reference/diagnostics.html#diagnostics |
Can I get more thorough documentation on the update function? I am trying to assign some values to a variable with the update function, but the changes don't show up.
The text was updated successfully, but these errors were encountered: