# Can someone point me to an example of pulling vertices from faces obtained from AssociationDef?

**URL:** https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909
**Category:** Using SMTK
**Created:** [October 4, 2022, 4:29pm UTC](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909 "2022-10-04T16:29:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RHMoore](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/r/898d66/32.png) [@RHMoore](https://discourse.kitware.com/u/RHMoore)
#### Post date: [October 4, 2022, 4:29pm UTC](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909/1 "2022-10-04T16:29:18Z")

</div>

The ATS example is very powerful and allows me to pick faces that were marked elsewhere:

```auto
<AttDef Type="region.labeled.surface" Label="region: labeled set - face" BaseType="region.physical">
      <AssociationsDef NumberOfRequiredValues="1">
        <Accepts>
          <Resource Name="smtk::model::Resource" Filter="face"></Resource>
        </Accepts>
      </AssociationsDef>
      <ItemDefinitions>
        <Block Name="SolidBCs"/>
      </ItemDefinitions>
    </AttDef>

```

I am able to add boundary conditions to the face the way they did with Exodus, but I need to have individual vertices/nodes for my finite element input file.  
The ATS example writes out:

```auto
<ParameterList name="region.labeled.surface-0" type="ParameterList">
      <ParameterList name="region: labeled set" type="ParameterList">
        <Parameter name="file" type="string" value="cube.obj"/>
        <Parameter name="format" type="string" value="Exodus II"/>
        <Parameter name="entity" type="string" value="face"/>
        **<Parameter name="label" type="string" value="face..bcc2"/>**
        <Parameter name="Ux" type="double" value="0.0"/>
        <Parameter name="Uy" type="double" value="0.0"/>
        <Parameter name="Uz" type="double" value="0.0"/>
        <Parameter name="label" type="string" value="face..bcc2"/>
      </ParameterList>
    </ParameterList>

```

The face name is shown above in bold.  
Using python, how do I extract the vertices that are part of face “face…bcc2”?  
Can someone point me to an example? I have searched, but have not yet found an answer.

For now, I would like a list of nodes. I don’t need XML output or any extra formatting, since I can handle that.

For example, is there some kind of example that does something like the 3rd line below:  
assoc\_item = region\_att.associations()  
model\_entity = assoc\_item.value()  
nodesForOneFace = model\_entity.get\_nodes()

Thank you.

---

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.kitware.com/user_avatar/discourse.kitware.com/dcthomp/32/10_2.png) [@dcthomp](https://discourse.kitware.com/u/dcthomp)
#### Post date: [October 4, 2022, 7:31pm UTC](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909/2 "2022-10-04T19:31:18Z")

</div>

> [@RHMoore](#):
>
> For example, is there some kind of example that does something like the 3rd line below:  
> assoc\_item = region\_att.associations()  
> model\_entity = assoc\_item.value()  
> nodesForOneFace = model\_entity.get\_nodes()

Do you want

- the node locations (i.e., (x,y,z) points in space);
- the index of the nodes in the connectivity array for the selected face(s); or
- the global or pedigree IDs of the the nodes (these may be explicitly or implicitly defined based on your file format – for example Exodus files allow for either)?

---

<div class="post-metadata">

### Author: ![RHMoore](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/r/898d66/32.png) [@RHMoore](https://discourse.kitware.com/u/RHMoore)
#### Post date: [October 4, 2022, 7:52pm UTC](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909/3 "2022-10-04T19:52:02Z")

</div>

Ultimately I want the global node index from the “original” unstructured grid that was imported into the cmb/SMTK/paraview application. For example, I will load in a VTK file from disk, mark a face, and then write the face node global IDs back to a finite element input file.

---

<div class="post-metadata">

### Author: ![RHMoore](https://discourse.kitware.com/letter_avatar_proxy/v4/letter/r/898d66/32.png) [@RHMoore](https://discourse.kitware.com/u/RHMoore)
#### Post date: [October 11, 2022, 5:17pm UTC](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909/4 "2022-10-11T17:17:49Z")

</div>

> [@dcthomp](#):
>
> the node locations (i.e., (x,y,z) points in space);

Thank you for your response. It would help me if I had your first option:

- the node locations (i.e., (x,y,z) points in space);

---

<div class="post-metadata">

### Author: ![dcthomp](https://discourse.kitware.com/user_avatar/discourse.kitware.com/dcthomp/32/10_2.png) [@dcthomp](https://discourse.kitware.com/u/dcthomp)
#### Post date: [October 11, 2022, 6:57pm UTC](https://discourse.kitware.com/t/can-someone-point-me-to-an-example-of-pulling-vertices-from-faces-obtained-from-associationdef/909/5 "2022-10-11T18:57:54Z")

</div>

@RHMoore Sorry this slipped off my radar.

Once you [have a model entity](https://discourse.kitware.com/t/using-the-python-interpreter-included-with-cmb-and-aevacmb/620) of interest selected in python (i.e., the SMTK face, like `face..bcc2`), you can get to the VTK data like so:

```python
from vtkmodules.util.numpy_support import vtk_to_numpy as vton
# Fetch the session object from the resource that owns the face of interest:
session = face.resource().session()
# Fetch the VTK object from the session by passing the UUID of the face:
faceData = session.findStorage(face.id())
# The VTK object may be vtkPolyData, vtkUnstructuredGrid, or vtkImageData
# and in any case should have global cell and point IDs.
cellIds = vton(faceData.GetCellData().GetGlobalIds())
nodeIds = vton(faceData.GetPointData().GetGlobalIds())
# If you want the locations of points in space, you can get those, too:
nodeCoords = vton(faceData.GetPoints().GetData())
# Finally, you many need connectivity information about which offsets into the
# nodeIds and nodeCoords a given cell references. This is different for
# vtkPolyData vs vtkUnstructuredGrid vs vtkImageData. For polydata, if you
# are interested in surface elements (triangles, quads), then
off = vton(faceData.GetPolys().GetOffsetsArray())
conn = vton(faceData.GetPolys().GetConnectivityArray())
# The "off" array is of length N+1, where N is the number of cells
# and each value an offset into the connectivity array "conn".
# The "conn" array holds offsets into all the point arrays (nodeIds, nodeCoords).

```

So, if you are interested in the nodes of cell 10, you can see how many nodes it has with `numNodes = off[11] - off[10]` and then get global point IDs

```python
pointIdsOfCell10 = [nodeIds[ii] for ii in conn[off[10]:off[10+1]]]

```

Similarly, for point locations

```python
pointsOfCell10 = [nodeCoords[ii,:] for ii in conn[off[10]:off[10+1]]]

```

**NB** : For the benefit of others, this reading this later, these instructions work for sessions based on `smtk::model::Resource` such as `smtk::session::vtk` or `smtk::session::aeva`. Other sessions such as opencascade don’t have VTK data backing model entities.
