2
$\begingroup$

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"]}]

The output is as this: enter image description here

$\endgroup$

1 Answer 1

2
$\begingroup$
netz[
n_ (*number of teeths*), 
L_(*total length*), 
H_ (*total height*)] := Block[{
\[CapitalDelta]H = H/2 (*toothheight*),
\[CapitalDelta]L = L/(n + n - 1)  (*toothwidth*),p, lines},
p = Join[{{0, 0}, {\[CapitalDelta]L, 0}},
Table[{{k \[CapitalDelta]L, \[CapitalDelta]H}, {(k +1)\[CapitalDelta]L, \[CapitalDelta]H}, {(k + 1) \[CapitalDelta]L, 0},{(k + 2) \[CapitalDelta]L,0}}, {k, 1, 2 n - 3, 2}] // Flatten[#, 1]&,
{{L, H}, {0, H}}] ;
lines =Join[Table[{k, k + 1}, {k, 1, Length[p ] - 1}], {{Length[p ],1}}];
ToBoundaryMesh["Coordinates" -> p,"BoundaryElements" -> {LineElement[lines]}]
]

netz[7, 1, 1/3] ["Wireframe"]

enter image description here

$\endgroup$

Your Answer

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

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