Skip to content

Commit 02a5b66

Browse files
authored
Merge pull request #156 from nichollsh/hn/morels
Hn/morels
2 parents 2fb5ab2 + 9e86640 commit 02a5b66

9 files changed

Lines changed: 57 additions & 45 deletions

File tree

.zenodo.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
}
2323
],
2424
"title": "AGNI: An open-source model for extreme atmospheres on rocky exoplanets",
25-
"version": "1.8.0",
25+
"version": "1.8.1",
2626
"access_right": "open",
2727
"related_identifiers": [
2828
{

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ authors:
88

99
title: "AGNI: An open-source model for extreme atmospheres on rocky exoplanets"
1010
doi: 10.21105/joss.07726
11-
date-released: 2025-11-03
11+
date-released: 2025-11-20
1212

13-
version: 1.8.0
13+
version: 1.8.1
1414
url: "https://github.com/nichollsh/AGNI"
1515
type: software
1616
license: "GPL-3.0"

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "AGNI"
22
uuid = "ede838c1-9ec3-4ebe-8ae8-da4091b3f21c"
33
authors = ["Harrison Nicholls <harrison.nicholls@physics.ox.ac.uk>"]
4-
version = "1.8.0"
4+
version = "1.8.1"
55

66
[deps]
77
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"

codemeta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
"identifier": "",
1414
"codeRepository": "https://github.com/nichollsh/AGNI",
1515
"datePublished": "2024-12-29",
16-
"dateModified": "2025-10-21",
16+
"dateModified": "2025-11-20",
1717
"dateCreated": "2024-09-13",
1818
"description": "An open-source model for extreme atmospheres on rocky exoplanets.",
1919
"keywords": "exoplanets, radiation, astronomy, atmosphere, optimization, julia, fortran, convection, chemistry, magma, planetary, physics",
2020
"license": "GPL-3.0",
2121
"title": "AGNI",
22-
"version": "1.8.0"
22+
"version": "1.8.1"
2323
}

misc/utilities/grid_agni.jl

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,17 @@ mass_arr::Array{Float64, 1} = 10.0 .^ vcat( range(start=log10(0.5), stop=log10(
3434
# enter the least-important parameters first
3535
grid::OrderedDict = OrderedDict{String,Array{Float64,1}}((
3636

37+
"frac_core" => range(start=0.2, stop=0.7, step=0.1),
38+
"frac_atm" => range(start=0.00, stop=0.15, step=0.03),
39+
"mass_tot" => mass_arr, # M_earth
40+
3741
# metallicities here are by MASS fraction relative to hydrogen (converted to mole below)
38-
"metal_C" => 10 .^ range(start=-1.0, stop=3.0, step=2.0),
3942
# "metal_S" => 10 .^ range(start=-1.0, stop=3.0, step=2.0),
4043
# "metal_O" => 10 .^ range(start=-1.0, stop=3.0, step=2.0),
41-
42-
"frac_core" => range(start=0.2, stop=0.7, step=0.1),
43-
"frac_atm" => range(start=0.00, stop=0.15, step=0.03),
44+
"metal_C" => 10 .^ range(start=-1.0, stop=3.0, step=2.0),
4445

4546
# "Teff" => range(start=2500, stop=6000, step=700.0),
4647
"instellation" => 10 .^ range(start=log10(1.0), stop=log10(2500.0), length=5), # S_earth
47-
48-
"mass_tot" => mass_arr, # M_earth
4948
))
5049

5150
# Variables to record
@@ -56,17 +55,16 @@ output_keys = ["succ", "flux_loss",
5655

5756
# Grid management options
5857
save_netcdfs = false # NetCDF file for each case
59-
save_plots = false # plots for each case
60-
save_ncdf_tp = true # a single NetCDF containing all T(p) solutions
58+
save_plots = true # plots for each case
6159

6260
# Runtime options
63-
AGNI.solver.ls_increase= 1.02
64-
modwrite::Int = 1 # frequency to write CSV file
65-
modplot::Int = 2 # Plot during runtime (debug)
61+
AGNI.solver.ls_increase= 1.1
62+
modwrite::Int = 2 # frequency to write CSV file
63+
modplot::Int = 0 # Plot during runtime (debug)
6664
frac_min::Float64 = 0.001 # 0.001 -> 1170 bar for Earth
6765
frac_max::Float64 = 1.0
6866
transspec_p::Float64 = 2e3 # Pa
69-
fc_floor::Float64 = 500.0 # K
67+
fc_floor::Float64 = 300.0 # K
7068

7169
# =============================================================================
7270
# Parse keys and flatten grid
@@ -84,6 +82,18 @@ mkdir(output_dir)
8482
# Backup config to output dir
8583
cp(joinpath(ROOT_DIR,cfg_base), joinpath(output_dir,"base_config.toml"))
8684

85+
# IO directory
86+
# IO_DIR::String = "/tmp/"
87+
# if haskey(ENV,"TMPDIR")
88+
# IO_DIR = abspath(ENV["TMPDIR"])
89+
# end
90+
# IO_DIR = joinpath(IO_DIR,"agni_grid") * "/"
91+
IO_DIR = output_dir
92+
@info "IO folder: $IO_DIR"
93+
94+
mkdir(joinpath(output_dir,"nc"))
95+
mkdir(joinpath(output_dir,"pl"))
96+
8797
# Results path
8898
result_table_path::String = joinpath(output_dir,"result_table.csv")
8999
result_emits_path::String = joinpath(output_dir,"result_emits.csv")
@@ -340,6 +350,7 @@ atmosphere.setup!(atmos, ROOT_DIR, output_dir,
340350
p_top,
341351
mf_dict, "";
342352

353+
IO_DIR=IO_DIR,
343354
condensates=condensates,
344355
κ_grey_lw=grey_lw,
345356
κ_grey_sw=grey_sw,
@@ -418,7 +429,8 @@ function update_structure!(atmos, mass_tot, frac_atm, frac_core)
418429
atmos.grav_surf = phys.grav_accel(atmos.interior_mass, atmos.rp)
419430

420431
# surface pressure
421-
atmos.p_boa = mass_atm * atmos.grav_surf / (4 * pi * atmos.rp^2)
432+
atmos.p_oboa = mass_atm * atmos.grav_surf / (4 * pi * atmos.rp^2)
433+
atmos.p_boa = atmos.p_oboa
422434
atmosphere.generate_pgrid!(atmos)
423435
end
424436

@@ -523,16 +535,14 @@ for (i,p) in enumerate(grid_flat)
523535

524536
# Set temperature array based on interpolation from last solution
525537
max_steps = Int(cfg["execution"]["max_steps"])
526-
easy_start = Bool(cfg["execution"]["easy_start"])
527-
if i > 1
528-
if succ_last
529-
# last iter was successful
530-
setpt.fromarrays!(atmos, result_profs[i-1]["p"], result_profs[i-1]["t"])
531-
else
532-
# last iter failed -> restore initial guess for T(p)
533-
setpt.request!(atmos, cfg["execution"]["initial_state"])
534-
easy_start = true
535-
end
538+
if succ_last && (i > 1)
539+
# last iter was successful
540+
setpt.fromarrays!(atmos, result_profs[i-1]["p"], result_profs[i-1]["t"])
541+
easy_start = false
542+
else
543+
# last iter failed -> restore initial guess for T(p)
544+
setpt.request!(atmos, cfg["execution"]["initial_state"])
545+
easy_start = Bool(cfg["execution"]["easy_start"])
536546
end
537547

538548
# Solve for RCE
@@ -554,20 +564,22 @@ for (i,p) in enumerate(grid_flat)
554564
save_frames=false,
555565
radiative_Kzz=false,
556566
perturb_all=perturb_all,
557-
558567
)
559568

560569
# Report radius
561570
@info @sprintf(" found r_phot = %.3f R_earth",atmos.transspec_r/R_earth)
562571

563572
# Write NetCDF file for this case
564573
if save_netcdfs
565-
save.write_ncdf(atmos, joinpath(atmos.OUT_DIR,@sprintf("%08d.nc",i)))
574+
save.write_ncdf(atmos, joinpath(atmos.OUT_DIR,"nc",@sprintf("%08d.nc",i)))
566575
end
567576

568577
# Make plot for this case
569578
if save_plots
570-
plotting.plot_pt(atmos, joinpath(atmos.OUT_DIR,@sprintf("%08d_pt.png",i)))
579+
plotting.combined(plotting.plot_pt(atmos,""), plotting.plot_fluxes(atmos, ""),
580+
plotting.plot_vmr(atmos,""), plotting.plot_radius(atmos, ""),
581+
"Index = $i Success = $succ",
582+
joinpath(atmos.OUT_DIR,"pl",@sprintf("%08d_pl.png",i)))
571583
end
572584

573585
# Record keys (all in SI)

res/config/structure_grid.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ title = "Base config for structure calcs"
2424
[composition]
2525
p_surf = 100.0
2626
p_top = 1e-5
27-
metallicities = {"C"=0.01, "S"=0.1, "O"=0.1} # mass fraction
27+
metallicities = {"C"=0.1, "O"=10.0} # mass fraction
2828
condensates = []
2929

3030
[execution]
3131
clean_output = false
3232
verbosity = 1
3333
max_steps = 50
3434
max_runtime = 200
35-
num_levels = 35
35+
num_levels = 30
3636
solution_type = 3
3737
solver = "newton"
38-
dx_max = 100.0
39-
initial_state = ["loglin","800"]
38+
dx_max = 300.0
39+
initial_state = ["iso","2000"]
4040
linesearch = 1
41-
easy_start = true
41+
easy_start = false
4242
grey_start = false
4343
converge_atol = 1.0
4444
converge_rtol = 1.0e-2

src/atmosphere.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ module atmosphere
3333
import ..spectrum
3434

3535
# Code versions
36-
const AGNI_VERSION::String = "1.8.0" # current agni version
36+
const AGNI_VERSION::String = "1.8.1" # current agni version
3737
const SOCVER_minimum::Float64 = 2407.2 # minimum required socrates version
3838

3939
# Hydrostatic and gravity calc (constants and limits)

src/solver.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ module solver
117117
plateau_r::Float64 = 0.98 # Cost ratio for determining whether to increment plateau_i
118118
# linesearch
119119
ls_tau::Float64 = 0.7 # backtracking downscale size
120-
ls_increase::Float64 = 1.08 # factor by which the cost can increase from last step before triggering linesearch
120+
ls_increase::Float64 = 0.9 # factor by which the cost can increase from last step before triggering linesearch
121121
ls_max_steps::Int = 10 # maximum steps undertaken by linesearch routine
122122
ls_min_scale::Float64 = 1.0e-5 # minimum step scale allowed by linesearch
123123
ls_max_scale::Float64 = 0.99 # maximum step scale allowed by linesearch
@@ -323,14 +323,15 @@ module solver
323323
# Set new temperatures
324324
_set_tmps!(x)
325325

326-
# Do saturation aloft here, only
327-
# chemistry.calc_composition!(atmos, oceans, chem, rainout)
326+
# Do saturation aloft here, only. Keep chemistry fixed.
328327
if rainout
329328
# reset back to post-chemistry mixing ratios
330329
for g in atmos.gas_names
331330
@. atmos.gas_vmr[g] = atmos.gas_cvmr[g]
332331
end
333332
chemistry._sat_aloft!(atmos)
333+
else
334+
atmosphere.calc_layer_props!(atmos)
334335
end
335336

336337
# Calculate fluxes
@@ -383,7 +384,6 @@ module solver
383384
ok::Bool = true
384385

385386
# Evalulate residuals at x
386-
# chemistry.calc_composition!(atmos, oceans, chem, rainout)
387387
ok = ok && _fev!(x, resid)
388388

389389
# For each level...
@@ -779,7 +779,7 @@ module solver
779779
end
780780

781781
ls_cost = _ls_func(ls_alpha)
782-
if ls_cost <= c_cur*ls_increase
782+
if ls_cost <= c_cur#*ls_increase
783783
# this scale is good enough
784784
break
785785
end

test/runtests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ if suite > 15
740740

741741
# temperature profile
742742
@info "Temperature..."
743-
arr_e[:] .= [160.66339503503497, 172.09710160055477, 178.03603947440752, 179.20888073828587, 179.91013709468695, 179.28194461691936, 179.48335170955022, 181.60786079397423, 183.11232837720024, 182.74336048754452, 183.44034094824806, 186.23392659907887, 190.33872200527122, 195.3550015009265, 201.1036011339729, 207.48982773345082, 214.28148826113636, 221.70556437388842, 231.68725754907447, 246.4815220524279, 263.35634452191607, 287.5627049103804, 320.30148032756995, 354.8531587447293, 392.11917744416724, 429.26323831006886, 460.58872296988125, 487.0625306433956, 514.4554623098902, 543.1684695093304, 570.3876923217258, 593.8467013136508, 610.9314215719224, 620.7713434612795, 625.5983452566984, 628.122351599638, 629.6697885689832, 630.5708014622505, 630.9679678191192, 631.0915922829595, 631.121625484581, 631.1282688098997, 631.1296751975232, 631.129812085828, 631.1298132423226]
743+
arr_e[:] .= [160.663417882603, 172.097128812409, 178.036068253899, 179.208908569656, 179.910164720311, 179.281972493295, 179.483379941445, 181.607889256078, 183.112356682626, 182.74338943682, 183.440372062087, 186.233959168495, 190.338756315127, 195.355039534191, 201.103646189501, 207.489881120782, 214.2815536312, 221.705657433829, 231.687457669314, 246.481687372921, 263.356595002906, 287.5630763156, 320.301515497962, 354.852774535303, 392.118464544988, 429.26259724383, 460.588392363893, 487.062314373208, 514.455301328919, 543.168345970076, 570.387595711342, 593.846621505299, 610.931353333751, 620.771283792757, 625.59828953617, 628.122297051458, 629.66973541692, 630.570749507789, 630.967916271267, 631.091540930136, 631.121574633071, 631.128221749457, 631.12965996539, 631.129771581873, 631.129771953692]
744744
if all(abs.(arr_e[:] .- arr_o_tmp[:]) .< abs.(arr_e[:].*rtol) .+ 0.5)
745745
@info "Pass"
746746
else
@@ -773,7 +773,7 @@ if suite > 15
773773

774774
# eddy diffusion coefficients
775775
@info "Kzz..."
776-
arr_e[:] .= [297631.1773891829, 245779.83944484807, 202961.69913189596, 167603.05242102614, 138404.3556049965, 114292.46289807544, 94381.18488545873, 77938.71821912714, 64360.74949697297, 53148.24480646298, 43889.108627309775, 36243.03799898127, 29929.015295112327, 24714.979924151103, 20409.299358103035, 16853.726022315273, 13917.581189404838, 11492.952116772693, 9490.725907098406, 7837.314323464027, 6471.949185555334, 5344.448944073614, 13566.607073176909, 12453.628747107967, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415, 8814.614880555415]
776+
arr_e[:] .= [293515.330261667, 242381.028037358, 200155.006214063, 165285.323017843, 136490.40572033, 112711.948729345, 93076.0174630662, 76860.9284503441, 63470.7251477871, 52413.2746248124, 43282.1800995569, 35741.8445533194, 29515.1364634408, 24373.2043307382, 20127.0656526946, 16620.6612101877, 13725.1193905086, 11334.0197421416, 9359.48168174701, 7728.93460077965, 6382.45066279981, 5270.54226322015, 13528.8039526634, 12294.5144847605, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378, 8732.90905977378]
777777
if all(abs.(arr_e[:] .- arr_o_Kzz[:]) .< abs.(arr_e[:].*rtol) .+ 1e4)
778778
@info "Pass"
779779
else

0 commit comments

Comments
 (0)