case

Physical parameters and forcings.

This module contains the Case class which is the one used to describe the parameters and the forcings of a model. It also contains the CaseTracable which is a variation of the first classe which works better with JAX specificities. This classes can be obtained by the prefix tunax.case. or directly by tunax..

ForcingType

Type that represent the different possible types of the forcings in Case.

alias of Tuple[float, float] | Callable[[float], float] | Callable[[float, float], float]

ForcingArrayType

Type that represent the different possible types of the forcings in CaseTracable.

alias of Tuple[float, float] | Float[Array, 'nz'] | Float[Array, 'nz nt']

class Case[source]

Physical parameters and forcings.

This class contains all the physical constants, and the constant forcings that definine an experience for the model. The forcings can be described as functions. The transformations from Case to CaseTracable is done when a model instance is created. The constructor takes all the attributes as parameters.

rho0

Default density of saltwater \([\text{kg} \cdot \text{m}^{-3}]\).

Type:

float, default=1024.

grav

Gravity acceleration \([\text{m} \cdot \text{s}^{-2}]\).

Type:

float, default=9.81

cp

Specific heat capacity of saltwater \([\text{J} \cdot \text{kg}^{-1} \cdot \text{K}^{-1}]\).

Type:

float, default=3985.

eos_tracers

Tracers used for the equation of state (the computation of the density). One of {'t', 's', 'ts’, 'b'}. - ‘t’: temperature - ‘s’: salinity - ‘ts’: temperature and salinity - ‘b’: buoyancy

Type:

str, default=’t’

alpha

Thermal expansion coefficient \([\text{K}^{-1}]\).

Type:

float, default=2e-4

beta

Salinity expansion coefficient \([\text{psu}^{-1}]\).

Type:

float, default=8e-4

t_rho_ref

Reference temperature for the equation of state (the computation of the density) \([° \text C]\).

Type:

float, default=0.

s_rho_ref

Reference salinity for the equation of state (the computation of the density) \([\text{psu}]\).

Type:

float, default=35.

do_pt

Compute or not a passive tracer.

Type:

bool, default=False

vkarmn

Von Kármán constant \([\text{dimensionless}]\).

Type:

float, default=0.384

fcor

Coriolis frequency at the water column \([\text{rad} \cdot \text{s}^{-1}]\).

Type:

float, default=0.

ustr_sfc

Zonal wind stress \([\text{m}^{2} \cdot \text{s}^{-2}]\).

Type:

float, default=0.

ustr_btm

Zonal current stress at the bottom \([\text{m}^{2} \cdot \text{s}^{-2}]\).

Type:

float, default=0.

vstr_sfc

Meridional wind stress \([\text{m}^{2} \cdot \text{s}^{-2}]\).

Type:

float, default=0.

vstr_btm

Meridional current stress at the bottom \([\text{m}^{2} \cdot \text{s}^{-2}]\).

Type:

float, default=0.

t_forcing

Description of the forcing of temperature (potentially no forcing if the variable is not activated i.e. if 't' is not in eos_tracers). There are 3 cases :

  • Border forcing : tuple of 2 floats, the first one is the forcing at the bottom and the second ont is the forcing at the top of the water column, the unit is in \([\text{K} \cdot \text{m} \cdot \text{s}^{-1}]\).

  • Deep constant forcing : function of signature float->float, the parameter is the depth and the ouput is the value of the forcing at this depth in \([\text{K} \cdot \text{s}^{-1}]\). The values of the functions represent the flux of the forcing (the derivative along the depth).)

  • Deep variable forcing : function of signature (float, float)->float, the parameters are the depth and the time and the ouput is the value of the forcing at this depth and this time in \([\text{K} \cdot \text{s}^{-1}]\). The values of the functions represent the flux of the forcing (the derivative along the depth).

Type:

tuple of 2 floats or a function, optionnal, default=None

s_forcing

Description of the forcing of salinity (potentially no forcing if the variable is not activated i.e. if 's' is not in eos_tracers). There are the 3 same cases as for the t_forcing, and the units are \([\text{psu} \cdot \text{m} \cdot \text{s}^{-1}]\) for the border forcing and \([\text{psu} \cdot \text{s}^{-1}]\) for the other ones.

Type:

tuple of 2 floats or a function, optionnal, default=None

b_forcing

Description of the forcing of buoyancy (potentially no forcing if the variable is not activated i.e. if 'b' is not in eos_tracers). There are the 3 same cases as for the t_forcing, and the units are \([\text{m} \cdot \text{s}^{-1}]\) for the border forcing and \([\text{s}^{-1}]\) for the other ones.

Type:

tuple of 2 floats or a function, optionnal, default=None

pt_forcing

Description of the forcing of passive tracer (potentially no forcing if the variable is not activated i.e. if do_pt is not set). There are the 3 same cases as for the t_forcing, and the units are \([\text{m} \cdot \text{s}^{-1}]\) for the border forcing and \([\text{s}^{-1}]\) for the other ones.

Type:

tuple of 2 floats or a function, optionnal, default=None

set_lat(lat)[source]

