Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    r986ed3 rbdc91e  
    1515#include "info.hpp"
    1616#include "linkedcell.hpp"
    17 #include "verbose.hpp"
    1817#include "log.hpp"
     18#include "memoryallocator.hpp"
    1919#include "molecule.hpp"
    2020#include "tesselation.hpp"
     
    2222#include "World.hpp"
    2323#include "Plane.hpp"
    24 #include "Matrix.hpp"
    25 #include "Box.hpp"
    26 
    27 #include <iostream>
    28 #include <iomanip>
    2924
    3025#include<gsl/gsl_poly.h>
     
    301296 * \param *out output stream for debugging
    302297 * \param *mol molecule structure with Atom's and Bond's.
     298 * \param *BoundaryPts set of boundary points to use or NULL
    303299 * \param *TesselStruct Tesselation filled with points, lines and triangles on boundary on return
    304300 * \param *LCList atoms in LinkedCell list
     
    306302 * \return *TesselStruct is filled with convex boundary and tesselation is stored under \a *filename.
    307303 */
    308 void FindConvexBorder(const molecule* mol, Tesselation *&TesselStruct, const LinkedCell *LCList, const char *filename)
     304void FindConvexBorder(const molecule* mol, Boundaries *BoundaryPts, Tesselation *&TesselStruct, const LinkedCell *LCList, const char *filename)
    309305{
    310306        Info FunctionInfo(__func__);
     
    317313
    318314  // 1. Find all points on the boundary
    319   if (BoundaryPoints == NULL) {
    320       BoundaryFreeFlag = true;
    321       BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
     315  if (BoundaryPts == NULL) {
     316    BoundaryFreeFlag = true;
     317    BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
    322318  } else {
    323       DoLog(0) && (Log() << Verbose(0) << "Using given boundary points set." << endl);
     319    BoundaryPoints = BoundaryPts;
     320    DoLog(0) && (Log() << Verbose(0) << "Using given boundary points set." << endl);
    324321  }
    325322
    326323// printing all inserted for debugging
    327   for (int axis=0; axis < NDIM; axis++)
    328     {
    329       DoLog(1) && (Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl);
    330       int i=0;
    331       for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
    332         if (runner != BoundaryPoints[axis].begin())
    333           DoLog(0) && (Log() << Verbose(0) << ", " << i << ": " << *runner->second.second);
    334         else
    335           DoLog(0) && (Log() << Verbose(0) << i << ": " << *runner->second.second);
    336         i++;
    337       }
    338       DoLog(0) && (Log() << Verbose(0) << endl);
    339     }
     324  for (int axis=0; axis < NDIM; axis++) {
     325    DoLog(1) && (Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl);
     326    int i=0;
     327    for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
     328      if (runner != BoundaryPoints[axis].begin())
     329        DoLog(0) && (Log() << Verbose(0) << ", " << i << ": " << *runner->second.second);
     330      else
     331        DoLog(0) && (Log() << Verbose(0) << i << ": " << *runner->second.second);
     332      i++;
     333    }
     334    DoLog(0) && (Log() << Verbose(0) << endl);
     335  }
    340336
    341337  // 2. fill the boundary point list
     
    343339    for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++)
    344340        if (!TesselStruct->AddBoundaryPoint(runner->second.second, 0))
    345           DoeLog(2) && (eLog()<< Verbose(2) << "Point " << *(runner->second.second) << " is already present!" << endl);
     341          DoLog(2) && (Log()<< Verbose(2) << "Point " << *(runner->second.second) << " is already present." << endl);
    346342
    347343  DoLog(0) && (Log() << Verbose(0) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl);
     
    677673
    678674  IsAngstroem = configuration->GetIsAngstroem();
     675  BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
    679676  GreatestDiameter = GetDiametersOfCluster(BoundaryPoints, mol, TesselStruct, IsAngstroem);
    680   BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
    681677  LinkedCell *LCList = new LinkedCell(mol, 10.);
    682   FindConvexBorder(mol, TesselStruct, (const LinkedCell *&)LCList, NULL);
     678  FindConvexBorder(mol, BoundaryPoints, TesselStruct, (const LinkedCell *&)LCList, NULL);
    683679  delete (LCList);
     680  delete[] BoundaryPoints;
    684681
    685682
     
    689686  else
    690687    clustervolume = ClusterVolume;
     688
     689  delete TesselStruct;
    691690
    692691  for (int i = 0; i < NDIM; i++)
     
    741740    mol->CenterInBox();
    742741  }
     742  delete GreatestDiameter;
    743743  // update Box of atoms by boundary
    744744  mol->SetBoxDimension(&BoxLengths);
     
    769769  int N[NDIM];
    770770  int n[NDIM];
    771   const Matrix &M = World::getInstance().getDomain().getM();
    772   Matrix Rotations;
    773   const Matrix &MInverse = World::getInstance().getDomain().getMinv();
     771  double *M =  ReturnFullMatrixforSymmetric(World::getInstance().getDomain());
     772  double Rotations[NDIM*NDIM];
     773  double *MInverse = InverseMatrix(M);
    774774  Vector AtomTranslations;
    775775  Vector FillerTranslations;
     
    804804
    805805  // calculate filler grid in [0,1]^3
    806   FillerDistance = MInverse * Vector(distance[0], distance[1], distance[2]);
     806  FillerDistance = Vector(distance[0], distance[1], distance[2]);
     807  FillerDistance.InverseMatrixMultiplication(M);
    807808  for(int i=0;i<NDIM;i++)
    808809    N[i] = (int) ceil(1./FillerDistance[i]);
     
    817818      for (n[2] = 0; n[2] < N[2]; n[2]++) {
    818819        // calculate position of current grid vector in untransformed box
    819         CurrentPosition = M * Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
     820        CurrentPosition = Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
     821        CurrentPosition.MatrixMultiplication(M);
    820822        // create molecule random translation vector ...
    821823        for (int i=0;i<NDIM;i++)
     
    838840            }
    839841
    840             Rotations.set(0,0,  cos(phi[0])            *cos(phi[2]) + (sin(phi[0])*sin(phi[1])*sin(phi[2])));
    841             Rotations.set(0,1,  sin(phi[0])            *cos(phi[2]) - (cos(phi[0])*sin(phi[1])*sin(phi[2])));
    842             Rotations.set(0,2,              cos(phi[1])*sin(phi[2])                                        );
    843             Rotations.set(1,0, -sin(phi[0])*cos(phi[1])                                                    );
    844             Rotations.set(1,1,  cos(phi[0])*cos(phi[1])                                                    );
    845             Rotations.set(1,2,              sin(phi[1])                                                    );
    846             Rotations.set(2,0, -cos(phi[0])            *sin(phi[2]) + (sin(phi[0])*sin(phi[1])*cos(phi[2])));
    847             Rotations.set(2,1, -sin(phi[0])            *sin(phi[2]) - (cos(phi[0])*sin(phi[1])*cos(phi[2])));
    848             Rotations.set(2,2,              cos(phi[1])*cos(phi[2])                                        );
     842            Rotations[0] =   cos(phi[0])            *cos(phi[2]) + (sin(phi[0])*sin(phi[1])*sin(phi[2]));
     843            Rotations[3] =   sin(phi[0])            *cos(phi[2]) - (cos(phi[0])*sin(phi[1])*sin(phi[2]));
     844            Rotations[6] =               cos(phi[1])*sin(phi[2])                                     ;
     845            Rotations[1] = - sin(phi[0])*cos(phi[1])                                                ;
     846            Rotations[4] =   cos(phi[0])*cos(phi[1])                                                ;
     847            Rotations[7] =               sin(phi[1])                                                ;
     848            Rotations[3] = - cos(phi[0])            *sin(phi[2]) + (sin(phi[0])*sin(phi[1])*cos(phi[2]));
     849            Rotations[5] = - sin(phi[0])            *sin(phi[2]) - (cos(phi[0])*sin(phi[1])*cos(phi[2]));
     850            Rotations[8] =               cos(phi[1])*cos(phi[2])                                     ;
    849851          }
    850852
     
    852854          Inserter = (*iter)->x;
    853855          if (DoRandomRotation)
    854             Inserter *= Rotations;
     856            Inserter.MatrixMultiplication(Rotations);
    855857          Inserter += AtomTranslations + FillerTranslations + CurrentPosition;
    856858
    857859          // check whether inserter is inside box
    858           Inserter *= MInverse;
     860          Inserter.MatrixMultiplication(MInverse);
    859861          FillIt = true;
    860862          for (int i=0;i<NDIM;i++)
    861863            FillIt = FillIt && (Inserter[i] >= -MYEPSILON) && ((Inserter[i]-1.) <= MYEPSILON);
    862           Inserter *= M;
     864          Inserter.MatrixMultiplication(M);
    863865
    864866          // Check whether point is in- or outside
     
    895897            }
    896898      }
     899  for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) {
     900    delete LCList[*ListRunner];
     901    delete TesselStruct[(*ListRunner)];
     902  }
     903  delete[](M);
     904  delete[](MInverse);
    897905
    898906  return Filling;
Note: See TracChangeset for help on using the changeset viewer.