Skip to content

Commit 3a9ba93

Browse files
committed
Update y-axis plot ticks
1 parent 9ee3b6f commit 3a9ba93

4 files changed

Lines changed: 70 additions & 34 deletions

File tree

src/atmosphere.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,8 @@ module atmosphere
12831283
Performs hydrostatic integration from the ground upwards.
12841284
Requires density, temperature, pressure to have already been set.
12851285
1286+
Does not account for ocean thickness.
1287+
12861288
Arguments:
12871289
- `atmos::Atmos_t` the atmosphere struct instance to be used.
12881290

src/chemistry.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,13 @@ module chemistry
152152

153153
# Super-saturated at the surface...
154154
elseif dp < 0
155-
@debug "Surface $c is supersaturated, dp is negative"
155+
@debug @sprintf(" %s super-saturated, partial pressure += %+.3f bar", c, dp/1e5)
156156

157157
# Sub-saturated at the surface...
158158
# work out change in partial pressure based on initial reservoir amount
159159
else
160-
@debug "Surface $c is subsaturated, dp is positive"
161160
dp = min(dp, atmos.ocean_ini[c] * atmos.grav_surf / (atmos.gas_dat[c].mmw/atmos.layer_μ[end]))
161+
@debug @sprintf(" %s sub-saturated, partial pressure += %+.3f bar", c, dp/1e5)
162162
end
163163

164164
# Record that at least one component has as changed
@@ -167,7 +167,6 @@ module chemistry
167167
# Reduce or increase total pressure and partial pressure
168168
atmos.p_boa += dp
169169
p_gas[c] += dp
170-
@debug @sprintf(" adjusted partial prssure by %+.3f bar", dp/1e5)
171170

172171
# Change in surface reservoir, with opposite sign to change in pressure
173172
atmos.ocean_tot[c] -= (dp / atmos.grav_surf) * (atmos.gas_dat[c].mmw/atmos.layer_μ[end])
@@ -185,7 +184,7 @@ module chemistry
185184
end
186185

187186
# Generate new pressure grid with updated p_boa
188-
@debug @sprintf("New surface pressure: %+.3f bar",atmos.p_boa/1e5)
187+
@debug @sprintf(" new p_boa = %.3f bar",atmos.p_boa/1e5)
189188
atmosphere.generate_pgrid!(atmos)
190189

191190
# Calculate new values for layer properties

src/plotting.jl

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,27 @@ module plotting
4040
return @sprintf("%d",v)
4141
end
4242

43+
# Get y-axis limits
44+
function _get_ylims(atmos::atmosphere.Atmos_t)::Tuple
45+
return (1e-5*atmos.pl[1]/1.5, 1e-5*max(atmos.p_oboa, atmos.p_boa)*1.5 )
46+
end
47+
48+
# Gey y-axis ticks for log10 axis scale
49+
function _get_yticks(atmos::atmosphere.Atmos_t)::Array
50+
ylims = _get_ylims(atmos)
51+
return 10.0 .^ round.(Int,range( log10(ylims[1]), stop=log10(ylims[2]), step=1))
52+
end
53+
54+
# Reusable plotting snippets
55+
macro _plt_pboa()
56+
return esc(:(hline!(plt, [atmos.p_boa/1e5 ], color="black", label=L"p_s", ls=:solid)))
57+
end
58+
macro _plt_poboa()
59+
return esc(:(hline!(plt, [atmos.p_oboa/1e5], color="black", label=L"p_s^o", ls=:dot)))
60+
end
61+
62+
63+
4364
"""
4465
Plot the temperature-pressure profile.
4566
"""
@@ -48,13 +69,14 @@ module plotting
4869
incl_magma::Bool=false,
4970
title::String="")
5071

