slim4.slim3d

Slim3d 3D hydrodynamics classes and functions

Enums

class slim4.slim3d.HorizontalViscosityFormula(IntEnum)

The formula for the viscosity.

Values

none: 0 — No viscosity.
direct: 1 — The horizontal viscosity is the slim4::slim::Data given.
smago: 2 — Smagorinsky horizontal viscosity.
class slim4.slim3d.HorizontalDiffusionOrientation(IntEnum)

The orientation for the horizontal diffusion.

Values

xy: 0 — The diffusion is oriented following the xy plane.
mesh: 1 — Default orientation. The diffusion is oriented following the mesh.
isopycnal: 2 — The diffusion is oriented following the isopycnal direction.
class slim4.slim3d.TurbulenceModelType(IntEnum)

Values

k_epsilon: 0 — k-epsilon
k_omega: 1 — k-omega
class slim4.slim3d.TurbulenceStabilityType(IntEnum)

Values

canuto: 0 — Canuto
kantha: 1 — Kantha
yamada: 2 — Yamada

Classes

class slim4.slim3d.Mesh

Bases: slim.Mesh.

A tri-dimensional mesh built from a bi-dimensional mesh extruded along the z-axis.

Properties

mesh2d: slim2d.Mesh — The bi-dimensional mesh.
z_layers: NDArray[np.int32] — Starting index of each column of prisms.
n_layers: NDArray[np.int32] — The number of layers for each triangle.
n_moving_layers: NDArray[np.int32] — Number of moving layers for each column of nodes. CG min of n_layers and n_moving_layers_max. shape [n_triangles, 3].),
n_layers_f2d: NDArray[np.int32] — Minimun of number of layers between a triangle and its face neighbours. Shape [n_triangles].
n_layers_max_cg: NDArray[np.int32] — CG max of n_layers, including neighbouring partitions. Shape [n_cg_nodes].
cg_column_start: NDArray[np.int32] — Start of each column of 3D CG nodes. Shape [n_cg_nodes_2d + 1].
first_prism_id: int — The id of the first prism.

Constructor

__init__(mesh2d, z_layers, n_moving_max=-1)

create a new 3D mesh from a 2D mesh and a vertical structure

Parameters

mesh2d: slim2d.Mesh — 2D mesh
z_layers: NDArray[np.int32] — Starting index of each column of prisms
n_moving_max: int — Maximum number of moving layers. If negative, all layers are moving.

Methods

static partition_output(outpath, meshfile, pfile='')

Partitions a 2D mesh with weights corresponding to the 3D mesh of an output

Parameters

outpath: str — Ouput path of SLIM 3D
meshfile: str — The name of the file to partition
pfile: str — The name of the output file given as a pattern that should contain ${rank}, ${rank} will be replaced by the rank of the partition. If Null the parition rank will be appended to the name of the original file.

Returns

spfile: str — return the name of the partitioned file for the current rank
static from_output(outpath, meshfile, n_moving_max=-1, tags2d=[], projection2d='', projection_type2d='')

Creates a new 3D mesh from an output of SLIM 3D

Parameters

outpath: str — Ouput path of SLIM 3D
meshfile: str — 2D mesh file
n_moving_max: int — Maximum number of moving layers. If negative, all layers are moving.
tags2d: List[str] — The physical tags of the entities to load (NULL for all).
projection2d: str — The coordinate system of the 2D mesh coordinates if any (the string format depends on projection_type).
projection_type2d: str — The type of the coordinate system of the 2D mesh coordinates if any (e.g. ‘proj4’, of ‘WKT’).

Returns

mesh: Mesh — a new 3D mesh
scatter_cg_to_dg(cg)

Scatter a CG array to a DG array.

Parameters

cg: NDArray[np.float64] — The array to scatter. […, n_cg_nodes]

Returns

dg: NDArray[np.float64] — the scattered array. […, 6, n_prisms]
gather_dg_to_cg(op, dg, z)

Gather a DG array to a CG array.

Parameters

op: slim2d.GatherOp | str — The operation to perform.
dg: NDArray[np.float64] — The array to gather. […, 6, n_prisms]
z: NDArray[np.float64] — The z vector. [1, 6, n_prisms]

Returns

cg: NDArray[np.float64] — the gathered array. […, n_cg_nodes]
repeat2d3d(v)

Repeat a 2D array to a 3D array. The 2D array is repeated along the z-axis.

Parameters

v: NDArray[np.float64] — The array to repeat. [n_triangles, 3, n_fields]

Returns

v3d: NDArray[np.float64] — the repeated array. [n_prisms, 6, n_fields]
create_coordinate_vector(z)

Create the xyz coordinate vector at every point in the 3D mesh.

Parameters

z: NDArray[np.float64] — The z vector. [n_prisms, 6] or [n_prisms, 6, 1]

Returns

xyz: NDArray[np.float64] — the coordinate vector. [n_prisms, 6, 3]
boundary_nodes(tags)

Return the nodes of the boundary edges.

Parameters

tags: List[str] — list of boundary tags

Returns

a: NDArray[np.int32] — new array with the boundary nodes (unique and sorted)
scatter_array(array)

Scatter a 3D GPU field.

Parameters

array: slim.ScalarArrayDeviceMPI — The field to scatter.
mass_mult(z, v)

Multiply a field v. by the mass matrix. v must have 1, 2 or 3 fields.

Parameters

z: slim.ScalarArrayDevice — The field to multiply.
v: slim.ScalarArrayDevice — The data that shall be multiplied by the mass matrix.
inv_mass_mult(z, v)

Multiply a field v. by the inverse of the mass matrix. v must have 1, 2 or 3 fields.

Parameters

z: slim.ScalarArrayDevice — The field to multiply.
v: slim.ScalarArrayDevice — The data that shall be multiplied by the mass matrix.
vertical_sum(in3d, out2d, alpha)

Sum a 3D field vertically. The result is a 2D field: out2d = sum(in3d) + out2d*alpha.

Parameters

in3d: slim.ScalarArrayDevice — The field to sum.
out2d: slim.ScalarArrayDevice — The result of the sum.
alpha: float — Optinal factor that mutiplies out2d.
new_mesh_3d(z_old, eta_new, z_new, wm=None, dt=0)

Compute the new z_coordinate from the old z_coordinate and the new free surface.

Parameters

z_old: slim.ScalarArrayDevice — The old z_coordinate.
eta_new: slim.ScalarArrayDevice — The new free surface.
z_new: slim.ScalarArrayDevice — The new z_coordinate.
wm: slim.ScalarArrayDevice | None — optional mesh speed to be computed.
dt: float — The time step for the mesh speed computation.
create_xdmf(z, fname, cg=False)

Create a new empty xdmf export

Parameters

z: NDArray[np.float64] — z coordinate of the mesh
fname: str — path to the new xdmf file (without the .xdmf extension).
cg: bool — if true, create a cg export, else create a dg export.
append_to_xdmf(fname, iter, t, z_dg, fields, precision='native')

Append a new timestep to an existing xdmf export

Parameters

fname: str — path to the existing xdmf file (without the .xdmf extension).
iter: int — output id
t: float — output time
z_dg: NDArray[np.float64] — z coordinate of the mesh for weighted average
fields: List[Tuple[str, NDArray[np.float64]]] — fields to be exported
precision: slim.OutputPrecision | str — native, half, single or double
integrate(z, factors)

Integrate a product of fields over the mesh. The integral is done numerically with a 28-point quadrature.

Parameters

z: NDArray[np.float64] — The z coordinate of the mesh.
factors: List[NDArray[np.float64]] — The fields to integrate.

Returns

I: float — the integral.
integrate_vertical(z, fields)

Integrate 3D fields vertically. The integral is done numerically with a 4-point quadrature.

Parameters

