Skip to content

Commit 73b830c

Browse files
committed
Add aerosol size array
1 parent 03bf845 commit 73b830c

5 files changed

Lines changed: 192 additions & 399 deletions

File tree

src/atmosphere.jl

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,9 @@ module atmosphere
287287
cloud_val_f::Float64 # /
288288

289289
# Parametrised aerosols (SOCRATES's classic aerosol functionality)
290-
aerosol_mmr::Dict{String, Array{Float64,1}} # Aerosol mass mixing ratio profiles [kg/kg]
291-
aerosol_size::Dict{String, Array{Float64,1}} # Aerosol particle size profiles [m]
290+
aerosol_arr_l::Dict{String, Array{Float64,1}} # Aerosol mass mixing ratio profiles [kg/kg]
291+
aerosol_arr_r::Dict{String, Array{Float64,1}} # Aerosol particle size profiles [m]
292+
aerosol_val_r::Float64 # Default particle size for aerosol species, if not specified in array
292293
aerosol_names::Array{String,1} # Map SOCRATES index (int) to name (string)
293294
aerosol_relhumid::Float64 # Mean relative humidity used by moist aerosol schemes [0,1]
294295
aerosol_phase_num::Int # Number of phase-function moments retained when averaging
@@ -795,22 +796,24 @@ module atmosphere
795796
_check_range("Evaporation efficiency", atmos.evap_efficiency; min=0, max=1) || return false
796797

797798
# Hardcoded cloud properties
798-
atmos.cloud_alpha = 0.01 # 1% of condensed water forms substantial clouds
799-
atmos.cloud_val_r = 1.0e-5 # 10 micron droplets
800-
atmos.cloud_val_l = 0.8 # 80% of the saturated vapor turns into cloud
801-
atmos.cloud_val_f = 0.8 # 100% of the cell "area" is cloud
799+
atmos.cloud_alpha = 0.01 # [INPUT] 1% of condensed water forms substantial clouds
800+
atmos.cloud_val_r = 1.0e-5 # [INPUT] 10 micron droplets
801+
atmos.cloud_val_l = 0.8 # [INPUT] Mass mixing ratio of water in each layer
802+
atmos.cloud_val_f = 0.8 # [INPUT] 100% of the cell "area" is cloud
802803

803804
# Aerosol parameters
804-
atmos.aerosol_phase_num = 1 # number of phase-function moments
805-
atmos.aerosol_relhumid = 0.0 # relative humidity used by moist aerosol schemes
806-
atmos.aerosol_mmr = Dict{String, Array{Float64,1}}() # list of MMR profiles
807-
atmos.aerosol_size = Dict{String, Array{Float64,1}}() # list of MMR profiles
805+
atmos.aerosol_phase_num = 1 # [INPUT] number of phase-function moments
806+
atmos.aerosol_relhumid = 0.0 # [INPUT] relative humidity used by moist aerosol schemes
807+
atmos.aerosol_val_r = 1.0e-5 # [INPUT] default particle size for aerosol species
808+
atmos.aerosol_arr_l = Dict{String, Array{Float64,1}}() # list of MMR profiles
809+
atmos.aerosol_arr_r = Dict{String, Array{Float64,1}}() # list of particle size profiles
808810
atmos.aerosol_names = String[] # list of species names, in same order as spectral file
809811
for (k, v) in aerosol_species
812+
k = lowercase(k)
810813
_check_range("Aerosol mass mixing ratio override for type $k", v; min=0.0) || return false
811-
atmos.aerosol_mmr[lowercase(k)] = zeros(Float64, atmos.nlev_c)
812-
atmos.aerosol_size[lowercase(k)] = zeros(Float64, atmos.nlev_c)
813-
set_aerosol!(atmos, lowercase(k), v)
814+
atmos.aerosol_arr_l[k] = zeros(Float64, atmos.nlev_c)
815+
atmos.aerosol_arr_r[k] = zeros(Float64, atmos.nlev_c)
816+
set_aerosol!(atmos,k , v)
814817

