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 simulationhalf:2— 16-bit Half-precision floats. May not be suitable for further processing.single:4— 32-bit Single-precision floatsdouble:8— 64-bit Double-precision floats
- class slim4.slim.DType(IntEnum)
The data type of the dataset
Values
double:0— Double precision floating pointfloat:1— Single precision floating pointfloat16:2— Half precision floating pointint:3— 32-bit Integerint64:4— 64-bit Integerunknown:5— Unknown data type
- class slim4.slim.Endianness(IntEnum)
The endianness of the dataset
Values
Little:0— endianBig:1— endianNot:2— applicableUnknown:3— endianness
- class slim4.slim.DataType(IntEnum)
Spatial discretization type
Values
UNIFORM:0— spatially constantDG:1— one value for each DG nodeCG:2— one value for each CG nodeCG_INTERP:3— interpolated from a sparse matrix with one line per cg nodeDG_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— Summin:1— Minimummax:2— Maximumprod:3— Product
- class slim4.slim.LimiterType(IntEnum)
determine if a limiter is applied
Values
none:0— no limiterzero_one:1— limiter to [0,1]positive:2— limiter to >= 0neighbour:3— limiter to [(min(n), max(n))], n being the mean value on the neighbouring elementspast_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 meshdimension: int — Dimension of the meshn_elements: int — Number of elementsn_cg_nodes: int — The number of nodes (periodicity is ignored, periodic nodes are duplicated).n_node_by_element: int — Number of nodes by elementn_boundary: int — Number of boundaryMethods
- 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 filechunk: 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 filechunk: 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 filechunk: 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 filechunk: 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 arrayReturns
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 arrayReturns
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 subarrayReturns
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 subarrayReturns
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 datan_fields: int — Number of fieldsMethods
- 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 evaluatedout: ScalarArrayDevice | None — Optional output array to store the resulttag: 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 evaluatedReturns
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
Methods
- static create_constant(mesh, value)
create a new uniform slim4::slim::DataStatic
Parameters
mesh: Mesh — The meshvalue: NDArray[np.float64] — The value of the dataReturns
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 dataConstructor
- __init__(filename, varname, mesh)
create a new slim4::slim::DataFile (this object will read data from the files and interpolate them when needed)
Parameters
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 datatime: NDArray[np.float64] | None — The time of the datacols: NDArray[np.int32] | None — The columns of the data CSR columns for DG_INTERP and CG_INTERPcsr_start: NDArray[np.int32] | None — The start of the CSR matrixweights: 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 datacols: NDArray[np.int32] | None — The columns of the data CSR columns for DG_INTERP and CG_INTERPcsr_start: NDArray[np.int32] | None — The start of the CSR matrixweights: 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 datashape: Tuple[int, …] — apparent shapeConstructor
- __init__(filename, varname, mesh)
create a new slim4::slim::DataOutput
Parameters
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 fileReturns
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 arrayConstructor
- __init__(array, mesh)
create a new slim4::slim::DataWrap
Parameters
array: ScalarArrayDevice — The GPU array to wrapmesh: 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 processsize: int — size of the communicatornode_rank: int — rank inside of the current nodenode_size: int — size of the current nodeMethods
- 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 valueReturns
sum: float — the sum of all local values
- min_scalar(local)
find the minimum scalar across all ranks
Parameters
local: float — the local valuesReturns
min: float — the minimum of all local values
- max_scalar(local)
find the maximum scalar across all ranks
Parameters
local: float — the local valuesReturns
max: float — the maximum of all local values
- sum_idx(local)
sum an index across all ranks
Parameters
local: int — the local valueReturns
sum: int — the sum of all local values
- max_idx(local)
find the maximum index across all ranks
Parameters
local: int — the local valuesReturns
max: int — the maximum of all local values
- min_idx(local)
find the minimum index across all ranks
Parameters
local: int — the local valuesReturns
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 valueReturns
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 arrayquantile: float — the quantile to computeReturns
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 arrayReturns
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 — timex: ScalarArrayDevice — the vector
- inv_mass_mult(t, x)
multiply a global vector by the inverse mass matrix in place
Parameters
t: float — timex: ScalarArrayDevice — the vector
- fill_vector(solution, t, dt, rhs)
fill the right hand side vector
Parameters
solution: ScalarArrayDevice — the solution vectort: float — the timedt: float — the time steprhs: 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 vectort: float — the timedt: float — the time stepsolbase: ScalarArrayDevice — the solution vector at the beginning of the total time stepsolnext: ScalarArrayDeviceMPI — the solution vector at the end of the sub time stepfinal: 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 stept: float — the current timedt: float — the time stepalpha: float — 1/dt for an euler implicit schemesys: LinearSolver — the linear solver and matrix to useR: ScalarArrayDevice — see documentation of the functionReturns
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 usemat: ScalarArrayDevice — The slim matrix this matrix is based oncsr: Csr — The CSR structure of the matrixoptions: 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 solveReturns
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 arrayfield: int — the index of the decaying field in the solution arraymu: 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 arrayfield_a: int — the index of the first field in the solution arrayfield_b: int — the index of the second field in the solution arraycarray: ScalarArrayDeviceMPI — the reaction coefficientsource: Data — the source dataf_ab: float — the reaction coefficientf_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 arraysolution_h: ScalarArrayDevice — the hydrodynamic solution device arrayfield_n: int — the index of the first field in the solution array - nitrogenfield_p: int — the index of the second field in the solution array - phytoplanktonfield_z: int — the index of the third field in the solution array - zooplanktonfield_d: int — the index of the fourth field in the solution array - detritusrad: Data — the radiation datah: Data — the bathymetry datal_mineral: float — the linear mineralization ratel_excretion: float — the linear excretion ratemax_uptake: float — the maximum uptake rateh_min: float — the H limitkd: float — the light extinction coefficientks_PAR: float — the half-saturation constant for PARks_n: float — the half-saturation constant for nitrogen uptakemax_graze: float — the maximum grazing rateks_graze: float — the half-saturation constant for grazingl_mortality_p: float — the linear mortality rate of phytoplanktonp_faeces: float — the proportion of phytoplankton going to faecesl_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 usemat: ScalarArrayDevice — The slim matrix this matrix is based oncsr: Csr — The CSR structure of the matrixoptions: 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 solveReturns
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 arraysize: int — the total number of elementscap: int — the total capacityname: str — the name of the arrayMethods
- static create_empty(shape)
create a newly allocated (and uninitialized) ava device array of scalars
Parameters
shape: List[int] — The shape of the arrayReturns
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 arrayReturns
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 arraysize: int — the total number of elementscap: int — the total capacityname: str — the name of the arrayMethods
- static create_empty(shape)
create a newly allocated (and uninitialized) ava device array of scalars
Parameters
shape: List[int] — The shape of the arrayReturns
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 arrayReturns
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 communicatorinout_dev: ScalarArrayDevice — the input and output device array. Must have the same size on all ranks.op: MpiReduceOp | str — the reduction operation to performcheck_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 doublecommtype: str — The communication type : one of ‘none’, ‘mpi’, ‘gpu_aware_mpi’, ‘nccl’ or ‘rccl’platform: str — The platform : one of ‘cpu’, ‘cuda’, ‘hip’ or unknownimplicit: 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 deviceReturns
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 valuesa: 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 valuesa: 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 dimensionReturns
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 formatprecision: int — The number of significant digits to displaysep: str — The separator between the number and the prefixbinary: bool — Whether to use binary prefixes (powers of 1024) or decimalReturns
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 integratesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepa: NDArray[np.float64] — the coefficients of the Butcher tableaub: NDArray[np.float64] — the coefficients of the Butcher tableauc: NDArray[np.float64] — the coefficients of the Butcher tableaunstep: int — the number of time stepsmean_sol: ScalarArrayDevice | None — the mean solution vectorreactions: List[Reaction] — the reactions to apply after each time stepReturns
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 integratesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepscheme: 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 stepsmean_sol: ScalarArrayDevice | None — the mean solution vectorreactions: List[Reaction] — the reactions to apply after each time stepReturns
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 integratesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepcoeffs: NDArray[np.float64] — the coefficients of the low-storage Runge-Kutta schemenstep: int — the number of time stepsmean_sol: ScalarArrayDevice | None — the mean solution vectorreactions: List[Reaction] — the reactions to apply after each time stepReturns
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 integratesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepscheme: 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 stepsmean_sol: ScalarArrayDevice | None — the mean solution vectorreactions: List[Reaction] — the reactions to apply after each time stepReturns
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 integratesys: LinearSolver — the linear solver to usesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepmaxit: int — the maximum number of iterations of the newton solverrtol: float — the relative tolerance of the newton solveratol: float — the absolute tolerance of the newton solvermean_sol: ScalarArrayDevice | None — the mean solution vectorReturns
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 integratesys: LinearSolver — the linear solver to usesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepA: List[List[float]] — the Butcher table APIB: List[float] — the Butcher table APIC: List[float] — the Butcher table APImaxit: int — the maximum number of iterations of the newton solverrtol: float — the relative tolerance of the newton solveratol: float — the absolute tolerance of the newton solvermean_sol: ScalarArrayDevice | None — the mean solution vectorReturns
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 integratesys: LinearSolver — the linear solver to usesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepmaxit: int — the maximum number of iterations of the newton solverrtol: float — the relative tolerance of the newton solveratol: float — the absolute tolerance of the newton solvermean_sol: ScalarArrayDevice | None — the mean solution vectorReturns
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 integratesys: LinearSolver — the linear solver to usesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepmaxit: int — the maximum number of iterations of the newton solverrtol: float — the relative tolerance of the newton solveratol: float — the absolute tolerance of the newton solvermean_sol: ScalarArrayDevice | None — the mean solution vectorReturns
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 integratesys: LinearSolver — the linear solver to usesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepmaxit: int — the maximum number of iterations of the newton solverrtol: float — the relative tolerance of the newton solveratol: float — the absolute tolerance of the newton solvermean_sol: ScalarArrayDevice | None — the mean solution vectorReturns
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 integratesys: LinearSolver — the linear solver to usesolution: ScalarArrayDeviceMPI — the solution vectortstart: float — the initial timedt: float — the time stepmaxit: int — the maximum number of iterations of the newton solverrtol: float — the relative tolerance of the newton solveratol: float — the absolute tolerance of the newton solvermean_sol: ScalarArrayDevice | None — the mean solution vectorReturns
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.