8
$\begingroup$

I have created a Finite Elements mesh on GID (quadrilateral 9 nodes elements). I exported the nodes and the elements topology and i'm reading it from the following two text files:

https://www.dropbox.com/s/93b98n139dfep4x/noschapacomfuroleft.txt?dl=0 https://www.dropbox.com/s/nhg8jass0ren6wc/elschapacomfuroleft.txt?dl=0

To read the files above i'm using the following code:

    topol = topol = Transpose@Drop[Transpose@Import["C:\\yourfolder\\elschapacomfuroleft.txt", "Table"], 1];
    nnodesx = Import["C:\\yourfolder\\noschapacomfuroleft.txt", "Table"][[;; , 2]];
    nnodesy = Import["C:\\yourfolder\\noschapacomfuroleft.txt", "Table"][[;; , 3]];
    nnodes = ParallelTable[{nnodesx[[i]], nnodesy[[i]]}, {i, 1,Length[nnodesx]}];

And then the following code plot's the mesh:

allcoords = 
  ParallelTable[
   nnodes[[ topol[[i]][[j]] ]], {i, 1, Length[topol]}, {j, 1, 9}];

allcoords2 = 
  ParallelTable[
   nnodes[[ topol[[i]][[j]] ]], {i, 1, Length[topol]}, {j, 1, 8}];

nodeids = 
  ListPlot[Table[Labeled[nnodes[[i]], i], {i, Length@nnodes}], 
   AspectRatio -> Automatic];

ord = FindCurvePath /@ allcoords2 // Flatten[#, 1] &;

allcoordsNEW = 
  ParallelTable[allcoords2[[i, ord[[i]]]], {i, 1, Length@ord}];

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

Show[nodeids, undefplot]

Which gives:

enter image description here

The problem is that it takes too long to plot. Is there a way to speedup this code? Is there a beter way to do this? Thank you.

Related paper: https://onlinelibrary.wiley.com/doi/full/10.1002/cae.21958

$\endgroup$
  • $\begingroup$ Give specific ImageSize to the node plot. The labeling algorithm relies on the information of PlotRange and ImageSize. If you don't specify, the image size will be 300 by default. This can speed things up a little bit, but probably still not satisfactory. $\endgroup$ – MinHsuan Peng Jan 11 '17 at 23:30
  • $\begingroup$ Thank you. I'm going to try this. $\endgroup$ – Diogo Jan 12 '17 at 2:28
7
$\begingroup$

Here is a way to speed things up

pack = Developer`ToPackedArray;
topol = pack @ Transpose @ Drop[Transpose @
      Import["~/Downloads/elschapacomfuroleft.txt", "Table"], 1];
nnodesAll = Import["~/Downloads/noschapacomfuroleft.txt", "Table"];
nnodes = pack@N[nnodesAll[[All, {2, 3}]]];

Now, the idea is to create graphics complexes:

(* edges are straight *)
meshVis1 = 
 Graphics[{FaceForm[], EdgeForm[Blue], 
   GraphicsComplex[nnodes, Polygon[topol[[All, {1, 2, 3, 4}]]]]}]

enter image description here

Or, if the edges could be curved, then this approximation is fast:

(* approximation to curved edges *)
meshVis2 = 
 Graphics[{FaceForm[], EdgeForm[Blue], 
   GraphicsComplex[nnodes, 
    Polygon[topol[[All, {1, 5, 2, 6, 3, 7, 4, 8}]]]]}]

The nodes are done separately - this is the slowest part

(* this is the slowest part *)
nodeVis = 
 Graphics[{MapIndexed[Text[#2[[1]], #1, {-1, 1}] &, nnodes], {Blue, 
    Point[nnodes]}}]

You can combine them with Show

Show[meshVis1, nodeVis, ImageSize -> Large]

enter image description here

$\endgroup$

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.