3
$\begingroup$
Needs["TetGenLink`"]
instTetgen = TetGenCreate[]; 
TetGenExpression[1]; 
pts = {{0., 0., 0.}, {2., 0., 0.}, {2., 0., 2.}, {0., 0., 2.}, {0., 
2., 0.}, {2., 2., 0.}, {2., 2., 2.}, {0., 2., 2.}}; 
TetGenSetPoints[instTetgen, pts]; 
instTetrahed = TetGenTetrahedralize[instTetgen, "-o2"]; 
elemPts = TetGenGetPoints[instTetrahed]; 
elemFaces = TetGenGetFaces[instTetrahed]; 
meshElements = TetGenGetElements[instTetrahed]; 
nElements = Length[meshElements]; 
nVertex = Length[elemPts]; 
Graphics3D[{Opacity[0.5], GraphicsComplex[elemPts, Polygon[elemFaces]]}, Boxed -> False]; 

elemPts
{{0.,0.,0.},{2.,0.,0.},{2.,0.,2.},{0.,0.,2.},{0.,2.,0.},{2.,2.,0.},{2.,2.,2.},{0.,2.,2.},{2.,2.,1.},{1.,1.,0.},{1.,1.,1.},{1.,2.,1.},{1.,2.,0.},{0.,1.,0.},{0.,1.,1.},{1.,0.,1.},{1.,1.,2.},{0.,1.,2.},{0.,0.,1.},{1.,0.,2.},{2.,1.,2.},{1.,0.,0.},{2.,1.,1.},{2.,0.,1.},{2.,1.,0.},{1.,2.,2.},{0.,2.,1.}}
elemFaces
{{7,6,1},{7,5,6},{6,5,1},{1,5,7},{8,1,3},{8,4,1},{1,4,3},{3,4,8},{1,7,3},{1,2,7},{7,2,3},{3,2,1},{6,2,7},{1,2,6},{7,8,1},{3,8,7},{1,5,8},{8,5,7}}
meshElements
{{7,6,1,5,9,10,11,12,13,14},{8,1,3,4,15,16,17,18,19,20},{1,7,3,2,11,21,16,22,23,24},{6,7,1,2,9,11,10,25,23,22},{7,1,3,8,11,16,21,26,15,17},{1,8,7,5,15,26,11,14,27,12}}
(*Ten nodes of the first tetrahedral element are:*)
elemPts[[meshElements[[1]]]]
{{2.,2.,2.},{2.,2.,0.},{0.,0.,0.},{0.,2.,0.},{2.,2.,1.},{1.,1.,0.},{1.,1.,1.},{1.,2.,1.},{1.,2.,0.},{0.,1.,0.}}

Is there a way to visualize the polyhedron such that all the ten nodes of the tetrahedral elements are considered and not only the primary four nodes of each tetrahedral element?

$\endgroup$
3
  • $\begingroup$ Can you explain which are the ten nodes? $\endgroup$
    – Szabolcs
    Sep 1, 2016 at 18:05
  • 1
    $\begingroup$ @Szabolcs In the above example, there are six tetrahedral elements in the cube. Each of these tetrahedral elements will have ten nodes. The first four nodes are the same as in the case of linear tetrahedral elements, the rest six are midpoints of each of the edges. meshElements[[1]] contains {7,6,1,5,9,10,11,12,13,14} these ten points. $\endgroup$
    – novice
    Sep 1, 2016 at 18:09
  • $\begingroup$ @Szabolcs I have edited the question and provided the ten nodes of the first tetrahedral element. $\endgroup$
    – novice
    Sep 1, 2016 at 18:31

1 Answer 1

1
$\begingroup$

here is one element:

Graphics3D[{Opacity[.5], GraphicsComplex[ elemPts , { 
      Polygon[#[[{1, 2, 3}]]],
      Polygon[#[[{1, 4, 3}]]],
      Polygon[#[[{1, 2, 4}]]],
      Polygon[#[[{2, 3, 4}]]],
      {Red, Opacity[1], PointSize[.02],Point[#]}
      }]}, Boxed -> False] &@ meshElements[[1]]

enter image description here

and all:

Show[Graphics3D[{Opacity[.5], GraphicsComplex[ elemPts , { 
       Polygon[#[[{1, 2, 3}]]],
        Polygon[#[[{1, 4, 3}]]] ,
       Polygon[#[[{1, 2, 4}]]],
       Polygon[#[[{2, 3, 4}]]] , {Red, Opacity[1], PointSize[.02], 
        Point[#]}
       }]}, Boxed -> False] & /@ meshElements]

enter image description here

note that your graphic is not composed to tetrahedrons, in fact all of the rendered polygons are on the faces of the cube. I'm not sure whats wrong though. The elemPts list has a point at the center of the cube {1,1,1}, yet in your figure there is no vertex or edge through that point.

$\endgroup$
4
  • $\begingroup$ Thanks. I think it is because I just used the faces which are at the boundary. If I used the -f flag also along with -o2 while using the TetGenTetrahedralize command. It will consider that point as well. $\endgroup$
    – novice
    Sep 1, 2016 at 22:23
  • $\begingroup$ i see. if you didnt use opacity it would look ok. Maybe the docs for TetGenGetFaces could say it just gives external faces. $\endgroup$
    – george2079
    Sep 2, 2016 at 0:52
  • $\begingroup$ Your suggestion takes care of the points but the tetrahedral faces do not change accordingly. Example if i change elemPts[[9]] = {2,2,1} to {2,2,3}, The point goes out of the cube but the cube does not change its shape. I am doing the dynamics where the vertex points evolve with time, I want to visualize the shape changes in the polygon as the values of the vertex point changes. $\endgroup$
    – novice
    Sep 2, 2016 at 14:53
  • 1
    $\begingroup$ If you move the edge nodes away from the mid-point of the tet edges the resulting object is no longer a tetrahedron, the faces no longer polyhedron. The edges become quadratic. At the very least this should be a new question. (BTW in my experience commercial FEM packages punt on the issue and treat second order tets as first order for redering purpose.) $\endgroup$
    – george2079
    Sep 2, 2016 at 15:17

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.