Changes in src/boundary.cpp [b5c2d7:d6eb80]
- File:
-
- 1 edited
-
src/boundary.cpp (modified) (31 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
src/boundary.cpp
-
Property mode
changed from
100644to100755
rb5c2d7 rd6eb80 17 17 #include "tesselation.hpp" 18 18 #include "tesselationhelpers.hpp" 19 #include "World.hpp"20 19 21 20 #include<gsl/gsl_poly.h> … … 57 56 } else { 58 57 BoundaryPoints = BoundaryPtr; 59 DoLog(0) && (Log() << Verbose(0) << "Using given boundary points set." << endl);58 Log() << Verbose(0) << "Using given boundary points set." << endl; 60 59 } 61 60 // determine biggest "diameter" of cluster for each axis … … 163 162 AngleReferenceNormalVector.x[(axis + 2) % NDIM] = 1.; 164 163 165 DoLog(1) && (Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl);164 Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl; 166 165 167 166 // 3b. construct set of all points, transformed into cylindrical system and with left and right neighbours … … 184 183 angle = 2. * M_PI - angle; 185 184 } 186 DoLog(1) && (Log() << Verbose(1) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);185 Log() << Verbose(1) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl; 187 186 BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, Walker))); 188 187 if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity 189 DoLog(2) && (Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl);190 DoLog(2) && (Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl);191 DoLog(2) && (Log() << Verbose(2) << "New vector: " << *Walker << endl);188 Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl; 189 Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl; 190 Log() << Verbose(2) << "New vector: " << *Walker << endl; 192 191 const double ProjectedVectorNorm = ProjectedVector.NormSquared(); 193 192 if ((ProjectedVectorNorm - BoundaryTestPair.first->second.first) > MYEPSILON) { 194 193 BoundaryTestPair.first->second.first = ProjectedVectorNorm; 195 194 BoundaryTestPair.first->second.second = Walker; 196 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);195 Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl; 197 196 } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) { 198 197 helper.CopyVector(&Walker->x); … … 203 202 if (helper.NormSquared() < oldhelperNorm) { 204 203 BoundaryTestPair.first->second.second = Walker; 205 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl);204 Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl; 206 205 } else { 207 DoLog(2) && (Log() << Verbose(2) << "Keeping present vector due to larger distance to molecule center " << oldhelperNorm << "." << endl);206 Log() << Verbose(2) << "Keeping present vector due to larger distance to molecule center " << oldhelperNorm << "." << endl; 208 207 } 209 208 } else { 210 DoLog(2) && (Log() << Verbose(2) << "Keeping present vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);209 Log() << Verbose(2) << "Keeping present vector due to larger projected distance " << ProjectedVectorNorm << "." << endl; 211 210 } 212 211 } … … 227 226 // 3c. throw out points whose distance is less than the mean of left and right neighbours 228 227 bool flag = false; 229 DoLog(1) && (Log() << Verbose(1) << "Looking for candidates to kick out by convex condition ... " << endl);228 Log() << Verbose(1) << "Looking for candidates to kick out by convex condition ... " << endl; 230 229 do { // do as long as we still throw one out per round 231 230 flag = false; … … 282 281 const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.); 283 282 //Log() << Verbose(1) << " I calculated: a = " << a << ", h = " << h << ", beta(" << left->second.second->Name << "," << left->second.second->Name << "-" << right->second.second->Name << ") = " << beta << ", delta(" << left->second.second->Name << "," << runner->second.second->Name << ") = " << delta << ", Min = " << MinDistance << "." << endl; 284 DoLog(1) && (Log() << Verbose(1) << "Checking CoG distance of runner " << *runner->second.second << " " << h << " against triangle's side length spanned by (" << *left->second.second << "," << *right->second.second << ") of " << MinDistance << "." << endl);283 Log() << Verbose(1) << "Checking CoG distance of runner " << *runner->second.second << " " << h << " against triangle's side length spanned by (" << *left->second.second << "," << *right->second.second << ") of " << MinDistance << "." << endl; 285 284 if ((fabs(h / fabs(h) - MinDistance / fabs(MinDistance)) < MYEPSILON) && ((h - MinDistance)) < -MYEPSILON) { 286 285 // throw out point 287 DoLog(1) && (Log() << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl);286 Log() << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl; 288 287 BoundaryPoints[axis].erase(runner); 289 288 flag = true; … … 320 319 BoundaryPoints = GetBoundaryPoints(mol, TesselStruct); 321 320 } else { 322 DoLog(0) && (Log() << Verbose(0) << "Using given boundary points set." << endl);321 Log() << Verbose(0) << "Using given boundary points set." << endl; 323 322 } 324 323 … … 326 325 for (int axis=0; axis < NDIM; axis++) 327 326 { 328 DoLog(1) && (Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl);327 Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl; 329 328 int i=0; 330 329 for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) { 331 330 if (runner != BoundaryPoints[axis].begin()) 332 DoLog(0) && (Log() << Verbose(0) << ", " << i << ": " << *runner->second.second);331 Log() << Verbose(0) << ", " << i << ": " << *runner->second.second; 333 332 else 334 DoLog(0) && (Log() << Verbose(0) << i << ": " << *runner->second.second);333 Log() << Verbose(0) << i << ": " << *runner->second.second; 335 334 i++; 336 335 } 337 DoLog(0) && (Log() << Verbose(0) << endl);336 Log() << Verbose(0) << endl; 338 337 } 339 338 … … 342 341 for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) 343 342 if (!TesselStruct->AddBoundaryPoint(runner->second.second, 0)) 344 DoeLog(2) && (eLog()<< Verbose(2) << "Point " << *(runner->second.second) << " is already present!" << endl);345 346 DoLog(0) && (Log() << Verbose(0) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl);343 eLog() << Verbose(2) << "Point " << *(runner->second.second) << " is already present!" << endl; 344 345 Log() << Verbose(0) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl; 347 346 // now we have the whole set of edge points in the BoundaryList 348 347 … … 362 361 // 3c. check whether all atoms lay inside the boundary, if not, add to boundary points, segment triangle into three with the new point 363 362 if (!TesselStruct->InsertStraddlingPoints(mol, LCList)) 364 DoeLog(1) && (eLog()<< Verbose(1) << "Insertion of straddling points failed!" << endl);365 366 DoLog(0) && (Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " intermediate triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl);363 eLog() << Verbose(1) << "Insertion of straddling points failed!" << endl; 364 365 Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " intermediate triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl; 367 366 368 367 // 4. Store triangles in tecplot file … … 395 394 for (LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) { 396 395 line = LineRunner->second; 397 DoLog(1) && (Log() << Verbose(1) << "INFO: Current line is " << *line << "." << endl);396 Log() << Verbose(1) << "INFO: Current line is " << *line << "." << endl; 398 397 if (!line->CheckConvexityCriterion()) { 399 DoLog(1) && (Log() << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl);398 Log() << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl; 400 399 401 400 // flip the line 402 401 if (TesselStruct->PickFarthestofTwoBaselines(line) == 0.) 403 DoeLog(1) && (eLog()<< Verbose(1) << "Correction of concave baselines failed!" << endl);402 eLog() << Verbose(1) << "Correction of concave baselines failed!" << endl; 404 403 else { 405 404 TesselStruct->FlipBaseline(line); 406 DoLog(1) && (Log() << Verbose(1) << "INFO: Correction of concave baselines worked." << endl);405 Log() << Verbose(1) << "INFO: Correction of concave baselines worked." << endl; 407 406 } 408 407 } … … 414 413 // Log() << Verbose(1) << "Correction of concave tesselpoints failed!" << endl; 415 414 416 DoLog(0) && (Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl);415 Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl; 417 416 418 417 // 4. Store triangles in tecplot file … … 456 455 457 456 if ((TesselStruct == NULL) || (TesselStruct->PointsOnBoundary.empty())) { 458 DoeLog(1) && (eLog()<< Verbose(1) << "TesselStruct is empty." << endl);457 eLog() << Verbose(1) << "TesselStruct is empty." << endl; 459 458 return false; 460 459 } … … 462 461 PointMap::iterator PointRunner; 463 462 while (!TesselStruct->PointsOnBoundary.empty()) { 464 DoLog(1) && (Log() << Verbose(1) << "Remaining points are: ");463 Log() << Verbose(1) << "Remaining points are: "; 465 464 for (PointMap::iterator PointSprinter = TesselStruct->PointsOnBoundary.begin(); PointSprinter != TesselStruct->PointsOnBoundary.end(); PointSprinter++) 466 DoLog(0) && (Log() << Verbose(0) << *(PointSprinter->second) << "\t");467 DoLog(0) && (Log() << Verbose(0) << endl);465 Log() << Verbose(0) << *(PointSprinter->second) << "\t"; 466 Log() << Verbose(0) << endl; 468 467 469 468 PointRunner = TesselStruct->PointsOnBoundary.begin(); … … 521 520 // check whether there is something to work on 522 521 if (TesselStruct == NULL) { 523 DoeLog(1) && (eLog()<< Verbose(1) << "TesselStruct is empty!" << endl);522 eLog() << Verbose(1) << "TesselStruct is empty!" << endl; 524 523 return volume; 525 524 } … … 537 536 PointAdvance++; 538 537 point = PointRunner->second; 539 DoLog(1) && (Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl);538 Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl; 540 539 for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) { 541 540 line = LineRunner->second; 542 DoLog(1) && (Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl);541 Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl; 543 542 if (!line->CheckConvexityCriterion()) { 544 543 // remove the point if needed 545 DoLog(1) && (Log() << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl);544 Log() << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl; 546 545 volume += TesselStruct->RemovePointFromTesselatedSurface(point); 547 546 sprintf(dummy, "-first-%d", ++run); … … 564 563 LineAdvance++; 565 564 line = LineRunner->second; 566 DoLog(1) && (Log() << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl);565 Log() << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl; 567 566 // take highest of both lines 568 567 if (TesselStruct->IsConvexRectangle(line) == NULL) { … … 605 604 606 605 // end 607 DoLog(0) && (Log() << Verbose(0) << "Volume is " << volume << "." << endl);606 Log() << Verbose(0) << "Volume is " << volume << "." << endl; 608 607 return volume; 609 608 }; … … 734 733 totalmass += Walker->type->mass; 735 734 } 736 DoLog(0) && (Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl);737 DoLog(0) && (Log() << Verbose(0) << "RESULT: The average density is " << setprecision(10) << totalmass / clustervolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);735 Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl; 736 Log() << Verbose(0) << "RESULT: The average density is " << setprecision(10) << totalmass / clustervolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl; 738 737 739 738 // solve cubic polynomial 740 DoLog(1) && (Log() << Verbose(1) << "Solving equidistant suspension in water problem ..." << endl);739 Log() << Verbose(1) << "Solving equidistant suspension in water problem ..." << endl; 741 740 if (IsAngstroem) 742 741 cellvolume = (TotalNoClusters * totalmass / SOLVENTDENSITY_A - (totalmass / clustervolume)) / (celldensity - 1); 743 742 else 744 743 cellvolume = (TotalNoClusters * totalmass / SOLVENTDENSITY_a0 - (totalmass / clustervolume)) / (celldensity - 1); 745 DoLog(1) && (Log() << Verbose(1) << "Cellvolume needed for a density of " << celldensity << " g/cm^3 is " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);744 Log() << Verbose(1) << "Cellvolume needed for a density of " << celldensity << " g/cm^3 is " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl; 746 745 747 746 double minimumvolume = TotalNoClusters * (GreatestDiameter[0] * GreatestDiameter[1] * GreatestDiameter[2]); 748 DoLog(1) && (Log() << Verbose(1) << "Minimum volume of the convex envelope contained in a rectangular box is " << minimumvolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);747 Log() << Verbose(1) << "Minimum volume of the convex envelope contained in a rectangular box is " << minimumvolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl; 749 748 if (minimumvolume > cellvolume) { 750 DoeLog(1) && (eLog()<< Verbose(1) << "the containing box already has a greater volume than the envisaged cell volume!" << endl);751 DoLog(0) && (Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl);749 eLog() << Verbose(1) << "the containing box already has a greater volume than the envisaged cell volume!" << endl; 750 Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl; 752 751 for (int i = 0; i < NDIM; i++) 753 752 BoxLengths.x[i] = GreatestDiameter[i]; … … 761 760 double x2 = 0.; 762 761 if (gsl_poly_solve_cubic(BoxLengths.x[0], BoxLengths.x[1], BoxLengths.x[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return 763 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl);762 Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl; 764 763 else { 765 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacings are: " << x0 << " and " << x1 << " and " << x2 << " ." << endl);764 Log() << Verbose(0) << "RESULT: The resulting spacings are: " << x0 << " and " << x1 << " and " << x2 << " ." << endl; 766 765 x0 = x2; // sorted in ascending order 767 766 } … … 774 773 775 774 // set new box dimensions 776 DoLog(0) && (Log() << Verbose(0) << "Translating to box with these boundaries." << endl);775 Log() << Verbose(0) << "Translating to box with these boundaries." << endl; 777 776 mol->SetBoxDimension(&BoxLengths); 778 777 mol->CenterInBox(); … … 780 779 // update Box of atoms by boundary 781 780 mol->SetBoxDimension(&BoxLengths); 782 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths.x[0] << " and " << BoxLengths.x[1] << " and " << BoxLengths.x[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);781 Log() << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths.x[0] << " and " << BoxLengths.x[1] << " and " << BoxLengths.x[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl; 783 782 }; 784 783 … … 790 789 * \param *filler molecule which the box is to be filled with 791 790 * \param configuration contains box dimensions 792 * \param MaxDistance fills in molecules only up to this distance (set to -1 if whole of the domain)793 791 * \param distance[NDIM] distance between filling molecules in each direction 794 792 * \param boundary length of boundary zone between molecule and filling mollecules … … 799 797 * \return *mol pointer to new molecule with filled atoms 800 798 */ 801 molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, const double MaxDistance, const doubledistance[NDIM], const double boundary, const double RandomAtomDisplacement, const double RandomMolDisplacement, const bool DoRandomRotation)799 molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, const double distance[NDIM], const double boundary, const double RandomAtomDisplacement, const double RandomMolDisplacement, const bool DoRandomRotation) 802 800 { 803 801 Info FunctionInfo(__func__); … … 806 804 int N[NDIM]; 807 805 int n[NDIM]; 808 double *M = ReturnFullMatrixforSymmetric( World::get()->cell_size);806 double *M = ReturnFullMatrixforSymmetric(filler->cell_size); 809 807 double Rotations[NDIM*NDIM]; 810 double *MInverse = InverseMatrix(M);811 808 Vector AtomTranslations; 812 809 Vector FillerTranslations; 813 810 Vector FillerDistance; 814 Vector Inserter;815 811 double FillIt = false; 816 812 atom *Walker = NULL; 817 813 bond *Binder = NULL; 814 int i = 0; 815 LinkedCell *LCList[List->ListOfMolecules.size()]; 818 816 double phi[NDIM]; 819 map<molecule *, Tesselation *> TesselStruct;820 map<molecule *, LinkedCell *> LCList; 821 822 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) 823 if ((*ListRunner)->AtomCount > 0) {824 DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl);825 LCList[(*ListRunner)] = new LinkedCell((*ListRunner), 10.); // get linked cell list826 DoLog(1) && (Log() << Verbose(1) << "Pre-creating tesselation for molecule " << *ListRunner << "." << endl);827 TesselStruct[(*ListRunner)] = NULL;828 FindNonConvexBorder((*ListRunner), TesselStruct[(*ListRunner)], (const LinkedCell *&)LCList[(*ListRunner)], 5., NULL);829 }817 class Tesselation *TesselStruct[List->ListOfMolecules.size()]; 818 819 i=0; 820 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) { 821 Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl; 822 LCList[i] = new LinkedCell((*ListRunner), 10.); // get linked cell list 823 Log() << Verbose(1) << "Pre-creating tesselation for molecule " << *ListRunner << "." << endl; 824 TesselStruct[i] = NULL; 825 FindNonConvexBorder((*ListRunner), TesselStruct[i], (const LinkedCell *&)LCList[i], 5., NULL); 826 i++; 827 } 830 828 831 829 // Center filler at origin 832 filler->Center Edge(&Inserter);830 filler->CenterOrigin(); 833 831 filler->Center.Zero(); 834 DoLog(2) && (Log() << Verbose(2) << "INFO: Filler molecule has the following bonds:" << endl);835 Binder = filler->first;836 while(Binder->next != filler->last) {837 Binder = Binder->next;838 DoLog(2) && (Log() << Verbose(2) << " " << *Binder << endl);839 }840 832 841 833 filler->CountAtoms(); … … 847 839 for(int i=0;i<NDIM;i++) 848 840 N[i] = (int) ceil(1./FillerDistance.x[i]); 849 DoLog(1) && (Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl);841 Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl; 850 842 851 843 // initialize seed of random number generator to current time … … 859 851 CurrentPosition.Init((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]); 860 852 CurrentPosition.MatrixMultiplication(M); 861 // create molecule random translation vector ... 862 for (int i=0;i<NDIM;i++) 863 FillerTranslations.x[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.); 864 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl); 865 866 // go through all atoms 867 for (int i=0;i<filler->AtomCount;i++) 868 CopyAtoms[i] = NULL; 869 Walker = filler->start; 870 while (Walker->next != filler->end) { 871 Walker = Walker->next; 872 873 // create atomic random translation vector ... 853 Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "." << endl; 854 // Check whether point is in- or outside 855 FillIt = true; 856 i=0; 857 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) { 858 // get linked cell list 859 if (TesselStruct[i] == NULL) { 860 eLog() << Verbose(0) << "TesselStruct of " << (*ListRunner) << " is NULL. Didn't we pre-create it?" << endl; 861 FillIt = false; 862 } else { 863 const double distance = (TesselStruct[i]->GetDistanceSquaredToSurface(CurrentPosition, LCList[i])); 864 FillIt = FillIt && (distance > boundary*boundary); 865 if (FillIt) { 866 Log() << Verbose(1) << "INFO: Position at " << CurrentPosition << " is outer point." << endl; 867 } else { 868 Log() << Verbose(1) << "INFO: Position at " << CurrentPosition << " is inner point or within boundary." << endl; 869 break; 870 } 871 i++; 872 } 873 } 874 875 if (FillIt) { 876 // fill in Filler 877 Log() << Verbose(2) << "Space at " << CurrentPosition << " is unoccupied by any molecule, filling in." << endl; 878 879 // create molecule random translation vector ... 874 880 for (int i=0;i<NDIM;i++) 875 AtomTranslations.x[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.); 876 877 // ... and rotation matrix 878 if (DoRandomRotation) { 879 for (int i=0;i<NDIM;i++) { 880 phi[i] = rand()/(RAND_MAX/(2.*M_PI)); 881 } 882 883 Rotations[0] = cos(phi[0]) *cos(phi[2]) + (sin(phi[0])*sin(phi[1])*sin(phi[2])); 884 Rotations[3] = sin(phi[0]) *cos(phi[2]) - (cos(phi[0])*sin(phi[1])*sin(phi[2])); 885 Rotations[6] = cos(phi[1])*sin(phi[2]) ; 886 Rotations[1] = - sin(phi[0])*cos(phi[1]) ; 887 Rotations[4] = cos(phi[0])*cos(phi[1]) ; 888 Rotations[7] = sin(phi[1]) ; 889 Rotations[3] = - cos(phi[0]) *sin(phi[2]) + (sin(phi[0])*sin(phi[1])*cos(phi[2])); 890 Rotations[5] = - sin(phi[0]) *sin(phi[2]) - (cos(phi[0])*sin(phi[1])*cos(phi[2])); 891 Rotations[8] = cos(phi[1])*cos(phi[2]) ; 892 } 893 894 // ... and put at new position 895 Inserter.CopyVector(&(Walker->x)); 896 if (DoRandomRotation) 897 Inserter.MatrixMultiplication(Rotations); 898 Inserter.AddVector(&AtomTranslations); 899 Inserter.AddVector(&FillerTranslations); 900 Inserter.AddVector(&CurrentPosition); 901 902 // check whether inserter is inside box 903 Inserter.MatrixMultiplication(MInverse); 904 FillIt = true; 905 for (int i=0;i<NDIM;i++) 906 FillIt = FillIt && (Inserter.x[i] >= -MYEPSILON) && ((Inserter.x[i]-1.) <= MYEPSILON); 907 Inserter.MatrixMultiplication(M); 908 909 // Check whether point is in- or outside 910 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) { 911 // get linked cell list 912 if (TesselStruct[(*ListRunner)] != NULL) { 913 const double distance = (TesselStruct[(*ListRunner)]->GetDistanceToSurface(Inserter, LCList[(*ListRunner)])); 914 FillIt = FillIt && (distance > boundary) && ((MaxDistance < 0) || (MaxDistance > distance)); 915 } 916 } 917 // insert into Filling 918 if (FillIt) { 919 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl); 881 FillerTranslations.x[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.); 882 Log() << Verbose(2) << "INFO: Translating this filler by " << FillerTranslations << "." << endl; 883 884 // go through all atoms 885 Walker = filler->start; 886 while (Walker->next != filler->end) { 887 Walker = Walker->next; 920 888 // copy atom ... 921 889 CopyAtoms[Walker->nr] = new atom(Walker); 922 CopyAtoms[Walker->nr]->x.CopyVector(&Inserter); 890 891 // create atomic random translation vector ... 892 for (int i=0;i<NDIM;i++) 893 AtomTranslations.x[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.); 894 895 // ... and rotation matrix 896 if (DoRandomRotation) { 897 for (int i=0;i<NDIM;i++) { 898 phi[i] = rand()/(RAND_MAX/(2.*M_PI)); 899 } 900 901 Rotations[0] = cos(phi[0]) *cos(phi[2]) + (sin(phi[0])*sin(phi[1])*sin(phi[2])); 902 Rotations[3] = sin(phi[0]) *cos(phi[2]) - (cos(phi[0])*sin(phi[1])*sin(phi[2])); 903 Rotations[6] = cos(phi[1])*sin(phi[2]) ; 904 Rotations[1] = - sin(phi[0])*cos(phi[1]) ; 905 Rotations[4] = cos(phi[0])*cos(phi[1]) ; 906 Rotations[7] = sin(phi[1]) ; 907 Rotations[3] = - cos(phi[0]) *sin(phi[2]) + (sin(phi[0])*sin(phi[1])*cos(phi[2])); 908 Rotations[5] = - sin(phi[0]) *sin(phi[2]) - (cos(phi[0])*sin(phi[1])*cos(phi[2])); 909 Rotations[8] = cos(phi[1])*cos(phi[2]) ; 910 } 911 912 // ... and put at new position 913 if (DoRandomRotation) 914 CopyAtoms[Walker->nr]->x.MatrixMultiplication(Rotations); 915 CopyAtoms[Walker->nr]->x.AddVector(&AtomTranslations); 916 CopyAtoms[Walker->nr]->x.AddVector(&FillerTranslations); 917 CopyAtoms[Walker->nr]->x.AddVector(&CurrentPosition); 918 919 // insert into Filling 920 921 // FIXME: gives completely different results if CopyAtoms[..] used instead of Walker, why??? 922 Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl; 923 923 Filling->AddAtom(CopyAtoms[Walker->nr]); 924 DoLog(4) && (Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl);925 } else {926 DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is inner point, within boundary or outside of MaxDistance." << endl);927 CopyAtoms[Walker->nr] = NULL;928 continue;929 924 } 930 } 931 // go through all bonds and add as well 932 Binder = filler->first; 933 while(Binder->next != filler->last) { 934 Binder = Binder->next; 935 if ((CopyAtoms[Binder->leftatom->nr] != NULL) && (CopyAtoms[Binder->rightatom->nr] != NULL)) { 936 Log() << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl; 925 926 // go through all bonds and add as well 927 Binder = filler->first; 928 while(Binder->next != filler->last) { 929 Binder = Binder->next; 930 Log() << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl; 937 931 Filling->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree); 938 932 } 933 } else { 934 // leave empty 935 Log() << Verbose(2) << "Space at " << CurrentPosition << " is occupied." << endl; 939 936 } 940 937 } 941 938 Free(&M); 942 Free(&MInverse); 943 939 940 // output to file 941 TesselStruct[0]->LastTriangle = NULL; 942 StoreTrianglesinFile(Filling, TesselStruct[0], "Tesselated", ".dat"); 943 944 for (size_t i=0;i<List->ListOfMolecules.size();i++) { 945 delete(LCList[i]); 946 delete(TesselStruct[i]); 947 } 944 948 return Filling; 945 949 }; … … 960 964 bool freeLC = false; 961 965 bool status = false; 962 CandidateForTesselation *baseline = NULL; 966 CandidateForTesselation *baseline; 967 LineMap::iterator testline; 963 968 bool OneLoopWithoutSuccessFlag = true; // marks whether we went once through all baselines without finding any without two triangles 964 969 bool TesselationFailFlag = false; 970 BoundaryTriangleSet *T = NULL; 965 971 966 972 if (TesselStruct == NULL) { 967 DoLog(1) && (Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl);973 Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl; 968 974 TesselStruct= new Tesselation; 969 975 } else { 970 976 delete(TesselStruct); 971 DoLog(1) && (Log() << Verbose(1) << "Re-Allocating Tesselation struct ..." << endl);977 Log() << Verbose(1) << "Re-Allocating Tesselation struct ..." << endl; 972 978 TesselStruct = new Tesselation; 973 979 } … … 980 986 981 987 // 1. get starting triangle 982 if (!TesselStruct->FindStartingTriangle(RADIUS, LCList)) { 983 DoeLog(0) && (eLog() << Verbose(0) << "No valid starting triangle found." << endl); 984 //performCriticalExit(); 985 } 986 if (filename != NULL) { 987 if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration 988 TesselStruct->Output(filename, mol); 989 } 990 } 988 TesselStruct->FindStartingTriangle(RADIUS, LCList); 991 989 992 990 // 2. expand from there 993 991 while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) { 994 (cerr << "There are " << TesselStruct->TrianglesOnBoundary.size() << " triangles and " << TesselStruct->OpenLines.size() << " open lines to scan for candidates." << endl); 995 // 2a. print OpenLines without candidates 996 DoLog(1) && (Log() << Verbose(1) << "There are the following open lines to scan for a candidates:" << endl); 992 // 2a. fill all new OpenLines 993 Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for candidates:" << endl; 997 994 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) 998 if (Runner->second->pointlist.empty()) 999 DoLog(1) && (Log() << Verbose(1) << " " << *(Runner->second) << endl); 1000 1001 // 2b. find best candidate for each OpenLine 1002 TesselationFailFlag = TesselStruct->FindCandidatesforOpenLines(RADIUS, LCList); 1003 1004 // 2c. print OpenLines with candidates again 1005 DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl); 995 Log() << Verbose(2) << *(Runner->second) << endl; 996 997 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) { 998 baseline = Runner->second; 999 if (baseline->pointlist.empty()) { 1000 T = (((baseline->BaseLine->triangles.begin()))->second); 1001 Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl; 1002 TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one. 1003 } 1004 } 1005 1006 // 2b. search for smallest ShortestAngle among all candidates 1007 double ShortestAngle = 4.*M_PI; 1008 Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl; 1006 1009 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) 1007 DoLog(1) && (Log() << Verbose(1) << " " << *(Runner->second) << endl); 1008 1009 // 2d. search for smallest ShortestAngle among all candidates 1010 double ShortestAngle = 4.*M_PI; 1010 Log() << Verbose(2) << *(Runner->second) << endl; 1011 1011 1012 for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) { 1012 1013 if (Runner->second->ShortestAngle < ShortestAngle) { 1013 1014 baseline = Runner->second; 1014 1015 ShortestAngle = baseline->ShortestAngle; 1015 DoLog(1) && (Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *(*baseline->pointlist.begin()) << " and angle " << baseline->ShortestAngle << endl);1016 //Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *baseline->point << " and angle " << baseline->ShortestAngle << endl; 1016 1017 } 1017 1018 } 1018 // 2e. if we found one, add candidate1019 1019 if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty())) 1020 1020 OneLoopWithoutSuccessFlag = false; 1021 1021 else { 1022 TesselStruct->AddCandidate Polygon(*baseline, RADIUS, LCList);1023 } 1024 1025 // 2f.write temporary envelope1022 TesselStruct->AddCandidateTriangle(*baseline); 1023 } 1024 1025 // write temporary envelope 1026 1026 if (filename != NULL) { 1027 1027 if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration … … 1058 1058 StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, ""); 1059 1059 1060 //// correct degenerated polygons1061 //TesselStruct->CorrectAllDegeneratedPolygons();1062 // 1063 //// check envelope for consistency1064 //status = CheckListOfBaselines(TesselStruct);1060 // correct degenerated polygons 1061 TesselStruct->CorrectAllDegeneratedPolygons(); 1062 1063 // check envelope for consistency 1064 status = CheckListOfBaselines(TesselStruct); 1065 1065 1066 1066 // write final envelope -
Property mode
changed from
Note:
See TracChangeset
for help on using the changeset viewer.
