FEM Mesh for pipes and tubes - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-10-14T00:06:53Z https://mathematica.stackexchange.com/feeds/question/134731 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/134731 8 FEM Mesh for pipes and tubes Hugh https://mathematica.stackexchange.com/users/12558 2017-01-04T11:25:52Z 2017-01-04T19:15:44Z <p>I work with pipe systems and would like to use finite elements within <a href="http://reference.wolfram.com/language/ref/NDSolve.html" rel="nofollow noreferrer"><code>NDSolve</code></a> for regions inside or exterior to a pipe. How to do I make a mesh of the region interior or exterior to a complex pipe geometry. Here is a very simple geometry. </p> <pre><code>Needs["NDSolve`FEM`"]; L1 = 10; L2 = 5; r = 0.5; R1 = 2; p1 = ParametricPlot3D[{x, r Cos[θ], r Sin[θ]}, {x, 0, L1}, {θ, -π, π}]; p2 = ParametricPlot3D[{L1 + Cos[t] (R1 + r Cos[u]), r Sin[u], R1 + Sin[t] (R1 + r Cos[u])}, {t, -(π/2), 0}, {u, 0, 2 π}]; p3 = ParametricPlot3D[{L1 + R1 + r Cos[θ], r Sin[θ], z + R1}, {z, 0, L2}, {θ, -π, π}]; Show[p1, p2, p3, PlotRange -&gt; {{-5, L1 + 5}, {-5, 5}, {-5, L2 + 5}}] </code></pre> <p><img src="https://i.stack.imgur.com/rtYzz.png" alt="Mathematica graphics"></p> <p>How do I convert this into a mesh within the pipe or in a cuboid external to the pipe?</p> <p>I have tried <a href="http://reference.wolfram.com/language/ref/DiscretizeRegion.html" rel="nofollow noreferrer"><code>DiscretizeRegion</code></a> but this only works for an ImplicitRegion. Do I have to turn my parametric region into an implicit region? Is there code for doing this? Are there other methods. </p> <p><strong>Edit 1</strong></p> <p>I have been working on using <a href="http://reference.wolfram.com/language/ref/ImplicitRegion.html" rel="nofollow noreferrer"><code>ImplicitRegion</code></a> and have come up with the following</p> <pre><code>ir = ImplicitRegion[(0 &lt;= x &lt;= L1 &amp;&amp; y^2 + z^2 == r^2) || ((R1 - Sqrt[(x - L1)^2 + (z - R1)^2])^2 + y^2 == r^2 &amp;&amp; L1 &lt;= x &lt;= L1 + R1 + r &amp;&amp; -R1 - r &lt;= z &lt;= R1) || (R1 &lt;= z &lt;= L2 &amp;&amp; y^2 + (x - L1 - R1)^2 == r^2), {x, y, z}]; DiscretizeRegion[ir, MaxCellMeasure -&gt; 0.01 r] </code></pre> <p><img src="https://i.stack.imgur.com/Kh3C1.png" alt="Mathematica graphics"></p> <p>Clearly I need some helper functions that will return the implicit functions for general pipe and bend locations. Are there methods for this? Are there better methods than this?</p> <p><strong>Edit 2</strong></p> <p>Following the suggestion of user9490 (thank you) I continue with the parametric plots and fill in the ends. </p> <pre><code>Needs["NDSolve`FEM`"]; L1 = 10; L2 = 5; r = 0.5; R1 = 2; p1 = ParametricPlot3D[{x, r Cos[θ], r Sin[θ]}, {x, 0, L1}, {θ, -π, π}]; p2 = ParametricPlot3D[{L1 + Cos[t] (R1 + r Cos[u]), r Sin[u], R1 + Sin[t] (R1 + r Cos[u])}, {t, -(π/2), 0}, {u, 0, 2 π}]; p3 = ParametricPlot3D[{L1 + R1 + r Cos[θ], r Sin[θ], z + R1}, {z, 0, L2}, {θ, -π, π}]; p4 = ParametricPlot3D[{0 , a Cos[θ], a Sin[θ]}, {a, 0, r}, {θ, -π, π}]; p5 = ParametricPlot3D[{L1 + R1 + a Cos[θ], a Sin[θ], L2 + R1}, {a, 0, r}, {θ, -π, π}]; g = Show[p1, p2, p3, p4, p5, PlotRange -&gt; {{-5, L1 + 5}, {-5, 5}, {-5, L2 + 5}}] </code></pre> <p><img src="https://i.stack.imgur.com/Cucpo.png" alt="Mathematica graphics"></p> <p>Now I go on to make discretized graphics item</p> <pre><code>a = DiscretizeGraphics[ Normal[g /. (Lighting -&gt; _) :&gt; Lighting -&gt; Automatic]] </code></pre> <p><img src="https://i.stack.imgur.com/QTxg7.png" alt="Mathematica graphics"></p> <p>This has worked but when I try to make a boundary mesh I get a poor quality mesh</p> <pre><code>b = ToBoundaryMesh[a, MaxCellMeasure -&gt; 0.2 r]; b["Wireframe"] </code></pre> <p><img src="https://i.stack.imgur.com/s2vo4.png" alt="Mathematica graphics"></p> <p>This is very clear if you zoom in</p> <pre><code>Show[b["Wireframe"], PlotRange -&gt; {{-1, 1}, {-1, 1}, {-1, 1}}] </code></pre> <p><img src="https://i.stack.imgur.com/DnPv3.png" alt="Mathematica graphics"></p> <p>Trying to make a three dimensional mesh fails. The MaxCellMeasure seems to have been ignored. So this approach goes further but I am not getting the 3D mesh I need for finite element work. Any ideas? </p>