diff --git a/.gitignore b/.gitignore index 127dc65f..79564524 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,10 @@ radiation_code.lock socrates SOCRATES +# FastChem folder +fastchem +FastChem + # Package deps/*.log test/out/ diff --git a/docs/src/usage.md b/docs/src/usage.md index 7789d1de..7c808962 100644 --- a/docs/src/usage.md +++ b/docs/src/usage.md @@ -9,12 +9,16 @@ of the repository. ## General execution The environment variable `RAD_DIR` must point to the SOCRATES installation directory. This is required for AGNI to find the SOCRATES libraries, and can be -done by running `source path/to/set_rad_env` in your terminal. +done by running `source path/to/socrates/set_rad_env` in your terminal. Then to use the model, simply run `./agni.jl [cfg]` where `[cfg]` is the path to the required configuration file. If `[cfg]` is not passed, then the default configuration will be used. +To calculate equilibrium chemistry self-consistently with the climate, FastChem +is coupled to AGNI. For AGNI to find FastChem, the environment variable `FC_DIR` +must point to the FastChem installation directory. + ## Configuration AGNI configuration files are formatted using [TOML](https://toml.io/en/). There are examples in `res/config/`. The default configuration file contains comments @@ -53,7 +57,7 @@ Some parameters: For example, setting `initial_state = ["dry", "sat", "H2O", "str", "180"]` will set T(p) to follow the dry adiabat from the surface, the water condensation curve above that, and then to be isothermal at 180 K until the top of the model. -* `composition.chem_type` describes the type of chemistry to implement within the model. This is handled externally by FastChem. You must also provide the path to the FastChem installation directory `fastchem_path` in the `[files]` section. The allowed values (integers) are... +* `composition.chem_type` describes the type of chemistry to implement within the model. This is handled externally by FastChem, so you must set the environment variable `FC_DIR` to point to the FastChem directory. The allowed values (integers) are... - 0 : Disabled - 1 : Equilibrium, gas phase only - 2 : Equilibrium, with condensation (condensates retained) diff --git a/get_fastchem.sh b/get_fastchem.sh new file mode 100755 index 00000000..66ef1984 --- /dev/null +++ b/get_fastchem.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Download via HTTPS only +fcpath="fastchem" +rm -rf "$fcpath" + +git clone https://github.com/NewStrangeWorlds/FastChem.git "$fcpath" + +# Compile FastChem +cd "$fcpath" +mkdir build +cd build + +cmake ".." +make + +cd .. +export FC_DIR="$(realpath $fcpath)" diff --git a/res/config/55cnce_chem.toml b/res/config/55cnce_chem.toml index 2eab48a4..392c9417 100644 --- a/res/config/55cnce_chem.toml +++ b/res/config/55cnce_chem.toml @@ -18,7 +18,6 @@ title = "Roughly 55 Cancri e @ fO2=IW" input_sf = "res/spectral_files/nogit/Dayspring/256/Dayspring.sf" input_star = "res/stellar_spectra/hd97658.txt" output_dir = "out/" - fastchem_path = "/Users/nichollsh/Projects/FastChem/" [composition] p_top = 1e-7 diff --git a/res/literature_data/profile/readme.txt b/res/literature_data/profile/readme.txt index 40818bef..326f22af 100644 --- a/res/literature_data/profile/readme.txt +++ b/res/literature_data/profile/readme.txt @@ -12,10 +12,5 @@ Their Seff = 1 corresponds to a value of 341.5 Wm−2, which comes from: This can be achieved by setting the following parameters in AGNI: - s0_fact = 0.6652 - zenith_angle = 60.0 - - albedo_b = 0.18 + - albedo_b = 0.0, but rayleigh scattering enabled - instellation = 1366 * S_eff - -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_int = sigma (T_int)^4 = OTR + F_UP_SW - F_DN_SW - diff --git a/res/literature_data/runaway/readme.txt b/res/literature_data/readme.txt similarity index 100% rename from res/literature_data/runaway/readme.txt rename to res/literature_data/readme.txt diff --git a/src/AGNI.jl b/src/AGNI.jl index b66bc907..5a7670a0 100755 --- a/src/AGNI.jl +++ b/src/AGNI.jl @@ -196,7 +196,7 @@ module AGNI # Hello @info "Hello" - # Temp folders + # Temp folders for OUTPUT dir_fastchem = joinpath(output_dir,"fastchem/") dir_frames = joinpath(output_dir,"frames/") rm(dir_fastchem,force=true,recursive=true) @@ -225,7 +225,6 @@ module AGNI mf_dict::Dict{String, Float64} = Dict{String, Float64}() mf_path::String = "" use_all_gases::Bool = cfg["composition"]["include_all"] - fastchem_path::String = "" if haskey(cfg["composition"],"p_surf") # set composition using VMRs + Psurf if haskey(cfg["composition"],"vmr_dict") @@ -259,7 +258,6 @@ module AGNI @error "Misconfiguration: FastChem coupling is incompatible with AGNI condensation scheme" exit(1) else - fastchem_path = cfg["files"]["fastchem_path"] mkdir(dir_fastchem) end end @@ -342,7 +340,6 @@ module AGNI tmp_int=tmp_int, albedo_s=albedo_s, thermo_functions=thermo_funct, C_d=turb_coeff, U=wind_speed, - fastchem_path=fastchem_path, use_all_gases=use_all_gases ) atmosphere.allocate!(atmos,star_file) diff --git a/src/atmosphere.jl b/src/atmosphere.jl index d2b0df25..5c3a311f 100644 --- a/src/atmosphere.jl +++ b/src/atmosphere.jl @@ -45,9 +45,10 @@ module atmosphere is_out_sw::Bool # Contains data for SW calculation # Directories - ROOT_DIR::String - OUT_DIR::String - THERMO_DIR::String + ROOT_DIR::String # path to AGNI root folder (containing agni.jl) + OUT_DIR::String # path to output folder + THERMO_DIR::String # path to thermo data + FC_DIR::String # path to fastchem exec folder # SOCRATES objects SOCRATES_VERSION::String @@ -197,7 +198,6 @@ module atmosphere # FastChem stuff fastchem_flag::Bool # Fastchem enabled? - fastchem_path::String # Path to fastchem installation folder (incl. executable) fastchem_work::String # Path to fastchem dir inside AGNI output folder Atmos_t() = new() @@ -264,7 +264,6 @@ module atmosphere - `flag_aerosol::Bool` include aersols? - `flag_cloud::Bool` include clouds? - `thermo_functions::Bool` use temperature-dependent thermodynamic properties - - `fastchem_path::String` path to FastChem folder (empty string => disabled) - `use_all_gases::Bool` store information on all supported gases, incl those not provided in cfg Returns: @@ -297,7 +296,6 @@ module atmosphere flag_aerosol::Bool = false, flag_cloud::Bool = false, thermo_functions::Bool = true, - fastchem_path::String = "", use_all_gases::Bool = false ) @@ -630,23 +628,28 @@ module atmosphere # Fastchem atmos.fastchem_flag = false - if !isempty(fastchem_path) + if ("FC_DIR" in keys(ENV)) + + @debug "FastChem env has been set" + # check folder - atmos.fastchem_path = abspath(fastchem_path) - if !isdir(fastchem_path) - @error "Could not find fastchem folder at '$(fastchem_path)'" + atmos.FC_DIR = abspath(ENV["FC_DIR"]) + if !isdir(atmos.FC_DIR) + @error "Could not find fastchem folder at '$(atmos.FC_DIR)'" return end - atmos.fastchem_work = joinpath(atmos.OUT_DIR, "fastchem/") + atmos.fastchem_work = joinpath(atmos.OUT_DIR, "fastchem/") # working directory # check executable - atmos.fastchem_flag = isfile(joinpath(fastchem_path,"fastchem")) + atmos.fastchem_flag = isfile(joinpath(atmos.FC_DIR,"fastchem")) if !atmos.fastchem_flag - @error "Could not find fastchem executable inside '$(atmos.fastchem_path)' " + @error "Could not find fastchem executable inside '$(atmos.FC_DIR)' " return else @info "Found FastChem executable" end + else + @debug "FastChem env variable not set" end # Record that the parameters are set @@ -1262,7 +1265,7 @@ module atmosphere count_elem_nonzero::Int = 0 # Paths - execpath::String = joinpath(atmos.fastchem_path,"fastchem") # Executable file + execpath::String = joinpath(atmos.FC_DIR, "fastchem") # Executable file confpath::String = joinpath(atmos.fastchem_work,"config.input") # Configuration by AGNI chempath::String = joinpath(atmos.fastchem_work,"chemistry.dat") # Chemistry by FastChem @@ -1293,7 +1296,7 @@ module atmosphere write(f,joinpath(atmos.fastchem_work,"elements.dat")*" \n\n") write(f,"#Species data files \n") - logK = joinpath(atmos.fastchem_path,"input/","logK/") + logK = joinpath(atmos.FC_DIR, "input/","logK/") write(f,joinpath(logK,"logK.dat")*" "*joinpath(logK,"logK_condensates.dat")*" \n\n") write(f,"#Accuracy of chemistry iteration \n")