815818
# Store empty strings for now (set in allocate! function)
816819
push!(atmos.aerosol_names, UNSET_STR)
@@ -1917,15 +1920,15 @@ module atmosphere
19171920
@debug "Generating aerosol .avg files with scatter_average_90"
19181921
aerosol_avg_files_rt = spectrum.generate_aerosol_avg_files(
19191922
atmos.spectral_file,
1920-
[s for s in keys(atmos.aerosol_mmr)],
1923+
[s for s in keys(atmos.aerosol_arr_l)],
19211924
atmos.IO_DIR,
19221925
atmos.aerosol_phase_num,
19231926
socstar,
19241927
atmos.SCATTERING_DIR
19251928
)
19261929

19271930
# check that all files were generated successfully
1928-
if length(aerosol_avg_files_rt) != length(atmos.aerosol_mmr)
1931+
if length(aerosol_avg_files_rt) != length(atmos.aerosol_arr_l)
19291932
@error "Failed to generate required aerosol .avg files"
19301933
list_available_aerosols(atmos)
19311934
return false
@@ -2310,14 +2313,18 @@ module atmosphere
23102313
# Enable aerosol
23112314
atmos.aer.mr_source[i] = SOCRATES.rad_pcf.ip_aersrc_classic_ron
23122315

2313-
# Add array to aerosol_mmr if not requested by user already
2314-
if !haskey(atmos.aerosol_mmr, name)
2315-
atmos.aerosol_mmr[name] = zeros(Float64, atmos.nlev_c)
2316+
# Add array if not requested by user already
2317+
if !haskey(atmos.aerosol_arr_l, name)
2318+
atmos.aerosol_arr_l[name] = zeros(Float64, atmos.nlev_c)
2319+
if haskey(atmos.aerosol_arr_r, name)
2320+
@warn "Aerosol '$name' mismatched in arrays!"
2321+
else
2322+
atmos.aerosol_arr_r[name] = zeros(Float64, atmos.nlev_c)
23162323
end
23172324
end
23182325

23192326
# warn if user has requested unsupported aerosol
2320-
for name in keys(atmos.aerosol_mmr)
2327+
for name in keys(atmos.aerosol_arr_l)
23212328
if !(name in atmos.aerosol_names)
23222329
@warn "Requested aerosol '$name' not found in spectral file"
23232330
list_available_aerosols(atmos)
@@ -2788,7 +2795,7 @@ module atmosphere
27882795
@info @sprintf(" %10s - %s", name, strip(title))
27892796
push!(aerosol_names, name)
27902797
end
2791-
if isempty(atmos.aerosol_mmr)
2798+
if isempty(atmos.aerosol_arr_l)
27922799
@info " [none]"
27932800
end
27942801

@@ -2851,7 +2858,7 @@ module atmosphere
28512858
end
28522859

