def paint(): for i, j in img: ii = min(max(1, i * N // res), N - 2) jj = min(max(1, j * N // res), N - 2) if img_field == 0: # density img[i, j] = Q[ii, jj][0] elif img_field == 1: # numerical schlieren img[i, j] = ti.sqrt(((Q[ii + 1, jj][0] - Q[ii - 1, jj][0]) / h)**2 + ((Q[ii, jj + 1][0] - Q[ii, jj - 1][0]) / h)**2) elif img_field == 2: # vorticity img[i, j] = (Q[ii + 1, jj][2] - Q[ii - 1, jj][2]) / h - ( Q[ii, jj + 1][1] - Q[ii, jj - 1][1]) / h elif img_field == 3: # velocity magnitude img[i, j] = ti.sqrt(Q[ii, jj][1]**2 + Q[ii, jj][2]**2) max = -1.0e10 min = 1.0e10 for i, j in img: ti.atomic_max(max, img[i, j]) ti.atomic_min(min, img[i, j]) for i, j in img: if use_fixed_caxis: min = fixed_caxis[0] max = fixed_caxis[1] img[i, j] = (img[i, j] - min) / (max - min)
def calc_dt(): dt[None] = 1.0e5 for i, j in Q: w = q_to_w(Q[i, j]) a = ti.sqrt(gamma * w[3] / w[0]) vel = ti.sqrt(w[1]**2 + w[2]**2) ws = a + vel ti.atomic_min(dt[None], CFL * h / ws / 2.0)
def foo(): # Parallel min for i in range(1000): ti.atomic_min(f[0], -3.13 * i) # Serial min for _ in range(1): for i in range(1000): f[1] = ti.min(-3.13 * i, f[1])
def compute_dist(t: ti.int32): for bs, i in ti.ndrange(BATCH_SIZE, particle_num): if material[i] == 0: dist = 0.0 for j in ti.static(range(3)): dist += (F_pos[bs, t, i][j] - target_centers[bs][j])**2 dist_sqr = ti.sqrt(dist) ti.atomic_min(min_dist[bs], dist_sqr) ti.atomic_max(max_height[bs], F_pos[bs, t, i][1]) ti.atomic_max(max_left[bs], F_pos[bs, t, i][0]) ti.atomic_max(max_right[bs], F_pos[bs, t, i][2])
def func(): for i in x: x[i] = y[None] x[0] = z[None] x[1] += z[None] x[2] -= z[None] x[3] *= z[None] x[4] //= z[None] x[5] %= z[None] x[6] &= z[None] x[7] |= z[None] x[8] ^= z[None] ti.atomic_min(x[10], z[None]) ti.atomic_max(x[11], z[None])
def func(): for i in x: x[i] = y[None] if ti.static(rhs_is_mat): x[0] = z[None] else: x[0].fill(z[None]) x[1] += z[None] x[2] -= z[None] x[3] *= z[None] x[4] /= z[None] x[5] //= z[None] x[6] %= z[None] ti.atomic_min(x[7], z[None]) ti.atomic_max(x[8], z[None])
def do_render(self, scene): W = 1 A = scene.uncook_coor(scene.camera.untrans_pos(self.a)) B = scene.uncook_coor(scene.camera.untrans_pos(self.b)) M, N = int(ti.floor(min(A, B) - W)), int(ti.ceil(max(A, B) + W)) for X in ti.grouped(ti.ndrange((M.x, N.x), (M.y, N.y))): P = B - A udf = (ts.cross(X, P) + ts.cross(B, A))**2 / P.norm_sqr() XoP = ts.dot(X, P) AoB = ts.dot(A, B) if XoP > B.norm_sqr() - AoB: udf = (B - X).norm_sqr() elif XoP < AoB - A.norm_sqr(): udf = (A - X).norm_sqr() if udf < 0: scene.img[X] = ts.vec3(1.0) elif udf < W**2: t = ts.smoothstep(udf, 0, W**2) ti.atomic_min(scene.img[X], ts.vec3(t))
def func(): a = 1000 for i in range(10): ti.atomic_min(a, i) A[None] = a
def func(): c[None] = 1000 for i in range(n): # this is an expr with side effect, make sure it's not optimized out. ti.atomic_min(c[None], i * step)
def test() -> ti.i32: hit_time = 1 ti.loop_config(block_dim=8) for i in range(8): ti.atomic_min(hit_time, 1) return hit_time
def test1(): for I in x: x[I] = ti.cast(1, ti.u64) << 63 x[1] = 100 for I in x: ti.atomic_min(x[0], x[I])
def compute_contact_distance_kernel(self, f: ti.i32): for i in range(self.n_particles): for primitive in ti.static(self.primitives): d_ij = max(primitive.sdf(f, self.particle_x[f, i]), 0.) ti.atomic_min(primitive.min_dist[None], max(d_ij, 0.))