Metadata-Version: 2.4
Name: crushdem
Version: 0.6.0
Summary: Soft-sphere discrete element method for crushers: Hertz-Mindlin contacts with tangential history, a numba CPU reference and a Warp CUDA path, pip-installable on Windows.
Author: Felipe Santibanez-Leal
License-Expression: MIT
Project-URL: Homepage, https://github.com/fsantibanezleal/CAOS_CrushDEM
Project-URL: Repository, https://github.com/fsantibanezleal/CAOS_CrushDEM
Project-URL: Documentation, https://github.com/fsantibanezleal/CAOS_CrushDEM/tree/main/docs
Project-URL: Issues, https://github.com/fsantibanezleal/CAOS_CrushDEM/issues
Project-URL: Changelog, https://github.com/fsantibanezleal/CAOS_CrushDEM/blob/main/CHANGELOG.md
Keywords: DEM,discrete element method,crusher,comminution,Hertz-Mindlin,mineral processing,Warp,numba
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Physics
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.26
Provides-Extra: jit
Requires-Dist: numba>=0.60; extra == "jit"
Provides-Extra: gpu
Requires-Dist: warp-lang>=1.5; extra == "gpu"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: jsonschema>=4.20; extra == "dev"
Requires-Dist: build>=1.0; extra == "dev"
Requires-Dist: tomli>=2.0; python_version < "3.11" and extra == "dev"
Requires-Dist: numba>=0.60; extra == "dev"
Dynamic: license-file

# crushdem

A soft-sphere discrete element method (DEM) with particle breakage for crushers: Hertz-Mindlin contacts with tangential
history, analytic walls with prescribed motion (a jaw's swing plate, a cone's gyrating mantle), and particle replacement
driven by the Tavares breakage model and the t10 progeny law. It installs with pip on Windows, Linux and macOS, runs on any
CPU (numba) and on NVIDIA GPUs (Warp), and needs no C++ toolchain, WSL or MPI.

## Status

Version 0.06.000 (0.05.000 was the first release on PyPI). The engine is implemented and tested: the soft-sphere core (particle state,
velocity-Verlet integration, the Hertz-Mindlin contact with tangential history, Coulomb sliding and Tsuji damping, rolling
resistance, the uniform hash grid), analytic walls with prescribed motion and their power, feed and discharge with a closing
mass balance, the machines built from them (the laboratory jaw of Barrios et al. 2020 and a parametric cone) and
particle-replacement breakage (the Tavares breakage model with damage, t10 and incomplete-beta progeny, a mass-conserving
replacement with bounded injected energy), on a numba CPU reference and a Warp CUDA path held equal by tests. The requirements
and the validation plan are in [`docs/design/SDD.md`](docs/design/SDD.md).

