Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/boundary.cpp

    rd6eb80 r58ed4a  
    1717#include "tesselation.hpp"
    1818#include "tesselationhelpers.hpp"
     19#include "World.hpp"
    1920
    2021#include<gsl/gsl_poly.h>
     
    341342    for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++)
    342343        if (!TesselStruct->AddBoundaryPoint(runner->second.second, 0))
    343           eLog() << Verbose(2) << "Point " << *(runner->second.second) << " is already present!" << endl;
     344          DoeLog(2) && (eLog()<< Verbose(2) << "Point " << *(runner->second.second) << " is already present!" << endl);
    344345
    345346  Log() << Verbose(0) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl;
     
    361362  // 3c. check whether all atoms lay inside the boundary, if not, add to boundary points, segment triangle into three with the new point
    362363  if (!TesselStruct->InsertStraddlingPoints(mol, LCList))
    363     eLog() << Verbose(1) << "Insertion of straddling points failed!" << endl;
     364    DoeLog(1) && (eLog()<< Verbose(1) << "Insertion of straddling points failed!" << endl);
    364365
    365366  Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " intermediate triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl;
     
    400401        // flip the line
    401402        if (TesselStruct->PickFarthestofTwoBaselines(line) == 0.)
    402           eLog() << Verbose(1) << "Correction of concave baselines failed!" << endl;
     403          DoeLog(1) && (eLog()<< Verbose(1) << "Correction of concave baselines failed!" << endl);
    403404        else {
    404405          TesselStruct->FlipBaseline(line);
     
    455456
    456457  if ((TesselStruct == NULL) || (TesselStruct->PointsOnBoundary.empty())) {
    457     eLog() << Verbose(1) << "TesselStruct is empty." << endl;
     458    DoeLog(1) && (eLog()<< Verbose(1) << "TesselStruct is empty." << endl);
    458459    return false;
    459460  }
     
    520521  // check whether there is something to work on
    521522  if (TesselStruct == NULL) {
    522     eLog() << Verbose(1) << "TesselStruct is empty!" << endl;
     523    DoeLog(1) && (eLog()<< Verbose(1) << "TesselStruct is empty!" << endl);
    523524    return volume;
    524525  }
     
    747748  Log() << Verbose(1) << "Minimum volume of the convex envelope contained in a rectangular box is " << minimumvolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
    748749  if (minimumvolume > cellvolume) {
    749     eLog() << Verbose(1) << "the containing box already has a greater volume than the envisaged cell volume!" << endl;
     750    DoeLog(1) && (eLog()<< Verbose(1) << "the containing box already has a greater volume than the envisaged cell volume!" << endl);
    750751    Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl;
    751752    for (int i = 0; i < NDIM; i++)
     
    789790 * \param *filler molecule which the box is to be filled with
    790791 * \param configuration contains box dimensions
     792 * \param MaxDistance fills in molecules only up to this distance (set to -1 if whole of the domain)
    791793 * \param distance[NDIM] distance between filling molecules in each direction
    792794 * \param boundary length of boundary zone between molecule and filling mollecules
     
    797799 * \return *mol pointer to new molecule with filled atoms
    798800 */
    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)
     801molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, const double MaxDistance, const double distance[NDIM], const double boundary, const double RandomAtomDisplacement, const double RandomMolDisplacement, const bool DoRandomRotation)
    800802{
    801803        Info FunctionInfo(__func__);
     
    804806  int N[NDIM];
    805807  int n[NDIM];
    806   double *M =  ReturnFullMatrixforSymmetric(filler->cell_size);
     808  double *M =  ReturnFullMatrixforSymmetric(World::get()->cell_size);
    807809  double Rotations[NDIM*NDIM];
     810  double *MInverse = InverseMatrix(M);
    808811  Vector AtomTranslations;
    809812  Vector FillerTranslations;
    810813  Vector FillerDistance;
     814  Vector Inserter;
    811815  double FillIt = false;
    812816  atom *Walker = NULL;
    813817  bond *Binder = NULL;
    814   int i = 0;
    815   LinkedCell *LCList[List->ListOfMolecules.size()];
    816818  double phi[NDIM];
    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   }
     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      Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl;
     825      LCList[(*ListRunner)] = new LinkedCell((*ListRunner), 10.); // get linked cell list
     826      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    }
    828830
    829831  // Center filler at origin
    830   filler->CenterOrigin();
     832  filler->CenterEdge(&Inserter);
    831833  filler->Center.Zero();
     834  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    Log() << Verbose(2) << "  " << *Binder << endl;
     839  }
    832840
    833841  filler->CountAtoms();
     
    851859        CurrentPosition.Init((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
    852860        CurrentPosition.MatrixMultiplication(M);
    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;
     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        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 ...
     874          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            Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl;
     920            // copy atom ...
     921            CopyAtoms[Walker->nr] = new atom(Walker);
     922            CopyAtoms[Walker->nr]->x.CopyVector(&Inserter);
     923            Filling->AddAtom(CopyAtoms[Walker->nr]);
     924            Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl;
    862925          } 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++;
     926            Log() << Verbose(1) << "INFO: Position at " << Inserter << " is inner point, within boundary or outside of MaxDistance." << endl;
     927            CopyAtoms[Walker->nr] = NULL;
     928            continue;
    872929          }
    873930        }
    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 ...
    880           for (int i=0;i<NDIM;i++)
    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;
    888             // copy atom ...
    889             CopyAtoms[Walker->nr] = new atom(Walker);
    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             Filling->AddAtom(CopyAtoms[Walker->nr]);
    924           }
    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;
     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;
    931937            Filling->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
    932938          }
    933         } else {
    934           // leave empty
    935           Log() << Verbose(2) << "Space at " << CurrentPosition << " is occupied." << endl;
    936939        }
    937940      }
    938941  Free(&M);
    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   }
     942  Free(&MInverse);
     943
    948944  return Filling;
    949945};
Note: See TracChangeset for help on using the changeset viewer.