diff options
Diffstat (limited to 'lid_driven_cavity/opencl/common.py')
-rw-r--r-- | lid_driven_cavity/opencl/common.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lid_driven_cavity/opencl/common.py b/lid_driven_cavity/opencl/common.py new file mode 100644 index 0000000..717c68f --- /dev/null +++ b/lid_driven_cavity/opencl/common.py @@ -0,0 +1,36 @@ +import pyopencl as cl +mf = cl.mem_flags + +import numpy + +import matplotlib +matplotlib.use('AGG') +import matplotlib.pyplot as plt + + +class CellList: + def __init__(self, context, queue, float_type, cells): + self.cl_cells = cl.Buffer(context, mf.READ_ONLY, size=len(cells) * numpy.uint32(0).nbytes) + self.np_cells = numpy.ndarray(shape=(len(cells), 1), dtype=numpy.uint32) + self.np_cells[:,0] = cells[:] + + cl.enqueue_copy(queue, self.cl_cells, self.np_cells).wait(); + + def get(self): + return self.cl_cells + + def size(self): + return (len(self.np_cells), 1, 1) + +def generate_moment_plots(lattice, moments): + for i, m in enumerate(moments): + print("Generating plot %d of %d." % (i+1, len(moments))) + + gid = lattice.memory.gid + velocity = numpy.reshape( + [ numpy.sqrt(m[gid(x,y)*3+1]**2 + m[gid(x,y)*3+2]**2) for x, y in lattice.geometry.inner_cells() ], + lattice.geometry.inner_size()) + + plt.figure(figsize=(10, 10)) + plt.imshow(velocity, origin='lower', cmap=plt.get_cmap('seismic')) + plt.savefig("result/ldc_2d_%02d.png" % i, bbox_inches='tight', pad_inches=0) |