Skip to content

Commit

Permalink
Updated generate_pgrid to avoid weird issues at surface of model. Upd…
Browse files Browse the repository at this point in the history
…ated tests. Renamed workflow.
  • Loading branch information
nichollsh committed Jul 6, 2024
1 parent d15a06b commit 8e6364d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/install_and_test.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This job installs AGNI and SOCRATES, and tests AGNI
# This occurs when a PR to main is created

name: Install SOCRATES+AGNI
name: AGNI_main_tests

on:
pull_request:
Expand All @@ -12,7 +12,7 @@ on:
jobs:
install:
runs-on: ubuntu-latest
name: Install and test
name: AGNI_main_tests
steps:
- uses: actions/checkout@v4

Expand Down
44 changes: 26 additions & 18 deletions src/atmosphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -798,33 +798,41 @@ module atmosphere
"""
**Generate pressure grid.**
Equally log-spaced between p_boa and p_boa. The bottommost layer has a
bespoke relative thicknesses of 1-boundary_scale, in order to avoid
numerical instabilities.
Almost-equally log-spaced between p_boa and p_boa. The near-surface layers
are smaller than they would be on an equally log-spaced grid, to avoid
numerical weirdness at the bottom boundary.
Arguments:
- `atmos::Atmos_t` the atmosphere struct instance to be used.
- `boundary_scale::Float64=1.0e-4` scale factor for the thickness of the bottom-most cell.
- `atmos::Atmos_t` the atmosphere struct instance to be used.
"""
function generate_pgrid!(atmos::atmosphere.Atmos_t; boundary_scale::Float64=1.0e-6)
function generate_pgrid!(atmos::atmosphere.Atmos_t)

# Allocate arrays
atmos.p = zeros(Float64, atmos.nlev_c)
atmos.pl = zeros(Float64, atmos.nlev_l)

# First, assign log10'd values...

boundary_scale = max(min(boundary_scale, 1.0-1.0e-8), 1.0e-8)
# Top and bottom boundaries
atmos.pl[end] = log10(atmos.p_boa)
atmos.pl[1] = log10(atmos.p_toa)

# Allocate cell-edge pressure array
atmos.pl = zeros(Float64, atmos.nlev_l)
# Almost-surface layer is VERY small
atmos.pl[end-1] = atmos.pl[end]*(1.0-1e-4)

# Surface pressure
atmos.pl[end] = atmos.p_boa
# Logarithmically-spaced levels above
atmos.pl[1:end-1] .= collect(Float64, range( start=atmos.pl[1], stop=atmos.pl[end-1], length=atmos.nlev_l-1))

# Bottom layer
atmos.pl[end-1] = atmos.pl[end]*(1.0-boundary_scale)
# Shrink near-surface layers by stretching all layers above
p_mid::Float64 = atmos.pl[end-1]*0.6 + atmos.pl[end-2]*0.4
atmos.pl[1:end-2] .= collect(Float64, range( start=atmos.pl[1], stop=p_mid, length=atmos.nlev_l-2))

# Logarithmically-spaced levels
atmos.pl[1:end-1] .= 10 .^ range( log10(atmos.p_toa), stop=log10(atmos.pl[end-1]), length=atmos.nlev_l-1)
# Set cell-centres at midpoint of cell-edges
atmos.p[1:end] .= 0.5 .* (atmos.pl[1:end-1] .+ atmos.pl[2:end])

# Set pressure cell-centre array using geometric mean
atmos.p = zeros(Float64, atmos.nlev_c)
atmos.p[1:end] .= sqrt.(atmos.pl[1:end-1].*atmos.pl[2:end])
# Finally, convert arrays to 'real' pressure units
atmos.p[:] .= 10.0 .^ atmos.p[:]
atmos.pl[:] .= 10.0 .^ atmos.pl[:]

return nothing
end
Expand Down
2 changes: 1 addition & 1 deletion src/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ module energy
function condense_diffuse!(atmos::atmosphere.Atmos_t)

# Parameter
timescale::Float64 = 8e5 # seconds
timescale::Float64 = 1e6 # seconds

# Reset flux and mask
fill!(atmos.flux_l, 0.0)
Expand Down
6 changes: 3 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ end

energy.radtrans!(atmos, false) # SW only

val_e = [20.0, 40.0] # known from previous tests
val_e = [25.0, 35.0] # known from previous tests
val_o = atmos.flux_u_sw[end] # bottom level
@info "Expected range = $(val_e) W m-2"
@info "Modelled value = $(val_o) W m-2"
Expand Down Expand Up @@ -340,8 +340,8 @@ energy.radtrans!(atmos, true)
energy.radtrans!(atmos, false)
atmos.flux_tot += atmos.flux_n
energy.calc_hrates!(atmos)
val_e = [20.0, 70.0] # tests have found ~54 K/day for this setup
val_o = atmos.heating_rate[atmos.nlev_c-2]
val_e = [5.6, 6.6] # from previous tests
val_o = atmos.heating_rate[atmos.nlev_c-10]
@info "Expected range = $(val_e) K/day"
@info "Modelled value = $(val_o) K/day"
if ( val_o > val_e[1]) && (val_o < val_e[2])
Expand Down

0 comments on commit 8e6364d

Please sign in to comment.