CoherentEddy#
- class fridom.nonhydro.initial_conditions.coherent_eddy.CoherentEddy(mset: ModelSettings, pos_x: float = 0.5, pos_y: float = 0.5, width: float = 0.1, amplitude: float = 1, gauss_field: str = 'streamfunction')[source]#
Bases:
StateCoherent barotropic eddy with Gaussian shape.
Description#
There are two versions of the coherent eddy. In the first version, the streamfunction of the eddy is given by an gaussian function:
\[\psi = A \exp\left( -\frac{(x - p_x L_x)^2 + (y - p_y L_y)^2}{(\sigma L_x)^2}\right)\]where \(A\) is the amplitude, \((p_x, p_y)\) is the relative position of the eddy, \((\sigma L_x)\) is the width of the eddy, and \(L_x, L_y\) are the domain sizes in the x and y directions. The velocity field is given by:
\[u = \partial_y \psi, \quad v = -\partial_x \psi\]The second version of the coherent eddy prescribes the horizontal velocity as a gaussian function:
\[\zeta = A \exp\left( -\frac{(x - p_x L_x)^2 + (y - p_y L_y)^2}{(\sigma L_x)^2}\right)\]Then the streamfunction is computed in spectral space:
\[\hat{\psi} = \frac{\hat{\zeta}}{k_x^2 + k_y^2}\]Parameters#
- msetModelSettings
The model settings.
- pos_xfloat, optional (default=0.5)
The relative position of the eddy in the x-direction.
- pos_yfloat, optional (default=0.5)
The relative position of the eddy in the y-direction.
- widthfloat, optional (default=0.1)
The relative width of the eddy. (relative to the domain size in the x-direction)
- amplitudefloat, optional (default=1)
The amplitude of the eddy. When the amplitude negative, the eddy rotates clockwise. Otherwise, it rotates counterclockwise.
- gauss_fieldstr, optional (default=’vorticity’)
The field that is prescribed as a gaussian function. It can be either ‘vorticity’ or ‘streamfunction’.
Examples#
This setup creates a coherent eddy in an scaled setup with varying coriolis parameter. The eddy moves in positive x and negative y direction and hits the northern wall.
import fridom.nonhydro as nh import numpy as np grid = nh.grid.cartesian.Grid( N=(128, 128, 1), L=(3, 3, 1), periodic_bounds=(True, False, False)) mset = nh.ModelSettings(grid=grid, f0=1, beta=0.2) mset.time_stepper.dt = 0.004 mset.setup() model = nh.Model(mset) model.z = nh.initial_conditions.CoherentEddy(mset, width=0.15) model.run(runlen=np.timedelta64(20, 's'))
The eddy becomes a rossby wave when either the amplitude is very small or the advection term is disabled:
mset.tendencies.advection.disable()
- __init__(mset: ModelSettings, pos_x: float = 0.5, pos_y: float = 0.5, width: float = 0.1, amplitude: float = 1, gauss_field: str = 'streamfunction') None[source]#
Methods
__init__(mset[, pos_x, pos_y, width, ...])abs()Map the field by taking the absolute value (\(|f|\)).
apply_elementwise(vector_field, op)Apply an operation elementwise to the vector field.
apply_water_mask()Apply a water mask to the field.
conj()Compute the complex conjugate.
cumulative_integral(axis[, direction])Compute the cumulative integral along an axis.
diff(axis[, order])Compute the partial derivative along an axis.
div()Compute the divergence.
dot(other)Compute the dot product with another field.
extend(topo)Extend the field in the specified directions.
fft([padding])Perform a Fast Fourier Transform (FFT) on the field.
from_netcdf(mset, path)Create a field from a NetCDF file.
from_xarray(mset, ds)Create a field from an xarray object.
grad([axes])Compute the gradient.
has_nan()Check if the field contains NaN values.
ifft([padding])Perform an Inverse Fast Fourier Transform (IFFT) on the field.
integrate([axes])Global integral of the Field in specified axes.
laplacian([axes])Compute the Laplacian.
max([axes])Maximum value of the Field over the whole domain.
mean([axes])Global mean of the Field in specified axes.
min([axes])Minimum value of the Field over the whole domain.
norm_l2()Calculate the L2 norm of the field.
norm_of_diff(other)Norm of difference between two vector fields.
project(p_vec, q_vec)Project a Vector Field onto a (spectral) vector.
set_random([seed])Set the field to random values.
sum([axes])Sum of the Field over the whole domain in the specified axes.
sync()Synchronize the field across all MPI ranks and apply boundary conditions.
to_netcdf(path)Save the field to a NetCDF file.
Attributes
bBuoyancy.
cflThe CFL number.
ekinThe kinetic energy.
epotThe potential energy.
etotThe total energy.
field_listThe list of scalar fields.
fieldsThe dictionary of scalar fields.
gridThe grid object.
infoDictionary with information about the field.
is_constantFlag indicating whether the field is constant.
is_spectralFlag indicating whether the field is in spectral space.
linear_pot_vortLinearized potential vorticity.
local_rossby_numberLocal Rossby number.
msetThe model settings.
pot_vortScaled potential vorticity field.
rel_vortThe relative vorticity.
rel_vort_xX-component of the relative vorticity.
rel_vort_yY-component of the relative vorticity.
rel_vort_zZ-component of the relative vorticity (horizontal vorticity).
tracersThe tracer fields.
uVelocity in the x-direction.
vVelocity in the y-direction.
vector_dimThe vector dimension.
velocityThe velocity vector field.
wVelocity in the z-direction.
xrThe xarray representation of the field.
xrsConvert a slice of the field to an xarray object.
Examples using
fridom.nonhydro.initial_conditions.CoherentEddy#