Atmospheric Chemistry and Thermodynamics Library
Project description
Kintera: Atmospheric Chemistry and Thermodynamics Library
KINTERA is a library for atmospheric chemistry and equation of state calculations, combining C++ performance with Python accessibility through pybind11 bindings.
Table of Contents
- Overview
- Features
- Prerequisites
- Installation
- Photochemistry Module
- Testing
- Documentation
- Development
- License
Overview
KINTERA provides efficient implementations of:
- Chemical kinetics calculations (Arrhenius, coagulation, evaporation)
- Photochemistry and photolysis reactions
- Thermodynamic equation of state
- Phase equilibrium computations
- Atmospheric chemistry models
The library is written in C++17 with Python bindings, leveraging PyTorch for tensor operations and providing GPU acceleration support via CUDA.
Features
- High Performance: C++17 core with optional CUDA support
- Python Interface: Full Python API via pybind11
- PyTorch Integration: Native tensor operations using PyTorch
- Chemical Kinetics: Comprehensive reaction mechanism support
- Photochemistry: Wavelength-dependent photolysis with multi-branch products
- Thermodynamics: Advanced equation of state calculations
- Cloud Physics: Nucleation and condensation modeling
Prerequisites
System Requirements
- C++ Compiler: Support for C++17 (GCC 9+, Clang 5+, or MSVC 2017+)
- CMake: Version 3.18 or higher
- Python: Version 3.10 or higher
- NetCDF: NetCDF C library
Python Dependencies
numpytorch(version 2.10.0)pyharp(version 2.2.0+pytest(for testing)
Platform-Specific Setup
Linux (Ubuntu/Debian)
sudo apt-get update
sudo apt-get install -y build-essential cmake libnetcdf-dev
macOS
brew update
brew install cmake netcdf
Installation
Quick Start
# 1. Install Python dependencies
pip install numpy 'torch==2.10.0' 'pyharp>=2.2.0'
# 2. Clone the repository
git clone https://github.com/chengcli/kintera.git
cd kintera
# 3. Configure and build the C++ library
cmake -B build
cmake --build build --parallel
# 4. Install the Python toolkit
pip install .
Photochemistry Module
KINTERA includes a complete photochemistry module for modeling photolysis reactions in planetary atmospheres.
Architecture
src/photolysis/
├── photolysis.hpp # PhotolysisOptions and PhotolysisImpl definitions
├── photolysis.cpp # Implementation with YAML parsing and rate computation
├── actinic_flux.hpp # Actinic flux helper functions
├── load_xsection_kin7.cpp # KINETICS7 cross-section loader
├── load_xsection_yaml.cpp # YAML cross-section loader
├── jacobian_photolysis.hpp # Photolysis Jacobian declarations
└── jacobian_photolysis.cpp # Species-space Jacobian helper implementation
Key Components
| Component | Description |
|---|---|
PhotolysisOptions |
Configuration: wavelength grid, cross-sections, branches |
Photolysis |
PyTorch module computing rates via wavelength integration |
actinic_flux.hpp helpers |
Flux construction and wavelength interpolation helpers |
jacobian_photolysis_species() |
Species-space Jacobian helper for implicit solvers |
Thermochemistry Data
NASA-9 polynomial data is stored with SpeciesThermoImpl as structured
per-species coefficient tables and converted to tensors on demand when
reversible kinetics needs equilibrium constants. KineticsImpl no longer owns
separate cached NASA-9 buffers.
Kinetics Species Layout
KineticsOptions.from_yaml(...) registers kinetics species using reaction-active
vapors plus cloud species, rather than every species listed in the YAML file.
In practice this means inert dry carrier species are not included in the
concentration tensor passed to Kinetics.forward(...) or
Kinetics.forward_nogil(...) unless they also participate in the reaction
mechanism. Callers that derive kinetics concentrations from a larger thermo
state should narrow or reorder species explicitly to the kinetics species list.
Rate Calculation
Photolysis rates are computed by integrating cross-sections weighted by actinic flux:
k = ∫ σ(λ,T) · F(λ) dλ
where σ is the cross-section [cm² molecule⁻¹], F is the actinic flux [photons cm⁻² s⁻¹ nm⁻¹], and λ is wavelength [nm].
YAML Configuration
Photolysis reactions are defined in YAML format:
reactions:
- equation: CH4 => CH3 + H + (1)CH2 + H2
type: photolysis
branches:
- "CH4:1" # photoabsorption
- "CH3:1 H:1" # CH3 + H branch
- "(1)CH2:1 H2:1" # singlet CH2 + H2 branch
cross-section:
- format: KINETICS7
filename: "CH4.dat2"
# Or inline YAML format:
- format: YAML
temperature: 300.
data:
- [100., 1.e-18, 0.5e-18]
- [150., 2.e-18, 1.0e-18]
C++ Usage
#include <kintera/photolysis/photolysis.hpp>
#include <kintera/photolysis/actinic_flux.hpp>
// Create options
auto opts = PhotolysisOptionsImpl::create();
opts->wavelength() = {100., 150., 200.};
opts->reactions().push_back(Reaction("N2 => N2"));
opts->cross_section() = {1.e-18, 2.e-18, 1.e-18};
// Create module and move to GPU
Photolysis module(opts);
module->to(torch::kCUDA, torch::kFloat64);
auto temp = torch::tensor({300.0}, module->wavelength.options());
// Create actinic flux on the module wavelength grid
auto flux = create_solar_flux(module->wavelength, 1.e14);
// Refresh the temperature-dependent cache before forward()
module->update_xs_diss_stacked(temp);
auto rate = module->forward(temp, flux);
Python Usage
from kintera import (
PhotolysisOptions, Photolysis, Reaction,
create_solar_flux, set_species_names
)
import torch
# Initialize species list
set_species_names(["N2", "O2", "CH4"])
# Configure photolysis
opts = PhotolysisOptions()
opts.wavelength([100., 150., 200.])
opts.reactions([Reaction("N2 => N2")])
opts.cross_section([1e-18, 2e-18, 1e-18])
# Create module
module = Photolysis(opts)
temp = torch.tensor([300.0], dtype=module.wavelength.dtype,
device=module.wavelength.device)
# Create flux on the module wavelength grid and compute rates
flux = create_solar_flux(module.wavelength, 1e14)
module.update_xs_diss_stacked(temp)
rate = module.forward(temp, flux)
Cross-Section File Formats
The module supports multiple cross-section formats:
| Format | Description |
|---|---|
YAML |
Inline wavelength/cross-section data |
KINETICS7 |
NCAR KINETICS7 format files |
VULCAN |
VULCAN photochemistry format |
Testing
KINTERA includes comprehensive C++ and Python tests.
Running All Tests
ctest --test-dir build/tests --output-on-failure
Photochemistry Tests
Run photochemistry-specific tests:
# Focused C++ tests
./build/tests/test_photolysis_options.release
./build/tests/test_ch4_photolysis.release
# Python tests
pytest tests/test_photolysis.py -v
Device Coverage
Parameterized C++ tests are generated for CPU and CUDA builds. MPS test instantiations have been removed from the default test matrix.
Test Coverage
| Test File | Coverage |
|---|---|
test_photolysis_options.cpp |
YAML parsing, cross-section loading |
test_photolysis_kinetics.cpp |
Kinetics integration, stoichiometry |
test_actinic_flux.cpp |
Flux interpolation, tensor shapes |
test_ch4_photolysis.cpp |
End-to-end CH4 photolysis, Jacobian |
test_photolysis.py |
Python bindings integration |
Documentation
Full documentation is available at: https://kintera.readthedocs.io
To build documentation locally:
cd docs
pip install -r requirements.txt
make html
Dependency Cache
A successful build saves cache files in .cache/. To force a clean rebuild:
rm -rf .cache build
Development
Project Structure
kintera/
├── src/
│ ├── kinetics/ # Kinetics modules (Arrhenius, falloff, three-body, etc.)
│ ├── photolysis/ # Photolysis, actinic flux, and Jacobian helpers
│ ├── diffusion/ # Diffusion operators
│ ├── units/ # Unit conversion helpers
│ ├── thermo/ # Thermodynamics
│ └── math/ # Interpolation utilities
├── python/
│ ├── csrc/ # pybind11 bindings
│ ├── kintera.pyi # Type stubs
│ └── py.typed # PEP 561 marker
├── tests/ # C++ and Python tests
├── examples/ # Usage examples
└── data/ # Test data (cross-sections, YAML configs)
Code Style
pip install pre-commit
pre-commit install
pre-commit run --all-files
Type Hints
KINTERA provides full type hint support through Python stub files:
- IDE autocomplete in VS Code, PyCharm
- Type checking with
mypyorpyright
See python/STUB_FILES.md for details.
Continuous Integration
GitHub Actions CI pipeline:
- Pre-commit checks (formatting, linting)
- Build on Linux and macOS
- Run all C++ and Python tests
License
See LICENSE file for details.
Authors
- Cheng Li - chengcli@umich.edu
- Sihe Chen
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kintera-2.3.3-cp313-cp313-manylinux_2_27_x86_64.whl.
File metadata
- Download URL: kintera-2.3.3-cp313-cp313-manylinux_2_27_x86_64.whl
- Upload date:
- Size: 31.8 MB
- Tags: CPython 3.13, manylinux: glibc 2.27+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6876798f90f41e4f9e07d6d9e899abe7a3b093c8be0ea3db19c3d2793812c080
|
|
| MD5 |
8376491dc5663e0beb529c3c1e55fe0d
|
|
| BLAKE2b-256 |
aa373f0e3bdfa091868c255f27b71fb1c1d2a570ffb5d5ff86a7f933c2d55240
|
File details
Details for the file kintera-2.3.3-cp313-cp313-macosx_15_0_arm64.whl.
File metadata
- Download URL: kintera-2.3.3-cp313-cp313-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.13, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27f6378ef19eaf58c6b94018e995962997e542c0a9d96ff261bf21276b2628e3
|
|
| MD5 |
c00eb06d1a16a7891006b32cbc864eff
|
|
| BLAKE2b-256 |
35de648d93efb125b75414a1bb63db9ae2e7712460254e798b45b7a8c927cd70
|
File details
Details for the file kintera-2.3.3-cp312-cp312-manylinux_2_27_x86_64.whl.
File metadata
- Download URL: kintera-2.3.3-cp312-cp312-manylinux_2_27_x86_64.whl
- Upload date:
- Size: 31.8 MB
- Tags: CPython 3.12, manylinux: glibc 2.27+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a78e55171faf69e2132f855bfbd38efe5c63d2652acfc352b58342f1e576204
|
|
| MD5 |
eddef52b98905c3b8e2137f5d6b096d1
|
|
| BLAKE2b-256 |
ba78984fac774fa4aadfe4b59bea963ec00a24de8901de99155dd5885bb4f250
|
File details
Details for the file kintera-2.3.3-cp312-cp312-macosx_15_0_arm64.whl.
File metadata
- Download URL: kintera-2.3.3-cp312-cp312-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.12, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bd78bbbe9227ffbc934c37fbc68da9cbf119d50fa2e725bb08c0c3e569df0fae
|
|
| MD5 |
f70165de54c12d15137f11693724fd8b
|
|
| BLAKE2b-256 |
e72b5ebd29dad820d5668bba0138ea47a135f417a8eb1c6404d0ee3d1f4a2948
|
File details
Details for the file kintera-2.3.3-cp311-cp311-manylinux_2_27_x86_64.whl.
File metadata
- Download URL: kintera-2.3.3-cp311-cp311-manylinux_2_27_x86_64.whl
- Upload date:
- Size: 31.7 MB
- Tags: CPython 3.11, manylinux: glibc 2.27+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a74207ec1114a1b37e275d5acc416218c6bc9f8696ca05ddb02f9fc32f376612
|
|
| MD5 |
e18d5637e069243160ea7f1ed2c7e52e
|
|
| BLAKE2b-256 |
1795c33647edf7f8cc4808afca5ce1b59c712ae920cf61ba3c1f959b1a0d6252
|
File details
Details for the file kintera-2.3.3-cp311-cp311-macosx_15_0_arm64.whl.
File metadata
- Download URL: kintera-2.3.3-cp311-cp311-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.11, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1699b15fb950d30c1ef7c08d96e9d33f99ac1eb890151af454887982bd3ed2f0
|
|
| MD5 |
73f4ca7530acdc13ac3437c53b9330f2
|
|
| BLAKE2b-256 |
6910dd47b237b9ed21c0b98cc9ed18e90b95216273e55100a6a26925e826966f
|
File details
Details for the file kintera-2.3.3-cp310-cp310-manylinux_2_27_x86_64.whl.
File metadata
- Download URL: kintera-2.3.3-cp310-cp310-manylinux_2_27_x86_64.whl
- Upload date:
- Size: 31.6 MB
- Tags: CPython 3.10, manylinux: glibc 2.27+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2967ca564b48130763e4562f16cabc664aca30d0714c78418202a57bec4531e
|
|
| MD5 |
4f739bf3736c70a3f671b37c9b9b959b
|
|
| BLAKE2b-256 |
39e21d7a7b3352dcd25732b1efc6092832d41f5eaf59ed040b85207a1109cc2a
|
File details
Details for the file kintera-2.3.3-cp310-cp310-macosx_15_0_arm64.whl.
File metadata
- Download URL: kintera-2.3.3-cp310-cp310-macosx_15_0_arm64.whl
- Upload date:
- Size: 3.8 MB
- Tags: CPython 3.10, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9b560f6cd6075858099cc112cae211b6face0eb68e3188da764fd99efe0fb7f
|
|
| MD5 |
12582a39526b5f20a6447a8d97fadf12
|
|
| BLAKE2b-256 |
daca766b4d4f9baf2831a0ae779cecc7750fba8436e15e7cb065d7bdad0101ca
|