z: NDArray[np.float64] — The z coordinate of the mesh.
fields: NDArray[np.float64] — The fields to integrate.

Returns

I: NDArray[np.float64] — the integral.
save_mesh(z, outpath)

Save the mesh to disk.

Parameters

z: NDArray[np.float64] — z coordinate of the mesh
outpath: str — path to the folder where the mesh will be saved.
static load(path, n_moving_max=-1)

Load a partitioned 3D mesh from disk.

Parameters

path: str — path to the splited mesh folder
n_moving_max: int — Maximum number of moving layers. If negative, all layers are moving.

Returns

mesh: Mesh — the mesh
z0: NDArray[np.float64] — the z coordinate
bath: slim.DataStatic — the bathymetry
find_points(z, xyz)

Find the prisms containing some points.

Parameters

z: NDArray[np.float64] — The z coordinate of the mesh.
xyz: NDArray[np.float64] — The x, y and z coordinates of the points of shape (3, n).

Returns

new_pids: NDArray[np.int32] — return a new array with the id of the prism containing each point.
new_uvw: NDArray[np.float64] — return a new array with the parametric coordinates of the points in the prisms.
find_points_z(z_mesh, eids, uv, z_points)

Find the prisms containing some points, knowing the triangle in which they are located.

Parameters

z_mesh: NDArray[np.float64] — The z coordinate of the mesh.
eids: NDArray[np.int32] — The id of the triangles containing each point.
uv: NDArray[np.float64] — The parametric xy-coordinates of each points of shape (2,n).
z_points: NDArray[np.float64] — The z coordinates of the points of shape (n).

Returns

new_pids: NDArray[np.int32] — return a new array with the id of the prism containing each point.
new_zeta: NDArray[np.float64] — return a new array with the parametric z-coordinates of the points in the prisms.
interpolate(z, field, xyz)

Interpolate on n field a given set of points.

Parameters

z: NDArray[np.float64] — The z coordinate of the mesh.
field: NDArray[np.float64] — The field to interpolate.
xyz: NDArray[np.float64] — The coordinates of the points to interpolate.

Returns

interp: NDArray[np.float64] — The interpolated values.
check_consistency_z(z, dmin=0)

Checks if the values in the ghost cells are consistent with the other partitions, checks the monotonicity of z with a minimum depth per layer checks that the bathymetry is continuous where the number of layers is continuous,

Parameters

z: NDArray[np.float64] — The z coordinate of the mesh.
dmin: float — The minimum distance between two layers
vorticity(z, uvw, t=-31536000000, out=None)

Computes the vorticity of a velocity field.

Parameters

z: Union[slim.ScalarArrayDevice, slim.Data] — The z coordinate of the mesh.
uvw: Union[slim.ScalarArrayDevice, slim.Data] — The velocity field. Can have 2 or 3 components. If it has 2 components, the vertical velocity is assumed to be zero.
t: float — The time (if z or uvw is provided as slim4::slim::Data)
out: slim.ScalarArrayDeviceMPI | None — optional output array for the vorticity. If None, a new array is created.

Returns

vorticity: slim.ScalarArrayDeviceMPI — The vertical vorticity if uvw has 2 components, the full vorticity if uvw has 3 components.
class slim4.slim3d.DataLinear

Bases: slim.Data.

Data linearly interpolated between two instants

Constructor

__init__(base)

create a new slim4::slim3d::DataLinear

Parameters

base: slim.Data — The base data

Methods

set_time(t0, t1)

set the two instants in between which the data is linearly interpolated

Parameters

t0: float — The first instant
t1: float — The second instant
class slim4.slim3d.DataVSum

Bases: slim.Data.

2D Data from Vertical sum of 3D data

Constructor

__init__(base)

create a new slim4::slim3d::DataVSum

Parameters

base: slim.Data — The base 3D data
class slim4.slim3d.DataExtrude

Bases: slim.Data.

3D Data from extruded from a 2D data

Constructor

__init__(base, mesh)

create a new slim4::slim3d::DataExtrude

Parameters

base: slim.Data — The base 2D data
mesh: slim.Mesh — The 3D mesh
class slim4.slim3d.DataHMultiply

Bases: slim.Data.

3D Data multiplied by prish height at each node

Constructor

__init__(base, eta, bath, z)

create a new slim4::slim3d::DataHMultiply

Parameters

base: slim.Data — The base 3D data
eta: slim.Data — The free surface elevation
bath: slim.Data — The bathymetry
z: NDArray[np.float64] — The z coordinate of the mesh
class slim4.slim3d.DataExtractLayer

Bases: slim.Data.

2D Data extracted from a layer of 3D data

Constructor

__init__(base, layer, topface)

create a new slim4::slim3d::DataExtractLayer

Parameters

base: slim.Data — The base 3D data
layer: int — The layer to extract (0 is the surface, 1 is the first layer below the surface, etc.). The bottom layer is -1. The CGbottom layer is -2.
topface: bool — Whether to extract the top face of the layer (true) or the bottom face (false)

Methods

set_layer(layer, topface)

set the layer to extract

Parameters

layer: int — The layer to extract (0 is the surface, 1 is the first layer below the surface, etc.). The bottom layer is -1. The CGbottom layer is -2.
topface: bool — Whether to extract the top face of the layer (true) or the bottom face (false)
class slim4.slim3d.TmpVar

Class to store all the temporary variables of the 3D model.

Properties

z_0: slim.ScalarArrayDeviceMPI — z_0 scratch space
z_next: slim.ScalarArrayDeviceMPI — z_next scratch space
uv_0: slim.ScalarArrayDeviceMPI — uv_0 scratch space
uv_next: slim.ScalarArrayDeviceMPI — uv_next scratch space
huv_gpu: slim.ScalarArrayDeviceMPI — huv_gpu scratch space
f3d_expl: slim.ScalarArrayDeviceMPI — f3d_expl scratch space
f3d_vsum: slim.ScalarArrayDeviceMPI — f3d_vsum scratch space
f2d_for_3d: slim.ScalarArrayDeviceMPI — f2d_for_3d scratch space
w_gpu: slim.ScalarArrayDeviceMPI — w_gpu scratch space
wm_gpu: slim.ScalarArrayDeviceMPI — wm_gpu scratch space
sol2d: slim.ScalarArrayDeviceMPI — sol2d scratch space
sol2d_0: slim.ScalarArrayDeviceMPI — sol2d at the beginning of the time step scratch space
sol2d_c: slim.ScalarArrayDeviceMPI — temp copy of sol2d
z_tracer: slim.ScalarArrayDeviceMPI — z coordinates of the mesh used to advance the tracers (may be None if no tracers on the problem)
w_tracer: slim.ScalarArrayDeviceMPI — vertical velocity used to advance the tracers (may be None if no tracers on the problem)
huv_tracer: slim.ScalarArrayDeviceMPI — horizontal velocity used to advance the tracers (may be None if no tracers on the problem)
sol2d_avg: slim.ScalarArrayDeviceMPI — 2D horizontal velocity used to advance the tracers (may be None if no tracers on the problem)
kpsi: slim.ScalarArrayDeviceMPI — turbulence variables (may be None if no turbulence on the problem)
nu_kappa: slim.ScalarArrayDeviceMPI — vertical viscosity and diffusivity for turbulence (may be None if no turbulence on the problem)
rho: slim.ScalarArrayDeviceMPI — density scratch space (may by None if no state equation)
hpg: slim.ScalarArrayDeviceMPI — Reduced horizontal baroclinic pressure gradient (may by None if no state equation)
tracers_0: Dict[str,:ref:slim.ScalarArrayDeviceMPI <api-class-slim4-slim-scalararraydevicempi>] — tracers at the beginning of the time step scratch space
tracers_next: Dict[str,:ref:slim.ScalarArrayDeviceMPI <api-class-slim4-slim-scalararraydevicempi>] — tracers at the end of the sub-time step scratch space
drho: slim.ScalarArrayDeviceMPI — density variation scratch space (may by None if no state equation)
class slim4.slim3d.Problem

