From bcc087a36ea7d84ac61a2c756458a208f6bc3ff3 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Thu, 25 Jul 2019 20:59:06 +0200 Subject: Dampen channel inflow --- channel_2d_gl_interop.py | 10 +++++----- simulation.py | 7 +++++-- template/kernel.mako | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/channel_2d_gl_interop.py b/channel_2d_gl_interop.py index 3abebd7..f8257e6 100644 --- a/channel_2d_gl_interop.py +++ b/channel_2d_gl_interop.py @@ -13,15 +13,15 @@ from OpenGL.GL import shaders screen_x = 1920 screen_y = 1200 -pixels_per_cell = 1 -updates_per_frame = 10 +pixels_per_cell = 2 +updates_per_frame = 80 inflow = 0.02 relaxation_time = 0.51 def get_obstacles(geometry): ys = numpy.linspace(geometry.size_y//50, geometry.size_y-geometry.size_y//50, num = 20) - xs = [ 100 for i, y in enumerate(ys) ] + xs = [ 50 for i, y in enumerate(ys) ] return list(zip(xs, ys)) def is_obstacle(geometry, x, y): @@ -50,7 +50,7 @@ boundary = Template(""" u_1 = 0.0; } if ( m == 3 ) { - u_0 = $inflow; + u_0 = min(time/10000.0 * $inflow, $inflow); u_1 = 0.0; } if ( m == 4 ) { @@ -130,7 +130,7 @@ fragment_shader = shaders.compileShader(""" in vec3 color; void main(){ - gl_FragColor = vec4(color.xyz, 0.0); + gl_FragColor = vec4(color.xyz, 0.0); }""", GL_FRAGMENT_SHADER) diff --git a/simulation.py b/simulation.py index b64ff96..700b8b6 100644 --- a/simulation.py +++ b/simulation.py @@ -109,6 +109,8 @@ class Lattice: self.geometry = geometry self.grid = Grid(self.geometry, padding) + self.time = 0 + self.float_type = { 'single': (numpy.float32, 'float'), 'double': (numpy.float64, 'double'), @@ -186,14 +188,15 @@ class Lattice: self.program = cl.Program(self.context, program_src).build(self.compiler_args) def evolve(self): + self.time += 1 if self.tick: self.tick = False self.program.collide_and_stream( - self.queue, self.grid.size(), self.layout, self.memory.cl_pop_a, self.memory.cl_pop_b, self.memory.cl_material) + self.queue, self.grid.size(), self.layout, self.memory.cl_pop_a, self.memory.cl_pop_b, self.memory.cl_material, numpy.uint32(self.time)) else: self.tick = True self.program.collide_and_stream( - self.queue, self.grid.size(), self.layout, self.memory.cl_pop_b, self.memory.cl_pop_a, self.memory.cl_material) + self.queue, self.grid.size(), self.layout, self.memory.cl_pop_b, self.memory.cl_pop_a, self.memory.cl_material, numpy.uint32(self.time)) def sync(self): self.queue.finish() diff --git a/template/kernel.mako b/template/kernel.mako index ceb7a7a..00a4345 100644 --- a/template/kernel.mako +++ b/template/kernel.mako @@ -38,7 +38,8 @@ def neighbor_offset(c_i): __kernel void collide_and_stream(__global __write_only ${float_type}* f_next, __global __read_only ${float_type}* f_prev, - __global __read_only int* material) + __global __read_only int* material, + unsigned int time) { const unsigned int gid = ${gid()}; -- cgit v1.2.3