Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def func(mul: ti.f32):
for i in range(n):
ti.atomic_add(total[None], x[i] * mul)
def func2():
ti.atomic_add(y[0], x[0] % 3)
def accumulate():
for i in x:
ti.atomic_add(sum, i)
def compute_loss(t: ti.i32):
for i in range(n_grid):
for j in range(n_grid):
ti.atomic_add(loss, dx * dx * ti.sqr(target[i, j] - p[t, i, j]))
def seed_from_voxels(self, material: ti.i32, color: ti.i32,
sample_density: ti.i32):
for i, j, k in self.voxelizer.voxels:
inside = 1
for d in ti.static(range(3)):
inside = inside and self.padding <= i and i < self.res[
d] - self.padding
if inside and self.voxelizer.voxels[i, j, k] > 0:
for l in range(sample_density):
x = ti.Vector(
[ti.random() + i,
ti.random() + j,
ti.random() + k]) * self.dx + self.source_bound[0]
p = ti.atomic_add(self.n_particles[None], 1)
self.seed_particle(p, x, material, color,
self.source_velocity[None])
def apply_impulse(t, i, impulse, location, toi_input):
# ti.print(toi)
delta_v = impulse * inverse_mass[i]
delta_omega = cross(location - x[t, i], impulse) * inverse_inertia[i]
toi = ti.min(ti.max(0.0, toi_input), dt)
ti.atomic_add(x_inc[t + 1, i], toi * (-delta_v))
ti.atomic_add(rotation_inc[t + 1, i], toi * (-delta_omega))
ti.atomic_add(v_inc[t + 1, i], delta_v)
ti.atomic_add(omega_inc[t + 1, i], delta_omega)
def apply_impulse(t, i, impulse, location):
ti.atomic_add(v_inc[t + 1, i], impulse * inverse_mass[i])
ti.atomic_add(omega_inc[t + 1, i],
cross(location - x[t, i], impulse) * inverse_inertia[i])
def apply_spring_force(t: ti.i32):
for i in range(n_springs):
a = spring_anchor_a[i]
b = spring_anchor_b[i]
pos_a = x[t, a]
pos_b = x[t, b]
dist = pos_a - pos_b
length = dist.norm() + 1e-4
target_length = spring_length[i] * (1.0 + spring_actuation[i] * act[t, i])
impulse = dt * (
length - target_length) * spring_stiffness[i] / length * dist
ti.atomic_add(v_inc[t + 1, a], -impulse)
ti.atomic_add(v_inc[t + 1, b], impulse)
def compute_total_energy():
for i in range(n_elements):
currentT = compute_T(i)
F = currentT @ restT[i].inverse()
# NeoHookean
I1 = (F @ ti.Matrix.transposed(F)).trace()
J = ti.Matrix.determinant(F)
element_energy = 0.5 * mu * (
I1 - 2) - mu * ti.log(J) + 0.5 * la * ti.log(J)**2
ti.atomic_add(total_energy[None], element_energy * 1e-3)