Set the Coriolis frequency from the latitude.

Parameters:

lat (float) – Latitude of the water column \([°]\).

Returns:

case – The self object with the the new value of fcor.

Return type:

Case

class CaseTracable[source]

Physical parameters and forcings tracable by JAX.

This class is similar to the Case one, but the function forcings are transformed in arrays so that the class is tracable by JAX which means that we can use jit() and grad() more freely. The constructor takes all the attributes as parameters.

rho0

cf. Case.rho0

Type:

float, default=1024.

grav

cf. Case.grav

Type:

float, default=9.81

cp

cf. Case.cp

Type:

float, default=3985.

eos_tracers

cf. Case.eos_tracers

Type:

str, default=’t’

alpha

cf. Case.alpha

Type:

float, default=2e-4

beta

cf. Case.beta

Type:

float, default=8e-4

t_rho_ref

cf. Case.t_rho_ref

Type:

float, default=0.

s_rho_ref

cf. Case.s_rho_ref

Type:

float, default=35.

do_pt

cf. Case.do_pt

Type:

bool, default=False

vkarmn

cf. Case.vkarmn

Type:

float, default=0.384

fcor

cf. Case.fcor

Type:

float, default=0.

ustr_sfc

cf. Case.ustr_sfc

Type:

float, default=0.

ustr_btm

cf. Case.ustr_btm

Type:

float, default=0.

vstr_sfc

cf. Case.vstr_sfc

Type:

float, default=0.

vstr_btm

cf. Case.vstr_btm

Type:

float, default=0.

t_forcing

Description of the temperature forcing cf. Case.t_forcing, the type depends on the forcing type :

  • Border forcing : tuple of 2 floats, the first one is the forcing at the bottom and the second one is the forcing at the top of the water column, the unit is in \([\text{K} \cdot \text{m} \cdot \text{s}^{-1}]\).

  • Deep constant forcing : array of shape (nz) : the value of the forcing function on the geometrical Grid of the model. The values represent the forcing flux, which is for each cell the difference between the forcing at the top of the cell and the forcing at bottom.

  • Deep variable forcing : array of shape (nz, nt) : the value of the forcing function on the geometrical Grid and the different iteration times of the model. As for deep constant forcing, the values represent the flux of the forcing at every time.

Type:

tuple of 2 floats or Array (nz) or (nz, nt), optionnal, default=None

s_forcing

Same as t_forcing for Salinity.

Type:

tuple of 2 floats or Array (nz) or (nz, nt), optionnal, default=None

b_forcing

Same as t_forcing for buoyancy.

Type:

tuple of 2 floats or Array (nz) or (nz, nt), optionnal, default=None

pt_forcing

Same as t_forcing for passive tracer.

Type:

tuple of 2 floats or Array (nz) or (nz, nt), optionnal, default=None

t_forcing_type

Description of the type of temperature forcing : 'borders' for border forcing, 'constant' for deep constant forcing and 'variable' for deep variable forcing

Type:

str, optionnal, default=None

s_forcing_type

Same as t_forcing_type for salinity.

Type:

str, optionnal, default=None

b_forcing_type

Same as t_forcing_type for buoyancy.

Type:

str, optionnal, default=None

pt_forcing_type

Same as t_forcing_type for passive tracer.

Type:

str, optionnal, default=None

tra_promote_borders_constant(tra, grid)[source]

Promote the dimension of a forcing from borders to constant.

It can be use to apply vmap() on SingleColumnModel for batch computing. The input CaseTracable instance should have a borders forcing type and the ouput instance will have deep constant forcing type.

Parameters:
  • tra (str) – Name of the tracer variable of the concerned forcing. One of {'t', 's', 'b’, 'pt’}.

  • grid (Grid) – Spatial grid to compute the constant forcing on.

Returns:

case_tracable – The self object with the promoted forcing.

Return type:

CaseTracable

tra_promote_borders_variable(tra, grid, nt)[source]

Promote the dimension of a forcing from borders to variable.

It can be use to apply vmap() on SingleColumnModel for batch computing. The input CaseTracable instance should have a borders forcing type and the ouput instance will have deep variable forcing type.

Parameters:
  • tra (str) – Name of the tracer variable of the concerned forcing. One of {'t', 's', 'b’, 'pt’}.

  • grid (Grid) – Spatial grid to compute the constant forcing on.

  • nt (int) – Number of integration iterations of the model.

Returns:

case_tracable – The self object with the promoted forcing.

Return type:

CaseTracable

tra_promote_constant_variable(tra, nt)[source]

Promote the dimension of a forcing from borders to constant.

It can be use to apply vmap() on SingleColumnModel for batch computing. The input CaseTracable instance should have a constant forcing type and the ouput instance will have deep variable forcing type.

Parameters:
  • tra (str) – Name of the tracer variable of the concerned forcing. One of {'t', 's', 'b', 'pt’}.

  • grid (Grid) – Spatial grid to compute the constant forcing on.

  • nt (int) – Number of integration iterations of the model.

Returns:

case_tracable – The self object with the promoted forcing.

Return type:

CaseTracable