# Join Two Element Meshes

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

Needs["NDSolveFEM"]
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$).

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]


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"


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


• Perfect, thank you! Commented Feb 13, 2015 at 3:33

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


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


• 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. Commented Feb 12, 2015 at 19:53
• @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.) Commented Feb 12, 2015 at 19:54
• 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. Commented Feb 12, 2015 at 19:59