From ddce989b535ddf47cd0cee8cf4ab43966d631a4f Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Tue, 24 Mar 2020 13:14:07 +0100 Subject: Use modern OpenGL for displaying the plot texture --- particles.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'particles.py') diff --git a/particles.py b/particles.py index 0f05786..048e52c 100644 --- a/particles.py +++ b/particles.py @@ -68,6 +68,7 @@ class GasFlow: self.cl_particle_position_b = cl.Buffer(self.context, mf.COPY_HOST_PTR, hostbuf=self.np_particle_position) self.cl_last_collide = cl.Buffer(self.context, mf.COPY_HOST_PTR, hostbuf=self.np_last_collide) + self.cl_particle_velocity_norms = cl.Buffer(self.context, mf.COPY_HOST_PTR, hostbuf=self.np_particle_velocity_norms) def __init__(self, setup, opengl = False, t_scale = 1.0): self.np_particle_position = setup.position.astype(np.float32) @@ -80,6 +81,8 @@ class GasFlow: self.np_last_collide = np.ndarray((self.n_particles, 1), dtype=np.uint32) self.np_last_collide[:,0] = self.n_particles + self.np_particle_velocity_norms = np.ndarray((self.n_particles, 1), dtype=np.float32) + self.kernel_src = build_kernel(self.t_scale*setup.radius/setup.char_u, self.n_particles, setup.radius) self.setup_cl() @@ -120,6 +123,16 @@ class GasFlow: cl.enqueue_copy(self.queue, self.np_particle_velocity, self.cl_particle_velocity_a).wait() return self.np_particle_velocity + def get_velocity_norms(self): + if self.tick: + self.program.get_velocity_norms(self.queue, (self.n_particles,), None, self.cl_particle_velocity_b, self.cl_particle_velocity_norms) + cl.enqueue_copy(self.queue, self.np_particle_velocity_norms, self.cl_particle_velocity_norms).wait() + return self.np_particle_velocity_norms + else: + self.program.get_velocity_norms(self.queue, (self.n_particles,), None, self.cl_particle_velocity_a, self.cl_particle_velocity_norms) + cl.enqueue_copy(self.queue, self.np_particle_velocity_norms, self.cl_particle_velocity_norms).wait() + return self.np_particle_velocity_norms + def get_positions(self): if self.tick: cl.enqueue_copy(self.queue, self.np_particle_position, self.cl_particle_position_b).wait() -- cgit v1.2.3