**Validation: the laboratory jaw is not reproduced.** Against the jaw crusher of Barrios et al. 2020
(https://doi.org/10.3390/min10080717) the throughput band set before the run is not met. The power band is met in the
steady-state window, but the energy per kilogram is a third of the measured one, so that verdict is not a sign that the energy
balance is right. The record states it as it is ([`docs/VALIDATION.md`](docs/VALIDATION.md),
[`validation/results/jaw_barrios2020.json`](validation/results/jaw_barrios2020.json)):

| Quantity, 63/52 mm feed, 6 Hz | Measured | crushdem (record of 0.04.000, model unchanged since) | Error | Band |
|---|---|---|---|---|
| Mean net power, steady-state window | 0.34 kW | 0.301 kW | -11.5 percent | 30 percent: met in the window |
| Mean net power, whole run | 0.34 kW (no window stated) | 0.228 kW | -32.8 percent | reported |
| Throughput | 798.7 kg/h | 2167 kg/h | +171 percent | 10 percent: not met |
| Specific energy (net power over throughput) | 1533 J/kg (derived) | 500 J/kg (window), 526 J/kg (whole run) | -67 and -66 percent | no band: reported |
| Product, median size d50 | 4.5 mm | 11.1 mm | about 2.5 times coarser | no band: reported |

The machine passes the batch about 2.7 times faster than the experiment and delivers about a third of the energy per kilogram;
the window power lands near the paper because the two errors offset. The ore is derived from the paper's single-particle tests
(all 30 particles of each Fig. 6b class, the paper's median); it was changed once, after the first review, from the paper's data
and text, never from the jaw result, and no ore property is tuned. The paper's own calibrated sphere (Fig. 6a) is about six
times stiffer than the Table 3 contact the case uses. The overlap limit was relaxed from 0.3 to 0.5 of the smaller radius on the
paper-ore runs, and 18 of the 29 window strokes exceed 0.3; one seed was run; the 3 and 9 Hz runs and a comparison ore stopped
with the engine's overlap error (a jammed bed or a too-large time step: the record does not show which), and the 3 and 9 Hz
points have no measurement. Seven candidate causes are listed in the record (the contact stiffness, the throw, the swing law and
the nip angle, flat smooth plates, the progeny law, the extrapolated size effect, spheres passing the gap by diameter); none has
been tested and none was tuned to reach a band.
Treat the engine as a research tool whose contact, wall and breakage mechanics are tested and whose agreement with a real
crusher is an open result. The cone case follows when its results are confirmed in an open text.

## Install

```
pip install crushdem            # numpy only: the core, on plain Python (correct, slow)
pip install "crushdem[jit]"     # + numba: the CPU reference path
pip install "crushdem[gpu]"     # + warp-lang: the CUDA path (NVIDIA GPU)
```

Python 3.10 to 3.13; Windows, Linux and macOS; no C++ toolchain, WSL or MPI. The extras are optional: the wheel imports and
runs with numpy alone.

## Minimal example

Two rock spheres collide head-on with a coefficient of restitution of 0.5, and the engine returns the speed they leave with.
It runs in about two seconds with numpy only, no extra needed.

```python
from crushdem import ContactTable, Material, PairParams, ParticleState, Simulation, stable_time_step

rock = Material("rock", youngs_modulus=1.0e8, poisson=0.25, density=2700.0)
table = ContactTable.build([rock], default=PairParams(restitution=0.5, friction=0.0))
state = ParticleState.from_arrays([[0.0, 0.0, 0.0], [0.010001, 0.0, 0.0]], [0.005, 0.005], table,
                                  vel=[[0.5, 0.0, 0.0], [-0.5, 0.0, 0.0]])
sim = Simulation(state, table, dt=stable_time_step(state, table, 0.05), gravity=(0.0, 0.0, 0.0))
sim.run(2000)
after = sim.state()
print(f"rebound ratio {(after.vel[1, 0] - after.vel[0, 0]) / 1.0:.4f} for a restitution of 0.5")
```

It prints `rebound ratio 0.4999 for a restitution of 0.5`. The notebooks in [`notebooks/`](notebooks/README.md) take this
contact apart and build up to the jaw.

### A bed that settles

A column of 2000 spheres falls onto a floor of frozen spheres and settles (with the `jit` extra: on plain Python this takes
hours); the same call runs on the GPU with `backend="warp"` (check `crushdem.available_backends()`).

```python
import crushdem
from crushdem import Simulation, stable_time_step
from crushdem.core.scenarios import settling_column

state, table = settling_column(2000, seed=1, initial_speed=1.0)   # spheres, and their material/contact table
dt = stable_time_step(state, table, fraction=0.1)                 # 0.1 of the Rayleigh time of the smallest sphere
sim = Simulation(state, table, dt=dt, backend="numba", seed=1)
sim.run(1000)
result = sim.result()
print(result["state"]["n_contacts"], "contacts,", f"{result['performance']['particle_steps_per_second']:.2e}", "particle-steps/s")
Simulation.write_result(result, "run.json")                       # validates against schemas/run.schema.json
```

### A jaw crusher

The laboratory jaw of Barrios et al. 2020, fed a batch of one narrow size class (without breakage coarse rock is trapped by
the gap, fine rock passes). Every machine dimension and where it comes from is in `machine.provenance`
([`docs/machines.md`](docs/machines.md)).

```python
import numpy as np
from crushdem import ParticleState, Simulation, stable_time_step
from crushdem.machines import BARRIOS_FEED_CLASSES, barrios_contact_table, jaw_barrios2020

machine, table = jaw_barrios2020(), barrios_contact_table()
feed = machine.feed([BARRIOS_FEED_CLASSES["16/13.2"]], batch_mass=0.05, seed=1)
probe = ParticleState.from_arrays([[0, 0, 0]], [feed.min_radius], table)
empty = ParticleState.from_arrays(np.zeros((0, 3)), np.zeros(0), table)
jaw = Simulation(empty, table, dt=stable_time_step(probe, table, 0.1), feed=feed, capacity=30, seed=1,
                 **machine.simulation_kwargs())
jaw.run_cycles(2, machine.period_s)
swing = next(w for w in jaw.wall_report() if w["name"] == "swing_plate")
print(f"swing plate {swing['mean_power_w']:.1f} W,", jaw.flow()["n_out"], "spheres out")
```

### The same jaw with breakage

Give the run an ore and its spheres break by the Tavares model and are replaced by progeny drawn from the pool of
`capacity` slots, which is the particle cap. The ore parameters of the jaw case, each with its source, are
`jaw_ore_barrios2020()`; the model, its bounds and what the result reports are in [`docs/breakage.md`](docs/breakage.md).

```python
from crushdem.machines import jaw_ore_barrios2020

ore = jaw_ore_barrios2020()
feed = machine.feed([BARRIOS_FEED_CLASSES["31.5/26.5"]], batch_mass=0.15, seed=1)
probe = ParticleState.from_arrays([[0, 0, 0]], [0.5 * ore.min_diameter], table)   # the smallest sphere sets the time step
crusher = Simulation(empty, table, dt=stable_time_step(probe, table, 0.1), feed=feed, capacity=400, ore=ore, seed=1,
                     **machine.simulation_kwargs())
crusher.run_cycles(1, machine.period_s)
b = crusher.breakage_report()
print(b["n_events"], "breakages,", b["n_progeny"], "progeny,", f"{crusher.flow()['fines_kg'] * 1000:.1f} g of fines")
```

### The laboratory jaw case of the paper, from the package

The case of the validation (the paper's constants and measurements, the ore derived from its single-particle tests, the run
control and the verdicts) is the module `crushdem.cases.barrios2020`; the feed class and the closed side setting are
parameters, and `FrameSpec` records the spheres of chosen strokes for a viewer without changing the run.

```python
from crushdem.cases import barrios2020 as case
ore, derivation = case.paper_ore("A", seed=1)   # the ore derived from the paper's Fig. 6b, with its provenance
run = case.run_attempt(ore, 6.0, 6.0, 1, 1500, 0.3, "numba", 400, 4 * 3600.0, 40, feed_class="63/52")  # hours
```

A full batch takes hours (10 to 40 s per stroke of the 63/52 mm feed on the CPU path, about 80 strokes), and what it
returns is the negative result of the section above, not a reproduction of the paper; `case.measured("31.5/26.5")` gives
the measurements the paper offers for a class (and its product curve from Fig. 7a, for each of the three feeds). The command
`python validation/jaw_barrios2020.py` regenerates the committed record from this module.

Your own spheres: `ContactTable.build([Material(...)], default=PairParams(restitution, friction))` and
`ParticleState.from_arrays(positions, radii, table, vel=...)`. The contact law and its sources are in
[`docs/contact.md`](docs/contact.md); measured speeds in [`docs/performance.md`](docs/performance.md); the benchmark is
`python bench/settle.py`; the jaw batch is `python bench/jaw_batch.py`.

## Areas

| Area | Where | State |
|---|---|---|
| Core (state, materials, contact law, scenarios) | `crushdem/core/` | active, tested |
| Neighbour search (hash grid) | `crushdem/neighbours/` | active, tested |
| Walls, their motion laws and power | `crushdem/walls/` | active, tested |
| Feed, discharge, mass balance | `crushdem/flow.py` | active, tested |
| Machines (Barrios jaw, parametric cone) | `crushdem/machines/` | active; the jaw is not reproduced, see Status |
| Breakage (Tavares model, t10 progeny, replacement) | `crushdem/breakage/` | active, tested |
| Backends (numba reference, Warp CUDA) | `crushdem/backends/` | active; the CPU path carries the release |
| Run loop and result | `crushdem/simulation.py`, `schemas/run.schema.json` | active |
| Comparison protocol (band, steady-state window, window statistics and the resolved-verdict rule, product passing sizes) | `crushdem/comparison.py` (`crushdem.comparison`, used by the validation case and the comparison notebook; functions and units in [`docs/design/SDD.md`](docs/design/SDD.md), Validation) | active, tested |
| Notebooks (five, English and Spanish, level 2; the comparison notebook imports `crushdem.comparison`) | [`notebooks/`](notebooks/README.md) | active |
| Cases (the laboratory jaw of Barrios et al. 2020, its measurements, ore and run control, optional particle frames) | `crushdem/cases/` (`crushdem.cases.barrios2020`, data in `crushdem/cases/data/`) | active; a negative result |
| Validation | [`validation/`](validation/) (the command over the case and its record), [`docs/VALIDATION.md`](docs/VALIDATION.md) | the jaw case, a negative result |
| Documentation | [`docs/`](docs/) (contact, machines, breakage, performance, design) | active |
| Tests and benchmarks | `tests/`, `bench/`, `scripts/run_notebooks.py` | `python -m pytest -q` |
| Deploy | `.github/workflows/publish.yml` | PyPI Trusted Publishing from a GitHub release |

Consumed by [CAOS_ChancaDEM](https://github.com/fsantibanezleal/CAOS_ChancaDEM), which bakes its runs offline.

## How to cite

Cite the software by its release and the methods by their sources. Software: Santibanez-Leal, F., crushdem, version 0.6.0,
https://github.com/fsantibanezleal/CAOS_CrushDEM (see [`CITATION.cff`](CITATION.cff)). Methods: the breakage model is
Tavares, L. M. (2022), KONA Powder and Particle Journal 39, 62-83, https://doi.org/10.14356/kona.2022012; the laboratory jaw
and its measurements are Barrios et al. (2020), Minerals 10(8), 717, https://doi.org/10.3390/min10080717; the contact damping
is Tsuji, Tanaka and Ishida (1992), Powder Technology 71, 239-250, https://doi.org/10.1016/0032-5910(92)88030-L.

## Licence

MIT, see [LICENSE](LICENSE).
