Veros setup class

class veros.VerosSetup(override=None)[source]

Bases: object

Main class for Veros, used for building a model and running it.

Note

This class is meant to be subclassed. Subclasses need to implement the methods set_parameter(), set_topography(), set_grid(), set_coriolis(), set_initial_conditions(), set_forcing(), and set_diagnostics().

Example

>>> import matplotlib.pyplot as plt
>>> from veros import VerosSetup
>>>
>>> class MyModel(VerosSetup):
>>>     ...
>>>
>>> simulation = MyModel()
>>> simulation.run()
>>> plt.imshow(simulation.state.variables.psi[..., 0])
>>> plt.show()
abstract set_parameter(state)[source]

To be implemented by subclass.

First function to be called during setup. Use this to modify the model settings.

Example

>>> def set_parameter(self, state):
>>>     settings = state.settings
>>>     settings.nx, settings.ny, settings.nz = (360, 120, 50)
>>>     settings.coord_degree = True
>>>     settings.enable_cyclic = True
abstract set_initial_conditions(state)[source]

To be implemented by subclass.

May be used to set initial conditions.

Example

>>> @veros_method
>>> def set_initial_conditions(self, state):
>>>     vs = state.variables
>>>     vs.u = update(vs.u, at[:, :, :, vs.tau], npx.random.rand(vs.u.shape[:-1]))
abstract set_grid(state)[source]

To be implemented by subclass.

Has to set the grid spacings dxt, dyt, and dzt, along with the coordinates of the grid origin, x_origin and y_origin.

Example

>>> @veros_method
>>> def set_grid(self, state):
>>>     vs = state.variables
>>>     vs.x_origin, vs.y_origin = 0, 0
>>>     vs.dxt = [0.1, 0.05, 0.025, 0.025, 0.05, 0.1]
>>>     vs.dyt = 1.
>>>     vs.dzt = [10, 10, 20, 50, 100, 200]
abstract set_coriolis(state)[source]

To be implemented by subclass.

Has to set the Coriolis parameter coriolis_t at T grid cells.

Example

>>> @veros_method
>>> def set_coriolis(self, state):
>>>     vs = state.variables
>>>     vs.coriolis_t = 2 * vs.omega * npx.sin(vs.yt[npx.newaxis, :] / 180. * vs.pi)
abstract set_topography(state)[source]

To be implemented by subclass.

Must specify the model topography by setting kbot.

Example

>>> @veros_method
>>> def set_topography(self, state):
>>>     vs = state.variables
>>>     vs.kbot = update(vs.kbot, at[...], 10)
>>>     # add a rectangular island somewhere inside the domain
>>>     vs.kbot = update(vs.kbot, at[10:20, 10:20], 0)
abstract set_forcing(state)[source]

To be implemented by subclass.

Called before every time step to update the external forcing, e.g. through forc_temp_surface, forc_salt_surface, surface_taux, surface_tauy, forc_tke_surface, temp_source, or salt_source. Use this method to implement time-dependent forcing.

Example

>>> @veros_method
>>> def set_forcing(self, state):
>>>     vs = state.variables
>>>     current_month = (vs.time / (31 * 24 * 60 * 60)) % 12
>>>     vs.surface_taux = vs._windstress_data[:, :, current_month]
abstract set_diagnostics(vs)[source]

To be implemented by subclass.

Called before setting up the diagnostics. Use this method e.g. to mark additional variables for output.

Example

>>> @veros_method
>>> def set_diagnostics(self, state):
>>>     state.diagnostics['snapshot'].output_variables += ['drho', 'dsalt', 'dtemp']
abstract after_timestep(state)[source]

Called at the end of each time step. Can be used to define custom, setup-specific events.

run(show_progress_bar=None)[source]

Main routine of the simulation.

Note

Make sure to call setup() prior to this function.

Parameters

show_progress_bar (bool, optional) – Whether to show fancy progress bar via tqdm. By default, only show if stdout is a terminal and Veros is running on a single process.