Skip to content

Commit

Permalink
Merge pull request #87 from nichollsh/hn/h2
Browse files Browse the repository at this point in the history
H2 Chabrier EOS, Runge-Kutta hydrostatic integration, self-gravity
  • Loading branch information
nichollsh authored Feb 20, 2025
2 parents b4da1f0 + ebbd09e commit bd57a36
Show file tree
Hide file tree
Showing 39 changed files with 2,739 additions and 6,167 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/install_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,15 @@ jobs:
sudo apt update
sudo apt-get install libnetcdff-dev netcdf-bin gfortran gcc
# Setup AGNI
# Setup Julia
- name: Setup Julia
uses: julia-actions/setup-julia@v2
with:
version: '1.11'

- name: Cache Julia
uses: julia-actions/cache@v2

# Setup SOCRATES
- name: Get SOCRATES
uses: actions/checkout@v4
Expand Down Expand Up @@ -65,6 +68,6 @@ jobs:
run: |
export RAD_DIR="/home/runner/work/AGNI/AGNI/SOCRATES"
export LD_LIBRARY_PATH=""
./test/runtests.jl
julia --project=. -e 'using Pkg; Pkg.test()'
3 changes: 1 addition & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AGNI"
uuid = "ede838c1-9ec3-4ebe-8ae8-da4091b3f21c"
authors = ["Harrison Nicholls <[email protected]>"]
version = "1.1.1"
version = "1.2.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
Expand All @@ -25,5 +25,4 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"

[compat]
Interpolations = "0.15.1"
julia = ">= 1.10"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</p>

<p align="center">
<b>A radiative-convective atmosphere model for lava planets</b>
<b>A radiative-convective model for lava planet atmospheres</b>
</p>


Expand Down
10 changes: 7 additions & 3 deletions agni.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,25 @@

# Don't show plot windows
ENV["GKSwstype"] = "100"
AGNI_DIR = dirname(abspath(@__FILE__))

# Check RAD_DIR
if !("RAD_DIR" in keys(ENV))
error("Cannot find SOCRATES! Have you set RAD_DIR?")
end

AGNI_DIR = dirname(abspath(@__FILE__))
# Check SOCRATES.jl
SOCjl = joinpath([abspath(ENV["RAD_DIR"]),"julia","src","SOCRATES.jl"])
if !isfile(SOCjl)
error("Cannot find SOCRATES library! Tried: '$SOCjl'")
end

# Activate environment
import Pkg
Pkg.activate(AGNI_DIR)

# Include AGNI
include(joinpath([AGNI_DIR,"src","AGNI.jl"]))
import .AGNI
import AGNI

# Run
if AGNI.main()
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"keywords": "physics, radiative transfer, exoplanets, astronomy, convection, radiation, planets, atmospheres",
"license": "GPL v3.0",
"title": "AGNI",
"version": "1.1.1"
"version": "1.2.0"
}
4 changes: 2 additions & 2 deletions docs/src/model/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Convection is a turbulent process which occurs across more than one spatial dime

MLT directly calculates the energy flux associated with convective heat transport, and thus is the preferred parameterisation within the model. It assumes that parcels of gas are diffused over a characteristic _mixing length_, transporting energy in the process. This requires choosing a scale for this mixing length, but in practice this has very little impact on the results from the model.

The atmosphere is assumed to be hydrostatically supported. Gas densities are combined using Amagat's additive volume law. The densities of each gas are calculated nominally using the Van der Walls equation of state. AQUA can be used as the EOS for water. The model will fallback to the ideal gas EOS if AQUA and VdW data are not available.
The atmosphere is assumed to be hydrostatically supported. Gas densities are combined using Amagat's additive volume law. The densities of each gas are nominally calculated using the Van der Walls equation of state (EOS). AQUA is implemented as the EOS for water. The Chabrier+2019 EOS is implemented as the EOS for hydrogen. AGNI will fallback to the ideal gas EOS for otherwise unsupported gases.


## Phase change
Expand All @@ -37,7 +37,7 @@ AGNI is designed for modelling planetary atmospheres with high surface pressures
It is necessary to tell AGNI what kind of atmospheric solution to solve for. There are currently a few options available set by the `solution_type` variable in the configuration file.
* (1) Aim to conserve energy fluxes throughout the column. The surface temperature is fixed.
* (2) Aim to conserve energy fluxes throughout the column. The surface temperature is set by energy transport through a solid conductive boundary layer of thickness $d$ such that $T_s = T_m - \frac{Fd}{k}$, where $T_m$ is the mantle temperature and $k$ is the thermal conductivity.
* (3) Solve for a state such that the flux carried at each level is equal to $F_{\text{eff}} = \sigma T_{\text{eff}}^4$, representing the rate at which a planet is losing energy into space.
* (3) Solve for a state such that the flux carried at each level is equal to $F_{\text{net}} = \sigma T_{\text{net}}^4$, representing the rate at which a planet is losing energy into space.

