Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
Merge #1388
Browse files Browse the repository at this point in the history
1388: Add turbulence statistics diagnostics r=kpamnany a=slifer50

# Description

Defines a callback for calculating volumetrically averaged dimensionless kinetic energy and dissipation



Co-authored-by: yassine <[email protected]>
  • Loading branch information
bors[bot] and slifer50 authored Jul 31, 2020
2 parents 137fe81 + e22da78 commit 842cf91
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 272 deletions.
1 change: 1 addition & 0 deletions docs/src/APIs/Diagnostics/Diagnostics.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Diagnostics.setup_atmos_default_diagnostics
Diagnostics.setup_atmos_core_diagnostics
Diagnostics.setup_atmos_default_perturbations
Diagnostics.setup_atmos_refstate_perturbations
Diagnostics.setup_atmos_turbulence_stats
Diagnostics.setup_dump_state_diagnostics
Diagnostics.setup_dump_aux_diagnostics
```
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ using DocStringExtensions
using LinearAlgebra

using CLIMAParameters
using CLIMAParameters.Planet: cp_d, MSLP, grav, LH_v0
using CLIMAParameters.Planet: R_d, cv_d, cp_d, MSLP, grav, LH_v0
using CLIMAParameters.Atmos.SubgridScale: C_smag
struct EarthParameterSet <: AbstractEarthParameterSet end
const param_set = EarthParameterSet()

Expand Down Expand Up @@ -84,7 +85,7 @@ function init_greenvortex!(bl, state, aux, (x, y, z), t)
e_pot = FT(0)# potential energy
Pinf = 101325
Uzero = FT(100)
p = Pinf +* Uzero / 16) * (2 + cos(z)) * (cos(x) + cos(y))
p = Pinf +* Uzero^2 / 16) * (2 + cos(z)) * (cos(x) + cos(y))
u = Uzero * sin(x) * cos(y) * cos(z)
v = -Uzero * cos(x) * sin(y) * cos(z)
e_kin = 0.5 * (u^2 + v^2)
Expand Down Expand Up @@ -120,7 +121,6 @@ function config_greenvortex(
ymin,
zmin,
)

ode_solver = ClimateMachine.ExplicitSolverType(
solver_method = LSRK144NiegemannDiehlBusch,
)
Expand Down Expand Up @@ -156,15 +156,21 @@ function config_greenvortex(
)
return config
end

# Here we define the diagnostic configuration specific to this problem.
function config_diagnostics(driver_config)
interval = "10000steps"
dgngrp = setup_atmos_default_diagnostics(interval, driver_config.name)
function config_diagnostics(driver_config, nor, iter)
interval = "360steps"
dgngrp = setup_atmos_turbulence_stats(
AtmosLESConfigType(),
interval,
driver_config.name,
nor,
iter,
)
return ClimateMachine.DiagnosticsConfiguration([dgngrp])
end

function main()

FT = Float64
N = 4
Ncellsx = 64
Expand All @@ -182,7 +188,7 @@ function main()
zmin = FT(-pi)
t0 = FT(0)
timeend = FT(0.1)
CFL = FT(1.8)
CFL = FT(0.9)

driver_config = config_greenvortex(
FT,
Expand All @@ -202,7 +208,9 @@ function main()
init_on_cpu = true,
Courant_number = CFL,
)
dgn_config = config_diagnostics(driver_config)
nor = FT(100)
iter = FT(0.01)
dgn_config = config_diagnostics(driver_config, nor, iter)

result = ClimateMachine.invoke!(
solver_config;
Expand Down
1 change: 0 additions & 1 deletion src/ClimateMachine.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,4 @@ include(joinpath("Utilities", "Checkpoint", "Checkpoint.jl"))
include(joinpath("Driver", "Callbacks", "Callbacks.jl"))
include(joinpath("Driver", "Driver.jl"))


end
1 change: 1 addition & 0 deletions src/Diagnostics/Diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export DiagnosticsGroup,
setup_atmos_core_diagnostics,
setup_atmos_default_perturbations,
setup_atmos_refstate_perturbations,
setup_atmos_turbulence_stats,
setup_dump_state_diagnostics,
setup_dump_aux_diagnostics

Expand Down
37 changes: 37 additions & 0 deletions src/Diagnostics/atmos_gcm_default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,43 @@ using ..Atmos
using ..Atmos: thermo_state
using ..TurbulenceClosures: turbulence_tensors

"""
setup_atmos_default_diagnostics(
::AtmosGCMConfigType,
interval::String,
out_prefix::String;
writer::AbstractWriter,
interpol = nothing,
)
Create and return a `DiagnosticsGroup` containing the "AtmosDefault"
diagnostics for GCM configurations. All the diagnostics in the group will run
at the specified `interval`, be interpolated to the specified boundaries and
resolution, and will be written to files prefixed by `out_prefix` using
`writer`.
"""
function setup_atmos_default_diagnostics(
::AtmosGCMConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
# TODO: remove this
@assert !isnothing(interpol)

return DiagnosticsGroup(
"AtmosGCMDefault",
Diagnostics.atmos_gcm_default_init,
Diagnostics.atmos_gcm_default_fini,
Diagnostics.atmos_gcm_default_collect,
interval,
out_prefix,
writer,
interpol,
)
end

include("diagnostic_fields.jl")

# 3D variables
Expand Down
37 changes: 37 additions & 0 deletions src/Diagnostics/atmos_les_core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,43 @@ using ..Mesh.Grids
using ..Thermodynamics
using LinearAlgebra

"""
setup_atmos_core_diagnostics(
::AtmosLESConfigType,
interval::String,
out_prefix::String;
writer::AbstractWriter,
interpol = nothing,
)
Create and return a `DiagnosticsGroup` containing the "AtmosLESCore"
diagnostics for LES configurations. All the diagnostics in the group
will run at the specified `interval`, be interpolated to the specified
boundaries and resolution, and will be written to files prefixed by
`out_prefix` using `writer`.
"""
function setup_atmos_core_diagnostics(
::AtmosLESConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
# TODO: remove this
@assert isnothing(interpol)

return DiagnosticsGroup(
"AtmosLESCore",
Diagnostics.atmos_les_core_init,
Diagnostics.atmos_les_core_fini,
Diagnostics.atmos_les_core_collect,
interval,
out_prefix,
writer,
interpol,
)
end

# Simple horizontal averages
function vars_atmos_les_core_simple(m::AtmosModel, FT)
@vars begin
Expand Down
37 changes: 37 additions & 0 deletions src/Diagnostics/atmos_les_default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,43 @@ using ..Thermodynamics
using ..TurbulenceClosures
using LinearAlgebra

"""
setup_atmos_default_diagnostics(
::AtmosLESConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
Create and return a `DiagnosticsGroup` containing the "AtmosDefault"
diagnostics for LES configurations. All the diagnostics in the group will
run at the specified `interval`, be interpolated to the specified boundaries
and resolution, and will be written to files prefixed by `out_prefix` using
`writer`.
"""
function setup_atmos_default_diagnostics(
::AtmosLESConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
# TODO: remove this
@assert isnothing(interpol)

return DiagnosticsGroup(
"AtmosLESDefault",
Diagnostics.atmos_les_default_init,
Diagnostics.atmos_les_default_fini,
Diagnostics.atmos_les_default_collect,
interval,
out_prefix,
writer,
interpol,
)
end

# Simple horizontal averages
function vars_atmos_les_default_simple(m::AtmosModel, FT)
@vars begin
Expand Down
36 changes: 36 additions & 0 deletions src/Diagnostics/atmos_les_default_perturbations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,42 @@ using ..Mesh.Topologies
using ..Mesh.Grids
using ..Thermodynamics

"""
setup_atmos_default_perturbations(
::AtmosLESConfigType,
interval::String,
out_prefix::String;
writer::AbstractWriter,
interpol = nothing,
)
Create and return a `DiagnosticsGroup` containing the
"AtmosLESDefaultPerturbations" diagnostics for the LES configuration.
All the diagnostics in the group will run at the specified `interval`,
and written to files prefixed by `out_prefix` using `writer`.
"""
function setup_atmos_default_perturbations(
::AtmosLESConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
# TODO: remove this
@assert !isnothing(interpol)

return DiagnosticsGroup(
"AtmosLESDefaultPerturbations",
Diagnostics.atmos_les_default_perturbations_init,
Diagnostics.atmos_les_default_perturbations_fini,
Diagnostics.atmos_les_default_perturbations_collect,
interval,
out_prefix,
writer,
interpol,
)
end

# Compute sums for density-averaged horizontal averages
#
# These are trimmed down versions of `atmos_les_default_simple_sums!()`:
Expand Down
38 changes: 38 additions & 0 deletions src/Diagnostics/atmos_refstate_perturbations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,44 @@ using ..Mesh.Topologies
using ..Mesh.Grids
using ..Thermodynamics

"""
setup_atmos_refstate_perturbations(
::ClimateMachineConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
Create and return a `DiagnosticsGroup` containing the
"AtmosRefStatePerturbations" diagnostics for both LES and GCM
configurations. All the diagnostics in the group will run at the
specified `interval`, be interpolated to the specified boundaries
and resolution, and written to files prefixed by `out_prefix`
using `writer`.
"""
function setup_atmos_refstate_perturbations(
::ClimateMachineConfigType,
interval::String,
out_prefix::String;
writer = NetCDFWriter(),
interpol = nothing,
)
# TODO: remove this
@assert !isnothing(interpol)

return DiagnosticsGroup(
"AtmosRefStatePerturbations",
Diagnostics.atmos_refstate_perturbations_init,
Diagnostics.atmos_refstate_perturbations_fini,
Diagnostics.atmos_refstate_perturbations_collect,
interval,
out_prefix,
writer,
interpol,
)
end

function vars_atmos_refstate_perturbations(m::AtmosModel, FT)
@vars begin
ref_state::vars_atmos_refstate_perturbations(m.ref_state, FT)
Expand Down
Loading

0 comments on commit 842cf91

Please sign in to comment.