# SLEPc solver with dolfinx

**URL:** <https://fenicsproject.discourse.group/t/slepc-solver-with-dolfinx/8825>\
**Category:** Uncategorized\
**Created:** [July 21, 2022, 4:02pm UTC](https://fenicsproject.discourse.group/t/slepc-solver-with-dolfinx/8825 "2022-07-21T16:02:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mathieu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mathieu/32/7844_2.png) [@Mathieu](https://fenicsproject.discourse.group/u/Mathieu)\
**Post date:** [July 21, 2022, 4:02pm UTC](https://fenicsproject.discourse.group/t/slepc-solver-with-dolfinx/8825/1 "2022-07-21T16:02:55Z")

</div>

Hello everyone,  
I’m currently working on the image dolfinx/dolfinx:latest

I’m trying to solve the classical Helmholtz equation on a simple domain as a 2D square (or 3D cube), but the tutoriel on FEniCSx GitHub about the Helmholtz equation is actually not solving the eigenproblem. Is there somewhere a simple example of the Helmholtz equation solved using SLEPc ? (I’m not talking about complex geometry nor parallelisation). I’ve tried this following code :

```auto
V = FunctionSpace(mesh, ("Lagrange", 1))
        
        u = TrialFunction(V)
        v = TestFunction(V)
        a = inner(grad(u), grad(v)) * dx
        b = inner(u, v) * dx

        A = assemble_matrix(a, [])

```

But I get the following issue :  
AttributeError: ‘Form’ object has no attribute ‘mesh’

Also, if you have any code or part of code to share, where you succeed to compute eigenvalues from a given problem (not necessarily the Helmholtz equation) , I would be grateful. I’m also interested if you have part of code where you define simple Dirichlet Boundary condition on such an eigenproblem.  
It would be the icing on the cake if you have a code which solves an eigenproblem, with Dirichlet BC somewhere AND which works in parallel 🙂

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 21, 2022, 5:29pm UTC](https://fenicsproject.discourse.group/t/slepc-solver-with-dolfinx/8825/2 "2022-07-21T17:29:09Z")

</div>

> [@Mathieu](#):
>
> ` A = assemble_matrix(a, [])`

You need to wrap `a` with `dolfinx.fem.Form`.

An example of an eigenvalue problem can be found at: [dolfinx\_mpc/python/demos/demo\_periodic\_gep.py at main · jorgensd/dolfinx\_mpc · GitHub](https://github.com/jorgensd/dolfinx_mpc/blob/master/python/demos/demo_periodic_gep.py)

---

<div class="post-metadata">

**Author:** ![Mathieu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mathieu/32/7844_2.png) [@Mathieu](https://fenicsproject.discourse.group/u/Mathieu)\
**Post date:** [July 22, 2022, 9:45am UTC](https://fenicsproject.discourse.group/t/slepc-solver-with-dolfinx/8825/3 "2022-07-22T09:45:27Z")

</div>

Thanks for the answer. Actually, this code requires the dolfinx\_mpc library which is not on the docker image of dolfinx. So I’ve tried to clone the repository of dolfinx\_mpc into the dolfinx image and try to install it with :

```auto
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -B build-dir cpp/
ninja -j3 install -C build-dir
pip3 install python/. --upgrade

```

But I got this error message (this is just a part of the error message):

```auto
root@e0e35fdee648:~/dolfinx_mpc# ninja -j3 install -C build-dir
ninja: Entering directory `build-dir'
[1/12] Building CXX object CMakeFiles/dolfinx_mpc.dir/PeriodicConstraint.cpp.o
FAILED: CMakeFiles/dolfinx_mpc.dir/PeriodicConstraint.cpp.o 
/usr/bin/c++ -DBOOST_ALL_NO_LIB -DBOOST_CHRONO_DYN_LINK -DBOOST_TIMER_DYN_LINK -DDOLFINX_MPC_VERSION=\"0.4.1.0\" -DDOLFINX_VERSION=\"0.4.2.0\" -DHAS_ADIOS2 -DHAS_PTSCOTCH -DHAS_SLEPC -Ddolfinx_mpc_EXPORTS -I/root/dolfinx_mpc/cpp -I/root/dolfinx_mpc/cpp/dolfinx_mpc -isystem /usr/local/lib/python3.10/dist-packages/ffcx/codegeneration -isystem /usr/local/petsc/linux-gnu-real-32/include -isystem /usr/local/petsc/include -isystem /usr/local/dolfinx-complex/include -isystem /usr/local/slepc/linux-gnu-real-32/include -isystem /usr/local/slepc/include -O3 -DNDEBUG -fPIC -std=c++20 -MD -MT CMakeFiles/dolfinx_mpc.dir/PeriodicConstraint.cpp.o -MF CMakeFiles/dolfinx_mpc.dir/PeriodicConstraint.cpp.o.d -o CMakeFiles/dolfinx_mpc.dir/PeriodicConstraint.cpp.o -c /root/dolfinx_mpc/cpp/PeriodicConstraint.cpp
/root/dolfinx_mpc/cpp/PeriodicConstraint.cpp: In function 'dolfinx_mpc::mpc_data {anonymous}::_create_periodic_condition(const dolfinx::fem::FunctionSpace&, std::span<int>, const std::function<xt::xarray_container<xt::uvector<double, std::allocator<double> >, xt::layout_type::row_major, xt::svector<long unsigned int, 4, std::allocator<long unsigned int>, true>, xt::xtensor_expression_tag>(const xt::xtensor_container<xt::uvector<double, std::allocator<double> >, 2, xt::layout_type::row_major, xt::xtensor_expression_tag>&)>&, double, const std::function<const int(const int&)>&, const dolfinx::fem::FunctionSpace&)':
/root/dolfinx_mpc/cpp/PeriodicConstraint.cpp:163:17: error: 'view' is not a member of 'xt'; did you mean 'xview'?
  163 | = xt::view(tabulated_basis_values, i, xt::all(), xt::all());
      | ^~~~
      | xview
/root/dolfinx_mpc/cpp/PeriodicConstraint.cpp:297:13: error: 'row' is not a member of 'xt'; did you mean 'pow'?
  297 | xt::row(coords_out, insert_location) = xt::row(mapped_T, i);
      | ^~~
      | pow
/root/dolfinx_mpc/cpp/PeriodicConstraint.cpp:297:52: error: 'row' is not a member of 'xt'; did you mean 'pow'?
  297 | xt::row(coords_out, insert_location) = xt::row(mapped_T, i);
      | ^~~
      | pow
/root/dolfinx_mpc/cpp/PeriodicConstraint.cpp:379:19: error: 'view' is not a member of 'xt'; did you mean 'xview'?
  379 | = xt::view(remote_basis_values, j, xt::all(), xt::all());
      | ^~~~
      | xview
[2/12] Building CXX object CMakeFiles/dolfinx_mpc.dir/SlipConstraint.cpp.o
FAILED: CMakeFiles/dolfinx_mpc.dir/SlipConstraint.cpp.o

```

This is my dockerfile for creating the dolfinx container :

```auto
FROM dolfinx/dolfinx:latest

WORKDIR /usr/src/app

COPY requirements.txt .
RUN pip install -r requirements.txt
RUN apt-get update
RUN apt-get install -y vim

```

And this is the file I use for running the image :

```auto
docker run -ti\
  --name run_test \
  --rm \
  -v /Users/cances/Desktop/stage_cerfacs/STORM/storm_code/src/storm:/root/storm \
  -v $(pwd):/usr/src/app \
  storm_image \
  /bin/bash

```

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 22, 2022, 9:55am UTC](https://fenicsproject.discourse.group/t/slepc-solver-with-dolfinx/8825/4 "2022-07-22T09:55:47Z")

</div>

`dolfinx_mpc` is currently broken, as I’ve not had time to add the API changes in: [Remove xtensor code from element code (#2278) · FEniCS/dolfinx@290e18c · GitHub](https://github.com/FEniCS/dolfinx/commit/290e18c65da1ab7939cb2fe9f540c3e6f5355429)  
If you use DOLFINx from one commit back: [Remove xtensor from VTK helper interface (#2272) · FEniCS/dolfinx@1f3c527 · GitHub](https://github.com/FEniCS/dolfinx/commit/1f3c527dfd739a6d1df2e541828e156e923e0f8a)  
or simply comment out the `dolfinx_mpc` functions in the code I referred you to, you will be able to solve an eigenvalue problem.

---

<div class="post-metadata">

**Author:** ![Mathieu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/mathieu/32/7844_2.png) [@Mathieu](https://fenicsproject.discourse.group/u/Mathieu)\
**Post date:** [July 22, 2022, 9:58am UTC](https://fenicsproject.discourse.group/t/slepc-solver-with-dolfinx/8825/5 "2022-07-22T09:58:28Z")

</div>

Ok i see, but there is this function assemble\_matrix which is used for assembling matrices of the problem. This function comes from the dolfinx\_mpc library

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [July 22, 2022, 12:42pm UTC](https://fenicsproject.discourse.group/t/slepc-solver-with-dolfinx/8825/6 "2022-07-22T12:42:06Z")

</div>

You can replace then with `dolfinx.fem.petsc.assemble_matrix/vector` and remove the `mpc` as input.
