Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Needs["NDSolve`FEM`"];
- r1 = ImplicitRegion[x^2 + y^2 <= 100, {x, y}];
- r2 = ImplicitRegion[x^2 + (y - 5)^2 <= 4, {x, y}];
- reg = RegionDifference[r1, r2];
- bmesh = ToBoundaryMesh[reg, "MaxBoundaryCellMeasure" -> 0.5];
- mesh = ToElementMesh[bmesh, MaxCellMeasure -> 1];
- mesh["Wireframe"]
- DynamicModule[{bL = 0.5, nn, bmesh, mesh, r = 10.2, mr, mcm, cL,
- x0 = -10, y0 = 7},
- bmesh = ToBoundaryMesh[reg, "MaxBoundaryCellMeasure" -> bL];
- mesh = ToElementMesh[bmesh];
- Column[{
- Row[{"Boundary Edge Length = ", Slider[Dynamic[bL, {(bL = # ) &,
- (bL = # ;
- bmesh = ToBoundaryMesh[reg, "MaxBoundaryCellMeasure" -> bL,
- AccuracyGoal -> 1];
- mesh = ToElementMesh[bmesh,
- MaxCellMeasure -> mcm]) &}], {0.05, 5},
- Appearance -> "Labeled"],
- " Cell Area = ", Slider[Dynamic[mcm, {(mcm = # ) &,
- (mcm = # ;
- bmesh = ToBoundaryMesh[reg, "MaxBoundaryCellMeasure" -> bL,
- AccuracyGoal -> 1];
- mesh = ToElementMesh[bmesh,
- MaxCellMeasure -> mcm]) &}], {0.05, 5},
- Appearance -> "Labeled"]}],
- Row[{"Approximate Cell Edge Length = ",
- Dynamic[cL = Sqrt[mcm 4/Sqrt[3]]]}],
- Dynamic@
- Show[Graphics[{{Orange,
- Triangle[{{x0, y0}, {x0 + cL, y0}, {x0 + cL/2,
- y0 + cL Sqrt[3]/2}}], Line[{{x0, y0}, {x0, y0 + bL}}]},
- Circle[{0, 0}, r],
- Table[Point[r {Cos[n 2 [Pi]/nn], Sin[n 2 [Pi]/nn]}], {n,
- nn = Round[2 [Pi] r/bL]}]}, ImageSize -> 10 72,
- Frame -> True],
- mr =
- MeshRegion[mesh,
- MeshCellStyle -> {0 -> {PointSize[0.002], Red}, 1 -> Black,
- 2 -> White}]
- ]
- }]
- ]
- Lx = 20; Ly = 30;
- coords = {{0, 0}, {Lx, 0}, {Lx, Ly}, {0, Ly}, {Lx/4, Ly/2}, {Lx/2, Ly/
- 2}, {Lx/2, (3 Ly)/4}, {Lx/4, 3 Ly/4}};
- ClearAll[makeBM];
- makeBM[bL_] := ToBoundaryMesh[
- "Coordinates" -> coords,
- "BoundaryElements" -> {LineElement[{{1, 2}, {2, 3}, {3, 4}, {4,
- 1}}], LineElement[{{5, 6}, {6, 7}, {7, 8}, {8, 5}}]},
- "RegionHoles" -> {{(3 Lx)/8, 5 Ly/8}},
- "MaxBoundaryCellMeasure" -> bL
- ];
- DynamicModule[{bL = 0.5, nn, bmesh, mesh, r = 10.2, mr, mcm, cL,
- x0 = -5, y0 = 25},
- bmesh = makeBM[bL];
- mesh = ToElementMesh[bmesh, MaxCellMeasure -> mcm];
- Column[{
- Row[{"Boundary Edge Length = ", Slider[Dynamic[bL, {(bL = # ) &,
- (bL = # ; bmesh = makeBM[bL];
- mesh = ToElementMesh[bmesh,
- MaxCellMeasure -> {"Area" -> mcm}]) &}],
- {0.05, 5}, Appearance -> "Labeled"],
- " Cell Area = ", Slider[Dynamic[mcm, {(mcm = # ) &,
- (mcm = # ; bmesh = makeBM[bL];
- mesh = ToElementMesh[bmesh,
- MaxCellMeasure -> {"Area" -> mcm}]) &}], {0.05, 5},
- Appearance -> "Labeled"]}],
- Row[{"Approximate Cell Edge Length = ",
- Dynamic[cL = Sqrt[mcm 4/Sqrt[3]]]}],
- Dynamic@
- Show[Graphics[{{Orange,
- Triangle[{{x0, y0}, {x0 + cL, y0}, {x0 + cL/2,
- y0 + cL Sqrt[3]/2}}], Line[{{x0, y0}, {x0, y0 + bL}}]}},
- ImageSize -> 10 72, Frame -> True],
- mr =
- MeshRegion[mesh,
- MeshCellStyle -> {0 -> {PointSize[0.002], Red}, 1 -> Black,
- 2 -> White}]
- ]
- }]
- ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement