Changeset 8cbb97 for src/boundary.cpp


Ignore:
Timestamp:
Apr 29, 2010, 1:55:21 PM (15 years ago)
Author:
Tillmann Crueger <crueger@…>
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.
Message:

Merge branch 'VectorRefactoring' into StructureRefactoring

Conflicts:

molecuilder/src/Legacy/oldmenu.cpp
molecuilder/src/Makefile.am
molecuilder/src/analysis_correlation.cpp
molecuilder/src/boundary.cpp
molecuilder/src/builder.cpp
molecuilder/src/config.cpp
molecuilder/src/ellipsoid.cpp
molecuilder/src/linkedcell.cpp
molecuilder/src/molecule.cpp
molecuilder/src/molecule_fragmentation.cpp
molecuilder/src/molecule_geometry.cpp
molecuilder/src/molecule_graph.cpp
molecuilder/src/moleculelist.cpp
molecuilder/src/tesselation.cpp
molecuilder/src/tesselationhelpers.cpp
molecuilder/src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
molecuilder/src/unittests/bondgraphunittest.cpp
molecuilder/src/vector.cpp
molecuilder/src/vector.hpp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    r632bc3 r8cbb97  
    1919#include "tesselationhelpers.hpp"
    2020#include "World.hpp"
     21#include "Plane.hpp"
    2122
    2223#include<gsl/gsl_poly.h>
     
    7879              if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around
    7980                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;
    8282              do { // seek for neighbour pair where it flips
    83                   OldComponent = DistanceVector.x[Othercomponent];
     83                  OldComponent = DistanceVector[Othercomponent];
    8484                  Neighbour++;
    8585                  if (Neighbour == BoundaryPoints[axis].end()) // make it wrap around
    8686                    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;
    8988                  //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl;
    9089                } while ((runner != Neighbour) && (fabs(OldComponent / fabs(
    91                   OldComponent) - DistanceVector.x[Othercomponent] / fabs(
    92                   DistanceVector.x[Othercomponent])) < MYEPSILON)); // as long as sign does not flip
     90                  OldComponent) - DistanceVector[Othercomponent] / fabs(
     91                  DistanceVector[Othercomponent])) < MYEPSILON)); // as long as sign does not flip
    9392              if (runner != Neighbour) {
    9493                  OtherNeighbour = Neighbour;
     
    9897                  //Log() << Verbose(1) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl;
    9998                  // 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;
    102100                  //Log() << Verbose(1) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl;
    103101                  //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl;
    104102                  // 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] + w2
    108                       * 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));
    109107                  // mark if it has greater diameter
    110108                  //Log() << Verbose(1) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl;
     
    160158    AngleReferenceVector.Zero();
    161159    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.;
    165163
    166164    DoLog(1) && (Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl);
     
    170168    while (Walker->next != mol->end) {
    171169      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);
    175172
    176173      // correct for negative side
    177174      const double radius = ProjectedVector.NormSquared();
    178175      if (fabs(radius) > MYEPSILON)
    179         angle = ProjectedVector.Angle(&AngleReferenceVector);
     176        angle = ProjectedVector.Angle(AngleReferenceVector);
    180177      else
    181178        angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues
    182179
    183180      //Log() << Verbose(1) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
    184       if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) {
     181      if (ProjectedVector.ScalarProduct(AngleReferenceNormalVector) > 0) {
    185182        angle = 2. * M_PI - angle;
    186183      }
     
    197194          DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
    198195        } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) {
    199           helper.CopyVector(&Walker->x);
    200           helper.SubtractVector(MolCenter);
     196          helper = Walker->x - (*MolCenter);
    201197          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);
    204199          if (helper.NormSquared() < oldhelperNorm) {
    205200            BoundaryTestPair.first->second.second = Walker;
     
    251246        {
    252247          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);
    256250          //          Log() << Verbose(1) << "SideA: " << SideA << endl;
    257251
    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);
    261254          //          Log() << Verbose(1) << "SideB: " << SideB << endl;
    262255
    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);
    266258          //          Log() << Verbose(1) << "SideC: " << SideC << endl;
    267259
    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);
    271262          //          Log() << Verbose(1) << "SideH: " << SideH << endl;
    272263
     
    277268          const double h = SideH.Norm();
    278269          // 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);
    283274          const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.);
    284275          //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;
     
    629620  for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++)
    630621    { // 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));
    638627      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));
    641632      const double h = x.Norm(); // distance of CoG to triangle
    642633      const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
     
    752743    DoLog(0) && (Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl);
    753744    for (int i = 0; i < NDIM; i++)
    754       BoxLengths.x[i] = GreatestDiameter[i];
     745      BoxLengths[i] = GreatestDiameter[i];
    755746    mol->CenterEdge(&BoxLengths);
    756747  } 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;
    760751    double x0 = 0.;
    761752    double x1 = 0.;
    762753    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 return
     754    if (gsl_poly_solve_cubic(BoxLengths[0], BoxLengths[1], BoxLengths[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return
    764755      DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl);
    765756    else {
     
    770761    cellvolume = 1.;
    771762    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];
    774765    }
    775766
     
    781772  // update Box of atoms by boundary
    782773  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);
    784775};
    785776
     
    844835
    845836  // 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]);
    847838  FillerDistance.InverseMatrixMultiplication(M);
    848839  for(int i=0;i<NDIM;i++)
    849     N[i] = (int) ceil(1./FillerDistance.x[i]);
     840    N[i] = (int) ceil(1./FillerDistance[i]);
    850841  DoLog(1) && (Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl);
    851842
     
    858849      for (n[2] = 0; n[2] < N[2]; n[2]++) {
    859850        // 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]);
    861852        CurrentPosition.MatrixMultiplication(M);
    862853        // create molecule random translation vector ...
    863854        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.);
    865856        DoLog(2) && (Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "+" << FillerTranslations << "." << endl);
    866857
     
    874865          // create atomic random translation vector ...
    875866          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.);
    877868
    878869          // ... and rotation matrix
     
    894885
    895886          // ... and put at new position
    896           Inserter.CopyVector(&(Walker->x));
     887          Inserter = Walker->x;
    897888          if (DoRandomRotation)
    898889            Inserter.MatrixMultiplication(Rotations);
    899           Inserter.AddVector(&AtomTranslations);
    900           Inserter.AddVector(&FillerTranslations);
    901           Inserter.AddVector(&CurrentPosition);
     890          Inserter += AtomTranslations + FillerTranslations + CurrentPosition;
    902891
    903892          // check whether inserter is inside box
     
    905894          FillIt = true;
    906895          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);
    908897          Inserter.MatrixMultiplication(M);
    909898
     
    921910            // copy atom ...
    922911            CopyAtoms[Walker->nr] = Walker->clone();
    923             CopyAtoms[Walker->nr]->x.CopyVector(&Inserter);
     912            CopyAtoms[Walker->nr]->x = Inserter;
    924913            Filling->AddAtom(CopyAtoms[Walker->nr]);
    925914            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.