From 6cfe4738c6dccf6ed01d8623171f440cff471a0e Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Tue, 27 Jul 2021 08:46:26 -0700 Subject: [PATCH] Use more grid abstractions Use more grid abstractions --- src/Turbulence_PrognosticTKE.jl | 59 +++++++++++++++++---------------- src/Variables.jl | 6 ++-- src/types.jl | 24 -------------- 3 files changed, 33 insertions(+), 56 deletions(-) diff --git a/src/Turbulence_PrognosticTKE.jl b/src/Turbulence_PrognosticTKE.jl index 3e8147f6d..584013eee 100755 --- a/src/Turbulence_PrognosticTKE.jl +++ b/src/Turbulence_PrognosticTKE.jl @@ -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, @@ -931,7 +931,7 @@ end function get_env_covar_from_GMV( - self, + self::EDMF_PrognosticTKE, au::UpdraftVariable, phi_u::UpdraftVariable, psi_u::UpdraftVariable, @@ -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 @@ -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] @@ -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 = ( @@ -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 = ( diff --git a/src/Variables.jl b/src/Variables.jl index 60c939c5f..853796273 100644 --- a/src/Variables.jl +++ b/src/Variables.jl @@ -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 @@ -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 @@ -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] diff --git a/src/types.jl b/src/types.jl index 4bcce54ca..40dd8a80d 100644 --- a/src/types.jl +++ b/src/types.jl @@ -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) @@ -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 @@ -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 @@ -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) @@ -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 @@ -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,