3
$\begingroup$

This is a very simple question, however, I haven't been able to find straight forward documentation for this. I have a region that I have converted to an element mesh (which we can visualize with 'wireframe'):

reg = ImplicitRegion[True, {{x, -10, 10}, {y, -10, 10}}];
mesh1 = ToElementMesh[reg, 
   "BoundaryMeshGenerator" -> {"Continuation"}, MaxCellMeasure -> .5, 
   "MaxBoundaryCellMeasure" -> 0.3];
mesh1["Wireframe"]

I would like the coordinates of the mesh on at the boundary of y=-10. So I could write

bmesh1 = ToBoundaryMesh[mesh1]
linecoords = Select[bmesh1["Coordinates"], #[[2]] == -10. &]

However, I was wondering if there is a way to get the same result by using Element Markers instead of Select. Plotting with

mesh1["Wireframe"["MeshElement" -> "BoundaryElements", 
  "MeshElementMarkerStyle" -> Red]]

shows that the y=-10 boundary have element marker 1. So I would like to say something like linecoords = bmesh1["ElementMarker"==1]["Coordinates"], but I can't seem to find the right syntax for it.

$\endgroup$

1 Answer 1

5
$\begingroup$

Similar to this answer you can use:

Needs["NDSolve`FEM`"]
reg = ImplicitRegion[True, {{x, -10, 10}, {y, -10, 10}}];
mesh1 = ToElementMesh[reg, 
   "BoundaryMeshGenerator" -> {"Continuation"}, MaxCellMeasure -> .75,
    "MaxBoundaryCellMeasure" -> 0.5];
(*mesh1["Wireframe"]*)

mesh1["Wireframe"[ElementMarker == 1, 
  "MeshElement" -> "BoundaryElements", 
  "MeshElementMarkerStyle" -> Red]]

enter image description here

Or for point elements:

mesh1["Wireframe"[ElementMarker == 1, 
  "MeshElement" -> "PointElements", "MeshElementMarkerStyle" -> Red]]

enter image description here

Now, if you need the actual coordinates you could use the following helper functions:

getCoords[mesh_, meshElement_, whichMarker_] := Module[
  {pos, gc},
  pos = Flatten[{ElementMarker /. 
      Solve[whichMarker, ElementMarker]}];
  pos = Alternatives @@ pos;
  pos = Position[ElementMarkers[mesh[meshElement]], pos];
  gc = ElementMeshToGraphicsComplex[mesh, pos, 
    "MeshElement" -> meshElement];
  If[meshElement == "PointElements",
   gc[[1]][[Flatten[Flatten[gc[[2]]][[All, 1]], 1]]]
   ,
   gc[[1]][[#]] & /@ Flatten[Flatten[t][[All, 1]], 1]
   ]
  ]

You'd then

coords = getCoords[mesh1, "PointElements", ElementMarker == 1];
Graphics[Point[coords]]

enter image description here

It's not 100% ideal but it will do the job.

If you just want the coordinates, then this is probably a better way:

pts = mesh1["Coordinates"];
pEle = mesh1["PointElements"];
theseEle = MeshElementByMarkerPredicate[pEle, {_?(# == 1 &)}];
GetElementCoordinates[pts, Flatten[ElementIncidents[theseEle]]]

Hope this helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.