slim4.slim

SlimCore

Enums

class slim4.slim.OutputPrecision(IntEnum)

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

Values

native: -1 — Use the presicion of the simulation
half: 2 — 16-bit Half-precision floats. May not be suitable for further processing.
single: 4 — 32-bit Single-precision floats
double: 8 — 64-bit Double-precision floats
class slim4.slim.DType(IntEnum)

The data type of the dataset

Values

double: 0 — Double precision floating point
float: 1 — Single precision floating point
float16: 2 — Half precision floating point
int: 3 — 32-bit Integer
int64: 4 — 64-bit Integer
unknown: 5 — Unknown data type
class slim4.slim.Endianness(IntEnum)

The endianness of the dataset

Values

Little: 0 — endian
Big: 1 — endian
Not: 2 — applicable
Unknown: 3 — endianness
class slim4.slim.DataType(IntEnum)

Spatial discretization type

Values

UNIFORM: 0 — spatially constant
DG: 1 — one value for each DG node
CG: 2 — one value for each CG node
CG_INTERP: 3 — interpolated from a sparse matrix with one line per cg node
DG_INTERP: 4 — interpolated from a sparse matrix with one line per dg node
class slim4.slim.MpiReduceOp(IntEnum)

determine the operation to perform during an MPI reduce.

Values

sum: 0 — Sum
min: 1 — Minimum
max: 2 — Maximum
prod: 3 — Product
class slim4.slim.LimiterType(IntEnum)

determine if a limiter is applied

Values

none: 0 — no limiter
zero_one: 1 — limiter to [0,1]
positive: 2 — limiter to >= 0
neighbour: 3 — limiter to [(min(n), max(n))], n being the mean value on the neighbouring elements
past_bound: 4 — limiter between the min and max of neighbouring elements at the previous time step

Classes

class slim4.slim.Mesh

Base class of Slim1dMesh, slim4::d2::Mesh, slim4::slim3d::Mesh

Properties

element_nodes: NDArray[np.int32] — Pointer to the mesh
dimension: int — Dimension of the mesh
n_elements: int — Number of elements
n_cg_nodes: int — The number of nodes (periodicity is ignored, periodic nodes are duplicated).
n_node_by_element: int — Number of nodes by element
n_boundary: int — Number of boundary

Methods

boundary_elements_by_tag(tag)

Warning : Low-level feature subject to change.

Parameters

tag: int — Tag id.

Returns

bndelems: NDArray[np.int32] — Array of elements indices for the given tag.
class slim4.slim.Ameta

Metadata of an abin datafile

class slim4.slim.Abin

Read and write abin files from/to ava::HostArray

Methods

static openread_idx(path, chunk)

Open and map the memory of an abin file to a slim4::slim::IdxArray

Parameters

path: str — The path to the abin file
chunk: int — Index in the first dimension to map (default = -1: map the whole file)

Returns

array: NDArray[np.int32] — The array mapped to the file
static openread_scalar(path, chunk)

Open and map the memory of an abin file to a slim4::slim::ScalarArray

Parameters

path: str — The path to the abin file
chunk: int — Index in the first dimension to map (default = -1: map the whole file)

Returns

array: NDArray[np.float64] — The array mapped to the file
static openread_double(path, chunk)

Open and map the memory of an abin file to a slim4::slim::DoubleArray

Parameters

path: str — The path to the abin file
chunk: int — Index in the first dimension to map (default = -1: map the whole file)

Returns

array: NDArray[np.float64] — The array mapped to the file
static openread_float(path, chunk)

Open and map the memory of an abin file to a FloatArray

Parameters

path: str — The path to the abin file
chunk: int — Index in the first dimension to map (default = -1: map the whole file)

Returns

array: NDArray[np.float32] — The array mapped to the file
class slim4.slim.ScalarArrayDeviceMPI

Bases: ScalarArrayDevice.

Scalar array on the device memory (GPU) with MPI communication buffers

Methods

static create_empty(shape)

create a newly allocated (and uninitialized) ava device array of scalars

Parameters

shape: List[int] — The shape of the array

Returns

new_device_array: ScalarArrayDeviceMPI — The newly created device array
static create_zeros(shape)

create a zero-initialized ava device array of scalars

Parameters

shape: List[int] — The shape of the array

Returns

new_device_array: ScalarArrayDeviceMPI — The newly created device array
static create_from_host(host_array)

create a newly allocated ava device array of scalars and set it from a host array

Parameters

host_array: NDArray[np.float64] — The host array to copy the data from.

Returns

new_device_array: ScalarArrayDeviceMPI — The newly created device array
get_sub(id)

DEPRECATED: use get_sub_view instead get an existing subarray

Parameters

id: int — The id of the subarray

Returns

subarray: ScalarArrayDeviceMPI — The subarray
get_sub_view(start, shape)

return a new sub array not registered in the parent array

Parameters

start: int — Start of the subarray (in number of entries)
shape: List[int] — The shape of the subarray

Returns

subarray: ScalarArrayDeviceMPI — The subarray
class slim4.slim.Data

Store necessary data for the simulation bathymetry, coriolis, wind, tides,… Two possible format CG (field x nb nodes) or DG (field x 3 x nb elements)

Properties

mesh: Mesh — Mesh of the data
n_fields: int — Number of fields

Methods

eval_mesh_gpu(t=-31536e6, out=None, tag=-1)

Evaluate the data at each (DG) node of the mesh on the GPU

Parameters

t: float — the time at which the data is evaluated
out: ScalarArrayDevice | None — Optional output array to store the result
tag: int — Warning : Low-level feature. Index of the tag in which to eval the data (-1 = whole domain)

Returns

_out: ScalarArrayDevice — the array with the data. If out is not null, _out == out
eval_mesh(t=-31536e6)

Evaluate the data at each (DG) node of the mesh

Parameters

t: float — the time at which the data is evaluated

Returns

new_v: NDArray[np.float64] — a new array with the data
set_name(name)

Set the name of the data

Parameters

name: str — the name of the data
set_ramp(t0, duration)

Set a linear ramp for the slim4::slim::Data

Parameters

t0: float — The starting time of the ramp (Unix timestamp)
duration: float — The duration of the ramp (s)
class slim4.slim.DataStatic

Bases: Data.

slim4::slim::Data from array of values

Constructor

__init__(mesh, type='CG', nfields=1, value=None)

create a new slim4::slim::DataStatic

Parameters

mesh: Mesh — The mesh
type: DataType | str — The type of the data
nfields: int — The number of fields
value: NDArray[np.float64] | None — The value of the data

Methods

static create_constant(mesh, value)

create a new uniform slim4::slim::DataStatic

Parameters

mesh: Mesh — The mesh
value: NDArray[np.float64] — The value of the data

Returns

self: DataStatic — The new slim4::slim::DataStatic
set(v)

Set the value

Parameters

v: NDArray[np.float64] — The value
class slim4.slim.DataFile

Bases: Data.

slim4::slim::Data loaded from a file

Properties

time: NDArray[np.float64] | None — The time of the data

Constructor

__init__(filename, varname, mesh)

create a new slim4::slim::DataFile (this object will read data from the files and interpolate them when needed)

Parameters

filename: str — The name of the file
varname: str — The name of the variable
mesh: Mesh — The mesh

Methods

static write(filename, data, datatype, time=None, cols=None, csr_start=None, weights=None)

Write fields to a file, the data to a file

Parameters

filename: str — The base path where to write the data (the partition rank will be appended).
data: List[Tuple[str, NDArray[np.float64]]] — A vector of pairs of name and data, the data dimension order should be [[time], N, [Node], dim]] the [Node] dimension is only present for dg data, the time dimension is only present if the data is temporal the dim dimension should always be there even if dim=1, the N dimension is the number of elements (1 for uniform, number of elements for dg, number of nodes for cg, number of data points for interpolated value)
datatype: DataType | str — The type of the data
time: NDArray[np.float64] | None — The time of the data
cols: NDArray[np.int32] | None — The columns of the data CSR columns for DG_INTERP and CG_INTERP
csr_start: NDArray[np.int32] | None — The start of the CSR matrix
weights: NDArray[np.float64] | None — The weights of the CSR matrix
class slim4.slim.DataFileWriter

A class to incrementally write temporal data to a file.

Constructor

__init__(filename, datatype, cols=None, csr_start=None, weights=None)

Initialize a data file structure (actual data will be written later by write_append)

Parameters

filename: str — The base path where to write the data (the partition rank will be appended).
datatype: DataType | str — The type of the data
cols: NDArray[np.int32] | None — The columns of the data CSR columns for DG_INTERP and CG_INTERP
csr_start: NDArray[np.int32] | None — The start of the CSR matrix
weights: NDArray[np.float64] | None — The weights of the CSR matrix

Methods

append(data, time)

Append fields to a data file previously initialized with write_init

Parameters

