ShallowWaters.ArakawaHsuVars
— TypeArakawaHsu variables collected in a struct.
ShallowWaters.ArakawaHsuVars
— MethodGenerator function for ArakawaHsu VarCollection.
ShallowWaters.BernoulliVars
— TypeBernoulli variables collected in a struct.
ShallowWaters.BernoulliVars
— MethodGenerator function for Bernoulli VarCollection.
ShallowWaters.BottomdragVars
— TypeBottomdrag variables collected in a struct.
ShallowWaters.BottomdragVars
— MethodGenerator function for Bottomdrag VarCollection.
ShallowWaters.Constants
— MethodGenerator function for the mutable struct Constants.
ShallowWaters.Grid
— MethodGenerator function for the Grid struct.
ShallowWaters.LaplaceVars
— TypeLaplace variables collected in a struct.
ShallowWaters.LaplaceVars
— MethodGenerator function for Laplace VarCollection.
ShallowWaters.NcFiles
— MethodGenerator function for "empty" NcFiles struct.
ShallowWaters.NcFiles
— MethodGenerator function for NcFiles struct, creating the underlying netCDF files.
ShallowWaters.Parameter
— TypeCreates a Parameter struct with following options and default values
T=Float32 # number format
Tprog=T # number format for prognostic variables
Tcomm=Tprog # number format for ghost-point copies
# DOMAIN RESOLUTION AND RATIO
nx::Int=100 # number of grid cells in x-direction
Lx::Real=2000e3 # length of the domain in x-direction [m]
L_ratio::Real=2 # Domain aspect ratio of Lx/Ly
# PHYSICAL CONSTANTS
g::Real=10. # gravitational acceleration [m/s]
H::Real=500. # layer thickness at rest [m]
ρ::Real=1e3 # water density [kg/m^3]
ϕ::Real=45. # central latitude of the domain (for coriolis) [°]
ω::Real=2π/(24*3600) # Earth's angular frequency [s^-1]
R::Real=6.371e6 # Earth's radius [m]
# WIND FORCING OPTIONS
wind_forcing_x::String="channel" # "channel", "double_gyre", "shear","constant" or "none"
wind_forcing_y::String="constant" # "channel", "double_gyre", "shear","constant" or "none"
Fx0::Real=0.12 # wind stress strength [Pa] in x-direction
Fy0::Real=0.0 # wind stress strength [Pa] in y-direction
seasonal_wind_x::Bool=false # Change the wind stress with a sine of frequency ωFx,ωFy
seasonal_wind_y::Bool=false # same for y-component
ωFx::Real=1.0 # frequency [1/year] for x component
ωFy::Real=1.0 # frequency [1/year] for y component
# BOTTOM TOPOGRAPHY OPTIONS
topography::String="ridge" # "ridge", "seamount", "flat", "ridges", "bathtub"
topo_height::Real=50. # height of seamount [m]
topo_width::Real=300e3 # horizontal scale [m] of the seamount
# SURFACE RELAXATION
surface_relax::Bool=false # yes?
t_relax::Real=100. # time scale of the relaxation [days]
η_refh::Real=5. # height difference [m] of the interface relaxation profile
η_refw::Real=50e3 # width [m] of the tangent used for the interface relaxation
# SURFACE FORCING
surface_forcing::Bool=false # yes?
ωFη::Real=1.0 # frequency [1/year] for surfance forcing
A::Real=3e-5 # Amplitude [m/s]
ϕk::Real=ϕ # Central latitude of Kelvin wave pumping
wk::Real=10e3 # width [m] in y of Gaussian used for surface forcing
# TIME STEPPING OPTIONS
time_scheme::String="RK" # Runge-Kutta ("RK") or strong-stability preserving RK ("SSPRK2","SSPRK3")
RKo::Int=4 # Order of the RK time stepping scheme (2, 3 or 4)
RKs::Int=2 # Number of stages for SSPRK2
cfl::Real=1.0 # CFL number (1.0 recommended for RK4, 0.6 for RK3)
Ndays::Real=10.0 # number of days to integrate for
nstep_diff::Int=1 # diffusive part every nstep_diff time steps.
nstep_advcor::Int=0 # advection and coriolis update every nstep_advcor time steps.
# 0 means it is included in every RK4 substep
# BOUNDARY CONDITION OPTIONS
bc::String="periodic" # "periodic" or anything else for nonperiodic
α::Real=2. # lateral boundary condition parameter
# 0 free-slip, 0<α<2 partial-slip, 2 no-slip
# MOMENTUM ADVECTION OPTIONS
adv_scheme::String="ArakawaHsu" # "Sadourny" or "ArakawaHsu"
dynamics::String="nonlinear" # "linear" or "nonlinear"
# BOTTOM FRICTION OPTIONS
bottom_drag::String="quadratic" # "linear", "quadratic" or "none"
cD::Real=1e-5 # bottom drag coefficient [dimensionless] for quadratic
τD::Real=300. # bottom drag coefficient [days] for linear
# DIFFUSION OPTIONS
diffusion::String="constant" # "Smagorinsky" or "constant", biharmonic in both cases
νB::Real=500.0 # [m^2/s] scaling constant for constant biharmonic diffusion
cSmag::Real=0.15 # Smagorinsky coefficient [dimensionless]
# TRACER ADVECTION
tracer_advection::Bool=true # yes?
tracer_relaxation::Bool=false # yes?
tracer_consumption::Bool=false # yes?
tracer_pumping::Bool=false # yes?
injection_region::String="west" # "west", "south", "rect" or "flat"
sst_initial::String="south" # "west", "south", "rect", "flat" or "restart"
sst_rect_coords::Array{Float64,1}=[0.,0.15,0.,1.0]
# (x0,x1,y0,y1) are the size of the rectangle in [0,1]
Uadv::Real=0.25 # Velocity scale [m/s] for tracer advection
SSTmax::Real=1. # tracer (sea surface temperature) max for restoring
SSTmin::Real=0. # tracer (sea surface temperature) min for restoring
τSST::Real=500. # tracer restoring time scale [days]
jSST::Real=365. # tracer consumption [days]
SST_λ0::Real=222e3 # [m] transition position of relaxation timescale
SST_λs::Real=111e3 # [m] transition width of relaxation timescale
SST_γ0::Real=8.35 # [days] injection time scale
SSTw::Real=5e3 # width [m] of the tangent used for the IC and interface relaxation
SSTϕ::Real=0.5 # latitude/longitude fraction ∈ [0,1] of sst edge
# OUTPUT OPTIONS
output::Bool=false # netcdf output?
output_vars::Array{String,1}=["u","v","η","sst"] # which variables to output? "du","dv","dη" also allowed
output_dt::Real=6 # output time step [hours]
outpath::String=pwd() # path to output folder
# INITIAL CONDITIONS
initial_cond::String="rest" # "rest" or "ncfile" for restart from file
initpath::String=outpath # folder where to pick the restart files from
init_run_id::Int=0 # run id for restart from run number
init_starti::Int=-1 # timestep to start from (-1 meaning last)
get_id_mode::String="continue" # How to determine the run id: "continue" or "fill"
run_id::Int=-1 # Output with a specific run id
init_interpolation::Bool=true # Interpolate the initial conditions in case grids don't match?
ShallowWaters.PrognosticVars
— TypeP = ProgVars{T}(u,v,η,sst)
Struct containing the prognostic variables u,v,η and sst.
ShallowWaters.PrognosticVars
— MethodZero generator function for Grid G as argument.
ShallowWaters.RungeKuttaVars
— TypeRunge Kutta time stepping scheme diagnostic cariables collected in a struct.
ShallowWaters.RungeKuttaVars
— MethodGenerator function for RungeKutta VarCollection.
ShallowWaters.SSPRK3coeff
— TypeCoefficients for strong stability-preserving Runge-Kutta 3rd order. From: KETCHESON, LOĆZI, AND PARSANI, 2014. INTERNAL ERROR PROPAGATION IN EXPLICIT RUNGE–KUTTA METHODS, SIAM J NUMER ANAL 52/5. DOI:10.1137/130936245
ShallowWaters.SSPRK3coeff
— MethodGenerator function for a SSPRK3coeff struct.
ShallowWaters.SemiLagrangeVars
— TypeSemiLagrange variables collected in a struct.
ShallowWaters.SemiLagrangeVars
— MethodGenerator function for SemiLagrange VarCollection.
ShallowWaters.SmagorinskyVars
— TypeSmagorinsky variables collected in a struct.
ShallowWaters.SmagorinskyVars
— MethodGenerator function for Smagorinsky VarCollection.
ShallowWaters.TendencyVars
— TypeTendencies collected in a struct.
ShallowWaters.TendencyVars
— MethodGenerator function for Tendencies VarCollection.
ShallowWaters.VolumeFluxVars
— TypeVolumeFluxes collected in a struct.
ShallowWaters.VolumeFluxVars
— MethodGenerator function for VolumeFluxes VarCollection.
ShallowWaters.VorticityVars
— TypeVorticity variables collected in a struct.
ShallowWaters.VorticityVars
— MethodGenerator function for Vorticity VarCollection.
Base.convert
— MethodConvert function for two arrays, X1, X2, in case their eltypes differ. Convert every element from X1 and store it in X2.
Base.convert
— MethodConvert function for two arrays, X1, X2, in case their eltypes are identical. Just pass X1, such that X2 is pointed to the same place in memory.
ShallowWaters.AHα!
— MethodLinear combination α of potential voriticity q according to the energy and enstrophy conserving scheme of Arakawa and Hsu, 1990
ShallowWaters.AHβ!
— MethodLinear combination δ of potential voriticity q according to the energy and enstrophy conserving scheme of Arakawa and Hsu, 1990
ShallowWaters.AHγ!
— MethodLinear combination γ of potential voriticity q according to the energy and enstrophy conserving scheme of Arakawa and Hsu, 1990
ShallowWaters.AHδ!
— MethodLinear combination β of potential voriticity q according to the energy and enstrophy conserving scheme of Arakawa and Hsu, 1990
ShallowWaters.ChannelWind
— MethodReturns the constant forcing matrices Fx,Fy that vary only meriodionally/zonally as a cosine with strongest forcing in the middle and vanishing forcing at boundaries.
ShallowWaters.ConstantWind
— MethodReturns constant in in space forcing matrices Fx,Fy.
ShallowWaters.DoubleGyreWind
— MethodReturns the constant forcing matrices Fx,Fy that vary only meriodionally/zonally with a superposition of sin & cos for a double gyre circulation. See Cooper&Zanna 2015 or Kloewer et al 2018.
ShallowWaters.FlatBottom
— MethodReturns a matrix of constant water depth H.
ShallowWaters.Ftime
— MethodTime evolution of forcing.
ShallowWaters.InterfaceRelaxation
— MethodReturns a reference state for Newtonian cooling/surface relaxation shaped as a hyperbolic tangent to force the continuity equation.
ShallowWaters.Ix!
— MethodLinear interpolation of a variable u in the x-direction. m,n = size(ux) must be m+1,n = size(u).
ShallowWaters.Ixy!
— MethodBilinear interpolation a variable u in x and y-direction. m,n = size(uxy) must be m+1,n+1 = size(u).
ShallowWaters.Iy!
— MethodLinear interpolation a variable u in the y-direction. m,n = size(uy) must be m,n+1 = size(u).
ShallowWaters.KelvinPump
— MethodReturns Kelvin wave pumping forcing of the continuity equation.
ShallowWaters.NoWind
— MethodReturns constant in in space forcing matrices Fx,Fy.
ShallowWaters.PV!
— MethodPotential vorticity calculated as q = (f + ∂v/∂x - ∂u/∂y)/h.
ShallowWaters.PV_ArakawaHsu!
— MethodAdvection of potential vorticity qhv,qhu as in Arakawa and Hsu, 1990 Energy and enstrophy conserving (in the limit of non-divergent mass flux) scheme with τ = 0.
ShallowWaters.PV_Sadourny!
— MethodAdvection of potential vorticity qhv,qhu as in Sadourny, 1975 enstrophy conserving scheme.
ShallowWaters.PVadvection!
— MethodTransit function to call the specified advection scheme.
ShallowWaters.Ridge
— MethodReturns a matrix of water depth for the whole domain that contains a meridional Gaussian ridge in the middle. Water depth, heigth and width of the ridge are adjusted with the constants waterdepth, topofeatheight and topofeat_width.
ShallowWaters.Ridges
— MethodSame as Ridge() but for 3 ridges at 1/4,1/2,3/4 of the domain.
ShallowWaters.RunModel
— Methodu,v,η,sst = RunModel()
runs ShallowWaters with default parameters as defined in src/DefaultParameters.jl
Examples
julia> u,v,η,sst = RunModel(Float64,nx=200,output=true)
ShallowWaters.Seamount
— MethodReturns a matrix of water depth for the whole domain that contains a Gaussian seamount in the middle. Water depth, heigth and width of the seamount are adjusted with the constants H, topofeatheight and topofeatwidth.
ShallowWaters.ShearWind
— MethodReturns the constant forcing matrices Fx,Fy that vary only meriodionally/zonally as a hyperbolic tangent with strongest shear in the middle.
ShallowWaters.UVfluxes!
— MethodCalculate the mass/volume fluxes U,V from u,v,η.
ShallowWaters.Uflux!
— MethodZonal mass flux U = uh.
ShallowWaters.Vflux!
— MethodMeridional mass flux V = vh.
ShallowWaters.add_drag_diff_tendencies!
— MethodUpdate u with bottom friction tendency (Bu,Bv) and biharmonic viscosity.
ShallowWaters.add_halo
— MethodExtends the matrices u,v,η,sst with a halo of ghost points for boundary conditions.
ShallowWaters.adv_sst!
— MethodAdvection of sst/tracer based on the departure points xd,yd via bilinear interpolation. Departure points are clipped/wrapped to remain within the domain. Boundary conditions either periodic (wrap around behaviour) or no-flux (no gradient via clipping). Once the respective 4 surrounding grid points are found do bilinear interpolation on the unit square.
ShallowWaters.advection_coriolis!
— MethodUpdate advective and Coriolis tendencies.
ShallowWaters.axb!
— MethodAdd to a x multiplied with b. a += x*b
ShallowWaters.backtraj!
— MethodSolves the trajectory equation for a given time step dt and the velocity uv (this can be u or v). One function for three cases
(i) u is interpolated from u-grid with halo onto T-grid (ii) v is interpolated from v-grid with halo onto T-grid (iii) u or v already on the T-grid: All matrices have same size.
Uses relative grid nodes in the departure points rd, such that actually solved is rd = 0 - dt*uv. The indices i,j of rd determine the arrival grid point.
ShallowWaters.bernoulli!
— MethodBernoulli potential p = 1/2*(u² + v²) + gη.
ShallowWaters.bilin
— MethodBilinear interpolation on (x,y) in the unit square [0,1]x[0,1]. The values at the corners are f00 = f(0,0), f01 = f(0,1), etc.
ShallowWaters.bottom_drag!
— MethodTransit function to call the specified bottom drag function.
ShallowWaters.bottom_drag_linear!
— MethodLinear bottom drag computed as rB*(u,v). rB is negative and contains the grid spacing Δ as gradient operators are dimensionless.
ShallowWaters.bottom_drag_quadratic!
— MethodQuadratic bottom drag Bu,Bv = cD/h * | u⃗ | * u⃗
ShallowWaters.caxb!
— Methodc equals add a to x multiplied with b. c = a + x*b
ShallowWaters.clip
— MethodClips the relative lower-left corner index xyi (for both x or y indices) to remain within the domain. ij is the index of the underlying matrix. xy is the actual coordinate, mn (m or n) the size of the domain, and h1,h2 are the halo sizes (left/south and right/north).
ShallowWaters.continuity!
— MethodTransit function to call the specified continuity function.
ShallowWaters.continuity_forcing!
— MethodContinuity equation's right-hand side with time&space dependent forcing.
ShallowWaters.continuity_itself!
— MethodContinuity equation's right-hand side -∂x(uh) - ∂y(vh) without forcing.
ShallowWaters.continuity_surf_relax!
— MethodContinuity equation's right-hand side with surface relaxation -∂x(uh) - ∂y(vh) + γ*(η_ref - η).
ShallowWaters.coriolis_at_lat
— MethodCoriolis parameter f [1/s] at latitude ϕ [°] given Earth's rotation ω [1/s].
ShallowWaters.cxab!
— Methodc equals add x multiplied to a plus b. c = x*(a+b)
ShallowWaters.cxayb!
— Methodc = xa + yb
ShallowWaters.departure!
— MethodComputes the departure point for semi-Lagrangian advection following Diamantakis, 2014. u,v are assumed to be the time averaged velocities over the previous advection time step. (Presumably need to be changed to 2nd order extrapolation in case the tracer is not passive)
Uses fixed-point iteration once to find the departure point.
ShallowWaters.diffusion!
— MethodTransit function to call the specified diffusion scheme.
ShallowWaters.diffusion_constant!
— MethodBiharmonic diffusion operator with constant viscosity coefficient Viscosity = ν∇⁴ ⃗u. Although constant, the coefficient is actually inside Viscosity = ∇⋅ν∇∇² ⃗u.
ShallowWaters.diffusion_smagorinsky!
— MethodSmagorinsky-like biharmonic viscosity Viscosity = ∇ ⋅ (cSmag Δ⁴ |D| ∇∇² ⃗u) The Δ⁴-scaling is omitted as gradient operators are dimensionless.
ShallowWaters.duration_estimate
— MethodEstimates the total time the model integration will take.
ShallowWaters.dxaybzc!
— Methodd = xa + yb + z*c
ShallowWaters.feedback!
— MethodFeedback function that calls duration estimate, nan_detection and progress.
ShallowWaters.feedback_end!
— MethodFinalises the progress txt file.
ShallowWaters.feedback_init
— MethodInitialises the progress txt file.
ShallowWaters.fu!
— MethodCoriolis term f*u.
ShallowWaters.fv!
— MethodCoriolis term f*v.
ShallowWaters.gap
— MethodFinds the first gap in a list of integers.
ShallowWaters.get_run_id_path
— MethodChecks output folders to determine a 4-digit run id number.
ShallowWaters.ghost_points!
— MethodDecide on boundary condition P.bc which ghost point function to execute.
ShallowWaters.ghost_points_sst!
— MethodDecide on boundary condition P.bc which ghost point function to execute.
ShallowWaters.ghost_points_sst_nonperiodic!
— MethodCopy ghost points for η from inside to the halo in the nonperiodic case.
ShallowWaters.ghost_points_sst_periodic!
— MethodCopy ghost points for η from inside to the halo in the periodic case.
ShallowWaters.ghost_points_u_nonperiodic!
— MethodCopy ghost points for u from inside to the halo in the nonperiodic case.
ShallowWaters.ghost_points_u_periodic!
— MethodCopy ghost points for u from inside to the halo in the periodic case.
ShallowWaters.ghost_points_uv!
— MethodDecide on boundary condition P.bc which ghost point function to execute.
ShallowWaters.ghost_points_v_nonperiodic!
— MethodCopy ghost points for v from inside to the halo in the nonperiodic case.
ShallowWaters.ghost_points_v_periodic!
— MethodCopy ghost points for v from inside to the halo in the periodic case.
ShallowWaters.ghost_points_η!
— MethodDecide on boundary condition P.bc which ghost point function to execute.
ShallowWaters.ghost_points_η_nonperiodic!
— MethodCopy ghost points for η from inside to the halo in the nonperiodic case.
ShallowWaters.ghost_points_η_periodic!
— MethodCopy ghost points for η from inside to the halo in the periodic case.
ShallowWaters.interp_uv!
— MethodInterpolates the matrix uv into the matrix uvi, where xx, yy specify the coordinates as indices (including fraction. Interpolation only onto the inner entries of uvi. (They will be copied back later via the ghostpoint function). Two cases (i) u velocities: from u-grid with halo to T-grid (ii) v velocities: from v-grid with halo to T-grid.
ShallowWaters.m_per_lat
— MethodMeter per 1 degree of latitude (or longitude at the equator).
ShallowWaters.meshgrid
— MethodSimilar to the numpy meshgrid function: repeats x length(y)-times and vice versa. Returns two matrices xx,yy of same shape so that each row of xx is x and each column of yy is y.
ShallowWaters.momentum_u!
— MethodSum up the tendencies of the non-diffusive right-hand side for the u-component.
ShallowWaters.momentum_v!
— MethodSum up the tendencies of the non-diffusive right-hand side for the v-component.
ShallowWaters.nan_detection!
— MethodReturns a boolean whether the prognostic variables contains a NaN.
ShallowWaters.nc_create
— MethodCreates a netCDF file based on grid vectors x,y the variable name, its path, unit and long_name.
ShallowWaters.no_bottom_drag!
— MethodNo bottom drag.
ShallowWaters.output_close!
— MethodCloses netCDF and progress.txt files.
ShallowWaters.preallocate
— MethodPreallocate the diagnostic variables and return them as matrices in structs.
ShallowWaters.progress!
— MethodConverts time step into percent for feedback.
ShallowWaters.readable_secs
— MethodReturns a human readable string representing seconds in terms of days, hours, minutes or seconds.
ShallowWaters.remove_halo
— MethodCut off the halo from the prognostic variables.
ShallowWaters.rhs!
— MethodTransit function to call either the rhslinear or the rhsnonlinear.
ShallowWaters.rhs_linear!
— MethodTendencies du,dv of
∂u/∂t = fv - g∂η/∂x + Fx
∂v/∂t = -fu - g∂η/∂y + Fy
the linear shallow water equations.
ShallowWaters.rhs_nonlinear!
— MethodTendencies du,dv of
∂u/∂t = qhv - ∂(1/2*(u²+v²) + gη)/∂x + Fx
∂v/∂t = -qhu - ∂(1/2*(u²+v²) + gη)/∂y + Fy
the nonlinear shallow water equations.
ShallowWaters.smagorinsky_coeff!
— MethodνSmag = cSmag * |D|, where deformation rate |D| = √((∂u/∂x - ∂v/∂y)^2 + (∂u/∂y + ∂v/∂x)^2). The grid spacing Δ is omitted here as the operators are dimensionless.
ShallowWaters.speed!
— MethodSquared velocities u²,v².
ShallowWaters.stress_tensor!
— MethodBiharmonic stress tensor ∇∇²(u,v) = (∂/∂x(∇²u), ∂/∂y(∇²u); ∂/∂x(∇²v), ∂/∂y(∇²v))
ShallowWaters.thickness!
— MethodLayer thickness h obtained by adding sea surface height η to bottom height H.
ShallowWaters.time_integration
— MethodIntegrates ShallowWaters forward in time.
ShallowWaters.tracer_consumption!
— MethodTracer consumption via relaxation back to .
ShallowWaters.viscous_tensor_constant!
— MethodBiharmonic stress tensor times constant viscosity coefficient νB * ∇∇² ⃗u = (S11, S12; S21, S22)
ShallowWaters.viscous_tensor_smagorinsky!
— MethodBiharmonic stress tensor times Smagorinsky coefficient νSmag * ∇∇² ⃗u = (S11, S12; S21, S22).
ShallowWaters.wrap
— MethodClips the relative lower-left corner index xyi (for both x or y indices) to remain within the domain. ij is the index of the underlying matrix. xy is the actual coordinate, mn (m or n) the size of the domain, and h is the halo size.
ShallowWaters.yy_q
— MethodHelper function to create yy_q based on the boundary condition bc.
ShallowWaters.β_at_lat
— MethodCoriolis parameter's derivative β wrt latitude [(ms)^-1] at latitude ϕ, given Earth's rotation ω [1/s] and radius R [m].
ShallowWaters.∂x!
— MethodCalculates the 2nd order centred gradient in x-direction on any grid (u,v,T or q). The size of dudx must be m-1,n compared to m,n = size(u)
ShallowWaters.∂x
— Method∂x is the 2nd order centred Gradient-operator ∂/∂x with grid spacing Δ (default 1).
ShallowWaters.∂y!
— MethodCalculates the 2nd order centred gradient in y-direction on any grid (u,v,T or q). The size of dudy must be m,n-1 compared to m,n = size(u).
ShallowWaters.∂y
— Method∂y is the 2nd order centred Gradient-operator ∂/∂y with grid spacing Δ (default 1).
ShallowWaters.∇²!
— Method∇² is the 2nd order centred Laplace-operator ∂/∂x^2 + ∂/∂y^2. The 1/Δ²-factor is omitted and moved into the viscosity coefficient.
ShallowWaters.∇²
— Method∇² is the 2nd order centred Laplace-operator ∂/∂x^2 + ∂/∂y^2 with grid spacing Δ (default 1).