Skip to content

Commit

Permalink
Merge #495 #496
Browse files Browse the repository at this point in the history
495: Make compute_ref_state not depend on Stats r=charleskawczynski a=charleskawczynski



496: Make cloud fraction a ClimaCore field r=charleskawczynski a=charleskawczynski



Co-authored-by: Charles Kawczynski <[email protected]>
  • Loading branch information
bors[bot] and charleskawczynski authored Nov 2, 2021
3 parents cf9d58d + ffe8f8a + 254fefb commit ae0ab27
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/src/PlotReferenceStates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function export_ref_profile(case_name::String)
aux = CC.Fields.FieldVector(cent = aux_cent_fields, face = aux_face_fields)
state = (; aux)

TC.compute_ref_state!(state, grid, param_set, Stats; ref_params...)
TC.compute_ref_state!(state, grid, param_set; ref_params...)

io_nt = TC.io_dictionary_ref_state(state)
TC.initialize_io(io_nt, Stats)
Expand Down
3 changes: 2 additions & 1 deletion integration_tests/utils/main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ cent_aux_vars_edmf(FT, n_up) = (;
q_liq = FT(0),
q_ice = FT(0),
T = FT(0),
cloud_fraction = FT(0),
),
up = ntuple(i -> cent_aux_vars_up(FT), n_up),
en = (;
Expand Down Expand Up @@ -210,7 +211,7 @@ function Simulation1d(namelist)

state = State(prog, aux, tendencies, diagnostics)

TC.compute_ref_state!(state, grid, param_set, Stats; ref_params...)
TC.compute_ref_state!(state, grid, param_set; ref_params...)

io_nt = (;
ref_state = TC.io_dictionary_ref_state(state),
Expand Down
14 changes: 2 additions & 12 deletions src/ReferenceState.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
compute_ref_state!(
state,
grid::Grid,
param_set::PS,
Stats::NetCDFIO_Stats;
param_set::PS;
Pg::FT,
Tg::FT,
qtg::FT,
Expand All @@ -18,17 +17,8 @@ TODO: add better docs once the API converges
The reference profiles, given
- `grid` the grid
- `param_set` the parameter set
- `Stats` the NC file handler struct
"""
function compute_ref_state!(
state,
grid::Grid,
param_set::PS,
Stats::NetCDFIO_Stats;
Pg::FT,
Tg::FT,
qtg::FT,
) where {PS, FT}
function compute_ref_state!(state, grid::Grid, param_set::PS; Pg::FT, Tg::FT, qtg::FT) where {PS, FT}

p0_c = center_ref_state(state).p0
ρ0_c = center_ref_state(state).ρ0
Expand Down
2 changes: 1 addition & 1 deletion src/Turbulence_PrognosticTKE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function update_cloud_frac(edmf::EDMF_PrognosticTKE, grid, state, gm::GridMeanVa
a_up_bulk = aux_tc.bulk.area
@inbounds for k in real_center_indices(grid) # update grid-mean cloud fraction and cloud cover
aux_gm.cloud_fraction[k] =
aux_en.area[k] * aux_en.cloud_fraction[k] + a_up_bulk[k] * edmf.UpdVar.cloud_fraction[k]
aux_en.area[k] * aux_en.cloud_fraction[k] + a_up_bulk[k] * aux_tc.bulk.cloud_fraction[k]
end
gm.cloud_cover = min(edmf.EnvVar.cloud_cover + sum(edmf.UpdVar.cloud_cover), 1)
end
Expand Down
2 changes: 2 additions & 0 deletions src/diagnostics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ function io_dictionary_aux(state)

"qr_mean" => (; dims = ("zc", "t"), group = "profiles", field = center_prog_precipitation(state).qr),

"updraft_cloud_fraction" => (; dims = ("zc", "t"), group = "profiles", field = center_aux_turbconv(state).bulk.cloud_fraction),

)
return io_dict
end
Expand Down
2 changes: 0 additions & 2 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ function io(precip::PrecipVariables, grid, state, Stats::NetCDFIO_Stats)
end

function initialize_io(up::UpdraftVariables, Stats::NetCDFIO_Stats)
add_profile(Stats, "updraft_cloud_fraction")

add_ts(Stats, "updraft_cloud_cover")
add_ts(Stats, "updraft_cloud_base")
Expand All @@ -74,7 +73,6 @@ function initialize_io(up::UpdraftVariables, Stats::NetCDFIO_Stats)
end

function io(up::UpdraftVariables, grid, state, Stats::NetCDFIO_Stats)
write_profile(Stats, "updraft_cloud_fraction", up.cloud_fraction)
# Note definition of cloud cover : each updraft is associated with a cloud cover equal to the maximum
# area fraction of the updraft where ql > 0. Each updraft is assumed to have maximum overlap with respect to
# itup (i.e. no consideration of tilting due to shear) while the updraft classes are assumed to have no overlap
Expand Down
7 changes: 2 additions & 5 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ end

mutable struct UpdraftVariables{A1}
n_updrafts::Int
cloud_fraction::A1
cloud_base::A1
cloud_top::A1
cloud_cover::A1
Expand All @@ -232,8 +231,6 @@ mutable struct UpdraftVariables{A1}
n_updrafts = nu

# cloud and precipitation diagnostics for output
cloud_fraction = center_field(grid)

cloud_base = zeros(nu)
cloud_top = zeros(nu)
cloud_cover = zeros(nu)
Expand All @@ -242,8 +239,8 @@ mutable struct UpdraftVariables{A1}
lwp = 0.0
iwp = 0.0

A1 = typeof(cloud_fraction)
return new{A1}(n_updrafts, cloud_fraction, cloud_base, cloud_top, cloud_cover, updraft_top, lwp, iwp)
A1 = typeof(cloud_base)
return new{A1}(n_updrafts, cloud_base, cloud_top, cloud_cover, updraft_top, lwp, iwp)
end
end

Expand Down
7 changes: 4 additions & 3 deletions src/update_aux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,11 @@ function update_aux!(edmf, gm, grid, state, Case, param_set, TS)
aux_tc.bulk.RH[k] = aux_gm.RH[k] # TODO - here we are using previous timestep values
aux_tc.bulk.T[k] = aux_gm.T[k] # TODO - here we are using previous timestep values
end
if TD.has_condensate(aux_tc.bulk.q_liq[k] + aux_tc.bulk.q_ice[k]) && a_bulk_c > 1e-3
up.cloud_fraction[k] = 1.0
has_condensate = TD.has_condensate(aux_tc.bulk.q_liq[k] + aux_tc.bulk.q_ice[k])
aux_tc.bulk.cloud_fraction[k] = if has_condensate && a_bulk_c > 1e-3
1
else
up.cloud_fraction[k] = 0.0
0
end

val1 = 1 / (1 - a_bulk_c)
Expand Down

0 comments on commit ae0ab27

Please sign in to comment.