Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
Needs["TetGenLink`"];

TetraMaker[pts_, surface_, TetGenString_?StringQ] := 
Module[{inInst, outInst, coords, surface1, meshElements, facets}, 
        inInst = TetGenCreate[];
        TetGenSetPoints[inInst, pts];
        facets = Partition[surface, 1];
        TetGenSetFacets[inInst, facets];
        outInst = TetGenTetrahedralize[inInst, TetGenString];
        coords = TetGenGetPoints[outInst]; (* element point *)
        surface1 = TetGenGetFaces[outInst]; (* element face *)
        meshElements = TetGenGetElements[outInst]; (* element indices *)
      {coords, surface1, meshElements}];

 TetrahedraVolume = 
         Compile[{{coords, _Real, 2}, {elements, _Integer, 1}}, 
         Block[{p}, p = coords[[elements]];
             1/6*Abs[Det[p[[{1, 2, 3}]] - p[[{2, 3, 4}]]]]], 
              RuntimeAttributes -> {Listable}, RuntimeOptions -> "Speed"];




 {coords1, surface1, meshElements1} = TetraMaker[data01, polysurface1, "pqa.8"];
  vb = Total[TetrahedraVolume[coords1, meshElements1]]
  Graphics3D[GraphicsComplex[coords1, Polygon[surface1]]]

Error dialog appears when running code below:

 {coords2, surface2, meshElements2} = TetraMaker[data02, polysurface2, "pqa.8"];
  vb = Total[TetrahedraVolume[coords2, meshElements2]]

Assertion failed!

Program: ... File: M:\Builds\2615350\checkout\Mathematica...\tetgen.cxx Line: 21962

Expression: dir !=COLLOSIONFACE

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts

(Press Retry to debug the application - JIT must be enabled)

I am trying to calculate volume. I wonder if both data sets are similar then why does it not work for 2nd data set? Is there any way I can fix this error?

share|improve this question
add comment

1 Answer 1

up vote 9 down vote accepted

Your second data set has intersecting facets. There is no way TetGen can tetrahedralize that.

Needs["TetGenLink`"];
res = TetGenDetectIntersectingFacets[data02, 
   Partition[polysurface2, 1]];
Graphics3D[GraphicsComplex[res[[1]], Polygon[res[[2]]]]]

enter image description here

So the solution is to fix the data set. I have to see about how to improve the assertion error. The problem is that there are duplicate faces. If you use

sf2 = DeleteDuplicates[Sort /@ polysurface2];
{coords1, surface1, meshElements1} = 
  TetraMaker[data02, sf2, "pqa.8"];
vb = Total[TetrahedraVolume[coords1, meshElements1]]
Graphics3D[GraphicsComplex[coords1, Polygon[surface1]]]

it will work.

share|improve this answer
    
@ ruebenko: very helpful, any hint on how to fix the data set. –  Jay Jul 5 '12 at 3:37
    
@Jay, this update should do it. I am curious, could you comment on what type of data this is and what the application is? –  user21 Jul 5 '12 at 16:24
    
@Jay, interesting. Is this lab data? How do you get the surface facets of the particles? –  user21 Jul 5 '12 at 17:02
    
@Jay, thanks for the clarification. Concerning the contour selection, one would need to see an example to say how this could be done in Mathematica. –  user21 Jul 5 '12 at 18:36
    
@Jay, I think it were good if you were to post this part as a new question. Many more people will then look at this. –  user21 Jul 5 '12 at 19:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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