1
$\begingroup$

I'm trying to plot a finite element mesh with its node id's. But i'm facing a problem with the ListLinePlot, which connects all poits, instead connect only the neighbour node. I need to eliminate the diagonal lines from the following ListLinePlot:

topol={{4, 1, 5, 8, 3, 2, 6, 7}, {5, 13, 17, 8, 10, 15, 11, 6},
       {30, 37, 35, 26, 33, 36, 31, 28}, {35, 32, 24, 26, 34, 29, 25, 31},
       {17, 23, 18, 8, 20, 21, 12, 11}, {4, 8, 18, 14, 7, 12, 16, 9},
       {24, 14, 18, 26, 19, 16, 22, 25}, {26, 18, 23, 30, 22, 21, 27, 28}};

nnodes = {{0, 6}, {0, 4.5}, {2.5, 6}, {0, 3}, {2.5, 3}, {0, 1.5}, {5, 6},
          {5, 4.5}, {5, 3}, {0, 0}, {2.5, 0}, {5, 1.5}, {7.5, 6}, {5, 0},
          {7.5, 3}, {7.5, 0}, {10, 6}, {10, 4.5}, {10, 3}, {10, 1.5}, {10, 0}};

 allcoords = {{{5, 0}, {5, 3}, {0, 3}, {0, 0}, {5, 1.5}, {2.5, 3}, {0, 1.5}, {2.5, 0}}, 
              {{10, 0}, {10, 3}, {5, 3}, {5, 0}, {10, 1.5}, {7.5, 3}, {5, 1.5}, {7.5, 0}},
              {{5, 3}, {5, 6}, {0, 6}, {0, 3}, {5, 4.5}, {2.5, 6}, {0, 4.5}, {2.5, 3}},
              {{10, 3}, {10, 6}, {5, 6}, {5, 3}, {10, 4.5}, {7.5, 6}, {5, 4.5}, {7.5, 3}}};

nodeids = 
  ListPlot[Table[Labeled[nnodes[[i]], i], {i, Length@nnodes}], 
   AspectRatio -> Automatic];
undefplot = 
  ListLinePlot[Tooltip[allcoords], AspectRatio -> Automatic, 
   PlotMarkers -> Automatic, PlotStyle -> {Thick}];
Show[nodeids, undefplot]

enter image description here

I need something like this:

Needs["NDSolve`FEM`"]
q = QuadElement[topol]
mesh = ToElementMesh["Coordinates" -> nnodes, "MeshElements" -> {q}]
Show[mesh["Wireframe"],
 mesh["Wireframe"["MeshElement" -> "PointElements", 
   "MeshElementStyle" -> Directive[Red, PointSize[0.02]], 
   "MeshElementIDStyle" -> Blue]]]

enter image description here

But in the figure above is missing the interior nodes.

How can i do that? Thank you!

$\endgroup$
8
  • $\begingroup$ How did you get your allcoords? Is it output from some code? $\endgroup$
    – BlacKow
    Jan 5, 2017 at 21:07
  • $\begingroup$ Yes: allcoords = Table[nnodes[[ topol[[i]][[j]] ]], {i, 1, Length[topol]}, {j, 1, 8}]; $\endgroup$
    – Stratus
    Jan 5, 2017 at 21:10
  • $\begingroup$ And topo is ...? It will be useful if you show a plot of desired result - maybe hardcoding coordinates fro demonstration purposes. $\endgroup$
    – BlacKow
    Jan 5, 2017 at 21:11
  • $\begingroup$ topol = Transpose@Drop[Transpose@Import["file.txt", "Table"], 1]; $\endgroup$
    – Stratus
    Jan 5, 2017 at 21:12
  • $\begingroup$ topol={{4, 1, 5, 8, 3, 2, 6, 7}, {5, 13, 17, 8, 10, 15, 11, 6}, {30, 37, 35, 26, 33, 36, 31, 28}, {35, 32, 24, 26, 34, 29, 25, 31}, {17, 23, 18, 8, 20, 21, 12, 11}, {4, 8, 18, 14, 7, 12, 16, 9}, {24, 14, 18, 26, 19, 16, 22, 25}, {26, 18, 23, 30, 22, 21, 27, 28}} $\endgroup$
    – Stratus
    Jan 5, 2017 at 21:13

1 Answer 1

3
$\begingroup$
ord = FindCurvePath /@ allcoords // Flatten[#, 1] &;

allcoordsNEW = MapThread[Part[#1, #2] &, {allcoords, ord}];
 (* or *)
allcoordsNEW = Table[allcoords[[i, ord[[i]]]], {i, 1, Length@ord}];

undefplot = 
  ListLinePlot[Tooltip[allcoordsNEW], AspectRatio -> Automatic, 
   PlotMarkers -> Automatic, PlotStyle -> {Thick}];

Show[nodeids, undefplot]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ A bit overkill for FindCurvePath.. I was sure the OP wants triangular mesh $\endgroup$
    – BlacKow
    Jan 5, 2017 at 21:48
  • 1
    $\begingroup$ Some text to accompany code is usually nice... $\endgroup$
    – Jason B.
    Jan 6, 2017 at 2:19

Your Answer

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

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