Skip to content

Commit

Permalink
Renamed F_eff to F_int. Requires julia>=1.9 explicitly. Fixes to note…
Browse files Browse the repository at this point in the history
…books.:
  • Loading branch information
nichollsh committed Jun 26, 2024
1 parent 06de7dd commit 5dd34dd
Show file tree
Hide file tree
Showing 20 changed files with 2,246 additions and 762 deletions.
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
julia = ">= 1.9"
2 changes: 1 addition & 1 deletion docs/src/model/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ using a 1D golden-section search method on $\alpha$. This means that the model i
AGNI can calculate emission spectra, provided with T(p) and the volume mixing ratios of the gases. This is performed using the same RT as the RCE calculations, so is limited in resolution by the choice of correlated-k bands. Similarly, the longwave contribution function can also be calculated.

## Julia and Fortran
AGNI is primarily written in Julia, while SOCRATES itself is written in Fortran. Julia was chosen because it allows the SOCRATES binaries to be included in the precompiled code, which significantly improves performance.
AGNI is primarily written in Julia, while SOCRATES itself is written in Fortran. Julia was chosen because it allows the SOCRATES binaries to be included in the precompiled code, which significantly improves performance. In theory, it is possible to call AGNI from a Python program via [PythonCall.jl](https://github.com/JuliaPy/PythonCall.jl).
2 changes: 1 addition & 1 deletion docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Some `execution` parameters:
* `solution_type` tells the model which state to solve for. The allowed values (integers) are...
- 1 : zero flux divergence at fixed `tmp_surf`
- 2 : zero flux divergence, with `tmp_surf` set such that the conductive skin (CBL) conserves energy flux
- 3 : the net upward flux at each layer is equal to `flux_eff = sigma * tmp_eff^4`
- 3 : the net upward flux at each layer is equal to `flux_int = sigma * tmp_int^4`

* `solvers` tells the model which solvers to use. This is a list of strings, so multiple solvers can be applied sequentially. An empty string is always appended to the end of this list. Allowed solvers are...
- [empty string] : no solving takes place, so the model just calculates fluxes using the initial state
Expand Down
2 changes: 1 addition & 1 deletion res/config/chemistry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ title = "Equilibrium chemistry demo" # Name for this configur
p_top = 1e-5 # Total top-of-atmosphere pressure [bar]
vmr = { H2O = 0.6, CO2=0.1, N2=0.1, SO2=0.1, O2=0.05, Fe=0.05} # Volatile volume mixing ratios
condensates = []
tmp_eff = 0.0 # Effective temperature
tmp_int = 0.0 # Effective temperature

[files]
clean_output = true
Expand Down
2 changes: 1 addition & 1 deletion res/config/cloud.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ title = "Test clouds w/ prescribed T(p)"
p_top = 1e-6
vmr = { H2O = 1.0 }
condensates = ["H2O"]
tmp_eff = 0.0
tmp_int = 0.0

[files]
clean_output = true
Expand Down
2 changes: 1 addition & 1 deletion res/config/condense.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ title = "Condensation test" # Name for this configuration fil
p_top = 1e-5
vmr = { H2O=0.8, CO2=0.1, CH4=0.08, H2=0.02}
condensates = ["H2O", "CO2"]
tmp_eff = 0.0
tmp_int = 0.0
turb_coeff = 1.0e-4
wind_speed = 10.0
skin_k = 2.0
Expand Down
2 changes: 1 addition & 1 deletion res/config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ title = "Default" # Name for this configuration file
skin_d = 0.01 # Conductive skin thickness [m]. Used when sol_type=2.
skin_k = 2.0 # Conductive skin conductivity [W m-1 K-1]. Used when sol_type=2.
tmp_magma = 3000.0 # Magma temperature [K]. Used when sol_type=2.
tmp_eff = 0.0 # Planet's effective interior temperature [K]. Used when sol_type=3.
tmp_int = 0.0 # Planet's effective interior temperature [K]. Used when sol_type=3.
turb_coeff = 0.001 # Turbulent exchange coefficient for sensible heat.
wind_speed = 2.0 # Effective wind speed for sensible heat [m s-1].

Expand Down
2 changes: 1 addition & 1 deletion res/config/hotdry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ title = "Hot and dry"
p_top = 1e-5 # Total top-of-atmosphere pressure [bar]
vmr = { H2O = 1.0 } # Volatile volume mixing ratios
condensates = []
tmp_eff = 0.0 # Effective temperature
tmp_int = 0.0 # Effective temperature
turb_coeff = 1.0e-4
wind_speed = 10.0

Expand Down
2 changes: 1 addition & 1 deletion res/config/k2-18b.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ title = "Roughly K2-18b @ IW-4"
p_top = 1e-5
vmr = { H2O=0.0085, N2=0.0009, H2=0.7931, CO=0.0111, CH4=0.1864 }
condensates = ["H2O","CH4","CO"]
tmp_eff = 0.0
tmp_int = 100.0
turb_coeff = 0.001
wind_speed = 2.0

Expand Down
2 changes: 1 addition & 1 deletion res/config/proteus.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ title = "PROTEUS configured"
skin_k = 2.0
skin_d = 0.01
tmp_magma = 1950.1074604027003
# tmp_eff = 1000.0
# tmp_int = 1000.0
turb_coeff = 1.0e-3
wind_speed = 10.0
condensates = []
Expand Down
2 changes: 1 addition & 1 deletion res/config/selsis.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ title = "Comparison with Selsis+23"
p_top = 1e-5
vmr = { H2O = 1.0 }
condensates = ["H2O"]
tmp_eff = 0.0
tmp_int = 0.0
turb_coeff = 1.0e-4
wind_speed = 10.0

Expand Down
2 changes: 1 addition & 1 deletion res/literature_data/profile/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ This can be achieved by setting the following parameters in AGNI:

To solve for these profiles, we need to set the net flux boundary condition such
that the same OLR is achieved. This may be done via:
F_eff = sigma (T_eff)^4 = OTR + F_UP_SW - F_DN_SW
F_int = sigma (T_int)^4 = OTR + F_UP_SW - F_DN_SW

6 changes: 3 additions & 3 deletions src/AGNI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,9 @@ module AGNI
tmp_magma = cfg["planet"]["tmp_magma"]
end
# effective temperature case
tmp_eff::Float64 = 0.0
tmp_int::Float64 = 0.0
if sol_type == 3
tmp_eff = cfg["planet"]["tmp_eff"]
tmp_int = cfg["planet"]["tmp_int"]
end
# target OLR case
target_olr::Float64 = 0.0
Expand Down Expand Up @@ -311,7 +311,7 @@ module AGNI
overlap_method=overlap,
skin_d=skin_d, skin_k=skin_k, tmp_magma=tmp_magma,
target_olr=target_olr,
tmp_eff=tmp_eff, albedo_s=albedo_s,
tmp_int=tmp_int, albedo_s=albedo_s,
thermo_functions=thermo_funct,
C_d=turb_coeff, U=wind_speed,
fastchem_path=fastchem_path
Expand Down
14 changes: 7 additions & 7 deletions src/atmosphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module atmosphere
SOL_TYPES::Array{String, 1} = [
"steadystate_ext", # zero divergence at fixed tmp_surf, extrapolated tmpl[end]
"cond_skin", # set tmp_surf such that conductive skin conserves energy flux
"flux_eff", # total flux at each level equal to flux_eff
"flux_int", # total flux at each level equal to flux_int
"target_olr", # OLR is equal to target_olr
]

Expand Down Expand Up @@ -71,7 +71,7 @@ module atmosphere
instellation::Float64 # Solar flux at top of atmopshere [W m-2]
s0_fact::Float64 # Scale factor to instellation (cronin+14)
tmp_surf::Float64 # Surface brightness temperature [K]
tmp_eff::Float64 # Effective temperature of the planet [K]
tmp_int::Float64 # Effective temperature of the planet [K]
grav_surf::Float64 # Surface gravity [m s-2]
overlap_method::Int # Absorber overlap method to be used

Expand Down Expand Up @@ -128,7 +128,7 @@ module atmosphere
layer_mass::Array{Float64,1} # mass per unit area [kg m-2]

# Calculated bolometric radiative fluxes (W m-2)
flux_eff::Float64 # Effective flux [W m-2] for sol_type=3
flux_int::Float64 # Effective flux [W m-2] for sol_type=3
target_olr::Float64 # Target olr [W m-2] for sol_type=4

flux_d_lw::Array{Float64,1} # down component, lw
Expand Down Expand Up @@ -252,7 +252,7 @@ module atmosphere
- `skin_k::Float64` skin thermal conductivity [W m-1 K-1].
- `overlap_method::Int` gaseous overlap scheme (2: rand overlap, 4: equiv extinct, 8: ro+resort+rebin).
- `target_olr::Float64` target OLR [W m-2] for sol_type==4.
- `tmp_eff::Float64` planet's effective brightness temperature [K] for sol_type==3.
- `tmp_int::Float64` planet's effective brightness temperature [K] for sol_type==3.
- `all_channels::Bool` use all channels available for RT?
- `flag_rayleigh::Bool` include rayleigh scattering?
- `flag_gcontinuum::Bool` include generalised continuum absorption?
Expand Down Expand Up @@ -284,7 +284,7 @@ module atmosphere
skin_k::Float64 = 2.0,
overlap_method::Int = 4,
target_olr::Float64 = 0.0,
tmp_eff::Float64 = 0.0,
tmp_int::Float64 = 0.0,
all_channels::Bool = true,
flag_rayleigh::Bool = false,
flag_gcontinuum::Bool = false,
Expand Down Expand Up @@ -336,7 +336,7 @@ module atmosphere
atmos.nlev_c = nlev_centre
atmos.nlev_l = atmos.nlev_c + 1
atmos.tmp_surf = max(tmp_surf, atmos.tmp_floor)
atmos.tmp_eff = tmp_eff
atmos.tmp_int = tmp_int
atmos.grav_surf = max(1.0e-7, gravity)
atmos.zenith_degrees = max(min(zenith_degrees,89.8), 0.2)
atmos.albedo_s = max(min(albedo_s, 1.0 ), 0.0)
Expand All @@ -345,7 +345,7 @@ module atmosphere
atmos.s0_fact = max(s0_fact,0.0)
atmos.toa_heating = atmos.instellation * (1.0 - atmos.albedo_b) * s0_fact * cosd(atmos.zenith_degrees)

atmos.flux_eff = phys.sigma * (atmos.tmp_eff)^4.0
atmos.flux_int = phys.sigma * (atmos.tmp_int)^4.0
atmos.target_olr = max(1.0e-20,target_olr)

atmos.mask_decay = 15
Expand Down
4 changes: 2 additions & 2 deletions src/dump.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module dump
# Scalar quantities
# Create variables
var_tmp_surf = defVar(ds, "tmp_surf", Float64, (), attrib = OrderedDict("units" => "K")) # Surface brightness temperature [K]
var_tmp_eff = defVar(ds, "tmp_eff", Float64, (), attrib = OrderedDict("units" => "K")) # Effective temperature [K]
var_tmp_int = defVar(ds, "tmp_int", Float64, (), attrib = OrderedDict("units" => "K")) # Effective temperature [K]
var_inst = defVar(ds, "instellation", Float64, (), attrib = OrderedDict("units" => "W m-2")) # Solar flux at TOA
var_s0fact = defVar(ds, "inst_factor", Float64, ()) # Scale factor applied to instellation
var_albbond = defVar(ds, "bond_albedo", Float64, ()) # Bond albedo used to scale-down instellation
Expand All @@ -150,7 +150,7 @@ module dump

# Store data
var_tmp_surf[1] = atmos.tmp_surf
var_tmp_eff[1] = atmos.tmp_eff
var_tmp_int[1] = atmos.tmp_int
var_inst[1] = atmos.instellation
var_s0fact[1] = atmos.s0_fact
var_albbond[1] = atmos.albedo_b
Expand Down
25 changes: 12 additions & 13 deletions src/energy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -458,47 +458,46 @@ module energy
"""
function condense_relax!(atmos::atmosphere.Atmos_t)

# Check if empty
if length(atmos.condensates) == 0
return nothing
end

# Get name
c::String = atmos.gas_names[1]
c::String = atmos.condensates[1]

# Reset flux and mask
fill!(atmos.flux_l, 0.0)
fill!(atmos.mask_l, 0)
fill!(atmos.gas_ptran[c], false)

# Check if empty
if length(atmos.condensates) == 0
return nothing
end

# Work variables
a::Float64 = 1.0
pp::Float64 = 0.0
qsat::Float64 = 0.0
dif::Array = zeros(Float64, atmos.nlev_c)


# Calculate flux (negative) divergence due to latent heat release...
# For all levels
for i in 1:atmos.nlev_c-1

# Check criticality
if atmos.tmp[i] > atmos.gas_dat[c].T_crit
continue
end

# Get partial pressure
pp = atmos.gas_vmr[c][i] * atmos.p[i]
if pp < 1.0e-10
continue
end

# check saturation
qsat = phys.get_Psat(atmos.gas_dat[c], atmo.tmp[i])/atmos.p[i]
qsat = phys.get_Psat(atmos.gas_dat[c], atmos.tmp[i])/atmos.p[i]
if (atmos.gas_vmr[c][i] < qsat+1.0e-10)
continue
end

# Check criticality
if atmos.tmp[i] > atmos.gas_dat[c].T_crit
continue
end

# relaxation function
dif[i] = a*(atmos.gas_vmr[c][i]-qsat)

Expand Down
4 changes: 2 additions & 2 deletions src/plotting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ module plotting
# Zero line
plot!(plt, [0.0, 0.0], [arr_P[1], arr_P[end]], lw=0.4, lc="black", label="")

# Effective flux
# Intrinsic/interior flux
if incl_eff
plot!(plt, [_symlog(atmos.flux_eff)], [arr_P[1], arr_P[end]], ls=:dashdot, lw=0.4, lc="black", label="EFF")
plot!(plt, [_symlog(atmos.flux_int)], [arr_P[1], arr_P[end]], ls=:dashdot, lw=0.4, lc="black", label="INT")
end

# LW component
Expand Down
21 changes: 13 additions & 8 deletions src/solver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module solver
Arguments:
- `atmos::Atmos_t` the atmosphere struct instance to be used.
- `sol_type::Int` solution type, 1: tmp_surf | 2: skin | 3: tmp_eff | 4: tgt_olr
- `sol_type::Int` solution type, 1: tmp_surf | 2: skin | 3: tmp_int | 4: tgt_olr
- `chem_type::Int` chemistry type (see wiki)
- `convect::Bool` include convection
- `sens_heat::Bool` include sensible heating
Expand Down Expand Up @@ -109,14 +109,17 @@ module solver
detect_plateau::Bool=true, perturb_all::Bool=false,
modplot::Int=1, save_frames::Bool=true,
modprint::Int=1,
conv_atol::Float64=1.0e-3, conv_rtol::Float64=1.0e-3
conv_atol::Float64=1.0e-2, conv_rtol::Float64=1.0e-3
)::Bool

# Validate sol_type
if (sol_type < 1) || (sol_type > 4)
@error "Invalid solution type ($sol_type)"
return false
end
if detect_plateau && !linesearch
@warn "Plateau nudging enabled without linesearch - expect instability"
end

# Start timer
wct_start::Float64 = time()
Expand Down Expand Up @@ -257,8 +260,8 @@ module solver
elseif (sol_type == 3)
# Zero loss
resid[2:end] .= atmos.flux_dif[1:end]
# Total flux at TOA is equal to sigma*tmp_eff^4
resid[1] = atmos.flux_tot[1] - atmos.flux_eff
# Total flux at TOA is equal to sigma*tmp_int^4
resid[1] = atmos.flux_tot[1] - atmos.flux_int

elseif (sol_type == 4)
# Zero loss
Expand Down Expand Up @@ -394,8 +397,8 @@ module solver
@info @sprintf(" skin_d = %.2f m", atmos.skin_d)
@info @sprintf(" skin_k = %.2f W K-1 m-1", atmos.skin_k)
elseif (sol_type == 3)
@info @sprintf(" tmp_eff = %.2f K", atmos.tmp_eff)
@info @sprintf(" f_eff = %.2f W m-2", atmos.flux_eff)
@info @sprintf(" tmp_int = %.2f K", atmos.tmp_int)
@info @sprintf(" f_int = %.2f W m-2", atmos.flux_int)
elseif (sol_type == 4)
@info @sprintf(" tgt_olr = %.2f W m-2", atmos.target_olr)
end
Expand Down Expand Up @@ -434,7 +437,9 @@ module solver
plot_step()
end

@info @sprintf(" step resid_med resid_2nm flux_OLR xvals_med xvals_max |dx|_max flags")
if modprint > 0
@info @sprintf(" step resid_med resid_2nm flux_OLR xvals_med xvals_max |dx|_max flags")
end
info_str::String = ""
stepflags::String = ""
while true
Expand Down Expand Up @@ -683,7 +688,7 @@ module solver
atmos.is_solved = true
atmos.is_converged = false
if code == 0
@info " success"
@info " success in $step steps"
atmos.is_converged = true
elseif code == 1
@error " failure (maximum iterations)"
Expand Down
Loading

0 comments on commit 5dd34dd

Please sign in to comment.