StateBase#
- class fridom.framework.state_base.StateBase(mset: ModelSettingsBase, field_list: list | dict, is_spectral=False)[source]#
Bases:
objectBase 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.
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
Return the dictionary of arrays (not FieldVariables).
Return the list of fields.
Return the grid of the model.
State as xarray dataset
State of sliced domain as xarray dataset
Examples using
fridom.framework.StateBase#- 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.
- 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}\]
- 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).
- classmethod from_netcdf(mset: ModelSettingsBase, path: str) None[source]#
Read the state from a NetCDF file.
- property grid#
Return the grid of the model.