Skip to main content
added 1982 characters in body
Source Link
user21
  • 40.7k
  • 8
  • 114
  • 170

ThisThese should work:

Method 1

EditMethod 2

All of these methods are documented in ToBoundaryMesh. There you can find more info.

Method 3

Here is yet another way to do it, but that will requite version 11.2:

 L = 1./5; d = 1./50; r = L - d; r1 = d; L2 = 1./250; L3 = 1./25; L4 = 
 L/8;
reg = RegionDifference[
   RegionUnion[Rectangle[{0, 0}, {L, L}], 
    Rectangle[{-L3, L4 - L2/2}, {0, L4 + L2/2}], 
    Rectangle[{-L3, (L - L4) - L2/2}, {0, (L - L4) + L2/2}]], 
   RegionUnion[Disk[{L, 0}, r], Disk[{2 d, L - 2 d}, r1]]];

Now we make boundary discretizations of the components and construct the region from those:

bdr = BoundaryDiscretizeRegion /@ reg[[2]];
bmr = Fold[RegionDifference, bdr]

enter image description here

Next, we create a NumericalRegion and attach the boundary mesh to it:

Needs["NDSolve`FEM`"]
nr = ToNumericalRegion[reg, RegionBounds[reg]];
bmesh = ToBoundaryMesh[bmr];
SetNumericalRegionElementMesh[nr, bmesh];

When we now mesh that numerical region have both the symbolic and the boundary representation available and a good approximation can be generated:

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

To compare the area of the mesh with the area of the symbolic representation we use:

narea = Total[mesh["MeshElementMeasure"], 2];

and

L = 1/5; d = 1/50; r = L - d; r1 = d; L2 = 1/250; L3 = 1/25; L4 = 
 L/8;
reg2 = RegionDifference[
   RegionUnion[Rectangle[{0, 0}, {L, L}], 
    Rectangle[{-L3, L4 - L2/2}, {0, L4 + L2/2}], 
    Rectangle[{-L3, (L - L4) - L2/2}, {0, (L - L4) + L2/2}]], 
   RegionUnion[Disk[{L, 0}, r], Disk[{2 d, L - 2 d}, r1]]];
sarea = Integrate[1, {x, y} \[Element] reg2];

The result:

narea - sarea
-2.4810104379269227`*^-7

I think this is quite good.

enter image description here

This should work:

Edit

All of these methods are documented in ToBoundaryMesh. There you can find more info.

These should work:

Method 1

Method 2

All of these methods are documented in ToBoundaryMesh. There you can find more info.

Method 3

Here is yet another way to do it, but that will requite version 11.2:

 L = 1./5; d = 1./50; r = L - d; r1 = d; L2 = 1./250; L3 = 1./25; L4 = 
 L/8;
reg = RegionDifference[
   RegionUnion[Rectangle[{0, 0}, {L, L}], 
    Rectangle[{-L3, L4 - L2/2}, {0, L4 + L2/2}], 
    Rectangle[{-L3, (L - L4) - L2/2}, {0, (L - L4) + L2/2}]], 
   RegionUnion[Disk[{L, 0}, r], Disk[{2 d, L - 2 d}, r1]]];

Now we make boundary discretizations of the components and construct the region from those:

bdr = BoundaryDiscretizeRegion /@ reg[[2]];
bmr = Fold[RegionDifference, bdr]

enter image description here

Next, we create a NumericalRegion and attach the boundary mesh to it:

Needs["NDSolve`FEM`"]
nr = ToNumericalRegion[reg, RegionBounds[reg]];
bmesh = ToBoundaryMesh[bmr];
SetNumericalRegionElementMesh[nr, bmesh];

When we now mesh that numerical region have both the symbolic and the boundary representation available and a good approximation can be generated:

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

To compare the area of the mesh with the area of the symbolic representation we use:

narea = Total[mesh["MeshElementMeasure"], 2];

and

L = 1/5; d = 1/50; r = L - d; r1 = d; L2 = 1/250; L3 = 1/25; L4 = 
 L/8;
reg2 = RegionDifference[
   RegionUnion[Rectangle[{0, 0}, {L, L}], 
    Rectangle[{-L3, L4 - L2/2}, {0, L4 + L2/2}], 
    Rectangle[{-L3, (L - L4) - L2/2}, {0, (L - L4) + L2/2}]], 
   RegionUnion[Disk[{L, 0}, r], Disk[{2 d, L - 2 d}, r1]]];
sarea = Integrate[1, {x, y} \[Element] reg2];

The result:

narea - sarea
-2.4810104379269227`*^-7

I think this is quite good.

enter image description here

added 516 characters in body
Source Link
user21
  • 40.7k
  • 8
  • 114
  • 170

This should work:

