Program: 70855
Project: 70855
Buggy source:
/** 
 * Takes a FemModel3d containing linear elements, and creates a quadratic model whose elements are the corresponding quadratic elements, with new nodes inserted along the edges as required. The new quadratic model will have straight edges in the rest position.
 * @param linMod A FemModel3d previously inialized with only linear elements.
 */
public static FemModel3d createQuadraticModel(FemModel3d quadMod,FemModel3d linMod){
  ComponentListView<FemNode3d> quadNodes=quadMod.getNodes();
  if (quadMod == linMod) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  HashMap<FemNode3d,FemNode3d> nodeMap=new HashMap<FemNode3d,FemNode3d>();
  for (  FemNode3d n : linMod.getNodes()) {
    FemNode3d newn=new FemNode3d(n.getPosition());
    nodeMap.put(n,newn);
    quadMod.addNode(newn);
  }
  for (  FemElement3d e : linMod.getElements()) {
    ArrayList<FemNode3d> allNodes=new ArrayList<FemNode3d>();
    FemNode3d qnodes[];
    for (    FemNode3d n : e.getNodes()) {
      allNodes.add(nodeMap.get(n));
    }
    if (e instanceof TetElement) {
      qnodes=QuadtetElement.getQuadraticNodes((TetElement)e);
    }
 else     if (e instanceof HexElement) {
      qnodes=QuadhexElement.getQuadraticNodes((HexElement)e);
    }
 else     if (e instanceof WedgeElement) {
      qnodes=QuadwedgeElement.getQuadraticNodes((WedgeElement)e);
    }
 else     if (e instanceof PyramidElement) {
      qnodes=QuadpyramidElement.getQuadraticNodes((PyramidElement)e);
    }
 else {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    for (int i=0; i < qnodes.length; i++) {
      boolean nodeExists=false;
      for (      FemNode3d n : quadNodes) {
        if (qnodes[i].getPosition().equals(n.getPosition())) {
          qnodes[i]=n;
          nodeExists=true;
          break;
        }
      }
      if (!nodeExists) {
        quadMod.addNode(qnodes[i]);
      }
    }
    for (    FemNode3d n : qnodes) {
      allNodes.add(n);
    }
    FemNode3d[] nodes=allNodes.toArray(new FemNode3d[0]);
    FemElement3d qe=null;
    if (e instanceof TetElement) {
      qe=new QuadtetElement(nodes);
    }
 else     if (e instanceof HexElement) {
      qe=new QuadhexElement(nodes);
    }
 else     if (e instanceof WedgeElement) {
      qe=new QuadwedgeElement(nodes);
    }
 else     if (e instanceof PyramidElement) {
      qe=new QuadpyramidElement(nodes);
    }
    quadMod.addElement(qe);
  }
  quadMod.setMaterial(linMod.getMaterial());
  for (  FemNode3d n : quadNodes) {
    n.setMass(0);
  }
  double density=linMod.getDensity();
  for (  FemElement3d e : quadMod.getElements()) {
    double mass=e.getRestVolume() * density;
    e.setMass(mass);
    e.updateNodeMasses(mass);
  }
  return quadMod;
}

Fixed version (ground truth):
/** 
 * Takes a FemModel3d containing linear elements, and creates a quadratic model whose elements are the corresponding quadratic elements, with new nodes inserted along the edges as required. The new quadratic model will have straight edges in the rest position.
 * @param linMod A FemModel3d previously inialized with only linear elements.
 */
public static FemModel3d createQuadraticModel(FemModel3d quadMod,FemModel3d linMod){
  ComponentListView<FemNode3d> quadNodes=quadMod.getNodes();
  if (quadMod == linMod) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  HashMap<FemNode3d,FemNode3d> nodeMap=new HashMap<FemNode3d,FemNode3d>();
  for (  FemNode3d n : linMod.getNodes()) {
    FemNode3d newn=new FemNode3d(n.getPosition());
    nodeMap.put(n,newn);
    quadMod.addNode(newn);
  }
  for (  FemElement3d e : linMod.getElements()) {
    ArrayList<FemNode3d> allNodes=new ArrayList<FemNode3d>();
    FemNode3d qnodes[];
    for (    FemNode3d n : e.getNodes()) {
      allNodes.add(nodeMap.get(n));
    }
    if (e instanceof TetElement) {
      qnodes=QuadtetElement.getQuadraticNodes((TetElement)e);
    }
 else     if (e instanceof HexElement) {
      qnodes=QuadhexElement.getQuadraticNodes((HexElement)e);
    }
 else     if (e instanceof WedgeElement) {
      qnodes=QuadwedgeElement.getQuadraticNodes((WedgeElement)e);
    }
 else     if (e instanceof PyramidElement) {
      qnodes=QuadpyramidElement.getQuadraticNodes((PyramidElement)e);
    }
 else {
      throw new UnsupportedOperationException("String_Node_Str");
    }
    for (int i=0; i < qnodes.length; i++) {
      boolean nodeExists=false;
      for (      FemNode3d n : quadNodes) {
        if (qnodes[i].getPosition().equals(n.getPosition())) {
          qnodes[i]=n;
          nodeExists=true;
          break;
        }
      }
      if (!nodeExists) {
        quadMod.addNode(qnodes[i]);
      }
    }
    for (    FemNode3d n : qnodes) {
      allNodes.add(n);
    }
    FemNode3d[] nodes=allNodes.toArray(new FemNode3d[0]);
    FemElement3d qe=null;
    if (e instanceof TetElement) {
      qe=new QuadtetElement(nodes);
    }
 else     if (e instanceof HexElement) {
      qe=new QuadhexElement(nodes);
    }
 else     if (e instanceof WedgeElement) {
      qe=new QuadwedgeElement(nodes);
    }
 else     if (e instanceof PyramidElement) {
      qe=new QuadpyramidElement(nodes);
    }
    quadMod.addElement(qe);
  }
  quadMod.setMaterial(linMod.getMaterial());
  for (  FemNode3d n : quadNodes) {
    n.clearMass();
  }
  double density=linMod.getDensity();
  for (  FemElement3d e : quadMod.getElements()) {
    double mass=e.getRestVolume() * density;
    e.setMass(mass);
    e.updateNodeMasses(mass);
  }
  return quadMod;
}