7

I want to get a list of all boundary elements belonging to a certain ElementMarker of a boundary mesh.

This code creates a simple mesh and allows to inspect the ElementMarkers of the boundary mesh.

<< NDSolve`FEM`

cubi = Cuboid[{0, 0, 0}, {1, 1, 1}]; mesh = DiscretizeRegion[cubi, MaxCellMeasure -> 1]; bmesh = ToBoundaryMesh[mesh];

(inspect element markers) groups = bmesh["BoundaryElementMarkerUnion"] temp = Most[Range[0, 1, 1/(Length[groups])]]; colors = ColorData["BrightBands"][#] & /@ temp; surfaces = AssociationThread[groups, bmesh["Wireframe"[ElementMarker == #, "MeshElementStyle" -> FaceForm[colors[[#]]]]] & /@ groups];

Manipulate[ Show[{bmesh["Edgeframe"], choices /. surfaces}], {{choices, groups}, groups, CheckboxBar}, ControlPlacement -> Top ]

mesh cube

With bmesh["Wireframe"[ElementMarker == 1]] I can visualize a specific boundary part: boundary part

While bmesh["BoundaryElements"] returns all the triangles of the boundary:

{TriangleElement[{{5, 6, 1}, {5, 7, 6}, {4, 3, 8}, {4, 1, 3}, {4, 8, 
1}, {2, 3, 1}, {2, 7, 3}, {2, 6, 7}, {2, 1, 6}, {8, 3, 7}, {5, 1, 
8}, {5, 8, 7}}, {1, 2, 3, 4, 5, 4, 6, 6, 1, 3, 5, 2}]}

How can I use something like bmesh["BoundaryElements"] in a way that it gives me all the boundary elements that belong to a certain ElementMarker?

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Tobias
  • 563
  • 2
  • 7

1 Answers1

7

Two things you can do:

Group them by marker and extract what you want:

bele = bmesh["BoundaryElements"];
MeshElementSplitByMarker[bele]

{{TriangleElement[{{5, 6, 1}, {2, 1, 6}}, {1, 1}], TriangleElement[{{5, 7, 6}, {5, 8, 7}}, {2, 2}], TriangleElement[{{4, 3, 8}, {8, 3, 7}}, {3, 3}], TriangleElement[{{4, 1, 3}, {2, 3, 1}}, {4, 4}], TriangleElement[{{4, 8, 1}, {5, 1, 8}}, {5, 5}], TriangleElement[{{2, 7, 3}, {2, 6, 7}}, {6, 6}]}}

or find the positions and extract what you want:

pos = Position[ElementMarkers[bele], Alternatives @@ {1, 6}];
elePart = Union[pos[[All, 1]]];
theseElements = 
 Function[{part}, 
   MeshElementByPart[bele[[part]], 
    Select[pos, First[#] == part &][[All, 2]]] ] /@ elePart

{TriangleElement[{{5, 6, 1}, {2, 7, 3}, {2, 6, 7}, {2, 1, 6}}, {1, 6, 6, 1}]}

user21
  • 39,710
  • 8
  • 110
  • 167