Skip to content

Commit 74a88f9

Browse files
Remove coriolis forces from the cache
1 parent 5b0e533 commit 74a88f9

File tree

13 files changed

+162
-116
lines changed

13 files changed

+162
-116
lines changed

src/ClimaAtmos.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ include(joinpath("utils", "read_gcm_driven_scm_data.jl"))
2323
include(joinpath("utils", "AtmosArtifacts.jl"))
2424
import .AtmosArtifacts as AA
2525

26+
include(joinpath("core", "core_quantities.jl"))
2627
include(
2728
joinpath("parameterized_tendencies", "radiation", "radiation_utilities.jl"),
2829
)

src/cache/cache.jl

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ struct AtmosCache{
3333
"""ClimaAtmosParameters that have to be used"""
3434
params::CAP
3535

36-
"""Variables that are used generally, such as ᶜΦ"""
36+
"""Variables that are used generally"""
3737
core::COR
3838

3939
"""Used by update_surface_conditions! in set_precomputed_quantities! and coupler"""
@@ -89,10 +89,8 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
8989
ᶜcoord = Fields.local_geometry_field(Y.c).coordinates
9090
ᶠcoord = Fields.local_geometry_field(Y.f).coordinates
9191
grav = FT(CAP.grav(params))
92-
ᶜΦ = grav .* ᶜcoord.z
93-
ᶠΦ = grav .* ᶠcoord.z
94-
95-
(; ᶜf³, ᶠf¹²) = compute_coriolis(ᶜcoord, ᶠcoord, params)
92+
ᶜz = ᶜcoord.z
93+
ᶠz = ᶠcoord.z
9694

9795
ghost_buffer =
9896
!do_dss(axes(Y.c)) ? (;) :
@@ -121,11 +119,8 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
121119
Fields.level(Fields.local_geometry_field(Y.f), Fields.half)
122120

123121
core = (
124-
ᶜΦ,
125-
ᶠgradᵥ_ᶜΦ = ᶠgradᵥ.(ᶜΦ),
126-
ᶜgradᵥ_ᶠΦ = ᶜgradᵥ.(ᶠΦ),
127-
ᶜf³,
128-
ᶠf¹²,
122+
ᶠgradᵥ_ᶜΦ = ᶠgradᵥ.(Φ.(grav, ᶜz)),
123+
ᶜgradᵥ_ᶠΦ = ᶜgradᵥ.(Φ.(grav, ᶠz)),
129124
# Used by diagnostics such as hfres, evspblw
130125
surface_ct3_unit = CT3.(
131126
unit_basis_vector_data.(CT3, sfc_local_geometry)
@@ -192,32 +187,3 @@ function build_cache(Y, atmos, params, surface_setup, sim_info, aerosol_names)
192187

193188
return AtmosCache{map(typeof, args)...}(args...)
194189
end
195-
196-
197-
function compute_coriolis(ᶜcoord, ᶠcoord, params)
198-
if eltype(ᶜcoord) <: Geometry.LatLongZPoint
199-
Ω = CAP.Omega(params)
200-
global_geom = Spaces.global_geometry(axes(ᶜcoord))
201-
if global_geom isa Geometry.DeepSphericalGlobalGeometry
202-
@info "using deep atmosphere"
203-
coriolis_deep(coord::Geometry.LatLongZPoint) = Geometry.LocalVector(
204-
Geometry.Cartesian123Vector(zero(Ω), zero(Ω), 2 * Ω),
205-
global_geom,
206-
coord,
207-
)
208-
ᶜf³ = @. CT3(CT123(coriolis_deep(ᶜcoord)))
209-
ᶠf¹² = @. CT12(CT123(coriolis_deep(ᶠcoord)))
210-
else
211-
coriolis_shallow(coord::Geometry.LatLongZPoint) =
212-
Geometry.WVector(2 * Ω * sind(coord.lat))
213-
ᶜf³ = @. CT3(coriolis_shallow(ᶜcoord))
214-
ᶠf¹² = nothing
215-
end
216-
else
217-
f = CAP.f_plane_coriolis_frequency(params)
218-
coriolis_f_plane(coord) = Geometry.WVector(f)
219-
ᶜf³ = @. CT3(coriolis_f_plane(ᶜcoord))
220-
ᶠf¹² = nothing
221-
end
222-
return (; ᶜf³, ᶠf¹²)
223-
end

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ NVTX.@annotate function set_diagnostic_edmfx_draft_quantities_level!(
3434
mse_level,
3535
q_tot_level,
3636
p_level,
37-
Φ_level,
37+
z_level,
3838
)
3939
FT = eltype(thermo_params)
40+
grav = TDP.grav(thermo_params)
4041
@. ts_level = TD.PhaseEquil_phq(
4142
thermo_params,
4243
p_level,
43-
mse_level - Φ_level,
44+
mse_level - Φ(grav, z_level),
4445
q_tot_level,
4546
8,
4647
FT(0.0003),
@@ -92,7 +93,6 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_bottom_bc!(
9293
(; turbconv_model) = p.atmos
9394
FT = eltype(Y)
9495
n = n_mass_flux_subdomains(turbconv_model)
95-
(; ᶜΦ) = p.core
9696
(; ᶜp, ᶠu³, ᶜh_tot, ᶜK) = p.precomputed
9797
(; q_tot) = p.precomputed.ᶜspecific
9898
(; ustar, obukhov_length, buoyancy_flux, ρ_flux_h_tot, ρ_flux_q_tot) =
@@ -112,7 +112,6 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_bottom_bc!(
112112
q_tot_int_level = Fields.field_values(Fields.level(q_tot, 1))
113113

114114
p_int_level = Fields.field_values(Fields.level(ᶜp, 1))
115-
Φ_int_level = Fields.field_values(Fields.level(ᶜΦ, 1))
116115

117116
local_geometry_int_level =
118117
Fields.field_values(Fields.level(Fields.local_geometry_field(Y.c), 1))
@@ -187,7 +186,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_bottom_bc!(
187186
mseʲ_int_level,
188187
q_totʲ_int_level,
189188
p_int_level,
190-
Φ_int_level,
189+
z_int_level,
191190
)
192191
@. ρaʲ_int_level = ρʲ_int_level * FT(turbconv_params.surface_area)
193192
end
@@ -296,7 +295,6 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
296295
ᶜdz = Fields.Δz_field(axes(Y.c))
297296
(; params) = p
298297
(; dt) = p
299-
(; ᶜΦ) = p.core
300298
(; ᶜp, ᶠu³, ᶜts, ᶜh_tot, ᶜK) = p.precomputed
301299
(; q_tot) = p.precomputed.ᶜspecific
302300
(;
@@ -324,13 +322,17 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
324322
microphys_1m_params = CAP.microphysics_1m_params(params)
325323
turbconv_params = CAP.turbconv_params(params)
326324

327-
ᶠΦ = p.scratch.ᶠtemp_scalar
328-
@. ᶠΦ = CAP.grav(params) * ᶠz
325+
g = CAP.grav(params)
326+
ᶜcoords = Fields.coordinate_field(Y.c)
327+
ᶜz = Fields.coordinate_field(Y.c).z
328+
ᶠz = Fields.coordinate_field(Y.f).z
329+
global_geom = Spaces.global_geometry(axes(ᶜcoords))
330+
329331
ᶜ∇Φ³ = p.scratch.ᶜtemp_CT3
330-
@. ᶜ∇Φ³ = CT3(ᶜgradᵥ(ᶠΦ))
331-
@. ᶜ∇Φ³ += CT3(gradₕ(ᶜΦ))
332+
@. ᶜ∇Φ³ = CT3(ᶜgradᵥ(Φ(g, ᶠz)))
333+
@. ᶜ∇Φ³ += CT3(gradₕ(Φ(g, ᶜz)))
332334
ᶜ∇Φ₃ = p.scratch.ᶜtemp_C3
333-
@. ᶜ∇Φ₃ = ᶜgradᵥ(ᶠΦ)
335+
@. ᶜ∇Φ₃ = ᶜgradᵥ(Φ(g, ᶠz))
334336

335337
z_sfc_halflevel =
336338
Fields.field_values(Fields.level(Fields.coordinate_field(Y.f).z, half))
@@ -344,7 +346,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
344346
h_tot_level = Fields.field_values(Fields.level(ᶜh_tot, i))
345347
q_tot_level = Fields.field_values(Fields.level(q_tot, i))
346348
p_level = Fields.field_values(Fields.level(ᶜp, i))
347-
Φ_level = Fields.field_values(Fields.level(ᶜΦ, i))
349+
z_level = Fields.field_values(Fields.level(ᶜz, i))
348350
local_geometry_level = Fields.field_values(
349351
Fields.level(Fields.local_geometry_field(Y.c), i),
350352
)
@@ -355,7 +357,6 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
355357
end_index = fieldcount(eltype(∂x∂ξ_level)) # This will be 4 in 2D and 9 in 3D.
356358
∂x³∂ξ³_level = ∂x∂ξ_level.:($end_index)
357359

358-
Φ_prev_level = Fields.field_values(Fields.level(ᶜΦ, i - 1))
359360
∇Φ³_prev_level = Fields.field_values(Fields.level(ᶜ∇Φ³, i - 1))
360361
∇Φ³_data_prev_level = ∇Φ³_prev_level.components.data.:1
361362
∇Φ₃_prev_level = Fields.field_values(Fields.level(ᶜ∇Φ₃, i - 1))
@@ -554,7 +555,6 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
554555
q_rai_prev_level,
555556
q_sno_prev_level,
556557
tsʲ_prev_level,
557-
Φ_prev_level,
558558
dt,
559559
microphys_1m_params,
560560
thermo_params,
@@ -701,7 +701,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
701701
e_tot_0M_precipitation_sources_helper(
702702
thermo_params,
703703
tsʲ_prev_level,
704-
Φ_prev_level,
704+
Φ(g, z_prev_level),
705705
)
706706
)
707707
)
@@ -806,7 +806,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_do_integral!(
806806
mseʲ_level,
807807
q_totʲ_level,
808808
p_level,
809-
Φ_level,
809+
z_level,
810810
)
811811
end
812812
ρaʲs_level = Fields.field_values(Fields.level(ᶜρaʲs, i))
@@ -1070,7 +1070,6 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_precipita
10701070
ᶜqᵣ,
10711071
ᶜqₛ,
10721072
ᶜts,
1073-
p.core.ᶜΦ,
10741073
p.dt,
10751074
microphys_1m_params,
10761075
thermo_params,

src/cache/precomputed_quantities.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,10 @@ NVTX.@annotate function set_precomputed_quantities!(Y, p, t)
471471
thermo_params = CAP.thermodynamics_params(p.params)
472472
n = n_mass_flux_subdomains(turbconv_model)
473473
thermo_args = (thermo_params, moisture_model)
474-
(; ᶜΦ) = p.core
475474
(; ᶜspecific, ᶜu, ᶠu³, ᶜK, ᶜts, ᶜp) = p.precomputed
476475
ᶠuₕ³ = p.scratch.ᶠtemp_CT3
476+
ᶜz = Fields.coordinate_field(axes(Y.c)).z
477+
grav = TDP.grav(thermo_params)
477478

478479
@. ᶜspecific = specific_gs(Y.c)
479480
set_ᶠuₕ³!(ᶠuₕ³, Y)
@@ -499,7 +500,7 @@ NVTX.@annotate function set_precomputed_quantities!(Y, p, t)
499500
# @. ᶜK += Y.c.sgs⁰.ρatke / Y.c.ρ
500501
# TODO: We should think more about these increments before we use them.
501502
end
502-
@. ᶜts = ts_gs(thermo_args..., ᶜspecific, ᶜK, ᶜΦ, Y.c.ρ)
503+
@. ᶜts = ts_gs(thermo_args..., ᶜspecific, ᶜK, Φ(grav, ᶜz), Y.c.ρ)
503504
@. ᶜp = TD.air_pressure(thermo_params, ᶜts)
504505

505506
if turbconv_model isa AbstractEDMF

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_environment!(
2020

2121
thermo_params = CAP.thermodynamics_params(p.params)
2222
(; turbconv_model) = p.atmos
23-
(; ᶜΦ,) = p.core
23+
ᶜz = Fields.coordinate_field(axes(Y.c)).z
24+
grav = TDP.grav(thermo_params)
2425
(; ᶜp, ᶜh_tot, ᶜK) = p.precomputed
2526
(; ᶜtke⁰, ᶜρa⁰, ᶠu₃⁰, ᶜu⁰, ᶠu³⁰, ᶜK⁰, ᶜts⁰, ᶜρ⁰, ᶜmse⁰, ᶜq_tot⁰) =
2627
p.precomputed
@@ -44,7 +45,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_environment!(
4445
set_sgs_ᶠu₃!(u₃⁰, ᶠu₃⁰, Y, turbconv_model)
4546
set_velocity_quantities!(ᶜu⁰, ᶠu³⁰, ᶜK⁰, ᶠu₃⁰, Y.c.uₕ, ᶠuₕ³)
4647
# @. ᶜK⁰ += ᶜtke⁰
47-
@. ᶜts⁰ = TD.PhaseEquil_phq(thermo_params, ᶜp, ᶜmse⁰ - ᶜΦ, ᶜq_tot⁰)
48+
@. ᶜts⁰ = TD.PhaseEquil_phq(thermo_params, ᶜp, ᶜmse⁰ - Φ(grav, ᶜz), ᶜq_tot⁰)
4849
@. ᶜρ⁰ = TD.air_density(thermo_params, ᶜts⁰)
4950
return nothing
5051
end
@@ -72,7 +73,8 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_draft_and_bc!
7273
thermo_params = CAP.thermodynamics_params(params)
7374
turbconv_params = CAP.turbconv_params(params)
7475

75-
(; ᶜΦ,) = p.core
76+
grav = TDP.grav(thermo_params)
77+
ᶜz = Fields.coordinate_field(Y.c).z
7678
(; ᶜspecific, ᶜp, ᶜh_tot, ᶜK) = p.precomputed
7779
(; ᶜuʲs, ᶠu³ʲs, ᶜKʲs, ᶠKᵥʲs, ᶜtsʲs, ᶜρʲs) = p.precomputed
7880
(; ustar, obukhov_length, buoyancy_flux) = p.precomputed.sfc_conditions
@@ -90,7 +92,8 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_draft_and_bc!
9092

9193
set_velocity_quantities!(ᶜuʲ, ᶠu³ʲ, ᶜKʲ, ᶠu₃ʲ, Y.c.uₕ, ᶠuₕ³)
9294
@. ᶠKᵥʲ = (adjoint(CT3(ᶠu₃ʲ)) * ᶠu₃ʲ) / 2
93-
@. ᶜtsʲ = TD.PhaseEquil_phq(thermo_params, ᶜp, ᶜmseʲ - ᶜΦ, ᶜq_totʲ)
95+
@. ᶜtsʲ =
96+
TD.PhaseEquil_phq(thermo_params, ᶜp, ᶜmseʲ - Φ(grav, ᶜz), ᶜq_totʲ)
9497
@. ᶜρʲ = TD.air_density(thermo_params, ᶜtsʲ)
9598

9699
# EDMFX boundary condition:
@@ -153,12 +156,11 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_draft_and_bc!
153156
)
154157

155158
# Then overwrite the prognostic variables at first inetrior point.
156-
ᶜΦ_int_val = Fields.field_values(Fields.level(ᶜΦ, 1))
157159
ᶜtsʲ_int_val = Fields.field_values(Fields.level(ᶜtsʲ, 1))
158160
@. ᶜtsʲ_int_val = TD.PhaseEquil_phq(
159161
thermo_params,
160162
ᶜp_int_val,
161-
ᶜmseʲ_int_val - ᶜΦ_int_val,
163+
ᶜmseʲ_int_val - Φ(grav, ᶜz_int_val),
162164
ᶜq_totʲ_int_val,
163165
)
164166
sgsʲs_ρ_int_val = Fields.field_values(Fields.level(ᶜρʲs.:($j), 1))
@@ -416,7 +418,6 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_precipitation
416418
@assert !(p.atmos.moisture_model isa DryModel)
417419

418420
(; params, dt) = p
419-
(; ᶜΦ,) = p.core
420421
thp = CAP.thermodynamics_params(params)
421422
cmp = CAP.microphysics_1m_params(params)
422423

@@ -443,7 +444,6 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_precipitation
443444
ᶜqᵣ,
444445
ᶜqₛ,
445446
ᶜtsʲs.:($j),
446-
ᶜΦ,
447447
dt,
448448
cmp,
449449
thp,
@@ -462,7 +462,6 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_precipitation
462462
ᶜqᵣ,
463463
ᶜqₛ,
464464
ᶜts⁰,
465-
ᶜΦ,
466465
dt,
467466
cmp,
468467
thp,

src/core/core_quantities.jl

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import ClimaCore.Geometry
2+
3+
(lg, global_geom, params) = (lg, lg.coordinates, global_geom, params)
4+
5+
f¹²(lg, global_geom, params) = f¹²(lg, lg.coordinates, global_geom, params)
6+
7+
function (
8+
lg,
9+
coord::Geometry.LatLongZPoint,
10+
global_geom::Geometry.DeepSphericalGlobalGeometry,
11+
params,
12+
)
13+
Ω = CAP.Omega(params)
14+
c123 = Geometry.Cartesian123Vector(zero(Ω), zero(Ω), 2 * Ω)
15+
lv = Geometry.LocalVector(c123, global_geom, coord)
16+
CT3(CT123(lv, lg), lg)
17+
end
18+
19+
function f¹²(
20+
lg,
21+
coord::Geometry.LatLongZPoint,
22+
global_geom::Geometry.DeepSphericalGlobalGeometry,
23+
params,
24+
)
25+
Ω = CAP.Omega(params)
26+
c123 = Geometry.Cartesian123Vector(zero(Ω), zero(Ω), 2 * Ω)
27+
lv = Geometry.LocalVector(c123, global_geom, coord)
28+
CT12(CT123(lv, lg), lg)
29+
end
30+
31+
# Shallow sphere
32+
function (lg, coord::Geometry.LatLongZPoint, global_geom, params)
33+
Ω = CAP.Omega(params)
34+
CT3(Geometry.WVector(2 * Ω * sind(coord.lat), lg), lg)
35+
end
36+
37+
# Shallow cartesian
38+
function (lg, coord, global_geom, params)
39+
f = CAP.f_plane_coriolis_frequency(params)
40+
CT3(Geometry.WVector(f, lg), lg)
41+
end
42+
43+
f¹²(lg, coord::Geometry.LatLongZPoint, global_geom, params) =
44+
error("Not supported for $coord, $global_geom.")
45+
f¹²(lg, coord, global_geom, p) =
46+
error("Not supported for $coord, $global_geom.")
47+
48+
Φ(g, z) = g * z

src/diagnostics/Diagnostics.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import ClimaCore.Utilities: half
1212
import Thermodynamics as TD
1313

1414
import ..AtmosModel
15+
import ..Φ
1516
import ..AtmosCallback
1617
import ..EveryNSteps
1718

0 commit comments

Comments
 (0)