Error reading gmsh mesh

Hello! I’m getting an error using gmsh importing function gmshio.read_from_msh when building DolfinX from source: AttributeError: type object 'CoordinateElement_float32' has no attribute '__qualname__'.

This seems like the compilation issue, so here’s the full compilation dockerfile (I cannot use precompiled binaries or conda):


from debian:bookworm

ARG DEBIAN_FRONTEND=noninteractive
ARG BUILD_DIR=/tmp/build
ARG GMSH_COMMIT=3862278e6705ecc0f5d32144289635a34f5d90cb
ARG GKLIB_COMMIT=8bd6bad750b2b0d90800c632cf18e8ee93ad72d7
ARG METIS_COMMIT=e0f1b88b8efcb24ffa0ec55eabb78fbe61e58ae7
ARG PARMETIS_COMMIT=8ee6a372ca703836f593e3c450ca903f04be14df
ARG ADIOS2_COMMIT=270757699c8dc4e0855f4b72febc2f3dca174d83
ARG NANOBIND_COMMIT=784efa2a0358a4dc5432c74f5685ee026e20f2b6
ARG BASIX_COMMIT=19555f5b629b4090b14014f9db5f2c9ac80984f9
ARG UFL_COMMIT=af2499e54ee882a694fca947aa65f2618d74435f
ARG FFCX_COMMIT=2ef366842d1ea5faf053d201364df66f6a693819
ARG DOLFIN_COMMIT=a1bd6f697e1784c7001caf9ebb32673b1fb22412


