forked from nichollsh/AGNI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agni.jl
executable file
·116 lines (96 loc) · 3.48 KB
/
agni.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env -S julia --color=yes --startup-file=no
# -------------
# AGNI executable file for standalone execution
# -------------
tbegin = time()
println("Begin AGNI")
# Get AGNI root directory
ROOT_DIR = dirname(abspath(@__FILE__))
ENV["GKSwstype"] = "100"
# Include libraries
using Revise
# Include local jl files
include("socrates/julia/src/SOCRATES.jl")
push!(LOAD_PATH, joinpath(ROOT_DIR,"src"))
import atmosphere
import setpt
import plotting
import solver_accel
import solver_cvode
import phys
# Configuration options
tstar = 2999.0 # Surface temperature [kelvin]
toa_heating = 778.5 # Instellation flux [W m-2]
radius = 7.12e6 # metres
gravity = 10.8 # m s-2
nlev_centre = 100
p_surf = 100.0 # bar
p_top = 1e-5 # bar
mf_dict = Dict([
("H2O" , 0.9),
("CO2" , 0.1),
# ("H2" , 7.53004),
# ("CO" , 90.58514),
# ("N2" , 1.41003)
])
spfile_name = "res/spectral_files/Mallard/Mallard"
star_file = "res/stellar_spectra/trappist-1.txt"
output_dir = "out/"
# Setup atmosphere
println("Setting up")
atmos = atmosphere.Atmos_t()
atmosphere.setup!(atmos, ROOT_DIR, output_dir,
spfile_name,
toa_heating, tstar,
gravity, radius,
nlev_centre, p_surf, p_top,
mf_dict=mf_dict,
flag_gcontinuum=true,
flag_rayleigh=true,
overlap_method=4,
zenith_degrees=54.4,
skin_d=0.01,
skin_k=2.0,
tmp_magma=3000.0,
tmp_floor=2.0
)
atmosphere.allocate!(atmos;stellar_spectrum=star_file,spfile_noremove=true)
# Set PT profile
println("Setting initial T(p)")
# setpt.fromcsv!(atmos,"out/pt_load.csv")
# setpt.prevent_surfsupersat!(atmos)
# setpt.dry_adiabat!(atmos)
# setpt.stratosphere!(atmos, 2000.0)
# Create output directory
rm(output_dir,force=true,recursive=true)
if !isdir(output_dir) && !isfile(output_dir)
mkdir(output_dir)
end
atmosphere.write_pt(atmos, joinpath(atmos.OUT_DIR,"pt_ini.csv"))
println("Running model...")
# Calculate LW and SW fluxes (once)
# atmosphere.radtrans!(atmos, true)
# atmosphere.radtrans!(atmos, false)
# Calculate convective fluxes (once)
# println("MLT: calculating fluxes")
# atmosphere.mlt!(atmos)
# Call solver
solver_accel.solve_energy!(atmos, surf_state=2, modplot=1, verbose=true,
dry_convect=true, accel=true, use_mlt=true,
max_steps=1500)
# solver_cvode.solve_energy!(atmos, surf_state=2, verbose=true, dry_convect=true, max_steps=500)
# Write arrays
atmosphere.write_ncdf(atmos, joinpath(atmos.OUT_DIR,"atm.nc"))
atmosphere.write_pt(atmos, joinpath(atmos.OUT_DIR,"pt.csv"))
atmosphere.write_fluxes(atmos, joinpath(atmos.OUT_DIR,"fl.csv"))
# Save plots
plotting.anim_solver(atmos)
plotting.plot_x(atmos, joinpath(atmos.OUT_DIR,"mf.pdf"))
plotting.plot_pt(atmos, joinpath(atmos.OUT_DIR,"pt.pdf"))
plotting.plot_fluxes(atmos, joinpath(atmos.OUT_DIR,"fl.pdf"))
# Deallocate atmosphere
println("Deallocating arrays")
atmosphere.deallocate!(atmos)
runtime = round(time() - tbegin, digits=2)
println("Runtime: $runtime seconds")
println("Goodbye")