Skip to content

Commit

Permalink
Merge CliMA#1834
Browse files Browse the repository at this point in the history
1834: Move second order moisture flux to new tend spec r=charleskawczynski a=charleskawczynski

### Description

This PR
 - moves second order moisture fluxes (`MoistureDiffusion`) to the new tendency specification.
 - Changes the argument order in `flux_second_order!(::MoistureModel, args...)` so that arguments can be easily passed through



Co-authored-by: Charles Kawczynski <[email protected]>
  • Loading branch information
bors[bot] and charleskawczynski authored Dec 15, 2020
2 parents e7c5707 + 8256ecc commit 19da615
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 52 deletions.
18 changes: 9 additions & 9 deletions src/Atmos/Model/AtmosModel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,13 @@ equations.
t::Real,
direction,
)
ρu_pad = SVector(1, 1, 1)
flux_pad = SVector(1, 1, 1)
ts = recover_thermo_state(m, state, aux)
tend = Flux{FirstOrder}()
args = (m, state, aux, t, ts, direction)
flux.ρ = Σfluxes(eq_tends(Mass(), m, tend), args...)
flux.ρu = Σfluxes(eq_tends(Momentum(), m, tend), args...) .* ρu_pad
flux.ρe = Σfluxes(eq_tends(Energy(), m, tend), args...)
flux.ρ = Σfluxes(eq_tends(Mass(), m, tend), args...) .* flux_pad
flux.ρu = Σfluxes(eq_tends(Momentum(), m, tend), args...) .* flux_pad
flux.ρe = Σfluxes(eq_tends(Energy(), m, tend), args...) .* flux_pad

flux_first_order!(m.moisture, m, flux, state, aux, t, ts, direction)
flux_first_order!(m.precipitation, m, flux, state, aux, t, ts, direction)
Expand Down Expand Up @@ -633,17 +633,17 @@ function. Contributions from subcomponents are then assembled (pointwise).
aux::Vars,
t::Real,
)
ρu_pad = SVector(1, 1, 1)
flux_pad = SVector(1, 1, 1)
ts = recover_thermo_state(atmos, state, aux)
tend = Flux{SecondOrder}()
args = (atmos, state, aux, t, ts, diffusive, hyperdiffusive)
flux.ρ = Σfluxes(eq_tends(Mass(), atmos, tend), args...) .* ρu_pad
flux.ρu = Σfluxes(eq_tends(Momentum(), atmos, tend), args...) .* ρu_pad
flux.ρe = Σfluxes(eq_tends(Energy(), atmos, tend), args...)
flux.ρ = Σfluxes(eq_tends(Mass(), atmos, tend), args...) .* flux_pad
flux.ρu = Σfluxes(eq_tends(Momentum(), atmos, tend), args...) .* flux_pad
flux.ρe = Σfluxes(eq_tends(Energy(), atmos, tend), args...) .* flux_pad

ν, D_t, τ = turbulence_tensors(atmos, state, diffusive, aux, t)