RUN apt-get update -q \
    && apt-get install -qy --no-install-recommends \
    build-essential \
    cmake \
    freecad-python3 \
    git \
    jupyter-notebook \
    libboost-filesystem-dev \
    libboost-timer-dev \
    libgmp-dev \
    libgomp1 \
    libocct-data-exchange-dev \
    libocct-foundation-dev \
    libocct-modeling-algorithms-dev \
    libocct-modeling-data-dev \
    libocct-ocaf-dev \
    libpetsc-complex-dev \
    libpugixml-dev \
    libslepc-complex-dev \
    libspdlog-dev \
    mpi-default-dev \
    pkg-config \
    python3 \
    python3-cffi \
    python3-dev \
    python3-matplotlib \
    python3-mpi4py \
    python3-petsc4py \
    python3-petsc4py-complex \
    python3-pip \
    python3-pybind11 \
    python3-scipy \
    python3-slepc4py \
    python3-slepc4py-complex \
    && apt-get autoremove \
    && apt-get autoclean \
    && rm -rf /var/lib/apt/lists/* \
    && ln -s libpetsc_complex.so /usr/lib/petscdir/petsc3.18/x86_64-linux-gnu-complex/lib/libpetsc.so \
    && ln -s libslepc_complex.so /usr/lib/slepcdir/slepc3.18/x86_64-linux-gnu-complex/lib/libslepc.so

ENV scalar_type=complex
ENV PETSC_DIR="/usr/lib/petscdir/petsc-$scalar_type"
ENV SLEPC_DIR="/usr/lib/slepcdir/slepc-$scalar_type"
ENV PETSC_ARCH="linux-gnu-$scalar_type-64"
ENV PYTHONPATH="$PETSC_DIR/lib/python3/dist-packages:$SLEPC_DIR/lib/python3/dist-packages"
ENV PKG_CONFIG_PATH="$PETSC_DIR/lib/pkgconfig:$PKG_CONFIG_PATH"
ENV LD_LIBRARY_PATH="$PETSC_DIR/lib:$LD_LIBRARY_PATH"

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/live-clones/gmsh.git \
    && git fetch origin ${GMSH_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && cmake -S . -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_TESTING=OFF \
    -DENABLE_BUILD_SHARED=ON \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DENABLE_FLTK=OFF \
    -DENABLE_WRAP_PYTHON=ON \
    -DENABLE_NUMPY=ON \
    -DENABLE_NETGEN=ON \
    -DENABLE_OCC=ON \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && cd / \
    && rm -rf ${BUILD_DIR}

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/KarypisLab/GKlib.git \
    && git fetch origin ${GKLIB_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && make config prefix=/usr \
    && make install \
    && cd / \
    && rm -rf ${BUILD_DIR}

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/KarypisLab/METIS.git \
    && git fetch origin ${METIS_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && make config prefix=/usr \
    && make install \
    && cd / \
    && rm -rf ${BUILD_DIR}

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/KarypisLab/ParMETIS.git \
    && git fetch origin ${PARMETIS_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && make config cc=mpicc prefix=/usr \
    && make install \
    && cd / \
    && rm -rf ${BUILD_DIR}

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/ornladios/ADIOS2.git \
    && git fetch origin ${ADIOS2_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DADIOS2_BUILD_EXAMPLES=OFF \
    -DBUILD_TESTING=OFF \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S . \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && cd / \
    && rm -rf ${BUILD_DIR}

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/wjakob/nanobind.git \
    && git fetch origin ${NANOBIND_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && git submodule update --init \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S . \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && cd / \
    && rm -rf ${BUILD_DIR}

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/FEniCS/basix.git \
    && git fetch origin ${BASIX_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S . \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/FEniCS/ffcx.git \
    && git fetch origin ${FFCX_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin https://github.com/FEniCS/dolfinx.git \
    && git fetch origin ${DOLFIN_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S ./cpp \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && . /usr/lib/x86_64-linux-gnu/dolfinx/dolfinx.conf \
    && pip3 install --break-system-packages ./python \
    && cd / \
    && rm -rf ${BUILD_DIR}

run find /usr/share/freecad/Mod/ -maxdepth 1 -type d \
    > /usr/lib/python3/dist-packages/freecad.pth \
    && echo /usr/share/freecad/Ext \
    >> /usr/lib/python3/dist-packages/freecad.pth \
    && echo /usr/lib/freecad-python3/lib \
    >> /usr/lib/python3/dist-packages/freecad.pth \
    && echo /lib/x86_64-linux-gnu \
    > /usr/lib/python3/dist-packages/gmsh.pth

RUN useradd -m user \
    && mkdir /home/user/work \
    && chown user:user /home/user/work

COPY start.sh /start.sh

USER user
WORKDIR /home/user
ENTRYPOINT /start.sh
EXPOSE 8888

start.sh file

#!/usr/bin/env bash
. /usr/lib/x86_64-linux-gnu/dolfinx/dolfinx.conf
jupyter-notebook --ip=0.0.0.0 --port=8888 --notebook-dir=/home/user --no-browser

The mesh and code, that actually throws the error:

rect.geo file:

SetFactory("OpenCASCADE");
Rectangle(1) = {0, 0, 0, 1, 1, 0};
Physical Surface(5) = {1};
Physical Curve(6) = {4, 3, 2, 1};

rect.msh from rect.geo file:

gmsh rect.geo -2

Executing code

from dolfinx.io import gmshio
from mpi4py import MPI

gmshio.read_from_msh("rect.msh", MPI.COMM_WORLD, 0, gdim=2)

returns error

gmshio.read_from_msh("rect.msh", MPI.COMM_WORLD, 0, gdim=2)
Info    : Reading 'rect.msh'...
Info    : 9 entities
Info    : 98 nodes
Info    : 194 elements
Info    : Done reading 'rect.msh'
terminate called after throwing an instance of 'nanobind::python_error'
  what():  AttributeError: type object 'CoordinateElement_float32' has no attribute '__qualname__'
[c5f9d0244ccb:00020] *** Process received signal ***
[c5f9d0244ccb:00020] Signal: Aborted (6)
[c5f9d0244ccb:00020] Signal code:  (-6)
[c5f9d0244ccb:00020] [ 0] /lib/x86_64-linux-gnu/libc.so.6(+0x3c050)[0x7f97e6fc9050]
[c5f9d0244ccb:00020] [ 1] /lib/x86_64-linux-gnu/libc.so.6(+0x8aebc)[0x7f97e7017ebc]
[c5f9d0244ccb:00020] [ 2] /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x12)[0x7f97e6fc8fb2]
[c5f9d0244ccb:00020] [ 3] /lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7f97e6fb3472]
[c5f9d0244ccb:00020] [ 4] /lib/x86_64-linux-gnu/libstdc++.so.6(+0x9d919)[0x7f97e2e17919]
[c5f9d0244ccb:00020] [ 5] /lib/x86_64-linux-gnu/libstdc++.so.6(+0xa8e1a)[0x7f97e2e22e1a]
[c5f9d0244ccb:00020] [ 6] /lib/x86_64-linux-gnu/libstdc++.so.6(+0xa7e89)[0x7f97e2e21e89]
[c5f9d0244ccb:00020] [ 7] /lib/x86_64-linux-gnu/libstdc++.so.6(__gxx_personality_v0+0x86)[0x7f97e2e225a6]
[c5f9d0244ccb:00020] [ 8] /lib/x86_64-linux-gnu/libgcc_s.so.1(+0x16934)[0x7f97e2a42934]
[c5f9d0244ccb:00020] [ 9] /lib/x86_64-linux-gnu/libgcc_s.so.1(_Unwind_RaiseException+0x311)[0x7f97e2a42ff1]
[c5f9d0244ccb:00020] [10] /lib/x86_64-linux-gnu/libstdc++.so.6(__cxa_throw+0x3b)[0x7f97e2e230cb]
[c5f9d0244ccb:00020] [11] /usr/local/lib/python3.11/dist-packages/dolfinx/cpp.cpython-311-x86_64-linux-gnu.so(+0x57662)[0x7f97dc355662]
[c5f9d0244ccb:00020] [12] /usr/local/lib/python3.11/dist-packages/dolfinx/cpp.cpython-311-x86_64-linux-gnu.so(+0x4ba998)[0x7f97dc7b8998]
[c5f9d0244ccb:00020] [13] /usr/local/lib/python3.11/dist-packages/dolfinx/cpp.cpython-311-x86_64-linux-gnu.so(+0x4aa5ee)[0x7f97dc7a85ee]
[c5f9d0244ccb:00020] [14] /usr/local/lib/python3.11/dist-packages/dolfinx/cpp.cpython-311-x86_64-linux-gnu.so(+0x4ab84e)[0x7f97dc7a984e]
[c5f9d0244ccb:00020] [15] /usr/local/lib/python3.11/dist-packages/dolfinx/cpp.cpython-311-x86_64-linux-gnu.so(+0x4a9459)[0x7f97dc7a7459]
[c5f9d0244ccb:00020] [16] python3(PyObject_Vectorcall+0x2c)[0x53b4cc]
[c5f9d0244ccb:00020] [17] python3(_PyEval_EvalFrameDefault+0x8f0)[0x52c330]
[c5f9d0244ccb:00020] [18] python3(PyEval_EvalCode+0xbb)[0x523fcb]
[c5f9d0244ccb:00020] [19] python3[0x648f77]
[c5f9d0244ccb:00020] [20] python3[0x64683f]
[c5f9d0244ccb:00020] [21] python3[0x483b0c]
[c5f9d0244ccb:00020] [22] python3(_PyRun_InteractiveLoopObject+0xc1)[0x48363e]
[c5f9d0244ccb:00020] [23] python3[0x46368a]
[c5f9d0244ccb:00020] [24] python3(PyRun_AnyFileExFlags+0x55)[0x46361d]
[c5f9d0244ccb:00020] [25] python3[0x461f3a]
[c5f9d0244ccb:00020] [26] python3(Py_BytesMain+0x27)[0x628e97]
[c5f9d0244ccb:00020] [27] /lib/x86_64-linux-gnu/libc.so.6(+0x2724a)[0x7f97e6fb424a]
[c5f9d0244ccb:00020] [28] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x85)[0x7f97e6fb4305]
[c5f9d0244ccb:00020] [29] python3(_start+0x21)[0x628d31]
[c5f9d0244ccb:00020] *** End of error message ***
Aborted (core dumped)

What could be the problem?

please search the forum with __qualname__ as keyword, as this has been discussed in the past. The issue boiled down to an incorrect version of either nanobind or mpi4py.

Solved by downgrading to pre-nanobind version of dolfinx. For completeness’ sake, here’s the dockerfile

from debian:bookworm

ARG DEBIAN_FRONTEND=noninteractive
ARG BUILD_DIR=/tmp/build

RUN apt-get update -q \
    && apt-get install -qy --no-install-recommends \
    build-essential \
    cmake \
    freecad-python3 \
    git \
    jupyter-notebook \
    libadios-dev \
    libboost-filesystem-dev \
    libboost-timer-dev \
    libgmp-dev \
    libgomp1 \
    libocct-data-exchange-dev \
    libocct-foundation-dev \
    libocct-modeling-algorithms-dev \
    libocct-modeling-data-dev \
    libocct-ocaf-dev \
    libpetsc-complex-dev \
    libpugixml-dev \
    libslepc-complex-dev \
    libspdlog-dev \
    mpi-default-dev \
    pkg-config \
    python3 \
    python3-cffi \
    python3-dev \
    python3-matplotlib \
    python3-mpi4py \
    python3-petsc4py \
    python3-petsc4py-complex \
    python3-pip \
    python3-pybind11 \
    python3-scipy \
    python3-slepc4py \
    python3-slepc4py-complex \
    && apt-get autoremove \
    && apt-get autoclean \
    && rm -rf /var/lib/apt/lists/* \
    && ln -s libpetsc_complex.so /usr/lib/petscdir/petsc3.18/x86_64-linux-gnu-complex/lib/libpetsc.so \
    && ln -s libslepc_complex.so /usr/lib/slepcdir/slepc3.18/x86_64-linux-gnu-complex/lib/libslepc.so

ENV scalar_type=complex
ENV PETSC_DIR="/usr/lib/petscdir/petsc-$scalar_type"
ENV SLEPC_DIR="/usr/lib/slepcdir/slepc-$scalar_type"
ENV PETSC_ARCH="linux-gnu-$scalar_type-64"
ENV PYTHONPATH="$PETSC_DIR/lib/python3/dist-packages:$SLEPC_DIR/lib/python3/dist-packages"
ENV PKG_CONFIG_PATH="$PETSC_DIR/lib/pkgconfig:$PKG_CONFIG_PATH"
ENV LD_LIBRARY_PATH="$PETSC_DIR/lib:$LD_LIBRARY_PATH"

# v4.13.1
ARG GMSH_URL=https://github.com/live-clones/gmsh.git
ARG GMSH_COMMIT=3862278e6705ecc0f5d32144289635a34f5d90cb

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${GMSH_URL} \
    && git fetch origin ${GMSH_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && cmake -S . -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_TESTING=OFF \
    -DENABLE_BUILD_SHARED=ON \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DENABLE_FLTK=OFF \
    -DENABLE_WRAP_PYTHON=ON \
    -DENABLE_NUMPY=ON \
    -DENABLE_NETGEN=ON \
    -DENABLE_OCC=ON \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && cd / \
    && rm -rf ${BUILD_DIR}

# v0.7.0.post0
ARG BASIX_URL=https://github.com/FEniCS/basix.git
ARG BASIX_COMMIT=09fc271aac9ff1fea51d140c2cdee357baf1835f

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${BASIX_URL} \
    && git fetch origin ${BASIX_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S . \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

# 2023.2.0
ARG UFL_URL=https://github.com/FEniCS/ufl.git
ARG UFL_COMMIT=9e8c5971a278b2daeb9ca8bc182011b56b745858

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${UFL_URL} \
    && git fetch origin ${FFCX_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

# v0.7.0
ARG FFCX_URL=https://github.com/FEniCS/ffcx.git
ARG FFCX_COMMIT=829854a630622b1a12fd87822987a406a05aa612

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${FFCX_URL} \
    && git fetch origin ${FFCX_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

# v0.7.3
ARG DOLFIN_URL=https://github.com/FEniCS/dolfinx.git
ARG DOLFIN_COMMIT=25db9a743ef95a78f686f05e38607aa18281b0d6

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${DOLFIN_URL} \
    && git fetch origin ${DOLFIN_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S ./cpp \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && . /usr/lib/x86_64-linux-gnu/dolfinx/dolfinx.conf \
    && pip3 install --break-system-packages ./python \
    && cd / \
    && rm -rf ${BUILD_DIR}

run find /usr/share/freecad/Mod/ -maxdepth 1 -type d \
    > /usr/lib/python3/dist-packages/freecad.pth \
    && echo /usr/share/freecad/Ext \
    >> /usr/lib/python3/dist-packages/freecad.pth \
    && echo /usr/lib/freecad-python3/lib \
    >> /usr/lib/python3/dist-packages/freecad.pth \
    && echo /lib/x86_64-linux-gnu \
    > /usr/lib/python3/dist-packages/gmsh.pth

RUN useradd -m user \
    && mkdir /home/user/work \
    && chown user:user /home/user/work

COPY start.sh /start.sh

USER user
WORKDIR /home/user
ENTRYPOINT /start.sh
EXPOSE 8888

Strangely enough, upgrading mpi4py to 4.0.1 solved the issue for dolfinx 0.9.0 (opposing to recommendation in No attribute '__qualname__' due to mpi4py 4.0.0).

from debian:bookworm

ARG DEBIAN_FRONTEND=noninteractive
ARG BUILD_DIR=/tmp/build

RUN apt-get update -q \
    && apt-get install -qy --no-install-recommends \
    build-essential \
    cmake \
    freecad-python3 \
    git \
    jupyter-console \
    jupyter-notebook \
    libadios-dev \
    libboost-filesystem-dev \
    libboost-timer-dev \
    libgmp-dev \
    libgomp1 \
    libocct-data-exchange-dev \
    libocct-foundation-dev \
    libocct-modeling-algorithms-dev \
    libocct-modeling-data-dev \
    libocct-ocaf-dev \
    libpetsc-complex-dev \
    libpugixml-dev \
    libslepc-complex-dev \
    libspdlog-dev \
    mpi-default-dev \
    pkg-config \
    python3 \
    python3-cffi \
    python3-dev \
    python3-matplotlib \
    python3-petsc4py \
    python3-petsc4py-complex \
    python3-pip \
    python3-pybind11 \
    python3-scipy \
    python3-slepc4py \
    python3-slepc4py-complex \
    && apt-get autoremove \
    && apt-get autoclean \
    && rm -rf /var/lib/apt/lists/* \
    && ln -s libpetsc_complex.so /usr/lib/petscdir/petsc3.18/x86_64-linux-gnu-complex/lib/libpetsc.so \
    && ln -s libslepc_complex.so /usr/lib/slepcdir/slepc3.18/x86_64-linux-gnu-complex/lib/libslepc.so

ENV scalar_type=complex
ENV PETSC_DIR="/usr/lib/petscdir/petsc-$scalar_type"
ENV SLEPC_DIR="/usr/lib/slepcdir/slepc-$scalar_type"
ENV PETSC_ARCH="linux-gnu-$scalar_type-64"
ENV PYTHONPATH="$PETSC_DIR/lib/python3/dist-packages:$SLEPC_DIR/lib/python3/dist-packages"
ENV PKG_CONFIG_PATH="$PETSC_DIR/lib/pkgconfig:$PKG_CONFIG_PATH"
ENV LD_LIBRARY_PATH="$PETSC_DIR/lib:$LD_LIBRARY_PATH"

# v4.13.1
ARG GMSH_URL=https://github.com/live-clones/gmsh.git
ARG GMSH_COMMIT=3862278e6705ecc0f5d32144289635a34f5d90cb

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${GMSH_URL} \
    && git fetch origin ${GMSH_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && cmake -S . -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_TESTING=OFF \
    -DENABLE_BUILD_SHARED=ON \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DENABLE_FLTK=OFF \
    -DENABLE_WRAP_PYTHON=ON \
    -DENABLE_NUMPY=ON \
    -DENABLE_NETGEN=ON \
    -DENABLE_OCC=ON \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && cd / \
    && rm -rf ${BUILD_DIR}

# v2.2.0
ARG NANOBIND_URL=https://github.com/wjakob/nanobind.git
ARG NANOBIND_COMMIT=784efa2a0358a4dc5432c74f5685ee026e20f2b6

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${NANOBIND_URL} \
    && git fetch origin ${NANOBIND_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && git submodule update --init \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S . \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

# v4.0.1
ARG MPI4PY_URL=https://github.com/mpi4py/mpi4py.git
ARG MPI4PY_COMMIT=e09824346446d26de63e72ffd64b4c388313c2fa
RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${MPI4PY_URL} \
    && git fetch origin ${MPI4PY_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && mkdir build \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

# v0.9.0
ARG BASIX_URL=https://github.com/FEniCS/basix.git
ARG BASIX_COMMIT=19555f5b629b4090b14014f9db5f2c9ac80984f9

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${BASIX_URL} \
    && git fetch origin ${BASIX_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S . \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

# 2024.2.0
ARG UFL_URL=https://github.com/FEniCS/ufl.git
ARG UFL_COMMIT=8ddb83037009d88d6cf67811f90766d7a0159c3c

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${UFL_URL} \
    && git fetch origin ${FFCX_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

# v0.9.0
ARG FFCX_URL=https://github.com/FEniCS/ffcx.git
ARG FFCX_COMMIT=2ef366842d1ea5faf053d201364df66f6a693819

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${FFCX_URL} \
    && git fetch origin ${FFCX_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && pip3 install --break-system-packages . \
    && cd / \
    && rm -rf ${BUILD_DIR}

# v0.9.0.post1
ARG DOLFIN_URL=https://github.com/FEniCS/dolfinx.git
ARG DOLFIN_COMMIT=a1bd6f697e1784c7001caf9ebb32673b1fb22412

RUN mkdir ${BUILD_DIR} \
    && cd ${BUILD_DIR} \
    && git init --initial-branch=master \
    && git remote add origin ${DOLFIN_URL} \
    && git fetch origin ${DOLFIN_COMMIT} \
    && git reset --hard FETCH_HEAD \
    && mkdir build \
    && cmake -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -B build -S ./cpp \
    && cmake --build build -j$(nproc) \
    && cmake --install build \
    && . /usr/lib/x86_64-linux-gnu/dolfinx/dolfinx.conf \
    && pip3 install --break-system-packages ./python \
    && cd / \
    && rm -rf ${BUILD_DIR}

run find /usr/share/freecad/Mod/ -maxdepth 1 -type d \
    > /usr/lib/python3/dist-packages/freecad.pth \
    && echo /usr/share/freecad/Ext \
    >> /usr/lib/python3/dist-packages/freecad.pth \
    && echo /usr/lib/freecad-python3/lib \
    >> /usr/lib/python3/dist-packages/freecad.pth \
    && echo /lib/x86_64-linux-gnu \
    > /usr/lib/python3/dist-packages/gmsh.pth

RUN useradd -m user \
    && mkdir /home/user/work \
    && chown user:user /home/user/work

COPY start.sh /start.sh

USER user
WORKDIR /home/user
ENTRYPOINT /start.sh
EXPOSE 8888