Skip to content

Commit

Permalink
Merge pull request #393 from SpeedyWeather/mk/stochstirring
Browse files Browse the repository at this point in the history
Accumulate vor/div tendencies
  • Loading branch information
milankl authored Oct 3, 2023
2 parents fc8face + 39b6fde commit 1fc152a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 13 deletions.
47 changes: 44 additions & 3 deletions src/dynamics/tendencies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,55 @@ end
"""
$(TYPEDSIGNATURES)
Set the tendencies in `diagn` to zero."""
function zero_tendencies!(diagn::DiagnosticVariables)
function zero_tendencies!(diagn::DiagnosticVariables{NF,Grid,Model}) where {NF,Grid,Model<:Barotropic}
for layer in diagn.layers
fill!(layer.tendencies.u_tend_grid,0)
fill!(layer.tendencies.v_tend_grid,0)
fill!(layer.tendencies.vor_tend,0)
end
end

"""
$(TYPEDSIGNATURES)
Set the tendencies in `diagn` to zero."""
function zero_tendencies!(diagn::DiagnosticVariables{NF,Grid,Model}) where {NF,Grid,Model<:ShallowWater}
for layer in diagn.layers
fill!(layer.tendencies.u_tend_grid,0)
fill!(layer.tendencies.v_tend_grid,0)
fill!(layer.tendencies.vor_tend,0)
fill!(layer.tendencies.div_tend,0)
end
fill!(diagn.surface.pres_tend_grid,0)
fill!(diagn.surface.pres_tend,0)
end

"""
$(TYPEDSIGNATURES)
Set the tendencies in `diagn` to zero."""
function zero_tendencies!(diagn::DiagnosticVariables{NF,Grid,Model}) where {NF,Grid,Model<:PrimitiveDry}
for layer in diagn.layers
fill!(layer.tendencies.u_tend_grid,0)
fill!(layer.tendencies.v_tend_grid,0)
fill!(layer.tendencies.vor_tend,0)
fill!(layer.tendencies.div_tend,0)
fill!(layer.tendencies.temp_tend_grid,0)
fill!(layer.tendencies.humid_tend_grid,0)
end
fill!(diagn.surface.pres_tend_grid,0)
fill!(diagn.surface.pres_tend,0)
return nothing
end

"""
$(TYPEDSIGNATURES)
Set the tendencies in `diagn` to zero."""
function zero_tendencies!(diagn::DiagnosticVariables{NF,Grid,Model}) where {NF,Grid,Model<:PrimitiveWet}
for layer in diagn.layers
fill!(layer.tendencies.u_tend_grid,0)
fill!(layer.tendencies.v_tend_grid,0)
fill!(layer.tendencies.vor_tend,0)
fill!(layer.tendencies.div_tend,0)
fill!(layer.tendencies.temp_tend_grid,0)
fill!(layer.tendencies.humid_tend_grid,0)
end
fill!(diagn.surface.pres_tend_grid,0)
fill!(diagn.surface.pres_tend,0)
end
11 changes: 6 additions & 5 deletions src/dynamics/tendencies_dynamics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,8 @@ function vorticity_flux_curldiv!( diagn::DiagnosticVariablesLayer,
C::DynamicsConstants,
G::Geometry,
S::SpectralTransform;
div::Bool=true) # also calculate div of vor flux?
div::Bool=true, # also calculate div of vor flux?
add::Bool=false) # accumulate in vor/div tendencies?

(;f_coriolis) = C
(;coslat⁻¹) = G
Expand Down Expand Up @@ -433,8 +434,8 @@ function vorticity_flux_curldiv!( diagn::DiagnosticVariablesLayer,
spectral!(u_tend,u_tend_grid,S)
spectral!(v_tend,v_tend_grid,S)

curl!(vor_tend,u_tend,v_tend,S) # ∂ζ/∂t = ∇×(u_tend,v_tend)
div && divergence!(div_tend,u_tend,v_tend,S) # ∂D/∂t = ∇⋅(u_tend,v_tend)
curl!(vor_tend,u_tend,v_tend,S;add) # ∂ζ/∂t = ∇×(u_tend,v_tend)
div && divergence!(div_tend,u_tend,v_tend,S;add) # ∂D/∂t = ∇⋅(u_tend,v_tend)
return nothing
end

Expand All @@ -456,7 +457,7 @@ function vorticity_flux!(diagn::DiagnosticVariablesLayer,model::ShallowWater)
C = model.constants
G = model.geometry
S = model.spectral_transform
vorticity_flux_curldiv!(diagn,C,G,S,div=true)
vorticity_flux_curldiv!(diagn,C,G,S,div=true,add=true)
end

"""
Expand All @@ -476,7 +477,7 @@ function vorticity_flux!(diagn::DiagnosticVariablesLayer,model::Barotropic)
C = model.constants
G = model.geometry
S = model.spectral_transform
vorticity_flux_curldiv!(diagn,C,G,S,div=false)
vorticity_flux_curldiv!(diagn,C,G,S,div=false,add=true)
end

"""
Expand Down
8 changes: 4 additions & 4 deletions src/output/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ function OutputWriter(
end

# default variables to output by model
default_output_vars(::Type{<:Barotropic}) = [:vor,:u]
default_output_vars(::Type{<:ShallowWater}) = [:vor,:u]
default_output_vars(::Type{<:PrimitiveDry}) = [:vor,:u,:temp,:pres]
default_output_vars(::Type{<:PrimitiveWet}) = [:vor,:u,:temp,:humid,:pres,:precip_cond,:precip_conv]
default_output_vars(::Type{<:Barotropic}) = [:vor,:u,:v]
default_output_vars(::Type{<:ShallowWater}) = [:vor,:u,:v]
default_output_vars(::Type{<:PrimitiveDry}) = [:vor,:u,:v,:temp,:pres]
default_output_vars(::Type{<:PrimitiveWet}) = [:vor,:u,:v,:temp,:humid,:pres,:precip_cond,:precip_conv]

# print all fields with type <: Number
function Base.show(io::IO,O::AbstractOutputWriter)
Expand Down
2 changes: 1 addition & 1 deletion src/utility_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function print_fields(io::IO,A,keys;arrays::Bool=false)
filtered = n < length(keys)
for (i,key) in enumerate(keys_filtered)
last = (i == n) & ~filtered
key = keys[i]
key = keys_filtered[i]
val = getfield(A,key)
~last ? println(io,"$key::$(typeof(val)) = $val") :
print(io, "$key::$(typeof(val)) = $val")
Expand Down

0 comments on commit 1fc152a

Please sign in to comment.