opendrift.models.eulerdrift

The main entry point of Advent is the simulation.Simulation class.

Submodules

Package Contents

Classes

Simulation

The simulation.

ExplSimulation

A simple explicit scheme for integrating the convection-equation.

Reader

OpendriftReader

Wrapper around an Opendrift reader.

ConstantReader

Args:

Functions

install_logs([level])

Set up fanzy, colorful, logging.

Attributes

logger

opendrift.models.eulerdrift.logger
class opendrift.models.eulerdrift.Simulation(grid)[source]

The simulation.

It contains the problem to be simulated, means to read necessary input variables, and the physics for modeling the convection of the initial conditions.

Convection:

Convection consists of advection and diffusion.

Diffusion is given by:

\[\frac{\partial U}{\partial t} = D \left( \frac{\partial^2 U}{\partial x^2} + \frac{\partial^2 U}{\partial y^2} \right)\]

The convection equation is (wiki):

\[\frac{\partial c}{\partial t} = ...\]

with the assumptions that:

  • the diffusion constant D is constant for the field,

  • and that the flow u is incompressible (i.e. has no divergence).

the equation simplifies to:

\[\frac{\partial c}{\partial t} = D \nabla^2 c - \mathbf{v} \cdot \nabla T\]

where \(\nabla^2 = \triangle\) is the Laplacian.

grid

Reference time datetime.Datetime

t0

Current time offset after t0

t = 0.0

Diffusivity (\(m^2/s\)). E.g. between 0.01 and 0.1 for oil on the surface of the ocean (Matsuzakia et. al., 2017).

Decreasing diffusivity places stricter stability criteria on time step.

D = 0.1

Porosity, rate of liquid volume to total volume (fraction of flux)

rho = 1.0

List of readers

readers
classmethod new(lon0=10.0, lat0=65.0, res=10.0, shape=(100, 100))[source]

New simulation on a grid.RegularGrid.

Args:

lon0: lower-left corner longitude

lat0: lower-left corner latitude

res: resolution (dx and dy)

shape: shape (size) of grid

source(lon, lat, X)[source]

Source X onto grid with lower-left corner lon, lat.

source_gaussian_blob(lon, lat, A=1.0, N=10, sigma=10.0)[source]

Source a Gaussian blob (2D normal distribution) at lon and lat with sigma (standard deviation, meters) radius.

Args:

lon, lat: Center coordinates, or \(\bar \mu\).

A: Amplitude.

N: Kernel size.

sigma: standard deviation (\(\sigma\)) in meters.

U(t)[source]

Get U (ocean current) for t0 + t

abstract step(dt=None)[source]

Step the simulation.

Stepping the simulation involves applying diffusion and advection to the field.

Args:

dt: time delta (or use automatic).

abstract integrate(dt=None, max_t=None, max_steps=None, observer=None)[source]

Run simulation until termination condition is met.

Args:

dt: override time step

observer: function to call after each step taking simulation object as first argument. the function may return False to stop the integration.

Termination conditions:

max_t: max time max_steps: max iterations

class opendrift.models.eulerdrift.ExplSimulation(grid)[source]

Bases: Simulation

A simple explicit scheme for integrating the convection-equation.

  • Forward difference in time

  • ndimage.laplace and np.gradient for spatial differences.

https://en.wikipedia.org/wiki/Numerical_solution_of_the_convection%E2%80%93diffusion_equation#Solving_the_convection%E2%80%93diffusion_equation_using_the_finite_difference_method

See also

Simulation.

stability(dx, D, umax)[source]

https://en.wikipedia.org/wiki/Numerical_solution_of_the_convection%E2%80%93diffusion_equation#Solving_the_convection%E2%80%93diffusion_equation_using_the_finite_difference_method

step(dt=None)[source]

Step the simulation.

Stepping the simulation involves applying diffusion and advection to the field.

Args:

dt: time delta (or use automatic).

class opendrift.models.eulerdrift.Reader[source]
abstract variables()[source]

Get list of variables

abstract read_grid(grid, var, t)[source]

Read variable for grid.

Args:

grid: grid to read variable for

var: list of strs, name of variables to read

t: datetime (UTC)

Returns:

v0, v1, …

tuple with each variables specified in var with same shape as grid.

class opendrift.models.eulerdrift.OpendriftReader(reader)[source]

Bases: Reader

Wrapper around an Opendrift reader.

Args:

reader: opendrift reader

variables()[source]

Get list of variables

read_grid(grid, var, t)[source]

Read variable for grid.

Args:

grid: grid to read variable for

var: list of strs, name of variables to read

t: datetime (UTC)

Returns:

v0, v1, …

tuple with each variables specified in var with same shape as grid.

class opendrift.models.eulerdrift.ConstantReader(consts)[source]

Bases: Reader

Args:

consts: dict, name of var: constant

read_grid(grid, var, _)[source]

Read variable for grid.

Args:

grid: grid to read variable for

var: list of strs, name of variables to read

t: datetime (UTC)

Returns:

v0, v1, …

tuple with each variables specified in var with same shape as grid.

variables()[source]

Get list of variables

static new_xy(x=0.5, y=0.5)[source]
opendrift.models.eulerdrift.install_logs(level=logging.DEBUG)[source]

Set up fanzy, colorful, logging.

Args:

level: Log level