-
Notifications
You must be signed in to change notification settings - Fork 0
/
explicit.py
36 lines (30 loc) · 1.08 KB
/
explicit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
scene = 1
if __name__ == "__main__":
if scene == 1:
from scene1 import *
elif scene == 2:
from scene2 import *
@ti.kernel
def substep():
# Compute force and new velocity
n = num_particles[None]
for i in range(n):
total_force = ti.Vector(gravity) * particle_mass
for j in range(n):
if rest_length[i, j] != 0:
x_ij = x[i] - x[j]
v_ij = v[i] - v[j]
total_force += -damping[None] * x_ij.normalized() * v_ij * x_ij.normalized() # damping
total_force += -spring_stiffness[None] * (x_ij.norm() - rest_length[i, j]) * x_ij.normalized() # spring
v[i] += dt * total_force / particle_mass
init_mass_spring_system()
while True:
process_input()
if not paused[None]:
for step in range(10):
substep()
update_position()
collide_with_ground()
compute_damp_energy()
compute_current_energy()
process_output()