aboutsummaryrefslogtreecommitdiff
path: root/symbolic
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-06-15 20:45:27 +0200
committerAdrian Kummerlaender2019-06-15 20:54:56 +0200
commitd71faec93ec0a55c46810e0d178b2803ee89130c (patch)
tree3c35650637615af20668a5ec7bf974b2c05b248b /symbolic
parentc43d3f38b6922d36d15e8ba2b6ce17ddb0c75b0a (diff)
downloadsymlbm_playground-d71faec93ec0a55c46810e0d178b2803ee89130c.tar
symlbm_playground-d71faec93ec0a55c46810e0d178b2803ee89130c.tar.gz
symlbm_playground-d71faec93ec0a55c46810e0d178b2803ee89130c.tar.bz2
symlbm_playground-d71faec93ec0a55c46810e0d178b2803ee89130c.tar.lz
symlbm_playground-d71faec93ec0a55c46810e0d178b2803ee89130c.tar.xz
symlbm_playground-d71faec93ec0a55c46810e0d178b2803ee89130c.tar.zst
symlbm_playground-d71faec93ec0a55c46810e0d178b2803ee89130c.zip
Add support for generating a D3Q19 kernel
Note how this basically required no changes besides generalizing cell indexing and adding the symbolic formulation of a D3Q19 BGK collision step. Increasing the neighborhood communication from 9 to 19 cells leads to a significant performance "regression": The 3D kernel yields ~ 360 MLUPS compared to the 2D version's ~ 820 MLUPS.
Diffstat (limited to 'symbolic')
-rw-r--r--symbolic/D3Q19.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/symbolic/D3Q19.py b/symbolic/D3Q19.py
new file mode 100644
index 0000000..789b083
--- /dev/null
+++ b/symbolic/D3Q19.py
@@ -0,0 +1,59 @@
+from sympy import *
+from sympy.codegen.ast import Assignment
+
+q = 19
+d = 3
+
+c = [ Matrix(x) for x in [
+ ( 0, 1, 1), (-1, 0, 1), ( 0, 0, 1), ( 1, 0, 1), ( 0, -1, 1),
+ (-1, 1, 0), ( 0, 1, 0), ( 1, 1, 0), (-1, 0, 0), ( 0, 0, 0), ( 1, 0, 0), (-1,-1, 0), ( 0, -1, 0), ( 1, -1, 0),
+ ( 0, 1,-1), (-1, 0,-1), ( 0, 0,-1), ( 1, 0,-1), ( 0, -1,-1)
+]]
+
+w = [Rational(*x) for x in [
+ (1,36), (1,36), (1,18), (1,36), (1,36),
+ (1,36), (1,18), (1,36), (1,18), (1,3), (1,18), (1,36), (1,18), (1,36),
+ (1,36), (1,36), (1,18), (1,36), (1,36)
+]]
+
+c_s = sqrt(Rational(1,3))
+
+f_next = symarray('f_next', q)
+f_curr = symarray('f_curr', q)
+
+def moments(f = f_curr, optimize = True):
+ rho = symbols('rho')
+ u = Matrix(symarray('u', d))
+
+ exprs = [ Assignment(rho, sum(f)) ]
+
+ for i, u_i in enumerate(u):
+ exprs.append(Assignment(u_i, sum([ (c_j*f[j])[i] for j, c_j in enumerate(c) ]) / sum(f)))
+
+ if optimize:
+ return cse(exprs, optimizations='basic', symbols=numbered_symbols(prefix='m'))
+ else:
+ return ([], exprs)
+
+def equilibrium():
+ rho = symbols('rho')
+ u = Matrix(symarray('u', d))
+
+ f_eq = []
+
+ for i, c_i in enumerate(c):
+ f_eq_i = w[i] * rho * ( 1
+ + c_i.dot(u) / c_s**2
+ + c_i.dot(u)**2 / (2*c_s**4)
+ - u.dot(u) / (2*c_s**2) )
+ f_eq.append(f_eq_i)
+
+ return f_eq
+
+def bgk(tau, f_eq = equilibrium(), optimize = True):
+ exprs = [ Assignment(f_next[i], f_curr[i] + 1/tau * ( f_eq_i - f_curr[i] )) for i, f_eq_i in enumerate(f_eq) ]
+
+ if optimize:
+ return cse(exprs, optimizations='basic')
+ else:
+ return ([], exprs)