5
$\begingroup$

I want to generate a mesh on the following domain that has finer mesh elements near the edges of the seven disks. How can I do so?

Needs["NDSolve`FEM`"]

Domain[scale_, radius_] := RegionDifference[
   Polygon[{{1, 0}, {1/2, Sqrt[3]/2}, {-1/2, Sqrt[3]/2}, {-1, 0}, {-1/2, -Sqrt[3]/2}, {1/2, -Sqrt[3]/2}}*scale],
   RegionUnion[
    Disk[{0, 0}, radius*scale], 
    Disk[{1, 0}, radius*scale],
    Disk[{1/2, Sqrt[3]/2}, radius*scale], 
    Disk[{-1/2, Sqrt[3]/2}, radius*scale], 
    Disk[{-1, 0}, radius*scale], 
    Disk[{-1/2, -Sqrt[3]/2}, radius*scale], 
    Disk[{1/2, -Sqrt[3]/2}, radius*scale]]];

ToElementMesh[Domain[1, 0.2], MaxCellMeasure -> .001]["Wireframe"]

enter image description here

$\endgroup$
1
  • 1
    $\begingroup$ Please look at the documentation for ToElementMesh, and find MeshRefinementFunction option. $\endgroup$
    – Domen
    Commented Aug 11 at 19:33

1 Answer 1

6
$\begingroup$

Got it.

Needs["NDSolve`FEM`"]

Domain[scale_, radius_] := RegionDifference[
   Polygon[{{1, 0}, {1/2, Sqrt[3]/2}, {-1/2, Sqrt[3]/2}, {-1, 
       0}, {-1/2, -Sqrt[3]/2}, {1/2, -Sqrt[3]/2}}*scale],
   RegionUnion[Disk[{0, 0}*scale, radius], Disk[{1, 0} scale, radius],
     Disk[{1/2, Sqrt[3]/2}*scale, radius], 
    Disk[{-1/2, Sqrt[3]/2}*scale, radius], 
    Disk[{-1, 0}*scale, radius], 
    Disk[{-1/2, -Sqrt[3]/2}*scale, radius], 
    Disk[{1/2, -Sqrt[3]/2}*scale, radius]]];

refinementFunction[scale_, radius_] := 
  Function[{vertices, area}, 
   Block[{x, y}, {x, y} = Mean[vertices]; 
    If[Sqrt[x^2 + y^2] > 1.1*radius && 
      Sqrt[(x - scale)^2 + y^2] > 1.05*radius && 
      Sqrt[(x + scale)^2 + y^2] > 1.05*radius && 
      Sqrt[(x - 0.5*scale)^2 + (y - Sqrt[3]/2*scale)^2] > 
       1.05*radius && 
      Sqrt[(x - 0.5*scale)^2 + (y + Sqrt[3]/2*scale)^2] > 
       1.05*radius && 
      Sqrt[(x + 0.5*scale)^2 + (y - Sqrt[3]/2*scale)^2] > 
       1.05*radius && 
      Sqrt[(x + 0.5*scale)^2 + (y + Sqrt[3]/2*scale)^2] > 1.05*radius,
      area > 0.001*(scale)^2, area > 0.0000003*(scale)^2]]];

ToElementMesh[Domain[50*^-6, 12.5*^-6], 
  MaxCellMeasure -> .001*(50*^-6)^2, 
  MeshRefinementFunction -> 
   refinementFunction[50*^-6, 12.5*^-6]]["Wireframe"]

enter image description here

$\endgroup$

Your Answer

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

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