By far the easiest way to get access to Dune is by installing into a virtual environment using pip. In some folder e.g. Dune setup a virtual environment and activate it
python3 -m venv dune-env source dune-env/bin/activate
Then download and build Dune (note that this takes some time to have coffee/tea at hand):
pip install dune-fem
To test that everything works you can download all the scripts described in this tutorial and try them out
python -m dune.fem cd fem_tutorial python concepts.py
All examples are available as Python scripts or IPython notebooks - for the later jupyter is needed
pip install jupyterlab jupyter lab
This has been tested with different Linux distributions, MacOS, and using the Windows Subsystem for Linux.
the current installation requires MPI to be available.
The first time you construct an object of a specific realization of one of the Dune interfaces (e.g. here a structured grid), the just in time compiler needs to be invoked. This can take quite some time - especially for grid realizations. This needs to be done only once so rerunning the above code a second time (even using other parameters in the structuredGrid function) should execute almost instantaniously.
Hints for Windows
Some hints on getting Dune to 11 using the Windows Subsystem for Linux (tested on Windows 11). Installation in three steps:
First we need to install the wsl (an Ubuntu version):
PowerShellas administrator and run
wsl --install(find Windows
PowerShelland right click; the first entry should be
Run as administrator). This step takes quite some time (‘get a coffee’ long). Close the
exit). Possibly one needs to restart after this step (second coffee).
We need to add some packages and setup a Python virtual environment. Open the wsl (Pinguin icon) - again some installation is done. Enter a new username and password. Then run the following commands:
sudo apt update # enter the password you used above sudo apt install --reinstall ca-certificates sudo apt install python3-dev python3-pip python3-venv cmake sudo apt install jupyter-core python3 -m venv dune-env source dune-env/bin/activate pip install jupyterlab
We have reached the Dune specific part of the installation (I would suggest some tea at this stage)
pip install dune-fem python -m dune.fem
The last step downloads the tutorial scripts into the folder
Each time to open the Linux terminal (wsl) again you will need to run the following commands:
To work on one of the scripts from the tutorial you can either use
cd ~/fem_tutorial/ jupyter lab &
then open the given link in your favourite web browser.
Instead of using the notebooks you can also run the python scripts from the command line, e.g., run
We strongly encourage the use of a python virtual environment and the following instructions are written assuming that a virtual environment is activated.
The following dependencies are needed for Dune-Fem python binding:
At least C++17 compatible C++ compiler (e.g. g++ 9 or later)
python (3.7 or later)
Required Dune modules (release 2.9 or later)
Optional Dune modules (release 2.9 or later)
The optional Dune modules are only need for the parts of the tutorial discussing extension modules.
Building the Required Dune Modules
Test your completed installation by opening a Python terminal and running
import math from dune.grid import structuredGrid from dune.fem.function import gridFunction grid = structuredGrid([0,0],[1,1],[10,10]) @gridFunction(grid,name="test",order=2) def f(x): return math.sin(x.two_norm*2*math.pi) f.plot()
If you have everything set up correctly (and have matplotlib) you should get a colored figure and are hopefully ready to go…
If you are using
Python 3.11or above the version of
Pybind11shipped with the release version of
Duneis not recent enough. Please try the prerelease version by using
$ pip install --pre dune-fem
The compiler version needs to be 7 or later. This can be checked in terminal with
$ g++ --version
If your version is out of date, you will need to upgrade your system to use Dune
It is possible that the python version may be an issue. The scripts require python3 including the development package being installed. If during the Dune installation you get the error
fatal error: pyconfig.h: No such file or directory
This can probably be fixed by installing additional python3.5 libraries with e.g.
$ sudo apt-get install libpython3-dev
One other problem is that a default version of Open MPI may already be installed. This will lead to errors where Dune appears to be looking in the wrong directory for Open MPI (e.g. usr/lib/openmpi instead of the home directory where the script installs it). This can be solved by running
$ make uninstall
in the original MPI install directory, followed by removing the folder. It will then be necessary to reinstall Open MPI and Dune. It may also be necessary to direct mpi4py to the new MPI installation. It is possible to check whether this is a problem by running python and trying out
from mpi4py import MPI
If it comes up with an error, this can be fixed by installing mpi4py manually using the following commands
$ git clone https://bitbucket.org/mpi4py/mpi4py.git $ cd mpi4py $ python setup.py build --mpicc=/path/to/openmpi/bin/mpicc $ python setup.py install --user
User warning from numpy
UserWarning: The value of the smallest subnormal for <class 'numpy.float64'> type is zero.
This is caused by some shared library using the compiler flag
fast-math. Check for example that you are not using this flag in your cmake setup for Dune. See here for a detailed description.