Skip to main content
Further option required to make the code work
Source Link
Hugh
  • 16.8k
  • 3
  • 32
  • 85

Combining the suggestions from the answers below is successful.

Further edit

If you use this mesh you will need to use the workaround from this question. Add the option "ImproveBoundaryPosition" -> False to ToElementMesh. The mesh coordinates are not all contained within the solution interpolation function. So the final ToElementMesh expression was

mesh = ToElementMesh[reg, {{-L3, L}, {0, L}}, 
   "MaxBoundaryCellMeasure" -> 0.001, MaxCellMeasure -> 1.1*^-6, 
   AccuracyGoal -> 8, MeshQualityGoal -> 1, 
   "BoundaryMeshGenerator" -> {"RegionPlot", "SamplePoints" -> 200},
   "ImproveBoundaryPosition" -> False];

and it worked to give this mesh

Mathematica graphics

Combining the suggestions from the answers below is successful.

Further edit

If you use this mesh you will need to use the workaround from this question. Add the option "ImproveBoundaryPosition" -> False to ToElementMesh. The mesh coordinates are not all contained within the solution interpolation function. So the final ToElementMesh expression was

mesh = ToElementMesh[reg, {{-L3, L}, {0, L}}, 
   "MaxBoundaryCellMeasure" -> 0.001, MaxCellMeasure -> 1.1*^-6, 
   AccuracyGoal -> 8, MeshQualityGoal -> 1, 
   "BoundaryMeshGenerator" -> {"RegionPlot", "SamplePoints" -> 200},
   "ImproveBoundaryPosition" -> False];

and it worked to give this mesh

Mathematica graphics

Additional problems put in as an extra edit.
Source Link
Hugh
  • 16.8k
  • 3
  • 32
  • 85

I am trying to make a finite element mesh in 2D. The features are not found by ToElementMesh. This is a shelf bracket with nails. I build the region using RegionDifference and RegionUnion and the result is clear.

   Needs["NDSolve`FEM`"]
L = 0.2; (* Bracket side length *)
d = 0.02;  (* End edge lenght *)
r = L - d;   (* radius of curved edge *)
r1 = d;    (* radius of hole *)
L2 = 0.004; (* nail thickness *)
L3 = 0.04; (* 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]

Mathematica graphics

This region looks good. Now I try to mesh.

mesh = ToElementMesh[reg, "BoundaryMeshGenerator" -> "Continuation", 
   "MaxBoundaryCellMeasure" -> 0.001, "MaxCellMeasure" -> 0.0001];
Show[mesh["Wireframe"], PlotRange -> All]

Mathematica graphics

The nails have been lost and the edges are very poorly represented. I have tried different options for ToElementMesh but have not hit on one that works. What is happening? Version 11.1 for Windows. Thanks

Edit

Helpful user21 gave a solution below which works for the resolution in his example. I have tried to increase the resolution and this is what happens.

mesh = ToElementMesh[reg, {{-0.04`, 0.2`}, {0.`, 0.2`}}, 
   "MaxBoundaryCellMeasure" -> 0.001, 
   "BoundaryMeshGenerator" -> {"RegionPlot", "SamplePoints" -> 200} ];
Show[mesh["Wireframe"], PlotRange -> All]

Mathematica graphics

The curved boundaries and the lower part of the vertical straight boundary are badly formed. I would like a high resolution because when doing stress calculations gradients of the solution are needed. Any more thoughts?

I am trying to make a finite element mesh in 2D. The features are not found by ToElementMesh. This is a shelf bracket with nails. I build the region using RegionDifference and RegionUnion and the result is clear.

   Needs["NDSolve`FEM`"]
L = 0.2; (* Bracket side length *)
d = 0.02;  (* End edge lenght *)
r = L - d;   (* radius of curved edge *)
r1 = d;    (* radius of hole *)
L2 = 0.004; (* nail thickness *)
L3 = 0.04; (* 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]

Mathematica graphics

This region looks good. Now I try to mesh.

mesh = ToElementMesh[reg, "BoundaryMeshGenerator" -> "Continuation", 
   "MaxBoundaryCellMeasure" -> 0.001, "MaxCellMeasure" -> 0.0001];
Show[mesh["Wireframe"], PlotRange -> All]

Mathematica graphics

The nails have been lost and the edges are very poorly represented. I have tried different options for ToElementMesh but have not hit on one that works. What is happening? Version 11.1 for Windows. Thanks

I am trying to make a finite element mesh in 2D. The features are not found by ToElementMesh. This is a shelf bracket with nails. I build the region using RegionDifference and RegionUnion and the result is clear.

   Needs["NDSolve`FEM`"]
L = 0.2; (* Bracket side length *)
d = 0.02;  (* End edge lenght *)
r = L - d;   (* radius of curved edge *)
r1 = d;    (* radius of hole *)
L2 = 0.004; (* nail thickness *)
L3 = 0.04; (* 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]

Mathematica graphics

This region looks good. Now I try to mesh.

mesh = ToElementMesh[reg, "BoundaryMeshGenerator" -> "Continuation", 
   "MaxBoundaryCellMeasure" -> 0.001, "MaxCellMeasure" -> 0.0001];
Show[mesh["Wireframe"], PlotRange -> All]

Mathematica graphics

The nails have been lost and the edges are very poorly represented. I have tried different options for ToElementMesh but have not hit on one that works. What is happening? Version 11.1 for Windows. Thanks

Edit

Helpful user21 gave a solution below which works for the resolution in his example. I have tried to increase the resolution and this is what happens.

mesh = ToElementMesh[reg, {{-0.04`, 0.2`}, {0.`, 0.2`}}, 
   "MaxBoundaryCellMeasure" -> 0.001, 
   "BoundaryMeshGenerator" -> {"RegionPlot", "SamplePoints" -> 200} ];
Show[mesh["Wireframe"], PlotRange -> All]

Mathematica graphics

The curved boundaries and the lower part of the vertical straight boundary are badly formed. I would like a high resolution because when doing stress calculations gradients of the solution are needed. Any more thoughts?

Tweeted twitter.com/StackMma/status/910501065828847618
Source Link
Hugh
  • 16.8k
  • 3
  • 32
  • 85

Finite element mesh not resolving features

I am trying to make a finite element mesh in 2D. The features are not found by ToElementMesh. This is a shelf bracket with nails. I build the region using RegionDifference and RegionUnion and the result is clear.

   Needs["NDSolve`FEM`"]
L = 0.2; (* Bracket side length *)
d = 0.02;  (* End edge lenght *)
r = L - d;   (* radius of curved edge *)
r1 = d;    (* radius of hole *)
L2 = 0.004; (* nail thickness *)
L3 = 0.04; (* 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]

Mathematica graphics

This region looks good. Now I try to mesh.

mesh = ToElementMesh[reg, "BoundaryMeshGenerator" -> "Continuation", 
   "MaxBoundaryCellMeasure" -> 0.001, "MaxCellMeasure" -> 0.0001];
Show[mesh["Wireframe"], PlotRange -> All]

Mathematica graphics

The nails have been lost and the edges are very poorly represented. I have tried different options for ToElementMesh but have not hit on one that works. What is happening? Version 11.1 for Windows. Thanks