- Timestamp:
- Aug 17, 2009, 10:48:03 AM (15 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 0077b5, 54a746, f1cccd
- Parents:
- 16d866
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/boundary.cpp
r16d866 r093645 229 229 void write_tecplot_file(ofstream *out, ofstream *tecplot, class Tesselation *TesselStruct, class molecule *mol, int N) 230 230 { 231 if (tecplot != NULL) { 231 if ((tecplot != NULL) && (TesselStruct != NULL)) { 232 // write header 232 233 *tecplot << "TITLE = \"3D CONVEX SHELL\"" << endl; 233 *tecplot << "VARIABLES = \"X\" \"Y\" \"Z\" " << endl;234 *tecplot << "ZONE T=\"TRIANGLES" << N << "\", N=" << TesselStruct->PointsOnBoundary Count << ", E=" << TesselStruct->TrianglesOnBoundaryCount<< ", DATAPACKING=POINT, ZONETYPE=FETRIANGLE" << endl;234 *tecplot << "VARIABLES = \"X\" \"Y\" \"Z\" \"U\"" << endl; 235 *tecplot << "ZONE T=\"TRIANGLES" << N << "\", N=" << TesselStruct->PointsOnBoundary.size() << ", E=" << TesselStruct->TrianglesOnBoundary.size() << ", DATAPACKING=POINT, ZONETYPE=FETRIANGLE" << endl; 235 236 int *LookupList = new int[mol->AtomCount]; 236 237 for (int i = 0; i < mol->AtomCount; i++) … … 244 245 Walker = target->second->node; 245 246 LookupList[Walker->nr] = Counter++; 246 *tecplot << Walker->node->x[0] << " " << Walker->node->x[1] << " " << Walker->node->x[2] << " " << endl;247 *tecplot << Walker->node->x[0] << " " << Walker->node->x[1] << " " << Walker->node->x[2] << " " << target->second->value << endl; 247 248 } 248 249 *tecplot << endl; … … 476 477 for (int axis = 0; axis < NDIM; axis++) 477 478 for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) 478 if (!mol->TesselStruct->Add Point(runner->second.second, 0))479 if (!mol->TesselStruct->AddBoundaryPoint(runner->second.second, 0)) 479 480 *out << Verbose(3) << "WARNING: Point " << *(runner->second.second) << " is already present!" << endl; 480 481 … … 524 525 525 526 // 3d. check all baselines whether the peaks of the two adjacent triangles with respect to center of baseline are convex, if not, make the baseline between the two peaks and baseline endpoints become the new peaks 526 if (!mol->TesselStruct->CorrectConcaveBaselines(out)) 527 *out << Verbose(1) << "Correction of concave baselines failed!" << endl; 527 bool AllConvex; 528 class BoundaryLineSet *line = NULL; 529 do { 530 AllConvex = true; 531 for (LineMap::iterator LineRunner = mol->TesselStruct->LinesOnBoundary.begin(); LineRunner != mol->TesselStruct->LinesOnBoundary.end(); LineRunner++) { 532 line = LineRunner->second; 533 *out << Verbose(1) << "INFO: Current line is " << *line << "." << endl; 534 if (!line->CheckConvexityCriterion(out)) { 535 *out << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl; 536 537 // flip the line 538 if (!mol->TesselStruct->PickFarthestofTwoBaselines(out, line)) 539 *out << Verbose(1) << "ERROR: Correction of concave baselines failed!" << endl; 540 else 541 *out << Verbose(1) << "INFO: Correction of concave baselines worked." << endl; 542 } 543 } 544 } while (!AllConvex); 528 545 529 546 // 3e. we need another correction here, for TesselPoints that are below the surface (i.e. have an odd number of concave triangles surrounding it) … … 562 579 563 580 /** Creates a convex envelope from a given non-convex one. 564 * -# We go through all PointsOnBoundary. 565 * -# We look at each of its lines and CheckConvexityCriterion(). 566 * -# If any returns concave, this Point cannot be on the final convex envelope. 567 * -# Hence, we remove it and re-create all its triangles from its getCircleOfConnectedPoints() 568 * -# We calculate the additional volume 569 * -# We go over the points until none yields a concave spot anymore. 570 * 581 * -# First step, remove concave spots, i.e. singular "dents" 582 * -# We go through all PointsOnBoundary. 583 * -# We CheckConvexityCriterion() for all its lines. 584 * -# If all its lines are concave, it cannot be on the convex envelope. 585 * -# Hence, we remove it and re-create all its triangles from its getCircleOfConnectedPoints() 586 * -# We calculate the additional volume. 587 * -# We go over all lines until none yields a concavity anymore. 588 * -# Second step, remove concave lines, i.e. line-shape "dents" 589 * -# We go through all LinesOnBoundary 590 * -# We CheckConvexityCriterion() 591 * -# If it returns concave, we flip the line in this quadrupel of points (abusing the degeneracy of the tesselation) 592 * -# We CheckConvexityCriterion(), 593 * -# if it's concave, we continue 594 * -# if not, we mark an error and stop 571 595 * Note: This routine - for free - calculates the difference in volume between convex and 572 596 * non-convex envelope, as the former is easy to calculate - VolumeOfConvexEnvelope() - it … … 574 598 * \param *out output stream for debugging 575 599 * \param *TesselStruct non-convex envelope, is changed in return! 576 * \param *configuration contains IsAngstroem() 600 * \param *mol molecule 601 * \param *filename name of file 577 602 * \return volume difference between the non- and the created convex envelope 578 603 */ 579 double ConvexizeNonconvexEnvelope(ofstream *out, class Tesselation *TesselStruct )604 double ConvexizeNonconvexEnvelope(ofstream *out, class Tesselation *TesselStruct, molecule *mol, char *filename) 580 605 { 581 606 double volume = 0; 582 607 class BoundaryPointSet *point = NULL; 583 608 class BoundaryLineSet *line = NULL; 584 class BoundaryTriangleSet *triangle = NULL; 585 Vector OldPoint, TetraederVector[3]; 609 bool Concavity; 610 PointMap::iterator PointRunner, PointAdvance; 611 LineMap::iterator LineRunner, LineAdvance; 612 TriangleMap::iterator TriangleRunner, TriangleAdvance; 613 586 614 *out << Verbose(0) << "Begin of ConvexizeNonconvexEnvelope" << endl; 587 615 616 // check whether there is something to work on 588 617 if (TesselStruct == NULL) { 589 618 *out << Verbose(1) << "ERROR: TesselStruct is empty!" << endl; … … 591 620 } 592 621 593 bool AllConvex = true; 594 bool Convexity = false; 595 do { 596 AllConvex = true; 597 for (PointMap::iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { 598 point = PointRunner->second; 599 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 600 Convexity = true; 601 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 602 line = LineRunner->second; 603 *out << Verbose(2) << "INFO: Current line is " << *line << "." << endl; 604 if (line->CheckConvexityCriterion(out)) { 605 // convex 606 } else { // concave 607 Convexity = false; // we have to go again through all ... 608 break; // no need to check the others too 609 } 610 } 611 AllConvex = AllConvex && Convexity; 612 if (!Convexity) { 613 *out << Verbose(1) << "... point cannot be on convex envelope." << endl; 614 OldPoint.CopyVector(point->node->node); 615 // get list of connected points 616 BoundaryPointSet *Otherpoint = line->GetOtherEndpoint(point); 617 list<TesselPoint*> *CircleofPoints = TesselStruct->getCircleOfConnectedPoints(out, point->node, Otherpoint->node->node); 618 // remove all triangles 619 int *numbers = NULL; 620 int count = 0; 621 int i=0; 622 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) 623 count+=LineRunner->second->triangles.size(); 624 numbers = new int[count]; 625 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 626 line = LineRunner->second; 627 for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) { 628 triangle = TriangleRunner->second; 629 *out << Verbose(2) << "Erasing triangle " << *triangle << "." << endl; 630 numbers[i] = triangle->Nr; 631 TesselStruct->TrianglesOnBoundary.erase(triangle->Nr); 632 delete(triangle); 633 i++; 634 } 635 } 636 *out << Verbose(1) << i << " triangles were removed." << endl; 637 638 // re-create all triangles by going through connected points list 639 list<TesselPoint*>::iterator OtherCircleRunner = CircleofPoints->end(); 640 OtherCircleRunner--; 641 i=0; 642 for (list<TesselPoint*>::iterator CircleRunner = CircleofPoints->begin(); CircleRunner != CircleofPoints->end(); CircleRunner++) { 643 *out << Verbose(2) << "Adding new triangle points."<< endl; 644 TesselStruct->AddPoint(point->node, 0); 645 TesselStruct->AddPoint(*CircleRunner, 1); 646 TesselStruct->AddPoint(*OtherCircleRunner, 2); 647 *out << Verbose(2) << "Adding new triangle lines."<< endl; 648 TesselStruct->AddTriangleLine(TesselStruct->BPS[0], TesselStruct->BPS[1], 0); 649 TesselStruct->AddTriangleLine(TesselStruct->BPS[0], TesselStruct->BPS[2], 1); 650 TesselStruct->AddTriangleLine(TesselStruct->BPS[1], TesselStruct->BPS[2], 2); 651 TesselStruct->BTS = new class BoundaryTriangleSet(TesselStruct->BLS, numbers[i]); 652 TesselStruct->TrianglesOnBoundary.insert(TrianglePair(numbers[i], triangle)); 653 *out << Verbose(2) << "Created triangle " << *TesselStruct->BTS << "." << endl; 654 // calculate volume summand as a general tetraeder 655 for (int j=0;j<3;j++) { 656 TetraederVector[j].CopyVector(TesselStruct->BPS[j]->node->node); 657 TetraederVector[j].SubtractVector(&OldPoint); 658 } 659 OldPoint.CopyVector(&TetraederVector[0]); 660 OldPoint.VectorProduct(&TetraederVector[1]); 661 volume += 1./6. * fabs(OldPoint.ScalarProduct(&TetraederVector[2])); 662 // advance other shank 663 OtherCircleRunner++; 664 if (OtherCircleRunner == CircleofPoints->end()) 665 OtherCircleRunner = CircleofPoints->begin(); 666 // advance number 667 i++; 668 if (i > count) 669 *out << Verbose(2) << "WARNING: Maximum of numbers reached!" << endl; 670 } 671 *out << Verbose(1) << i << " triangles were created." << endl; 672 673 delete[](numbers); 674 } 675 } 676 } while (!AllConvex); 622 // First step: RemovePointFromTesselatedSurface 623 PointRunner = TesselStruct->PointsOnBoundary.begin(); 624 PointAdvance = PointRunner; // we need an advanced point, as the PointRunner might get removed 625 while (PointRunner != TesselStruct->PointsOnBoundary.end()) { 626 PointAdvance++; 627 point = PointRunner->second; 628 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 629 Concavity = true; 630 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 631 line = LineRunner->second; 632 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 633 Concavity = Concavity && (!line->CheckConvexityCriterion(out)); 634 } 635 if (Concavity) { 636 *out << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl; 637 // remove the point 638 TesselStruct->RemovePointFromTesselatedSurface(out, point); 639 } 640 PointRunner = PointAdvance; 641 } 642 643 644 // // print all lines 645 // LineRunner = TesselStruct->LinesOnBoundary.begin(); 646 // LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed 647 // *out << Verbose(1) << "Printing all boundary lines for debugging." << endl; 648 // while (LineRunner != TesselStruct->LinesOnBoundary.end()) { 649 // LineAdvance++; 650 // line = LineRunner->second; 651 // *out << Verbose(2) << "INFO: Current line is " << *line << "." << endl; 652 // if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 653 // *out << Verbose(2) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl; 654 // LineRunner = LineAdvance; 655 // } 656 // 657 // // print all triangles 658 // TriangleRunner = TesselStruct->TrianglesOnBoundary.begin(); 659 // TriangleAdvance = TriangleRunner; // we need an advanced line, as the LineRunner might get removed 660 // *out << Verbose(1) << "Printing all boundary triangles for debugging." << endl; 661 // while (TriangleRunner != TesselStruct->TrianglesOnBoundary.end()) { 662 // TriangleAdvance++; 663 // *out << Verbose(2) << "INFO: Current triangle is " << *(TriangleRunner->second) << "." << endl; 664 // if (TriangleAdvance != TesselStruct->TrianglesOnBoundary.end()) 665 // *out << Verbose(2) << "INFO: Next triangle will be " << *(TriangleAdvance->second) << "." << endl; 666 // TriangleRunner = TriangleAdvance; 667 // } 668 669 // second step: PickFarthestofTwoBaselines 670 LineRunner = TesselStruct->LinesOnBoundary.begin(); 671 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed 672 while (LineRunner != TesselStruct->LinesOnBoundary.end()) { 673 LineAdvance++; 674 line = LineRunner->second; 675 *out << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl; 676 if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 677 // take highest of both lines 678 TesselStruct->PickFarthestofTwoBaselines(out, line); 679 LineRunner = LineAdvance; 680 } 681 682 // calculate remaining concavity 683 for (PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { 684 point = PointRunner->second; 685 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 686 point->value = 0; 687 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 688 line = LineRunner->second; 689 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 690 if (!line->CheckConvexityCriterion(out)) 691 point->value += 1; 692 } 693 } 694 695 // 4. Store triangles in tecplot file 696 if (filename != NULL) { 697 if (DoTecplotOutput) { 698 string OutputName(filename); 699 OutputName.append("_intermed"); 700 OutputName.append(TecplotSuffix); 701 ofstream *tecplot = new ofstream(OutputName.c_str()); 702 write_tecplot_file(out, tecplot, mol->TesselStruct, mol, 0); 703 tecplot->close(); 704 delete(tecplot); 705 } 706 if (DoRaster3DOutput) { 707 string OutputName(filename); 708 OutputName.append("_intermed"); 709 OutputName.append(Raster3DSuffix); 710 ofstream *rasterplot = new ofstream(OutputName.c_str()); 711 write_raster3d_file(out, rasterplot, mol->TesselStruct, mol); 712 rasterplot->close(); 713 delete(rasterplot); 714 } 715 } 716 717 // third step: IsConvexRectangle 718 LineRunner = TesselStruct->LinesOnBoundary.begin(); 719 LineAdvance = LineRunner; // we need an advanced line, as the LineRunner might get removed 720 while (LineRunner != TesselStruct->LinesOnBoundary.end()) { 721 LineAdvance++; 722 line = LineRunner->second; 723 *out << Verbose(1) << "INFO: Current line is " << *line << "." << endl; 724 if (LineAdvance != TesselStruct->LinesOnBoundary.end()) 725 *out << Verbose(1) << "INFO: Next line will be " << *(LineAdvance->second) << "." << endl; 726 if (!line->CheckConvexityCriterion(out)) { 727 *out << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl; 728 729 // take highest of both lines 730 point = TesselStruct->IsConvexRectangle(out, line); 731 if (point != NULL) 732 TesselStruct->RemovePointFromTesselatedSurface(out, point); 733 } 734 LineRunner = LineAdvance; 735 } 736 737 // calculate remaining concavity 738 for (PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) { 739 point = PointRunner->second; 740 *out << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 741 point->value = 0; 742 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 743 line = LineRunner->second; 744 *out << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 745 if (!line->CheckConvexityCriterion(out)) 746 point->value += 1; 747 } 748 } 749 750 // 4. Store triangles in tecplot file 751 if (filename != NULL) { 752 if (DoTecplotOutput) { 753 string OutputName(filename); 754 OutputName.append(TecplotSuffix); 755 ofstream *tecplot = new ofstream(OutputName.c_str()); 756 write_tecplot_file(out, tecplot, mol->TesselStruct, mol, 0); 757 tecplot->close(); 758 delete(tecplot); 759 } 760 if (DoRaster3DOutput) { 761 string OutputName(filename); 762 OutputName.append(Raster3DSuffix); 763 ofstream *rasterplot = new ofstream(OutputName.c_str()); 764 write_raster3d_file(out, rasterplot, mol->TesselStruct, mol); 765 rasterplot->close(); 766 delete(rasterplot); 767 } 768 } 769 770 // end 677 771 *out << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl; 678 679 // end680 772 return volume; 681 773 }; -
src/boundary.hpp
r16d866 r093645 39 39 void Find_convex_border(ofstream *out, molecule* mol, class LinkedCell *LCList, const char *filename); 40 40 void Find_non_convex_border(ofstream *out, molecule* mol, class LinkedCell *LC, const char *tempbasename, const double RADIUS); 41 double ConvexizeNonconvexEnvelope(ofstream *out, class Tesselation *TesselStruct );41 double ConvexizeNonconvexEnvelope(ofstream *out, class Tesselation *TesselStruct, molecule *mol, char *filename); 42 42 void Find_next_suitable_point(class BoundaryTriangleSet *BaseTriangle, class BoundaryLineSet *BaseLine, atom*& OptCandidate, Vector *OptCandidateCenter, double *ShortestAngle, const double RADIUS, LinkedCell *LC); 43 43 Boundaries *GetBoundaryPoints(ofstream *out, molecule *mol);
Note:
See TracChangeset
for help on using the changeset viewer.