Installation#

pip - Install#

_images/python.png

Recommended for all platforms

# Depending on platform, use either pip or pip3
pip install --upgrade ngsolve

# to work with jupyter notebooks
pip install --upgrade webgui_jupyter_widgets

# following commands are only necessary for jupyter < 7.0.0
jupyter nbextension install --user --py webgui_jupyter_widgets
jupyter nbextension enable --user --py webgui_jupyter_widgets

Building from Source#

Prerequisites#

Make sure that you have the following packages installed

  • You need a recent compiler, we advise Microsoft Visual Studio 2022

  • Python 3: You can get it here if you don’t already have it. Make sure to download one of the “x86-64” installers. Also make sure to select the option “Add Python 3 to PATH” during the installation.

  • cmake to generate Visual Studio Projects Files (Win32 Installer works for both architectures) we recommend the install option ‘Add CMake to the system PATH for all users’

  • git for downloading Netgen/NGSolve sources

  • You need to have Xcode installed. We will build using the default clang compiler. If it is not in the default location/path, please set

export CC=<MyPathtoClang>
export CXX=<MyPathtoClang++>
  • You need to have make installed for command line use. Xcode Command Line Tools package comes with make. You can install Xcode Command Line Tools by xcode-select --install.

  • You need to have cmake installed. You can either download and install CMake. Make sure to install the command line tools: Open CMake, click on “How to Install For Command Line Use” in the “Tools” menu and execute one of the suggested options.

  • Install Python

  • You need a recent compiler

  • We advise to have Python installed, in version 3.8 or higher (you can compile Netgen/NGSolve also without python support). Make sure to install according packages in their “dev”-version to have the suitable header files installed.

  • You will need tcl / tk in version >=8.5 Make sure to install according packages in their “dev”-version to have the suitable header files installed.

  • git (to get the sources)

  • cmake (>=3.16) for the build system

  • libxmu-dev (you might also need the xorg-dev package)

  • libglu (again, the “dev”-version)

  • liblapacke-dev

The following line should update/install all prerequisites on Ubuntu (you need root privileges):

sudo apt-get update && sudo apt-get -y install python3 python3-distutils python3-tk libpython3-dev libxmu-dev tk-dev tcl-dev cmake git g++ libglu1-mesa-dev liblapacke-dev libocct-data-exchange-dev libocct-draw-dev occt-misc libtbb-dev libxi-dev

Directory structure#

For ease of presentation we use a directory structure with three main directories:

  • “src” for the source code NGSolve

  • “build” for the output of CMake and the compiler

  • “install” for the actual installation

In the following we assume that you have chosen a base directory where three (empty) directories “src”, “build” and “install” have been created. This base directory will be denoted as BASEDIR in the following.

Getting the source#

Start a console (“Git Bash” on Windows), navigate to BASEDIR and execute

git clone --recurse-submodules https://github.com/NGSolve/ngsolve.git src

Go to the source directory and initialize the git submodules to download the source files for Netgen and Pybind11.

cd src
git submodule update --init --recursive
cd ..

After this step you should have the source code of Netgen in src/external_dependencies/netgen.

Building from the source#

Next, change to the “build” directory and use cmake to configure from the sources. The standard configuring command looks like this

mkdir build
cd build
cmake "../src" -DCMAKE_INSTALL_PREFIX="BASEDIR/install"
cd build
cmake ../src
cd build
cmake ../src

There are many options for cmake, which you can find using

cmake --help

To build Netgen/NGSolve, execute

cmake --build . --config Release --target install
make install
make install

Alternatively you can open BASEDIR\build\SUPERBUILD.sln in Visual Studio and build the “INSTALL” project. Make sure to select the desired solution configuration (e.g. Release).

Finishing the installation#

Finally you have to set the environment variables PATH, NETGENDIR and PYTHONPATH to the appropriate values. This is done by building the “set_environment_variables” target.

cmake --build . --config Release --target set_environment_variables

Add the following line to your .bashrc file in your home directory

and execute the file with

source .bashrc

to set all environment variable needed to start Netgen/NGSolve from the command line.

Finally you have to set the environment variable NETGENDIR to the location of the executable, eg. by

export NETGENDIR="${BASEDIR}/ngsolve-install/bin"

or

setenv NETGENDIR "${BASEDIR}/ngsolve-install/bin"

(depends on your linux distribution). You may want to add the corresponding line to your .bashrc, s.t. it is automatically set whenever you log in into your bash-shell. To be able to start netgen from the command line, you have to add NETGENDIR to the PATH, eg. by

export PATH=$NETGENDIR:$PATH

or

setenv PATH "$NETGENDIR:$PATH"

When you want to run Python scripts, you also have to set PYTHONPATH to the appropriate directory:

export PYTHONPATH=$NETGENDIR/../`python3 -c "import os.path, sysconfig;print(os.path.relpath(sysconfig.get_path('platlib'), sysconfig.get_path('data')))"`

Keep it up to date#

To update Netgen/NGSolve go to the source directory (${BASEDIR}/src) and fetch the latest sources. The second line is needed to update all dependencies provided as git submodules (such as Netgen).

git pull
git submodule update --recursive --init

After that, go to the build directory (${BASEDIR}/ngsolve-build) and build/install again

cmake --build . --config Release --target install
make install
make install