-
Couldn't load subscription status.
- Fork 10
Adds a mixed layer depth diagnostic #182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
cfaf34b
added mld calculaion
jagoosw 71653f6
added tests and fixed
jagoosw b88191c
generalised mld computation
jagoosw 453f76b
Merge branch 'main' into jsw/mld
jagoosw 5597908
Merge branch 'main' into jsw/mld
tomchor 6239950
Update test/runtests.jl
tomchor 6d3e07b
Update src/FlowDiagnostics.jl
tomchor 52b9fd9
Merge branch 'main' into jsw/mld
tomchor 15012c1
Update test/runtests.jl
tomchor 8018aad
move test to proper file
tomchor 766458d
Added buoyancy criterion and fixed tests
jagoosw 21952d6
correct buoyancy default
jagoosw dc44374
updated
jagoosw 3d5303b
fixed tests
jagoosw 6d9390b
test on all the buoyancy models
jagoosw f9ac0e1
remove signature where it does nothing
tomchor 53049f2
Update src/FlowDiagnostics.jl
tomchor 0492f0f
move MLD test one loop out
tomchor 7225e51
remove SIGNATURES that dont do anything
tomchor 0554ff2
added TYPEDEF to structs and types
tomchor 32a152c
test that MLD doesnt work for buoyancy==Nothing
tomchor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,18 +4,23 @@ using DocStringExtensions | |||||
| export RichardsonNumber, RossbyNumber | ||||||
| export ErtelPotentialVorticity, ThermalWindPotentialVorticity, DirectionalErtelPotentialVorticity | ||||||
| export StrainRateTensorModulus, VorticityTensorModulus, Q, QVelocityGradientTensorInvariant | ||||||
| export MixedLayerDepth, BuoyancyAnomalyCriterion, DensityAnomalyCriterion | ||||||
|
|
||||||
| using Oceanostics: validate_location, | ||||||
| validate_dissipative_closure, | ||||||
| add_background_fields, | ||||||
| get_coriolis_frequency_components | ||||||
|
|
||||||
| using Oceananigans: NonhydrostaticModel, FPlane, ConstantCartesianCoriolis, BuoyancyField, BuoyancyTracer | ||||||
| using Oceananigans.BuoyancyFormulations: get_temperature_and_salinity, SeawaterBuoyancy, g_Earth, buoyancy_perturbationᶜᶜᶜ | ||||||
| using Oceananigans.Operators | ||||||
| using Oceananigans.AbstractOperations | ||||||
| using Oceananigans.AbstractOperations: KernelFunctionOperation | ||||||
| using Oceananigans.BuoyancyFormulations: buoyancy | ||||||
| using Oceananigans.Grids: Center, Face, NegativeZDirection, ZDirection | ||||||
| using Oceananigans.Grids: Center, Face, NegativeZDirection, ZDirection, znode | ||||||
|
|
||||||
| using SeawaterPolynomials: ρ′, BoussinesqEquationOfState | ||||||
| using SeawaterPolynomials.SecondOrderSeawaterPolynomials: SecondOrderSeawaterPolynomial | ||||||
|
|
||||||
| #+++ Richardson number | ||||||
| @inline ψ²(i, j, k, grid, ψ) = @inbounds ψ[i, j, k]^2 | ||||||
|
|
@@ -441,6 +446,129 @@ function QVelocityGradientTensorInvariant(model; location = (Center, Center, Cen | |||||
| end | ||||||
|
|
||||||
| const Q = QVelocityGradientTensorInvariant | ||||||
| #--- | ||||||
|
|
||||||
| struct MixedLayerDepth{C} | ||||||
| criterion::C | ||||||
| end | ||||||
|
|
||||||
| """ | ||||||
| $(SIGNATURES) | ||||||
|
|
||||||
| Returns the mixed layer depth defined as the depth at which `criterion` is true. | ||||||
|
|
||||||
| Defaults to `DensityAnomalyCriterion` where the depth is that at which the density | ||||||
| is some threshold (defaults to 0.125kg/m³) higher than the surface density. | ||||||
|
|
||||||
| When `DensityAnomalyCriterion` is used, the arguments `buoyancy` and `C` should be | ||||||
| supplied where `buoyancy` should be the buoyancy model, and `C` should be a named | ||||||
| tuple of `(; T, S)`, `(; T)` or `(; S)` (the latter two if the buoyancy model | ||||||
| specifies a constant salinity or temperature). | ||||||
| """ | ||||||
| function MixedLayerDepth(grid, args...; criterion = BuoyancyAnomalyCriterion(convert(eltype(grid), -1/8 * 1020 / g_Earth))) | ||||||
| validate_criterion_model(criterion, args...) | ||||||
|
|
||||||
| MLD = MixedLayerDepth(criterion) | ||||||
|
|
||||||
| return KernelFunctionOperation{Center, Center, Nothing}(MLD, grid, args...) | ||||||
| end | ||||||
|
|
||||||
| function (MLD::MixedLayerDepth)(i, j, k, grid, args...) | ||||||
| kₘₗ = -1 | ||||||
|
|
||||||
| for k in grid.Nz-1:-1:1 | ||||||
| below_mixed_layer = MLD.criterion(i, j, k, grid, args...) | ||||||
|
|
||||||
| kₘₗ = ifelse(below_mixed_layer & (kₘₗ < 0), k, kₘₗ) | ||||||
| end | ||||||
|
|
||||||
| zₘₗ = interpolate_from_nearest_cell(MLD.criterion, i, j, kₘₗ, grid, args...) | ||||||
|
|
||||||
| return ifelse(kₘₗ == -1, -Inf, zₘₗ) | ||||||
| end | ||||||
|
|
||||||
| """ | ||||||
| $(SIGNATURES) | ||||||
|
|
||||||
| An abstract mixed layer depth criterion where the mixed layer is defined to be | ||||||
| `anomaly` + `pertubation` greater than the surface value of `anomaly`. | ||||||
|
|
||||||
| $(SIGNATURES) types should provide a method for the function `anomaly` in the form | ||||||
| `anomaly(criterion, i, j, k, grid, args...)`, and should have a property `pertubation`. | ||||||
| """ | ||||||
| abstract type AbstractAnomalyCriterion end | ||||||
|
|
||||||
| @inline function (criterion::AbstractAnomalyCriterion)(i, j, k, grid, args...) | ||||||
| δ = criterion.pertubation | ||||||
|
|
||||||
| ref = (anomaly(criterion, i, j, grid.Nz, grid, args...) + anomaly(criterion, i, j, grid.Nz+1, grid, args...)) * convert(eltype(grid), 0.5) | ||||||
|
|
||||||
| val = anomaly(criterion, i, j, k, grid,args...) | ||||||
|
|
||||||
| return val < ref + δ | ||||||
| end | ||||||
|
|
||||||
| @inline function interpolate_from_nearest_cell(criterion::AbstractAnomalyCriterion, i, j, k, grid, args...) | ||||||
| δ = criterion.pertubation | ||||||
|
|
||||||
| ref = (anomaly(criterion, i, j, grid.Nz, grid, args...) + anomaly(criterion, i, j, grid.Nz + 1, grid, args...)) * convert(eltype(grid), 0.5) | ||||||
|
|
||||||
| k_val = anomaly(criterion, i, j, k, grid, args...) | ||||||
| k⁺_val = anomaly(criterion, i, j, k + 1, grid, args...) | ||||||
|
|
||||||
| zₖ = znode(i, j, k, grid, Center(), Center(), Center()) | ||||||
| z₊ = znode(i, j, k+1, grid, Center(), Center(), Center()) | ||||||
|
|
||||||
| return zₖ + (z₊ - zₖ) * (ref + δ - k_val) / (k⁺_val - k_val) | ||||||
| end | ||||||
|
|
||||||
| """ | ||||||
| $(SIGNATURES) | ||||||
|
|
||||||
| Defines the mixed layer to be the depth at which the density is more than `pertubation` | ||||||
| greater than the surface density. | ||||||
|
|
||||||
| When this model is used, the arguments `buoyancy` and `C` should be | ||||||
| supplied where `buoyancy` should be the buoyancy model, and `C` should be a named | ||||||
| tuple of `(; T, S)`, `(; T)` or `(; S)` (the latter two if the buoyancy model | ||||||
| specifies a constant salinity or temperature). | ||||||
| """ | ||||||
| struct DensityAnomalyCriterion{FT} <: AbstractAnomalyCriterion | ||||||
| pertubation :: FT | ||||||
| end | ||||||
|
|
||||||
| validate_criterion_model(::DensityAnomalyCriterion, args...) = | ||||||
| @error "For DensityAnomalyCriterion you must supply the arguments buoyancy and C, where C is a named tuple of (; T, S), (; T) or (; S)" | ||||||
|
|
||||||
| validate_criterion_model(::DensityAnomalyCriterion, buoyancy, C) = nothing | ||||||
|
|
||||||
| validate_criterion_model(::DensityAnomalyCriterion, ::SeawaterBuoyancy{<:Any, <:BoussinesqEquationOfState}, C::NamedTuple) = nothing | ||||||
|
|
||||||
| @inline function anomaly(::DensityAnomalyCriterion, i, j, k, grid, b::SeawaterBuoyancy{<:Any, <:BoussinesqEquationOfState}, C) | ||||||
| T, S = get_temperature_and_salinity(b, C) | ||||||
|
|
||||||
| return ρ′(i, j, k, grid, b.equation_of_state, T, S) | ||||||
| end | ||||||
|
|
||||||
| """ | ||||||
| $(SIGNATURES) | ||||||
|
|
||||||
| Defines the mixed layer to be the depth at which the buoyancy is more than `pertubation` | ||||||
| greater than the surface buoyancy (but the pertubaton is usually negative). | ||||||
|
|
||||||
| When this model is used, the arguments `buoyancy` and `C` should be | ||||||
| supplied where `buoyancy` should be the buoyancy model, and `C` should be a named | ||||||
| tuple of `(; T, S)`, `(; T)` or `(; S)` (the latter two if the buoyancy model | ||||||
| specifies a constant salinity or temperature). | ||||||
| """ | ||||||
| @kwdef struct BuoyancyAnomalyCriterion{FT} <: AbstractAnomalyCriterion | ||||||
| pertubation :: FT = - 1/8 * 1020 / g_Earth | ||||||
tomchor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| pertubation :: FT = - 1/8 * 1020 / g_Earth | |
| anomaly :: FT = - 1/8 * 1020 / g_Earth |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.