Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.10 KB | None | 0 0
  1. Needs["NDSolve`FEM`"];
  2. r1 = ImplicitRegion[x^2 + y^2 <= 100, {x, y}];
  3. r2 = ImplicitRegion[x^2 + (y - 5)^2 <= 4, {x, y}];
  4. reg = RegionDifference[r1, r2];
  5. bmesh = ToBoundaryMesh[reg, "MaxBoundaryCellMeasure" -> 0.5];
  6. mesh = ToElementMesh[bmesh, MaxCellMeasure -> 1];
  7. mesh["Wireframe"]
  8.  
  9. DynamicModule[{bL = 0.5, nn, bmesh, mesh, r = 10.2, mr, mcm, cL,
  10. x0 = -10, y0 = 7},
  11. bmesh = ToBoundaryMesh[reg, "MaxBoundaryCellMeasure" -> bL];
  12. mesh = ToElementMesh[bmesh];
  13. Column[{
  14. Row[{"Boundary Edge Length = ", Slider[Dynamic[bL, {(bL = # ) &,
  15. (bL = # ;
  16. bmesh = ToBoundaryMesh[reg, "MaxBoundaryCellMeasure" -> bL,
  17. AccuracyGoal -> 1];
  18.  
  19. mesh = ToElementMesh[bmesh,
  20. MaxCellMeasure -> mcm]) &}], {0.05, 5},
  21. Appearance -> "Labeled"],
  22. " Cell Area = ", Slider[Dynamic[mcm, {(mcm = # ) &,
  23. (mcm = # ;
  24. bmesh = ToBoundaryMesh[reg, "MaxBoundaryCellMeasure" -> bL,
  25. AccuracyGoal -> 1];
  26.  
  27. mesh = ToElementMesh[bmesh,
  28. MaxCellMeasure -> mcm]) &}], {0.05, 5},
  29. Appearance -> "Labeled"]}],
  30. Row[{"Approximate Cell Edge Length = ",
  31. Dynamic[cL = Sqrt[mcm 4/Sqrt[3]]]}],
  32. Dynamic@
  33. Show[Graphics[{{Orange,
  34. Triangle[{{x0, y0}, {x0 + cL, y0}, {x0 + cL/2,
  35. y0 + cL Sqrt[3]/2}}], Line[{{x0, y0}, {x0, y0 + bL}}]},
  36. Circle[{0, 0}, r],
  37. Table[Point[r {Cos[n 2 [Pi]/nn], Sin[n 2 [Pi]/nn]}], {n,
  38. nn = Round[2 [Pi] r/bL]}]}, ImageSize -> 10 72,
  39. Frame -> True],
  40. mr =
  41. MeshRegion[mesh,
  42. MeshCellStyle -> {0 -> {PointSize[0.002], Red}, 1 -> Black,
  43. 2 -> White}]
  44. ]
  45. }]
  46. ]
  47.  
  48. Lx = 20; Ly = 30;
  49. coords = {{0, 0}, {Lx, 0}, {Lx, Ly}, {0, Ly}, {Lx/4, Ly/2}, {Lx/2, Ly/
  50. 2}, {Lx/2, (3 Ly)/4}, {Lx/4, 3 Ly/4}};
  51. ClearAll[makeBM];
  52. makeBM[bL_] := ToBoundaryMesh[
  53. "Coordinates" -> coords,
  54. "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4,
  55. 1}}], LineElement[{{5, 6}, {6, 7}, {7, 8}, {8, 5}}]},
  56. "RegionHoles" -> {{(3 Lx)/8, 5 Ly/8}},
  57. "MaxBoundaryCellMeasure" -> bL
  58. ];
  59.  
  60. DynamicModule[{bL = 0.5, nn, bmesh, mesh, r = 10.2, mr, mcm, cL,
  61. x0 = -5, y0 = 25},
  62. bmesh = makeBM[bL];
  63. mesh = ToElementMesh[bmesh, MaxCellMeasure -> mcm];
  64. Column[{
  65. Row[{"Boundary Edge Length = ", Slider[Dynamic[bL, {(bL = # ) &,
  66. (bL = # ; bmesh = makeBM[bL];
  67.  
  68. mesh = ToElementMesh[bmesh,
  69. MaxCellMeasure -> {"Area" -> mcm}]) &}],
  70. {0.05, 5}, Appearance -> "Labeled"],
  71. " Cell Area = ", Slider[Dynamic[mcm, {(mcm = # ) &,
  72. (mcm = # ; bmesh = makeBM[bL];
  73.  
  74. mesh = ToElementMesh[bmesh,
  75. MaxCellMeasure -> {"Area" -> mcm}]) &}], {0.05, 5},
  76. Appearance -> "Labeled"]}],
  77. Row[{"Approximate Cell Edge Length = ",
  78. Dynamic[cL = Sqrt[mcm 4/Sqrt[3]]]}],
  79. Dynamic@
  80. Show[Graphics[{{Orange,
  81. Triangle[{{x0, y0}, {x0 + cL, y0}, {x0 + cL/2,
  82. y0 + cL Sqrt[3]/2}}], Line[{{x0, y0}, {x0, y0 + bL}}]}},
  83. ImageSize -> 10 72, Frame -> True],
  84. mr =
  85. MeshRegion[mesh,
  86. MeshCellStyle -> {0 -> {PointSize[0.002], Red}, 1 -> Black,
  87. 2 -> White}]
  88. ]
  89. }]
  90. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement