14
$\begingroup$

I am trying to use the FEMAddOns package to make a structured mesh with a hole and then extrude it. As a warm up example this worked nicely.

Needs["FEMAddOns`"]
pts1 = Table[
  25. ( Cos[θ]^2 + 1) {Cos[θ], Sin[θ]} // 
   N, {θ, 0, 2 π, (2 π)/360}]; pts2 = 
 Table[10. {Cos[θ], Sin[θ]} // N, {θ, 0, 
   2 π, (2 π)/360}];
mesh = StructuredMesh[{pts1, pts2}, {90, 20}];
mesh["Wireframe"] 

Mathematica graphics

So now I tried my actual problem which has a rectangular boundary.

Lx = 100;
Ly = 50;
pts1 = DeleteDuplicates@Join[
    Table[{Lx, L}, {L, 0, Ly, Ly/(2 50)}],
    Table[{L, Ly}, {L, Lx, -Lx, -(Lx/(2 100))}], 
    Table[{-Lx, L}, {L, Ly, -Ly, -(Ly/(2 100))}],
    Table[{L, -Ly}, {L, -Lx, Lx, Lx/(2 100)}],
    Table[{Lx, L}, {L, -Ly, 0, Ly/(2 50)}]
    ];
mesh = StructuredMesh[{pts1, pts2}, {90, 20}];
mesh["Wireframe"]

This fails with the message

(* StructuredMesh::array: Raster of input points must be a full array of numbers with depth of 4. *)

Can this be fixed? Can I then extrude the mesh?

Thanks

$\endgroup$
13
$\begingroup$

Update: New version of FEMAddOns v1.4.2 includes ExtrudeMesh

@user21 updated FEMAddOns and ExtrudeMesh is included. Now, you only need to call FEMAddOns and don't need to worry about namespace collisions with MeshTools. For completeness, here is the updated workflow to get the latest version of FEMAddOns and extend Alex's answer by two lines:

ResourceFunction["FEMAddOnsInstall"][]
Needs["FEMAddOns`"]
(* From Alex Trounev's Answer *)
Lx = 100;
Ly = 50; r[t_] := 
 Piecewise[{{Lx/Cos[t], 0 <= t <= ArcTan[Ly/Lx]}, {Ly/Sin[t], 
    ArcTan[Ly/Lx] < t <= Pi - ArcTan[Ly/Lx]}, {-Lx/Cos[t], 
    Pi - ArcTan[Ly/Lx] < t <= Pi + ArcTan[Ly/Lx]}, {-Ly/Sin[t], 
    Pi + ArcTan[Ly/Lx] < t <= 2 Pi - ArcTan[Ly/Lx]}, {Lx/Cos[t], 
    2 Pi - ArcTan[Ly/Lx] < t <= 2 Pi}}]; pts1 = 
 Table[r[θ] {Cos[θ], Sin[θ]} // N, {θ, 0, 
   2 π, 2 Pi/360}]; pts2 = 
 Table[10. {Cos[θ], Sin[θ]} // N, {θ, 0, 2 π,
    2 Pi/360}];
mesh2D = StructuredMesh[{pts1, pts2}, {96, 16}];
mesh2D["Wireframe"]
(* Extrude the mesh *)
mesh3D = ExtrudeMesh[mesh2D, 40, 6];
mesh3D["Wireframe"]

Original Answer

This is an extension of Alex Trounev's answer because I found a potential version problem with FEMAddOns package. Perhaps someone can confirm.

If you download the latest version (v1.4.0) of FEMAddOns, you will see that ExtrudeMesh appears to be missing.

ResourceFunction["FEMAddOnsInstall"][]
Needs["FEMAddOns`"]
SystemOpen["paclet:FEMAddOns/guide/FEMAddOns"]

paclet version

FEMAddOns Documentation

A potential workaround is to download MeshTools directly as shown in the following:

ClearAll["Global`*"]
ResourceFunction["GitHubInstall"]["c3m-labs", "MeshTools"]
Needs["MeshTools`"]
(* From Alex Trounev's Answer *)
Lx = 100;
Ly = 50; r[t_] := 
 Piecewise[{{Lx/Cos[t], 0 <= t <= ArcTan[Ly/Lx]}, {Ly/Sin[t], 
    ArcTan[Ly/Lx] < t <= Pi - ArcTan[Ly/Lx]}, {-Lx/Cos[t], 
    Pi - ArcTan[Ly/Lx] < t <= Pi + ArcTan[Ly/Lx]}, {-Ly/Sin[t], 
    Pi + ArcTan[Ly/Lx] < t <= 2 Pi - ArcTan[Ly/Lx]}, {Lx/Cos[t], 
    2 Pi - ArcTan[Ly/Lx] < t <= 2 Pi}}]; pts1 = 
 Table[r[θ] {Cos[θ], Sin[θ]} // N, {θ, 0, 
   2 π, 2 Pi/360}]; pts2 = 
 Table[10. {Cos[θ], Sin[θ]} // N, {θ, 0, 2 π,
    2 Pi/360}];
mesh2D = StructuredMesh[{pts1, pts2}, {96, 16}];
mesh2D["Wireframe"]
(* Extrude the mesh *)
mesh3D = ExtrudeMesh[mesh2D, 40, 6];
mesh3D["Wireframe"]

Extruded Mesh

| improve this answer | |
$\endgroup$
  • 6
    $\begingroup$ I have made a new FEMAddOns release that has the ExtudeMesh included. $\endgroup$ – user21 Jun 26 at 6:55
  • $\begingroup$ It looks like ExtrudeMesh[] on in my version, but not working without Needs["MeshTools"]. After that there are two messages coming: ExtrudeMesh::shdw: Symbol ExtrudeMesh appears in multiple contexts {MeshTools,Global}; definitions in context MeshTools may shadow or be shadowed by other definitions. StructuredMesh::shdw: Symbol StructuredMesh appears in multiple contexts {MeshTools,FEMUtils}; definitions in context MeshTools` may shadow or be shadowed by other definitions.` $\endgroup$ – Alex Trounev Jun 26 at 10:13
  • $\begingroup$ @user21 Thanks! I knew you would quickly resolve the issue. I was confused for a bit why ExtrudeMesh was not working, but all is good now. $\endgroup$ – Tim Laska Jun 26 at 13:18
  • 1
    $\begingroup$ @AlexTrounev I saw the same warnings. There are a lot on namespace collisions when you try to load both FEMAddOns and MeshTools. Fortunately, @user21 updated FEMAddOns (which technically should include the full MeshTools) so that you only need call FEMAddOns now. $\endgroup$ – Tim Laska Jun 26 at 13:22
  • 1
    $\begingroup$ Thanks Tim. This has got me going again. Also, thanks user21 for his rapid response.. $\endgroup$ – Hugh Jun 26 at 13:24
12
$\begingroup$

We can play with numbers to get an ideal mesh. As a stating point you could use this one:

Needs["MeshTools`"](*Needs["FEMAddOns`"]*)
Lx = 100;
Ly = 50; r[t_] := 
 Piecewise[{{Lx/Cos[t], 0 <= t <= ArcTan[Ly/Lx]}, {Ly/Sin[t], 
    ArcTan[Ly/Lx] < t <= Pi - ArcTan[Ly/Lx]}, {-Lx/Cos[t], 
    Pi - ArcTan[Ly/Lx] < t <= Pi + ArcTan[Ly/Lx]}, {-Ly/Sin[t], 
    Pi + ArcTan[Ly/Lx] < t <= 2 Pi - ArcTan[Ly/Lx]}, {Lx/Cos[t], 
    2 Pi - ArcTan[Ly/Lx] < t <= 2 Pi}}]; pts1 = 
 Table[r[\[Theta]] {Cos[\[Theta]], Sin[\[Theta]]} // N, {\[Theta], 0, 
   2 \[Pi], 2 Pi/360}]; pts2 = 
 Table[10. {Cos[\[Theta]], Sin[\[Theta]]} // N, {\[Theta], 0, 2 \[Pi],
    2 Pi/360}];
mesh = StructuredMesh[{pts1, pts2}, {96, 16}];
mesh["Wireframe"] 

Figure 1

Thanks Tim Laska for explanation interface with MeshTools. Since I have MeshTools installed, I call directly

mesh3D = ExtrudeMesh[mesh, 42, 9];
mesh3D["Wireframe"["MeshElementStyle" -> EdgeForm[Gray]]] 

Figure 2

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks Alex. What order mesh do you get? Will ToElementMesh give a first order or second order? $\endgroup$ – Hugh Jun 26 at 13:22
  • $\begingroup$ @Hugh Just call mesh["MeshOrder"] and get answer 1. In a case of ToElementMesh we have order 2 as Automatic option and order 1 with option "MeshOrder"->1 . $\endgroup$ – Alex Trounev Jun 26 at 15:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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