ToElementMesh[reg,{{-0.04`, 0.2`}, {0.`, 0.2`}},
"MaxBoundaryCellMeasure" -> 0.005, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

mesh

The problem is that "Coninuation" fails (which needs to be investigated) and the "RegionPlot" one does need the "SamplePoints" (think "PlotPloints"). Hope this helps.

If you need a finer mesh you can use:

ToElementMesh[reg, {{-0.04`, 0.2`}, {0.`, 0.2`}}, 
  "MaxBoundaryCellMeasure" -> 0.005, "MaxCellMeasure" -> 0.00001, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

enter image description here

Edit

Here is a better way to do it:

mesh = ToElementMesh[reg, RegionBounds[reg], 
   "BoundaryMeshGenerator" -> {"BoundaryDiscretizeRegion"}, 
   "MaxBoundaryCellMeasure" -> 0.001, "MaxCellMeasure" -> 0.0001];
mesh["Wireframe"]

enter image description here

All of these methods are documented in ToBoundaryMesh. There you can find more info.

This should work:

ToElementMesh[reg,{{-0.04`, 0.2`}, {0.`, 0.2`}},
"MaxBoundaryCellMeasure" -> 0.005, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

mesh

The problem is that "Coninuation" fails (which needs to be investigated) and the "RegionPlot" one does need the "SamplePoints" (think "PlotPloints"). Hope this helps.

If you need a finer mesh you can use:

ToElementMesh[reg, {{-0.04`, 0.2`}, {0.`, 0.2`}}, 
  "MaxBoundaryCellMeasure" -> 0.005, "MaxCellMeasure" -> 0.00001, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

enter image description here

This should work:

ToElementMesh[reg,{{-0.04`, 0.2`}, {0.`, 0.2`}},
"MaxBoundaryCellMeasure" -> 0.005, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

mesh

The problem is that "Coninuation" fails (which needs to be investigated) and the "RegionPlot" one does need the "SamplePoints" (think "PlotPloints"). Hope this helps.

If you need a finer mesh you can use:

ToElementMesh[reg, {{-0.04`, 0.2`}, {0.`, 0.2`}}, 
  "MaxBoundaryCellMeasure" -> 0.005, "MaxCellMeasure" -> 0.00001, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

enter image description here

Edit

Here is a better way to do it:

mesh = ToElementMesh[reg, RegionBounds[reg], 
   "BoundaryMeshGenerator" -> {"BoundaryDiscretizeRegion"}, 
   "MaxBoundaryCellMeasure" -> 0.001, "MaxCellMeasure" -> 0.0001];
mesh["Wireframe"]

enter image description here

All of these methods are documented in ToBoundaryMesh. There you can find more info.

added 252 characters in body
Source Link
user21
  • 40.7k
  • 8
  • 114
  • 170

This should work:

ToElementMesh[reg,{{-0.04`, 0.2`}, {0.`, 0.2`}},
"MaxBoundaryCellMeasure" -> 0.005, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

mesh

The problem is that "Coninuation" fails (which needs to be investigated) and the "RegionPlot" one does need the "SamplePoints" (think "PlotPloints"). Hope this helps.

If you need a finer mesh you can use:

ToElementMesh[reg, {{-0.04`, 0.2`}, {0.`, 0.2`}}, 
  "MaxBoundaryCellMeasure" -> 0.005, "MaxCellMeasure" -> 0.00001, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

enter image description here

This should work:

ToElementMesh[reg,{{-0.04`, 0.2`}, {0.`, 0.2`}},
"MaxBoundaryCellMeasure" -> 0.005, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

mesh

The problem is that "Coninuation" fails (which needs to be investigated) and the "RegionPlot" one does need the "SamplePoints" (think "PlotPloints"). Hope this helps.

This should work:

ToElementMesh[reg,{{-0.04`, 0.2`}, {0.`, 0.2`}},
"MaxBoundaryCellMeasure" -> 0.005, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

mesh

The problem is that "Coninuation" fails (which needs to be investigated) and the "RegionPlot" one does need the "SamplePoints" (think "PlotPloints"). Hope this helps.

If you need a finer mesh you can use:

ToElementMesh[reg, {{-0.04`, 0.2`}, {0.`, 0.2`}}, 
  "MaxBoundaryCellMeasure" -> 0.005, "MaxCellMeasure" -> 0.00001, 
  "BoundaryMeshGenerator" -> {"RegionPlot", 
    "SamplePoints" -> 41}]["Wireframe"]

enter image description here

deleted 24 characters in body
Source Link
user21
  • 40.7k
  • 8
  • 114
  • 170
Loading
added 25 characters in body
Source Link
user21
  • 40.7k
  • 8
  • 114
  • 170
Loading
Source Link
user21
  • 40.7k
  • 8
  • 114
  • 170
Loading