yuanming-hu / taichi_mpm

High-performance moving least squares material point method (MLS-MPM) solver. (ACM Transactions on Graphics, SIGGRAPH 2018)
MIT License
2.38k stars 315 forks source link

Is the 88 LOC Version 2D? #5

Closed Schizo closed 6 years ago

Schizo commented 6 years ago

Just wondering if this implementation is a 2D or 3D implementation?

yuanming-hu commented 6 years ago

It has both 2D and 3D.

Schizo commented 6 years ago

Sorry I actually wanted to refer to the 88 LOC version.

yuanming-hu commented 6 years ago

That one is 2D :-)

Schizo commented 6 years ago

Just out of curiosity, would it need a lot of modification's for 3D or would it be small adjustments? Just trying to figure out if I should give it a try with numpy for a weekend project.

yuanming-hu commented 6 years ago

The modification will be very small, but you probably need a good way to visualize the particles

yuanming-hu commented 6 years ago

Let me know if you run into any troubles.

Schizo commented 6 years ago

Thanks, I would visualize it in Houdini, which ships with numpy.

Schizo commented 6 years ago

I'm getting negative values for the sqrt operation, are we expecting negative values to appearin fx?

Vec w[3]{Vec(0.5) * sqr(Vec(1.5) - fx), Vec(0.75) - sqr(fx - Vec(1.0)),
             Vec(0.5) * sqr(fx - Vec(0.5))};

My values for fx on the first frame in numpy:

[ 0.92728481 -4.5629436 ]
[ 3.35277425  4.02428301]
[-3.37517478 -1.65776099]
[ 1.59791531  1.60818924]
[ 1.02547799 -4.36063837]

produced using:

numOfParticles = 5
arr.pos = [[(np.random.random_sample() * 2.0-1) * 0.08 + x, (np.random.random_sample() * 2.0-1) * 0.08 + y] for i in range(0, numOfParticles)]
yuanming-hu commented 6 years ago

Hi, sqr(x) here means x*x.

Schizo commented 6 years ago

Oh ok, completely missed that it's the square. Thanks a lot.

Schizo commented 6 years ago

How does np.linalg.svd align with taichis svd function?

The returned sig in svd_u, sig, svd_v = np.linalg.svd(p['F']) is a( 1x1) matrix.

yuanming-hu commented 6 years ago

Not sure about numpy. In taichi, svd(M, U, sig, V) gives M=U sig V^T UU^T=I VV^T=I sig=diag(sig)

Schizo commented 6 years ago

Ok, that should be the same, and sig is as well the diag, could you verify that the following assumptions are correct, especially in terms of shape?

#Input
F = [[0, 1], [2,3]]
svd(F, svd_u, sig, svd_v)

#Output
svd_u = [[-0.22975292 -0.97324899]
 [-0.97324899  0.22975292]]

sig = [ 3.70245917  0.54018151]

svd_v = [[-0.52573111 -0.85065081]
 [ 0.85065081 -0.52573111]]

Are those the expected shapes of the matrices?

yuanming-hu commented 6 years ago
  1. Sig is a diagonal matrix instead of a vector
  2. You seem to be computing F = U^T sig V, instead of F=U sig V^T... see below
    import numpy as np
    U = np.array([[-0.22975292, -0.97324899], [-0.97324899 , 0.22975292]])
    sig = np.array([[3.70245917, 0], [0,  0.54018151]])
    V = [[-0.52573111, -0.85065081], [ 0.85065081, -0.52573111]]
    print(np.dot(np.dot(np.transpose(U), sig), V))
[[ -1.54186712e-09   9.99999996e-01]
 [  1.99999999e+00   3.00000001e+00]]
yuanming-hu commented 5 years ago

Hi Schizo,

There seem to be a few other people trying to implement mls-mpm88 with numpy. Do you mind sharing your numpy code to help them? You can create a github repo and I will link to it.

Thanks, Yuanming