From 186bfae321f9d34b702a7c31b420eed4d10e7a50 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 19 Sep 2021 21:02:52 +0200 Subject: Small changes to channel example --- lbm.org | 75 +++++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'lbm.org') diff --git a/lbm.org b/lbm.org index 168427b..b21ca1d 100644 --- a/lbm.org +++ b/lbm.org @@ -157,7 +157,7 @@ speaking compiling and testing the examples requires neither Emacs nor Python. Note that I started developing this as a beginner in both Emacs and Org mode so some aspects of this document may be more clunky than necessary. Most of the complexity stems from maintaining a Python session for the -generation of optimized GPU kernel functions using the SymPy CAS: +generation of optimized GPU kernel functions using the SymPy CAS. * Lattice The cartesian grids used for the spatial discretization are commonly described as =DXQY= lattices where =X= is the number of spatial dimensions and =Y= is the number of discrete velocities $\xi_i$. e.g. a =D2Q9= lattice is two dimensional and stores nine population values per cell. Each population has @@ -173,7 +173,6 @@ class Descriptor: self.c = [ Matrix(eval(row[0])) for row in data ] self.w = [ Rational(f.numerator, f.denominator) for f in [ Fraction(row[1]) for row in data ] ] - self.d = self.c[0].shape[0] self.q = len(self.c) self.c_s = sqrt(Rational(1,3)) @@ -261,14 +260,14 @@ class CodeBlockPrinter(C11CodePrinter): self.custom_assignment = custom_assignment for f in custom_functions: self._kf[f] = f - + def _print_Indexed(self, expr): assert len(expr.indices) == 1 if expr.base.name[0] == 'f': return f"{expr.base.name}[{expr.indices[0]}]" else: return f"{expr.base.name}_{expr.indices[0]}" - + def _print_Float(self, flt): return "T{%s}" % str(flt.evalf()) @@ -1666,6 +1665,10 @@ A convenient way for generating SDFs for arbitrary shapes is to construct them b various primitives such as spheres and boxes using boolean operators such as addition and substraction. +A comprensive listing of different such functions is available on [[https://iquilezles.org/www/articles/distfunctions/distfunctions.htm][iquilezles.org]]. +The remainder of this section translates some of these shader functions into C++ +functions executable both on the host and the device. + #+BEGIN_SRC cpp :tangle tangle/LLBM/sdf.h namespace sdf { #+END_SRC @@ -1747,6 +1750,17 @@ __device__ __host__ float sintersect(float a, float b, float k) { } #+END_SRC +#+BEGIN_SRC cpp :tangle tangle/LLBM/sdf.h +__device__ __host__ float3 twisted(float3 p, float k) { + float c = cos(k*p.y); + float s = sin(k*p.y); + float3 q = make_float3(0,0,p.y); + q.x = p.x*c + p.z*-s; + q.y = p.x*s + p.z* c; + return q; +} +#+END_SRC + #+BEGIN_SRC cpp :tangle tangle/LLBM/sdf.h } #+END_SRC @@ -3086,20 +3100,15 @@ def readColormap(src): for s in root.findall('.//Point'): values.append(float(s.attrib['x'])) colors.append((float(s.attrib['r']), float(s.attrib['g']), float(s.attrib['b']))) - colormap = [ ] if values[0] != 0: colormap.append((0, colors[0])) - for pos, color in zip(values, colors): colormap.append((pos, color)) - if values[-1] != 1: colormap.append((1, colors[-1])) - return colormap - def renderColormap(cmap, path, reversed = False): gradient = np.linspace(1, 0, 1000) if reversed else np.linspace(0, 1, 1000) gradient = np.vstack((gradient, gradient)) @@ -5377,10 +5386,10 @@ magnus effect and the formation of a Kármán vortex street.