data: List[Tuple[str, NDArray[np.float64]]] — A vector of pairs of name and data for one time step, the data dimension order should be [N, [Node], dim]] the [Node] dimension is only present for dg data, the time dimension is only present if the data is temporal the dim dimension should always be there even if dim=1, the N dimension is the number of elements (1 for uniform, number of elements for dg, number of nodes for cg, number of data points for interpolated value)
time: float — The time of the appended data
close()

Close the file and write the time and metadata

class slim4.slim.DataOutput

Bases: Data.

slim4::slim::Data loaded from an output of a simulation

Properties

time: NDArray[np.float64] — time of the data
shape: Tuple[int, …] — apparent shape

Constructor

__init__(filename, varname, mesh)

create a new slim4::slim::DataOutput

Parameters

filename: str — The name of the file
varname: str — The name of the variable
mesh: Mesh — The mesh

Methods

__getitem__(idx)

Access the data as if it was a big array of DG values with time as a first dim. Creates a copy.

Parameters

idx: List[Tuple[int, int, int, int, NDArray[np.int32]]] — The name of the file

Returns

data: NDArray[np.float64] — The accessed data
class slim4.slim.DataWrap

Bases: Data.

Wrap a GPU array as a slim4::slim::Data

Properties

array: ScalarArrayDevice — The wraapped array

Constructor

__init__(array, mesh)

create a new slim4::slim::DataWrap

Parameters

array: ScalarArrayDevice — The GPU array to wrap
mesh: Mesh — The mesh
class slim4.slim.LBVH

Constructor

__init__(xy=None)

create a new LBVH

Parameters

xy: ScalarArrayDevice | None — The (x,y) coordinates of the Triangulation. Shape = (2, 3, n_elements_2d)

Methods

find_nearest_points(xy)

Find the nearest points on the triangles to some query points.

Parameters

xy: ScalarArrayDevice — The x and y coordinates of the points of shape (2, n).

Returns

new_eid: IdxArrayDevice — return a new array with the id of the triangle containing each point.
new_uv: ScalarArrayDevice — return a new array with the parametric coordinates of the points in the triangles.
find_points(xy)

Find the triangles containing some points.

Parameters

xy: ScalarArrayDevice — The x and y coordinates of the points of shape (2, n).

Returns

new_eid: IdxArrayDevice — return a new array with the id of the triangle containing each point.
new_uv: ScalarArrayDevice — return a new array with the parametric coordinates of the points in the triangles.
class slim4.slim.MPI

slim4::slim::MPI wrapper to MPI if present.

Properties

rank: int — rank of the current process
size: int — size of the communicator
node_rank: int — rank inside of the current node
node_size: int — size of the current node

Methods

static get_default()

Get the default mpi communicator

Returns

mpi: MPI — return the default mpi communicator
barrier()

synchronize all mpi ranks

sum_scalar(local)

sum a scalar across all ranks

Parameters

local: float — the local value

Returns

sum: float — the sum of all local values
min_scalar(local)

find the minimum scalar across all ranks

Parameters

local: float — the local values

Returns

min: float — the minimum of all local values
max_scalar(local)

find the maximum scalar across all ranks

Parameters

local: float — the local values

Returns

max: float — the maximum of all local values
sum_idx(local)

sum an index across all ranks

Parameters

local: int — the local value

Returns

sum: int — the sum of all local values
max_idx(local)

find the maximum index across all ranks

Parameters

local: int — the local values

Returns

max: int — the maximum of all local values
min_idx(local)

find the minimum index across all ranks

Parameters

local: int — the local values

Returns

min: int — the minimum of all local values
exscan_sum_idx(local)

compute the exclusive scan of the sum of all local values on rank with a smaller id than myself

Parameters

local: int — the local value

Returns

prec_value: int — the sum of all local values on rank with a smaller id than myself
quantile_scalar(sendbuf, quantile)

compute the quantile of a scalar array

Parameters

sendbuf: NDArray[np.float64] — the local array
quantile: float — the quantile to compute

Returns

out: float — the quantile
allgatherv_scalar(sendbuf)

concatenate along the first dimension all local SlimScalar arrays into a single new global SlimScalar arrays

Parameters

sendbuf: NDArray[np.float64] — the local array

Returns

recvbuf: NDArray[np.float64] — return the new global SlimScalar array
class slim4.slim.Equation

an equation that can be called by the time integrators

Methods

mass_mult(t, x)

multiply a global vector by the mass matrix in place

Parameters

t: float — time
x: ScalarArrayDevice — the vector
inv_mass_mult(t, x)

multiply a global vector by the inverse mass matrix in place

Parameters

t: float — time
x: ScalarArrayDevice — the vector
fill_vector(solution, t, dt, rhs)

