MeshConnectivity in python

Hello,

I would like to ask about the syntax of MeshConnectivity class in python. I have a 3D box (submesh) inside another 3D box (mesh) and I need to have two lists with the nodes which belong to each surface. (insurface->inside box, outsurface->outside box). Thank you!!

import matplotlib.pyplot as plt
from dolfin import *
import numpy as np
import random

mesh = Mesh(“dolfinmesh.xml”)
mesh_file_volume = MeshFunction(‘size_t’, mesh ,“dolfinmesh_volume_meshvalue.xml”)
mesh_file_surface = MeshFunction(‘size_t’ , mesh , “dolfinmesh_surface_meshvalue.xml”)
mesh_file_boundary = MeshFunction(‘size_t’ , mesh , “dolfinmesh_bcfunc.xml”)

V = FunctionSpace(mesh, “Lagrange”, 1)

insurface = list()
outsurface = list()

#I’ve tried: connectivity32 = mesh.topology(mesh, 3, 2); or connectivity32 = MeshConnectivity(3, 2); but #it doesn’t seem to work.

for cell in cells(mesh):

You need to initialize the mesh connectivity, as it is not computed by default:

from dolfin import *
mesh = UnitCubeMesh(3,3,3)
mesh.init(3, 2)
c2f = mesh.topology()(3,2)
print(c2f(0))

Thank you very much!

I also try to extract the nodes of which the surfaces (triangles) consist of. I’ve tried dof to vertex map but it doesn’t seem to work because surfaces are not my cell index. Any idea about how I can approach these nodes?

Thank you

Consider the following:

from dolfin import *
mesh = UnitCubeMesh(1,1,1)
mesh.init(3, 2)
c2f = mesh.topology()(3,2)
mesh.init(2,0)
f2v = mesh.topology()(2,0)
for cell in range(mesh.num_cells()):
    facets = c2f(cell)
    for facet in facets:
        vertices = f2v(facet)
        print("Cell ", cell, " Facet ", facet, " Vertices ", vertices)

Thank you again, so much!