# | Line 1 | Line 1 | |
---|---|---|
1 | < | /* Copyright (c) 2006 The University of Notre Dame. All Rights Reserved. |
1 | > | /* Copyright (c) 2008 The University of Notre Dame. All Rights Reserved. |
2 | * | |
3 | * The University of Notre Dame grants you ("Licensee") a | |
4 | * non-exclusive, royalty free, license to use, modify and | |
# | Line 44 | Line 44 | |
44 | * | |
45 | * Created by Charles F. Vardeman II on 11 Dec 2006. | |
46 | * @author Charles F. Vardeman II | |
47 | < | * @version $Id: ConvexHull.cpp,v 1.8 2008-09-14 01:32:25 chuckv Exp $ |
47 | > | * @version $Id: ConvexHull.cpp,v 1.12 2008-10-21 16:44:00 chuckv Exp $ |
48 | * | |
49 | */ | |
50 | ||
# | Line 369 | Line 369 | void ConvexHull::printHull(const std::string& geomFile | |
369 | #else | |
370 | #ifdef HAVE_QHULL | |
371 | /* Old options Qt Qu Qg QG0 FA */ | |
372 | < | ConvexHull::ConvexHull() : Hull(), dim_(3), options_("qhull Qt Qci Tcv Pp") { |
372 | > | /* More old opts Qc Qi Pp*/ |
373 | > | ConvexHull::ConvexHull() : Hull(), dim_(3), options_("qhull Qt Pp"), Ns_(200), nTriangles_(0) { |
374 | //If we are doing the mpi version, set up some vectors for data communication | |
375 | #ifdef IS_MPI | |
376 | ||
# | Line 380 | Line 381 | ConvexHull::ConvexHull() : Hull(), dim_(3), options_(" | |
381 | displs_ = new int[nproc_]; | |
382 | ||
383 | // Create a surface point type in MPI to send | |
384 | < | surfacePtType = MPI::DOUBLE.Create_contiguous(3); |
385 | < | surfacePtType.Commit(); |
384 | > | //surfacePtType = MPI::DOUBLE.Create_contiguous(3); |
385 | > | // surfacePtType.Commit(); |
386 | ||
387 | ||
388 | #endif | |
# | Line 413 | Line 414 | void ConvexHull::computeHull(std::vector<StuntDouble*> | |
414 | ||
415 | //pt_array = (coordT*) malloc(sizeof(coordT) * (numpoints * dim_)); | |
416 | ||
417 | < | double* ptArray = new double[numpoints * 3]; |
417 | > | // double* ptArray = new double[numpoints * 3]; |
418 | > | std::vector<double> ptArray(numpoints*3); |
419 | std::vector<bool> isSurfaceID(numpoints); | |
420 | ||
421 | // Copy the positon vector into a points vector for qhull. | |
# | Line 435 | Line 437 | void ConvexHull::computeHull(std::vector<StuntDouble*> | |
437 | ||
438 | ||
439 | boolT ismalloc = False; | |
440 | + | /* Clean up memory from previous convex hull calculations*/ |
441 | + | |
442 | Triangles_.clear(); | |
443 | surfaceSDs_.clear(); | |
444 | < | |
445 | < | if (qh_new_qhull(dim_, numpoints, ptArray, ismalloc, |
444 | > | surfaceSDs_.reserve(Ns_); |
445 | > | |
446 | > | if (qh_new_qhull(dim_, numpoints, &ptArray[0], ismalloc, |
447 | const_cast<char *>(options_.c_str()), NULL, stderr)) { | |
448 | ||
449 | sprintf(painCave.errMsg, "ConvexHull: Qhull failed to compute convex hull"); | |
450 | < | painCave.isFatal = 0; |
450 | > | painCave.isFatal = 1; |
451 | simError(); | |
452 | ||
453 | } //qh_new_qhull | |
# | Line 450 | Line 455 | void ConvexHull::computeHull(std::vector<StuntDouble*> | |
455 | ||
456 | #ifdef IS_MPI | |
457 | std::vector<double> localPts; | |
458 | + | std::vector<double> localVel; |
459 | int localPtArraySize; | |
460 | ||
461 | + | |
462 | std::fill(isSurfaceID.begin(),isSurfaceID.end(),false); | |
463 | + | |
464 | ||
465 | FORALLfacets { | |
466 | ||
467 | if (!facet->simplicial){ | |
468 | // should never happen with Qt | |
469 | sprintf(painCave.errMsg, "ConvexHull: non-simplicaial facet detected"); | |
470 | < | painCave.isFatal = 0; |
470 | > | painCave.isFatal = 1; |
471 | simError(); | |
472 | } | |
473 | ||
# | Line 484 | Line 492 | void ConvexHull::computeHull(std::vector<StuntDouble*> | |
492 | int localPtArraySize = surfaceIDs.size() * 3; | |
493 | */ | |
494 | ||
495 | < | localPts.resize(localPtArraySize); |
496 | < | // std::fill(localPts.begin(),globalPts.end(),0.0); |
495 | > | //localPts.resize(localPtArraySize); |
496 | > | //std::fill(localPts.begin(),localPts.end(),0.0); |
497 | ||
498 | ||
499 | int idx = 0; | |
500 | + | int nIsIts = 0; |
501 | + | /* |
502 | // Copy the surface points into an array. | |
503 | for(std::vector<bool>::iterator list_iter = isSurfaceID.begin(); | |
504 | list_iter != isSurfaceID.end(); list_iter++) | |
# | Line 499 | Line 509 | void ConvexHull::computeHull(std::vector<StuntDouble*> | |
509 | localPts.push_back(ptArray[dim_ * idx + 1]); | |
510 | localPts.push_back(ptArray[dim_ * idx + 2]); | |
511 | localPtsMap.push_back(idx); | |
512 | + | nIsIts++; |
513 | } //Isit | |
514 | idx++; | |
515 | } //isSurfaceID | |
516 | < | |
516 | > | */ |
517 | > | FORALLvertices { |
518 | > | idx = qh_pointid(vertex->point); |
519 | > | localPts.push_back(ptArray[dim_ * idx]); |
520 | > | localPts.push_back(ptArray[dim_ * idx + 1]); |
521 | > | localPts.push_back(ptArray[dim_ * idx + 2]); |
522 | ||
523 | + | Vector3d vel = bodydoubles[idx]->getVel(); |
524 | + | localVel.push_back(vel.x()); |
525 | + | localVel.push_back(vel.y()); |
526 | + | localVel.push_back(vel.z()); |
527 | + | |
528 | + | localPtsMap.push_back(idx); |
529 | + | } |
530 | + | |
531 | + | |
532 | localPtArraySize = localPts.size(); | |
533 | + | |
534 | + | |
535 | MPI::COMM_WORLD.Allgather(&localPtArraySize,1,MPI::INT,&NstoProc_[0],1,MPI::INT); | |
536 | ||
537 | + | Nsglobal_=0; |
538 | for (int i = 0; i < nproc_; i++){ | |
539 | Nsglobal_ += NstoProc_[i]; | |
540 | } | |
541 | + | |
542 | + | |
543 | + | int nglobalPts = int(Nsglobal_/3); |
544 | + | |
545 | ||
546 | < | std::vector<double> globalPts; |
547 | < | globalPts.resize(Nsglobal_); |
548 | < | isSurfaceID.resize(int(Nsglobal_/3)); |
546 | > | std::vector<double> globalPts(Nsglobal_); |
547 | > | std::vector<double> globalVel(Nsglobal_); |
548 | > | |
549 | > | isSurfaceID.resize(nglobalPts); |
550 | > | |
551 | > | |
552 | std::fill(globalPts.begin(),globalPts.end(),0.0); | |
553 | + | |
554 | + | displs_[0] = 0; |
555 | /* Build a displacements array */ | |
556 | for (int i = 1; i < nproc_; i++){ | |
557 | displs_[i] = displs_[i-1] + NstoProc_[i-1]; | |
558 | } | |
559 | ||
560 | + | |
561 | int noffset = displs_[myrank_]; | |
562 | /* gather the potential hull */ | |
563 | ||
564 | < | MPI::COMM_WORLD.Allgatherv(&localPts[0],localPtArraySize,MPI::DOUBLE,&globalPts[0],NstoProc_,displs_,MPI::DOUBLE); |
564 | > | MPI::COMM_WORLD.Allgatherv(&localPts[0],localPtArraySize,MPI::DOUBLE,&globalPts[0],&NstoProc_[0],&displs_[0],MPI::DOUBLE); |
565 | > | MPI::COMM_WORLD.Allgatherv(&localVel[0],localPtArraySize,MPI::DOUBLE,&globalVel[0],&NstoProc_[0],&displs_[0],MPI::DOUBLE); |
566 | ||
567 | < | |
568 | < | |
569 | < | |
567 | > | /* |
568 | > | if (myrank_ == 0){ |
569 | > | for (i = 0; i < globalPts.size(); i++){ |
570 | > | std::cout << globalPts[i] << std::endl; |
571 | > | } |
572 | > | } |
573 | > | */ |
574 | // Free previous hull | |
575 | qh_freeqhull(!qh_ALL); | |
576 | qh_memfreeshort(&curlong, &totlong); | |
# | Line 535 | Line 578 | void ConvexHull::computeHull(std::vector<StuntDouble*> | |
578 | std::cerr << "qhull internal warning (main): did not free %d bytes of long memory (%d pieces) " | |
579 | << totlong << curlong << std::endl; | |
580 | ||
581 | < | if (qh_new_qhull(dim_, numpoints, &globalPts[0], ismalloc, |
581 | > | if (qh_new_qhull(dim_, nglobalPts, &globalPts[0], ismalloc, |
582 | const_cast<char *>(options_.c_str()), NULL, stderr)){ | |
583 | ||
584 | sprintf(painCave.errMsg, "ConvexHull: Qhull failed to compute global convex hull"); | |
585 | < | painCave.isFatal = 0; |
585 | > | painCave.isFatal = 1; |
586 | simError(); | |
587 | ||
588 | } //qh_new_qhull | |
# | Line 552 | Line 595 | void ConvexHull::computeHull(std::vector<StuntDouble*> | |
595 | ||
596 | ||
597 | unsigned int nf = qh num_facets; | |
598 | < | |
598 | > | |
599 | /* Build Surface SD list first */ | |
600 | ||
601 | std::fill(isSurfaceID.begin(),isSurfaceID.end(),false); | |
# | Line 562 | Line 605 | void ConvexHull::computeHull(std::vector<StuntDouble*> | |
605 | if (!facet->simplicial){ | |
606 | // should never happen with Qt | |
607 | sprintf(painCave.errMsg, "ConvexHull: non-simplicaial facet detected"); | |
608 | < | painCave.isFatal = 0; |
608 | > | painCave.isFatal = 1; |
609 | simError(); | |
610 | } //simplicical | |
611 | ||
612 | < | Triangle* face = new Triangle(); |
612 | > | Triangle face; |
613 | Vector3d V3dNormal(facet->normal[0],facet->normal[1],facet->normal[2]); | |
614 | < | face->setNormal(V3dNormal); |
615 | < | //face->setCentroid(V3dCentroid); |
614 | > | face.setNormal(V3dNormal); |
615 | > | |
616 | > | |
617 | > | |
618 | RealType faceArea = 0.5*V3dNormal.length(); | |
619 | < | face->setArea(faceArea); |
619 | > | face.setArea(faceArea); |
620 | ||
621 | ||
622 | vertices = qh_facet3vertex(facet); | |
623 | + | |
624 | + | coordT *center = qh_getcenter(vertices); |
625 | + | Vector3d V3dCentroid(center[0], center[1], center[2]); |
626 | + | face.setCentroid(V3dCentroid); |
627 | + | Vector3d faceVel = V3Zero; |
628 | FOREACHvertex_(vertices){ | |
629 | id = qh_pointid(vertex->point); | |
630 | < | face->addVertex(bodydoubles[id]); |
631 | < | if( !isSurfaceID[id] ){ |
632 | < | isSurfaceID[id] = true; |
633 | < | surfaceSDs_.push_back(bodydoubles[id]); |
634 | < | } //IF isSurfaceID |
635 | < | } //Foreachvertex |
630 | > | int localindex = id; |
631 | > | #ifdef IS_MPI |
632 | > | Vector3d velVector(globalVel[dim_ * id],globalVel[dim_ * id + 1], globalVel[dim_ * id + 1]); |
633 | > | faceVel = faceVel + velVector; |
634 | > | if (id >= noffset/3 && id < (noffset + localPtArraySize)/3 ){ |
635 | > | localindex = localPtsMap[id-noffset/3]; |
636 | > | #else |
637 | > | faceVel = faceVel + bodydoubles[localindex]->getVel(); |
638 | > | #endif |
639 | > | face.addVertex(bodydoubles[localindex]); |
640 | > | if( !isSurfaceID[id] ){ |
641 | > | isSurfaceID[id] = true; |
642 | > | #ifdef IS_MPI |
643 | > | |
644 | > | #endif |
645 | > | |
646 | > | surfaceSDs_.push_back(bodydoubles[localindex]); |
647 | > | |
648 | > | } //IF isSurfaceID |
649 | ||
650 | < | |
650 | > | #ifdef IS_MPI |
651 | > | |
652 | > | }else{ |
653 | > | face.addVertex(NULL); |
654 | > | } |
655 | > | #endif |
656 | > | } //Foreachvertex |
657 | > | /* |
658 | > | if (!SETempty_(facet->coplanarset)){ |
659 | > | FOREACHpoint_(facet->coplanarset){ |
660 | > | id = qh_pointid(point); |
661 | > | surfaceSDs_.push_back(bodydoubles[id]); |
662 | > | } |
663 | > | } |
664 | > | */ |
665 | > | face.setFacetVelocity(faceVel/3.0); |
666 | Triangles_.push_back(face); | |
667 | qh_settempfree(&vertices); | |
668 | < | |
668 | > | |
669 | } //FORALLfacets | |
592 | – | |
670 | ||
594 | – | |
595 | – | |
671 | /* | |
672 | < | std::sort(surfaceIDs.begin(),surfaceIDs.end()); |
673 | < | surfaceIDs.erase(std::unique(surfaceIDs.begin(), surfaceIDs.end()), surfaceIDs.end()); |
674 | < | for(std::vector<int>::iterator list_iter = surfaceIDs.begin(); |
675 | < | list_iter != surfaceIDs.end(); list_iter++) |
601 | < | { |
602 | < | int i = *list_iter; |
603 | < | surfaceSDs_.push_back(bodydoubles[i]); |
672 | > | std::cout << surfaceSDs_.size() << std::endl; |
673 | > | for (SD = surfaceSDs_.begin(); SD != surfaceSDs_.end(); ++SD){ |
674 | > | Vector3d thisatom = (*SD)->getPos(); |
675 | > | std::cout << "Au " << thisatom.x() << " " << thisatom.y() << " " << thisatom.z() << std::endl; |
676 | } | |
677 | */ | |
678 | ||
679 | ||
680 | ||
681 | < | |
682 | < | |
683 | < | |
684 | < | Ns_ = surfaceSDs_.size(); |
685 | < | |
686 | < | |
687 | < | qh_getarea(qh facet_list); |
688 | < | volume_ = qh totvol; |
689 | < | area_ = qh totarea; |
690 | < | |
691 | < | |
692 | < | |
693 | < | qh_freeqhull(!qh_ALL); |
694 | < | qh_memfreeshort(&curlong, &totlong); |
695 | < | if (curlong || totlong) |
696 | < | std::cerr << "qhull internal warning (main): did not free %d bytes of long memory (%d pieces) " |
697 | < | << totlong << curlong << std::endl; |
626 | < | |
627 | < | |
628 | < | // free(pt_array); |
629 | < | |
681 | > | Ns_ = surfaceSDs_.size(); |
682 | > | nTriangles_ = Triangles_.size(); |
683 | > | |
684 | > | qh_getarea(qh facet_list); |
685 | > | volume_ = qh totvol; |
686 | > | area_ = qh totarea; |
687 | > | |
688 | > | |
689 | > | |
690 | > | qh_freeqhull(!qh_ALL); |
691 | > | qh_memfreeshort(&curlong, &totlong); |
692 | > | if (curlong || totlong) |
693 | > | std::cerr << "qhull internal warning (main): did not free %d bytes of long memory (%d pieces) " |
694 | > | << totlong << curlong << std::endl; |
695 | > | |
696 | > | |
697 | > | |
698 | } | |
699 | ||
700 |
– | Removed lines |
+ | Added lines |
< | Changed lines |
> | Changed lines |