fill the right hand side vector

Parameters

solution: ScalarArrayDevice — the solution vector
t: float — the time
dt: float — the time step
rhs: ScalarArrayDeviceMPI — the right hand side vector to be filled
rkls_iter(solution, t, dt, solbase, solnext, final)

perform one explicit sub-iteration

Parameters

solution: ScalarArrayDevice — the solution vector
t: float — the time
dt: float — the time step
solbase: ScalarArrayDevice — the solution vector at the beginning of the total time step
solnext: ScalarArrayDeviceMPI — the solution vector at the end of the sub time step
final: bool — wether it is the last sub-timestep
implicit_iter(solnext, sol0, t, dt, alpha, sys, R)

perform one implicit sub-iteration

Parameters

solnext: ScalarArrayDeviceMPI — the current solution vector (will be overwritten)
sol0: ScalarArrayDevice — the solution vector at the beginning of the sub time step
t: float — the current time
dt: float — the time step
alpha: float — 1/dt for an euler implicit scheme
sys: LinearSolver — the linear solver and matrix to use
R: ScalarArrayDevice — see documentation of the function

Returns

normp: float — the norm of the residual
new_vector()

Create a zero vector on the device (e.g. GPU) with the shape of a solution vector.

Returns

new_v: ScalarArrayDeviceMPI — zero vector on the devive (e.g. GPU).
class slim4.slim.Csr

compressed sparse row structure of a sparse matrix

class slim4.slim.LinearSolver

Wrapper of a matrix linear solver package (PETSc or CUDSS).

Constructor

__init__(mpi, mat, csr, options)

Create a new linear solver.

Parameters

mpi: MPI — The MPI communicator to use
mat: ScalarArrayDevice — The slim matrix this matrix is based on
csr: Csr — The CSR structure of the matrix
options: str — The options to pass to the PETSc linear solver (e.g. ‘-pc_type ilu -ksp_monitor’)

Methods

solve(b, x, same_matrix)

Solve the linear system Ax=b.

Parameters

b: ScalarArrayDevice — The right hand side vector [element,node,field]
x: ScalarArrayDevice — the pre-allocated solution vector [element,node,field]
same_matrix: bool — If true, the matrix is assumed to be identical to the one used in the previous call to solve

Returns

xnorm: float — the norm of the solution vector
class slim4.slim.Reaction

A callback to be call after each time step intended to be used as as an ode on each node

Methods

react(t, dt)

Evolves the reactives field between t and t+dt.

Parameters

t: float — The time.
dt: float — The time step.
class slim4.slim.ReactionExponentialDecay

Bases: Reaction.

exponential decay dc/dt = -mu*c

Constructor

__init__(solution, field, mu)

Create a new exponential decay reaction.

Parameters

solution: ScalarArrayDevice — the tracer solution device array
field: int — the index of the decaying field in the solution array
mu: float — The reaction coefficient
class slim4.slim.ReactionDemo

Bases: Reaction.

2 tracer demo reaction module da/dt = - f_ab a + source db/dt = f_ab a - f_b b dc/dt = f_b b where source is a slim4::slim::Data, f_ab and f_b are constant parameters, and c is a device array.

Constructor

__init__(solution, field_a, field_b, carray, source, f_ab, f_b)

Create a new demo reaction

Parameters

solution: ScalarArrayDevice — the tracer solution device array
field_a: int — the index of the first field in the solution array
field_b: int — the index of the second field in the solution array
carray: ScalarArrayDeviceMPI — the reaction coefficient
source: Data — the source data
f_ab: float — the reaction coefficient
f_b: float — the reaction coefficient
class slim4.slim.ReactionNPZD

Bases: Reaction.

4 tracers demo reaction module dn/dt = l_mineral * d + l_excretion * z - max_uptake * par/(par+ks_PAR) * n / (n + ks_n) * p dp/dt = max_uptake * par/(par+ks_PAR) * n / (n + ks_n) * p - max_graze * p / (p + ks_graze) * z - l_mortality_p * p dz/dt = (1 - p_faeces) * max_graze * p / (p + ks_graze) * z - l_excretion * z - l_mortality_z * z * z dd/dt = l_mortality_z * z * z + l_mortality_p * p - l_mineral * d + p_faeces * max_graze * p / (p + ks_graze) * z where l_mineral, l_excretion, max_uptake, ks_PAR, ks_n, l_mortality_p, l_mortality_z, max_graze, h_min, kd, ks_graze and p_faeces are constant parameters, and rad and h are slim4::slim::Data that help calculate par.

