Skip to content

Commit

Permalink
scaling information for diagn corrected
Browse files Browse the repository at this point in the history
  • Loading branch information
milankl committed Mar 20, 2024
1 parent e4c9c55 commit 5b83db7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/dynamics/diagnostic_variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Base.@kwdef struct DynamicsVariables{NF<:AbstractFloat, Grid<:AbstractGrid{NF}}
trunc::Int

# MULTI-PURPOSE VECTOR (a, b), work array to be reused in various places, examples:
# uω_coslat⁻¹, vω_coslat⁻¹ = a, b (all models)
# uω_coslat⁻¹, vω_coslat⁻¹ = a, b (all models)
# uω_coslat⁻¹_grid, vω_coslat⁻¹_grid = a_grid, b_grid (all models)
# uh_coslat⁻¹, vh_coslat⁻¹ = a, b (ShallowWaterModel)
# uh_coslat⁻¹_grid, vh_coslat⁻¹_grid = a_grid, b_grid (ShallowWaterModel)
Expand Down Expand Up @@ -138,8 +138,8 @@ Base.@kwdef struct SurfaceVariables{NF<:AbstractFloat, Grid<:AbstractGrid{NF}}
div_mean::LTM{Complex{NF}} = zeros(LTM{Complex{NF}}, trunc+2, trunc+1) # divergence (in spectral though)

precip_large_scale::Grid = zeros(Grid, nlat_half) # large scale precipitation (for output)
precip_convection::Grid = zeros(Grid, nlat_half) # convective precipitation (for output)
cloud_top::Grid = zeros(Grid, nlat_half) # cloud top [hPa]
precip_convection::Grid = zeros(Grid, nlat_half) # convective precipitation (for output)
cloud_top::Grid = zeros(Grid, nlat_half) # cloud top [hPa]
soil_moisture_availability::Grid = zeros(Grid, nlat_half)
end

Expand Down Expand Up @@ -217,10 +217,10 @@ function Base.zeros(
nthreads = Threads.nthreads()
columns = [ColumnVariables{NF}(; nlev) for _ in 1:nthreads]

# particle work arrays
# particle work arrays
particles = zeros(ParticleVariables, SG)

scale = Ref(convert(SG.NF, SG.radius))
scale = Ref(one(NF))

return DiagnosticVariables{NF, Grid{NF}, Model}(
layers, surface, columns, particles,
Expand Down
4 changes: 4 additions & 0 deletions src/dynamics/scaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,15 @@ $(TYPEDSIGNATURES)
Scales the prognostic variables vorticity and divergence with
the Earth's radius which is used in the dynamical core."""
function scale!(progn::PrognosticVariables,
diagn::DiagnosticVariables,
scale::Real)
new_scale = scale/progn.scale[] # undo previous scale and new scale in one go
scale!(progn, :vor, new_scale)
scale!(progn, :div, new_scale)
progn.scale[] = scale # store scaling information
diagn.scale[] = scale # store scaling information
# no need to actually scale the diagnostic variables as they will be
# overwritten by the transform of the prognostic variables anyway
end

"""
Expand Down
4 changes: 2 additions & 2 deletions src/dynamics/time_integration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ function time_stepping!(
(; time_stepping) = model

# SCALING: we use vorticity*radius, divergence*radius in the dynamical core
scale!(progn, model.spectral_grid.radius)
scale!(progn, diagn, model.spectral_grid.radius)

# OUTPUT INITIALISATION AND STORING INITIAL CONDITIONS + FEEDBACK
# propagate spectral state to grid variables for initial condition output
Expand All @@ -410,7 +410,7 @@ function time_stepping!(
callback!(model.callbacks, progn, diagn, model)
end

# UNSCALE, CLOSE, FINISH
# UNSCALE, CLOSE, FINISH
finish!(feedback) # finish the progress meter, do first for benchmark accuracy
unscale!(progn) # undo radius-scaling for vor, div from the dynamical core
unscale!(diagn) # undo radius-scaling for vor, div from the dynamical core
Expand Down

0 comments on commit 5b83db7

Please sign in to comment.