Dolfinx-mpc bad_cast

Hi Everyone,

I installed dolfinx and dolfinx_mpc on WSL2 using

sudo apt install python3-dolfinx
sudo apt install python3-dolfinx-mpc

When I try to solve a problem with periodic boundary conditions, the following RuntimeError is raised:

    mpc.create_periodic_constraint_geometrical(V, slave, master, bcs, scale)
  File "/usr/lib/python3/dist-packages/dolfinx_mpc/multipointconstraint.py", line 286, in create_periodic_constraint_geometrical
    mpc_data = dolfinx_mpc.cpp.mpc.create_periodic_constraint_geometrical(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: std::bad_cast

Could this be an installation issue? Or what are my options for debugging this?

Could you provide the full code you are running?

For instance, using docker to emulate your commands:

FROM ubuntu:24.04

RUN apt-get update && apt-get install -y software-properties-common
RUN add-apt-repository ppa:fenics-packages/fenics

RUN apt update && apt install -y python3-pip  python3-dolfinx  python3-dolfinx-mpc  git
WORKDIR /src

RUN git clone --single-branch --branch=v0.9.1 https://github.com/jorgensd/dolfinx_mpc.git
RUN python3 -m pip install pytest --break-system-packages
RUN python3 -m pytest -xvs dolfinx_mpc/python/tests

which I execute with

docker build -t test_dolfinx_mpc -f Dockerfile .                 

passes

Sorry I forgot to update the post.
Turns out I misinterpreted the indicator and relation variables that have to be supplied to

mpi.create_period_constraint_geometrical()

My bad for not reading the docs well enough.