--- trunk/src/math/ConvexHull.cpp 2009/10/22 19:43:10 1384 +++ trunk/src/math/ConvexHull.cpp 2010/02/24 16:09:21 1411 @@ -1,23 +1,14 @@ -/* Copyright (c) 2008, 2009 The University of Notre Dame. All Rights Reserved. +/* Copyright (c) 2010 The University of Notre Dame. All Rights Reserved. * * The University of Notre Dame grants you ("Licensee") a * non-exclusive, royalty free, license to use, modify and * redistribute this software in source and binary code form, provided * that the following conditions are met: * - * 1. Acknowledgement of the program authors must be made in any - * publication of scientific results based in part on use of the - * program. An acceptable form of acknowledgement is citation of - * the article in which the program was described (Matthew - * A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher - * J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented - * Parallel Simulation Engine for Molecular Dynamics," - * J. Comput. Chem. 26, pp. 252-271 (2005)) - * - * 2. Redistributions of source code must retain the above copyright + * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - * 3. Redistributions in binary form must reproduce the above copyright + * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the * distribution. @@ -37,14 +28,23 @@ * University of Notre Dame has been advised of the possibility of * such damages. * + * SUPPORT OPEN SCIENCE! If you use OpenMD or its source code in your + * research, please cite the appropriate papers when you publish your + * work. Good starting points are: + * + * [1] Meineke, et al., J. Comp. Chem. 26, 252-271 (2005). + * [2] Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006). + * [3] Sun, Lin & Gezelter, J. Chem. Phys. 128, 24107 (2008). + * [4] Vardeman & Gezelter, in progress (2009). * + * * ConvexHull.cpp * * Purpose: To calculate convexhull, hull volume libqhull. * * Created by Charles F. Vardeman II on 11 Dec 2006. * @author Charles F. Vardeman II - * @version $Id: ConvexHull.cpp,v 1.20 2009-10-22 19:43:10 gezelter Exp $ + * @version $Id: ConvexHull.cpp,v 1.21 2009-11-25 20:02:01 gezelter Exp $ * */ @@ -62,7 +62,7 @@ #include #endif -using namespace oopse; +using namespace OpenMD; #ifdef HAVE_QHULL extern "C" @@ -90,6 +90,7 @@ void ConvexHull::computeHull(std::vector facetT *facet; setT *vertices; int curlong, totlong; + pointT *intPoint; std::vector ptArray(numpoints*dim_); @@ -104,12 +105,14 @@ void ConvexHull::computeHull(std::vector i++; } + /* Clean up memory from previous convex hull calculations */ boolT ismalloc = False; - /* Clean up memory from previous convex hull calculations*/ + /* compute the hull for our local points (or all the points for single + processor versions) */ if (qh_new_qhull(dim_, numpoints, &ptArray[0], ismalloc, const_cast(options_.c_str()), NULL, stderr)) { - + sprintf(painCave.errMsg, "ConvexHull: Qhull failed to compute convex hull"); painCave.isFatal = 1; simError(); @@ -193,9 +196,13 @@ void ConvexHull::computeHull(std::vector // Free previous hull qh_freeqhull(!qh_ALL); qh_memfreeshort(&curlong, &totlong); - if (curlong || totlong) - std::cerr << "qhull internal warning (main): did not free %d bytes of long memory (%d pieces) " - << totlong << curlong << std::endl; + if (curlong || totlong) { + sprintf(painCave.errMsg, "ConvexHull: qhull internal warning:\n" + "\tdid not free %d bytes of long memory (%d pieces)", + totlong, curlong); + painCave.isFatal = 1; + simError(); + } if (qh_new_qhull(dim_, globalHullSites, &globalCoords[0], ismalloc, const_cast(options_.c_str()), NULL, stderr)){ @@ -207,12 +214,13 @@ void ConvexHull::computeHull(std::vector } //qh_new_qhull #endif - + intPoint = qh interior_point; + RealType calcvol = 0.0; FORALLfacets { Triangle face; - + //Qhull sets the unit normal in facet->normal Vector3d V3dNormal(facet->normal[0], facet->normal[1], facet->normal[2]); - face.setNormal(V3dNormal); + face.setUnitNormal(V3dNormal); RealType faceArea = qh_facetarea(facet); face.setArea(faceArea); @@ -234,7 +242,6 @@ void ConvexHull::computeHull(std::vector p[ver][0] = vertex->point[0]; p[ver][1] = vertex->point[1]; p[ver][2] = vertex->point[2]; - Vector3d vel; RealType mass; @@ -249,15 +256,17 @@ void ConvexHull::computeHull(std::vector int localID = id - displacements[myrank]; - if (localID >= 0 && localID < hullSitesOnProc[myrank]) + + if (localID >= 0 && localID < hullSitesOnProc[myrank]){ face.addVertexSD(bodydoubles[indexMap[localID]]); - + }else{ + face.addVertexSD(NULL); + } #else vel = bodydoubles[id]->getVel(); mass = bodydoubles[id]->getMass(); face.addVertexSD(bodydoubles[id]); -#endif - +#endif faceVel = faceVel + vel; faceMass = faceMass + mass; ver++; @@ -266,6 +275,15 @@ void ConvexHull::computeHull(std::vector face.addVertices(p[0], p[1], p[2]); face.setFacetMass(faceMass); face.setFacetVelocity(faceVel/3.0); + /* + RealType comparea = face.computeArea(); + realT calcarea = qh_facetarea (facet); + Vector3d V3dCompNorm = -face.computeUnitNormal(); + RealType thisOffset = ((0.0-p[0][0])*V3dCompNorm[0] + (0.0-p[0][1])*V3dCompNorm[1] + (0.0-p[0][2])*V3dCompNorm[2]); + RealType dist = facet->offset + intPoint[0]*V3dNormal[0] + intPoint[1]*V3dNormal[1] + intPoint[2]*V3dNormal[2]; + std::cout << "facet offset and computed offset: " << facet->offset << " " << thisOffset << std::endl; + calcvol += -dist*comparea/qh hull_dim; + */ Triangles_.push_back(face); qh_settempfree(&vertices); @@ -274,12 +292,16 @@ void ConvexHull::computeHull(std::vector qh_getarea(qh facet_list); volume_ = qh totvol; area_ = qh totarea; - + // std::cout << "My volume is: " << calcvol << " qhull volume is:" << volume_ << std::endl; qh_freeqhull(!qh_ALL); qh_memfreeshort(&curlong, &totlong); - if (curlong || totlong) - std::cerr << "qhull internal warning (main): did not free %d bytes of long memory (%d pieces) " - << totlong << curlong << std::endl; + if (curlong || totlong) { + sprintf(painCave.errMsg, "ConvexHull: qhull internal warning:\n" + "\tdid not free %d bytes of long memory (%d pieces)", + totlong, curlong); + painCave.isFatal = 1; + simError(); + } } void ConvexHull::printHull(const std::string& geomFileName) {