28532860
"""
2854-
**Set aerosol profile for a given species.**
2861+
**Set aerosol profiles for a given species.**
28552862
28562863
Arguments:
28572864
- `atmos::atmosphere.Atmos_t` the atmosphere struct instance to be used
@@ -2873,16 +2880,19 @@ module atmosphere
28732880
# Set mixing ratio profile for aerosol
28742881
if isa(mmr, Float64)
28752882
# constant profile
2876-
atmos.aerosol_mmr[species][idx_mask] .= mmr
2883+
atmos.aerosol_arr_l[species][idx_mask] .= mmr
28772884
else
28782885
# 1D profile
28792886
if length(mmr) != length(atmos.p)
28802887
@error "Length of input mmr array does not match number of layers"
28812888
return false
28822889
end
2883-
atmos.aerosol_mmr[species][idx_mask] .= mmr[idx_mask]
2890+
atmos.aerosol_arr_l[species][idx_mask] .= mmr[idx_mask]
28842891
end
28852892

2893+
# Set constant size
2894+
fill!(atmos.aerosol_arr_r[species], atmos.aerosol_val_r)
2895+
28862896
return true
28872897
end
28882898

src/energy.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ module energy
174174
fill!(atmos.aer.mix_ratio, 0.0)
175175
if atmos.control.l_aerosol
176176
for i = 1:atmos.spectrum.Aerosol.n_aerosol_mr
177-
atmos.aer.mix_ratio[1, :, i] .= atmos.aerosol_mmr[atmos.aerosol_names[i]][:]
177+
atmos.aer.mix_ratio[1, :, i] .= atmos.aerosol_arr_l[atmos.aerosol_names[i]][:]
178178
end
179179
end
180180

src/plotting.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ module plotting
212212

213213
lw = 2.0
214214

215+
y = atmos.p * 1e-5 # pressure -> bar
216+
215217
# Create plot
216218
plt = plot( xlims=xlims, xticks=xticks,
217219
ylims=_get_ylims(atmos), yticks=_get_yticks(atmos),
@@ -220,18 +222,18 @@ module plotting
220222
# Temperature profile for reference
221223
tmp_nrm = (atmos.tmp .- minimum(atmos.tmp))./(maximum(atmos.tmp)-minimum(atmos.tmp))
222224
@. tmp_nrm = xlims[1] + (xlims[2]-xlims[1])*tmp_nrm
223-
plot!(plt, tmp_nrm, atmos.p*1e-5, lc="black",
225+
plot!(plt, tmp_nrm, y, lc="black",
224226
linealpha=0.3, lw=lw, label=L"\hat{T}(p)")
225227

226228
# Plot cloud profiles
227229
ls = atmos.control.l_cloud ? :solid : :dot
228-
plot!(plt, log10.(clamp.(atmos.cloud_arr_l,10^xlims[1],10^xlims[2])), atmos.p*1e-5,
230+
plot!(plt, log10.(clamp.(atmos.cloud_arr_l,10^xlims[1],10^xlims[2])), y,
229231
lw=lw, ls=ls, label="Cloud", linealpha=0.7)
230232

231233
# Plot aerosol profiles
232234
ls = atmos.control.l_aerosol ? :solid : :dot
233-
for k_aer in keys(atmos.aerosol_mmr)
234-
plot!(plt, log10.(clamp.(atmos.aerosol_mmr[k_aer], 10^xlims[1], 10^xlims[2])), atmos.p*1e-5,
235+
for k_aer in keys(atmos.aerosol_arr_l)
236+
plot!(plt, log10.(clamp.(atmos.aerosol_arr_l[k_aer], 10^xlims[1], 10^xlims[2])), y,
235237
lw=lw, ls=ls, label=k_aer, linealpha=0.7)
236238
end
237239

src/save.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ module save
127127
nlev_c = Int(atmos.nlev_c)
128128
nlev_l = nlev_c + 1
129129
ngases = atmos.gas_num
130-
naeros = max(1,length(atmos.aerosol_mmr))
130+
naeros = max(1,length(atmos.aerosol_arr_l))
131131
nchars = 16
132132

133133
defDim(ds, "nlev_c", nlev_c) # Cell centres
@@ -339,12 +339,12 @@ module save
339339
var_cldr[:] = atmos.cloud_arr_r
340340

341341
# Aerosols
342-
if length(atmos.aerosol_mmr) == 0
342+
if length(atmos.aerosol_arr_l) == 0
343343
var_aerosols[:, 1] = fill(' ', nchars)
344344
var_aer_l[1, :] = collect(0.0 for i in 1:nlev_c)
345345
var_aer_r[1, :] = collect(0.0 for i in 1:nlev_c)
346346
else
347-
for (i_aer, k_aer) in enumerate(sort(collect(keys(atmos.aerosol_mmr))))
347+
for (i_aer, k_aer) in enumerate(sort(collect(keys(atmos.aerosol_arr_l))))
348348
# Fill aerosol names
349349
for i_char in 1:nchars
350350
var_aerosols[i_char, i_aer] = ' '
@@ -355,8 +355,8 @@ module save
355355

356356
# Fill MMR and sizes
357357
for i_lvl in 1:nlev_c
358-
var_aer_l[i_aer, i_lvl] = atmos.aerosol_mmr[k_aer][i_lvl]
359-
var_aer_r[i_aer, i_lvl] = atmos.aerosol_size[k_aer][i_lvl]
358+
var_aer_l[i_aer, i_lvl] = atmos.aerosol_arr_l[k_aer][i_lvl]
359+
var_aer_r[i_aer, i_lvl] = atmos.aerosol_arr_r[k_aer][i_lvl]
360360
end
361361
end
362362
end

0 commit comments

Comments
 (0)