Skip to content

Commit

Permalink
Relax to approx in test + remove unnecessary saved output
Browse files Browse the repository at this point in the history
  • Loading branch information
jbisits committed Jul 17, 2024
1 parent 3b54557 commit 884f558
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/TwoLayerDirectNumericalShenanigans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using SeawaterPolynomials: BoussinesqEquationOfState, ρ
using SeawaterPolynomials.TEOS10
using SeawaterPolynomials.SecondOrderSeawaterPolynomials
using SpecialFunctions: erf
using Oceanostics: KineticEnergyDissipationRate, KineticEnergy
using Oceanostics: KineticEnergyDissipationRate, KineticEnergy, PotentialEnergy
using CUDA: allowscalar, CuArray
import Base: show, iterate

Expand Down
15 changes: 3 additions & 12 deletions src/twolayerdns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,28 +294,19 @@ function save_computed_output!(simulation, tldns, save_schedule, save_file, outp
ϵ_maximum = Reduction(maximum!, ϵ, dims = (1, 2, 3))
Eₖ = KineticEnergy(model)
∫Eₖ = Integral(Eₖ)
Eₚ = potential_energy(model)
Eₚ = PotentialEnergy(model)
∫Eₚ = Integral(Eₚ)

# Horizontally integrated vertical temperature flux and vertical temperature gradient
T = model.tracers.T
w′T′ = vertical_tracer_flux(model, T)
∫ₐw′T′ = Integral(w′T′, dims = (1, 2))
∂T∂z = ∂z(T)
∫ₐ∂T∂z = Integral(∂T∂z, dims = (1, 2))

computed_outputs = Dict("σ" => σ, "∫ϵ" => ∫ϵ, "ϵ_maximum" => ϵ_maximum, "∫Eₖ" => ∫Eₖ,
"∫Eₚ" => ∫Eₚ, "∫ₐ∂T∂z" => ∫ₐ∂T∂z, "∫ₐw′T′" => ∫ₐw′T′)
"∫Eₚ" => ∫Eₚ)

oa = Dict(
"σ" => Dict("longname" => "Seawater potential density calculated using TEOS-10 at $(reference_gp_height)dbar",
"units" => "kgm⁻³"),
"ϵ_maximum" => Dict("longname" => "Maximum (in space) TKE dissipation"),
"∫ϵ" => Dict("longname" => "Volume integrated turbulent kintetic energy dissipation"),
"∫Eₖ" => Dict("longname" => "Volume integrated turbulent kinetic energy"),
"∫Eₚ" => Dict("longname" => "Volume integrated potential energy (g∫ᵥρzdV)"),
"∫ₐw′T′" => Dict("longname" => "Horizontally integrated vertical temeprature flux"),
"∫ₐ∂T∂z" => Dict("longname" => "Horizontally integrated vertical temperature gradient")
"∫Eₚ" => Dict("longname" => "Volume integrated potential energy (g∫ᵥρzdV)")
)
simulation.output_writers[:computed_output] =
save_file == :netcdf ? NetCDFOutputWriter(model, computed_outputs;
Expand Down
34 changes: 18 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,36 +172,38 @@ include("output_test.jl")
simulation, td, tldns = run_sim(:netcdf)
NCDataset(simulation.output_writers[:tracers].filepath) do ds
S, T = ds[:S], ds[:T]
@test all(S[:, :, 1:td, :] .== tldns.initial_conditions.S₀ˡ)
@test all(S[:, :, td+1:end, :] .== tldns.initial_conditions.S₀ᵘ)
@test all(T[:, :, 1:td, :] .== tldns.initial_conditions.T₀ˡ)
@test all(T[:, :, td+1:end, :] .== tldns.initial_conditions.T₀ᵘ)
@test all(S[:, :, 1:td, :] . tldns.initial_conditions.S₀ˡ)
@test all(S[:, :, td+1:end, :] . tldns.initial_conditions.S₀ᵘ)
@test all(T[:, :, 1:td, :] . tldns.initial_conditions.T₀ˡ)
@test all(T[:, :, td+1:end, :] . tldns.initial_conditions.T₀ᵘ)
end
NCDataset(simulation.output_writers[:computed_output].filepath) do ds
σ = ds[]
@test all(σ[:, :, 1:td, :] .== SeawaterPolynomials.ρ(tldns.initial_conditions.T₀ˡ,
tldns.initial_conditions.S₀ˡ, 0,
tldns.model.buoyancy.model.equation_of_state))
@test all(σ[:, :, td+1:end, :] .== SeawaterPolynomials.ρ(tldns.initial_conditions.T₀ᵘ,
tldns.initial_conditions.S₀ᵘ, 0,
tldns.model.buoyancy.model.equation_of_state))
@test all(σ[:, :, 1:td, :] .≈
SeawaterPolynomials.ρ(tldns.initial_conditions.T₀ˡ,
tldns.initial_conditions.S₀ˡ, 0,
tldns.model.buoyancy.model.equation_of_state))
@test all(σ[:, :, td+1:end, :] .≈
SeawaterPolynomials.ρ(tldns.initial_conditions.T₀ᵘ,
tldns.initial_conditions.S₀ᵘ, 0,
tldns.model.buoyancy.model.equation_of_state))
end
end

@testset "jld2" begin
simulation, td, tldns = run_sim(:jld2)
S = FieldTimeSeries(simulation.output_writers[:tracers].filepath, "S")
T = FieldTimeSeries(simulation.output_writers[:tracers].filepath, "T")
@test all(S.data[:, :, 1:td, :] .== tldns.initial_conditions.S₀ˡ)
@test all(S.data[:, :, td+1:end, :] .== tldns.initial_conditions.S₀ᵘ)
@test all(T.data[:, :, 1:td, :] .== tldns.initial_conditions.T₀ˡ)
@test all(T.data[:, :, td+1:end, :] .== tldns.initial_conditions.T₀ᵘ)
@test all(S.data[:, :, 1:td, :] . tldns.initial_conditions.S₀ˡ)
@test all(S.data[:, :, td+1:end, :] . tldns.initial_conditions.S₀ᵘ)
@test all(T.data[:, :, 1:td, :] . tldns.initial_conditions.T₀ˡ)
@test all(T.data[:, :, td+1:end, :] . tldns.initial_conditions.T₀ᵘ)
σ = FieldTimeSeries(simulation.output_writers[:computed_output].filepath, "σ")
@test all.data[:, :, 1:td, :] .==
@test all.data[:, :, 1:td, :] .
SeawaterPolynomials.ρ(tldns.initial_conditions.T₀ˡ,
tldns.initial_conditions.S₀ˡ, 0,
tldns.model.buoyancy.model.equation_of_state))
@test all.data[:, :, td+1:end, :] .==
@test all.data[:, :, td+1:end, :] .
SeawaterPolynomials.ρ(tldns.initial_conditions.T₀ᵘ,
tldns.initial_conditions.S₀ᵘ, 0,
tldns.model.buoyancy.model.equation_of_state))
Expand Down

0 comments on commit 884f558

Please sign in to comment.