import taichi as ti
ti.init(arch=ti.gpu)
# Constants
particle_mass = 1.0
h = 2.0 # smoothing length
# Particle data
particles = ti.Vector.field(2, dtype=float)
velocities = ti.Vector.field(2, dtype=float)
@ti.kernel
def initialize_particles():
for i in range(particles.shape[0]):
particles[i] = [ti.random(), ti.random()]
velocities[i] = [0.0, 0.0]
# SPH simulation step (e.g., using WCSPH method)
@ti.kernel
def simulation_step():
# Implement SPH simulation step here
pass
# Export particle data
@ti.kernel
def export_data():
for i in range(particles.shape[0]):
print(particles[i][0], particles[i][1], velocities[i][0], velocities[i][1])
# Main simulation loop
num_particles = 100
initialize_particles()
for frame in range(100):
simulation_step()
export_data()