### Construction
The atmosphere is constructed of $N$ levels (cell-centres), corresponding to $N+1$ interfaces (cell-edges). The RT model takes cell-centre temperatures $T_i$, pressures $p_i$, geometric heights, and mixing ratios as input variables at each level $i$. As well as the surface temperature and incoming stellar flux. In return, it provides cell-edges spectral fluxes $F_i$ at all $N+1$ interfaces for LW & SW components and upward & downward streams. Convective fluxes can be estimated using the MLT scheme, condensation fluxes from the condensation scheme, and sensible heat from a simple TKE approximation.
Expand Down
27 changes: 17 additions & 10 deletions docs/src/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,35 @@ Follow the steps below in order to setup the code.
4. Setup SOCRATES by doing either **ONE** of the following...
- Follow the instructions on the [SOCRATES GitHub](https://github.com/nichollsh/SOCRATES) page
- Run `source src/get_socrates.sh`
5. `julia -e 'using Pkg; Pkg.activate("."); Pkg.build()'`
5. `bash src/get_agni.sh`
AGNI is now installed as a package into a Julia environment in the AGNI
directory. This will also have downloaded some basic input data.
You should run the tests next.
directory. This will also have downloaded some basic input data, and have run the tests.

!!! tip
The `src/get_socrates.sh` script automatically adds the radiation code to your
The `get_socrates.sh` script automatically adds the radiation code to your
environment with the variable `RAD_DIR`, which points to the SOCRATES installation.
This variable must be set whenever AGNI is being used.

## Testing
Now try running the tests in your terminal.
If you want to run the tests manually, simply use the script in the `test/` folder...
```bash
julia ./test/runtests.jl
julia test/runtests.jl
```
This will print information on whether tests passed or failed.

## Coupling with FastChem
This can be enabled using the configuration file parameter `composition.chem_type`. Of
course, it is first necessary to setup FastChem, which can be done by running
`source src/get_fastchem.sh` and then setting the `FC_DIR` environment variable.
## Updating
It's important that you keep AGNI up to date, especially if you are using as part of
the [PROTEUS framework](https://github.com/FormingWorlds/PROTEUS). Use this script to
automatically pull changes from GitHub and download any required data files.
```bash
bash src/get_agni.sh
```

## Using the code
See [Running the model](@ref) for information on using the code.
See [Troubleshooting](@ref) for troubleshooting advice.

## Coupling with FastChem
This can be enabled using the configuration file parameter `composition.chem_type`. Of
course, it is first necessary to setup FastChem, which can be done by running
`source src/get_fastchem.sh` and then setting the `FC_DIR` environment variable.
1 change: 1 addition & 0 deletions docs/src/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Check the path in the configuration file. Download additional spectral files usi
```bash
./src/get_data.sh steam
```
Other spectral files can be downloaded from OSF: https://osf.io/vehxg/.

## Cannot find FastChem
You need to install FastChem. This can be done by running the command:
Expand Down
13 changes: 4 additions & 9 deletions misc/L98-59d.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,13 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Import AGNI\n",
"ROOT_DIR = abspath(joinpath(pwd(),\"../\"))\n",
"using AGNI\n",
"import AGNI.atmosphere as atmosphere\n",
"import AGNI.solver as nl\n",
"import AGNI.setpt as setpt\n",
"import AGNI.dump as dump\n",
"import AGNI.plotting as plotting\n",
"\n",
"# Disable logging from AGNI module\n",
"AGNI.setup_logging(\"\",1)"
Expand Down Expand Up @@ -140,7 +135,7 @@
"metadata": {},
"outputs": [],
"source": [
"solver_success = nl.solve_energy!(atmos,\n",
"solver_success = solver.solve_energy!(atmos,\n",
" sol_type=1,\n",
" sens_heat=true,\n",
" latent=true,\n",
Expand Down Expand Up @@ -187,7 +182,7 @@
" atmosphere.generate_pgrid!(atmos)\n",
"\n",
" # Run model\n",
" solver_success = nl.solve_energy!(atmos,\n",
" solver_success = solver.solve_energy!(atmos,\n",
" sol_type=3,\n",
" method=1,\n",
" dx_max=300.0,\n",
Expand All @@ -212,7 +207,7 @@
"source": [
"for (i, atm) in enumerate(atm_arr)\n",
" @printf(\"Writing index %d \\n\",i)\n",
" dump.write_ncdf(atm, joinpath(atm.OUT_DIR, \"$i.nc\"))\n",
" save.write_ncdf(atm, joinpath(atm.OUT_DIR, \"$i.nc\"))\n",
"end\n",
"@printf(\"Done! \\n\")"
]
Expand Down
Loading

0 comments on commit bd57a36

Please sign in to comment.