Skip to content

Commit 63bdc13

Browse files
committed
chore: clean up some files
1 parent 9405d3c commit 63bdc13

File tree

7 files changed

+156
-424
lines changed

7 files changed

+156
-424
lines changed

src/cache/precipitation_precomputed_quantities.jl

Lines changed: 40 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ function set_precipitation_velocities!(Y, p, _, _, _)
4343
@. ᶜwₕhₜ = Geometry.WVector(0)
4444
return nothing
4545
end
46-
function set_precipitation_velocities!(
47-
Y,
48-
p,
46+
function set_precipitation_velocities!(Y, p,
4947
moisture_model::NonEquilMoistModel,
5048
microphysics_model::Microphysics1Moment,
5149
_,
@@ -100,9 +98,7 @@ function set_precipitation_velocities!(
10098
) / Y.c.ρ
10199
return nothing
102100
end
103-
function set_precipitation_velocities!(
104-
Y,
105-
p,
101+
function set_precipitation_velocities!(Y, p,
106102
moisture_model::NonEquilMoistModel,
107103
microphysics_model::Microphysics1Moment,
108104
turbconv_model::PrognosticEDMFX,
@@ -233,9 +229,7 @@ function set_precipitation_velocities!(
233229

234230
return nothing
235231
end
236-
function set_precipitation_velocities!(
237-
Y,
238-
p,
232+
function set_precipitation_velocities!(Y, p,
239233
moisture_model::NonEquilMoistModel,
240234
microphysics_model::Microphysics2Moment,
241235
_,
@@ -322,9 +316,7 @@ function set_precipitation_velocities!(
322316
) / Y.c.ρ
323317
return nothing
324318
end
325-
function set_precipitation_velocities!(
326-
Y,
327-
p,
319+
function set_precipitation_velocities!(Y, p,
328320
moisture_model::NonEquilMoistModel,
329321
microphysics_model::Microphysics2Moment,
330322
turbconv_model::PrognosticEDMFX,
@@ -589,23 +581,13 @@ function set_precipitation_cache!(Y, p, ::Microphysics0Moment, _)
589581
thermo_params = CAP.thermodynamics_params(params)
590582
@. ᶜS_ρq_tot =
591583
Y.c.ρ * q_tot_0M_precipitation_sources(
592-
thermo_params,
593-
cm_params,
594-
dt,
595-
Y.c.ρq_tot / Y.c.ρ,
596-
ᶜts,
584+
thermo_params, cm_params, dt, Y.c.ρq_tot / Y.c.ρ, ᶜts,
597585
)
598-
@. ᶜS_ρe_tot =
599-
ᶜS_ρq_tot *
600-
e_tot_0M_precipitation_sources_helper(thermo_params, ᶜts, ᶜΦ)
586+
@. ᶜS_ρe_tot = ᶜS_ρq_tot *
587+
e_tot_0M_precipitation_sources_helper(thermo_params, ᶜts, ᶜΦ)
601588
return nothing
602589
end
603-
function set_precipitation_cache!(
604-
Y,
605-
p,
606-
::Microphysics0Moment,
607-
::DiagnosticEDMFX,
608-
)
590+
function set_precipitation_cache!(Y, p, ::Microphysics0Moment, ::DiagnosticEDMFX)
609591
# For environment we multiply by grid mean ρ and not byᶜρa⁰
610592
# assuming a⁰=1
611593
(; ᶜΦ) = p.core
@@ -619,28 +601,17 @@ function set_precipitation_cache!(
619601

620602
@. ᶜS_ρq_tot = ᶜSqₜᵖ⁰ * ρ
621603
@. ᶜS_ρe_tot =
622-
ᶜSqₜᵖ⁰ *
623-
ρ *
604+
ᶜSqₜᵖ⁰ * ρ *
624605
e_tot_0M_precipitation_sources_helper(thermo_params, ᶜts, ᶜΦ)
625606
for j in 1:n
626607
@. ᶜS_ρq_tot += ᶜSqₜᵖʲs.:($$j) * ᶜρaʲs.:($$j)
627608
@. ᶜS_ρe_tot +=
628-
ᶜSqₜᵖʲs.:($$j) *
629-
ᶜρaʲs.:($$j) *
630-
e_tot_0M_precipitation_sources_helper(
631-
thermo_params,
632-
ᶜtsʲs.:($$j),
633-
ᶜΦ,
634-
)
609+
ᶜSqₜᵖʲs.:($$j) * ᶜρaʲs.:($$j) *
610+
e_tot_0M_precipitation_sources_helper(thermo_params, ᶜtsʲs.:($$j), ᶜΦ)
635611
end
636612
return nothing
637613
end
638-
function set_precipitation_cache!(
639-
Y,
640-
p,
641-
::Microphysics0Moment,
642-
::PrognosticEDMFX,
643-
)
614+
function set_precipitation_cache!(Y, p, ::Microphysics0Moment, ::PrognosticEDMFX)
644615
(; ᶜΦ) = p.core
645616
(; ᶜSqₜᵖ⁰, ᶜSqₜᵖʲs) = p.precomputed
646617
(; ᶜS_ρq_tot, ᶜS_ρe_tot) = p.precomputed
@@ -652,25 +623,19 @@ function set_precipitation_cache!(
652623

653624
@. ᶜS_ρq_tot = ᶜSqₜᵖ⁰ * ᶜρa⁰
654625
@. ᶜS_ρe_tot =
655-
ᶜSqₜᵖ⁰ *
656-
ᶜρa⁰ *
626+
ᶜSqₜᵖ⁰ * ᶜρa⁰ *
657627
e_tot_0M_precipitation_sources_helper(thermo_params, ᶜts⁰, ᶜΦ)
658628
for j in 1:n
659629
@. ᶜS_ρq_tot += ᶜSqₜᵖʲs.:($$j) * Y.c.sgsʲs.:($$j).ρa
660630
@. ᶜS_ρe_tot +=
661-
ᶜSqₜᵖʲs.:($$j) *
662-
Y.c.sgsʲs.:($$j).ρa *
663-
e_tot_0M_precipitation_sources_helper(
664-
thermo_params,
665-
ᶜtsʲs.:($$j),
666-
ᶜΦ,
667-
)
631+
ᶜSqₜᵖʲs.:($$j) * Y.c.sgsʲs.:($$j).ρa *
632+
e_tot_0M_precipitation_sources_helper(thermo_params, ᶜtsʲs.:($$j), ᶜΦ)
668633
end
669634
return nothing
670635
end
671636
function set_precipitation_cache!(Y, p, ::Microphysics1Moment, _)
672637
(; dt) = p
673-
(; ᶜts, ᶜwᵣ, ᶜwₛ, ᶜu) = p.precomputed
638+
(; ᶜts) = p.precomputed
674639
(; ᶜSqₗᵖ, ᶜSqᵢᵖ, ᶜSqᵣᵖ, ᶜSqₛᵖ) = p.precomputed
675640

676641
ᶜq_tot = @. lazy(specific(Y.c.ρq_tot, Y.c.ρ))
@@ -681,7 +646,6 @@ function set_precipitation_cache!(Y, p, ::Microphysics1Moment, _)
681646

682647
ᶜSᵖ = p.scratch.ᶜtemp_scalar
683648
ᶜSᵖ_snow = p.scratch.ᶜtemp_scalar_2
684-
ᶜ∇T = p.scratch.ᶜtemp_CT123
685649

686650
# get thermodynamics and 1-moment microphysics params
687651
(; params) = p
@@ -690,58 +654,25 @@ function set_precipitation_cache!(Y, p, ::Microphysics1Moment, _)
690654

691655
# compute precipitation source terms on the grid mean
692656
compute_precipitation_sources!(
693-
ᶜSᵖ,
694-
ᶜSᵖ_snow,
695-
ᶜSqₗᵖ,
696-
ᶜSqᵢᵖ,
697-
ᶜSqᵣᵖ,
698-
ᶜSqₛᵖ,
699-
Y.c.ρ,
700-
ᶜq_tot,
701-
ᶜq_liq,
702-
ᶜq_ice,
703-
ᶜq_rai,
704-
ᶜq_sno,
705-
ᶜts,
706-
dt,
707-
cmp,
708-
thp,
657+
ᶜSᵖ, ᶜSᵖ_snow, ᶜSqₗᵖ, ᶜSqᵢᵖ, ᶜSqᵣᵖ, ᶜSqₛᵖ,
658+
Y.c.ρ, ᶜq_tot, ᶜq_liq, ᶜq_ice, ᶜq_rai, ᶜq_sno,
659+
ᶜts, dt, cmp, thp,
709660
)
710661

711662
# compute precipitation sinks on the grid mean
712663
compute_precipitation_sinks!(
713-
ᶜSᵖ,
714-
ᶜSqᵣᵖ,
715-
ᶜSqₛᵖ,
716-
Y.c.ρ,
717-
ᶜq_tot,
718-
ᶜq_liq,
719-
ᶜq_ice,
720-
ᶜq_rai,
721-
ᶜq_sno,
722-
ᶜts,
723-
dt,
724-
cmp,
725-
thp,
664+
ᶜSᵖ, ᶜSqᵣᵖ, ᶜSqₛᵖ,
665+
Y.c.ρ, ᶜq_tot, ᶜq_liq, ᶜq_ice, ᶜq_rai, ᶜq_sno,
666+
ᶜts, dt, cmp, thp,
726667
)
727668
return nothing
728669
end
729-
function set_precipitation_cache!(
730-
Y,
731-
p,
732-
::Microphysics1Moment,
733-
::DiagnosticEDMFX,
734-
)
670+
function set_precipitation_cache!(Y, p, ::Microphysics1Moment, ::DiagnosticEDMFX)
735671
# Nothing needs to be done on the grid mean. The Sources are computed
736672
# in edmf sub-domains.
737673
return nothing
738674
end
739-
function set_precipitation_cache!(
740-
Y,
741-
p,
742-
::Microphysics1Moment,
743-
::PrognosticEDMFX,
744-
)
675+
function set_precipitation_cache!(Y, p, ::Microphysics1Moment, ::PrognosticEDMFX)
745676
# Nothing needs to be done on the grid mean. The Sources are computed
746677
# in edmf sub-domains.
747678
return nothing
@@ -788,21 +719,11 @@ function set_precipitation_cache!(Y, p, ::Microphysics2Moment, _)
788719

789720
return nothing
790721
end
791-
function set_precipitation_cache!(
792-
Y,
793-
p,
794-
::Microphysics2Moment,
795-
::DiagnosticEDMFX,
796-
)
722+
function set_precipitation_cache!(Y, p, ::Microphysics2Moment, ::DiagnosticEDMFX)
797723
error("Not implemented yet")
798724
return nothing
799725
end
800-
function set_precipitation_cache!(
801-
Y,
802-
p,
803-
::Microphysics2Moment,
804-
::PrognosticEDMFX,
805-
)
726+
function set_precipitation_cache!(Y, p, ::Microphysics2Moment, ::PrognosticEDMFX)
806727
# Nothing needs to be done on the grid mean. The Sources are computed
807728
# in edmf sub-domains.
808729
return nothing
@@ -842,42 +763,35 @@ end
842763
"""
843764
set_precipitation_surface_fluxes!(Y, p, precipitation model)
844765
845-
Computes the flux of rain and snow at the surface. For the 0-moment microphysics
846-
it is an integral of the source terms in the column. For 1-moment microphysics
847-
it is the flux through the bottom cell face.
766+
Computes the flux of rain and snow at the surface.
767+
768+
For the 0-moment microphysics it is an integral of the source terms in the column.
769+
For 1-moment microphysics it is the flux through the bottom cell face.
848770
"""
849771
set_precipitation_surface_fluxes!(Y, p, _) = nothing
850-
function set_precipitation_surface_fluxes!(
851-
Y,
852-
p,
853-
microphysics_model::Microphysics0Moment,
854-
)
855-
ᶜT = p.scratch.ᶜtemp_scalar
772+
function set_precipitation_surface_fluxes!(Y, p, ::Microphysics0Moment)
856773
(; ᶜts) = p.precomputed # assume ᶜts has been updated
857774
(; ᶜS_ρq_tot, ᶜS_ρe_tot) = p.precomputed
858775
(; surface_rain_flux, surface_snow_flux) = p.precomputed
859776
(; col_integrated_precip_energy_tendency) = p.conservation_check
860777

861778
# update total column energy source for surface energy balance
862779
Operators.column_integral_definite!(
863-
col_integrated_precip_energy_tendency,
864-
ᶜS_ρe_tot,
780+
col_integrated_precip_energy_tendency, ᶜS_ρe_tot,
865781
)
866782
# update surface precipitation fluxes in cache for coupler's use
867783
thermo_params = CAP.thermodynamics_params(p.params)
868784
T_freeze = TD.Parameters.T_freeze(thermo_params)
869785
FT = eltype(p.params)
870-
@. ᶜT = TD.air_temperature(thermo_params, ᶜts)
786+
ᶜT = @. lazy(TD.air_temperature(thermo_params, ᶜts))
871787
ᶜ3d_rain = @. lazy(ifelse(ᶜT >= T_freeze, ᶜS_ρq_tot, FT(0)))
872788
ᶜ3d_snow = @. lazy(ifelse(ᶜT < T_freeze, ᶜS_ρq_tot, FT(0)))
873789
Operators.column_integral_definite!(surface_rain_flux, ᶜ3d_rain)
874790
Operators.column_integral_definite!(surface_snow_flux, ᶜ3d_snow)
875791
return nothing
876792
end
877-
function set_precipitation_surface_fluxes!(
878-
Y,
879-
p,
880-
microphysics_model::Union{Microphysics1Moment, Microphysics2Moment},
793+
function set_precipitation_surface_fluxes!(Y, p,
794+
::Union{Microphysics1Moment, Microphysics2Moment},
881795
)
882796
(; surface_rain_flux, surface_snow_flux) = p.precomputed
883797
(; col_integrated_precip_energy_tendency) = p.conservation_check
@@ -905,21 +819,16 @@ function set_precipitation_surface_fluxes!(
905819
@. ᶜq_sno = specific(Y.c.ρq_sno, Y.c.ρ)
906820
@. ᶜq_liq = specific(Y.c.ρq_liq, Y.c.ρ)
907821
@. ᶜq_ice = specific(Y.c.ρq_ice, Y.c.ρ)
908-
sfc_qᵣ =
909-
Fields.Field(Fields.field_values(Fields.level(ᶜq_rai, 1)), sfc_space)
910-
sfc_qₛ =
911-
Fields.Field(Fields.field_values(Fields.level(ᶜq_sno, 1)), sfc_space)
912-
sfc_qₗ =
913-
Fields.Field(Fields.field_values(Fields.level(ᶜq_liq, 1)), sfc_space)
914-
sfc_qᵢ =
915-
Fields.Field(Fields.field_values(Fields.level(ᶜq_ice, 1)), sfc_space)
822+
sfc_qᵣ = Fields.Field(Fields.field_values(Fields.level(ᶜq_rai, 1)), sfc_space)
823+
sfc_qₛ = Fields.Field(Fields.field_values(Fields.level(ᶜq_sno, 1)), sfc_space)
824+
sfc_qₗ = Fields.Field(Fields.field_values(Fields.level(ᶜq_liq, 1)), sfc_space)
825+
sfc_qᵢ = Fields.Field(Fields.field_values(Fields.level(ᶜq_ice, 1)), sfc_space)
916826
sfc_wᵣ = Fields.Field(Fields.field_values(Fields.level(ᶜwᵣ, 1)), sfc_space)
917827
sfc_wₛ = Fields.Field(Fields.field_values(Fields.level(ᶜwₛ, 1)), sfc_space)
918828
sfc_wₗ = Fields.Field(Fields.field_values(Fields.level(ᶜwₗ, 1)), sfc_space)
919829
sfc_wᵢ = Fields.Field(Fields.field_values(Fields.level(ᶜwᵢ, 1)), sfc_space)
920830
sfc_wₕhₜ = Fields.Field(
921-
Fields.field_values(Fields.level(ᶜwₕhₜ.components.data.:1, 1)),
922-
sfc_space,
831+
Fields.field_values(Fields.level(ᶜwₕhₜ.components.data.:1, 1)), sfc_space,
923832
)
924833

925834
@. surface_rain_flux = sfc_ρ * (sfc_qᵣ * (-sfc_wᵣ) + sfc_qₗ * (-sfc_wₗ))

src/prognostic_equations/surface_flux.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,12 @@ function surface_flux_tendency!(Yₜ, Y, p, t)
109109
thermo_params = CAP.thermodynamics_params(params)
110110

111111
if !disable_momentum_vertical_diffusion(p.atmos.vertical_diffusion)
112-
btt =
113-
boundary_tendency_momentum(Y.c.ρ, Y.c.uₕ, sfc_conditions.ρ_flux_uₕ)
112+
btt = boundary_tendency_momentum(Y.c.ρ, Y.c.uₕ, sfc_conditions.ρ_flux_uₕ)
114113
@. Yₜ.c.uₕ -= btt
115114
end
116115

117-
ᶜh_tot = @. lazy(
118-
TD.total_specific_enthalpy(
119-
thermo_params,
120-
ᶜts,
121-
specific(Y.c.ρe_tot, Y.c.ρ),
122-
),
123-
)
116+
ᶜe_tot = @. lazy(specific(Y.c.ρe_tot, Y.c.ρ))
117+
ᶜh_tot = @. lazy(TD.total_specific_enthalpy(thermo_params, ᶜts, ᶜe_tot))
124118
btt = boundary_tendency_scalar(ᶜh_tot, sfc_conditions.ρ_flux_h_tot)
125119
@. Yₜ.c.ρe_tot -= btt
126120
ρ_flux_χ = p.scratch.sfc_temp_C3

0 commit comments

Comments
 (0)