Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • Sparse
  • WallLaw
  • improved_comm
  • master
  • mr_refactor_wfb
  • suffa/cumulantfourth_order_correction_with_psm
  • release/0.2.1
  • release/0.2.10
  • release/0.2.11
  • release/0.2.12
  • release/0.2.13
  • release/0.2.14
  • release/0.2.15
  • release/0.2.2
  • release/0.2.3
  • release/0.2.4
  • release/0.2.5
  • release/0.2.6
  • release/0.2.7
  • release/0.2.8
  • release/0.2.9
  • release/0.3.0
  • release/0.3.1
  • release/0.3.2
  • release/0.3.3
  • release/0.3.4
  • release/0.4.0
  • release/0.4.1
  • release/0.4.2
  • release/0.4.3
  • release/0.4.4
  • release/1.0
  • release/1.0.1
  • release/1.1
  • release/1.1.1
  • release/1.2
  • release/1.3
  • release/1.3.1
  • release/1.3.2
  • release/1.3.3
  • release/1.3.4
  • release/1.3.5
  • release/1.3.6
  • release/1.3.7
44 results

Target

Select target project
  • ravi.k.ayyala/lbmpy
  • brendan-waters/lbmpy
  • anirudh.jonnalagadda/lbmpy
  • jbadwaik/lbmpy
  • alexander.reinauer/lbmpy
  • itischler/lbmpy
  • he66coqe/lbmpy
  • ev81oxyl/lbmpy
  • Bindgen/lbmpy
  • da15siwa/lbmpy
  • holzer/lbmpy
  • RudolfWeeber/lbmpy
  • pycodegen/lbmpy
13 results
Select Git revision
  • GetterSetterAPI
  • HRR
  • HydroPressure
  • InplaceConfig
  • Outflow
  • PhaseField
  • Sparse
  • UBBVelocity
  • UpdateAPISparse
  • WallLaw
  • WetNodeBoundaries
  • csebug
  • feature/sparse
  • feature/try
  • improved_comm
  • install_requires
  • master
  • phaseField
  • relaxationrates
  • test_martin
  • release/0.2.1
  • release/0.2.10
  • release/0.2.11
  • release/0.2.12
  • release/0.2.13
  • release/0.2.14
  • release/0.2.15
  • release/0.2.2
  • release/0.2.3
  • release/0.2.4
  • release/0.2.5
  • release/0.2.6
  • release/0.2.7
  • release/0.2.8
  • release/0.2.9
  • release/0.3.0
  • release/0.3.1
  • release/0.3.2
  • release/0.3.3
  • release/0.3.4
  • release/0.4.0
  • release/0.4.1
  • release/0.4.2
  • release/0.4.3
  • release/0.4.4
  • release/1.0
  • release/1.0.1
  • release/1.1
  • release/1.1.1
  • release/1.2
  • release/1.3
  • release/1.3.1
  • release/1.3.2
  • release/1.3.3
  • release/1.3.4
  • release/1.3.5
  • release/1.3.6
