diff options
Diffstat (limited to 'codegen_lbm.py')
-rw-r--r-- | codegen_lbm.py | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/codegen_lbm.py b/codegen_lbm.py index 6b36c23..e1906dc 100644 --- a/codegen_lbm.py +++ b/codegen_lbm.py @@ -135,18 +135,16 @@ class D2Q9_BGK_Lattice: self.context = cl.Context(properties=[(cl.context_properties.PLATFORM, self.platform)]) self.queue = cl.CommandQueue(self.context) - self.np_moments = numpy.ndarray(shape=(3, self.nCells), dtype=numpy.float32) + self.np_moments = [] self.np_material = numpy.ndarray(shape=(self.nCells, 1), dtype=numpy.int32) - self.np_stat_moments = [] - self.setup_geometry() self.cl_pop_a = cl.Buffer(self.context, mf.READ_WRITE, size=9*self.nCells*numpy.float32(0).nbytes) self.cl_pop_b = cl.Buffer(self.context, mf.READ_WRITE, size=9*self.nCells*numpy.float32(0).nbytes) + self.cl_moments = cl.Buffer(self.context, mf.WRITE_ONLY, size=3*self.nCells*numpy.float32(0).nbytes) self.cl_material = cl.Buffer(self.context, mf.READ_ONLY | mf.USE_HOST_PTR, hostbuf=self.np_material) - self.cl_moments = cl.Buffer(self.context, mf.READ_WRITE | mf.USE_HOST_PTR, hostbuf=self.np_moments) self.build_kernel() @@ -178,13 +176,15 @@ class D2Q9_BGK_Lattice: self.program = cl.Program(self.context, program_src).build() def collect_moments(self): + moments = numpy.ndarray(shape=(3, self.nCells), dtype=numpy.float32) + if self.tick: self.program.collect_moments(self.queue, (self.nX,self.nY), (32,1), self.cl_pop_b, self.cl_moments) else: self.program.collect_moments(self.queue, (self.nX,self.nY), (32,1), self.cl_pop_a, self.cl_moments) - cl.enqueue_copy(LBM.queue, self.np_moments, LBM.cl_moments).wait(); - self.np_stat_moments.append(self.np_moments.copy()) + cl.enqueue_copy(LBM.queue, moments, LBM.cl_moments).wait(); + self.np_moments.append(moments) def evolve(self): if self.tick: @@ -198,19 +198,19 @@ class D2Q9_BGK_Lattice: self.queue.finish() def generate_moment_plots(self): - for i, np_moments in enumerate(self.np_stat_moments): - print("Generating plot %d of %d." % (i+1, len(self.np_stat_moments))) + for i, moments in enumerate(self.np_moments): + print("Generating plot %d of %d." % (i+1, len(self.np_moments))) density = numpy.ndarray(shape=(self.nY-2, self.nX-2)) for y in range(1,self.nY-1): for x in range(1,self.nX-1): - density[y-1,x-1] = np_moments[0,self.idx(x,y)] + density[y-1,x-1] = moments[0,self.idx(x,y)] plt.figure(figsize=(10, 10)) plt.imshow(density, origin='lower', vmin=0.2, vmax=2.0, cmap=plt.get_cmap('seismic')) plt.savefig("result/density_" + str(i) + ".png", bbox_inches='tight', pad_inches=0) - self.np_stat_moments = [] + self.np_moments = [] def MLUPS(cells, steps, time): |