Skip to main content

A PyTorch Implementation of MLS-MPM (Moving Least Squares Material Point Method)

Project description

A PyTorch Implementation of MLS-MPM (Moving Least Squares Material Point Method)

This repository provides a PyTorch implementation of the MLS-MPM (Moving Least Squares Material Point Method). The algorithm is implemented using a few lines of tensor operations in PyTorch, making it naturally differentiable and optimized for GPU acceleration. The code is vectorized without any explicit loops, which makes it efficient for large-scale simulations.

Gradient Checkpointing is highly recommended when integrating the MLS-MPM into a trainable deep learning framework. See OmniPhysGS (ICLR 2025) for an example.

Installation

From source

git clone https://github.com/wgsxm/MPM-PyTorch.git
cd MPM-PyTorch
pip install .

Quick Start

Run the following code to try a simple example of MLS-MPM simulation. The code simulates a 3D elastic jelly falling onto a rigid floor. By default, the code will produce a video of the simulation in the output directory.

python simulate.py --config examples/jelly.yaml

Usage

Refer to simulate.py for more details.

from mpm_pytorch import MPMSolver, set_boundary_conditions
from mpm_pytorch.constitutive_models import *
particles = ... # Particle positions to simulate
# Create a MPM solver with default parameters
mpm_solver = MPMSolver(particles)
# Set boundary conditions (optional)
boundary_conditions = ... # Refer to example configs
set_boundary_conditions(mpm_solver, boundary_conditions)
# Create constitutive models
elasticity = CorotatedElasticity(E=2e6)
plasicity = IdentityPlasticity()
# Init particle state
x = particles
v = torch.zeros_like(x)
C = torch.zeros((x.shape[0], 3, 3), device=x.device)
F = torch.eye(3, device=x.device).unsqueeze(0).repeat(x.shape[0], 1, 1)
# Start simulation for T steps
for i in range(T):
    # Update stress
    stress = elasticity(F)
    # Particle to grid, grid update, grid to particle
    grid_update = mpm_solver(x, v, C, F, stress)
    # Plasticity correction
    F = plasticity(F)

Fast Batched SVD

Batched SVD is a common operation in constitutive models. Original PyTorch SVD is not optimized for batched computation. We adopt a warp-lang implementation of differentiable batched SVD in mpm_pytorch.constitutive_models.warp_svd from NCLaw. It can run on CPU or GPU with CUDA.

The result of the decomposed matrices is not guaranteed to be the same as the original PyTorch SVD. You can also use the original PyTorch SVD or other batched SVD implementations if there is any environment conflict (the version of warp-lang requires numpy<2).

We provide a script to benchmark the batched SVD implementation.

python benchmark_svd.py

If you encounter error as ModuleNotFoundError: No module named 'imp' when using higher version of Python, simply change the import statement from import imp to import importlib as imp.

Citation

If you find our work helpful, please consider citing:

@inproceedings{
  lin2025omniphysgs,
  title={OmniPhys{GS}: 3D Constitutive Gaussians for General Physics-Based Dynamics Generation},
  author={Yuchen Lin and Chenguo Lin and Jianjin Xu and Yadong MU},
  booktitle={The Thirteenth International Conference on Learning Representations},
  year={2025},
}
@article{hu2018moving,
  title={A moving least squares material point method with displacement discontinuity and two-way rigid body coupling},
  author={Hu, Yuanming and Fang, Yu and Ge, Ziheng and Qu, Ziyin and Zhu, Yixin and Pradhana, Andre and Jiang, Chenfanfu},
  journal={ACM Transactions on Graphics (TOG)},
  year={2018},
}
@article{stomakhin2013material,
  title={A material point method for snow simulation},
  author={Stomakhin, Alexey and Schroeder, Craig and Chai, Lawrence and Teran, Joseph and Selle, Andrew},
  journal={ACM Transactions on Graphics (TOG)},
  year={2013},
}

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

mpm_pytorch-0.1.1.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

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

mpm_pytorch-0.1.1-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file mpm_pytorch-0.1.1.tar.gz.

File metadata

  • Download URL: mpm_pytorch-0.1.1.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mpm_pytorch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fd21047cbc1000ccea446bceeb6c83f3811c2e53314cbb5527328df93705000c
MD5 640c999cff1f90698ba3b820666d129f
BLAKE2b-256 368d321c08510b899e7db5d636354fb7461c28b1fc881f35fb419735b05988e4

See more details on using hashes here.

File details

Details for the file mpm_pytorch-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mpm_pytorch-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for mpm_pytorch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2f62136c0c9ce2b9354e30ea6849ac74389eac6c731266a612749d5fe7bf8010
MD5 cb7de4f64a1075f6f4462c5530b17a11
BLAKE2b-256 8972a7bf52fdfa64181848a03e6b5490d09bdeb4a289a2af6b5f8714f4923f13

See more details on using hashes here.

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