The main class to handle all the subproblems of the 3D model.

Properties

problemUV: UV — the 3d horizontal velocity problem uv(x,y,z,t)
problemUV2d: slim2d.ShallowWater — the 2d shallow water problem uv(x,y,t) solving the wave equation external mode
problem_tracer: Dict[str,:ref:Tracer <api-class-slim4-slim3d-tracer>] — the tracers problems
problemTurbulence: Turbulence — the turbulence problem
mesh: Mesh — the 3d mesh (2D mesh + extrusion in the vertical)
bathymetry: slim.Data — the bathymetry data
lin_data: List[DataLinear] — data linearized over a full time step
max_uv_speed: float — the maximum
uv_clip_loc: slim.ScalarArrayDevice | None — registers how many times the velocity clipper acts on each element between two exports
sys_2d: slim.LinearSolver — the linear system for the 2D problem
reactions: List[slim.Reaction] — the reactions solved as ordinary differential equations on each node

Constructor

__init__(mesh, g, bathymetry, rho_0=1000.0)

Create a new 3D problem.

Parameters

mesh: Mesh — the 3D mesh
g: float — the gravity
bathymetry: slim.Data — the bathymetry data
rho_0: float — the reference density

Methods

get_gpu_tmpvars()

Get (and allocate if they do not exist) the temporary variables used by the times-stepping and export functions

Returns

tmpvars: TmpVar — A class storing the temporary variables
compute_cfl(u_max=2, drho=None)

Compute the time step based on the Courant-Friedrichs-Lewy condition

Parameters

u_max: float — the maximum velocity
drho: NDArray[np.float64] | None — the density variation : either None (=0), an array of size (1) an array of size (n_elements, 6)

Returns

dt3d: float — the 3D time step
cfl: float — the 2D time step
add_tracer(nfields, name, limiter_type='past_bound', wadd=0.0)

Add a new tracer to the problem

Parameters

nfields: int — the number of tracer fields
name: str — the name of the tracer
limiter_type: slim.LimiterType | str — The type of limiter
wadd: float — the additional vertical velocity

Returns

tracer: Tracer — the new tracer
add_turbulence(model='k_epsilon', stability='canuto', initial_value=1e-8, z0b=None, z0s=None)

Add a turbulence model to the problem

Parameters

model: TurbulenceModelType | str — the turbulence model
stability: TurbulenceStabilityType | str — the stability model
initial_value: float — the initial value of the turbulence
z0b: slim.Data | None — the bottom roughness
z0s: slim.Data | None — the surface roughness
add_reaction(reaction)

Add a reaction to the problem

Parameters

reaction: slim.Reaction — the reaction
set_wall_boundary(tag, slip=False)

Set a wall boundary condition

Parameters

tag: str — the tag of the boundary
slip: bool — if True, slip (frictionless) wall. (default False)
set_open_boundary(tag, eta=None, u=None, t={}, uv_is_transport=True)

Set an open boundary condition

Parameters

tag: str — the tag of the boundary
eta: slim.Data | None — the elevation data
u: slim.Data | None — the velocity data
t: Dict[str,:ref:slim.Data <api-class-slim4-slim-data>] — the tracers data
uv_is_transport: bool — whether the velocity is a transport variable
set_state_equation_jackett(temperature, salinity)

Set the state equation to the jackett equation

Parameters

temperature: slim.ScalarArrayDevice — the temperature data
salinity: slim.ScalarArrayDevice — the salinity data
set_state_equation_teos10(temperature, salinity)

Set the state equation to the teos10 density equation.

Parameters

temperature: slim.ScalarArrayDevice — the potential temperature data [°C]
salinity: slim.ScalarArrayDevice — the absolute salinity data [g/kg]
set_state_equation_linear(tracer_scalar_pairs)

Set the state equation to a linear equation

Parameters

tracer_scalar_pairs: List[Tuple[slim.ScalarArrayDevice, float]] — the tracers and their scalar values
set_dissipation(gamma, log=False)

Set the dissipation

Parameters

gamma: slim.Data — the dissipation
log: bool — true if gamma is the coefficient of the log profile, false if it is directly the friction coefficient.
set_surface_stress(tau)

Set the surface stress

Parameters

tau: slim.Data — the surface stress
set_surface_water(q_water, t={}, upwind={})

Set the quantity of water added by precipitation or removed by evaporation

Parameters

q_water: slim.Data — the quantity of water added by precipitation or removed by evaporation (in m/s)
t: Dict[str,:ref:slim.Data <api-class-slim4-slim-data>] — the tracer concentration of entering/outgoing water (2D)
upwind: Dict[str,List[bool]] — if True, the tracer concentration is taken from the domain for evaporation and from the data in t for precipitation
set_surface_flux(tracer, flux)

Set the surface flux

Parameters

tracer: str — the tracer
flux: slim.Data — the surface source flux [[tracer]*m/s]
set_penetrating_flux(pen_flux, pen_dist, tracer, z)

Set the penetrating flux

Parameters

pen_flux: slim.Data — the Total penetrating source flux [T*m/s]
pen_dist: slim.Data — the characteristic absorption distance [m]. The absorbed flux is computed as C * exp(-depth/pen_dist)
tracer: slim.ScalarArrayDevice — the tracer
z: slim.ScalarArrayDevice — the vertical mesh coordinate vector
set_surface_tracer_nudging(tracer, obs, surf_nudg_time, surf_nudg_depth, nudging_active)

Set the surface tracer nudging

Parameters

tracer: str — the tracer
obs: slim.Data — the observation data
surf_nudg_time: float — the nudging time
surf_nudg_depth: float — the nudging depth
nudging_active: List[bool] — If the nudging is active (1) or not (0) for each field.
set_atmospheric_pressure(atm)

Set the atmospheric pressure

Parameters

atm: slim.Data — the atmospheric pressure data
set_velocity_nudging(a_nudging, uv_nudging)

Add a nudging term as a source term in the momentum equation. None unsets the forcing.

Parameters

a_nudging: slim.Data — nudging coefficient over the domain during the simulation (1/s)
uv_nudging: slim.Data — 3D velocity (m/s) over the domain and over the duration of the simulation, expressed in the same projection as the mesh.
do_export(path2d, path3d, iout, t, z, uv, tracers=[], Huv=True, rho=False, turbulence=False, nuv=False, kappav=False, fields_2d=[], fields_3d=[], clip_loc=None, nitperex=-1, precision='single')

Export the solution to the xdmf file.

Parameters

path2d: str — the path to the xdmf file for the 2D solution
path3d: str — the path to the xdmf file for the 3D solution
iout: int — the index of the export
t: float — the time of the export expressed in unix time (seconds since 1970-01-01 00:00:00)
z: slim.ScalarArrayDevice — the 3D mesh vertical coordinate
uv: slim.ScalarArrayDevice — the 3D horizontal velocity
tracers: List[slim.ScalarArrayDevice] — the list of tracers
Huv: bool — if True, export the total velocity
rho: bool — if True, export the density
turbulence: bool — if True, export the k-psi turbulent variable
nuv: bool — if True, export the vertical viscosity
kappav: bool — if True, export the vertical diffusivity
fields_2d: List[Tuple[str, NDArray[np.float64]]] — the list of additional fields to export in the 2D file
fields_3d: List[Tuple[str, NDArray[np.float64]]] — the list of additional fields to export in the 3D file
clip_loc: slim.ScalarArrayDevice | None — registers how many times the velocity clipper acts on each element between two exports
nitperex: int — the number of iterations between two exports (used for clip_loc)
precision: slim.OutputPrecision | str — the floating-point number precision of the output

Returns

next_iout: int — the index for the next export
export_mean_transport(path2d, path3d, iout, t, z, uv)

Export the solution to the xdmf file.

Parameters

path2d: str — the path to the xdmf file for the 2D solution
path3d: str — the path to the xdmf file for the 3D solution
iout: int — the index of the export
t: float — the time of the export expressed in unix time (seconds since 1970-01-01 00:00:00)
z: slim.ScalarArrayDevice — the 3D mesh vertical coordinate
uv: slim.ScalarArrayDevice — the 3D horizontal velocity

Returns

next_iout: int — the index for the next export
new_linear_system(options)

Create a new 2D linear system

Parameters

options: str — the (e.g. PETSc) options for the linear system
save(t, iout, iiter, path, z, uv, tracers)

Save the solution to an xdmf file that can be reloaded later

Parameters

t: float — the time of the export expressed in unix time (seconds since 1970-01-01 00:00:00)
iout: int — the index of the export
iiter: int — the iteration index
path: str — the path to the xdmf file
z: slim.ScalarArrayDevice — the 3D mesh vertical coordinate
uv: slim.ScalarArrayDevice — the 3D horizontal velocity
tracers: List[slim.ScalarArrayDevice] — the list of tracers
load(path, z, uv, tracers)

Load a saved solution from an xdmf file

Parameters

path: str — the path to the xdmf file
z: slim.ScalarArrayDeviceMPI — the 3D mesh vertical coordinate
uv: slim.ScalarArrayDeviceMPI — the 3D horizontal velocity
tracers: List[slim.ScalarArrayDeviceMPI] — the list of tracers

Returns

time: float — the time of the saved solution
iout: int — the index of the saved solution
iiter: int — the iteration index of the saved solution
set_clipping_velocity(max_uv_speed, clip_loc, realbath=None)

Set the clipping velocity value

Parameters

max_uv_speed: float — the maximum velocity [m/s]
clip_loc: slim.ScalarArrayDevice — vector to register how many times the clipper acts on each element between two exports.
realbath: slim.Data | None — The real (unclipped) bathymetry. If provided, any elements below the real bathymetry will be clipped to zero velocity.
class slim4.slim3d.OfflineProblem

The main class to handle all the subproblems of the 3D model.

Properties

problemUV: UV — the 3d horizontal velocity problem uv(x,y,z,t)
problem_tracer: Dict[str,:ref:Tracer <api-class-slim4-slim3d-tracer>] — the tracers problems
mesh: Mesh — the 3d mesh (2D mesh + extrusion in the vertical)
reactions: List[slim.Reaction] — the reactions solved as ordinary differential equations on each node
lin_data: List[DataLinear] — data linearized over a full time step

Constructor

__init__(mesh, g, sol2d_data, huv_data, z_data, data_time)

Create a new 3D problem.

Parameters

mesh: Mesh — the 3D mesh
g: float — the gravity
sol2d_data: slim.Data — the mean 2D solution (surface elevation and 2D transport)
huv_data: slim.Data — the mean 3D transport and layer height
z_data: slim.Data — the exported vertical mesh coordinate
data_time: NDArray[np.float64] — the time of the exported data

Methods

get_gpu_tmpvars()

Get (and allocate if they do not exist) the temporary variables used by the times-stepping and export functions

Returns

tmpvars: TmpVar — A class storing the temporary variables
compute_cfl(u_max=2)

Compute the time step based on the Courant-Friedrichs-Lewy condition

Parameters

u_max: float — the maximum velocity

Returns

dt3d: float — the 3D time step
add_tracer(nfields, name, limiter_type='past_bound', wadd=0.0)

Add a new tracer to the problem

Parameters

nfields: int — the number of tracer fields
name: str — the name of the tracer
limiter_type: slim.LimiterType | str — The type of limiter
wadd: float — the additional vertical velocity

Returns

tracer: Tracer — the new tracer
add_reaction(reaction)

Add a reaction to the problem

Parameters

reaction: slim.Reaction — the reaction
set_wall_boundary(tag, slip=False)

Set a wall boundary condition

Parameters

tag: str — the tag of the boundary
slip: bool — if True, slip (frictionless) wall. (default False)
set_open_boundary(tag, eta=None, u=None, t={}, uv_is_transport=True)

Set an open boundary condition

Parameters

tag: str — the tag of the boundary
eta: slim.Data | None — the elevation data
u: slim.Data | None — the velocity data
t: Dict[str,:ref:slim.Data <api-class-slim4-slim-data>] — the tracers data
uv_is_transport: bool — whether the velocity is a transport variable
set_surface_water(q_water, t={}, upwind={})

Set the quantity of water added by precipitation or removed by evaporation

Parameters

q_water: slim.Data — the quantity of water added by precipitation or removed by evaporation (in m/s)
t: Dict[str,:ref:slim.Data <api-class-slim4-slim-data>] — the tracer concentration of entering/outgoing water (2D)
upwind: Dict[str,List[bool]] — if True, the tracer concentration is taken from the domain for evaporation and from the data in t for precipitation
set_surface_flux(tracer, flux)

Set the surface flux

Parameters

tracer: str — the tracer
flux: slim.Data — the surface source flux [[tracer]*m/s]
set_penetrating_flux(pen_flux, pen_dist, tracer, z)

Set the penetrating flux

Parameters

pen_flux: slim.Data — the Total penetrating source flux [T*m/s]
pen_dist: slim.Data — the characteristic absorption distance [m]. The absorbed flux is computed as C * exp(-depth/pen_dist)
tracer: slim.ScalarArrayDevice — the tracer
z: slim.ScalarArrayDevice — the vertical mesh coordinate vector
set_surface_tracer_nudging(tracer, obs, surf_nudg_time, surf_nudg_depth, nudging_active)

Set the surface tracer nudging

Parameters

tracer: str — the tracer
obs: slim.Data — the observation data
surf_nudg_time: float — the nudging time
surf_nudg_depth: float — the nudging depth
nudging_active: List[bool] — If the nudging is active (1) or not (0) for each field.
class slim4.slim3d.TemporalIterator

time integration methods (for now only used as the external solver (2d part) of the 3d time integrator)

Methods

iterate(eq, sol, t, ddt, nstep, sol_avg)

Parameters

eq: slim.Equation — the equation to integrate
sol: slim.ScalarArrayDeviceMPI — the solution vector
t: float — the current time
ddt: float — the time step
nstep: int — the number of time steps
sol_avg: slim.ScalarArrayDevice — the average solution vector (output)
static rk(order)

create a Runge-Kutta iterator

Parameters

order: int — the order of the Runge-Kutta method

Returns

rk: TemporalIterator — the Runge-Kutta method
static rkls(scheme=2. / 13)

create a low-storage Runge-Kutta iterator

Parameters

scheme: float — the order of the Runge-Kutta method (2./13 is 3-step 2nd order)

Returns

rk: TemporalIterator — the Runge-Kutta method
static rk_butcher(a, b, c)

create a Runge-Kutta iterator with a given Butcher table

Parameters

a: NDArray[np.float64] — the matrix of the Butcher table
b: NDArray[np.float64] — the vector of the Butcher table
c: NDArray[np.float64] — the vector of the Butcher table

Returns

rk: TemporalIterator — the Runge-Kutta method
static dirk(sys, order, maxit=10, rtol=1e-5, atol=1e-5)

create a Diagonally Implicit Runge-Kutta iterator

Parameters

sys: slim.LinearSolver — the linear system solver
order: int — the order of the DIRK method
maxit: int — the maximum number of iterations
rtol: float — the relative tolerance
atol: float — the absolute tolerance

Returns

dirk: TemporalIterator — the DIRK method
static dirk_butcher(sys, a, b, c, maxit=10, rtol=1e-5, atol=1e-5)

create a Diagonally Implicit Runge-Kutta iterator with a given Butcher table

Parameters

sys: slim.LinearSolver — the linear system solver
a: List[List[float]] — the matrix of the Butcher table
b: List[float] — the vector of the Butcher table
c: List[float] — the vector of the Butcher table
maxit: int — the maximum number of iterations
rtol: float — the relative tolerance
atol: float — the absolute tolerance

Returns

dirk: TemporalIterator — the DIRK method
static midpoint(sys, maxit=10, rtol=1e-5, atol=1e-5)

create a Midpoint iterator

Parameters

sys: slim.LinearSolver — the linear system solver
maxit: int — the maximum number of iterations
rtol: float — the relative tolerance
atol: float — the absolute tolerance

Returns

midp: TemporalIterator — the Midpoint method
static crank_nicolson(sys, maxit=10, rtol=1e-5, atol=1e-5)

create a Crank-Nicolson iterator

Parameters

sys: slim.LinearSolver — the linear system solver
maxit: int — the maximum number of iterations
rtol: float — the relative tolerance
atol: float — the absolute tolerance

Returns

cn: TemporalIterator — the Crank-Nicolson method
class slim4.slim3d.UV

3D shallow water problem

Properties

mesh: Mesh — The mesh.
g: float — The gravity.
rho_0: float — The reference density.
bath: slim.Data — The bathymetry.
cor: slim.Data — The Coriolis parameter.
q_water: slim.Data — The precipitation/evaporation.
tau: slim.Data — The surface stress.
gamma: slim.Data — The dissipation coefficient.
a_nudging: slim.Data — The nudging coefficient.
uv_nudging: slim.Data — The nudging velocity.
gamma_log: bool — true if gamma_log is the coefficient of the log profile, false if it is directly the friction coefficient.
c: slim.ScalarArrayDevice — he 2D wave speed.
nu_h: slim.Data — The horizontal viscosity.
nu_v: slim.ScalarArrayDevice — The vertical viscosity.

Constructor

__init__(mesh, g, bath, rho_0, t=-31536000000)

Create a new 3D shallow water problem

Parameters

mesh: Mesh — The mesh.
g: float — The gravity.
bath: slim.Data — The bathymetry.
rho_0: float — The reference density.
t: float — The time.

Methods

set_wall_decay_time(decay_time)

Set the characteristic time of the wall zero velocity condition

Parameters

decay_time: float — The characteristic time of the wall zero velocity condition.
set_state_equation_jackett(temperature, salinity)

Set the state equation for the density of the fluid with the Jackett model

Parameters

temperature: slim.ScalarArrayDevice — The temperature.
salinity: slim.ScalarArrayDevice — The salinity.
set_state_equation_teos10(temperature, salinity)

Set the state equation for the density of the fluid with the teos10 model

Parameters

temperature: slim.ScalarArrayDevice — The conservative temperature.
salinity: slim.ScalarArrayDevice — The absolute salinity.
set_state_equation_linear(tracers_coeff)

Parameters

tracers_coeff: List[Tuple[slim.ScalarArrayDevice, float]] — The tracers and their coefficients.
set_wall_boundary(tag, slip=False)

Set a wall boundary condition

Parameters

tag: str — The tag of the boundary.
slip: bool — if True, slip (frictionless) wall. (default False)
set_open_boundary(tag, u=None, eta=None, uv_is_transport=False)

Set an open boundary condition

Parameters

tag: str — The tag of the boundary.
u: slim.Data | None — The velocity data.
eta: slim.Data | None — The elevation data.
uv_is_transport: bool — 1 if the boundary is a transport boundary, 0 if it is a velocity boundary.
set_dissipation(gamma, log_profile=False)

Set the dissipation coefficient.

Parameters

gamma: slim.Data — The dissipation coefficient.
log_profile: bool — true if gamma is the coefficient of the log profile, false if it is directly the friction coefficient.
set_surface_stress(tau)

Set the surface stress.

Parameters

tau: slim.Data — The surface stress.
set_coriolis(cor)

Set the Coriolis parameter.

Parameters

cor: slim.Data — The Coriolis parameter.
set_surface_water(q_water)

Set the surface water flow. Positive values are precipitation, negative values are evaporation.

Parameters

q_water: slim.Data — The surface water flow. Positive for rain, negative for evaoration
set_nudging(a_nudging, uv_nudging)

Add a nudging term as a source term in the momentum equation. None unsets the forcing.

Parameters

a_nudging: slim.Data — nudging coefficient over the domain during the simulation (1/s)
uv_nudging: slim.Data — 3D velocity (m/s) over the domain and over the duration of the simulation, expressed in the same projection as the mesh.
get_default_wave_speed(t=-31536000000)

Get the default wave speed sqrt(g*bath) for the 3D Shallow water problem.

Parameters

t: float — The time.

Returns

c: slim.ScalarArrayDevice — Output: The wave speed.
update_density(z, rho)

Update the density rho according to the state equation.

Parameters

z: slim.ScalarArrayDevice — The vertical coordinate.
rho: slim.ScalarArrayDevice — The density deviation to be computed.
clip_velocity(uv, z, vmax, t, uv_clip_loc=None)

Clip the speed to the maximum value

Parameters

uv: slim.ScalarArrayDevice — The horizontal velocity.
z: slim.ScalarArrayDevice — The vertical coordinate.
vmax: float — The maximum speed.
t: float — The time
uv_clip_loc: slim.ScalarArrayDevice | None — A table that registers in which elements the velocity is clipped.
set_c(c)

Set the maximum characteristic speed array (c) used in upwind stabilisation. Must be set before any temporal integration

Parameters

c: slim.ScalarArrayDevice — The 2D c array.
set_horizontal_viscosity(nu_h, formula='direct', direction='mesh')

Set the horizontal viscosity array (nu_h) used in upwind stabilisation.

Parameters

nu_h: slim.Data — The nu_h array.
formula: HorizontalViscosityFormula | str — The formula for the horizontal viscosity.
direction: HorizontalDiffusionOrientation | str — The orientation for the horizontal viscosity.
set_vertical_viscosity(nu_v_gpu)

Set the vertical viscosity array (nu_v) used in upwind stabilisation.

Parameters

nu_v_gpu: slim.ScalarArrayDevice — The nu_v array.
new_vector()

Create a new vector uv for the 3D shallow water equation.

Returns

new_v: slim.ScalarArrayDeviceMPI — The new vector.
solve_w(z, huv_nodal, sol_2d, t, w)

Compute the vertical velocity w from the 3D horizontal transport hu and hv.

Parameters

z: slim.ScalarArrayDevice — The vertical coordinate.
huv_nodal: slim.ScalarArrayDevice — The horizontal transport.
sol_2d: slim.ScalarArrayDevice — The 2D solution containing the free surface elevation.
t: float — The time.
w: slim.ScalarArrayDeviceMPI — The vertical velocity to be computed
solve_w_tilde(huv_nodal, sol_2d, t, w)

Compute the vertical velocity tilde w from the 3D horizontal transport hu and hv.

Parameters

huv_nodal: slim.ScalarArrayDevice — The horizontal transport.
sol_2d: slim.ScalarArrayDevice — The 2D solution containing the free surface elevation.
t: float — The time.
w: slim.ScalarArrayDeviceMPI — The vertical velocity to be computed
solve_hpg(z, rho, sol_2d, t, hpg)

Compute the reduced horizontal baroclinic pressure gradient hpg.

Parameters

z: slim.ScalarArrayDevice — The vertical coordinate.
rho: slim.ScalarArrayDevice — The density.
sol_2d: slim.ScalarArrayDevice — The 2D solution containing the free surface elevation.
t: float — The time.
hpg: slim.ScalarArrayDeviceMPI — The reduced horizontal baroclinic pressure gradient to be computed
solve_horizontal(z, sol_2d, uv, hpg, huv, drho, t, dt, dt_total, f_expl, implicit, f_total_vsum)

Compute horizontal derivative of the horizontal velocity u and v.

Parameters

z: slim.ScalarArrayDevice — The vertical coordinate.
sol_2d: slim.ScalarArrayDevice — The 2D solution containing the free surface elevation.
uv: slim.ScalarArrayDevice — The horizontal velocity.
hpg: slim.ScalarArrayDevice — The reduced horizontal baroclinic pressure gradient
huv: slim.ScalarArrayDevice — The horizontal transport.
drho: slim.ScalarArrayDevice — The density gradient.
t: float — The time.
dt: float — The sub time step.
dt_total: float — The total time step.
f_expl: slim.ScalarArrayDeviceMPI — The explicit part of the rhs of the time derivative of uv, M*duvdt = f_expl + f_impl.
implicit: bool — Whether to use implicit friction.
f_total_vsum: slim.ScalarArrayDevice — The vertically integrated rhs, including thr implicit part of the rhs (friction).
solve_vertical(z_old, z_mid, z_next, w, wm, f_expl, f2d, uv_old, uv_mid, uv_next, huv, drho, sol2d_mean, hpg, t, dt, dt_total, implicit)

Compute the vertical derivative of the horizontal velocity u and v.

Parameters

z_old: slim.ScalarArrayDevice — The vertical coordinate at the beginning of the time step.
z_mid: slim.ScalarArrayDevice — The vertical coordinate inside of the time step for the explicit scheme. Can be None if implicit=True.
z_next: slim.ScalarArrayDevice — The vertical coordinate at the end of the time step.
w: slim.ScalarArrayDevice — The vertical velocity.
wm: slim.ScalarArrayDevice — The vertical mesh velocity.
f_expl: slim.ScalarArrayDevice — The explicit part of the rhs of the time derivative of uv, M*duvdt = f_expl + f_impl.
f2d: slim.ScalarArrayDevice — The 2D explicit rhs added to f_expl.
uv_old: slim.ScalarArrayDevice — The horizontal velocity at the beginning of the time step.
uv_mid: slim.ScalarArrayDevice — The horizontal velocity inside of the time step for the explicit scheme. Can be None if implicit=True.
uv_next: slim.ScalarArrayDeviceMPI — The computed value of uv at the end of the time step.
huv: slim.ScalarArrayDevice — The horizontal transport.
drho: slim.ScalarArrayDevice — The density gradient.
sol2d_mean: slim.ScalarArrayDevice — The average 2D solution corresponding to huv.
hpg: slim.ScalarArrayDeviceMPI — The reduced horizontal baroclinic pressure gradient.
t: float — The time.
dt: float — The sub time step.
dt_total: float — The total time step.
implicit: bool — Whether to use implicit or explicit vertical advection/diffusion.
get_2d_variables(z, uv, sol2d, c=None)

Get the 2D variables from the 3D Shallow water problem.

Parameters

z: slim.ScalarArrayDevice — The vertical coordinate.
uv: slim.ScalarArrayDevice — The horizontal 3D velocity.
sol2d: slim.ScalarArrayDevice — The 2D solution that will be computed.
c: slim.ScalarArrayDevice | None — Optional : The 2D wave speed that will be computed.
compute_huv(z, uv, huv)

Compute the horizontal transport and element height huv.

Parameters

z: slim.ScalarArrayDevice — The vertical coordinate.
uv: slim.ScalarArrayDevice — The horizontal 3D velocity.
huv: slim.ScalarArrayDevice — The horizontal transport that will be computed.
compute_2d_contribution(sol0, sol1, f3d_to_subtract, f2d_for_3d, dt)

Compute the transport derivative dHu/dt that comes from the 2D mode only.

Parameters

sol0: slim.ScalarArrayDevice — The 2D solution at the previous time step.
sol1: slim.ScalarArrayDevice — The 2D solution at the current time step.
f3d_to_subtract: slim.ScalarArrayDevice — The 3D rhs that should be removed from sol1-sol0.
f2d_for_3d: slim.ScalarArrayDevice — The 2D rhs that will be computed.
dt: float — The time step.
get_tracer_variables(z, uv, sol2d_avg, z_tracer, huv_tracer)

Reconstruct z and huv from the averaged 2D for the tracer equations

Parameters

z: slim.ScalarArrayDevice — The vertical coordinate.
uv: slim.ScalarArrayDevice — The horizontal 3D velocity.
sol2d_avg: slim.ScalarArrayDevice — The averaged 2D solution.
z_tracer: slim.ScalarArrayDevice — The vertical coordinate for the tracer equations.
huv_tracer: slim.ScalarArrayDevice — The horizontal 3D transport for the tracer equations
class slim4.slim3d.Tracer

A tracer problem on a 3D mesh

Properties

nfields: int — the number of tracer fields

Constructor

__init__(mesh, g, h, nfields, name, limiter_type='past_bound', wadd=0)

create a new 3D tracer problem

Parameters

mesh: Mesh — The 3D mesh.
g: float — The gravity.
h: slim.Data — The water depth.
nfields: int — The number of tracer fields.
name: str — The name of the tracer.
limiter_type: slim.LimiterType | str — The type of limiter in use
wadd: float — The additional vertical velocity.

Methods

set_wall_boundary(tag, slip=False)

Set a boundary condition.

Parameters

tag: str — The tag of the boundary.
slip: bool — if True, slip (frictionless) wall. (default False)
set_open_boundary(tag, tracer, u, eta, uv_is_transport)

Set a boundary condition.

Parameters

tag: str — The tag of the boundary.
tracer: slim.Data — The tracer data.
u: slim.Data — The velocity data.
eta: slim.Data — The elevation data.
uv_is_transport: bool — 1 if the boundary is a transport boundary, 0 if it is a velocity boundary.
set_c(c)

Set the maximum characteristic speed array (c) used in upwind stabilisation. Must be set before any temporal integration.

Parameters

c: slim.ScalarArrayDevice — the 2D c array
set_surface_flux(flux_surf)

Set surface source tracer flux

Parameters

flux_surf: slim.Data — Surface source flux [T*m/s]
set_surface_water(flux_water)

Set source surface freshwater flux [m/s]

Parameters

flux_water: slim.Data — Surface freshwater flux [m/s], negative means evaporation, positive means precipitation
set_surface_water_tracer(flux_water, flux_water_tracer, upwind)

Set tracer concentration of entering/outgoing freshwater [T]

Parameters

flux_water: slim.Data — Surface freshwater flux [m/s], negative means evaporation, positive means precipitation
flux_water_tracer: slim.Data — Concentration of tracer [T]
upwind: List[bool] — if True, the tracer concentration is taken from the domain for evaporation and from the data in t for precipitation
set_surface_tracer_nudging(surf_tracer, surf_nudg_time, surf_nudg_depth, nudging_active)

Set surface tracer nudging towards observations

Parameters

surf_tracer: slim.Data — Sea surface tracer observations [T]
surf_nudg_time: float — Nudging time scale for sea surface tracer [s]
surf_nudg_depth: float — Nudging depth for sea surface tracer [m]
nudging_active: List[bool] — If the nudging is active (1) or not (0) for each field. fields
set_horizontal_diffusivity(kappa_h, formula='direct', direction='mesh')

Set the horizontal diffusivity array (kappa_h) used in upwind stabilisation.

Parameters

kappa_h: slim.Data — The data
formula: slim2d.HorizontalDiffusivityFormula | str — The formula to use to compute the horizontal diffusivity
direction: HorizontalDiffusionOrientation | str — The orientation for the horizontal diffusivity
set_vertical_diffusivity(kappa_v_gpu)

