Changeset 8cbb97 for src/boundary.cpp
- Timestamp:
- Apr 29, 2010, 1:55:21 PM (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:
- d79639
- Parents:
- 632bc3 (diff), 753f02 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/boundary.cpp
r632bc3 r8cbb97 19 19 #include "tesselationhelpers.hpp" 20 20 #include "World.hpp" 21 #include "Plane.hpp" 21 22 22 23 #include<gsl/gsl_poly.h> … … 78 79 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around 79 80 Neighbour = BoundaryPoints[axis].begin(); 80 DistanceVector.CopyVector(&runner->second.second->x); 81 DistanceVector.SubtractVector(&Neighbour->second.second->x); 81 DistanceVector = runner->second.second->x - Neighbour->second.second->x; 82 82 do { // seek for neighbour pair where it flips 83 OldComponent = DistanceVector .x[Othercomponent];83 OldComponent = DistanceVector[Othercomponent]; 84 84 Neighbour++; 85 85 if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around 86 86 Neighbour = BoundaryPoints[axis].begin(); 87 DistanceVector.CopyVector(&runner->second.second->x); 88 DistanceVector.SubtractVector(&Neighbour->second.second->x); 87 DistanceVector = runner->second.second->x - Neighbour->second.second->x; 89 88 //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl; 90 89 } while ((runner != Neighbour) && (fabs(OldComponent / fabs( 91 OldComponent) - DistanceVector .x[Othercomponent] / fabs(92 DistanceVector .x[Othercomponent])) < MYEPSILON)); // as long as sign does not flip90 OldComponent) - DistanceVector[Othercomponent] / fabs( 91 DistanceVector[Othercomponent])) < MYEPSILON)); // as long as sign does not flip 93 92 if (runner != Neighbour) { 94 93 OtherNeighbour = Neighbour; … … 98 97 //Log() << Verbose(1) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl; 99 98 // now we have found the pair: Neighbour and OtherNeighbour 100 OtherVector.CopyVector(&runner->second.second->x); 101 OtherVector.SubtractVector(&OtherNeighbour->second.second->x); 99 OtherVector = runner->second.second->x - OtherNeighbour->second.second->x; 102 100 //Log() << Verbose(1) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl; 103 101 //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl; 104 102 // do linear interpolation between points (is exact) to extract exact intersection between Neighbour and OtherNeighbour 105 w1 = fabs(OtherVector .x[Othercomponent]);106 w2 = fabs(DistanceVector .x[Othercomponent]);107 tmp = fabs((w1 * DistanceVector .x[component] + w2108 * OtherVector .x[component]) / (w1 + w2));103 w1 = fabs(OtherVector[Othercomponent]); 104 w2 = fabs(DistanceVector[Othercomponent]); 105 tmp = fabs((w1 * DistanceVector[component] + w2 106 * OtherVector[component]) / (w1 + w2)); 109 107 // mark if it has greater diameter 110 108 //Log() << Verbose(1) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl; … … 160 158 AngleReferenceVector.Zero(); 161 159 AngleReferenceNormalVector.Zero(); 162 AxisVector .x[axis] = 1.;163 AngleReferenceVector .x[(axis + 1) % NDIM] = 1.;164 AngleReferenceNormalVector .x[(axis + 2) % NDIM] = 1.;160 AxisVector[axis] = 1.; 161 AngleReferenceVector[(axis + 1) % NDIM] = 1.; 162 AngleReferenceNormalVector[(axis + 2) % NDIM] = 1.; 165 163 166 164 DoLog(1) && (Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl); … … 170 168 while (Walker->next != mol->end) { 171 169 Walker = Walker->next; 172 ProjectedVector.CopyVector(&Walker->x); 173 ProjectedVector.SubtractVector(MolCenter); 174 ProjectedVector.ProjectOntoPlane(&AxisVector); 170 ProjectedVector = Walker->x - (*MolCenter); 171 ProjectedVector.ProjectOntoPlane(AxisVector); 175 172 176 173 // correct for negative side 177 174 const double radius = ProjectedVector.NormSquared(); 178 175 if (fabs(radius) > MYEPSILON) 179 angle = ProjectedVector.Angle( &AngleReferenceVector);176 angle = ProjectedVector.Angle(AngleReferenceVector); 180 177 else 181 178 angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues 182 179 183 180 //Log() << Verbose(1) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl; 184 if (ProjectedVector.ScalarProduct( &AngleReferenceNormalVector) > 0) {181 if (ProjectedVector.ScalarProduct(AngleReferenceNormalVector) > 0) { 185 182 angle = 2. * M_PI - angle; 186 183 } … … 197 194 DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl); 198 195 } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) { 199 helper.CopyVector(&Walker->x); 200 helper.SubtractVector(MolCenter); 196 helper = Walker->x - (*MolCenter); 201 197 const double oldhelperNorm = helper.NormSquared(); 202 helper.CopyVector(&BoundaryTestPair.first->second.second->x); 203 helper.SubtractVector(MolCenter); 198 helper = BoundaryTestPair.first->second.second->x - (*MolCenter); 204 199 if (helper.NormSquared() < oldhelperNorm) { 205 200 BoundaryTestPair.first->second.second = Walker; … … 251 246 { 252 247 Vector SideA, SideB, SideC, SideH; 253 SideA.CopyVector(&left->second.second->x); 254 SideA.SubtractVector(MolCenter); 255 SideA.ProjectOntoPlane(&AxisVector); 248 SideA = left->second.second->x - (*MolCenter); 249 SideA.ProjectOntoPlane(AxisVector); 256 250 // Log() << Verbose(1) << "SideA: " << SideA << endl; 257 251 258 SideB.CopyVector(&right->second.second->x); 259 SideB.SubtractVector(MolCenter); 260 SideB.ProjectOntoPlane(&AxisVector); 252 SideB = right->second.second->x -(*MolCenter); 253 SideB.ProjectOntoPlane(AxisVector); 261 254 // Log() << Verbose(1) << "SideB: " << SideB << endl; 262 255 263 SideC.CopyVector(&left->second.second->x); 264 SideC.SubtractVector(&right->second.second->x); 265 SideC.ProjectOntoPlane(&AxisVector); 256 SideC = left->second.second->x - right->second.second->x; 257 SideC.ProjectOntoPlane(AxisVector); 266 258 // Log() << Verbose(1) << "SideC: " << SideC << endl; 267 259 268 SideH.CopyVector(&runner->second.second->x); 269 SideH.SubtractVector(MolCenter); 270 SideH.ProjectOntoPlane(&AxisVector); 260 SideH = runner->second.second->x -(*MolCenter); 261 SideH.ProjectOntoPlane(AxisVector); 271 262 // Log() << Verbose(1) << "SideH: " << SideH << endl; 272 263 … … 277 268 const double h = SideH.Norm(); 278 269 // calculate the angles 279 const double alpha = SideA.Angle( &SideH);280 const double beta = SideA.Angle( &SideC);281 const double gamma = SideB.Angle( &SideH);282 const double delta = SideC.Angle( &SideH);270 const double alpha = SideA.Angle(SideH); 271 const double beta = SideA.Angle(SideC); 272 const double gamma = SideB.Angle(SideH); 273 const double delta = SideC.Angle(SideH); 283 274 const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.); 284 275 //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; … … 629 620 for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++) 630 621 { // go through every triangle, calculate volume of its pyramid with CoG as peak 631 x.CopyVector(runner->second->endpoints[0]->node->node); 632 x.SubtractVector(runner->second->endpoints[1]->node->node); 633 y.CopyVector(runner->second->endpoints[0]->node->node); 634 y.SubtractVector(runner->second->endpoints[2]->node->node); 635 const double a = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node)); 636 const double b = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(runner->second->endpoints[2]->node->node)); 637 const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(runner->second->endpoints[1]->node->node)); 622 x = (*runner->second->endpoints[0]->node->node) - (*runner->second->endpoints[1]->node->node); 623 y = (*runner->second->endpoints[0]->node->node) - (*runner->second->endpoints[2]->node->node); 624 const double a = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(*runner->second->endpoints[1]->node->node)); 625 const double b = sqrt(runner->second->endpoints[0]->node->node->DistanceSquared(*runner->second->endpoints[2]->node->node)); 626 const double c = sqrt(runner->second->endpoints[2]->node->node->DistanceSquared(*runner->second->endpoints[1]->node->node)); 638 627 const double G = sqrt(((a + b + c) * (a + b + c) - 2 * (a * a + b * b + c * c)) / 16.); // area of tesselated triangle 639 x.MakeNormalVector(runner->second->endpoints[0]->node->node, runner->second->endpoints[1]->node->node, runner->second->endpoints[2]->node->node); 640 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(&x)); 628 x = Plane(*(runner->second->endpoints[0]->node->node), 629 *(runner->second->endpoints[1]->node->node), 630 *(runner->second->endpoints[2]->node->node)).getNormal(); 631 x.Scale(runner->second->endpoints[1]->node->node->ScalarProduct(x)); 641 632 const double h = x.Norm(); // distance of CoG to triangle 642 633 const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak) … … 752 743 DoLog(0) && (Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl); 753 744 for (int i = 0; i < NDIM; i++) 754 BoxLengths .x[i] = GreatestDiameter[i];745 BoxLengths[i] = GreatestDiameter[i]; 755 746 mol->CenterEdge(&BoxLengths); 756 747 } else { 757 BoxLengths .x[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]);758 BoxLengths .x[1] = (repetition[0] * repetition[1] * GreatestDiameter[0] * GreatestDiameter[1] + repetition[0] * repetition[2] * GreatestDiameter[0] * GreatestDiameter[2] + repetition[1] * repetition[2] * GreatestDiameter[1] * GreatestDiameter[2]);759 BoxLengths .x[2] = minimumvolume - cellvolume;748 BoxLengths[0] = (repetition[0] * GreatestDiameter[0] + repetition[1] * GreatestDiameter[1] + repetition[2] * GreatestDiameter[2]); 749 BoxLengths[1] = (repetition[0] * repetition[1] * GreatestDiameter[0] * GreatestDiameter[1] + repetition[0] * repetition[2] * GreatestDiameter[0] * GreatestDiameter[2] + repetition[1] * repetition[2] * GreatestDiameter[1] * GreatestDiameter[2]); 750 BoxLengths[2] = minimumvolume - cellvolume; 760 751 double x0 = 0.; 761 752 double x1 = 0.; 762 753 double x2 = 0.; 763 if (gsl_poly_solve_cubic(BoxLengths .x[0], BoxLengths.x[1], BoxLengths.x[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return754 if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return 764 755 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl); 765 756 else { … … 770 761 cellvolume = 1.; 771 762 for (int i = 0; i < NDIM; i++) { 772 BoxLengths .x[i] = repetition[i] * (x0 + GreatestDiameter[i]);773 cellvolume *= BoxLengths .x[i];763 BoxLengths[i] = repetition[i] * (x0 + GreatestDiameter[i]); 764 cellvolume *= BoxLengths[i]; 774 765 } 775 766 … … 781 772 // update Box of atoms by boundary 782 773 mol->SetBoxDimension(&BoxLengths); 783 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);774 DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting cell dimensions are: " << BoxLengths[0] << " and " << BoxLengths[1] << " and " << BoxLengths[2] << " with total volume of " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl); 784 775 }; 785 776 … … 844 835 845 836 // calculate filler grid in [0,1]^3 846 FillerDistance .Init(distance[0], distance[1], distance[2]);837 FillerDistance = Vector(distance[0], distance[1], distance[2]); 847 838 FillerDistance.InverseMatrixMultiplication(M); 848 839 for(int i=0;i<NDIM;i++) 849 N[i] = (int) ceil(1./FillerDistance .x[i]);840 N[i] = (int) ceil(1./FillerDistance[i]); 850 841 DoLog(1) && (Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl); 851 842 … … 858 849 for (n[2] = 0; n[2] < N[2]; n[2]++) { 859 850 // calculate position of current grid vector in untransformed box 860 CurrentPosition .Init((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);851 CurrentPosition = Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]); 861 852 CurrentPosition.MatrixMultiplication(M); 862 853 // create molecule random translation vector ... 863 854 for (int i=0;i<NDIM;i++) 864 FillerTranslations .x[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);855 FillerTranslations[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.); 865 856 DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl); 866 857 … … 874 865 // create atomic random translation vector ... 875 866 for (int i=0;i<NDIM;i++) 876 AtomTranslations .x[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.);867 AtomTranslations[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.); 877 868 878 869 // ... and rotation matrix … … 894 885 895 886 // ... and put at new position 896 Inserter .CopyVector(&(Walker->x));887 Inserter = Walker->x; 897 888 if (DoRandomRotation) 898 889 Inserter.MatrixMultiplication(Rotations); 899 Inserter.AddVector(&AtomTranslations); 900 Inserter.AddVector(&FillerTranslations); 901 Inserter.AddVector(&CurrentPosition); 890 Inserter += AtomTranslations + FillerTranslations + CurrentPosition; 902 891 903 892 // check whether inserter is inside box … … 905 894 FillIt = true; 906 895 for (int i=0;i<NDIM;i++) 907 FillIt = FillIt && (Inserter .x[i] >= -MYEPSILON) && ((Inserter.x[i]-1.) <= MYEPSILON);896 FillIt = FillIt && (Inserter[i] >= -MYEPSILON) && ((Inserter[i]-1.) <= MYEPSILON); 908 897 Inserter.MatrixMultiplication(M); 909 898 … … 921 910 // copy atom ... 922 911 CopyAtoms[Walker->nr] = Walker->clone(); 923 CopyAtoms[Walker->nr]->x .CopyVector(&Inserter);912 CopyAtoms[Walker->nr]->x = Inserter; 924 913 Filling->AddAtom(CopyAtoms[Walker->nr]); 925 914 DoLog(4) && (Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl);
Note:
See TracChangeset
for help on using the changeset viewer.