Skip to main content

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

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

  • numpy
  • torch (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 mypy or pyright

See python/STUB_FILES.md for details.

Continuous Integration

GitHub Actions CI pipeline:

  1. Pre-commit checks (formatting, linting)
  2. Build on Linux and macOS
  3. Run all C++ and Python tests

License

See LICENSE file for details.

Authors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

kintera-2.4.0-cp313-cp313-manylinux_2_27_x86_64.whl (34.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64

kintera-2.4.0-cp313-cp313-macosx_15_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.13macOS 15.0+ ARM64

kintera-2.4.0-cp312-cp312-manylinux_2_27_x86_64.whl (34.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64

kintera-2.4.0-cp312-cp312-macosx_15_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.12macOS 15.0+ ARM64

kintera-2.4.0-cp311-cp311-manylinux_2_27_x86_64.whl (34.6 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64

kintera-2.4.0-cp311-cp311-macosx_15_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

kintera-2.4.0-cp310-cp310-manylinux_2_27_x86_64.whl (34.6 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64

kintera-2.4.0-cp310-cp310-macosx_15_0_arm64.whl (4.0 MB view details)

Uploaded CPython 3.10macOS 15.0+ ARM64

File details

Details for the file kintera-2.4.0-cp313-cp313-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for kintera-2.4.0-cp313-cp313-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 70d2cc0d2405c5f6565314417a2c674e16c236d08033012df4b24454d6771744
MD5 f99258a3f72e10221efac98bb7b5f007
BLAKE2b-256 39275a4d3daf4e46df62c957c2f25958027752c4706ba4430a584ca272b50027

See more details on using hashes here.

File details

Details for the file kintera-2.4.0-cp313-cp313-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for kintera-2.4.0-cp313-cp313-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 6d0c380db769733a43759ab8e1383a529a8c65c203f873eab4fa10b42e12d892
MD5 115beb2ce4cd01f7e047c3001c864bf3
BLAKE2b-256 d2e20320a966804fa855f81215bef20e5f581d906bef9f81f319c52a28f1e726

See more details on using hashes here.

File details

Details for the file kintera-2.4.0-cp312-cp312-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for kintera-2.4.0-cp312-cp312-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 f964540d074aaac16d04b5587f9dc5b8b1fe48d57b3ba66d903ba4a7964a280f
MD5 08f015d3e98f6d00ae3ec023942e4a00
BLAKE2b-256 f1ea80e91b3f362c4c2a2736f364a7d5e3196daa9450a6ec0c903f0dd53cba50

See more details on using hashes here.

File details

Details for the file kintera-2.4.0-cp312-cp312-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for kintera-2.4.0-cp312-cp312-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 b837439ebb0facebe626146cbff49d0f686f21d66c9b2fd5a87202bc9130e61a
MD5 40ead23047955a2f33f6d568d183d9c7
BLAKE2b-256 e2cdd7f5ec547af840d285656deb1b1f30cdce5e60a8549c85aede7c9286b4b0

See more details on using hashes here.

File details

Details for the file kintera-2.4.0-cp311-cp311-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for kintera-2.4.0-cp311-cp311-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 9b722adf95af071072a521ed00ffea959b68295005605fcfd2609f7528245e12
MD5 ba5665096404990959f60288919ffa6c
BLAKE2b-256 b79be56ec58b22e8892210f747a59d203f0fb9dcb2990c9bd4f3769cd733ea9b

See more details on using hashes here.

File details

Details for the file kintera-2.4.0-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for kintera-2.4.0-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 2f40b921b5a1cb430b3e95e2d3d47d8ed29055dcb765a8ab12a065be5c06be83
MD5 3bc70a53a6344278b49014a7e6d85e93
BLAKE2b-256 3018693e500b82bc23166a1bfd29609bf0744207ea001ac3f44af16f8f2a5d1d

See more details on using hashes here.

File details

Details for the file kintera-2.4.0-cp310-cp310-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for kintera-2.4.0-cp310-cp310-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 e023b292a5d3acb29648a282cc4c345c1020facbfbb62ac4ddd7d1f6515eab29
MD5 3f86542bba1e522d544785a2e50f80e8
BLAKE2b-256 c4cb589cee3babc5a873f75fea5c67d65072eae53f4f034fb1c44e3197a8cbf8

See more details on using hashes here.

File details

Details for the file kintera-2.4.0-cp310-cp310-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for kintera-2.4.0-cp310-cp310-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 d94b3874b85da9d8563c6f6223545ef0b1a80e9acf057b4f79a77f1b3fe5e6a2
MD5 59ee544a079bdcef4fed8f3c9f9613b4
BLAKE2b-256 ce015cca5ff61df36f4c1018319baaabfe0ca88ce31d051aae2326ffe94496a6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page