Skip to main content

MANTIS: A Monolithic Assembly of Nonlinear Transport Interactions Solver

MANTIS is a high-performance 1D reactive-transport modeling (RTM) framework written in Python, designed to simulate stiff, tightly coupled advection-diffusion-reaction networks.


What is MANTIS?

Reactive-transport systems in natural environments—such as marine sediments, groundwater aquifers, and geochemical reactors—involve simultaneous transport (advection, molecular diffusion, bio-irrigation, and bioturbation) coupled with complex networks of nonlinear chemical, mineral, and biological reactions.

MANTIS provides:

  • Declarative Geochemical Model Definition: Define chemical species, phases, reaction stoichiometries, and kinetic limiters (Monod, inhibition, threshold laws) in intuitive, human-readable Python configuration files.
  • Automated Symbolic Jacobian Generation: Automatically parses reaction networks and compiles analytical chemical Jacobians using symbolic computer algebra (SymPy), eliminating error-prone manual differentiation.
  • Monolithic Block Newton-Raphson Solver: Solves all chemical species and transport equations simultaneously in a coupled block-tridiagonal system using a Numba-accelerated Block Thomas algorithm.
  • Adaptive Time Stepping: Features PID-controlled adaptive time stepping with automatic step rejection and convergence recovery.
  • Unified Declarative Interface: Configure and run simulations through DiageneticModel, complete with automatic CLI argument handling, checkpointing, publication-ready summary plots, and asynchronous time-lapse video generation.

How is MANTIS Different from Other Python RTM Packages?

Most existing Python and geochemical reactive-transport modeling packages rely on operator splitting (such as Sequential Non-Iterative Approach [SNIA] or Sequential Iterative Approach [SIA]) or decoupled Picard (Gauss-Seidel) iterations:

  1. Monolithic Coupling vs. Operator Splitting:

    • Operator splitting alternates between solving pure transport and pure batch chemistry over a time step. While simple, it introduces splitting errors and often requires tiny time steps ($\Delta t$ on the order of seconds or hours) to avoid artificial oscillations or numerical divergence when reactions are fast and stiff.
    • Picard iterations solve each chemical species sequentially, lagging cross-species couplings from the previous iteration. At sharp reaction fronts (e.g., where sulfide meets oxygen or ferric iron), this decoupling frequently causes severe numerical lag oscillations.
    • MANTIS solves the entire system monolithically: Transport and reactions for all species are assembled into a single unified block-tridiagonal linear system at each Newton step. This achieves true simultaneous coupling and quadratic Newton convergence.
  2. Exact Symbolic Jacobians vs. Finite Differences:

    • Rather than approximating derivatives via costly numerical perturbations (finite differences) or requiring users to manually code and maintain hundreds of lines of Jacobian terms, MANTIS computes exact analytical Jacobians symbolically via SymPy ahead of time and compiles them to optimized machine code.
  3. High-Performance Native Numba Engine:

    • The core block-tridiagonal solver and residual evaluations run directly in compiled machine code via Numba. This delivers C-like performance without external heavy PDE framework dependencies.
  4. Unconditional Numerical Stability:

    • Thanks to its fully implicit monolithic formulation, MANTIS does not suffer from Courant-Friedrichs-Lewy (CFL) or diffusion time step stability restrictions, enabling long-term simulations (centuries to millennia) with large time steps.

Scope and General Applicability

While the bundled examples and default templates are geared toward marine sediment early diagenesis (e.g., organic matter mineralization cascades, dissimilatory iron and sulfate reduction, iron sulfide and pyrite precipitation, and stable sulfur isotope fractionation $\delta^{34}\text{S}$), the underlying numerical formulation is domain-agnostic.

The monolithic advection-diffusion-reaction solver can be directly applied to any 1D reactive transport problem involving:

  • Stiff, multi-species nonlinear reaction networks
  • Combined particulate (solid) and solute (porewater/fluid) phases
  • Advection, molecular and eddy diffusion, and nonlocal exchange processes
  • Stable isotope fractionation and multi-isotope tracking

Current Limitations

While MANTIS provides robust and unconditionally stable solutions for stiff reactive transport, the current release has the following limitations:

  1. Time-Invariant Spatial Mesh:
    • The spatial grid $z$ is static throughout the simulation. Dynamic grid adaptation, moving boundaries, or expanding domains (e.g., physical sediment column growth over time) are not currently supported.
  2. Time-Invariant Porosity:
    • The porosity profile $\phi(z)$ is stationary in time (steady-state compaction). Transient sediment compaction or compaction-driven dynamic fluid expulsion over time is not currently modeled.
  3. Time-Invariant Temperature:
    • The temperature profile $T(z)$ is steady-state. Dynamic thermal evolution and time-dependent diffusion coefficients or rate constants driven by non-isothermal thermal transients are not currently supported.

Installation

MANTIS requires Python 3.12 or newer. Clone the repository and install in editable mode:

git clone https://github.com/uliw/mantis.git
cd mantis
pip install -e .

Dependencies include numpy, pandas, matplotlib, numba, sympy, chempy, and watchdog.


Quick Start Example

A typical simulation directory contains declarative configuration files defining species, reactions, rate constants, and plot layouts:

from mantis import DiageneticModel

# 1. Initialize the model (auto-detects species.py, reactions, constants in the directory)
model = DiageneticModel(
    reactions="fes_reactions.py",
    constants="kinetic_constants_slow.py",
    layout="plot_layout.py",
    experiment="marine_diagenesis",
)

# 2. Configure environmental and grid parameters
model.configure(
    max_depth="0.5 m",
    t_end="2 kyr",
    dt_init="1 day",
    dt_max="1 year",
    w="0.2 cm/yr",
    phi=0.8,
    bioturbation={
        "BT0": "4 cm^2/year",
        "depth": "6 cm",
        "attenuation": "2 cm",
    },
)

# 3. Enable CLI flag overrides (--video, --solver-tol, --t-end, etc.)
model.parse_cli_args()

# 4. Run the simulation
result = model.run()

# 5. Export results and summary plots
df, csv_path = result.save_csv()
result.plot_summary()

Running Tests

Run the unit test suite using pytest:

pytest

License

This project is licensed under the GPL-3.0 License. See the LICENSE file for details.

Metadata

Release files for mantis-rtm 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mantis-rtm 0.1.1
File Size Uploaded
mantis_rtm-0.1.1.tar.gz 157.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mantis-rtm 0.1.1
File Interpreter ABI Platform
mantis_rtm-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 258.2 kB

Release files / mantis_rtm-0.1.1.tar.gz

Download URL mantis_rtm-0.1.1.tar.gz
Size 157.5 kB
Tags Source
SHA-256 checksum
How to use checksums
6c819d2cc821f85c5d4443d717b0ab28585e14021e4654de7ff3cf60bee2db09
BLAKE2b-256 checksum
How to use checksums
df333fcabd836893e9415cc80b7a15dcd658f61412f9f3d11dbc351e5412226f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release files / mantis_rtm-0.1.1-py3-none-any.whl

Download URL mantis_rtm-0.1.1-py3-none-any.whl
Size 100.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0826aa604c6153800d0ead7f8cc02e1142a7f47b85e07ac540380150e4ee06df
BLAKE2b-256 checksum
How to use checksums
90a0489a6563576934828e08733c55b75084f18eb768f6b710363640df5fe5f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.2

2 release files

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page