Skip to content

Commit

Permalink
Use more grid abstractions
Browse files Browse the repository at this point in the history
Use more grid abstractions
  • Loading branch information
charleskawczynski committed Jul 27, 2021
1 parent 969df66 commit 6cfe473
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 56 deletions.
59 changes: 30 additions & 29 deletions src/Turbulence_PrognosticTKE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ end
# Note: this assumes all variables are defined on half levels not full levels (i.e. phi, psi are not w)
# if covar_e.name is not "tke".
function get_GMV_CoVar(
self,
self::EDMF_PrognosticTKE,
au::UpdraftVariable,
phi_u::UpdraftVariable,
psi_u::UpdraftVariable,
Expand Down Expand Up @@ -931,7 +931,7 @@ end


function get_env_covar_from_GMV(
self,
self::EDMF_PrognosticTKE,
au::UpdraftVariable,
phi_u::UpdraftVariable,
psi_u::UpdraftVariable,
Expand All @@ -943,7 +943,8 @@ function get_env_covar_from_GMV(
gmv_covar,
)

ae = pyones(get_grid(self).nzg) .- au.bulkvalues
grid = get_grid(self)
ae = pyones(grid.nzg) .- au.bulkvalues
tke_factor = 1.0
is_tke = covar_e.name == "tke"
if is_tke
Expand Down Expand Up @@ -1376,28 +1377,32 @@ function solve_updraft_scalars(self::EDMF_PrognosticTKE, GMV::GridMeanVariables)

@inbounds for i in xrange(self.n_updrafts)

# at the surface
if self.UpdVar.Area.new[i, gw] >= self.minimum_area
self.UpdVar.H.new[i, gw] = self.h_surface_bc[i]
self.UpdVar.QT.new[i, gw] = self.qt_surface_bc[i]
else
self.UpdVar.H.new[i, gw] = GMV.H.values[gw]
self.UpdVar.QT.new[i, gw] = GMV.QT.values[gw]
end
# starting from the bottom do entrainment at each level
@inbounds for k in real_center_indicies(grid)
if k == gw
# at the surface
if self.UpdVar.Area.new[i, k] >= self.minimum_area
self.UpdVar.H.new[i, k] = self.h_surface_bc[i]
self.UpdVar.QT.new[i, k] = self.qt_surface_bc[i]
else
self.UpdVar.H.new[i, k] = GMV.H.values[k]
self.UpdVar.QT.new[i, k] = GMV.QT.values[k]
end

# saturation adjustment
sa = eos(
self.UpdThermo.t_to_prog_fp,
self.UpdThermo.prog_to_t_fp,
ref_state.p0_half[k],
self.UpdVar.QT.new[i, k],
self.UpdVar.H.new[i, k],
)
self.UpdVar.QL.new[i, k] = sa.ql
self.UpdVar.T.new[i, k] = sa.T
continue
end

# saturation adjustment
sa = eos(
self.UpdThermo.t_to_prog_fp,
self.UpdThermo.prog_to_t_fp,
ref_state.p0_half[gw],
self.UpdVar.QT.new[i, gw],
self.UpdVar.H.new[i, gw],
)
self.UpdVar.QL.new[i, gw] = sa.ql
self.UpdVar.T.new[i, gw] = sa.T

# starting from the bottom do entrainment at each level
@inbounds for k in xrange(gw + 1, grid.nzg - gw)
H_entr = self.EnvVar.H.values[k]
QT_entr = self.EnvVar.QT.values[k]

Expand Down Expand Up @@ -2307,9 +2312,7 @@ function compute_tke_advection(self::EDMF_PrognosticTKE)
ae = pyones(grid.nzg) .- self.UpdVar.Area.bulkvalues # area of environment
drho_ae_we_e_plus = 0.0

# TODO: why minus 1?
# @inbounds for k in real_center_indicies(grid) # TODO: try changing to this
@inbounds for k in xrange(gw, get_grid(self).nzg - gw - 1)
@inbounds for k in real_face_indicies(grid)
drho_ae_we_e_minus = drho_ae_we_e_plus
drho_ae_we_e_plus =
(
Expand Down Expand Up @@ -2338,9 +2341,7 @@ function compute_tke_transport(self::EDMF_PrognosticTKE)
KM = diffusivity_m(self).values
rho0_half = reference_state(self).rho0_half

# TODO: why minus 1?
# @inbounds for k in real_center_indicies(grid) # TODO: try changing to this
@inbounds for k in xrange(gw, grid.nzg - gw - 1)
@inbounds for k in real_face_indicies(grid)
drho_ae_K_m_de_low = drho_ae_K_m_de_plus
drho_ae_K_m_de_plus =
(
Expand Down
6 changes: 3 additions & 3 deletions src/Variables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function zero_tendencies(self::GridMeanVariables)
end

function update(self::GridMeanVariables, TS::TimeStepping)
@inbounds for k in xrange(self.Gr.gw, self.Gr.nzg - self.Gr.gw)
@inbounds for k in center_indicies(self.Gr)
self.U.values[k] += self.U.tendencies[k] * TS.dt
self.V.values[k] += self.V.tendencies[k] * TS.dt
self.H.values[k] += self.H.tendencies[k] * TS.dt
Expand Down Expand Up @@ -173,7 +173,7 @@ function mean_cloud_diagnostics(self)
self.cloud_base = self.Gr.z_half[self.Gr.nzg - self.Gr.gw - 1]
self.cloud_top = 0.0

@inbounds for k in xrange(self.Gr.gw, self.Gr.nzg - self.Gr.gw)
@inbounds for k in real_center_indicies(self.Gr)
self.lwp += self.Ref.rho0_half[k] * self.QL.values[k] * self.Gr.dz

if self.QL.values[k] > 1e-8
Expand All @@ -186,7 +186,7 @@ end

function satadjust(self::GridMeanVariables)
sa = eos_struct()
@inbounds for k in xrange(self.Gr.nzg)
@inbounds for k in center_indicies(self.Gr)
h = self.H.values[k]
qt = self.QT.values[k]
p0 = self.Ref.p0_half[k]
Expand Down
24 changes: 0 additions & 24 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ struct RainVariable{T}
function RainVariable(nz, name, units)
loc = "half"
kind = "scalar"
name = name
units = units

values = pyzeros(nz)
new = pyzeros(nz)
Expand Down Expand Up @@ -200,14 +198,9 @@ struct VariablePrognostic{T}
if loc != "half" && loc != "full"
print("Invalid location setting for variable! Must be half or full")
end
loc = loc
if kind != "scalar" && kind != "velocity"
print("Invalid kind setting for variable! Must be scalar or velocity")
end
bc = bc
kind = kind
name = name
units = units
return new{typeof(values)}(values, new, mf_update, tendencies, loc, bc, kind, name, units)
end
end
Expand All @@ -226,14 +219,9 @@ struct VariableDiagnostic{T}
if loc != "half" && loc != "full"
print("Invalid location setting for variable! Must be half or full")
end
loc = loc
if kind != "scalar" && kind != "velocity"
print("Invalid kind setting for variable! Must be scalar or velocity")
end
bc = bc
kind = kind
name = name
units = units
return new{typeof(values)}(values, loc, bc, kind, name, units)
end
end
Expand All @@ -259,13 +247,9 @@ struct UpdraftVariable{A1, A2}
if loc != "half" && loc != "full"
print("Invalid location setting for variable! Must be half or full")
end
loc = loc
if kind != "scalar" && kind != "velocity"
print("Invalid kind setting for variable! Must be scalar or velocity")
end
kind = kind
name = name
units = units
A1 = typeof(bulkvalues)
A2 = typeof(values)
return new{A1, A2}(values, old, new, tendencies, flux, bulkvalues, loc, kind, name, units)
Expand Down Expand Up @@ -528,13 +512,9 @@ struct EnvironmentVariable{T}
if loc != "half" && loc != "full"
println("Invalid location setting for variable! Must be half or full")
end
loc = loc
if kind != "scalar" && kind != "velocity"
println("Invalid kind setting for variable! Must be scalar or velocity")
end
kind = kind
name = name
units = units
return new{typeof(values)}(values, flux, loc, kind, name, units)
end
end
Expand Down Expand Up @@ -566,13 +546,9 @@ struct EnvironmentVariable_2m{A1}
if loc != "half"
println("Invalid location setting for variable! Must be half")
end
loc = loc
if kind != "scalar" && kind != "velocity"
println("Invalid kind setting for variable! Must be scalar or velocity")
end
kind = kind
name = name
units = units
return new{typeof(values)}(
values,
dissipation,
Expand Down

0 comments on commit 6cfe473

Please sign in to comment.