flux_second_order!(atmos.moisture, flux, state, diffusive, aux, t, D_t)
flux_second_order!(atmos.moisture, flux, args...)
flux_second_order!(atmos.precipitation, flux, args...)
flux_second_order!(
atmos.hyperdiffusion,
Expand Down
25 changes: 17 additions & 8 deletions src/Atmos/Model/atmos_tendencies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,32 @@ eq_tends(pv::PV, ::AtmosModel, ::Flux{FirstOrder}) where {N, PV <: Tracers{N}} =
##### Second order fluxes
#####

eq_tends(
pv::PV,
::DryModel,
::Flux{SecondOrder},
) where {PV <: Union{Mass, Momentum, Moisture}} = ()
eq_tends(
pv::PV,
::MoistureModel,
::Flux{SecondOrder},
) where {PV <: Union{Mass, Momentum, Moisture}} = (MoistureDiffusion{PV}(),)

# Mass
moist_diffusion(pv::PV, ::DryModel) where {PV <: Mass} = ()
moist_diffusion(pv::PV, ::MoistureModel) where {PV <: Mass} =
(MoistureDiffusion{PV}(),)
eq_tends(pv::PV, m::AtmosModel, ::Flux{SecondOrder}) where {PV <: Mass} =
(moist_diffusion(pv, m.moisture)...,)
eq_tends(pv::PV, m::AtmosModel, tt::Flux{SecondOrder}) where {PV <: Mass} =
(eq_tends(pv, m.moisture, tt)...,)

# Momentum
eq_tends(pv::PV, ::AtmosModel, ::Flux{SecondOrder}) where {PV <: Momentum} =
(ViscousStress{PV}(),)
eq_tends(pv::PV, m::AtmosModel, tt::Flux{SecondOrder}) where {PV <: Momentum} =
(ViscousStress{PV}(), eq_tends(pv, m.moisture, tt)...)

# Energy
eq_tends(pv::PV, ::AtmosModel, ::Flux{SecondOrder}) where {PV <: Energy} =
(ViscousFlux{PV}(), DiffEnthalpyFlux{PV}())

# Moisture
eq_tends(pv::PV, ::AtmosModel, ::Flux{SecondOrder}) where {PV <: Moisture} = ()
eq_tends(pv::PV, m::AtmosModel, tt::Flux{SecondOrder}) where {PV <: Moisture} =
(eq_tends(pv, m.moisture, tt)...,)

# Precipitation
eq_tends(
Expand Down
58 changes: 25 additions & 33 deletions src/Atmos/Model/moisture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ function compute_gradient_flux!(
function flux_second_order!(
::MoistureModel,
flux::Grad,
atmos::AtmosModel,
state::Vars,
diffusive::Vars,
aux::Vars,
t::Real,
D_t,
ts,
diffusive::Vars,
hyperdiffusive::Vars,
) end

function compute_gradient_argument!(
Expand Down Expand Up @@ -167,19 +169,18 @@ end
function flux_second_order!(
moist::EquilMoist,
flux::Grad,
atmos::AtmosModel,
state::Vars,
diffusive::Vars,
aux::Vars,
t::Real,
D_t,
ts,
diffusive::Vars,
hyperdiffusive::Vars,
)
d_q_tot = (-D_t) .* diffusive.moisture.∇q_tot
flux_second_order!(moist, flux, state, d_q_tot)
end
#TODO: Consider whether to not pass ρ and ρu (not state), foc BCs reasons
function flux_second_order!(moist::EquilMoist, flux::Grad, state::Vars, d_q_tot)
flux.ρu += d_q_tot .* state.ρu'
flux.moisture.ρq_tot += d_q_tot * state.ρ
tend = Flux{SecondOrder}()
args = (atmos, state, aux, t, ts, diffusive, hyperdiffusive)
flux.moisture.ρq_tot =
Σfluxes(eq_tends(TotalMoisture(), atmos, tend), args...)
end

function source!(m::EquilMoist, source::Vars, atmos::AtmosModel, args)
Expand Down Expand Up @@ -269,33 +270,24 @@ function flux_first_order!(
end

function flux_second_order!(
moist::NonEquilMoist,
::NonEquilMoist,
flux::Grad,
atmos::AtmosModel,
state::Vars,
diffusive::Vars,
aux::Vars,
t::Real,
D_t,
)
d_q_tot = (-D_t) .* diffusive.moisture.∇q_tot
d_q_liq = (-D_t) .* diffusive.moisture.∇q_liq
d_q_ice = (-D_t) .* diffusive.moisture.∇q_ice

flux_second_order!(moist, flux, state, d_q_tot, d_q_liq, d_q_ice)
end

function flux_second_order!(
moist::NonEquilMoist,
flux::Grad,
state::Vars,
d_q_tot,
d_q_liq,
d_q_ice,
ts,
diffusive::Vars,
hyperdiffusive::Vars,
)
flux.ρu += d_q_tot .* state.ρu'
flux.moisture.ρq_tot += d_q_tot * state.ρ
flux.moisture.ρq_liq += d_q_liq * state.ρ
flux.moisture.ρq_ice += d_q_ice * state.ρ
tend = Flux{SecondOrder}()
args = (atmos, state, aux, t, ts, diffusive, hyperdiffusive)
flux.moisture.ρq_tot =
Σfluxes(eq_tends(TotalMoisture(), atmos, tend), args...)
flux.moisture.ρq_liq =
Σfluxes(eq_tends(LiquidMoisture(), atmos, tend), args...)
flux.moisture.ρq_ice =
Σfluxes(eq_tends(IceMoisture(), atmos, tend), args...)
end

function source!(m::NonEquilMoist, source::Vars, atmos::AtmosModel, args)
Expand Down
2 changes: 2 additions & 0 deletions src/Atmos/Model/multiphysics_types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct Pressure{PV <: Energy} <: TendencyDef{Flux{FirstOrder}, PV} end
struct Advect{PV} <: TendencyDef{Flux{FirstOrder}, PV} end
struct Diffusion{PV} <: TendencyDef{Flux{SecondOrder}, PV} end

struct MoistureDiffusion{PV <: Union{Mass, Momentum, Moisture}} <:
TendencyDef{Flux{SecondOrder}, PV} end

export RemovePrecipitation
"""
Expand Down
1 change: 0 additions & 1 deletion src/Atmos/Model/tendencies_mass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ end
##### Second order fluxes
#####

struct MoistureDiffusion{PV <: Mass} <: TendencyDef{Flux{SecondOrder}, PV} end
function flux(
::MoistureDiffusion{Mass},
m,
Expand Down
49 changes: 49 additions & 0 deletions src/Atmos/Model/tendencies_moisture.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,55 @@ function flux(::Advect{IceMoisture}, m, state, aux, t, ts, direction)
return u * state.moisture.ρq_ice
end

#####
##### Second order fluxes
#####

function flux(
::MoistureDiffusion{TotalMoisture},
m,
state,
aux,
t,
ts,
diffusive,
hyperdiff,
)
ν, D_t, τ = turbulence_tensors(m, state, diffusive, aux, t)
d_q_tot = (-D_t) .* diffusive.moisture.∇q_tot
return d_q_tot * state.ρ
end

function flux(
::MoistureDiffusion{LiquidMoisture},
m,
state,
aux,
t,
ts,
diffusive,
hyperdiff,
)
ν, D_t, τ = turbulence_tensors(m, state, diffusive, aux, t)
d_q_liq = (-D_t) .* diffusive.moisture.∇q_liq
return d_q_liq * state.ρ
end

function flux(
::MoistureDiffusion{IceMoisture},
m,
state,
aux,
t,
ts,
diffusive,
hyperdiff,
)
ν, D_t, τ = turbulence_tensors(m, state, diffusive, aux, t)
d_q_ice = (-D_t) .* diffusive.moisture.∇q_ice
return d_q_ice * state.ρ
end

#####
##### Sources
#####
Expand Down
18 changes: 17 additions & 1 deletion src/Atmos/Model/tendencies_momentum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,25 @@ function flux(
ts,
diffusive,
hyperdiff,
)
pad = (state.ρu .* (state.ρu / state.ρ)') * 0
ν, D_t, τ = turbulence_tensors(m, state, diffusive, aux, t)
return pad + τ * state.ρ
end

function flux(
::MoistureDiffusion{Momentum},
m,
state,
aux,
t,
ts,
diffusive,
hyperdiff,
)
ν, D_t, τ = turbulence_tensors(m, state, diffusive, aux, t)
return τ * state.ρ
d_q_tot = (-D_t) .* diffusive.moisture.∇q_tot
return d_q_tot .* state.ρu'
end

#####
Expand Down

0 comments on commit 19da615

Please sign in to comment.