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 = 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): ti.append( self.pid.parent(), box_ipos - ti.Vector(self.particle_grid_offset), p) self.voxel_has_particle[box_ipos] = 1 self.voxel_grid_density[box_ipos] = 1