Plot a MultiMesh

Hello. I am a beginner to fences and I am currently using it in a project that requires me to use the multimesh features. I am building a simple multimesh and attempting to plot it using the plot feature. Below is the code.

from fenics import *

mesh = UnitSquareMesh(8,8)
mesh2 = UnitSquareMesh(10,10)
multimesh = MultiMesh()
multimesh.add(mesh)
multimesh.add(mesh2)
multimesh.build()
plot(multimesh)

When I try to plot this, an error is throwing.

Traceback (most recent call last):
File “”, line 1, in
File “/opt/anaconda3/envs/ucb_fem/lib/python3.8/site-packages/dolfin/common/plotting.py”, line 434, in plot
raise RuntimeError(msg)
RuntimeError: Don’t know how to plot given object:
<dolfin.cpp.mesh.MultiMesh object at 0x1069b2f90>
and projection failed:
‘dolfin.cpp.mesh.MultiMesh’ object has no attribute ‘ufl_shape’

Does anyone have any suggestions

For an arbitrary number of meshes, you can do the following:

from dolfin import *
import matplotlib.pyplot as plt

mesh0 = UnitSquareMesh(10,10)
mesh1 = RectangleMesh(Point(0.33,0.33), Point(0.66,0.66), 5,5)
multimesh = MultiMesh()
multimesh.add(mesh0)
multimesh.add(mesh1)
multimesh.build()
for part in range(multimesh.num_parts()):
    plot(multimesh.part(part))
plt.savefig("mm.png")
1 Like

…or on separate sync’ed 3d renderers:

from vedo.dolfin import plot as vplot
n = multimesh.num_parts()
for i in range(n):
    vplot(multimesh.part(i), at=i, N=n, wireframe=1, lw=2, c=i)

2 Likes