1
$\begingroup$

I have a following code:

    bmesh = ToBoundaryMesh[
   "Coordinates" -> {{-1, -1}, {1, -1}, {1, 1}, {-1, 
      1}, {-1/2, -1/2}, {1/2, -1/2}, {1/2, 1/2}, {-1/2, 1/2}}, 
   "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4, 
        1},{5, 6}, {6, 7}, {7, 8}, {8, 5}}]}, 
   "RegionHoles" -> {{0, 0}}];
   bmesh["Wireframe"]


ToElementMesh[bmesh]["Wireframe"]

the output is:

enter image description here

How can we create mesh in the inner region and holes/empty at the exterior?

I need something like the following,

enter image description here

==================== Update ==================

How to have regionholes in the smaller rectangular region?

    bmesh = ToBoundaryMesh[
   "Coordinates" -> {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {0.5, 1.1}, {1, 
      1.1}, {1, 1.6}, {0.5, 1.6}}, 
   "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4, 
        1}, {5, 6}, {6, 7}, {7, 8}, {8, 5}}]}];
bmesh["Wireframe"]

enter image description here

$\endgroup$

1 Answer 1

3
$\begingroup$

You can use "RegionHoles"->None :

bmesh = ToBoundaryMesh[
   "Coordinates" -> {{-1, -1}, {1, -1}, {1, 1}, {-1, 
      1}, {-1/2, -1/2}, {1/2, -1/2}, {1/2, 1/2}, {-1/2, 1/2}}, 
   "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4, 
        1}, {5, 6}, {6, 7}, {7, 8}, {8, 5}}]}, 
   "RegionHoles" -> None];
(*bmesh["Wireframe"]*)
ToElementMesh[bmesh]["Wireframe"]

enter image description here

If you want to remove the outer part, you should start with a smaller boundary mesh region. Having a boundary line and a fully meshed inner region does not work with an ElementMesh. You might be able to do this with a MeshRegion - but you will not be able to use that for a finite element analysis.

Here is an example of a material region and a region hole:

Needs["NDSolve`FEM`"]
bmesh = ToBoundaryMesh[
   "Coordinates" -> {{-1, -1}, {1, -1}, {1, 1}, {-1, 
      1}, {-1/2, -1/2}, {1/2, -1/2}, {1/2, 1/2}, {-1/2, 
      1/2}, {-4/5, -4/5}, {-3/5, -4/5}, {-3/5, -3/5}, {-4/5, -3/5}}, 
   "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4, 
        1}, {5, 6}, {6, 7}, {7, 8}, {8, 5}, {9, 10}, {10, 11}, {11, 
        12}, {12, 9}}]}, "RegionHoles" -> {{-7/10, -7/10}}];
(*bmesh["Wireframe"]*)
ToElementMesh[bmesh, MaxCellMeasure -> 0.005]["Wireframe"]

enter image description here

Here the region touches the boundary and is correctly removed:

Needs["NDSolve`FEM`"]
ToElementMesh[
  RegionDifference[
   RegionDifference[Rectangle[{-1, -1}, {1, 1}], 
    Rectangle[{-1, -4/5}, {-3/5, -3/5}]], 
   Rectangle[{-1/2, -1/2}, {1/2, 1/2}]], MaxCellMeasure -> 0.005, 
  "RegionHoles" -> None]["Wireframe"]

enter image description here

The mesh you want to use, if that's for finite element analysis then it's not valid. You can get very close to the boundary but not touch it.

Needs["NDSolve`FEM`"]
ToElementMesh[
  RegionDifference[Rectangle[{-1, -1}, {1, 1}], 
   RegionUnion[Rectangle[{-99/100, -4/5}, {-3/5, -3/5}], 
    Rectangle[{-1/2, -1/2}, {1/2, 1/2}]]], MaxCellMeasure -> 0.005, 
  "RegionHoles" -> None]["Wireframe"]

enter image description here

$\endgroup$
9
  • $\begingroup$ In the original problem, I need to have a fully meshed inner region and within a boundary line I have boundary conditions/ boundary contact lets say a small rectangle at right top and left bottom. So, that's why I want to have an empty boundary region, which has boundary conditions and inner fully meshed region. will I be able to use that for finite element analysis. $\endgroup$
    – a019
    Jan 31 at 14:04
  • $\begingroup$ @MuhammadAli, I have trouble understanding what you need. Can you make a drawing? $\endgroup$
    – user21
    Jan 31 at 16:36
  • $\begingroup$ I edited the question, can we have this? if not that's fine as well. $\endgroup$
    – a019
    Feb 1 at 8:42
  • $\begingroup$ @MuhammadAli, we can have something like as a MeshRegion this but not as finite element mesh. What do you want to do with this? Also, the boundary conditions are not in contact with the domain - there are not really a boundary. I think what you really want is a full mesh in each region but different material coefficients in them. $\endgroup$
    – user21
    Feb 1 at 9:26
  • 1
    $\begingroup$ @MuhammadAli, you'd need to mesh all of the domain. See for example this $\endgroup$
    – user21
    Feb 1 at 12:01

Your Answer

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

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