Skip to content
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

Closed
kasped opened this issue Oct 12, 2023 · 17 comments
Closed

Update function #543

kasped opened this issue Oct 12, 2023 · 17 comments

Comments

@kasped
Copy link

kasped commented Oct 12, 2023

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.

@dionhaefner
Copy link
Collaborator

Can you show what you tried?

@kasped
Copy link
Author

kasped commented Oct 15, 2023 via email

@dionhaefner
Copy link
Collaborator

Please paste your code here instead of uploading an image.

@kasped
Copy link
Author

kasped commented Oct 16, 2023 via email

@dionhaefner
Copy link
Collaborator

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.

@kasped
Copy link
Author

kasped commented Oct 16, 2023 via email

@kasped
Copy link
Author

kasped commented Oct 16, 2023 via email

@dionhaefner
Copy link
Collaborator

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

[[35.]
 [35.]]

@kasped
Copy link
Author

kasped commented Oct 19, 2023 via email

@dionhaefner
Copy link
Collaborator

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

@kasped
Copy link
Author

kasped commented Oct 27, 2023 via email

@dionhaefner
Copy link
Collaborator

You can update ssh in set_forcing to whatever value you want. This function is called in every timestep.

@kasped
Copy link
Author

kasped commented Oct 27, 2023 via email

@kasped
Copy link
Author

kasped commented Nov 6, 2023 via email

@dionhaefner
Copy link
Collaborator

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.

@kasped
Copy link
Author

kasped commented Nov 13, 2023 via email

@dionhaefner
Copy link
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants