slim4.slim2d

2D hydrodynamics classes and functions

Enums

class slim4.slim2d.GatherOp(IntEnum)

determine the operation to perform during a DG to CG gather.

Values

sum: 0 — Sum
max: 1 — Maximum
min: 2 — Minimum
mean_area: 3 — Mean weighted by the area of the triangles. Should NOT be used in 3D
mean_volume: 4 — Mean weighted by the volume of the prisms (3D only)
class slim4.slim2d.DissipationType(IntEnum)

determine how the dissipation is computed (_exp : always eplicit and interpolated from nodes to quadrature points, _imp : implicit in implicit scheme and evaluated directly at quadrature points. If in doubt, use ‘LINEAR’.

Values

linear: 0 — : du/dt = -gamma_expl u_impl
quadratic: 1 — : du/dt = -(gamma/u)_expl |u|_impl u_impl
class slim4.slim2d.DissipationFormula(IntEnum)

how is the dissipation coefficient ‘gamma’ computed

Values

none: 0 — no dissipation
linear: 1 — Direct dissipation coefficient: tau_b/rho = gamma*Hu (s^-1) if type==linear; tau_b/rho = gamma*|u|*Hu if type==quadratic; coefficient = gamma
manning: 2 — Manning formula : Chezy-Manning-Strickler formulation tau_b/rho = (n*n*g/(H^4/3))*|u|*u (sm^(-1/3)). coefficient = n is the Manning coefficient
bulk: 4 — Bulk drag : tau_b/rho = (C_d/H)*|u|*u (dimensionless), coefficient=C_d
slope: 8 — tau_b/rho = Cs |gradH*u|/H * u
class slim4.slim2d.ViscosityFormula(IntEnum)

how is the viscosity coefficient ‘nu’ computed

Values

none: 0 — no viscosity
smagorinsky: 1 — Smagorinsky viscosity
class slim4.slim2d.HorizontalDiffusivityFormula(IntEnum)

The formula for the viscosity.

Values

none: 0 — No diffusivity.
direct: 1 — The horizontal diffusivity is the slim4::slim::Data given.
okubo: 2 — Okubo horizontal diffusivity. It is evaluated as coefficient * area^(1.15/2)
smago: 3 — Smagorinsky horizontal.

Classes

class slim4.slim2d.Mesh

Bases: slim.Mesh.

A bi-dimensional mesh

Properties

projection_type: str — The type of the coordinate system of the mesh (e.g. ‘proj4’, of ‘WKT’).
projection: str — The coordinate system of the mesh coordinates (the meaning of the string depends on projection_type).
n_triangles: int — The number of triangles, excluding ghosts
x: NDArray[np.float64] — 2d-coordinates [xy]/node/tri
xnodes: NDArray[np.float64] — 2d-coordinates [xy]/node(continuous)
area: NDArray[np.float64] — The area of each triangle.
n_edges: int — The number of edges not including boundary edges and edges touching a ghost triangle.
n_boundary_edges: int — The number of boundary edges.
n_ghosts: int — The total number of ghost edges/triangles
n_intern: int — The number of triangles which are not adjascent to boundary or to ghost element, rounded down to multiple of the gpu block size.
edges: NDArray[np.int32] — The edges : (element_left, element_right, closure_left, closure_righ closure%3 is the local index of the edge in the element, closure/3 is the orientation of the edge in the element. This array contains successively, the internal edges, the ghost edges and the boundary edges. Ghost edges are edges whose element_right is owned by another partiion. They are sorted by the rank of the partition ownning element_right. The boundary edges are (element_left, -INT_MAX, closure_left, boundary_tag). They are sorted by boundary_tag.
n_neighbour_partition: int — The number of neighbouring partitions.
neighbour_partition: NDArray[np.int32] — The rank of the neighbouring partitions.
ghost_edge_start: NDArray[np.int32] — The start of the ghost edges for each partition. Serves as an index in the edges array.
boundary_names: List[str] — The name of the boundary tags.
boundary_edges_start: NDArray[np.int32] — The start of the boundary edges for each boundary tag. Serves as an index in the edges array.
gmsh_nodes_id: NDArray[np.int32] — The gmsh id of the nodes.
triangle_start: int — The start of the triangles owned by this partition.
triangles_global_id: NDArray[np.int32] — The global id of the triangles.
triangles_gmsh_id: NDArray[np.int32] — The gmsh id of the triangles.
neighbours: NDArray[np.int32] — The neighbours of each triangle and associated closures.
neighbour_partition_cg: NDArray[np.int32] — The rank of the neighbouring partitions (all partitions touching one node of any elements, including ghosts).
cg_nodes_global_idx: NDArray[np.int32] — global index of the cg nodes
cg_nodes_type: NDArray[np.int32] — 0:owned 1:ghost(cg) 2:ghost(dg only)
cg_nodes_start: int — global index of the first owned cg node
cg_nodes_end: int — global index of the last owned cg nod

Constructor

__init__(file_name, tags=[], projection='', projection_type='', set_triangles_gmsh_id=None)

Create a 2d mesh from a file.

Parameters

file_name: str — The name of the file to read.
tags: List[str] — The physical tags of the entities to load (NULL for all).
projection: str — The coordinate system of the mesh coordinates if any (the string format depends on projection_type).
projection_type: str — The type of the coordinate system of the mesh coordinates if any (e.g. ‘proj4’, of ‘WKT’).
set_triangles_gmsh_id: NDArray[np.int32] | None — The gmsh id of the triangles in the desired order.

Methods

scatter_array(x)

Scatter a scalar array. Fill the values of the ghost triangles from the values on the rank owning those triangles.

Parameters

x: slim.ScalarArrayDeviceMPI — The array to scatter. [n_fields, n_phi, n_elements]. n_fields * n_phi must be < 9
boundary_id(name)

Return the id of the boundary tag.

Parameters

name: str — The name of the boundary tag.

Returns

id: int — return the id of the boundary tag.
get_boundary_name(id)

Return the tag of the boundary id.

Parameters

id: int — the id of the boundary tag.

Returns

name: str — return the name of the boundary tag.
find_points(xy)

Find the triangles containing some points.

Parameters

xy: NDArray[np.float64] — The x and y coordinates of the points of shape (2, n).

Returns

new_eid: NDArray[np.int32] — return a new array with the id of the triangle containing each point.
new_uv: NDArray[np.float64] — return a new array with the parametric coordinates of the points in the triangles.
boundary_nodes_dg(tags)

Return the dg nodes of the boundary edges.

Parameters

tags: List[str] — list of boundary tags

Returns

triangles: NDArray[np.int32] — return a new array with the id of the triangles adjacents to the boundary
nodes_id: NDArray[np.int32] — return a new array with the position of the nodes inside the triangle (0,1,2)
boundary_nodes(tags, unique=True)

Return the nodes of the boundary edges.

Parameters

tags: List[str] — list of boundary tags
unique: bool — if true, return a flat array of sorted unique nodes, else return a [n_bnd_seg, 2] array of nodes

Returns

new_nodes: NDArray[np.int32] — return a new array with the boundary nodes
gather_dg_to_cg(op, dg)

Gather a dg array to a cg array. The cg array is allocated.

Parameters

op: GatherOp | str — the gather operation
dg: NDArray[np.float64] — the input dg array […, node, elem]

Returns

new_cg: NDArray[np.float64] — return the newly-allocated cg array […, n_cg_nodes]
gather_dg_to_cg_idx(op, dg)

Gather a dg array to a cg array. The cg array is allocated.

Parameters

op: GatherOp | str — the gather operation
dg: NDArray[np.int32] — the input dg array […, node, elem]

Returns

new_cg: NDArray[np.int32] — return the newly-allocated cg array […, n_cg_nodes]
scatter_cg_scalar(dg)

Scatter a cg array. The returned cg array is allocated.

Parameters

dg: NDArray[np.float64] — the input cg array […, n_cg_nodes]

Returns

new_cg: NDArray[np.float64] — return the newly-allocated cg array […, n_cg_nodes]
scatter_cg_idx(dg)

Scatter a cg array. The returned cg array is allocated.

Parameters

dg: NDArray[np.int32] — the input cg array […, n_cg_nodes]

Returns

new_cg: NDArray[np.int32] — return the newly-allocated cg array […, n_cg_nodes]
smooth_bath(bath_dg, coefficient=0.5, minimum_delta=0.3)

Smooth the bathymetry : ensures that (H_max - H_min) < coefficient * H_max + min_delta on any element

Parameters

bath_dg: NDArray[np.float64] — The bathymetry
coefficient: float — The Maximum value of
minimum_delta: float — The minimum delta

Returns

new_bath_smoothed: NDArray[np.float64] — return the smoothed bathymetry
smooth_bath_haney(bath_dg, coefficient=1.2, minimum_delta=0.5)

Smooth the bathymetry with respect to haney critiria with a given coefficient

Parameters

bath_dg: NDArray[np.float64] — The bathymetry
coefficient: float — The smoothing coefficient
minimum_delta: float — The minimum delta

Returns

new_bath_smoothed: NDArray[np.float64] — return the smoothed bathymetry
create_xdmf(fname, cg=False)

Create a new empty xdmf export

Parameters

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, 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
fields: List[Tuple[str, NDArray[np.float64]]] — fields to be exported
precision: slim.OutputPrecision | str — native, half, single or double
to_neighbours_cg_nodes(i, with_dg_ghost=True)

Parameters

i: int — The index of the neighbouring partition
with_dg_ghost: bool — If True, include the dg ghost nodes

Returns

indices: NDArray[np.int32] — The id of the cg nodes to send to the neighbouring partition
neighbour_partition_cg_extent(i)

Parameters

i: int — The index of the neighbouring partition ([start, end[)

Returns

start: int — The first node of the neighbouring partition
end: int — The node after the last node of the neighbouring partition
check_consistency_scalar(data, rtol)

Checks if the values in the ghost cells are consistent with the other partitions

Parameters

data: NDArray[np.float64] — The data field to check for consistency
rtol: float — The relative tolerance used fo the check. Checks that abs(a-b)/(abs(a+b) + min_scalar) < rtol

Returns

validity: bool — true if the data is consistent up to , else false
check_consistency_idx(data)

Checks if the values in the ghost cells are consistent with the other partitions

Parameters

data: NDArray[np.int32] — The data field to check for consistency

Returns

validity: bool — true if the data is consistent, else false
class slim4.slim2d.ShallowWater

Bases: slim.Equation.

data of the shallow water problem

Properties

mesh: Mesh — the mesh
g: float — The gravity
rho_0: float — reference density
bath: slim.Data — depth bellow reference level
wd_coeff: slim.ScalarArrayDeviceMPI — wetting and drying coefficient
cfl: float — sub-critical cfl-based maximum time step : min (2*area/(perimeter*sqrt(g*h)))

Constructor

__init__(mesh, g, bath, rho_0=1000, wave_only=False)

Create the depth-averaged shallow water equation.

Parameters

mesh: Mesh — the mesh
g: float — mean gravitational acceleration (m/s²)
bath: slim.Data — bathymetry (in m, 0 at the surface, positive on the bottom)
rho_0: float — mean water density in the domain (kg/³)
wave_only: bool — If true, only the wave equation is solved. Should be false unless used as part of the 3D scheme.

Methods

set_c(c)

Set the maximum characteristic speed array (c) used in upwind stabilisation. If not set, c is computed from the bathymetry and the gravity.

Parameters

c: slim.ScalarArrayDevice — the c array
set_f3d(f3d)

Sets the 3D source term in the shallow water equation.

Parameters

f3d: slim.ScalarArrayDevice — the f3d array
set_surface_stress(tau)

Add a surface stress term in the shallow water equation.

Parameters

tau: slim.Data — 2D surface stress over the domain and over the duration of the simulation, expressed in the same projection as your mesh (kg m^-1 s^-1)
set_atmospheric_pressure(atm_press)

Add a momentum source term accounting for the variation in the atmospheric pressure in the shallow water equations.

Parameters

atm_press: slim.Data — Surface pressure over the domain and over the duration of the simulation (Pa)
set_coriolis(f)

Add a coriolis term -f e_z x Hu in the shallow water equation

Parameters

f: slim.Data — the coriolis factor (1/s), generraly 2*Omega*cos(latitude)
set_surface_water(q_water)

Add a precipitation-evaporation term q in the shallow water equation

Parameters

q_water: slim.Data — the q quantity (m/s)
set_nudging(a_nudging, uv_nudging, is_transport=False)

Add a nudging term as a source term in the conservative shallow water equation.

Parameters

a_nudging: slim.Data — nudging coefficient over the domain during the simulation (1/s)
uv_nudging: slim.Data — 2D depth-averaged velocity (m/s) or transport (m^2/s) over the domain and over the duration of the simulation, expressed in the same projection as your mesh (slimdata format)
is_transport: bool — set whether ux and uy are velocities (False) or transport (True)
set_dissipation(coefficient, type='linear', formula='linear')

DEPRETACTED in favor of add_dissipation. Add dissipation due to bottom friction: basic linear or quadratic scheme, Chezy-Manning scheme, bulk drag fomulation or slope dissipation

Parameters

coefficient: slim.Data — coefficient value (gamma, C_d, n or C_s depending on the mode) over the whole domain
type: DissipationType | str — dissipation type
formula: DissipationFormula | str — dissipation formula
add_dissipation(coefficient, type='linear', formula='linear')

Add dissipation due to bottom friction: basic linear or quadratic scheme, Chezy-Manning scheme, bulk drag fomulation or slope dissipation

Parameters

coefficient: slim.Data — coefficient value (gamma, C_d, n or C_s depending on the mode) over the whole domain
type: DissipationType | str — dissipation type
formula: DissipationFormula | str — dissipation formula
set_viscosity(coefficient, formula='none')

Add a viscous term in the shallow water equation.

Parameters

coefficient: slim.Data — kappa (m^2/s) if formula is NONE else smagorinsky coefficient (dimensionless)
formula: ViscosityFormula | str — viscosity formula
set_wall_boundary(tag, slip=False)

Set a wall boundary condition on a boundary tag.

Parameters

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

Open boundary condition: impose discharge/currents (u) and sea surface elevation (eta) either eta or u can be omitted but not both.

Parameters

tag: str — mesh tag of the part of the boundary on which this boundary condition is applied.
eta: slim.Data | None — sea surface elevation data (m)
u: slim.Data | None — velocity data (m/s) or transport (m²/s)
uv_is_transport: bool — set whether u are velocities (False) or transport (True)
enable_wetting_drying(Hthin)

Enable wetting and drying with explicit flux limiter + solution limiter to guaratee a positive H

Parameters

Hthin: float — Minimum water depth
new_linear_system(options='')

Create a new linear system with the shape and the matrix structure of the shallow water problem.

Parameters

options: str — options for the linear solver (see petsc documentation)

Returns

new_sys: slim.LinearSolver — No description.
compute_cfl(eta=None)

Compute the cfl number of the shallow water problem.

Parameters

eta: NDArray[np.float64] | None — The water elevation above the reference level

Returns

cfl: float — the cfl number
class slim4.slim2d.Tracer

Bases: slim.Equation.

data of n 2d tracer problems

Constructor

__init__(mesh, hydro, h, g, nf=1, limiter_type='none')

create a 2d tracer problem

Parameters

mesh: Mesh — mesh
hydro: ShallowWater — shallow water equation (may be NULL)
h: slim.Data — depth bellow reference level
g: float — gravity
nf: int — number of tracer fields
limiter_type: slim.LimiterType | str — type of limiter to apply on tracers subtimestep

Methods

set_diffusion(kappa)

set the diffusion coefficient

Parameters

kappa: slim.Data — diffusion coefficient
set_source(source)

set the source term

Parameters

source: slim.Data — source term
set_wall_boundary(tag, slip=False)

set a boundary condition: zero flux condition at the boundary

Parameters

tag: str — tag of the part of the boundary on which this boundary condition is applied.
slip: bool — if True, slip (frictionless) wall. (default False)
set_open_boundary(tag, tracer, u=None, eta=None, uv_is_transport=False, diffusion=True)

set a boundary condition: one can impose the external concentration

Parameters

tag: str — tag of the part of the boundary on which this boundary condition is applied.
tracer: slim.Data — Tracer concentration at the boundary (in c)
u: slim.Data | None — velocity (or transport) vector which will be applied at the boundary (in m/s, slimdata format). It has to be the same data as for the Shallowwater equation.
eta: slim.Data | None — sea surface elevation which will be applied at the boundary (in m, slimdata format). It has to be the same data as for the Shallowwater equation.
uv_is_transport: bool — set whether u are velocities (False) or transport (True)
diffusion: bool — compute (default) or ignore the diffusion term (if any) through the boundary
new_linear_system(options='')

Create a new linear system with the shape and the matrix structure of the shallow water problem.

Parameters

options: str — options for the linear solver (see petsc documentation)

Returns

new_sys: slim.LinearSolver — a new linear system.

Functions

slim4.slim2d.partition_mesh(filename, pfile='')

Partition a 2d mesh and write a new mesh file for each partition. (Rank 0 load the whole mesh and partition it into mpi_size partitions).

Parameters

filename: 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
slim4.slim2d.compute_grad(mesh, field)

Compute the field gradient

Parameters

mesh: Mesh — The mesh
field: NDArray[np.float64] — The field

Returns

grad: NDArray[np.float64] — the field horizontal gradient
slim4.slim2d.compute_curl(mesh, field)

Compute the field curl

Parameters

mesh: Mesh — The mesh
field: NDArray[np.float64] — The field

Returns

curl: NDArray[np.float64] — the field curl