12
$\begingroup$

Let's say I have two element meshes defined as the following:

Needs["NDSolve`FEM`"] a = ToElementMesh[ImplicitRegion[0 <= x <= 1/2 && 0 <= y <= 1, {x, y}]] b = ToElementMesh[ImplicitRegion[1/2 <= x <= 1 && 0 <= y <= 1, {x, y}]] 

Is there any way I can construct a mesh that is the union of these two sets of mesh elements? I haven't been able to find any such commands in the documentation, but I'd like to be able to construct "boundaries" on the inside of my mesh region (in this case, a vertical line at $x = 1/2$).

$\endgroup$

2 Answers 2

10
$\begingroup$

RegionPlot can find boundaries between implicit regions even with a small number of PlotPoints. For example, you have 4 implicit regions

ineqs = {-2 <= x <= 0 && -2 <= y <= 2 && x^2 + y^2 >= 1, x <= 0 && x^2 + y^2 <= 1, x >= 0 && x^2 + y^2 <= 1, 0 <= x <= 2 && -2 <= y <= 2 && x^2 + y^2 >= 1}; r = RegionPlot[ineqs, {x, -2, 2}, {y, -2, 2}, PlotPoints -> 10, MaxRecursion -> 2] 

enter image description here

Then you can construct boundary mesh. Sometimes RegionPlot produces small numerical errors so I use Round[#, 0.001] to "glue" identical points. By default, ToBoundaryMesh have option "DeleteDuplicateCoordinates" -> True so vertices with the same coordinates will be reduced to one vertex.

bmesh = ToBoundaryMesh["Coordinates" -> Round[#, 0.001] &@ First@Cases[r, GraphicsComplex[v_, ___] :> v, ∞], "BoundaryElements" -> Cases[r, Line[p_, ___] :> LineElement@Partition[p, 2, 1], ∞]]; bmesh@"Wireframe" 

enter image description here

mesh = ToElementMesh[bmesh]; mesh["Wireframe"] 

enter image description here

$\endgroup$
0
3
$\begingroup$

Would this work for you?

As I understood, your goal was a boundary in the middle of the region.

bmesh = ToBoundaryMesh[ "Coordinates" -> {{0., 0.}, {1., 0.}, {1., 1.}, {0., 1.}, {.5, 0}, {.5, 1}}, "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4, 1}, {5, 6}}]}] bmesh["Wireframe"] 

Mathematica graphics

mesh = ToElementMesh[bmesh]; mesh["Wireframe"] 

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Looks great, and that's exactly the output I wanted! I'm wondering whether there's a way to automate this for more complicated regions, though. $\endgroup$ Commented Feb 12, 2015 at 19:53
  • $\begingroup$ @MichaelLee What exactly do you mean by automating it? You mean join two regions and include the original boundaries in the output, as you originally described the question? (Sorry, I don't know off-hand how to do that.) $\endgroup$ Commented Feb 12, 2015 at 19:54
  • $\begingroup$ Sorry, yes, that's what I meant. Ideally, I'd be able to specify two parametric regions that share a boundary, and then create a single mesh from those two regions that includes the boundary. $\endgroup$ Commented Feb 12, 2015 at 19:59

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.