Add-On to NGSolve for unfitted finite element discretizations (XFEM, CutFEM, TraceFEM, etc...)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
cmake_modules Update build system and python code Jun 2, 2017

About ngsxfem

ngsxfem is an Add-on library to Netgen/NGSolve which enables the use of unfitted finite element technologies known as XFEM, CutFEM, TraceFEM, Finite Cell, … . ngsxfem is an academic software. Its primary intention is to facilitate the development and validation of new numerical methods.

The main features

Numerical integration on implicitly described (via a level set function) geometries which are not fitted to the mesh

Given a level set function φ which describes the geometry (e.g. Ω = { φ < 0 }) a piecewise linear approximation is made. On simplices (triangles and tetrahedra) this gives a planar intersection on every element which allows for an explicit decomposition into simple geometries. On these simple (uncut) geometries standard quadrature rules of arbitrary order can be applied which results in quadrature rules for the (approximated) subdomains where the level set is positive/negative/zero.

Tools to work on an “active mesh” only

In unfitted finite element methods some functions and integrals are only defined on a subset of the mesh. Accordingly finite element spaces and integrals have to be defined only on this active mesh. ngsxfem offers the tools to mark the corresponding elements and facets and use the marking during assembly and definition of finite element spaces. On cut elements one often also uses locally modified finite elements, e.g. by restriction of finite elements on the background mesh.

Higher order representation of implicit level-set geometries

To obtain higher order accuracy, we offer a mesh transformation technique in the spirit of isoparametric finite element methods. Thereby the piecewise linear approximation (which is only of second order) is mapped onto a higher order accurate approximation of the true geometry.

Space-Time Finite Elements for the treatment of moving domain problems

To obtain robust method for PDEs on unfitted moving domain we can formulate space-time discretization. ngsxfem provides necessary tools (so far only in two space dimensions) to define space-time finite element spaces and to integrate on space-time domains. Further, it extends the tools for higher order accurate geometry handling to the space-time setting.


This section is to be added soon …


Linux Build Steps

You require Netgen/NGSolve to run and build the xfem module (ngsxfem). You can either install it before hand (default option) or let Netgen/NGSolve be installed as an external dependency.

git clone
cd ngsxfem
mkdir build
cd build

Building xfem with pre-installed NGSolve

You have Netgen/NGSolve installed? Perfect. Then let INSTLOCATION be the location Netgen/NGSolve is already installed to. To install xfem make sure that you have write access to that same directory. Then build ngsxfem with

make install

Prerequisites on Ubuntu

On Ubuntu you require python3-dev to build ngsxfem (and similar dependencies as NGSolve has, cf.

Fix of potential issues

If you have compiling problems or at run time some NGSolve symbols are not found, it may be (happened in some configurations) that the NGSolve compiler and linker wrapper ngscxx and ngsld were not used. In this case you may add

cmake ... -DCMAKE_CXX_COMPILER=ngscxx -DCMAKE_LINKER=ngsld

to the cmake configuration.

ngsxfem on MacOSX

On MacOSX, you need to add the location of the NGSolve cmake configuration files:


If NGSolve is installed from the dmg-file NGSOLVE_INSTALLATION_LOCATION is /Applications/

Building the NGS-Suite and ngsxfem together

If you do not have Netgen/NGSolve installed, you may first call

git submodule update --init

which pulls Netgen/NGSolve as external dependencies. Then, just call

make install

For INSTLOCATION you choose a nice installation location. Afterwards make sure that the installed NGS/xfem-libraries and executable will be found by PATH and python.

Updating ngsxfem

To update ngsxfem, update the sources

git pull origin master

As the ngsolve-version that the updated xfem-version depends on can be updated in the mean time, make sure to update NGSolve. If you build NGSolve as an external dependency update the submodule NGSolve:

git submodule update --init --recursive

Otherwise update your NGSolve version manually. As a rule we try to be compatible to the latest release of NGSolve. To be sure check the version in external_dependencies/ngsolve


To run the python examples be sure to follow the build steps above. Then navigate into the py_tutorials and run


where stands for any of the available python files.


Tests are enabled by default. To run the test navigate to the build directory and run make test or ctest. If you need to see specific tests failing use ctest -V. To run individual tests use ctest -R <regex>. E.g. ctest -R cutint to only run cut integration tests. Note that we use pytest (with python version > 3).

pde vs. py files

From version 1.0.0 on there are no pde-files used in this project anymore. Only python-files are used.


At you can find tutorial-style jupyter notebooks for ngsxfem. Further, in py_tutorials/ there are some simple examples for some known unfitted discretizations:

  • py_tutorials/ : stationary interface problem with a (P1) CutFEM method with Nitsche
  • py_tutorials/ : stationary interface problem with a (P1) XFEM method with Nitsche (similar to
  • py_tutorials/ : stationary interface problem with a higher order isoparametric unfitted FEM with Nitsche (similar to
  • py_tutorials/ : stationary fictitious domain problem with isoparametric CutFEM, Nitsche and ghost penalty stabilization
  • py_tutorials/ : stationary fictitious domain problem with isoparametric Cut-DG-FEM, Nitsche and ghost penalty stabilization
  • py_tutorials/ : stationary Stokes interface problem with an isoparametric (P2X/P1X) Taylor-Hood-Nitsche-XFEM discretization
  • py_tutorials/ : stationary 2D surface PDE problem with a TraceFEM discretization (low order)
  • py_tutorials/ : stationary 3D surface PDE problem with a TraceFEM discretization (higher order)
  • spacetime/py_tutorials/ : moving fictitous domain problem using a space time unfitted FEM