aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2020-01-11 00:18:20 +0100
committerAdrian Kummerlaender2020-01-11 00:18:20 +0100
commit74392de73ae6c799486f34eccf5c2c37ff9187ea (patch)
tree4630bd89d141955f359a0fef90cc1626589f9051
parentac226d7ddf6ccfde2d5db3dc4807456ab3d46521 (diff)
downloadboltzgen_examples-74392de73ae6c799486f34eccf5c2c37ff9187ea.tar
boltzgen_examples-74392de73ae6c799486f34eccf5c2c37ff9187ea.tar.gz
boltzgen_examples-74392de73ae6c799486f34eccf5c2c37ff9187ea.tar.bz2
boltzgen_examples-74392de73ae6c799486f34eccf5c2c37ff9187ea.tar.lz
boltzgen_examples-74392de73ae6c799486f34eccf5c2c37ff9187ea.tar.xz
boltzgen_examples-74392de73ae6c799486f34eccf5c2c37ff9187ea.tar.zst
boltzgen_examples-74392de73ae6c799486f34eccf5c2c37ff9187ea.zip
Add support for SSS propagation in OpenCL example
-rw-r--r--boltzgen.nix2
-rw-r--r--lid_driven_cavity/opencl/SSS.py85
-rw-r--r--lid_driven_cavity/opencl/ldc_2d.py13
3 files changed, 96 insertions, 4 deletions
diff --git a/boltzgen.nix b/boltzgen.nix
index 74ba512..dcbc7e0 100644
--- a/boltzgen.nix
+++ b/boltzgen.nix
@@ -7,7 +7,7 @@ let in {
src = builtins.fetchGit {
url = "https://code.kummerlaender.eu/boltzgen/";
- rev = "aa509dd4ebbb9d1d8ad6ebfe05111228fd9ae7c0";
+ rev = "b5a24f31871d900342a3c47398cc75e22bad0b6f";
};
propagatedBuildInputs = with pkgs.python37Packages; [
diff --git a/lid_driven_cavity/opencl/SSS.py b/lid_driven_cavity/opencl/SSS.py
new file mode 100644
index 0000000..86b42a9
--- /dev/null
+++ b/lid_driven_cavity/opencl/SSS.py
@@ -0,0 +1,85 @@
+import pyopencl as cl
+mf = cl.mem_flags
+
+import numpy
+
+class Memory:
+ def __init__(self, descriptor, geometry, context, float_type):
+ self.context = context
+ self.float_type = float_type
+
+ self.size_x = geometry.size_x
+ self.size_y = geometry.size_y
+ self.size_z = geometry.size_z
+ self.volume = self.size_x * self.size_y * self.size_z
+
+ padding = (max(geometry.size_x,geometry.size_y,geometry.size_z)+1)**(descriptor.d-1)
+ self.pop_size = (geometry.volume+2*padding) * descriptor.q * self.float_type(0).nbytes
+
+ self.moments_size = 3 * self.volume * self.float_type(0).nbytes
+
+ self.cl_pop = cl.Buffer(self.context, mf.READ_WRITE, size=self.pop_size)
+ self.cl_control = cl.Buffer(self.context, mf.READ_WRITE, size=descriptor.q * 8)
+
+ self.cl_moments = cl.Buffer(self.context, mf.WRITE_ONLY, size=self.moments_size)
+
+ def gid(self, x, y, z = 0):
+ return z * (self.size_x*self.size_y) + y * self.size_x + x;
+
+class Lattice:
+ def __init__(self, geometry, kernel_src, descriptor, context, queue, precision = 'single'):
+ self.geometry = geometry
+ self.descriptor = descriptor
+
+ self.float_type = {
+ 'single': (numpy.float32, 'float'),
+ 'double': (numpy.float64, 'double'),
+ }.get(precision, None)
+
+ self.layout = None
+
+ self.context = context
+ self.queue = queue
+
+ self.memory = Memory(descriptor, self.geometry, self.context, self.float_type[0])
+
+ self.compiler_args = {
+ 'single': '-cl-single-precision-constant -cl-fast-relaxed-math',
+ 'double': '-cl-fast-relaxed-math'
+ }.get(precision, None)
+
+ self.build_kernel(kernel_src)
+
+ self.program.init_sss_control_structure(
+ self.queue, (1,1,1), None, self.memory.cl_pop, self.memory.cl_control).wait()
+
+ self.program.equilibrilize_domain(
+ self.queue, self.geometry.size(), self.layout, self.memory.cl_control).wait()
+
+ self.tasks = []
+
+ def build_kernel(self, src):
+ self.program = cl.Program(self.context, src).build(self.compiler_args)
+
+ def schedule(self, f, cells, *params):
+ self.tasks += [ (eval("self.program.%s" % f), cells, params) ]
+
+ def evolve(self):
+ for f, cells, params in self.tasks:
+ f(self.queue, cells.size(), self.layout, self.memory.cl_control, cells.get(), *params)
+
+ self.program.update_sss_control_structure(
+ self.queue, (1,1,1), None, self.memory.cl_control)
+
+ def sync(self):
+ self.queue.finish()
+
+ def get_moments(self):
+ moments = numpy.ndarray(shape=(self.memory.volume*(self.descriptor.d+1),1), dtype=self.float_type[0])
+
+ self.program.collect_moments_domain(
+ self.queue, self.geometry.inner_size(), self.layout, self.memory.cl_control, self.memory.cl_moments)
+
+ cl.enqueue_copy(self.queue, moments, self.memory.cl_moments).wait();
+
+ return moments
diff --git a/lid_driven_cavity/opencl/ldc_2d.py b/lid_driven_cavity/opencl/ldc_2d.py
index 1ea80aa..8f9a0c3 100644
--- a/lid_driven_cavity/opencl/ldc_2d.py
+++ b/lid_driven_cavity/opencl/ldc_2d.py
@@ -20,10 +20,14 @@ functions = ['collide_and_stream', 'equilibrilize', 'collect_moments', 'momenta_
extras = ['cell_list_dispatch']
precision = 'single'
-streaming = 'AA'
+streaming = 'SSS'
+
+if streaming == 'SSS':
+ functions = functions + ['update_sss_control_structure']
-import AA
import AB
+import AA
+import SSS
Lattice = eval('%s.Lattice' % streaming)
@@ -60,7 +64,10 @@ wall_cells = CellList(lattice.context, lattice.queue, lattice.float_type,
lid_cells = CellList(lattice.context, lattice.queue, lattice.float_type,
[ gid(x,y) for x, y in geometry.inner_cells() if y == geometry.size_y-2 ])
-if streaming == 'AB':
+if streaming == 'SSS':
+ lattice.schedule('equilibrilize', ghost_cells)
+
+if streaming in ['AB', 'SSS']:
lattice.schedule('collide_and_stream', bulk_cells)
lattice.schedule('velocity_momenta_boundary', wall_cells, numpy.array([0.0, 0.0], dtype=lattice.float_type[0]))
lattice.schedule('velocity_momenta_boundary', lid_cells, numpy.array([0.1, 0.0], dtype=lattice.float_type[0]))