Constructor

__init__(solution_tr, solution_h, field_n, field_p, field_z, field_d, rad, h, l_mineral, l_excretion, max_uptake, h_min, kd, ks_PAR, ks_n, max_graze, ks_graze, l_mortality_p, p_faeces, l_mortality_z)

Create a new NPZD reaction

Parameters

solution_tr: ScalarArrayDevice — the tracer solution device array
solution_h: ScalarArrayDevice — the hydrodynamic solution device array
field_n: int — the index of the first field in the solution array - nitrogen
field_p: int — the index of the second field in the solution array - phytoplankton
field_z: int — the index of the third field in the solution array - zooplankton
field_d: int — the index of the fourth field in the solution array - detritus
rad: Data — the radiation data
h: Data — the bathymetry data
l_mineral: float — the linear mineralization rate
l_excretion: float — the linear excretion rate
max_uptake: float — the maximum uptake rate
h_min: float — the H limit
kd: float — the light extinction coefficient
ks_PAR: float — the half-saturation constant for PAR
ks_n: float — the half-saturation constant for nitrogen uptake
max_graze: float — the maximum grazing rate
ks_graze: float — the half-saturation constant for grazing
l_mortality_p: float — the linear mortality rate of phytoplankton
p_faeces: float — the proportion of phytoplankton going to faeces
l_mortality_z: float — the linear mortality rate of zooplankton
class slim4.slim.LinearSolverPETSc

Bases: LinearSolver.

Wrapper of a PETSc matrix (Mat) and a PETSc linear solver (KSP).

Constructor

__init__(mpi, mat, csr, options)

Create a new PETSc linear solver.

Parameters

mpi: MPI — The MPI communicator to use
mat: ScalarArrayDevice — The slim matrix this matrix is based on
csr: Csr — The CSR structure of the matrix
options: str — The options to pass to the PETSc linear solver (e.g. ‘-pc_type ilu -ksp_monitor’)

Methods

solve(b, x, same_matrix)

Solve the linear system Ax=b.

Parameters

b: ScalarArrayDevice — The right hand side vector [element,node,field]
x: ScalarArrayDevice — the pre-allocated solution vector [element,node,field]
same_matrix: bool — If true, the matrix is assumed to be identical to the one used in the previous call to solve

Returns

xnorm: float — the norm of the solution vector
class slim4.slim.ScalarArrayDevice

Scalar array on the device memory (GPU)

Properties

shape: List[int] — the shape of the array
size: int — the total number of elements
cap: int — the total capacity
name: str — the name of the array

Methods

static create_empty(shape)

create a newly allocated (and uninitialized) ava device array of scalars

Parameters

shape: List[int] — The shape of the array

Returns

new_device_array: ScalarArrayDevice — The newly created device array
static create_zeros(shape)

create a zero-initialized ava device array of scalars

Parameters

shape: List[int] — The shape of the array

Returns

new_device_array: ScalarArrayDevice — The newly created device array
static create_from_host(host_array)

create a newly allocated ava device array of scalars and set it from a host array

Parameters

host_array: NDArray[np.float64] — The host array to copy the data from.

Returns

new_device_array: ScalarArrayDevice — The newly created device array
get()

get a ava::HostArray on the CPU from a DeviceArray on the GPU

Returns

new_host_array: NDArray[np.float64] — The newly created host array. The data is copied from the device to the host
set_from_host(host_array)

set a DeviceArray on the GPU from a HostArray on the CPU

Parameters

host_array: NDArray[np.float64] — The host array. The data is copied from the host to the device
set(host_array)

set a DeviceArray on the GPU from a ava::HostArray on the CPU alias for set_from_host (deprecated, for backward compatibility)

Parameters

host_array: NDArray[np.float64] — The host array. The data is copied from the host to the device
set_from_device(device_array)

set a DeviceArray on the GPU from another DeviceArray on the GPU

Parameters

device_array: ScalarArrayDevice — The device array. The data is copied from the device to the device
duplicate()

create a copy of a DeviceArray

Returns

new_device_array: ScalarArrayDevice — The newly created device array
resize(shape)

Resize an existing ava device array, allowing to reuse previous memory. If the total size of new_shape is greater or equal to the current, the underlying data is unchanged. If it is smaller, the data is truncated.

Parameters

shape: List[int] — The new shape of the array
resize_no_copy(shape)

Resize an existing ava device array, allowing to reuse previous memory. The underlying data is not maintained.

Parameters

shape: List[int] — The new shape of the array
set_name(name)

set the name of a DeviceArray

Parameters

