I want to plot the square wave region for FEM solver, and when the tooth number of the square region is 3, then the total coordinates is 12, when the tooth number of the square region is n
,then the total coordinates is 4n
, so it is inconvenient to list all the coordinate and its x
and y
value manfully, so is there a better way to define this region, for example you just have to indicate the tooth number(maybe 20), then you can get the region you want?
The codes are as follows:
Needs["NDSolve`FEM`"];
(*sh=0.2;sh2=0.02;sw=0.3;*)
ToothNumber = 3;
SlotNumber = ToothNumber - 1;
RectangleNumber = ToothNumber + SlotNumber;
ToothLength = 0.1;
ToothHeight = 0.1;
SlotHeight = 0.1;
coordinates = {{0., 0.}, {ToothLength, 0}, {ToothLength,
ToothHeight}, {2*ToothLength, ToothHeight}, {2*ToothLength,
0}, {3*ToothLength, 0}, {3*ToothLength,
ToothHeight}, {4*ToothLength, ToothHeight}, {4*ToothLength,
0}, {5*ToothLength, 0}, {5*ToothLength,
ToothHeight + SlotHeight}, {0, ToothHeight + SlotHeight}};
el1 = LineElement[{{1, 2}, {2, 3}, {3, 4}, {4, 5}, {5, 6}, {6, 7}, {7,
8}, {8, 9}, {9, 10}, {10, 11}, {11, 12}, {12, 1}}];
bMesh2 = ToBoundaryMesh["Coordinates" -> coordinates,
"BoundaryElements" -> {el1}];
GraphicsRow[{bMesh2["Wireframe"]}]