Finite element mesh not resolving features
These should work:
Method 1
ToElementMesh[reg,{{-0.04`, 0.2`}, {0.`, 0.2`}},
"MaxBoundaryCellMeasure" -> 0.005,
"BoundaryMeshGenerator" -> {"RegionPlot",
"SamplePoints" -> 41}]["Wireframe"]
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"]
Method 2
Here is a better way to do it:
mesh = ToElementMesh[reg, RegionBounds[reg],
"BoundaryMeshGenerator" -> {"BoundaryDiscretizeRegion"},
"MaxBoundaryCellMeasure" -> 0.001, "MaxCellMeasure" -> 0.0001];
mesh["Wireframe"]
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]
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.
I've had success using AccuracyGoal -> 8
for meshing regions with small dimensions. (Note: Use fractions for greater accuracy)
Needs["NDSolve`FEM`"]
L = 2/10; (*Bracket side length*)
d = 2/100; (*End edge lenght*)
r = L - d; (*radius of curved edge*)
r1 = d; (*radius of hole*)
L2 = 4/1000; (*nail thickness*)
L3 = 4/100; (*nail length*)
L4 = L/8; (*location of nail from bottom*)
Y = 10^3; (*modulus of elasticity*)
ν = 33/100; (*Poisson ratio*)
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]]];
Show[Region[reg], PlotRange -> All, Frame -> True]
mesh = ToElementMesh[reg, {{-4/100, 2/10}, {0, 2/10}},
"MaxBoundaryCellMeasure" -> 0.001, MaxCellMeasure -> 1*^-5,
AccuracyGoal -> 7, MeshQualityGoal -> 1,
"BoundaryMeshGenerator" -> {"RegionPlot", "SamplePoints" -> 50}];
Show[mesh["Wireframe"], PlotRange -> All]