def initialize_particle_grid(): for p in range(num_particles[None]): x = mpm.x[p] v = mpm.v[p] # ipos = ti.Matrix.floor(x * particle_grid_res).cast(ti.i32) # ipos = ti.Matrix.floor((x * particle_grid_res)/10).cast(ti.i32) #particle postion to grid coorid ipos = ti.Matrix.floor(world_to_grid_forkernel(x)).cast( ti.i32) #particle postion to grid coorid for i in range(-support, support + 1): for j in range(-support, support + 1): for k in range(-support, support + 1): offset = ti.Vector([i, j, k]) box_ipos = ipos + offset # print(box_ipos[0]) if inside_particle_grid(box_ipos): # print(box_ipos[0]) # print(box_ipos[1]) # print(box_ipos[2]) # box_min = box_ipos * (1/particle_grid_res) # box_min = box_ipos * (10/ particle_grid_res) box_min = grid_to_world_forkernel(box_ipos) # box_max = (box_ipos + ti.Vector([1, 1, 1])) * (1 / particle_grid_res) # box_max = (box_ipos + ti.Vector([1, 1, 1])) * (10 / particle_grid_res) box_max = grid_to_world_forkernel( (box_ipos + ti.Vector([1, 1, 1]))) # if sphere_aabb_intersect_motion( # box_min, box_max, x - 0.5 * shutter_time * v, # x + 0.5 * shutter_time * v, sphere_radius): # print(voxel_has_particle[box_ipos]) ti.append(pid.parent(), box_ipos, p) voxel_has_particle[box_ipos] = 1
def insert(): for i in x: x[i] = ti.Vector([ ti.random() * (1 - 2 * bound) + bound, ti.random() * (1 - 2 * bound) + bound ]) ti.append(pid.parent(), [int(x[i][0] * N), int(x[i][1] * N)], i)
def func(): ti.serialize() for i in range(n): for j in range(n): ti.append(x.parent(), j, i) for i in range(n): l[i] = ti.length(x.parent(), i)
def func(): ti.loop_config(serialize=True) for i in range(n): for j in range(n): ti.append(x.parent(), j, i) for i in range(n): l[i] = ti.length(x.parent(), i)
def func(): for i in range(m): ti.append(xp, [], i) l[0] = ti.length(xp, []) x[20] = 42 l[1] = ti.length(xp, []) x[10] = 43 l[2] = ti.length(xp, [])
def insert(): ti.block_dim(256) for i in x: # It is important to ensure insert and p2g uses the exact same way to compute the base # coordinates. Otherwise there might be coordinate mismatch due to float-point errors. base = ti.Vector([ int(ti.floor(x[i][0] * N) - grid_offset[0]), int(ti.floor(x[i][1] * N) - grid_offset[1]) ]) ti.append(pid.parent(), base, i)
def insert(): ti.block_dim(256) for i in x: # Note that since we manually subtract grid offset from base, its values are always positive. # So no ti.floor is needed here and int() suffices. base = ti.Vector([ int(x[i][0] * N - grid_offset[0]), int(x[i][1] * N - grid_offset[1]) ]) ti.append(pid.parent(), base, i)
def build_pid(self, pid: ti.template(), grid_m: ti.template(), offset: ti.template()): """ grid has blocking (e.g. 4x4x4), we wish to put the particles from each block into a GPU block, then used shared memory (ti.block_local) to accelerate :param pid: :param grid_m: :param offset: :return: """ ti.block_dim(64) for p in self.x: base = int(ti.floor(self.x[p] * self.inv_dx - 0.5)) \ - ti.Vector(list(self.offset)) # pid grandparent is `block` base_pid = ti.rescale_index(grid_m, pid.parent(2), base) ti.append(pid.parent(), base_pid, p)
def initialize_particle_grid(): for p in range(num_particles[None]): x = particle_x[p] v = particle_v[p] ipos = ti.floor(x * particle_grid_res).cast(ti.i32) for i in range(-support, support + 1): for j in range(-support, support + 1): for k in range(-support, support + 1): offset = ti.Vector([i, j, k]) box_ipos = ipos + offset if inside_particle_grid(box_ipos): box_min = box_ipos * (1 / particle_grid_res) box_max = (box_ipos + ti.Vector([1, 1, 1])) * ( 1 / particle_grid_res) if sphere_aabb_intersect_motion( box_min, box_max, x - 0.5 * shutter_time * v, x + 0.5 * shutter_time * v, sphere_radius): ti.append(pid.parent(), box_ipos, p) voxel_has_particle[box_ipos] = 1
def initialize_particle_grid(self): for p in range(self.num_particles[None]): v = ti.Vector([0.0, 0.0, 0.0]) if ti.static(self.enable_motion_blur): v = self.particle_v[p] x = self.particle_x[p] ipos = ti.floor(x * self.inv_dx).cast(ti.i32) offset_begin = shutter_begin * self.shutter_time * v offset_end = (shutter_begin + 1.0) * self.shutter_time * v offset_begin_grid = offset_begin offset_end_grid = offset_end for k in ti.static(range(3)): if offset_end_grid[k] < offset_begin_grid[k]: t = offset_end_grid[k] offset_end_grid[k] = offset_begin_grid[k] offset_begin_grid[k] = t offset_begin_grid = int(ti.floor( offset_begin_grid * self.inv_dx)) - 1 offset_end_grid = int(ti.ceil(offset_end_grid * self.inv_dx)) + 2 for i in range(offset_begin_grid[0], offset_end_grid[0]): for j in range(offset_begin_grid[1], offset_end_grid[1]): for k in range(offset_begin_grid[2], offset_end_grid[2]): offset = ti.Vector([i, j, k]) box_ipos = ipos + offset if self.inside_particle_grid(box_ipos): box_min = box_ipos * self.dx box_max = (box_ipos + ti.Vector([1, 1, 1])) * self.dx if sphere_aabb_intersect_motion( box_min, box_max, x + offset_begin, x + offset_end, self.sphere_radius): self.voxel_has_particle[box_ipos] = 1 self.voxel_grid_density[box_ipos] = 1 ti.append( self.pid.parent(), box_ipos - ti.Vector(self.particle_grid_offset), p)
def func(mul: ti.i32): for i in range(n): for j in range(i * i * mul): ti.append(x.parent(), i, j) s[i] = ti.length(x.parent(), i)
def func(): for i in range(n): u = ti.append(x.parent(), [], i) y[u] = i + 1 z[u] = i + 3
def build_pid(self): ti.block_dim(256) for p in self.x: base = ti.floor(self.x[p] * self.inv_dx - 0.5).cast(int) ti.append(self.pid.parent(), base, p)
def make_lists(): for i in range(n): for j in range(i): ti.append(x.parent(), i, j * j) l[i] = ti.length(x.parent(), i)
def func(): a[2] = 0 <= ti.append(a.parent(), [], 10) < 1
def func(): for i in range(n): ti.append(x, [], i)
def append(): for i in range(n): for j in range(i): ti.append(x.parent(), i, j * 2)
def build_pid(self): ti.block_dim(64) for p in self.x: base = int(ti.floor(self.x[p] * self.inv_dx - 0.5)) ti.append(self.pid.parent(), base - ti.Vector(list(self.offset)), p)
def append(): for i in range(n): for j in range(i): ti.append(x, i, j * 2)
def build_pid(self): ti.loop_config(block_dim=256) for p in self.x: base = ti.floor(self.x[p] * self.inv_dx - 0.5).cast(int) + 1 ti.append(self.pid.parent(), base, p)
def func(): for i in range(n): ti.append(x.parent(), [], i)
def func(mul: ti.i32): for i in range(n): for j in range(i * i * mul): ti.append(lst, i, j)