Skip to content

Commit 8bb0bb3

Browse files
authored
Merge pull request #23 from chahak13/docs
Add type annotations, docstrings and documentation
2 parents d993273 + 5021c3b commit 8bb0bb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+10630
-426
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
# DiffMPM
1+
# Differentiable Material Point Method (DiffMPM)
2+
3+
MPM simulations are applied in various fields such as computer graphics, geotechnical engineering, computational mechanics and more. `diffmpm` is a differentiable MPM simulation library written entirely in JAX which means it also has all the niceties that come with JAX. It is a highly parallel, Just-In-Time compiled code that can run on CPUs, GPUs or TPUs. It aims to be a fast solver that can be used in various problems like optimization and inverse problems. Having a differentiable MPM simulation opens up several advantages -
4+
- **Efficient Gradient-based Optimization:** Since the entire simulation model is differentiable, it can be used in conjunction with various gradient-based optimization techniques such as stochastic gradient descent (SGD), ADAM etc.
5+
- **Inverse Problems:** It also enables us to solve inverse problems to determine material properties by formulating an inverse problem as an optimization task.
6+
- **Integration with Deep Learning:** It can be seamlessly integrated with other Neural Network models to enable training physics-informed neural networks.
7+
8+
## Installation
9+
`diffmpm` can be installed directly from PyPI using `pip`
10+
11+
``` shell
12+
pip install diffmpm
13+
```
14+
15+
#### ToDo
16+
Add separate installation commands for CPU/GPU.
17+
18+
## Usage
19+
Once installed, `diffmpm` can be used as a CLI tool or can be imported as a library in Python. Example input files can be found in the `benchmarks/` directory.
20+
21+
```
22+
Usage: mpm [OPTIONS]
23+
24+
CLI utility for DiffMPM.
25+
26+
Options:
27+
-f, --file TEXT Input TOML file [required]
28+
--version Show the version and exit.
29+
--help Show this message and exit.
30+
```
31+
32+
Further documentation about the input file can be found in the documentation _[INSERT LINK HERE]_. `diffmpm` can write the output to various file types like `.npz`, `.vtk` etc. that can then be used to visualize the output of the simulations.
33+
34+
## Examples

benchmarks/2d/uniaxial_nodal_forces/test_benchmark.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
from pathlib import Path
3+
34
import jax.numpy as jnp
5+
46
from diffmpm import MPM
57

68

benchmarks/2d/uniaxial_particle_traction/test_benchmark.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
from pathlib import Path
3+
34
import jax.numpy as jnp
5+
46
from diffmpm import MPM
57

68

benchmarks/2d/uniaxial_stress/test_benchmark.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
from pathlib import Path
3+
34
import jax.numpy as jnp
5+
46
from diffmpm import MPM
57

68

diffmpm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(self, filepath):
4040
raise ValueError("Wrong type of solver specified.")
4141

4242
def solve(self):
43-
"""Solve the MPM simulation."""
43+
"""Solve the MPM simulation using JIT solver."""
4444
arrays = self.solver.solve_jit(
4545
self._config.parsed_config["external_loading"]["gravity"],
4646
)

diffmpm/cli/mpm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
from diffmpm import MPM
44

55

6-
@click.command()
6+
@click.command() # type: ignore
77
@click.option(
88
"-f", "--file", "filepath", required=True, type=str, help="Input TOML file"
99
)
1010
@click.version_option(package_name="diffmpm")
1111
def mpm(filepath):
12+
"""CLI utility for DiffMPM."""
1213
solver = MPM(filepath)
1314
solver.solve()

diffmpm/constraint.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,18 @@
33

44
@register_pytree_node_class
55
class Constraint:
6-
def __init__(self, dir, velocity):
6+
"""Generic velocity constraints to apply on nodes or particles."""
7+
8+
def __init__(self, dir: int, velocity: float):
9+
"""Contains 2 govering parameters.
10+
11+
Attributes
12+
----------
13+
dir : int
14+
Direction in which constraint is applied.
15+
velocity : float
16+
Constrained velocity to be applied.
17+
"""
718
self.dir = dir
819
self.velocity = velocity
920

@@ -16,16 +27,15 @@ def tree_unflatten(cls, aux_data, children):
1627
return cls(*aux_data)
1728

1829
def apply(self, obj, ids):
19-
"""
20-
Apply constraint values to the passed object.
30+
"""Apply constraint values to the passed object.
2131
22-
Arguments
23-
---------
32+
Parameters
33+
----------
2434
obj : diffmpm.node.Nodes, diffmpm.particle.Particles
2535
Object on which the constraint is applied
2636
ids : array_like
2737
The indices of the container `obj` on which the constraint
28-
will be applied.
38+
will be applied.
2939
"""
3040
obj.velocity = obj.velocity.at[ids, :, self.dir].set(self.velocity)
3141
obj.momentum = obj.momentum.at[ids, :, self.dir].set(

0 commit comments

Comments
 (0)