Set the vertical diffusivity array (kappa_v) used in upwind stabilisation.

Parameters

kappa_v_gpu: slim.ScalarArrayDevice — The kappa_v array
set_nudging(a_nudging, tracer_nudging)

Add a nudging term as a source term in the momentum equation. None unsets the forcing.

Parameters

a_nudging: slim.Data — nudging coefficient(s) over the domain during the simulation (1/s)
tracer_nudging: slim.Data — Tracer field(s) over the domain and over the duration of the simulation, expressed in the same projection as the mesh.
new_vector()

Create a new 3D tracer vector.

Returns

new_v: slim.ScalarArrayDeviceMPI — return The new vector
solve(z_old, z_mid, z_next, w, wm, huv, drho, tracer_old, tracer_mid, tracer_next, sol2d, t, dt, implicit, apply_limiter)

Solve the 3D tracer equations.

Parameters

z_old: slim.ScalarArrayDevice — The vertical coordinate at the beginning of the time step
z_mid: slim.ScalarArrayDevice — The vertical coordinate inside of the time step for the explicit scheme. Can be None if implicit=True
z_next: slim.ScalarArrayDevice — The vertical coordinate at the end of the time step
w: slim.ScalarArrayDevice — The vertical velocity
wm: slim.ScalarArrayDevice — The vertical mesh velocity
huv: slim.ScalarArrayDevice — The horizontal transport
drho: slim.ScalarArrayDevice — The density gradient
tracer_old: slim.ScalarArrayDevice — The tracer at the beginning of the time step
tracer_mid: slim.ScalarArrayDevice — The tracer inside of the time step for the explicit scheme. Can be None if implicit=True
tracer_next: slim.ScalarArrayDeviceMPI — The computed value of tracer at the end of the time step
sol2d: slim.ScalarArrayDevice — The average 2D solution corresponding to to z_mid and huv
t: float — The time
dt: float — The time step.
implicit: bool — Whether to use implicit or explicit vertical advection/diffusion
apply_limiter: bool — Whether to apply the limiter
class slim4.slim3d.Turbulence

A 3D turbulence object

Constructor

__init__(mesh, g, rho_0, model, stab, z0b, z0s)

create a new 3D turbulence object.

Parameters

mesh: Mesh — 3D mesh
g: float — gravity
rho_0: float — reference density
model: TurbulenceModelType | str — turbulence model
stab: TurbulenceStabilityType | str — stability model
z0b: slim.Data — length scale for bottom roughness
z0s: slim.Data — length scale for surface roughness

Methods

new_vector()

Create a new vector for the 3D Turbulence problem. The two individual components can be accessed with the get_sub method.

Returns

turb: slim.ScalarArrayDeviceMPI — The new vector
solve_fv(z_old, z_new, uv, rho, kpsi, kpsi_next, nu_kappa, t, dt)

Solve the 3D Shallow water equations using the finite volume method.

Parameters

z_old: slim.ScalarArrayDevice — The vertical coordinate at the beginning of the time step
z_new: slim.ScalarArrayDevice — The vertical coordinate at the end of the time step
uv: slim.ScalarArrayDevice — The horizontal velocity
rho: slim.ScalarArrayDevice — The density
kpsi: slim.ScalarArrayDevice — The turbulent kinetic energy and the turbulent stream function
kpsi_next: slim.ScalarArrayDeviceMPI — The computed value of kpsi at the end of the time step
nu_kappa: slim.ScalarArrayDeviceMPI — The computed vertical eddy viscosity and diffusivity
t: float — The current time
dt: float — The time step
class slim4.slim3d.ReactionLinearDecay

Bases: slim.Reaction.

A linear reaction term.

Properties

alpha: float — The reaction coefficient
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector
reactives: slim.ScalarArrayDevice — The tracers

Constructor

__init__(mesh, alpha, z, reactives)

Create a new linear decay reaction.

Parameters

mesh: Mesh — The mesh.
alpha: float — The reaction coefficient.
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector.
reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
class slim4.slim3d.ReactionExponentialDecay3d

Bases: slim.Reaction.

An exponential decay reaction term.

Properties

mu: float — The reaction coefficient
z: slim.ScalarArrayDevice — The vertical mesh coordinate vector
reactives: slim.ScalarArrayDevice — The tracers

Constructor

__init__(mesh, mu, z, reactives)

Create a new exponential decay reaction.

Parameters

mesh: Mesh — The mesh.
mu: float — The reaction coefficient.
z: slim.ScalarArrayDevice — The vertical mesh coordinate vector.
reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
class slim4.slim3d.ReactionNPZD3d

Bases: slim.Reaction.

A NPZD model

Properties

mu: float — The max phytoplankton growth rate
gamma: float — The zooplankton assimilation efficiency
rd: float — The detritus remineralization rate
mp: float — The phytoplankton mortality rate
mz: float — The zooplankton mortality rate
gmax: float — The maximum growth rate
kn: float — The nutrient half-saturation constant
kp: float — The phosphorus half-saturation constant
ki: float — The light half-saturation constant
I0: float — The initial light intensity
k: float — The light attenuation with depth coefficient
z: slim.ScalarArrayDevice — The vertical mesh coordinate vector
reactives: slim.ScalarArrayDevice — The tracers

Constructor

__init__(mesh, mu, gamma, rd, mp, mz, gmax, kn, kp, ki, I0, k, z, reactives)

Create a new exponential decay reaction.

Parameters

mesh: Mesh — The mesh.
mu: float — The max phytoplankton growth rate.
gamma: float — The zooplankton assimilation efficiency.
rd: float — The detritus remineralization rate.
mp: float — The phytoplankton mortality rate.
mz: float — The zooplankton mortality rate.
gmax: float — The maximum growth rate.
kn: float — The nutrient half-saturation constant.
kp: float — The phosphorus half-saturation constant.
ki: float — The light half-saturation constant.
I0: float — The initial light intensity.
k: float — The light attenuation with depth coefficient.
z: slim.ScalarArrayDevice — The vertical mesh coordinate vector.
reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
class slim4.slim3d.ReactionSurfaceProd

Bases: slim.Reaction.

A surface production term.

Properties

source: slim.Data — The surface source data
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector
reactives: slim.ScalarArrayDevice — The tracers

Constructor

__init__(mesh, source, z, reactives)

Create a new linear decay reaction.

Parameters

mesh: Mesh — The mesh.
source: slim.Data — The surface source data.
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector.
reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
class slim4.slim3d.ReactionLWHC

Bases: slim.Reaction.

Long-Wave heat correction

Properties

surface_temp: slim.Data — The surface temperature data
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector
reactives: slim.ScalarArrayDevice — The tracers

Constructor

__init__(mesh, surface_temp, z, reactives)

Create a new linear decay reaction.

Parameters

mesh: Mesh — The mesh.
surface_temp: slim.Data — The surface temperature data
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector.
reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
class slim4.slim3d.ReactionLatentFlux

Bases: slim.Reaction.

Temperature corrections including: - Latent turbulent heat flux correction

Properties

surface_temp: slim.Data — The surface temperature data [°C]
air_mix_ratio: slim.Data — The air mixing ratio [g/kg]
sat_mix_ratio: slim.Data — The saturation mixing ratio [g/kg]
q_lat: slim.Data — The latent heat flux [W/m2]
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector
reactives: slim.ScalarArrayDevice — The tracers

Constructor

__init__(mesh, surface_temp, air_mix_ratio, sat_mix_ratio, q_lat, z, reactives)

Create a new linear decay reaction.

Parameters

