transiflow.Discretization

class Discretization(parameters, nx, ny, nz=1, dim=None, dof=None, x=None, y=None, z=None, boundary_conditions=None)

Bases: object

Finite volume discretization of the incompressible Navier-Stokes equations on a (possibly non-uniform) Arakawa C-grid. After discretization, the incompressible Navier-Stokes equations can be writen as a system of ordinary differential equations with algebraic constraints (DAE) of the form

\[M(p) \frac{\d u}{\d t} = F(u, p)\]

where $u$ is a state vector, $p$ is a set of parameters, $M(p)$ is a singular mass matrix, and $F(u, p)$ is the non-linear function including the forcing that is applied to the system.

The variables in the state vector $u$ are ordered according to

[u, v, w, p, T, S, u, v, w, p, T, S, u, v, w, p, T, S, ...]

at positions

(0, 0, 0), (1, 0, 0), ..., (0, 1, 0), ..., (0, 0, 1), ...

Velocities u, v, w are staggered according to the C-grid definition, pressure p, temperature T and salinity S are defined in the centers of the grid cells. Variables are left out if they are not relevant to the problem. A 2D lid-driven cavity, for instance, only has [u, v, p].

Parameters:
parametersdict

Key-value pairs describing parameters of the model, for instance the Renolds number and the problem type. Possible values can be found in Problem definitions.

nxint

Grid size in the x direction.

nyint

Grid size in the y direction.

nzint, optional

Grid size in the z direction. 1 for 2-dimensional problems. This is the default.

dimint, optional

Physical dimension of the problem. In case this is set to 2, w is not referenced in the state vector. The default is based on the value of nz.

dofint, optional

Degrees of freedom for this problem. This should be set to dim plus 1 for each of pressure, temperature and salinity, if they are required for your problem. For example a 3D differentially heated cavity has dof = 3 + 1 + 1 = 5.

xarray_like, optional

Coordinate vector in the x direction.

yarray_like, optional

Coordinate vector in the y direction.

zarray_like, optional

Coordinate vector in the z direction.

boundary_conditionsfunction, optional

User-supplied function that implements the boundary conditions. It is called as boundary_conditions(bc, atom) where bc is an instance of the BoundaryConditions class.

Notes

All discretizations are defined on atoms which for every grid cell define the contributions of neighbouring grid cells. In 3D this means 27 contributions from neighbouring grid cells are defined for every grid cell. For instance

atom[i, j, k, :, :, 1, 1, 1]

contains the contribution from the current cell at point (i, j, k) and

atom[i, j, k, :, :, 1, 0, 1]

contains the contribution from the cell south of the current one. A discretization of $u_{xx}$ on a uniform grid in 1D could be defined by

atom[i, j, k, :, :, 0, 1, 1] =  1 / dx
atom[i, j, k, :, :, 1, 1, 1] = -2 / dx
atom[i, j, k, :, :, 2, 1, 1] =  1 / dx

where we note that the mass matrix is also scaled by dx.

The remaining two indices, denoted by (:, :) above, contain the variable that is being used and the location of the equation that is being discretized. If we work in 2D, and we compute $p_x$ located in the first equation (as in the standard formulation of the incompressible Navier-Stokes equations), then the contribution is stored in

atom[:, :, :, 0, 2, :, :, :]

where the 0 comes from the first equation, 2 comes from the pressure.

get_coordinate_vector(start, end, nx)

Get a coordinate vector according to the set parameters.

Parameters:
startfloat

Start of the domain

endfloat

End of the domain

nxint

Amount of steps

get_parameter(name, default=0)

Get a parameter from self.parameters.

Parameters:
namestr

Name of the parameter

defaultAny, optional

Default return value if the parameter is not found in self.parameters. The default value is 0.

Returns:
The value of the parameter
jacobian(state)

Compute the Jacobian matrix $J(u, p)$ of the right-hand side of the DAE. That is the Jacobian matrix of $F(u, p)$ in

\[M(p) \frac{\d u}{\d t} = F(u, p)\]
Parameters:
statearray_like

State $u$ at which to evaluate $J(u, p)$

Returns:
jacCrsMatrix

The matrix $J(u, p)$ in CSR format

mass_matrix()

Compute the mass matrix of the DAE. That is the mass matrix $M(p)$ in

\[M(p) \frac{\d u}{\d t} = F(u, p)\]
Returns:
massCrsMatrix

The matrix $M(p)$ in CSR format

rhs(state)

Compute the right-hand side of the DAE. That is the right-hand side $F(u, p)$ in

\[M(p) \frac{\d u}{\d t} = F(u, p)\]
Parameters:
statearray_like

State $u$ at which to evaluate $F(u, p)$

Returns:
rhsarray_like

The value of $F(u, p)$

set_parameter(name, value)

Set a parameter in self.parameters. Changing a value in self.parameters will make us recompute the linear part of the equation.

Parameters:
namestr

Name of the parameter

valueAny

Value of the parameter. Generally a floating point value

\[\]