ThermoFun
ThermoFun: A C++/Python library for computing standard thermodynamic properties of substances and reactions across wide ranges of temperatures and pressures - Published in JOSS (2023)
Science Score: 95.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 4 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org -
✓Committers with academic emails
2 of 9 committers (22.2%) from academic institutions -
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Keywords
Repository
A code for calculating the standard state thermodynamic properties at a given temperature and pressure.
Basic Info
- Host: GitHub
- Owner: thermohub
- License: lgpl-2.1
- Language: C++
- Default Branch: master
- Homepage: https://thermohub.org/thermofun/thermofun/
- Size: 19.2 MB
Statistics
- Stars: 29
- Watchers: 4
- Forks: 9
- Open Issues: 2
- Releases: 35
Topics
Metadata Files
README.md
ThermoFun
Linux, OSX, Windows
A code for calculating the standard state thermodynamic properties of substances and reactions at a given temperature and pressure.
If you use it in your work please cite the JOSS publication
- Code documentation
- Simple C++ API example
- Try ThermoFun
- Python example
- Install using Conda
- Build and install using cmake
- Build and install using cmake and conda
- Reporting bugs
- Contributing
Try ThermoFun in your browser click launch binder
Wait until the Jupyter Lab Notebook server starts (~1 min) then double click on any how-to-... tutorial notebook. Binder is a free service and not using the browser tab for more than a few miuntes will turn off the virutal server. To restart the Jupyter Lab Notebook server click again on the launch binder icon above. Refreshing the webpage will not help restarting the server.
More information on Jupyter Notebooks: Jupyter Documentation
Simple C++ API example
- Using a json database file
```
!c++
int main() { // Create the batch object using a database file in JSON ThermoFun::ThermoBatch batch("Resources/Databases/aq17-thermofun.json");
// Optional: set units, default units are in SI
batch.setPropertiesUnits({"temperature", "pressure"},{"degC","bar"});
// Optional: change default significant digits
batch.setPropertiesDigits({"gibbs_energy","entropy", "volume", "enthalpy", "temperature", "pressure"}, {0, 1, 2, 0, 0, 0});
// Retrieve the entropy of H2O
double H2Oentropy = batch.thermoPropertiesSubstance( 300, 2000, "H2O@", "entropy").toDouble();
// Retrieve the derivative of G with respect to T
double H2OdGdT = batch.thermoPropertiesSubstance( 300, 2000, "H2O", "entropy").toThermoScalar().ddt;
// Write results to a comma separate files for a list of T-P pairs, substances, and properties
batch.thermoPropertiesSubstance({{25, 1},{40, 1},{70, 100},{90, 100},{100, 100}}, // list of T-P pairs
{"Al+3", "OH-", "SiO2@"}, // list of substance symbols
{"gibbs_energy","entropy", "volume", "enthalpy"} // list of properties
).toCSV("results.csv"); // output
return 0;
} ```
- Using the database client and retrieving a ThermoDataSet from the remote database. This example uses the
thermohubclient
```
!c++
int main() { // Initialize a database client object ThermoFun::DatabaseClient dbc;
// Create a ThermoFun database using the records list
ThermoFun::Database db(dbc.getDatabase('aq17'));
// Initialize an batch object using the database
ThermoFun::ThermoBatch batch (db);
// Optional set calculation and output preferences
ThermoFun::OutputSettings op;
op.isFixed = true;
op.outputSolventProperties = true;
op.reactionPropertiesFromReactants = false;
op.substancePropertiesFromReaction = false;
batch.setOutputSettings(op);
// Optional set units and significant digits
batch.setPropertiesUnits({"temperature", "pressure"},{"degC","bar"});
batch.setPropertiesDigits({ "reaction_gibbs_energy","reaction_entropy", "reaction_volume",
"reaction_enthalpy","logKr", "temperature", "pressure"}, {0, 4, 4, 4, 4, 0, 0});
batch.thermoPropertiesReaction({{25,1}}, {"AmSO4+", "MgSiO3@"}, {"reaction_gibbs_energy", "reaction_entropy",
"reaction_volume", "reaction_enthalpy", "logKr"}).toCSV("results.csv");
batch.thermoPropertiesReaction({0,20,50,75},{0,0,0,0},{"AmSO4+", "MgSiO3@"}, {"reaction_gibbs_energy", "reaction_entropy",
"reaction_volume", "reaction_enthalpy", "logKr"}).toCSV("results.csv");
}
```
Simple Python API example
- Using a json database file
```
!Python
import thermofun as fun import thermohubclient as hubclient
properties = fun.ThermoPropertiesSubstance
engine = fun.ThermoEngine("Resources/databases/aq17-thermofun.json")
prop = engine.thermoPropertiesSubstance(373.15, 100000000, "H2O@")
print(prop.gibbsenergy.val) print(prop.gibbsenergy.ddt) print(prop.entropy.val) print(prop.gibbsenergy.ddp) print(prop.gibbsenergy.err) print(prop.gibbs_energy.sta)
Create the engine object using a database file in JSON
batch = fun.ThermoBatch("Resources/databases/aq17-thermofun.json")
Optional: change default units
batch.setPropertiesUnits(["temperature", "pressure"],["degC","bar"])
Optional: change default significant digits
batch.setPropertiesDigits(["gibbs_energy","entropy", "volume", "enthalpy", "temperature", "pressure"], [0, 1, 2, 0, 0, 0])
H2Oentropy = batch.thermoPropertiesSubstance( 300, 2000, "H2O@", "entropy").toDouble() print(H2Oentropy)
V = batch.thermoPropertiesSubstance( 250, 1000, "H2O@", "volume").toThermoScalar()
Write results to a comma separate files for a list of T-P pairs, substances, and properties
batch.thermoPropertiesSubstance( [[25, 1],[40, 1],[70, 100],[90, 100],[100, 100]], # // list of T-P pairs
["Al+3", "OH-", "SiO2@"], # // list of substance symbols
["gibbs_energy","entropy", "volume", "enthalpy"] # // list of properties
).toCSV("results.csv")
```
- Using the database client and retrieving a ThermoDataSet from the remote database. This example uses the
thermohubclient, that can be installed from conda-forge executingconda install -c conda-forge thermohubclient
```
!Python
import thermofun as fun import thermohubclient as hubclient
print("\n# Initialize a database client object\n") dbc = hubclient.DatabaseClient()
print("ThermoDataSets") for t in dbc.availableThermoDataSets(): print(f'{t}') print('\n')
aq17 = fun.Database(dbc.getDatabase('aq17'))
print("\n# Initialize an interface object using the database\n") batch2 = fun.ThermoBatch(aq17)
print("\n# Optional: set the solvent symbol used for calculating properties of aqueous species\n") batch2.setSolventSymbol("H2O@")
print("\n# Optional set calculation and output preferences\n") op = fun.BatchPreferences() op.isFixed = True op.outputSolventProperties = True op.reactionPropertiesFromReactants = False op.substancePropertiesFromReaction = False batch2.setBatchPreferences(op)
print("\n# Optional set units and significant digits\n") batch2.setPropertiesUnits(["temperature", "pressure"],["degC","bar"])
batch2.setPropertiesDigits(["gibbs_energy","entropy", "volume", "enthalpy","logKr", "temperature", "pressure"], [0, 4, 4, 4, 4, 0, 0])
print("\n# Do calculations and write output\n") batch2.thermoPropertiesSubstance([[25,1]], ["NaCO3-", "Mg+2"], ["gibbsenergy", "entropy", "volume", "enthalpy"]).toCSV("resultsdbc.csv") ```
Installation using Conda
ThermoFun can be easily installed using Conda package manager. If you have Conda installed, first add the conda-forge channel by executing
```
!bash
conda config --add channels conda-forge ```
install ThermoFun by executing the following command:
```
!bash
conda install thermofun ```
Conda can be installed from Miniconda.
Install ThermoFun using CMake
- Make sure you have g++, cmake and git installed. If not, install them (on Ubuntu Linux):
```
!bash
sudo apt-get install g++ cmake git ```
Download ThermoFun source code using git clone
In a terminal, at the home directory level e.g.
<user>@ubuntu:~$copy-paste and run the following code:
```
!bash
git clone https://github.com/thermohub/thermofun.git && cd thermofun ```
- In the terminal you should be in
~/thermofun$.
(A) Build and install ThermoFun library (working with json database files)
This option allows the user to build thermofun library that works with a user provided thermodynamic database file in json format and has only one thirdpary library dependency. To build thermofun with access to the thermohub thermodynamic database cloud and local server see bellow.
Install Dependencies (if not using Conda environment)
The thermofun library uses nlohmann/json.hpp as thirdparty dependency to parse database files in json format. To install the header only json library in a terminal ~/thermofun$ execute the following:
```
!bash
sudo ./install-dependencies.sh ```
Compiling the C++ library
In the terminal ~/thermofun$, execute the following commands:
```
!bash
mkdir build && \ cd build && \ cmake .. && \ make ```
To take advantage of parallel compilation use make -j3. 3 representing the number of threads.
For a global installation of the compiled libraries in your system, execute:
```
!bash
sudo make install ```
This will install Thermofun library and header files in the default installation directory of your system (e.g, /usr/local/ or if conda is active, in the instalation directory of the conda environment).
For a local installation, you can specify a directory path for the installed files as follows:
```
!bash
cmake .. -DCMAKEINSTALLPREFIX=/home/username/local/ ``` then execute:
sudo make install
To compile ThermoFun library in debug mode:
```
!bash
cmake .. -DCMAKEBUILDTYPE=Debug ``` then execute:
sudo make install
(B) Build and install ThermoFun library (working with access to the local and cloud ThemroHub database)
This option builds thermofun library together with the dbclient, which provides access to the local and cloud thermohub databases, allowing specific a ThermoDataSet to be used or a selection on elements of the thermodynamic data.
Install ThermoHubClient
Clone and install ThermoHubClient library
```
!bash
git clone https://bitbucket.org/gems4/thermohubclient.git cd thermohubclient sudo ./install-dependencies.sh mkdir build cd build cmake .. make ```
For a global installation of the compiled library in your system, execute:
```
!bash
sudo make install ```
Compile and install ThermoFun using CMake and Conda
This procedure uses Conda for handling all the dependencies of ThermoFun and builds ThermoFun for Windows, Mac OS X, and Linux.
Once you have conda installed execute:
```
!bash
conda install -n base conda-devenv ``` This installs conda-devenv, a conda tool used to define and initialize conda environments.
Download ThermoFun from github
```
!bash
git clone https://github.com/thermohub/thermofun.git && cd thermofun ```
In the next step we create a clean environment with all dependencies necessary to build ThermoFun, executing:
```
!bash
conda devenv ```
In the next step we need to activate the thermofun environment
```
!bash
conda activate thermofun ```
Remember to always activate thermofun environment whenever you use ThermoFun from C++ or Python. This is because conda will adjust some environment variables in your system.
Now we can proceed and build ThermoFun using CMake.
Reporting bugs
To report a bug, please go to ThermoFun's Issues and enter a descriptive title and write your issue with enough details. Please provide a minimum reproducible example to be more efficient in identifying the bug and fixing it.
For questions and issues don't hesitate to chat with us on Gitter.
Contributing with development
The Fork & Pull Request Workflow is used. Below is a summary of the necessary steps you need to take:
- Fork this repository
- Clone the repository at your machine
- Add your changes in a branch named after what's being done (
lower-case-with-hyphens) - Make a pull request to
thermohub/thermofun, targeting themainbranch
Owner
- Name: ThermoHub
- Login: thermohub
- Kind: organization
- Website: https://thermohub.org/
- Repositories: 3
- Profile: https://github.com/thermohub
ThermoEcos is an open-source framework for thermodynamic modeling, integrating experiments, thermodynamic data optimization and prediction.
JOSS Publication
ThermoFun: A C++/Python library for computing standard thermodynamic properties of substances and reactions across wide ranges of temperatures and pressures
Authors
Laboratory for Waste Management LES, Paul Scherrer Institut, 5232 Villigen, Switzerland
Geothermal Energy and Geofluids Group, Institute of Geophysics, ETH Zurich, Switzerland
Cosylab Switzerland GmbH, Badenerstrasse 13, CH–5200 Brugg, Switzerland
Laboratory for Waste Management LES, Paul Scherrer Institut, 5232 Villigen, Switzerland
Tags
Python thermodynamics standard state thermodynamic properties equations of state materialsGitHub Events
Total
- Create event: 6
- Issues event: 1
- Release event: 1
- Watch event: 3
- Delete event: 2
- Issue comment event: 6
- Push event: 23
- Pull request review event: 3
- Pull request event: 15
- Fork event: 1
Last Year
- Create event: 6
- Issues event: 1
- Release event: 1
- Watch event: 3
- Delete event: 2
- Issue comment event: 6
- Push event: 23
- Pull request review event: 3
- Pull request event: 15
- Fork event: 1
Committers
Last synced: 7 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| dmiron | d****n@p****h | 711 |
| svetad | s****d@c****m | 156 |
| dmiron | d****n@p****h | 46 |
| Allan Leal | a****n@g****m | 36 |
| Dmitrii Kulik | d****k@p****h | 24 |
| svetad | s****r@g****m | 4 |
| j-engelmann | j****n@g****e | 1 |
| Robert Collar | 4****o | 1 |
| Alexander Gysi | 7****i | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 19
- Total pull requests: 61
- Average time to close issues: 3 months
- Average time to close pull requests: 6 days
- Total issue authors: 8
- Total pull request authors: 6
- Average comments per issue: 2.05
- Average comments per pull request: 0.26
- Merged pull requests: 58
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 8
- Average time to close issues: N/A
- Average time to close pull requests: 6 days
- Issue authors: 1
- Pull request authors: 3
- Average comments per issue: 3.0
- Average comments per pull request: 0.25
- Merged pull requests: 6
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- yurivict (5)
- hgandhi2411 (5)
- fnattino (3)
- allanleal (2)
- Jarnovr (1)
- defencedog (1)
- gdmiron (1)
- j-engelmann (1)
- eddya7med (1)
Pull Request Authors
- gdmiron (59)
- allanleal (9)
- sdmytrievs (3)
- cardinalgeo (1)
- j-engelmann (1)
- lucydot (1)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/cache v3 composite
- actions/checkout v3 composite
- conda-incubator/setup-miniconda v2 composite
- actions/cache v3 composite
- actions/checkout v3 composite
- conda-incubator/setup-miniconda v2 composite
- actions/cache v3 composite
- actions/checkout v3 composite
- conda-incubator/setup-miniconda v2 composite