Veros setup class

class veros.VerosSetup(state=None, 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().

Parameters:
  • backend (bool, optional) – Backend to use for array operations. Possible values are numpy and bohrium. Defaults to None, which tries to read the backend from the command line (set via a flag -b/--backend), and uses numpy if no command line argument is given.
  • loglevel (one of {debug, info, warning, error, critical}, optional) – Verbosity of the model. Tries to read value from command line if not given (-v/--loglevel). Defaults to info.

Example

>>> import matplotlib.pyplot as plt
>>> from veros import VerosSetup
>>>
>>> class MyModel(VerosSetup):
>>>     ...
>>>
>>> simulation = MyModel(backend='bohrium')
>>> simulation.run()
>>> plt.imshow(simulation.state.psi[..., 0])
>>> plt.show()
set_parameter(vs)[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, vs):
>>>     vs.nx, vs.ny, vs.nz = (360, 120, 50)
>>>     vs.coord_degree = True
>>>     vs.enable_cyclic = True
set_initial_conditions(vs)[source]

To be implemented by subclass.

May be used to set initial conditions.

Example

>>> @veros_method
>>> def set_initial_conditions(self, vs):
>>>     vs.u[:, :, :, vs.tau] = np.random.rand(vs.u.shape[:-1])
set_grid(vs)[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, vs):
>>>     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]
set_coriolis(vs)[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, vs):
>>>     vs.coriolis_t[:, :] = 2 * vs.omega * np.sin(vs.yt[np.newaxis, :] / 180. * vs.pi)
set_topography(vs)[source]

To be implemented by subclass.

Must specify the model topography by setting kbot.

Example

>>> @veros_method
>>> def set_topography(self, vs):
>>>     vs.kbot[:, :] = 10
>>>     # add a rectangular island somewhere inside the domain
>>>     vs.kbot[10:20, 10:20] = 0
set_forcing(vs)[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, vs):
>>>     current_month = (vs.time / (31 * 24 * 60 * 60)) % 12
>>>     vs.surface_taux[:, :] = vs._windstress_data[:, :, current_month]
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, vs):
>>>     vs.diagnostics['snapshot'].output_vars += ['drho', 'dsalt', 'dtemp']
after_timestep(vs)[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.