name: str — The name of the array
fill(value)

Fill a DeviceArray with a value, akin to std::fill

Parameters

value: float — The scalar value to set
memset(value=0)

set all bytes of a DeviceArray to value

Parameters

value: int — The byte with which to fill the DeviceArray
transpose()

transpose an array in a new array (only for 3-dimensional arrays)

Returns

dest: ScalarArrayDevice — Transposed array
has_nan()

Returns

hasnan: bool — True if the array contains any NaN
class slim4.slim.IdxArrayDevice

Scalar array on the device memory (GPU)

Properties

shape: List[int] — the shape of the array
size: int — the total number of elements
cap: int — the total capacity
name: str — the name of the array

Methods

static create_empty(shape)

create a newly allocated (and uninitialized) ava device array of scalars

Parameters

shape: List[int] — The shape of the array

Returns

new_device_array: IdxArrayDevice — The newly created device array
static create_zeros(shape)

create a zero-initialized ava device array of scalars

Parameters

shape: List[int] — The shape of the array

Returns

new_device_array: IdxArrayDevice — The newly created device array
static create_from_host(host_array)

create a newly allocated ava device array of scalars and set it from a host array

Parameters

host_array: NDArray[np.int32] — The host array to copy the data from.

Returns

new_device_array: IdxArrayDevice — The newly created device array
get()

get a ava::HostArray on the CPU from a DeviceArray on the GPU

Returns

new_host_array: NDArray[np.int32] — The newly created host array. The data is copied from the device to the host
set_from_host(host_array)

set a DeviceArray on the GPU from a HostArray on the CPU

Parameters

host_array: NDArray[np.int32] — The host array. The data is copied from the host to the device
set(host_array)

set a DeviceArray on the GPU from a ava::HostArray on the CPU alias for set_from_host (deprecated, for backward compatibility)

Parameters

host_array: NDArray[np.int32] — The host array. The data is copied from the host to the device
set_from_device(device_array)

set a DeviceArray on the GPU from another DeviceArray on the GPU

Parameters

device_array: IdxArrayDevice — The device array. The data is copied from the device to the device
duplicate()

create a copy of a DeviceArray

Returns

new_device_array: IdxArrayDevice — The newly created device array
resize(shape)

Resize an existing ava device array, allowing to reuse previous memory. If the total size of new_shape is greater or equal to the current, the underlying data is unchanged. If it is smaller, the data is truncated.

Parameters

shape: List[int] — The new shape of the array
resize_no_copy(shape)

Resize an existing ava device array, allowing to reuse previous memory. The underlying data is not maintained.

Parameters

shape: List[int] — The new shape of the array
set_name(name)

set the name of a DeviceArray

Parameters

name: str — The name of the array
fill(value)

Fill a DeviceArray with a value, akin to std::fill

Parameters

value: int — The scalar value to set
memset(value=0)

set all bytes of a DeviceArray to value

Parameters

value: int — The byte with which to fill the DeviceArray
transpose()

transpose an array in a new array (only for 3-dimensional arrays)

Returns

dest: IdxArrayDevice — Transposed array
has_nan()

Returns

hasnan: bool — True if the array contains any NaN

Functions

slim4.slim.allreduce_dev(mpi, inout_dev, op, check_size=True)

Performs an inplace allreduce on a device array.

Parameters

mpi: MPI — The MPI communicator
inout_dev: ScalarArrayDevice — the input and output device array. Must have the same size on all ranks.
op: MpiReduceOp | str — the reduction operation to perform
check_size: bool — if true, check that the size of the input array is the same on all ranks. Set it to false if you are sure that the size is the same on all ranks to save some time.
slim4.slim.get_compile_params()

Get the compile parameters of the library at runtime.

Returns

dtype: int — The data type : 0 for float and 1 for double
commtype: str — The communication type : one of ‘none’, ‘mpi’, ‘gpu_aware_mpi’, ‘nccl’ or ‘rccl’
platform: str — The platform : one of ‘cpu’, ‘cuda’, ‘hip’ or unknown
implicit: bool — Implicit support : True for yes, False for no
slim4.slim.select_gpu(device)

Select the GPU device to use.

Parameters

device: int — The requested device

Returns

id: int — the id of the selected device (may be different from the requested device if not enough devices)
slim4.slim.synchronize()

Wait for all GPU calls to finish.

slim4.slim.mkpath(file_path)

create all the parent directories of a file path

Parameters

file_path: str — The file path
slim4.slim.fill_mask(npass, a)

Extrapolate values of array to fill masked values.

Parameters

