5

For a given triangle meshRegion(examplary) \[CapitalDelta]reg

\[CapitalDelta]reg =DiscretizeRegion[Triangle [], MaxCellMeasure -> 1/10]

enter image description here

I need to know/detect the indexes of neighbouring elements and their common side.
I know the command MeshCells.

How to solve this problem? Thanks!

Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55

1 Answers1

4

My first attempt:

\[CapitalDelta]reg = 
 DiscretizeRegion[Triangle[], MaxCellMeasure -> 1/10]
polys = MeshPrimitives[\[CapitalDelta]reg, 2]
mcells = MeshCells[\[CapitalDelta]reg, 2]
amc1 = AdjacentMeshCells[\[CapitalDelta]reg, #, 1] & /@ mcells
amc2 = AdjacentMeshCells[\[CapitalDelta]reg, #, 2] & /@ mcells
Manipulate[
 Show[
  HighlightMesh[\[CapitalDelta]reg, amc2[[i]]]
  , Graphics[{AbsolutePointSize[10], Red, 
    Point@RegionCentroid[polys[[i]]]
    }]
  ]
 , {i, 1, Length@mcells, 1}
 ]

enter image description here

You can also see the lines being highlighted by using amc1 instead of amc2 above. polys is just for centroid calculation.

Syed
  • 52,495
  • 4
  • 30
  • 85
  • 1
    Perfect solution, thank you . I didn't know AdjacentMeshCells[] – Ulrich Neumann Apr 02 '22 at 10:39
  • AnnotationValue[{\[CapitalDelta]reg, 2}, MeshCellCentroid] and RegionCentroid /@ polys give the same result, so the above solution can be made shorter (something I just discovered). Try: Names["*MeshCell*"]. Thanks for the accept. – Syed Apr 02 '22 at 10:53
  • You're welcome. My goal is to model 2D finite volume method(didn't find info on stackexchange), therefore I need this elementwise knowledge of elements and adjacent sides. Thanks again. – Ulrich Neumann Apr 02 '22 at 10:58