57 results
Show changes
Commits on Source (37)
Showing
with 1626 additions and 379 deletions
...@@ -21,6 +21,9 @@ doc/bibtex.json ...@@ -21,6 +21,9 @@ doc/bibtex.json
/src/lbmpy/phasefield/simplex_projection.*.so /src/lbmpy/phasefield/simplex_projection.*.so
/src/lbmpy/phasefield/simplex_projection.c /src/lbmpy/phasefield/simplex_projection.c
test-report
report.xml
# macOS # macOS
**/.DS_Store **/.DS_Store
*.uuid *.uuid
......
stages: stages:
- pretest - "Code Quality"
- test - "Tests"
- "Prerelease-Tests"
- integration
- nightly
- docs
- deploy - deploy
# -------------------------- Code Quality --------------------------------------------------------------------------------
# -------------------------- Pre Tests --------------------------------------------------------------------------------
# Linter for code formatting
flake8-lint:
stage: "Code Quality"
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:alpine
script:
- nox -s lint
tags:
- docker
# -------------------------- Tests --------------------------------------------------------------------------------
# Normal test - runs on every commit all but "long run" tests # Normal test - runs on every commit all but "long run" tests
tests-and-coverage: testsuite-cuda-py3.10:
stage: pretest stage: "Tests"
except: image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:ubuntu24.04-cuda12.6
variables: needs: []
- $ENABLE_NIGHTLY_BUILDS
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
script: script:
# - pip install sympy --upgrade
- export NUM_CORES=$(nproc --all)
- mkdir -p ~/.config/matplotlib - mkdir -p ~/.config/matplotlib
- echo "backend:template" > ~/.config/matplotlib/matplotlibrc - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
- mkdir public - nox -s "testsuite_gpu-3.10(cupy12)"
- pip install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils
- env
- pip list
- py.test -v -n $NUM_CORES --cov-report html --cov-report xml --cov-report term --cov=. -m "not longrun" --junitxml=report.xml
- python3 -m coverage xml
tags: tags:
- docker - docker
- cuda11 - cuda
- cudaComputeCapability6.1
- AVX - AVX
coverage: /Total coverage:\s\d+.\d+\%/ coverage: /Total coverage:\s\d+.\d+\%/
artifacts: artifacts:
when: always when: always
paths: paths:
- coverage_report - coverage_report
- test-report
reports: reports:
coverage_report: coverage_report:
coverage_format: cobertura coverage_format: cobertura
path: coverage.xml path: coverage.xml
junit: report.xml junit: report.xml
testsuite-cpu-py3.13:
stage: "Tests"
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:alpine
needs: []
script:
- mkdir -p ~/.config/matplotlib
- echo "backend:template" > ~/.config/matplotlib/matplotlibrc
- nox -s "testsuite_cpu-3.13"
tags:
- docker
- AVX
artifacts:
when: always
paths:
- test-report
reports:
junit: report.xml
# Normal test with longruns # Normal test with longruns
tests-and-coverage-with-longrun: tests-and-coverage-with-longrun:
stage: test stage: "Tests"
when: manual when: manual
allow_failure: true allow_failure: true
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
...@@ -57,163 +86,117 @@ tests-and-coverage-with-longrun: ...@@ -57,163 +86,117 @@ tests-and-coverage-with-longrun:
- py.test -v -n $NUM_CORES - py.test -v -n $NUM_CORES
tags: tags:
- docker - docker
- cuda11 - cuda
- cudaComputeCapability6.1
- AVX - AVX
minimal-conda: # -------------------------- Nightly and Pre-Release Tests --------------------------------------------------------------------------------
stage: pretest
except:
variables:
- $ENABLE_NIGHTLY_BUILDS
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/minimal_conda
script:
- pip install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils
- pip install -e .
- python quicktest.py
tags:
- docker
# Linter for code formatting
flake8-lint:
stage: pretest
except:
variables:
- $ENABLE_NIGHTLY_BUILDS
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
script:
- flake8 src/lbmpy
tags:
- docker
- cuda11
# -------------------------- Tests -------------------------------------------------------------------------------------
# pipeline with latest python version # Test against latest pystencils 2.0 development version
latest-python: pystencils-2.0dev:
stage: test stage: "Prerelease-Tests"
except: image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:ubuntu24.04-cuda12.6
variables: allow_failure: true
- $ENABLE_NIGHTLY_BUILDS needs: []
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/latest_python
before_script:
- pip install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils
script: script:
- env
- pip list
- export NUM_CORES=$(nproc --all)
- mkdir -p ~/.config/matplotlib - mkdir -p ~/.config/matplotlib
- echo "backend:template" > ~/.config/matplotlib/matplotlibrc - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
- mkdir public - nox -s "testsuite_pystencils2(cupy12)"
- py.test -v -n $NUM_CORES -m "not longrun" --junitxml=report.xml
tags: tags:
- docker - docker
- AVX - AVX
- cuda
- cudaComputeCapability6.1
artifacts: artifacts:
when: always when: always
paths:
- test-report
reports: reports:
junit: report.xml junit: report.xml
# Minimal tests in windows environment
#minimal-windows:
# stage: test
# except:
# variables:
# - $ENABLE_NIGHTLY_BUILDS
# tags:
# - win
# script:
# - export NUM_CORES=$(nproc --all)
# - export MPLBACKEND=Agg
# - source /cygdrive/c/Users/build/Miniconda3/Scripts/activate
# - source activate pystencils
# - pip install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils
# - python -c "import numpy"
# - pip install sympy==1.9
# - py.test -v -m "not (notebook or longrun)"
minimal-sympy-master: minimal-sympy-master:
stage: test stage: "Prerelease-Tests"
except: needs: []
variables: image: i10git.cs.fau.de:5005/pycodegen/pycodegen/nox:alpine
- $ENABLE_NIGHTLY_BUILDS
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/minimal_conda
before_script:
- pip install -e .
script: script:
- pip install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils - nox -s quicktest -P 3.13 -- --sympy-master
- python -m pip install --upgrade git+https://github.com/sympy/sympy.git
- pip list
- python quicktest.py
allow_failure: true allow_failure: true
tags: tags:
- docker - docker
- cuda
ubuntu: # pycodegen-integration:
stage: test # image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
except: # stage: integration
variables: # when: manual
- $ENABLE_NIGHTLY_BUILDS # allow_failure: true
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/ubuntu # script:
# - env
# - pip list
# - git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pycodegen.git
# - cd pycodegen
# - git submodule sync --recursive
# - git submodule update --init --recursive
# - git submodule foreach git fetch origin # compare the latest master version!
# - git submodule foreach git reset --hard origin/master
# - cd lbmpy
# - git remote add test $CI_REPOSITORY_URL
# - git fetch test
# - git reset --hard $CI_COMMIT_SHA
# - cd ..
# - pip install -e pystencils/
# - pip install -e lbmpy/
# - ./install_walberla.sh
# # build all integration tests
# - cd walberla/build/
# - make -j $NUM_CORES MicroBenchmarkGpuLbm LbCodeGenerationExample
# - cd apps/benchmarks/UniformGridGPU
# - make -j $NUM_CORES
# - cd ../UniformGridCPU
# - make -j $NUM_CORES
# tags:
# - docker
# - cuda
# - cudaComputeCapability6.1
# - AVX
# -------------------- Scheduled Tasks --------------------------------------------------------------------------
nightly-sympy:
stage: nightly
rules:
- if: $CI_PIPELINE_SOURCE == "schedule"
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/latest_python
before_script: before_script:
# - apt-get -y remove python3-sympy - pip install -e .
- ln -s /usr/include/locale.h /usr/include/xlocale.h - pip install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils
# - pip3 install `grep -Eo 'sympy[>=]+[0-9\.]+' setup.py | sed 's/>/=/g'` - pip install --upgrade --pre sympy
- pip3 install git+https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pystencils.git@master#egg=pystencils
script: script:
- env
- pip list
- export NUM_CORES=$(nproc --all) - export NUM_CORES=$(nproc --all)
- mkdir -p ~/.config/matplotlib - mkdir -p ~/.config/matplotlib
- echo "backend:template" > ~/.config/matplotlib/matplotlibrc - echo "backend:template" > ~/.config/matplotlib/matplotlibrc
- env - mkdir public
- pip3 list
- pytest -v -n $NUM_CORES -m "not longrun" --junitxml=report.xml - pytest -v -n $NUM_CORES -m "not longrun" --junitxml=report.xml
tags: tags:
- docker - docker
- cuda11 - AVX
- cuda
- cudaComputeCapability6.1
artifacts: artifacts:
when: always when: always
reports: reports:
junit: report.xml junit: report.xml
pycodegen-integration:
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
stage: test
when: manual
allow_failure: true
script:
- env
- pip list
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@i10git.cs.fau.de/pycodegen/pycodegen.git
- cd pycodegen
- git submodule sync --recursive
- git submodule update --init --recursive
- git submodule foreach git fetch origin # compare the latest master version!
- git submodule foreach git reset --hard origin/master
- cd lbmpy
- git remote add test $CI_REPOSITORY_URL
- git fetch test
- git reset --hard $CI_COMMIT_SHA
- cd ..
- pip install -e pystencils/
- pip install -e lbmpy/
- ./install_walberla.sh
# build all integration tests
- cd walberla/build/
- make -j $NUM_CORES MicroBenchmarkGpuLbm LbCodeGenerationExample
- cd apps/benchmarks/UniformGridGPU
- make -j $NUM_CORES
- cd ../UniformGridCPU
- make -j $NUM_CORES
tags:
- docker
- cuda11
- AVX
# -------------------- Documentation and deploy ------------------------------------------------------------------------ # -------------------- Documentation and deploy ------------------------------------------------------------------------
build-documentation: build-documentation:
stage: test stage: docs
needs: []
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/documentation image: i10git.cs.fau.de:5005/pycodegen/pycodegen/documentation
before_script: before_script:
- pip install -e . - pip install -e .
...@@ -224,7 +207,8 @@ build-documentation: ...@@ -224,7 +207,8 @@ build-documentation:
- sphinx-build -W -b html doc html_doc - sphinx-build -W -b html doc html_doc
tags: tags:
- docker - docker
- cuda11 - cuda
- cudaComputeCapability6.1
artifacts: artifacts:
paths: paths:
- html_doc - html_doc
...@@ -232,7 +216,10 @@ build-documentation: ...@@ -232,7 +216,10 @@ build-documentation:
pages: pages:
image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full image: i10git.cs.fau.de:5005/pycodegen/pycodegen/full
rules:
- if: '$CI_PIPELINE_SOURCE != "schedule" && $CI_PROJECT_PATH == "pycodegen/lbmpy" && $CI_COMMIT_BRANCH == "master"'
stage: deploy stage: deploy
needs: ["testsuite-cuda-py3.10", "build-documentation"]
script: script:
- ls -l - ls -l
- mv coverage_report html_doc - mv coverage_report html_doc
...@@ -242,5 +229,3 @@ pages: ...@@ -242,5 +229,3 @@ pages:
- public - public
tags: tags:
- docker - docker
only:
- master@pycodegen/lbmpy
...@@ -11,3 +11,4 @@ Contributors: ...@@ -11,3 +11,4 @@ Contributors:
- Rudolf Weeber <weeber@icp.uni-stuttgart.de> - Rudolf Weeber <weeber@icp.uni-stuttgart.de>
- Christian Godenschwager <christian.godenschwager@fau.de> - Christian Godenschwager <christian.godenschwager@fau.de>
- Jan Hönig <jan.hoenig@fau.de> - Jan Hönig <jan.hoenig@fau.de>
- Philipp Suffa <philipp.suffa@fau.de>
------------------------ Important ---------------------------------
lbmpy is under the following GNU AGPLv3 license.
This license holds for the sources of lbmpy itself as well
as for all kernels generated with lbmpy i.e.
the output of lbmpy is also protected by the GNU AGPLv3 license.
----------------------------------------------------------------------
GNU AFFERO GENERAL PUBLIC LICENSE GNU AFFERO GENERAL PUBLIC LICENSE
Version 3, 19 November 2007 Version 3, 19 November 2007
......
...@@ -5,13 +5,18 @@ import runpy ...@@ -5,13 +5,18 @@ import runpy
import sys import sys
import warnings import warnings
import platform import platform
import pathlib
import nbformat import nbformat
from nbconvert import PythonExporter import nbconvert
import sympy import sympy
from lbmpy._compat import IS_PYSTENCILS_2
# Trigger config file reading / creation once - to avoid race conditions when multiple instances are creating it # Trigger config file reading / creation once - to avoid race conditions when multiple instances are creating it
# at the same time # at the same time
from pystencils.cpu import cpujit if not IS_PYSTENCILS_2:
from pystencils.cpu import cpujit
# trigger cython imports - there seems to be a problem when multiple processes try to compile the same cython file # trigger cython imports - there seems to be a problem when multiple processes try to compile the same cython file
# at the same time # at the same time
...@@ -19,9 +24,9 @@ try: ...@@ -19,9 +24,9 @@ try:
import pyximport import pyximport
pyximport.install(language_level=3) pyximport.install(language_level=3)
from lbmpy.phasefield.simplex_projection import simplex_projection_2d # NOQA
except ImportError: except ImportError:
pass pass
from lbmpy.phasefield.simplex_projection import simplex_projection_2d # NOQA
SCRIPT_FOLDER = os.path.dirname(os.path.realpath(__file__)) SCRIPT_FOLDER = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(0, os.path.abspath('lbmpy')) sys.path.insert(0, os.path.abspath('lbmpy'))
...@@ -44,6 +49,13 @@ collect_ignore = [os.path.join(SCRIPT_FOLDER, "doc", "conf.py"), ...@@ -44,6 +49,13 @@ collect_ignore = [os.path.join(SCRIPT_FOLDER, "doc", "conf.py"),
os.path.join(SCRIPT_FOLDER, "doc", "img", "mb_discretization", "maxwell_boltzmann_stencil_plot.py")] os.path.join(SCRIPT_FOLDER, "doc", "img", "mb_discretization", "maxwell_boltzmann_stencil_plot.py")]
add_path_to_ignore('_local_tmp') add_path_to_ignore('_local_tmp')
if IS_PYSTENCILS_2:
# TODO: Fix these step-by-step
collect_ignore += [
os.path.join(SCRIPT_FOLDER, "doc", "notebooks", "10_tutorial_conservative_allen_cahn_two_phase.ipynb"),
os.path.join(SCRIPT_FOLDER, "tests", "test_compiled_in_boundaries.ipynb")
]
try: try:
import cupy import cupy
except ImportError: except ImportError:
...@@ -106,22 +118,29 @@ class IPyNbTest(pytest.Item): ...@@ -106,22 +118,29 @@ class IPyNbTest(pytest.Item):
# disable matplotlib output # disable matplotlib output
exec("import matplotlib.pyplot as p; " exec("import matplotlib.pyplot as p; "
"p.close('all'); "
"p.switch_backend('Template')", global_dict) "p.switch_backend('Template')", global_dict)
# in notebooks there is an implicit plt.show() - if this is not called a warning is shown when the next # in notebooks there is an implicit plt.show() - if this is not called a warning is shown when the next
# plot is created. This warning is suppressed here # plot is created. This warning is suppressed here
# Also animations cannot be shown, which also leads to a warning.
exec("import warnings;" exec("import warnings;"
"warnings.filterwarnings('ignore', 'Adding an axes using the same arguments as a previous.*');", "warnings.filterwarnings('ignore', 'Adding an axes using the same arguments as a previous.*');"
"warnings.filterwarnings('ignore', 'Animation was deleted without rendering anything.*');",
global_dict) global_dict)
with tempfile.NamedTemporaryFile() as f: with tempfile.NamedTemporaryFile() as f:
f.write(self.code.encode()) f.write(self.code.encode())
f.flush() f.flush()
runpy.run_path(f.name, init_globals=global_dict, run_name=self.name) runpy.run_path(f.name, init_globals=global_dict, run_name=self.name)
# Close any open figures
exec("import matplotlib.pyplot as p; "
"p.close('all')", global_dict)
class IPyNbFile(pytest.File): class IPyNbFile(pytest.File):
def collect(self): def collect(self):
exporter = PythonExporter() exporter = nbconvert.PythonExporter()
exporter.exclude_markdown = True exporter.exclude_markdown = True
exporter.exclude_input_prompt = True exporter.exclude_input_prompt = True
...@@ -140,10 +159,19 @@ class IPyNbFile(pytest.File): ...@@ -140,10 +159,19 @@ class IPyNbFile(pytest.File):
pass pass
def pytest_collect_file(path, parent): if pytest_version >= 70000:
glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"] # Since pytest 7.0, usage of `py.path.local` is deprecated and `pathlib.Path` should be used instead
if any(path.fnmatch(g) for g in glob_exprs): import pathlib
if pytest_version >= 50403:
return IPyNbFile.from_parent(fspath=path, parent=parent) def pytest_collect_file(file_path: pathlib.Path, parent):
else: glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"]
return IPyNbFile(path, parent) if any(file_path.match(g) for g in glob_exprs):
return IPyNbFile.from_parent(path=file_path, parent=parent)
else:
def pytest_collect_file(path, parent):
glob_exprs = ["*demo*.ipynb", "*tutorial*.ipynb", "test_*.ipynb"]
if any(path.fnmatch(g) for g in glob_exprs):
if pytest_version >= 50403:
return IPyNbFile.from_parent(fspath=path, parent=parent)
else:
return IPyNbFile(path, parent)
This diff is collapsed.
...@@ -2,23 +2,23 @@ ...@@ -2,23 +2,23 @@
<!-- Created with Inkscape (http://www.inkscape.org/) --> <!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg <svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="53.913788mm" width="53.913788mm"
height="53.913788mm" height="53.913788mm"
viewBox="0 0 53.913788 53.913788" viewBox="0 0 53.913788 53.913788"
version="1.1" version="1.1"
id="svg834" id="svg834"
inkscape:version="0.92.3 (2405546, 2018-03-11)" inkscape:version="1.4.2 (ebf0e940d0, 2025-05-08)"
sodipodi:docname="logo.svg" sodipodi:docname="logo.svg"
inkscape:export-filename="/local/bauer/code/lbmpy/lbmpy/doc/img/logo.png" inkscape:export-filename="/local/bauer/code/lbmpy/lbmpy/doc/img/logo.png"
inkscape:export-xdpi="70.669998" inkscape:export-xdpi="70.669998"
inkscape:export-ydpi="70.669998"> inkscape:export-ydpi="70.669998"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/">
<defs <defs
id="defs828"> id="defs828">
<marker <marker
...@@ -641,25 +641,31 @@ ...@@ -641,25 +641,31 @@
inkscape:pageopacity="0.0" inkscape:pageopacity="0.0"
inkscape:pageshadow="2" inkscape:pageshadow="2"
inkscape:zoom="1.4" inkscape:zoom="1.4"
inkscape:cx="158.26067" inkscape:cx="158.21429"
inkscape:cy="-4.9825309" inkscape:cy="251.78571"
inkscape:document-units="mm" inkscape:document-units="mm"
inkscape:current-layer="layer1" inkscape:current-layer="layer1"
showgrid="false" showgrid="false"
inkscape:window-width="1214" inkscape:window-width="1557"
inkscape:window-height="1052" inkscape:window-height="1122"
inkscape:window-x="1482" inkscape:window-x="0"
inkscape:window-y="524" inkscape:window-y="0"
inkscape:window-maximized="0" inkscape:window-maximized="0"
fit-margin-top="0" fit-margin-top="0"
fit-margin-left="0" fit-margin-left="0"
fit-margin-right="0" fit-margin-right="0"
fit-margin-bottom="0"> fit-margin-bottom="0"
inkscape:showpageshadow="0"
inkscape:pagecheckerboard="1"
inkscape:deskcolor="#d1d1d1">
<inkscape:grid <inkscape:grid
type="xygrid" type="xygrid"
id="grid1886" id="grid1886"
originx="-9.8407853" originx="-9.8407853"
originy="-227.28709" /> originy="-227.28709"
spacingy="1"
spacingx="1"
units="mm" />
</sodipodi:namedview> </sodipodi:namedview>
<metadata <metadata
id="metadata831"> id="metadata831">
...@@ -688,21 +694,11 @@ ...@@ -688,21 +694,11 @@
ry="3.0735996" ry="3.0735996"
inkscape:export-xdpi="188.45" inkscape:export-xdpi="188.45"
inkscape:export-ydpi="188.45" /> inkscape:export-ydpi="188.45" />
<text <path
xml:space="preserve" style="font-weight:bold;font-size:16.9333px;line-height:125%;font-family:'Latin Modern Mono Light';-inkscape-font-specification:'Latin Modern Mono Light, Bold';letter-spacing:0px;word-spacing:0px;fill:#ffffff;stroke-width:0.264583px"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:2.11666656px;line-height:125%;font-family:'Latin Modern Mono Light';-inkscape-font-specification:'Latin Modern Mono Light, ';letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:0.26458332px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" d="m 21.505785,62.578241 c 0,-0.626532 -0.474132,-0.643466 -0.795865,-0.643466 h -2.015062 v -8.26345 c 0,-0.609599 -0.118533,-0.812798 -0.795865,-0.812798 h -2.607729 c -0.321732,0 -0.812798,0.01693 -0.812798,0.643465 0,0.609599 0.507999,0.626532 0.795865,0.626532 h 2.015063 v 7.806251 h -1.99813 c -0.321732,0 -0.812798,0.01693 -0.812798,0.643466 0,0.609599 0.507999,0.626532 0.795865,0.626532 h 5.435589 c 0.3048,0 0.795865,-0.01693 0.795865,-0.626532 z m 9.228643,-3.064927 c 0,-2.116663 -1.54093,-3.776126 -3.352793,-3.776126 -0.728132,0 -1.405464,0.237066 -1.964263,0.643465 v -2.709328 c 0,-0.609599 -0.118533,-0.812798 -0.795865,-0.812798 h -1.202265 c -0.321732,0 -0.812798,0.01693 -0.812798,0.643465 0,0.609599 0.507999,0.626532 0.795865,0.626532 h 0.609599 v 8.263451 c 0,0.406399 0.01693,0.812798 0.711198,0.812798 0.524933,0 0.660399,-0.237066 0.677332,-0.575732 0.643466,0.541865 1.303865,0.677332 1.79493,0.677332 1.862663,0 3.53906,-1.625597 3.53906,-3.793059 z m -1.388531,0 c 0,1.49013 -1.083731,2.523061 -2.184395,2.523061 -1.202265,0 -1.727197,-1.371597 -1.727197,-2.116662 v -1.202265 c 0,-0.914398 0.897465,-1.710263 1.862663,-1.710263 1.151464,0 2.048929,1.151465 2.048929,2.506129 z m 10.820373,3.064927 c 0,-0.558799 -0.321733,-0.643466 -0.931331,-0.643466 v -3.860792 c 0,-0.355599 -0.03387,-2.336795 -1.608664,-2.336795 -0.474132,0 -1.117598,0.186266 -1.608663,0.745065 -0.287867,-0.491066 -0.745066,-0.745065 -1.269998,-0.745065 -0.491066,0 -0.948265,0.169333 -1.337731,0.474132 -0.118533,-0.372533 -0.440265,-0.389466 -0.745065,-0.389466 h -0.524932 c -0.3048,0 -0.812799,0.03387 -0.812799,0.626532 0,0.558799 0.321733,0.643466 0.931332,0.643466 v 4.842923 c -0.609599,0 -0.931332,0.08467 -0.931332,0.643466 0,0.609599 0.524933,0.626532 0.812799,0.626532 h 1.43933 c 0.3048,0 0.761999,-0.01693 0.761999,-0.626532 0,-0.558799 -0.270933,-0.643466 -0.880532,-0.643466 v -2.827861 c 0,-1.354664 0.575732,-2.099729 1.219198,-2.099729 0.321733,0 0.474132,0.270933 0.474132,1.219198 v 3.708392 c -0.355599,0.01693 -0.677332,0.1016 -0.677332,0.643466 0,0.609599 0.474133,0.626532 0.761999,0.626532 h 1.236131 c 0.304799,0 0.761998,-0.01693 0.761998,-0.626532 0,-0.558799 -0.287866,-0.643466 -0.897465,-0.643466 v -2.827861 c 0,-1.354664 0.592666,-2.099729 1.219198,-2.099729 0.338666,0 0.474132,0.270933 0.474132,1.219198 v 3.708392 c -0.338666,0.01693 -0.660398,0.1016 -0.660398,0.643466 0,0.609599 0.474132,0.626532 0.745065,0.626532 h 1.236131 c 0.304799,0 0.812798,-0.01693 0.812798,-0.626532 z m 9.829776,-3.064927 c 0,-2.116663 -1.540931,-3.776126 -3.352794,-3.776126 -0.728132,0 -1.422397,0.237066 -1.981196,0.660398 -0.01693,-0.389466 -0.169333,-0.575732 -0.778932,-0.575732 H 42.68086 c -0.321733,0 -0.812798,0.03387 -0.812798,0.643466 0,0.609598 0.507999,0.626532 0.795865,0.626532 h 0.609598 v 8.500516 H 42.68086 c -0.321733,0 -0.812798,0.01693 -0.812798,0.643466 0,0.609598 0.507999,0.626532 0.795865,0.626532 h 2.624661 c 0.287866,0 0.795865,-0.01693 0.795865,-0.626532 0,-0.626532 -0.491065,-0.643466 -0.812798,-0.643466 h -0.592666 v -2.963327 c 0.643466,0.558799 1.286931,0.677332 1.777997,0.677332 1.862663,0 3.53906,-1.625597 3.53906,-3.793059 z m -1.388531,0 c 0,1.49013 -1.083731,2.523061 -2.184396,2.523061 -1.202264,0 -1.727196,-1.371597 -1.727196,-2.116662 v -1.202265 c 0,-0.914398 0.897465,-1.710263 1.862663,-1.710263 1.151464,0 2.048929,1.151465 2.048929,2.506129 z M 59.08922,56.46532 c 0,-0.626533 -0.474133,-0.643466 -0.795865,-0.643466 h -1.930397 c -0.304799,0 -0.795865,0.03387 -0.795865,0.626532 0,0.626532 0.474133,0.643466 0.795865,0.643466 h 0.270933 l -1.456264,4.419591 -1.676396,-4.419591 h 0.220133 c 0.304799,0 0.795865,-0.01693 0.795865,-0.626532 0,-0.626533 -0.474133,-0.643466 -0.795865,-0.643466 h -1.930397 c -0.321732,0 -0.795865,0.01693 -0.795865,0.643466 0,0.609598 0.491066,0.626532 0.795865,0.626532 H 52.2143 l 2.370662,5.977455 c -0.06773,0.186266 -0.423333,1.371597 -0.609599,1.744129 -0.338666,0.643466 -0.863598,1.032932 -1.185331,1.032932 0.01693,-0.06773 0.186266,-0.118533 0.186266,-0.372533 0,-0.491066 -0.355599,-0.846665 -0.846665,-0.846665 -0.524932,0 -0.846665,0.355599 -0.846665,0.846665 0,0.761999 0.609599,1.490131 1.490131,1.490131 1.69333,0 2.523062,-2.252129 2.590795,-2.438396 l 2.523061,-7.433718 h 0.4064 c 0.304799,0 0.795865,-0.01693 0.795865,-0.626532 z"
x="13.547134"
y="63.204773"
id="text1392" id="text1392"
inkscape:export-xdpi="188.45" aria-label="lbm py" />
inkscape:export-ydpi="188.45"><tspan
sodipodi:role="line"
id="tspan1390"
x="13.547134"
y="63.204773"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:16.93333244px;font-family:'Latin Modern Mono Light';-inkscape-font-specification:'Latin Modern Mono Light, Bold';fill:#ffffff;stroke-width:0.26458332px">lbm<tspan
style="font-size:2.82222223px"
id="tspan1398"> </tspan>py</tspan></text>
<path <path
style="fill:none;fill-rule:evenodd;stroke:#dddddd;stroke-width:0.84519458;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Send-8-6-9)" style="fill:none;fill-rule:evenodd;stroke:#dddddd;stroke-width:0.84519458;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Send-8-6-9)"
d="M 36.797679,33.475 H 23.568513" d="M 36.797679,33.475 H 23.568513"
......
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
from IPython.display import clear_output from IPython.display import clear_output
from lbmpy.session import * from lbmpy.session import *
from lbmpy.relaxationrates import relaxation_rate_from_lattice_viscosity from lbmpy.relaxationrates import relaxation_rate_from_lattice_viscosity
from pystencils.typing import BasicType, TypedSymbol
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
# Demo: Interpolation Bounce Back Boundaries # Demo: Interpolation Bounce Back Boundaries
In this notebook we present how to use interpolation bounce back boundaries. We will show this on a simple flow around sphere in two dimensions using the linearised bounce back boundary by [Bouzidi et. al.](https://doi.org/10.1063/1.1399290) and the `QuadraticBounceBack` boundary condition by [Geier et. al.](https://www.sciencedirect.com/science/article/pii/S0898122115002126) In this notebook we present how to use interpolation bounce back boundaries. We will show this on a simple flow around sphere in two dimensions using the linearised bounce back boundary by [Bouzidi et. al.](https://doi.org/10.1063/1.1399290) and the `QuadraticBounceBack` boundary condition by [Geier et. al.](https://www.sciencedirect.com/science/article/pii/S0898122115002126)
   
The first part of the demo is similar to other demos / tutorials, so we will not go into detail about these parts The first part of the demo is similar to other demos / tutorials, so we will not go into detail about these parts
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
stencil = LBStencil(Stencil.D2Q9) stencil = LBStencil(Stencil.D2Q9)
reference_length = 30 reference_length = 30
maximal_velocity = 0.05 maximal_velocity = 0.05
reynolds_number = 500 reynolds_number = 500
kinematic_vicosity = (reference_length * maximal_velocity) / reynolds_number kinematic_vicosity = (reference_length * maximal_velocity) / reynolds_number
   
initial_velocity=(maximal_velocity, 0) initial_velocity=(maximal_velocity, 0)
omega = relaxation_rate_from_lattice_viscosity(kinematic_vicosity) omega = relaxation_rate_from_lattice_viscosity(kinematic_vicosity)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
domain_size = (400, 150) domain_size = (400, 150)
dim = len(domain_size) dim = len(domain_size)
circle_mid = np.array((40, 75)) circle_mid = np.array((40, 75))
circle_rad = 10 circle_rad = 10
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
dh = ps.create_data_handling(domain_size=domain_size) dh = ps.create_data_handling(domain_size=domain_size)
   
src = dh.add_array('pdfs', values_per_cell=len(stencil)) src = dh.add_array('pdfs', values_per_cell=len(stencil))
dh.fill(src.name, 0.0, ghost_layers=True) dh.fill(src.name, 0.0, ghost_layers=True)
dst = dh.add_array('pdfs_tmp', values_per_cell=len(stencil)) dst = dh.add_array('pdfs_tmp', values_per_cell=len(stencil))
dh.fill(dst.name, 0.0, ghost_layers=True) dh.fill(dst.name, 0.0, ghost_layers=True)
   
velField = dh.add_array('velField', values_per_cell=dh.dim) velField = dh.add_array('velField', values_per_cell=dh.dim)
dh.fill('velField', 0.0, ghost_layers=True) dh.fill('velField', 0.0, ghost_layers=True)
   
densityField = dh.add_array('densityField', values_per_cell=1) densityField = dh.add_array('densityField', values_per_cell=1)
dh.fill('densityField', 1.0, ghost_layers=True) dh.fill('densityField', 1.0, ghost_layers=True)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
lbm_config = LBMConfig(stencil=stencil, method=Method.CUMULANT, relaxation_rate=omega, lbm_config = LBMConfig(stencil=stencil, method=Method.CUMULANT, relaxation_rate=omega,
compressible=True, output={"velocity": velField, "density": densityField}) compressible=True, output={"velocity": velField, "density": densityField})
   
method = create_lb_method(lbm_config=lbm_config) method = create_lb_method(lbm_config=lbm_config)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
init = pdf_initialization_assignments(method, 1.0, (0.0, 0.0, 0.0), src.center_vector) init = pdf_initialization_assignments(method, 1.0, (0.0, 0.0, 0.0), src.center_vector)
   
ast_init = ps.create_kernel(init, target=dh.default_target) ast_init = ps.create_kernel(init, target=dh.default_target)
kernel_init = ast_init.compile() kernel_init = ast_init.compile()
   
dh.run_kernel(kernel_init) dh.run_kernel(kernel_init)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
lbm_optimisation = LBMOptimisation(symbolic_field=src, symbolic_temporary_field=dst) lbm_optimisation = LBMOptimisation(symbolic_field=src, symbolic_temporary_field=dst)
update = create_lb_update_rule(lb_method=method, update = create_lb_update_rule(lb_method=method,
lbm_config=lbm_config, lbm_config=lbm_config,
lbm_optimisation=lbm_optimisation) lbm_optimisation=lbm_optimisation)
   
ast_kernel = ps.create_kernel(update, target=dh.default_target) ast_kernel = ps.create_kernel(update, target=dh.default_target)
kernel = ast_kernel.compile() kernel = ast_kernel.compile()
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
def set_sphere(x, y, *_): def set_sphere(x, y, *_):
return (x-circle_mid[0])**2 + (y-circle_mid[1])**2 < circle_rad**2 return (x-circle_mid[0])**2 + (y-circle_mid[1])**2 < circle_rad**2
``` ```
   
%% Cell type:markdown id: tags: %% Cell type:markdown id: tags:
   
# Interpolation Boundary Conditions implementation details # Interpolation Boundary Conditions implementation details
   
The most important part of the interpolation bounce back boundary is, that we need to define the distance to the wall for each boundary cell. Thus, we need to provide a Python CallBack function to the boundary that calculates the normalised wall distance `q` for each cell and stores the value in `boundary_data`. The normalised wall distance is defined as: The most important part of the interpolation bounce back boundary is, that we need to define the distance to the wall for each boundary cell. Thus, we need to provide a Python CallBack function to the boundary that calculates the normalised wall distance `q` for each cell and stores the value in `boundary_data`. The normalised wall distance is defined as:
   
$$ $$
\begin{align} \begin{align}
q = \frac{|\boldsymbol{x}_{F} - \boldsymbol{x}_{w}|}{|\boldsymbol{x}_{F} - \boldsymbol{x}_{b}|}. q = \frac{|\boldsymbol{x}_{F} - \boldsymbol{x}_{w}|}{|\boldsymbol{x}_{F} - \boldsymbol{x}_{b}|}.
\end{align} \end{align}
$$ $$
   
The variable `boundary_data` is an index vector that every boundary condition holds internally. For simple boundaries it stores the `x`- and `y`- (and `z` in 3D) coordinate to represent a fluid cell that is next to a boundary cell and the lattice direction `dir` to get from the fluid cell to the boundary cell. The variable `boundary_data` is an index vector that every boundary condition holds internally. For simple boundaries it stores the `x`- and `y`- (and `z` in 3D) coordinate to represent a fluid cell that is next to a boundary cell and the lattice direction `dir` to get from the fluid cell to the boundary cell.
   
In the case of the interpolation boundaries we have an additional value `q` that needs to be stored in each cell. This value needs to be between 0 and 1, otherwise the boundary condition would fall back to a simple bounce back boundary without interpolation. In the case of the interpolation boundaries we have an additional value `q` that needs to be stored in each cell. This value needs to be between 0 and 1, otherwise the boundary condition would fall back to a simple bounce back boundary without interpolation.
   
<center> <center>
<img src="../img/Boundary.svg" alt="Boundary.svg" width="400" height="400"> <img src="../img/Boundary.svg" alt="Boundary.svg" width="400" height="400">
</center> </center>
   
Two dimensional representation of the boundary nodes with the normalised wall distance `q`. The figure was inspired by [Directional lattice Boltzmann boundary conditions](https://doi.org/10.13097/archive-ouverte/unige:160770). Two dimensional representation of the boundary nodes with the normalised wall distance `q`. The figure was inspired by [Directional lattice Boltzmann boundary conditions](https://doi.org/10.13097/archive-ouverte/unige:160770).
   
The linear Bouzidi boundary condition is implemented using the following equation The linear Bouzidi boundary condition is implemented using the following equation
$$ $$
\begin{align} \begin{align}
f_{\bar{i}}^{t + 1}(\boldsymbol{x}_b) = f_{\bar{i}}^{t + 1}(\boldsymbol{x}_b) =
\begin{cases} \begin{cases}
\frac{1}{2q} f_{i}(\boldsymbol{x}_F) + \frac{2q-1}{2q} f_{\bar{i}}(\boldsymbol{x}_{F}), & \text{if } q \geq 0.5\\ \frac{1}{2q} f_{i}(\boldsymbol{x}_F) + \frac{2q-1}{2q} f_{\bar{i}}(\boldsymbol{x}_{F}), & \text{if } q \geq 0.5\\
2 q f_{i}(\boldsymbol{x}_F) + (1 - 2q) f_{i}(\boldsymbol{x}_{FF}), & q > 0 \land q < 0.5 \\ 2 q f_{i}(\boldsymbol{x}_F) + (1 - 2q) f_{i}(\boldsymbol{x}_{FF}), & q > 0 \land q < 0.5 \\
f_{i}(\boldsymbol{x}_F), & q = -1 f_{i}(\boldsymbol{x}_F), & q = -1
\end{cases} \end{cases}
\end{align} \end{align}
$$ $$
   
where $f_{\bar{i}}^{t + 1}(\boldsymbol{x}_b)$ is the missing lattice link that will be needed in the next streaming step. Furthermore, $f_{i}(\boldsymbol{x}_F)$ represents the lattice link flowing in wall direction at $\boldsymbol{x}_{F}$, $f_{\bar{i}}(\boldsymbol{x}_{F})$ is the inverse direction at $\boldsymbol{x}_{F}$ and $f_{i}(\boldsymbol{x}_{FF})$ is the lattice link at the next cell. where $f_{\bar{i}}^{t + 1}(\boldsymbol{x}_b)$ is the missing lattice link that will be needed in the next streaming step. Furthermore, $f_{i}(\boldsymbol{x}_F)$ represents the lattice link flowing in wall direction at $\boldsymbol{x}_{F}$, $f_{\bar{i}}(\boldsymbol{x}_{F})$ is the inverse direction at $\boldsymbol{x}_{F}$ and $f_{i}(\boldsymbol{x}_{FF})$ is the lattice link at the next cell.
   
**The linearised bounce back boundary by [Bouzidi et. al.](https://doi.org/10.1063/1.1399290) needs a second fluid node for the interpolation. This fluid node is not guaranteed to exist. In this case, we implemented a fallback scenario to a simple bounce back scheme with interpolation by setting `q` to -1.** **The linearised bounce back boundary by [Bouzidi et. al.](https://doi.org/10.1063/1.1399290) needs a second fluid node for the interpolation. This fluid node is not guaranteed to exist. In this case, we implemented a fallback scenario to a simple bounce back scheme with interpolation by setting `q` to -1.**
   
To overcome this problem, we can use the `QuadraticBounceBack` boundary condition by [Geier et. al.](https://www.sciencedirect.com/science/article/pii/S0898122115002126). It uses the following rule: To overcome this problem, we can use the `QuadraticBounceBack` boundary condition by [Geier et. al.](https://www.sciencedirect.com/science/article/pii/S0898122115002126). It uses the following rule:
   
$$ $$
\begin{align} \begin{align}
f_{\bar{i}}^{\mathrm{p}}(\boldsymbol{x}_F) &= \frac{f_{\bar{i}}(\boldsymbol{x}_F) - f_{i}(\boldsymbol{x}_F)}{2} + \frac{f_{\bar{i}}(\boldsymbol{x}_F) + f_{i}(\boldsymbol{x}_F)- \omega(f_{\bar{i}}^{\mathrm{eq}}(\boldsymbol{x}_F) + f_{i}^{\mathrm{eq}}(\boldsymbol{x}_F))}{2 - 2\omega} \\ f_{\bar{i}}^{\mathrm{p}}(\boldsymbol{x}_F) &= \frac{f_{\bar{i}}(\boldsymbol{x}_F) - f_{i}(\boldsymbol{x}_F)}{2} + \frac{f_{\bar{i}}(\boldsymbol{x}_F) + f_{i}(\boldsymbol{x}_F)- \omega(f_{\bar{i}}^{\mathrm{eq}}(\boldsymbol{x}_F) + f_{i}^{\mathrm{eq}}(\boldsymbol{x}_F))}{2 - 2\omega} \\
f_{\bar{i}}^{\mathrm{wall}}(\boldsymbol{x}_F) &= (1 - q)f_{\bar{i}}^{\mathrm{p}}(\boldsymbol{x}_F) + q f_{\bar{i}}(\boldsymbol{x}_F) \\ f_{\bar{i}}^{\mathrm{wall}}(\boldsymbol{x}_F) &= (1 - q)f_{\bar{i}}^{\mathrm{p}}(\boldsymbol{x}_F) + q f_{\bar{i}}(\boldsymbol{x}_F) \\
f_{\bar{i}}^{t + 1}(\boldsymbol{x}_b) &= \frac{1}{q+1} f_{\bar{i}}^{\mathrm{wall}}(\boldsymbol{x}_F) + \frac{q}{q+1}f_{i}(\boldsymbol{x}_F) f_{\bar{i}}^{t + 1}(\boldsymbol{x}_b) &= \frac{1}{q+1} f_{\bar{i}}^{\mathrm{wall}}(\boldsymbol{x}_F) + \frac{q}{q+1}f_{i}(\boldsymbol{x}_F)
\end{align} \end{align}
$$ $$
   
In this BC the idea is to realise the interpolation with the pre collision PDF value (marked with the subscript p). Since the pre collision PDF value is not available a simple reconstruction needs to be done. This happens via the BGK rule and the relaxation rate for the fluid viscosity. Thus, this boundary condition needs the equilibrium at the wall. However, the equilibrium at the wall can be calculated inplace from the PDFs. Thus, this BC does not need any further information and can be applied in all cases. Furthermore, we have no more branches with the subgrid distance `q` In this BC the idea is to realise the interpolation with the pre collision PDF value (marked with the subscript p). Since the pre collision PDF value is not available a simple reconstruction needs to be done. This happens via the BGK rule and the relaxation rate for the fluid viscosity. Thus, this boundary condition needs the equilibrium at the wall. However, the equilibrium at the wall can be calculated inplace from the PDFs. Thus, this BC does not need any further information and can be applied in all cases. Furthermore, we have no more branches with the subgrid distance `q`
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
def init_wall_distance(boundary_data, **_): def init_wall_distance(boundary_data, **_):
dim = boundary_data.dim dim = boundary_data.dim
coords = [coord for coord, _ in zip(['x', 'y', 'z'], range(dim))] coords = [coord for coord, _ in zip(['x', 'y', 'z'], range(dim))]
   
for cell in boundary_data.index_array: for cell in boundary_data.index_array:
direction = np.array(stencil[cell['dir']]) direction = np.array(stencil[cell['dir']])
fluid_cell = np.array(tuple([cell[coord] for coord in coords])) - np.array([0.5] * dim) fluid_cell = np.array(tuple([cell[coord] for coord in coords])) - np.array([0.5] * dim)
boundary_cell = fluid_cell + direction boundary_cell = fluid_cell + direction
   
f = fluid_cell - circle_mid f = fluid_cell - circle_mid
d = (boundary_cell - circle_mid) - f d = (boundary_cell - circle_mid) - f
   
a = d.dot(d) a = d.dot(d)
b = 2.0 * ( d.dot(f)) b = 2.0 * ( d.dot(f))
c = f.dot(f) - circle_rad**2 c = f.dot(f) - circle_rad**2
   
bb4ac = b * b - ( 4.0 * a * c ) bb4ac = b * b - ( 4.0 * a * c )
assert bb4ac > 0 assert bb4ac > 0
   
sqrtbb4ac = np.sqrt(bb4ac) sqrtbb4ac = np.sqrt(bb4ac)
q = np.min( [( -b + sqrtbb4ac ) / ( 2.0 * a ), ( -b - sqrtbb4ac ) / ( 2.0 * a )] ) q = np.min( [( -b + sqrtbb4ac ) / ( 2.0 * a ), ( -b - sqrtbb4ac ) / ( 2.0 * a )] )
   
assert q > 0 and q < 1 assert q > 0 and q < 1
   
cell['q'] = q cell['q'] = q
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
bh = LatticeBoltzmannBoundaryHandling(method, dh, src.name, name="bh") bh = LatticeBoltzmannBoundaryHandling(method, dh, src.name, name="bh")
   
inflow = UBB(initial_velocity) inflow = UBB(initial_velocity)
outflow = ExtrapolationOutflow(stencil[4], method) outflow = ExtrapolationOutflow(stencil[4], method)
wall = NoSlip("wall") wall = NoSlip("wall")
# obstacle = NoSlip("obstacle") # obstacle = NoSlip("obstacle")
# obstacle = NoSlipLinearBouzidi("obstacle", init_wall_distance=init_wall_distance) # obstacle = NoSlipLinearBouzidi("obstacle", init_wall_distance=init_wall_distance)
obstacle = QuadraticBounceBack(omega, "obstacle", init_wall_distance=init_wall_distance) obstacle = QuadraticBounceBack(omega, "obstacle", init_wall_distance=init_wall_distance)
   
bh.set_boundary(inflow, slice_from_direction('W', dim)) bh.set_boundary(inflow, slice_from_direction('W', dim))
bh.set_boundary(outflow, slice_from_direction('E', dim)) bh.set_boundary(outflow, slice_from_direction('E', dim))
for direction in ('N', 'S'): for direction in ('N', 'S'):
bh.set_boundary(wall, slice_from_direction(direction, dim)) bh.set_boundary(wall, slice_from_direction(direction, dim))
   
bh.set_boundary(obstacle, mask_callback=set_sphere) bh.set_boundary(obstacle, mask_callback=set_sphere)
   
plt.figure(dpi=200) plt.figure(dpi=200)
plt.boundary_handling(bh) plt.boundary_handling(bh)
``` ```
   
%% Output %% Output
   
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
def timeloop(timeSteps): def timeloop(timeSteps):
for i in range(timeSteps): for i in range(timeSteps):
bh() bh()
dh.run_kernel(kernel) dh.run_kernel(kernel)
dh.swap(src.name, dst.name) dh.swap(src.name, dst.name)
``` ```
   
%% Cell type:code id: tags: %% Cell type:code id: tags:
   
``` python ``` python
mask = np.fromfunction(set_sphere, (domain_size[0], domain_size[1], len(domain_size))) mask = np.fromfunction(set_sphere, (domain_size[0], domain_size[1], len(domain_size)))
if 'is_test_run' not in globals(): if 'is_test_run' not in globals():
timeloop(50000) # initial steps timeloop(50000) # initial steps
   
def run(): def run():
timeloop(50) timeloop(50)
return np.ma.array(dh.gather_array('velField'), mask=mask) return np.ma.array(dh.gather_array('velField'), mask=mask)
   
animation = plt.vector_field_magnitude_animation(run, frames=600, rescale=True) animation = plt.vector_field_magnitude_animation(run, frames=600, rescale=True)
set_display_mode('video') set_display_mode('video')
res = display_animation(animation) res = display_animation(animation)
else: else:
timeloop(10) timeloop(10)
res = None res = None
res res
``` ```
   
%% Output %% Output
   
<IPython.core.display.HTML object> <IPython.core.display.HTML object>
This diff is collapsed.
from __future__ import annotations
from typing import Sequence
from argparse import ArgumentParser
import os
import nox
import subprocess
import re
nox.options.sessions = ["lint", "typecheck"]
def get_cuda_version(session: nox.Session) -> None | tuple[int, ...]:
query_args = ["nvcc", "--version"]
try:
query_result = subprocess.run(query_args, capture_output=True)
except FileNotFoundError:
return None
matches = re.findall(r"release \d+\.\d+", str(query_result.stdout))
if matches:
match = matches[0]
version_string = match.split()[-1]
try:
return tuple(int(v) for v in version_string.split("."))
except ValueError:
pass
session.warn("nvcc was found, but I am unable to determine the CUDA version.")
return None
def install_cupy(
session: nox.Session, cupy_version: str, skip_if_no_cuda: bool = False
):
if cupy_version is not None:
cuda_version = get_cuda_version(session)
if cuda_version is None or cuda_version[0] not in (11, 12):
if skip_if_no_cuda:
session.skip(
"No compatible installation of CUDA found - Need either CUDA 11 or 12"
)
else:
session.warn(
"Running without cupy: no compatbile installation of CUDA found. Need either CUDA 11 or 12."
)
return
cuda_major = cuda_version[0]
cupy_package = f"cupy-cuda{cuda_major}x=={cupy_version}"
session.install(cupy_package)
def check_external_doc_dependencies(session: nox.Session):
dot_args = ["dot", "--version"]
try:
_ = subprocess.run(dot_args, capture_output=True)
except FileNotFoundError:
session.error(
"Unable to build documentation: "
"Command `dot` from the `graphviz` package (https://www.graphviz.org/) is not available"
)
def editable_install(session: nox.Session, opts: Sequence[str] = ()):
if opts:
opts_str = "[" + ",".join(opts) + "]"
else:
opts_str = ""
session.install("-e", f".{opts_str}")
def install_pystencils_master(session: nox.Session):
session.install("git+https://i10git.cs.fau.de/pycodegen/pystencils.git@master")
def install_sympy_master(session: nox.Session):
session.install("--upgrade", "git+https://github.com/sympy/sympy.git@master")
@nox.session(python="3.10", tags=["qa", "code-quality"])
def lint(session: nox.Session):
"""Lint code using flake8"""
session.install("flake8")
session.run("flake8", "src/lbmpy")
@nox.session(python="3.10", tags=["qa", "code-quality"])
def typecheck(session: nox.Session):
"""Run MyPy for static type checking"""
editable_install(session)
session.install("mypy")
session.run("mypy", "src/lbmpy")
def run_testsuite(session: nox.Session, coverage: bool = True):
num_cores = os.cpu_count()
args = [
"pytest",
"-v",
"-n",
str(num_cores),
"-m",
"not longrun",
"--html",
"test-report/index.html",
"--junitxml=report.xml",
]
if coverage:
args += [
"--cov-report=term",
"--cov=.",
]
session.run(*args)
if coverage:
session.run("coverage", "html")
session.run("coverage", "xml")
@nox.session(python=["3.10", "3.11", "3.12", "3.13"])
def testsuite_cpu(session: nox.Session):
install_pystencils_master(session)
editable_install(session, ["alltrafos", "use_cython", "interactive", "tests"])
run_testsuite(session, coverage=False)
@nox.session(python=["3.10", "3.11", "3.12", "3.13"])
@nox.parametrize("cupy_version", ["12", "13"], ids=["cupy12", "cupy13"])
def testsuite_gpu(session: nox.Session, cupy_version: str | None):
install_cupy(session, cupy_version, skip_if_no_cuda=True)
install_pystencils_master(session)
editable_install(session, ["alltrafos", "use_cython", "interactive", "tests"])
run_testsuite(session)
@nox.parametrize("cupy_version", [None, "12", "13"], ids=["cpu", "cupy12", "cupy13"])
@nox.session(python="3.10", tags=["test"])
def testsuite_pystencils2(session: nox.Session, cupy_version: str | None):
if cupy_version is not None:
install_cupy(session, cupy_version, skip_if_no_cuda=True)
session.install(
"git+https://i10git.cs.fau.de/pycodegen/pystencils.git@v2.0-dev"
)
editable_install(session, ["alltrafos", "use_cython", "interactive", "tests"])
run_testsuite(session)
@nox.session
def quicktest(session: nox.Session):
parser = ArgumentParser()
parser.add_argument(
"--sympy-master", action="store_true", help="Use latest SymPy master revision"
)
args = parser.parse_args(session.posargs)
install_pystencils_master(session)
editable_install(session)
if args.sympy_master:
install_sympy_master(session)
session.run("python", "quicktest.py")
...@@ -11,7 +11,7 @@ authors = [ ...@@ -11,7 +11,7 @@ authors = [
] ]
license = { file = "COPYING.txt" } license = { file = "COPYING.txt" }
requires-python = ">=3.10" requires-python = ">=3.10"
dependencies = ["pystencils>=1.3", "sympy>=1.6,<=1.11.1", "numpy>=1.8.0", "appdirs", "joblib"] dependencies = ["pystencils>=1.3", "sympy>=1.12", "numpy>=1.8.0", "appdirs", "joblib", "packaging"]
classifiers = [ classifiers = [
"Development Status :: 4 - Beta", "Development Status :: 4 - Beta",
"Framework :: Jupyter", "Framework :: Jupyter",
......
...@@ -3,7 +3,12 @@ testpaths = src tests doc/notebooks ...@@ -3,7 +3,12 @@ testpaths = src tests doc/notebooks
pythonpath = src pythonpath = src
python_files = test_*.py *_test.py scenario_*.py python_files = test_*.py *_test.py scenario_*.py
norecursedirs = *.egg-info .git .cache .ipynb_checkpoints htmlcov norecursedirs = *.egg-info .git .cache .ipynb_checkpoints htmlcov
addopts = --doctest-modules --durations=20 --cov-config pytest.ini addopts =
--doctest-modules --durations=20
--cov-config pytest.ini
--ignore=src/lbmpy/custom_code_nodes.py
--ignore=src/lbmpy/lookup_tables.py
--ignore=src/lbmpy/phasefield_allen_cahn/contact_angle.py
markers = markers =
longrun: tests only run at night since they have large execution time longrun: tests only run at night since they have large execution time
notebook: mark for notebooks notebook: mark for notebooks
...@@ -24,7 +29,10 @@ omit = doc/* ...@@ -24,7 +29,10 @@ omit = doc/*
setup.py setup.py
conftest.py conftest.py
versioneer.py versioneer.py
quicktest.py
noxfile.py
src/lbmpy/_version.py src/lbmpy/_version.py
src/lbmpy/_compat.py
venv/ venv/
[report] [report]
......
...@@ -12,6 +12,7 @@ from .lbstep import LatticeBoltzmannStep ...@@ -12,6 +12,7 @@ from .lbstep import LatticeBoltzmannStep
from .macroscopic_value_kernels import ( from .macroscopic_value_kernels import (
pdf_initialization_assignments, pdf_initialization_assignments,
macroscopic_values_getter, macroscopic_values_getter,
strain_rate_tensor_getter,
compile_macroscopic_values_getter, compile_macroscopic_values_getter,
compile_macroscopic_values_setter, compile_macroscopic_values_setter,
create_advanced_velocity_setter_collision_rule, create_advanced_velocity_setter_collision_rule,
...@@ -42,6 +43,7 @@ __all__ = [ ...@@ -42,6 +43,7 @@ __all__ = [
"LatticeBoltzmannStep", "LatticeBoltzmannStep",
"pdf_initialization_assignments", "pdf_initialization_assignments",
"macroscopic_values_getter", "macroscopic_values_getter",
"strain_rate_tensor_getter",
"compile_macroscopic_values_getter", "compile_macroscopic_values_getter",
"compile_macroscopic_values_setter", "compile_macroscopic_values_setter",
"create_advanced_velocity_setter_collision_rule", "create_advanced_velocity_setter_collision_rule",
......
from pystencils import __version__ as ps_version
# Determine if we're running pystencils 1.x or 2.x
version_tokes = ps_version.split(".")
PYSTENCILS_VERSION_MAJOR = int(version_tokes[0])
IS_PYSTENCILS_2 = PYSTENCILS_VERSION_MAJOR == 2
if IS_PYSTENCILS_2:
from pystencils.defaults import DEFAULTS
def get_loop_counter_symbol(coord: int):
return DEFAULTS.spatial_counters[coord]
def get_supported_instruction_sets():
from pystencils import Target
vector_targets = Target.available_vector_cpu_targets()
isas = []
for target in vector_targets:
tokens = target.name.split("_")
isas.append(tokens[-1].lower())
return isas
else:
from pystencils.backends.simd_instruction_sets import (
get_supported_instruction_sets as get_supported_instruction_sets_,
)
get_supported_instruction_sets = get_supported_instruction_sets_
def get_loop_counter_symbol(coord: int):
from pystencils.astnodes import LoopOverCoordinate
return LoopOverCoordinate.get_loop_counter_symbol(coord)
def import_guard_pystencils1(feature):
if IS_PYSTENCILS_2:
raise ImportError(
f"The following feature is not yet available when running pystencils 2.x: {feature}"
)
return True
import itertools import itertools
from pystencils import CreateKernelConfig, Field, Assignment, AssignmentCollection from pystencils import CreateKernelConfig, Field, Assignment, AssignmentCollection, Target
from pystencils.slicing import shift_slice, get_slice_before_ghost_layer, normalize_slice from pystencils.slicing import (
from lbmpy.advanced_streaming.utility import is_inplace, get_accessor, numeric_index, \ shift_slice,
Timestep, get_timesteps, numeric_offsets get_slice_before_ghost_layer,
normalize_slice,
)
from lbmpy.advanced_streaming.utility import (
is_inplace,
get_accessor,
numeric_index,
Timestep,
get_timesteps,
numeric_offsets,
)
from pystencils.datahandling import SerialDataHandling from pystencils.datahandling import SerialDataHandling
from pystencils.enums import Target
from itertools import chain from itertools import chain
class LBMPeriodicityHandling: class LBMPeriodicityHandling:
def __init__(self, stencil, data_handling, pdf_field_name, def __init__(
streaming_pattern='pull', ghost_layers=1, self,
cupy_direct_copy=True): stencil,
data_handling,
pdf_field_name,
streaming_pattern="pull",
ghost_layers=1,
cupy_direct_copy=True,
):
""" """
Periodicity Handling for Lattice Boltzmann Streaming. Periodicity Handling for Lattice Boltzmann Streaming.
**On the usage with cuda:** **On the usage with cuda:**
- cupy allows the copying of sliced arrays within device memory using the numpy syntax, - cupy allows the copying of sliced arrays within device memory using the numpy syntax,
e.g. `dst[:,0] = src[:,-1]`. In this implementation, this is the default for periodicity e.g. `dst[:,0] = src[:,-1]`. In this implementation, this is the default for periodicity
handling. Alternatively, if you set `cupy_direct_copy=False`, GPU kernels are generated and handling. Alternatively, if you set `cupy_direct_copy=False`, GPU kernels are generated and
compiled. The compiled kernels are almost twice as fast in execution as cupy array copying, compiled. The compiled kernels are almost twice as fast in execution as cupy array copying,
but especially for large stencils like D3Q27, their compilation can take up to 20 seconds. but especially for large stencils like D3Q27, their compilation can take up to 20 seconds.
Choose your weapon depending on your use case. Choose your weapon depending on your use case.
""" """
if not isinstance(data_handling, SerialDataHandling): if not isinstance(data_handling, SerialDataHandling):
raise ValueError('Only serial data handling is supported!') raise ValueError("Only serial data handling is supported!")
self.stencil = stencil self.stencil = stencil
self.dim = stencil.D self.dim = stencil.D
...@@ -56,12 +71,16 @@ class LBMPeriodicityHandling: ...@@ -56,12 +71,16 @@ class LBMPeriodicityHandling:
self.comm_slices = [] self.comm_slices = []
timesteps = get_timesteps(streaming_pattern) timesteps = get_timesteps(streaming_pattern)
for timestep in timesteps: for timestep in timesteps:
slices_per_comm_dir = get_communication_slices(stencil=stencil, slices_per_comm_dir = get_communication_slices(
comm_stencil=copy_directions, stencil=stencil,
streaming_pattern=streaming_pattern, comm_stencil=copy_directions,
prev_timestep=timestep, streaming_pattern=streaming_pattern,
ghost_layers=ghost_layers) prev_timestep=timestep,
self.comm_slices.append(list(chain.from_iterable(v for k, v in slices_per_comm_dir.items()))) ghost_layers=ghost_layers,
)
self.comm_slices.append(
list(chain.from_iterable(v for k, v in slices_per_comm_dir.items()))
)
if self.target == Target.GPU and not cupy_direct_copy: if self.target == Target.GPU and not cupy_direct_copy:
self.device_copy_kernels = list() self.device_copy_kernels = list()
...@@ -81,11 +100,11 @@ class LBMPeriodicityHandling: ...@@ -81,11 +100,11 @@ class LBMPeriodicityHandling:
arr[dst] = arr[src] arr[dst] = arr[src]
def _compile_copy_kernels(self, timestep): def _compile_copy_kernels(self, timestep):
assert self.target == Target.GPU
pdf_field = self.dh.fields[self.pdf_field_name] pdf_field = self.dh.fields[self.pdf_field_name]
kernels = [] kernels = []
for src, dst in self.comm_slices[timestep.idx]: for src, dst in self.comm_slices[timestep.idx]:
kernels.append( kernels.append(periodic_pdf_gpu_copy_kernel(pdf_field, src, dst))
periodic_pdf_copy_kernel(pdf_field, src, dst, target=self.target))
return kernels return kernels
def _periodicity_handling_gpu(self, prev_timestep): def _periodicity_handling_gpu(self, prev_timestep):
...@@ -100,7 +119,12 @@ class LBMPeriodicityHandling: ...@@ -100,7 +119,12 @@ class LBMPeriodicityHandling:
def get_communication_slices( def get_communication_slices(
stencil, comm_stencil=None, streaming_pattern='pull', prev_timestep=Timestep.BOTH, ghost_layers=1): stencil,
comm_stencil=None,
streaming_pattern="pull",
prev_timestep=Timestep.BOTH,
ghost_layers=1,
):
""" """
Return the source and destination slices for periodicity handling or communication between blocks. Return the source and destination slices for periodicity handling or communication between blocks.
...@@ -116,7 +140,9 @@ def get_communication_slices( ...@@ -116,7 +140,9 @@ def get_communication_slices(
if comm_stencil is None: if comm_stencil is None:
comm_stencil = itertools.product(*([-1, 0, 1] for _ in range(stencil.D))) comm_stencil = itertools.product(*([-1, 0, 1] for _ in range(stencil.D)))
pdfs = Field.create_generic('pdfs', spatial_dimensions=len(stencil[0]), index_shape=(stencil.Q,)) pdfs = Field.create_generic(
"pdfs", spatial_dimensions=len(stencil[0]), index_shape=(stencil.Q,)
)
write_accesses = get_accessor(streaming_pattern, prev_timestep).write(pdfs, stencil) write_accesses = get_accessor(streaming_pattern, prev_timestep).write(pdfs, stencil)
slices_per_comm_direction = dict() slices_per_comm_direction = dict()
...@@ -130,7 +156,9 @@ def get_communication_slices( ...@@ -130,7 +156,9 @@ def get_communication_slices(
d = stencil.index(streaming_dir) d = stencil.index(streaming_dir)
write_index = numeric_index(write_accesses[d])[0] write_index = numeric_index(write_accesses[d])[0]
origin_slice = get_slice_before_ghost_layer(comm_dir, ghost_layers=ghost_layers, thickness=1) origin_slice = get_slice_before_ghost_layer(
comm_dir, ghost_layers=ghost_layers, thickness=1
)
src_slice = _fix_length_one_slices(origin_slice) src_slice = _fix_length_one_slices(origin_slice)
write_offsets = numeric_offsets(write_accesses[d]) write_offsets = numeric_offsets(write_accesses[d])
...@@ -138,13 +166,15 @@ def get_communication_slices( ...@@ -138,13 +166,15 @@ def get_communication_slices(
# TODO: this is just a hotfix. _trim_slice_in_direction breaks FreeSlip BC with adjacent periodic side # TODO: this is just a hotfix. _trim_slice_in_direction breaks FreeSlip BC with adjacent periodic side
if streaming_pattern != "pull": if streaming_pattern != "pull":
src_slice = shift_slice(_trim_slice_in_direction(src_slice, tangential_dir), write_offsets) src_slice = shift_slice(
_trim_slice_in_direction(src_slice, tangential_dir), write_offsets
)
neighbour_transform = _get_neighbour_transform(comm_dir, ghost_layers) neighbour_transform = _get_neighbour_transform(comm_dir, ghost_layers)
dst_slice = shift_slice(src_slice, neighbour_transform) dst_slice = shift_slice(src_slice, neighbour_transform)
src_slice = src_slice + (write_index, ) src_slice = src_slice + (write_index,)
dst_slice = dst_slice + (write_index, ) dst_slice = dst_slice + (write_index,)
slices_for_dir.append((src_slice, dst_slice)) slices_for_dir.append((src_slice, dst_slice))
...@@ -152,10 +182,10 @@ def get_communication_slices( ...@@ -152,10 +182,10 @@ def get_communication_slices(
return slices_per_comm_direction return slices_per_comm_direction
def periodic_pdf_copy_kernel(pdf_field, src_slice, dst_slice, def periodic_pdf_gpu_copy_kernel(pdf_field, src_slice, dst_slice, domain_size=None):
domain_size=None, target=Target.GPU): """Generate a GPU kernel which copies all values from one slice of a field
"""Copies a rectangular array slice onto another non-overlapping array slice""" to another non-overlapping slice."""
from pystencils.gpucuda.kernelcreation import create_cuda_kernel from pystencils import create_kernel
pdf_idx = src_slice[-1] pdf_idx = src_slice[-1]
assert isinstance(pdf_idx, int), "PDF index needs to be an integer constant" assert isinstance(pdf_idx, int), "PDF index needs to be an integer constant"
...@@ -176,18 +206,28 @@ def periodic_pdf_copy_kernel(pdf_field, src_slice, dst_slice, ...@@ -176,18 +206,28 @@ def periodic_pdf_copy_kernel(pdf_field, src_slice, dst_slice,
def _stop(s): def _stop(s):
return s.stop if isinstance(s, slice) else s return s.stop if isinstance(s, slice) else s
offset = [_start(s1) - _start(s2) for s1, s2 in zip(normalized_from_slice, normalized_to_slice)] offset = [
assert offset == [_stop(s1) - _stop(s2) for s1, s2 in zip(normalized_from_slice, normalized_to_slice)], \ _start(s1) - _start(s2)
"Slices have to have same size" for s1, s2 in zip(normalized_from_slice, normalized_to_slice)
]
copy_eq = AssignmentCollection(main_assignments=[Assignment(pdf_field(pdf_idx), pdf_field[tuple(offset)](pdf_idx))]) assert offset == [
config = CreateKernelConfig(iteration_slice=dst_slice, skip_independence_check=True) _stop(s1) - _stop(s2)
ast = create_cuda_kernel(copy_eq, config=config) for s1, s2 in zip(normalized_from_slice, normalized_to_slice)
if target == Target.GPU: ], "Slices have to have same size"
from pystencils.gpucuda import make_python_function
return make_python_function(ast) copy_eq = AssignmentCollection(
else: main_assignments=[
raise ValueError('Invalid target:', target) Assignment(pdf_field(pdf_idx), pdf_field[tuple(offset)](pdf_idx))
]
)
config = CreateKernelConfig(
iteration_slice=dst_slice,
skip_independence_check=True,
target=Target.GPU,
)
ast = create_kernel(copy_eq, config=config)
return ast.compile()
def _extend_dir(direction): def _extend_dir(direction):
...@@ -196,10 +236,10 @@ def _extend_dir(direction): ...@@ -196,10 +236,10 @@ def _extend_dir(direction):
elif direction[0] == 0: elif direction[0] == 0:
for d in [-1, 0, 1]: for d in [-1, 0, 1]:
for rest in _extend_dir(direction[1:]): for rest in _extend_dir(direction[1:]):
yield (d, ) + rest yield (d,) + rest
else: else:
for rest in _extend_dir(direction[1:]): for rest in _extend_dir(direction[1:]):
yield (direction[0], ) + rest yield (direction[0],) + rest
def _get_neighbour_transform(direction, ghost_layers): def _get_neighbour_transform(direction, ghost_layers):
......
...@@ -2,10 +2,17 @@ import numpy as np ...@@ -2,10 +2,17 @@ import numpy as np
import sympy as sp import sympy as sp
import pystencils as ps import pystencils as ps
from pystencils.typing import TypedSymbol, create_type from .._compat import IS_PYSTENCILS_2
from lbmpy.advanced_streaming.utility import get_accessor, inverse_dir_index, is_inplace, Timestep
from lbmpy.custom_code_nodes import TranslationArraysNode if IS_PYSTENCILS_2:
from pystencils import TypedSymbol, create_type
from pystencils.types.quick import Arr
from lbmpy.lookup_tables import TranslationArraysNode
else:
from pystencils.typing import TypedSymbol, create_type
from ..custom_code_nodes import TranslationArraysNode
from lbmpy.advanced_streaming.utility import get_accessor, inverse_dir_index, is_inplace, Timestep
from itertools import product from itertools import product
...@@ -64,13 +71,21 @@ class BetweenTimestepsIndexing: ...@@ -64,13 +71,21 @@ class BetweenTimestepsIndexing:
assert f_dir in ['in', 'out'] assert f_dir in ['in', 'out']
inv = '_inv' if inverse else '' inv = '_inv' if inverse else ''
name = f"f_{f_dir}{inv}_dir_idx" name = f"f_{f_dir}{inv}_dir_idx"
return TypedSymbol(name, self._index_dtype) if IS_PYSTENCILS_2:
return TypedSymbol(name, Arr(self._index_dtype, self._q))
else:
return TypedSymbol(name, self._index_dtype)
def _offset_array_symbols(self, f_dir, inverse): def _offset_array_symbols(self, f_dir, inverse):
assert f_dir in ['in', 'out'] assert f_dir in ['in', 'out']
inv = '_inv' if inverse else '' inv = '_inv' if inverse else ''
name_base = f"f_{f_dir}{inv}_offsets_" name_base = f"f_{f_dir}{inv}_offsets_"
symbols = [TypedSymbol(name_base + d, self._index_dtype) for d in self._coordinate_names]
if IS_PYSTENCILS_2:
symbols = [TypedSymbol(name_base + d, Arr(self._index_dtype, self._q)) for d in self._coordinate_names]
else:
symbols = [TypedSymbol(name_base + d, self._index_dtype) for d in self._coordinate_names]
return symbols return symbols
def _array_symbols(self, f_dir, inverse, index): def _array_symbols(self, f_dir, inverse, index):
...@@ -169,15 +184,25 @@ class BetweenTimestepsIndexing: ...@@ -169,15 +184,25 @@ class BetweenTimestepsIndexing:
indices, offsets = self._get_translated_indices_and_offsets(f_dir, inv) indices, offsets = self._get_translated_indices_and_offsets(f_dir, inv)
index_array_symbol = self._index_array_symbol(f_dir, inv) index_array_symbol = self._index_array_symbol(f_dir, inv)
symbols_defined.add(index_array_symbol) symbols_defined.add(index_array_symbol)
array_content.append((self._index_dtype, index_array_symbol.name, indices))
if IS_PYSTENCILS_2:
array_content.append((index_array_symbol, indices))
else:
array_content.append((self._index_dtype, index_array_symbol.name, indices))
for f_dir, inv in self._required_offset_arrays: for f_dir, inv in self._required_offset_arrays:
indices, offsets = self._get_translated_indices_and_offsets(f_dir, inv) indices, offsets = self._get_translated_indices_and_offsets(f_dir, inv)
offset_array_symbols = self._offset_array_symbols(f_dir, inv) offset_array_symbols = self._offset_array_symbols(f_dir, inv)
symbols_defined |= set(offset_array_symbols) symbols_defined |= set(offset_array_symbols)
for d, arrsymb in enumerate(offset_array_symbols): for d, arrsymb in enumerate(offset_array_symbols):
array_content.append((self._offsets_dtype, arrsymb.name, offsets[d])) if IS_PYSTENCILS_2:
array_content.append((arrsymb, offsets[d]))
else:
array_content.append((self._offsets_dtype, arrsymb.name, offsets[d]))
return TranslationArraysNode(array_content, symbols_defined) if IS_PYSTENCILS_2:
return TranslationArraysNode(array_content)
else:
return TranslationArraysNode(array_content, symbols_defined)
# end class AdvancedStreamingIndexing # end class AdvancedStreamingIndexing
import sympy as sp import sympy as sp
from .._compat import IS_PYSTENCILS_2
from lbmpy.advanced_streaming.indexing import BetweenTimestepsIndexing from lbmpy.advanced_streaming.indexing import BetweenTimestepsIndexing
from lbmpy.advanced_streaming.utility import Timestep, get_accessor from lbmpy.advanced_streaming.utility import Timestep, get_accessor
from lbmpy.custom_code_nodes import LbmWeightInfo
from pystencils.boundaries.boundaryhandling import BoundaryOffsetInfo from pystencils.boundaries.boundaryhandling import BoundaryOffsetInfo
from pystencils.assignment import Assignment from pystencils import Assignment
from pystencils.astnodes import Block, Conditional, LoopOverCoordinate, SympyAssignment from pystencils.simp import AssignmentCollection, sympy_cse_on_assignment_list
from pystencils.simp.assignment_collection import AssignmentCollection
from pystencils.simp.simplifications import sympy_cse_on_assignment_list
from pystencils.stencil import inverse_direction from pystencils.stencil import inverse_direction
from pystencils.sympyextensions import fast_subs from pystencils.sympyextensions import fast_subs
if IS_PYSTENCILS_2:
from lbmpy.lookup_tables import LbmWeightInfo
else:
from lbmpy.custom_code_nodes import LbmWeightInfo
from pystencils.astnodes import Block, Conditional, LoopOverCoordinate, SympyAssignment # TODO replace
def direction_indices_in_direction(direction, stencil): def direction_indices_in_direction(direction, stencil):
for i, offset in enumerate(stencil): for i, offset in enumerate(stencil):
...@@ -58,6 +63,9 @@ def border_conditions(direction, field, ghost_layers=1): ...@@ -58,6 +63,9 @@ def border_conditions(direction, field, ghost_layers=1):
def boundary_conditional(boundary, direction, streaming_pattern, prev_timestep, lb_method, output_field, cse=False): def boundary_conditional(boundary, direction, streaming_pattern, prev_timestep, lb_method, output_field, cse=False):
if IS_PYSTENCILS_2:
raise NotImplementedError("In-Kernel Boundaries are not yet available on pystencils 2.0")
stencil = lb_method.stencil stencil = lb_method.stencil
dir_indices = direction_indices_in_direction(direction, stencil) dir_indices = direction_indices_in_direction(direction, stencil)
...@@ -67,7 +75,7 @@ def boundary_conditional(boundary, direction, streaming_pattern, prev_timestep, ...@@ -67,7 +75,7 @@ def boundary_conditional(boundary, direction, streaming_pattern, prev_timestep,
assignments = [] assignments = []
for direction_idx in dir_indices: for direction_idx in dir_indices:
rule = boundary(f_out, f_in, direction_idx, inv_dir, lb_method, index_field=None) rule = boundary(f_out, f_in, direction_idx, inv_dir, lb_method, index_field=None, force_vector=None)
# rhs: replace f_out by post collision symbols. # rhs: replace f_out by post collision symbols.
rhs_substitutions = {f_out(i): sym for i, sym in enumerate(lb_method.post_collision_pdf_symbols)} rhs_substitutions = {f_out(i): sym for i, sym in enumerate(lb_method.post_collision_pdf_symbols)}
......
from dataclasses import replace
import numpy as np import numpy as np
from pystencils import Assignment, CreateKernelConfig, create_kernel, Field, Target from pystencils import Assignment, CreateKernelConfig, create_kernel, Field, Target, FieldType
from pystencils.boundaries import BoundaryHandling from pystencils.boundaries import BoundaryHandling
from pystencils.boundaries.createindexlist import numpy_data_type_for_boundary_object from pystencils.boundaries.createindexlist import numpy_data_type_for_boundary_object
from pystencils.simp import add_subexpressions_for_field_reads from pystencils.simp import add_subexpressions_for_field_reads
...@@ -9,6 +10,11 @@ from pystencils.stencil import inverse_direction ...@@ -9,6 +10,11 @@ from pystencils.stencil import inverse_direction
from lbmpy.advanced_streaming.indexing import BetweenTimestepsIndexing from lbmpy.advanced_streaming.indexing import BetweenTimestepsIndexing
from lbmpy.advanced_streaming.utility import is_inplace, Timestep, AccessPdfValues from lbmpy.advanced_streaming.utility import is_inplace, Timestep, AccessPdfValues
from .._compat import IS_PYSTENCILS_2
if IS_PYSTENCILS_2:
from pystencils.types import PsNumericType
class LatticeBoltzmannBoundaryHandling(BoundaryHandling): class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
""" """
...@@ -18,13 +24,16 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling): ...@@ -18,13 +24,16 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
""" """
def __init__(self, lb_method, data_handling, pdf_field_name, streaming_pattern='pull', def __init__(self, lb_method, data_handling, pdf_field_name, streaming_pattern='pull',
name="boundary_handling", flag_interface=None, target=Target.CPU, openmp=False): name="boundary_handling", flag_interface=None, target=Target.CPU, openmp=False, **kwargs):
self._lb_method = lb_method self._lb_method = lb_method
self._streaming_pattern = streaming_pattern self._streaming_pattern = streaming_pattern
self._inplace = is_inplace(streaming_pattern) self._inplace = is_inplace(streaming_pattern)
self._prev_timestep = None self._prev_timestep = None
super(LatticeBoltzmannBoundaryHandling, self).__init__(data_handling, pdf_field_name, lb_method.stencil, super(LatticeBoltzmannBoundaryHandling, self).__init__(
name, flag_interface, target, openmp) data_handling, pdf_field_name, lb_method.stencil,
name, flag_interface, target=target, openmp=openmp,
**kwargs
)
# ------------------------- Overridden methods of pystencils.BoundaryHandling ------------------------- # ------------------------- Overridden methods of pystencils.BoundaryHandling -------------------------
...@@ -50,7 +59,7 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling): ...@@ -50,7 +59,7 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
def _add_inplace_boundary(self, boundary_obj, flag=None): def _add_inplace_boundary(self, boundary_obj, flag=None):
if boundary_obj not in self._boundary_object_to_boundary_info: if boundary_obj not in self._boundary_object_to_boundary_info:
sym_index_field = Field.create_generic('indexField', spatial_dimensions=1, sym_index_field = Field.create_generic('indexField', spatial_dimensions=1, field_type=FieldType.INDEXED,
dtype=numpy_data_type_for_boundary_object(boundary_obj, self.dim)) dtype=numpy_data_type_for_boundary_object(boundary_obj, self.dim))
ast_even = self._create_boundary_kernel(self._data_handling.fields[self._field_name], sym_index_field, ast_even = self._create_boundary_kernel(self._data_handling.fields[self._field_name], sym_index_field,
...@@ -65,10 +74,15 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling): ...@@ -65,10 +74,15 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
return self._boundary_object_to_boundary_info[boundary_obj].flag return self._boundary_object_to_boundary_info[boundary_obj].flag
def _create_boundary_kernel(self, symbolic_field, symbolic_index_field, boundary_obj, prev_timestep=Timestep.BOTH): def _create_boundary_kernel(self, symbolic_field, symbolic_index_field, boundary_obj, prev_timestep=Timestep.BOTH):
if IS_PYSTENCILS_2:
additional_args = {"default_dtype": self._default_dtype}
else:
additional_args = dict()
return create_lattice_boltzmann_boundary_kernel( return create_lattice_boltzmann_boundary_kernel(
symbolic_field, symbolic_index_field, self._lb_method, boundary_obj, symbolic_field, symbolic_index_field, self._lb_method, boundary_obj,
prev_timestep=prev_timestep, streaming_pattern=self._streaming_pattern, prev_timestep=prev_timestep, streaming_pattern=self._streaming_pattern,
target=self._target, cpu_openmp=self._openmp) target=self._target, cpu_openmp=self._openmp, **additional_args)
class InplaceStreamingBoundaryInfo(object): class InplaceStreamingBoundaryInfo(object):
...@@ -156,33 +170,80 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling): ...@@ -156,33 +170,80 @@ class LatticeBoltzmannBoundaryHandling(BoundaryHandling):
def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method, boundary_functor, def create_lattice_boltzmann_boundary_kernel(pdf_field, index_field, lb_method, boundary_functor,
prev_timestep=Timestep.BOTH, streaming_pattern='pull', prev_timestep=Timestep.BOTH, streaming_pattern='pull',
target=Target.CPU, **kernel_creation_args): target=Target.CPU, force_vector=None, **kernel_creation_args):
from .._compat import IS_PYSTENCILS_2
indexing = BetweenTimestepsIndexing( indexing = BetweenTimestepsIndexing(
pdf_field, lb_method.stencil, prev_timestep, streaming_pattern, np.int32, np.int32) pdf_field, lb_method.stencil, prev_timestep, streaming_pattern, np.int32, np.int32)
dim = lb_method.stencil.D
f_out, f_in = indexing.proxy_fields f_out, f_in = indexing.proxy_fields
dir_symbol = indexing.dir_symbol dir_symbol = indexing.dir_symbol
inv_dir = indexing.inverse_dir_symbol inv_dir = indexing.inverse_dir_symbol
boundary_assignments = boundary_functor(f_out, f_in, dir_symbol, inv_dir, lb_method, index_field) if IS_PYSTENCILS_2:
boundary_assignments = indexing.substitute_proxies(boundary_assignments) from pystencils.types.quick import SInt
config = CreateKernelConfig(
index_field=index_field,
target=target,
index_dtype=SInt(32),
skip_independence_check=True,
**kernel_creation_args
)
default_data_type: PsNumericType = config.get_option("default_dtype")
if force_vector is None:
force_vector_type = np.dtype([(f"F_{i}", default_data_type.numpy_dtype) for i in range(dim)], align=True)
force_vector = Field.create_generic('force_vector', spatial_dimensions=1,
dtype=force_vector_type, field_type=FieldType.INDEXED)
boundary_assignments = boundary_functor(f_out, f_in, dir_symbol, inv_dir, lb_method, index_field, force_vector)
boundary_assignments = indexing.substitute_proxies(boundary_assignments)
if pdf_field.dtype != default_data_type:
boundary_assignments = add_subexpressions_for_field_reads(boundary_assignments, data_type=default_data_type)
elements: list[Assignment] = []
index_arrs_node = indexing.create_code_node()
elements += index_arrs_node.get_array_declarations()
for node in boundary_functor.get_additional_code_nodes(lb_method)[::-1]:
elements += node.get_array_declarations()
elements += [Assignment(dir_symbol, index_field[0]('dir'))]
elements += boundary_assignments.all_assignments
kernel = create_kernel(elements, config=config)
return kernel
else:
config = CreateKernelConfig(index_fields=[index_field], target=target, default_number_int="int32",
skip_independence_check=True, **kernel_creation_args)
default_data_type = config.data_type.default_factory()
if force_vector is None:
force_vector_type = np.dtype([(f"F_{i}", default_data_type.c_name) for i in range(dim)], align=True)
force_vector = Field.create_generic('force_vector', spatial_dimensions=1,
dtype=force_vector_type, field_type=FieldType.INDEXED)
config = replace(config, index_fields=[index_field, force_vector])
config = CreateKernelConfig(index_fields=[index_field], target=target, default_number_int="int32", boundary_assignments = boundary_functor(f_out, f_in, dir_symbol, inv_dir, lb_method, index_field, force_vector)
skip_independence_check=True, **kernel_creation_args) boundary_assignments = indexing.substitute_proxies(boundary_assignments)
default_data_type = config.data_type.default_factory() if pdf_field.dtype != default_data_type:
if pdf_field.dtype != default_data_type: boundary_assignments = add_subexpressions_for_field_reads(boundary_assignments, data_type=default_data_type)
boundary_assignments = add_subexpressions_for_field_reads(boundary_assignments, data_type=default_data_type)
elements = [Assignment(dir_symbol, index_field[0]('dir'))] elements = [Assignment(dir_symbol, index_field[0]('dir'))]
elements += boundary_assignments.all_assignments elements += boundary_assignments.all_assignments
kernel = create_kernel(elements, config=config) kernel = create_kernel(elements, config=config)
# Code Elements ahead of the loop # Code Elements ahead of the loop
index_arrs_node = indexing.create_code_node() index_arrs_node = indexing.create_code_node()
for node in boundary_functor.get_additional_code_nodes(lb_method)[::-1]: for node in boundary_functor.get_additional_code_nodes(lb_method)[::-1]:
kernel.body.insert_front(node) kernel.body.insert_front(node)
kernel.body.insert_front(index_arrs_node) kernel.body.insert_front(index_arrs_node)
return kernel return kernel