aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2019-10-30 19:40:56 +0100
committerAdrian Kummerlaender2019-10-30 19:40:56 +0100
commitfc58dab96f27624435a1c08480234a7c03071e27 (patch)
tree674a828469241c396551f242373e8e4fb6b63e63
parent2bff37d2d4c0e210fd3e4288bdd0add12b9eb86b (diff)
downloadboltzgen_examples-fc58dab96f27624435a1c08480234a7c03071e27.tar
boltzgen_examples-fc58dab96f27624435a1c08480234a7c03071e27.tar.gz
boltzgen_examples-fc58dab96f27624435a1c08480234a7c03071e27.tar.bz2
boltzgen_examples-fc58dab96f27624435a1c08480234a7c03071e27.tar.lz
boltzgen_examples-fc58dab96f27624435a1c08480234a7c03071e27.tar.xz
boltzgen_examples-fc58dab96f27624435a1c08480234a7c03071e27.tar.zst
boltzgen_examples-fc58dab96f27624435a1c08480234a7c03071e27.zip
Extract settings into config file, add documentation
-rw-r--r--ldc_2d/cpp/CMakeLists.txt2
-rw-r--r--ldc_2d/cpp/README.md18
-rw-r--r--ldc_2d/cpp/config.py13
-rwxr-xr-xldc_2d/cpp/generate.py20
4 files changed, 42 insertions, 11 deletions
diff --git a/ldc_2d/cpp/CMakeLists.txt b/ldc_2d/cpp/CMakeLists.txt
index e00af90..5b5fb90 100644
--- a/ldc_2d/cpp/CMakeLists.txt
+++ b/ldc_2d/cpp/CMakeLists.txt
@@ -16,7 +16,7 @@ add_custom_command(
WORKING_DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS
- generate.py ldc.cpp.mako
+ generate.py config.py ldc.cpp.mako
)
include_directories(
diff --git a/ldc_2d/cpp/README.md b/ldc_2d/cpp/README.md
new file mode 100644
index 0000000..8e84c83
--- /dev/null
+++ b/ldc_2d/cpp/README.md
@@ -0,0 +1,18 @@
+# Lid driven cavity
+
+This example models the common lid driven cavity example.
+Note that the actual optimized C++ implementation is generated using the _boltzgen_ library.
+
+See `config.py` for various configuration options. Both 2D and 3D are supported.
+
+## Build instructions
+
+```
+mkdir build
+cd build
+cmake ..
+make
+./ldc
+```
+
+This should result in some summarizing CLI output in addition to a `test.vtk` file for visualization in Paraview.
diff --git a/ldc_2d/cpp/config.py b/ldc_2d/cpp/config.py
new file mode 100644
index 0000000..3ed8bd5
--- /dev/null
+++ b/ldc_2d/cpp/config.py
@@ -0,0 +1,13 @@
+from boltzgen.lbm.model import *
+from boltzgen import Geometry
+
+descriptor = D2Q9
+geometry = Geometry(512, 512)
+tau = 0.52
+precision = 'single'
+
+## 3D LDC
+#descriptor = D3Q19
+#geometry = Geometry(64, 64, 64)
+#tau = 0.52
+#precision = 'single'
diff --git a/ldc_2d/cpp/generate.py b/ldc_2d/cpp/generate.py
index 167cc1b..4222e98 100755
--- a/ldc_2d/cpp/generate.py
+++ b/ldc_2d/cpp/generate.py
@@ -5,6 +5,8 @@ import argparse
from boltzgen import LBM, Generator, Geometry
from boltzgen.lbm.model import D2Q9
+import config
+
argparser = argparse.ArgumentParser(
description = 'Generate a C++ implementation of a lid driven cavity simulation using LBM')
argparser.add_argument(
@@ -12,29 +14,27 @@ argparser.add_argument(
args = argparser.parse_args()
-geometry = Geometry(128, 128)
-
-functions = ['collide_and_stream', 'equilibrilize', 'collect_moments', 'momenta_boundary']
-
-lbm = LBM(D2Q9)
+lbm = LBM(config.descriptor)
generator = Generator(
- descriptor = D2Q9,
+ descriptor = config.descriptor,
moments = lbm.moments(),
- collision = lbm.bgk(f_eq = lbm.equilibrium(), tau = 0.52),
+ collision = lbm.bgk(f_eq = lbm.equilibrium(), tau = config.tau),
target = 'cpp',
- precision = 'double',
+ precision = config.precision,
index = 'XYZ',
layout = 'AOS')
if args.output is None:
args.output = '.'
+functions = ['collide_and_stream', 'equilibrilize', 'collect_moments', 'momenta_boundary']
+
with open('%s/kernel.h' % args.output, 'w') as kernel:
- kernel.write(generator.kernel(geometry, functions))
+ kernel.write(generator.kernel(config.geometry, functions))
ldc_src = ''
with open('ldc.cpp.mako', 'r') as template:
ldc_src = template.read()
with open('%s/ldc.cpp' % args.output, 'w') as app:
- app.write(generator.custom(geometry, ldc_src))
+ app.write(generator.custom(config.geometry, ldc_src))