I want to create a 1D mesh from a list of vertices and interpolate an expression in parallel.
This is my MWE:
import fenics as f
import numpy as np
vertices = sorted(np.linspace(0, 1, num=99))
nb_points = len(vertices)
nb_cells = nb_points - 1
editor = f.MeshEditor()
mesh = f.Mesh()
editor.open(mesh, "interval", 1, 1) # top. and geom. dimension are both 1
editor.init_vertices(nb_points) # number of vertices
editor.init_cells(nb_cells) # number of cells
for i in range(0, nb_points):
editor.add_vertex(i, np.array([vertices[i]]))
for j in range(0, nb_cells):
editor.add_cell(j, np.array([j, j + 1]))
editor.close()
V = f.FunctionSpace(mesh, "P", 1)
u = f.interpolate(f.Constant(300), V)
I run the above code with:
mpirun -np 2 python3 test.py
And it produces the following error:
Traceback (most recent call last):
File "/home/remidm/festim/test_fenics.py", line 20, in <module>
Traceback (most recent call last):
File "/home/remidm/festim/test_fenics.py", line 20, in <module>
u = f.interpolate(f.Constant(300), V)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/remidm/miniconda3/envs/festim/lib/python3.11/site-packages/dolfin/fem/interpolation.py", line 71, in interpolate
Pv.interpolate(v._cpp_object)
File "/home/remidm/miniconda3/envs/festim/lib/python3.11/site-packages/dolfin/function/function.py", line 365, in interpolate
u = f.interpolate(f.Constant(300), V)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/remidm/miniconda3/envs/festim/lib/python3.11/site-packages/dolfin/fem/interpolation.py", line 71, in interpolate
Pv.interpolate(v._cpp_object)
File "/home/remidm/miniconda3/envs/festim/lib/python3.11/site-packages/dolfin/function/function.py", line 365, in interpolate
self._cpp_object.interpolate(u)
RuntimeError:
*** -------------------------------------------------------------------------
*** DOLFIN encountered an error. If you are not able to resolve this issue
*** using the information listed below, you can ask for help at
***
*** fenics-support@googlegroups.com
***
*** Remember to include the error message listed below and, if possible,
*** include a *minimal* running example to reproduce the error.
***
*** -------------------------------------------------------------------------
*** Error: Unable to interpolate function into function space.
*** Reason: Wrong size of vector.
*** Where: This error was encountered inside FunctionSpace.cpp.
*** Process: 0
***
*** DOLFIN version: 2019.1.0
*** Git changeset: 12ef077802cc9fad34cf984ec7af80585b44301b
*** -------------------------------------------------------------------------
Works fine in serial.
I wonder if it’s a case of Function evaluation hangs in parrallel (sometimes)
I tried adding mesh.bounding_box_tree()
but that didn’t fix the issue.
Any idea?