Skip to content

Commit c922526

Browse files
committed
Module docstrings. Fixed tests. Moved calc_layer_props back to atmosphere module. Moved colours to style module. Add header to all files
1 parent 2a2eb36 commit c922526

34 files changed

Lines changed: 626 additions & 482 deletions

src/AGNI.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
12
# Core file containing functions for running the model
23

34
# Not for direct execution
@@ -26,8 +27,8 @@ module AGNI
2627
include("energy/spectrum.jl"); import .spectrum; export spectrum
2728
include("state/atmosphere.jl"); import .atmosphere; export atmosphere
2829
include("state/diagnostics.jl"); import .diagnostics; export diagnostics
29-
include("state/layers.jl"); import .layers; export layers
3030
include("compose/ocean.jl"); import .ocean; export ocean
31+
include("compose/fastchem.jl"); import .fastchem; export fastchem
3132
include("compose/chemistry.jl"); import .chemistry; export chemistry
3233
include("energy/rfm.jl"); import .rfm; export rfm
3334
include("interface/setpt.jl"); import .setpt; export setpt

src/compose/chemistry.jl

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contains things relating to atmospheric chemistry
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
22

33
"""
44
This module handles chemistry, condensation, and evaporation.
@@ -17,10 +17,9 @@ module chemistry
1717
# Local files
1818
import ..phys
1919
import ..atmosphere
20-
import ..layers
2120
import ..species
2221
import ..ocean
23-
include("fastchem.jl"); import .fastchem
22+
import ..fastchem
2423

2524
# Constants
2625
const SMALL_FLOAT::Float64 = 1e-20 # small number for numerical stability
@@ -96,7 +95,7 @@ module chemistry
9695
atmosphere.generate_pgrid!(atmos)
9796

9897
# Layer properties
99-
layers.calc_layer_props!(atmos)
98+
atmosphere.calc_layer_props!(atmos)
10099
end
101100

102101

@@ -143,7 +142,7 @@ module chemistry
143142
# rainout completely, and skip condensation
144143
dp = -p_gas[c]
145144
atmos.p_boa += dp
146-
@debug @sprintf(" %s de-mixed, partial pressure += %+.3f bar", c, dp/1e5)
145+
@debug @sprintf(" %s de-mixed, partial pressure += %+.3e bar", c, dp/1e5)
147146
any_changed = true
148147

149148
# If supercritical, do nothing
@@ -163,13 +162,13 @@ module chemistry
163162

164163
# Super-saturated at the surface...
165164
elseif dp < 0
166-
@debug @sprintf(" %s super-saturated, partial pressure += %+.3f bar", c, dp/1e5)
165+
@debug @sprintf(" %s super-saturated, partial pressure += %+.3e bar", c, dp/1e5)
167166

168167
# Sub-saturated at the surface...
169168
# work out change in partial pressure based on initial reservoir amount
170169
else
171170
dp = min(dp, atmos.ocean_ini[c] * atmos.grav_surf / (atmos.gas_dat[c].mmw/atmos.layer_μ[end]))
172-
@debug @sprintf(" %s sub-saturated, partial pressure += %+.3f bar", c, dp/1e5)
171+
@debug @sprintf(" %s sub-saturated, partial pressure += %+.3e bar", c, dp/1e5)
173172
end
174173

175174
# Record that at least one component has as changed
@@ -207,7 +206,7 @@ module chemistry
207206
atmosphere.generate_pgrid!(atmos)
208207

209208
# Calculate new values for layer properties
210-
layers.calc_layer_props!(atmos)
209+
atmosphere.calc_layer_props!(atmos)
211210

212211
return any_changed
213212
end
@@ -301,7 +300,7 @@ module chemistry
301300
end # end saturation check
302301

303302
# recalculate layer properties after raining-out this species
304-
layers.calc_layer_props!(atmos)
303+
atmosphere.calc_layer_props!(atmos)
305304

306305
end # end condensate
307306

@@ -395,15 +394,15 @@ module chemistry
395394
end # go to next j level (below)
396395

397396
# Layer properties
398-
layers.calc_layer_props!(atmos)
397+
atmosphere.calc_layer_props!(atmos)
399398

400399
end # end loop over condensates
401400

402401
# Layer properties
403402
for i in 1:atmos.nlev_c
404403
normalise_vmrs!(atmos, i)
405404
end
406-
layers.calc_layer_props!(atmos)
405+
atmosphere.calc_layer_props!(atmos)
407406

408407
# Set water clouds at levels where condensation occurs
409408
if "H2O" in atmos.condensates
@@ -466,7 +465,7 @@ module chemistry
466465
end
467466

468467
# recalculate layer properties
469-
layers.calc_layer_props!(atmos)
468+
atmosphere.calc_layer_props!(atmos)
470469

471470
# Warn on failure
472471
if state > 0

src/compose/fastchem.jl

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
2+
3+
"""
4+
**Run FastChem to solve gas phase chemistry.**
5+
6+
FastChem is a fast and robust chemical equilibrium solver, designed for use in exoplanet
7+
and brown dwarf atmospheres. This module writes the necessary input files for FastChem,
8+
runs the code, and parses the output to update the gas phase composition.
9+
"""
110
module fastchem
211

312
# Import packages
@@ -6,8 +15,10 @@ module fastchem
615
import DelimitedFiles:readdlm
716

817
# Include local modules
9-
using ..atmosphere
10-
using ..phys
18+
import ..atmosphere
19+
import ..phys
20+
import ..consts
21+
import ..formulae
1122

1223
# Constants
1324
const SMOOTH_SCALE::Float64 = 12.0 # smoothing scale for fastchem floor
@@ -93,7 +104,7 @@ module fastchem
93104
@debug "Elements set by user-provided metallicities"
94105

95106
# copy original to calculated; set elem to zero if it was not provided
96-
for e in phys.elems_standard
107+
for e in consts.elems_standard
97108
atmos.metal_calc[e] = get(atmos.metal_orig, e, 0.0)
98109
end
99110
atmos.metal_calc["H"] = 1.0
@@ -104,8 +115,8 @@ module fastchem
104115

105116
# Calculate elemental abundances from surface mixing ratios [molecules/m^3]
106117
# assuming ideal gas: N/V = P*x/(Kb*T) , where x is the VMR
107-
N_inp_t = zeros(Float64, length(phys.elems_standard)) # total atoms in all gases
108-
N_inp_g = zeros(Float64, length(phys.elems_standard)) # atoms in current gas
118+
N_inp_t = zeros(Float64, length(consts.elems_standard)) # total atoms in all gases
119+
N_inp_g = zeros(Float64, length(consts.elems_standard)) # atoms in current gas
109120
# loop over gases
110121
for gas in atmos.gas_names
111122
fill!(N_inp_g, 0.0)
@@ -116,16 +127,16 @@ module fastchem
116127
end
117128

118129
# count atoms in this gas
119-
d = phys.count_atoms(gas)
120-
for (i,e) in enumerate(phys.elems_standard)
130+
d = formulae.count_atoms(gas)
131+
for (i,e) in enumerate(consts.elems_standard)
121132
if haskey(d, e)
122133
N_inp_g[i] += d[e] # N_inp_g stores num of atoms in this gas
123134
end
124135
end
125136

126137
# Get gas abundance from original VMR value
127138
# scale number of atoms by the abundance of the gas (p = Ng kB T)
128-
N_inp_g *= atmos.gas_vmr[gas][end] * atmos.p[end] / (phys.k_B * atmos.tmp[end])
139+
N_inp_g *= atmos.gas_vmr[gas][end] * atmos.p[end] / (consts.k_B * atmos.tmp[end])
129140

130141
# Add atoms from this gas to total atoms in the mixture
131142
N_inp_t += N_inp_g
@@ -138,7 +149,7 @@ module fastchem
138149
end
139150

140151
# Convert elemental abundances to metallicity number ratios, rel to hydrogen
141-
for (i,e) in enumerate(phys.elems_standard)
152+
for (i,e) in enumerate(consts.elems_standard)
142153
atmos.metal_calc[e] = N_inp_t[i]/N_inp_t[1]
143154
end
144155
end
@@ -148,7 +159,7 @@ module fastchem
148159
# for each element `e`, value = log10(N_e/N_H) + 12
149160
open(atmos.fastchem_elem,"w") do f
150161
write(f,"# Elemental abundances file written by AGNI \n")
151-
for e in phys.elems_standard
162+
for e in consts.elems_standard
152163

153164
# skip this element if its abundance is too small
154165
if atmos.metal_calc[e] < 1.0e-30
@@ -160,7 +171,7 @@ module fastchem
160171
write(f, @sprintf("%s %.3f \n",e,log10(atmos.metal_calc[e]) + 12.0))
161172
else
162173
@warn "Got non-finite metallicity for $e - adopting solar value"
163-
write(f, @sprintf("%s %.3f \n",e,phys.consts._solar_metallicity[e]))
174+
write(f, @sprintf("%s %.3f \n",e,consts.solar_metallicity[e]))
164175
end
165176

166177
count_elem_nonzero += 1
@@ -276,10 +287,10 @@ module fastchem
276287

277288
# not stored => search based on atoms
278289
if !match
279-
d_fc = phys.count_atoms(g_fc) # get atoms dict from FC name
290+
d_fc = formulae.count_atoms(g_fc) # get atoms dict from FC name
280291

281292
for g in atmos.gas_names
282-
if phys.same_atoms(d_fc, atmos.gas_dat[g].atoms)
293+
if formulae.same_atoms(d_fc, atmos.gas_dat[g].atoms)
283294
match = true
284295
g_in = g
285296
break

src/compose/ocean.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
12
# Contains module handling surface oceans
23

34
"""

