Skip to content
Go to file

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time

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.

Geometries described by multiple level sets

Many geometries do not have – due to sharp corners or edges – an implicit description by a smooth level set function. Instead multiple level set functions can be used to describe theses geometries.


Two-phase diffusion problems / viscous flow problems (Stokes). This section is to be added soon …


Installation with pip

If you run Linux you can install ngsxfem through pip:

pip install git+ --user --upgrade --verbose

This will build ngsxfem assuming that a compatible NGSolve version is installed. If this fails (e.g. because you are not using MacOS or you haven’t installed NGSolve yet consider the build steps below). You also will need cmake, NGSolve and a (modestly) recent compiler (e.g. clang) installed.

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, i.e.:

cmake \

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 unfitted isoparametric (P2/P1) Taylor-Hood-Nitsche 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

List of contributing authors (with major contributions)

  • Christoph Lehrenfeld
  • Janosch Preuss (space-time)
  • Fabian Heimann (cutIntegration, space-time)
  • Thomas Ludescher (multigrid)
  • Henry von Wahl (multiple levelsets)


ngsxfem has been used in the following scientific works (that we are aware of):

Journal publications / preprints:

  • A. Aretaki1, E.N. Karatzas. Random geometries and quasi Monte Carlo methods for optimal control PDE problems based on fictitious domain pdf

FEMs and cut elements.

  • H. von Wahl, T. Richter, C. Lehrenfeld. An unfitted Eulerian finite element method for the time-dependent Stokes problem on moving domains. pdf
  • P. Brandner, A. Reusken. Finite element error analysis of surface Stokes equations in stream function formulation. pdf
  • T. Jankuhn, A. Reusken. Higher order Trace Finite Element Methods for the Surface Stokes Equation pdf
  • T. Jankuhn, A. Reusken. Trace Finite Element Methods for Surface Vector-Laplace Equations pdf
  • E. N. Karatzas, F. Ballarin, G. Rozza. Projection-based reduced order models for a cut finite element method in parametrized domains pdf
  • C. Lehrenfeld, M. A. Olshanskii. An Eulerian finite element method for PDEs in time-dependent domains pdf
  • F. Heimann, C. Lehrenfeld. Numerical integration on hyperrectangles in isoparametric unfitted finite elements. link
  • C. Lehrenfeld, A. Reusken. L2-estimates for a high order unfitted finite element method for elliptic interface problems. http
  • J. Grande, C. Lehrenfeld, A. Reusken. Analysis of a high-order trace finite element method for PDEs on level set surfaces http
  • C. Lehrenfeld, A. Reusken. Analysis of a high order unfitted finite element method for an elliptic interface problem. http
  • C. Lehrenfeld, A. Reusken. Optimal preconditioners for Nitsche-XFEM discretizations of interface problems. http
  • C. Lehrenfeld. High order unfitted finite element methods on level set domains using isoparametric mappings. http
  • C. Lehrenfeld. A higher order isoparametric fictitious domain method for level set domains. http
  • P. Lederer, C.-M. Pfeiler, C. Wintersteiger, C. Lehrenfeld. Higher order unfitted FEM for Stokes interface problems. http
  • C. Lehrenfeld. Removing the stabilization parameter in fitted and unfitted symmetric Nitsche formulations. http

PhD theses:

  • T. Ludescher: Multilevel Preconditioning of Stabilized Unfitted Finite Element Discretizations

Master theses:

  • J. Preuss: Higher order unfitted isoparametric space-time FEM on moving domains
  • H.G. Raumer: Shape Optimization for Interface Problems using unfitted Finite Elements

Bachelor theses:

  • F. Heimann: Higher order Discontinuous Galerkin methods for the Laplace-Beltrami problem on unfitted smooth surfaces


Add-On to NGSolve for unfitted finite element discretizations (XFEM, CutFEM, TraceFEM, etc...)




No packages published
You can’t perform that action at this time.