Metadata-Version: 2.5
Name: psdm
Version: 0.4.0
Summary: Pore and Surface Diffusion Model (PSDM) for fixed-bed granular activated carbon adsorbers
Project-URL: Documentation, https://psdm.readthedocs.io
Project-URL: Source, https://github.com/zohoMatt/psdm
Project-URL: Issues, https://github.com/zohoMatt/psdm/issues
Project-URL: Changelog, https://github.com/zohoMatt/psdm/blob/main/CHANGELOG.md
Author: Matt Zuo
License-Expression: MIT
License-File: LICENSE
Keywords: AdDesignS,GAC,PSDM,activated carbon,adsorption,water treatment
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering :: Chemistry
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: numpy>=1.23
Requires-Dist: pandas>=1.5
Requires-Dist: scipy>=1.9
Provides-Extra: excel
Requires-Dist: openpyxl>=3.0; extra == 'excel'
Provides-Extra: plot
Requires-Dist: matplotlib>=3.6; extra == 'plot'
Description-Content-Type: text/markdown

# psdm

[![CI](https://github.com/zohoMatt/psdm/actions/workflows/ci.yml/badge.svg)](https://github.com/zohoMatt/psdm/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/psdm.svg)](https://pypi.org/project/psdm/)
[![Docs](https://readthedocs.org/projects/psdm/badge/?version=latest)](https://psdm.readthedocs.io)

The **Pore and Surface Diffusion Model (PSDM)** for fixed-bed granular activated carbon (GAC)
adsorbers, as a small, tested and documented Python package.

- Multi-component competitive adsorption (ideal adsorbed solution theory, Freundlich isotherms)
- Film, pore and surface diffusion with built-in correlations or user-supplied coefficients
- Natural organic matter fouling and the time-dependent tortuosity correlation of AdDesignS
- Time-varying influent, any time / concentration / flow units
- Reader for the US EPA PSDM Excel input template

psdm covers the PSDM of AdDesignS only. The fitting, capacity-estimation, uncertainty and
full-scale/RSSCT design tools of the EPA package have no AdDesignS counterpart and were
removed in 0.4.0.

## Installation

```bash
pip install psdm            # core
pip install "psdm[excel]"   # + Excel input files
pip install "psdm[plot]"    # + plotting
```

## Quick start

```python
import pandas as pd
import psdm

column = psdm.Column.from_units(
    length=(2.765, "m"), diameter=(10, "ft"), mass=(20000, "lb"), flow_rate=(567, "gpm"),
    particle_radius=(0.513, "mm"), particle_density=(0.803, "g/mL"), particle_porosity=0.641,
)
tce = psdm.Compound("TCE", mw=131.39, molar_volume=102.0, k=5026.04, n_inv=0.43)
influent = pd.DataFrame({"TCE": [50.0, 50.0]}, index=[0.0, 174.0])  # days, mg/L

result = psdm.simulate(column, tce, influent, conc_unit="mg/L", water="Rhine")
result.effluent          # DataFrame: effluent concentration vs. time
result([30, 60, 90])     # interpolated at given times
```

Reading the EPA Excel template:

```python
from psdm.io import read_excel

data = read_excel("Example_Multi.xlsx")
result = data.simulate(nr=4, nz=8, ne=2)
```

See the [documentation](https://psdm.readthedocs.io) for the model description, the full API
and more examples.

## Validation

psdm is a rewrite of the original
[US EPA Python PSDM](https://github.com/USEPA/Water_Treatment_Models/tree/3f514c2/PSDM)
(commit `3f514c2`). It solves the same model equations: orthogonal-collocation discretisation,
film, pore and surface diffusion, and the AdDesignS fouling correlations. It integrates them with
the same ODE method, scipy's BDF solver with the same tolerances and Jacobian sparsity pattern, and
reproduces the original's results.

- **Against the original EPA code.** The comparison covers 11 cases: 7 single-compound AdDesignS
  cases (Rhine, Organic Free and Portage water at 5–50 mg/L), 2 multi-component cases from
  `Example_Multi.xlsx` and 2 time-varying influent cases from `Example_TCE.xlsx`. The largest
  difference anywhere on a breakthrough curve is **0.33 % of the influent concentration C0**, and
  the RMS difference is at most 0.06 % of C0.
- **Against AdDesignS.** For the 7 single-compound cases with AdDesignS output, psdm stays within
  0.57 % of C0 of AdDesignS. The original EPA code stays within 0.62 %.
- **Test suite.** The tests check psdm against reference curves generated with the EPA code and
  against the AdDesignS output, with a tolerance of 0.5 % of C0. They include six
  `Example_TCE.xlsx` curves with time-varying influent and measured effluent, four of them at
  the K and 1/n where the EPA fitter `run_all_smart` ends. Both codes integrate these with
  `rtol=1e-6`; the largest difference is 0.06 % of C0.
- **Where psdm follows AdDesignS instead of the EPA code.** The pore diffusion modulus with a
  tortuosity other than 1, the Houghton water coefficient `a4`, and the exact onset of the
  tortuosity correlation; see the [changelog](CHANGELOG.md) for 0.4.0. None of the cases
  above is affected.

The case-by-case comparison, with overlaid breakthrough curves, is in
[`benchmarks/report.html`](benchmarks/report.html) (download it and open it in a browser). It
is generated by [`scripts/benchmark.py`](scripts/benchmark.py).

## Credits

This package is a rewrite of the Python PSDM from the US EPA
[Water Treatment Models](https://github.com/USEPA/Water_Treatment_Models) repository
(J. Burkhardt, L. Haupert, B. Datsov et al.), which converted the Fortran PSDM in AdDesignS™
(D.R. Hokanson, D.W. Hand, J.C. Crittenden, T.N. Rogers, E.J. Oman, Michigan Technological
University) to Python. It is not affiliated with or endorsed by the US EPA or Michigan
Technological University.

## License

MIT — see [LICENSE](LICENSE).