src/energy/energy.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1-
# Contains the energy module, for everything relating to energy transport
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
22

3+
4+
"""
5+
**Contains the energy module, for everything relating to energy transport**
6+
7+
Calculates radiative, convective, conductive, etc, flux terms. Combines them together
8+
self-consistently to update the temperature profile.
9+
"""
310
module energy
411

512
# System libraries

src/energy/rfm.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
# Contains module and functions for performing radiative transfer with RFM
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
22

3+
4+
"""
5+
**Module and functions for performing radiative transfer with RFM**
6+
7+
The RFM (Reference Forward Model) is a line-by-line radiative transfer code developed
8+
by Anu Dudhia at Oxford. This module contains writies the required input files, runs it,
9+
and parses the output to update the radiative fluxes in AGNI for post-processing.
10+
"""
311
module rfm
412

513
# Import modules

src/energy/spectrum.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
# Contains the spectrum module, for updating the SOCRATES spectral file at
2-
# runtime with the solar flux / thermal source function, and scattering.
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
32

3+
4+
"""
5+
**Contains the spectrum module, for updating the SOCRATES spectral files**
6+
7+
Specifically for SOCRATES. Inserts solar flux, thermal source function, and scattering
8+
data into the spectral files using SOCRATES utilities.
9+
"""
410
module spectrum
511

