Skip to content

Commit

Permalink
FastChem accessed via FC_DIR env variable, rather than through cfg. C…
Browse files Browse the repository at this point in the history
…onsistent with SOCRATES RAD_DIR
  • Loading branch information
nichollsh committed Jul 4, 2024
1 parent c4ce6e2 commit 45012c2
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 28 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ radiation_code.lock
socrates
SOCRATES

# FastChem folder
fastchem
FastChem

# Package
deps/*.log
test/out/
Expand Down
8 changes: 6 additions & 2 deletions docs/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions get_fastchem.sh
Original file line number Diff line number Diff line change
@@ -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)"
1 change: 0 additions & 1 deletion res/config/55cnce_chem.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions res/literature_data/profile/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

File renamed without changes.
5 changes: 1 addition & 4 deletions src/AGNI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
33 changes: 18 additions & 15 deletions src/atmosphere.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 45012c2

Please sign in to comment.