npass: int — The number of passes to fill masked values
a: NDArray[np.float64] — The array of values to be filled [nx,ny]

Returns

filled: NDArray[np.float64] — The filled array
slim4.slim.fill_mask_nd(npass, a, weight=None)

Extrapolate values of array to fill masked values. The function computes a weigthed average of the neighbours.

Parameters

npass: int — The number of passes to fill masked values
a: NDArray[np.float64] — The array of values to be filled of shape (ntime, …)
weight: NDArray[np.float64] | None — The weight of each dimension (size ndim). If None, the weight is 1 for each dimension

Returns

filled: NDArray[np.float64] — The filled array
slim4.slim.interpolation_weights_second_dimension_structured_grid(coord_data, coord_mesh)

Compute the interpolation weights for the specific case of a grid structured in the second dimension but not in the first dimension. The points are assumed to be sorted 1) along the second dimension and 2) along the first dimension. This is typically the case for era5 data.

Parameters

coord_data: NDArray[np.float64] — The coordinates of the data points (n by 2)
coord_mesh: NDArray[np.float64] — The coordinates of the mesh points (m by 2)

Returns

weights: NDArray[np.int32] — The interpolation weights (4 by mesh nodes)
indices: NDArray[np.float64] — The indices of the points (4 by mesh nodes)
slim4.slim.split_segments(points, segments)

Computes the set segments obtained by removing eventual NANs in the coordinates.

Parameters

points: NDArray[np.float64] — The points (2, npoints).
segments: NDArray[np.int32] — The range of each segment in points (nsegments, 2)

Returns

separators: NDArray[np.int32] — The split segments (n_split_segments, 2). The new i-th segment is points[:, split_segments[i,0]:split_segments[i,1]]
slim4.slim.si_format(n, precision=2, sep='', binary=False)

Format a number in a human readable format with SI prefixes.

Parameters

n: float — The number to format
precision: int — The number of significant digits to display
sep: str — The separator between the number and the prefix
binary: bool — Whether to use binary prefixes (powers of 1024) or decimal

Returns

The: str — formatted string
slim4.slim.iterate_runge_kutta_butcher(equation, solution, tstart, dt, a, b, c, nstep, mean_sol=None, reactions=[])

perform a Runge-Kutta time integration scheme with the Butcher tableau

Parameters

equation: Equation — the equation to integrate
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
a: NDArray[np.float64] — the coefficients of the Butcher tableau
b: NDArray[np.float64] — the coefficients of the Butcher tableau
c: NDArray[np.float64] — the coefficients of the Butcher tableau
nstep: int — the number of time steps
mean_sol: ScalarArrayDevice | None — the mean solution vector
reactions: List[Reaction] — the reactions to apply after each time step

Returns

t: float — the final time
slim4.slim.iterate_runge_kutta(equation, solution, tstart, dt, scheme, nstep, mean_sol=None, reactions=[])

perform a Runge-Kutta time integration scheme, the scheme is identified by an integer

Parameters

equation: Equation — the equation to integrate
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
scheme: int — the runge-kutta scheme (1 forward Euler, 2 explicit midpoint, 3 Ralston third-order, 4 classical RK4, 30 or -3: another third-order scheme)
nstep: int — the number of time steps
mean_sol: ScalarArrayDevice | None — the mean solution vector
reactions: List[Reaction] — the reactions to apply after each time step

Returns

t: float — the final time
slim4.slim.iterate_low_storage_runge_kutta_array(equation, solution, tstart, dt, coeffs, nstep, mean_sol=None, reactions=[])

perform a low-storage Runge-Kutta time integration scheme

Parameters

equation: Equation — the equation to integrate
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
coeffs: NDArray[np.float64] — the coefficients of the low-storage Runge-Kutta scheme
nstep: int — the number of time steps
mean_sol: ScalarArrayDevice | None — the mean solution vector
reactions: List[Reaction] — the reactions to apply after each time step

Returns

t: float — the final time
slim4.slim.iterate_low_storage_runge_kutta(equation, solution, tstart, dt, scheme, nstep, mean_sol=None, reactions=[])

perform a low-storage Runge-Kutta time integration scheme

Parameters

equation: Equation — the equation to integrate
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
scheme: float — the order of the low-storage Runge-Kutta scheme (integers : classical Runge-Kutta schemes, 2/13 : a specific third-order scheme)
nstep: int — the number of time steps
mean_sol: ScalarArrayDevice | None — the mean solution vector
reactions: List[Reaction] — the reactions to apply after each time step

Returns

