Skip to main content

Compute classical and quantum Euler solutions

Project description

Classical and Quantum Ideal Gases

Exact Riemann solvers for classical and quantum Euler gases, with a fast polylogarithm kernel used to resolve the quantum equation of state.

This repository ports the MATLAB implementation found in this thesis to Python 3.11. The polylog function has been ported from the MATLAB implementation to C++ and the Toro exact Riemann solver has been extended to support Fermi–Dirac (FD), Bose–Einstein (BE), and Maxwell–Boltzmann (MB) statistics.

Requirements

  • Python 3.11+
  • pip (or uv)

Building from source additionally requires a C++17 compiler. See DEVELOPER_GUIDE.md.

Installation

pip install ideal-gases

For plotting (euler plot, interactive explorers):

pip install ideal-gases[plot]

After install, the euler command-line tool is available.

Interactive mode

Launch matplotlib widget explorers to build custom Riemann problems with sliders, statistic toggles (quantum), and Save/Reset controls. Y-axis limits autoscale automatically on each update.

euler interactive classical
euler interactive quantum

Seed the initial state from CLI flags or a JSON config (same fields as euler solve):

euler interactive classical --gamma 1.4 --t-end 0.5 --nx 101
euler interactive quantum --rho-l 2 --t-l 1.5 --n 3 --h 0.5
euler interactive classical --config case.json

Optional domain flags (--x-min, --x-max, --x0, --nx) default to an interactive Sod-tube layout (x in [-10, 10], discontinuity at x0=0, nx=1024). Use -f path.png to set the Save button target; nothing is written until you click Save.

Example usage

euler interactive quantum

Outputs a Sod shock tube problem resolved with a quantum Euler solver for all statistics. We deactivate the solutions of MB and BE to focus on the FD solution. Using the slider, we can vary the left and right states and the thermal scale parameter h and the number of degrees of freedom n of the gas.

In Fig. 5 of Hu and Jing (2010), a fictitious 2-d fermi gas degenerate regime is used to prove the accuracy of Kinetic Flux Vector Splitting schemes for quantum Euler equations. Using the interactive mode, we set n : 2 and set the left and right states ($\rho,u,\theta$). Using the h slider, we found that the degenerate gas is resolved approximately for h $\approx$ 3.71. As show in the following figure:

Sod shock tube

Command-line mode

Compute exact solution profiles, save plots to PNG, and write CSV/JSON files with the solution fields.

Classical Sod shock tube

euler solve classical \
  --rho-l 1 --u-l 0 --p-l 1 \
  --rho-r 0.125 --u-r 0 --p-r 0.1 \
  --t-end 0.25 --gamma 1.4 \
  --nx 101 -o sod.csv

Quantum Euler

euler solve quantum \
  --rho-l 1 --u-l 0 --t-l 1 \
  --rho-r 0.125 --u-r 0 --t-r 0.25 \
  --t-end 0.20 --n 2 --h 0.1 --statistic FD \
  -o euler_fd.csv

Write separate files for FD, MB, and BE with --all-statistics (e.g. euler_case7_FD.csv, euler_case7_MB.csv, euler_case7_BE.csv):

euler solve quantum ... --all-statistics -o euler_case7

Built-in benchmarks

euler toro 1 -o toro_test1.csv
euler list --toro

euler quantum-example 7 --all-statistics -o euler_eg7
euler list --quantum

JSON config files

Define a problem in JSON and run it with euler run or pass --config to euler solve:

euler run --config case.json
euler solve classical --config case.json -o override.csv

Example case.json:

{
  "mode": "quantum",
  "left": {"rho": 1.0, "u": 0.0, "theta": 1.0},
  "right": {"rho": 0.125, "u": 0.0, "theta": 0.25},
  "t_end": 0.20,
  "n": 2.0,
  "h": 0.1,
  "statistic": "FD",
  "all_statistics": true,
  "format": "json",
  "output": "euler_case7",
  "domain": {"x_min": 0.0, "x_max": 1.0, "x0": 0.5, "nx": 101}
}

Use --format json (or a .json output path) for JSON instead of CSV. CLI flags override values from the config file.

Visualization

Save a classical Sod shock tube figure:

euler plot classical \
  --rho-l 1 --u-l 0 --p-l 1 \
  --rho-r 0.125 --u-r 0 --p-r 0.1 \
  --t-end 0.2 --gamma 1.4 --nx 101 \
  -f sod.png

