Skip to content

Commit 4c250c6

Browse files
committed
optimization for inv_free
1 parent 7fbe672 commit 4c250c6

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

4_friction/simulator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
# simulation setup
1111
side_len = 1
1212
rho = 1000 # density of square
13-
k = 2e4 # spring stiffness
14-
n_seg = 4 # num of segments per side of the square
13+
k = 4e4 # spring stiffness
14+
n_seg = 10 # num of segments per side of the square
1515
h = 0.01 # time step size in s
1616
DBC = [] # no nodes need to be fixed
1717
# ANCHOR: slope_setup

6_inv_free/simulator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
E = 1e5 # Young's modulus
1515
nu = 0.4 # Poisson's ratio
1616
# ANCHOR_END: lame_param
17-
n_seg = 4 # num of segments per side of the square
17+
n_seg = 6 # num of segments per side of the square
1818
h = 0.01 # time step size in s
1919
DBC = [(n_seg + 1) * (n_seg + 1)] # dirichlet node index
2020
DBC_v = [np.array([0.0, -0.5])] # dirichlet node velocity
@@ -50,6 +50,7 @@
5050
resolution = np.array([900, 900])
5151
offset = resolution / 2
5252
scale = 200
53+
DBC_stiff = [1000]
5354
def screen_projection(x):
5455
return [offset[0] + scale * x[0], resolution[1] - (offset[1] + scale * x[1])]
5556

@@ -84,7 +85,7 @@ def screen_projection(x):
8485
pygame.display.flip() # flip the display
8586

8687
# step forward simulation and wait for screen refresh
87-
[x, v] = time_integrator.step_forward(x, e, v, m, vol, IB, mu_lame, lam, ground_n, ground_o, contact_area, mu, is_DBC, DBC, DBC_v, DBC_limit, h, 1e-2)
88+
[x, v] = time_integrator.step_forward(x, e, v, m, vol, IB, mu_lame, lam, ground_n, ground_o, contact_area, mu, is_DBC, DBC, DBC_v, DBC_limit,DBC_stiff, h, 1e-2)
8889
time_step += 1
8990
pygame.time.wait(int(h * 1000))
9091
square_mesh.write_to_file(time_step, x, e)

6_inv_free/time_integrator.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@
1313
import FrictionEnergy
1414
import SpringEnergy
1515

16-
def step_forward(x, e, v, m, vol, IB, mu_lame, lam, n, o, contact_area, mu, is_DBC, DBC, DBC_v, DBC_limit, h, tol):
16+
17+
18+
19+
def step_forward(x, e, v, m, vol, IB, mu_lame, lam, n, o, contact_area, mu, is_DBC, DBC, DBC_v, DBC_limit, DBC_stiff_,h, tol):
1720
x_tilde = x + v * h # implicit Euler predictive position
1821
x_n = copy.deepcopy(x)
1922
mu_lambda = BarrierEnergy.compute_mu_lambda(x, n, o, contact_area, mu) # compute mu * lambda for each node using x^n
@@ -23,7 +26,7 @@ def step_forward(x, e, v, m, vol, IB, mu_lame, lam, n, o, contact_area, mu, is_D
2326
DBC_target.append(x_n[DBC[i]] + h * DBC_v[i])
2427
else:
2528
DBC_target.append(x_n[DBC[i]])
26-
DBC_stiff = 1000 # initialize stiffness for DBC springs
29+
DBC_stiff = DBC_stiff_[0]
2730

2831
# Newton loop
2932
iter = 0
@@ -35,7 +38,8 @@ def step_forward(x, e, v, m, vol, IB, mu_lame, lam, n, o, contact_area, mu, is_D
3538

3639
if (LA.norm(p, inf) / h <= tol) & (sum(DBC_satisfied) != len(DBC)):
3740
# increase DBC stiffness and recompute energy value record
38-
DBC_stiff *= 2
41+
DBC_stiff_[0] *= 2
42+
DBC_stiff = DBC_stiff_[0]
3943
E_last = IP_val(x, e, x_tilde, m, vol, IB, mu_lame, lam, n, o, contact_area, (x - x_n) / h, mu_lambda, DBC, DBC_target, DBC_stiff, h)
4044

4145
# filter line search

0 commit comments

Comments
 (0)