write_to_disk = False # Try to run on GPU ti.init(arch=ti.cuda, kernel_profiler=True) gui = ti.GUI("MPM Benchmark", res=256, background_color=0x112F41) mpm = MPMSolver(res=(256, 256, 256), size=1, unbounded=False) particles = np.fromfile('benchmark_particles.bin', dtype=np.float32) particles = particles.reshape(len(particles) // 3, 3) print(len(particles)) mpm.add_particles(particles=particles, material=MPMSolver.material_elastic, color=0xFFFF00) mpm.set_gravity((0, -20, 0)) for frame in range(1500): mpm.step(3e-3) particles = mpm.particle_info() np_x = particles['position'] / 1.0 # simple camera transform screen_x = ((np_x[:, 0] + np_x[:, 2]) / 2**0.5) - 0.2 screen_y = (np_x[:, 1]) screen_pos = np.stack([screen_x, screen_y], axis=-1)
addParticlesCount = 2000 for frame in range(15000): print(f'frame {frame}') t = time.time() # mpm.add_cube((0.0, 0.3, 0.0), (0.99999, 0.01, 0.8), # mpm.material_water, # sample_density=10, # color=0x8888FF, # velocity=[0, -1, 0]) if mpm.n_particles[None] < max_num_particles: particles = np.zeros((addParticlesCount, 3), dtype=np.float32) for part in range(addParticlesCount): particles[part][0] = random.random() particles[part][1] = 0.8 particles[part][2] = random.random() mpm.add_particles(particles=particles, material=MPMSolver.material_water, color=0xFF8888, velocity=(0, 0, 0)) mpm.step(4e-3, print_stat=True) if with_gui: particles = mpm.particle_info() visualize(particles) if write_to_disk: mpm.write_particles(f'{output_dir}/{frame:05d}.npz') print(f'Frame total time {time.time() - t:.3f}') print(f'Total running time {time.time() - start_t:.3f}')