612
using LoggingExtras

src/interface/load.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# Load atmosphere from NetCDF file
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
22

3+
"""
4+
**Module for loading atmospheric states from NetCDF and CSV files.**
5+
"""
36
module load
47

58
import ..atmosphere
6-
import ..layers: calc_layer_props!
79

810
using NCDatasets
911
using LoggingExtras

src/interface/paths.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
2+
3+
"""
4+
**Module for handling file paths and directories.**
5+
"""
16
module paths
27

38
# Load modules

src/interface/plotting.jl

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
# Contains functions for plotting/diagnosing the atmosphere
1+
# This file is part of AGNI. License is GPL-3.0: https://www.gnu.org/licenses
22

3+
"""
4+
**Contains functions for plotting/diagnosing the atmosphere**
5+
"""
36
module plotting
47

58
# Import stuff
@@ -14,22 +17,11 @@ module plotting
1417
import ..phys
1518
import ..species
1619
import ..multicol
17-
18-
# Allowed plot file extensions
19-
const ALLOWED_EXTS::Set{String} = Set(["png", "pdf", "svg"])
20+
using ..style
2021

2122
# Axis margins
2223
TMP_MARGIN::Float64 = 100.0
2324

24-
# Colors
25-
const col_r::String = "#c0c0c0"
26-
const col_n::String = "#000000"
27-
const col_c::String = "#6495ed"
28-
const col_t::String = "#ff4400"
29-
const col_o::String = "#66CD00"
30-
const col_p::String = "#ecb000"
31-
const col_d::String = "#8B008B"
32-
3325
# Default plotting configuration
3426
const la::Float64 = 0.7
3527
const lw::Float64 = 1.9

0 commit comments

Comments
 (0)