Tensors module

Module holding the model’s tendencies tensor encoding each of their additive terms.

qgs tensor module

This module computes and holds the tensors representing the tendencies of the model’s equations.

TODO: Add a list of the different tensor available

class qgs.tensors.qgtensor.QgsTensor(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: object

qgs tendencies tensor class.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

sparse.COO(float)

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

sparse.COO(float)

compute_tensor()[source]

Routine to compute the tensor.

static jacobian_from_tensor(tensor)[source]

Function to compute the Jacobian tensor.

Parameters:

tensor (sparse.COO) – The qgs tensor.

Returns:

The Jacobian tensor.

Return type:

sparse.COO

load_from_file(filename, **kwargs)[source]

Function to load previously a saved tensor object with the method save_to_file().

Parameters:
  • filename (str) – The file name where the tensor object was saved.

  • kwargs (dict) – Keyword arguments to pass to the pickle module method.

print_jacobian_tensor(tensor_name='')[source]

Routine to print the Jacobian tensor.

Parameters:

tensor_name (str, optional) – Specify the name to print beside the values of the tensor. Default to QgsTensorJacobian.

print_jacobian_tensor_to_file(filename, tensor_name='')[source]

Routine to print the Jacobian tensor to a file.

Parameters:
  • filename (str) – The filename where to print the tensor.

  • tensor_name (str, optional) – Specify the name to print beside the values of the tensor. Default to QgsTensorJacobian.

print_tensor(tensor_name='')[source]

Routine to print the tensor.

Parameters:

tensor_name (str, optional) – Specify the name to print beside the values of the tensor. Default to QgsTensor.

print_tensor_to_file(filename, tensor_name='')[source]

Routine to print the tensor to a file.

Parameters:
  • filename (str) – The filename where to print the tensor.

  • tensor_name (str, optional) – Specify the name to print beside the values of the tensor. Default to QgsTensor.

save_to_file(filename, **kwargs)[source]

Function to save the tensor object to a file with the pickle module.

Parameters:
  • filename (str) – The file name where to save the tensor object.

  • kwargs (dict) – Keyword arguments to pass to the pickle module method.

static simplify_tensor(tensor)[source]

Routine that simplifies the component of a tensor \(\mathcal{T}\). For each index \(i\), it upper-triangularizes the tensor \(\mathcal{T}_{i,\ldots}\) for all the subsequent indices.

Parameters:

tensor (sparse.COO) – The tensor to simplify.

Returns:

The upper-triangularized tensor.

Return type:

sparse.COO

class qgs.tensors.qgtensor.QgsTensorDynamicT(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: QgsTensor

qgs dynamical temperature first order (linear) tendencies tensor class.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

sparse.COO(float)

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

sparse.COO(float)

compute_tensor()[source]

Routine to compute the tensor.

class qgs.tensors.qgtensor.QgsTensorT4(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: QgsTensorDynamicT

qgs \(T^4\) tendencies tensor class. Implies dynamical zeroth-order temperature.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

sparse.COO(float)

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

sparse.COO(float)

qgs atmospheric thermodynamic tensor module

This module computes and holds the tensors representing the atmospheric thermodynamic tendencies of the model’s equations needed to compute the vertical wind velocity \(\omega\).

TODO: Add a list of the different tensor available

class qgs.tensors.atmo_thermo_tensor.AtmoThermoTensor(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: QgsTensor

Atmospheric thermodynamic tendencies tensor class.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

sparse.COO(float)

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

sparse.COO(float)

class qgs.tensors.atmo_thermo_tensor.AtmoThermoTensorDynamicT(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: AtmoThermoTensor

Atmospheric thermodynamic dynamical temperature first order (linear) tendencies tensor class.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

sparse.COO(float)

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

sparse.COO(float)

compute_tensor()[source]

Routine to compute the tensor.

class qgs.tensors.atmo_thermo_tensor.AtmoThermoTensorT4(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: AtmoThermoTensorDynamicT

Atmospheric thermodynamic \(T^4\) tendencies tensor class. Implies dynamical zeroth-order temperature.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

sparse.COO(float)

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

sparse.COO(float)

symbolic qgs tensor module

This module computes and holds the symbolic representation of the tensors representing the tendencies of the model’s equations.

class qgs.tensors.symbolic_qgtensor.SymbolicQgsTensor(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: object

Symbolic qgs tendencies tensor class.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None. The inner product is returned in symbolic or numeric form.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None. The inner product is returned in symbolic or numeric form.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None. The inner product is returned in symbolic or numeric form.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

ImmutableSparseNDimArray

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

ImmutableSparseNDimArray

compute_tensor()[source]

Routine to compute the tensor.

static jacobian_from_dict(dic)[source]

Calculates the Jacobian from the qgs tensor

Parameters:

dic (dict) – dictionary of tendencies of the model

Returns:

dic_jac – Jacobian tensor stored in a dictionary

Return type:

dict

print_tensor(tensor=None, dict_opp=True, tol=1e-10)[source]

Print the non-zero coordinates of values of the tensor of the model tendencies

Parameters:
  • tensor (dict(~sympy.core.expr.Expr or float) or ~sympy.tensor.array.ImmutableSparseNDimArray or None) –

    Tensor of model tendencies, either as

    • a dictionary with keys of non-zero coordinates, and values of Sympy expressions or floats

    • or a sparse Sympy tensor

    If None, defaults to the stored tensor. Defaults to None.

  • dict_opp (bool) – If True, returns the unsimplified symbolic expressions, if False the simplified expressions are returned.

  • tol (float) – The tolerance to allow for numerical errors when finding non-zero values.

static remove_dic_zeros(dic)[source]

Removes zero values from dictionary

Parameters:

tensor (dict) – dictionary which could include 0 in values

Returns:

ten_out – dictionary with same keys and values as input, but keys with value of 0 are removed

Return type:

dict

save_to_file(filename, **kwargs)[source]

Function to save the tensor object to a file with the pickle module.

Parameters:
  • filename (str) – The file name where to save the tensor object.

  • kwargs (dict) – Keyword arguments to pass to the pickle module method.

static simplify_dict(dic)[source]

calculates the upper triangular tensor of a given tensor, stored in dictionary

Parameters:

dic (dict) – dictionary of tendencies of the model

Returns:

dic_upp – Upper triangular tensor, stored as a tensor where the keys are the coordinates of the corresponding value.

Return type:

dict

sub_tensor(tensor=None, continuation_variables=None)[source]

Uses sympy substitution to convert the symbolic tensor or a symbolic dictionary to a numerical one.

Parameters:
  • tensor (dict(Expr or float) or ImmutableSparseNDimArray) –

    Tensor of model tendencies, either as

    • a dictionary with keys of non-zero coordinates, and values of Sympy expressions or floats

    • or a sparse Sympy tensor

  • continuation_variables (list(Parameter, ScalingParameter or ParametersArray) or None) – Variables which remain symbolic, all other variables are substituted with numerical values. If None all variables are substituted.

Returns:

ten_out – Dictionary of the substituted tensor of the model tendencies, with coordinates and numerical values

Return type:

dict(float)

class qgs.tensors.symbolic_qgtensor.SymbolicQgsTensorDynamicT(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: SymbolicQgsTensor

qgs dynamical temperature first order (linear) symbolic tendencies tensor class.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

ImmutableSparseNDimArray

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

ImmutableSparseNDimArray

compute_tensor()[source]

Routine to compute the tensor.

class qgs.tensors.symbolic_qgtensor.SymbolicQgsTensorT4(params=None, atmospheric_inner_products=None, oceanic_inner_products=None, ground_inner_products=None)[source]

Bases: SymbolicQgsTensor

qgs dynamical temperature first order (linear) symbolic tendencies tensor class.

Parameters:
  • params (None or QgParams, optional) – The models parameters to configure the tensor. None to initialize an empty tensor. Default to None.

  • atmospheric_inner_products (None or AtmosphericInnerProducts, optional) – The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

  • oceanic_inner_products (None or OceanicInnerProducts, optional) – The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

  • ground_inner_products (None or GroundInnerProducts, optional) – The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

params

The models parameters used to configure the tensor. None for an empty tensor.

Type:

None or QgParams

atmospheric_inner_products

The inner products of the atmospheric basis functions on which the model’s PDE atmospheric equations are projected. If None, disable the atmospheric tendencies. Default to None.

Type:

None or AtmosphericInnerProducts

oceanic_inner_products

The inner products of the oceanic basis functions on which the model’s PDE oceanic equations are projected. If None, disable the oceanic tendencies. Default to None.

Type:

None or OceanicInnerProducts

ground_inner_products

The inner products of the ground basis functions on which the model’s PDE ground equations are projected. If None, disable the ground tendencies. Default to None.

Type:

None or GroundInnerProducts

tensor

The tensor \(\mathcal{T}_{i,j,k}\) \(i\)-th components.

Type:

ImmutableSparseNDimArray

jacobian_tensor

The jacobian tensor \(\mathcal{T}_{i,j,k} + \mathcal{T}_{i,k,j}\) \(i\)-th components.

Type:

ImmutableSparseNDimArray

compute_tensor()[source]

Routine to compute the tensor.