Skip to content

Commit

Permalink
liquid
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanming-hu committed Nov 11, 2018
1 parent be17767 commit 63cb7c6
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tetris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ void advance(real dt) {
real J = determinant(p.F); // Current volume
Mat r, s;
polar_decomp(p.F, r, s); // Polar decomp. for fixed corotated model
auto stress = // Cauchy stress times dt and inv_dx
-4 * inv_dx * inv_dx * dt * vol *
(2 * mu * (p.F - r) * transposed(p.F) + lambda * (J - 1) * J);
Mat cauchy;
if (p.type == 2) {
cauchy = Mat(0.2_f * E * (pow<1>(p.Jp) - 1));
} else {
cauchy = 2 * mu * (p.F - r) * transposed(p.F) + lambda * (J - 1) * J;
}
auto stress = // Cauchy stress times dt and inv_dx
-4 * inv_dx * inv_dx * dt * vol * cauchy;
auto affine = stress + particle_mass * p.C;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) { // Scatter to grid
Expand Down Expand Up @@ -94,6 +99,8 @@ void advance(real dt) {
p.Jp = Jp_new;
}
p.F = F;
} else { // liquid
p.Jp *= determinant(Mat(1) + dt * p.C);
}
}
}
Expand All @@ -108,7 +115,7 @@ int main() {
GUI gui("Real-time 2D MLS-MPM", window_size, window_size);
add_object(Vec(0.55, 0.45), 0xED553B, 0);
add_object(Vec(0.45, 0.65), 0xF2B134, 1);
add_object(Vec(0.55, 0.85), 0x068587, 1);
add_object(Vec(0.55, 0.85), 0x068587, 2);
auto &canvas = gui.get_canvas();
int f = 0;
for (int i = 0;; i++) { // Main Loop
Expand Down

0 comments on commit 63cb7c6

Please sign in to comment.