Skip to content

Commit 259289f

Browse files
authored
Stop hard coding in gravity. (#47)
Stop hard coding in gravity.
2 parents 7fc4470 + 1fa7d7a commit 259289f

File tree

4 files changed

+21
-25
lines changed

4 files changed

+21
-25
lines changed

src/models.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mutable struct CompressibleModel{A, FT, G, M, D, T, TS, B, C, TC, DF, MP, F, P,
2424
forcing :: F
2525
parameters :: P
2626
reference_pressure :: FT
27+
gravity :: FT
2728
slow_forcings :: SF
2829
right_hand_sides :: RHS
2930
intermediate_vars :: IV
@@ -34,6 +35,9 @@ end
3435
##### Constructor for compressible models
3536
#####
3637

38+
const pₛ_Earth = 100000
39+
const g_Earth = 9.80665
40+
3741
function CompressibleModel(;
3842
grid,
3943
architecture = CPU(),
@@ -50,7 +54,8 @@ function CompressibleModel(;
5054
microphysics = nothing,
5155
forcing = ModelForcing(),
5256
parameters = nothing,
53-
reference_pressure = 100000,
57+
reference_pressure = pₛ_Earth,
58+
gravity = g_Earth,
5459
slow_forcings = ForcingFields(architecture, grid, tracernames(tracers)),
5560
right_hand_sides = RightHandSideFields(architecture, grid, tracernames(tracers)),
5661
intermediate_vars = RightHandSideFields(architecture, grid, tracernames(tracers)),
@@ -61,14 +66,15 @@ function CompressibleModel(;
6166
validate_microphysics(microphysics, tracers)
6267

6368
reference_pressure = float_type(reference_pressure)
64-
tracers = TracerFields(architecture, grid, tracers)
69+
gravity = float_type(gravity)
6570

71+
tracers = TracerFields(architecture, grid, tracers)
6672
forcing = ModelForcing(tracernames(tracers), forcing)
6773
closure = with_tracers(tracernames(tracers), closure)
6874

6975
return CompressibleModel(architecture, grid, clock, momenta, density, prognostic_temperature,
7076
tracers, buoyancy, coriolis, closure, diffusivities, microphysics,
71-
forcing, parameters, reference_pressure, slow_forcings,
77+
forcing, parameters, reference_pressure, gravity, slow_forcings,
7278
right_hand_sides, intermediate_vars, acoustic_time_stepper)
7379
end
7480

@@ -93,9 +99,7 @@ function ForcingFields(arch, grid, tracernames)
9399
ρv = FaceFieldY(arch, grid)
94100
ρw = FaceFieldZ(arch, grid)
95101
momenta = (ρu=ρu, ρv=ρv, ρw=ρw)
96-
97102
tracers = TracerFields(arch, grid, tracernames)
98-
99103
return merge(momenta, tracers)
100104
end
101105

@@ -105,8 +109,6 @@ function RightHandSideFields(arch, grid, tracernames)
105109
ρw = FaceFieldZ(arch, grid)
106110
ρ = CellField(arch, grid)
107111
momenta_and_density = (ρu=ρu, ρv=ρv, ρw=ρw, ρ=ρ)
108-
109112
tracers = TracerFields(arch, grid, tracernames)
110-
111113
return merge(momenta_and_density, tracers)
112114
end

src/right_hand_sides.jl

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
####
2-
#### Dirty hacks!
3-
####
4-
5-
const grav = 9.80665
6-
71
####
82
#### Element-wise forcing and right-hand-side calculations
93
####
@@ -33,28 +27,28 @@ end
3327
@inline FC(i, j, k, grid, closure, ρᵈ, C, tracer_index, K̃) =
3428
@inbounds ρᵈ[i, j, k] * ∇_κ_∇c(i, j, k, grid, closure, ρᵈ, C, Val(tracer_index), K̃)
3529

36-
@inline function RU(i, j, k, grid, pt, b, pₛ, mp, ρᵈ, Ũ, C, FU)
30+
@inline function RU(i, j, k, grid, pt, b, mp, pₛ, ρᵈ, Ũ, C, FU)
3731
@inbounds begin
3832
return (- div_ρuũ(i, j, k, grid, ρᵈ, Ũ)
3933
- ρᵈ_over_ρᵐ(i, j, k, grid, mp, ρᵈ, C) * ∂p∂x(i, j, k, grid, pt, b, ρᵈ, C)
4034
+ FU[i, j, k])
4135
end
4236
end
4337

44-
@inline function RV(i, j, k, grid, pt, b, pₛ, mp, ρᵈ, Ũ, C, FV)
38+
@inline function RV(i, j, k, grid, pt, b, mp, pₛ, ρᵈ, Ũ, C, FV)
4539
@inbounds begin
4640
return (- div_ρvũ(i, j, k, grid, ρᵈ, Ũ)
4741
- ρᵈ_over_ρᵐ(i, j, k, grid, mp, ρᵈ, C) * ∂p∂y(i, j, k, grid, pt, b, ρᵈ, C)
4842
+ FV[i, j, k])
4943
end
5044
end
5145

52-
@inline function RW(i, j, k, grid, pt, b, pₛ, mp, ρᵈ, Ũ, C, FW)
46+
@inline function RW(i, j, k, grid, pt, b, mp, pₛ, gravity, ρᵈ, Ũ, C, FW)
5347
@inbounds begin
5448
return (- div_ρwũ(i, j, k, grid, ρᵈ, Ũ)
5549
- ρᵈ_over_ρᵐ(i, j, k, grid, mp, ρᵈ, C) * (
5650
∂p∂z(i, j, k, grid, pt, b, ρᵈ, C)
57-
+ buoyancy_perturbation(i, j, k, grid, grav, mp, ρᵈ, C))
51+
+ buoyancy_perturbation(i, j, k, grid, gravity, mp, ρᵈ, C))
5852
+ FW[i, j, k])
5953
end
6054
end

src/time_stepping.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ function time_step!(model::CompressibleModel; Δt, Nt=1)
5252
IV = model.intermediate_vars
5353

5454
pₛ = model.reference_pressure
55+
g = model.gravity
5556

5657
# On third RK3 step, we update Φ⁺ instead of model.intermediate_vars
5758
Φ⁺ = merge(Ũ, C̃, (ρ=ρᵈ,))
@@ -79,12 +80,12 @@ function time_step!(model::CompressibleModel; Δt, Nt=1)
7980

8081
@debug " Computing right hand sides..."
8182
if rk3_iter == 1
82-
compute_rhs_args = (R, grid, prog_temp, buoyancy, pₛ, microphysics, ρᵈ, Ũ, C̃, F)
83+
compute_rhs_args = (R, grid, prog_temp, buoyancy, microphysics, pₛ, g, ρᵈ, Ũ, C̃, F)
8384
fill_halo_regions!(ρᵈ.data, hpbcs, arch, grid)
8485
fill_halo_regions!(datatuple(merge(Ũ, C̃)), hpbcs, arch, grid)
8586
fill_halo_regions!(Ũ.ρw.data, hpbcs_np, arch, grid)
8687
else
87-
compute_rhs_args = (R, grid, prog_temp, buoyancy, pₛ, microphysics, IV.ρ, IV_Ũ, IV_C̃, F)
88+
compute_rhs_args = (R, grid, prog_temp, buoyancy, microphysics, pₛ, g, IV.ρ, IV_Ũ, IV_C̃, F)
8889
fill_halo_regions!(IV.ρ.data, hpbcs, arch, grid)
8990
fill_halo_regions!(datatuple(merge(IV_Ũ, IV_C̃)), hpbcs, arch, grid)
9091
fill_halo_regions!(IV_Ũ.ρw.data, hpbcs_np, arch, grid)

src/time_stepping_kernels.jl

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ end
2323
"""
2424
Fast forcings include advection, pressure gradient, and buoyancy terms.
2525
"""
26-
function compute_right_hand_sides!(R, grid, pt, b, pₛ, mp, ρᵈ, Ũ, C̃, F)
26+
function compute_right_hand_sides!(R, grid, pt, b, mp, pₛ, g, ρᵈ, Ũ, C̃, F)
2727
@inbounds begin
2828
for k in 1:grid.Nz, j in 1:grid.Ny, i in 1:grid.Nx
29-
R.ρu[i, j, k] = RU(i, j, k, grid, pt, b, pₛ, mp, ρᵈ, Ũ, C̃, F.ρu)
30-
R.ρv[i, j, k] = RV(i, j, k, grid, pt, b, pₛ, mp, ρᵈ, Ũ, C̃, F.ρv)
31-
R.ρw[i, j, k] = RW(i, j, k, grid, pt, b, pₛ, mp, ρᵈ, Ũ, C̃, F.ρw)
32-
33-
R.ρ[i, j, k] = (i, j, k, grid, Ũ)
29+
R.ρu[i, j, k] = RU(i, j, k, grid, pt, b, mp, pₛ, ρᵈ, Ũ, C̃, F.ρu)
30+
R.ρv[i, j, k] = RV(i, j, k, grid, pt, b, mp, pₛ, ρᵈ, Ũ, C̃, F.ρv)
31+
R.ρw[i, j, k] = RW(i, j, k, grid, pt, b, mp, pₛ, g, ρᵈ, Ũ, C̃, F.ρw)
32+
R.ρ[i, j, k] = (i, j, k, grid, Ũ)
3433
end
3534

3635
for C_name in propertynames(C̃)

0 commit comments

Comments
 (0)