Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/boundary.cpp

    r112b09 r8f215d  
    33 * Implementations and super-function for envelopes
    44 */
    5 
    6 #include "Helpers/MemDebug.hpp"
    75
    86#include "World.hpp"
     
    141139{
    142140        Info FunctionInfo(__func__);
     141  atom *Walker = NULL;
    143142  PointMap PointsOnBoundary;
    144143  LineMap LinesOnBoundary;
     
    166165
    167166    // 3b. construct set of all points, transformed into cylindrical system and with left and right neighbours
    168     for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    169       ProjectedVector = (*iter)->x - (*MolCenter);
     167    Walker = mol->start;
     168    while (Walker->next != mol->end) {
     169      Walker = Walker->next;
     170      ProjectedVector = Walker->x - (*MolCenter);
    170171      ProjectedVector.ProjectOntoPlane(AxisVector);
    171172
     
    181182        angle = 2. * M_PI - angle;
    182183      }
    183     DoLog(1) && (Log() << Verbose(1) << "Inserting " << **iter << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);
    184       BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, (*iter))));
     184      DoLog(1) && (Log() << Verbose(1) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);
     185      BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, Walker)));
    185186      if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity
    186187        DoLog(2) && (Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl);
    187188        DoLog(2) && (Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl);
    188         DoLog(2) && (Log() << Verbose(2) << "New vector: " << **iter << endl);
     189        DoLog(2) && (Log() << Verbose(2) << "New vector: " << *Walker << endl);
    189190        const double ProjectedVectorNorm = ProjectedVector.NormSquared();
    190191        if ((ProjectedVectorNorm - BoundaryTestPair.first->second.first) > MYEPSILON) {
    191192          BoundaryTestPair.first->second.first = ProjectedVectorNorm;
    192           BoundaryTestPair.first->second.second = (*iter);
     193          BoundaryTestPair.first->second.second = Walker;
    193194          DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
    194195        } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) {
    195           helper = (*iter)->x;
    196           helper -= *MolCenter;
     196          helper = Walker->x - (*MolCenter);
    197197          const double oldhelperNorm = helper.NormSquared();
    198198          helper = BoundaryTestPair.first->second.second->x - (*MolCenter);
    199199          if (helper.NormSquared() < oldhelperNorm) {
    200             BoundaryTestPair.first->second.second = (*iter);
     200            BoundaryTestPair.first->second.second = Walker;
    201201            DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl);
    202202          } else {
     
    226226    do { // do as long as we still throw one out per round
    227227      flag = false;
    228       Boundaries::iterator left = BoundaryPoints[axis].begin();
    229       Boundaries::iterator right = BoundaryPoints[axis].begin();
    230       Boundaries::iterator runner = BoundaryPoints[axis].begin();
    231       bool LoopOnceDone = false;
    232       while (!LoopOnceDone) {
    233         runner = right;
    234         right++;
     228      Boundaries::iterator left = BoundaryPoints[axis].end();
     229      Boundaries::iterator right = BoundaryPoints[axis].end();
     230      for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
    235231        // set neighbours correctly
    236232        if (runner == BoundaryPoints[axis].begin()) {
     
    240236        }
    241237        left--;
     238        right = runner;
     239        right++;
    242240        if (right == BoundaryPoints[axis].end()) {
    243241          right = BoundaryPoints[axis].begin();
    244           LoopOnceDone = true;
    245242        }
    246243        // check distance
     
    282279            DoLog(1) && (Log() << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl);
    283280            BoundaryPoints[axis].erase(runner);
    284             runner = right;
    285281            flag = true;
    286282          }
     
    363359
    364360  // 4. Store triangles in tecplot file
    365   StoreTrianglesinFile(mol, TesselStruct, filename, "_intermed");
     361  if (filename != NULL) {
     362    if (DoTecplotOutput) {
     363      string OutputName(filename);
     364      OutputName.append("_intermed");
     365      OutputName.append(TecplotSuffix);
     366      ofstream *tecplot = new ofstream(OutputName.c_str());
     367      WriteTecplotFile(tecplot, TesselStruct, mol, 0);
     368      tecplot->close();
     369      delete(tecplot);
     370    }
     371    if (DoRaster3DOutput) {
     372      string OutputName(filename);
     373      OutputName.append("_intermed");
     374      OutputName.append(Raster3DSuffix);
     375      ofstream *rasterplot = new ofstream(OutputName.c_str());
     376      WriteRaster3dFile(rasterplot, TesselStruct, mol);
     377      rasterplot->close();
     378      delete(rasterplot);
     379    }
     380  }
    366381
    367382  // 3d. check all baselines whether the peaks of the two adjacent triangles with respect to center of baseline are convex, if not, make the baseline between the two peaks and baseline endpoints become the new peaks
     
    382397          TesselStruct->FlipBaseline(line);
    383398          DoLog(1) && (Log() << Verbose(1) << "INFO: Correction of concave baselines worked." << endl);
    384           LineRunner = TesselStruct->LinesOnBoundary.begin(); // LineRunner may have been erase if line was deleted from LinesOnBoundary
    385399        }
    386400      }
     
    395409
    396410  // 4. Store triangles in tecplot file
    397   StoreTrianglesinFile(mol, TesselStruct, filename, "");
     411  if (filename != NULL) {
     412    if (DoTecplotOutput) {
     413      string OutputName(filename);
     414      OutputName.append(TecplotSuffix);
     415      ofstream *tecplot = new ofstream(OutputName.c_str());
     416      WriteTecplotFile(tecplot, TesselStruct, mol, 0);
     417      tecplot->close();
     418      delete(tecplot);
     419    }
     420    if (DoRaster3DOutput) {
     421      string OutputName(filename);
     422      OutputName.append(Raster3DSuffix);
     423      ofstream *rasterplot = new ofstream(OutputName.c_str());
     424      WriteRaster3dFile(rasterplot, TesselStruct, mol);
     425      rasterplot->close();
     426      delete(rasterplot);
     427    }
     428  }
     429
    398430
    399431  // free reference lists
     
    646678/** Creates multiples of the by \a *mol given cluster and suspends them in water with a given final density.
    647679 * We get cluster volume by VolumeOfConvexEnvelope() and its diameters by GetDiametersOfCluster()
    648  * TODO: Here, we need a VolumeOfGeneralEnvelope (i.e. non-convex one)
    649680 * \param *out output stream for debugging
    650681 * \param *configuration needed for path to store convex envelope file
     
    664695  int repetition[NDIM] = { 1, 1, 1 };
    665696  int TotalNoClusters = 1;
     697  atom *Walker = NULL;
    666698  double totalmass = 0.;
    667699  double clustervolume = 0.;
     
    674706  GreatestDiameter = GetDiametersOfCluster(BoundaryPoints, mol, TesselStruct, IsAngstroem);
    675707  BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
    676   LinkedCell *LCList = new LinkedCell(mol, 10.);
    677   FindConvexBorder(mol, TesselStruct, (const LinkedCell *&)LCList, NULL);
    678   delete (LCList);
    679 
     708  LinkedCell LCList(mol, 10.);
     709  FindConvexBorder(mol, TesselStruct, &LCList, NULL);
    680710
    681711  // some preparations beforehand
     
    689719
    690720  // sum up the atomic masses
    691   for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
    692       totalmass += (*iter)->type->mass;
     721  Walker = mol->start;
     722  while (Walker->next != mol->end) {
     723      Walker = Walker->next;
     724      totalmass += Walker->type->mass;
    693725  }
    694726  DoLog(0) && (Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl);
     
    772804  Vector Inserter;
    773805  double FillIt = false;
     806  atom *Walker = NULL;
    774807  bond *Binder = NULL;
    775808  double phi[NDIM];
     
    778811
    779812  for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++)
    780     if ((*ListRunner)->getAtomCount() > 0) {
     813    if ((*ListRunner)->AtomCount > 0) {
    781814      DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl);
    782815      LCList[(*ListRunner)] = new LinkedCell((*ListRunner), 10.); // get linked cell list
     
    789822  filler->CenterEdge(&Inserter);
    790823  filler->Center.Zero();
    791   const int FillerCount = filler->getAtomCount();
    792824  DoLog(2) && (Log() << Verbose(2) << "INFO: Filler molecule has the following bonds:" << endl);
    793   for(molecule::iterator AtomRunner = filler->begin(); AtomRunner != filler->end(); ++AtomRunner)
    794     for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
    795       if ((*BondRunner)->leftatom == *AtomRunner)
    796         DoLog(2) && (Log() << Verbose(2) << "  " << *(*BondRunner) << endl);
    797 
    798   atom * CopyAtoms[FillerCount];
     825  Binder = filler->first;
     826  while(Binder->next != filler->last) {
     827    Binder = Binder->next;
     828    DoLog(2) && (Log() << Verbose(2) << "  " << *Binder << endl);
     829  }
     830
     831  filler->CountAtoms();
     832  atom * CopyAtoms[filler->AtomCount];
    799833
    800834  // calculate filler grid in [0,1]^3
     
    821855
    822856        // go through all atoms
    823         for (int i=0;i<FillerCount;i++)
     857        for (int i=0;i<filler->AtomCount;i++)
    824858          CopyAtoms[i] = NULL;
    825         for(molecule::const_iterator iter = filler->begin(); iter !=filler->end();++iter){
     859        Walker = filler->start;
     860        while (Walker->next != filler->end) {
     861          Walker = Walker->next;
    826862
    827863          // create atomic random translation vector ...
     
    847883
    848884          // ... and put at new position
    849           Inserter = (*iter)->x;
     885          Inserter = Walker->x;
    850886          if (DoRandomRotation)
    851887            Inserter.MatrixMultiplication(Rotations);
     
    871907            DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is outer point." << endl);
    872908            // copy atom ...
    873             CopyAtoms[(*iter)->nr] = (*iter)->clone();
    874             CopyAtoms[(*iter)->nr]->x = Inserter;
    875             Filling->AddAtom(CopyAtoms[(*iter)->nr]);
    876             DoLog(4) && (Log() << Verbose(4) << "Filling atom " << **iter << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[(*iter)->nr]->x) << "." << endl);
     909            CopyAtoms[Walker->nr] = Walker->clone();
     910            CopyAtoms[Walker->nr]->x = Inserter;
     911            Filling->AddAtom(CopyAtoms[Walker->nr]);
     912            DoLog(4) && (Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl);
    877913          } else {
    878914            DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is inner point, within boundary or outside of MaxDistance." << endl);
    879             CopyAtoms[(*iter)->nr] = NULL;
     915            CopyAtoms[Walker->nr] = NULL;
    880916            continue;
    881917          }
    882918        }
    883919        // go through all bonds and add as well
    884         for(molecule::iterator AtomRunner = filler->begin(); AtomRunner != filler->end(); ++AtomRunner)
    885           for(BondList::iterator BondRunner = (*AtomRunner)->ListOfBonds.begin(); BondRunner != (*AtomRunner)->ListOfBonds.end(); ++BondRunner)
    886             if ((*BondRunner)->leftatom == *AtomRunner) {
    887               Binder = (*BondRunner);
    888               if ((CopyAtoms[Binder->leftatom->nr] != NULL) && (CopyAtoms[Binder->rightatom->nr] != NULL)) {
    889                 Log()  << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl;
    890                 Filling->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
    891               }
    892             }
     920        Binder = filler->first;
     921        while(Binder->next != filler->last) {
     922          Binder = Binder->next;
     923          if ((CopyAtoms[Binder->leftatom->nr] != NULL) && (CopyAtoms[Binder->rightatom->nr] != NULL)) {
     924            Log()  << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl;
     925            Filling->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
     926          }
     927        }
    893928      }
    894   delete[](M);
    895   delete[](MInverse);
     929  Free(&M);
     930  Free(&MInverse);
    896931
    897932  return Filling;
     
    917952  bool TesselationFailFlag = false;
    918953
    919   mol->getAtomCount();
    920 
    921954  if (TesselStruct == NULL) {
    922955    DoLog(1) && (Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl);
     
    9901023//  // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles
    9911024//  //->InsertStraddlingPoints(mol, LCList);
    992 //  for (molecule::const_iterator iter = mol->begin(); iter != mol->end(); ++iter) {
     1025//  mol->GoToFirst();
    9931026//  class TesselPoint *Runner = NULL;
    994 //    Runner = *iter;
     1027//  while (!mol->IsEnd()) {
     1028//    Runner = mol->GetPoint();
    9951029//    Log() << Verbose(1) << "Checking on " << Runner->Name << " ... " << endl;
    9961030//    if (!->IsInnerPoint(Runner, LCList)) {
     
    10001034//      Log() << Verbose(2) << Runner->Name << " is inside of or on envelope." << endl;
    10011035//    }
     1036//    mol->GoToNext();
    10021037//  }
    10031038
     
    10081043  status = CheckListOfBaselines(TesselStruct);
    10091044
    1010   cout << "before correction" << endl;
    1011 
    10121045  // store before correction
    1013   StoreTrianglesinFile(mol, TesselStruct, filename, "");
     1046  StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
    10141047
    10151048//  // correct degenerated polygons
     
    10211054  // write final envelope
    10221055  CalculateConcavityPerBoundaryPoint(TesselStruct);
    1023   cout << "after correction" << endl;
    1024   StoreTrianglesinFile(mol, TesselStruct, filename, "");
     1056  StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
    10251057
    10261058  if (freeLC)
Note: See TracChangeset for help on using the changeset viewer.