# MeshConnectivity in python

**URL:** <https://fenicsproject.discourse.group/t/meshconnectivity-in-python/3025>\
**Category:** mesh\
**Created:** [April 26, 2020, 11:01pm UTC](https://fenicsproject.discourse.group/t/meshconnectivity-in-python/3025 "2020-04-26T23:01:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![et93](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@et93](https://fenicsproject.discourse.group/u/et93)\
**Post date:** [April 26, 2020, 11:01pm UTC](https://fenicsproject.discourse.group/t/meshconnectivity-in-python/3025/1 "2020-04-26T23:01:27Z")

</div>

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):  
…  
…

---

<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:** [April 27, 2020, 8:29pm UTC](https://fenicsproject.discourse.group/t/meshconnectivity-in-python/3025/2 "2020-04-27T20:29:15Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![et93](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@et93](https://fenicsproject.discourse.group/u/et93)\
**Post date:** [May 11, 2020, 10:59pm UTC](https://fenicsproject.discourse.group/t/meshconnectivity-in-python/3025/3 "2020-05-11T22:59:10Z")

</div>

Thank you very much!

---

<div class="post-metadata">

**Author:** ![et93](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@et93](https://fenicsproject.discourse.group/u/et93)\
**Post date:** [May 12, 2020, 12:51am UTC](https://fenicsproject.discourse.group/t/meshconnectivity-in-python/3025/4 "2020-05-12T00:51:06Z")

</div>

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

---

<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:** [May 12, 2020, 8:32pm UTC](https://fenicsproject.discourse.group/t/meshconnectivity-in-python/3025/5 "2020-05-12T20:32:48Z")

</div>

Consider the following:

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![et93](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@et93](https://fenicsproject.discourse.group/u/et93)\
**Post date:** [May 13, 2020, 12:36am UTC](https://fenicsproject.discourse.group/t/meshconnectivity-in-python/3025/6 "2020-05-13T00:36:39Z")

</div>

Thank you again, so much!