Plot a single quantum statistic or compare FD/MB/BE:

euler plot quantum \
  --rho-l 1 --u-l 0 --t-l 1 \
  --rho-r 0.125 --u-r 0 --t-r 0.25 \
  --t-end 0.20 --n 2 --h 0.1 --statistic FD \
  -f qfd.png

euler plot quantum-example 7 --all-statistics -f eg7

With --all-statistics, -f eg7 writes eg7_panels.png (3×6 grid) and eg7_comparison.png (overlay). Use --layout panels|comparison|both to select one or both (default: both). Add --show for an interactive window, or -o to export CSV/JSON in the same run.

Example usage

In Filbet, Hu and Jing (2010), the authors use a Sod shock tube initial condition with a fictitious 2-d fermi and bose gas to prove the accuracy of their numerical scheme in classical and quantum hydronamic regimes. These are examples 7 and 8, respectively, in the CLI plot tool.

euler plot quantum-example 7 --all-statistics -f sod_2d_gas_classical --layout comparison --show

yields the following plot: Sod shock tube

euler plot quantum-example 8 --all-statistics -f sod_2d_gas_quantum --layout comparison --show

yields the following plot: Sod shock tube

Python module

Import ideal_gases to compute classical and quantum gas solutions in your own scripts.

Classical Sod shock tube

import numpy as np
from ideal_gases import classical_gas

x = np.linspace(0.0, 1.0, 101)
result = classical_gas(
    rho_l=1.0,
    u_l=0.0,
    p_l=1.0,
    rho_r=0.125,
    u_r=0.0,
    p_r=0.1,
    t_end=0.2,
    gamma=1.4,
    x=x,
    x0=0.5,
)

Quantum Euler (FD / BE / MB)

Left and right states are given in terms of density rho, velocity u, and temperature theta (written t in the API). The solver converts these to effective pressures via the quantum EOS, then applies the Toro exact Riemann solver.

import numpy as np
from ideal_gases import quantum_gas

x = np.linspace(0.0, 1.0, 101)
result = quantum_gas(
    rho_l=1.0,
    u_l=0.0,
    t_l=1.0,
    rho_r=0.125,
    u_r=0.0,
    t_r=0.25,
    t_end=0.20,
    n=2.0,          # degrees of freedom; gamma = (n+2)/n
    h=0.1,          # thermal scale parameter
    statistic="FD", # "FD", "BE", or "MB"
    x=x,
    x0=0.5,
)

This returns a RiemannResult object that contains the solution fields: x, rho, ux, p, e, z (fugacity), t (temperature), mach, entropy.

In the classical limit, MB statistics with h → 0 recover the ideal-gas behaviour (pressures p = rho * theta).

Polylogarithm module

The polylogarithm module is used to compute the fermi and bose quantum functions. The current implementation is based on the Bhagat approximation and Sommerfeld's lemma. Providing up to 6 digits of accuracy for the polylogarithm function for half-integer orders. This is a trade-off between accuracy and performance. Nevertheless, it is known that this approximation might fail for z values very close to 1 (Degenerate limit of Bose gases).

NOTE: This is a known issue and the author is working on a more accurate implementation.

We can use the polylogarithm module on our scripts as follows:

import numpy as np
from ideal_gases import polylog

polylog(2, 0.5)                         # scalar
polylog(1.5, np.linspace(0.2, 0.9, 50)) # array

We can plot the polylogarithm function to verify the accuracy of the implementation for integer and half-integer orders as follows:

uv run scripts/plot_polylogarithms.py

yields the following plot: Polylogarithm

Public API

from ideal_gases import (
    RiemannResult,
    adiabatic_index,
    classical_gas,
    quantum_gas,
    polylog,
)
Symbol Role
polylog(n, z) Fast polylogarithm (scalar or NumPy array)
adiabatic_index(n) Returns γ = (n + 2) / n
classical_gas(...) Classical ideal-gas exact Riemann solver
quantum_gas(...) Quantum EOS + Toro exact Riemann solver
RiemannResult Solution profiles on the spatial grid

License

MIT License. See LICENSE for the full text.

Copyright (c) 2026 Manuel A. Diaz

For building from source, tests, linting, CI, and releases, see DEVELOPER_GUIDE.md.

Project details


