Metadata-Version: 2.4
Name: dismech-newton
Version: 0.1.0
Summary: Discrete Elastic Rods for NVIDIA Newton.
Keywords: discrete elastic rods,rods,simulation,physics,robotics,newton,warp,gpu
Author: ryanchaiyakul
Author-email: ryanchaiyakul <ryanchaiyakul@gmail.com>
License-Expression: GPL-3.0-or-later
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Environment :: GPU :: NVIDIA CUDA
Classifier: Topic :: Scientific/Engineering :: Physics
Requires-Dist: newton~=1.6.0
Requires-Dist: scipy>=1.14
Requires-Dist: cupy-cuda13x>=14.2.0 ; extra == 'gpu'
Requires-Dist: nvmath-python[cu13]>=1.0 ; extra == 'gpu'
Requires-Dist: imgui-bundle>=1.92.900 ; extra == 'viewer'
Requires-Dist: pyglet>=2.1.6,<3 ; extra == 'viewer'
Requires-Dist: pyopengl>=3.1 ; extra == 'viewer'
Requires-Dist: pillow>=10 ; extra == 'viewer'
Requires-Python: >=3.10
Project-URL: Homepage, https://github.com/ryanchaiyakul/dismech-newton
Project-URL: Issues, https://github.com/ryanchaiyakul/dismech-newton/issues
Provides-Extra: gpu
Provides-Extra: viewer
Description-Content-Type: text/markdown

# DiSMech-Newton

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://opensource.org/license/gpl-3.0)
![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue)
![CUDA 13](https://img.shields.io/badge/CUDA-13-76B900)

Discrete elastic rods for [NVIDIA Newton](https://github.com/newton-physics/newton).

- **`ADMMDiSMechSolver`**: implicit DER solved with ADMM, inspired by
  [Daviet (2023)](https://research.nvidia.com/labs/prl/admm_hair/), with rod-rod, rod-shape and
  rod-ground contact and Coulomb friction.
- **`DiSMechSolver`**: implicit DER solved with Newton-Raphson.

## Examples

<table>
  <tr>
    <th>Plectoneme</th>
    <th>Overhand knot</th>
  </tr>
  <tr>
    <td><img src="docs/admm_plectoneme.webp" alt="Plectoneme" width="100%"></td>
    <td><img src="docs/admm_knot.webp" alt="Overhand knot" width="100%"></td>
  </tr>
  <tr>
    <td>A cable between two clamps is counter-twisted until it buckles into a plectoneme, held open by self-contact.<br>
    <code>uv run examples/cable_plectoneme.py</code><br>
    <td>A loose overhand knot is pulled tight with friction, matching <a href="https://doi.org/10.1103/PhysRevLett.99.164301">Audoly et al. (2007)</a> and <a href="https://doi.org/10.1103/PhysRevLett.115.118302">Jawed et al. (2015)</a>.<br>
    <code>uv run examples/overhand_knot.py</code><br>
  </tr>
  <tr>
    <th>Flagella bundling</th>
    <th>Cantilever</th>
  </tr>
  <tr>
    <td><img src="docs/admm_flagella.webp" alt="Flagella bundling" width="100%"></td>
    <td><img src="docs/admm_cantilever.webp" alt="Cantilever" width="100%"></td>
  </tr>
  <tr>
    <td>Ten helical flagella spin in a viscous fluid and bundle, after <a href="https://arxiv.org/abs/2205.10309">Tong et al. (2022)</a>.<br>
    <code>uv run examples/flagella.py --flagella 10</code><br>
    <td>A clamped rod sags under gravity, next to Newton's VBD cable and the Euler-Bernoulli curve.<br>
    <code>uv run examples/cantilever.py</code><br>
  </tr>
  <tr>
    <th colspan="2">Gradient Optimization</th>
  </tr>
  <tr>
    <td colspan="2"><img src="docs/fit_stiffness.webp" alt="Fitting stiffness and damping by gradient" width="100%"></td>
  </tr>
  <tr>
    <td colspan="2">L-BFGS fits a cantilever's bending stiffness and damping to an observed motion, with gradients through the solver. Each iteration (green) beside the truth (grey), with its path on the loss landscape.<br>
    <code>uv run examples/fit_stiffness.py</code><br>
  </tr>
</table>

## Install

Requires an NVIDIA GPU with CUDA 13, Python 3.10+ and [uv](https://docs.astral.sh/uv/).

```bash
git clone https://github.com/ryanchaiyakul/dismech-newton.git
cd dismech-newton
uv sync --extra gpu --extra viewer
uv run examples/cantilever.py
```
