This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How can I visualize a mesh in pieces in paraview?

0 votes

I would very much like to take apart a geometry of the left chamber of the heart and show various pieces arranged just slightly apart from one another.

I made a prototype of this idea with a rectangle

from dolfin import *

mesh = RectangleMesh(Point(0,0), Point(1,2), 1,2)

sd = CompiledSubDomain("x[1] <= 1.0")
mf = MeshFunction("size_t", mesh, 2)
mf.set_all(0)
sd.mark(mf, 1)

top = SubMesh(mesh, mf, 0)
bottom = SubMesh(mesh, mf, 1)
down = Expression(["0.0", "-1.0"])

bottom.move(down)
bottomfile = XDMFFile(mpi_comm_world(), "bottom.xdmf")
topfile = XDMFFile(mpi_comm_world(), "top.xdmf")

bottomfile << bottom
topfile << top

But when I loaded both geometries into paraview they were on top of each other and not 1.0 units apart like I had hoped. Is there a way to visualize the geometries slightly separated with the distance predefined?

asked Jun 16, 2016 by Gabriel Balaban FEniCS User (1,210 points)

1 Answer

+2 votes
 
Best answer

Hi, have you tried zooming out of the 2d plot? In 3d the following works for me just fine

from dolfin import *
from itertools import product

mesh = BoxMesh(Point(-1, -1, -1), Point(1, 1, 1), 2, 2, 3)

domains = CellFunction('size_t', mesh, 0)
qs = [CompiledSubDomain('x[0] %s= 0 && x[1] %s= 0' % (s, t))
      for s, t in product(('>', '<'), ('>', '<'))]

for i, q in enumerate(qs, 1): q.mark(domains, i)

submeshes = [SubMesh(mesh, domains, i) for i in range(1, 5)]

[submesh.move(Expression(('a', 'b', '0'), a=a, b=b))
for (submesh, (a, b)) in zip(submeshes, product((0.2, -0.2), (0.2, -0.2)))]

for i, mesh in enumerate(submeshes, 1):
    f = XDMFFile(mpi_comm_world(), "q%d_mesh.xdmf" % i)
    f << mesh

Here is the output from paraview.

answered Jun 17, 2016 by MiroK FEniCS Expert (80,920 points)
selected Jun 17, 2016 by Gabriel Balaban

I think something was broken with my zoom when I ran paraview yesterday. Today I see two rectangles from my code and 4 cubes from yours! So everything is fine in both cases. Thanks for the assistance.

...