Download files

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

Source Distribution

ideal_gases-0.1.2.tar.gz (440.9 kB view details)

Uploaded Source

Built Distributions

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

ideal_gases-0.1.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (120.8 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ideal_gases-0.1.2-cp313-cp313-macosx_11_0_arm64.whl (103.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

ideal_gases-0.1.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (120.8 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ideal_gases-0.1.2-cp312-cp312-macosx_11_0_arm64.whl (103.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

ideal_gases-0.1.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl (120.1 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.24+ x86-64manylinux: glibc 2.28+ x86-64

ideal_gases-0.1.2-cp311-cp311-macosx_11_0_arm64.whl (102.4 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

File details

Details for the file ideal_gases-0.1.2.tar.gz.

File metadata

  • Download URL: ideal_gases-0.1.2.tar.gz
  • Upload date:
  • Size: 440.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ideal_gases-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e2a1874c3fc6fe85d518a78b0934aeb87ae938947b394162674b188e1e9a628c
MD5 4368c9b97c028aa285dcca7454525364
BLAKE2b-256 1e2669b0e0481dd7e712a2b638c58f7f2fe0d9b5b57794dc9519d0ce9e54566f

See more details on using hashes here.

Provenance

The following attestation bundles were made for ideal_gases-0.1.2.tar.gz:

Publisher: publish.yml on wme7/ideal-gases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ideal_gases-0.1.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ideal_gases-0.1.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 9033488cec9f178f634a16b350444559e8183101fde2e13f4e47809fe08a875f
MD5 3f6307e844f1b13e1a1eddd81bf4af53
BLAKE2b-256 caa0d750b0e3e23fe1ae88b55a4cff2740997c2d4de3c1230e8a0351d4938c56

See more details on using hashes here.

Provenance

The following attestation bundles were made for ideal_gases-0.1.2-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on wme7/ideal-gases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ideal_gases-0.1.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ideal_gases-0.1.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 355fc1626e31dffd873f70905dbea54a49b536ec73d3975f5fa798b6adc74e37
MD5 95ce2077c965fee9270ea98bd6f62b6c
BLAKE2b-256 ee70fc87c3d516445def0e54ead545c7acc690ad7818cf7c25bb145816c65b63

See more details on using hashes here.

Provenance

The following attestation bundles were made for ideal_gases-0.1.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: publish.yml on wme7/ideal-gases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ideal_gases-0.1.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ideal_gases-0.1.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 af8d015b9b244ce9aae3449830b61d9de3b4479f8489637165f7fd2ade585c51
MD5 d0bb93a44b69ca085ec785f4a4024595
BLAKE2b-256 f436167dcd27e7f24c52562afa7b8ea5c53bc63dee06824a041d46119cce43cb

See more details on using hashes here.

Provenance

The following attestation bundles were made for ideal_gases-0.1.2-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on wme7/ideal-gases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ideal_gases-0.1.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ideal_gases-0.1.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8cd7702daba2593eccce918815010dd7cf6bb3bdc73c96f9920d7002e5915b65
MD5 1a0a7fc9d36a38deb2d21d49e897dbd8
BLAKE2b-256 f94d55ad17cb167f46c89ffcce605bd66c0414fd7370af25323c2005dcbc517a

See more details on using hashes here.

Provenance

The following attestation bundles were made for ideal_gases-0.1.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on wme7/ideal-gases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ideal_gases-0.1.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for ideal_gases-0.1.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 2b600655c6ed64facdf8bebb68943ce6f04331f2c78e73423e67f16855fefda4
MD5 ac598e3a8d566c37664b8a164c1fb83d
BLAKE2b-256 bf561077e4f49f939ca09e2adb80d97c1565cb30fc7ccd2782fb1775de1371c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for ideal_gases-0.1.2-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl:

Publisher: publish.yml on wme7/ideal-gases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ideal_gases-0.1.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for ideal_gases-0.1.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3308b6f6cf6cc5555faa1681198ebab62c11e375aa6ec9ff2cdfb838012c037b
MD5 66431152878a92157a554c929d8afbff
BLAKE2b-256 711bf0a4a5bd7bd08d2ba41eab1e503847aa83b55f88b180f300e53171079112

See more details on using hashes here.

Provenance

The following attestation bundles were made for ideal_gases-0.1.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: publish.yml on wme7/ideal-gases

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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