Join Two Element Meshes
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"]
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"]