StateBase#

class fridom.framework.state_base.StateBase(mset: ModelSettingsBase, field_list: list | dict, is_spectral=False)[source]#

Bases: object

Base class for a model state.

Description#

A model state is a collection of fields that represent the state of the model. This class provides basic operations on the state, such as addition, subtraction, multiplication, division, as well as dot products, norms, and fourier transforms.

Parameters#

msetModelSettings

The model settings

field_listlist[FieldVariable] | dict[str, FieldVariable]

The list of fields that make up the state.

is_spectralbool

Whether the state is in spectral space. (default: False)

Attributes#

fieldsdict[str, FieldVariable]

A dictionary of fields that make up the state.

Methods#

fft() -> State

Calculate the Fourier transform of the state.

sync() -> None

Synchronize the state. (Exchange ghost cells)

project(p_vec: State, q_vec: State) -> State

Project the state on a (spectral) vector.

dot(other: State) -> FieldVariable

Calculate the dot product of the state with another state.

norm_l2() -> float

Calculate the L2 norm of the state.

norm_of_diff(other: State) -> float

Calculate the norm of the difference between two states.

__init__(mset: ModelSettingsBase, field_list: list | dict, is_spectral=False) None[source]#

Methods

__init__(mset, field_list[, is_spectral])

dot(other)

Calculate the dot product of the state with another state.

fft([padding])

Calculate the Fourier transform of the state.

from_netcdf(mset, path)

Read the state from a NetCDF file.

has_nan()

Check if the state contains NaN values.

ifft([padding])

Calculate the inverse Fourier transform of the state.

norm_l2()

Calculate the L2 norm of the state.

norm_of_diff(other)

The norm of the difference between two states.

project(p_vec, q_vec)

Project the state on a (spectral) vector.

sync()

Synchronize the state.

to_netcdf(path)

Write the state to a NetCDF file.

Attributes

arr_dict

Return the dictionary of arrays (not FieldVariables).

field_list

Return the list of fields.

grid

Return the grid of the model.

xr

State as xarray dataset

xrs

State of sliced domain as xarray dataset

Examples using fridom.framework.StateBase#

Barotropic Jet

Barotropic Jet

Reflecting Wave Package

Reflecting Wave Package

Convection and Closures

Convection and Closures

Rayleigh-Taylor Instability

Rayleigh-Taylor Instability

Rayleigh-Bénard Convection

Rayleigh-Bénard Convection

Single Internal Wave

Single Internal Wave

Dancing Eddies

Dancing Eddies

Symmetric Instability

Symmetric Instability

Tracers and Eddies

Tracers and Eddies

Barotropic Instability

Barotropic Instability
fft(padding=FFTPadding.NOPADDING) StateBase[source]#

Calculate the Fourier transform of the state. (forward and backward)

ifft(padding=FFTPadding.NOPADDING) StateBase[source]#

Calculate the inverse Fourier transform of the state.

sync() None[source]#

Synchronize the state. (Exchange ghost cells)

project(p_vec: StateBase, q_vec: StateBase) StateBase[source]#

Project the state on a (spectral) vector. $ z = q_vec * (z cdot p_vec) $

Arguments:

p_vec (State) : P-Vector. q_vec (State) : Q-Vector.

dot(other: StateBase) FieldVariable[source]#

Calculate the dot product of the state with another state.

Arguments:

other (State) : Other state (gets complex conjugated).

norm_l2() float[source]#

Calculate the L2 norm of the state.

$$ ||z||_2 = sqrt{ sum_{i} int z_i^2 dV } $$ where $z_i$ are the fields of the state.

Returns:

norm (float) : L2 norm of the state.

norm_of_diff(other: StateBase) float[source]#

The norm of the difference between two states.

\[2 \frac{||z - z'||_2}{||z||_2 + ||z'||_2}\]
has_nan() bool[source]#

Check if the state contains NaN values.

property xr#

State as xarray dataset

property xrs#

State of sliced domain as xarray dataset

property field_list: list#

Return the list of fields.

property arr_dict: dict[str, np.ndarray]#

Return the dictionary of arrays (not FieldVariables).

to_netcdf(path: str) None[source]#

Write the state to a NetCDF file.

classmethod from_netcdf(mset: ModelSettingsBase, path: str) None[source]#

Read the state from a NetCDF file.

property grid#

Return the grid of the model.