mesh: Mesh — The mesh.
surface_temp: slim.Data — The surface temperature data
air_mix_ratio: slim.Data — The air mixing ratio
sat_mix_ratio: slim.Data — The saturation mixing ratio
q_lat: slim.Data — The latent heat flux
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector.
reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
class slim4.slim3d.ReactionTemperatureCorrection

Bases: slim.Reaction.

Temperature corrections including: - Longwave radiative heat flux correction - Latent turbulent heat flux correction

Properties

surface_temp: slim.Data — The surface temperature data [°C]
air_mix_ratio: slim.Data — The air mixing ratio [g/kg]
sat_mix_ratio: slim.Data — The saturation mixing ratio [g/kg]
q_lat: slim.Data — The latent heat flux [W/m2]
q_sens: slim.Data — The sensible heat flux [W/m2]
tair: slim.Data — The air temperature at 2m above the interface [°C]
wind_velocity: slim.Data — The near-surface wind velocity [m/s]
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector
reactives: slim.ScalarArrayDevice — The tracers

Constructor

__init__(mesh, surface_temp, air_mix_ratio, sat_mix_ratio, q_lat, q_sens, tair, wind_velocity, z, reactives)

Create a new linear decay reaction.

Parameters

mesh: Mesh — The mesh.
surface_temp: slim.Data — The surface temperature data
air_mix_ratio: slim.Data — The air mixing ratio
sat_mix_ratio: slim.Data — The saturation mixing ratio
q_lat: slim.Data — The latent heat flux
q_sens: slim.Data — The sensible heat flux
tair: slim.Data — The air temperature at 2m above the interface
wind_velocity: slim.Data — The near-surface wind velocity
z: slim.ScalarArrayDevice — The verticla mesh coordinate vector.
reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
class slim4.slim3d.ReactionPenSource

Bases: slim.Reaction.

Penetration source term

Constructor

__init__(mesh, pen_flux, pen_dist, tracer, z)

Create a new linear decay reaction.

Parameters

mesh: Mesh — The mesh.
pen_flux: slim.Data — Total penetrating source flux [T*m/s]
pen_dist: slim.Data — Characteristic absorption distance [m]. The absorbed flux is computed as C * exp(-depth/pen_dist)
tracer: slim.ScalarArrayDevice — The tracers on which the reaction acts.
z: slim.ScalarArrayDevice — The vertical mesh coordinate vector.

Functions

slim4.slim3d.partition_mesh(meshfile2d, path3d, outpath)

Partition a 3D mesh and write a new mesh file for each partition.

Parameters

meshfile2d: str — The path to the non-partitioned 2d mesh file.
path3d: str — The path to the 3d mesh, as created by mesh3d.save_mesh(). The path should contain n_layers, triangle_element_tag and z in the abin format.
outpath: str — The folder for the split 3D mesh.
slim4.slim3d.project_l2_points(mesh, z)

Get the points where to evaluate an analytic funtion for the projection to a 3D mesh.

Parameters

mesh: Mesh — T
z: NDArray[np.float64] — The z coordinate of the mesh

Returns

points: NDArray[np.float64] — The points where to evaluate the function
slim4.slim3d.project_l2(mesh, z, function_at_points)

Project a function to a 3D mesh using L2 projection.

Parameters

mesh: Mesh — The 3D mesh
z: NDArray[np.float64] — The z coordinate of the mesh
function_at_points: NDArray[np.float64] — The function, evaluated at the points given by project_l2_points

Returns

projected: NDArray[np.float64] — The projected function
slim4.slim3d.iterate(problem, z_gpu, uv_gpu, tracers, t, dt, nstep, nrk2d, implicit_steps, solver_2d=None, split=True)

Parameters

problem: Problem — the problem to solve
z_gpu: slim.ScalarArrayDevice — the z solution field
uv_gpu: slim.ScalarArrayDevice — the uv solution field
tracers: List[slim.ScalarArrayDevice] — the tracers solution fields
t: float — the current time
dt: float — the time step
nstep: int — the number of sub-time steps
nrk2d: List[int] — the number of 2d sub time-steps for each 3d sub-step
implicit_steps: List[bool] — indicates if each sub-step is implicit
solver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)
split: bool — if False, the 2D and 3D modes execute in lockstep instead of split-imex.

Returns

end_t: float — the end time
slim4.slim3d.iterate_midpoint(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)

Second-order 2-step imex scheme. The first step is vertically implicit, second step is explicit. This is the recommended default scheme for SLIM 3D, as it is a good balance between accuracy, stability and performance.

Parameters

problem: Problem — the problem to solve
t: float — the current time
dt: float — the time step
M: float — the number of sub-time steps
nstep: int — the number of sub-time steps
z_gpu: slim.ScalarArrayDevice — the z solution field
uv_gpu: slim.ScalarArrayDevice — the uv solution field
tracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fields
solver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)

Returns

end_t: float — the end time
slim4.slim3d.iterate_impl(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)

3-step vertically implicit runge-kutta. It is recommended to try the midpoint scheme first, and only use this scheme if the midpoint scheme is unstable due to the bottom friction or vertical viscosity/diffusivity. This scheme is stable but only formally first-order due to the first-order treatment of the bottom friction.

Parameters

problem: Problem — the problem to solve
t: float — the current time
dt: float — the time step
M: float — the number of sub-time steps
nstep: int — the number of sub-time steps
z_gpu: slim.ScalarArrayDevice — the z solution field
uv_gpu: slim.ScalarArrayDevice — the uv solution field
tracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fields
solver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)

Returns

end_t: float — the end time
slim4.slim3d.iterate_expl(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)

Second-order 3-step explicit runge-kutta scheme. Using this scheme for real life simulations is STRONGLY DISCOURAGED, as it is not stable enough. It is mostly available for testing purposes. treatment of the bottom friction.

Parameters

problem: Problem — the problem to solve
t: float — the current time
dt: float — the time step
M: float — the number of sub-time steps
nstep: int — the number of sub-time steps
z_gpu: slim.ScalarArrayDevice — the z solution field
uv_gpu: slim.ScalarArrayDevice — the uv solution field
tracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fields
solver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)

Returns

end_t: float — the end time
slim4.slim3d.iterate_impl_rk1(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)

1-step vertically implicit runge-kutta. This scheme is stable but only first-order accurate. It is mostly available for testing purposes.

Parameters

problem: Problem — the problem to solve
t: float — the current time
dt: float — the time step
M: float — the number of sub-time steps
nstep: int — the number of sub-time steps
z_gpu: slim.ScalarArrayDevice — the z solution field
uv_gpu: slim.ScalarArrayDevice — the uv solution field
tracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fields
solver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)

Returns

end_t: float — the end time
slim4.slim3d.iterate_expl_rk1(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)

1-step vertically explicit runge-kutta. This scheme is very unstable and only first-order accurate. It should never be used for real-life simulations.

Parameters

problem: Problem — the problem to solve
t: float — the current time
dt: float — the time step
M: float — the number of sub-time steps
nstep: int — the number of sub-time steps
z_gpu: slim.ScalarArrayDevice — the z solution field
uv_gpu: slim.ScalarArrayDevice — the uv solution field
tracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fields
solver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)

Returns

end_t: float — the end time
slim4.slim3d.iterate_offline(problem, z, tracers, t, dt, nstep, nrk2d, implicit_steps)

Iterate over a slim4::slim3d::OfflineProblem.

Parameters

problem: OfflineProblem — the offline tracer problem to solve
z: slim.ScalarArrayDevice — the vertical coordinate of the mesh
tracers: List[slim.ScalarArrayDevice] — the tracers solution fields
t: float — the current time
dt: float — the time step
nstep: int — the number of sub-time steps
nrk2d: List[int] — the number of 2d sub time-steps for each 3d sub-step
implicit_steps: List[bool] — indicates if each sub-step is implicit

Returns

end_t: float — the end time