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

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

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

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:

<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"/>

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.

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)?

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.

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);

@RHMoore Sorry this slipped off my radar.

Once you have a model entity of interest selected in python (i.e., the SMTK face, like face..bcc2), you can get to the VTK data like so:

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(
# 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

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

Similarly, for point locations

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.