Tetgen command failed
TheNightbringer117 opened this issue · comments
Hi, I'm trying to use the surf2mesh function but I'm getting the error:
"
Error using surf2mesh (line 114)
Tetgen command failed
"
Can you help with this?
Regards,
Nightbringer
hi @TheNightbringer117, can you give me a short example how I can produce this issue?
it is actually quite common that tetgen fails if a user does not process the input surface carefully - mostly because your input surface is self-intersecting. If it is a single closed surface, you can use meshcheckrepair() with the 'meshfix' option to repair the bad surface, then tetgen will not complain.
Hi fangq,
Sorry for the delayed response.
I modified my script to include the check and it caused another error.
The script I am using is now:
file_1 = "K:\AMA\ISO2MESH\20mmcube18infillstrokeregioninset2mm.stl"
file_2 = "K:\AMA\ISO2MESH\20mmcube18infillstrokeregioninset3mm.stl"
disp("Importing geometry file data...")
[VL1unchecked,FL1unchecked] = VLFLreadSTLb(file_1)
[VL2unchecked,FL2unchecked] = VLFLreadSTLb(file_2)
[VL1,FL1] = meshcheckrepair(VL1unchecked,FL1unchecked,meshfix)
[VL2,FL2] = meshcheckrepair(VL2unchecked,FL2unchecked,meshfix)
disp(".stl File Reading Complete")
disp("Plotting Individual Files...")
figure
subplot(2,1,1)
plotsurf(VL1,FL1)
subplot(2,1,2)
plotsurf(VL2,FL2)
keepratio=1;
maxvol=10;
addpath('C:\MATLAB\iso2mesh-master\iso2mesh-master')
which vol2mesh
[node,elem,face] = surf2mesh(VL1,FL1,[-100 -100 -100],[100 100 100],keepratio,maxvol);
figure
plotmesh(face(:,1:3),node);
disp("Calculating Boolean Subtraction...")
Which returns the error:
Error in meshfix (line 16)
writeOFF(off_filename,V,F);
Error in PolyComparison (line 27)
[VL1,FL1] = meshcheckrepair(VL1unchecked,FL1unchecked,meshfix)
Previously, I was using:
file_1 = "K:\AMA\ISO2MESH\20mmcube18infillstrokeregioninset2mm.stl"
file_2 = "K:\AMA\ISO2MESH\20mmcube18infillstrokeregioninset3mm.stl"
disp("Importing geometry file data...")
[VL1,FL1] = VLFLreadSTLb(file_1)
[VL2,FL2] = VLFLreadSTLb(file_2)
disp(".stl File Reading Complete")
disp("Plotting Individual Files...")
figure
subplot(2,1,1)
plotsurf(VL1,FL1)
subplot(2,1,2)
plotsurf(VL2,FL2)
keepratio=1;
maxvol=10;
addpath('C:\MATLAB\iso2mesh-master\iso2mesh-master')
which vol2mesh
[node,elem,face] = surf2mesh(VL1,FL1,[-100 -100 -100],[100 100 100],keepratio,maxvol);
figure
plotmesh(face(:,1:3),node);
disp("Calculating Boolean Subtraction...")
Which returned the error:
Error using surf2mesh (line 114)
Tetgen command failed
Error in PolyComparison (line 48)
[node,elem,face] = surf2mesh(VL1,FL1,[-100 -100 -100],[100 100 100],keepratio,maxvol);
I can email you the .stls if that will help.
Your help is much appreciated.
Regards,
Nightbringer
@TheNightbringer117, it appears to me that you called meshcheckrepair() using an incorrect input, please change
[VL1,FL1] = meshcheckrepair(VL1unchecked,FL1unchecked,meshfix)
[VL2,FL2] = meshcheckrepair(VL2unchecked,FL2unchecked,meshfix)
to
[VL1,FL1] = meshcheckrepair(VL1unchecked,FL1unchecked,'meshfix');
[VL2,FL2] = meshcheckrepair(VL2unchecked,FL2unchecked,'meshfix');
and let me know what you see.
I am closing this ticket as there was no updates. feel free to reopen if issue remains.
Dear Fang,
I have used
[node,elem]=meshcheckrepair(nodes_TP(:,2:4),triangularelements,'meshfix').
This generated node array of size103242x3 and element array of size 208868x3.
Later I ran
[node1,face1]=extrudesurf(node(:,1:3),elem(:,1:3),[0 0 +7]);
keepratio = 1;
maxvol=0.1;
[node11,elem11,face11] = s2m(node1,face1,keepratio,maxvol).
still I am getting the same error.
Please help me.
Thanks in advance
extrudesurf can easily generate self-intersecting triangles, you will have to call meshcheckrepair again before calling s2m.
Dear Dr. Fang,
I am using iso2mesh to generate a 4-slab medium, but it generates "Tetgen command failed" error. Could you help with it?
Here is my code:
L = [10, 20, 30];
[node1,face1]=meshabox([0 0 0],[100 100 L(1)], 2sqrt(2), 2^3/6);
[node2,face2]=meshabox([0 0 L(1)],[100 100 L(2)], 2sqrt(2), 2^3/6);
[node3,face3]=meshabox([0 0 L(2)],[100 100 L(3)], 2sqrt(2), 2^3/6);
[node4,face4]=meshabox([0 0 L(3)],[100 100 100], 2sqrt(2), 2^3/6);
[node,face]=mergemesh(node1,face1,node2,face2,node3,face3,node4,face4);
plotmesh(node,face);
[node,elem]=surf2mesh(node,face,[],[],1,2^3/6,[1 1 1; 1 1 11; 1 1 21; 1 1 31],[],0);
Error information:
Error using surf2mesh (line 117)
Tetgen command failed
Error in exmaple_4slab_MMC_simulation (line 13)
[node,elem]=surf2mesh(node,face,[],[],1,2^3/6,[1 1 1; 1 1 11; 1 1 21; 1 1 31],[],0);
Thank you in advance!
@hzhao329, mergemesh
does not do intersection test. it simply concatenate meshes. in your case, separately generated box-shaped meshes are completely overlapping on z=L(1/2/3) and those inconsistent boundaries make it impossible to surf2mesh to create volumetric mesh.
instead of creating boxes for each layer, you should use latticegrid
and this example to create a single mesh of multiple compartment, see
https://github.com/fangq/mmc/blob/master/mmclab/example/demo_sfdi_2layer.m#L20-L41