51-
ylims = (1e-5*atmos.pl[1]/1.5, 1e-5*atmos.pl[end]*1.5)
52-
yticks = 10.0 .^ round.(Int,range(log10(ylims[1]), stop=log10(ylims[2]), step=1))
53-
5472
# Create plot
55-
plt = plot(ylims=ylims, yticks=yticks, legend=:outertopright,
73+
plt = plot(ylims=_get_ylims(atmos), yticks=_get_yticks(atmos), legend=:outertopright,
5674
size=(size_x,size_y); plt_default...)
5775

76+
# Plot current surface pressure and original
77+
@_plt_pboa
78+
@_plt_poboa
79+
5880
# Plot phase boundary
5981
if atmos.condense_any
6082
sat_t::Array{Float64,1} = zeros(Float64, atmos.nlev_c)
@@ -80,15 +102,15 @@ module plotting
80102

81103
# Plot tmp_magma
82104
if incl_magma
83-
scatter!(plt, [atmos.tmp_magma], [atmos.pl[end]*1e-5],
105+
scatter!(plt, [atmos.tmp_magma], [atmos.p_boa/1e5],
84106
color="cornflowerblue", label=L"T_m")
85107
end
86108

87109
# Plot tmp_surf
88-
scatter!(plt, [atmos.tmp_surf], [atmos.pl[end]*1e-5], color="brown3", label=L"T_s")
110+
scatter!(plt, [atmos.tmp_surf], [atmos.p_boa/1e5], color="brown3", label=L"T_s")
89111

90112
# Plot profile
91-
plot!(plt, atmos.tmpl, atmos.pl*1e-5, lc="black", lw=2, label=L"T(p)")
113+
plot!(plt, atmos.tmpl, atmos.pl/1e5, lc="black", lw=2, label=L"T(p)")
92114

93115
# Decorate
94116
xlabel!(plt, "Temperature [K]")
@@ -112,13 +134,15 @@ module plotting
112134
size_x::Int=500, size_y::Int=400,
113135
title::String="")
114136

115-
ylims = (1e-5*atmos.pl[1]/1.5, 1e-5*atmos.pl[end]*1.5)
116-
yticks = 10.0 .^ round.(Int,range( log10(ylims[1]), stop=log10(ylims[2]), step=1))
117-
118137
# Create plot
119-
plt = plot(ylims=ylims, yticks=yticks, legend=:outertopright,
138+
plt = plot(ylims=_get_ylims(atmos), yticks=_get_yticks(atmos),
139+
legend=:outertopright,
120140
size=(size_x,size_y); plt_default...)
121141

142+
# Plot current surface pressure and original
143+
@_plt_pboa
144+
@_plt_poboa
145+
122146
# Plot surface
123147
scatter!(plt, [atmos.rp*1e-3], [atmos.pl[end]*1e-5], color="brown3", label=L"P_s")
124148

@@ -151,12 +175,9 @@ module plotting
151175
xlims = (-1, 101)
152176
xticks = collect(range(start=0.0, stop=100.0, step=10.0))
153177

154-
ylims = (1e-5*atmos.pl[1]/1.5, 1e-5*atmos.pl[end]*1.5)
155-
yticks = 10.0 .^ round.(Int,range( log10(ylims[1]), stop=log10(ylims[2]), step=1))
156-
157178
# Create plot
158179
plt = plot( xlims=xlims, xticks=xticks,
159-
ylims=ylims, yticks=yticks,
180+
ylims=_get_ylims(atmos), yticks=_get_yticks(atmos),
160181
legend=:outertopright, size=(size_x,size_y); plt_default...)
161182

162183
# Temperature profile for reference
@@ -195,13 +216,17 @@ module plotting
195216
la = 0.7
196217

197218
arr_P = atmos.p .* 1.0e-5 # Convert Pa to bar
198-
ylims = (arr_P[1]/1.5, arr_P[end]*1.5)
199-
yticks = 10.0 .^ round.(Int,range( log10(ylims[1]), stop=log10(ylims[2]), step=1))
200219

201220
# Create plot
202-
plt = plot(ylims=ylims, yticks=yticks, legend=:outertopright,
221+
plt = plot(ylims=_get_ylims(atmos), yticks=_get_yticks(atmos),
222+
legend=:outertopright,
203223
size=(size_x,size_y); plt_default...)
204224

225+
226+
# Plot current surface pressure and original
227+
@_plt_pboa
228+
@_plt_poboa
229+
205230
# Plot log10 VMRs for each gas
206231
gas_xsurf::Array = zeros(Float64, atmos.gas_num)
207232
gas::String = ""
@@ -287,19 +312,23 @@ module plotting
287312
)
288313

289314
arr_P = atmos.pl .* 1.0e-5 # Convert Pa to bar
290-
ylims = (arr_P[1]/1.5, arr_P[end]*1.5)
291-
yticks = 10.0 .^ round.(Int,range( log10(ylims[1]), stop=log10(ylims[2]), step=1))
292315

293316
max_fl = log10(max(100.0, maximum(abs.(atmos.flux_tot)), maximum(atmos.flux_u), maximum(atmos.flux_d)))
294317
xticks_pos = unique(ceil.(Int, range( start=1, stop=max_fl+1, step=1)))
295318
xticks = unique(vcat(-1.0.*reverse(xticks_pos), 0.0, xticks_pos))
296319
xlims = (-xticks_pos[end], xticks_pos[end])
297320
xticklabels = _intstr.(round.(Int, abs.(xticks)))
298321

299-
plt = plot(legend=:outertopright, ylims=ylims, yticks=yticks,
322+
plt = plot(legend=:outertopright,
323+
ylims=_get_ylims(atmos), yticks=_get_yticks(atmos),
300324
xticks=(xticks, xticklabels), xlims=xlims,
301325
size=(size_x,size_y); plt_default...)
302326

327+
# Plot current surface pressure and original
328+
@_plt_pboa
329+
@_plt_poboa
330+
331+
303332
col_r::String = "#c0c0c0"
304333
col_n::String = "#000000"
305334
col_c::String = "#6495ed"

src/solver.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,11 +332,11 @@ module solver
332332
# Do saturation aloft here, only
333333
# chemistry.calc_composition!(atmos, rainout, chem, rainout)
334334
if rainout
335-
# reset back to post-chemistry value
335+
# reset back to post-chemistry mixing ratios
336336
for g in atmos.gas_names
337-
@. atmos.gas_vmr[g] = atmos.gas_cvmr
337+
@. atmos.gas_vmr[g] = atmos.gas_cvmr[g]
338338
end
339-
_sat_aloft!(atmos)
339+
chemistry._sat_aloft!(atmos)
340340
end
341341

342342
# Calculate fluxes
@@ -621,7 +621,7 @@ module solver
621621

622622
easy_sf = min(1.0, easy_sf*easy_incr)
623623
easy_step = true
624-
@debug " updated easy_sf = $easy_sf"
624+
@debug " updated easy_sf = $easy_sf"
625625

626626
# done modulating
627627
if easy_sf > 0.99
@@ -803,7 +803,7 @@ module solver
803803

804804
# Apply best scale from linesearch
805805
ls_alpha = min(max(ls_alpha, ls_min_scale), ls_max_scale)
806-
@debug " linesearch scale ls_alpha = $ls_alpha"
806+
@debug " ls_alpha = $ls_alpha"
807807
x_dif *= ls_alpha
808808
end
809809

@@ -930,6 +930,7 @@ module solver
930930
end
931931

932932
# perform one last evaluation to set `atmos` given the final `x_cur`
933+
chemistry.calc_composition!(atmos, rainout, chem, rainout)
933934
_fev!(x_cur, zeros(Float64, arr_len))
934935

935936
# calc kzz profile
@@ -966,15 +967,20 @@ module solver
966967
# ----------------------------------------------------------
967968
loss = maximum(abs.(atmos.flux_tot)) - minimum(abs.(atmos.flux_tot))
968969
loss_pct = 100.0*loss/maximum(abs.(atmos.flux_tot))
969-
@info @sprintf(" outgoing LW flux = %+.2e W m-2 ", atmos.flux_u_lw[1])
970-
if (sol_type == 2)
970+
if sol_type == 4
971+
@info @sprintf(" outgoing LW flux = %+.2e W m-2 ", atmos.flux_u_lw[1])
972+
end
973+
if sol_type == 2
971974
@info @sprintf(" conduct. skin flux = %+.2e W m-2 ", energy.skin_flux(atmos))
972975
end
973976
@info @sprintf(" total flux at TOA = %+.2e W m-2 ", atmos.flux_tot[1])
974977
@info @sprintf(" total flux at BOA = %+.2e W m-2 ", atmos.flux_tot[end])
975-
@info @sprintf(" total flux lost = %+.2e W m-2 (%+.2e %%) ", loss, loss_pct)
976-
@info @sprintf(" final cost value = %+.2e W m-2 ", c_cur)
978+
@info @sprintf(" global flux loss = %+.2e W m-2 (%+.2e %%) ", loss, loss_pct)
979+
# @info @sprintf(" final cost value = %+.2e W m-2 ", c_cur)
977980
@info @sprintf(" surf temperature = %-9.3f K ", atmos.tmp_surf)
981+
if rainout
982+
@info @sprintf(" surf pressure = %-9.3e bar ", atmos.p_boa/1e5)
983+
end
978984

979985

980986
return atmos.is_converged

0 commit comments

Comments
 (0)