Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
*.tmp
*.pyc
/contrib/perplex/perplex-installer
/contrib/perplex/iron_olivine_lo_res
/contrib/perplex/iron_olivine_lo_res
/contrib/perplex/ASPECT_1D_isentrope_properties.txt
31 changes: 25 additions & 6 deletions contrib/perplex/Readme.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Perple_X P-T Table Generation

This repository contains scripts and resources to download, install, and use **Perple_X** to generate and read a low-resolution thermodynamic table for an iron-olivine system. It can be used as a template to
create and read your own tables.
This repository contains scripts and resources to download, install, and use **Perple_X** to generate and read a low-resolution thermodynamic table for an iron-olivine system. It also contains a script to
create a smoothed 1D adiabatic profile for use in ASPECT (https://github.com/geodynamics/aspect/).

These scripts can be used as a template to create, read and process your own tables.

## Contents

Expand All @@ -12,10 +14,18 @@ create and read your own tables.
A Python script to generate a low-resolution thermodynamic table using Perple_X. This script calls Perple_X programs and configures the run for a simplified system.

- **read_lo_res_table.py**
A Python script to read and parse the generated low-resolution table (e.g., from `table.txt`) for further analysis or plotting.
A Python script to read and parse the generated low-resolution table for further
analysis and plotting.

- **generate_aspect_compatible_1D_adiabat_table.py**
A Python script to generate a smoothed table of properties along a 1D isentrope using
a generated table.

- **perplex_utils.py**
A python file containing useful Perple_X-related functions.
A python file containing useful Perple_X-related functions. The start of the file defines
some database dictionaries for the Holland and Powell (2018),
and Stixrude and Lithgow-Bertelloni (2021, 2024) datasets which can be passed to the other
functions or used as a basis for your own dictionaries.

## Getting Started

Expand All @@ -41,9 +51,18 @@ create and read your own tables.
python read_lo_res_table.py
```

This script parses the output table for further use (e.g., plotting or machine learning workflows).
This script parses the output table for further use (e.g., evaluating properties or plotting).

4. **Create ASPECT compatible Table:**

```bash
python generate_aspect_compatible_1D_adiabat_table.py
```

This script creates an ASPECT-compatible table.

## Notes

- The resolution and thermodynamic scope in this example are intentionally simplified.
- The resolution and thermodynamic scope in this example are intentionally simplified. You will
need to change the scripts if you want to increase the resolution.
- Make sure to review Perple_X license and citation guidelines when using in published work.
115 changes: 59 additions & 56 deletions contrib/perplex/create_lo_res_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,71 @@
from perplex_utils import run_vertex, run_pssect
from perplex_utils import create_perplex_table

project_name = "iron_olivine_lo_res"
database = databases["stx24"]
composition = burnman.Composition(
{"MgO": 1.8, "FeO": 0.2, "SiO2": 1.0, "Fe": 0.1}, "molar"
)
pressure_range = [1.0e5, 10.0e9]
temperature_range = [200.0, 3000.0]
n_pressures = 11
n_temperatures = 11
outfile = "iron_olivine_lo_res_table.dat"
if __name__ == "__main__":
project_name = "iron_olivine_lo_res"
database = databases["stx24"]
composition = burnman.Composition(
{"MgO": 1.8, "FeO": 0.2, "SiO2": 1.0, "Fe": 0.1}, "molar"
)
pressure_range = [1.0e5, 10.0e9]
temperature_range = [200.0, 3000.0]
n_pressures = 11
n_temperatures = 11
outfile = "iron_olivine_lo_res_table.dat"

perplex_dir = os.path.join(os.getcwd(), "perplex-installer/Perple_X")
perplex_bindir = os.path.join(os.getcwd(), "perplex-installer/Perple_X/bin")
perplex_dir = os.path.join(os.getcwd(), "perplex-installer/Perple_X")
perplex_bindir = os.path.join(os.getcwd(), "perplex-installer/Perple_X/bin")

try:
shutil.rmtree(project_name)
print(f"Deleted old project directory ({project_name}).")
except FileNotFoundError:
pass
try:
shutil.rmtree(project_name)
print(f"Deleted old project directory ({project_name}).")
except FileNotFoundError:
pass

os.mkdir(project_name)
os.chdir(project_name)
print(f"Now working in newly created directory ({os.getcwd().split("/")[-1]}).")
os.mkdir(project_name)
os.chdir(project_name)
print(f"Now working in newly created directory ({project_name}).")

print("Creating local copies of requested thermodynamic data files...")
endmember_file = os.path.join(perplex_dir, "datafiles", database["data_file"])
solution_file = os.path.join(perplex_dir, "datafiles", database["solution_model_file"])
shutil.copyfile(endmember_file, os.path.join(os.getcwd(), database["data_file"]))
shutil.copyfile(
solution_file, os.path.join(os.getcwd(), database["solution_model_file"])
)
perplex_option_file = "burnman_perplex_options.dat"
print("Creating local copies of requested thermodynamic data files...")
endmember_file = os.path.join(perplex_dir, "datafiles", database["data_file"])
solution_file = os.path.join(
perplex_dir, "datafiles", database["solution_model_file"]
)
shutil.copyfile(endmember_file, os.path.join(os.getcwd(), database["data_file"]))
shutil.copyfile(
solution_file, os.path.join(os.getcwd(), database["solution_model_file"])
)
perplex_option_file = "burnman_perplex_options.dat"

with open(perplex_option_file, "w") as f:
f.write("sample_on_grid F")
with open(perplex_option_file, "w") as f:
f.write("sample_on_grid F")

print("Making build file...")
make_build_file(
perplex_bindir,
project_name,
database,
perplex_option_file,
composition,
pressure_range,
temperature_range,
verbose=False,
)
print("Making build file...")
make_build_file(
perplex_bindir,
project_name,
database,
perplex_option_file,
composition,
pressure_range,
temperature_range,
verbose=False,
)

print("Running vertex...")
run_vertex(perplex_bindir, project_name, verbose=False)
print("Running vertex...")
run_vertex(perplex_bindir, project_name, verbose=False)

print("Running pssect...")
run_pssect(perplex_bindir, project_name, convert_to_pdf=False, verbose=False)
print("Running pssect...")
run_pssect(perplex_bindir, project_name, convert_to_pdf=False, verbose=False)

print("Creating BurnMan-readable table...")
create_perplex_table(
perplex_bindir,
project_name,
outfile,
n_pressures,
n_temperatures,
pressure_range,
temperature_range,
)
print("Processing complete.")
print("Creating BurnMan-readable table...")
create_perplex_table(
perplex_bindir,
project_name,
outfile,
n_pressures,
n_temperatures,
pressure_range,
temperature_range,
)
print("Processing complete.")
13 changes: 8 additions & 5 deletions contrib/perplex/download_and_install_perplex.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/bin/bash

if [ -d perplex-installer ]; then
rm -rf perplex-installer
cd perplex-installer
git pull --recurse-submodules origin main
cd ..
else
git clone --recurse-submodules https://github.com/bobmyhill/perplex-installer.git
cd perplex-installer
./install_perplex.sh
cd ..
fi
git clone --recursive [email protected]:bobmyhill/perplex-installer.git
cd perplex-installer
./install_perplex.sh
cd ..
Loading