slim4.slim3d
Slim3d 3D hydrodynamics classes and functions
Enums
- class slim4.slim3d.HorizontalViscosityFormula(IntEnum)
The formula for the viscosity.
Values
none:0— No viscosity.direct:1— The horizontal viscosity is the slim4::slim::Data given.smago:2— Smagorinsky horizontal viscosity.
- class slim4.slim3d.HorizontalDiffusionOrientation(IntEnum)
The orientation for the horizontal diffusion.
Values
xy:0— The diffusion is oriented following the xy plane.mesh:1— Default orientation. The diffusion is oriented following the mesh.isopycnal:2— The diffusion is oriented following the isopycnal direction.
- class slim4.slim3d.TurbulenceModelType(IntEnum)
Values
k_epsilon:0— k-epsilonk_omega:1— k-omega
- class slim4.slim3d.TurbulenceStabilityType(IntEnum)
Values
canuto:0— Canutokantha:1— Kanthayamada:2— Yamada
Classes
- class slim4.slim3d.Mesh
Bases: slim.Mesh.
A tri-dimensional mesh built from a bi-dimensional mesh extruded along the z-axis.
Properties
mesh2d: slim2d.Mesh — The bi-dimensional mesh.z_layers: NDArray[np.int32] — Starting index of each column of prisms.n_layers: NDArray[np.int32] — The number of layers for each triangle.n_moving_layers: NDArray[np.int32] — Number of moving layers for each column of nodes. CG min of n_layers and n_moving_layers_max. shape [n_triangles, 3].),n_layers_f2d: NDArray[np.int32] — Minimun of number of layers between a triangle and its face neighbours. Shape [n_triangles].n_layers_max_cg: NDArray[np.int32] — CG max of n_layers, including neighbouring partitions. Shape [n_cg_nodes].cg_column_start: NDArray[np.int32] — Start of each column of 3D CG nodes. Shape [n_cg_nodes_2d + 1].first_prism_id: int — The id of the first prism.Constructor
- __init__(mesh2d, z_layers, n_moving_max=-1)
create a new 3D mesh from a 2D mesh and a vertical structure
Parameters
mesh2d: slim2d.Mesh — 2D meshz_layers: NDArray[np.int32] — Starting index of each column of prismsn_moving_max: int — Maximum number of moving layers. If negative, all layers are moving.
Methods
- static partition_output(outpath, meshfile, pfile='')
Partitions a 2D mesh with weights corresponding to the 3D mesh of an output
Parameters
outpath: str — Ouput path of SLIM 3Dmeshfile: str — The name of the file to partitionpfile: str — The name of the output file given as a pattern that should contain ${rank}, ${rank} will be replaced by the rank of the partition. If Null the parition rank will be appended to the name of the original file.Returns
spfile: str — return the name of the partitioned file for the current rank
- static from_output(outpath, meshfile, n_moving_max=-1, tags2d=[], projection2d='', projection_type2d='')
Creates a new 3D mesh from an output of SLIM 3D
Parameters
outpath: str — Ouput path of SLIM 3Dmeshfile: str — 2D mesh filen_moving_max: int — Maximum number of moving layers. If negative, all layers are moving.tags2d: List[str] — The physical tags of the entities to load (NULL for all).projection2d: str — The coordinate system of the 2D mesh coordinates if any (the string format depends on projection_type).projection_type2d: str — The type of the coordinate system of the 2D mesh coordinates if any (e.g. ‘proj4’, of ‘WKT’).Returns
mesh: Mesh — a new 3D mesh
- scatter_cg_to_dg(cg)
Scatter a CG array to a DG array.
Parameters
cg: NDArray[np.float64] — The array to scatter. […, n_cg_nodes]Returns
dg: NDArray[np.float64] — the scattered array. […, 6, n_prisms]
- gather_dg_to_cg(op, dg, z)
Gather a DG array to a CG array.
Parameters
op: slim2d.GatherOp | str — The operation to perform.dg: NDArray[np.float64] — The array to gather. […, 6, n_prisms]z: NDArray[np.float64] — The z vector. [1, 6, n_prisms]Returns
cg: NDArray[np.float64] — the gathered array. […, n_cg_nodes]
- repeat2d3d(v)
Repeat a 2D array to a 3D array. The 2D array is repeated along the z-axis.
Parameters
v: NDArray[np.float64] — The array to repeat. [n_triangles, 3, n_fields]Returns
v3d: NDArray[np.float64] — the repeated array. [n_prisms, 6, n_fields]
- create_coordinate_vector(z)
Create the xyz coordinate vector at every point in the 3D mesh.
Parameters
z: NDArray[np.float64] — The z vector. [n_prisms, 6] or [n_prisms, 6, 1]Returns
xyz: NDArray[np.float64] — the coordinate vector. [n_prisms, 6, 3]
- boundary_nodes(tags)
Return the nodes of the boundary edges.
Parameters
tags: List[str] — list of boundary tagsReturns
a: NDArray[np.int32] — new array with the boundary nodes (unique and sorted)
- scatter_array(array)
Scatter a 3D GPU field.
Parameters
array: slim.ScalarArrayDeviceMPI — The field to scatter.
- mass_mult(z, v)
Multiply a field v. by the mass matrix. v must have 1, 2 or 3 fields.
Parameters
z: slim.ScalarArrayDevice — The field to multiply.v: slim.ScalarArrayDevice — The data that shall be multiplied by the mass matrix.
- inv_mass_mult(z, v)
Multiply a field v. by the inverse of the mass matrix. v must have 1, 2 or 3 fields.
Parameters
z: slim.ScalarArrayDevice — The field to multiply.v: slim.ScalarArrayDevice — The data that shall be multiplied by the mass matrix.
- vertical_sum(in3d, out2d, alpha)
Sum a 3D field vertically. The result is a 2D field: out2d = sum(in3d) + out2d*alpha.
Parameters
in3d: slim.ScalarArrayDevice — The field to sum.out2d: slim.ScalarArrayDevice — The result of the sum.alpha: float — Optinal factor that mutiplies out2d.
- new_mesh_3d(z_old, eta_new, z_new, wm=None, dt=0)
Compute the new z_coordinate from the old z_coordinate and the new free surface.
Parameters
z_old: slim.ScalarArrayDevice — The old z_coordinate.eta_new: slim.ScalarArrayDevice — The new free surface.z_new: slim.ScalarArrayDevice — The new z_coordinate.wm: slim.ScalarArrayDevice | None — optional mesh speed to be computed.dt: float — The time step for the mesh speed computation.
- create_xdmf(z, fname, cg=False)
Create a new empty xdmf export
Parameters
z: NDArray[np.float64] — z coordinate of the meshfname: str — path to the new xdmf file (without the .xdmf extension).cg: bool — if true, create a cg export, else create a dg export.
- append_to_xdmf(fname, iter, t, z_dg, fields, precision='native')
Append a new timestep to an existing xdmf export
Parameters
fname: str — path to the existing xdmf file (without the .xdmf extension).iter: int — output idt: float — output timez_dg: NDArray[np.float64] — z coordinate of the mesh for weighted averagefields: List[Tuple[str, NDArray[np.float64]]] — fields to be exportedprecision: slim.OutputPrecision | str — native, half, single or double
- integrate(z, factors)
Integrate a product of fields over the mesh. The integral is done numerically with a 28-point quadrature.
Parameters
z: NDArray[np.float64] — The z coordinate of the mesh.factors: List[NDArray[np.float64]] — The fields to integrate.Returns
I: float — the integral.
- integrate_vertical(z, fields)
Integrate 3D fields vertically. The integral is done numerically with a 4-point quadrature.
Parameters
z: NDArray[np.float64] — The z coordinate of the mesh.fields: NDArray[np.float64] — The fields to integrate.Returns
I: NDArray[np.float64] — the integral.
- save_mesh(z, outpath)
Save the mesh to disk.
Parameters
z: NDArray[np.float64] — z coordinate of the meshoutpath: str — path to the folder where the mesh will be saved.
- static load(path, n_moving_max=-1)
Load a partitioned 3D mesh from disk.
Parameters
path: str — path to the splited mesh foldern_moving_max: int — Maximum number of moving layers. If negative, all layers are moving.Returns
mesh: Mesh — the meshz0: NDArray[np.float64] — the z coordinatebath: slim.DataStatic — the bathymetry
- find_points(z, xyz)
Find the prisms containing some points.
Parameters
z: NDArray[np.float64] — The z coordinate of the mesh.xyz: NDArray[np.float64] — The x, y and z coordinates of the points of shape (3, n).Returns
new_pids: NDArray[np.int32] — return a new array with the id of the prism containing each point.new_uvw: NDArray[np.float64] — return a new array with the parametric coordinates of the points in the prisms.
- find_points_z(z_mesh, eids, uv, z_points)
Find the prisms containing some points, knowing the triangle in which they are located.
Parameters
z_mesh: NDArray[np.float64] — The z coordinate of the mesh.eids: NDArray[np.int32] — The id of the triangles containing each point.uv: NDArray[np.float64] — The parametric xy-coordinates of each points of shape (2,n).z_points: NDArray[np.float64] — The z coordinates of the points of shape (n).Returns
new_pids: NDArray[np.int32] — return a new array with the id of the prism containing each point.new_zeta: NDArray[np.float64] — return a new array with the parametric z-coordinates of the points in the prisms.
- interpolate(z, field, xyz)
Interpolate on n field a given set of points.
Parameters
z: NDArray[np.float64] — The z coordinate of the mesh.field: NDArray[np.float64] — The field to interpolate.xyz: NDArray[np.float64] — The coordinates of the points to interpolate.Returns
interp: NDArray[np.float64] — The interpolated values.
- check_consistency_z(z, dmin=0)
Checks if the values in the ghost cells are consistent with the other partitions, checks the monotonicity of z with a minimum depth per layer checks that the bathymetry is continuous where the number of layers is continuous,
Parameters
z: NDArray[np.float64] — The z coordinate of the mesh.dmin: float — The minimum distance between two layers
- vorticity(z, uvw, t=-31536000000, out=None)
Computes the vorticity of a velocity field.
Parameters
z: Union[slim.ScalarArrayDevice, slim.Data] — The z coordinate of the mesh.uvw: Union[slim.ScalarArrayDevice, slim.Data] — The velocity field. Can have 2 or 3 components. If it has 2 components, the vertical velocity is assumed to be zero.t: float — The time (if z or uvw is provided as slim4::slim::Data)out: slim.ScalarArrayDeviceMPI | None — optional output array for the vorticity. If None, a new array is created.Returns
vorticity: slim.ScalarArrayDeviceMPI — The vertical vorticity if uvw has 2 components, the full vorticity if uvw has 3 components.
- class slim4.slim3d.DataLinear
Bases: slim.Data.
Data linearly interpolated between two instants
Constructor
Methods
- set_time(t0, t1)
set the two instants in between which the data is linearly interpolated
Parameters
t0: float — The first instantt1: float — The second instant
- class slim4.slim3d.DataExtrude
Bases: slim.Data.
3D Data from extruded from a 2D data
Constructor
- __init__(base, mesh)
create a new slim4::slim3d::DataExtrude
Parameters
- class slim4.slim3d.DataHMultiply
Bases: slim.Data.
3D Data multiplied by prish height at each node
Constructor
- __init__(base, eta, bath, z)
create a new slim4::slim3d::DataHMultiply
Parameters
- class slim4.slim3d.DataExtractLayer
Bases: slim.Data.
2D Data extracted from a layer of 3D data
Constructor
- __init__(base, layer, topface)
create a new slim4::slim3d::DataExtractLayer
Parameters
base: slim.Data — The base 3D datalayer: int — The layer to extract (0 is the surface, 1 is the first layer below the surface, etc.). The bottom layer is -1. The CGbottom layer is -2.topface: bool — Whether to extract the top face of the layer (true) or the bottom face (false)
Methods
- set_layer(layer, topface)
set the layer to extract
Parameters
layer: int — The layer to extract (0 is the surface, 1 is the first layer below the surface, etc.). The bottom layer is -1. The CGbottom layer is -2.topface: bool — Whether to extract the top face of the layer (true) or the bottom face (false)
- class slim4.slim3d.TmpVar
Class to store all the temporary variables of the 3D model.
Properties
z_0: slim.ScalarArrayDeviceMPI — z_0 scratch spacez_next: slim.ScalarArrayDeviceMPI — z_next scratch spaceuv_0: slim.ScalarArrayDeviceMPI — uv_0 scratch spaceuv_next: slim.ScalarArrayDeviceMPI — uv_next scratch spacehuv_gpu: slim.ScalarArrayDeviceMPI — huv_gpu scratch spacef3d_expl: slim.ScalarArrayDeviceMPI — f3d_expl scratch spacef3d_vsum: slim.ScalarArrayDeviceMPI — f3d_vsum scratch spacef2d_for_3d: slim.ScalarArrayDeviceMPI — f2d_for_3d scratch spacew_gpu: slim.ScalarArrayDeviceMPI — w_gpu scratch spacewm_gpu: slim.ScalarArrayDeviceMPI — wm_gpu scratch spacesol2d: slim.ScalarArrayDeviceMPI — sol2d scratch spacesol2d_0: slim.ScalarArrayDeviceMPI — sol2d at the beginning of the time step scratch spacesol2d_c: slim.ScalarArrayDeviceMPI — temp copy of sol2dz_tracer: slim.ScalarArrayDeviceMPI — z coordinates of the mesh used to advance the tracers (may be None if no tracers on the problem)w_tracer: slim.ScalarArrayDeviceMPI — vertical velocity used to advance the tracers (may be None if no tracers on the problem)huv_tracer: slim.ScalarArrayDeviceMPI — horizontal velocity used to advance the tracers (may be None if no tracers on the problem)sol2d_avg: slim.ScalarArrayDeviceMPI — 2D horizontal velocity used to advance the tracers (may be None if no tracers on the problem)kpsi: slim.ScalarArrayDeviceMPI — turbulence variables (may be None if no turbulence on the problem)nu_kappa: slim.ScalarArrayDeviceMPI — vertical viscosity and diffusivity for turbulence (may be None if no turbulence on the problem)rho: slim.ScalarArrayDeviceMPI — density scratch space (may by None if no state equation)hpg: slim.ScalarArrayDeviceMPI — Reduced horizontal baroclinic pressure gradient (may by None if no state equation)tracers_0: Dict[str,:ref:slim.ScalarArrayDeviceMPI <api-class-slim4-slim-scalararraydevicempi>] — tracers at the beginning of the time step scratch spacetracers_next: Dict[str,:ref:slim.ScalarArrayDeviceMPI <api-class-slim4-slim-scalararraydevicempi>] — tracers at the end of the sub-time step scratch spacedrho: slim.ScalarArrayDeviceMPI — density variation scratch space (may by None if no state equation)
- class slim4.slim3d.Problem
The main class to handle all the subproblems of the 3D model.
Properties
problemUV: UV — the 3d horizontal velocity problem uv(x,y,z,t)problemUV2d: slim2d.ShallowWater — the 2d shallow water problem uv(x,y,t) solving the wave equation external modeproblem_tracer: Dict[str,:ref:Tracer <api-class-slim4-slim3d-tracer>] — the tracers problemsproblemTurbulence: Turbulence — the turbulence problemmesh: Mesh — the 3d mesh (2D mesh + extrusion in the vertical)bathymetry: slim.Data — the bathymetry datalin_data: List[DataLinear] — data linearized over a full time stepmax_uv_speed: float — the maximumuv_clip_loc: slim.ScalarArrayDevice | None — registers how many times the velocity clipper acts on each element between two exportssys_2d: slim.LinearSolver — the linear system for the 2D problemreactions: List[slim.Reaction] — the reactions solved as ordinary differential equations on each nodeConstructor
- __init__(mesh, g, bathymetry, rho_0=1000.0)
Create a new 3D problem.
Parameters
Methods
- get_gpu_tmpvars()
Get (and allocate if they do not exist) the temporary variables used by the times-stepping and export functions
Returns
tmpvars: TmpVar — A class storing the temporary variables
- compute_cfl(u_max=2, drho=None)
Compute the time step based on the Courant-Friedrichs-Lewy condition
Parameters
u_max: float — the maximum velocitydrho: NDArray[np.float64] | None — the density variation : either None (=0), an array of size (1) an array of size (n_elements, 6)Returns
dt3d: float — the 3D time stepcfl: float — the 2D time step
- add_tracer(nfields, name, limiter_type='past_bound', wadd=0.0)
Add a new tracer to the problem
Parameters
nfields: int — the number of tracer fieldsname: str — the name of the tracerlimiter_type: slim.LimiterType | str — The type of limiterwadd: float — the additional vertical velocityReturns
tracer: Tracer — the new tracer
- add_turbulence(model='k_epsilon', stability='canuto', initial_value=1e-8, z0b=None, z0s=None)
Add a turbulence model to the problem
Parameters
model: TurbulenceModelType | str — the turbulence modelstability: TurbulenceStabilityType | str — the stability modelinitial_value: float — the initial value of the turbulencez0b: slim.Data | None — the bottom roughnessz0s: slim.Data | None — the surface roughness
- add_reaction(reaction)
Add a reaction to the problem
Parameters
reaction: slim.Reaction — the reaction
- set_wall_boundary(tag, slip=False)
Set a wall boundary condition
Parameters
tag: str — the tag of the boundaryslip: bool — if True, slip (frictionless) wall. (default False)
- set_open_boundary(tag, eta=None, u=None, t={}, uv_is_transport=True)
Set an open boundary condition
Parameters
- set_state_equation_jackett(temperature, salinity)
Set the state equation to the jackett equation
Parameters
temperature: slim.ScalarArrayDevice — the temperature datasalinity: slim.ScalarArrayDevice — the salinity data
- set_state_equation_teos10(temperature, salinity)
Set the state equation to the teos10 density equation.
Parameters
temperature: slim.ScalarArrayDevice — the potential temperature data [°C]salinity: slim.ScalarArrayDevice — the absolute salinity data [g/kg]
- set_state_equation_linear(tracer_scalar_pairs)
Set the state equation to a linear equation
Parameters
tracer_scalar_pairs: List[Tuple[slim.ScalarArrayDevice, float]] — the tracers and their scalar values
- set_dissipation(gamma, log=False)
Set the dissipation
Parameters
gamma: slim.Data — the dissipationlog: bool — true if gamma is the coefficient of the log profile, false if it is directly the friction coefficient.
- set_surface_water(q_water, t={}, upwind={})
Set the quantity of water added by precipitation or removed by evaporation
Parameters
q_water: slim.Data — the quantity of water added by precipitation or removed by evaporation (in m/s)t: Dict[str,:ref:slim.Data <api-class-slim4-slim-data>] — the tracer concentration of entering/outgoing water (2D)upwind: Dict[str,List[bool]] — if True, the tracer concentration is taken from the domain for evaporation and from the data in t for precipitation
- set_surface_flux(tracer, flux)
Set the surface flux
Parameters
tracer: str — the tracerflux: slim.Data — the surface source flux [[tracer]*m/s]
- set_penetrating_flux(pen_flux, pen_dist, tracer, z)
Set the penetrating flux
Parameters
pen_flux: slim.Data — the Total penetrating source flux [T*m/s]pen_dist: slim.Data — the characteristic absorption distance [m]. The absorbed flux is computed as C * exp(-depth/pen_dist)tracer: slim.ScalarArrayDevice — the tracerz: slim.ScalarArrayDevice — the vertical mesh coordinate vector
- set_surface_tracer_nudging(tracer, obs, surf_nudg_time, surf_nudg_depth, nudging_active)
Set the surface tracer nudging
Parameters
tracer: str — the tracerobs: slim.Data — the observation datasurf_nudg_time: float — the nudging timesurf_nudg_depth: float — the nudging depthnudging_active: List[bool] — If the nudging is active (1) or not (0) for each field.
- set_atmospheric_pressure(atm)
Set the atmospheric pressure
Parameters
atm: slim.Data — the atmospheric pressure data
- set_velocity_nudging(a_nudging, uv_nudging)
Add a nudging term as a source term in the momentum equation. None unsets the forcing.
Parameters
- do_export(path2d, path3d, iout, t, z, uv, tracers=[], Huv=True, rho=False, turbulence=False, nuv=False, kappav=False, fields_2d=[], fields_3d=[], clip_loc=None, nitperex=-1, precision='single')
Export the solution to the xdmf file.
Parameters
path2d: str — the path to the xdmf file for the 2D solutionpath3d: str — the path to the xdmf file for the 3D solutioniout: int — the index of the exportt: float — the time of the export expressed in unix time (seconds since 1970-01-01 00:00:00)z: slim.ScalarArrayDevice — the 3D mesh vertical coordinateuv: slim.ScalarArrayDevice — the 3D horizontal velocitytracers: List[slim.ScalarArrayDevice] — the list of tracersHuv: bool — if True, export the total velocityrho: bool — if True, export the densityturbulence: bool — if True, export the k-psi turbulent variablenuv: bool — if True, export the vertical viscositykappav: bool — if True, export the vertical diffusivityfields_2d: List[Tuple[str, NDArray[np.float64]]] — the list of additional fields to export in the 2D filefields_3d: List[Tuple[str, NDArray[np.float64]]] — the list of additional fields to export in the 3D fileclip_loc: slim.ScalarArrayDevice | None — registers how many times the velocity clipper acts on each element between two exportsnitperex: int — the number of iterations between two exports (used for clip_loc)precision: slim.OutputPrecision | str — the floating-point number precision of the outputReturns
next_iout: int — the index for the next export
- export_mean_transport(path2d, path3d, iout, t, z, uv)
Export the solution to the xdmf file.
Parameters
path2d: str — the path to the xdmf file for the 2D solutionpath3d: str — the path to the xdmf file for the 3D solutioniout: int — the index of the exportt: float — the time of the export expressed in unix time (seconds since 1970-01-01 00:00:00)z: slim.ScalarArrayDevice — the 3D mesh vertical coordinateuv: slim.ScalarArrayDevice — the 3D horizontal velocityReturns
next_iout: int — the index for the next export
- new_linear_system(options)
Create a new 2D linear system
Parameters
options: str — the (e.g. PETSc) options for the linear system
- save(t, iout, iiter, path, z, uv, tracers)
Save the solution to an xdmf file that can be reloaded later
Parameters
t: float — the time of the export expressed in unix time (seconds since 1970-01-01 00:00:00)iout: int — the index of the exportiiter: int — the iteration indexpath: str — the path to the xdmf filez: slim.ScalarArrayDevice — the 3D mesh vertical coordinateuv: slim.ScalarArrayDevice — the 3D horizontal velocitytracers: List[slim.ScalarArrayDevice] — the list of tracers
- load(path, z, uv, tracers)
Load a saved solution from an xdmf file
Parameters
path: str — the path to the xdmf filez: slim.ScalarArrayDeviceMPI — the 3D mesh vertical coordinateuv: slim.ScalarArrayDeviceMPI — the 3D horizontal velocitytracers: List[slim.ScalarArrayDeviceMPI] — the list of tracersReturns
time: float — the time of the saved solutioniout: int — the index of the saved solutioniiter: int — the iteration index of the saved solution
- set_clipping_velocity(max_uv_speed, clip_loc, realbath=None)
Set the clipping velocity value
Parameters
max_uv_speed: float — the maximum velocity [m/s]clip_loc: slim.ScalarArrayDevice — vector to register how many times the clipper acts on each element between two exports.realbath: slim.Data | None — The real (unclipped) bathymetry. If provided, any elements below the real bathymetry will be clipped to zero velocity.
- class slim4.slim3d.OfflineProblem
The main class to handle all the subproblems of the 3D model.
Properties
problemUV: UV — the 3d horizontal velocity problem uv(x,y,z,t)problem_tracer: Dict[str,:ref:Tracer <api-class-slim4-slim3d-tracer>] — the tracers problemsmesh: Mesh — the 3d mesh (2D mesh + extrusion in the vertical)reactions: List[slim.Reaction] — the reactions solved as ordinary differential equations on each nodelin_data: List[DataLinear] — data linearized over a full time stepConstructor
- __init__(mesh, g, sol2d_data, huv_data, z_data, data_time)
Create a new 3D problem.
Parameters
mesh: Mesh — the 3D meshg: float — the gravitysol2d_data: slim.Data — the mean 2D solution (surface elevation and 2D transport)huv_data: slim.Data — the mean 3D transport and layer heightz_data: slim.Data — the exported vertical mesh coordinatedata_time: NDArray[np.float64] — the time of the exported data
Methods
- get_gpu_tmpvars()
Get (and allocate if they do not exist) the temporary variables used by the times-stepping and export functions
Returns
tmpvars: TmpVar — A class storing the temporary variables
- compute_cfl(u_max=2)
Compute the time step based on the Courant-Friedrichs-Lewy condition
Parameters
u_max: float — the maximum velocityReturns
dt3d: float — the 3D time step
- add_tracer(nfields, name, limiter_type='past_bound', wadd=0.0)
Add a new tracer to the problem
Parameters
nfields: int — the number of tracer fieldsname: str — the name of the tracerlimiter_type: slim.LimiterType | str — The type of limiterwadd: float — the additional vertical velocityReturns
tracer: Tracer — the new tracer
- add_reaction(reaction)
Add a reaction to the problem
Parameters
reaction: slim.Reaction — the reaction
- set_wall_boundary(tag, slip=False)
Set a wall boundary condition
Parameters
tag: str — the tag of the boundaryslip: bool — if True, slip (frictionless) wall. (default False)
- set_open_boundary(tag, eta=None, u=None, t={}, uv_is_transport=True)
Set an open boundary condition
Parameters
- set_surface_water(q_water, t={}, upwind={})
Set the quantity of water added by precipitation or removed by evaporation
Parameters
q_water: slim.Data — the quantity of water added by precipitation or removed by evaporation (in m/s)t: Dict[str,:ref:slim.Data <api-class-slim4-slim-data>] — the tracer concentration of entering/outgoing water (2D)upwind: Dict[str,List[bool]] — if True, the tracer concentration is taken from the domain for evaporation and from the data in t for precipitation
- set_surface_flux(tracer, flux)
Set the surface flux
Parameters
tracer: str — the tracerflux: slim.Data — the surface source flux [[tracer]*m/s]
- set_penetrating_flux(pen_flux, pen_dist, tracer, z)
Set the penetrating flux
Parameters
pen_flux: slim.Data — the Total penetrating source flux [T*m/s]pen_dist: slim.Data — the characteristic absorption distance [m]. The absorbed flux is computed as C * exp(-depth/pen_dist)tracer: slim.ScalarArrayDevice — the tracerz: slim.ScalarArrayDevice — the vertical mesh coordinate vector
- set_surface_tracer_nudging(tracer, obs, surf_nudg_time, surf_nudg_depth, nudging_active)
Set the surface tracer nudging
Parameters
tracer: str — the tracerobs: slim.Data — the observation datasurf_nudg_time: float — the nudging timesurf_nudg_depth: float — the nudging depthnudging_active: List[bool] — If the nudging is active (1) or not (0) for each field.
- class slim4.slim3d.TemporalIterator
time integration methods (for now only used as the external solver (2d part) of the 3d time integrator)
Methods
- iterate(eq, sol, t, ddt, nstep, sol_avg)
Parameters
eq: slim.Equation — the equation to integratesol: slim.ScalarArrayDeviceMPI — the solution vectort: float — the current timeddt: float — the time stepnstep: int — the number of time stepssol_avg: slim.ScalarArrayDevice — the average solution vector (output)
- static rk(order)
create a Runge-Kutta iterator
Parameters
order: int — the order of the Runge-Kutta methodReturns
rk: TemporalIterator — the Runge-Kutta method
- static rkls(scheme=2. / 13)
create a low-storage Runge-Kutta iterator
Parameters
scheme: float — the order of the Runge-Kutta method (2./13 is 3-step 2nd order)Returns
rk: TemporalIterator — the Runge-Kutta method
- static rk_butcher(a, b, c)
create a Runge-Kutta iterator with a given Butcher table
Parameters
a: NDArray[np.float64] — the matrix of the Butcher tableb: NDArray[np.float64] — the vector of the Butcher tablec: NDArray[np.float64] — the vector of the Butcher tableReturns
rk: TemporalIterator — the Runge-Kutta method
- static dirk(sys, order, maxit=10, rtol=1e-5, atol=1e-5)
create a Diagonally Implicit Runge-Kutta iterator
Parameters
sys: slim.LinearSolver — the linear system solverorder: int — the order of the DIRK methodmaxit: int — the maximum number of iterationsrtol: float — the relative toleranceatol: float — the absolute toleranceReturns
dirk: TemporalIterator — the DIRK method
- static dirk_butcher(sys, a, b, c, maxit=10, rtol=1e-5, atol=1e-5)
create a Diagonally Implicit Runge-Kutta iterator with a given Butcher table
Parameters
sys: slim.LinearSolver — the linear system solvera: List[List[float]] — the matrix of the Butcher tableb: List[float] — the vector of the Butcher tablec: List[float] — the vector of the Butcher tablemaxit: int — the maximum number of iterationsrtol: float — the relative toleranceatol: float — the absolute toleranceReturns
dirk: TemporalIterator — the DIRK method
- static midpoint(sys, maxit=10, rtol=1e-5, atol=1e-5)
create a Midpoint iterator
Parameters
sys: slim.LinearSolver — the linear system solvermaxit: int — the maximum number of iterationsrtol: float — the relative toleranceatol: float — the absolute toleranceReturns
midp: TemporalIterator — the Midpoint method
- static crank_nicolson(sys, maxit=10, rtol=1e-5, atol=1e-5)
create a Crank-Nicolson iterator
Parameters
sys: slim.LinearSolver — the linear system solvermaxit: int — the maximum number of iterationsrtol: float — the relative toleranceatol: float — the absolute toleranceReturns
cn: TemporalIterator — the Crank-Nicolson method
- class slim4.slim3d.UV
3D shallow water problem
Properties
mesh: Mesh — The mesh.g: float — The gravity.rho_0: float — The reference density.bath: slim.Data — The bathymetry.cor: slim.Data — The Coriolis parameter.q_water: slim.Data — The precipitation/evaporation.tau: slim.Data — The surface stress.gamma: slim.Data — The dissipation coefficient.a_nudging: slim.Data — The nudging coefficient.uv_nudging: slim.Data — The nudging velocity.gamma_log: bool — true if gamma_log is the coefficient of the log profile, false if it is directly the friction coefficient.c: slim.ScalarArrayDevice — he 2D wave speed.nu_h: slim.Data — The horizontal viscosity.nu_v: slim.ScalarArrayDevice — The vertical viscosity.Constructor
- __init__(mesh, g, bath, rho_0, t=-31536000000)
Create a new 3D shallow water problem
Parameters
Methods
- set_wall_decay_time(decay_time)
Set the characteristic time of the wall zero velocity condition
Parameters
decay_time: float — The characteristic time of the wall zero velocity condition.
- set_state_equation_jackett(temperature, salinity)
Set the state equation for the density of the fluid with the Jackett model
Parameters
temperature: slim.ScalarArrayDevice — The temperature.salinity: slim.ScalarArrayDevice — The salinity.
- set_state_equation_teos10(temperature, salinity)
Set the state equation for the density of the fluid with the teos10 model
Parameters
temperature: slim.ScalarArrayDevice — The conservative temperature.salinity: slim.ScalarArrayDevice — The absolute salinity.
- set_state_equation_linear(tracers_coeff)
Parameters
tracers_coeff: List[Tuple[slim.ScalarArrayDevice, float]] — The tracers and their coefficients.
- set_wall_boundary(tag, slip=False)
Set a wall boundary condition
Parameters
tag: str — The tag of the boundary.slip: bool — if True, slip (frictionless) wall. (default False)
- set_open_boundary(tag, u=None, eta=None, uv_is_transport=False)
Set an open boundary condition
Parameters
- set_dissipation(gamma, log_profile=False)
Set the dissipation coefficient.
Parameters
gamma: slim.Data — The dissipation coefficient.log_profile: bool — true if gamma is the coefficient of the log profile, false if it is directly the friction coefficient.
- set_surface_water(q_water)
Set the surface water flow. Positive values are precipitation, negative values are evaporation.
Parameters
q_water: slim.Data — The surface water flow. Positive for rain, negative for evaoration
- set_nudging(a_nudging, uv_nudging)
Add a nudging term as a source term in the momentum equation. None unsets the forcing.
Parameters
- get_default_wave_speed(t=-31536000000)
Get the default wave speed sqrt(g*bath) for the 3D Shallow water problem.
Parameters
t: float — The time.Returns
c: slim.ScalarArrayDevice — Output: The wave speed.
- update_density(z, rho)
Update the density rho according to the state equation.
Parameters
z: slim.ScalarArrayDevice — The vertical coordinate.rho: slim.ScalarArrayDevice — The density deviation to be computed.
- clip_velocity(uv, z, vmax, t, uv_clip_loc=None)
Clip the speed to the maximum value
Parameters
uv: slim.ScalarArrayDevice — The horizontal velocity.z: slim.ScalarArrayDevice — The vertical coordinate.vmax: float — The maximum speed.t: float — The timeuv_clip_loc: slim.ScalarArrayDevice | None — A table that registers in which elements the velocity is clipped.
- set_c(c)
Set the maximum characteristic speed array (c) used in upwind stabilisation. Must be set before any temporal integration
Parameters
c: slim.ScalarArrayDevice — The 2D c array.
- set_horizontal_viscosity(nu_h, formula='direct', direction='mesh')
Set the horizontal viscosity array (nu_h) used in upwind stabilisation.
Parameters
nu_h: slim.Data — The nu_h array.formula: HorizontalViscosityFormula | str — The formula for the horizontal viscosity.direction: HorizontalDiffusionOrientation | str — The orientation for the horizontal viscosity.
- set_vertical_viscosity(nu_v_gpu)
Set the vertical viscosity array (nu_v) used in upwind stabilisation.
Parameters
nu_v_gpu: slim.ScalarArrayDevice — The nu_v array.
- new_vector()
Create a new vector uv for the 3D shallow water equation.
Returns
new_v: slim.ScalarArrayDeviceMPI — The new vector.
- solve_w(z, huv_nodal, sol_2d, t, w)
Compute the vertical velocity w from the 3D horizontal transport hu and hv.
Parameters
z: slim.ScalarArrayDevice — The vertical coordinate.huv_nodal: slim.ScalarArrayDevice — The horizontal transport.sol_2d: slim.ScalarArrayDevice — The 2D solution containing the free surface elevation.t: float — The time.w: slim.ScalarArrayDeviceMPI — The vertical velocity to be computed
- solve_w_tilde(huv_nodal, sol_2d, t, w)
Compute the vertical velocity tilde w from the 3D horizontal transport hu and hv.
Parameters
huv_nodal: slim.ScalarArrayDevice — The horizontal transport.sol_2d: slim.ScalarArrayDevice — The 2D solution containing the free surface elevation.t: float — The time.w: slim.ScalarArrayDeviceMPI — The vertical velocity to be computed
- solve_hpg(z, rho, sol_2d, t, hpg)
Compute the reduced horizontal baroclinic pressure gradient hpg.
Parameters
z: slim.ScalarArrayDevice — The vertical coordinate.rho: slim.ScalarArrayDevice — The density.sol_2d: slim.ScalarArrayDevice — The 2D solution containing the free surface elevation.t: float — The time.hpg: slim.ScalarArrayDeviceMPI — The reduced horizontal baroclinic pressure gradient to be computed
- solve_horizontal(z, sol_2d, uv, hpg, huv, drho, t, dt, dt_total, f_expl, implicit, f_total_vsum)
Compute horizontal derivative of the horizontal velocity u and v.
Parameters
z: slim.ScalarArrayDevice — The vertical coordinate.sol_2d: slim.ScalarArrayDevice — The 2D solution containing the free surface elevation.uv: slim.ScalarArrayDevice — The horizontal velocity.hpg: slim.ScalarArrayDevice — The reduced horizontal baroclinic pressure gradienthuv: slim.ScalarArrayDevice — The horizontal transport.drho: slim.ScalarArrayDevice — The density gradient.t: float — The time.dt: float — The sub time step.dt_total: float — The total time step.f_expl: slim.ScalarArrayDeviceMPI — The explicit part of the rhs of the time derivative of uv, M*duvdt = f_expl + f_impl.implicit: bool — Whether to use implicit friction.f_total_vsum: slim.ScalarArrayDevice — The vertically integrated rhs, including thr implicit part of the rhs (friction).
- solve_vertical(z_old, z_mid, z_next, w, wm, f_expl, f2d, uv_old, uv_mid, uv_next, huv, drho, sol2d_mean, hpg, t, dt, dt_total, implicit)
Compute the vertical derivative of the horizontal velocity u and v.
Parameters
z_old: slim.ScalarArrayDevice — The vertical coordinate at the beginning of the time step.z_mid: slim.ScalarArrayDevice — The vertical coordinate inside of the time step for the explicit scheme. Can be None if implicit=True.z_next: slim.ScalarArrayDevice — The vertical coordinate at the end of the time step.w: slim.ScalarArrayDevice — The vertical velocity.wm: slim.ScalarArrayDevice — The vertical mesh velocity.f_expl: slim.ScalarArrayDevice — The explicit part of the rhs of the time derivative of uv, M*duvdt = f_expl + f_impl.f2d: slim.ScalarArrayDevice — The 2D explicit rhs added to f_expl.uv_old: slim.ScalarArrayDevice — The horizontal velocity at the beginning of the time step.uv_mid: slim.ScalarArrayDevice — The horizontal velocity inside of the time step for the explicit scheme. Can be None if implicit=True.uv_next: slim.ScalarArrayDeviceMPI — The computed value of uv at the end of the time step.huv: slim.ScalarArrayDevice — The horizontal transport.drho: slim.ScalarArrayDevice — The density gradient.sol2d_mean: slim.ScalarArrayDevice — The average 2D solution corresponding to huv.hpg: slim.ScalarArrayDeviceMPI — The reduced horizontal baroclinic pressure gradient.t: float — The time.dt: float — The sub time step.dt_total: float — The total time step.implicit: bool — Whether to use implicit or explicit vertical advection/diffusion.
- get_2d_variables(z, uv, sol2d, c=None)
Get the 2D variables from the 3D Shallow water problem.
Parameters
z: slim.ScalarArrayDevice — The vertical coordinate.uv: slim.ScalarArrayDevice — The horizontal 3D velocity.sol2d: slim.ScalarArrayDevice — The 2D solution that will be computed.c: slim.ScalarArrayDevice | None — Optional : The 2D wave speed that will be computed.
- compute_huv(z, uv, huv)
Compute the horizontal transport and element height huv.
Parameters
z: slim.ScalarArrayDevice — The vertical coordinate.uv: slim.ScalarArrayDevice — The horizontal 3D velocity.huv: slim.ScalarArrayDevice — The horizontal transport that will be computed.
- compute_2d_contribution(sol0, sol1, f3d_to_subtract, f2d_for_3d, dt)
Compute the transport derivative dHu/dt that comes from the 2D mode only.
Parameters
sol0: slim.ScalarArrayDevice — The 2D solution at the previous time step.sol1: slim.ScalarArrayDevice — The 2D solution at the current time step.f3d_to_subtract: slim.ScalarArrayDevice — The 3D rhs that should be removed from sol1-sol0.f2d_for_3d: slim.ScalarArrayDevice — The 2D rhs that will be computed.dt: float — The time step.
- get_tracer_variables(z, uv, sol2d_avg, z_tracer, huv_tracer)
Reconstruct z and huv from the averaged 2D for the tracer equations
Parameters
z: slim.ScalarArrayDevice — The vertical coordinate.uv: slim.ScalarArrayDevice — The horizontal 3D velocity.sol2d_avg: slim.ScalarArrayDevice — The averaged 2D solution.z_tracer: slim.ScalarArrayDevice — The vertical coordinate for the tracer equations.huv_tracer: slim.ScalarArrayDevice — The horizontal 3D transport for the tracer equations
- class slim4.slim3d.Tracer
A tracer problem on a 3D mesh
Properties
nfields: int — the number of tracer fieldsConstructor
- __init__(mesh, g, h, nfields, name, limiter_type='past_bound', wadd=0)
create a new 3D tracer problem
Parameters
mesh: Mesh — The 3D mesh.g: float — The gravity.h: slim.Data — The water depth.nfields: int — The number of tracer fields.name: str — The name of the tracer.limiter_type: slim.LimiterType | str — The type of limiter in usewadd: float — The additional vertical velocity.
Methods
- set_wall_boundary(tag, slip=False)
Set a boundary condition.
Parameters
tag: str — The tag of the boundary.slip: bool — if True, slip (frictionless) wall. (default False)
- set_open_boundary(tag, tracer, u, eta, uv_is_transport)
Set a boundary condition.
Parameters
- set_c(c)
Set the maximum characteristic speed array (c) used in upwind stabilisation. Must be set before any temporal integration.
Parameters
c: slim.ScalarArrayDevice — the 2D c array
- set_surface_flux(flux_surf)
Set surface source tracer flux
Parameters
flux_surf: slim.Data — Surface source flux [T*m/s]
- set_surface_water(flux_water)
Set source surface freshwater flux [m/s]
Parameters
flux_water: slim.Data — Surface freshwater flux [m/s], negative means evaporation, positive means precipitation
- set_surface_water_tracer(flux_water, flux_water_tracer, upwind)
Set tracer concentration of entering/outgoing freshwater [T]
Parameters
flux_water: slim.Data — Surface freshwater flux [m/s], negative means evaporation, positive means precipitationflux_water_tracer: slim.Data — Concentration of tracer [T]upwind: List[bool] — if True, the tracer concentration is taken from the domain for evaporation and from the data in t for precipitation
- set_surface_tracer_nudging(surf_tracer, surf_nudg_time, surf_nudg_depth, nudging_active)
Set surface tracer nudging towards observations
Parameters
surf_tracer: slim.Data — Sea surface tracer observations [T]surf_nudg_time: float — Nudging time scale for sea surface tracer [s]surf_nudg_depth: float — Nudging depth for sea surface tracer [m]nudging_active: List[bool] — If the nudging is active (1) or not (0) for each field. fields
- set_horizontal_diffusivity(kappa_h, formula='direct', direction='mesh')
Set the horizontal diffusivity array (kappa_h) used in upwind stabilisation.
Parameters
kappa_h: slim.Data — The dataformula: slim2d.HorizontalDiffusivityFormula | str — The formula to use to compute the horizontal diffusivitydirection: HorizontalDiffusionOrientation | str — The orientation for the horizontal diffusivity
- set_vertical_diffusivity(kappa_v_gpu)
Set the vertical diffusivity array (kappa_v) used in upwind stabilisation.
Parameters
kappa_v_gpu: slim.ScalarArrayDevice — The kappa_v array
- set_nudging(a_nudging, tracer_nudging)
Add a nudging term as a source term in the momentum equation. None unsets the forcing.
Parameters
- new_vector()
Create a new 3D tracer vector.
Returns
new_v: slim.ScalarArrayDeviceMPI — return The new vector
- solve(z_old, z_mid, z_next, w, wm, huv, drho, tracer_old, tracer_mid, tracer_next, sol2d, t, dt, implicit, apply_limiter)
Solve the 3D tracer equations.
Parameters
z_old: slim.ScalarArrayDevice — The vertical coordinate at the beginning of the time stepz_mid: slim.ScalarArrayDevice — The vertical coordinate inside of the time step for the explicit scheme. Can be None if implicit=Truez_next: slim.ScalarArrayDevice — The vertical coordinate at the end of the time stepw: slim.ScalarArrayDevice — The vertical velocitywm: slim.ScalarArrayDevice — The vertical mesh velocityhuv: slim.ScalarArrayDevice — The horizontal transportdrho: slim.ScalarArrayDevice — The density gradienttracer_old: slim.ScalarArrayDevice — The tracer at the beginning of the time steptracer_mid: slim.ScalarArrayDevice — The tracer inside of the time step for the explicit scheme. Can be None if implicit=Truetracer_next: slim.ScalarArrayDeviceMPI — The computed value of tracer at the end of the time stepsol2d: slim.ScalarArrayDevice — The average 2D solution corresponding to to z_mid and huvt: float — The timedt: float — The time step.implicit: bool — Whether to use implicit or explicit vertical advection/diffusionapply_limiter: bool — Whether to apply the limiter
- class slim4.slim3d.Turbulence
A 3D turbulence object
Constructor
- __init__(mesh, g, rho_0, model, stab, z0b, z0s)
create a new 3D turbulence object.
Parameters
mesh: Mesh — 3D meshg: float — gravityrho_0: float — reference densitymodel: TurbulenceModelType | str — turbulence modelstab: TurbulenceStabilityType | str — stability modelz0b: slim.Data — length scale for bottom roughnessz0s: slim.Data — length scale for surface roughness
Methods
- new_vector()
Create a new vector for the 3D Turbulence problem. The two individual components can be accessed with the get_sub method.
Returns
turb: slim.ScalarArrayDeviceMPI — The new vector
- solve_fv(z_old, z_new, uv, rho, kpsi, kpsi_next, nu_kappa, t, dt)
Solve the 3D Shallow water equations using the finite volume method.
Parameters
z_old: slim.ScalarArrayDevice — The vertical coordinate at the beginning of the time stepz_new: slim.ScalarArrayDevice — The vertical coordinate at the end of the time stepuv: slim.ScalarArrayDevice — The horizontal velocityrho: slim.ScalarArrayDevice — The densitykpsi: slim.ScalarArrayDevice — The turbulent kinetic energy and the turbulent stream functionkpsi_next: slim.ScalarArrayDeviceMPI — The computed value of kpsi at the end of the time stepnu_kappa: slim.ScalarArrayDeviceMPI — The computed vertical eddy viscosity and diffusivityt: float — The current timedt: float — The time step
- class slim4.slim3d.ReactionLinearDecay
Bases: slim.Reaction.
A linear reaction term.
Properties
alpha: float — The reaction coefficientz: slim.ScalarArrayDevice — The verticla mesh coordinate vectorreactives: slim.ScalarArrayDevice — The tracersConstructor
- __init__(mesh, alpha, z, reactives)
Create a new linear decay reaction.
Parameters
mesh: Mesh — The mesh.alpha: float — The reaction coefficient.z: slim.ScalarArrayDevice — The verticla mesh coordinate vector.reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
- class slim4.slim3d.ReactionExponentialDecay3d
Bases: slim.Reaction.
An exponential decay reaction term.
Properties
mu: float — The reaction coefficientz: slim.ScalarArrayDevice — The vertical mesh coordinate vectorreactives: slim.ScalarArrayDevice — The tracersConstructor
- __init__(mesh, mu, z, reactives)
Create a new exponential decay reaction.
Parameters
mesh: Mesh — The mesh.mu: float — The reaction coefficient.z: slim.ScalarArrayDevice — The vertical mesh coordinate vector.reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
- class slim4.slim3d.ReactionNPZD3d
Bases: slim.Reaction.
A NPZD model
Properties
mu: float — The max phytoplankton growth rategamma: float — The zooplankton assimilation efficiencyrd: float — The detritus remineralization ratemp: float — The phytoplankton mortality ratemz: float — The zooplankton mortality rategmax: float — The maximum growth ratekn: float — The nutrient half-saturation constantkp: float — The phosphorus half-saturation constantki: float — The light half-saturation constantI0: float — The initial light intensityk: float — The light attenuation with depth coefficientz: slim.ScalarArrayDevice — The vertical mesh coordinate vectorreactives: slim.ScalarArrayDevice — The tracersConstructor
- __init__(mesh, mu, gamma, rd, mp, mz, gmax, kn, kp, ki, I0, k, z, reactives)
Create a new exponential decay reaction.
Parameters
mesh: Mesh — The mesh.mu: float — The max phytoplankton growth rate.gamma: float — The zooplankton assimilation efficiency.rd: float — The detritus remineralization rate.mp: float — The phytoplankton mortality rate.mz: float — The zooplankton mortality rate.gmax: float — The maximum growth rate.kn: float — The nutrient half-saturation constant.kp: float — The phosphorus half-saturation constant.ki: float — The light half-saturation constant.I0: float — The initial light intensity.k: float — The light attenuation with depth coefficient.z: slim.ScalarArrayDevice — The vertical mesh coordinate vector.reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
- class slim4.slim3d.ReactionSurfaceProd
Bases: slim.Reaction.
A surface production term.
Properties
source: slim.Data — The surface source dataz: slim.ScalarArrayDevice — The verticla mesh coordinate vectorreactives: slim.ScalarArrayDevice — The tracersConstructor
- __init__(mesh, source, z, reactives)
Create a new linear decay reaction.
Parameters
mesh: Mesh — The mesh.source: slim.Data — The surface source data.z: slim.ScalarArrayDevice — The verticla mesh coordinate vector.reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
- class slim4.slim3d.ReactionLWHC
Bases: slim.Reaction.
Long-Wave heat correction
Properties
surface_temp: slim.Data — The surface temperature dataz: slim.ScalarArrayDevice — The verticla mesh coordinate vectorreactives: slim.ScalarArrayDevice — The tracersConstructor
- __init__(mesh, surface_temp, z, reactives)
Create a new linear decay reaction.
Parameters
mesh: Mesh — The mesh.surface_temp: slim.Data — The surface temperature dataz: slim.ScalarArrayDevice — The verticla mesh coordinate vector.reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
- class slim4.slim3d.ReactionLatentFlux
Bases: slim.Reaction.
Temperature corrections including: - Latent turbulent heat flux correction
Properties
surface_temp: slim.Data — The surface temperature data [°C]air_mix_ratio: slim.Data — The air mixing ratio [g/kg]sat_mix_ratio: slim.Data — The saturation mixing ratio [g/kg]q_lat: slim.Data — The latent heat flux [W/m2]z: slim.ScalarArrayDevice — The verticla mesh coordinate vectorreactives: slim.ScalarArrayDevice — The tracersConstructor
- __init__(mesh, surface_temp, air_mix_ratio, sat_mix_ratio, q_lat, z, reactives)
Create a new linear decay reaction.
Parameters
mesh: Mesh — The mesh.surface_temp: slim.Data — The surface temperature dataair_mix_ratio: slim.Data — The air mixing ratiosat_mix_ratio: slim.Data — The saturation mixing ratioq_lat: slim.Data — The latent heat fluxz: slim.ScalarArrayDevice — The verticla mesh coordinate vector.reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
- class slim4.slim3d.ReactionTemperatureCorrection
Bases: slim.Reaction.
Temperature corrections including: - Longwave radiative heat flux correction - Latent turbulent heat flux correction
Properties
surface_temp: slim.Data — The surface temperature data [°C]air_mix_ratio: slim.Data — The air mixing ratio [g/kg]sat_mix_ratio: slim.Data — The saturation mixing ratio [g/kg]q_lat: slim.Data — The latent heat flux [W/m2]q_sens: slim.Data — The sensible heat flux [W/m2]tair: slim.Data — The air temperature at 2m above the interface [°C]wind_velocity: slim.Data — The near-surface wind velocity [m/s]z: slim.ScalarArrayDevice — The verticla mesh coordinate vectorreactives: slim.ScalarArrayDevice — The tracersConstructor
- __init__(mesh, surface_temp, air_mix_ratio, sat_mix_ratio, q_lat, q_sens, tair, wind_velocity, z, reactives)
Create a new linear decay reaction.
Parameters
mesh: Mesh — The mesh.surface_temp: slim.Data — The surface temperature dataair_mix_ratio: slim.Data — The air mixing ratiosat_mix_ratio: slim.Data — The saturation mixing ratioq_lat: slim.Data — The latent heat fluxq_sens: slim.Data — The sensible heat fluxtair: slim.Data — The air temperature at 2m above the interfacewind_velocity: slim.Data — The near-surface wind velocityz: slim.ScalarArrayDevice — The verticla mesh coordinate vector.reactives: slim.ScalarArrayDevice — The tracers on which the reaction acts.
- class slim4.slim3d.ReactionPenSource
Bases: slim.Reaction.
Penetration source term
Constructor
- __init__(mesh, pen_flux, pen_dist, tracer, z)
Create a new linear decay reaction.
Parameters
mesh: Mesh — The mesh.pen_flux: slim.Data — Total penetrating source flux [T*m/s]pen_dist: slim.Data — Characteristic absorption distance [m]. The absorbed flux is computed as C * exp(-depth/pen_dist)tracer: slim.ScalarArrayDevice — The tracers on which the reaction acts.z: slim.ScalarArrayDevice — The vertical mesh coordinate vector.
Functions
- slim4.slim3d.partition_mesh(meshfile2d, path3d, outpath)
Partition a 3D mesh and write a new mesh file for each partition.
Parameters
meshfile2d: str — The path to the non-partitioned 2d mesh file.path3d: str — The path to the 3d mesh, as created by mesh3d.save_mesh(). The path should contain n_layers, triangle_element_tag and z in the abin format.outpath: str — The folder for the split 3D mesh.
- slim4.slim3d.project_l2_points(mesh, z)
Get the points where to evaluate an analytic funtion for the projection to a 3D mesh.
Parameters
mesh: Mesh — Tz: NDArray[np.float64] — The z coordinate of the meshReturns
points: NDArray[np.float64] — The points where to evaluate the function
- slim4.slim3d.project_l2(mesh, z, function_at_points)
Project a function to a 3D mesh using L2 projection.
Parameters
mesh: Mesh — The 3D meshz: NDArray[np.float64] — The z coordinate of the meshfunction_at_points: NDArray[np.float64] — The function, evaluated at the points given by project_l2_pointsReturns
projected: NDArray[np.float64] — The projected function
- slim4.slim3d.iterate(problem, z_gpu, uv_gpu, tracers, t, dt, nstep, nrk2d, implicit_steps, solver_2d=None, split=True)
Parameters
problem: Problem — the problem to solvez_gpu: slim.ScalarArrayDevice — the z solution fielduv_gpu: slim.ScalarArrayDevice — the uv solution fieldtracers: List[slim.ScalarArrayDevice] — the tracers solution fieldst: float — the current timedt: float — the time stepnstep: int — the number of sub-time stepsnrk2d: List[int] — the number of 2d sub time-steps for each 3d sub-stepimplicit_steps: List[bool] — indicates if each sub-step is implicitsolver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)split: bool — if False, the 2D and 3D modes execute in lockstep instead of split-imex.Returns
end_t: float — the end time
- slim4.slim3d.iterate_midpoint(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)
Second-order 2-step imex scheme. The first step is vertically implicit, second step is explicit. This is the recommended default scheme for SLIM 3D, as it is a good balance between accuracy, stability and performance.
Parameters
problem: Problem — the problem to solvet: float — the current timedt: float — the time stepM: float — the number of sub-time stepsnstep: int — the number of sub-time stepsz_gpu: slim.ScalarArrayDevice — the z solution fielduv_gpu: slim.ScalarArrayDevice — the uv solution fieldtracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fieldssolver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)Returns
end_t: float — the end time
- slim4.slim3d.iterate_impl(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)
3-step vertically implicit runge-kutta. It is recommended to try the midpoint scheme first, and only use this scheme if the midpoint scheme is unstable due to the bottom friction or vertical viscosity/diffusivity. This scheme is stable but only formally first-order due to the first-order treatment of the bottom friction.
Parameters
problem: Problem — the problem to solvet: float — the current timedt: float — the time stepM: float — the number of sub-time stepsnstep: int — the number of sub-time stepsz_gpu: slim.ScalarArrayDevice — the z solution fielduv_gpu: slim.ScalarArrayDevice — the uv solution fieldtracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fieldssolver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)Returns
end_t: float — the end time
- slim4.slim3d.iterate_expl(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)
Second-order 3-step explicit runge-kutta scheme. Using this scheme for real life simulations is STRONGLY DISCOURAGED, as it is not stable enough. It is mostly available for testing purposes. treatment of the bottom friction.
Parameters
problem: Problem — the problem to solvet: float — the current timedt: float — the time stepM: float — the number of sub-time stepsnstep: int — the number of sub-time stepsz_gpu: slim.ScalarArrayDevice — the z solution fielduv_gpu: slim.ScalarArrayDevice — the uv solution fieldtracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fieldssolver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)Returns
end_t: float — the end time
- slim4.slim3d.iterate_impl_rk1(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)
1-step vertically implicit runge-kutta. This scheme is stable but only first-order accurate. It is mostly available for testing purposes.
Parameters
problem: Problem — the problem to solvet: float — the current timedt: float — the time stepM: float — the number of sub-time stepsnstep: int — the number of sub-time stepsz_gpu: slim.ScalarArrayDevice — the z solution fielduv_gpu: slim.ScalarArrayDevice — the uv solution fieldtracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fieldssolver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)Returns
end_t: float — the end time
- slim4.slim3d.iterate_expl_rk1(problem, t, dt, M, nstep, z_gpu, uv_gpu, tracers_gpu, solver_2d=None)
1-step vertically explicit runge-kutta. This scheme is very unstable and only first-order accurate. It should never be used for real-life simulations.
Parameters
problem: Problem — the problem to solvet: float — the current timedt: float — the time stepM: float — the number of sub-time stepsnstep: int — the number of sub-time stepsz_gpu: slim.ScalarArrayDevice — the z solution fielduv_gpu: slim.ScalarArrayDevice — the uv solution fieldtracers_gpu: List[slim.ScalarArrayDevice] — the tracers solution fieldssolver_2d: TemporalIterator | None — the 2d solver (default to order-2 3-steps low-storage RK)Returns
end_t: float — the end time
- slim4.slim3d.iterate_offline(problem, z, tracers, t, dt, nstep, nrk2d, implicit_steps)
Iterate over a slim4::slim3d::OfflineProblem.
Parameters
problem: OfflineProblem — the offline tracer problem to solvez: slim.ScalarArrayDevice — the vertical coordinate of the meshtracers: List[slim.ScalarArrayDevice] — the tracers solution fieldst: float — the current timedt: float — the time stepnstep: int — the number of sub-time stepsnrk2d: List[int] — the number of 2d sub time-steps for each 3d sub-stepimplicit_steps: List[bool] — indicates if each sub-step is implicitReturns
end_t: float — the end time