diff --git a/examples/EnvSetup/CMakeLists.txt b/examples/EnvSetup/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..36d2851483f0469106030983921772cb5a658dc9 --- /dev/null +++ b/examples/EnvSetup/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required( VERSION 3.24 ) +project( <your-project-name> ) + +include(FetchContent) + +FetchContent_Declare( + walberla + GIT_REPOSITORY https://i10git.cs.fau.de/walberla/walberla.git +) + +FetchContent_Declare( + sfg-walberla + GIT_REPOSITORY https://i10git.cs.fau.de/da15siwa/sfg-walberla.git +) + +FetchContent_MakeAvailable(walberla sfg-walberla) diff --git a/examples/EnvSetup/EnvSetup.md b/examples/EnvSetup/EnvSetup.md new file mode 100644 index 0000000000000000000000000000000000000000..7088ef48d5fcfe1c83265d7c6cd06688943f0489 --- /dev/null +++ b/examples/EnvSetup/EnvSetup.md @@ -0,0 +1,101 @@ +(env_setup)= +# Environment and Project Setup + +This chapter attempts to briefly explain the necessary steps to get next-gen code generation +working with your waLBerla-based project. +This involves two steps: + - Set up a Python environment with the required pycodegen packages; + - Set up a CMake build system including the latest versions of *walberla* and *sfg-walberla*. + +## Prequesites + +You are going to need at least +- a C++ compiler supporting at least C++17; +- a Python installation of version >= 3.10; +- a CMake installation of version >= 3.24; +- an up-to-date installation of Git. + +Also, the following optional dependencies are highly recommended: +- clang-format for prettier code generator output + +## Project Setup + +To get started, create a new, empty directory +(we are going to use `myproject` as a placeholder for your project directory). + +### Python Environment + +WaLBerla next-gen codegen relies on a set of Python packages that have not been released yet. +To simplify their installation, download our {download}`requirements.txt` file and place it in your +project directory. +Then, create and activate a new [Python virtual environment][py-venv] in your project folder: + +```bash +python -m venv .venv +source .venv/bin/activate +``` + +Next, install the required packages from the requirements file: + +```bash +export PIP_REQUIRE_VIRTUALENV=true +pip install -r requirements.txt +``` + +:::{note} +We set the `PIP_REQUIRE_VIRTUALENV` environment variable as a fail-save, +to make sure that pip rejects any attempts at installing packages +outside of a virtual environment. +::: + +Now, to see if everything worked, run the following quick-check command: + +```bash +python -c "from sfg_walberla import __version__ as v; print(f'Success! SFG-waLBerla version is {v}')" +``` + +This should print out `Success!` and the version of the code generator engine. + +### CMake + +Create a `CMakeLists.txt` file in your project directory, and populate it with at least the following code: + +::::{card} {download}`CMakeLists.txt` +:::{literalinclude} CMakeLists.txt +::: +:::: + +Here, we use [FetchContent][FetchContent] to dynamically pull both the *waLBerla* and *sfg-walberla* CMake projects. +Next, run the following commands to generate your build system: + +```bash +mkdir build +cmake -S . -B build -DPython_EXECUTABLE=`pwd`/.venv/bin/python +``` + +:::{note} +It is essential that we point CMake at the Python interpreter of the virtual environment we created above, by setting the `Python_EXECUTABLE` cache variable. +If you forget this, the CMake generation step will still run succesfully as long as your shell has that environment activated. +If it is not active, though. you might receive an error message reading: +> Could not find pystencils-sfg in current Python environment. +::: + +Done! Now we can get down to business and populate our project with waLBerla simulation applications. + +(adding_examples)= +## Adding Examples + +As you explore the examples in this book, +you can try out each by downloading and extracting them into the just-created project directory +and adding them to the CMake project. +For example, to include the [force-driven poiseulle channel example](#ForceDrivenChannel), +extract its code into the `ForceDrivenChannel` subdirectory and add + +```CMake +add_subdirectory( ForceDrivenChannel ) +``` + +to your root `CMakeLists.txt`. + +[py-venv]: https://docs.python.org/3/library/venv.html +[FetchContent]: https://cmake.org/cmake/help/latest/module/FetchContent.html diff --git a/examples/EnvSetup/requirements.txt b/examples/EnvSetup/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..62ef403ff9930f5c4ce164ce6967eac2d6e4bed5 --- /dev/null +++ b/examples/EnvSetup/requirements.txt @@ -0,0 +1,14 @@ +# pystencils 2.0 Development Branch +git+https://i10git.cs.fau.de/pycodegen/pystencils.git@v2.0-dev + +# lbmpy: feature branch for pystencils-2.0 compatibility +git+https://i10git.cs.fau.de/pycodegen/lbmpy.git@fhennig/pystencils2.0-compat + +# pystencils-sfg: master +git+https://i10git.cs.fau.de/pycodegen/pystencils-sfg.git + +# sfg-walberla: master +git+https://i10git.cs.fau.de/da15siwa/sfg-walberla.git + +# for legacy waLBerla features +jinja2 diff --git a/examples/PoiseuilleChannel/CMakeLists.txt b/examples/ForceDrivenChannel/CMakeLists.txt similarity index 100% rename from examples/PoiseuilleChannel/CMakeLists.txt rename to examples/ForceDrivenChannel/CMakeLists.txt diff --git a/examples/PoiseuilleChannel/PoiseuilleChannel.cpp b/examples/ForceDrivenChannel/ForceDrivenChannel.cpp similarity index 100% rename from examples/PoiseuilleChannel/PoiseuilleChannel.cpp rename to examples/ForceDrivenChannel/ForceDrivenChannel.cpp diff --git a/examples/PoiseuilleChannel/PoiseuilleChannel.md b/examples/ForceDrivenChannel/ForceDrivenChannel.md similarity index 86% rename from examples/PoiseuilleChannel/PoiseuilleChannel.md rename to examples/ForceDrivenChannel/ForceDrivenChannel.md index b2a43666cb53f7329114ab8445cd9e26811c2bba..1cc8d1481dd7767d6e111bceebb60646890b77e0 100644 --- a/examples/PoiseuilleChannel/PoiseuilleChannel.md +++ b/examples/ForceDrivenChannel/ForceDrivenChannel.md @@ -1,3 +1,4 @@ +(ForceDrivenChannel)= # Force-Driven Poiseuille Channel This example aims to illustrate the basic code generation features of `sfg-walberla` @@ -5,11 +6,11 @@ by building a force-driven channel flow application. ## Files -{download}`PoiseuilleChannel.zip </zipped-examples/PoiseuilleChannel.zip>`. +{download}`ForceDrivenChannel.zip </zipped-examples/ForceDrivenChannel.zip>`. This example comprises the following files: - - `PoiseuilleChannel.cpp`: The main simulation application; + - `ForceDrivenChannel.cpp`: The main simulation application; - `LbmAlgorithms.py`: The code generation script producing the lattice Boltzmann algorithms; - `CMakeLists.txt`: The CMake build system configuration; - `Channel.prm`: the parameter file describing the channel. diff --git a/examples/PoiseuilleChannel/LbmAlgorithms.py b/examples/ForceDrivenChannel/LbmAlgorithms.py similarity index 100% rename from examples/PoiseuilleChannel/LbmAlgorithms.py rename to examples/ForceDrivenChannel/LbmAlgorithms.py diff --git a/examples/GeneratorScriptBasics/GeneratorScriptBasics.md b/examples/GeneratorScriptBasics/GeneratorScriptBasics.md index 27924119f23764dafb2e6964af8b53eaa6966f34..1dc4edeefdc6e4ad4247338e1dd24d3deb967b80 100644 --- a/examples/GeneratorScriptBasics/GeneratorScriptBasics.md +++ b/examples/GeneratorScriptBasics/GeneratorScriptBasics.md @@ -1,7 +1,6 @@ # Getting Started with Generator Scripts -This example aims to illustrate the basic code generation features of `sfg-walberla` -by building a force-driven channel flow application. +This chapter aims to give an introduction on working with ## Files @@ -21,8 +20,5 @@ This example comprises the following files: :::: ::: -Then, we register our code generator script `LbmAlgorithms.py` via the -[`pystencilssfg_generate_target_sources`][sfg_add_gen_scripts] CMake function. - [sfg_add_gen_scripts]: https://pycodegen.pages.i10git.cs.fau.de/pystencils-sfg/usage/project_integration.html#add-generator-scripts "pystencils-sfg Documentation" \ No newline at end of file diff --git a/examples/Makefile b/examples/Makefile index bfa9099e133dcd0678634b2188fab2f1c1017d84..d931dfac6dcefe86452b20b310c390c0ea648d86 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -31,7 +31,6 @@ clean: @rm -rf $(ZIPPED_EXAMPLES) @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -ZipExamples: $(ZIPPED_EXAMPLES)/PoiseuilleChannel.zip ZipExamples: $(foreach example, $(EXAMPLES), $(ZIPPED_EXAMPLES)/$(example).zip) $(ZIPPED_EXAMPLES)/%.zip: %/* diff --git a/examples/conf.py b/examples/conf.py index f1f2ca36c6c0a1989293dfcc0bad92b3144d47ad..ca204c777c94d36dfc0e19b74202b8c5cea70ba7 100644 --- a/examples/conf.py +++ b/examples/conf.py @@ -6,7 +6,7 @@ # -- Project information ----------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information -project = 'waLBerla codegen by example' +project = 'waLBerla next-codegen' copyright = '2024, Frederik Hennig' author = 'Frederik Hennig' @@ -34,4 +34,4 @@ myst_enable_extensions = [ html_theme = 'sphinx_book_theme' html_static_path = ['zipped-examples'] -html_title = "waLBerla codegen by example" +html_title = "waLBerla next-codegen" diff --git a/examples/examples.mk b/examples/examples.mk index d36074572d7ca27aa6cc49d6c2869c073859ac64..2d78f20423a18f80a6bc70282b541fdaee4ac96d 100644 --- a/examples/examples.mk +++ b/examples/examples.mk @@ -1 +1 @@ -EXAMPLES = GeneratorScriptBasics PoiseuilleChannel +EXAMPLES = GeneratorScriptBasics ForceDrivenChannel diff --git a/examples/index.md b/examples/index.md index 733282293dbe554e424450e39ccfecbf8a3fc269..c0dc6d13d1a5efeca903f4adcd7816b9ada7e7b9 100644 --- a/examples/index.md +++ b/examples/index.md @@ -1,10 +1,38 @@ -# waLBerla Code Generation by Example +# The Next Generation of waLBerla Code Generation +Welcome to *The Next Generation of waLBerla Code Generation*. +This book is aimed at teaching you how to use the next generation of code generators for waLBerla +by walking through a set of example applications, each designed to highlight specific features. + +The next-gen code generators for waLBerla are based on bleeding-edge developments in +[pystencils 2.0][pystencils_2_0] and [pystencils-sfg][pystencils-sfg], +and are currently located in the separate [sfg-walberla][sfg-walberla] repository. +This project is still unstable and immature, but growing steadily. + +Until the next-gen code generators are stabilized and merged with the waLBerla master, +setting up a build system and development environment for working with them is slightly more +complicated. Since you will need such an environment to follow along with the examples +in this book, start by reading the chapter [](env_setup). +Afterward, you are free to explore the remainder of the book. + +## Table of Contents :::{toctree} :caption: Fundamentals :maxdepth: 1 +EnvSetup/EnvSetup GeneratorScriptBasics/GeneratorScriptBasics -PoiseuilleChannel/PoiseuilleChannel ::: + +:::{toctree} +:caption: Basic LBM Simulations +:maxdepth: 1 + +ForceDrivenChannel/ForceDrivenChannel +::: + + +[pystencils_2_0]: https://da15siwa.pages.i10git.cs.fau.de/dev-docs/pystencils-nbackend/ "pystencils 2.0 Documentation" +[pystencils-sfg]: https://pycodegen.pages.i10git.cs.fau.de/pystencils-sfg/index.html "pystencils-sfg Documentation" +[sfg-walberla]: https://i10git.cs.fau.de/da15siwa/sfg-walberla "SFG-waLBerla Repository"