t: float — the final time
slim4.slim.iterate_crank_nicolson(equation, sys, solution, tstart, dt, maxit=10, rtol=1e-5, atol=1e-5, mean_sol=None)

Parameters

equation: Equation — the equation to integrate
sys: LinearSolver — the linear solver to use
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
maxit: int — the maximum number of iterations of the newton solver
rtol: float — the relative tolerance of the newton solver
atol: float — the absolute tolerance of the newton solver
mean_sol: ScalarArrayDevice | None — the mean solution vector

Returns

t: float — the final time
slim4.slim.iterate_dirk_butcher(equation, sys, solution, tstart, dt, A, B, C, maxit, rtol, atol, mean_sol=None)

Parameters

equation: Equation — the equation to integrate
sys: LinearSolver — the linear solver to use
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
A: List[List[float]] — the Butcher table API
B: List[float] — the Butcher table API
C: List[float] — the Butcher table API
maxit: int — the maximum number of iterations of the newton solver
rtol: float — the relative tolerance of the newton solver
atol: float — the absolute tolerance of the newton solver
mean_sol: ScalarArrayDevice | None — the mean solution vector

Returns

t: float — the final time
slim4.slim.iterate_midpoint(equation, sys, solution, tstart, dt, maxit=10, rtol=1e-5, atol=1e-5, mean_sol=None)

Parameters

equation: Equation — the equation to integrate
sys: LinearSolver — the linear solver to use
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
maxit: int — the maximum number of iterations of the newton solver
rtol: float — the relative tolerance of the newton solver
atol: float — the absolute tolerance of the newton solver
mean_sol: ScalarArrayDevice | None — the mean solution vector

Returns

t: float — the final time
slim4.slim.iterate_dirk2(equation, sys, solution, tstart, dt, maxit=10, rtol=1e-5, atol=1e-5, mean_sol=None)

Parameters

equation: Equation — the equation to integrate
sys: LinearSolver — the linear solver to use
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
maxit: int — the maximum number of iterations of the newton solver
rtol: float — the relative tolerance of the newton solver
atol: float — the absolute tolerance of the newton solver
mean_sol: ScalarArrayDevice | None — the mean solution vector

Returns

t: float — the final time
slim4.slim.iterate_dirk3(equation, sys, solution, tstart, dt, maxit=10, rtol=1e-5, atol=1e-5, mean_sol=None)

Parameters

equation: Equation — the equation to integrate
sys: LinearSolver — the linear solver to use
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
maxit: int — the maximum number of iterations of the newton solver
rtol: float — the relative tolerance of the newton solver
atol: float — the absolute tolerance of the newton solver
mean_sol: ScalarArrayDevice | None — the mean solution vector

Returns

t: float — the final time
slim4.slim.iterate_implicit_euler(equation, sys, solution, tstart, dt, maxit=10, rtol=1e-5, atol=1e-5, mean_sol=None)

Parameters

equation: Equation — the equation to integrate
sys: LinearSolver — the linear solver to use
solution: ScalarArrayDeviceMPI — the solution vector
tstart: float — the initial time
dt: float — the time step
maxit: int — the maximum number of iterations of the newton solver
rtol: float — the relative tolerance of the newton solver
atol: float — the absolute tolerance of the newton solver
mean_sol: ScalarArrayDevice | None — the mean solution vector

Returns

t: float — the final time
slim4.slim.proj_transform(from_proj, to_proj, points)

Transforms an array of points from one projection to another.

Parameters

from_proj: str — The source projection, in any format accepted by PROJ (ex: ‘EPSG:4326’, ‘4326’, ‘lonlat’, Proj4, WKT, etc).
to_proj: str — The target projection, in any format accepted by PROJ (ex: ‘EPSG:4326’, ‘4326’, ‘lonlat’, Proj4, WKT, etc).
points: NDArray[np.float64] — A (2, …) or (3, …) array of points to transform. The first dimension is the coordinate dimension (2 for 2D points, 3 for 3D points). The other dimensions are free and will be preserved in the output.

Returns

A: NDArray[np.float64] — (3, …) array of transformed points.
slim4.slim.geodesic_distance(points, proj='lonlat')

Computes the cumulative geodesic distance of a sequence of points on the WGS84 ellipsoid

Parameters

points: NDArray[np.float64] — Sequence of points. shape (2, n)
proj: str — The projection, in any format accepted by PROJ (ex: ‘EPSG:4326’, ‘4326’, ‘lonlat’, Proj4, WKT, etc).

Returns

distances: NDArray[np.float64] — Cumulative geodesic distance along the points, in meters. shape (n,). The first value is always 0.