Program: 70949
Project: 70949
Buggy source:
/** 
 * Creates a tetrahedral FEM model from a triangular surface mesh. The tetrahedra will be added to either an existing model (supplied through the argument <code>model</code>), or a newly created <code>FemModel3d</code> (if <code>model</code> is <code>null</code>). <p> The tessellation is done using tetgen, which is called through a JNI interface. The tessellation quality is controlled using the <code>quality</code> variable, described below.
 * @param model model to which the tetrahedra should be added, or <code>null</code> if the model is to be created from scratch.
 * @param surface triangular surface mesh used to define the tessellation.
 * @param quality If 0, then only the mesh nodes will be used to form the tessellation. However, this may result in highly degenerate tetrahedra. Otherwise, if > 0, tetgen will add additional nodes to ensure that the minimum edge-radius ratio does not exceed <code>quality</code>. A good default value for <code>quality</code> is 2. If set too small (such as less then 1), then tetgen may not terminate.
 * @return the FEM model
 */
public static FemModel3d createFromMesh(FemModel3d model,PolygonalMesh surface,double quality){
  TetgenTessellator tetgen=new TetgenTessellator();
  tetgen.buildFromMesh(surface,quality);
  if (model == null) {
    model=new FemModel3d();
  }
 else {
    model.clear();
  }
  Point3d[] points=tetgen.getPoints();
  for (int i=0; i < points.length; i++) {
    model.addNode(new FemNode3d(points[i]));
  }
  ComponentList<FemNode3d> nodes=model.getNodes();
  int[] tets=tetgen.getTets();
  for (int i=0; i < tets.length / 4; i++) {
    FemNode3d n0=nodes.get(tets[i * 4 + 0]);
    FemNode3d n1=nodes.get(tets[i * 4 + 1]);
    FemNode3d n2=nodes.get(tets[i * 4 + 2]);
    FemNode3d n3=nodes.get(tets[i * 4 + 3]);
    TetElement elem=new TetElement(n1,n3,n2,n0);
    model.addElement(elem);
  }
  return model;
}

Fixed version (ground truth):
/** 
 * Creates a tetrahedral FEM model from a triangular surface mesh. The tetrahedra will be added to either an existing model (supplied through the argument <code>model</code>), or a newly created <code>FemModel3d</code> (if <code>model</code> is <code>null</code>). <p> The tessellation is done using tetgen, which is called through a JNI interface. The tessellation quality is controlled using the <code>quality</code> variable, described below.
 * @param model model to which the tetrahedra should be added, or <code>null</code> if the model is to be created from scratch.
 * @param surface triangular surface mesh used to define the tessellation.
 * @param quality If 0, then only the mesh nodes will be used to form the tessellation. However, this may result in highly degenerate tetrahedra. Otherwise, if &gt; 0, tetgen will add additional nodes to ensure that the minimum edge-radius ratio does not exceed <code>quality</code>. A good default value for <code>quality</code> is 2. If set too small (such as less then 1), then tetgen may not terminate.
 * @return the FEM model
 */
public static FemModel3d createFromMesh(FemModel3d model,PolygonalMesh surface,double quality){
  TetgenTessellator tetgen=new TetgenTessellator();
  tetgen.buildFromMesh(surface,quality);
  if (model == null) {
    model=new FemModel3d();
  }
 else {
    model.clear();
  }
  Point3d[] points=tetgen.getPoints();
  for (int i=0; i < points.length; i++) {
    model.addNode(new FemNode3d(points[i]));
  }
  ComponentList<FemNode3d> nodes=model.getNodes();
  int[] tets=tetgen.getTets();
  for (int i=0; i < tets.length / 4; i++) {
    FemNode3d n0=nodes.get(tets[i * 4 + 0]);
    FemNode3d n1=nodes.get(tets[i * 4 + 1]);
    FemNode3d n2=nodes.get(tets[i * 4 + 2]);
    FemNode3d n3=nodes.get(tets[i * 4 + 3]);
    TetElement elem=new TetElement(n1,n3,n2,n0);
    model.addElement(elem);
  }
  return model;
}