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

Commit

Permalink
Fix second order rain flux
Browse files Browse the repository at this point in the history
Move precipitation flux def up before ref
  • Loading branch information
charleskawczynski committed Dec 10, 2020
1 parent 62189ae commit 0c64aa3
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 56 deletions.
11 changes: 11 additions & 0 deletions src/Atmos/Model/multiphysics_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ RemovePrecipitation(b::Bool) = (
RemovePrecipitation{TotalMoisture}(b),
)

"""
PrecipitationFlux{PV <: Union{Rain, Snow}} <: TendencyDef{Flux{FirstOrder}, PV}
Computes the precipitation flux as a sum of air velocity and terminal velocity
multiplied by the advected variable.
"""
struct PrecipitationFlux{PV <: Union{Rain, Snow}} <:
TendencyDef{Flux{FirstOrder}, PV} end

PrecipitationFlux() = (PrecipitationFlux{Rain}(), PrecipitationFlux{Snow}())

function remove_precipitation_sources(
s::RemovePrecipitation{PV},
atmos,
Expand Down
63 changes: 7 additions & 56 deletions src/Atmos/Model/precipitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,54 +56,6 @@ function compute_gradient_argument!(

source!(::PrecipitationModel, args...) = nothing

"""
PrecipitationFlux{PV <: Union{Rain, Snow}} <: TendencyDef{Flux{FirstOrder}, PV}
Computes the precipitation flux as a sum of air velocity and terminal velocity
multiplied by the advected variable.
"""
struct PrecipitationFlux{PV <: Union{Rain, Snow}} <:
TendencyDef{Flux{FirstOrder}, PV} end

PrecipitationFlux() = (PrecipitationFlux{Rain()}, PrecipitationFlux{Snow()})

function flux(::PrecipitationFlux{Rain}, m, state, aux, t, ts, direction)
FT = eltype(state)
u = state.ρu / state.ρ
q_rai = state.precipitation.ρq_rai / state.ρ

v_term_rai::FT = FT(0)
if q_rai > FT(0)
v_term_rai = terminal_velocity(
m.param_set,
m.param_set.microphys.rai,
state.ρ,
q_rai,
)
end

= vertical_unit_vector(m, aux)
return state.precipitation.ρq_rai * (u -* v_term_rai)
end
function flux(::PrecipitationFlux{Snow}, m, state, aux, t, ts, direction)
FT = eltype(state)
u = state.ρu / state.ρ
q_sno = state.precipitation.ρq_sno / state.ρ

v_term_sno::FT = FT(0)
if q_sno > FT(0)
v_term_sno = terminal_velocity(
m.param_set,
m.param_set.microphys.sno,
state.ρ,
q_sno,
)
end

= vertical_unit_vector(m, aux)
return state.precipitation.ρq_sno * (u -* v_term_sno)
end

"""
NoPrecipitation <: PrecipitationModel
Expand Down Expand Up @@ -170,18 +122,17 @@ end
function flux_second_order!(
precip::RainModel,
flux::Grad,
atmos::AtmosModel,
state::Vars,
diffusive::Vars,
aux::Vars,
t::Real,
D_t,
ts,
diffusive::Vars,
hyperdiffusive::Vars,
)
d_q_rai = (-D_t) .* diffusive.precipitation.∇q_rai

flux_second_order!(precip, flux, state, d_q_rai)
end
function flux_second_order!(precip::RainModel, flux::Grad, state::Vars, d_q_rai)
flux.precipitation.ρq_rai += d_q_rai * state.ρ
tend = Flux{SecondOrder}()
args = (atmos, state, aux, t, ts, diffusive, hyperdiffusive)
flux.precipitation.ρq_rai = Σfluxes(eq_tends(Rain(), atmos, tend), args...)
end

function source!(
Expand Down
39 changes: 39 additions & 0 deletions src/Atmos/Model/tendencies_precipitation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,45 @@
##### First order fluxes
#####

function flux(::PrecipitationFlux{Rain}, m, state, aux, t, ts, direction)
FT = eltype(state)
u = state.ρu / state.ρ
q_rai = state.precipitation.ρq_rai / state.ρ

v_term_rai::FT = FT(0)
if q_rai > FT(0)
v_term_rai = terminal_velocity(
m.param_set,
m.param_set.microphys.rai,
state.ρ,
q_rai,
)
end

= vertical_unit_vector(m, aux)
return state.precipitation.ρq_rai * (u -* v_term_rai)
end

function flux(::PrecipitationFlux{Snow}, m, state, aux, t, ts, direction)
FT = eltype(state)
u = state.ρu / state.ρ
q_sno = state.precipitation.ρq_sno / state.ρ

v_term_sno::FT = FT(0)
if q_sno > FT(0)
v_term_sno = terminal_velocity(
m.param_set,
m.param_set.microphys.sno,
state.ρ,
q_sno,
)
end

= vertical_unit_vector(m, aux)
return state.precipitation.ρq_sno * (u -* v_term_sno)
end


#####
##### Second order fluxes
#####
Expand Down

0 comments on commit 0c64aa3

Please sign in to comment.