Changes in / [e5ad5c:ee7e25]


Ignore:
Files:
94 added
75 edited

Legend:

Unmodified
Added
Removed
  • configure.ac

    re5ad5c ree7e25  
    8787AC_CONFIG_TESTDIR(tests)
    8888AC_CONFIG_FILES([tests/atlocal tests/Makefile])
     89AC_CONFIG_FILES([tests/Tesselations/Makefile tests/Tesselations/defs])
    8990AC_CONFIG_FILES([tests/molecuilder], [chmod +x tests/molecuilder])
    9091AC_CONFIG_FILES([doc/molecuilder.xml])
  • src/Makefile.am

    re5ad5c ree7e25  
    22ATOMHEADER = atom.hpp atom_atominfo.hpp atom_bondedparticle.hpp atom_bondedparticleinfo.hpp atom_graphnode.hpp atom_graphnodeinfo.hpp atom_particleinfo.hpp atom_trajectoryparticle.hpp atom_trajectoryparticleinfo.hpp
    33
    4 SOURCE = analysis_correlation.cpp ${ATOMSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp vector.cpp verbose.cpp
    5 HEADER = analysis_correlation.hpp ${ATOMHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp vector.hpp verbose.hpp
     4LINALGSOURCE = gslmatrix.cpp gslvector.cpp linearsystemofequations.cpp
     5LINALGHEADER = gslmatrix.hpp gslvector.hpp linearsystemofequations.hpp
     6
     7ANALYSISSOURCE = analysis_bonds.cpp analysis_correlation.cpp
     8ANALYSISHEADER = analysis_bonds.hpp analysis_correlation.hpp
     9
     10SOURCE = ${ANALYSISSOURCE} ${ATOMSOURCE} bond.cpp bondgraph.cpp boundary.cpp config.cpp element.cpp ellipsoid.cpp errorlogger.cpp graph.cpp helpers.cpp info.cpp leastsquaremin.cpp linkedcell.cpp log.cpp logger.cpp memoryusageobserver.cpp moleculelist.cpp molecule.cpp molecule_dynamics.cpp molecule_fragmentation.cpp molecule_geometry.cpp molecule_graph.cpp molecule_pointcloud.cpp parser.cpp periodentafel.cpp tesselation.cpp tesselationhelpers.cpp triangleintersectionlist.cpp vector.cpp verbose.cpp World.cpp
     11HEADER = ${ANALYSISHEADER} ${ATOMHEADER} bond.hpp bondgraph.hpp boundary.hpp config.hpp defs.hpp element.hpp ellipsoid.hpp errorlogger.hpp graph.hpp helpers.hpp info.hpp leastsquaremin.hpp linkedcell.hpp lists.hpp log.hpp logger.hpp memoryallocator.hpp memoryusageobserver.hpp molecule.hpp molecule_template.hpp parser.hpp periodentafel.hpp stackclass.hpp tesselation.hpp tesselationhelpers.hpp triangleintersectionlist.cpp vector.hpp verbose.hpp World.hpp
    612
    713BOOST_LIB = $(BOOST_LDFLAGS) $(BOOST_MPL_LIB)
    814INCLUDES = -I$(top_srcdir)/src/unittests
    915
    10 noinst_LIBRARIES = libmolecuilder.a
     16noinst_LIBRARIES = libmolecuilder.a libgslwrapper.a
    1117bin_PROGRAMS = molecuilder joiner analyzer
    1218molecuilderdir = ${bindir}
    1319libmolecuilder_a_SOURCES = ${SOURCE} ${HEADER}
     20libgslwrapper_a_SOURCES = ${LINALGSOURCE} ${LINALGHEADER}
    1421molecuilder_DATA = elements.db valence.db orbitals.db Hbonddistance.db Hbondangle.db
    1522molecuilder_LDFLAGS = $(BOOST_LIB)
    1623molecuilder_SOURCES = builder.cpp
    17 molecuilder_LDADD = libmolecuilder.a
     24molecuilder_LDADD = libmolecuilder.a libgslwrapper.a
    1825joiner_SOURCES = joiner.cpp datacreator.cpp parser.cpp datacreator.hpp helpers.hpp parser.hpp periodentafel.hpp
    1926joiner_LDADD = libmolecuilder.a
     
    2229
    2330#EXTRA_DIST = ${molecuilder_DATA}
     31
     32FORCE:
     33$(srcdir)/.git-version: FORCE
     34        @if (test -d $(top_srcdir)/../.git && cd $(srcdir) && git describe HEAD) > .git-version-t 2>/dev/null \
     35          && ! diff .git-version-t $(srcdir)/.git-version >/dev/null 2>&1; then \
     36          mv -f .git-version-t $(srcdir)/.git-version; \
     37        else \
     38          rm -f .git-version-t; \
     39        fi
     40
     41EXTRA_DIST = $(srcdir)/.git-version
     42
     43$(srcdir)/version.c: $(srcdir)/.git-version
     44        echo "const char *ESPACKVersion = \"$(PACKAGE_NAME) -- git version: "`cat $(srcdir)/.git-version`"\";" > $@
     45
     46molecuilder_SOURCES += $(srcdir)/version.c
  • src/analysis_correlation.cpp

    re5ad5c ree7e25  
    1010#include "analysis_correlation.hpp"
    1111#include "element.hpp"
     12#include "info.hpp"
    1213#include "log.hpp"
    1314#include "molecule.hpp"
    1415#include "tesselation.hpp"
    1516#include "tesselationhelpers.hpp"
     17#include "triangleintersectionlist.hpp"
    1618#include "vector.hpp"
    1719#include "verbose.hpp"
     20#include "World.hpp"
    1821
    1922
     
    2831PairCorrelationMap *PairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2 )
    2932{
     33  Info FunctionInfo(__func__);
    3034  PairCorrelationMap *outmap = NULL;
    3135  double distance = 0.;
    3236
    3337  if (molecules->ListOfMolecules.empty()) {
    34     eLog() << Verbose(1) <<"No molecule given." << endl;
     38    DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
    3539    return outmap;
    3640  }
     
    3842  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    3943    if ((*MolWalker)->ActiveFlag) {
    40       eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    41       atom *Walker = (*MolWalker)->start;
    42       while (Walker->next != (*MolWalker)->end) {
    43         Walker = Walker->next;
    44         Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     44      DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
     45      atom *Walker = (*MolWalker)->start;
     46      while (Walker->next != (*MolWalker)->end) {
     47        Walker = Walker->next;
     48        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    4549        if ((type1 == NULL) || (Walker->type == type1)) {
    4650          for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
    4751            if ((*MolOtherWalker)->ActiveFlag) {
    48               Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;
     52              DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
    4953              atom *OtherWalker = (*MolOtherWalker)->start;
    5054              while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
    5155                OtherWalker = OtherWalker->next;
    52                 Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
     56                DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
    5357                if (Walker->nr < OtherWalker->nr)
    5458                  if ((type2 == NULL) || (OtherWalker->type == type2)) {
    55                     distance = Walker->node->PeriodicDistance(OtherWalker->node, (*MolWalker)->cell_size);
     59                    distance = Walker->node->PeriodicDistance(OtherWalker->node, World::get()->cell_size);
    5660                    //Log() << Verbose(1) <<"Inserting " << *Walker << " and " << *OtherWalker << endl;
    5761                    outmap->insert ( pair<double, pair <atom *, atom*> > (distance, pair<atom *, atom*> (Walker, OtherWalker) ) );
     
    7781PairCorrelationMap *PeriodicPairCorrelation(MoleculeListClass * const &molecules, const element * const type1, const element * const type2, const int ranges[NDIM] )
    7882{
     83  Info FunctionInfo(__func__);
    7984  PairCorrelationMap *outmap = NULL;
    8085  double distance = 0.;
     
    8792
    8893  if (molecules->ListOfMolecules.empty()) {
    89     eLog() << Verbose(1) <<"No molecule given." << endl;
     94    DoeLog(1) && (eLog()<< Verbose(1) <<"No molecule given." << endl);
    9095    return outmap;
    9196  }
     
    9398  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    9499    if ((*MolWalker)->ActiveFlag) {
    95       const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
    96       const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
    97       eLog() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    98       atom *Walker = (*MolWalker)->start;
    99       while (Walker->next != (*MolWalker)->end) {
    100         Walker = Walker->next;
    101         Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     100      double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     101      double * FullInverseMatrix = InverseMatrix(FullMatrix);
     102      DoeLog(2) && (eLog()<< Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
     103      atom *Walker = (*MolWalker)->start;
     104      while (Walker->next != (*MolWalker)->end) {
     105        Walker = Walker->next;
     106        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    102107        if ((type1 == NULL) || (Walker->type == type1)) {
    103108          periodicX.CopyVector(Walker->node);
     
    112117                for (MoleculeList::const_iterator MolOtherWalker = MolWalker; MolOtherWalker != molecules->ListOfMolecules.end(); MolOtherWalker++)
    113118                  if ((*MolOtherWalker)->ActiveFlag) {
    114                     Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl;
     119                    DoLog(2) && (Log() << Verbose(2) << "Current other molecule is " << *MolOtherWalker << "." << endl);
    115120                    atom *OtherWalker = (*MolOtherWalker)->start;
    116121                    while (OtherWalker->next != (*MolOtherWalker)->end) { // only go up to Walker
    117122                      OtherWalker = OtherWalker->next;
    118                       Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl;
     123                      DoLog(3) && (Log() << Verbose(3) << "Current otheratom is " << *OtherWalker << "." << endl);
    119124                      if (Walker->nr < OtherWalker->nr)
    120125                        if ((type2 == NULL) || (OtherWalker->type == type2)) {
     
    138143        }
    139144      }
     145      Free(&FullMatrix);
     146      Free(&FullInverseMatrix);
    140147    }
    141148
     
    152159CorrelationToPointMap *CorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point )
    153160{
     161  Info FunctionInfo(__func__);
    154162  CorrelationToPointMap *outmap = NULL;
    155163  double distance = 0.;
    156164
    157165  if (molecules->ListOfMolecules.empty()) {
    158     Log() << Verbose(1) <<"No molecule given." << endl;
     166    DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
    159167    return outmap;
    160168  }
     
    162170  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    163171    if ((*MolWalker)->ActiveFlag) {
    164       Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    165       atom *Walker = (*MolWalker)->start;
    166       while (Walker->next != (*MolWalker)->end) {
    167         Walker = Walker->next;
    168         Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     172      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
     173      atom *Walker = (*MolWalker)->start;
     174      while (Walker->next != (*MolWalker)->end) {
     175        Walker = Walker->next;
     176        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    169177        if ((type == NULL) || (Walker->type == type)) {
    170           distance = Walker->node->PeriodicDistance(point, (*MolWalker)->cell_size);
    171           Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
     178          distance = Walker->node->PeriodicDistance(point, World::get()->cell_size);
     179          DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    172180          outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
    173181        }
     
    188196CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] )
    189197{
     198  Info FunctionInfo(__func__);
    190199  CorrelationToPointMap *outmap = NULL;
    191200  double distance = 0.;
     
    195204
    196205  if (molecules->ListOfMolecules.empty()) {
    197     Log() << Verbose(1) <<"No molecule given." << endl;
     206    DoLog(1) && (Log() << Verbose(1) <<"No molecule given." << endl);
    198207    return outmap;
    199208  }
     
    201210  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    202211    if ((*MolWalker)->ActiveFlag) {
    203       const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
    204       const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
    205       Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    206       atom *Walker = (*MolWalker)->start;
    207       while (Walker->next != (*MolWalker)->end) {
    208         Walker = Walker->next;
    209         Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     212      double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     213      double * FullInverseMatrix = InverseMatrix(FullMatrix);
     214      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
     215      atom *Walker = (*MolWalker)->start;
     216      while (Walker->next != (*MolWalker)->end) {
     217        Walker = Walker->next;
     218        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    210219        if ((type == NULL) || (Walker->type == type)) {
    211220          periodicX.CopyVector(Walker->node);
     
    219228                checkX.MatrixMultiplication(FullMatrix);
    220229                distance = checkX.Distance(point);
    221                 Log() << Verbose(4) << "Current distance is " << distance << "." << endl;
     230                DoLog(4) && (Log() << Verbose(4) << "Current distance is " << distance << "." << endl);
    222231                outmap->insert ( pair<double, pair<atom *, const Vector*> >(distance, pair<atom *, const Vector*> (Walker, point) ) );
    223232              }
    224233        }
    225234      }
     235      Free(&FullMatrix);
     236      Free(&FullInverseMatrix);
    226237    }
    227238
     
    239250CorrelationToSurfaceMap *CorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC )
    240251{
     252  Info FunctionInfo(__func__);
    241253  CorrelationToSurfaceMap *outmap = NULL;
    242254  double distance = 0;
     
    245257
    246258  if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
    247     Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
     259    DoeLog(1) && (eLog()<< Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
    248260    return outmap;
    249261  }
     
    251263  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    252264    if ((*MolWalker)->ActiveFlag) {
    253       Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    254       atom *Walker = (*MolWalker)->start;
    255       while (Walker->next != (*MolWalker)->end) {
    256         Walker = Walker->next;
    257         Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     265      DoLog(1) && (Log() << Verbose(1) << "Current molecule is " << (*MolWalker)->name << "." << endl);
     266      atom *Walker = (*MolWalker)->start;
     267      while (Walker->next != (*MolWalker)->end) {
     268        Walker = Walker->next;
     269        //Log() << Verbose(1) << "Current atom is " << *Walker << "." << endl;
    258270        if ((type == NULL) || (Walker->type == type)) {
    259           triangle = Surface->FindClosestTriangleToPoint(Walker->node, LC );
    260           if (triangle != NULL) {
    261             distance = DistanceToTrianglePlane(Walker->node, triangle);
    262             outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
    263           }
    264         }
    265       }
    266     }
     271          TriangleIntersectionList Intersections(Walker->node,Surface,LC);
     272          distance = Intersections.GetSmallestDistance();
     273          triangle = Intersections.GetClosestTriangle();
     274          outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
     275        }
     276      }
     277    } else
     278      DoLog(1) && (Log() << Verbose(1) << "molecule " << (*MolWalker)->name << " is not active." << endl);
     279
    267280
    268281  return outmap;
     
    284297CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] )
    285298{
     299  Info FunctionInfo(__func__);
    286300  CorrelationToSurfaceMap *outmap = NULL;
    287301  double distance = 0;
     
    293307
    294308  if ((Surface == NULL) || (LC == NULL) || (molecules->ListOfMolecules.empty())) {
    295     Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl;
     309    DoLog(1) && (Log() << Verbose(1) <<"No Tesselation, no LinkedCell or no molecule given." << endl);
    296310    return outmap;
    297311  }
    298312  outmap = new CorrelationToSurfaceMap;
    299   for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
    300     if ((*MolWalker)->ActiveFlag) {
    301       const double * const FullMatrix = ReturnFullMatrixforSymmetric((*MolWalker)->cell_size);
    302       const double * const FullInverseMatrix = InverseMatrix(FullMatrix);
    303       Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl;
    304       atom *Walker = (*MolWalker)->start;
    305       while (Walker->next != (*MolWalker)->end) {
    306         Walker = Walker->next;
    307         Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl;
     313  double ShortestDistance = 0.;
     314  BoundaryTriangleSet *ShortestTriangle = NULL;
     315  for (MoleculeList::const_iterator MolWalker = molecules->ListOfMolecules.begin(); MolWalker != molecules->ListOfMolecules.end(); MolWalker++)
     316    if ((*MolWalker)->ActiveFlag) {
     317      double * FullMatrix = ReturnFullMatrixforSymmetric(World::get()->cell_size);
     318      double * FullInverseMatrix = InverseMatrix(FullMatrix);
     319      DoLog(2) && (Log() << Verbose(2) << "Current molecule is " << *MolWalker << "." << endl);
     320      atom *Walker = (*MolWalker)->start;
     321      while (Walker->next != (*MolWalker)->end) {
     322        Walker = Walker->next;
     323        DoLog(3) && (Log() << Verbose(3) << "Current atom is " << *Walker << "." << endl);
    308324        if ((type == NULL) || (Walker->type == type)) {
    309325          periodicX.CopyVector(Walker->node);
    310326          periodicX.MatrixMultiplication(FullInverseMatrix);  // x now in [0,1)^3
    311327          // go through every range in xyz and get distance
     328          ShortestDistance = -1.;
    312329          for (n[0]=-ranges[0]; n[0] <= ranges[0]; n[0]++)
    313330            for (n[1]=-ranges[1]; n[1] <= ranges[1]; n[1]++)
     
    316333                checkX.AddVector(&periodicX);
    317334                checkX.MatrixMultiplication(FullMatrix);
    318                 triangle = Surface->FindClosestTriangleToPoint(&checkX, LC );
    319                 if (triangle != NULL) {
    320                   distance = DistanceToTrianglePlane(&checkX, triangle);
    321                   outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(distance, pair<atom *, BoundaryTriangleSet*> (Walker, triangle) ) );
     335                TriangleIntersectionList Intersections(&checkX,Surface,LC);
     336                distance = Intersections.GetSmallestDistance();
     337                triangle = Intersections.GetClosestTriangle();
     338                if ((ShortestDistance == -1.) || (distance < ShortestDistance)) {
     339                  ShortestDistance = distance;
     340                  ShortestTriangle = triangle;
    322341                }
    323           }
    324         }
    325       }
    326     }
    327 
    328   return outmap;
    329 };
    330 
    331 /** Returns the start of the bin for a given value.
     342              }
     343          // insert
     344          outmap->insert ( pair<double, pair<atom *, BoundaryTriangleSet*> >(ShortestDistance, pair<atom *, BoundaryTriangleSet*> (Walker, ShortestTriangle) ) );
     345          //Log() << Verbose(1) << "INFO: Inserting " << Walker << " with distance " << ShortestDistance << " to " << *ShortestTriangle << "." << endl;
     346        }
     347      }
     348      Free(&FullMatrix);
     349      Free(&FullInverseMatrix);
     350    }
     351
     352  return outmap;
     353};
     354
     355/** Returns the index of the bin for a given value.
    332356 * \param value value whose bin to look for
    333357 * \param BinWidth width of bin
    334358 * \param BinStart first bin
    335359 */
    336 double GetBin ( const double value, const double BinWidth, const double BinStart )
    337 {
    338   double bin =(double) (floor((value - BinStart)/BinWidth));
    339   return (bin*BinWidth+BinStart);
     360int GetBin ( const double value, const double BinWidth, const double BinStart )
     361{
     362  Info FunctionInfo(__func__);
     363  int bin =(int) (floor((value - BinStart)/BinWidth));
     364  return (bin);
    340365};
    341366
     
    347372void OutputCorrelation( ofstream * const file, const BinPairMap * const map )
    348373{
    349   *file << "# BinStart\tCount" << endl;
     374  Info FunctionInfo(__func__);
     375  *file << "BinStart\tCount" << endl;
    350376  for (BinPairMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    351     *file << runner->first << "\t" << runner->second << endl;
     377    *file << setprecision(8) << runner->first << "\t" << runner->second << endl;
    352378  }
    353379};
     
    359385void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map )
    360386{
    361   *file << "# BinStart\tAtom1\tAtom2" << endl;
     387  Info FunctionInfo(__func__);
     388  *file << "BinStart\tAtom1\tAtom2" << endl;
    362389  for (PairCorrelationMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    363     *file << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
     390    *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
    364391  }
    365392};
     
    371398void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map )
    372399{
    373   *file << "# BinStart\tAtom::x[i]-point.x[i]" << endl;
     400  Info FunctionInfo(__func__);
     401  *file << "BinStart\tAtom::x[i]-point.x[i]" << endl;
    374402  for (CorrelationToPointMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    375403    *file << runner->first;
    376404    for (int i=0;i<NDIM;i++)
    377       *file << "\t" << (runner->second.first->node->x[i] - runner->second.second->x[i]);
     405      *file << "\t" << setprecision(8) << (runner->second.first->node->x[i] - runner->second.second->x[i]);
    378406    *file << endl;
    379407  }
     
    386414void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map )
    387415{
    388   *file << "# BinStart\tTriangle" << endl;
    389   for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
    390     *file << runner->first << "\t" << *(runner->second.second) << endl;
    391   }
    392 };
    393 
     416  Info FunctionInfo(__func__);
     417  *file << "BinStart\tTriangle" << endl;
     418  if (!map->empty())
     419    for (CorrelationToSurfaceMap::const_iterator runner = map->begin(); runner != map->end(); ++runner) {
     420      *file << setprecision(8) << runner->first << "\t" << *(runner->second.first) << "\t" << *(runner->second.second) << endl;
     421    }
     422};
     423
  • src/analysis_correlation.hpp

    re5ad5c ree7e25  
    5151CorrelationToPointMap *PeriodicCorrelationToPoint(MoleculeListClass * const &molecules, const element * const type, const Vector *point, const int ranges[NDIM] );
    5252CorrelationToSurfaceMap *PeriodicCorrelationToSurface(MoleculeListClass * const &molecules, const element * const type, const Tesselation * const Surface, const LinkedCell *LC, const int ranges[NDIM] );
    53 double GetBin ( const double value, const double BinWidth, const double BinStart );
     53int GetBin ( const double value, const double BinWidth, const double BinStart );
    5454void OutputCorrelation( ofstream * const file, const BinPairMap * const map );
    55 void OutputPairCorrelation( ofstream * const file, const BinPairMap * const map );
    56 void OutputCorrelationToPoint( ofstream * const file, const BinPairMap * const map );
    57 void OutputCorrelationToSurface( ofstream * const file, const BinPairMap * const map );
     55void OutputPairCorrelation( ofstream * const file, const PairCorrelationMap * const map );
     56void OutputCorrelationToPoint( ofstream * const file, const CorrelationToPointMap * const map );
     57void OutputCorrelationToSurface( ofstream * const file, const CorrelationToSurfaceMap * const map );
    5858
    5959
     
    7171
    7272  if (map == NULL) {
    73     eLog() << Verbose(0) << "Nothing to min/max, map is NULL!" << endl;
     73    DoeLog(0) && (eLog()<< Verbose(0) << "Nothing to min/max, map is NULL!" << endl);
     74    performCriticalExit();
    7475    return;
    7576  }
     
    8990/** Puts given correlation data into bins of given size (histogramming).
    9091 * Note that BinStart and BinEnd are desired to fill the complete range, even where Bins are zero. If this is
    91  * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater.
     92 * not desired, give equal BinStart and BinEnd and the map will contain only Bins where the count is one or greater. If a
     93 * certain start value is desired, give BinStart and a BinEnd that is smaller than BinStart, then only BinEnd will be
     94 * calculated automatically, i.e. BinStart = 0. and BinEnd = -1. .
    9295 * Also note that the range is given inclusive, i.e. [ BinStart, BinEnd ].
    9396 * \param *map map of doubles to count
     
    100103{
    101104  BinPairMap *outmap = new BinPairMap;
    102   double bin = 0.;
     105  int bin = 0;
    103106  double start = 0.;
    104107  double end = 0.;
     
    106109
    107110  if (map == NULL) {
    108     eLog() << Verbose(0) << "Nothing to bin, is NULL!" << endl;
     111    DoeLog(0) && (eLog()<< Verbose(0) << "Nothing to bin, is NULL!" << endl);
     112    performCriticalExit();
    109113    return outmap;
    110114  }
     
    112116  if (BinStart == BinEnd) { // if same, find range ourselves
    113117    GetMinMax( map, start, end);
    114   } else { // if not, initialise range to zero
     118  } else if (BinEnd < BinStart) { // if BinEnd smaller, just look for new max
     119    GetMinMax( map, start, end);
     120    start = BinStart;
     121  } else { // else take both values
    115122    start = BinStart;
    116123    end = BinEnd;
    117     for (double runner = start; runner <= end; runner += BinWidth)
    118       outmap->insert( pair<double, int> (runner, 0) );
    119124  }
     125  for (int runner = 0; runner <= ceil((end-start)/BinWidth); runner++)
     126    outmap->insert( pair<double, int> ((double)runner*BinWidth+start, 0) );
    120127
    121128  for (typename T::iterator runner = map->begin(); runner != map->end(); ++runner) {
    122129    bin = GetBin (runner->first, BinWidth, start);
    123     BinPairMapInserter = outmap->insert ( pair<double, int> (bin, 1) );
     130    BinPairMapInserter = outmap->insert ( pair<double, int> ((double)bin*BinWidth+start, 1) );
    124131    if (!BinPairMapInserter.second) {  // bin already present, increase
    125132      BinPairMapInserter.first->second += 1;
  • src/analyzer.cpp

    re5ad5c ree7e25  
    77
    88//============================ INCLUDES ===========================
     9
     10#include <cstring>
    911
    1012#include "datacreator.hpp"
     
    6163  int counter = 0;
    6264
    63   Log() << Verbose(0) << "ANOVA Analyzer" << endl;
    64   Log() << Verbose(0) << "==============" << endl;
     65  DoLog(0) && (Log() << Verbose(0) << "ANOVA Analyzer" << endl);
     66  DoLog(0) && (Log() << Verbose(0) << "==============" << endl);
    6567
    6668  // Get the command line options
    6769  if (argc < 4) {
    68     Log() << Verbose(0) << "Usage: " << argv[0] << " <inputdir> <prefix> <outputdir> [elementsdb]" << endl;
    69     Log() << Verbose(0) << "<inputdir>\ttherein the output of a molecuilder fragmentation is expected, each fragment with a subdir containing an energy.all and a forces.all file." << endl;
    70     Log() << Verbose(0) << "<prefix>\tprefix of energy and forces file." << endl;
    71     Log() << Verbose(0) << "<outputdir>\tcreated plotfiles and datafiles are placed into this directory " << endl;
    72     Log() << Verbose(0) << "[elementsdb]\tpath to elements database, needed for shieldings." << endl;
     70    DoLog(0) && (Log() << Verbose(0) << "Usage: " << argv[0] << " <inputdir> <prefix> <outputdir> [elementsdb]" << endl);
     71    DoLog(0) && (Log() << Verbose(0) << "<inputdir>\ttherein the output of a molecuilder fragmentation is expected, each fragment with a subdir containing an energy.all and a forces.all file." << endl);
     72    DoLog(0) && (Log() << Verbose(0) << "<prefix>\tprefix of energy and forces file." << endl);
     73    DoLog(0) && (Log() << Verbose(0) << "<outputdir>\tcreated plotfiles and datafiles are placed into this directory " << endl);
     74    DoLog(0) && (Log() << Verbose(0) << "[elementsdb]\tpath to elements database, needed for shieldings." << endl);
    7375    return 1;
    7476  } else {
     
    7981
    8082  if (argc > 4) {
    81     Log() << Verbose(0) << "Loading periodentafel." << endl;
     83    DoLog(0) && (Log() << Verbose(0) << "Loading periodentafel." << endl);
    8284    periode = Malloc<periodentafel>(1, "main - periode");
    8385    periode->LoadPeriodentafel(argv[4]);
     
    9496  if (!Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX,0,0)) {
    9597    NoHCorrection = true;
    96     Log() << Verbose(0) << "No HCorrection file found, skipping these." << endl;
     98    DoeLog(2) && (eLog()<< Verbose(2) << "No HCorrection file found, skipping these." << endl);
    9799  }
    98100 
     
    100102  if (!Hessian.ParseFragmentMatrix(argv[1], dir, HessianSuffix,0,0)) {
    101103    NoHessian = true;
    102     Log() << Verbose(0) << "No Hessian file found, skipping these." << endl;
     104    DoeLog(2) && (eLog()<< Verbose(2) << "No Hessian file found, skipping these." << endl);
    103105  }
    104106  if (!Time.ParseFragmentMatrix(argv[1], dir, TimeSuffix, 10,1)) {
    105107    NoTime = true;
    106     Log() << Verbose(0) << "No speed file found, skipping these." << endl;
     108    DoeLog(2) && (eLog()<< Verbose(2) << "No speed file found, skipping these." << endl);
    107109  }
    108110  if (periode != NULL) { // also look for PAS values
     
    246248  // +++++++++++++++ ANALYZING ++++++++++++++++++++++++++++++
    247249
    248   Log() << Verbose(0) << "Analyzing ..." << endl;
     250  DoLog(0) && (Log() << Verbose(0) << "Analyzing ..." << endl);
    249251
    250252  // ======================================= Creating the data files ==============================================================
     
    557559  delete(periode);
    558560  Free(&dir);
    559   Log() << Verbose(0) << "done." << endl;
     561  DoLog(0) && (Log() << Verbose(0) << "done." << endl);
    560562  return 0;
    561563};
  • src/atom_bondedparticle.cpp

    re5ad5c ree7e25  
    4444void BondedParticle::OutputBondOfAtom() const
    4545{
    46   Log() << Verbose(4) << "Atom " << Name << "/" << nr << " with " << ListOfBonds.size() << " bonds: ";
     46  DoLog(4) && (Log() << Verbose(4) << "Atom " << Name << "/" << nr << " with " << ListOfBonds.size() << " bonds: " << endl);
    4747  int TotalDegree = 0;
    4848  for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); ++Runner) {
    49     Log() << Verbose(0) << **Runner << "\t";
     49    DoLog(4) && (Log() << Verbose(4) << **Runner << endl);
    5050    TotalDegree += (*Runner)->BondDegree;
    5151  }
    52   Log() << Verbose(0) << " -- TotalDegree: " << TotalDegree << endl;
     52  DoLog(4) && (Log() << Verbose(4) << " -- TotalDegree: " << TotalDegree << endl);
    5353};
    5454
     
    5656 * \param *AdjacencyFile output stream
    5757 */
    58 void BondedParticle::OutputAdjacency(ofstream *AdjacencyFile) const
     58void BondedParticle::OutputAdjacency(ofstream * const AdjacencyFile) const
    5959{
    6060  *AdjacencyFile << nr << "\t";
     
    6262    *AdjacencyFile << (*Runner)->GetOtherAtom(this)->nr << "\t";
    6363  *AdjacencyFile << endl;
     64};
     65
     66/** Output of atom::nr along each bond partner per line.
     67 * Only bonds are printed where atom::nr is smaller than the one of the bond partner.
     68 * \param *AdjacencyFile output stream
     69 */
     70void BondedParticle::OutputBonds(ofstream * const BondFile) const
     71{
     72  for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner))
     73    if (nr < (*Runner)->GetOtherAtom(this)->nr)
     74      *BondFile << nr << "\t" << (*Runner)->GetOtherAtom(this)->nr << "\n";
    6475};
    6576
     
    7586      status = true;
    7687    } else {
    77       Log() << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl;
     88      DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
    7889    }
    7990  } else {
    80     Log() << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl;
     91    DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
    8192  }
    8293  return status;
     
    94105      status = true;
    95106    } else {
    96       Log() << Verbose(1) << "ERROR: " << *Binder << " does not contain " << *this << "." << endl;
     107      DoeLog(1) && (eLog()<< Verbose(1) << *Binder << " does not contain " << *this << "." << endl);
    97108    }
    98109  } else {
    99     Log() << Verbose(1) << "ERROR: Binder is " << Binder << "." << endl;
     110    DoeLog(1) && (eLog()<< Verbose(1) << "Binder is " << Binder << "." << endl);
    100111  }
    101112  return status;
     
    121132  bond *CandidateBond = NULL;
    122133
     134  NoBonds = CountBonds();
    123135  //Log() << Verbose(3) << "Walker " << *this << ": " << (int)this->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    124   NoBonds = CountBonds();
    125136  if ((int)(type->NoValenceOrbitals) > NoBonds) { // we have a mismatch, check all bonding partners for mismatch
    126137    for (BondList::const_iterator Runner = ListOfBonds.begin(); Runner != ListOfBonds.end(); (++Runner)) {
    127138      OtherWalker = (*Runner)->GetOtherAtom(this);
    128139      OtherNoBonds = OtherWalker->CountBonds();
    129       //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << NoBonds << "?" << endl;
    130       if ((int)(OtherWalker->type->NoValenceOrbitals) > NoBonds) { // check if possible candidate
     140      //Log() << Verbose(3) << "OtherWalker " << *OtherWalker << ": " << (int)OtherWalker->type->NoValenceOrbitals << " > " << OtherNoBonds << "?" << endl;
     141      if ((int)(OtherWalker->type->NoValenceOrbitals) > OtherNoBonds) { // check if possible candidate
    131142        if ((CandidateBond == NULL) || (ListOfBonds.size() > OtherWalker->ListOfBonds.size())) { // pick the one with fewer number of bonds first
    132143          CandidateBond = (*Runner);
     
    137148    if ((CandidateBond != NULL)) {
    138149      CandidateBond->BondDegree++;
    139       Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
     150      //Log() << Verbose(2) << "Increased bond degree for bond " << *CandidateBond << "." << endl;
    140151    } else {
    141       //Log() << Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl;
     152      DoeLog(2) && (eLog()<< Verbose(2) << "Could not find correct degree for atom " << *this << "." << endl);
    142153      FalseBondDegree++;
    143154    }
  • src/atom_bondedparticle.hpp

    re5ad5c ree7e25  
    4444  int CorrectBondDegree();
    4545  void OutputBondOfAtom() const;
    46   void OutputAdjacency(ofstream *AdjacencyFile) const;
     46  void OutputAdjacency(ofstream * const AdjacencyFile) const;
     47  void OutputBonds(ofstream * const BondFile) const;
    4748  void OutputOrder(ofstream *file) const;
    4849
  • src/atom_graphnode.cpp

    re5ad5c ree7e25  
    2727void GraphNode::OutputGraphInfo() const
    2828{
    29   Log() << Verbose(2) << "Atom " << Name << " is " << ((SeparationVertex) ? "a" : "not a") << " separation vertex, components are ";
     29  DoLog(2) && (Log() << Verbose(2) << "Atom " << Name << " is " << ((SeparationVertex) ? "a" : "not a") << " separation vertex, components are ");
    3030  OutputComponentNumber();
    31   Log() << Verbose(0) << " with Lowpoint " << LowpointNr << " and Graph Nr. " << GraphNr << "." << endl;
     31  DoLog(3) && (Log() << Verbose(3) << " with Lowpoint " << LowpointNr << " and Graph Nr. " << GraphNr << "." << endl);
    3232};
    3333
     
    4040  if (ComponentNr != NULL) {
    4141    for (int i=0; ComponentNr[i] != -1; i++)
    42       Log() << Verbose(0) << ComponentNr[i] << " ";
     42      DoLog(2) && (Log() << Verbose(2) << ComponentNr[i] << " ");
    4343  }
    4444};
  • src/atom_particleinfo.cpp

    re5ad5c ree7e25  
    2222ostream & operator << (ostream &ost, const ParticleInfo &a)
    2323{
    24   ost << "[" << a.Name << "|" << &a << "]";
     24  if (a.Name == NULL)
     25    ost << "[NULL]";
     26  else
     27    ost << "[" << a.Name << "|" << &a << "]";
    2528  return ost;
    2629};
     
    2831ostream & ParticleInfo::operator << (ostream &ost) const
    2932{
    30   ost << "[" << Name << "|" << this << "]";
     33  if (Name == NULL)
     34    ost << "[NULL]";
     35  else
     36    ost << "[" << Name << "|" << this << "]";
    3137  return ost;
    3238};
  • src/atom_trajectoryparticle.cpp

    re5ad5c ree7e25  
    198198    // throw a dice to determine whether it gets hit by a heat bath particle
    199199    if (((((rand()/(double)RAND_MAX))*configuration->TempFrequency) < 1.)) {
    200       Log() << Verbose(3) << "Particle " << *this << " was hit (sigma " << sigma << "): " << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << " -> ";
     200      DoLog(3) && (Log() << Verbose(3) << "Particle " << *this << " was hit (sigma " << sigma << "): " << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << " -> ");
    201201      // pick three random numbers from a Boltzmann distribution around the desired temperature T for each momenta axis
    202202      for (int d=0; d<NDIM; d++) {
    203203        U[d] = gsl_ran_gaussian (r, sigma);
    204204      }
    205       Log() << Verbose(0) << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << endl;
     205      DoLog(2) && (Log() << Verbose(2) << sqrt(U[0]*U[0]+U[1]*U[1]+U[2]*U[2]) << endl);
    206206    }
    207207    for (int d=0; d<NDIM; d++)
  • src/bond.cpp

    re5ad5c ree7e25  
    6363  if(rightatom == Atom)
    6464    return leftatom;
    65   eLog() << Verbose(0) << "Bond " << *this << " does not contain atom " << *Atom << "!" << endl;
     65  DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << *this << " does not contain atom " << *Atom << "!" << endl);
    6666  return NULL;
    6767};
     
    9999bool bond::MarkUsed(const enum Shading color) {
    100100  if (Used == black) {
    101     eLog() << Verbose(0) << "ERROR: Bond " << this << " was already marked black!." << endl;
     101    DoeLog(1) && (eLog()<< Verbose(1) << "Bond " << this << " was already marked black!." << endl);
    102102    return false;
    103103  } else {
     
    113113  Used = white;
    114114};
     115
     116/** Calculates the bond length.
     117 * \return |a - b| with a = bond::leftatom and b = bond::rightatom.
     118 */
     119double bond::GetDistance() const
     120{
     121  return (leftatom->node->Distance(rightatom->node));
     122};
     123
     124/** Calculates the bond length.
     125 * \return |a - b|^2 with a = bond::leftatom and b = bond::rightatom.
     126 */
     127double bond::GetDistanceSquared() const
     128{
     129  return (leftatom->node->DistanceSquared(rightatom->node));
     130};
  • src/bond.hpp

    re5ad5c ree7e25  
    5151  bool Contains(const ParticleInfo * const ptr);
    5252  bool Contains(const int nr);
     53  double GetDistance() const;
     54  double GetDistanceSquared() const;
    5355
    5456  bond();
  • src/bondgraph.cpp

    re5ad5c ree7e25  
    99
    1010#include "atom.hpp"
     11#include "bond.hpp"
    1112#include "bondgraph.hpp"
    1213#include "element.hpp"
     14#include "info.hpp"
    1315#include "log.hpp"
    1416#include "molecule.hpp"
     
    3537/** Parses the bond lengths in a given file and puts them int a matrix form.
    3638 * Allocates \a MatrixContainer for BondGraph::BondLengthMatrix, using MatrixContainer::ParseMatrix(),
    37  * but only if parsing is successfull. Otherwise variable is left as NULL.
     39 * but only if parsing is successful. Otherwise variable is left as NULL.
    3840 * \param *out output stream for debugging
    3941 * \param filename file with bond lengths to parse
     
    4244bool BondGraph::LoadBondLengthTable(const string &filename)
    4345{
     46  Info FunctionInfo(__func__);
    4447  bool status = true;
    4548  MatrixContainer *TempContainer = NULL;
     
    4750  // allocate MatrixContainer
    4851  if (BondLengthMatrix != NULL) {
    49     Log() << Verbose(1) << "MatrixContainer for Bond length already present, removing." << endl;
     52    DoLog(1) && (Log() << Verbose(1) << "MatrixContainer for Bond length already present, removing." << endl);
    5053    delete(BondLengthMatrix);
    5154  }
     
    5356
    5457  // parse in matrix
    55   status = TempContainer->ParseMatrix(filename.c_str(), 0, 1, 0);
     58  if ((status = TempContainer->ParseMatrix(filename.c_str(), 0, 1, 0))) {
     59    DoLog(1) && (Log() << Verbose(1) << "Parsing bond length matrix successful." << endl);
     60  } else {
     61    DoeLog(1) && (eLog()<< Verbose(1) << "Parsing bond length matrix failed." << endl);
     62  }
    5663
    5764  // find greatest distance
     
    8087bool BondGraph::ConstructBondGraph(molecule * const mol)
    8188{
    82   bool status = true;
     89  Info FunctionInfo(__func__);
     90bool status = true;
    8391
    8492  if (mol->start->next == mol->end) // only construct if molecule is not empty
     
    113121double BondGraph::SetMaxDistanceToMaxOfCovalentRadii(const molecule * const mol)
    114122{
     123  Info FunctionInfo(__func__);
    115124  max_distance = 0.;
    116125
     
    153162{
    154163  if (BondLengthMatrix == NULL) {// safety measure if no matrix has been parsed yet
    155     eLog() << Verbose(1) << "WARNING:  BondLengthMatrixMinMaxDistance() called without having parsed the bond length matrix yet!" << endl;
     164    DoeLog(2) && (eLog()<< Verbose(2) << "BondLengthMatrixMinMaxDistance() called without having parsed the bond length matrix yet!" << endl);
    156165    CovalentMinMaxDistance(Walker, OtherWalker, MinDistance, MaxDistance, IsAngstroem);
    157166  } else {
     
    162171  }
    163172};
    164 
  • src/bondgraph.hpp

    re5ad5c ree7e25  
    1919
    2020#include <iostream>
     21
     22/*********************************************** defines ***********************************/
     23
     24#define BONDTHRESHOLD 0.4   //!< CSD threshold in bond check which is the width of the interval whose center is the sum of the covalent radii
    2125
    2226/****************************************** forward declarations *****************************/
  • src/boundary.cpp

    • Property mode changed from 100755 to 100644
    re5ad5c ree7e25  
    1010#include "element.hpp"
    1111#include "helpers.hpp"
     12#include "info.hpp"
    1213#include "linkedcell.hpp"
    1314#include "log.hpp"
     
    1617#include "tesselation.hpp"
    1718#include "tesselationhelpers.hpp"
     19#include "World.hpp"
    1820
    1921#include<gsl/gsl_poly.h>
     22#include<time.h>
    2023
    2124// ========================================== F U N C T I O N S =================================
     
    3336double *GetDiametersOfCluster(const Boundaries *BoundaryPtr, const molecule *mol, Tesselation *&TesselStruct, const bool IsAngstroem)
    3437{
     38        Info FunctionInfo(__func__);
    3539  // get points on boundary of NULL was given as parameter
    3640  bool BoundaryFreeFlag = false;
     
    5357  } else {
    5458    BoundaryPoints = BoundaryPtr;
    55     Log() << Verbose(1) << "Using given boundary points set." << endl;
     59    DoLog(0) && (Log() << Verbose(0) << "Using given boundary points set." << endl);
    5660  }
    5761  // determine biggest "diameter" of cluster for each axis
     
    6771          //Log() << Verbose(1) << "Current component is " << component << ", Othercomponent is " << Othercomponent << "." << endl;
    6872          for (Boundaries::const_iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
    69               //Log() << Verbose(2) << "Current runner is " << *(runner->second.second) << "." << endl;
     73              //Log() << Verbose(1) << "Current runner is " << *(runner->second.second) << "." << endl;
    7074              // seek for the neighbours pair where the Othercomponent sign flips
    7175              Neighbour = runner;
     
    8286                  DistanceVector.CopyVector(&runner->second.second->x);
    8387                  DistanceVector.SubtractVector(&Neighbour->second.second->x);
    84                   //Log() << Verbose(3) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl;
     88                  //Log() << Verbose(2) << "OldComponent is " << OldComponent << ", new one is " << DistanceVector.x[Othercomponent] << "." << endl;
    8589                } while ((runner != Neighbour) && (fabs(OldComponent / fabs(
    8690                  OldComponent) - DistanceVector.x[Othercomponent] / fabs(
     
    9195                    OtherNeighbour = BoundaryPoints[axis].end();
    9296                  OtherNeighbour--;
    93                   //Log() << Verbose(2) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl;
     97                  //Log() << Verbose(1) << "The pair, where the sign of OtherComponent flips, is: " << *(Neighbour->second.second) << " and " << *(OtherNeighbour->second.second) << "." << endl;
    9498                  // now we have found the pair: Neighbour and OtherNeighbour
    9599                  OtherVector.CopyVector(&runner->second.second->x);
    96100                  OtherVector.SubtractVector(&OtherNeighbour->second.second->x);
    97                   //Log() << Verbose(2) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl;
    98                   //Log() << Verbose(2) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl;
     101                  //Log() << Verbose(1) << "Distances to Neighbour and OtherNeighbour are " << DistanceVector.x[component] << " and " << OtherVector.x[component] << "." << endl;
     102                  //Log() << Verbose(1) << "OtherComponents to Neighbour and OtherNeighbour are " << DistanceVector.x[Othercomponent] << " and " << OtherVector.x[Othercomponent] << "." << endl;
    99103                  // do linear interpolation between points (is exact) to extract exact intersection between Neighbour and OtherNeighbour
    100104                  w1 = fabs(OtherVector.x[Othercomponent]);
     
    103107                      * OtherVector.x[component]) / (w1 + w2));
    104108                  // mark if it has greater diameter
    105                   //Log() << Verbose(2) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl;
     109                  //Log() << Verbose(1) << "Comparing current greatest " << GreatestDiameter[component] << " to new " << tmp << "." << endl;
    106110                  GreatestDiameter[component] = (GreatestDiameter[component]
    107111                      > tmp) ? GreatestDiameter[component] : tmp;
    108112                } //else
    109               //Log() << Verbose(2) << "Saw no sign flip, probably top or bottom node." << endl;
     113              //Log() << Verbose(1) << "Saw no sign flip, probably top or bottom node." << endl;
    110114            }
    111115        }
     
    135139Boundaries *GetBoundaryPoints(const molecule *mol, Tesselation *&TesselStruct)
    136140{
     141        Info FunctionInfo(__func__);
    137142  atom *Walker = NULL;
    138143  PointMap PointsOnBoundary;
     
    149154  double angle = 0.;
    150155
    151   Log() << Verbose(1) << "Finding all boundary points." << endl;
    152156  // 3a. Go through every axis
    153157  for (int axis = 0; axis < NDIM; axis++) {
     
    159163    AngleReferenceNormalVector.x[(axis + 2) % NDIM] = 1.;
    160164
    161     Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl;
     165    DoLog(1) && (Log() << Verbose(1) << "Axisvector is " << AxisVector << " and AngleReferenceVector is " << AngleReferenceVector << ", and AngleReferenceNormalVector is " << AngleReferenceNormalVector << "." << endl);
    162166
    163167    // 3b. construct set of all points, transformed into cylindrical system and with left and right neighbours
     
    176180        angle = 0.; // otherwise it's a vector in Axis Direction and unimportant for boundary issues
    177181
    178       //Log() << Verbose(0) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
     182      //Log() << Verbose(1) << "Checking sign in quadrant : " << ProjectedVector.Projection(&AngleReferenceNormalVector) << "." << endl;
    179183      if (ProjectedVector.ScalarProduct(&AngleReferenceNormalVector) > 0) {
    180184        angle = 2. * M_PI - angle;
    181185      }
    182       Log() << Verbose(2) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl;
     186      DoLog(1) && (Log() << Verbose(1) << "Inserting " << *Walker << ": (r, alpha) = (" << radius << "," << angle << "): " << ProjectedVector << endl);
    183187      BoundaryTestPair = BoundaryPoints[axis].insert(BoundariesPair(angle, DistancePair (radius, Walker)));
    184188      if (!BoundaryTestPair.second) { // same point exists, check first r, then distance of original vectors to center of gravity
    185         Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl;
    186         Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl;
    187         Log() << Verbose(2) << "New vector: " << *Walker << endl;
     189        DoLog(2) && (Log() << Verbose(2) << "Encountered two vectors whose projection onto axis " << axis << " is equal: " << endl);
     190        DoLog(2) && (Log() << Verbose(2) << "Present vector: " << *BoundaryTestPair.first->second.second << endl);
     191        DoLog(2) && (Log() << Verbose(2) << "New vector: " << *Walker << endl);
    188192        const double ProjectedVectorNorm = ProjectedVector.NormSquared();
    189193        if ((ProjectedVectorNorm - BoundaryTestPair.first->second.first) > MYEPSILON) {
    190194          BoundaryTestPair.first->second.first = ProjectedVectorNorm;
    191195          BoundaryTestPair.first->second.second = Walker;
    192           Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl;
     196          DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
    193197        } else if (fabs(ProjectedVectorNorm - BoundaryTestPair.first->second.first) < MYEPSILON) {
    194198          helper.CopyVector(&Walker->x);
     
    199203          if (helper.NormSquared() < oldhelperNorm) {
    200204            BoundaryTestPair.first->second.second = Walker;
    201             Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl;
     205            DoLog(2) && (Log() << Verbose(2) << "Keeping new vector due to larger distance to molecule center " << helper.NormSquared() << "." << endl);
    202206          } else {
    203             Log() << Verbose(2) << "Keeping present vector due to larger distance to molecule center " << oldhelperNorm << "." << endl;
     207            DoLog(2) && (Log() << Verbose(2) << "Keeping present vector due to larger distance to molecule center " << oldhelperNorm << "." << endl);
    204208          }
    205209        } else {
    206           Log() << Verbose(2) << "Keeping present vector due to larger projected distance " << ProjectedVectorNorm << "." << endl;
     210          DoLog(2) && (Log() << Verbose(2) << "Keeping present vector due to larger projected distance " << ProjectedVectorNorm << "." << endl);
    207211        }
    208212      }
     
    210214    // printing all inserted for debugging
    211215    //    {
    212     //      Log() << Verbose(2) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
     216    //      Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
    213217    //      int i=0;
    214218    //      for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
     
    223227    // 3c. throw out points whose distance is less than the mean of left and right neighbours
    224228    bool flag = false;
    225     Log() << Verbose(1) << "Looking for candidates to kick out by convex condition ... " << endl;
     229    DoLog(1) && (Log() << Verbose(1) << "Looking for candidates to kick out by convex condition ... " << endl);
    226230    do { // do as long as we still throw one out per round
    227231      flag = false;
     
    249253          SideA.SubtractVector(MolCenter);
    250254          SideA.ProjectOntoPlane(&AxisVector);
    251           //          Log() << Verbose(0) << "SideA: ";
    252           //          SideA.Output(out);
    253           //          Log() << Verbose(0) << endl;
     255          //          Log() << Verbose(1) << "SideA: " << SideA << endl;
    254256
    255257          SideB.CopyVector(&right->second.second->x);
    256258          SideB.SubtractVector(MolCenter);
    257259          SideB.ProjectOntoPlane(&AxisVector);
    258           //          Log() << Verbose(0) << "SideB: ";
    259           //          SideB.Output(out);
    260           //          Log() << Verbose(0) << endl;
     260          //          Log() << Verbose(1) << "SideB: " << SideB << endl;
    261261
    262262          SideC.CopyVector(&left->second.second->x);
    263263          SideC.SubtractVector(&right->second.second->x);
    264264          SideC.ProjectOntoPlane(&AxisVector);
    265           //          Log() << Verbose(0) << "SideC: ";
    266           //          SideC.Output(out);
    267           //          Log() << Verbose(0) << endl;
     265          //          Log() << Verbose(1) << "SideC: " << SideC << endl;
    268266
    269267          SideH.CopyVector(&runner->second.second->x);
    270268          SideH.SubtractVector(MolCenter);
    271269          SideH.ProjectOntoPlane(&AxisVector);
    272           //          Log() << Verbose(0) << "SideH: ";
    273           //          SideH.Output(out);
    274           //          Log() << Verbose(0) << endl;
     270          //          Log() << Verbose(1) << "SideH: " << SideH << endl;
    275271
    276272          // calculate each length
     
    285281          const double delta = SideC.Angle(&SideH);
    286282          const double MinDistance = a * sin(beta) / (sin(delta)) * (((alpha < M_PI / 2.) || (gamma < M_PI / 2.)) ? 1. : -1.);
    287           //Log() << Verbose(2) << " 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;
    288           Log() << Verbose(1) << "Checking CoG distance of runner " << *runner->second.second << " " << h << " against triangle's side length spanned by (" << *left->second.second << "," << *right->second.second << ") of " << MinDistance << "." << endl;
     283          //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;
     284          DoLog(1) && (Log() << Verbose(1) << "Checking CoG distance of runner " << *runner->second.second << " " << h << " against triangle's side length spanned by (" << *left->second.second << "," << *right->second.second << ") of " << MinDistance << "." << endl);
    289285          if ((fabs(h / fabs(h) - MinDistance / fabs(MinDistance)) < MYEPSILON) && ((h - MinDistance)) < -MYEPSILON) {
    290286            // throw out point
    291             Log() << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl;
     287            DoLog(1) && (Log() << Verbose(1) << "Throwing out " << *runner->second.second << "." << endl);
    292288            BoundaryPoints[axis].erase(runner);
    293289            flag = true;
     
    311307void FindConvexBorder(const molecule* mol, Tesselation *&TesselStruct, const LinkedCell *LCList, const char *filename)
    312308{
     309        Info FunctionInfo(__func__);
    313310  bool BoundaryFreeFlag = false;
    314311  Boundaries *BoundaryPoints = NULL;
    315 
    316   Log() << Verbose(1) << "Begin of FindConvexBorder" << endl;
    317312
    318313  if (TesselStruct != NULL) // free if allocated
     
    325320      BoundaryPoints = GetBoundaryPoints(mol, TesselStruct);
    326321  } else {
    327       Log() << Verbose(1) << "Using given boundary points set." << endl;
     322      DoLog(0) && (Log() << Verbose(0) << "Using given boundary points set." << endl);
    328323  }
    329324
     
    331326  for (int axis=0; axis < NDIM; axis++)
    332327    {
    333       Log() << Verbose(2) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl;
     328      DoLog(1) && (Log() << Verbose(1) << "Printing list of candidates for axis " << axis << " which we have inserted so far." << endl);
    334329      int i=0;
    335330      for(Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++) {
    336331        if (runner != BoundaryPoints[axis].begin())
    337           Log() << Verbose(0) << ", " << i << ": " << *runner->second.second;
     332          DoLog(0) && (Log() << Verbose(0) << ", " << i << ": " << *runner->second.second);
    338333        else
    339           Log() << Verbose(0) << i << ": " << *runner->second.second;
     334          DoLog(0) && (Log() << Verbose(0) << i << ": " << *runner->second.second);
    340335        i++;
    341336      }
    342       Log() << Verbose(0) << endl;
     337      DoLog(0) && (Log() << Verbose(0) << endl);
    343338    }
    344339
     
    347342    for (Boundaries::iterator runner = BoundaryPoints[axis].begin(); runner != BoundaryPoints[axis].end(); runner++)
    348343        if (!TesselStruct->AddBoundaryPoint(runner->second.second, 0))
    349           Log() << Verbose(3) << "WARNING: Point " << *(runner->second.second) << " is already present!" << endl;
    350 
    351   Log() << Verbose(2) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl;
     344          DoeLog(2) && (eLog()<< Verbose(2) << "Point " << *(runner->second.second) << " is already present!" << endl);
     345
     346  DoLog(0) && (Log() << Verbose(0) << "I found " << TesselStruct->PointsOnBoundaryCount << " points on the convex boundary." << endl);
    352347  // now we have the whole set of edge points in the BoundaryList
    353348
     
    367362  // 3c. check whether all atoms lay inside the boundary, if not, add to boundary points, segment triangle into three with the new point
    368363  if (!TesselStruct->InsertStraddlingPoints(mol, LCList))
    369     Log() << Verbose(1) << "Insertion of straddling points failed!" << endl;
    370 
    371   Log() << Verbose(2) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " intermediate triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl;
     364    DoeLog(1) && (eLog()<< Verbose(1) << "Insertion of straddling points failed!" << endl);
     365
     366  DoLog(0) && (Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " intermediate triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl);
    372367
    373368  // 4. Store triangles in tecplot file
     
    400395    for (LineMap::iterator LineRunner = TesselStruct->LinesOnBoundary.begin(); LineRunner != TesselStruct->LinesOnBoundary.end(); LineRunner++) {
    401396      line = LineRunner->second;
    402       Log() << Verbose(1) << "INFO: Current line is " << *line << "." << endl;
     397      DoLog(1) && (Log() << Verbose(1) << "INFO: Current line is " << *line << "." << endl);
    403398      if (!line->CheckConvexityCriterion()) {
    404         Log() << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl;
     399        DoLog(1) && (Log() << Verbose(1) << "... line " << *line << " is concave, flipping it." << endl);
    405400
    406401        // flip the line
    407402        if (TesselStruct->PickFarthestofTwoBaselines(line) == 0.)
    408           Log() << Verbose(1) << "ERROR: Correction of concave baselines failed!" << endl;
     403          DoeLog(1) && (eLog()<< Verbose(1) << "Correction of concave baselines failed!" << endl);
    409404        else {
    410405          TesselStruct->FlipBaseline(line);
    411           Log() << Verbose(1) << "INFO: Correction of concave baselines worked." << endl;
     406          DoLog(1) && (Log() << Verbose(1) << "INFO: Correction of concave baselines worked." << endl);
    412407        }
    413408      }
     
    419414//    Log() << Verbose(1) << "Correction of concave tesselpoints failed!" << endl;
    420415
    421   Log() << Verbose(2) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl;
     416  DoLog(0) && (Log() << Verbose(0) << "I created " << TesselStruct->TrianglesOnBoundary.size() << " triangles with " << TesselStruct->LinesOnBoundary.size() << " lines and " << TesselStruct->PointsOnBoundary.size() << " points." << endl);
    422417
    423418  // 4. Store triangles in tecplot file
     
    445440  if (BoundaryFreeFlag)
    446441    delete[] (BoundaryPoints);
    447 
    448   Log() << Verbose(1) << "End of FindConvexBorder" << endl;
    449442};
    450443
     
    458451bool RemoveAllBoundaryPoints(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename)
    459452{
     453        Info FunctionInfo(__func__);
    460454  int i=0;
    461455  char number[MAXSTRINGSIZE];
    462456
    463457  if ((TesselStruct == NULL) || (TesselStruct->PointsOnBoundary.empty())) {
    464     Log() << Verbose(2) << "ERROR: TesselStruct is empty." << endl;
     458    DoeLog(1) && (eLog()<< Verbose(1) << "TesselStruct is empty." << endl);
    465459    return false;
    466460  }
     
    468462  PointMap::iterator PointRunner;
    469463  while (!TesselStruct->PointsOnBoundary.empty()) {
    470     Log() << Verbose(2) << "Remaining points are: ";
     464    DoLog(1) && (Log() << Verbose(1) << "Remaining points are: ");
    471465    for (PointMap::iterator PointSprinter = TesselStruct->PointsOnBoundary.begin(); PointSprinter != TesselStruct->PointsOnBoundary.end(); PointSprinter++)
    472       Log() << Verbose(0) << *(PointSprinter->second) << "\t";
    473     Log() << Verbose(0) << endl;
     466      DoLog(0) && (Log() << Verbose(0) << *(PointSprinter->second) << "\t");
     467    DoLog(0) && (Log() << Verbose(0) << endl);
    474468
    475469    PointRunner = TesselStruct->PointsOnBoundary.begin();
     
    511505double ConvexizeNonconvexEnvelope(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename)
    512506{
     507        Info FunctionInfo(__func__);
    513508  double volume = 0;
    514509  class BoundaryPointSet *point = NULL;
     
    524519  int run = 0;
    525520
    526   Log() << Verbose(0) << "Begin of ConvexizeNonconvexEnvelope" << endl;
    527 
    528521  // check whether there is something to work on
    529522  if (TesselStruct == NULL) {
    530     Log() << Verbose(1) << "ERROR: TesselStruct is empty!" << endl;
     523    DoeLog(1) && (eLog()<< Verbose(1) << "TesselStruct is empty!" << endl);
    531524    return volume;
    532525  }
     
    544537      PointAdvance++;
    545538      point = PointRunner->second;
    546       Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl;
     539      DoLog(1) && (Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl);
    547540      for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    548541        line = LineRunner->second;
    549         Log() << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
     542        DoLog(1) && (Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl);
    550543        if (!line->CheckConvexityCriterion()) {
    551544          // remove the point if needed
    552           Log() << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl;
     545          DoLog(1) && (Log() << Verbose(1) << "... point " << *point << " cannot be on convex envelope." << endl);
    553546          volume += TesselStruct->RemovePointFromTesselatedSurface(point);
    554547          sprintf(dummy, "-first-%d", ++run);
     
    571564      LineAdvance++;
    572565      line = LineRunner->second;
    573       Log() << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl;
     566      DoLog(1) && (Log() << Verbose(1) << "INFO: Picking farthest baseline for line is " << *line << "." << endl);
    574567      // take highest of both lines
    575568      if (TesselStruct->IsConvexRectangle(line) == NULL) {
     
    612605
    613606  // end
    614   Log() << Verbose(1) << "Volume is " << volume << "." << endl;
    615   Log() << Verbose(0) << "End of ConvexizeNonconvexEnvelope" << endl;
     607  DoLog(0) && (Log() << Verbose(0) << "Volume is " << volume << "." << endl);
    616608  return volume;
    617609};
     
    627619double VolumeOfConvexEnvelope(class Tesselation *TesselStruct, class config *configuration)
    628620{
     621        Info FunctionInfo(__func__);
    629622  bool IsAngstroem = configuration->GetIsAngstroem();
    630623  double volume = 0.;
     
    633626
    634627  // 6a. Every triangle forms a pyramid with the center of gravity as its peak, sum up the volumes
    635   Log() << Verbose(1)
    636       << "Calculating the volume of the pyramids formed out of triangles and center of gravity."
    637       << endl;
    638628  for (TriangleMap::iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++)
    639629    { // go through every triangle, calculate volume of its pyramid with CoG as peak
     
    650640      const double h = x.Norm(); // distance of CoG to triangle
    651641      const double PyramidVolume = (1. / 3.) * G * h; // this formula holds for _all_ pyramids (independent of n-edge base or (not) centered peak)
    652       Log() << Verbose(2) << "Area of triangle is " << setprecision(10) << G << " "
     642      Log() << Verbose(1) << "Area of triangle is " << setprecision(10) << G << " "
    653643          << (IsAngstroem ? "angstrom" : "atomiclength") << "^2, height is "
    654644          << h << " and the volume is " << PyramidVolume << " "
     
    656646      volume += PyramidVolume;
    657647    }
    658   Log() << Verbose(0) << "RESULT: The summed volume is " << setprecision(8)
     648  Log() << Verbose(0) << "RESULT: The summed volume is " << setprecision(6)
    659649      << volume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3."
    660650      << endl;
     
    666656 * \param *out output stream for debugging
    667657 * \param *mol molecule with atoms and bonds
    668  * \param *&TesselStruct Tesselation with boundary triangles
     658 * \param *TesselStruct Tesselation with boundary triangles
    669659 * \param *filename prefix of filename
    670660 * \param *extraSuffix intermediate suffix
    671661 */
    672 void StoreTrianglesinFile(const molecule * const mol, const Tesselation *&TesselStruct, const char *filename, const char *extraSuffix)
     662void StoreTrianglesinFile(const molecule * const mol, const Tesselation * const TesselStruct, const char *filename, const char *extraSuffix)
    673663{
     664        Info FunctionInfo(__func__);
    674665  // 4. Store triangles in tecplot file
    675666  if (filename != NULL) {
     
    679670      OutputName.append(TecplotSuffix);
    680671      ofstream *tecplot = new ofstream(OutputName.c_str());
    681       WriteTecplotFile(tecplot, TesselStruct, mol, 0);
     672      WriteTecplotFile(tecplot, TesselStruct, mol, -1);
    682673      tecplot->close();
    683674      delete(tecplot);
     
    706697void PrepareClustersinWater(config *configuration, molecule *mol, double ClusterVolume, double celldensity)
    707698{
     699        Info FunctionInfo(__func__);
    708700  bool IsAngstroem = true;
    709701  double *GreatestDiameter = NULL;
     
    742734      totalmass += Walker->type->mass;
    743735  }
    744   Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl;
    745   Log() << Verbose(0) << "RESULT: The average density is " << setprecision(10) << totalmass / clustervolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
     736  DoLog(0) && (Log() << Verbose(0) << "RESULT: The summed mass is " << setprecision(10) << totalmass << " atomicmassunit." << endl);
     737  DoLog(0) && (Log() << Verbose(0) << "RESULT: The average density is " << setprecision(10) << totalmass / clustervolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
    746738
    747739  // solve cubic polynomial
    748   Log() << Verbose(1) << "Solving equidistant suspension in water problem ..." << endl;
     740  DoLog(1) && (Log() << Verbose(1) << "Solving equidistant suspension in water problem ..." << endl);
    749741  if (IsAngstroem)
    750742    cellvolume = (TotalNoClusters * totalmass / SOLVENTDENSITY_A - (totalmass / clustervolume)) / (celldensity - 1);
    751743  else
    752744    cellvolume = (TotalNoClusters * totalmass / SOLVENTDENSITY_a0 - (totalmass / clustervolume)) / (celldensity - 1);
    753   Log() << Verbose(1) << "Cellvolume needed for a density of " << celldensity << " g/cm^3 is " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
     745  DoLog(1) && (Log() << Verbose(1) << "Cellvolume needed for a density of " << celldensity << " g/cm^3 is " << cellvolume << " " << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
    754746
    755747  double minimumvolume = TotalNoClusters * (GreatestDiameter[0] * GreatestDiameter[1] * GreatestDiameter[2]);
    756   Log() << Verbose(1) << "Minimum volume of the convex envelope contained in a rectangular box is " << minimumvolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl;
     748  DoLog(1) && (Log() << Verbose(1) << "Minimum volume of the convex envelope contained in a rectangular box is " << minimumvolume << " atomicmassunit/" << (IsAngstroem ? "angstrom" : "atomiclength") << "^3." << endl);
    757749  if (minimumvolume > cellvolume) {
    758     eLog() << Verbose(0) << "ERROR: the containing box already has a greater volume than the envisaged cell volume!" << endl;
    759     Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl;
     750    DoeLog(1) && (eLog()<< Verbose(1) << "the containing box already has a greater volume than the envisaged cell volume!" << endl);
     751    DoLog(0) && (Log() << Verbose(0) << "Setting Box dimensions to minimum possible, the greatest diameters." << endl);
    760752    for (int i = 0; i < NDIM; i++)
    761753      BoxLengths.x[i] = GreatestDiameter[i];
     
    769761    double x2 = 0.;
    770762    if (gsl_poly_solve_cubic(BoxLengths.x[0], BoxLengths.x[1], BoxLengths.x[2], &x0, &x1, &x2) == 1) // either 1 or 3 on return
    771       Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl;
     763      DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacing is: " << x0 << " ." << endl);
    772764    else {
    773       Log() << Verbose(0) << "RESULT: The resulting spacings are: " << x0 << " and " << x1 << " and " << x2 << " ." << endl;
     765      DoLog(0) && (Log() << Verbose(0) << "RESULT: The resulting spacings are: " << x0 << " and " << x1 << " and " << x2 << " ." << endl);
    774766      x0 = x2; // sorted in ascending order
    775767    }
     
    782774
    783775    // set new box dimensions
    784     Log() << Verbose(0) << "Translating to box with these boundaries." << endl;
     776    DoLog(0) && (Log() << Verbose(0) << "Translating to box with these boundaries." << endl);
    785777    mol->SetBoxDimension(&BoxLengths);
    786778    mol->CenterInBox();
     
    788780  // update Box of atoms by boundary
    789781  mol->SetBoxDimension(&BoxLengths);
    790   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;
     782  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);
    791783};
    792784
     
    798790 * \param *filler molecule which the box is to be filled with
    799791 * \param configuration contains box dimensions
     792 * \param MaxDistance fills in molecules only up to this distance (set to -1 if whole of the domain)
    800793 * \param distance[NDIM] distance between filling molecules in each direction
     794 * \param boundary length of boundary zone between molecule and filling mollecules
     795 * \param epsilon distance to surface which is not filled
    801796 * \param RandAtomDisplacement maximum distance for random displacement per atom
    802797 * \param RandMolDisplacement maximum distance for random displacement per filler molecule
     
    804799 * \return *mol pointer to new molecule with filled atoms
    805800 */
    806 molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, double distance[NDIM], double RandomAtomDisplacement, double RandomMolDisplacement, 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)
    807802{
     803        Info FunctionInfo(__func__);
    808804  molecule *Filling = new molecule(filler->elemente);
    809805  Vector CurrentPosition;
    810806  int N[NDIM];
    811807  int n[NDIM];
    812   double *M =  ReturnFullMatrixforSymmetric(filler->cell_size);
     808  double *M =  ReturnFullMatrixforSymmetric(World::get()->cell_size);
    813809  double Rotations[NDIM*NDIM];
     810  double *MInverse = InverseMatrix(M);
    814811  Vector AtomTranslations;
    815812  Vector FillerTranslations;
    816813  Vector FillerDistance;
     814  Vector Inserter;
    817815  double FillIt = false;
    818816  atom *Walker = NULL;
    819817  bond *Binder = NULL;
    820   int i = 0;
    821   LinkedCell *LCList[List->ListOfMolecules.size()];
    822818  double phi[NDIM];
    823   class Tesselation *TesselStruct[List->ListOfMolecules.size()];
    824 
    825   Log() << Verbose(0) << "Begin of FillBoxWithMolecule" << endl;
    826 
    827   i=0;
    828   for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) {
    829     Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl;
    830     LCList[i] = new LinkedCell((*ListRunner), 5.); // get linked cell list
    831     if (TesselStruct[i] == NULL) {
    832       Log() << Verbose(1) << "Pre-creating tesselation for molecule " << *ListRunner << "." << endl;
    833       FindNonConvexBorder((*ListRunner), TesselStruct[i], (const LinkedCell *&)LCList[i], 5., NULL);
    834     }
    835     i++;
    836   }
     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      DoLog(1) && (Log() << Verbose(1) << "Pre-creating linked cell lists for molecule " << *ListRunner << "." << endl);
     825      LCList[(*ListRunner)] = new LinkedCell((*ListRunner), 10.); // get linked cell list
     826      DoLog(1) && (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    }
    837830
    838831  // Center filler at origin
    839   filler->CenterOrigin();
     832  filler->CenterEdge(&Inserter);
    840833  filler->Center.Zero();
     834  DoLog(2) && (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    DoLog(2) && (Log() << Verbose(2) << "  " << *Binder << endl);
     839  }
    841840
    842841  filler->CountAtoms();
     
    846845  FillerDistance.Init(distance[0], distance[1], distance[2]);
    847846  FillerDistance.InverseMatrixMultiplication(M);
    848   Log() << Verbose(1) << "INFO: Grid steps are ";
    849   for(int i=0;i<NDIM;i++) {
     847  for(int i=0;i<NDIM;i++)
    850848    N[i] = (int) ceil(1./FillerDistance.x[i]);
    851     Log() << Verbose(0) << N[i];
    852     if (i != NDIM-1)
    853       Log() << Verbose(0)<< ", ";
    854     else
    855       Log() << Verbose(0) << "." << endl;
    856   }
     849  DoLog(1) && (Log() << Verbose(1) << "INFO: Grid steps are " << N[0] << ", " << N[1] << ", " << N[2] << "." << endl);
     850
     851  // initialize seed of random number generator to current time
     852  srand ( time(NULL) );
    857853
    858854  // go over [0,1]^3 filler grid
     
    863859        CurrentPosition.Init((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);
    864860        CurrentPosition.MatrixMultiplication(M);
    865         Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "." << endl;
    866         // Check whether point is in- or outside
    867         FillIt = true;
    868         i=0;
    869         for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) {
    870           // get linked cell list
    871           if (TesselStruct[i] == NULL) {
    872             Log() << Verbose(1) << "ERROR: TesselStruct of " << (*ListRunner) << " is NULL. Didn't we pre-create it?" << endl;
    873             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        DoLog(2) && (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            DoLog(1) && (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            DoLog(4) && (Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl);
    874925          } else {
    875             FillIt = FillIt && (!TesselStruct[i]->IsInnerPoint(CurrentPosition, LCList[i]));
    876             i++;
     926            DoLog(1) && (Log() << Verbose(1) << "INFO: Position at " << Inserter << " is inner point, within boundary or outside of MaxDistance." << endl);
     927            CopyAtoms[Walker->nr] = NULL;
     928            continue;
    877929          }
    878930        }
    879 
    880         if (FillIt) {
    881           // fill in Filler
    882           Log() << Verbose(2) << "Space at " << CurrentPosition << " is unoccupied by any molecule, filling in." << endl;
    883 
    884           // create molecule random translation vector ...
    885           for (int i=0;i<NDIM;i++)
    886             FillerTranslations.x[i] = RandomMolDisplacement*(rand()/(RAND_MAX/2.) - 1.);
    887           Log() << Verbose(3) << "INFO: Translating this filler by " << FillerTranslations << "." << endl;
    888 
    889           // go through all atoms
    890           Walker = filler->start;
    891           while (Walker->next != filler->end) {
    892             Walker = Walker->next;
    893             // copy atom ...
    894             CopyAtoms[Walker->nr] = new atom(Walker);
    895 
    896             // create atomic random translation vector ...
    897             for (int i=0;i<NDIM;i++)
    898               AtomTranslations.x[i] = RandomAtomDisplacement*(rand()/(RAND_MAX/2.) - 1.);
    899 
    900             // ... and rotation matrix
    901             if (DoRandomRotation) {
    902               for (int i=0;i<NDIM;i++) {
    903                 phi[i] = rand()/(RAND_MAX/(2.*M_PI));
    904               }
    905 
    906               Rotations[0] =   cos(phi[0])            *cos(phi[2]) + (sin(phi[0])*sin(phi[1])*sin(phi[2]));
    907               Rotations[3] =   sin(phi[0])            *cos(phi[2]) - (cos(phi[0])*sin(phi[1])*sin(phi[2]));
    908               Rotations[6] =               cos(phi[1])*sin(phi[2])                                     ;
    909               Rotations[1] = - sin(phi[0])*cos(phi[1])                                                ;
    910               Rotations[4] =   cos(phi[0])*cos(phi[1])                                                ;
    911               Rotations[7] =               sin(phi[1])                                                ;
    912               Rotations[3] = - cos(phi[0])            *sin(phi[2]) + (sin(phi[0])*sin(phi[1])*cos(phi[2]));
    913               Rotations[5] = - sin(phi[0])            *sin(phi[2]) - (cos(phi[0])*sin(phi[1])*cos(phi[2]));
    914               Rotations[8] =               cos(phi[1])*cos(phi[2])                                     ;
    915             }
    916 
    917             // ... and put at new position
    918             if (DoRandomRotation)
    919               CopyAtoms[Walker->nr]->x.MatrixMultiplication(Rotations);
    920             CopyAtoms[Walker->nr]->x.AddVector(&AtomTranslations);
    921             CopyAtoms[Walker->nr]->x.AddVector(&FillerTranslations);
    922             CopyAtoms[Walker->nr]->x.AddVector(&CurrentPosition);
    923 
    924             // insert into Filling
    925 
    926             // FIXME: gives completely different results if CopyAtoms[..] used instead of Walker, why???
    927             Log() << Verbose(4) << "Filling atom " << *Walker << ", translated to " << AtomTranslations << ", at final position is " << (CopyAtoms[Walker->nr]->x) << "." << endl;
    928             Filling->AddAtom(CopyAtoms[Walker->nr]);
    929           }
    930 
    931           // go through all bonds and add as well
    932           Binder = filler->first;
    933           while(Binder->next != filler->last) {
    934             Binder = Binder->next;
    935             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;
    936937            Filling->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
    937938          }
    938         } else {
    939           // leave empty
    940           Log() << Verbose(2) << "Space at " << CurrentPosition << " is occupied." << endl;
    941939        }
    942940      }
    943   Log() << Verbose(0) << "End of FillBoxWithMolecule" << endl;
     941  Free(&M);
     942  Free(&MInverse);
    944943
    945944  return Filling;
     
    954953 * \param RADIUS radius of the virtual sphere
    955954 * \param *filename filename prefix for output of vertex data
    956  */
    957 void FindNonConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LCList, const double RADIUS, const char *filename = NULL)
     955 * \return true - tesselation successful, false - tesselation failed
     956 */
     957bool FindNonConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LCList, const double RADIUS, const char *filename = NULL)
    958958{
     959        Info FunctionInfo(__func__);
    959960  bool freeLC = false;
    960   LineMap::iterator baseline;
    961   LineMap::iterator testline;
    962   bool OneLoopWithoutSuccessFlag = false;  // marks whether we went once through all baselines without finding any without two triangles
     961  bool status = false;
     962  CandidateForTesselation *baseline = NULL;
     963  bool OneLoopWithoutSuccessFlag = true;  // marks whether we went once through all baselines without finding any without two triangles
    963964  bool TesselationFailFlag = false;
    964965
    965   Log() << Verbose(1) << "Entering search for non convex hull. " << endl;
    966966  if (TesselStruct == NULL) {
    967     Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl;
     967    DoLog(1) && (Log() << Verbose(1) << "Allocating Tesselation struct ..." << endl);
    968968    TesselStruct= new Tesselation;
    969969  } else {
    970970    delete(TesselStruct);
    971     Log() << Verbose(1) << "Re-Allocating Tesselation struct ..." << endl;
     971    DoLog(1) && (Log() << Verbose(1) << "Re-Allocating Tesselation struct ..." << endl);
    972972    TesselStruct = new Tesselation;
    973973  }
    974 
    975   Log() << Verbose(0) << "Begin of FindNonConvexBorder\n";
    976974
    977975  // initialise Linked Cell
     
    982980
    983981  // 1. get starting triangle
    984   TesselStruct->FindStartingTriangle(RADIUS, LCList);
     982  if (!TesselStruct->FindStartingTriangle(RADIUS, LCList)) {
     983    DoeLog(0) && (eLog() << Verbose(0) << "No valid starting triangle found." << endl);
     984    //performCriticalExit();
     985  }
     986  if (filename != NULL) {
     987    if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration
     988      TesselStruct->Output(filename, mol);
     989    }
     990  }
    985991
    986992  // 2. expand from there
    987   baseline = TesselStruct->LinesOnBoundary.begin();
    988   baseline++; // skip first line
    989   while ((baseline != TesselStruct->LinesOnBoundary.end()) || (OneLoopWithoutSuccessFlag)) {
    990     if (baseline->second->triangles.size() == 1) {
    991       // 3. find next triangle
    992       TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*(baseline->second), *(((baseline->second->triangles.begin()))->second), RADIUS, LCList); //the line is there, so there is a triangle, but only one.
    993       OneLoopWithoutSuccessFlag = OneLoopWithoutSuccessFlag || TesselationFailFlag;
    994       if (!TesselationFailFlag)
    995         eLog() << Verbose(0) << "WARNING: FindNextSuitableTriangle failed." << endl;
    996 
    997       // write temporary envelope
    998       if (filename != NULL) {
    999         if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration
    1000           TesselStruct->Output(filename, mol);
    1001         }
     993  while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
     994    (cerr << "There are " <<  TesselStruct->TrianglesOnBoundary.size() << " triangles and " << TesselStruct->OpenLines.size() << " open lines to scan for candidates." << endl);
     995    // 2a. print OpenLines without candidates
     996    DoLog(1) && (Log() << Verbose(1) << "There are the following open lines to scan for a candidates:" << endl);
     997    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
     998      if (Runner->second->pointlist.empty())
     999        DoLog(1) && (Log() << Verbose(1) << " " << *(Runner->second) << endl);
     1000
     1001    // 2b. find best candidate for each OpenLine
     1002    TesselationFailFlag = TesselStruct->FindCandidatesforOpenLines(RADIUS, LCList);
     1003
     1004    // 2c. print OpenLines with candidates again
     1005    DoLog(1) && (Log() << Verbose(1) << "There are " << TesselStruct->OpenLines.size() << " open lines to scan for the best candidates:" << endl);
     1006    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++)
     1007      DoLog(1) && (Log() << Verbose(1) << " " << *(Runner->second) << endl);
     1008
     1009    // 2d. search for smallest ShortestAngle among all candidates
     1010    double ShortestAngle = 4.*M_PI;
     1011    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
     1012      if (Runner->second->ShortestAngle < ShortestAngle) {
     1013        baseline = Runner->second;
     1014        ShortestAngle = baseline->ShortestAngle;
     1015        DoLog(1) && (Log() << Verbose(1) << "New best candidate is " << *baseline->BaseLine << " with point " << *(*baseline->pointlist.begin()) << " and angle " << baseline->ShortestAngle << endl);
    10021016      }
    1003       baseline = TesselStruct->LinesOnBoundary.end();
    1004       Log() << Verbose(2) << "Baseline set to end." << endl;
    1005     } else {
    1006       //Log() << Verbose(1) << "Line " << *baseline->second << " has " << baseline->second->triangles.size() << " triangles adjacent" << endl;
    1007       if (baseline->second->triangles.size() != 2)
    1008         Log() << Verbose(1) << "ERROR: TESSELATION FINISHED WITH INVALID TRIANGLE COUNT!" << endl;
    1009     }
    1010 
    1011     if ((baseline == TesselStruct->LinesOnBoundary.end()) && (OneLoopWithoutSuccessFlag)) {
    1012       baseline = TesselStruct->LinesOnBoundary.begin();   // restart if we reach end due to newly inserted lines
     1017    }
     1018    // 2e. if we found one, add candidate
     1019    if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
    10131020      OneLoopWithoutSuccessFlag = false;
    1014     }
    1015     baseline++;
    1016   }
    1017   // check envelope for consistency
    1018   CheckListOfBaselines(TesselStruct);
    1019 
    1020   // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles
    1021   //->InsertStraddlingPoints(mol, LCList);
     1021    else {
     1022      TesselStruct->AddCandidatePolygon(*baseline, RADIUS, LCList);
     1023    }
     1024
     1025    // 2f. write temporary envelope
     1026    if (filename != NULL) {
     1027      if ((DoSingleStepOutput && ((TesselStruct->TrianglesOnBoundary.size() % SingleStepWidth == 0)))) { // if we have a new triangle and want to output each new triangle configuration
     1028        TesselStruct->Output(filename, mol);
     1029      }
     1030    }
     1031  }
     1032//  // check envelope for consistency
     1033//  status = CheckListOfBaselines(TesselStruct);
     1034//
     1035//  // look whether all points are inside of the convex envelope, otherwise add them via degenerated triangles
     1036//  //->InsertStraddlingPoints(mol, LCList);
    10221037//  mol->GoToFirst();
    10231038//  class TesselPoint *Runner = NULL;
     
    10341049//  }
    10351050
    1036   // Purges surplus triangles.
    1037   TesselStruct->RemoveDegeneratedTriangles();
     1051//  // Purges surplus triangles.
     1052//  TesselStruct->RemoveDegeneratedTriangles();
    10381053
    10391054  // check envelope for consistency
    1040   CheckListOfBaselines(TesselStruct);
     1055  status = CheckListOfBaselines(TesselStruct);
     1056
     1057  // store before correction
     1058  StoreTrianglesinFile(mol, (const Tesselation *&)TesselStruct, filename, "");
     1059
     1060//  // correct degenerated polygons
     1061//  TesselStruct->CorrectAllDegeneratedPolygons();
     1062//
     1063//  // check envelope for consistency
     1064//  status = CheckListOfBaselines(TesselStruct);
    10411065
    10421066  // write final envelope
     
    10461070  if (freeLC)
    10471071    delete(LCList);
    1048   Log() << Verbose(0) << "End of FindNonConvexBorder\n";
     1072
     1073  return status;
    10491074};
    10501075
     
    10581083Vector* FindEmbeddingHole(MoleculeListClass *mols, molecule *srcmol)
    10591084{
     1085        Info FunctionInfo(__func__);
    10601086  Vector *Center = new Vector;
    10611087  Center->Zero();
  • src/boundary.hpp

    re5ad5c ree7e25  
    3636#define DEBUG 1
    3737#define DoSingleStepOutput 0
    38 #define SingleStepWidth 1
     38#define SingleStepWidth 10
    3939
    4040#define DistancePair pair < double, atom* >
     
    4949
    5050double ConvexizeNonconvexEnvelope(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename);
    51 molecule * FillBoxWithMolecule(MoleculeListClass *List, molecule *filler, config &configuration, double distance[NDIM], double RandAtomDisplacement, double RandMolDisplacement, bool DoRandomRotation);
     51molecule * 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);
    5252void FindConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *LCList, const char *filename);
    5353Vector* FindEmbeddingHole(MoleculeListClass *mols, molecule *srcmol);
    5454void FindNextSuitablePoint(class BoundaryTriangleSet *BaseTriangle, class BoundaryLineSet *BaseLine, atom*& OptCandidate, Vector *OptCandidateCenter, double *ShortestAngle, const double RADIUS, LinkedCell *LC);
    55 void FindNonConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LC, const double RADIUS, const char *tempbasename);
     55bool FindNonConvexBorder(const molecule* const mol, Tesselation *&TesselStruct, const LinkedCell *&LC, const double RADIUS, const char *tempbasename);
    5656Boundaries *GetBoundaryPoints(const molecule *mol, Tesselation *&TesselStruct);
    5757double * GetDiametersOfCluster(const Boundaries *BoundaryPtr, const molecule *mol, Tesselation *&TesselStruct, const bool IsAngstroem);
    5858void PrepareClustersinWater(config *configuration, molecule *mol, double ClusterVolume, double celldensity);
    5959bool RemoveAllBoundaryPoints(class Tesselation *&TesselStruct, const molecule * const mol, const char * const filename);
    60 void StoreTrianglesinFile(const molecule * const mol, const Tesselation *&TesselStruct, const char *filename, const char *extraSuffix);
     60void StoreTrianglesinFile(const molecule * const mol, const Tesselation * const TesselStruct, const char *filename, const char *extraSuffix);
    6161double VolumeOfConvexEnvelope(class Tesselation *TesselStruct, class config *configuration);
    6262
  • src/builder.cpp

    re5ad5c ree7e25  
    5050using namespace std;
    5151
     52#include <cstring>
     53
     54#include "analysis_bonds.hpp"
    5255#include "analysis_correlation.hpp"
    5356#include "atom.hpp"
     
    6568#include "molecule.hpp"
    6669#include "periodentafel.hpp"
     70#include "version.h"
     71#include "World.hpp"
    6772
    6873/********************************************* Subsubmenu routine ************************************/
     
    8186  bool valid;
    8287
    83   Log() << Verbose(0) << "===========ADD ATOM============================" << endl;
    84   Log() << Verbose(0) << " a - state absolute coordinates of atom" << endl;
    85   Log() << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
    86   Log() << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
    87   Log() << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
    88   Log() << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
    89   Log() << Verbose(0) << "all else - go back" << endl;
    90   Log() << Verbose(0) << "===============================================" << endl;
    91   Log() << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
    92   Log() << Verbose(0) << "INPUT: ";
     88  cout << Verbose(0) << "===========ADD ATOM============================" << endl;
     89  cout << Verbose(0) << " a - state absolute coordinates of atom" << endl;
     90  cout << Verbose(0) << " b - state relative coordinates of atom wrt to reference point" << endl;
     91  cout << Verbose(0) << " c - state relative coordinates of atom wrt to already placed atom" << endl;
     92  cout << Verbose(0) << " d - state two atoms, two angles and a distance" << endl;
     93  cout << Verbose(0) << " e - least square distance position to a set of atoms" << endl;
     94  cout << Verbose(0) << "all else - go back" << endl;
     95  cout << Verbose(0) << "===============================================" << endl;
     96  cout << Verbose(0) << "Note: Specifiy angles in degrees not multiples of Pi!" << endl;
     97  cout << Verbose(0) << "INPUT: ";
    9398  cin >> choice;
    9499
    95100  switch (choice) {
    96101    default:
    97       Log() << Verbose(0) << "Not a valid choice." << endl;
     102      DoeLog(2) && (eLog()<< Verbose(2) << "Not a valid choice." << endl);
    98103      break;
    99104      case 'a': // absolute coordinates of atom
    100         Log() << Verbose(0) << "Enter absolute coordinates." << endl;
     105        cout << Verbose(0) << "Enter absolute coordinates." << endl;
    101106        first = new atom;
    102         first->x.AskPosition(mol->cell_size, false);
     107        first->x.AskPosition(World::get()->cell_size, false);
    103108        first->type = periode->AskElement();  // give type
    104109        mol->AddAtom(first);  // add to molecule
     
    109114        valid = true;
    110115        do {
    111           if (!valid) Log() << Verbose(0) << "Resulting position out of cell." << endl;
    112           Log() << Verbose(0) << "Enter reference coordinates." << endl;
    113           x.AskPosition(mol->cell_size, true);
    114           Log() << Verbose(0) << "Enter relative coordinates." << endl;
    115           first->x.AskPosition(mol->cell_size, false);
     116          if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl);
     117          cout << Verbose(0) << "Enter reference coordinates." << endl;
     118          x.AskPosition(World::get()->cell_size, true);
     119          cout << Verbose(0) << "Enter relative coordinates." << endl;
     120          first->x.AskPosition(World::get()->cell_size, false);
    116121          first->x.AddVector((const Vector *)&x);
    117           Log() << Verbose(0) << "\n";
     122          cout << Verbose(0) << "\n";
    118123        } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
    119124        first->type = periode->AskElement();  // give type
     
    125130        valid = true;
    126131        do {
    127           if (!valid) Log() << Verbose(0) << "Resulting position out of cell." << endl;
     132          if (!valid) DoeLog(2) && (eLog()<< Verbose(2) << "Resulting position out of cell." << endl);
    128133          second = mol->AskAtom("Enter atom number: ");
    129           Log() << Verbose(0) << "Enter relative coordinates." << endl;
    130           first->x.AskPosition(mol->cell_size, false);
     134          DoLog(0) && (Log() << Verbose(0) << "Enter relative coordinates." << endl);
     135          first->x.AskPosition(World::get()->cell_size, false);
    131136          for (int i=NDIM;i--;) {
    132137            first->x.x[i] += second->x.x[i];
     
    142147        do {
    143148          if (!valid) {
    144             Log() << Verbose(0) << "Resulting coordinates out of cell - ";
    145             first->x.Output();
    146             Log() << Verbose(0) << endl;
     149            DoeLog(2) && (eLog()<< Verbose(2) << "Resulting coordinates out of cell - " << first->x << endl);
    147150          }
    148           Log() << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
     151          cout << Verbose(0) << "First, we need two atoms, the first atom is the central, while the second is the outer one." << endl;
    149152          second = mol->AskAtom("Enter central atom: ");
    150153          third = mol->AskAtom("Enter second atom (specifying the axis for first angle): ");
     
    157160          c *= M_PI/180.;
    158161          bound(&c, -M_PI, M_PI);
    159           Log() << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
     162          cout << Verbose(0) << "radius: " << a << "\t phi: " << b*180./M_PI << "\t theta: " << c*180./M_PI << endl;
    160163/*
    161164          second->Output(1,1,(ofstream *)&cout);
     
    169172
    170173          if (!z.SolveSystem(&x,&y,&n, b, c, a)) {
    171             Log() << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
     174         coutg() << Verbose(0) << "Failure solving self-dependent linear system!" << endl;
    172175            continue;
    173176          }
    174           Log() << Verbose(0) << "resulting relative coordinates: ";
     177          DoLog(0) && (Log() << Verbose(0) << "resulting relative coordinates: ");
    175178          z.Output();
    176           Log() << Verbose(0) << endl;
     179          DoLog(0) && (Log() << Verbose(0) << endl);
    177180          */
    178181          // calc axis vector
     
    182185          Log() << Verbose(0) << "x: ",
    183186          x.Output();
    184           Log() << Verbose(0) << endl;
     187          DoLog(0) && (Log() << Verbose(0) << endl);
    185188          z.MakeNormalVector(&second->x,&third->x,&fourth->x);
    186189          Log() << Verbose(0) << "z: ",
    187190          z.Output();
    188           Log() << Verbose(0) << endl;
     191          DoLog(0) && (Log() << Verbose(0) << endl);
    189192          y.MakeNormalVector(&x,&z);
    190193          Log() << Verbose(0) << "y: ",
    191194          y.Output();
    192           Log() << Verbose(0) << endl;
     195          DoLog(0) && (Log() << Verbose(0) << endl);
    193196
    194197          // rotate vector around first angle
     
    197200          Log() << Verbose(0) << "Rotated vector: ",
    198201          first->x.Output();
    199           Log() << Verbose(0) << endl;
     202          DoLog(0) && (Log() << Verbose(0) << endl);
    200203          // remove the projection onto the rotation plane of the second angle
    201204          n.CopyVector(&y);
     
    203206          Log() << Verbose(0) << "N1: ",
    204207          n.Output();
    205           Log() << Verbose(0) << endl;
     208          DoLog(0) && (Log() << Verbose(0) << endl);
    206209          first->x.SubtractVector(&n);
    207210          Log() << Verbose(0) << "Subtracted vector: ",
    208211          first->x.Output();
    209           Log() << Verbose(0) << endl;
     212          DoLog(0) && (Log() << Verbose(0) << endl);
    210213          n.CopyVector(&z);
    211214          n.Scale(first->x.ScalarProduct(&z));
    212215          Log() << Verbose(0) << "N2: ",
    213216          n.Output();
    214           Log() << Verbose(0) << endl;
     217          DoLog(0) && (Log() << Verbose(0) << endl);
    215218          first->x.SubtractVector(&n);
    216219          Log() << Verbose(0) << "2nd subtracted vector: ",
    217220          first->x.Output();
    218           Log() << Verbose(0) << endl;
     221          DoLog(0) && (Log() << Verbose(0) << endl);
    219222
    220223          // rotate another vector around second angle
     
    223226          Log() << Verbose(0) << "2nd Rotated vector: ",
    224227          n.Output();
    225           Log() << Verbose(0) << endl;
     228          DoLog(0) && (Log() << Verbose(0) << endl);
    226229
    227230          // add the two linear independent vectors
     
    231234          first->x.AddVector(&second->x);
    232235
    233           Log() << Verbose(0) << "resulting coordinates: ";
     236          DoLog(0) && (Log() << Verbose(0) << "resulting coordinates: ");
    234237          first->x.Output();
    235           Log() << Verbose(0) << endl;
     238          DoLog(0) && (Log() << Verbose(0) << endl);
    236239        } while (!(valid = mol->CheckBounds((const Vector *)&first->x)));
    237240        first->type = periode->AskElement();  // give type
     
    246249          atoms[i] = NULL;
    247250        int i=0, j=0;
    248         Log() << Verbose(0) << "Now we need at least three molecules.\n";
     251        cout << Verbose(0) << "Now we need at least three molecules.\n";
    249252        do {
    250           Log() << Verbose(0) << "Enter " << i+1 << "th atom: ";
     253          cout << Verbose(0) << "Enter " << i+1 << "th atom: ";
    251254          cin >> j;
    252255          if (j != -1) {
     
    263266        } else {
    264267          delete first;
    265           Log() << Verbose(0) << "Please enter at least two vectors!\n";
     268          cout << Verbose(0) << "Please enter at least two vectors!\n";
    266269        }
    267270        break;
     
    277280  char choice;  // menu choice char
    278281
    279   Log() << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
    280   Log() << Verbose(0) << " a - on origin" << endl;
    281   Log() << Verbose(0) << " b - on center of gravity" << endl;
    282   Log() << Verbose(0) << " c - within box with additional boundary" << endl;
    283   Log() << Verbose(0) << " d - within given simulation box" << endl;
    284   Log() << Verbose(0) << "all else - go back" << endl;
    285   Log() << Verbose(0) << "===============================================" << endl;
    286   Log() << Verbose(0) << "INPUT: ";
     282  cout << Verbose(0) << "===========CENTER ATOMS=========================" << endl;
     283  cout << Verbose(0) << " a - on origin" << endl;
     284  cout << Verbose(0) << " b - on center of gravity" << endl;
     285  cout << Verbose(0) << " c - within box with additional boundary" << endl;
     286  cout << Verbose(0) << " d - within given simulation box" << endl;
     287  cout << Verbose(0) << "all else - go back" << endl;
     288  cout << Verbose(0) << "===============================================" << endl;
     289  cout << Verbose(0) << "INPUT: ";
    287290  cin >> choice;
    288291
    289292  switch (choice) {
    290293    default:
    291       Log() << Verbose(0) << "Not a valid choice." << endl;
     294      cout << Verbose(0) << "Not a valid choice." << endl;
    292295      break;
    293296    case 'a':
    294       Log() << Verbose(0) << "Centering atoms in config file on origin." << endl;
     297      cout << Verbose(0) << "Centering atoms in config file on origin." << endl;
    295298      mol->CenterOrigin();
    296299      break;
    297300    case 'b':
    298       Log() << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
     301      cout << Verbose(0) << "Centering atoms in config file on center of gravity." << endl;
    299302      mol->CenterPeriodic();
    300303      break;
    301304    case 'c':
    302       Log() << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
     305      cout << Verbose(0) << "Centering atoms in config file within given additional boundary." << endl;
    303306      for (int i=0;i<NDIM;i++) {
    304         Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
     307        cout << Verbose(0) << "Enter axis " << i << " boundary: ";
    305308        cin >> y.x[i];
    306309      }
     
    313316      break;
    314317    case 'd':
    315       Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
     318      cout << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
    316319      for (int i=0;i<NDIM;i++) {
    317         Log() << Verbose(0) << "Enter axis " << i << " boundary: ";
     320        cout << Verbose(0) << "Enter axis " << i << " boundary: ";
    318321        cin >> x.x[i];
    319322      }
     
    336339  char choice;  // menu choice char
    337340
    338   Log() << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
    339   Log() << Verbose(0) << " a - state three atoms defining align plane" << endl;
    340   Log() << Verbose(0) << " b - state alignment vector" << endl;
    341   Log() << Verbose(0) << " c - state two atoms in alignment direction" << endl;
    342   Log() << Verbose(0) << " d - align automatically by least square fit" << endl;
    343   Log() << Verbose(0) << "all else - go back" << endl;
    344   Log() << Verbose(0) << "===============================================" << endl;
    345   Log() << Verbose(0) << "INPUT: ";
     341  cout << Verbose(0) << "===========ALIGN ATOMS=========================" << endl;
     342  cout << Verbose(0) << " a - state three atoms defining align plane" << endl;
     343  cout << Verbose(0) << " b - state alignment vector" << endl;
     344  cout << Verbose(0) << " c - state two atoms in alignment direction" << endl;
     345  cout << Verbose(0) << " d - align automatically by least square fit" << endl;
     346  cout << Verbose(0) << "all else - go back" << endl;
     347  cout << Verbose(0) << "===============================================" << endl;
     348  cout << Verbose(0) << "INPUT: ";
    346349  cin >> choice;
    347350
     
    356359      break;
    357360    case 'b': // normal vector of mirror plane
    358       Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
    359       n.AskPosition(mol->cell_size,0);
     361      cout << Verbose(0) << "Enter normal vector of mirror plane." << endl;
     362      n.AskPosition(World::get()->cell_size,0);
    360363      n.Normalize();
    361364      break;
     
    376379        fscanf(stdin, "%3s", shorthand);
    377380      } while ((param.type = periode->FindElement(shorthand)) == NULL);
    378       Log() << Verbose(0) << "Element is " << param.type->name << endl;
     381      cout << Verbose(0) << "Element is " << param.type->name << endl;
    379382      mol->GetAlignvector(&param);
    380383      for (int i=NDIM;i--;) {
     
    383386      }
    384387      gsl_vector_free(param.x);
    385       Log() << Verbose(0) << "Offset vector: ";
     388      cout << Verbose(0) << "Offset vector: ";
    386389      x.Output();
    387       Log() << Verbose(0) << endl;
     390      DoLog(0) && (Log() << Verbose(0) << endl);
    388391      n.Normalize();
    389392      break;
    390393  };
    391   Log() << Verbose(0) << "Alignment vector: ";
     394  DoLog(0) && (Log() << Verbose(0) << "Alignment vector: ");
    392395  n.Output();
    393   Log() << Verbose(0) << endl;
     396  DoLog(0) && (Log() << Verbose(0) << endl);
    394397  mol->Align(&n);
    395398};
     
    404407  char choice;  // menu choice char
    405408
    406   Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl;
    407   Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl;
    408   Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl;
    409   Log() << Verbose(0) << " c - state two atoms in normal direction" << endl;
    410   Log() << Verbose(0) << "all else - go back" << endl;
    411   Log() << Verbose(0) << "===============================================" << endl;
    412   Log() << Verbose(0) << "INPUT: ";
     409  DoLog(0) && (Log() << Verbose(0) << "===========MIRROR ATOMS=========================" << endl);
     410  DoLog(0) && (Log() << Verbose(0) << " a - state three atoms defining mirror plane" << endl);
     411  DoLog(0) && (Log() << Verbose(0) << " b - state normal vector of mirror plane" << endl);
     412  DoLog(0) && (Log() << Verbose(0) << " c - state two atoms in normal direction" << endl);
     413  DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
     414  DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
     415  DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
    413416  cin >> choice;
    414417
     
    423426      break;
    424427    case 'b': // normal vector of mirror plane
    425       Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl;
    426       n.AskPosition(mol->cell_size,0);
     428      DoLog(0) && (Log() << Verbose(0) << "Enter normal vector of mirror plane." << endl);
     429      n.AskPosition(World::get()->cell_size,0);
    427430      n.Normalize();
    428431      break;
     
    436439      break;
    437440  };
    438   Log() << Verbose(0) << "Normal vector: ";
     441  DoLog(0) && (Log() << Verbose(0) << "Normal vector: ");
    439442  n.Output();
    440   Log() << Verbose(0) << endl;
     443  DoLog(0) && (Log() << Verbose(0) << endl);
    441444  mol->Mirror((const Vector *)&n);
    442445};
     
    452455  char choice;  // menu choice char
    453456
    454   Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl;
    455   Log() << Verbose(0) << " a - state atom for removal by number" << endl;
    456   Log() << Verbose(0) << " b - keep only in radius around atom" << endl;
    457   Log() << Verbose(0) << " c - remove this with one axis greater value" << endl;
    458   Log() << Verbose(0) << "all else - go back" << endl;
    459   Log() << Verbose(0) << "===============================================" << endl;
    460   Log() << Verbose(0) << "INPUT: ";
     457  DoLog(0) && (Log() << Verbose(0) << "===========REMOVE ATOMS=========================" << endl);
     458  DoLog(0) && (Log() << Verbose(0) << " a - state atom for removal by number" << endl);
     459  DoLog(0) && (Log() << Verbose(0) << " b - keep only in radius around atom" << endl);
     460  DoLog(0) && (Log() << Verbose(0) << " c - remove this with one axis greater value" << endl);
     461  DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
     462  DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
     463  DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
    461464  cin >> choice;
    462465
     
    465468    case 'a':
    466469      if (mol->RemoveAtom(mol->AskAtom("Enter number of atom within molecule: ")))
    467         Log() << Verbose(1) << "Atom removed." << endl;
     470        DoLog(1) && (Log() << Verbose(1) << "Atom removed." << endl);
    468471      else
    469         Log() << Verbose(1) << "Atom not found." << endl;
     472        DoLog(1) && (Log() << Verbose(1) << "Atom not found." << endl);
    470473      break;
    471474    case 'b':
    472475      second = mol->AskAtom("Enter number of atom as reference point: ");
    473       Log() << Verbose(0) << "Enter radius: ";
     476      DoLog(0) && (Log() << Verbose(0) << "Enter radius: ");
    474477      cin >> tmp1;
    475478      first = mol->start;
     
    483486      break;
    484487    case 'c':
    485       Log() << Verbose(0) << "Which axis is it: ";
     488      DoLog(0) && (Log() << Verbose(0) << "Which axis is it: ");
    486489      cin >> axis;
    487       Log() << Verbose(0) << "Lower boundary: ";
     490      DoLog(0) && (Log() << Verbose(0) << "Lower boundary: ");
    488491      cin >> tmp1;
    489       Log() << Verbose(0) << "Upper boundary: ";
     492      DoLog(0) && (Log() << Verbose(0) << "Upper boundary: ");
    490493      cin >> tmp2;
    491494      first = mol->start;
     
    517520  char choice;  // menu choice char
    518521
    519   Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl;
    520   Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl;
    521   Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl;
    522   Log() << Verbose(0) << " c - calculate bond angle" << endl;
    523   Log() << Verbose(0) << " d - calculate principal axis of the system" << endl;
    524   Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl;
    525   Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl;
    526   Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl;
    527   Log() << Verbose(0) << "all else - go back" << endl;
    528   Log() << Verbose(0) << "===============================================" << endl;
    529   Log() << Verbose(0) << "INPUT: ";
     522  DoLog(0) && (Log() << Verbose(0) << "===========MEASURE ATOMS=========================" << endl);
     523  DoLog(0) && (Log() << Verbose(0) << " a - calculate bond length between one atom and all others" << endl);
     524  DoLog(0) && (Log() << Verbose(0) << " b - calculate bond length between two atoms" << endl);
     525  DoLog(0) && (Log() << Verbose(0) << " c - calculate bond angle" << endl);
     526  DoLog(0) && (Log() << Verbose(0) << " d - calculate principal axis of the system" << endl);
     527  DoLog(0) && (Log() << Verbose(0) << " e - calculate volume of the convex envelope" << endl);
     528  DoLog(0) && (Log() << Verbose(0) << " f - calculate temperature from current velocity" << endl);
     529  DoLog(0) && (Log() << Verbose(0) << " g - output all temperatures per step from velocities" << endl);
     530  DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
     531  DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
     532  DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
    530533  cin >> choice;
    531534
    532535  switch(choice) {
    533536    default:
    534       Log() << Verbose(1) << "Not a valid choice." << endl;
     537      DoLog(1) && (Log() << Verbose(1) << "Not a valid choice." << endl);
    535538      break;
    536539    case 'a':
     
    564567      x.SubtractVector((const Vector *)&second->x);
    565568      tmp1 = x.Norm();
    566       Log() << Verbose(1) << "Distance vector is ";
     569      DoLog(1) && (Log() << Verbose(1) << "Distance vector is ");
    567570      x.Output();
    568       Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl;
     571      DoLog(0) && (Log() << Verbose(0) << "." << endl << "Norm of distance is " << tmp1 << "." << endl);
    569572      break;
    570573
    571574    case 'c':
    572       Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl;
     575      DoLog(0) && (Log() << Verbose(0) << "Evaluating bond angle between three - first, central, last - atoms." << endl);
    573576      first = mol->AskAtom("Enter first atom: ");
    574577      second = mol->AskAtom("Enter central atom: ");
     
    579582      y.CopyVector((const Vector *)&third->x);
    580583      y.SubtractVector((const Vector *)&second->x);
    581       Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
    582       Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl;
     584      DoLog(0) && (Log() << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ");
     585      DoLog(0) && (Log() << Verbose(0) << (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.) << " degrees" << endl);
    583586      break;
    584587    case 'd':
    585       Log() << Verbose(0) << "Evaluating prinicipal axis." << endl;
    586       Log() << Verbose(0) << "Shall we rotate? [0/1]: ";
     588      DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
     589      DoLog(0) && (Log() << Verbose(0) << "Shall we rotate? [0/1]: ");
    587590      cin >> Z;
    588591      if ((Z >=0) && (Z <=1))
     
    593596    case 'e':
    594597      {
    595         Log() << Verbose(0) << "Evaluating volume of the convex envelope.";
     598        DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope.");
    596599        class Tesselation *TesselStruct = NULL;
    597600        const LinkedCell *LCList = NULL;
     
    599602        FindConvexBorder(mol, TesselStruct, LCList, NULL);
    600603        double clustervolume = VolumeOfConvexEnvelope(TesselStruct, configuration);
    601         Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl;\
     604        DoLog(0) && (Log() << Verbose(0) << "The tesselated surface area is " << clustervolume << "." << endl);\
    602605        delete(LCList);
    603606        delete(TesselStruct);
     
    610613      {
    611614        char filename[255];
    612         Log() << Verbose(0) << "Please enter filename: " << endl;
     615        DoLog(0) && (Log() << Verbose(0) << "Please enter filename: " << endl);
    613616        cin >> filename;
    614         Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl;
     617        DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << filename << "." << endl);
    615618        ofstream *output = new ofstream(filename, ios::trunc);
    616619        if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
    617           Log() << Verbose(2) << "File could not be written." << endl;
     620          DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
    618621        else
    619           Log() << Verbose(2) << "File stored." << endl;
     622          DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
    620623        output->close();
    621624        delete(output);
     
    634637  clock_t start, end;
    635638
    636   Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
    637   Log() << Verbose(0) << "What's the desired bond order: ";
     639  DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
     640  DoLog(0) && (Log() << Verbose(0) << "What's the desired bond order: ");
    638641  cin >> Order1;
    639642  if (mol->first->next != mol->last) {  // there are bonds
     
    641644    mol->FragmentMolecule(Order1, configuration);
    642645    end = clock();
    643     Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
     646    DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
    644647  } else
    645     Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl;
     648    DoLog(0) && (Log() << Verbose(0) << "Connection matrix has not yet been generated!" << endl);
    646649};
    647650
     
    654657static void ManipulateAtoms(periodentafel *periode, MoleculeListClass *molecules, config *configuration)
    655658{
    656   atom *first, *second;
     659  atom *first, *second, *third;
    657660  molecule *mol = NULL;
    658661  Vector x,y,z,n; // coordinates for absolute point in cell volume
     
    662665  bool valid;
    663666
    664   Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl;
    665   Log() << Verbose(0) << "a - add an atom" << endl;
    666   Log() << Verbose(0) << "r - remove an atom" << endl;
    667   Log() << Verbose(0) << "b - scale a bond between atoms" << endl;
    668   Log() << Verbose(0) << "u - change an atoms element" << endl;
    669   Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl;
    670   Log() << Verbose(0) << "all else - go back" << endl;
    671   Log() << Verbose(0) << "===============================================" << endl;
     667  DoLog(0) && (Log() << Verbose(0) << "=========MANIPULATE ATOMS======================" << endl);
     668  DoLog(0) && (Log() << Verbose(0) << "a - add an atom" << endl);
     669  DoLog(0) && (Log() << Verbose(0) << "r - remove an atom" << endl);
     670  DoLog(0) && (Log() << Verbose(0) << "b - scale a bond between atoms" << endl);
     671  DoLog(0) && (Log() << Verbose(0) << "t - turn an atom round another bond" << endl);
     672  DoLog(0) && (Log() << Verbose(0) << "u - change an atoms element" << endl);
     673  DoLog(0) && (Log() << Verbose(0) << "l - measure lengths, angles, ... for an atom" << endl);
     674  DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
     675  DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
    672676  if (molecules->NumberOfActiveMolecules() > 1)
    673     Log() << Verbose(0) << "WARNING: There is more than one molecule active! Atoms will be added to each." << endl;
    674   Log() << Verbose(0) << "INPUT: ";
     677    DoeLog(2) && (eLog()<< Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl);
     678  DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
    675679  cin >> choice;
    676680
    677681  switch (choice) {
    678682    default:
    679       Log() << Verbose(0) << "Not a valid choice." << endl;
     683      DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
    680684      break;
    681685
     
    684688        if ((*ListRunner)->ActiveFlag) {
    685689        mol = *ListRunner;
    686         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
     690        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
    687691        AddAtoms(periode, mol);
    688692      }
     
    693697        if ((*ListRunner)->ActiveFlag) {
    694698        mol = *ListRunner;
    695         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
    696         Log() << Verbose(0) << "Scaling bond length between two atoms." << endl;
     699        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
     700        DoLog(0) && (Log() << Verbose(0) << "Scaling bond length between two atoms." << endl);
    697701        first = mol->AskAtom("Enter first (fixed) atom: ");
    698702        second = mol->AskAtom("Enter second (shifting) atom: ");
     
    701705          minBond += (first->x.x[i]-second->x.x[i])*(first->x.x[i] - second->x.x[i]);
    702706        minBond = sqrt(minBond);
    703         Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl;
    704         Log() << Verbose(0) << "Enter new bond length [a.u.]: ";
     707        DoLog(0) && (Log() << Verbose(0) << "Current Bond length between " << first->type->name << " Atom " << first->nr << " and " << second->type->name << " Atom " << second->nr << ": " << minBond << " a.u." << endl);
     708        DoLog(0) && (Log() << Verbose(0) << "Enter new bond length [a.u.]: ");
    705709        cin >> bond;
    706710        for (int i=NDIM;i--;) {
     
    716720        if ((*ListRunner)->ActiveFlag) {
    717721        mol = *ListRunner;
    718         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
    719        Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl;
    720        Log() << Verbose(0) << "Enter three factors: ";
     722        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
     723       DoLog(0) && (Log() << Verbose(0) << "Angstroem -> Bohrradius: 1.8897261\t\tBohrradius -> Angstroem: 0.52917721" << endl);
     724       DoLog(0) && (Log() << Verbose(0) << "Enter three factors: ");
    721725       factor = new double[NDIM];
    722726       cin >> factor[0];
     
    733737        if ((*ListRunner)->ActiveFlag) {
    734738        mol = *ListRunner;
    735         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
     739        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
    736740        MeasureAtoms(periode, mol, configuration);
    737741      }
     
    742746        if ((*ListRunner)->ActiveFlag) {
    743747        mol = *ListRunner;
    744         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
     748        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
    745749        RemoveAtoms(mol);
    746750      }
     751      break;
     752
     753    case 't': // turn/rotate atom
     754      for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
     755        if ((*ListRunner)->ActiveFlag) {
     756          mol = *ListRunner;
     757          DoLog(0) && (Log() << Verbose(0) << "Turning atom around another bond - first is atom to turn, second (central) and third specify bond" << endl);
     758          first = mol->AskAtom("Enter turning atom: ");
     759          second = mol->AskAtom("Enter central atom: ");
     760          third  = mol->AskAtom("Enter bond atom: ");
     761          cout << Verbose(0) << "Enter new angle in degrees: ";
     762          double tmp = 0.;
     763          cin >> tmp;
     764          // calculate old angle
     765          x.CopyVector((const Vector *)&first->x);
     766          x.SubtractVector((const Vector *)&second->x);
     767          y.CopyVector((const Vector *)&third->x);
     768          y.SubtractVector((const Vector *)&second->x);
     769          double alpha = (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.);
     770          cout << Verbose(0) << "Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
     771          cout << Verbose(0) << alpha << " degrees" << endl;
     772          // rotate
     773          z.MakeNormalVector(&x,&y);
     774          x.RotateVector(&z,(alpha-tmp)*M_PI/180.);
     775          x.AddVector(&second->x);
     776          first->x.CopyVector(&x);
     777          // check new angle
     778          x.CopyVector((const Vector *)&first->x);
     779          x.SubtractVector((const Vector *)&second->x);
     780          alpha = (acos(x.ScalarProduct((const Vector *)&y)/(y.Norm()*x.Norm()))/M_PI*180.);
     781          cout << Verbose(0) << "new Bond angle between first atom Nr." << first->nr << ", central atom Nr." << second->nr << " and last atom Nr." << third->nr << ": ";
     782          cout << Verbose(0) << alpha << " degrees" << endl;
     783        }
    747784      break;
    748785
     
    752789        int Z;
    753790        mol = *ListRunner;
    754         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
     791        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
    755792        first = NULL;
    756793        do {
    757           Log() << Verbose(0) << "Change the element of which atom: ";
     794          DoLog(0) && (Log() << Verbose(0) << "Change the element of which atom: ");
    758795          cin >> Z;
    759796        } while ((first = mol->FindAtom(Z)) == NULL);
    760         Log() << Verbose(0) << "New element by atomic number Z: ";
     797        DoLog(0) && (Log() << Verbose(0) << "New element by atomic number Z: ");
    761798        cin >> Z;
    762799        first->type = periode->FindElement(Z);
    763         Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl;
     800        DoLog(0) && (Log() << Verbose(0) << "Atom " << first->nr << "'s element is " << first->type->name << "." << endl);
    764801      }
    765802      break;
     
    782819  MoleculeLeafClass *Subgraphs = NULL;
    783820
    784   Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl;
    785   Log() << Verbose(0) << "c - scale by unit transformation" << endl;
    786   Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl;
    787   Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl;
    788   Log() << Verbose(0) << "g - center atoms in box" << endl;
    789   Log() << Verbose(0) << "i - realign molecule" << endl;
    790   Log() << Verbose(0) << "m - mirror all molecules" << endl;
    791   Log() << Verbose(0) << "o - create connection matrix" << endl;
    792   Log() << Verbose(0) << "t - translate molecule by vector" << endl;
    793   Log() << Verbose(0) << "all else - go back" << endl;
    794   Log() << Verbose(0) << "===============================================" << endl;
     821  DoLog(0) && (Log() << Verbose(0) << "=========MANIPULATE GLOBALLY===================" << endl);
     822  DoLog(0) && (Log() << Verbose(0) << "c - scale by unit transformation" << endl);
     823  DoLog(0) && (Log() << Verbose(0) << "d - duplicate molecule/periodic cell" << endl);
     824  DoLog(0) && (Log() << Verbose(0) << "f - fragment molecule many-body bond order style" << endl);
     825  DoLog(0) && (Log() << Verbose(0) << "g - center atoms in box" << endl);
     826  DoLog(0) && (Log() << Verbose(0) << "i - realign molecule" << endl);
     827  DoLog(0) && (Log() << Verbose(0) << "m - mirror all molecules" << endl);
     828  DoLog(0) && (Log() << Verbose(0) << "o - create connection matrix" << endl);
     829  DoLog(0) && (Log() << Verbose(0) << "t - translate molecule by vector" << endl);
     830  DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
     831  DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
    795832  if (molecules->NumberOfActiveMolecules() > 1)
    796     Log() << Verbose(0) << "WARNING: There is more than one molecule active! Atoms will be added to each." << endl;
    797   Log() << Verbose(0) << "INPUT: ";
     833    DoeLog(2) && (eLog()<< Verbose(2) << "There is more than one molecule active! Atoms will be added to each." << endl);
     834  DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
    798835  cin >> choice;
    799836
    800837  switch (choice) {
    801838    default:
    802       Log() << Verbose(0) << "Not a valid choice." << endl;
     839      DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
    803840      break;
    804841
     
    807844        if ((*ListRunner)->ActiveFlag) {
    808845        mol = *ListRunner;
    809         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
    810         Log() << Verbose(0) << "State the axis [(+-)123]: ";
     846        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
     847        DoLog(0) && (Log() << Verbose(0) << "State the axis [(+-)123]: ");
    811848        cin >> axis;
    812         Log() << Verbose(0) << "State the factor: ";
     849        DoLog(0) && (Log() << Verbose(0) << "State the factor: ");
    813850        cin >> faktor;
    814851
     
    827864          }
    828865          if (count != j)
    829             Log() << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
     866            DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
    830867          x.Zero();
    831868          y.Zero();
    832           y.x[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
     869          y.x[abs(axis)-1] = World::get()->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
    833870          for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    834871            x.AddVector(&y); // per factor one cell width further
     
    853890            mol->Translate(&x);
    854891          }
    855           mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
     892          World::get()->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
    856893        }
    857894      }
     
    866903        if ((*ListRunner)->ActiveFlag) {
    867904        mol = *ListRunner;
    868         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
     905        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
    869906        CenterAtoms(mol);
    870907      }
     
    875912        if ((*ListRunner)->ActiveFlag) {
    876913        mol = *ListRunner;
    877         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
     914        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
    878915        AlignAtoms(periode, mol);
    879916      }
     
    884921        if ((*ListRunner)->ActiveFlag) {
    885922        mol = *ListRunner;
    886         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
     923        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
    887924        MirrorAtoms(mol);
    888925      }
     
    895932          double bonddistance;
    896933          clock_t start,end;
    897           Log() << Verbose(0) << "What's the maximum bond distance: ";
     934          DoLog(0) && (Log() << Verbose(0) << "What's the maximum bond distance: ");
    898935          cin >> bonddistance;
    899936          start = clock();
    900937          mol->CreateAdjacencyList(bonddistance, configuration->GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
    901938          end = clock();
    902           Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
     939          DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
    903940        }
    904941      break;
     
    908945        if ((*ListRunner)->ActiveFlag) {
    909946        mol = *ListRunner;
    910         Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl;
    911         Log() << Verbose(0) << "Enter translation vector." << endl;
    912         x.AskPosition(mol->cell_size,0);
     947        DoLog(0) && (Log() << Verbose(0) << "Current molecule is: " << mol->IndexNr << "\t" << mol->name << endl);
     948        DoLog(0) && (Log() << Verbose(0) << "Enter translation vector." << endl);
     949        x.AskPosition(World::get()->cell_size,0);
    913950        mol->Center.AddVector((const Vector *)&x);
    914951     }
     
    937974  molecule *mol = NULL;
    938975
    939   Log() << Verbose(0) << "==========EDIT MOLECULES=====================" << endl;
    940   Log() << Verbose(0) << "c - create new molecule" << endl;
    941   Log() << Verbose(0) << "l - load molecule from xyz file" << endl;
    942   Log() << Verbose(0) << "n - change molecule's name" << endl;
    943   Log() << Verbose(0) << "N - give molecules filename" << endl;
    944   Log() << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl;
    945   Log() << Verbose(0) << "r - remove a molecule" << endl;
    946   Log() << Verbose(0) << "all else - go back" << endl;
    947   Log() << Verbose(0) << "===============================================" << endl;
    948   Log() << Verbose(0) << "INPUT: ";
     976  DoLog(0) && (Log() << Verbose(0) << "==========EDIT MOLECULES=====================" << endl);
     977  DoLog(0) && (Log() << Verbose(0) << "c - create new molecule" << endl);
     978  DoLog(0) && (Log() << Verbose(0) << "l - load molecule from xyz file" << endl);
     979  DoLog(0) && (Log() << Verbose(0) << "n - change molecule's name" << endl);
     980  DoLog(0) && (Log() << Verbose(0) << "N - give molecules filename" << endl);
     981  DoLog(0) && (Log() << Verbose(0) << "p - parse atoms in xyz file into molecule" << endl);
     982  DoLog(0) && (Log() << Verbose(0) << "r - remove a molecule" << endl);
     983  DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
     984  DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
     985  DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
    949986  cin >> choice;
    950987
    951988  switch (choice) {
    952989    default:
    953       Log() << Verbose(0) << "Not a valid choice." << endl;
     990      DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
    954991      break;
    955992    case 'c':
     
    961998      {
    962999        char filename[MAXSTRINGSIZE];
    963         Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
     1000        DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl);
    9641001        mol = new molecule(periode);
    9651002        do {
    966           Log() << Verbose(0) << "Enter file name: ";
     1003          DoLog(0) && (Log() << Verbose(0) << "Enter file name: ");
    9671004          cin >> filename;
    9681005        } while (!mol->AddXYZFile(filename));
     
    9701007        // center at set box dimensions
    9711008        mol->CenterEdge(&center);
    972         mol->cell_size[0] = center.x[0];
    973         mol->cell_size[1] = 0;
    974         mol->cell_size[2] = center.x[1];
    975         mol->cell_size[3] = 0;
    976         mol->cell_size[4] = 0;
    977         mol->cell_size[5] = center.x[2];
     1009        double * const cell_size = World::get()->cell_size;
     1010        cell_size[0] = center.x[0];
     1011        cell_size[1] = 0;
     1012        cell_size[2] = center.x[1];
     1013        cell_size[3] = 0;
     1014        cell_size[4] = 0;
     1015        cell_size[5] = center.x[2];
    9781016        molecules->insert(mol);
    9791017      }
     
    9841022        char filename[MAXSTRINGSIZE];
    9851023        do {
    986           Log() << Verbose(0) << "Enter index of molecule: ";
     1024          DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
    9871025          cin >> nr;
    9881026          mol = molecules->ReturnIndex(nr);
    9891027        } while (mol == NULL);
    990         Log() << Verbose(0) << "Enter name: ";
     1028        DoLog(0) && (Log() << Verbose(0) << "Enter name: ");
    9911029        cin >> filename;
    9921030        strcpy(mol->name, filename);
     
    9981036        char filename[MAXSTRINGSIZE];
    9991037        do {
    1000           Log() << Verbose(0) << "Enter index of molecule: ";
     1038          DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
    10011039          cin >> nr;
    10021040          mol = molecules->ReturnIndex(nr);
    10031041        } while (mol == NULL);
    1004         Log() << Verbose(0) << "Enter name: ";
     1042        DoLog(0) && (Log() << Verbose(0) << "Enter name: ");
    10051043        cin >> filename;
    10061044        mol->SetNameFromFilename(filename);
     
    10131051        mol = NULL;
    10141052        do {
    1015           Log() << Verbose(0) << "Enter index of molecule: ";
     1053          DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
    10161054          cin >> nr;
    10171055          mol = molecules->ReturnIndex(nr);
    10181056        } while (mol == NULL);
    1019         Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl;
     1057        DoLog(0) && (Log() << Verbose(0) << "Format should be XYZ with: ShorthandOfElement\tX\tY\tZ" << endl);
    10201058        do {
    1021           Log() << Verbose(0) << "Enter file name: ";
     1059          DoLog(0) && (Log() << Verbose(0) << "Enter file name: ");
    10221060          cin >> filename;
    10231061        } while (!mol->AddXYZFile(filename));
     
    10271065
    10281066    case 'r':
    1029       Log() << Verbose(0) << "Enter index of molecule: ";
     1067      DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
    10301068      cin >> nr;
    10311069      count = 1;
     
    10501088  char choice;  // menu choice char
    10511089
    1052   Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl;
    1053   Log() << Verbose(0) << "a - simple add of one molecule to another" << endl;
    1054   Log() << Verbose(0) << "e - embedding merge of two molecules" << endl;
    1055   Log() << Verbose(0) << "m - multi-merge of all molecules" << endl;
    1056   Log() << Verbose(0) << "s - scatter merge of two molecules" << endl;
    1057   Log() << Verbose(0) << "t - simple merge of two molecules" << endl;
    1058   Log() << Verbose(0) << "all else - go back" << endl;
    1059   Log() << Verbose(0) << "===============================================" << endl;
    1060   Log() << Verbose(0) << "INPUT: ";
     1090  DoLog(0) && (Log() << Verbose(0) << "===========MERGE MOLECULES=====================" << endl);
     1091  DoLog(0) && (Log() << Verbose(0) << "a - simple add of one molecule to another" << endl);
     1092  DoLog(0) && (Log() << Verbose(0) << "b - count the number of bonds of two elements" << endl);
     1093  DoLog(0) && (Log() << Verbose(0) << "B - count the number of bonds of three elements " << endl);
     1094  DoLog(0) && (Log() << Verbose(0) << "e - embedding merge of two molecules" << endl);
     1095  DoLog(0) && (Log() << Verbose(0) << "h - count the number of hydrogen bonds" << endl);
     1096  DoLog(0) && (Log() << Verbose(0) << "b - count the number of hydrogen bonds" << endl);
     1097  DoLog(0) && (Log() << Verbose(0) << "m - multi-merge of all molecules" << endl);
     1098  DoLog(0) && (Log() << Verbose(0) << "s - scatter merge of two molecules" << endl);
     1099  DoLog(0) && (Log() << Verbose(0) << "t - simple merge of two molecules" << endl);
     1100  DoLog(0) && (Log() << Verbose(0) << "all else - go back" << endl);
     1101  DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
     1102  DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
    10611103  cin >> choice;
    10621104
    10631105  switch (choice) {
    10641106    default:
    1065       Log() << Verbose(0) << "Not a valid choice." << endl;
     1107      DoLog(0) && (Log() << Verbose(0) << "Not a valid choice." << endl);
    10661108      break;
    10671109
     
    10721114        {
    10731115          do {
    1074             Log() << Verbose(0) << "Enter index of destination molecule: ";
     1116            DoLog(0) && (Log() << Verbose(0) << "Enter index of destination molecule: ");
    10751117            cin >> dest;
    10761118            destmol = molecules->ReturnIndex(dest);
    10771119          } while ((destmol == NULL) && (dest != -1));
    10781120          do {
    1079             Log() << Verbose(0) << "Enter index of source molecule to add from: ";
     1121            DoLog(0) && (Log() << Verbose(0) << "Enter index of source molecule to add from: ");
    10801122            cin >> src;
    10811123            srcmol = molecules->ReturnIndex(src);
     
    10871129      break;
    10881130
     1131    case 'b':
     1132      {
     1133        const int nr = 2;
     1134        char *names[nr] = {"first", "second"};
     1135        int Z[nr];
     1136        element *elements[nr];
     1137        for (int i=0;i<nr;i++) {
     1138          Z[i] = 0;
     1139          do {
     1140            cout << "Enter " << names[i] << " element: ";
     1141            cin >> Z[i];
     1142          } while ((Z[i] <= 0) && (Z[i] > MAX_ELEMENTS));
     1143          elements[i] = periode->FindElement(Z[i]);
     1144        }
     1145        const int count = CountBondsOfTwo(molecules, elements[0], elements[1]);
     1146        cout << endl << "There are " << count << " ";
     1147        for (int i=0;i<nr;i++) {
     1148          if (i==0)
     1149            cout << elements[i]->symbol;
     1150          else
     1151            cout << "-" << elements[i]->symbol;
     1152        }
     1153        cout << " bonds." << endl;
     1154      }
     1155    break;
     1156
     1157    case 'B':
     1158      {
     1159        const int nr = 3;
     1160        char *names[nr] = {"first", "second", "third"};
     1161        int Z[nr];
     1162        element *elements[nr];
     1163        for (int i=0;i<nr;i++) {
     1164          Z[i] = 0;
     1165          do {
     1166            cout << "Enter " << names[i] << " element: ";
     1167            cin >> Z[i];
     1168          } while ((Z[i] <= 0) && (Z[i] > MAX_ELEMENTS));
     1169          elements[i] = periode->FindElement(Z[i]);
     1170        }
     1171        const int count = CountBondsOfThree(molecules, elements[0], elements[1], elements[2]);
     1172        cout << endl << "There are " << count << " ";
     1173        for (int i=0;i<nr;i++) {
     1174          if (i==0)
     1175            cout << elements[i]->symbol;
     1176          else
     1177            cout << "-" << elements[i]->symbol;
     1178        }
     1179        cout << " bonds." << endl;
     1180      }
     1181    break;
     1182
    10891183    case 'e':
    10901184      {
     
    10921186        molecule *srcmol = NULL, *destmol = NULL;
    10931187        do {
    1094           Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): ";
     1188          DoLog(0) && (Log() << Verbose(0) << "Enter index of matrix molecule (the variable one): ");
    10951189          cin >> src;
    10961190          srcmol = molecules->ReturnIndex(src);
    10971191        } while ((srcmol == NULL) && (src != -1));
    10981192        do {
    1099           Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ";
     1193          DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule to merge into (the fixed one): ");
    11001194          cin >> dest;
    11011195          destmol = molecules->ReturnIndex(dest);
     
    11061200      break;
    11071201
     1202    case 'h':
     1203      {
     1204        int Z;
     1205        cout << "Please enter interface element: ";
     1206        cin >> Z;
     1207        element * const InterfaceElement = periode->FindElement(Z);
     1208        cout << endl << "There are " << CountHydrogenBridgeBonds(molecules, InterfaceElement) << " hydrogen bridges with connections to " << (InterfaceElement != 0 ? InterfaceElement->name : "None") << "." << endl;
     1209      }
     1210      break;
     1211
    11081212    case 'm':
    11091213      {
     
    11111215        molecule *mol = NULL;
    11121216        do {
    1113           Log() << Verbose(0) << "Enter index of molecule to merge into: ";
     1217          DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule to merge into: ");
    11141218          cin >> nr;
    11151219          mol = molecules->ReturnIndex(nr);
     
    11281232
    11291233    case 's':
    1130       Log() << Verbose(0) << "Not implemented yet." << endl;
     1234      DoLog(0) && (Log() << Verbose(0) << "Not implemented yet." << endl);
    11311235      break;
    11321236
     
    11371241        {
    11381242          do {
    1139             Log() << Verbose(0) << "Enter index of destination molecule: ";
     1243            DoLog(0) && (Log() << Verbose(0) << "Enter index of destination molecule: ");
    11401244            cin >> dest;
    11411245            destmol = molecules->ReturnIndex(dest);
    11421246          } while ((destmol == NULL) && (dest != -1));
    11431247          do {
    1144             Log() << Verbose(0) << "Enter index of source molecule to merge into: ";
     1248            DoLog(0) && (Log() << Verbose(0) << "Enter index of source molecule to merge into: ");
    11451249            cin >> src;
    11461250            srcmol = molecules->ReturnIndex(src);
     
    11711275    mol = (molecules->ListOfMolecules.front())->CopyMolecule();
    11721276  else {
    1173     eLog() << Verbose(0) << "I don't have anything to test on ... ";
     1277    DoeLog(0) && (eLog()<< Verbose(0) << "I don't have anything to test on ... ");
     1278    performCriticalExit();
    11741279    return;
    11751280  }
     
    11771282
    11781283  // generate some KeySets
    1179   Log() << Verbose(0) << "Generating KeySets." << endl;
     1284  DoLog(0) && (Log() << Verbose(0) << "Generating KeySets." << endl);
    11801285  KeySet TestSets[mol->AtomCount+1];
    11811286  i=1;
     
    11871292    i++;
    11881293  }
    1189   Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl;
     1294  DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in KeySets." << endl);
    11901295  KeySetTestPair test;
    11911296  test = TestSets[mol->AtomCount-1].insert(Walker->nr);
    11921297  if (test.second) {
    1193     Log() << Verbose(1) << "Insertion worked?!" << endl;
     1298    DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl);
    11941299  } else {
    1195     Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl;
     1300    DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*test.first) << "." << endl);
    11961301  }
    11971302  TestSets[mol->AtomCount].insert(mol->end->previous->nr);
     
    11991304
    12001305  // constructing Graph structure
    1201   Log() << Verbose(0) << "Generating Subgraph class." << endl;
     1306  DoLog(0) && (Log() << Verbose(0) << "Generating Subgraph class." << endl);
    12021307  Graph Subgraphs;
    12031308
    12041309  // insert KeySets into Subgraphs
    1205   Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl;
     1310  DoLog(0) && (Log() << Verbose(0) << "Inserting KeySets into Subgraph class." << endl);
    12061311  for (int j=0;j<mol->AtomCount;j++) {
    12071312    Subgraphs.insert(GraphPair (TestSets[j],pair<int, double>(counter++, 1.)));
    12081313  }
    1209   Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl;
     1314  DoLog(0) && (Log() << Verbose(0) << "Testing insertion of already present item in Subgraph." << endl);
    12101315  GraphTestPair test2;
    12111316  test2 = Subgraphs.insert(GraphPair (TestSets[mol->AtomCount],pair<int, double>(counter++, 1.)));
    12121317  if (test2.second) {
    1213     Log() << Verbose(1) << "Insertion worked?!" << endl;
     1318    DoLog(1) && (Log() << Verbose(1) << "Insertion worked?!" << endl);
    12141319  } else {
    1215     Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl;
     1320    DoLog(1) && (Log() << Verbose(1) << "Insertion rejected: Present object is " << (*(test2.first)).second.first << "." << endl);
    12161321  }
    12171322
    12181323  // show graphs
    1219   Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl;
     1324  DoLog(0) && (Log() << Verbose(0) << "Showing Subgraph's contents, checking that it's sorted." << endl);
    12201325  Graph::iterator A = Subgraphs.begin();
    12211326  while (A !=  Subgraphs.end()) {
    1222     Log() << Verbose(0) << (*A).second.first << ": ";
     1327    DoLog(0) && (Log() << Verbose(0) << (*A).second.first << ": ");
    12231328    KeySet::iterator key = (*A).first.begin();
    12241329    comp = -1;
    12251330    while (key != (*A).first.end()) {
    12261331      if ((*key) > comp)
    1227         Log() << Verbose(0) << (*key) << " ";
     1332        DoLog(0) && (Log() << Verbose(0) << (*key) << " ");
    12281333      else
    1229         Log() << Verbose(0) << (*key) << "! ";
     1334        DoLog(0) && (Log() << Verbose(0) << (*key) << "! ");
    12301335      comp = (*key);
    12311336      key++;
    12321337    }
    1233     Log() << Verbose(0) << endl;
     1338    DoLog(0) && (Log() << Verbose(0) << endl);
    12341339    A++;
    12351340  }
     
    12481353  ofstream output;
    12491354  molecule *mol = new molecule(periode);
     1355  mol->SetNameFromFilename(ConfigFileName);
     1356
     1357  if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
     1358    DoeLog(2) && (eLog()<< Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl);
     1359  }
     1360
     1361
     1362  // first save as PDB data
     1363  if (ConfigFileName != NULL)
     1364    strcpy(filename, ConfigFileName);
     1365  if (output == NULL)
     1366    strcpy(filename,"main_pcp_linux");
     1367  DoLog(0) && (Log() << Verbose(0) << "Saving as pdb input ");
     1368  if (configuration->SavePDB(filename, molecules))
     1369    DoLog(0) && (Log() << Verbose(0) << "done." << endl);
     1370  else
     1371    DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
     1372
     1373  // then save as tremolo data file
     1374  if (ConfigFileName != NULL)
     1375    strcpy(filename, ConfigFileName);
     1376  if (output == NULL)
     1377    strcpy(filename,"main_pcp_linux");
     1378  DoLog(0) && (Log() << Verbose(0) << "Saving as tremolo data input ");
     1379  if (configuration->SaveTREMOLO(filename, molecules))
     1380    DoLog(0) && (Log() << Verbose(0) << "done." << endl);
     1381  else
     1382    DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
    12501383
    12511384  // translate each to its center and merge all molecules in MoleculeListClass into this molecule
     
    12671400  }
    12681401
    1269   Log() << Verbose(0) << "Storing configuration ... " << endl;
     1402  DoLog(0) && (Log() << Verbose(0) << "Storing configuration ... " << endl);
    12701403  // get correct valence orbitals
    12711404  mol->CalculateOrbitals(*configuration);
     
    12831416  output.close();
    12841417  output.clear();
    1285   Log() << Verbose(0) << "Saving of config file ";
     1418  DoLog(0) && (Log() << Verbose(0) << "Saving of config file ");
    12861419  if (configuration->Save(filename, periode, mol))
    1287     Log() << Verbose(0) << "successful." << endl;
     1420    DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
    12881421  else
    1289     Log() << Verbose(0) << "failed." << endl;
     1422    DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
    12901423
    12911424  // and save to xyz file
     
    13001433    output.open(filename, ios::trunc);
    13011434  }
    1302   Log() << Verbose(0) << "Saving of XYZ file ";
     1435  DoLog(0) && (Log() << Verbose(0) << "Saving of XYZ file ");
    13031436  if (mol->MDSteps <= 1) {
    13041437    if (mol->OutputXYZ(&output))
    1305       Log() << Verbose(0) << "successful." << endl;
     1438      DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
    13061439    else
    1307       Log() << Verbose(0) << "failed." << endl;
     1440      DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
    13081441  } else {
    13091442    if (mol->OutputTrajectoriesXYZ(&output))
    1310       Log() << Verbose(0) << "successful." << endl;
     1443      DoLog(0) && (Log() << Verbose(0) << "successful." << endl);
    13111444    else
    1312       Log() << Verbose(0) << "failed." << endl;
     1445      DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
    13131446  }
    13141447  output.close();
     
    13201453  if (output == NULL)
    13211454    strcpy(filename,"main_pcp_linux");
    1322   Log() << Verbose(0) << "Saving as mpqc input ";
     1455  DoLog(0) && (Log() << Verbose(0) << "Saving as mpqc input ");
    13231456  if (configuration->SaveMPQC(filename, mol))
    1324     Log() << Verbose(0) << "done." << endl;
     1457    DoLog(0) && (Log() << Verbose(0) << "done." << endl);
    13251458  else
    1326     Log() << Verbose(0) << "failed." << endl;
     1459    DoLog(0) && (Log() << Verbose(0) << "failed." << endl);
    13271460
    13281461  if (!strcmp(configuration->configpath, configuration->GetDefaultPath())) {
    1329     eLog() << Verbose(0) << "WARNING: config is found under different path then stated in config file::defaultpath!" << endl;
     1462    DoeLog(2) && (eLog()<< Verbose(2) << "config is found under different path then stated in config file::defaultpath!" << endl);
    13301463  }
     1464
    13311465  delete(mol);
    13321466};
     
    13561490  enum ConfigStatus configPresent = absent;
    13571491  clock_t start,end;
     1492  double MaxDistance = -1;
    13581493  int argptr;
    13591494  molecule *mol = NULL;
    1360   string BondGraphFileName("");
     1495  string BondGraphFileName("\n");
     1496  int verbosity = 0;
    13611497  strncpy(configuration.databasepath, LocalPath, MAXSTRINGSIZE-1);
    13621498
     
    13661502    do {
    13671503      if (argv[argptr][0] == '-') {
    1368         Log() << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n";
     1504        DoLog(0) && (Log() << Verbose(0) << "Recognized command line argument: " << argv[argptr][1] << ".\n");
    13691505        argptr++;
    13701506        switch(argv[argptr-1][1]) {
     
    13721508          case 'H':
    13731509          case '?':
    1374             Log() << Verbose(0) << "MoleCuilder suite" << endl << "==================" << endl << endl;
    1375             Log() << Verbose(0) << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl;
    1376             Log() << Verbose(0) << "or simply " << argv[0] << " without arguments for interactive session." << endl;
    1377             Log() << Verbose(0) << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl;
    1378             Log() << Verbose(0) << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl;
    1379             Log() << Verbose(0) << "\t-b xx xy xz yy yz zz\tCenter atoms in domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl;
    1380             Log() << Verbose(0) << "\t-B xx xy xz yy yz zz\tBound atoms by domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl;
    1381             Log() << Verbose(0) << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl;
    1382             Log() << Verbose(0) << "\t-C\tPair Correlation analysis." << endl;
    1383             Log() << Verbose(0) << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl;
    1384             Log() << Verbose(0) << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl;
    1385             Log() << Verbose(0) << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl;
    1386             Log() << Verbose(0) << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl;
    1387             Log() << Verbose(0) << "\t-f/F <dist> <order>\tFragments the molecule in BOSSANOVA manner (with/out rings compressed) and stores config files in same dir as config (return code 0 - fragmented, 2 - no fragmentation necessary)." << endl;
    1388             Log() << Verbose(0) << "\t-g <file>\tParses a bond length table from the given file." << endl;
    1389             Log() << Verbose(0) << "\t-h/-H/-?\tGive this help screen." << endl;
    1390             Log() << Verbose(0) << "\t-L <step0> <step1> <prefix>\tStore a linear interpolation between two configurations <step0> and <step1> into single config files with prefix <prefix> and as Trajectories into the current config file." << endl;
    1391             Log() << Verbose(0) << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl;
    1392             Log() << Verbose(0) << "\t-M <basis>\tSetting basis to store to MPQC config files." << endl;
    1393             Log() << Verbose(0) << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl;
    1394             Log() << Verbose(0) << "\t-N <radius> <file>\tGet non-convex-envelope." << endl;
    1395             Log() << Verbose(0) << "\t-o <out>\tGet volume of the convex envelope (and store to tecplot file)." << endl;
    1396             Log() << Verbose(0) << "\t-O\tCenter atoms in origin." << endl;
    1397             Log() << Verbose(0) << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl;
    1398             Log() << Verbose(0) << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl;
    1399             Log() << Verbose(0) << "\t-r <id>\t\tRemove an atom with given id." << endl;
    1400             Log() << Verbose(0) << "\t-R <id> <radius>\t\tRemove all atoms out of sphere around a given one." << endl;
    1401             Log() << Verbose(0) << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl;
    1402             Log() << Verbose(0) << "\t-S <file> Store temperatures from the config file in <file>." << endl;
    1403             Log() << Verbose(0) << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl;
    1404             Log() << Verbose(0) << "\t-T x1 x2 x3\tTranslate periodically all atoms by this vector (x1,x2,x3)." << endl;
    1405             Log() << Verbose(0) << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl;
    1406             Log() << Verbose(0) << "\t-v/-V\t\tGives version information." << endl;
    1407             Log() << Verbose(0) << "Note: config files must not begin with '-' !" << endl;
     1510            DoLog(0) && (Log() << Verbose(0) << "MoleCuilder suite" << endl << "==================" << endl << endl);
     1511            DoLog(0) && (Log() << Verbose(0) << "Usage: " << argv[0] << "[config file] [-{acefpsthH?vfrp}] [further arguments]" << endl);
     1512            DoLog(0) && (Log() << Verbose(0) << "or simply " << argv[0] << " without arguments for interactive session." << endl);
     1513            DoLog(0) && (Log() << Verbose(0) << "\t-a Z x1 x2 x3\tAdd new atom of element Z at coordinates (x1,x2,x3)." << endl);
     1514            DoLog(0) && (Log() << Verbose(0) << "\t-A <source>\tCreate adjacency list from bonds parsed from 'dbond'-style file." <<endl);
     1515            DoLog(0) && (Log() << Verbose(0) << "\t-b xx xy xz yy yz zz\tCenter atoms in domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl);
     1516            DoLog(0) && (Log() << Verbose(0) << "\t-B xx xy xz yy yz zz\tBound atoms by domain with given symmetric matrix of (xx,xy,xz,yy,yz,zz)." << endl);
     1517            DoLog(0) && (Log() << Verbose(0) << "\t-c x1 x2 x3\tCenter atoms in domain with a minimum distance to boundary of (x1,x2,x3)." << endl);
     1518            DoLog(0) && (Log() << Verbose(0) << "\t-C <type> [params] <output> <bin output> <BinWidth> <BinStart> <BinEnd>\tPair Correlation analysis." << endl);
     1519            DoLog(0) && (Log() << Verbose(0) << "\t-d x1 x2 x3\tDuplicate cell along each axis by given factor." << endl);
     1520            DoLog(0) && (Log() << Verbose(0) << "\t-D <bond distance>\tDepth-First-Search Analysis of the molecule, giving cycles and tree/back edges." << endl);
     1521            DoLog(0) && (Log() << Verbose(0) << "\t-e <file>\tSets the databases path to be parsed (default: ./)." << endl);
     1522            DoLog(0) && (Log() << Verbose(0) << "\t-E <id> <Z>\tChange atom <id>'s element to <Z>, <id> begins at 0." << endl);
     1523            DoLog(0) && (Log() << Verbose(0) << "\t-f <dist> <order>\tFragments the molecule in BOSSANOVA manner (with/out rings compressed) and stores config files in same dir as config (return code 0 - fragmented, 2 - no fragmentation necessary)." << endl);
     1524            DoLog(0) && (Log() << Verbose(0) << "\t-F <xyz of filler> <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>\tFilling Box with water molecules." << endl);
     1525            DoLog(0) && (Log() << Verbose(0) << "\t-FF <MaxDistance> <xyz of filler> <dist_x> <dist_y> <dist_z> <epsilon> <randatom> <randmol> <DoRotate>\tFilling Box with water molecules." << endl);
     1526            DoLog(0) && (Log() << Verbose(0) << "\t-g <file>\tParses a bond length table from the given file." << endl);
     1527            DoLog(0) && (Log() << Verbose(0) << "\t-h/-H/-?\tGive this help screen." << endl);
     1528            DoLog(0) && (Log() << Verbose(0) << "\t-I\t Dissect current system of molecules into a set of disconnected (subgraphs of) molecules." << endl);
     1529            DoLog(0) && (Log() << Verbose(0) << "\t-j\t<path> Store all bonds to file." << endl);
     1530            DoLog(0) && (Log() << Verbose(0) << "\t-J\t<path> Store adjacency per atom to file." << endl);
     1531            DoLog(0) && (Log() << Verbose(0) << "\t-L <step0> <step1> <prefix>\tStore a linear interpolation between two configurations <step0> and <step1> into single config files with prefix <prefix> and as Trajectories into the current config file." << endl);
     1532            DoLog(0) && (Log() << Verbose(0) << "\t-m <0/1>\tCalculate (0)/ Align in(1) PAS with greatest EV along z axis." << endl);
     1533            DoLog(0) && (Log() << Verbose(0) << "\t-M <basis>\tSetting basis to store to MPQC config files." << endl);
     1534            DoLog(0) && (Log() << Verbose(0) << "\t-n\tFast parsing (i.e. no trajectories are looked for)." << endl);
     1535            DoLog(0) && (Log() << Verbose(0) << "\t-N <radius> <file>\tGet non-convex-envelope." << endl);
     1536            DoLog(0) && (Log() << Verbose(0) << "\t-o <out>\tGet volume of the convex envelope (and store to tecplot file)." << endl);
     1537            DoLog(0) && (Log() << Verbose(0) << "\t-O\tCenter atoms in origin." << endl);
     1538            DoLog(0) && (Log() << Verbose(0) << "\t-p <file>\tParse given xyz file and create raw config file from it." << endl);
     1539            DoLog(0) && (Log() << Verbose(0) << "\t-P <file>\tParse given forces file and append as an MD step to config file via Verlet." << endl);
     1540            DoLog(0) && (Log() << Verbose(0) << "\t-r <id>\t\tRemove an atom with given id." << endl);
     1541            DoLog(0) && (Log() << Verbose(0) << "\t-R <id> <radius>\t\tRemove all atoms out of sphere around a given one." << endl);
     1542            DoLog(0) && (Log() << Verbose(0) << "\t-s x1 x2 x3\tScale all atom coordinates by this vector (x1,x2,x3)." << endl);
     1543            DoLog(0) && (Log() << Verbose(0) << "\t-S <file> Store temperatures from the config file in <file>." << endl);
     1544            DoLog(0) && (Log() << Verbose(0) << "\t-t x1 x2 x3\tTranslate all atoms by this vector (x1,x2,x3)." << endl);
     1545            DoLog(0) && (Log() << Verbose(0) << "\t-T x1 x2 x3\tTranslate periodically all atoms by this vector (x1,x2,x3)." << endl);
     1546            DoLog(0) && (Log() << Verbose(0) << "\t-u rho\tsuspend in water solution and output necessary cell lengths, average density rho and repetition." << endl);
     1547            DoLog(0) && (Log() << Verbose(0) << "\t-v\t\tsets verbosity (more is more)." << endl);
     1548            DoLog(0) && (Log() << Verbose(0) << "\t-V\t\tGives version information." << endl);
     1549            DoLog(0) && (Log() << Verbose(0) << "\t-X\t\tset default name of a molecule." << endl);
     1550            DoLog(0) && (Log() << Verbose(0) << "Note: config files must not begin with '-' !" << endl);
    14081551            return (1);
    14091552            break;
    14101553          case 'v':
     1554            while (argv[argptr-1][verbosity+1] == 'v') {
     1555              verbosity++;
     1556            }
     1557            setVerbosity(verbosity);
     1558            DoLog(0) && (Log() << Verbose(0) << "Setting verbosity to " << verbosity << "." << endl);
     1559            break;
    14111560          case 'V':
    1412             Log() << Verbose(0) << argv[0] << " " << VERSIONSTRING << endl;
    1413             Log() << Verbose(0) << "Build your own molecule position set." << endl;
     1561            DoLog(0) && (Log() << Verbose(0) << argv[0] << " " << VERSIONSTRING << endl);
     1562            DoLog(0) && (Log() << Verbose(0) << "Build your own molecule position set." << endl);
    14141563            return (1);
     1564            break;
     1565          case 'B':
     1566            if (ExitFlag == 0) ExitFlag = 1;
     1567            if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
     1568              ExitFlag = 255;
     1569              DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
     1570              performCriticalExit();
     1571            } else {
     1572              SaveFlag = true;
     1573              j = -1;
     1574              DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
     1575              double * const cell_size = World::get()->cell_size;
     1576              for (int i=0;i<6;i++) {
     1577                cell_size[i] = atof(argv[argptr+i]);
     1578              }
     1579              argptr+=6;
     1580            }
    14151581            break;
    14161582          case 'e':
    14171583            if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    1418               eLog() << Verbose(0) << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl;
     1584              DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying element db: -e <db file>" << endl);
     1585              performCriticalExit();
    14191586            } else {
    1420               Log() << Verbose(0) << "Using " << argv[argptr] << " as elements database." << endl;
     1587              DoLog(0) && (Log() << Verbose(0) << "Using " << argv[argptr] << " as elements database." << endl);
    14211588              strncpy (configuration.databasepath, argv[argptr], MAXSTRINGSIZE-1);
    14221589              argptr+=1;
     
    14251592          case 'g':
    14261593            if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    1427               eLog() << Verbose(0) << "Not enough or invalid arguments for specifying bond length table: -g <table file>" << endl;
     1594              DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for specifying bond length table: -g <table file>" << endl);
     1595              performCriticalExit();
    14281596            } else {
    14291597              BondGraphFileName = argv[argptr];
    1430               Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl;
     1598              DoLog(0) && (Log() << Verbose(0) << "Using " << BondGraphFileName << " as bond length table." << endl);
    14311599              argptr+=1;
    14321600            }
    14331601            break;
    14341602          case 'n':
    1435             Log() << Verbose(0) << "I won't parse trajectories." << endl;
     1603            DoLog(0) && (Log() << Verbose(0) << "I won't parse trajectories." << endl);
    14361604            configuration.FastParsing = true;
     1605            break;
     1606          case 'X':
     1607            {
     1608              char **name = &(World::get()->DefaultName);
     1609              delete[](*name);
     1610              const int length = strlen(argv[argptr]);
     1611              *name = new char[length+2];
     1612              strncpy(*name, argv[argptr], length);
     1613              DoLog(0) && (Log() << Verbose(0) << "Default name of new molecules set to " << *name << "." << endl);
     1614            }
    14371615            break;
    14381616          default:   // no match? Step on
     
    14461624    // 3a. Parse the element database
    14471625    if (periode->LoadPeriodentafel(configuration.databasepath)) {
    1448       Log() << Verbose(0) << "Element list loaded successfully." << endl;
     1626      DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
    14491627      //periode->Output();
    14501628    } else {
    1451       Log() << Verbose(0) << "Element list loading failed." << endl;
     1629      DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
    14521630      return 1;
    14531631    }
     
    14551633    if (argv[1][0] != '-') {
    14561634      // simply create a new molecule, wherein the config file is loaded and the manipulation takes place
    1457       Log() << Verbose(0) << "Config file given." << endl;
     1635      DoLog(0) && (Log() << Verbose(0) << "Config file given." << endl);
    14581636      test.open(argv[1], ios::in);
    14591637      if (test == NULL) {
     
    14611639        output.open(argv[1], ios::out);
    14621640        if (output == NULL) {
    1463           Log() << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl;
     1641          DoLog(1) && (Log() << Verbose(1) << "Specified config file " << argv[1] << " not found." << endl);
    14641642          configPresent = absent;
    14651643        } else {
    1466           Log() << Verbose(0) << "Empty configuration file." << endl;
     1644          DoLog(0) && (Log() << Verbose(0) << "Empty configuration file." << endl);
    14671645          ConfigFileName = argv[1];
    14681646          configPresent = empty;
     
    14721650        test.close();
    14731651        ConfigFileName = argv[1];
    1474         Log() << Verbose(1) << "Specified config file found, parsing ... ";
     1652        DoLog(1) && (Log() << Verbose(1) << "Specified config file found, parsing ... ");
    14751653        switch (configuration.TestSyntax(ConfigFileName, periode)) {
    14761654          case 1:
    1477             Log() << Verbose(0) << "new syntax." << endl;
     1655            DoLog(0) && (Log() << Verbose(0) << "new syntax." << endl);
    14781656            configuration.Load(ConfigFileName, BondGraphFileName, periode, molecules);
    14791657            configPresent = present;
    14801658            break;
    14811659          case 0:
    1482             Log() << Verbose(0) << "old syntax." << endl;
     1660            DoLog(0) && (Log() << Verbose(0) << "old syntax." << endl);
    14831661            configuration.LoadOld(ConfigFileName, BondGraphFileName, periode, molecules);
    14841662            configPresent = present;
    14851663            break;
    14861664          default:
    1487             Log() << Verbose(0) << "Unknown syntax or empty, yet present file." << endl;
     1665            DoLog(0) && (Log() << Verbose(0) << "Unknown syntax or empty, yet present file." << endl);
    14881666            configPresent = empty;
    14891667       }
     
    15021680       mol = new molecule(periode);
    15031681       mol->ActiveFlag = true;
     1682       if (ConfigFileName != NULL)
     1683         mol->SetNameFromFilename(ConfigFileName);
    15041684       molecules->insert(mol);
     1685     }
     1686     if (configuration.BG == NULL) {
     1687       configuration.BG = new BondGraph(configuration.GetIsAngstroem());
     1688       if ((!BondGraphFileName.empty()) && (configuration.BG->LoadBondLengthTable(BondGraphFileName))) {
     1689         DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
     1690       } else {
     1691         DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
     1692       }
    15051693     }
    15061694
     
    15081696    argptr = 1;
    15091697    do {
    1510       Log() << Verbose(0) << "Current Command line argument: " << argv[argptr] << "." << endl;
     1698      DoLog(0) && (Log() << Verbose(0) << "Current Command line argument: " << argv[argptr] << "." << endl);
    15111699      if (argv[argptr][0] == '-') {
    15121700        argptr++;
     
    15171705              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    15181706                ExitFlag = 255;
    1519                 eLog() << Verbose(0) << "Not enough arguments for parsing: -p <xyz file>" << endl;
     1707                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough arguments for parsing: -p <xyz file>" << endl);
     1708                performCriticalExit();
    15201709              } else {
    15211710                SaveFlag = true;
    1522                 Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl;
     1711                DoLog(1) && (Log() << Verbose(1) << "Parsing xyz file for new atoms." << endl);
    15231712                if (!mol->AddXYZFile(argv[argptr]))
    1524                   Log() << Verbose(2) << "File not found." << endl;
     1713                  DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
    15251714                else {
    1526                   Log() << Verbose(2) << "File found and parsed." << endl;
     1715                  DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
    15271716                  configPresent = present;
    15281717                }
     
    15331722              if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3]))) {
    15341723                ExitFlag = 255;
    1535                 eLog() << Verbose(0) << "Not enough or invalid arguments for adding atom: -a <element> <x> <y> <z>" << endl;
     1724                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for adding atom: -a <element> <x> <y> <z>" << endl);
     1725                performCriticalExit();
    15361726              } else {
    15371727                SaveFlag = true;
    1538                 Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ";
     1728                DoLog(1) && (Log() << Verbose(1) << "Adding new atom with element " << argv[argptr] << " at (" << argv[argptr+1] << "," << argv[argptr+2] << "," << argv[argptr+3] << "), ");
    15391729                first = new atom;
    15401730                first->type = periode->FindElement(atoi(argv[argptr]));
    15411731                if (first->type != NULL)
    1542                   Log() << Verbose(2) << "found element " << first->type->name << endl;
     1732                  DoLog(2) && (Log() << Verbose(2) << "found element " << first->type->name << endl);
    15431733                for (int i=NDIM;i--;)
    15441734                  first->x.x[i] = atof(argv[argptr+1+i]);
     
    15481738                    configPresent = present;
    15491739                } else
    1550                   eLog() << Verbose(1) << "Could not find the specified element." << endl;
     1740                  DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the specified element." << endl);
    15511741                argptr+=4;
    15521742              }
     
    15611751              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    15621752                ExitFlag = 255;
    1563                 eLog() << Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -B <basis name>" << endl;
     1753                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for setting MPQC basis: -B <basis name>" << endl);
     1754                performCriticalExit();
    15641755              } else {
    15651756                configuration.basis = argv[argptr];
    1566                 Log() << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl;
     1757                DoLog(1) && (Log() << Verbose(1) << "Setting MPQC basis to " << configuration.basis << "." << endl);
    15671758                argptr+=1;
    15681759              }
     
    15711762              if (ExitFlag == 0) ExitFlag = 1;
    15721763              {
    1573                 Log() << Verbose(1) << "Depth-First-Search Analysis." << endl;
     1764                DoLog(1) && (Log() << Verbose(1) << "Depth-First-Search Analysis." << endl);
    15741765                MoleculeLeafClass *Subgraphs = NULL;      // list of subgraphs from DFS analysis
    15751766                int *MinimumRingSize = new int[mol->AtomCount];
     
    16011792              //argptr+=1;
    16021793              break;
     1794            case 'I':
     1795              DoLog(1) && (Log() << Verbose(1) << "Dissecting molecular system into a set of disconnected subgraphs ... " << endl);
     1796              // @TODO rather do the dissection afterwards
     1797              molecules->DissectMoleculeIntoConnectedSubgraphs(periode, &configuration);
     1798              mol = NULL;
     1799              if (molecules->ListOfMolecules.size() != 0) {
     1800                for (MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
     1801                  if ((*ListRunner)->ActiveFlag) {
     1802                    mol = *ListRunner;
     1803                    break;
     1804                  }
     1805              }
     1806              if ((mol == NULL) && (!molecules->ListOfMolecules.empty())) {
     1807                mol = *(molecules->ListOfMolecules.begin());
     1808                if (mol != NULL)
     1809                  mol->ActiveFlag = true;
     1810              }
     1811              break;
    16031812            case 'C':
     1813              {
     1814                int ranges[3] = {1, 1, 1};
     1815                bool periodic = (argv[argptr-1][2] =='p');
     1816                if (ExitFlag == 0) ExitFlag = 1;
     1817                if ((argptr >= argc)) {
     1818                  ExitFlag = 255;
     1819                  DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C[p] <type: E/P/S> [more params] <output> <bin output> <BinStart> <BinEnd>" << endl);
     1820                  performCriticalExit();
     1821                } else {
     1822                  switch(argv[argptr][0]) {
     1823                    case 'E':
     1824                      {
     1825                        if ((argptr+6 >= argc) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (!IsValidNumber(argv[argptr+2])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-') || (argv[argptr+4][0] == '-')) {
     1826                          ExitFlag = 255;
     1827                          DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C E <Z1> <Z2> <output> <bin output>" << endl);
     1828                          performCriticalExit();
     1829                        } else {
     1830                          ofstream output(argv[argptr+3]);
     1831                          ofstream binoutput(argv[argptr+4]);
     1832                          const double BinStart = atof(argv[argptr+5]);
     1833                          const double BinEnd = atof(argv[argptr+6]);
     1834
     1835                          element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
     1836                          element *elemental2 = periode->FindElement((const int) atoi(argv[argptr+2]));
     1837                          PairCorrelationMap *correlationmap = NULL;
     1838                          if (periodic)
     1839                            correlationmap = PeriodicPairCorrelation(molecules, elemental, elemental2, ranges);
     1840                          else
     1841                            correlationmap = PairCorrelation(molecules, elemental, elemental2);
     1842                          //OutputCorrelationToSurface(&output, correlationmap);
     1843                          BinPairMap *binmap = BinData( correlationmap, 0.5, BinStart, BinEnd );
     1844                          OutputCorrelation ( &binoutput, binmap );
     1845                          output.close();
     1846                          binoutput.close();
     1847                          delete(binmap);
     1848                          delete(correlationmap);
     1849                          argptr+=7;
     1850                        }
     1851                      }
     1852                      break;
     1853
     1854                    case 'P':
     1855                      {
     1856                        if ((argptr+8 >= argc) || (!IsValidNumber(argv[argptr+1])) ||  (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+7])) || (!IsValidNumber(argv[argptr+8])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-') || (argv[argptr+4][0] == '-') || (argv[argptr+5][0] == '-') || (argv[argptr+6][0] == '-')) {
     1857                          ExitFlag = 255;
     1858                          DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C P <Z1> <x> <y> <z> <output> <bin output>" << endl);
     1859                          performCriticalExit();
     1860                        } else {
     1861                          ofstream output(argv[argptr+5]);
     1862                          ofstream binoutput(argv[argptr+6]);
     1863                          const double BinStart = atof(argv[argptr+7]);
     1864                          const double BinEnd = atof(argv[argptr+8]);
     1865
     1866                          element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
     1867                          Vector *Point = new Vector((const double) atof(argv[argptr+1]),(const double) atof(argv[argptr+2]),(const double) atof(argv[argptr+3]));
     1868                          CorrelationToPointMap *correlationmap = NULL;
     1869                          if (periodic)
     1870                            correlationmap  = PeriodicCorrelationToPoint(molecules, elemental, Point, ranges);
     1871                          else
     1872                            correlationmap = CorrelationToPoint(molecules, elemental, Point);
     1873                          //OutputCorrelationToSurface(&output, correlationmap);
     1874                          BinPairMap *binmap = BinData( correlationmap, 0.5, BinStart, BinEnd );
     1875                          OutputCorrelation ( &binoutput, binmap );
     1876                          output.close();
     1877                          binoutput.close();
     1878                          delete(Point);
     1879                          delete(binmap);
     1880                          delete(correlationmap);
     1881                          argptr+=9;
     1882                        }
     1883                      }
     1884                      break;
     1885
     1886                    case 'S':
     1887                      {
     1888                        if ((argptr+6 >= argc) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-') || (argv[argptr+3][0] == '-')) {
     1889                          ExitFlag = 255;
     1890                          DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C S <Z> <output> <bin output> <BinWidth> <BinStart> <BinEnd>" << endl);
     1891                          performCriticalExit();
     1892                        } else {
     1893                          ofstream output(argv[argptr+2]);
     1894                          ofstream binoutput(argv[argptr+3]);
     1895                          const double radius = 4.;
     1896                          const double BinWidth = atof(argv[argptr+4]);
     1897                          const double BinStart = atof(argv[argptr+5]);
     1898                          const double BinEnd = atof(argv[argptr+6]);
     1899                          double LCWidth = 20.;
     1900                          if (BinEnd > 0) {
     1901                            if (BinEnd > 2.*radius)
     1902                                LCWidth = BinEnd;
     1903                            else
     1904                              LCWidth = 2.*radius;
     1905                          }
     1906
     1907                          // get the boundary
     1908                          class molecule *Boundary = NULL;
     1909                          class Tesselation *TesselStruct = NULL;
     1910                          const LinkedCell *LCList = NULL;
     1911                          // find biggest molecule
     1912                          int counter  = 0;
     1913                          for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
     1914                            if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) {
     1915                              Boundary = *BigFinder;
     1916                            }
     1917                            counter++;
     1918                          }
     1919                          bool *Actives = Malloc<bool>(counter, "ParseCommandLineOptions() - case C -- *Actives");
     1920                          counter = 0;
     1921                          for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
     1922                            Actives[counter++] = (*BigFinder)->ActiveFlag;
     1923                            (*BigFinder)->ActiveFlag = (*BigFinder == Boundary) ? false : true;
     1924                          }
     1925                          LCList = new LinkedCell(Boundary, LCWidth);
     1926                          element *elemental = periode->FindElement((const int) atoi(argv[argptr+1]));
     1927                          FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
     1928                          CorrelationToSurfaceMap *surfacemap = NULL;
     1929                          if (periodic)
     1930                            surfacemap = PeriodicCorrelationToSurface( molecules, elemental, TesselStruct, LCList, ranges);
     1931                          else
     1932                            surfacemap = CorrelationToSurface( molecules, elemental, TesselStruct, LCList);
     1933                          OutputCorrelationToSurface(&output, surfacemap);
     1934                          // check whether radius was appropriate
     1935                          {
     1936                            double start; double end;
     1937                            GetMinMax( surfacemap, start, end);
     1938                            if (LCWidth < end)
     1939                              DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell width is smaller than the found range of values! Bins can only be correct up to: " << radius << "." << endl);
     1940                          }
     1941                          BinPairMap *binmap = BinData( surfacemap, BinWidth, BinStart, BinEnd );
     1942                          OutputCorrelation ( &binoutput, binmap );
     1943                          output.close();
     1944                          binoutput.close();
     1945                          for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++)
     1946                            (*BigFinder)->ActiveFlag = Actives[counter++];
     1947                          Free(&Actives);
     1948                          delete(LCList);
     1949                          delete(TesselStruct);
     1950                          delete(binmap);
     1951                          delete(surfacemap);
     1952                          argptr+=7;
     1953                        }
     1954                      }
     1955                      break;
     1956
     1957                    default:
     1958                      ExitFlag = 255;
     1959                      DoeLog(0) && (eLog()<< Verbose(0) << "Invalid type given for pair correlation analysis: -C <type: E/P/S> [more params] <output> <bin output>" << endl);
     1960                      performCriticalExit();
     1961                      break;
     1962                  }
     1963                }
     1964                break;
     1965              }
     1966            case 'E':
    16041967              if (ExitFlag == 0) ExitFlag = 1;
    1605               if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr][0] == '-') || (argv[argptr+1][0] == '-') || (argv[argptr+2][0] == '-')) {
     1968              if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) {
    16061969                ExitFlag = 255;
    1607                 eLog() << Verbose(0) << "Not enough or invalid arguments given for pair correlation analysis: -C <Z> <output> <bin output>" << endl;
     1970                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl);
     1971                performCriticalExit();
    16081972              } else {
    1609                 SaveFlag = false;
    1610                 ofstream output(argv[argptr+1]);
    1611                 ofstream binoutput(argv[argptr+2]);
    1612                 const double radius = 5.;
    1613 
    1614                 // get the boundary
    1615                 class molecule *Boundary = NULL;
    1616                 class Tesselation *TesselStruct = NULL;
     1973                SaveFlag = true;
     1974                DoLog(1) && (Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl);
     1975                first = mol->FindAtom(atoi(argv[argptr]));
     1976                first->type = periode->FindElement(atoi(argv[argptr+1]));
     1977                argptr+=2;
     1978              }
     1979              break;
     1980            case 'F':
     1981              if (ExitFlag == 0) ExitFlag = 1;
     1982              MaxDistance = -1;
     1983              if (argv[argptr-1][2] == 'F') { // option is -FF?
     1984                // fetch first argument as max distance to surface
     1985                MaxDistance = atof(argv[argptr++]);
     1986                DoLog(0) && (Log() << Verbose(0) << "Filling with maximum layer distance of " << MaxDistance << "." << endl);
     1987              }
     1988              if ((argptr+7 >=argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) || (!IsValidNumber(argv[argptr+6])) || (!IsValidNumber(argv[argptr+7]))) {
     1989                ExitFlag = 255;
     1990                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for filling box with water: -F <xyz of filler> <dist_x> <dist_y> <dist_z> <boundary> <randatom> <randmol> <DoRotate>" << endl);
     1991                performCriticalExit();
     1992              } else {
     1993                SaveFlag = true;
     1994                DoLog(1) && (Log() << Verbose(1) << "Filling Box with water molecules." << endl);
     1995                // construct water molecule
     1996                molecule *filler = new molecule(periode);
     1997                if (!filler->AddXYZFile(argv[argptr])) {
     1998                  DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse filler molecule from " << argv[argptr] << "." << endl);
     1999                }
     2000                filler->SetNameFromFilename(argv[argptr]);
     2001                configuration.BG->ConstructBondGraph(filler);
     2002                molecule *Filling = NULL;
     2003                // call routine
     2004                double distance[NDIM];
     2005                for (int i=0;i<NDIM;i++)
     2006                  distance[i] = atof(argv[argptr+i+1]);
     2007                Filling = FillBoxWithMolecule(molecules, filler, configuration, MaxDistance, distance, atof(argv[argptr+4]), atof(argv[argptr+5]), atof(argv[argptr+6]), atoi(argv[argptr+7]));
     2008                if (Filling != NULL) {
     2009                  Filling->ActiveFlag = false;
     2010                  molecules->insert(Filling);
     2011                }
     2012                delete(filler);
     2013                argptr+=6;
     2014              }
     2015              break;
     2016            case 'A':
     2017              if (ExitFlag == 0) ExitFlag = 1;
     2018              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
     2019                ExitFlag =255;
     2020                DoeLog(0) && (eLog()<< Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile>" << endl);
     2021                performCriticalExit();
     2022              } else {
     2023                DoLog(0) && (Log() << Verbose(0) << "Parsing bonds from " << argv[argptr] << "." << endl);
     2024                ifstream *input = new ifstream(argv[argptr]);
     2025                mol->CreateAdjacencyListFromDbondFile(input);
     2026                input->close();
     2027                argptr+=1;
     2028              }
     2029              break;
     2030
     2031            case 'J':
     2032              if (ExitFlag == 0) ExitFlag = 1;
     2033              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
     2034                ExitFlag =255;
     2035                DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of adjacency file: -j <path>" << endl);
     2036                performCriticalExit();
     2037              } else {
     2038                DoLog(0) && (Log() << Verbose(0) << "Storing adjacency to path " << argv[argptr] << "." << endl);
     2039                configuration.BG->ConstructBondGraph(mol);
     2040                mol->StoreAdjacencyToFile(NULL, argv[argptr]);
     2041                argptr+=1;
     2042              }
     2043              break;
     2044
     2045            case 'j':
     2046              if (ExitFlag == 0) ExitFlag = 1;
     2047              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
     2048                ExitFlag =255;
     2049                DoeLog(0) && (eLog()<< Verbose(0) << "Missing path of bonds file: -j <path>" << endl);
     2050                performCriticalExit();
     2051              } else {
     2052                DoLog(0) && (Log() << Verbose(0) << "Storing bonds to path " << argv[argptr] << "." << endl);
     2053                configuration.BG->ConstructBondGraph(mol);
     2054                mol->StoreBondsToFile(NULL, argv[argptr]);
     2055                argptr+=1;
     2056              }
     2057              break;
     2058
     2059            case 'N':
     2060              if (ExitFlag == 0) ExitFlag = 1;
     2061              if ((argptr+1 >= argc) || (argv[argptr+1][0] == '-')){
     2062                ExitFlag = 255;
     2063                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for non-convex envelope: -o <radius> <tecplot output file>" << endl);
     2064                performCriticalExit();
     2065              } else {
     2066                class Tesselation *T = NULL;
    16172067                const LinkedCell *LCList = NULL;
     2068                molecule * Boundary = NULL;
     2069                //string filename(argv[argptr+1]);
     2070                //filename.append(".csv");
     2071                DoLog(0) && (Log() << Verbose(0) << "Evaluating non-convex envelope of biggest molecule.");
     2072                DoLog(1) && (Log() << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl);
    16182073                // find biggest molecule
    16192074                int counter  = 0;
    16202075                for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
     2076                  (*BigFinder)->CountAtoms();
    16212077                  if ((Boundary == NULL) || (Boundary->AtomCount < (*BigFinder)->AtomCount)) {
    16222078                    Boundary = *BigFinder;
     
    16242080                  counter++;
    16252081                }
    1626                 bool *Actives = Malloc<bool>(counter, "ParseCommandLineOptions() - case C -- *Actives");
    1627                 counter = 0;
    1628                 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++) {
    1629                   Actives[counter] = (*BigFinder)->ActiveFlag;
    1630                   (*BigFinder)->ActiveFlag = (*BigFinder == Boundary) ? false : true;
    1631                 }
    1632                 LCList = new LinkedCell(Boundary, 2.*radius);
    1633                 element *elemental = periode->FindElement((const int) atoi(argv[argptr]));
    1634                 FindNonConvexBorder(Boundary, TesselStruct, LCList, radius, NULL);
    1635                 int ranges[NDIM] = {1,1,1};
    1636                 CorrelationToSurfaceMap *surfacemap = PeriodicCorrelationToSurface( molecules, elemental, TesselStruct, LCList, ranges );
    1637                 BinPairMap *binmap = BinData( surfacemap, 0.5, 0., 0. );
    1638                 OutputCorrelation ( &binoutput, binmap );
    1639                 output.close();
    1640                 binoutput.close();
    1641                 for (MoleculeList::iterator BigFinder = molecules->ListOfMolecules.begin(); BigFinder != molecules->ListOfMolecules.end(); BigFinder++)
    1642                   (*BigFinder)->ActiveFlag = Actives[counter];
    1643                 Free(&Actives);
    1644                 delete(LCList);
    1645                 delete(TesselStruct);
    1646                 argptr+=3;
    1647               }
    1648               break;
    1649             case 'E':
    1650               if (ExitFlag == 0) ExitFlag = 1;
    1651               if ((argptr+1 >= argc) || (!IsValidNumber(argv[argptr])) || (argv[argptr+1][0] == '-')) {
    1652                 ExitFlag = 255;
    1653                 eLog() << Verbose(0) << "Not enough or invalid arguments given for changing element: -E <atom nr.> <element>" << endl;
    1654               } else {
    1655                 SaveFlag = true;
    1656                 Log() << Verbose(1) << "Changing atom " << argv[argptr] << " to element " << argv[argptr+1] << "." << endl;
    1657                 first = mol->FindAtom(atoi(argv[argptr]));
    1658                 first->type = periode->FindElement(atoi(argv[argptr+1]));
    1659                 argptr+=2;
    1660               }
    1661               break;
    1662             case 'F':
    1663               if (ExitFlag == 0) ExitFlag = 1;
    1664               if (argptr+5 >=argc) {
    1665                 ExitFlag = 255;
    1666                 eLog() << Verbose(0) << "Not enough or invalid arguments given for filling box with water: -F <dist_x> <dist_y> <dist_z> <randatom> <randmol> <DoRotate>" << endl;
    1667               } else {
    1668                 SaveFlag = true;
    1669                 Log() << Verbose(1) << "Filling Box with water molecules." << endl;
    1670                 // construct water molecule
    1671                 molecule *filler = new molecule(periode);;
    1672                 molecule *Filling = NULL;
    1673                 atom *second = NULL, *third = NULL;
    1674                 first = new atom();
    1675                 first->type = periode->FindElement(1);
    1676                 first->x.Init(0.441, -0.143, 0.);
    1677                 filler->AddAtom(first);
    1678                 second = new atom();
    1679                 second->type = periode->FindElement(1);
    1680                 second->x.Init(-0.464, 1.137, 0.0);
    1681                 filler->AddAtom(second);
    1682                 third = new atom();
    1683                 third->type = periode->FindElement(8);
    1684                 third->x.Init(-0.464, 0.177, 0.);
    1685                 filler->AddAtom(third);
    1686                 filler->AddBond(first, third, 1);
    1687                 filler->AddBond(second, third, 1);
    1688                 // call routine
    1689                 double distance[NDIM];
    1690                 for (int i=0;i<NDIM;i++)
    1691                   distance[i] = atof(argv[argptr+i]);
    1692                 Filling = FillBoxWithMolecule(molecules, filler, configuration, distance, atof(argv[argptr+3]), atof(argv[argptr+4]), atoi(argv[argptr+5]));
    1693                 if (Filling != NULL) {
    1694                   molecules->insert(Filling);
    1695                 }
    1696                 delete(filler);
    1697                 argptr+=6;
    1698               }
    1699               break;
    1700             case 'A':
    1701               if (ExitFlag == 0) ExitFlag = 1;
    1702               if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    1703                 ExitFlag =255;
    1704                 eLog() << Verbose(0) << "Missing source file for bonds in molecule: -A <bond sourcefile>" << endl;
    1705               } else {
    1706                 Log() << Verbose(0) << "Parsing bonds from " << argv[argptr] << "." << endl;
    1707                 ifstream *input = new ifstream(argv[argptr]);
    1708                 mol->CreateAdjacencyListFromDbondFile(input);
    1709                 input->close();
    1710                 argptr+=1;
    1711               }
    1712               break;
    1713             case 'N':
    1714               if (ExitFlag == 0) ExitFlag = 1;
    1715               if ((argptr+1 >= argc) || (argv[argptr+1][0] == '-')){
    1716                 ExitFlag = 255;
    1717                 eLog() << Verbose(0) << "Not enough or invalid arguments given for non-convex envelope: -o <radius> <tecplot output file>" << endl;
    1718               } else {
    1719                 class Tesselation *T = NULL;
    1720                 const LinkedCell *LCList = NULL;
    1721                 string filename(argv[argptr+1]);
    1722                 filename.append(".csv");
    1723                 Log() << Verbose(0) << "Evaluating non-convex envelope.";
    1724                 Log() << Verbose(1) << "Using rolling ball of radius " << atof(argv[argptr]) << " and storing tecplot data in " << argv[argptr+1] << "." << endl;
     2082                DoLog(1) && (Log() << Verbose(1) << "Biggest molecule has " << Boundary->AtomCount << " atoms." << endl);
    17252083                start = clock();
    1726                 LCList = new LinkedCell(mol, atof(argv[argptr])*2.);
    1727                 FindNonConvexBorder(mol, T, LCList, atof(argv[argptr]), argv[argptr+1]);
     2084                LCList = new LinkedCell(Boundary, atof(argv[argptr])*2.);
     2085                if (!FindNonConvexBorder(Boundary, T, LCList, atof(argv[argptr]), argv[argptr+1]))
     2086                  ExitFlag = 255;
    17282087                //FindDistributionOfEllipsoids(T, &LCList, N, number, filename.c_str());
    17292088                end = clock();
    1730                 Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
     2089                DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
    17312090                delete(LCList);
     2091                delete(T);
    17322092                argptr+=2;
    17332093              }
     
    17372097              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    17382098                ExitFlag = 255;
    1739                 eLog() << Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file>" << endl;
     2099                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -S <temperature file>" << endl);
     2100                performCriticalExit();
    17402101              } else {
    1741                 Log() << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl;
     2102                DoLog(1) && (Log() << Verbose(1) << "Storing temperatures in " << argv[argptr] << "." << endl);
    17422103                ofstream *output = new ofstream(argv[argptr], ios::trunc);
    17432104                if (!mol->OutputTemperatureFromTrajectories(output, 0, mol->MDSteps))
    1744                   Log() << Verbose(2) << "File could not be written." << endl;
     2105                  DoLog(2) && (Log() << Verbose(2) << "File could not be written." << endl);
    17452106                else
    1746                   Log() << Verbose(2) << "File stored." << endl;
     2107                  DoLog(2) && (Log() << Verbose(2) << "File stored." << endl);
    17472108                output->close();
    17482109                delete(output);
     
    17542115              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    17552116                ExitFlag = 255;
    1756                 eLog() << Verbose(0) << "Not enough or invalid arguments given for storing tempature: -L <step0> <step1> <prefix> <identity mapping?>" << endl;
     2117                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for storing tempature: -L <step0> <step1> <prefix> <identity mapping?>" << endl);
     2118                performCriticalExit();
    17572119              } else {
    17582120                SaveFlag = true;
    1759                 Log() << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl;
     2121                DoLog(1) && (Log() << Verbose(1) << "Linear interpolation between configuration " << argv[argptr] << " and " << argv[argptr+1] << "." << endl);
    17602122                if (atoi(argv[argptr+3]) == 1)
    1761                   Log() << Verbose(1) << "Using Identity for the permutation map." << endl;
     2123                  DoLog(1) && (Log() << Verbose(1) << "Using Identity for the permutation map." << endl);
    17622124                if (!mol->LinearInterpolationBetweenConfiguration(atoi(argv[argptr]), atoi(argv[argptr+1]), argv[argptr+2], configuration, atoi(argv[argptr+3])) == 1 ? true : false)
    1763                   Log() << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl;
     2125                  DoLog(2) && (Log() << Verbose(2) << "Could not store " << argv[argptr+2] << " files." << endl);
    17642126                else
    1765                   Log() << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl;
     2127                  DoLog(2) && (Log() << Verbose(2) << "Steps created and " << argv[argptr+2] << " files stored." << endl);
    17662128                argptr+=4;
    17672129              }
     
    17712133              if ((argptr >= argc) || (argv[argptr][0] == '-')) {
    17722134                ExitFlag = 255;
    1773                 eLog() << Verbose(0) << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl;
     2135                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for parsing and integrating forces: -P <forces file>" << endl);
     2136                performCriticalExit();
    17742137              } else {
    17752138                SaveFlag = true;
    1776                 Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl;
     2139                DoLog(1) && (Log() << Verbose(1) << "Parsing forces file and Verlet integrating." << endl);
    17772140                if (!mol->VerletForceIntegration(argv[argptr], configuration))
    1778                   Log() << Verbose(2) << "File not found." << endl;
     2141                  DoLog(2) && (Log() << Verbose(2) << "File not found." << endl);
    17792142                else
    1780                   Log() << Verbose(2) << "File found and parsed." << endl;
     2143                  DoLog(2) && (Log() << Verbose(2) << "File found and parsed." << endl);
    17812144                argptr+=1;
    17822145              }
     
    17862149              if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])))  {
    17872150                ExitFlag = 255;
    1788                 eLog() << Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <id> <distance>" << endl;
     2151                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -R <id> <distance>" << endl);
     2152                performCriticalExit();
    17892153              } else {
    17902154                SaveFlag = true;
    1791                 Log() << Verbose(1) << "Removing atoms around " << argv[argptr] << " with radius " << argv[argptr+1] << "." << endl;
     2155                DoLog(1) && (Log() << Verbose(1) << "Removing atoms around " << argv[argptr] << " with radius " << argv[argptr+1] << "." << endl);
    17922156                double tmp1 = atof(argv[argptr+1]);
    17932157                atom *third = mol->FindAtom(atoi(argv[argptr]));
     
    18022166                  }
    18032167                } else {
    1804                   eLog() << Verbose(0) << "Removal failed due to missing atoms on molecule or wrong id." << endl;
     2168                  DoeLog(1) && (eLog()<< Verbose(1) << "Removal failed due to missing atoms on molecule or wrong id." << endl);
    18052169                }
    18062170                argptr+=2;
     
    18112175              if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
    18122176                ExitFlag = 255;
    1813                 eLog() << Verbose(0) << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl;
     2177                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for translation: -t <x> <y> <z>" << endl);
     2178                performCriticalExit();
    18142179              } else {
    18152180                if (ExitFlag == 0) ExitFlag = 1;
    18162181                SaveFlag = true;
    1817                 Log() << Verbose(1) << "Translating all ions by given vector." << endl;
     2182                DoLog(1) && (Log() << Verbose(1) << "Translating all ions by given vector." << endl);
    18182183                for (int i=NDIM;i--;)
    18192184                  x.x[i] = atof(argv[argptr+i]);
     
    18262191              if ((argptr+2 >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
    18272192                ExitFlag = 255;
    1828                 eLog() << Verbose(0) << "Not enough or invalid arguments given for periodic translation: -T <x> <y> <z>" << endl;
     2193                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for periodic translation: -T <x> <y> <z>" << endl);
     2194                performCriticalExit();
    18292195              } else {
    18302196                if (ExitFlag == 0) ExitFlag = 1;
    18312197                SaveFlag = true;
    1832                 Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl;
     2198                DoLog(1) && (Log() << Verbose(1) << "Translating all ions periodically by given vector." << endl);
    18332199                for (int i=NDIM;i--;)
    18342200                  x.x[i] = atof(argv[argptr+i]);
     
    18412207              if ((argptr >= argc) || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
    18422208                ExitFlag = 255;
    1843                 eLog() << Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl;
     2209                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for scaling: -s <factor_x> [factor_y] [factor_z]" << endl);
     2210                performCriticalExit();
    18442211              } else {
    18452212                SaveFlag = true;
    18462213                j = -1;
    1847                 Log() << Verbose(1) << "Scaling all ion positions by factor." << endl;
     2214                DoLog(1) && (Log() << Verbose(1) << "Scaling all ion positions by factor." << endl);
    18482215                factor = new double[NDIM];
    18492216                factor[0] = atof(argv[argptr]);
     
    18512218                factor[2] = atof(argv[argptr+2]);
    18522219                mol->Scale((const double ** const)&factor);
     2220                double * const cell_size = World::get()->cell_size;
    18532221                for (int i=0;i<NDIM;i++) {
    18542222                  j += i+1;
    18552223                  x.x[i] = atof(argv[NDIM+i]);
    1856                   mol->cell_size[j]*=factor[i];
     2224                  cell_size[j]*=factor[i];
    18572225                }
    18582226                delete[](factor);
     
    18642232              if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
    18652233                ExitFlag = 255;
    1866                 eLog() << Verbose(0) << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl;
     2234                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering in box: -b <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
     2235                performCriticalExit();
    18672236              } else {
    18682237                SaveFlag = true;
    18692238                j = -1;
    1870                 Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
     2239                DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
     2240                double * const cell_size = World::get()->cell_size;
    18712241                for (int i=0;i<6;i++) {
    1872                   mol->cell_size[i] = atof(argv[argptr+i]);
     2242                  cell_size[i] = atof(argv[argptr+i]);
    18732243                }
    18742244                // center
     
    18812251              if ((argptr+5 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) || (!IsValidNumber(argv[argptr+3])) || (!IsValidNumber(argv[argptr+4])) || (!IsValidNumber(argv[argptr+5])) ) {
    18822252                ExitFlag = 255;
    1883                 eLog() << Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl;
     2253                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for bounding in box: -B <xx> <xy> <xz> <yy> <yz> <zz>" << endl);
     2254                performCriticalExit();
    18842255              } else {
    18852256                SaveFlag = true;
    18862257                j = -1;
    1887                 Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl;
     2258                DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given simulation box." << endl);
     2259                double * const cell_size = World::get()->cell_size;
    18882260                for (int i=0;i<6;i++) {
    1889                   mol->cell_size[i] = atof(argv[argptr+i]);
     2261                  cell_size[i] = atof(argv[argptr+i]);
    18902262                }
    18912263                // center
     
    18982270              if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
    18992271                ExitFlag = 255;
    1900                 eLog() << Verbose(0) << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl;
     2272                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for centering with boundary: -c <boundary_x> <boundary_y> <boundary_z>" << endl);
     2273                performCriticalExit();
    19012274              } else {
    19022275                SaveFlag = true;
    19032276                j = -1;
    1904                 Log() << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl;
     2277                DoLog(1) && (Log() << Verbose(1) << "Centering atoms in config file within given additional boundary." << endl);
    19052278                // make every coordinate positive
    19062279                mol->CenterEdge(&x);
     
    19082281                mol->SetBoxDimension(&x);
    19092282                // translate each coordinate by boundary
     2283                double * const cell_size = World::get()->cell_size;
    19102284                j=-1;
    19112285                for (int i=0;i<NDIM;i++) {
    19122286                  j += i+1;
    19132287                  x.x[i] = atof(argv[argptr+i]);
    1914                   mol->cell_size[j] += x.x[i]*2.;
     2288                  cell_size[j] += x.x[i]*2.;
    19152289                }
    19162290                mol->Translate((const Vector *)&x);
     
    19212295              if (ExitFlag == 0) ExitFlag = 1;
    19222296              SaveFlag = true;
    1923               Log() << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl;
     2297              DoLog(1) && (Log() << Verbose(1) << "Centering atoms on edge and setting box dimensions." << endl);
    19242298              x.Zero();
    19252299              mol->CenterEdge(&x);
     
    19312305              if ((argptr >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])))  {
    19322306                ExitFlag = 255;
    1933                 eLog() << Verbose(0) << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl;
     2307                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for removing atoms: -r <id>" << endl);
     2308                performCriticalExit();
    19342309              } else {
    19352310                SaveFlag = true;
    1936                 Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl;
     2311                DoLog(1) && (Log() << Verbose(1) << "Removing atom " << argv[argptr] << "." << endl);
    19372312                atom *first = mol->FindAtom(atoi(argv[argptr]));
    19382313                mol->RemoveAtom(first);
     
    19442319              if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1]))) {
    19452320                ExitFlag = 255;
    1946                 eLog() << Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl;
     2321                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments for fragmentation: -f <max. bond distance> <bond order>" << endl);
     2322                performCriticalExit();
    19472323              } else {
    1948                 Log() << Verbose(0) << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl;
    1949                 Log() << Verbose(0) << "Creating connection matrix..." << endl;
     2324                DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with bond distance " << argv[argptr] << " angstroem, order of " << argv[argptr+1] << "." << endl);
     2325                DoLog(0) && (Log() << Verbose(0) << "Creating connection matrix..." << endl);
    19502326                start = clock();
    19512327                mol->CreateAdjacencyList(atof(argv[argptr++]), configuration.GetIsAngstroem(), &BondGraph::CovalentMinMaxDistance, NULL);
    1952                 Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl;
     2328                DoLog(0) && (Log() << Verbose(0) << "Fragmenting molecule with current connection matrix ..." << endl);
    19532329                if (mol->first->next != mol->last) {
    19542330                  ExitFlag = mol->FragmentMolecule(atoi(argv[argptr]), &configuration);
    19552331                }
    19562332                end = clock();
    1957                 Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl;
     2333                DoLog(0) && (Log() << Verbose(0) << "Clocks for this operation: " << (end-start) << ", time: " << ((double)(end-start)/CLOCKS_PER_SEC) << "s." << endl);
    19582334                argptr+=2;
    19592335              }
     
    19632339              j = atoi(argv[argptr++]);
    19642340              if ((j<0) || (j>1)) {
    1965                 eLog() << Verbose(1) << "ERROR: Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl;
     2341                DoeLog(1) && (eLog()<< Verbose(1) << "Argument of '-m' should be either 0 for no-rotate or 1 for rotate." << endl);
    19662342                j = 0;
    19672343              }
    19682344              if (j) {
    19692345                SaveFlag = true;
    1970                 Log() << Verbose(0) << "Converting to prinicipal axis system." << endl;
     2346                DoLog(0) && (Log() << Verbose(0) << "Converting to prinicipal axis system." << endl);
    19712347              } else
    1972                 Log() << Verbose(0) << "Evaluating prinicipal axis." << endl;
     2348                DoLog(0) && (Log() << Verbose(0) << "Evaluating prinicipal axis." << endl);
    19732349              mol->PrincipalAxisSystem((bool)j);
    19742350              break;
     
    19772353              if ((argptr+1 >= argc) || (argv[argptr][0] == '-')){
    19782354                ExitFlag = 255;
    1979                 eLog() << Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o <convex output file> <non-convex output file>" << endl;
     2355                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for convex envelope: -o <convex output file> <non-convex output file>" << endl);
     2356                performCriticalExit();
    19802357              } else {
    19812358                class Tesselation *TesselStruct = NULL;
    19822359                const LinkedCell *LCList = NULL;
    1983                 Log() << Verbose(0) << "Evaluating volume of the convex envelope.";
    1984                 Log() << Verbose(1) << "Storing tecplot convex data in " << argv[argptr] << "." << endl;
    1985                 Log() << Verbose(1) << "Storing tecplot non-convex data in " << argv[argptr+1] << "." << endl;
     2360                DoLog(0) && (Log() << Verbose(0) << "Evaluating volume of the convex envelope.");
     2361                DoLog(1) && (Log() << Verbose(1) << "Storing tecplot convex data in " << argv[argptr] << "." << endl);
     2362                DoLog(1) && (Log() << Verbose(1) << "Storing tecplot non-convex data in " << argv[argptr+1] << "." << endl);
    19862363                LCList = new LinkedCell(mol, 10.);
    19872364                //FindConvexBorder(mol, LCList, argv[argptr]);
     
    19902367                double volumedifference = ConvexizeNonconvexEnvelope(TesselStruct, mol, argv[argptr]);
    19912368                double clustervolume = VolumeOfConvexEnvelope(TesselStruct, &configuration);
    1992                 Log() << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
    1993                 Log() << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl;
     2369                DoLog(0) && (Log() << Verbose(0) << "The tesselated volume area is " << clustervolume << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl);
     2370                DoLog(0) && (Log() << Verbose(0) << "The non-convex tesselated volume area is " << clustervolume-volumedifference << " " << (configuration.GetIsAngstroem() ? "angstrom" : "atomiclength") << "^3." << endl);
    19942371                delete(TesselStruct);
    19952372                delete(LCList);
     
    20012378              if ((argptr+1 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) ) {
    20022379                ExitFlag = 255;
    2003                 eLog() << Verbose(0) << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl;
    2004                 volume = -1; // for case 'u': don't print error again
     2380                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension with specified volume: -U <volume> <density>" << endl);
     2381                performCriticalExit();
    20052382              } else {
    20062383                volume = atof(argv[argptr++]);
    2007                 Log() << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl;
     2384                DoLog(0) && (Log() << Verbose(0) << "Using " << volume << " angstrom^3 as the volume instead of convex envelope one's." << endl);
    20082385              }
    20092386            case 'u':
     
    20122389                if (volume != -1)
    20132390                  ExitFlag = 255;
    2014                   eLog() << Verbose(0) << "Not enough arguments given for suspension: -u <density>" << endl;
     2391                  DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for suspension: -u <density>" << endl);
     2392                  performCriticalExit();
    20152393              } else {
    20162394                double density;
    20172395                SaveFlag = true;
    2018                 Log() << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.";
     2396                DoLog(0) && (Log() << Verbose(0) << "Evaluating necessary cell volume for a cluster suspended in water.");
    20192397                density = atof(argv[argptr++]);
    20202398                if (density < 1.0) {
    2021                   eLog() << Verbose(0) << "Density must be greater than 1.0g/cm^3 !" << endl;
     2399                  DoeLog(1) && (eLog()<< Verbose(1) << "Density must be greater than 1.0g/cm^3 !" << endl);
    20222400                  density = 1.3;
    20232401                }
     
    20252403//                  repetition[i] = atoi(argv[argptr++]);
    20262404//                  if (repetition[i] < 1)
    2027 //                    eLog() << Verbose(0) << "ERROR: repetition value must be greater 1!" << endl;
     2405//                    DoeLog(1) && (eLog()<< Verbose(1) << "repetition value must be greater 1!" << endl);
    20282406//                  repetition[i] = 1;
    20292407//                }
     
    20352413              if ((argptr+2 >= argc) || (argv[argptr][0] == '-') || (!IsValidNumber(argv[argptr])) || (!IsValidNumber(argv[argptr+1])) || (!IsValidNumber(argv[argptr+2])) ) {
    20362414                ExitFlag = 255;
    2037                 eLog() << Verbose(0) << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl;
     2415                DoeLog(0) && (eLog()<< Verbose(0) << "Not enough or invalid arguments given for repeating cells: -d <repeat_x> <repeat_y> <repeat_z>" << endl);
     2416                performCriticalExit();
    20382417              } else {
    20392418                SaveFlag = true;
     2419                double * const cell_size = World::get()->cell_size;
    20402420                for (int axis = 1; axis <= NDIM; axis++) {
    20412421                  int faktor = atoi(argv[argptr++]);
     
    20442424                  Vector ** vectors;
    20452425                  if (faktor < 1) {
    2046                     eLog() << Verbose(0) << "ERROR: Repetition faktor mus be greater than 1!" << endl;
     2426                    DoeLog(1) && (eLog()<< Verbose(1) << "Repetition factor mus be greater than 1!" << endl);
    20472427                    faktor = 1;
    20482428                  }
     
    20612441                    }
    20622442                    if (count != j)
    2063                       Log() << Verbose(0) << "ERROR: AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl;
     2443                      DoeLog(1) && (eLog()<< Verbose(1) << "AtomCount " << count << " is not equal to number of atoms in molecule " << j << "!" << endl);
    20642444                    x.Zero();
    20652445                    y.Zero();
    2066                     y.x[abs(axis)-1] = mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
     2446                    y.x[abs(axis)-1] = cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] * abs(axis)/axis; // last term is for sign, first is for magnitude
    20672447                    for (int i=1;i<faktor;i++) {  // then add this list with respective translation factor times
    20682448                      x.AddVector(&y); // per factor one cell width further
     
    20852465                      mol->Translate(&x);
    20862466                    }
    2087                     mol->cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
     2467                    cell_size[(abs(axis) == 2) ? 2 : ((abs(axis) == 3) ? 5 : 0)] *= faktor;
    20882468                  }
    20892469                }
     
    21022482  } else {  // no arguments, hence scan the elements db
    21032483    if (periode->LoadPeriodentafel(configuration.databasepath))
    2104       Log() << Verbose(0) << "Element list loaded successfully." << endl;
     2484      DoLog(0) && (Log() << Verbose(0) << "Element list loaded successfully." << endl);
    21052485    else
    2106       Log() << Verbose(0) << "Element list loading failed." << endl;
     2486      DoLog(0) && (Log() << Verbose(0) << "Element list loading failed." << endl);
    21072487    configuration.RetrieveConfigPathAndName("main_pcp_linux");
    21082488  }
     
    21262506  int j;
    21272507
    2128   setVerbosity(2);
     2508  cout << ESPACKVersion << endl;
     2509
     2510  DoLog(1) && (Log() << Verbose(1) << "test" << endl);
     2511  DoLog(3) && (Log() << Verbose(1) << "test");
     2512
     2513  setVerbosity(0);
    21292514
    21302515  // =========================== PARSE COMMAND LINE OPTIONS ====================================
     
    21422527        << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    21432528      MemoryUsageObserver::getInstance()->purgeInstance();
     2529      logger::purgeInstance();
     2530      errorLogger::purgeInstance();
    21442531     return (j == 1 ? 0 : j);
    21452532    default:
     
    21502537  if (molecules->ListOfMolecules.size() == 0) {
    21512538    mol = new molecule(periode);
    2152     if (mol->cell_size[0] == 0.) {
    2153       Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl;
     2539    double * const cell_size = World::get()->cell_size;
     2540    if (cell_size[0] == 0.) {
     2541      DoLog(0) && (Log() << Verbose(0) << "enter lower tridiagonal form of basis matrix" << endl << endl);
    21542542      for (int i=0;i<6;i++) {
    2155         Log() << Verbose(1) << "Cell size" << i << ": ";
    2156         cin >> mol->cell_size[i];
     2543        DoLog(1) && (Log() << Verbose(1) << "Cell size" << i << ": ");
     2544        cin >> cell_size[i];
    21572545      }
    21582546    }
     
    21642552
    21652553  // now the main construction loop
    2166   Log() << Verbose(0) << endl << "Now comes the real construction..." << endl;
     2554  DoLog(0) && (Log() << Verbose(0) << endl << "Now comes the real construction..." << endl);
    21672555  do {
    2168     Log() << Verbose(0) << endl << endl;
    2169     Log() << Verbose(0) << "============Molecule list=======================" << endl;
     2556    DoLog(0) && (Log() << Verbose(0) << endl << endl);
     2557    DoLog(0) && (Log() << Verbose(0) << "============Molecule list=======================" << endl);
    21702558    molecules->Enumerate((ofstream *)&cout);
    2171     Log() << Verbose(0) << "============Menu===============================" << endl;
    2172     Log() << Verbose(0) << "a - set molecule (in)active" << endl;
    2173     Log() << Verbose(0) << "e - edit molecules (load, parse, save)" << endl;
    2174     Log() << Verbose(0) << "g - globally manipulate atoms in molecule" << endl;
    2175     Log() << Verbose(0) << "M - Merge molecules" << endl;
    2176     Log() << Verbose(0) << "m - manipulate atoms" << endl;
    2177     Log() << Verbose(0) << "-----------------------------------------------" << endl;
    2178     Log() << Verbose(0) << "c - edit the current configuration" << endl;
    2179     Log() << Verbose(0) << "-----------------------------------------------" << endl;
    2180     Log() << Verbose(0) << "s - save current setup to config file" << endl;
    2181     Log() << Verbose(0) << "T - call the current test routine" << endl;
    2182     Log() << Verbose(0) << "q - quit" << endl;
    2183     Log() << Verbose(0) << "===============================================" << endl;
    2184     Log() << Verbose(0) << "Input: ";
     2559    DoLog(0) && (Log() << Verbose(0) << "============Menu===============================" << endl);
     2560    DoLog(0) && (Log() << Verbose(0) << "a - set molecule (in)active" << endl);
     2561    DoLog(0) && (Log() << Verbose(0) << "e - edit molecules (load, parse, save)" << endl);
     2562    DoLog(0) && (Log() << Verbose(0) << "g - globally manipulate atoms in molecule" << endl);
     2563    DoLog(0) && (Log() << Verbose(0) << "M - Merge molecules" << endl);
     2564    DoLog(0) && (Log() << Verbose(0) << "m - manipulate atoms" << endl);
     2565    DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl);
     2566    DoLog(0) && (Log() << Verbose(0) << "c - edit the current configuration" << endl);
     2567    DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl);
     2568    DoLog(0) && (Log() << Verbose(0) << "s - save current setup to config file" << endl);
     2569    DoLog(0) && (Log() << Verbose(0) << "T - call the current test routine" << endl);
     2570    DoLog(0) && (Log() << Verbose(0) << "q - quit" << endl);
     2571    DoLog(0) && (Log() << Verbose(0) << "===============================================" << endl);
     2572    DoLog(0) && (Log() << Verbose(0) << "Input: ");
    21852573    cin >> choice;
    21862574
     
    21882576      case 'a':  // (in)activate molecule
    21892577        {
    2190           Log() << Verbose(0) << "Enter index of molecule: ";
     2578          DoLog(0) && (Log() << Verbose(0) << "Enter index of molecule: ");
    21912579          cin >> j;
    21922580          for(MoleculeList::iterator ListRunner = molecules->ListOfMolecules.begin(); ListRunner != molecules->ListOfMolecules.end(); ListRunner++)
     
    22342622  // save element data base
    22352623  if (periode->StorePeriodentafel(configuration->databasepath)) //ElementsFileName
    2236     Log() << Verbose(0) << "Saving of elements.db successful." << endl;
     2624    DoLog(0) && (Log() << Verbose(0) << "Saving of elements.db successful." << endl);
    22372625  else
    2238     Log() << Verbose(0) << "Saving of elements.db failed." << endl;
     2626    DoLog(0) && (Log() << Verbose(0) << "Saving of elements.db failed." << endl);
    22392627
    22402628  delete(molecules); // also free's all molecules contained
     
    22472635    << MemoryUsageObserver::getInstance()->getUsedMemorySize() << endl;
    22482636  MemoryUsageObserver::purgeInstance();
     2637  logger::purgeInstance();
     2638  errorLogger::purgeInstance();
    22492639
    22502640  return (0);
  • src/config.cpp

    re5ad5c ree7e25  
    55 */
    66
     7#include <stdio.h>
     8#include <cstring>
     9
    710#include "atom.hpp"
     11#include "bond.hpp"
    812#include "config.hpp"
    913#include "element.hpp"
     
    1519#include "molecule.hpp"
    1620#include "periodentafel.hpp"
     21#include "World.hpp"
    1722
    1823/******************************** Functions for class ConfigFileBuffer **********************/
     
    2429    char number1[8];
    2530    char number2[8];
    26     char *dummy1, *dummy2;
     31    const char *dummy1, *dummy2;
    2732    //Log() << Verbose(0) << s1 << "  " << s2 << endl;
    2833    dummy1 = strchr(s1, '_')+sizeof(char)*5;  // go just after "Ion_Type"
     
    6974  file= new ifstream(filename);
    7075  if (file == NULL) {
    71     eLog() << Verbose(0) << "ERROR: config file " << filename << " missing!" << endl;
     76    DoeLog(1) && (eLog()<< Verbose(1) << "config file " << filename << " missing!" << endl);
    7277    return;
    7378  }
     
    8085  file->clear();
    8186  file->seekg(file_position, ios::beg);
    82   Log() << Verbose(1) << NoLines-1 << " lines were recognized." << endl;
     87  DoLog(1) && (Log() << Verbose(1) << NoLines-1 << " lines were recognized." << endl);
    8388
    8489  // allocate buffer's 1st dimension
    8590  if (buffer != NULL) {
    86     eLog() << Verbose(0) << "ERROR: FileBuffer->buffer is not NULL!" << endl;
     91    DoeLog(1) && (eLog()<< Verbose(1) << "FileBuffer->buffer is not NULL!" << endl);
    8792    return;
    8893  } else
     
    100105    lines++;
    101106  } while((!file->eof()) && (lines < NoLines));
    102   Log() << Verbose(1) << lines-1 << " lines were read into the buffer." << endl;
     107  DoLog(1) && (Log() << Verbose(1) << lines-1 << " lines were read into the buffer." << endl);
    103108
    104109  // close and exit
     
    137142void ConfigFileBuffer::MapIonTypesInBuffer(const int NoAtoms)
    138143{
    139   map<const char *, int, IonTypeCompare> LineList;
     144  map<const char *, int, IonTypeCompare> IonTypeLineMap;
    140145  if (LineMapping == NULL) {
    141     eLog() << Verbose(0) << "map pointer is NULL: " << LineMapping << endl;
     146    DoeLog(0) && (eLog()<< Verbose(0) << "map pointer is NULL: " << LineMapping << endl);
     147    performCriticalExit();
    142148    return;
    143149  }
     
    145151  // put all into hashed map
    146152  for (int i=0; i<NoAtoms; ++i) {
    147     LineList.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
     153    IonTypeLineMap.insert(pair<const char *, int> (buffer[CurrentLine+i], CurrentLine+i));
    148154  }
    149155
    150156  // fill map
    151157  int nr=0;
    152   for (map<const char *, int, IonTypeCompare>::iterator runner = LineList.begin(); runner != LineList.end(); ++runner) {
     158  for (map<const char *, int, IonTypeCompare>::iterator runner = IonTypeLineMap.begin(); runner != IonTypeLineMap.end(); ++runner) {
    153159    if (CurrentLine+nr < NoLines)
    154160      LineMapping[CurrentLine+(nr++)] = runner->second;
    155     else
    156       eLog() << Verbose(0) << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl;
     161    else {
     162      DoeLog(0) && (eLog()<< Verbose(0) << "config::MapIonTypesInBuffer - NoAtoms is wrong: We are past the end of the file!" << endl);
     163      performCriticalExit();
     164    }
    157165  }
    158166}
     
    200208    Free(&ThermostatNames[j]);
    201209  Free(&ThermostatNames);
     210
     211  if (BG != NULL)
     212    delete(BG);
    202213};
    203214
     
    239250        Thermostat = None;
    240251      } else {
    241         Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
     252        DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    242253        Thermostat = None;
    243254      }
     
    247258        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read scaling frequency
    248259      } else {
    249         Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
     260        DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    250261        Thermostat = None;
    251262      }
     
    255266        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, int_type, &ScaleTempStep, 1, critical); // read collision rate
    256267      } else {
    257         Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
     268        DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    258269        Thermostat = None;
    259270      }
     
    263274        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read gamma
    264275        if (ParseForParameter(verbose,fb,"Thermostat", 0, 3, 1, double_type, &alpha, 1, optional)) {
    265           Log() << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << "." << endl;
     276          DoLog(2) && (Log() << Verbose(2) << "Extended Stochastic Thermostat detected with interpolation coefficient " << alpha << "." << endl);
    266277        } else {
    267278          alpha = 1.;
    268279        }
    269280      } else {
    270         Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
     281        DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    271282        Thermostat = None;
    272283      }
     
    276287        ParseForParameter(verbose,fb,"Thermostat", 0, 2, 1, double_type, &TempFrequency, 1, critical); // read \tau_T
    277288      } else {
    278         Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
     289        DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    279290        Thermostat = None;
    280291      }
     
    285296        alpha = 0.;
    286297      } else {
    287         Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl;
     298        DoLog(1) && (Log() << Verbose(1) << "Warning: " << ThermostatNames[0] << " thermostat not implemented, falling back to None." << endl);
    288299        Thermostat = None;
    289300      }
    290301    } else {
    291       Log() << Verbose(1) << " Warning: thermostat name was not understood!" << endl;
     302      DoLog(1) && (Log() << Verbose(1) << " Warning: thermostat name was not understood!" << endl);
    292303      Thermostat = None;
    293304    }
    294305  } else {
    295306    if ((MaxOuterStep > 0) && (TargetTemp != 0))
    296       Log() << Verbose(2) <<  "No thermostat chosen despite finite temperature MD, falling back to None." << endl;
     307      DoLog(2) && (Log() << Verbose(2) <<  "No thermostat chosen despite finite temperature MD, falling back to None." << endl);
    297308    Thermostat = None;
    298309  }
     
    310321
    311322  do {
    312     Log() << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl;
    313     Log() << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl;
    314     Log() << Verbose(0) << " B - Default path (for runtime files)" << endl;
    315     Log() << Verbose(0) << " C - Path of pseudopotential files" << endl;
    316     Log() << Verbose(0) << " D - Number of coefficient sharing processes" << endl;
    317     Log() << Verbose(0) << " E - Number of wave function sharing processes" << endl;
    318     Log() << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl;
    319     Log() << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl;
    320     Log() << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl;
    321     Log() << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl;
    322     Log() << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl;
    323     Log() << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl;
    324     Log() << Verbose(0) << " L - 0: Wannier centres as calculated, 1: common centre for all, 2: unite centres according to spread, 3: cell centre, 4: shifted to nearest grid point" << endl;
    325     Log() << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl;
    326     Log() << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl;
    327     Log() << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl;
    328     Log() << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl;
    329     Log() << Verbose(0) << " Q - Initial integer value of random number generator" << endl;
    330     Log() << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl;
    331     Log() << Verbose(0) << " T - Output visual after ...th step" << endl;
    332     Log() << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl;
    333     Log() << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl;
    334     Log() << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl;
    335     Log() << Verbose(0) << " Z - Maximum number of minimization iterations" << endl;
    336     Log() << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl;
    337     Log() << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl;
    338     Log() << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl;
    339     Log() << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl;
    340     Log() << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl;
    341     Log() << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl;
    342     Log() << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl;
     323    DoLog(0) && (Log() << Verbose(0) << "===========EDIT CONFIGURATION============================" << endl);
     324    DoLog(0) && (Log() << Verbose(0) << " A - mainname (prefix for all runtime files)" << endl);
     325    DoLog(0) && (Log() << Verbose(0) << " B - Default path (for runtime files)" << endl);
     326    DoLog(0) && (Log() << Verbose(0) << " C - Path of pseudopotential files" << endl);
     327    DoLog(0) && (Log() << Verbose(0) << " D - Number of coefficient sharing processes" << endl);
     328    DoLog(0) && (Log() << Verbose(0) << " E - Number of wave function sharing processes" << endl);
     329    DoLog(0) && (Log() << Verbose(0) << " F - 0: Don't output density for OpenDX, 1: do" << endl);
     330    DoLog(0) && (Log() << Verbose(0) << " G - 0: Don't output physical data, 1: do" << endl);
     331    DoLog(0) && (Log() << Verbose(0) << " H - 0: Don't output densities of each unperturbed orbital for OpenDX, 1: do" << endl);
     332    DoLog(0) && (Log() << Verbose(0) << " I - 0: Don't output current density for OpenDX, 1: do" << endl);
     333    DoLog(0) && (Log() << Verbose(0) << " J - 0: Don't do the full current calculation, 1: do" << endl);
     334    DoLog(0) && (Log() << Verbose(0) << " K - 0: Don't do perturbation calculation to obtain susceptibility and shielding, 1: do" << endl);
     335    DoLog(0) && (Log() << Verbose(0) << " L - 0: Wannier centres as calculated, 1: common centre for all, 2: unite centres according to spread, 3: cell centre, 4: shifted to nearest grid point" << endl);
     336    DoLog(0) && (Log() << Verbose(0) << " M - Absolute begin of unphysical sawtooth transfer for position operator within cell" << endl);
     337    DoLog(0) && (Log() << Verbose(0) << " N - (0,1,2) x,y,z-plane to do two-dimensional current vector cut" << endl);
     338    DoLog(0) && (Log() << Verbose(0) << " O - Absolute position along vector cut axis for cut plane" << endl);
     339    DoLog(0) && (Log() << Verbose(0) << " P - Additional Gram-Schmidt-Orthonormalization to stabilize numerics" << endl);
     340    DoLog(0) && (Log() << Verbose(0) << " Q - Initial integer value of random number generator" << endl);
     341    DoLog(0) && (Log() << Verbose(0) << " R - for perturbation 0, for structure optimization defines upper limit of iterations" << endl);
     342    DoLog(0) && (Log() << Verbose(0) << " T - Output visual after ...th step" << endl);
     343    DoLog(0) && (Log() << Verbose(0) << " U - Output source densities of wave functions after ...th step" << endl);
     344    DoLog(0) && (Log() << Verbose(0) << " X - minimization iterations per wave function, if unsure leave at default value 0" << endl);
     345    DoLog(0) && (Log() << Verbose(0) << " Y - tolerance value for total spread in iterative Jacobi diagonalization" << endl);
     346    DoLog(0) && (Log() << Verbose(0) << " Z - Maximum number of minimization iterations" << endl);
     347    DoLog(0) && (Log() << Verbose(0) << " a - Relative change in total energy to stop min. iteration" << endl);
     348    DoLog(0) && (Log() << Verbose(0) << " b - Relative change in kinetic energy to stop min. iteration" << endl);
     349    DoLog(0) && (Log() << Verbose(0) << " c - Check stop conditions every ..th step during min. iteration" << endl);
     350    DoLog(0) && (Log() << Verbose(0) << " e - Maximum number of minimization iterations during initial level" << endl);
     351    DoLog(0) && (Log() << Verbose(0) << " f - Relative change in total energy to stop min. iteration during initial level" << endl);
     352    DoLog(0) && (Log() << Verbose(0) << " g - Relative change in kinetic energy to stop min. iteration during initial level" << endl);
     353    DoLog(0) && (Log() << Verbose(0) << " h - Check stop conditions every ..th step during min. iteration during initial level" << endl);
    343354//    Log() << Verbose(0) << " j - six lower diagonal entries of matrix, defining the unit cell" << endl;
    344     Log() << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl;
    345     Log() << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl;
    346     Log() << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl;
    347     Log() << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl;
    348     Log() << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl;
    349     Log() << Verbose(0) << " p - Number of Riemann levels" << endl;
    350     Log() << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl;
    351     Log() << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl;
    352     Log() << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl;
    353     Log() << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl;
    354     Log() << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl;
    355     Log() << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl;
    356     Log() << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl;
    357     Log() << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl;
    358     Log() << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl;
    359     Log() << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl;
    360     Log() << Verbose(0) << "=========================================================" << endl;
    361     Log() << Verbose(0) << "INPUT: ";
     355    DoLog(0) && (Log() << Verbose(0) << " k - Energy cutoff of plane wave basis in Hartree" << endl);
     356    DoLog(0) && (Log() << Verbose(0) << " l - Maximum number of levels in multi-level-ansatz" << endl);
     357    DoLog(0) && (Log() << Verbose(0) << " m - Factor by which grid nodes increase between standard and upper level" << endl);
     358    DoLog(0) && (Log() << Verbose(0) << " n - 0: Don't use RiemannTensor, 1: Do" << endl);
     359    DoLog(0) && (Log() << Verbose(0) << " o - Factor by which grid nodes increase between Riemann and standard(?) level" << endl);
     360    DoLog(0) && (Log() << Verbose(0) << " p - Number of Riemann levels" << endl);
     361    DoLog(0) && (Log() << Verbose(0) << " r - 0: Don't Use RiemannTensor, 1: Do" << endl);
     362    DoLog(0) && (Log() << Verbose(0) << " s - 0: Doubly occupied orbitals, 1: Up-/Down-Orbitals" << endl);
     363    DoLog(0) && (Log() << Verbose(0) << " t - Number of orbitals (depends pn SpinType)" << endl);
     364    DoLog(0) && (Log() << Verbose(0) << " u - Number of SpinUp orbitals (depends on SpinType)" << endl);
     365    DoLog(0) && (Log() << Verbose(0) << " v - Number of SpinDown orbitals (depends on SpinType)" << endl);
     366    DoLog(0) && (Log() << Verbose(0) << " w - Number of additional, unoccupied orbitals" << endl);
     367    DoLog(0) && (Log() << Verbose(0) << " x - radial cutoff for ewald summation in Bohrradii" << endl);
     368    DoLog(0) && (Log() << Verbose(0) << " y - 0: Don't do structure optimization beforehand, 1: Do" << endl);
     369    DoLog(0) && (Log() << Verbose(0) << " z - 0: Units are in Bohr radii, 1: units are in Aengstrom" << endl);
     370    DoLog(0) && (Log() << Verbose(0) << " i - 0: Coordinates given in file are absolute, 1: ... are relative to unit cell" << endl);
     371    DoLog(0) && (Log() << Verbose(0) << "=========================================================" << endl);
     372    DoLog(0) && (Log() << Verbose(0) << "INPUT: ");
    362373    cin >> choice;
    363374
    364375    switch (choice) {
    365376        case 'A': // mainname
    366           Log() << Verbose(0) << "Old: " << config::mainname << "\t new: ";
     377          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::mainname << "\t new: ");
    367378          cin >> config::mainname;
    368379          break;
    369380        case 'B': // defaultpath
    370           Log() << Verbose(0) << "Old: " << config::defaultpath << "\t new: ";
     381          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::defaultpath << "\t new: ");
    371382          cin >> config::defaultpath;
    372383          break;
    373384        case 'C': // pseudopotpath
    374           Log() << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ";
     385          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::pseudopotpath << "\t new: ");
    375386          cin >> config::pseudopotpath;
    376387          break;
    377388
    378389        case 'D': // ProcPEGamma
    379           Log() << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ";
     390          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ProcPEGamma << "\t new: ");
    380391          cin >> config::ProcPEGamma;
    381392          break;
    382393        case 'E': // ProcPEPsi
    383           Log() << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ";
     394          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ProcPEPsi << "\t new: ");
    384395          cin >> config::ProcPEPsi;
    385396          break;
    386397        case 'F': // DoOutVis
    387           Log() << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ";
     398          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutVis << "\t new: ");
    388399          cin >> config::DoOutVis;
    389400          break;
    390401        case 'G': // DoOutMes
    391           Log() << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ";
     402          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutMes << "\t new: ");
    392403          cin >> config::DoOutMes;
    393404          break;
    394405        case 'H': // DoOutOrbitals
    395           Log() << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ";
     406          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutOrbitals << "\t new: ");
    396407          cin >> config::DoOutOrbitals;
    397408          break;
    398409        case 'I': // DoOutCurrent
    399           Log() << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ";
     410          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoOutCurrent << "\t new: ");
    400411          cin >> config::DoOutCurrent;
    401412          break;
    402413        case 'J': // DoFullCurrent
    403           Log() << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ";
     414          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoFullCurrent << "\t new: ");
    404415          cin >> config::DoFullCurrent;
    405416          break;
    406417        case 'K': // DoPerturbation
    407           Log() << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ";
     418          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::DoPerturbation << "\t new: ");
    408419          cin >> config::DoPerturbation;
    409420          break;
    410421        case 'L': // CommonWannier
    411           Log() << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ";
     422          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::CommonWannier << "\t new: ");
    412423          cin >> config::CommonWannier;
    413424          break;
    414425        case 'M': // SawtoothStart
    415           Log() << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ";
     426          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::SawtoothStart << "\t new: ");
    416427          cin >> config::SawtoothStart;
    417428          break;
    418429        case 'N': // VectorPlane
    419           Log() << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ";
     430          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::VectorPlane << "\t new: ");
    420431          cin >> config::VectorPlane;
    421432          break;
    422433        case 'O': // VectorCut
    423           Log() << Verbose(0) << "Old: " << config::VectorCut << "\t new: ";
     434          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::VectorCut << "\t new: ");
    424435          cin >> config::VectorCut;
    425436          break;
    426437        case 'P': // UseAddGramSch
    427           Log() << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ";
     438          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::UseAddGramSch << "\t new: ");
    428439          cin >> config::UseAddGramSch;
    429440          break;
    430441        case 'Q': // Seed
    431           Log() << Verbose(0) << "Old: " << config::Seed << "\t new: ";
     442          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::Seed << "\t new: ");
    432443          cin >> config::Seed;
    433444          break;
    434445
    435446        case 'R': // MaxOuterStep
    436           Log() << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ";
     447          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxOuterStep << "\t new: ");
    437448          cin >> config::MaxOuterStep;
    438449          break;
    439450        case 'T': // OutVisStep
    440           Log() << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ";
     451          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::OutVisStep << "\t new: ");
    441452          cin >> config::OutVisStep;
    442453          break;
    443454        case 'U': // OutSrcStep
    444           Log() << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ";
     455          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::OutSrcStep << "\t new: ");
    445456          cin >> config::OutSrcStep;
    446457          break;
    447458        case 'X': // MaxPsiStep
    448           Log() << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ";
     459          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxPsiStep << "\t new: ");
    449460          cin >> config::MaxPsiStep;
    450461          break;
    451462        case 'Y': // EpsWannier
    452           Log() << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ";
     463          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::EpsWannier << "\t new: ");
    453464          cin >> config::EpsWannier;
    454465          break;
    455466
    456467        case 'Z': // MaxMinStep
    457           Log() << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ";
     468          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxMinStep << "\t new: ");
    458469          cin >> config::MaxMinStep;
    459470          break;
    460471        case 'a': // RelEpsTotalEnergy
    461           Log() << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ";
     472          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelEpsTotalEnergy << "\t new: ");
    462473          cin >> config::RelEpsTotalEnergy;
    463474          break;
    464475        case 'b': // RelEpsKineticEnergy
    465           Log() << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ";
     476          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelEpsKineticEnergy << "\t new: ");
    466477          cin >> config::RelEpsKineticEnergy;
    467478          break;
    468479        case 'c': // MaxMinStopStep
    469           Log() << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ";
     480          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxMinStopStep << "\t new: ");
    470481          cin >> config::MaxMinStopStep;
    471482          break;
    472483        case 'e': // MaxInitMinStep
    473           Log() << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ";
     484          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxInitMinStep << "\t new: ");
    474485          cin >> config::MaxInitMinStep;
    475486          break;
    476487        case 'f': // InitRelEpsTotalEnergy
    477           Log() << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ";
     488          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitRelEpsTotalEnergy << "\t new: ");
    478489          cin >> config::InitRelEpsTotalEnergy;
    479490          break;
    480491        case 'g': // InitRelEpsKineticEnergy
    481           Log() << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ";
     492          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitRelEpsKineticEnergy << "\t new: ");
    482493          cin >> config::InitRelEpsKineticEnergy;
    483494          break;
    484495        case 'h': // InitMaxMinStopStep
    485           Log() << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ";
     496          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::InitMaxMinStopStep << "\t new: ");
    486497          cin >> config::InitMaxMinStopStep;
    487498          break;
     
    489500//        case 'j': // BoxLength
    490501//          Log() << Verbose(0) << "enter lower triadiagonalo form of basis matrix" << endl << endl;
     502//          double * const cell_size = World::get()->cell_size;
    491503//          for (int i=0;i<6;i++) {
    492504//            Log() << Verbose(0) << "Cell size" << i << ": ";
    493 //            cin >> mol->cell_size[i];
     505//            cin >> cell_size[i];
    494506//          }
    495507//          break;
    496508
    497509        case 'k': // ECut
    498           Log() << Verbose(0) << "Old: " << config::ECut << "\t new: ";
     510          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::ECut << "\t new: ");
    499511          cin >> config::ECut;
    500512          break;
    501513        case 'l': // MaxLevel
    502           Log() << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ";
     514          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxLevel << "\t new: ");
    503515          cin >> config::MaxLevel;
    504516          break;
    505517        case 'm': // RiemannTensor
    506           Log() << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ";
     518          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RiemannTensor << "\t new: ");
    507519          cin >> config::RiemannTensor;
    508520          break;
    509521        case 'n': // LevRFactor
    510           Log() << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ";
     522          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::LevRFactor << "\t new: ");
    511523          cin >> config::LevRFactor;
    512524          break;
    513525        case 'o': // RiemannLevel
    514           Log() << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ";
     526          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RiemannLevel << "\t new: ");
    515527          cin >> config::RiemannLevel;
    516528          break;
    517529        case 'p': // Lev0Factor
    518           Log() << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ";
     530          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::Lev0Factor << "\t new: ");
    519531          cin >> config::Lev0Factor;
    520532          break;
    521533        case 'r': // RTActualUse
    522           Log() << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ";
     534          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RTActualUse << "\t new: ");
    523535          cin >> config::RTActualUse;
    524536          break;
    525537        case 's': // PsiType
    526           Log() << Verbose(0) << "Old: " << config::PsiType << "\t new: ";
     538          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiType << "\t new: ");
    527539          cin >> config::PsiType;
    528540          break;
    529541        case 't': // MaxPsiDouble
    530           Log() << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ";
     542          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::MaxPsiDouble << "\t new: ");
    531543          cin >> config::MaxPsiDouble;
    532544          break;
    533545        case 'u': // PsiMaxNoUp
    534           Log() << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ";
     546          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiMaxNoUp << "\t new: ");
    535547          cin >> config::PsiMaxNoUp;
    536548          break;
    537549        case 'v': // PsiMaxNoDown
    538           Log() << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ";
     550          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::PsiMaxNoDown << "\t new: ");
    539551          cin >> config::PsiMaxNoDown;
    540552          break;
    541553        case 'w': // AddPsis
    542           Log() << Verbose(0) << "Old: " << config::AddPsis << "\t new: ";
     554          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::AddPsis << "\t new: ");
    543555          cin >> config::AddPsis;
    544556          break;
    545557
    546558        case 'x': // RCut
    547           Log() << Verbose(0) << "Old: " << config::RCut << "\t new: ";
     559          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RCut << "\t new: ");
    548560          cin >> config::RCut;
    549561          break;
    550562        case 'y': // StructOpt
    551           Log() << Verbose(0) << "Old: " << config::StructOpt << "\t new: ";
     563          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::StructOpt << "\t new: ");
    552564          cin >> config::StructOpt;
    553565          break;
    554566        case 'z': // IsAngstroem
    555           Log() << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ";
     567          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::IsAngstroem << "\t new: ");
    556568          cin >> config::IsAngstroem;
    557569          break;
    558570        case 'i': // RelativeCoord
    559           Log() << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ";
     571          DoLog(0) && (Log() << Verbose(0) << "Old: " << config::RelativeCoord << "\t new: ");
    560572          cin >> config::RelativeCoord;
    561573          break;
     
    636648  }
    637649  strcpy(configname, ptr);
    638   Log() << Verbose(0) << "Found configpath: " << configpath << ", dir slash was found at " << last << ", config name is " << configname << "." << endl;
     650  DoLog(0) && (Log() << Verbose(0) << "Found configpath: " << configpath << ", dir slash was found at " << last << ", config name is " << configname << "." << endl);
    639651  delete[](buffer);
    640652};
     
    647659{
    648660  if (FileBuffer != NULL) {
    649     eLog() << Verbose(1) << "WARNING: deleting present FileBuffer in PrepareFileBuffer()." << endl;
     661    DoeLog(2) && (eLog()<< Verbose(2) << "deleting present FileBuffer in PrepareFileBuffer()." << endl);
    650662    delete(FileBuffer);
    651663  }
     
    673685
    674686  if (mol == NULL) {
    675     eLog() << Verbose(0) << "Molecule is not allocated in LoadMolecule(), exit.";
     687    DoeLog(0) && (eLog()<< Verbose(0) << "Molecule is not allocated in LoadMolecule(), exit.");
    676688    performCriticalExit();
    677689  }
     
    679691  ParseForParameter(verbose,FileBuffer,"MaxTypes", 0, 1, 1, int_type, &(MaxTypes), 1, critical);
    680692  if (MaxTypes == 0) {
    681     eLog() << Verbose(0) << "There are no atoms according to MaxTypes in this config file." << endl;
     693    DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms according to MaxTypes in this config file." << endl);
     694    //performCriticalExit();
    682695  } else {
    683696    // prescan number of ions per type
    684     Log() << Verbose(0) << "Prescanning ions per type: " << endl;
     697    DoLog(0) && (Log() << Verbose(0) << "Prescanning ions per type: " << endl);
    685698    int NoAtoms = 0;
    686699    for (int i=0; i < MaxTypes; i++) {
     
    689702      ParseForParameter(verbose,FileBuffer, name, 0, 2, 1, int_type, &Z, 1, critical);
    690703      elementhash[i] = periode->FindElement(Z);
    691       Log() << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl;
     704      DoLog(1) && (Log() << Verbose(1) << i << ". Z = " << elementhash[i]->Z << " with " << No[i] << " ions." << endl);
    692705      NoAtoms += No[i];
    693706    }
     
    697710    sprintf(name,"Ion_Type%i",MaxTypes);
    698711    if (!ParseForParameter(verbose,FileBuffer, (const char*)name, 1, 1, 1, int_type, &value[0], 1, critical)) {
    699       eLog() << Verbose(0) << "There are no atoms in the config file!" << endl;
     712      DoeLog(0) && (eLog()<< Verbose(0) << "There are no atoms in the config file!" << endl);
     713      performCriticalExit();
    700714      return;
    701715    }
     
    714728      bool status = true;
    715729      while (status) {
    716         Log() << Verbose(0) << "Currently parsing MD step " << repetition << "." << endl;
     730        DoLog(0) && (Log() << Verbose(0) << "Currently parsing MD step " << repetition << "." << endl);
    717731        for (int i=0; i < MaxTypes; i++) {
    718732          sprintf(name,"Ion_Type%i",i+1);
     
    780794      }
    781795      repetition--;
    782       Log() << Verbose(0) << "Found " << repetition << " trajectory steps." << endl;
     796      DoLog(0) && (Log() << Verbose(0) << "Found " << repetition << " trajectory steps." << endl);
    783797      if (repetition <= 1)  // if onyl one step, desactivate use of trajectories
    784798        mol->MDSteps = 0;
     
    792806              ParseForParameter(verbose,FileBuffer, "Ion_Type1_1", 0, 3, 1, double_type, &value[2], repetition, (repetition == 0) ? critical : optional))
    793807        repetition++;
    794       Log() << Verbose(0) << "I found " << repetition << " times the keyword Ion_Type1_1." << endl;
     808      DoLog(0) && (Log() << Verbose(0) << "I found " << repetition << " times the keyword Ion_Type1_1." << endl);
    795809      // parse in molecule coordinates
    796810      for (int i=0; i < MaxTypes; i++) {
     
    841855  ifstream *file = new ifstream(filename);
    842856  if (file == NULL) {
    843     eLog() << Verbose(0) << "ERROR: config file " << filename << " missing!" << endl;
     857    DoeLog(1) && (eLog()<< Verbose(1) << "config file " << filename << " missing!" << endl);
    844858    return;
    845859  }
     
    953967  // Unit cell and magnetic field
    954968  ParseForParameter(verbose,FileBuffer, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
    955   mol->cell_size[0] = BoxLength[0];
    956   mol->cell_size[1] = BoxLength[3];
    957   mol->cell_size[2] = BoxLength[4];
    958   mol->cell_size[3] = BoxLength[6];
    959   mol->cell_size[4] = BoxLength[7];
    960   mol->cell_size[5] = BoxLength[8];
     969  double * const cell_size = World::get()->cell_size;
     970  cell_size[0] = BoxLength[0];
     971  cell_size[1] = BoxLength[3];
     972  cell_size[2] = BoxLength[4];
     973  cell_size[3] = BoxLength[6];
     974  cell_size[4] = BoxLength[7];
     975  cell_size[5] = BoxLength[8];
    961976  //if (1) fprintf(stderr,"\n");
    962977
     
    10451060
    10461061  // 2. parse the bond graph file if given
    1047   BG = new BondGraph(IsAngstroem);
    1048   if (BG->LoadBondLengthTable(BondGraphFileName)) {
    1049     Log() << Verbose(0) << "Bond length table loaded successfully." << endl;
    1050   } else {
    1051     Log() << Verbose(0) << "Bond length table loading failed." << endl;
     1062  if (BG == NULL) {
     1063    BG = new BondGraph(IsAngstroem);
     1064    if (BG->LoadBondLengthTable(BondGraphFileName)) {
     1065      DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
     1066    } else {
     1067      DoeLog(1) && (eLog()<< Verbose(1) << "Bond length table loading failed." << endl);
     1068    }
    10521069  }
    10531070
    10541071  // 3. parse the molecule in
    10551072  LoadMolecule(mol, FileBuffer, periode, FastParsing);
     1073  mol->SetNameFromFilename(filename);
    10561074  mol->ActiveFlag = true;
    10571075  MolList->insert(mol);
    10581076
    10591077  // 4. dissect the molecule into connected subgraphs
    1060   BG->ConstructBondGraph(mol);
     1078  // don't do this here ...
     1079  //MolList->DissectMoleculeIntoConnectedSubgraphs(mol,this);
     1080  //delete(mol);
    10611081
    10621082  delete(FileBuffer);
     
    10741094  ifstream *file = new ifstream(filename);
    10751095  if (file == NULL) {
    1076     eLog() << Verbose(0) << "ERROR: config file " << filename << " missing!" << endl;
     1096    DoeLog(1) && (eLog()<< Verbose(1) << "config file " << filename << " missing!" << endl);
    10771097    return;
    10781098  }
     
    11521172
    11531173  ParseForParameter(verbose,file, "BoxLength", 0, 3, 3, lower_trigrid, BoxLength, 1, critical); /* Lattice->RealBasis */
    1154   mol->cell_size[0] = BoxLength[0];
    1155   mol->cell_size[1] = BoxLength[3];
    1156   mol->cell_size[2] = BoxLength[4];
    1157   mol->cell_size[3] = BoxLength[6];
    1158   mol->cell_size[4] = BoxLength[7];
    1159   mol->cell_size[5] = BoxLength[8];
     1174  double * const cell_size = World::get()->cell_size;
     1175  cell_size[0] = BoxLength[0];
     1176  cell_size[1] = BoxLength[3];
     1177  cell_size[2] = BoxLength[4];
     1178  cell_size[3] = BoxLength[6];
     1179  cell_size[4] = BoxLength[7];
     1180  cell_size[5] = BoxLength[8];
    11601181  if (1) fprintf(stderr,"\n");
    11611182  config::DoPerturbation = 0;
     
    12331254  BG = new BondGraph(IsAngstroem);
    12341255  if (BG->LoadBondLengthTable(BondGraphFileName)) {
    1235     Log() << Verbose(0) << "Bond length table loaded successfully." << endl;
     1256    DoLog(0) && (Log() << Verbose(0) << "Bond length table loaded successfully." << endl);
    12361257  } else {
    1237     Log() << Verbose(0) << "Bond length table loading failed." << endl;
     1258    DoLog(0) && (Log() << Verbose(0) << "Bond length table loading failed." << endl);
    12381259  }
    12391260
     
    12421263  for (i=MAX_ELEMENTS;i--;)
    12431264    elementhash[i] = NULL;
    1244   Log() << Verbose(0) << "Parsing Ions ..." << endl;
     1265  DoLog(0) && (Log() << Verbose(0) << "Parsing Ions ..." << endl);
    12451266  No=0;
    12461267  found = 0;
    12471268  while (getline(*file,zeile,'\n')) {
    12481269    if (zeile.find("Ions_Data") == 0) {
    1249       Log() << Verbose(1) << "found Ions_Data...begin parsing" << endl;
     1270      DoLog(1) && (Log() << Verbose(1) << "found Ions_Data...begin parsing" << endl);
    12501271      found ++;
    12511272    }
     
    12611282      input >> b;     // element mass
    12621283      elementhash[No] = periode->FindElement(Z);
    1263       Log() << Verbose(1) << "AtomNo: " << AtomNo << "\tZ: " << Z << "\ta:" << a << "\tl:"  << l << "\b:" << b << "\tElement:" << elementhash[No] << "\t:" << endl;
     1284      DoLog(1) && (Log() << Verbose(1) << "AtomNo: " << AtomNo << "\tZ: " << Z << "\ta:" << a << "\tl:"  << l << "\b:" << b << "\tElement:" << elementhash[No] << "\t:" << endl);
    12641285      for(i=0;i<AtomNo;i++) {
    12651286        if (!getline(*file,zeile,'\n')) {// parse on and on
    1266           Log() << Verbose(2) << "Error: Too few items in ionic list of element" << elementhash[No] << "." << endl << "Exiting." << endl;
     1287          DoLog(2) && (Log() << Verbose(2) << "Error: Too few items in ionic list of element" << elementhash[No] << "." << endl << "Exiting." << endl);
    12671288          // return 1;
    12681289        } else {
     
    12951316  // bring MaxTypes up to date
    12961317  mol->CountElements();
     1318  const double * const cell_size = World::get()->cell_size;
    12971319  ofstream * const output = new ofstream(filename, ios::out);
    12981320  if (output != NULL) {
     
    13651387    *output << endl;
    13661388    *output << "BoxLength\t\t\t# (Length of a unit cell)" << endl;
    1367     *output << mol->cell_size[0] << "\t" << endl;
    1368     *output << mol->cell_size[1] << "\t" << mol->cell_size[2] << "\t" << endl;
    1369     *output << mol->cell_size[3] << "\t" << mol->cell_size[4] << "\t" << mol->cell_size[5] << "\t" << endl;
     1389    *output << cell_size[0] << "\t" << endl;
     1390    *output << cell_size[1] << "\t" << cell_size[2] << "\t" << endl;
     1391    *output << cell_size[3] << "\t" << cell_size[4] << "\t" << cell_size[5] << "\t" << endl;
    13701392    // FIXME
    13711393    *output << endl;
     
    14101432    delete(output);
    14111433    return result;
    1412   } else
     1434  } else {
     1435    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open output file:" << filename << endl);
    14131436    return false;
     1437  }
    14141438};
    14151439
     
    14301454    *fname << filename << ".in";
    14311455    output = new ofstream(fname->str().c_str(), ios::out);
     1456    if (output == NULL) {
     1457      DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc output file:" << fname << endl);
     1458      delete(fname);
     1459      return false;
     1460    }
    14321461    *output << "% Created by MoleCuilder" << endl;
    14331462    *output << "mpqc: (" << endl;
     
    14681497    *fname << filename << ".hess.in";
    14691498    output = new ofstream(fname->str().c_str(), ios::out);
     1499    if (output == NULL) {
     1500      DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open mpqc hessian output file:" << fname << endl);
     1501      delete(fname);
     1502      return false;
     1503    }
    14701504    *output << "% Created by MoleCuilder" << endl;
    14711505    *output << "mpqc: (" << endl;
     
    14991533    delete(fname);
    15001534  }
     1535
     1536  return true;
     1537};
     1538
     1539/** Stores all atoms from all molecules in a PDB input file.
     1540 * Note that this format cannot be parsed again.
     1541 * \param *filename name of file (without ".in" suffix!)
     1542 * \param *MolList pointer to MoleculeListClass containing all atoms
     1543 */
     1544bool config::SavePDB(const char * const filename, const MoleculeListClass * const MolList) const
     1545{
     1546  int AtomNo = -1;
     1547  int MolNo = 0;
     1548  atom *Walker = NULL;
     1549  FILE *f = NULL;
     1550
     1551  char name[MAXSTRINGSIZE];
     1552  strncpy(name, filename, MAXSTRINGSIZE-1);
     1553  strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
     1554  f = fopen(name, "w" );
     1555  if (f == NULL) {
     1556    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
     1557    return false;
     1558  }
     1559  fprintf(f, "# Created by MoleCuilder\n");
     1560
     1561  for (MoleculeList::const_iterator Runner = MolList->ListOfMolecules.begin(); Runner != MolList->ListOfMolecules.end(); Runner++) {
     1562    Walker = (*Runner)->start;
     1563    int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo");
     1564    AtomNo = 0;
     1565    while (Walker->next != (*Runner)->end) {
     1566      Walker = Walker->next;
     1567      sprintf(name, "%2s%2d",Walker->type->symbol, elementNo[Walker->type->Z]);
     1568      elementNo[Walker->type->Z] = (elementNo[Walker->type->Z]+1) % 100;   // confine to two digits
     1569      fprintf(f,
     1570             "ATOM %6u %-4s %4s%c%4u    %8.3f%8.3f%8.3f%6.2f%6.2f      %4s%2s%2s\n",
     1571             Walker->nr,                /* atom serial number */
     1572             name,         /* atom name */
     1573             (*Runner)->name,      /* residue name */
     1574             'a'+(unsigned char)(AtomNo % 26),           /* letter for chain */
     1575             MolNo,         /* residue sequence number */
     1576             Walker->node->x[0],                 /* position X in Angstroem */
     1577             Walker->node->x[1],                 /* position Y in Angstroem */
     1578             Walker->node->x[2],                 /* position Z in Angstroem */
     1579             (double)Walker->type->Valence,         /* occupancy */
     1580             (double)Walker->type->NoValenceOrbitals,          /* temperature factor */
     1581             "0",            /* segment identifier */
     1582             Walker->type->symbol,    /* element symbol */
     1583             "0");           /* charge */
     1584      AtomNo++;
     1585    }
     1586    Free(&elementNo);
     1587    MolNo++;
     1588  }
     1589  fclose(f);
     1590
     1591  return true;
     1592};
     1593
     1594/** Stores all atoms in a PDB input file.
     1595 * Note that this format cannot be parsed again.
     1596 * \param *filename name of file (without ".in" suffix!)
     1597 * \param *mol pointer to molecule
     1598 */
     1599bool config::SavePDB(const char * const filename, const molecule * const mol) const
     1600{
     1601  int AtomNo = -1;
     1602  atom *Walker = NULL;
     1603  FILE *f = NULL;
     1604
     1605  int *elementNo = Calloc<int>(MAX_ELEMENTS, "config::SavePDB - elementNo");
     1606  char name[MAXSTRINGSIZE];
     1607  strncpy(name, filename, MAXSTRINGSIZE-1);
     1608  strncat(name, ".pdb", MAXSTRINGSIZE-(strlen(name)+1));
     1609  f = fopen(name, "w" );
     1610  if (f == NULL) {
     1611    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open pdb output file:" << name << endl);
     1612    Free(&elementNo);
     1613    return false;
     1614  }
     1615  fprintf(f, "# Created by MoleCuilder\n");
     1616
     1617  Walker = mol->start;
     1618  AtomNo = 0;
     1619  while (Walker->next != mol->end) {
     1620    Walker = Walker->next;
     1621    sprintf(name, "%2s%2d",Walker->type->symbol, elementNo[Walker->type->Z]);
     1622    elementNo[Walker->type->Z] = (elementNo[Walker->type->Z]+1) % 100;   // confine to two digits
     1623    fprintf(f,
     1624           "ATOM %6u %-4s %4s%c%4u    %8.3f%8.3f%8.3f%6.2f%6.2f      %4s%2s%2s\n",
     1625           Walker->nr,                /* atom serial number */
     1626           name,         /* atom name */
     1627           mol->name,      /* residue name */
     1628           'a'+(unsigned char)(AtomNo % 26),           /* letter for chain */
     1629           0,         /* residue sequence number */
     1630           Walker->node->x[0],                 /* position X in Angstroem */
     1631           Walker->node->x[1],                 /* position Y in Angstroem */
     1632           Walker->node->x[2],                 /* position Z in Angstroem */
     1633           (double)Walker->type->Valence,         /* occupancy */
     1634           (double)Walker->type->NoValenceOrbitals,          /* temperature factor */
     1635           "0",            /* segment identifier */
     1636           Walker->type->symbol,    /* element symbol */
     1637           "0");           /* charge */
     1638    AtomNo++;
     1639  }
     1640  fclose(f);
     1641  Free(&elementNo);
     1642
     1643  return true;
     1644};
     1645
     1646/** Stores all atoms in a TREMOLO data input file.
     1647 * Note that this format cannot be parsed again.
     1648 * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
     1649 * \param *filename name of file (without ".in" suffix!)
     1650 * \param *mol pointer to molecule
     1651 */
     1652bool config::SaveTREMOLO(const char * const filename, const molecule * const mol) const
     1653{
     1654  atom *Walker = NULL;
     1655  ofstream *output = NULL;
     1656  stringstream * const fname = new stringstream;
     1657
     1658  *fname << filename << ".data";
     1659  output = new ofstream(fname->str().c_str(), ios::out);
     1660  if (output == NULL) {
     1661    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
     1662    delete(fname);
     1663    return false;
     1664  }
     1665
     1666  // scan maximum number of neighbours
     1667  Walker = mol->start;
     1668  int MaxNeighbours = 0;
     1669  while (Walker->next != mol->end) {
     1670    Walker = Walker->next;
     1671    const int count = Walker->ListOfBonds.size();
     1672    if (MaxNeighbours < count)
     1673      MaxNeighbours = count;
     1674  }
     1675  *output << "# ATOMDATA Id name resName resSeq x=3 charge type neighbors=" << MaxNeighbours << endl;
     1676
     1677  Walker = mol->start;
     1678  while (Walker->next != mol->end) {
     1679    Walker = Walker->next;
     1680    *output << Walker->nr << "\t";
     1681    *output << Walker->Name << "\t";
     1682    *output << mol->name << "\t";
     1683    *output << 0 << "\t";
     1684    *output << Walker->node->x[0] << "\t" << Walker->node->x[1] << "\t" << Walker->node->x[2] << "\t";
     1685    *output << (double)Walker->type->Valence << "\t";
     1686    *output << Walker->type->symbol << "\t";
     1687    for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++)
     1688      *output << (*runner)->GetOtherAtom(Walker)->nr << "\t";
     1689    for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++)
     1690      *output << "-\t";
     1691    *output << endl;
     1692  }
     1693  output->flush();
     1694  output->close();
     1695  delete(output);
     1696  delete(fname);
     1697
     1698  return true;
     1699};
     1700
     1701/** Stores all atoms from all molecules in a TREMOLO data input file.
     1702 * Note that this format cannot be parsed again.
     1703 * Note that TREMOLO does not like Id starting at 0, but at 1. Atoms with Id 0 are discarded!
     1704 * \param *filename name of file (without ".in" suffix!)
     1705 * \param *MolList pointer to MoleculeListClass containing all atoms
     1706 */
     1707bool config::SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const
     1708{
     1709  atom *Walker = NULL;
     1710  ofstream *output = NULL;
     1711  stringstream * const fname = new stringstream;
     1712
     1713  *fname << filename << ".data";
     1714  output = new ofstream(fname->str().c_str(), ios::out);
     1715  if (output == NULL) {
     1716    DoeLog(1) && (eLog()<< Verbose(1) << "Cannot open tremolo output file:" << fname << endl);
     1717    delete(fname);
     1718    return false;
     1719  }
     1720
     1721  // scan maximum number of neighbours
     1722  int MaxNeighbours = 0;
     1723  for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
     1724    Walker = (*MolWalker)->start;
     1725    while (Walker->next != (*MolWalker)->end) {
     1726      Walker = Walker->next;
     1727      const int count = Walker->ListOfBonds.size();
     1728      if (MaxNeighbours < count)
     1729        MaxNeighbours = count;
     1730    }
     1731  }
     1732  *output << "# ATOMDATA Id name resName resSeq x=3 charge type neighbors=" << MaxNeighbours << endl;
     1733
     1734  // create global to local id map
     1735  int **LocalNotoGlobalNoMap = Calloc<int *>(MolList->ListOfMolecules.size(), "config::SaveTREMOLO - **LocalNotoGlobalNoMap");
     1736  {
     1737    int MolCounter = 0;
     1738    int AtomNo = 0;
     1739    for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
     1740      LocalNotoGlobalNoMap[MolCounter] = Calloc<int>(MolList->CountAllAtoms(), "config::SaveTREMOLO - *LocalNotoGlobalNoMap[]");
     1741
     1742      (*MolWalker)->SetIndexedArrayForEachAtomTo( LocalNotoGlobalNoMap[MolCounter], &atom::nr, IncrementalAbsoluteValue, &AtomNo);
     1743
     1744      MolCounter++;
     1745    }
     1746  }
     1747
     1748  // write the file
     1749  {
     1750    int MolCounter = 0;
     1751    int AtomNo = 0;
     1752    for (MoleculeList::const_iterator MolWalker = MolList->ListOfMolecules.begin(); MolWalker != MolList->ListOfMolecules.end(); MolWalker++) {
     1753      Walker = (*MolWalker)->start;
     1754      while (Walker->next != (*MolWalker)->end) {
     1755        Walker = Walker->next;
     1756        *output << AtomNo+1 << "\t";
     1757        *output << Walker->Name << "\t";
     1758        *output << (*MolWalker)->name << "\t";
     1759        *output << MolCounter+1 << "\t";
     1760        *output << Walker->node->x[0] << "\t" << Walker->node->x[1] << "\t" << Walker->node->x[2] << "\t";
     1761        *output << (double)Walker->type->Valence << "\t";
     1762        *output << Walker->type->symbol << "\t";
     1763        for (BondList::iterator runner = Walker->ListOfBonds.begin(); runner != Walker->ListOfBonds.end(); runner++)
     1764          *output << LocalNotoGlobalNoMap[MolCounter][ (*runner)->GetOtherAtom(Walker)->nr ]+1 << "\t";
     1765        for(int i=Walker->ListOfBonds.size(); i < MaxNeighbours; i++)
     1766          *output << "-\t";
     1767        *output << endl;
     1768        AtomNo++;
     1769      }
     1770      MolCounter++;
     1771    }
     1772  }
     1773
     1774  // store & free
     1775  output->flush();
     1776  output->close();
     1777  delete(output);
     1778  delete(fname);
     1779  for(size_t i=0;i<MolList->ListOfMolecules.size(); i++)
     1780    Free(&LocalNotoGlobalNoMap[i]);
     1781  Free(&LocalNotoGlobalNoMap);
    15011782
    15021783  return true;
     
    18502131              }
    18512132              line++;
    1852             } while (dummy1 != NULL && (dummy1[0] == '#') || (dummy1[0] == '\n'));
     2133            } while ((dummy1 != NULL) && ((dummy1[0] == '#') || (dummy1[0] == '\n')));
    18532134            dummy = dummy1;
    18542135          } else { // simple int, strings or doubles start in the same line
  • src/config.hpp

    re5ad5c ree7e25  
    1010
    1111using namespace std;
    12 
    13 class MoleculeListClass;
    1412
    1513/*********************************************** includes ***********************************/
     
    2725
    2826class molecule;
     27class MoleculeListClass;
    2928class periodentafel;
    3029
     
    142141  bool Save(const char * const filename, const periodentafel * const periode, molecule * const mol) const;
    143142  bool SaveMPQC(const char * const filename, const molecule * const mol) const;
     143  bool SavePDB(const char * const filename, const MoleculeListClass * const MolList) const;
     144  bool SavePDB(const char * const filename, const molecule * const mol) const;
     145  bool SaveTREMOLO(const char * const filename, const molecule * const mol) const;
     146  bool SaveTREMOLO(const char * const filename, const MoleculeListClass * const MolList) const;
     147
    144148  void Edit();
    145149  bool GetIsAngstroem() const;
  • src/datacreator.cpp

    re5ad5c ree7e25  
    2525  output.open(name.str().c_str(), ios::out);
    2626  if (output == NULL) {
    27     Log() << Verbose(0) << "Unable to open " << name.str() << " for writing, is directory correct?" << endl;
     27    DoLog(0) && (Log() << Verbose(0) << "Unable to open " << name.str() << " for writing, is directory correct?" << endl);
    2828    return false;
    2929  }
     
    4343  output.open(name.str().c_str(), ios::app);
    4444  if (output == NULL) {
    45     Log() << Verbose(0) << "Unable to open " << name.str() << " for writing, is directory correct?" << endl;
     45    DoLog(0) && (Log() << Verbose(0) << "Unable to open " << name.str() << " for writing, is directory correct?" << endl);
    4646    return false;
    4747  }
     
    6363  filename << prefix << ".dat";
    6464  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    65   Log() << Verbose(0) << msg << endl;
     65  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    6666  output << "# " << msg << ", created on " << datum;
    6767  output << "#Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
     
    9696  filename << prefix << ".dat";
    9797  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    98   Log() << Verbose(0) << msg << endl;
     98  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    9999  output << "# " << msg << ", created on " << datum;
    100100  output << "#Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
     
    133133  filename << prefix << ".dat";
    134134  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    135   Log() << Verbose(0) << msg << endl;
     135  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    136136  output << "# " << msg << ", created on " << datum;
    137137  output << "# Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
     
    165165  filename << prefix << ".dat";
    166166  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    167   Log() << Verbose(0) << msg << endl;
     167  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    168168  output << "# " << msg << ", created on " << datum;
    169169  output << "# Order\tFrag.No.\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
     
    198198  filename << prefix << ".dat";
    199199  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    200   Log() << Verbose(0) << msg << endl;
     200  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    201201  output << "# " << msg << ", created on " << datum;
    202202  output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
     
    244244  filename << prefix << ".dat";
    245245  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    246   Log() << Verbose(0) << msg << endl;
     246  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    247247  output << "# " << msg << ", created on " << datum;
    248248  output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
     
    281281  filename << prefix << ".dat";
    282282  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    283   Log() << Verbose(0) << msg << endl;
     283  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    284284  output << "# " << msg << ", created on " << datum;
    285285  output << "# AtomNo\t" << Fragments.Header[Fragments.MatrixCounter] << endl;
     
    321321  filename << prefix << ".dat";
    322322  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    323   Log() << Verbose(0) << msg << endl;
     323  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    324324  output << "# " << msg << ", created on " << datum;
    325325  output << "# AtomNo\t";
     
    363363  filename << prefix << ".dat";
    364364  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    365   Log() << Verbose(0) << msg << endl;
     365  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    366366  output << "# " << msg << ", created on " << datum;
    367367  output << "# AtomNo\t" << Fragments.Header[ Fragments.MatrixCounter ] << endl;
     
    393393  filename << prefix << ".dat";
    394394  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    395   Log() << Verbose(0) << msg << endl;
     395  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    396396  output << "# " << msg << ", created on " << datum << endl;
    397397  output << "#Order\tFrag.No.\t" << Fragment.Header[ Fragment.MatrixCounter ] << endl;
     
    458458  filename << prefix << ".dat";
    459459  if (!OpenOutputFile(output, dir, filename.str().c_str())) return false;
    460   Log() << Verbose(0) << msg << endl;
     460  DoLog(0) && (Log() << Verbose(0) << msg << endl);
    461461  output << "# " << msg << ", created on " << datum;
    462462  output << "#Order\tFrag.No.\t" << Fragment.Header[ Fragment.MatrixCounter ] << endl;
  • src/defs.hpp

    re5ad5c ree7e25  
    1212#define MAX_ELEMENTS 128  //!< maximum number of elements for certain lookup tables
    1313#define AtomicLengthToAngstroem  0.52917721 //!< conversion factor from atomic length/bohrradius to angstroem
    14 #define BONDTHRESHOLD 0.5   //!< CSD threshold in bond check which is the width of the interval whose center is the sum of the covalent radii
    1514#define AtomicEnergyToKelvin 315774.67  //!< conversion factor from atomic energy to kelvin via boltzmann factor
    1615#define KelvinToAtomicTemperature 3.1668152e-06    //!< conversion factor for Kelvin to atomic temperature (Hartree over k_B)
  • src/ellipsoid.cpp

    re5ad5c ree7e25  
    146146{
    147147  int status = GSL_SUCCESS;
    148   Log() << Verbose(2) << "Begin of FitPointSetToEllipsoid " << endl;
     148  DoLog(2) && (Log() << Verbose(2) << "Begin of FitPointSetToEllipsoid " << endl);
    149149  if (N >= 3) { // check that enough points are given (9 d.o.f.)
    150150    struct EllipsoidMinimisation par;
     
    199199          EllipsoidAngle[i] = gsl_vector_get (s->x, i+6);
    200200        }
    201         Log() << Verbose(4) << setprecision(3) << "Converged fit at: " << *EllipsoidCenter << ", lengths " << EllipsoidLength[0] << ", " << EllipsoidLength[1] << ", " << EllipsoidLength[2] << ", angles " << EllipsoidAngle[0] << ", " << EllipsoidAngle[1] << ", " << EllipsoidAngle[2] << " with summed distance " << s->fval << "." << endl;
     201        DoLog(4) && (Log() << Verbose(4) << setprecision(3) << "Converged fit at: " << *EllipsoidCenter << ", lengths " << EllipsoidLength[0] << ", " << EllipsoidLength[1] << ", " << EllipsoidLength[2] << ", angles " << EllipsoidAngle[0] << ", " << EllipsoidAngle[1] << ", " << EllipsoidAngle[2] << " with summed distance " << s->fval << "." << endl);
    202202      }
    203203
     
    209209
    210210  } else {
    211     Log() << Verbose(3) << "Not enough points provided for fit to ellipsoid." << endl;
     211    DoLog(3) && (Log() << Verbose(3) << "Not enough points provided for fit to ellipsoid." << endl);
    212212    return false;
    213213  }
    214   Log() << Verbose(2) << "End of FitPointSetToEllipsoid" << endl;
     214  DoLog(2) && (Log() << Verbose(2) << "End of FitPointSetToEllipsoid" << endl);
    215215  if (status == GSL_SUCCESS)
    216216    return true;
     
    235235  int index;
    236236  TesselPoint *Candidate = NULL;
    237   Log() << Verbose(2) << "Begin of PickRandomPointSet" << endl;
     237  DoLog(2) && (Log() << Verbose(2) << "Begin of PickRandomPointSet" << endl);
    238238
    239239  // allocate array
     
    241241    x = new Vector[PointsToPick];
    242242  } else {
    243     eLog() << Verbose(2) << "WARNING: Given pointer to vector array seems already allocated." << endl;
     243    DoeLog(2) && (eLog()<< Verbose(2) << "Given pointer to vector array seems already allocated." << endl);
    244244  }
    245245
     
    247247    for(int i=0;i<NDIM;i++) // pick three random indices
    248248      LC->n[i] = (rand() % LC->N[i]);
    249     Log() << Verbose(2) << "INFO: Center cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " ... ";
     249    DoLog(2) && (Log() << Verbose(2) << "INFO: Center cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " ... ");
    250250    // get random cell
    251     const LinkedNodes *List = LC->GetCurrentCell();
     251    const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    252252    if (List == NULL) {  // set index to it
    253253      continue;
    254254    }
    255     Log() << Verbose(2) << "with No. " << LC->index << "." << endl;
    256 
    257     Log() << Verbose(2) << "LC Intervals:";
     255    DoLog(2) && (Log() << Verbose(2) << "with No. " << LC->index << "." << endl);
     256
     257    DoLog(2) && (Log() << Verbose(2) << "LC Intervals:");
    258258    for (int i=0;i<NDIM;i++) {
    259259      Nlower[i] = ((LC->n[i]-1) >= 0) ? LC->n[i]-1 : 0;
    260260      Nupper[i] = ((LC->n[i]+1) < LC->N[i]) ? LC->n[i]+1 : LC->N[i]-1;
    261       Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
    262     }
    263     Log() << Verbose(0) << endl;
     261      DoLog(0) && (Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ");
     262    }
     263    DoLog(0) && (Log() << Verbose(0) << endl);
    264264
    265265    // count whether there are sufficient atoms in this cell+neighbors
     
    268268      for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    269269        for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    270           const LinkedNodes *List = LC->GetCurrentCell();
     270          const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    271271          PointsLeft += List->size();
    272272        }
    273     Log() << Verbose(2) << "There are " << PointsLeft << " atoms in this neighbourhood." << endl;
     273    DoLog(2) && (Log() << Verbose(2) << "There are " << PointsLeft << " atoms in this neighbourhood." << endl);
    274274    if (PointsLeft < PointsToPick) {  // ensure that we can pick enough points in its neighbourhood at all.
    275275      continue;
     
    293293      for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    294294        for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    295           const LinkedNodes *List = LC->GetCurrentCell();
     295          const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    296296//          Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
    297297          if (List != NULL) {
     
    300300//            else
    301301//              Log() << Verbose(2) << "Cell is empty ... " << endl;
    302             for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     302            for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    303303              if ((current != PickedAtomNrs.end()) && (*current == index)) {
    304304                Candidate = (*Runner);
    305                 Log() << Verbose(2) << "Current picked node is " << **Runner << " with index " << index << "." << endl;
     305                DoLog(2) && (Log() << Verbose(2) << "Current picked node is " << **Runner << " with index " << index << "." << endl);
    306306                x[PointsPicked++].CopyVector(Candidate->node);    // we have one more atom picked
    307307                current++;    // next pre-picked atom
     
    313313          }
    314314        }
    315     Log() << Verbose(2) << "The following points were picked: " << endl;
     315    DoLog(2) && (Log() << Verbose(2) << "The following points were picked: " << endl);
    316316    for (size_t i=0;i<PointsPicked;i++)
    317       Log() << Verbose(2) << x[i] << endl;
     317      DoLog(2) && (Log() << Verbose(2) << x[i] << endl);
    318318    if (PointsPicked == PointsToPick)  // break out of loop if we have all
    319319      break;
    320320  } while(1);
    321321
    322   Log() << Verbose(2) << "End of PickRandomPointSet" << endl;
     322  DoLog(2) && (Log() << Verbose(2) << "End of PickRandomPointSet" << endl);
    323323};
    324324
     
    335335  double value, threshold;
    336336  PointMap *List = &T->PointsOnBoundary;
    337   Log() << Verbose(2) << "Begin of PickRandomPointSet" << endl;
     337  DoLog(2) && (Log() << Verbose(2) << "Begin of PickRandomPointSet" << endl);
    338338
    339339  // allocate array
     
    341341    x = new Vector[PointsToPick];
    342342  } else {
    343     eLog() << Verbose(2) << "WARNING: Given pointer to vector array seems already allocated." << endl;
     343    DoeLog(2) && (eLog()<< Verbose(2) << "Given pointer to vector array seems already allocated." << endl);
    344344  }
    345345
     
    358358      PointsLeft--;
    359359    }
    360   Log() << Verbose(2) << "The following points were picked: " << endl;
     360  DoLog(2) && (Log() << Verbose(2) << "The following points were picked: " << endl);
    361361  for (size_t i=0;i<PointsPicked;i++)
    362     Log() << Verbose(3) << x[i] << endl;
    363 
    364   Log() << Verbose(2) << "End of PickRandomPointSet" << endl;
     362    DoLog(3) && (Log() << Verbose(3) << x[i] << endl);
     363
     364  DoLog(2) && (Log() << Verbose(2) << "End of PickRandomPointSet" << endl);
    365365};
    366366
     
    382382  double EllipsoidAngle[3];
    383383  double distance, MaxDistance, MinDistance;
    384   Log() << Verbose(0) << "Begin of FindDistributionOfEllipsoids" << endl;
     384  DoLog(0) && (Log() << Verbose(0) << "Begin of FindDistributionOfEllipsoids" << endl);
    385385
    386386  // construct center of gravity of boundary point set for initial ellipsoid center
     
    389389    Center.AddVector(Runner->second->node->node);
    390390  Center.Scale(1./T->PointsOnBoundaryCount);
    391   Log() << Verbose(1) << "Center is at " << Center << "." << endl;
     391  DoLog(1) && (Log() << Verbose(1) << "Center is at " << Center << "." << endl);
    392392
    393393  // Output header
     
    397397  // loop over desired number of parameter sets
    398398  for (;number >0;number--) {
    399     Log() << Verbose(1) << "Determining data set " << number << " ... " << endl;
     399    DoLog(1) && (Log() << Verbose(1) << "Determining data set " << number << " ... " << endl);
    400400    // pick the point set
    401401    x = NULL;
     
    423423    // fit the parameters
    424424    if (FitPointSetToEllipsoid(x, N, &EllipsoidCenter, &EllipsoidLength[0], &EllipsoidAngle[0])) {
    425       Log() << Verbose(1) << "Picking succeeded!" << endl;
     425      DoLog(1) && (Log() << Verbose(1) << "Picking succeeded!" << endl);
    426426      // output obtained parameter set
    427427      output << number << "\t";
     
    434434      output << endl;
    435435    } else { // increase N to pick one more
    436       Log() << Verbose(1) << "Picking failed!" << endl;
     436      DoLog(1) && (Log() << Verbose(1) << "Picking failed!" << endl);
    437437      number++;
    438438    }
     
    442442  output.close();
    443443
    444   Log() << Verbose(0) << "End of FindDistributionOfEllipsoids" << endl;
    445 };
     444  DoLog(0) && (Log() << Verbose(0) << "End of FindDistributionOfEllipsoids" << endl);
     445};
  • src/errorlogger.cpp

    re5ad5c ree7e25  
    8181  int verbosityLevel = l.verbosity;
    8282  l.nix->clear();
    83   if (v.DoOutput(verbosityLevel))
     83  if (v.DoErrorOutput(verbosityLevel)) {
     84    switch(v.Verbosity) {
     85      case 0:
     86        cerr << "CRITICAL: ";
     87        break;
     88      case 1:
     89        cerr << "ERROR: ";
     90        break;
     91      case 2:
     92        cerr << "WARNING: ";
     93        break;
     94      default:
     95        break;
     96    }
     97    v.print(cerr);
    8498    return cerr;
    85   else
     99  } else
    86100    return *l.nix;
    87101};
     
    90104  int verbosityLevel = l->verbosity;
    91105  l->nix->clear();
    92   if (v.DoOutput(verbosityLevel))
     106  if (v.DoErrorOutput(verbosityLevel)) {
     107    switch(v.Verbosity) {
     108      case 0:
     109        cerr << "CRITICAL: ";
     110        break;
     111      case 1:
     112        cerr << "ERROR: ";
     113        break;
     114      case 2:
     115      default:
     116        cerr << "WARNING: ";
     117        break;
     118    }
     119    v.print(cerr);
    93120    return cerr;
    94   else
     121  } else
    95122    return *l->nix;
    96123};
  • src/graph.cpp

    re5ad5c ree7e25  
    8585  testGraphInsert = Fragment->Leaflet->insert(GraphPair (*Fragment->FragmentSet,pair<int,double>(Fragment->FragmentCounter,Fragment->TEFactor)));  // store fragment number and current factor
    8686  if (testGraphInsert.second) {
    87     Log() << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " successfully inserted." << endl;
     87    DoLog(2) && (Log() << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " successfully inserted." << endl);
    8888    Fragment->FragmentCounter++;
    8989  } else {
    90     Log() << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first << endl;
     90    DoLog(2) && (Log() << Verbose(2) << "KeySet " << Fragment->FragmentCounter << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first << endl);
    9191    ((*(testGraphInsert.first)).second).second += Fragment->TEFactor;  // increase the "created" counter
    92     Log() << Verbose(2) << "New factor is " << ((*(testGraphInsert.first)).second).second << "." << endl;
     92    DoLog(2) && (Log() << Verbose(2) << "New factor is " << ((*(testGraphInsert.first)).second).second << "." << endl);
    9393  }
    9494};
     
    115115    testGraphInsert = graph1.insert(GraphPair ((*runner).first,pair<int,double>((*counter)++,((*runner).second).second)));  // store fragment number and current factor
    116116    if (testGraphInsert.second) {
    117       Log() << Verbose(2) << "KeySet " << (*counter)-1 << " successfully inserted." << endl;
     117      DoLog(2) && (Log() << Verbose(2) << "KeySet " << (*counter)-1 << " successfully inserted." << endl);
    118118    } else {
    119       Log() << Verbose(2) << "KeySet " << (*counter)-1 << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first << endl;
     119      DoLog(2) && (Log() << Verbose(2) << "KeySet " << (*counter)-1 << " failed to insert, present fragment is " << ((*(testGraphInsert.first)).second).first << endl);
    120120      ((*(testGraphInsert.first)).second).second += (*runner).second.second;
    121       Log() << Verbose(2) << "New factor is " << (*(testGraphInsert.first)).second.second << "." << endl;
     121      DoLog(2) && (Log() << Verbose(2) << "New factor is " << (*(testGraphInsert.first)).second.second << "." << endl);
    122122    }
    123123  }
  • src/helpers.cpp

    re5ad5c ree7e25  
    1919  double test = 0.1439851348959832147598734598273456723948652983045928346598365;
    2020  do {
    21     Log() << Verbose(0) << text;
     21    DoLog(0) && (Log() << Verbose(0) << text);
    2222    cin >> test;
    2323  } while (test == 0.1439851348959832147598734598273456723948652983045928346598365);
  • src/helpers.hpp

    re5ad5c ree7e25  
    7676};
    7777
     78/** returns greater of the two values.
     79 * \param x first value
     80 * \param y second value
     81 * \return greater of the two (by operator>())
     82 */
     83template <typename T> T Max(T x, T y)
     84{
     85  if (x > y)
     86    return x;
     87  else return y;
     88};
     89
     90/** returns smaller of the two values.
     91 * \param x first value
     92 * \param y second value
     93 * \return smaller of the two (by operator<())
     94 */
     95template <typename T> T Min(T x, T y)
     96{
     97  if (x < y)
     98    return x;
     99  else return y;
     100};
     101
    78102/** Creates a lookup table for true father's Atom::Nr -> atom ptr.
    79103 * \param *start begin of chain list
     
    90114
    91115  if (LookupTable != NULL) {
    92     Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl;
     116    DoLog(0) && (Log() << Verbose(0) << "Pointer for Lookup table is not NULL! Aborting ..." <<endl);
    93117    return false;
    94118  }
     
    103127  }
    104128  if (count <= 0) {
    105     Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl;
     129    DoLog(0) && (Log() << Verbose(0) << "Count of lookup list is 0 or less." << endl);
    106130    return false;
    107131  }
     
    110134  LookupTable = Calloc<T*>(count, "CreateFatherLookupTable - **LookupTable");
    111135  if (LookupTable == NULL) {
    112     eLog() << Verbose(0) << "LookupTable memory allocation failed!" << endl;
     136    DoeLog(0) && (eLog()<< Verbose(0) << "LookupTable memory allocation failed!" << endl);
     137    performCriticalExit();
    113138    status = false;
    114139  } else {
     
    121146        LookupTable[AtomNo] = Walker;
    122147      } else {
    123         Log() << Verbose(0) << "Walker " << *Walker << " exceeded range of nuclear ids [0, " << count << ")." << endl;
     148        DoLog(0) && (Log() << Verbose(0) << "Walker " << *Walker << " exceeded range of nuclear ids [0, " << count << ")." << endl);
    124149        status = false;
    125150        break;
  • src/joiner.cpp

    re5ad5c ree7e25  
    77
    88//============================ INCLUDES ===========================
     9
     10#include <cstring>
    911
    1012#include "datacreator.hpp"
     
    4547  bool NoHessian = false;
    4648
    47   Log() << Verbose(0) << "Joiner" << endl;
    48   Log() << Verbose(0) << "======" << endl;
     49  DoLog(0) && (Log() << Verbose(0) << "Joiner" << endl);
     50  DoLog(0) && (Log() << Verbose(0) << "======" << endl);
    4951
    5052  // Get the command line options
    5153  if (argc < 3) {
    52     Log() << Verbose(0) << "Usage: " << argv[0] << " <inputdir> <prefix> [elementsdb]" << endl;
    53     Log() << Verbose(0) << "<inputdir>\ttherein the output of a molecuilder fragmentation is expected, each fragment with a subdir containing an energy.all and a forces.all file." << endl;
    54     Log() << Verbose(0) << "<prefix>\tprefix of energy and forces file." << endl;
    55     Log() << Verbose(0) << "[elementsdb]\tpath to elements database, needed for shieldings." << endl;
     54    DoLog(0) && (Log() << Verbose(0) << "Usage: " << argv[0] << " <inputdir> <prefix> [elementsdb]" << endl);
     55    DoLog(0) && (Log() << Verbose(0) << "<inputdir>\ttherein the output of a molecuilder fragmentation is expected, each fragment with a subdir containing an energy.all and a forces.all file." << endl);
     56    DoLog(0) && (Log() << Verbose(0) << "<prefix>\tprefix of energy and forces file." << endl);
     57    DoLog(0) && (Log() << Verbose(0) << "[elementsdb]\tpath to elements database, needed for shieldings." << endl);
    5658    return 1;
    5759  } else {
     
    7577  if (!Hcorrection.ParseFragmentMatrix(argv[1], "", HCORRECTIONSUFFIX, 0,0)) {
    7678    NoHCorrection = true;
    77     Log() << Verbose(0) << "No HCorrection matrices found, skipping these." << endl;
     79    DoLog(0) && (Log() << Verbose(0) << "No HCorrection matrices found, skipping these." << endl);
    7880  }
    7981  if (!Force.ParseFragmentMatrix(argv[1], dir, ForcesSuffix, 0,0)) return 1;
    8082  if (!Hessian.ParseFragmentMatrix(argv[1], dir, HessianSuffix, 0,0)) {
    8183    NoHessian = true;
    82     Log() << Verbose(0) << "No hessian matrices found, skipping these." << endl;
     84    DoLog(0) && (Log() << Verbose(0) << "No hessian matrices found, skipping these." << endl);
    8385  }
    8486  if (periode != NULL) { // also look for PAS values
     
    144146  for (int BondOrder=0;BondOrder<KeySet.Order;BondOrder++) {
    145147    // --------- sum up energy --------------------
    146     Log() << Verbose(0) << "Summing energy of order " << BondOrder+1 << " ..." << endl;
     148    DoLog(0) && (Log() << Verbose(0) << "Summing energy of order " << BondOrder+1 << " ..." << endl);
    147149    if (!EnergyFragments.SumSubManyBodyTerms(Energy, KeySet, BondOrder)) return 1;
    148150    if (!NoHCorrection) {
     
    153155      if (!Energy.SumSubEnergy(EnergyFragments, NULL, KeySet, BondOrder, 1.)) return 1;
    154156    // --------- sum up Forces --------------------
    155     Log() << Verbose(0) << "Summing forces of order " << BondOrder+1 << " ..." << endl;
     157    DoLog(0) && (Log() << Verbose(0) << "Summing forces of order " << BondOrder+1 << " ..." << endl);
    156158    if (!ForceFragments.SumSubManyBodyTerms(Force, KeySet, BondOrder)) return 1;
    157159    if (!Force.SumSubForces(ForceFragments, KeySet, BondOrder, 1.)) return 1;
    158160    // --------- sum up Hessian --------------------
    159161    if (!NoHessian) {
    160       Log() << Verbose(0) << "Summing Hessian of order " << BondOrder+1 << " ..." << endl;
     162      DoLog(0) && (Log() << Verbose(0) << "Summing Hessian of order " << BondOrder+1 << " ..." << endl);
    161163      if (!HessianFragments.SumSubManyBodyTerms(Hessian, KeySet, BondOrder)) return 1;
    162164      if (!Hessian.SumSubHessians(HessianFragments, KeySet, BondOrder, 1.)) return 1;
    163165    }
    164166    if (periode != NULL) { // also look for PAS values
    165       Log() << Verbose(0) << "Summing shieldings and susceptibilities of order " << BondOrder+1 << " ..." << endl;
     167      DoLog(0) && (Log() << Verbose(0) << "Summing shieldings and susceptibilities of order " << BondOrder+1 << " ..." << endl);
    166168      if (!ShieldingFragments.SumSubManyBodyTerms(Shielding, KeySet, BondOrder)) return 1;
    167169      if (!Shielding.SumSubForces(ShieldingFragments, KeySet, BondOrder, 1.)) return 1;
     
    177179    prefix.str(" ");
    178180    prefix << dir << OrderSuffix << (BondOrder+1);
    179     Log() << Verbose(0) << "Writing files " << argv[1] << prefix.str() << ". ..." << endl;
     181    DoLog(0) && (Log() << Verbose(0) << "Writing files " << argv[1] << prefix.str() << ". ..." << endl);
    180182    // energy
    181183    if (!Energy.WriteLastMatrix(argv[1], (prefix.str()).c_str(), EnergySuffix)) return 1;
     
    242244  delete(periode);
    243245  Free(&dir);
    244   Log() << Verbose(0) << "done." << endl;
     246  DoLog(0) && (Log() << Verbose(0) << "done." << endl);
    245247  return 0;
    246248};
  • src/linkedcell.cpp

    re5ad5c ree7e25  
    4545  max.Zero();
    4646  min.Zero();
    47   Log() << Verbose(1) << "Begin of LinkedCell" << endl;
    48   if (set->IsEmpty()) {
    49     eLog() << Verbose(0) << "ERROR: set contains no linked cell nodes!" << endl;
     47  DoLog(1) && (Log() << Verbose(1) << "Begin of LinkedCell" << endl);
     48  if ((set == NULL) || (set->IsEmpty())) {
     49    DoeLog(1) && (eLog()<< Verbose(1) << "set is NULL or contains no linked cell nodes!" << endl);
    5050    return;
    5151  }
     
    6868    set->GoToNext();
    6969  }
    70   Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl;
     70  DoLog(2) && (Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl);
    7171
    7272  // 2. find then number of cells per axis
     
    7474    N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1;
    7575  }
    76   Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl;
     76  DoLog(2) && (Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl);
    7777
    7878  // 3. allocate the lists
    79   Log() << Verbose(2) << "Allocating cells ... ";
     79  DoLog(2) && (Log() << Verbose(2) << "Allocating cells ... ");
    8080  if (LC != NULL) {
    81     Log() << Verbose(1) << "ERROR: Linked Cell list is already allocated, I do nothing." << endl;
     81    DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell list is already allocated, I do nothing." << endl);
    8282    return;
    8383  }
     
    8686    LC [index].clear();
    8787  }
    88   Log() << Verbose(0) << "done."  << endl;
     88  DoLog(0) && (Log() << Verbose(0) << "done."  << endl);
    8989
    9090  // 4. put each atom into its respective cell
    91   Log() << Verbose(2) << "Filling cells ... ";
     91  DoLog(2) && (Log() << Verbose(2) << "Filling cells ... ");
    9292  set->GoToFirst();
    9393  while (!set->IsEnd()) {
     
    101101    set->GoToNext();
    102102  }
    103   Log() << Verbose(0) << "done."  << endl;
    104   Log() << Verbose(1) << "End of LinkedCell" << endl;
     103  DoLog(0) && (Log() << Verbose(0) << "done."  << endl);
     104  DoLog(1) && (Log() << Verbose(1) << "End of LinkedCell" << endl);
    105105};
    106106
     
    120120  max.Zero();
    121121  min.Zero();
    122   Log() << Verbose(1) << "Begin of LinkedCell" << endl;
     122  DoLog(1) && (Log() << Verbose(1) << "Begin of LinkedCell" << endl);
    123123  if (set->empty()) {
    124     eLog() << Verbose(0) << "ERROR: set contains no linked cell nodes!" << endl;
     124    DoeLog(1) && (eLog()<< Verbose(1) << "set contains no linked cell nodes!" << endl);
    125125    return;
    126126  }
     
    140140    }
    141141  }
    142   Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl;
     142  DoLog(2) && (Log() << Verbose(2) << "Bounding box is " << min << " and " << max << "." << endl);
    143143
    144144  // 2. find then number of cells per axis
     
    146146    N[i] = (int)floor((max.x[i] - min.x[i])/RADIUS)+1;
    147147  }
    148   Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl;
     148  DoLog(2) && (Log() << Verbose(2) << "Number of cells per axis are " << N[0] << ", " << N[1] << " and " << N[2] << "." << endl);
    149149
    150150  // 3. allocate the lists
    151   Log() << Verbose(2) << "Allocating cells ... ";
     151  DoLog(2) && (Log() << Verbose(2) << "Allocating cells ... ");
    152152  if (LC != NULL) {
    153     Log() << Verbose(1) << "ERROR: Linked Cell list is already allocated, I do nothing." << endl;
     153    DoeLog(1) && (eLog()<< Verbose(1) << "Linked Cell list is already allocated, I do nothing." << endl);
    154154    return;
    155155  }
     
    158158    LC [index].clear();
    159159  }
    160   Log() << Verbose(0) << "done."  << endl;
     160  DoLog(0) && (Log() << Verbose(0) << "done."  << endl);
    161161
    162162  // 4. put each atom into its respective cell
    163   Log() << Verbose(2) << "Filling cells ... ";
     163  DoLog(2) && (Log() << Verbose(2) << "Filling cells ... ");
    164164  for (LinkedNodes::iterator Runner = set->begin(); Runner != set->end(); Runner++) {
    165165    Walker = *Runner;
     
    171171    //Log() << Verbose(2) << *Walker << " goes into cell " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
    172172  }
    173   Log() << Verbose(0) << "done."  << endl;
    174   Log() << Verbose(1) << "End of LinkedCell" << endl;
     173  DoLog(0) && (Log() << Verbose(0) << "done."  << endl);
     174  DoLog(1) && (Log() << Verbose(1) << "End of LinkedCell" << endl);
    175175};
    176176
     
    199199    status = status && ((n[i] >=0) && (n[i] < N[i]));
    200200  if (!status)
    201   eLog() << Verbose(0) << "ERROR: indices are out of bounds!" << endl;
     201  DoeLog(1) && (eLog()<< Verbose(1) << "indices are out of bounds!" << endl);
    202202  return status;
    203203};
     
    220220 * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[] are out of bounds.
    221221 */
    222 const LinkedNodes* LinkedCell::GetCurrentCell() const
     222const LinkedCell::LinkedNodes* LinkedCell::GetCurrentCell() const
    223223{
    224224  if (CheckBounds()) {
     
    234234 * \return LinkedAtoms pointer to current cell, NULL if LinkedCell::n[]+relative[] are out of bounds.
    235235 */
    236 const LinkedNodes* LinkedCell::GetRelativeToCurrentCell(const int relative[NDIM]) const
     236const LinkedCell::LinkedNodes* LinkedCell::GetRelativeToCurrentCell(const int relative[NDIM]) const
    237237{
    238238  if (CheckBounds(relative)) {
     
    242242    return NULL;
    243243  }
     244};
     245
     246/** Set the index to the cell containing a given Vector *x.
     247 * \param *x Vector with coordinates
     248 * \return Vector is inside bounding box - true, else - false
     249 */
     250bool LinkedCell::SetIndexToVector(const Vector * const x) const
     251{
     252  for (int i=0;i<NDIM;i++)
     253    n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS);
     254
     255  return CheckBounds();
    244256};
    245257
     
    260272    return status;
    261273  } else {
    262     eLog() << Verbose(1) << "ERROR: Node at " << *Walker << " is out of bounds." << endl;
     274    DoeLog(1) && (eLog()<< Verbose(1) << "Node at " << *Walker << " is out of bounds." << endl);
    263275    return false;
    264276  }
     
    268280 * \param *lower lower bounds
    269281 * \param *upper upper bounds
    270  */
    271 void LinkedCell::GetNeighbourBounds(int lower[NDIM], int upper[NDIM]) const
    272 {
    273   for (int i=0;i<NDIM;i++) {
    274     lower[i] = ((n[i]-1) >= 0) ? n[i]-1 : 0;
    275     upper[i] = ((n[i]+1) < N[i]) ? n[i]+1 : N[i]-1;
    276     //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
    277     // check for this axis whether the point is outside of our grid
     282 * \param step how deep to check the neighbouring cells (i.e. number of layers to check)
     283 */
     284void LinkedCell::GetNeighbourBounds(int lower[NDIM], int upper[NDIM], int step) const
     285{
     286  for (int i=0;i<NDIM;i++) {
     287    lower[i] = n[i];
     288    for (int s=step; s>0;--s)
     289      if ((n[i]-s) >= 0) {
     290        lower[i] = n[i]-s;
     291        break;
     292      }
     293    upper[i] = n[i];
     294    for (int s=step; s>0;--s)
     295      if ((n[i]+s) < N[i]) {
     296        upper[i] = n[i]+s;
     297        break;
     298      }
     299    //Log() << Verbose(0) << "axis " << i << " has bounds [" << lower[i] << "," << upper[i] << "]" << endl;
     300  }
     301};
     302
     303/** Returns a list with all neighbours from the current LinkedCell::index.
     304 * \param distance (if no distance, then adjacent cells are taken)
     305 * \return list of tesselpoints
     306 */
     307LinkedCell::LinkedNodes* LinkedCell::GetallNeighbours(const double distance) const
     308{
     309  int Nlower[NDIM], Nupper[NDIM];
     310  TesselPoint *Walker = NULL;
     311  LinkedNodes *TesselList = new LinkedNodes;
     312
     313  // then go through the current and all neighbouring cells and check the contained points for possible candidates
     314  const int step = (distance == 0) ? 1 : (int)floor(distance/RADIUS + 1.);
     315  GetNeighbourBounds(Nlower, Nupper, step);
     316
     317  //Log() << Verbose(0) << endl;
     318  for (n[0] = Nlower[0]; n[0] <= Nupper[0]; n[0]++)
     319    for (n[1] = Nlower[1]; n[1] <= Nupper[1]; n[1]++)
     320      for (n[2] = Nlower[2]; n[2] <= Nupper[2]; n[2]++) {
     321        const LinkedNodes *List = GetCurrentCell();
     322        //Log() << Verbose(1) << "Current cell is " << n[0] << ", " << n[1] << ", " << n[2] << " with No. " << index << "." << endl;
     323        if (List != NULL) {
     324          for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     325            Walker = *Runner;
     326            TesselList->push_back(Walker);
     327          }
     328        }
     329      }
     330  return TesselList;
     331};
     332
     333/** Set the index to the cell containing a given Vector *x, which is not inside the LinkedCell's domain
     334 * Note that as we have to check distance from every corner of the closest cell, this function is faw more
     335 * expensive and if Vector is known to be inside LinkedCell's domain, then SetIndexToVector() should be used.
     336 * \param *x Vector with coordinates
     337 * \return minimum squared distance of cell to given vector (if inside of domain, distance is 0)
     338 */
     339double LinkedCell::SetClosestIndexToOutsideVector(const Vector * const x) const
     340{
     341  for (int i=0;i<NDIM;i++) {
     342    n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS);
    278343    if (n[i] < 0)
    279       upper[i] = lower[i];
    280     if (n[i] > N[i])
    281       lower[i] = upper[i];
    282 
    283     //Log() << Verbose(0) << "axis " << i << " has bounds [" << lower[i] << "," << upper[i] << "]" << endl;
    284   }
    285 };
    286 
    287 /** Calculates the index for a given Vector *x.
    288  * \param *x Vector with coordinates
    289  * \return Vector is inside bounding box - true, else - false
    290  */
    291 bool LinkedCell::SetIndexToVector(const Vector * const x) const
    292 {
    293   bool status = true;
    294   for (int i=0;i<NDIM;i++) {
    295     n[i] = (int)floor((x->x[i] - min.x[i])/RADIUS);
    296     if (max.x[i] < x->x[i])
    297       status = false;
    298     if (min.x[i] > x->x[i])
    299       status = false;
    300   }
    301   return status;
    302 };
    303 
     344      n[i] = 0;
     345    if (n[i] >= N[i])
     346      n[i] = N[i]-1;
     347  }
     348
     349  // calculate distance of cell to vector
     350  double distanceSquared = 0.;
     351  bool outside = true;  // flag whether x is found in- or outside of LinkedCell's domain/closest cell
     352  Vector corner; // current corner of closest cell
     353  Vector tester; // Vector pointing from corner to center of closest cell
     354  Vector Distance;  // Vector from corner of closest cell to x
     355
     356  Vector center;  // center of the closest cell
     357  for (int i=0;i<NDIM;i++)
     358    center.x[i] = min.x[i]+((double)n[i]+.5)*RADIUS;
     359
     360  int c[NDIM];
     361  for (c[0]=0;c[0]<=1;c[0]++)
     362    for (c[1]=0; c[1]<=1;c[1]++)
     363      for (c[2]=0; c[2]<=1;c[2]++) {
     364        // set up corner
     365        for (int i=0;i<NDIM;i++)
     366          corner.x[i] = min.x[i]+RADIUS*((double)n[i]+c[i]);
     367        // set up distance vector
     368        Distance.CopyVector(x);
     369        Distance.SubtractVector(&corner);
     370        const double dist = Distance.NormSquared();
     371        // check whether distance is smaller
     372        if (dist< distanceSquared)
     373          distanceSquared = dist;
     374        // check whether distance vector goes inside or outside
     375        tester.CopyVector(&center);
     376        tester.SubtractVector(&corner);
     377        if (tester.ScalarProduct(&Distance) < 0)
     378          outside = false;
     379      }
     380  return (outside ? distanceSquared : 0.);
     381};
     382
     383/** Returns a list of all TesselPoint with distance less than \a radius to \a *Center.
     384 * \param radius radius of sphere
     385 * \param *center center of sphere
     386 * \return list of all points inside sphere
     387 */
     388LinkedCell::LinkedNodes* LinkedCell::GetPointsInsideSphere(const double radius, const Vector * const center) const
     389{
     390  const double radiusSquared = radius*radius;
     391  TesselPoint *Walker = NULL;
     392  LinkedNodes *TesselList = new LinkedNodes;
     393  LinkedNodes *NeighbourList = NULL;
     394
     395  // set index of LC to center of sphere
     396  const double dist = SetClosestIndexToOutsideVector(center);
     397  if (dist > 2.*radius) {
     398    DoeLog(1) && (eLog()<< Verbose(1) << "Vector " << *center << " is too far away from any atom in LinkedCell's bounding box." << endl);
     399    return TesselList;
     400  } else
     401    DoLog(1) && (Log() << Verbose(1) << "Distance of closest cell to center of sphere with radius " << radius << " is " << dist << "." << endl);
     402
     403  // gather all neighbours first, then look who fulfills distance criteria
     404  NeighbourList = GetallNeighbours(2.*radius-dist);
     405  //Log() << Verbose(1) << "I found " << NeighbourList->size() << " neighbours to check." << endl;
     406  if (NeighbourList != NULL) {
     407    for (LinkedNodes::const_iterator Runner = NeighbourList->begin(); Runner != NeighbourList->end(); Runner++) {
     408      Walker = *Runner;
     409      //Log() << Verbose(1) << "Current neighbour is at " << *Walker->node << "." << endl;
     410      if ((center->DistanceSquared(Walker->node) - radiusSquared) < MYEPSILON) {
     411        TesselList->push_back(Walker);
     412      }
     413    }
     414    delete(NeighbourList);
     415  } else
     416    DoeLog(2) && (eLog()<< Verbose(2) << "Around vector " << *center << " there are no atoms." << endl);
     417  return TesselList;
     418};
  • src/linkedcell.hpp

    re5ad5c ree7e25  
    3333/********************************************** definitions *********************************/
    3434
    35 #define LinkedNodes list<TesselPoint *>
    3635
    3736/********************************************** declarations *******************************/
     
    4039 */
    4140class LinkedCell {
    42   public:
     41private:
     42
     43public:
     44  typedef list<TesselPoint *> LinkedNodes;
     45
     46
    4347    Vector max;       // upper boundary
    4448    Vector min;       // lower boundary
     
    5357    LinkedCell(LinkedNodes *set, const double radius);
    5458    ~LinkedCell();
    55     const LinkedNodes* GetCurrentCell()const ;
    56     const LinkedNodes* GetRelativeToCurrentCell(const int relative[NDIM])const ;
     59    const LinkedCell::LinkedNodes* GetCurrentCell()const ;
     60    const LinkedCell::LinkedNodes* GetRelativeToCurrentCell(const int relative[NDIM])const ;
    5761    bool SetIndexToNode(const TesselPoint * const Walker)const ;
    5862    bool SetIndexToVector(const Vector * const x)const ;
     63    double SetClosestIndexToOutsideVector(const Vector * const x) const;
    5964    bool CheckBounds()const ;
    6065    bool CheckBounds(const int relative[NDIM])const ;
    61     void GetNeighbourBounds(int lower[NDIM], int upper[NDIM])const ;
     66    void GetNeighbourBounds(int lower[NDIM], int upper[NDIM], int step = 1)const ;
    6267
     68    LinkedCell::LinkedNodes* GetallNeighbours(const double distance = 0) const;
     69    LinkedCell::LinkedNodes* GetPointsInsideSphere(const double radius, const Vector * const center) const;
    6370    // not implemented yet
    6471    bool AddNode(Vector *Walker);
  • src/log.cpp

    re5ad5c ree7e25  
    1616void setVerbosity(int verbosityLevel) {
    1717  logger::getInstance()->setVerbosity(verbosityLevel);
    18   errorLogger::getInstance()->setVerbosity(verbosityLevel);
    1918}
    2019
     
    2827}
    2928
     29/** Checks verbosity for logger.
     30 * Is supposed to be used in construct as this:
     31 * DoLog(2) && (Log() << Verbose(2) << "message." << endl);
     32 * If DoLog does not return true, the right-hand side is not evaluated and we save some time.
     33 * \param verbose verbosity level of this message
     34 * \return true - print, false - don't
     35 */
     36bool DoLog(int verbose) {
     37  return (verbose <= logger::getInstance()->verbosity);
     38}
     39
     40/** Checks verbosity for errorlogger.
     41 * Is supposed to be used in construct as this:
     42 * DoLog(2) && (Log() << Verbose(2) << "message." << endl);
     43 * If DoLog does not return true, the right-hand side is not evaluated and we save some time.
     44 * \param verbose verbosity level of this message
     45 * \return true - print, false - don't
     46 */
     47bool DoeLog(int verbose) {
     48  return (verbose <= errorLogger::getInstance()->verbosity);
     49}
     50
    3051/**
    3152 * Prints an error log entry.
  • src/log.hpp

    re5ad5c ree7e25  
    1515class errorLogger * eLog();
    1616void setVerbosity(int verbosityLevel);
     17bool DoLog(int verbose);
     18bool DoeLog(int verbose);
    1719
    1820#endif /* LOG_HPP_ */
  • src/logger.cpp

    re5ad5c ree7e25  
    8181  int verbosityLevel = l.verbosity;
    8282  l.nix->clear();
    83   if (v.DoOutput(verbosityLevel))
     83  if (v.DoOutput(verbosityLevel)) {
     84    v.print(cout);
    8485    return cout;
    85   else
     86  } else
    8687    return *l.nix;
    8788};
     
    9091  int verbosityLevel = l->verbosity;
    9192  l->nix->clear();
    92   if (v.DoOutput(verbosityLevel))
     93  if (v.DoOutput(verbosityLevel)) {
     94    v.print(cout);
    9395    return cout;
    94   else
     96  } else
    9597    return *l->nix;
    9698};
  • src/memoryallocator.hpp

    re5ad5c ree7e25  
    1616#endif
    1717
     18#include <cstdlib>
    1819#include <iostream>
    1920#include <iomanip>
  • src/memoryusageobserver.cpp

    re5ad5c ree7e25  
    44 * This class represents a Singleton for observing memory usage.
    55 */
     6
     7#include <cstdlib>
    68
    79#include "log.hpp"
     
    8890
    8991  if (current == memoryUsers.end()) {
    90     Log() << Verbose(0) << "WARNING: There is non-tracked memory to be freed. Pointer "
     92    eLog() << Verbose(2) << "There is non-tracked memory to be freed. Pointer "
    9193      << pointer << " is not registered by MemoryUsageObserver: ";
    9294    if (msg != NULL)
    93       Log() << Verbose(0) << *msg;
    94     Log() << Verbose(0) << endl;
     95      DoLog(0) && (Log() << Verbose(0) << *msg);
     96    DoLog(0) && (Log() << Verbose(0) << endl);
    9597    return;
    9698  }
  • src/molecule.cpp

    re5ad5c ree7e25  
    44 *
    55 */
     6
     7#include <cstring>
    68
    79#include "atom.hpp"
     
    2123#include "tesselation.hpp"
    2224#include "vector.hpp"
     25#include "World.hpp"
    2326
    2427/************************************* Functions for class molecule *********************************/
     
    4346  for(int i=MAX_ELEMENTS;i--;)
    4447    ElementsInMolecule[i] = 0;
    45   cell_size[0] = cell_size[2] = cell_size[5]= 20.;
    46   cell_size[1] = cell_size[3] = cell_size[4]= 0.;
    47   strcpy(name,"none");
     48  strcpy(name,World::get()->DefaultName);
    4849};
    4950
     
    155156  Vector Orthovector1, Orthovector2;  // temporary vectors in coordination construction
    156157  Vector InBondvector;    // vector in direction of *Bond
    157   double *matrix;
     158  double *matrix = NULL;
    158159  bond *Binder = NULL;
     160  double * const cell_size = World::get()->cell_size;
    159161
    160162//  Log() << Verbose(3) << "Begin of AddHydrogenReplacementAtom." << endl;
     
    192194  BondRescale = TopOrigin->type->HBondDistance[TopBond->BondDegree-1];
    193195  if (BondRescale == -1) {
    194     eLog() << Verbose(3) << "ERROR: There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;
     196    DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond distance in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl);
    195197    return false;
    196198    BondRescale = bondlength;
     
    235237            SecondOtherAtom = (*Runner)->GetOtherAtom(TopOrigin);
    236238          } else {
    237             Log() << Verbose(3) << "WARNING: Detected more than four bonds for atom " << TopOrigin->Name;
     239            DoeLog(2) && (eLog()<< Verbose(2) << "Detected more than four bonds for atom " << TopOrigin->Name);
    238240          }
    239241        }
     
    272274      bondangle = TopOrigin->type->HBondAngle[1];
    273275      if (bondangle == -1) {
    274         Log() << Verbose(3) << "ERROR: There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl;
     276        DoeLog(1) && (eLog()<< Verbose(1) << "There is no typical hydrogen bond angle in replacing bond (" << TopOrigin->Name << "<->" << TopReplacement->Name << ") of degree " << TopBond->BondDegree << "!" << endl);
    275277        return false;
    276278        bondangle = 0;
     
    394396      break;
    395397    default:
    396       eLog() << Verbose(0) << "ERROR: BondDegree does not state single, double or triple bond!" << endl;
     398      DoeLog(1) && (eLog()<< Verbose(1) << "BondDegree does not state single, double or triple bond!" << endl);
    397399      AllWentWell = false;
    398400      break;
    399401  }
     402  Free(&matrix);
    400403
    401404//  Log() << Verbose(3) << "End of AddHydrogenReplacementAtom." << endl;
     
    426429  input = new istringstream(line);
    427430  *input >> NumberOfAtoms;
    428   Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl;
     431  DoLog(0) && (Log() << Verbose(0) << "Parsing " << NumberOfAtoms << " atoms in file." << endl);
    429432  getline(xyzfile,line,'\n'); // Read comment
    430   Log() << Verbose(1) << "Comment: " << line << endl;
     433  DoLog(1) && (Log() << Verbose(1) << "Comment: " << line << endl);
    431434
    432435  if (MDSteps == 0) // no atoms yet present
     
    444447    Walker->type = elemente->FindElement(shorthand);
    445448    if (Walker->type == NULL) {
    446       eLog() << Verbose(0) << "Could not parse the element at line: '" << line << "', setting to H.";
     449      DoeLog(1) && (eLog()<< Verbose(1) << "Could not parse the element at line: '" << line << "', setting to H.");
    447450      Walker->type = elemente->FindElement(1);
    448451    }
     
    540543    add(Binder, last);
    541544  } else {
    542     eLog() << Verbose(1) << "ERROR: Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl;
     545    DoeLog(1) && (eLog()<< Verbose(1) << "Could not add bond between " << atom1->Name << " and " << atom2->Name << " as one or both are not present in the molecule." << endl);
    543546  }
    544547  return Binder;
     
    552555bool molecule::RemoveBond(bond *pointer)
    553556{
    554   //eLog() << Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl;
     557  //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
    555558  pointer->leftatom->RegisterBond(pointer);
    556559  pointer->rightatom->RegisterBond(pointer);
     
    566569bool molecule::RemoveBonds(atom *BondPartner)
    567570{
    568   //eLog() << Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl;
     571  //DoeLog(1) && (eLog()<< Verbose(1) << "molecule::RemoveBond: Function not implemented yet." << endl);
    569572  BondList::const_iterator ForeRunner;
    570573  while (!BondPartner->ListOfBonds.empty()) {
     
    586589  else
    587590    molname = filename; // contains no slashes
    588   char *endname = strchr(molname, '.');
     591  const char *endname = strchr(molname, '.');
    589592  if ((endname == NULL) || (endname < molname))
    590593    length = strlen(molname);
     
    600603void molecule::SetBoxDimension(Vector *dim)
    601604{
     605  double * const cell_size = World::get()->cell_size;
    602606  cell_size[0] = dim->x[0];
    603607  cell_size[1] = 0.;
     
    618622    AtomCount--;
    619623  } else
    620     eLog() << Verbose(0) << "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;
     624    DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
    621625  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    622626    ElementCount--;
     
    636640    ElementsInMolecule[pointer->type->Z]--; // decrease number of atom of this element
    637641  else
    638     eLog() << Verbose(0) << "ERROR: Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl;
     642    DoeLog(1) && (eLog()<< Verbose(1) << "Atom " << pointer->Name << " is of element " << pointer->type->Z << " but the entry in the table of the molecule is 0!" << endl);
    639643  if (ElementsInMolecule[pointer->type->Z] == 0)  // was last atom of this element?
    640644    ElementCount--;
     
    661665    return walker;
    662666  } else {
    663     Log() << Verbose(0) << "Atom not found in list." << endl;
     667    DoLog(0) && (Log() << Verbose(0) << "Atom not found in list." << endl);
    664668    return NULL;
    665669  }
     
    677681    //mol->Output((ofstream *)&cout);
    678682    //Log() << Verbose(0) << "===============================================" << endl;
    679     Log() << Verbose(0) << text;
     683    DoLog(0) && (Log() << Verbose(0) << text);
    680684    cin >> No;
    681685    ion = this->FindAtom(No);
     
    690694bool molecule::CheckBounds(const Vector *x) const
    691695{
     696  double * const cell_size = World::get()->cell_size;
    692697  bool result = true;
    693698  int j =-1;
     
    765770void molecule::OutputListOfBonds() const
    766771{
    767   Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl;
     772  DoLog(2) && (Log() << Verbose(2) << endl << "From Contents of ListOfBonds, all non-hydrogen atoms:" << endl);
    768773  ActOnAllAtoms (&atom::OutputBondOfAtom );
    769   Log() << Verbose(0) << endl;
     774  DoLog(0) && (Log() << Verbose(0) << endl);
    770775};
    771776
     
    824829  }
    825830  if ((AtomCount == 0) || (i != AtomCount)) {
    826     Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl;
     831    DoLog(3) && (Log() << Verbose(3) << "Mismatch in AtomCount " << AtomCount << " and recounted number " << i << ", renaming all." << endl);
    827832    AtomCount = i;
    828833
     
    840845        Walker->Name = Malloc<char>(6, "molecule::CountAtoms: *walker->Name");
    841846        sprintf(Walker->Name, "%2s%02d", Walker->type->symbol, Walker->nr+1);
    842         Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl;
     847        DoLog(3) && (Log() << Verbose(3) << "Naming atom nr. " << Walker->nr << " " << Walker->Name << "." << endl);
    843848        i++;
    844849      }
    845850    } else
    846       Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl;
     851      DoLog(3) && (Log() << Verbose(3) << "AtomCount is still " << AtomCount << ", thus counting nothing." << endl);
    847852  }
    848853};
     
    904909  bool result = true; // status of comparison
    905910
    906   Log() << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl;
     911  DoLog(3) && (Log() << Verbose(3) << "Begin of IsEqualToWithinThreshold." << endl);
    907912  /// first count both their atoms and elements and update lists thereby ...
    908913  //Log() << Verbose(0) << "Counting atoms, updating list" << endl;
     
    916921  if (result) {
    917922    if (AtomCount != OtherMolecule->AtomCount) {
    918       Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl;
     923      DoLog(4) && (Log() << Verbose(4) << "AtomCounts don't match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl);
    919924      result = false;
    920925    } else Log() << Verbose(4) << "AtomCounts match: " << AtomCount << " == " << OtherMolecule->AtomCount << endl;
     
    923928  if (result) {
    924929    if (ElementCount != OtherMolecule->ElementCount) {
    925       Log() << Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl;
     930      DoLog(4) && (Log() << Verbose(4) << "ElementCount don't match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl);
    926931      result = false;
    927932    } else Log() << Verbose(4) << "ElementCount match: " << ElementCount << " == " << OtherMolecule->ElementCount << endl;
     
    935940    }
    936941    if (flag < MAX_ELEMENTS) {
    937       Log() << Verbose(4) << "ElementsInMolecule don't match." << endl;
     942      DoLog(4) && (Log() << Verbose(4) << "ElementsInMolecule don't match." << endl);
    938943      result = false;
    939944    } else Log() << Verbose(4) << "ElementsInMolecule match." << endl;
     
    941946  /// then determine and compare center of gravity for each molecule ...
    942947  if (result) {
    943     Log() << Verbose(5) << "Calculating Centers of Gravity" << endl;
     948    DoLog(5) && (Log() << Verbose(5) << "Calculating Centers of Gravity" << endl);
    944949    DeterminePeriodicCenter(CenterOfGravity);
    945950    OtherMolecule->DeterminePeriodicCenter(OtherCenterOfGravity);
    946     Log() << Verbose(5) << "Center of Gravity: ";
     951    DoLog(5) && (Log() << Verbose(5) << "Center of Gravity: ");
    947952    CenterOfGravity.Output();
    948     Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: ";
     953    DoLog(0) && (Log() << Verbose(0) << endl << Verbose(5) << "Other Center of Gravity: ");
    949954    OtherCenterOfGravity.Output();
    950     Log() << Verbose(0) << endl;
     955    DoLog(0) && (Log() << Verbose(0) << endl);
    951956    if (CenterOfGravity.DistanceSquared(&OtherCenterOfGravity) > threshold*threshold) {
    952       Log() << Verbose(4) << "Centers of gravity don't match." << endl;
     957      DoLog(4) && (Log() << Verbose(4) << "Centers of gravity don't match." << endl);
    953958      result = false;
    954959    }
     
    957962  /// ... then make a list with the euclidian distance to this center for each atom of both molecules
    958963  if (result) {
    959     Log() << Verbose(5) << "Calculating distances" << endl;
     964    DoLog(5) && (Log() << Verbose(5) << "Calculating distances" << endl);
    960965    Distances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: Distances");
    961966    OtherDistances = Calloc<double>(AtomCount, "molecule::IsEqualToWithinThreshold: OtherDistances");
     
    964969
    965970    /// ... sort each list (using heapsort (o(N log N)) from GSL)
    966     Log() << Verbose(5) << "Sorting distances" << endl;
     971    DoLog(5) && (Log() << Verbose(5) << "Sorting distances" << endl);
    967972    PermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermMap");
    968973    OtherPermMap = Calloc<size_t>(AtomCount, "molecule::IsEqualToWithinThreshold: *OtherPermMap");
     
    970975    gsl_heapsort_index (OtherPermMap, OtherDistances, AtomCount, sizeof(double), CompareDoubles);
    971976    PermutationMap = Calloc<int>(AtomCount, "molecule::IsEqualToWithinThreshold: *PermutationMap");
    972     Log() << Verbose(5) << "Combining Permutation Maps" << endl;
     977    DoLog(5) && (Log() << Verbose(5) << "Combining Permutation Maps" << endl);
    973978    for(int i=AtomCount;i--;)
    974979      PermutationMap[PermMap[i]] = (int) OtherPermMap[i];
    975980
    976981    /// ... and compare them step by step, whether the difference is individually(!) below \a threshold for all
    977     Log() << Verbose(4) << "Comparing distances" << endl;
     982    DoLog(4) && (Log() << Verbose(4) << "Comparing distances" << endl);
    978983    flag = 0;
    979984    for (int i=0;i<AtomCount;i++) {
    980       Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " <<  threshold << endl;
     985      DoLog(5) && (Log() << Verbose(5) << "Distances squared: |" << Distances[PermMap[i]] << " - " << OtherDistances[OtherPermMap[i]] << "| = " << fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) << " ?<? " <<  threshold << endl);
    981986      if (fabs(Distances[PermMap[i]] - OtherDistances[OtherPermMap[i]]) > threshold*threshold)
    982987        flag = 1;
     
    994999  }
    9951000  /// return pointer to map if all distances were below \a threshold
    996   Log() << Verbose(3) << "End of IsEqualToWithinThreshold." << endl;
     1001  DoLog(3) && (Log() << Verbose(3) << "End of IsEqualToWithinThreshold." << endl);
    9971002  if (result) {
    998     Log() << Verbose(3) << "Result: Equal." << endl;
     1003    DoLog(3) && (Log() << Verbose(3) << "Result: Equal." << endl);
    9991004    return PermutationMap;
    10001005  } else {
    1001     Log() << Verbose(3) << "Result: Not equal." << endl;
     1006    DoLog(3) && (Log() << Verbose(3) << "Result: Not equal." << endl);
    10021007    return NULL;
    10031008  }
     
    10141019{
    10151020  atom *Walker = NULL, *OtherWalker = NULL;
    1016   Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl;
     1021  DoLog(3) && (Log() << Verbose(3) << "Begin of GetFatherAtomicMap." << endl);
    10171022  int *AtomicMap = Malloc<int>(AtomCount, "molecule::GetAtomicMap: *AtomicMap");
    10181023  for (int i=AtomCount;i--;)
     
    10211026    for (int i=AtomCount;i--;) // no need as -1 means already that there is trivial correspondence
    10221027      AtomicMap[i] = i;
    1023     Log() << Verbose(4) << "Map is trivial." << endl;
     1028    DoLog(4) && (Log() << Verbose(4) << "Map is trivial." << endl);
    10241029  } else {
    1025     Log() << Verbose(4) << "Map is ";
     1030    DoLog(4) && (Log() << Verbose(4) << "Map is ");
    10261031    Walker = start;
    10271032    while (Walker->next != end) {
     
    10401045        }
    10411046      }
    1042       Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t";
    1043     }
    1044     Log() << Verbose(0) << endl;
    1045   }
    1046   Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl;
     1047      DoLog(0) && (Log() << Verbose(0) << AtomicMap[Walker->nr] << "\t");
     1048    }
     1049    DoLog(0) && (Log() << Verbose(0) << endl);
     1050  }
     1051  DoLog(3) && (Log() << Verbose(3) << "End of GetFatherAtomicMap." << endl);
    10471052  return AtomicMap;
    10481053};
  • src/molecule.hpp

    re5ad5c ree7e25  
    8282class molecule : public PointCloud {
    8383  public:
    84     double cell_size[6];//!< cell size
    8584    const periodentafel * const elemente; //!< periodic table with each element
    8685    atom *start;        //!< start of atom list
     
    106105
    107106  // re-definition of virtual functions from PointCloud
     107  const char * const GetName() const;
    108108  Vector *GetCenter() const ;
    109109  TesselPoint *GetPoint() const ;
    110110  TesselPoint *GetTerminalPoint() const ;
     111  int GetMaxId() const;
    111112  void GoToNext() const ;
    112113  void GoToPrevious() const ;
     
    267268  int FragmentMolecule(int Order, config *configuration);
    268269  bool CheckOrderAtSite(bool *AtomMask, Graph *GlobalKeySetList, int Order, int *MinimumRingSize, char *path = NULL);
    269   bool StoreAdjacencyToFile(char *path);
     270  bool StoreBondsToFile(char *path, char *filename);
     271  bool StoreAdjacencyToFile(char *path, char *filename);
    270272  bool CheckAdjacencyFileAgainstMolecule(char *path, atom **ListOfAtoms);
    271273  bool ParseOrderAtSiteFromFile(char *path);
     
    321323  void Enumerate(ofstream *out);
    322324  void Output(ofstream *out);
    323   void DissectMoleculeIntoConnectedSubgraphs(molecule * const mol, config * const configuration);
     325  void DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration);
     326  int CountAllAtoms() const;
    324327
    325328  // merging of molecules
  • src/molecule_dynamics.cpp

    re5ad5c ree7e25  
    207207    doubles++;
    208208  if (doubles >0)
    209     Log() << Verbose(2) << "Found " << doubles << " Doubles." << endl;
     209    DoLog(2) && (Log() << Verbose(2) << "Found " << doubles << " Doubles." << endl);
    210210  Free(&DoubleList);
    211211//  Log() << Verbose(2) << zeile1.str() << endl << zeile2.str() << endl;
     
    249249    Params.DoubleList[Params.DistanceList[Walker->nr]->begin()->second->nr]++;            // increase this target's source count (>1? not injective)
    250250    Params.DistanceIterators[Walker->nr] = Params.DistanceList[Walker->nr]->begin();    // and remember which one we picked
    251     Log() << Verbose(2) << *Walker << " starts with distance " << Params.DistanceList[Walker->nr]->begin()->first << "." << endl;
     251    DoLog(2) && (Log() << Verbose(2) << *Walker << " starts with distance " << Params.DistanceList[Walker->nr]->begin()->first << "." << endl);
    252252  }
    253253};
     
    277277      Params.DistanceIterators[Walker->nr] = NewBase;
    278278      OldPotential = Potential;
    279       Log() << Verbose(3) << "Found a new permutation, new potential is " << OldPotential << "." << endl;
     279      DoLog(3) && (Log() << Verbose(3) << "Found a new permutation, new potential is " << OldPotential << "." << endl);
    280280    }
    281281  }
     
    306306  for (int i=mol->AtomCount; i--;) // now each single entry in the DoubleList should be <=1
    307307    if (Params.DoubleList[i] > 1) {
    308       eLog() << Verbose(0) << "Failed to create an injective PermutationMap!" << endl;
    309       exit(1);
    310     }
    311   Log() << Verbose(1) << "done." << endl;
     308      DoeLog(0) && (eLog()<< Verbose(0) << "Failed to create an injective PermutationMap!" << endl);
     309      performCriticalExit();
     310    }
     311  DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    312312};
    313313
     
    358358  Params.PenaltyConstants[2] = 1e+7;    // just a huge penalty
    359359  // generate the distance list
    360   Log() << Verbose(1) << "Allocating, initializting and filling the distance list ... " << endl;
     360  DoLog(1) && (Log() << Verbose(1) << "Allocating, initializting and filling the distance list ... " << endl);
    361361  FillDistanceList(this, Params);
    362362
     
    365365
    366366  // make the PermutationMap injective by checking whether we have a non-zero constants[2] term in it
    367   Log() << Verbose(1) << "Making the PermutationMap injective ... " << endl;
     367  DoLog(1) && (Log() << Verbose(1) << "Making the PermutationMap injective ... " << endl);
    368368  MakeInjectivePermutation(this, Params);
    369369  Free(&Params.DoubleList);
    370370
    371371  // argument minimise the constrained potential in this injective PermutationMap
    372   Log() << Verbose(1) << "Argument minimising the PermutationMap, at current potential " << OldPotential << " ... " << endl;
     372  DoLog(1) && (Log() << Verbose(1) << "Argument minimising the PermutationMap." << endl);
    373373  OldPotential = 1e+10;
    374374  round = 0;
    375375  do {
    376     Log() << Verbose(2) << "Starting round " << ++round << " ... " << endl;
     376    DoLog(2) && (Log() << Verbose(2) << "Starting round " << ++round << ", at current potential " << OldPotential << " ... " << endl);
    377377    OlderPotential = OldPotential;
    378378    do {
     
    424424            } else {
    425425              Params.DistanceIterators[Runner->nr] = Rider;  // if successful also move the pointer in the iterator list
    426               Log() << Verbose(3) << "Found a better permutation, new potential is " << Potential << " vs." << OldPotential << "." << endl;
     426              DoLog(3) && (Log() << Verbose(3) << "Found a better permutation, new potential is " << Potential << " vs." << OldPotential << "." << endl);
    427427              OldPotential = Potential;
    428428            }
    429429            if (Potential > Params.PenaltyConstants[2]) {
    430               eLog() << Verbose(0) << "ERROR: The two-step permutation procedure did not maintain injectivity!" << endl;
     430              DoeLog(1) && (eLog()<< Verbose(1) << "The two-step permutation procedure did not maintain injectivity!" << endl);
    431431              exit(255);
    432432            }
    433433            //Log() << Verbose(0) << endl;
    434434          } else {
    435             eLog() << Verbose(0) << "ERROR: " << *Runner << " was not the owner of " << *Sprinter << "!" << endl;
     435            DoeLog(1) && (eLog()<< Verbose(1) << *Runner << " was not the owner of " << *Sprinter << "!" << endl);
    436436            exit(255);
    437437          }
     
    443443    } while (Walker->next != end);
    444444  } while ((OlderPotential - OldPotential) > 1e-3);
    445   Log() << Verbose(1) << "done." << endl;
     445  DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    446446
    447447
     
    466466{
    467467  /// evaluate forces (only the distance to target dependent part) with the final PermutationMap
    468   Log() << Verbose(1) << "Calculating forces and adding onto ForceMatrix ... " << endl;
     468  DoLog(1) && (Log() << Verbose(1) << "Calculating forces and adding onto ForceMatrix ... " << endl);
    469469  ActOnAllAtoms( &atom::EvaluateConstrainedForce, startstep, endstep, PermutationMap, Force );
    470   Log() << Verbose(1) << "done." << endl;
     470  DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    471471};
    472472
     
    503503
    504504  // go through all steps and add the molecular configuration to the list and to the Trajectories of \a this molecule
    505   Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl;
     505  DoLog(1) && (Log() << Verbose(1) << "Filling intermediate " << MaxSteps << " steps with MDSteps of " << MDSteps << "." << endl);
    506506  for (int step = 0; step <= MaxSteps; step++) {
    507507    mol = new molecule(elemente);
     
    568568    // parse file into ForceMatrix
    569569    if (!Force.ParseMatrix(file, 0,0,0)) {
    570       eLog() << Verbose(0) << "Could not parse Force Matrix file " << file << "." << endl;
     570      DoeLog(0) && (eLog()<< Verbose(0) << "Could not parse Force Matrix file " << file << "." << endl);
     571      performCriticalExit();
    571572      return false;
    572573    }
    573574    if (Force.RowCounter[0] != AtomCount) {
    574       eLog() << Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << AtomCount << "." << endl;
     575      DoeLog(0) && (eLog()<< Verbose(0) << "Mismatch between number of atoms in file " << Force.RowCounter[0] << " and in molecule " << AtomCount << "." << endl);
     576      performCriticalExit();
    575577      return false;
    576578    }
     
    650652  switch(Thermostat) {
    651653     case None:
    652       Log() << Verbose(2) <<  "Applying no thermostat..." << endl;
     654      DoLog(2) && (Log() << Verbose(2) <<  "Applying no thermostat..." << endl);
    653655      break;
    654656     case Woodcock:
    655657      if ((configuration.ScaleTempStep > 0) && ((MDSteps-1) % configuration.ScaleTempStep == 0)) {
    656         Log() << Verbose(2) <<  "Applying Woodcock thermostat..." << endl;
     658        DoLog(2) && (Log() << Verbose(2) <<  "Applying Woodcock thermostat..." << endl);
    657659        ActOnAllAtoms( &atom::Thermostat_Woodcock, sqrt(ScaleTempFactor), MDSteps, &ekin );
    658660      }
    659661      break;
    660662     case Gaussian:
    661       Log() << Verbose(2) <<  "Applying Gaussian thermostat..." << endl;
     663      DoLog(2) && (Log() << Verbose(2) <<  "Applying Gaussian thermostat..." << endl);
    662664      ActOnAllAtoms( &atom::Thermostat_Gaussian_init, MDSteps, &G, &E );
    663665
    664       Log() << Verbose(1) << "Gaussian Least Constraint constant is " << G/E << "." << endl;
     666      DoLog(1) && (Log() << Verbose(1) << "Gaussian Least Constraint constant is " << G/E << "." << endl);
    665667      ActOnAllAtoms( &atom::Thermostat_Gaussian_least_constraint, MDSteps, G/E, &ekin, &configuration);
    666668
    667669      break;
    668670     case Langevin:
    669       Log() << Verbose(2) <<  "Applying Langevin thermostat..." << endl;
     671      DoLog(2) && (Log() << Verbose(2) <<  "Applying Langevin thermostat..." << endl);
    670672      // init random number generator
    671673      gsl_rng_env_setup();
     
    677679
    678680     case Berendsen:
    679       Log() << Verbose(2) <<  "Applying Berendsen-VanGunsteren thermostat..." << endl;
     681      DoLog(2) && (Log() << Verbose(2) <<  "Applying Berendsen-VanGunsteren thermostat..." << endl);
    680682      ActOnAllAtoms( &atom::Thermostat_Berendsen, MDSteps, ScaleTempFactor, &ekin, &configuration );
    681683      break;
    682684
    683685     case NoseHoover:
    684       Log() << Verbose(2) <<  "Applying Nose-Hoover thermostat..." << endl;
     686      DoLog(2) && (Log() << Verbose(2) <<  "Applying Nose-Hoover thermostat..." << endl);
    685687      // dynamically evolve alpha (the additional degree of freedom)
    686688      delta_alpha = 0.;
     
    688690      delta_alpha = (delta_alpha - (3.*AtomCount+1.) * configuration.TargetTemp)/(configuration.HooverMass*Units2Electronmass);
    689691      configuration.alpha += delta_alpha*configuration.Deltat;
    690       Log() << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.alpha << "." << endl;
     692      DoLog(3) && (Log() << Verbose(3) << "alpha = " << delta_alpha << " * " << configuration.Deltat << " = " << configuration.alpha << "." << endl);
    691693      // apply updated alpha as additional force
    692694      ActOnAllAtoms( &atom::Thermostat_NoseHoover_scale, MDSteps, &ekin, &configuration );
    693695      break;
    694696  }
    695   Log() << Verbose(1) << "Kinetic energy is " << ekin << "." << endl;
    696 };
     697  DoLog(1) && (Log() << Verbose(1) << "Kinetic energy is " << ekin << "." << endl);
     698};
  • src/molecule_fragmentation.cpp

    re5ad5c ree7e25  
    55 *      Author: heber
    66 */
     7
     8#include <cstring>
    79
    810#include "atom.hpp"
     
    1618#include "molecule.hpp"
    1719#include "periodentafel.hpp"
     20#include "World.hpp"
    1821
    1922/************************************* Functions for class molecule *********************************/
     
    4144  }
    4245  FragmentCount = NoNonHydrogen*(1 << (c*order));
    43   Log() << Verbose(1) << "Upper limit for this subgraph is " << FragmentCount << " for " << NoNonHydrogen << " non-H atoms with maximum bond degree of " << c << "." << endl;
     46  DoLog(1) && (Log() << Verbose(1) << "Upper limit for this subgraph is " << FragmentCount << " for " << NoNonHydrogen << " non-H atoms with maximum bond degree of " << c << "." << endl);
    4447  return FragmentCount;
    4548};
     
    6568    } // else it's "-1" or else and thus must not be added
    6669  }
    67   Log() << Verbose(1) << "The scanned KeySet is ";
     70  DoLog(1) && (Log() << Verbose(1) << "The scanned KeySet is ");
    6871  for(KeySet::iterator runner = CurrentSet.begin(); runner != CurrentSet.end(); runner++) {
    69     Log() << Verbose(0) << (*runner) << "\t";
    70   }
    71   Log() << Verbose(0) << endl;
     72    DoLog(0) && (Log() << Verbose(0) << (*runner) << "\t");
     73  }
     74  DoLog(0) && (Log() << Verbose(0) << endl);
    7275  return (status != 0);
    7376};
     
    97100
    98101  // 1st pass: open file and read
    99   Log() << Verbose(1) << "Parsing the KeySet file ... " << endl;
     102  DoLog(1) && (Log() << Verbose(1) << "Parsing the KeySet file ... " << endl);
    100103  sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, KEYSETFILE);
    101104  InputFile.open(filename);
     
    110113        testGraphInsert = FragmentList->insert(GraphPair (CurrentSet,pair<int,double>(NumberOfFragments++,1)));  // store fragment number and current factor
    111114        if (!testGraphInsert.second) {
    112           eLog() << Verbose(0) << "KeySet file must be corrupt as there are two equal key sets therein!" << endl;
     115          DoeLog(0) && (eLog()<< Verbose(0) << "KeySet file must be corrupt as there are two equal key sets therein!" << endl);
     116          performCriticalExit();
    113117        }
    114118      }
     
    118122    InputFile.clear();
    119123    Free(&buffer);
    120     Log() << Verbose(1) << "done." << endl;
     124    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    121125  } else {
    122     Log() << Verbose(1) << "File " << filename << " not found." << endl;
     126    DoLog(1) && (Log() << Verbose(1) << "File " << filename << " not found." << endl);
    123127    status = false;
    124128  }
     
    150154
    151155  // 2nd pass: open TEFactors file and read
    152   Log() << Verbose(1) << "Parsing the TEFactors file ... " << endl;
     156  DoLog(1) && (Log() << Verbose(1) << "Parsing the TEFactors file ... " << endl);
    153157  sprintf(filename, "%s/%s%s", path, FRAGMENTPREFIX, TEFACTORSFILE);
    154158  InputFile.open(filename);
     
    160164        InputFile >> TEFactor;
    161165        (*runner).second.second = TEFactor;
    162         Log() << Verbose(2) << "Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "." << endl;
     166        DoLog(2) && (Log() << Verbose(2) << "Setting " << ++NumberOfFragments << " fragment's TEFactor to " << (*runner).second.second << "." << endl);
    163167      } else {
    164168        status = false;
     
    168172    // 4. Free and done
    169173    InputFile.close();
    170     Log() << Verbose(1) << "done." << endl;
     174    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    171175  } else {
    172     Log() << Verbose(1) << "File " << filename << " not found." << endl;
     176    DoLog(1) && (Log() << Verbose(1) << "File " << filename << " not found." << endl);
    173177    status = false;
    174178  }
     
    198202  line += KEYSETFILE;
    199203  output.open(line.c_str(), ios::out);
    200   Log() << Verbose(1) << "Saving key sets of the total graph ... ";
     204  DoLog(1) && (Log() << Verbose(1) << "Saving key sets of the total graph ... ");
    201205  if(output != NULL) {
    202206    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++) {
     
    208212      output << endl;
    209213    }
    210     Log() << Verbose(0) << "done." << endl;
     214    DoLog(0) && (Log() << Verbose(0) << "done." << endl);
    211215  } else {
    212     eLog() << Verbose(0) << "Unable to open " << line << " for writing keysets!" << endl;
     216    DoeLog(0) && (eLog()<< Verbose(0) << "Unable to open " << line << " for writing keysets!" << endl);
     217    performCriticalExit();
    213218    status = false;
    214219  }
     
    238243  line += TEFACTORSFILE;
    239244  output.open(line.c_str(), ios::out);
    240   Log() << Verbose(1) << "Saving TEFactors of the total graph ... ";
     245  DoLog(1) && (Log() << Verbose(1) << "Saving TEFactors of the total graph ... ");
    241246  if(output != NULL) {
    242247    for(Graph::iterator runner = KeySetList.begin(); runner != KeySetList.end(); runner++)
    243248      output << (*runner).second.second << endl;
    244     Log() << Verbose(1) << "done." << endl;
     249    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    245250  } else {
    246     Log() << Verbose(1) << "failed to open " << line << "." << endl;
     251    DoLog(1) && (Log() << Verbose(1) << "failed to open " << line << "." << endl);
    247252    status = false;
    248253  }
     
    288293        (*PresentItem).second.first = fabs(Value);
    289294        (*PresentItem).second.second = FragOrder;
    290         Log() << Verbose(2) << "Updated element (" <<  (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl;
     295        DoLog(2) && (Log() << Verbose(2) << "Updated element (" <<  (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);
    291296      } else {
    292         Log() << Verbose(2) << "Did not update element " <<  (*PresentItem).first << " as " << FragOrder << " is less than or equal to " << (*PresentItem).second.second << "." << endl;
     297        DoLog(2) && (Log() << Verbose(2) << "Did not update element " <<  (*PresentItem).first << " as " << FragOrder << " is less than or equal to " << (*PresentItem).second.second << "." << endl);
    293298      }
    294299    } else {
    295       Log() << Verbose(2) << "Inserted element (" <<  (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl;
     300      DoLog(2) && (Log() << Verbose(2) << "Inserted element (" <<  (*PresentItem).first << ",[" << (*PresentItem).second.first << "," << (*PresentItem).second.second << "])." << endl);
    296301    }
    297302  } else {
    298     Log() << Verbose(1) << "No Fragment under No. " << No << "found." << endl;
     303    DoLog(1) && (Log() << Verbose(1) << "No Fragment under No. " << No << "found." << endl);
    299304  }
    300305};
     
    355360  atom *Walker = mol->start;
    356361  map<double, pair<int,int> > *FinalRootCandidates = new map<double, pair<int,int> > ;
    357   Log() << Verbose(1) << "Root candidate list is: " << endl;
     362  DoLog(1) && (Log() << Verbose(1) << "Root candidate list is: " << endl);
    358363  for(map<int, pair<double,int> >::iterator runner = AdaptiveCriteriaList->begin(); runner != AdaptiveCriteriaList->end(); runner++) {
    359364    Walker = mol->FindAtom((*runner).first);
     
    361366      //if ((*runner).second.second >= Walker->AdaptiveOrder) { // only insert if this is an "active" root site for the current order
    362367      if (!Walker->MaxOrder) {
    363         Log() << Verbose(2) << "(" << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "])" << endl;
     368        DoLog(2) && (Log() << Verbose(2) << "(" << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "])" << endl);
    364369        FinalRootCandidates->insert( make_pair( (*runner).second.first, pair<int,int>((*runner).first, (*runner).second.second) ) );
    365370      } else {
    366         Log() << Verbose(2) << "Excluding (" << *Walker << ", " << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "]), as it has reached its maximum order." << endl;
     371        DoLog(2) && (Log() << Verbose(2) << "Excluding (" << *Walker << ", " << (*runner).first << ",[" << (*runner).second.first << "," << (*runner).second.second << "]), as it has reached its maximum order." << endl);
    367372      }
    368373    } else {
    369       eLog() << Verbose(0) << "Atom No. " << (*runner).second.first << " was not found in this molecule." << endl;
     374      DoeLog(0) && (eLog()<< Verbose(0) << "Atom No. " << (*runner).second.first << " was not found in this molecule." << endl);
     375      performCriticalExit();
    370376    }
    371377  }
     
    391397    Walker = mol->FindAtom(No);
    392398    //if (Walker->AdaptiveOrder < MinimumRingSize[Walker->nr]) {
    393       Log() << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", setting entry " << No << " of Atom mask to true." << endl;
     399      DoLog(2) && (Log() << Verbose(2) << "Root " << No << " is still above threshold (10^{" << Order <<"}: " << runner->first << ", setting entry " << No << " of Atom mask to true." << endl);
    394400      AtomMask[No] = true;
    395401      status = true;
     
    407413void PrintAtomMask(bool *AtomMask, int AtomCount)
    408414{
    409   Log() << Verbose(2) << "              ";
     415  DoLog(2) && (Log() << Verbose(2) << "              ");
    410416  for(int i=0;i<AtomCount;i++)
    411     Log() << Verbose(0) << (i % 10);
    412   Log() << Verbose(0) << endl;
    413   Log() << Verbose(2) << "Atom mask is: ";
     417    DoLog(0) && (Log() << Verbose(0) << (i % 10));
     418  DoLog(0) && (Log() << Verbose(0) << endl);
     419  DoLog(2) && (Log() << Verbose(2) << "Atom mask is: ");
    414420  for(int i=0;i<AtomCount;i++)
    415     Log() << Verbose(0) << (AtomMask[i] ? "t" : "f");
    416   Log() << Verbose(0) << endl;
     421    DoLog(0) && (Log() << Verbose(0) << (AtomMask[i] ? "t" : "f"));
     422  DoLog(0) && (Log() << Verbose(0) << endl);
    417423};
    418424
     
    441447    // transmorph graph keyset list into indexed KeySetList
    442448    if (GlobalKeySetList == NULL) {
    443       Log() << Verbose(1) << "ERROR: Given global key set list (graph) is NULL!" << endl;
     449      DoeLog(1) && (eLog()<< Verbose(1) << "Given global key set list (graph) is NULL!" << endl);
    444450      return false;
    445451    }
     
    449455    map<int, pair<double,int> > *AdaptiveCriteriaList = ScanAdaptiveFileIntoMap(path, *IndexKeySetList); // (Root No., (Value, Order)) !
    450456    if (AdaptiveCriteriaList->empty()) {
    451       eLog() << Verbose(0) << "Unable to parse file, incrementing all." << endl;
     457      DoeLog(2) && (eLog()<< Verbose(2) << "Unable to parse file, incrementing all." << endl);
    452458      while (Walker->next != end) {
    453459        Walker = Walker->next;
     
    487493    if (!status) {
    488494      if (Order == 0)
    489         Log() << Verbose(1) << "Single stepping done." << endl;
     495        DoLog(1) && (Log() << Verbose(1) << "Single stepping done." << endl);
    490496      else
    491         Log() << Verbose(1) << "Order at every site is already equal or above desired order " << Order << "." << endl;
     497        DoLog(1) && (Log() << Verbose(1) << "Order at every site is already equal or above desired order " << Order << "." << endl);
    492498    }
    493499  }
     
    506512{
    507513  if (SortIndex != NULL) {
    508     Log() << Verbose(1) << "SortIndex is " << SortIndex << " and not NULL as expected." << endl;
     514    DoLog(1) && (Log() << Verbose(1) << "SortIndex is " << SortIndex << " and not NULL as expected." << endl);
    509515    return false;
    510516  }
     
    557563  bool *AtomMask = NULL;
    558564
    559   Log() << Verbose(0) << endl;
     565  DoLog(0) && (Log() << Verbose(0) << endl);
    560566#ifdef ADDHYDROGEN
    561   Log() << Verbose(0) << "I will treat hydrogen special and saturate dangling bonds with it." << endl;
     567  DoLog(0) && (Log() << Verbose(0) << "I will treat hydrogen special and saturate dangling bonds with it." << endl);
    562568#else
    563   Log() << Verbose(0) << "Hydrogen is treated just like the rest of the lot." << endl;
     569  DoLog(0) && (Log() << Verbose(0) << "Hydrogen is treated just like the rest of the lot." << endl);
    564570#endif
    565571
     
    587593    // fill the bond structure of the individually stored subgraphs
    588594  MolecularWalker->FillBondStructureFromReference(this, FragmentCounter, ListOfLocalAtoms, false);  // we want to keep the created ListOfLocalAtoms
    589     Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl;
     595    DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
    590596    LocalBackEdgeStack = new StackClass<bond *> (MolecularWalker->Leaf->BondCount);
    591597//    // check the list of local atoms for debugging
     
    596602//      else
    597603//        Log() << Verbose(0) << "\t" << ListOfLocalAtoms[FragmentCounter][i]->Name;
    598     Log() << Verbose(0) << "Gathering local back edges for subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl;
     604    DoLog(0) && (Log() << Verbose(0) << "Gathering local back edges for subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
    599605    MolecularWalker->Leaf->PickLocalBackEdges(ListOfLocalAtoms[FragmentCounter++], BackEdgeStack, LocalBackEdgeStack);
    600     Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl;
     606    DoLog(0) && (Log() << Verbose(0) << "Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
    601607    MolecularWalker->Leaf->CyclicStructureAnalysis(LocalBackEdgeStack, MinimumRingSize);
    602     Log() << Verbose(0) << "Done with Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl;
     608    DoLog(0) && (Log() << Verbose(0) << "Done with Analysing the cycles of subgraph " << MolecularWalker->Leaf << " with nr. " << FragmentCounter << "." << endl);
    603609    delete(LocalBackEdgeStack);
    604610  }
     
    631637    while (MolecularWalker->next != NULL) {
    632638      MolecularWalker = MolecularWalker->next;
    633       Log() << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl;
     639      DoLog(1) && (Log() << Verbose(1) << "Fragmenting subgraph " << MolecularWalker << "." << endl);
    634640      //MolecularWalker->Leaf->OutputListOfBonds(out);  // output atom::ListOfBonds for debugging
    635641      if (MolecularWalker->Leaf->first->next != MolecularWalker->Leaf->last) {
    636642        // call BOSSANOVA method
    637         Log() << Verbose(0) << endl << " ========== BOND ENERGY of subgraph " << FragmentCounter << " ========================= " << endl;
     643        DoLog(0) && (Log() << Verbose(0) << endl << " ========== BOND ENERGY of subgraph " << FragmentCounter << " ========================= " << endl);
    638644        MolecularWalker->Leaf->FragmentBOSSANOVA(FragmentList[FragmentCounter], RootStack[FragmentCounter], MinimumRingSize);
    639645      } else {
    640         eLog() << Verbose(0) << "Subgraph " << MolecularWalker << " has no atoms!" << endl;
     646        DoeLog(1) && (eLog()<< Verbose(1) << "Subgraph " << MolecularWalker << " has no atoms!" << endl);
    641647      }
    642648      FragmentCounter++;  // next fragment list
    643649    }
    644650  }
    645   Log() << Verbose(2) << "CheckOrder is " << CheckOrder << "." << endl;
     651  DoLog(2) && (Log() << Verbose(2) << "CheckOrder is " << CheckOrder << "." << endl);
    646652  delete[](RootStack);
    647653  delete[](AtomMask);
     
    674680  for(Graph::iterator runner = TotalGraph.begin(); runner != TotalGraph.end(); runner++) {
    675681    KeySet test = (*runner).first;
    676     Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl;
     682    DoLog(0) && (Log() << Verbose(0) << "Fragment No." << (*runner).second.first << " with TEFactor " << (*runner).second.second << "." << endl);
    677683    BondFragments->insert(StoreFragmentFromKeySet(test, configuration));
    678684    k++;
    679685  }
    680   Log() << Verbose(0) << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl;
     686  DoLog(0) && (Log() << Verbose(0) << k << "/" << BondFragments->ListOfMolecules.size() << " fragments generated from the keysets." << endl);
    681687
    682688  // ===== 9. Save fragments' configuration and keyset files et al to disk ===
     
    685691    CreateMappingLabelsToConfigSequence(SortIndex);
    686692
    687     Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl;
     693    DoLog(1) && (Log() << Verbose(1) << "Writing " << BondFragments->ListOfMolecules.size() << " possible bond fragmentation configs" << endl);
    688694    if (BondFragments->OutputConfigForListOfFragments(configuration, SortIndex))
    689       Log() << Verbose(1) << "All configs written." << endl;
     695      DoLog(1) && (Log() << Verbose(1) << "All configs written." << endl);
    690696    else
    691       Log() << Verbose(1) << "Some config writing failed." << endl;
     697      DoLog(1) && (Log() << Verbose(1) << "Some config writing failed." << endl);
    692698
    693699    // store force index reference file
     
    698704
    699705    // store Adjacency file
    700     StoreAdjacencyToFile(configuration->configpath);
     706    char *filename = Malloc<char> (MAXSTRINGSIZE, "molecule::FragmentMolecule - *filename");
     707    strcpy(filename, FRAGMENTPREFIX);
     708    strcat(filename, ADJACENCYFILE);
     709    StoreAdjacencyToFile(configuration->configpath, filename);
     710    Free(&filename);
    701711
    702712    // store Hydrogen saturation correction file
     
    710720
    711721    // free memory for bond part
    712     Log() << Verbose(1) << "Freeing bond memory" << endl;
     722    DoLog(1) && (Log() << Verbose(1) << "Freeing bond memory" << endl);
    713723    delete(FragmentList); // remove bond molecule from memory
    714724    Free(&SortIndex);
    715725  } else {
    716     Log() << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl;
     726    DoLog(1) && (Log() << Verbose(1) << "FragmentList is zero on return, splitting failed." << endl);
    717727  }
    718728  delete(BondFragments);
    719   Log() << Verbose(0) << "End of bond fragmentation." << endl;
     729  DoLog(0) && (Log() << Verbose(0) << "End of bond fragmentation." << endl);
    720730
    721731  return ((int)(!FragmentationToDo)+1);    // 1 - continue, 2 - stop (no fragmentation occured)
     
    736746  line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
    737747  file.open(line.str().c_str());
    738   Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl;
     748  DoLog(1) && (Log() << Verbose(1) << "Writing OrderAtSite " << ORDERATSITEFILE << " ... " << endl);
    739749  if (file != NULL) {
    740750    ActOnAllAtoms( &atom::OutputOrder, &file );
    741751    file.close();
    742     Log() << Verbose(1) << "done." << endl;
     752    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    743753    return true;
    744754  } else {
    745     Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl;
     755    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    746756    return false;
    747757  }
     
    764774  ifstream file;
    765775
    766   Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl;
     776  DoLog(1) && (Log() << Verbose(1) << "Begin of ParseOrderAtSiteFromFile" << endl);
    767777  line << path << "/" << FRAGMENTPREFIX << ORDERATSITEFILE;
    768778  file.open(line.str().c_str());
     
    785795    SetAtomValueToIndexedArray( MaxArray, &atom::nr, &atom::MaxOrder );
    786796
    787     Log() << Verbose(1) << "done." << endl;
     797    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    788798    status = true;
    789799  } else {
    790     Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl;
     800    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    791801    status = false;
    792802  }
     
    794804  Free(&MaxArray);
    795805
    796   Log() << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl;
     806  DoLog(1) && (Log() << Verbose(1) << "End of ParseOrderAtSiteFromFile" << endl);
    797807  return status;
    798808};
     
    811821  int SP, Removal;
    812822
    813   Log() << Verbose(2) << "Looking for removal candidate." << endl;
     823  DoLog(2) && (Log() << Verbose(2) << "Looking for removal candidate." << endl);
    814824  SP = -1; //0;  // not -1, so that Root is never removed
    815825  Removal = -1;
     
    838848
    839849  Leaf->BondDistance = mol->BondDistance;
    840   for(int i=NDIM*2;i--;)
    841     Leaf->cell_size[i] = mol->cell_size[i];
    842850
    843851  // first create the minimal set of atoms from the KeySet
     
    898906      }
    899907    } else {
    900       Log() << Verbose(0) << "ERROR: Son " << Runner->Name << " has father " << FatherOfRunner->Name << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl;
     908      DoeLog(1) && (eLog()<< Verbose(1) << "Son " << Runner->Name << " has father " << FatherOfRunner->Name << " but its entry in SonList is " << SonList[FatherOfRunner->nr] << "!" << endl);
    901909    }
    902910    if ((LonelyFlag) && (Leaf->AtomCount > 1)) {
    903       Log() << Verbose(0) << *Runner << "has got bonds only to hydrogens!" << endl;
     911      DoLog(0) && (Log() << Verbose(0) << *Runner << "has got bonds only to hydrogens!" << endl);
    904912    }
    905913#ifdef ADDHYDROGEN
     
    10481056    TouchedList[j] = -1;
    10491057  }
    1050   Log() << Verbose(2) << "Remaining local nr.s on snake stack are: ";
     1058  DoLog(2) && (Log() << Verbose(2) << "Remaining local nr.s on snake stack are: ");
    10511059  for(KeySet::iterator runner = FragmentSet->begin(); runner != FragmentSet->end(); runner++)
    1052     Log() << Verbose(0) << (*runner) << " ";
    1053   Log() << Verbose(0) << endl;
     1060    DoLog(0) && (Log() << Verbose(0) << (*runner) << " ");
     1061  DoLog(0) && (Log() << Verbose(0) << endl);
    10541062  TouchedIndex = 0; // set Index to 0 for list of atoms added on this level
    10551063};
     
    11281136        Log() << Verbose(1+verbosity) << "Enough items on stack for a fragment!" << endl;
    11291137        // store fragment as a KeySet
    1130         Log() << Verbose(2) << "Found a new fragment[" << FragmentSearch->FragmentCounter << "], local nr.s are: ";
     1138        DoLog(2) && (Log() << Verbose(2) << "Found a new fragment[" << FragmentSearch->FragmentCounter << "], local nr.s are: ");
    11311139        for(KeySet::iterator runner = FragmentSearch->FragmentSet->begin(); runner != FragmentSearch->FragmentSet->end(); runner++)
    1132           Log() << Verbose(0) << (*runner) << " ";
    1133         Log() << Verbose(0) << endl;
     1140          DoLog(0) && (Log() << Verbose(0) << (*runner) << " ");
     1141        DoLog(0) && (Log() << Verbose(0) << endl);
    11341142        //if (!CheckForConnectedSubgraph(FragmentSearch->FragmentSet))
    1135           //Log() << Verbose(0) << "ERROR: The found fragment is not a connected subgraph!" << endl;
     1143          //DoeLog(1) && (eLog()<< Verbose(1) << "The found fragment is not a connected subgraph!" << endl);
    11361144        InsertFragmentIntoGraph(FragmentSearch);
    11371145      }
     
    12131221{
    12141222  bond *Binder = NULL;
    1215   Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl;
     1223  DoLog(0) && (Log() << Verbose(0) << "Free'ing all found lists. and resetting index lists" << endl);
    12161224  for(int i=Order;i--;) {
    1217     Log() << Verbose(1) << "Current SP level is " << i << ": ";
     1225    DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << ": ");
    12181226    Binder = FragmentSearch.BondsPerSPList[2*i];
    12191227    while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
     
    12261234    cleanup(FragmentSearch.BondsPerSPList[2*i], FragmentSearch.BondsPerSPList[2*i+1]);
    12271235    // also start and end node
    1228     Log() << Verbose(0) << "cleaned." << endl;
     1236    DoLog(0) && (Log() << Verbose(0) << "cleaned." << endl);
    12291237  }
    12301238};
     
    12561264  int SP = -1;
    12571265
    1258   Log() << Verbose(0) << "Starting BFS analysis ..." << endl;
     1266  DoLog(0) && (Log() << Verbose(0) << "Starting BFS analysis ..." << endl);
    12591267  for (SP = 0; SP < (Order-1); SP++) {
    1260     Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << FragmentSearch.BondsPerSPCount[SP] << " item(s)";
     1268    DoLog(1) && (Log() << Verbose(1) << "New SP level reached: " << SP << ", creating new SP list with " << FragmentSearch.BondsPerSPCount[SP] << " item(s)");
    12611269    if (SP > 0) {
    1262       Log() << Verbose(0) << ", old level closed with " << FragmentSearch.BondsPerSPCount[SP-1] << " item(s)." << endl;
     1270      DoLog(0) && (Log() << Verbose(0) << ", old level closed with " << FragmentSearch.BondsPerSPCount[SP-1] << " item(s)." << endl);
    12631271      FragmentSearch.BondsPerSPCount[SP] = 0;
    12641272    } else
    1265       Log() << Verbose(0) << "." << endl;
     1273      DoLog(0) && (Log() << Verbose(0) << "." << endl);
    12661274
    12671275    RemainingWalkers = FragmentSearch.BondsPerSPCount[SP];
     
    12731281      Predecessor = CurrentEdge->leftatom;    // ... and leftatom is predecessor
    12741282      AtomKeyNr = Walker->nr;
    1275       Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->nr << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl;
     1283      DoLog(0) && (Log() << Verbose(0) << "Current Walker is: " << *Walker << " with nr " << Walker->nr << " and SP of " << SP << ", with " << RemainingWalkers << " remaining walkers on this level." << endl);
    12761284      // check for new sp level
    12771285      // go through all its bonds
    1278       Log() << Verbose(1) << "Going through all bonds of Walker." << endl;
     1286      DoLog(1) && (Log() << Verbose(1) << "Going through all bonds of Walker." << endl);
    12791287      for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    12801288        OtherWalker = (*Runner)->GetOtherAtom(Walker);
     
    12841292  #endif
    12851293                                                              ) {  // skip hydrogens and restrict to fragment
    1286           Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->nr << " in bond " << *(*Runner) << "." << endl;
     1294          DoLog(2) && (Log() << Verbose(2) << "Current partner is " << *OtherWalker << " with nr " << OtherWalker->nr << " in bond " << *(*Runner) << "." << endl);
    12871295          // set the label if not set (and push on root stack as well)
    12881296          if ((OtherWalker != Predecessor) && (OtherWalker->GetTrueFather()->nr > RootKeyNr)) { // only pass through those with label bigger than Root's
    12891297            FragmentSearch.ShortestPathList[OtherWalker->nr] = SP+1;
    1290             Log() << Verbose(3) << "Set Shortest Path to " << FragmentSearch.ShortestPathList[OtherWalker->nr] << "." << endl;
     1298            DoLog(3) && (Log() << Verbose(3) << "Set Shortest Path to " << FragmentSearch.ShortestPathList[OtherWalker->nr] << "." << endl);
    12911299            // add the bond in between to the SP list
    12921300            Binder = new bond(Walker, OtherWalker); // create a new bond in such a manner, that bond::rightatom is always the one more distant
    12931301            add(Binder, FragmentSearch.BondsPerSPList[2*(SP+1)+1]);
    12941302            FragmentSearch.BondsPerSPCount[SP+1]++;
    1295             Log() << Verbose(3) << "Added its bond to SP list, having now " << FragmentSearch.BondsPerSPCount[SP+1] << " item(s)." << endl;
     1303            DoLog(3) && (Log() << Verbose(3) << "Added its bond to SP list, having now " << FragmentSearch.BondsPerSPCount[SP+1] << " item(s)." << endl);
    12961304          } else {
    12971305            if (OtherWalker != Predecessor)
    1298               Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->nr << " is smaller than that of Root " << RootKeyNr << "." << endl;
     1306              DoLog(3) && (Log() << Verbose(3) << "Not passing on, as index of " << *OtherWalker << " " << OtherWalker->GetTrueFather()->nr << " is smaller than that of Root " << RootKeyNr << "." << endl);
    12991307            else
    1300               Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl;
     1308              DoLog(3) && (Log() << Verbose(3) << "This is my predecessor " << *Predecessor << "." << endl);
    13011309          }
    13021310        } else Log() << Verbose(2) << "Is not in the restricted keyset or skipping hydrogen " << *OtherWalker << "." << endl;
     
    13141322{
    13151323  bond *Binder = NULL;
    1316   Log() << Verbose(0) << "Printing all found lists." << endl;
     1324  DoLog(0) && (Log() << Verbose(0) << "Printing all found lists." << endl);
    13171325  for(int i=1;i<Order;i++) {    // skip the root edge in the printing
    13181326    Binder = FragmentSearch.BondsPerSPList[2*i];
    1319     Log() << Verbose(1) << "Current SP level is " << i << "." << endl;
     1327    DoLog(1) && (Log() << Verbose(1) << "Current SP level is " << i << "." << endl);
    13201328    while (Binder->next != FragmentSearch.BondsPerSPList[2*i+1]) {
    13211329      Binder = Binder->next;
    1322       Log() << Verbose(2) << *Binder << endl;
     1330      DoLog(2) && (Log() << Verbose(2) << *Binder << endl);
    13231331    }
    13241332  }
     
    13641372  int Counter = FragmentSearch.FragmentCounter; // mark current value of counter
    13651373
    1366   Log() << Verbose(0) << endl;
    1367   Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl;
     1374  DoLog(0) && (Log() << Verbose(0) << endl);
     1375  DoLog(0) && (Log() << Verbose(0) << "Begin of PowerSetGenerator with order " << Order << " at Root " << *FragmentSearch.Root << "." << endl);
    13681376
    13691377  SetSPList(Order, FragmentSearch);
     
    13771385  // creating fragments with the found edge sets  (may be done in reverse order, faster)
    13781386  int SP = CountNumbersInBondsList(Order, FragmentSearch);
    1379   Log() << Verbose(0) << "Total number of edges is " << SP << "." << endl;
     1387  DoLog(0) && (Log() << Verbose(0) << "Total number of edges is " << SP << "." << endl);
    13801388  if (SP >= (Order-1)) {
    13811389    // start with root (push on fragment stack)
    1382     Log() << Verbose(0) << "Starting fragment generation with " << *FragmentSearch.Root << ", local nr is " << FragmentSearch.Root->nr << "." << endl;
     1390    DoLog(0) && (Log() << Verbose(0) << "Starting fragment generation with " << *FragmentSearch.Root << ", local nr is " << FragmentSearch.Root->nr << "." << endl);
    13831391    FragmentSearch.FragmentSet->clear();
    1384     Log() << Verbose(0) << "Preparing subset for this root and calling generator." << endl;
     1392    DoLog(0) && (Log() << Verbose(0) << "Preparing subset for this root and calling generator." << endl);
    13851393
    13861394    // prepare the subset and call the generator
     
    13921400    Free(&BondsList);
    13931401  } else {
    1394     Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl;
     1402    DoLog(0) && (Log() << Verbose(0) << "Not enough total number of edges to build " << Order << "-body fragments." << endl);
    13951403  }
    13961404
    13971405  // as FragmentSearch structure is used only once, we don't have to clean it anymore
    13981406  // remove root from stack
    1399   Log() << Verbose(0) << "Removing root again from stack." << endl;
     1407  DoLog(0) && (Log() << Verbose(0) << "Removing root again from stack." << endl);
    14001408  FragmentSearch.FragmentSet->erase(FragmentSearch.Root->nr);
    14011409
     
    14041412
    14051413  // return list
    1406   Log() << Verbose(0) << "End of PowerSetGenerator." << endl;
     1414  DoLog(0) && (Log() << Verbose(0) << "End of PowerSetGenerator." << endl);
    14071415  return (FragmentSearch.FragmentCounter - Counter);
    14081416};
     
    14501458  atom *Walker = NULL;
    14511459
    1452   Log() << Verbose(0) << "Combining the lists of all orders per order and finally into a single one." << endl;
     1460  DoLog(0) && (Log() << Verbose(0) << "Combining the lists of all orders per order and finally into a single one." << endl);
    14531461  if (FragmentList == NULL) {
    14541462    FragmentList = new Graph;
     
    14831491void FreeAllOrdersList(Graph ***FragmentLowerOrdersList, KeyStack &RootStack, molecule *mol)
    14841492{
    1485   Log() << Verbose(1) << "Free'ing the lists of all orders per order." << endl;
     1493  DoLog(1) && (Log() << Verbose(1) << "Free'ing the lists of all orders per order." << endl);
    14861494  int RootNr = 0;
    14871495  int RootKeyNr = 0;
     
    15361544  struct UniqueFragments FragmentSearch;
    15371545
    1538   Log() << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl;
     1546  DoLog(0) && (Log() << Verbose(0) << "Begin of FragmentBOSSANOVA." << endl);
    15391547
    15401548  // FragmentLowerOrdersList is a 2D-array of pointer to MoleculeListClass objects, one dimension represents the ANOVA expansion of a single order (i.e. 5)
     
    15861594
    15871595      // create top order where nothing is reduced
    1588       Log() << Verbose(0) << "==============================================================================================================" << endl;
    1589       Log() << Verbose(0) << "Creating KeySets of Bond Order " << Order << " for " << *Walker << ", " << (RootStack.size()-RootNr) << " Roots remaining." << endl; // , NumLevels is " << NumLevels << "
     1596      DoLog(0) && (Log() << Verbose(0) << "==============================================================================================================" << endl);
     1597      DoLog(0) && (Log() << Verbose(0) << "Creating KeySets of Bond Order " << Order << " for " << *Walker << ", " << (RootStack.size()-RootNr) << " Roots remaining." << endl); // , NumLevels is " << NumLevels << "
    15901598
    15911599      // Create list of Graphs of current Bond Order (i.e. F_{ij})
     
    15971605
    15981606      // output resulting number
    1599       Log() << Verbose(1) << "Number of resulting KeySets is: " << NumMoleculesOfOrder[RootNr] << "." << endl;
     1607      DoLog(1) && (Log() << Verbose(1) << "Number of resulting KeySets is: " << NumMoleculesOfOrder[RootNr] << "." << endl);
    16001608      if (NumMoleculesOfOrder[RootNr] != 0) {
    16011609        NumMolecules = 0;
     
    16141622    }
    16151623  }
    1616   Log() << Verbose(0) << "==============================================================================================================" << endl;
    1617   Log() << Verbose(1) << "Total number of resulting molecules is: " << TotalNumMolecules << "." << endl;
    1618   Log() << Verbose(0) << "==============================================================================================================" << endl;
     1624  DoLog(0) && (Log() << Verbose(0) << "==============================================================================================================" << endl);
     1625  DoLog(1) && (Log() << Verbose(1) << "Total number of resulting molecules is: " << TotalNumMolecules << "." << endl);
     1626  DoLog(0) && (Log() << Verbose(0) << "==============================================================================================================" << endl);
    16191627
    16201628  // cleanup FragmentSearch structure
     
    16341642  Free(&NumMoleculesOfOrder);
    16351643
    1636   Log() << Verbose(0) << "End of FragmentBOSSANOVA." << endl;
     1644  DoLog(0) && (Log() << Verbose(0) << "End of FragmentBOSSANOVA." << endl);
    16371645};
    16381646
     
    16491657  atom *Walker = NULL;
    16501658  atom *OtherWalker = NULL;
     1659  double * const cell_size = World::get()->cell_size;
    16511660  double *matrix = ReturnFullMatrixforSymmetric(cell_size);
    16521661  enum Shading *ColorList = NULL;
     
    16571666  bool flag = true;
    16581667
    1659   Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl;
     1668  DoLog(2) && (Log() << Verbose(2) << "Begin of ScanForPeriodicCorrection." << endl);
    16601669
    16611670  ColorList = Calloc<enum Shading>(AtomCount, "molecule::ScanForPeriodicCorrection: *ColorList");
     
    16751684          OtherBinder = Binder->next; // note down binding partner for later re-insertion
    16761685          unlink(Binder);   // unlink bond
    1677           Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl;
     1686          DoLog(2) && (Log() << Verbose(2) << "Correcting at bond " << *Binder << "." << endl);
    16781687          flag = true;
    16791688          break;
     
    16911700      //Log() << Verbose(3) << "Translation vector is ";
    16921701      Translationvector.Output();
    1693       Log() << Verbose(0) << endl;
     1702      DoLog(0) && (Log() << Verbose(0) << endl);
    16941703      // apply to all atoms of first component via BFS
    16951704      for (int i=AtomCount;i--;)
     
    17131722      link(Binder, OtherBinder);
    17141723    } else {
    1715       Log() << Verbose(3) << "No corrections for this fragment." << endl;
     1724      DoLog(3) && (Log() << Verbose(3) << "No corrections for this fragment." << endl);
    17161725    }
    17171726    //delete(CompStack);
     
    17221731  Free(&ColorList);
    17231732  Free(&matrix);
    1724   Log() << Verbose(2) << "End of ScanForPeriodicCorrection." << endl;
    1725 };
     1733  DoLog(2) && (Log() << Verbose(2) << "End of ScanForPeriodicCorrection." << endl);
     1734};
  • src/molecule_geometry.cpp

    re5ad5c ree7e25  
    1515#include "memoryallocator.hpp"
    1616#include "molecule.hpp"
     17#include "World.hpp"
    1718
    1819/************************************* Functions for class molecule *********************************/
     
    2627  bool status = true;
    2728  const Vector *Center = DetermineCenterOfAll();
     29  double * const cell_size = World::get()->cell_size;
    2830  double *M = ReturnFullMatrixforSymmetric(cell_size);
    2931  double *Minv = InverseMatrix(M);
     
    3335  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    3436
    35   delete(M);
    36   delete(Minv);
     37  Free(&M);
     38  Free(&Minv);
    3739  delete(Center);
    3840  return status;
     
    4648{
    4749  bool status = true;
     50  double * const cell_size = World::get()->cell_size;
    4851  double *M = ReturnFullMatrixforSymmetric(cell_size);
    4952  double *Minv = InverseMatrix(M);
     
    5255  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    5356
    54   delete(M);
    55   delete(Minv);
     57  Free(&M);
     58  Free(&Minv);
    5659  return status;
    5760};
     
    101104{
    102105  int Num = 0;
    103   atom *ptr = start->next;  // start at first in list
     106  atom *ptr = start;  // start at first in list
    104107
    105108  Center.Zero();
    106109
    107   if (ptr != end) {   //list not empty?
     110  if (ptr->next != end) {   //list not empty?
    108111    while (ptr->next != end) {  // continue with second if present
    109112      ptr = ptr->next;
     
    226229void molecule::TranslatePeriodically(const Vector *trans)
    227230{
     231  double * const cell_size = World::get()->cell_size;
    228232  double *M = ReturnFullMatrixforSymmetric(cell_size);
    229233  double *Minv = InverseMatrix(M);
     
    233237  ActOnAllVectors( &Vector::WrapPeriodically, (const double *)M, (const double *)Minv);
    234238
    235   delete(M);
    236   delete(Minv);
     239  Free(&M);
     240  Free(&Minv);
    237241};
    238242
     
    252256{
    253257  atom *Walker = start;
     258  double * const cell_size = World::get()->cell_size;
    254259  double *matrix = ReturnFullMatrixforSymmetric(cell_size);
     260  double *inversematrix = InverseMatrix(cell_size);
    255261  double tmp;
    256262  bool flag;
     
    266272#endif
    267273        Testvector.CopyVector(&Walker->x);
    268         Testvector.InverseMatrixMultiplication(matrix);
     274        Testvector.MatrixMultiplication(inversematrix);
    269275        Translationvector.Zero();
    270276        for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
     
    274280              if ((fabs(tmp)) > BondDistance) {
    275281                flag = false;
    276                 Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl;
     282                DoLog(0) && (Log() << Verbose(0) << "Hit: atom " << Walker->Name << " in bond " << *(*Runner) << " has to be shifted due to " << tmp << "." << endl);
    277283                if (tmp > 0)
    278284                  Translationvector.x[j] -= 1.;
     
    285291        Testvector.MatrixMultiplication(matrix);
    286292        Center.AddVector(&Testvector);
    287         Log() << Verbose(1) << "vector is: ";
     293        DoLog(1) && (Log() << Verbose(1) << "vector is: ");
    288294        Testvector.Output();
    289         Log() << Verbose(0) << endl;
     295        DoLog(0) && (Log() << Verbose(0) << endl);
    290296#ifdef ADDHYDROGEN
    291297        // now also change all hydrogens
     
    293299          if ((*Runner)->GetOtherAtom(Walker)->type->Z == 1) {
    294300            Testvector.CopyVector(&(*Runner)->GetOtherAtom(Walker)->x);
    295             Testvector.InverseMatrixMultiplication(matrix);
     301            Testvector.MatrixMultiplication(inversematrix);
    296302            Testvector.AddVector(&Translationvector);
    297303            Testvector.MatrixMultiplication(matrix);
    298304            Center.AddVector(&Testvector);
    299             Log() << Verbose(1) << "Hydrogen vector is: ";
     305            DoLog(1) && (Log() << Verbose(1) << "Hydrogen vector is: ");
    300306            Testvector.Output();
    301             Log() << Verbose(0) << endl;
     307            DoLog(0) && (Log() << Verbose(0) << endl);
    302308          }
    303309        }
     
    307313  } while (!flag);
    308314  Free(&matrix);
     315  Free(&inversematrix);
     316
    309317  Center.Scale(1./(double)AtomCount);
    310318};
     
    344352  }
    345353  // print InertiaTensor for debugging
    346   Log() << Verbose(0) << "The inertia tensor is:" << endl;
     354  DoLog(0) && (Log() << Verbose(0) << "The inertia tensor is:" << endl);
    347355  for(int i=0;i<NDIM;i++) {
    348356    for(int j=0;j<NDIM;j++)
    349       Log() << Verbose(0) << InertiaTensor[i*NDIM+j] << " ";
    350     Log() << Verbose(0) << endl;
    351   }
    352   Log() << Verbose(0) << endl;
     357      DoLog(0) && (Log() << Verbose(0) << InertiaTensor[i*NDIM+j] << " ");
     358    DoLog(0) && (Log() << Verbose(0) << endl);
     359  }
     360  DoLog(0) && (Log() << Verbose(0) << endl);
    353361
    354362  // diagonalize to determine principal axis system
     
    362370
    363371  for(int i=0;i<NDIM;i++) {
    364     Log() << Verbose(1) << "eigenvalue = " << gsl_vector_get(eval, i);
    365     Log() << Verbose(0) << ", eigenvector = (" << evec->data[i * evec->tda + 0] << "," << evec->data[i * evec->tda + 1] << "," << evec->data[i * evec->tda + 2] << ")" << endl;
     372    DoLog(1) && (Log() << Verbose(1) << "eigenvalue = " << gsl_vector_get(eval, i));
     373    DoLog(0) && (Log() << Verbose(0) << ", eigenvector = (" << evec->data[i * evec->tda + 0] << "," << evec->data[i * evec->tda + 1] << "," << evec->data[i * evec->tda + 2] << ")" << endl);
    366374  }
    367375
    368376  // check whether we rotate or not
    369377  if (DoRotate) {
    370     Log() << Verbose(1) << "Transforming molecule into PAS ... ";
     378    DoLog(1) && (Log() << Verbose(1) << "Transforming molecule into PAS ... ");
    371379    // the eigenvectors specify the transformation matrix
    372380    ActOnAllVectors( &Vector::MatrixMultiplication, (const double *) evec->data );
    373     Log() << Verbose(0) << "done." << endl;
     381    DoLog(0) && (Log() << Verbose(0) << "done." << endl);
    374382
    375383    // summing anew for debugging (resulting matrix has to be diagonal!)
     
    396404    }
    397405    // print InertiaTensor for debugging
    398     Log() << Verbose(0) << "The inertia tensor is:" << endl;
     406    DoLog(0) && (Log() << Verbose(0) << "The inertia tensor is:" << endl);
    399407    for(int i=0;i<NDIM;i++) {
    400408      for(int j=0;j<NDIM;j++)
    401         Log() << Verbose(0) << InertiaTensor[i*NDIM+j] << " ";
    402       Log() << Verbose(0) << endl;
    403     }
    404     Log() << Verbose(0) << endl;
     409        DoLog(0) && (Log() << Verbose(0) << InertiaTensor[i*NDIM+j] << " ");
     410      DoLog(0) && (Log() << Verbose(0) << endl);
     411    }
     412    DoLog(0) && (Log() << Verbose(0) << endl);
    405413  }
    406414
     
    425433
    426434  // rotate on z-x plane
    427   Log() << Verbose(0) << "Begin of Aligning all atoms." << endl;
     435  DoLog(0) && (Log() << Verbose(0) << "Begin of Aligning all atoms." << endl);
    428436  alpha = atan(-n->x[0]/n->x[2]);
    429   Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... ";
     437  DoLog(1) && (Log() << Verbose(1) << "Z-X-angle: " << alpha << " ... ");
    430438  while (ptr->next != end) {
    431439    ptr = ptr->next;
     
    443451  n->x[0] =  cos(alpha) * tmp +  sin(alpha) * n->x[2];
    444452  n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
    445   Log() << Verbose(1) << "alignment vector after first rotation: ";
     453  DoLog(1) && (Log() << Verbose(1) << "alignment vector after first rotation: ");
    446454  n->Output();
    447   Log() << Verbose(0) << endl;
     455  DoLog(0) && (Log() << Verbose(0) << endl);
    448456
    449457  // rotate on z-y plane
    450458  ptr = start;
    451459  alpha = atan(-n->x[1]/n->x[2]);
    452   Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... ";
     460  DoLog(1) && (Log() << Verbose(1) << "Z-Y-angle: " << alpha << " ... ");
    453461  while (ptr->next != end) {
    454462    ptr = ptr->next;
     
    467475  n->x[2] = -sin(alpha) * tmp +  cos(alpha) * n->x[2];
    468476
    469   Log() << Verbose(1) << "alignment vector after second rotation: ";
     477  DoLog(1) && (Log() << Verbose(1) << "alignment vector after second rotation: ");
    470478  n->Output();
    471   Log() << Verbose(1) << endl;
    472   Log() << Verbose(0) << "End of Aligning all atoms." << endl;
     479  DoLog(1) && (Log() << Verbose(1) << endl);
     480  DoLog(0) && (Log() << Verbose(0) << "End of Aligning all atoms." << endl);
    473481};
    474482
  • src/molecule_graph.cpp

    re5ad5c ree7e25  
    1717#include "memoryallocator.hpp"
    1818#include "molecule.hpp"
     19#include "World.hpp"
    1920
    2021struct BFSAccounting
     
    5859
    5960  if (!input) {
    60     Log() << Verbose(1) << "Opening silica failed \n";
     61    DoLog(1) && (Log() << Verbose(1) << "Opening silica failed \n");
    6162  };
    6263
    6364  *input >> ws >> atom1;
    6465  *input >> ws >> atom2;
    65   Log() << Verbose(1) << "Scanning file\n";
     66  DoLog(1) && (Log() << Verbose(1) << "Scanning file\n");
    6667  while (!input->eof()) // Check whether we read everything already
    6768  {
     
    106107  LinkedCell *LC = NULL;
    107108  bool free_BG = false;
     109  double * const cell_size = World::get()->cell_size;
    108110
    109111  if (BG == NULL) {
     
    113115
    114116  BondDistance = bonddistance; // * ((IsAngstroem) ? 1. : 1./AtomicLengthToAngstroem);
    115   Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl;
     117  DoLog(0) && (Log() << Verbose(0) << "Begin of CreateAdjacencyList." << endl);
    116118  // remove every bond from the list
    117119  bond *Binder = NULL;
     
    126128  // count atoms in molecule = dimension of matrix (also give each unique name and continuous numbering)
    127129  CountAtoms();
    128   Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl;
     130  DoLog(1) && (Log() << Verbose(1) << "AtomCount " << AtomCount << " and bonddistance is " << bonddistance << "." << endl);
    129131
    130132  if ((AtomCount > 1) && (bonddistance > 1.)) {
    131     Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl;
     133    DoLog(2) && (Log() << Verbose(2) << "Creating Linked Cell structure ... " << endl);
    132134    LC = new LinkedCell(this, bonddistance);
    133135
    134136    // create a list to map Tesselpoint::nr to atom *
    135     Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl;
     137    DoLog(2) && (Log() << Verbose(2) << "Creating TesselPoint to atom map ... " << endl);
    136138    AtomMap = Calloc<atom *> (AtomCount, "molecule::CreateAdjacencyList - **AtomCount");
    137139    Walker = start;
     
    142144
    143145    // 3a. go through every cell
    144     Log() << Verbose(2) << "Celling ... " << endl;
     146    DoLog(2) && (Log() << Verbose(2) << "Celling ... " << endl);
    145147    for (LC->n[0] = 0; LC->n[0] < LC->N[0]; LC->n[0]++)
    146148      for (LC->n[1] = 0; LC->n[1] < LC->N[1]; LC->n[1]++)
    147149        for (LC->n[2] = 0; LC->n[2] < LC->N[2]; LC->n[2]++) {
    148           const LinkedNodes *List = LC->GetCurrentCell();
     150          const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
    149151//          Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
    150152          if (List != NULL) {
    151             for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     153            for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    152154              Walker = AtomMap[(*Runner)->nr];
    153155//              Log() << Verbose(0) << "Current Atom is " << *Walker << "." << endl;
     
    156158                for (n[1] = -1; n[1] <= 1; n[1]++)
    157159                  for (n[2] = -1; n[2] <= 1; n[2]++) {
    158                     const LinkedNodes *OtherList = LC->GetRelativeToCurrentCell(n);
     160                    const LinkedCell::LinkedNodes *OtherList = LC->GetRelativeToCurrentCell(n);
    159161//                    Log() << Verbose(2) << "Current relative cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << " containing " << List->size() << " points." << endl;
    160162                    if (OtherList != NULL) {
    161                       for (LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
     163                      for (LinkedCell::LinkedNodes::const_iterator OtherRunner = OtherList->begin(); OtherRunner != OtherList->end(); OtherRunner++) {
    162164                        if ((*OtherRunner)->nr > Walker->nr) {
    163165                          OtherWalker = AtomMap[(*OtherRunner)->nr];
     
    187189    Free(&AtomMap);
    188190    delete (LC);
    189     Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl;
     191    DoLog(1) && (Log() << Verbose(1) << "I detected " << BondCount << " bonds in the molecule with distance " << BondDistance << "." << endl);
    190192
    191193    // correct bond degree by comparing valence and bond degree
    192     Log() << Verbose(2) << "Correcting bond degree ... " << endl;
     194    DoLog(2) && (Log() << Verbose(2) << "Correcting bond degree ... " << endl);
    193195    CorrectBondDegree();
    194196
     
    196198    ActOnAllAtoms( &atom::OutputBondOfAtom );
    197199  } else
    198     Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl;
    199   Log() << Verbose(0) << "End of CreateAdjacencyList." << endl;
     200    DoLog(1) && (Log() << Verbose(1) << "AtomCount is " << AtomCount << ", thus no bonds, no connections!." << endl);
     201  DoLog(0) && (Log() << Verbose(0) << "End of CreateAdjacencyList." << endl);
    200202  if (free_BG)
    201203    delete(BG);
     
    208210void molecule::OutputBondsList() const
    209211{
    210   Log() << Verbose(1) << endl << "From contents of bond chain list:";
     212  DoLog(1) && (Log() << Verbose(1) << endl << "From contents of bond chain list:");
    211213  bond *Binder = first;
    212214  while (Binder->next != last) {
    213215    Binder = Binder->next;
    214     Log() << Verbose(0) << *Binder << "\t" << endl;
    215   }
    216   Log() << Verbose(0) << endl;
     216    DoLog(0) && (Log() << Verbose(0) << *Binder << "\t" << endl);
     217  }
     218  DoLog(0) && (Log() << Verbose(0) << endl);
    217219}
    218220;
     
    231233
    232234  if (BondCount != 0) {
    233     Log() << Verbose(1) << "Correcting Bond degree of each bond ... " << endl;
     235    DoLog(1) && (Log() << Verbose(1) << "Correcting Bond degree of each bond ... " << endl);
    234236    do {
    235237      OldNo = No;
    236238      No = SumPerAtom( &atom::CorrectBondDegree );
    237239    } while (OldNo != No);
    238     Log() << Verbose(0) << " done." << endl;
     240    DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    239241  } else {
    240     Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl;
    241   }
    242   Log() << Verbose(0) << No << " bonds could not be corrected." << endl;
     242    DoLog(1) && (Log() << Verbose(1) << "BondCount is " << BondCount << ", no bonds between any of the " << AtomCount << " atoms." << endl);
     243  }
     244  DoLog(0) && (Log() << Verbose(0) << No << " bonds could not be corrected." << endl);
    243245
    244246  return (No);
     
    259261  bond *Binder = first;
    260262  if ((Binder->next != last) && (Binder->next->Type == Undetermined)) {
    261     Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl;
     263    DoLog(0) && (Log() << Verbose(0) << "No Depth-First-Search analysis performed so far, calling ..." << endl);
    262264    Subgraphs = DepthFirstSearchAnalysis(BackEdgeStack);
    263265    while (Subgraphs->next != NULL) {
     
    314316    Walker->GraphNr = DFS.CurrentGraphNr;
    315317    Walker->LowpointNr = DFS.CurrentGraphNr;
    316     Log() << Verbose(1) << "Setting Walker[" << Walker->Name << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl;
     318    DoLog(1) && (Log() << Verbose(1) << "Setting Walker[" << Walker->Name << "]'s number to " << Walker->GraphNr << " with Lowpoint " << Walker->LowpointNr << "." << endl);
    317319    DFS.AtomStack->Push(Walker);
    318320    DFS.CurrentGraphNr++;
     
    341343    if (Binder == NULL)
    342344      break;
    343     Log() << Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl;
     345    DoLog(2) && (Log() << Verbose(2) << "Current Unused Bond is " << *Binder << "." << endl);
    344346    // (4) Mark Binder used, ...
    345347    Binder->MarkUsed(black);
    346348    OtherAtom = Binder->GetOtherAtom(Walker);
    347     Log() << Verbose(2) << "(4) OtherAtom is " << OtherAtom->Name << "." << endl;
     349    DoLog(2) && (Log() << Verbose(2) << "(4) OtherAtom is " << OtherAtom->Name << "." << endl);
    348350    if (OtherAtom->GraphNr != -1) {
    349351      // (4a) ... if "other" atom has been visited (GraphNr != 0), set lowpoint to minimum of both, go to (3)
     
    351353      DFS.BackEdgeStack->Push(Binder);
    352354      Walker->LowpointNr = (Walker->LowpointNr < OtherAtom->GraphNr) ? Walker->LowpointNr : OtherAtom->GraphNr;
    353       Log() << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->Name << "] to " << Walker->LowpointNr << "." << endl;
     355      DoLog(3) && (Log() << Verbose(3) << "(4a) Visited: Setting Lowpoint of Walker[" << Walker->Name << "] to " << Walker->LowpointNr << "." << endl);
    354356    } else {
    355357      // (4b) ... otherwise set OtherAtom as Ancestor of Walker and Walker as OtherAtom, go to (2)
     
    357359      OtherAtom->Ancestor = Walker;
    358360      Walker = OtherAtom;
    359       Log() << Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->Name << "]'s Ancestor is now " << OtherAtom->Ancestor->Name << ", Walker is OtherAtom " << OtherAtom->Name << "." << endl;
     361      DoLog(3) && (Log() << Verbose(3) << "(4b) Not Visited: OtherAtom[" << OtherAtom->Name << "]'s Ancestor is now " << OtherAtom->Ancestor->Name << ", Walker is OtherAtom " << OtherAtom->Name << "." << endl);
    360362      break;
    361363    }
     
    379381
    380382  // (5) if Ancestor of Walker is ...
    381   Log() << Verbose(1) << "(5) Number of Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "] is " << Walker->Ancestor->GraphNr << "." << endl;
     383  DoLog(1) && (Log() << Verbose(1) << "(5) Number of Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "] is " << Walker->Ancestor->GraphNr << "." << endl);
    382384
    383385  if (Walker->Ancestor->GraphNr != DFS.Root->GraphNr) {
     
    386388      // (6a) set Ancestor's Lowpoint number to minimum of of its Ancestor and itself, go to Step(8)
    387389      Walker->Ancestor->LowpointNr = (Walker->Ancestor->LowpointNr < Walker->LowpointNr) ? Walker->Ancestor->LowpointNr : Walker->LowpointNr;
    388       Log() << Verbose(2) << "(6) Setting Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl;
     390      DoLog(2) && (Log() << Verbose(2) << "(6) Setting Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s Lowpoint to " << Walker->Ancestor->LowpointNr << "." << endl);
    389391    } else {
    390392      // (7) (Ancestor of Walker is a separating vertex, remove all from stack till Walker (including), these and Ancestor form a component
    391393      Walker->Ancestor->SeparationVertex = true;
    392       Log() << Verbose(2) << "(7) Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s is a separating vertex, creating component." << endl;
     394      DoLog(2) && (Log() << Verbose(2) << "(7) Walker[" << Walker->Name << "]'s Ancestor[" << Walker->Ancestor->Name << "]'s is a separating vertex, creating component." << endl);
    393395      mol->SetNextComponentNumber(Walker->Ancestor, DFS.ComponentNumber);
    394       Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl;
     396      DoLog(3) && (Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Ancestor's Compont is " << DFS.ComponentNumber << "." << endl);
    395397      mol->SetNextComponentNumber(Walker, DFS.ComponentNumber);
    396       Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;
     398      DoLog(3) && (Log() << Verbose(3) << "(7) Walker[" << Walker->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl);
    397399      do {
    398400        OtherAtom = DFS.AtomStack->PopLast();
    399401        LeafWalker->Leaf->AddCopyAtom(OtherAtom);
    400402        mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber);
    401         Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;
     403        DoLog(3) && (Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl);
    402404      } while (OtherAtom != Walker);
    403405      DFS.ComponentNumber++;
    404406    }
    405407    // (8) Walker becomes its Ancestor, go to (3)
    406     Log() << Verbose(2) << "(8) Walker[" << Walker->Name << "] is now its Ancestor " << Walker->Ancestor->Name << ", backstepping. " << endl;
     408    DoLog(2) && (Log() << Verbose(2) << "(8) Walker[" << Walker->Name << "] is now its Ancestor " << Walker->Ancestor->Name << ", backstepping. " << endl);
    407409    Walker = Walker->Ancestor;
    408410    DFS.BackStepping = true;
     
    428430    //DFS.AtomStack->Output(out);
    429431    mol->SetNextComponentNumber(DFS.Root, DFS.ComponentNumber);
    430     Log() << Verbose(3) << "(9) Root[" << DFS.Root->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl;
     432    DoLog(3) && (Log() << Verbose(3) << "(9) Root[" << DFS.Root->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl);
    431433    mol->SetNextComponentNumber(Walker, DFS.ComponentNumber);
    432     Log() << Verbose(3) << "(9) Walker[" << Walker->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl;
     434    DoLog(3) && (Log() << Verbose(3) << "(9) Walker[" << Walker->Name << "]'s Component is " << DFS.ComponentNumber << "." << endl);
    433435    do {
    434436      OtherAtom = DFS.AtomStack->PopLast();
    435437      LeafWalker->Leaf->AddCopyAtom(OtherAtom);
    436438      mol->SetNextComponentNumber(OtherAtom, DFS.ComponentNumber);
    437       Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl;
     439      DoLog(3) && (Log() << Verbose(3) << "(7) Other[" << OtherAtom->Name << "]'s Compont is " << DFS.ComponentNumber << "." << endl);
    438440    } while (OtherAtom != Walker);
    439441    DFS.ComponentNumber++;
     
    442444    Walker = DFS.Root;
    443445    Binder = mol->FindNextUnused(Walker);
    444     Log() << Verbose(1) << "(10) Walker is Root[" << DFS.Root->Name << "], next Unused Bond is " << Binder << "." << endl;
     446    DoLog(1) && (Log() << Verbose(1) << "(10) Walker is Root[" << DFS.Root->Name << "], next Unused Bond is " << Binder << "." << endl);
    445447    if (Binder != NULL) { // Root is separation vertex
    446       Log() << Verbose(1) << "(11) Root is a separation vertex." << endl;
     448      DoLog(1) && (Log() << Verbose(1) << "(11) Root is a separation vertex." << endl);
    447449      Walker->SeparationVertex = true;
    448450    }
     
    499501  bond *Binder = NULL;
    500502
    501   Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl;
     503  if (AtomCount == 0)
     504    return SubGraphs;
     505  DoLog(0) && (Log() << Verbose(0) << "Begin of DepthFirstSearchAnalysis" << endl);
    502506  DepthFirstSearchAnalysis_Init(DFS, this);
    503507
     
    521525
    522526        if (Binder == NULL) {
    523           Log() << Verbose(2) << "No more Unused Bonds." << endl;
     527          DoLog(2) && (Log() << Verbose(2) << "No more Unused Bonds." << endl);
    524528          break;
    525529        } else
     
    538542
    539543    // From OldGraphNr to CurrentGraphNr ranges an disconnected subgraph
    540     Log() << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl;
     544    DoLog(0) && (Log() << Verbose(0) << "Disconnected subgraph ranges from " << OldGraphNr << " to " << DFS.CurrentGraphNr << "." << endl);
    541545    LeafWalker->Leaf->Output((ofstream *)&cout);
    542     Log() << Verbose(0) << endl;
     546    DoLog(0) && (Log() << Verbose(0) << endl);
    543547
    544548    // step on to next root
     
    558562  // free all and exit
    559563  DepthFirstSearchAnalysis_Finalize(DFS);
    560   Log() << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl;
     564  DoLog(0) && (Log() << Verbose(0) << "End of DepthFirstSearchAnalysis" << endl);
    561565  return SubGraphs;
    562566}
     
    584588void molecule::OutputGraphInfoPerAtom() const
    585589{
    586   Log() << Verbose(1) << "Final graph info for each atom is:" << endl;
     590  DoLog(1) && (Log() << Verbose(1) << "Final graph info for each atom is:" << endl);
    587591  ActOnAllAtoms( &atom::OutputGraphInfo );
    588592}
     
    594598void molecule::OutputGraphInfoPerBond() const
    595599{
    596   Log() << Verbose(1) << "Final graph info for each bond is:" << endl;
     600  DoLog(1) && (Log() << Verbose(1) << "Final graph info for each bond is:" << endl);
    597601  bond *Binder = first;
    598602  while (Binder->next != last) {
    599603    Binder = Binder->next;
    600     Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <";
    601     Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.";
     604    DoLog(2) && (Log() << Verbose(2) << ((Binder->Type == TreeEdge) ? "TreeEdge " : "BackEdge ") << *Binder << ": <");
     605    DoLog(0) && (Log() << Verbose(0) << ((Binder->leftatom->SeparationVertex) ? "SP," : "") << "L" << Binder->leftatom->LowpointNr << " G" << Binder->leftatom->GraphNr << " Comp.");
    602606    Binder->leftatom->OutputComponentNumber();
    603     Log() << Verbose(0) << " ===  ";
    604     Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.";
     607    DoLog(0) && (Log() << Verbose(0) << " ===  ");
     608    DoLog(0) && (Log() << Verbose(0) << ((Binder->rightatom->SeparationVertex) ? "SP," : "") << "L" << Binder->rightatom->LowpointNr << " G" << Binder->rightatom->GraphNr << " Comp.");
    605609    Binder->rightatom->OutputComponentNumber();
    606     Log() << Verbose(0) << ">." << endl;
     610    DoLog(0) && (Log() << Verbose(0) << ">." << endl);
    607611    if (Binder->Cyclic) // cyclic ??
    608       Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl;
     612      DoLog(3) && (Log() << Verbose(3) << "Lowpoint at each side are equal: CYCLIC!" << endl);
    609613  }
    610614}
     
    680684  do { // look for Root
    681685    Walker = BFS.BFSStack->PopFirst();
    682     Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl;
     686    DoLog(2) && (Log() << Verbose(2) << "Current Walker is " << *Walker << ", we look for SP to Root " << *BFS.Root << "." << endl);
    683687    for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    684688      if ((*Runner) != BackEdge) { // only walk along DFS spanning tree (otherwise we always find SP of one being backedge Binder)
     
    687691        if (OtherAtom->type->Z != 1) {
    688692#endif
    689         Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl;
     693        DoLog(2) && (Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl);
    690694        if (BFS.ColorList[OtherAtom->nr] == white) {
    691695          BFS.TouchedStack->Push(OtherAtom);
     
    693697          BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor
    694698          BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1;
    695           Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl;
     699          DoLog(2) && (Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " lightgray, its predecessor is " << Walker->Name << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl);
    696700          //if (BFS.ShortestPathList[OtherAtom->nr] < MinimumRingSize[Walker->GetTrueFather()->nr]) { // Check for maximum distance
    697           Log() << Verbose(3) << "Putting OtherAtom into queue." << endl;
     701          DoLog(3) && (Log() << Verbose(3) << "Putting OtherAtom into queue." << endl);
    698702          BFS.BFSStack->Push(OtherAtom);
    699703          //}
    700704        } else {
    701           Log() << Verbose(3) << "Not Adding, has already been visited." << endl;
     705          DoLog(3) && (Log() << Verbose(3) << "Not Adding, has already been visited." << endl);
    702706        }
    703707        if (OtherAtom == BFS.Root)
     
    705709#ifdef ADDHYDROGEN
    706710      } else {
    707         Log() << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl;
     711        DoLog(2) && (Log() << Verbose(2) << "Skipping hydrogen atom " << *OtherAtom << "." << endl);
    708712        BFS.ColorList[OtherAtom->nr] = black;
    709713      }
    710714#endif
    711715      } else {
    712         Log() << Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl;
     716        DoLog(2) && (Log() << Verbose(2) << "Bond " << *(*Runner) << " not Visiting, is the back edge." << endl);
    713717      }
    714718    }
    715719    BFS.ColorList[Walker->nr] = black;
    716     Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
     720    DoLog(1) && (Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl);
    717721    if (OtherAtom == BFS.Root) { // if we have found the root, check whether this cycle wasn't already found beforehand
    718722      // step through predecessor list
     
    724728      }
    725729      if (OtherAtom == BackEdge->rightatom) { // if each atom in found cycle is cyclic, loop's been found before already
    726         Log() << Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl;
     730        DoLog(3) && (Log() << Verbose(3) << "This cycle was already found before, skipping and removing seeker from search." << endl);
    727731        do {
    728732          OtherAtom = BFS.TouchedStack->PopLast();
    729733          if (BFS.PredecessorList[OtherAtom->nr] == Walker) {
    730             Log() << Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl;
     734            DoLog(4) && (Log() << Verbose(4) << "Removing " << *OtherAtom << " from lists and stacks." << endl);
    731735            BFS.PredecessorList[OtherAtom->nr] = NULL;
    732736            BFS.ShortestPathList[OtherAtom->nr] = -1;
     
    762766    RingSize = 1;
    763767    BFS.Root->GetTrueFather()->IsCyclic = true;
    764     Log() << Verbose(1) << "Found ring contains: ";
     768    DoLog(1) && (Log() << Verbose(1) << "Found ring contains: ");
    765769    Walker = BFS.Root;
    766770    while (Walker != BackEdge->rightatom) {
    767       Log() << Verbose(0) << Walker->Name << " <-> ";
     771      DoLog(0) && (Log() << Verbose(0) << Walker->Name << " <-> ");
    768772      Walker = BFS.PredecessorList[Walker->nr];
    769773      Walker->GetTrueFather()->IsCyclic = true;
    770774      RingSize++;
    771775    }
    772     Log() << Verbose(0) << Walker->Name << "  with a length of " << RingSize << "." << endl << endl;
     776    DoLog(0) && (Log() << Verbose(0) << Walker->Name << "  with a length of " << RingSize << "." << endl << endl);
    773777    // walk through all and set MinimumRingSize
    774778    Walker = BFS.Root;
     
    782786      MinRingSize = RingSize;
    783787  } else {
    784     Log() << Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl;
     788    DoLog(1) && (Log() << Verbose(1) << "No ring containing " << *BFS.Root << " with length equal to or smaller than " << MinimumRingSize[Walker->GetTrueFather()->nr] << " found." << endl);
    785789  }
    786790};
     
    860864
    861865      }
    862       Log() << Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->nr] << "." << endl;
    863     }
    864     Log() << Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl;
     866      DoLog(1) && (Log() << Verbose(1) << "Minimum ring size of " << *Root << " is " << MinimumRingSize[Root->GetTrueFather()->nr] << "." << endl);
     867    }
     868    DoLog(1) && (Log() << Verbose(1) << "Minimum ring size is " << MinRingSize << ", over " << NumCycles << " cycles total." << endl);
    865869  } else
    866     Log() << Verbose(1) << "No rings were detected in the molecular structure." << endl;
     870    DoLog(1) && (Log() << Verbose(1) << "No rings were detected in the molecular structure." << endl);
    867871}
    868872;
     
    892896  //BackEdgeStack->Output(out);
    893897
    894   Log() << Verbose(1) << "Analysing cycles ... " << endl;
     898  DoLog(1) && (Log() << Verbose(1) << "Analysing cycles ... " << endl);
    895899  NumCycles = 0;
    896900  while (!BackEdgeStack->IsEmpty()) {
     
    903907    ResetBFSAccounting(Walker, BFS);
    904908
    905     Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl;
     909    DoLog(1) && (Log() << Verbose(1) << "---------------------------------------------------------------------------------------------------------" << endl);
    906910    OtherAtom = NULL;
    907911    CyclicStructureAnalysis_CyclicBFSFromRootToRoot(BackEdge, BFS);
     
    932936        break; // breaking here will not cause error!
    933937    }
    934     if (i == vertex->ListOfBonds.size())
    935       eLog() << Verbose(0) << "Error: All Component entries are already occupied!" << endl;
    936   } else
    937     eLog() << Verbose(0) << "Error: Given vertex is NULL!" << endl;
     938    if (i == vertex->ListOfBonds.size()) {
     939      DoeLog(0) && (eLog()<< Verbose(0) << "Error: All Component entries are already occupied!" << endl);
     940      performCriticalExit();
     941    }
     942  } else {
     943    DoeLog(0) && (eLog()<< Verbose(0) << "Error: Given vertex is NULL!" << endl);
     944    performCriticalExit();
     945  }
    938946}
    939947;
     
    971979void OutputAlreadyVisited(int *list)
    972980{
    973   Log() << Verbose(4) << "Already Visited Bonds:\t";
     981  DoLog(4) && (Log() << Verbose(4) << "Already Visited Bonds:\t");
    974982  for (int i = 1; i <= list[0]; i++)
    975     Log() << Verbose(0) << list[i] << "  ";
    976   Log() << Verbose(0) << endl;
     983    DoLog(0) && (Log() << Verbose(0) << list[i] << "  ");
     984  DoLog(0) && (Log() << Verbose(0) << endl);
    977985}
    978986;
     
    980988/** Storing the bond structure of a molecule to file.
    981989 * Simply stores Atom::nr and then the Atom::nr of all bond partners per line.
    982  * \param *out output stream for debugging
    983990 * \param *path path to file
     991 * \param *filename name of file
    984992 * \return true - file written successfully, false - writing failed
    985993 */
    986 bool molecule::StoreAdjacencyToFile(char *path)
     994bool molecule::StoreAdjacencyToFile(char *path, char *filename)
    987995{
    988996  ofstream AdjacencyFile;
     
    990998  bool status = true;
    991999
    992   line << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
     1000  if (path != NULL)
     1001    line << path << "/" << filename;
     1002  else
     1003    line << filename;
    9931004  AdjacencyFile.open(line.str().c_str(), ios::out);
    994   Log() << Verbose(1) << "Saving adjacency list ... ";
     1005  DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... ");
    9951006  if (AdjacencyFile != NULL) {
     1007    AdjacencyFile << "m\tn" << endl;
    9961008    ActOnAllAtoms(&atom::OutputAdjacency, &AdjacencyFile);
    9971009    AdjacencyFile.close();
    998     Log() << Verbose(1) << "done." << endl;
     1010    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    9991011  } else {
    1000     Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl;
     1012    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
     1013    status = false;
     1014  }
     1015
     1016  return status;
     1017}
     1018;
     1019
     1020/** Storing the bond structure of a molecule to file.
     1021 * Simply stores Atom::nr and then the Atom::nr of all bond partners, one per line.
     1022 * \param *path path to file
     1023 * \param *filename name of file
     1024 * \return true - file written successfully, false - writing failed
     1025 */
     1026bool molecule::StoreBondsToFile(char *path, char *filename)
     1027{
     1028  ofstream BondFile;
     1029  stringstream line;
     1030  bool status = true;
     1031
     1032  if (path != NULL)
     1033    line << path << "/" << filename;
     1034  else
     1035    line << filename;
     1036  BondFile.open(line.str().c_str(), ios::out);
     1037  DoLog(1) && (Log() << Verbose(1) << "Saving adjacency list ... ");
     1038  if (BondFile != NULL) {
     1039    BondFile << "m\tn" << endl;
     1040    ActOnAllAtoms(&atom::OutputBonds, &BondFile);
     1041    BondFile.close();
     1042    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
     1043  } else {
     1044    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    10011045    status = false;
    10021046  }
     
    10111055  filename << path << "/" << FRAGMENTPREFIX << ADJACENCYFILE;
    10121056  File.open(filename.str().c_str(), ios::out);
    1013   Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ";
     1057  DoLog(1) && (Log() << Verbose(1) << "Looking at bond structure stored in adjacency file and comparing to present one ... ");
    10141058  if (File == NULL)
    10151059    return false;
     
    10521096    //Log() << Verbose(0) << endl;
    10531097  } else {
    1054     Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl;
     1098    DoLog(0) && (Log() << Verbose(0) << "Number of bonds for Atom " << *Walker << " does not match, parsed " << CurrentBondsOfAtom << " against " << Walker->ListOfBonds.size() << "." << endl);
    10551099    status = false;
    10561100  }
     
    10751119
    10761120  if (!CheckAdjacencyFileAgainstMolecule_Init(path, File, CurrentBonds)) {
    1077     Log() << Verbose(1) << "Adjacency file not found." << endl;
     1121    DoLog(1) && (Log() << Verbose(1) << "Adjacency file not found." << endl);
    10781122    return true;
    10791123  }
     
    11011145
    11021146  if (status) { // if equal we parse the KeySetFile
    1103     Log() << Verbose(1) << "done: Equal." << endl;
     1147    DoLog(1) && (Log() << Verbose(1) << "done: Equal." << endl);
    11041148  } else
    1105     Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl;
     1149    DoLog(1) && (Log() << Verbose(1) << "done: Not equal by " << NonMatchNumber << " atoms." << endl);
    11061150  return status;
    11071151}
     
    11191163  bool status = true;
    11201164  if (ReferenceStack->IsEmpty()) {
    1121     eLog() << Verbose(0) << "ReferenceStack is empty!" << endl;
     1165    DoLog(1) && (Log() << Verbose(1) << "ReferenceStack is empty!" << endl);
    11221166    return false;
    11231167  }
     
    11341178        if (OtherAtom == ListOfLocalAtoms[(*Runner)->rightatom->nr]) { // found the bond
    11351179          LocalStack->Push((*Runner));
    1136           Log() << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl;
     1180          DoLog(3) && (Log() << Verbose(3) << "Found local edge " << *(*Runner) << "." << endl);
    11371181          break;
    11381182        }
    11391183      }
    11401184    Binder = ReferenceStack->PopFirst(); // loop the stack for next item
    1141     Log() << Verbose(3) << "Current candidate edge " << Binder << "." << endl;
     1185    DoLog(3) && (Log() << Verbose(3) << "Current candidate edge " << Binder << "." << endl);
    11421186    ReferenceStack->Push(Binder);
    11431187  } while (FirstBond != Binder);
     
    11881232  BFS.PredecessorList[OtherAtom->nr] = Walker; // Walker is the predecessor
    11891233  BFS.ShortestPathList[OtherAtom->nr] = BFS.ShortestPathList[Walker->nr] + 1;
    1190   Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " " << ((BFS.ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->Name << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl;
     1234  DoLog(2) && (Log() << Verbose(2) << "Coloring OtherAtom " << OtherAtom->Name << " " << ((BFS.ColorList[OtherAtom->nr] == white) ? "white" : "lightgray") << ", its predecessor is " << Walker->Name << " and its Shortest Path is " << BFS.ShortestPathList[OtherAtom->nr] << " egde(s) long." << endl);
    11911235  if ((((BFS.ShortestPathList[OtherAtom->nr] < BFS.BondOrder) && (Binder != Bond)))) { // Check for maximum distance
    1192     Log() << Verbose(3);
     1236    DoLog(3) && (Log() << Verbose(3));
    11931237    if (AddedAtomList[OtherAtom->nr] == NULL) { // add if it's not been so far
    11941238      AddedAtomList[OtherAtom->nr] = Mol->AddCopyAtom(OtherAtom);
    1195       Log() << Verbose(0) << "Added OtherAtom " << OtherAtom->Name;
     1239      DoLog(0) && (Log() << Verbose(0) << "Added OtherAtom " << OtherAtom->Name);
    11961240      AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder);
    1197       Log() << Verbose(0) << " and bond " << *(AddedBondList[Binder->nr]) << ", ";
     1241      DoLog(0) && (Log() << Verbose(0) << " and bond " << *(AddedBondList[Binder->nr]) << ", ");
    11981242    } else { // this code should actually never come into play (all white atoms are not yet present in BondMolecule, that's why they are white in the first place)
    1199       Log() << Verbose(0) << "Not adding OtherAtom " << OtherAtom->Name;
     1243      DoLog(0) && (Log() << Verbose(0) << "Not adding OtherAtom " << OtherAtom->Name);
    12001244      if (AddedBondList[Binder->nr] == NULL) {
    12011245        AddedBondList[Binder->nr] = Mol->CopyBond(AddedAtomList[Walker->nr], AddedAtomList[OtherAtom->nr], Binder);
    1202         Log() << Verbose(0) << ", added Bond " << *(AddedBondList[Binder->nr]);
     1246        DoLog(0) && (Log() << Verbose(0) << ", added Bond " << *(AddedBondList[Binder->nr]));
    12031247      } else
    1204         Log() << Verbose(0) << ", not added Bond ";
    1205     }
    1206     Log() << Verbose(0) << ", putting OtherAtom into queue." << endl;
     1248        DoLog(0) && (Log() << Verbose(0) << ", not added Bond ");
     1249    }
     1250    DoLog(0) && (Log() << Verbose(0) << ", putting OtherAtom into queue." << endl);
    12071251    BFS.BFSStack->Push(OtherAtom);
    12081252  } else { // out of bond order, then replace
     
    12101254      BFS.ColorList[OtherAtom->nr] = white; // unmark if it has not been queued/added, to make it available via its other bonds (cyclic)
    12111255    if (Binder == Bond)
    1212       Log() << Verbose(3) << "Not Queueing, is the Root bond";
     1256      DoLog(3) && (Log() << Verbose(3) << "Not Queueing, is the Root bond");
    12131257    else if (BFS.ShortestPathList[OtherAtom->nr] >= BFS.BondOrder)
    1214       Log() << Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder;
     1258      DoLog(3) && (Log() << Verbose(3) << "Not Queueing, is out of Bond Count of " << BFS.BondOrder);
    12151259    if (!Binder->Cyclic)
    1216       Log() << Verbose(0) << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl;
     1260      DoLog(0) && (Log() << Verbose(0) << ", is not part of a cyclic bond, saturating bond with Hydrogen." << endl);
    12171261    if (AddedBondList[Binder->nr] == NULL) {
    12181262      if ((AddedAtomList[OtherAtom->nr] != NULL)) { // .. whether we add or saturate
     
    12311275void BreadthFirstSearchAdd_VisitedNode(molecule *Mol, struct BFSAccounting &BFS, atom *&Walker, atom *&OtherAtom, bond *&Binder, bond *&Bond, atom **&AddedAtomList, bond **&AddedBondList, bool IsAngstroem)
    12321276{
    1233   Log() << Verbose(3) << "Not Adding, has already been visited." << endl;
     1277  DoLog(3) && (Log() << Verbose(3) << "Not Adding, has already been visited." << endl);
    12341278  // This has to be a cyclic bond, check whether it's present ...
    12351279  if (AddedBondList[Binder->nr] == NULL) {
     
    12771321    // followed by n+1 till top of stack.
    12781322    Walker = BFS.BFSStack->PopFirst(); // pop oldest added
    1279     Log() << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl;
     1323    DoLog(1) && (Log() << Verbose(1) << "Current Walker is: " << Walker->Name << ", and has " << Walker->ListOfBonds.size() << " bonds." << endl);
    12801324    for (BondList::const_iterator Runner = Walker->ListOfBonds.begin(); Runner != Walker->ListOfBonds.end(); (++Runner)) {
    12811325      if ((*Runner) != NULL) { // don't look at bond equal NULL
    12821326        Binder = (*Runner);
    12831327        OtherAtom = (*Runner)->GetOtherAtom(Walker);
    1284         Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl;
     1328        DoLog(2) && (Log() << Verbose(2) << "Current OtherAtom is: " << OtherAtom->Name << " for bond " << *(*Runner) << "." << endl);
    12851329        if (BFS.ColorList[OtherAtom->nr] == white) {
    12861330          BreadthFirstSearchAdd_UnvisitedNode(Mol, BFS, Walker, OtherAtom, Binder, Bond, AddedAtomList, AddedBondList, IsAngstroem);
     
    12911335    }
    12921336    BFS.ColorList[Walker->nr] = black;
    1293     Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl;
     1337    DoLog(1) && (Log() << Verbose(1) << "Coloring Walker " << Walker->Name << " black." << endl);
    12941338  }
    12951339  BreadthFirstSearchAdd_Free(BFS);
     
    13161360  // reset parent list
    13171361  ParentList = Calloc<atom*> (AtomCount, "molecule::BuildInducedSubgraph_Init: **ParentList");
    1318   Log() << Verbose(3) << "Resetting ParentList." << endl;
     1362  DoLog(3) && (Log() << Verbose(3) << "Resetting ParentList." << endl);
    13191363}
    13201364;
     
    13231367{
    13241368  // fill parent list with sons
    1325   Log() << Verbose(3) << "Filling Parent List." << endl;
     1369  DoLog(3) && (Log() << Verbose(3) << "Filling Parent List." << endl);
    13261370  atom *Walker = mol->start;
    13271371  while (Walker->next != mol->end) {
     
    13291373    ParentList[Walker->father->nr] = Walker;
    13301374    // Outputting List for debugging
    1331     Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl;
     1375    DoLog(4) && (Log() << Verbose(4) << "Son[" << Walker->father->nr << "] of " << Walker->father << " is " << ParentList[Walker->father->nr] << "." << endl);
    13321376  }
    13331377
     
    13471391  atom *OtherAtom = NULL;
    13481392  // check each entry of parent list and if ok (one-to-and-onto matching) create bonds
    1349   Log() << Verbose(3) << "Creating bonds." << endl;
     1393  DoLog(3) && (Log() << Verbose(3) << "Creating bonds." << endl);
    13501394  Walker = Father->start;
    13511395  while (Walker->next != Father->end) {
     
    13581402          OtherAtom = (*Runner)->GetOtherAtom(Walker);
    13591403          if (ParentList[OtherAtom->nr] != NULL) { // if otheratom is also a father of an atom on this molecule, create the bond
    1360             Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl;
     1404            DoLog(4) && (Log() << Verbose(4) << "Endpoints of Bond " << (*Runner) << " are both present: " << ParentList[Walker->nr]->Name << " and " << ParentList[OtherAtom->nr]->Name << "." << endl);
    13611405            mol->AddBond(ParentList[Walker->nr], ParentList[OtherAtom->nr], (*Runner)->BondDegree);
    13621406          }
     
    13831427  atom **ParentList = NULL;
    13841428
    1385   Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl;
     1429  DoLog(2) && (Log() << Verbose(2) << "Begin of BuildInducedSubgraph." << endl);
    13861430  BuildInducedSubgraph_Init(ParentList, Father->AtomCount);
    13871431  BuildInducedSubgraph_FillParentList(this, Father, ParentList);
    13881432  status = BuildInducedSubgraph_CreateBondsFromParent(this, Father, ParentList);
    13891433  BuildInducedSubgraph_Finalize(ParentList);
    1390   Log() << Verbose(2) << "End of BuildInducedSubgraph." << endl;
     1434  DoLog(2) && (Log() << Verbose(2) << "End of BuildInducedSubgraph." << endl);
    13911435  return status;
    13921436}
     
    14051449  int size;
    14061450
    1407   Log() << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl;
    1408   Log() << Verbose(2) << "Disconnected atom: ";
     1451  DoLog(1) && (Log() << Verbose(1) << "Begin of CheckForConnectedSubgraph" << endl);
     1452  DoLog(2) && (Log() << Verbose(2) << "Disconnected atom: ");
    14091453
    14101454  // count number of atoms in graph
     
    14281472      }
    14291473      if (!BondStatus) {
    1430         Log() << Verbose(0) << (*Walker) << endl;
     1474        DoLog(0) && (Log() << Verbose(0) << (*Walker) << endl);
    14311475        return false;
    14321476      }
    14331477    }
    14341478  else {
    1435     Log() << Verbose(0) << "none." << endl;
     1479    DoLog(0) && (Log() << Verbose(0) << "none." << endl);
    14361480    return true;
    14371481  }
    1438   Log() << Verbose(0) << "none." << endl;
    1439 
    1440   Log() << Verbose(1) << "End of CheckForConnectedSubgraph" << endl;
     1482  DoLog(0) && (Log() << Verbose(0) << "none." << endl);
     1483
     1484  DoLog(1) && (Log() << Verbose(1) << "End of CheckForConnectedSubgraph" << endl);
    14411485
    14421486  return true;
  • src/molecule_pointcloud.cpp

    re5ad5c ree7e25  
    1313/************************************* Functions for class molecule *********************************/
    1414
     15/** Returns a name for this point cloud, here the molecule's name.
     16 * \return name of point cloud
     17 */
     18const char * const molecule::GetName() const
     19{
     20  return name;
     21};
    1522
    1623/** Determine center of all atoms.
     
    4148{
    4249  return end;
     50};
     51
     52/** Return the greatest index of all atoms in the list.
     53 * \return greatest index
     54 */
     55int molecule::GetMaxId() const
     56{
     57  return last_atom;
    4358};
    4459
  • src/moleculelist.cpp

    re5ad5c ree7e25  
    44 *
    55 */
     6
     7#include <cstring>
    68
    79#include "atom.hpp"
     
    1719#include "memoryallocator.hpp"
    1820#include "periodentafel.hpp"
     21#include "World.hpp"
    1922
    2023/*********************************** Functions for class MoleculeListClass *************************/
     
    3336MoleculeListClass::~MoleculeListClass()
    3437{
    35   Log() << Verbose(3) << this << ": Freeing ListOfMolcules." << endl;
     38  DoLog(3) && (Log() << Verbose(3) << this << ": Freeing ListOfMolcules." << endl);
    3639  for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
    37     Log() << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl;
     40    DoLog(4) && (Log() << Verbose(4) << "ListOfMolecules: Freeing " << *ListRunner << "." << endl);
    3841    delete (*ListRunner);
    3942  }
    40   Log() << Verbose(4) << "Freeing ListOfMolecules." << endl;
     43  DoLog(4) && (Log() << Verbose(4) << "Freeing ListOfMolecules." << endl);
    4144  ListOfMolecules.clear(); // empty list
    4245};
     
    142145
    143146  // header
    144   Log() << Verbose(0) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl;
    145   Log() << Verbose(0) << "-----------------------------------------------" << endl;
     147  DoLog(0) && (Log() << Verbose(0) << "Index\tName\t\tAtoms\tFormula\tCenter\tSize" << endl);
     148  DoLog(0) && (Log() << Verbose(0) << "-----------------------------------------------" << endl);
    146149  if (ListOfMolecules.size() == 0)
    147     Log() << Verbose(0) << "\tNone" << endl;
     150    DoLog(0) && (Log() << Verbose(0) << "\tNone" << endl);
    148151  else {
    149152    Origin.Zero();
     
    162165      }
    163166      // output Index, Name, number of atoms, chemical formula
    164       Log() << Verbose(0) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t";
     167      DoLog(0) && (Log() << Verbose(0) << ((*ListRunner)->ActiveFlag ? "*" : " ") << (*ListRunner)->IndexNr << "\t" << (*ListRunner)->name << "\t\t" << (*ListRunner)->AtomCount << "\t");
    165168      Elemental = (*ListRunner)->elemente->end;
    166169      while(Elemental->previous != (*ListRunner)->elemente->start) {
    167170        Elemental = Elemental->previous;
    168171        if (Counts[Elemental->Z] != 0)
    169           Log() << Verbose(0) << Elemental->symbol << Counts[Elemental->Z];
     172          DoLog(0) && (Log() << Verbose(0) << Elemental->symbol << Counts[Elemental->Z]);
    170173      }
    171174      // Center and size
    172       Log() << Verbose(0) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl;
     175      DoLog(0) && (Log() << Verbose(0) << "\t" << (*ListRunner)->Center << "\t" << sqrt(size) << endl);
    173176    }
    174177  }
     
    311314  Tesselation *TesselStruct = NULL;
    312315  if ((srcmol == NULL) || (mol == NULL)) {
    313     Log() << Verbose(1) << "ERROR: Either fixed or variable molecule is given as NULL." << endl;
     316    DoeLog(1) && (eLog()<< Verbose(1) << "Either fixed or variable molecule is given as NULL." << endl);
    314317    return false;
    315318  }
     
    319322  FindNonConvexBorder(mol, TesselStruct, (const LinkedCell *&)LCList, 4., NULL);
    320323  if (TesselStruct == NULL) {
    321     Log() << Verbose(1) << "ERROR: Could not tesselate the fixed molecule." << endl;
     324    DoeLog(1) && (eLog()<< Verbose(1) << "Could not tesselate the fixed molecule." << endl);
    322325    return false;
    323326  }
     
    336339  while (Walker->next != srcmol->end) {
    337340    Walker = Walker->next;
    338     Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl;
     341    DoLog(2) && (Log() << Verbose(2) << "INFO: Current Walker is " << *Walker << "." << endl);
    339342    if (!TesselStruct->IsInnerPoint(Walker->x, LCList)) {
    340343      CopyAtoms[Walker->nr] = new atom(Walker);
     
    345348    }
    346349  }
    347   Log() << Verbose(1) << nr << " of " << srcmol->AtomCount << " atoms have been merged.";
     350  DoLog(1) && (Log() << Verbose(1) << nr << " of " << srcmol->AtomCount << " atoms have been merged.");
    348351
    349352  // go through all bonds and add as well
     
    351354  while(Binder->next != srcmol->last) {
    352355    Binder = Binder->next;
    353     Log() << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl;
     356    DoLog(3) && (Log() << Verbose(3) << "Adding Bond between " << *CopyAtoms[Binder->leftatom->nr] << " and " << *CopyAtoms[Binder->rightatom->nr]<< "." << endl);
    354357    mol->AddBond(CopyAtoms[Binder->leftatom->nr], CopyAtoms[Binder->rightatom->nr], Binder->BondDegree);
    355358  }
     
    363366void MoleculeListClass::Output(ofstream *out)
    364367{
    365   Log() << Verbose(1) << "MoleculeList: ";
     368  DoLog(1) && (Log() << Verbose(1) << "MoleculeList: ");
    366369  for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++)
    367     Log() << Verbose(0) << *ListRunner << "\t";
    368   Log() << Verbose(0) << endl;
     370    DoLog(0) && (Log() << Verbose(0) << *ListRunner << "\t");
     371  DoLog(0) && (Log() << Verbose(0) << endl);
    369372};
    370373
     
    392395  char *FragmentNumber = NULL;
    393396
    394   Log() << Verbose(1) << "Saving hydrogen saturation correction ... ";
     397  DoLog(1) && (Log() << Verbose(1) << "Saving hydrogen saturation correction ... ");
    395398  // 0. parse in fit constant files that should have the same dimension as the final energy files
    396399  // 0a. find dimension of matrices with constants
     
    402405  input.open(line.c_str());
    403406  if (input == NULL) {
    404     eLog() << Verbose(0) << endl << "Unable to open " << line << ", is the directory correct?"
    405         << endl;
     407    DoLog(1) && (Log() << Verbose(1) << endl << "Unable to open " << line << ", is the directory correct?" << endl);
    406408    return false;
    407409  }
     
    420422    b++;
    421423  }
    422   Log() << Verbose(0) << "I recognized " << a << " columns and " << b << " rows, ";
     424  DoLog(0) && (Log() << Verbose(0) << "I recognized " << a << " columns and " << b << " rows, ");
    423425  input.close();
    424426
     
    441443    input.open(line.c_str());
    442444    if (input == NULL) {
    443       eLog() << Verbose(0) << endl << "Unable to open " << line << ", is the directory correct?" << endl;
     445      DoeLog(0) && (eLog()<< Verbose(0) << endl << "Unable to open " << line << ", is the directory correct?" << endl);
     446      performCriticalExit();
    444447      return false;
    445448    }
     
    462465  }
    463466  for (int k = 0; k < 3; k++) {
    464     Log() << Verbose(0) << "Constants " << k << ":" << endl;
     467    DoLog(0) && (Log() << Verbose(0) << "Constants " << k << ":" << endl);
    465468    for (int j = 0; j < b; j++) {
    466469      for (int i = 0; i < a; i++) {
    467         Log() << Verbose(0) << FitConstant[k][i][j] << "\t";
     470        DoLog(0) && (Log() << Verbose(0) << FitConstant[k][i][j] << "\t");
    468471      }
    469       Log() << Verbose(0) << endl;
    470     }
    471     Log() << Verbose(0) << endl;
     472      DoLog(0) && (Log() << Verbose(0) << endl);
     473    }
     474    DoLog(0) && (Log() << Verbose(0) << endl);
    472475  }
    473476
     
    557560  }
    558561  Free(&FitConstant);
    559   Log() << Verbose(0) << "done." << endl;
     562  DoLog(0) && (Log() << Verbose(0) << "done." << endl);
    560563  return true;
    561564};
     
    577580
    578581  // open file for the force factors
    579   Log() << Verbose(1) << "Saving  force factors ... ";
     582  DoLog(1) && (Log() << Verbose(1) << "Saving  force factors ... ");
    580583  line << path << "/" << FRAGMENTPREFIX << FORCESFILE;
    581584  ForcesFile.open(line.str().c_str(), ios::out);
     
    605608    }
    606609    ForcesFile.close();
    607     Log() << Verbose(1) << "done." << endl;
     610    DoLog(1) && (Log() << Verbose(1) << "done." << endl);
    608611  } else {
    609612    status = false;
    610     Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl;
     613    DoLog(1) && (Log() << Verbose(1) << "failed to open file " << line.str() << "." << endl);
    611614  }
    612615  ForcesFile.close();
     
    636639  int FragmentCounter = 0;
    637640  ofstream output;
    638 
     641  double cell_size_backup[6];
     642  double * const cell_size = World::get()->cell_size;
     643
     644  // backup cell_size
     645  for (int i=0;i<6;i++)
     646    cell_size_backup[i] = cell_size[i];
    639647  // store the fragments as config and as xyz
    640648  for (MoleculeList::iterator ListRunner = ListOfMolecules.begin(); ListRunner != ListOfMolecules.end(); ListRunner++) {
     
    643651    if (path != NULL)
    644652      strcpy(PathBackup, path);
    645     else
    646       eLog() << Verbose(0) << "OutputConfigForListOfFragments: NULL default path obtained from config!" << endl;
     653    else {
     654      DoeLog(0) && (eLog()<< Verbose(0) << "OutputConfigForListOfFragments: NULL default path obtained from config!" << endl);
     655      performCriticalExit();
     656    }
    647657
    648658    // correct periodic
     
    653663    sprintf(FragmentName, "%s/%s%s.conf.xyz", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    654664    outputFragment.open(FragmentName, ios::out);
    655     Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as XYZ ...";
     665    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as XYZ ...");
    656666    if ((intermediateResult = (*ListRunner)->OutputXYZ(&outputFragment)))
    657       Log() << Verbose(0) << " done." << endl;
     667      DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    658668    else
    659       Log() << Verbose(0) << " failed." << endl;
     669      DoLog(0) && (Log() << Verbose(0) << " failed." << endl);
    660670    result = result && intermediateResult;
    661671    outputFragment.close();
     
    663673
    664674    // list atoms in fragment for debugging
    665     Log() << Verbose(2) << "Contained atoms: ";
     675    DoLog(2) && (Log() << Verbose(2) << "Contained atoms: ");
    666676    Walker = (*ListRunner)->start;
    667677    while (Walker->next != (*ListRunner)->end) {
    668678      Walker = Walker->next;
    669       Log() << Verbose(0) << Walker->Name << " ";
    670     }
    671     Log() << Verbose(0) << endl;
     679      DoLog(0) && (Log() << Verbose(0) << Walker->Name << " ");
     680    }
     681    DoLog(0) && (Log() << Verbose(0) << endl);
    672682
    673683    // center on edge
     
    678688      j += k + 1;
    679689      BoxDimension.x[k] = 2.5 * (configuration->GetIsAngstroem() ? 1. : 1. / AtomicLengthToAngstroem);
    680       (*ListRunner)->cell_size[j] += BoxDimension.x[k] * 2.;
     690      cell_size[j] = BoxDimension.x[k] * 2.;
    681691    }
    682692    (*ListRunner)->Translate(&BoxDimension);
     
    693703    // and save as config
    694704    sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    695     Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as config ...";
     705    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as config ...");
    696706    if ((intermediateResult = configuration->Save(FragmentName, (*ListRunner)->elemente, (*ListRunner))))
    697       Log() << Verbose(0) << " done." << endl;
     707      DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    698708    else
    699       Log() << Verbose(0) << " failed." << endl;
     709      DoLog(0) && (Log() << Verbose(0) << " failed." << endl);
    700710    result = result && intermediateResult;
    701711
     
    705715    // and save as mpqc input file
    706716    sprintf(FragmentName, "%s/%s%s.conf", configuration->configpath, FRAGMENTPREFIX, FragmentNumber);
    707     Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as mpqc input ...";
     717    DoLog(2) && (Log() << Verbose(2) << "Saving bond fragment No. " << FragmentNumber << "/" << FragmentCounter - 1 << " as mpqc input ...");
    708718    if ((intermediateResult = configuration->SaveMPQC(FragmentName, (*ListRunner))))
    709       Log() << Verbose(2) << " done." << endl;
     719      DoLog(2) && (Log() << Verbose(2) << " done." << endl);
    710720    else
    711       Log() << Verbose(0) << " failed." << endl;
     721      DoLog(0) && (Log() << Verbose(0) << " failed." << endl);
    712722
    713723    result = result && intermediateResult;
     
    716726    Free(&FragmentNumber);
    717727  }
    718   Log() << Verbose(0) << " done." << endl;
     728  DoLog(0) && (Log() << Verbose(0) << " done." << endl);
    719729
    720730  // printing final number
    721   Log() << Verbose(2) << "Final number of fragments: " << FragmentCounter << "." << endl;
     731  DoLog(2) && (Log() << Verbose(2) << "Final number of fragments: " << FragmentCounter << "." << endl);
     732
     733  // restore cell_size
     734  for (int i=0;i<6;i++)
     735    cell_size[i] = cell_size_backup[i];
    722736
    723737  return result;
     
    737751/** Dissects given \a *mol into connected subgraphs and inserts them as new molecules but with old atoms into \a this.
    738752 * \param *out output stream for debugging
    739  * \param *mol molecule with atoms to dissect
     753 * \param *periode periodentafel
    740754 * \param *configuration config with BondGraph
    741755 */
    742 void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(molecule * const mol, config * const configuration)
    743 {
     756void MoleculeListClass::DissectMoleculeIntoConnectedSubgraphs(const periodentafel * const periode, config * const configuration)
     757{
     758  molecule *mol = new molecule(periode);
     759  atom *Walker = NULL;
     760  atom *Advancer = NULL;
     761  bond *Binder = NULL;
     762  bond *Stepper = NULL;
     763  // 0. gather all atoms into single molecule
     764  for (MoleculeList::iterator MolRunner = ListOfMolecules.begin(); !ListOfMolecules.empty(); MolRunner = ListOfMolecules.begin()) {
     765    // shift all atoms to new molecule
     766    Advancer = (*MolRunner)->start->next;
     767    while (Advancer != (*MolRunner)->end) {
     768      Walker = Advancer;
     769      Advancer = Advancer->next;
     770      DoLog(3) && (Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl);
     771      unlink(Walker);
     772      Walker->father = Walker;
     773      mol->AddAtom(Walker);    // counting starts at 1
     774    }
     775    // remove all bonds
     776    Stepper = (*MolRunner)->first->next;
     777    while (Stepper != (*MolRunner)->last) {
     778      Binder = Stepper;
     779      Stepper = Stepper->next;
     780      delete(Binder);
     781    }
     782    // remove the molecule
     783    delete(*MolRunner);
     784    ListOfMolecules.erase(MolRunner);
     785  }
     786
    744787  // 1. dissect the molecule into connected subgraphs
    745   configuration ->BG->ConstructBondGraph(mol);
     788  if (!configuration->BG->ConstructBondGraph(mol)) {
     789    delete (mol);
     790    DoeLog(1) && (eLog()<< Verbose(1) << "There are no bonds." << endl);
     791    return;
     792  }
    746793
    747794  // 2. scan for connected subgraphs
     
    750797  Subgraphs = mol->DepthFirstSearchAnalysis(BackEdgeStack);
    751798  delete(BackEdgeStack);
     799  if ((Subgraphs == NULL) || (Subgraphs->next == NULL)) {
     800    delete (mol);
     801    DoeLog(1) && (eLog()<< Verbose(1) << "There are no atoms." << endl);
     802    return;
     803  }
    752804
    753805  // 3. dissect (the following construct is needed to have the atoms not in the order of the DFS, but in
     
    757809  // 4a. create array of molecules to fill
    758810  const int MolCount = Subgraphs->next->Count();
     811  char number[MAXSTRINGSIZE];
    759812  molecule **molecules = Malloc<molecule *>(MolCount, "config::Load() - **molecules");
    760813  for (int i=0;i<MolCount;i++) {
    761814    molecules[i] = (molecule*) new molecule(mol->elemente);
    762815    molecules[i]->ActiveFlag = true;
     816    strncpy(molecules[i]->name, mol->name, MAXSTRINGSIZE);
     817    if (MolCount > 1) {
     818      sprintf(number, "-%d", i+1);
     819      strncat(molecules[i]->name, number, MAXSTRINGSIZE - strlen(mol->name) - 1);
     820    }
     821    DoLog(1) && (Log() << Verbose(1) << "MolName is " << molecules[i]->name << endl);
    763822    insert(molecules[i]);
    764823  }
     
    768827  int *MolMap = Calloc<int>(mol->AtomCount, "config::Load() - *MolMap");
    769828  MoleculeLeafClass *MolecularWalker = Subgraphs;
    770   atom *Walker = NULL;
     829  Walker = NULL;
    771830  while (MolecularWalker->next != NULL) {
    772831    MolecularWalker = MolecularWalker->next;
     
    780839
    781840  // 4c. relocate atoms to new molecules and remove from Leafs
    782   Walker = mol->start;
     841  Walker = NULL;
    783842  while (mol->start->next != mol->end) {
    784843    Walker = mol->start->next;
    785844    if ((Walker->nr <0) || (Walker->nr >= mol->AtomCount)) {
    786       eLog() << Verbose(0) << "Index of atom " << *Walker << " is invalid!" << endl;
     845      DoeLog(0) && (eLog()<< Verbose(0) << "Index of atom " << *Walker << " is invalid!" << endl);
    787846      performCriticalExit();
    788847    }
    789848    FragmentCounter = MolMap[Walker->nr];
    790849    if (FragmentCounter != 0) {
    791       Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl;
     850      DoLog(3) && (Log() << Verbose(3) << "Re-linking " << *Walker << "..." << endl);
    792851      unlink(Walker);
    793852      molecules[FragmentCounter-1]->AddAtom(Walker);    // counting starts at 1
    794853    } else {
    795       eLog() << Verbose(0) << "Atom " << *Walker << " not associated to molecule!" << endl;
     854      DoeLog(0) && (eLog()<< Verbose(0) << "Atom " << *Walker << " not associated to molecule!" << endl);
    796855      performCriticalExit();
    797856    }
    798857  }
    799   // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintained their ListOfBonds
     858  // 4d. we don't need to redo bonds, as they are connected subgraphs and still maintain their ListOfBonds, but we have to remove them from first..last list
     859  Binder = mol->first;
     860  while (mol->first->next != mol->last) {
     861    Binder = mol->first->next;
     862    Walker = Binder->leftatom;
     863    unlink(Binder);
     864    link(Binder,molecules[MolMap[Walker->nr]-1]->last);   // counting starts at 1
     865  }
    800866  // 4e. free Leafs
    801867  MolecularWalker = Subgraphs;
     
    807873  Free(&MolMap);
    808874  Free(&molecules);
    809   Log() << Verbose(1) << "I scanned " << FragmentCounter << " molecules." << endl;
    810 };
     875  DoLog(1) && (Log() << Verbose(1) << "I scanned " << FragmentCounter << " molecules." << endl);
     876};
     877
     878/** Count all atoms in each molecule.
     879 * \return number of atoms in the MoleculeListClass.
     880 * TODO: the inner loop should be done by some (double molecule::CountAtom()) function
     881 */
     882int MoleculeListClass::CountAllAtoms() const
     883{
     884  atom *Walker = NULL;
     885  int AtomNo = 0;
     886  for (MoleculeList::const_iterator MolWalker = ListOfMolecules.begin(); MolWalker != ListOfMolecules.end(); MolWalker++) {
     887    Walker = (*MolWalker)->start;
     888    while (Walker->next != (*MolWalker)->end) {
     889      Walker = Walker->next;
     890      AtomNo++;
     891    }
     892  }
     893  return AtomNo;
     894}
     895
    811896
    812897/******************************************* Class MoleculeLeafClass ************************************************/
     
    897982  int AtomNo;
    898983
    899   Log() << Verbose(1) << "Begin of FillBondStructureFromReference." << endl;
     984  DoLog(1) && (Log() << Verbose(1) << "Begin of FillBondStructureFromReference." << endl);
    900985  // fill ListOfLocalAtoms if NULL was given
    901986  if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) {
    902     Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl;
     987    DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl);
    903988    return false;
    904989  }
    905990
    906991  if (status) {
    907     Log() << Verbose(1) << "Creating adjacency list for subgraph " << Leaf << "." << endl;
     992    DoLog(1) && (Log() << Verbose(1) << "Creating adjacency list for subgraph " << Leaf << "." << endl);
    908993    // remove every bond from the list
    909994    bond *Binder = NULL;
     
    9261011            Leaf->AddBond(Walker, OtherWalker, (*Runner)->BondDegree);
    9271012        } else {
    928           Log() << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << (*Runner)->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl;
     1013          DoLog(1) && (Log() << Verbose(1) << "OtherWalker = ListOfLocalAtoms[" << FragmentCounter << "][" << (*Runner)->GetOtherAtom(Walker->GetTrueFather())->nr << "] is NULL!" << endl);
    9291014          status = false;
    9301015        }
     
    9391024      Free(&ListOfLocalAtoms);
    9401025  }
    941   Log() << Verbose(1) << "End of FillBondStructureFromReference." << endl;
     1026  DoLog(1) && (Log() << Verbose(1) << "End of FillBondStructureFromReference." << endl);
    9421027  return status;
    9431028};
     
    9721057        next->FillRootStackForSubgraphs(RootStack, AtomMask, ++FragmentCounter);
    9731058    } else {
    974       Log() << Verbose(1) << "Rootstack[" << FragmentCounter << "] is NULL." << endl;
     1059      DoLog(1) && (Log() << Verbose(1) << "Rootstack[" << FragmentCounter << "] is NULL." << endl);
    9751060      return false;
    9761061    }
     
    9781063    return true;
    9791064  } else {
    980     Log() << Verbose(1) << "Rootstack is NULL." << endl;
     1065    DoLog(1) && (Log() << Verbose(1) << "Rootstack is NULL." << endl);
    9811066    return false;
    9821067  }
     
    10281113  int KeySetCounter = 0;
    10291114
    1030   Log() << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl;
     1115  DoLog(1) && (Log() << Verbose(1) << "Begin of AssignKeySetsToFragment." << endl);
    10311116  // fill ListOfLocalAtoms if NULL was given
    10321117  if (!FillListOfLocalAtoms(ListOfLocalAtoms, FragmentCounter, reference->AtomCount, FreeList)) {
    1033     Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl;
     1118    DoLog(1) && (Log() << Verbose(1) << "Filling of ListOfLocalAtoms failed." << endl);
    10341119    return false;
    10351120  }
     
    10591144    delete (TempSet);
    10601145    if (KeySetCounter == 0) {// if there are no keysets, delete the list
    1061       Log() << Verbose(1) << "KeySetCounter is zero, deleting FragmentList." << endl;
     1146      DoLog(1) && (Log() << Verbose(1) << "KeySetCounter is zero, deleting FragmentList." << endl);
    10621147      delete (FragmentList[FragmentCounter]);
    10631148    } else
    1064       Log() << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl;
     1149      DoLog(1) && (Log() << Verbose(1) << KeySetCounter << " keysets were assigned to subgraph " << FragmentCounter << "." << endl);
    10651150    FragmentCounter++;
    10661151    if (next != NULL)
     
    10681153    FragmentCounter--;
    10691154  } else
    1070     Log() << Verbose(1) << "KeySetList is NULL or empty." << endl;
     1155    DoLog(1) && (Log() << Verbose(1) << "KeySetList is NULL or empty." << endl);
    10711156
    10721157  if ((FreeList) && (ListOfLocalAtoms != NULL)) {
     
    10761161      Free(&ListOfLocalAtoms);
    10771162  }
    1078   Log() << Verbose(1) << "End of AssignKeySetsToFragment." << endl;
     1163  DoLog(1) && (Log() << Verbose(1) << "End of AssignKeySetsToFragment." << endl);
    10791164  return status;
    10801165};
     
    10891174void MoleculeLeafClass::TranslateIndicesToGlobalIDs(Graph **FragmentList, int &FragmentCounter, int &TotalNumberOfKeySets, Graph &TotalGraph)
    10901175{
    1091   Log() << Verbose(1) << "Begin of TranslateIndicesToGlobalIDs." << endl;
     1176  DoLog(1) && (Log() << Verbose(1) << "Begin of TranslateIndicesToGlobalIDs." << endl);
    10921177  KeySet *TempSet = new KeySet;
    10931178  if (FragmentList[FragmentCounter] != NULL) {
     
    11001185    delete (TempSet);
    11011186  } else {
    1102     Log() << Verbose(1) << "FragmentList is NULL." << endl;
     1187    DoLog(1) && (Log() << Verbose(1) << "FragmentList is NULL." << endl);
    11031188  }
    11041189  if (next != NULL)
    11051190    next->TranslateIndicesToGlobalIDs(FragmentList, ++FragmentCounter, TotalNumberOfKeySets, TotalGraph);
    11061191  FragmentCounter--;
    1107   Log() << Verbose(1) << "End of TranslateIndicesToGlobalIDs." << endl;
     1192  DoLog(1) && (Log() << Verbose(1) << "End of TranslateIndicesToGlobalIDs." << endl);
    11081193};
    11091194
  • src/parser.cpp

    re5ad5c ree7e25  
    77// ======================================= INCLUDES ==========================================
    88
     9#include <cstring>
     10
    911#include "helpers.hpp"
    1012#include "memoryallocator.hpp"
     
    3032  if (input == NULL) {
    3133    if (!test)
    32       Log() << Verbose(0) << endl << "Unable to open " << filename << ", is the directory correct?" << endl;
     34      DoLog(0) && (Log() << Verbose(0) << endl << "Unable to open " << filename << ", is the directory correct?" << endl);
    3335    return false;
    3436  }
     
    107109bool MatrixContainer::InitialiseIndices(class MatrixContainer *Matrix)
    108110{
    109   Log() << Verbose(0) << "Initialising indices";
     111  DoLog(0) && (Log() << Verbose(0) << "Initialising indices");
    110112  if (Matrix == NULL) {
    111     Log() << Verbose(0) << " with trivial mapping." << endl;
     113    DoLog(0) && (Log() << Verbose(0) << " with trivial mapping." << endl);
    112114    Indices = Malloc<int*>(MatrixCounter + 1, "MatrixContainer::InitialiseIndices: **Indices");
    113115    for(int i=MatrixCounter+1;i--;) {
     
    117119    }
    118120  } else {
    119     Log() << Verbose(0) << " from other MatrixContainer." << endl;
     121    DoLog(0) && (Log() << Verbose(0) << " from other MatrixContainer." << endl);
    120122    if (MatrixCounter != Matrix->MatrixCounter)
    121123      return false;
     
    156158
    157159  input.open(name, ios::in);
    158   //Log() << Verbose(0) << "Opening " << name << " ... "  << input << endl;
     160  //Log() << Verbose(1) << "Opening " << name << " ... "  << input << endl;
    159161  if (input == NULL) {
    160     eLog() << Verbose(0) << endl << "Unable to open " << name << ", is the directory correct?" << endl;
     162    DoeLog(1) && (eLog()<< Verbose(1) << endl << "Unable to open " << name << ", is the directory correct?" << endl);
     163    //performCriticalExit();
    161164    return false;
    162165  }
     
    178181  }
    179182  //Log() << Verbose(0) << line.str() << endl;
    180   //Log() << Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl;
    181   if (ColumnCounter[MatrixNr] == 0)
    182     eLog() << Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl;
     183  //Log() << Verbose(1) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << "." << endl;
     184  if (ColumnCounter[MatrixNr] == 0) {
     185    DoeLog(0) && (eLog()<< Verbose(0) << "ColumnCounter[" << MatrixNr << "]: " << ColumnCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl);
     186    performCriticalExit();
     187  }
    183188 
    184189  // scan rest for number of rows/lines
     
    192197    }
    193198  }
    194   //Log() << Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;
    195   if (RowCounter[MatrixNr] == 0)
    196     eLog() << Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl;
     199  //Log() << Verbose(1) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << "." << endl;
     200  if (RowCounter[MatrixNr] == 0) {
     201    DoeLog(0) && (eLog()<< Verbose(0) << "RowCounter[" << MatrixNr << "]: " << RowCounter[MatrixNr] << " from file " << name << ", this is probably an error!" << endl);
     202    performCriticalExit();
     203  }
    197204
    198205  // allocate matrix if it's not zero dimension in one direction
     
    213220      input.getline(filename, 1023);
    214221      stringstream lines(filename);
    215       //Log() << Verbose(0) << "Matrix at level " << j << ":";// << filename << endl;
     222      //Log() << Verbose(2) << "Matrix at level " << j << ":";// << filename << endl;
    216223      for(int k=skipcolumns;k--;)
    217224        lines >> filename;
    218225      for(int k=0;(k<ColumnCounter[MatrixNr]) && (!lines.eof());k++) {
    219226        lines >> Matrix[MatrixNr][j][k];
    220         //Log() << Verbose(0) << " " << setprecision(2) << Matrix[MatrixNr][j][k];;
     227        //Log() << Verbose(1) << " " << setprecision(2) << Matrix[MatrixNr][j][k] << endl;
    221228      }
    222       //Log() << Verbose(0) << endl;
    223229      Matrix[MatrixNr][ RowCounter[MatrixNr] ] = Malloc<double>(ColumnCounter[MatrixNr], "MatrixContainer::ParseMatrix: *Matrix[RowCounter[MatrixNr]][]");
    224230      for(int j=ColumnCounter[MatrixNr];j--;)
     
    226232    }
    227233  } else {
    228     eLog() << Verbose(0) << "ERROR: Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl;
     234    DoeLog(1) && (eLog()<< Verbose(1) << "Matrix nr. " << MatrixNr << " has column and row count of (" << ColumnCounter[MatrixNr] << "," << RowCounter[MatrixNr] << "), could not allocate nor parse!" << endl);
    229235  }
    230236  input.close();
     
    263269  input.open(file.str().c_str(), ios::in);
    264270  if (input == NULL) {
    265     Log() << Verbose(0) << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
     271    DoLog(0) && (Log() << Verbose(0) << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl);
    266272    return false;
    267273  }
     
    272278  }
    273279  input.close();
    274   Log() << Verbose(0) << "Determined " << MatrixCounter << " fragments." << endl;
    275 
    276   Log() << Verbose(0) << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl;
     280  DoLog(0) && (Log() << Verbose(0) << "Determined " << MatrixCounter << " fragments." << endl);
     281
     282  DoLog(0) && (Log() << Verbose(0) << "Parsing through each fragment and retrieving " << prefix << suffix << "." << endl);
    277283  Header = ReAlloc<char*>(Header, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: **Header"); // one more each for the total molecule
    278284  Matrix = ReAlloc<double**>(Matrix, MatrixCounter + 1, "MatrixContainer::ParseFragmentMatrix: ***Matrix"); // one more each for the total molecule
     
    427433              //Log() << Verbose(0) << "Corresponding index in CurrentFragment is " << m << "." << endl;
    428434              if (m > RowCounter[ KeySets.OrderSet[Order][CurrentFragment] ]) {
    429                 eLog() << Verbose(0) << "In fragment No. " << KeySets.OrderSet[Order][CurrentFragment]   << " current force index " << m << " is greater than " << RowCounter[ KeySets.OrderSet[Order][CurrentFragment] ] << "!" << endl;
     435                DoeLog(0) && (eLog()<< Verbose(0) << "In fragment No. " << KeySets.OrderSet[Order][CurrentFragment]   << " current force index " << m << " is greater than " << RowCounter[ KeySets.OrderSet[Order][CurrentFragment] ] << "!" << endl);
     436                performCriticalExit();
    430437                return false;
    431438              }
     
    462469  char *FragmentNumber = NULL;
    463470
    464   Log() << Verbose(0) << "Writing fragment files." << endl;
     471  DoLog(0) && (Log() << Verbose(0) << "Writing fragment files." << endl);
    465472  for(int i=0;i<MatrixCounter;i++) {
    466473    stringstream line;
     
    470477    output.open(line.str().c_str(), ios::out);
    471478    if (output == NULL) {
    472       eLog() << Verbose(0) << "Unable to open output energy file " << line.str() << "!" << endl;
     479      DoeLog(0) && (eLog()<< Verbose(0) << "Unable to open output energy file " << line.str() << "!" << endl);
     480      performCriticalExit();
    473481      return false;
    474482    }
     
    495503  stringstream line;
    496504
    497   Log() << Verbose(0) << "Writing matrix values of " << suffix << "." << endl;
     505  DoLog(0) && (Log() << Verbose(0) << "Writing matrix values of " << suffix << "." << endl);
    498506  line << name << prefix << suffix;
    499507  output.open(line.str().c_str(), ios::out);
    500508  if (output == NULL) {
    501     eLog() << Verbose(0) << "Unable to open output matrix file " << line.str() << "!" << endl;
     509    DoeLog(0) && (eLog()<< Verbose(0) << "Unable to open output matrix file " << line.str() << "!" << endl);
     510    performCriticalExit();
    502511    return false;
    503512  }
     
    520529bool EnergyMatrix::ParseIndices()
    521530{
    522   Log() << Verbose(0) << "Parsing energy indices." << endl;
     531  DoLog(0) && (Log() << Verbose(0) << "Parsing energy indices." << endl);
    523532  Indices = Malloc<int*>(MatrixCounter + 1, "EnergyMatrix::ParseIndices: **Indices");
    524533  for(int i=MatrixCounter+1;i--;) {
     
    579588    }
    580589    // allocate last plus one matrix
    581     Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
     590    DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    582591    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
    583592    for(int j=0;j<=RowCounter[MatrixCounter];j++)
     
    606615  stringstream line;
    607616
    608   Log() << Verbose(0) << "Parsing force indices for " << MatrixCounter << " matrices." << endl;
     617  DoLog(0) && (Log() << Verbose(0) << "Parsing force indices for " << MatrixCounter << " matrices." << endl);
    609618  Indices = Malloc<int*>(MatrixCounter + 1, "ForceMatrix::ParseIndices: **Indices");
    610619  line << name << FRAGMENTPREFIX << FORCESFILE;
     
    612621  //Log() << Verbose(0) << "Opening " << line.str() << " ... "  << input << endl;
    613622  if (input == NULL) {
    614     Log() << Verbose(0) << endl << "Unable to open " << line.str() << ", is the directory correct?" << endl;
     623    DoLog(0) && (Log() << Verbose(0) << endl << "Unable to open " << line.str() << ", is the directory correct?" << endl);
    615624    return false;
    616625  }
     
    655664      int j = Indices[ FragmentNr ][l];
    656665      if (j > RowCounter[MatrixCounter]) {
    657         eLog() << Verbose(0) << "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!" << endl;
     666        DoeLog(0) && (eLog()<< Verbose(0) << "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!" << endl);
     667        performCriticalExit();
    658668        return false;
    659669      }
     
    690700    input.open(file.str().c_str(), ios::in);
    691701    if (input == NULL) {
    692       Log() << Verbose(0) << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
     702      DoLog(0) && (Log() << Verbose(0) << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl);
    693703      return false;
    694704    }
     
    714724 
    715725    // allocate last plus one matrix
    716     Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
     726    DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    717727    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
    718728    for(int j=0;j<=RowCounter[MatrixCounter];j++)
     
    743753  stringstream line;
    744754 
    745   Log() << Verbose(0) << "Parsing hessian indices for " << MatrixCounter << " matrices." << endl;
     755  DoLog(0) && (Log() << Verbose(0) << "Parsing hessian indices for " << MatrixCounter << " matrices." << endl);
    746756  Indices = Malloc<int*>(MatrixCounter + 1, "HessianMatrix::ParseIndices: **Indices");
    747757  line << name << FRAGMENTPREFIX << FORCESFILE;
     
    749759  //Log() << Verbose(0) << "Opening " << line.str() << " ... "  << input << endl;
    750760  if (input == NULL) {
    751     Log() << Verbose(0) << endl << "Unable to open " << line.str() << ", is the directory correct?" << endl;
     761    DoLog(0) && (Log() << Verbose(0) << endl << "Unable to open " << line.str() << ", is the directory correct?" << endl);
    752762    return false;
    753763  }
     
    792802      int j = Indices[ FragmentNr ][l];
    793803      if (j > RowCounter[MatrixCounter]) {
    794         eLog() << Verbose(0) << "Current hessian index " << j << " is greater than " << RowCounter[MatrixCounter] << ", where i=" << i << ", Order=" << Order << ", l=" << l << " and FragmentNr=" << FragmentNr << "!" << endl;
     804        DoeLog(0) && (eLog()<< Verbose(0) << "Current hessian index " << j << " is greater than " << RowCounter[MatrixCounter] << ", where i=" << i << ", Order=" << Order << ", l=" << l << " and FragmentNr=" << FragmentNr << "!" << endl);
     805        performCriticalExit();
    795806        return false;
    796807      }
     
    799810          int k = Indices[ FragmentNr ][m];
    800811          if (k > ColumnCounter[MatrixCounter]) {
    801             eLog() << Verbose(0) << "Current hessian index " << k << " is greater than " << ColumnCounter[MatrixCounter] << ", where m=" << m << ", j=" << j << ", i=" << i << ", Order=" << Order << ", l=" << l << " and FragmentNr=" << FragmentNr << "!" << endl;
     812            DoeLog(0) && (eLog()<< Verbose(0) << "Current hessian index " << k << " is greater than " << ColumnCounter[MatrixCounter] << ", where m=" << m << ", j=" << j << ", i=" << i << ", Order=" << Order << ", l=" << l << " and FragmentNr=" << FragmentNr << "!" << endl);
     813            performCriticalExit();
    802814            return false;
    803815          }
     
    851863              //Log() << Verbose(0) << "Corresponding row index for " << k << " in CurrentFragment is " << m << "." << endl;
    852864              if (m > RowCounter[ KeySets.OrderSet[Order][CurrentFragment] ]) {
    853                 eLog() << Verbose(0) << "In fragment No. " << KeySets.OrderSet[Order][CurrentFragment]   << " current row index " << m << " is greater than " << RowCounter[ KeySets.OrderSet[Order][CurrentFragment] ] << "!" << endl;
     865                DoeLog(0) && (eLog()<< Verbose(0) << "In fragment No. " << KeySets.OrderSet[Order][CurrentFragment]   << " current row index " << m << " is greater than " << RowCounter[ KeySets.OrderSet[Order][CurrentFragment] ] << "!" << endl);
     866                performCriticalExit();
    854867                return false;
    855868              }
     
    868881                  //Log() << Verbose(0) << "Corresponding column index for " << l << " in CurrentFragment is " << n << "." << endl;
    869882                  if (n > ColumnCounter[ KeySets.OrderSet[Order][CurrentFragment] ]) {
    870                     eLog() << Verbose(0) << "In fragment No. " << KeySets.OrderSet[Order][CurrentFragment]   << " current column index " << n << " is greater than " << ColumnCounter[ KeySets.OrderSet[Order][CurrentFragment] ] << "!" << endl;
     883                    DoeLog(0) && (eLog()<< Verbose(0) << "In fragment No. " << KeySets.OrderSet[Order][CurrentFragment]   << " current column index " << n << " is greater than " << ColumnCounter[ KeySets.OrderSet[Order][CurrentFragment] ] << "!" << endl);
     884                    performCriticalExit();
    871885                    return false;
    872886                  }
     
    916930    input.open(file.str().c_str(), ios::in);
    917931    if (input == NULL) {
    918       Log() << Verbose(0) << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
     932      DoLog(0) && (Log() << Verbose(0) << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl);
    919933      return false;
    920934    }
     
    938952 
    939953    // allocate last plus one matrix
    940     Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl;
     954    DoLog(0) && (Log() << Verbose(0) << "Allocating last plus one matrix with " << (RowCounter[MatrixCounter]+1) << " rows and " << ColumnCounter[MatrixCounter] << " columns." << endl);
    941955    Matrix[MatrixCounter] = Malloc<double*>(RowCounter[MatrixCounter] + 1, "MatrixContainer::ParseFragmentMatrix: **Matrix[]");
    942956    for(int j=0;j<=RowCounter[MatrixCounter];j++)
     
    9931007
    9941008  FragmentCounter = FCounter;
    995   Log() << Verbose(0) << "Parsing key sets." << endl;
     1009  DoLog(0) && (Log() << Verbose(0) << "Parsing key sets." << endl);
    9961010  KeySets = Malloc<int*>(FragmentCounter, "KeySetsContainer::ParseKeySets: **KeySets");
    9971011  for(int i=FragmentCounter;i--;)
     
    10001014  input.open(file.str().c_str(), ios::in);
    10011015  if (input == NULL) {
    1002     Log() << Verbose(0) << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl;
     1016    DoLog(0) && (Log() << Verbose(0) << endl << "Unable to open " << file.str() << ", is the directory correct?" << endl);
    10031017    return false;
    10041018  }
     
    10341048  int Counter;
    10351049
    1036   Log() << Verbose(0) << "Creating Fragment terms." << endl;
     1050  DoLog(0) && (Log() << Verbose(0) << "Creating Fragment terms." << endl);
    10371051  // scan through all to determine maximum order
    10381052  Order=0;
     
    10451059      Order = Counter;
    10461060  }
    1047   Log() << Verbose(0) << "Found Order is " << Order << "." << endl;
     1061  DoLog(0) && (Log() << Verbose(0) << "Found Order is " << Order << "." << endl);
    10481062
    10491063  // scan through all to determine fragments per order
     
    10591073  }
    10601074  for(int i=0;i<Order;i++)
    1061     Log() << Verbose(0) << "Found No. of Fragments of Order " << i+1 << " is " << FragmentsPerOrder[i] << "." << endl;
     1075    DoLog(0) && (Log() << Verbose(0) << "Found No. of Fragments of Order " << i+1 << " is " << FragmentsPerOrder[i] << "." << endl);
    10621076
    10631077  // scan through all to gather indices to each order set
     
    10751089    FragmentsPerOrder[Counter-1]++;
    10761090  }
    1077   Log() << Verbose(0) << "Printing OrderSet." << endl;
     1091  DoLog(0) && (Log() << Verbose(0) << "Printing OrderSet." << endl);
    10781092  for(int i=0;i<Order;i++) {
    10791093    for (int j=0;j<FragmentsPerOrder[i];j++) {
    1080       Log() << Verbose(0) << " " << OrderSet[i][j];
    1081     }
    1082     Log() << Verbose(0) << endl;
    1083   }
    1084   Log() << Verbose(0) << endl;
     1094      DoLog(0) && (Log() << Verbose(0) << " " << OrderSet[i][j]);
     1095    }
     1096    DoLog(0) && (Log() << Verbose(0) << endl);
     1097  }
     1098  DoLog(0) && (Log() << Verbose(0) << endl);
    10851099
    10861100
  • src/periodentafel.cpp

    re5ad5c ree7e25  
    99#include <iomanip>
    1010#include <fstream>
     11#include <cstring>
    1112
    1213#include "element.hpp"
     
    4849  pointer->sort = &pointer->Z;
    4950  if (pointer->Z < 1 && pointer->Z >= MAX_ELEMENTS)
    50     Log() << Verbose(0) << "Invalid Z number!\n";
     51    DoLog(0) && (Log() << Verbose(0) << "Invalid Z number!\n");
    5152  return add(pointer, end);
    5253};
     
    103104  int Z;
    104105  do {
    105     Log() << Verbose(0) << "Atomic number Z: ";
     106    DoLog(0) && (Log() << Verbose(0) << "Atomic number Z: ");
    106107    cin >> Z;
    107108    walker = this->FindElement(Z);  // give type
     
    117118  element *walker = NULL;
    118119  int Z = -1;
    119   Log() << Verbose(0) << "Atomic number: " << Z << endl;
     120  DoLog(0) && (Log() << Verbose(0) << "Atomic number: " << Z << endl);
    120121  cin >> Z;
    121122  walker = FindElement(Z);
    122123  if (walker == NULL) {
    123     Log() << Verbose(0) << "Element not found in database, please enter." << endl;
     124    DoLog(0) && (Log() << Verbose(0) << "Element not found in database, please enter." << endl);
    124125    walker = new element;
    125126    walker->Z = Z;
    126     Log() << Verbose(0) << "Mass: " << endl;
     127    DoLog(0) && (Log() << Verbose(0) << "Mass: " << endl);
    127128    cin >> walker->mass;
    128     Log() << Verbose(0) << "Name [max 64 chars]: " << endl;
     129    DoLog(0) && (Log() << Verbose(0) << "Name [max 64 chars]: " << endl);
    129130    cin >> walker->name;
    130     Log() << Verbose(0) << "Short form [max 3 chars]: " << endl;
     131    DoLog(0) && (Log() << Verbose(0) << "Short form [max 3 chars]: " << endl);
    131132    cin >> walker->symbol;
    132133    periodentafel::AddElement(walker);
     
    197198    infile.getline(header1, MAXSTRINGSIZE);
    198199    infile.getline(header2, MAXSTRINGSIZE); // skip first two header lines
    199     Log() << Verbose(0) <<  "Parsed elements:";
     200    DoLog(0) && (Log() << Verbose(0) <<  "Parsed elements:");
    200201    while (!infile.eof()) {
    201202      element *neues = new element;
     
    219220      //infile >> ws;
    220221      infile >> ws;
    221       Log() << Verbose(0) << " " << neues->symbol;
     222      DoLog(0) && (Log() << Verbose(0) << " " << neues->symbol);
    222223      //neues->Output((ofstream *)&cout);
    223224      if ((neues->Z > 0) && (neues->Z < MAX_ELEMENTS))
    224225        periodentafel::AddElement(neues);
    225226      else {
    226         Log() << Verbose(0) << "Could not parse element: ";
     227        DoLog(0) && (Log() << Verbose(0) << "Could not parse element: ");
    227228        neues->Output((ofstream *)&cout);
    228229        delete(neues);
    229230      }
    230231    }
    231     Log() << Verbose(0) << endl;
     232    DoLog(0) && (Log() << Verbose(0) << endl);
    232233    infile.close();
    233234    infile.clear();
     
    313314
    314315  if (!otherstatus)
    315     eLog() << Verbose(0) << "WARNING: Something went wrong while parsing the other databases!" << endl;
     316    DoeLog(2) && (eLog()<< Verbose(2) << "Something went wrong while parsing the other databases!" << endl);
    316317
    317318  return status;
  • src/stackclass.hpp

    re5ad5c ree7e25  
    7272    return true;
    7373  } else {
    74     eLog() << Verbose(0) << "ERROR: Stack is full, " << "Stack: CurrentLastEntry " << CurrentLastEntry<< "\tCurrentFirstEntry " << CurrentFirstEntry << "\tNextFreeField " << NextFreeField << "\tEntryCount " << EntryCount << "!" << endl;
     74    DoeLog(1) && (eLog()<< Verbose(1) << "Stack is full, " << "Stack: CurrentLastEntry " << CurrentLastEntry<< "\tCurrentFirstEntry " << CurrentFirstEntry << "\tNextFreeField " << NextFreeField << "\tEntryCount " << EntryCount << "!" << endl);
    7575    return false;
    7676  }
     
    8787    Walker = StackList[CurrentFirstEntry];
    8888    if (Walker == NULL)
    89       eLog() << Verbose(0) << "ERROR: Stack's field is empty!" << endl;
     89      DoeLog(1) && (eLog()<< Verbose(1) << "Stack's field is empty!" << endl);
    9090    StackList[CurrentFirstEntry] = NULL;
    9191    if (CurrentFirstEntry != CurrentLastEntry) { // hasn't last item been popped as well?
     
    9696    }
    9797  } else
    98     eLog() << Verbose(0) << "ERROR: Stack is empty!" << endl;
     98    DoeLog(1) && (eLog()<< Verbose(1) << "Stack is empty!" << endl);
    9999  return Walker;
    100100};
     
    111111    StackList[CurrentLastEntry] = NULL;
    112112    if (Walker == NULL)
    113       eLog() << Verbose(0) << "ERROR: Stack's field is empty!" << endl;
     113      DoeLog(1) && (eLog()<< Verbose(1) << "Stack's field is empty!" << endl);
    114114    NextFreeField = CurrentLastEntry;
    115115    if (CurrentLastEntry != CurrentFirstEntry)  // has there been more than one item on stack
    116116      CurrentLastEntry = (CurrentLastEntry + (EntryCount-1)) % EntryCount; // step back from current free field to last (modulo does not work in -1, thus go EntryCount-1 instead)
    117117  } else {
    118     eLog() << Verbose(0) << "ERROR: Stack is empty!" << endl;
     118    DoeLog(1) && (eLog()<< Verbose(1) << "Stack is empty!" << endl);
    119119  }
    120120  return Walker;
     
    130130{
    131131  bool found = false;
    132   Log() << Verbose(5) << "First " << CurrentFirstEntry<< "\tLast " << CurrentLastEntry<< "\tNext " << NextFreeField<< "\tCount " << EntryCount<< "." << endl;
     132  DoLog(5) && (Log() << Verbose(5) << "First " << CurrentFirstEntry<< "\tLast " << CurrentLastEntry<< "\tNext " << NextFreeField<< "\tCount " << EntryCount<< "." << endl);
    133133  int i=CurrentFirstEntry;
    134134  if (!IsEmpty())
    135135    do {
    136136      if (StackList[i] == ptr) {  // if item found, remove
    137         Log() << Verbose(5) << "Item " << *ptr << " was number " << i << " on stack, removing it." << endl;
     137        DoLog(5) && (Log() << Verbose(5) << "Item " << *ptr << " was number " << i << " on stack, removing it." << endl);
    138138        found = true;
    139139        StackList[i] = NULL;
     
    141141      if ((found) && (StackList[i] != NULL)) {  // means we have to shift (and not the removed item)
    142142        if (i == 0) { // we are down to first item in stack, have to put onto last item
    143           Log() << Verbose(5) << "Shifting item 0 to place " << EntryCount-1 << "." << endl;
     143          DoLog(5) && (Log() << Verbose(5) << "Shifting item 0 to place " << EntryCount-1 << "." << endl);
    144144          StackList[EntryCount-1] = StackList[0];
    145145        } else {
    146           Log() << Verbose(5) << "Shifting item " << i << " to place " << i-1 << "." << endl;
     146          DoLog(5) && (Log() << Verbose(5) << "Shifting item " << i << " to place " << i-1 << "." << endl);
    147147          StackList[i-1] = StackList[i];
    148148        }
     
    151151    } while (i!=NextFreeField);
    152152  else
    153     eLog() << Verbose(0) << "ERROR: Stack is already empty!" << endl;
     153    DoeLog(1) && (eLog()<< Verbose(1) << "Stack is already empty!" << endl);
    154154  if (found) {
    155155    NextFreeField = CurrentLastEntry;
  • src/tesselation.cpp

    re5ad5c ree7e25  
    77
    88#include <fstream>
     9#include <assert.h>
    910
    1011#include "helpers.hpp"
     12#include "info.hpp"
    1113#include "linkedcell.hpp"
    1214#include "log.hpp"
    1315#include "tesselation.hpp"
    1416#include "tesselationhelpers.hpp"
     17#include "triangleintersectionlist.hpp"
    1518#include "vector.hpp"
    1619#include "verbose.hpp"
     
    2225/** Constructor of BoundaryPointSet.
    2326 */
    24 BoundaryPointSet::BoundaryPointSet()
    25 {
    26   LinesCount = 0;
    27   Nr = -1;
    28   value = 0.;
    29 };
     27BoundaryPointSet::BoundaryPointSet() :
     28  LinesCount(0), value(0.), Nr(-1)
     29{
     30  Info FunctionInfo(__func__);
     31  DoLog(1) && (Log() << Verbose(1) << "Adding noname." << endl);
     32}
     33;
    3034
    3135/** Constructor of BoundaryPointSet with Tesselpoint.
    3236 * \param *Walker TesselPoint this boundary point represents
    3337 */
    34 BoundaryPointSet::BoundaryPointSet(TesselPoint * Walker)
    35 {
    36   node = Walker;
    37   LinesCount = 0;
    38   Nr = Walker->nr;
    39   value = 0.;
    40 };
     38BoundaryPointSet::BoundaryPointSet(TesselPoint * const Walker) :
     39  LinesCount(0), node(Walker), value(0.), Nr(Walker->nr)
     40{
     41  Info FunctionInfo(__func__);
     42  DoLog(1) && (Log() << Verbose(1) << "Adding Node " << *Walker << endl);
     43}
     44;
    4145
    4246/** Destructor of BoundaryPointSet.
     
    4650BoundaryPointSet::~BoundaryPointSet()
    4751{
    48   //Log() << Verbose(5) << "Erasing point nr. " << Nr << "." << endl;
     52  Info FunctionInfo(__func__);
     53  //Log() << Verbose(0) << "Erasing point nr. " << Nr << "." << endl;
    4954  if (!lines.empty())
    50     eLog() << Verbose(0) << "WARNING: Memory Leak! I " << *this << " am still connected to some lines." << endl;
     55    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some lines." << endl);
    5156  node = NULL;
    52 };
     57}
     58;
    5359
    5460/** Add a line to the LineMap of this point.
    5561 * \param *line line to add
    5662 */
    57 void BoundaryPointSet::AddLine(class BoundaryLineSet *line)
    58 {
    59   Log() << Verbose(6) << "Adding " << *this << " to line " << *line << "."
    60       << endl;
    61   if (line->endpoints[0] == this)
    62     {
    63       lines.insert(LinePair(line->endpoints[1]->Nr, line));
    64     }
    65   else
    66     {
    67       lines.insert(LinePair(line->endpoints[0]->Nr, line));
    68     }
     63void BoundaryPointSet::AddLine(BoundaryLineSet * const line)
     64{
     65  Info FunctionInfo(__func__);
     66  DoLog(1) && (Log() << Verbose(1) << "Adding " << *this << " to line " << *line << "." << endl);
     67  if (line->endpoints[0] == this) {
     68    lines.insert(LinePair(line->endpoints[1]->Nr, line));
     69  } else {
     70    lines.insert(LinePair(line->endpoints[0]->Nr, line));
     71  }
    6972  LinesCount++;
    70 };
     73}
     74;
    7175
    7276/** output operator for BoundaryPointSet.
     
    8589/** Constructor of BoundaryLineSet.
    8690 */
    87 BoundaryLineSet::BoundaryLineSet()
    88 {
     91BoundaryLineSet::BoundaryLineSet() :
     92  Nr(-1)
     93{
     94  Info FunctionInfo(__func__);
    8995  for (int i = 0; i < 2; i++)
    9096    endpoints[i] = NULL;
    91   Nr = -1;
    92 };
     97}
     98;
    9399
    94100/** Constructor of BoundaryLineSet with two endpoints.
     
    97103 * \param number number of the list
    98104 */
    99 BoundaryLineSet::BoundaryLineSet(class BoundaryPointSet *Point[2], const int number)
    100 {
     105BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point[2], const int number)
     106{
     107  Info FunctionInfo(__func__);
    101108  // set number
    102109  Nr = number;
     
    106113  Point[0]->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
    107114  Point[1]->AddLine(this); //
     115  // set skipped to false
     116  skipped = false;
    108117  // clear triangles list
    109   Log() << Verbose(5) << "New Line with endpoints " << *this << "." << endl;
    110 };
     118  DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
     119}
     120;
     121
     122/** Constructor of BoundaryLineSet with two endpoints.
     123 * Adds line automatically to each endpoints' LineMap
     124 * \param *Point1 first boundary point
     125 * \param *Point2 second boundary point
     126 * \param number number of the list
     127 */
     128BoundaryLineSet::BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number)
     129{
     130  Info FunctionInfo(__func__);
     131  // set number
     132  Nr = number;
     133  // set endpoints in ascending order
     134  SetEndpointsOrdered(endpoints, Point1, Point2);
     135  // add this line to the hash maps of both endpoints
     136  Point1->AddLine(this); //Taken out, to check whether we can avoid unwanted double adding.
     137  Point2->AddLine(this); //
     138  // set skipped to false
     139  skipped = false;
     140  // clear triangles list
     141  DoLog(0) && (Log() << Verbose(0) << "New Line with endpoints " << *this << "." << endl);
     142}
     143;
    111144
    112145/** Destructor for BoundaryLineSet.
     
    116149BoundaryLineSet::~BoundaryLineSet()
    117150{
     151  Info FunctionInfo(__func__);
    118152  int Numbers[2];
    119153
     
    134168        for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
    135169          if ((*Runner).second == this) {
    136             //Log() << Verbose(5) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
     170            //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
    137171            endpoints[i]->lines.erase(Runner);
    138172            break;
     
    140174      } else { // there's just a single line left
    141175        if (endpoints[i]->lines.erase(Nr)) {
    142           //Log() << Verbose(5) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
     176          //Log() << Verbose(0) << "Removing Line Nr. " << Nr << " in boundary point " << *endpoints[i] << "." << endl;
    143177        }
    144178      }
    145179      if (endpoints[i]->lines.empty()) {
    146         //Log() << Verbose(5) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
     180        //Log() << Verbose(0) << *endpoints[i] << " has no more lines it's attached to, erasing." << endl;
    147181        if (endpoints[i] != NULL) {
    148           delete(endpoints[i]);
     182          delete (endpoints[i]);
    149183          endpoints[i] = NULL;
    150184        }
     
    153187  }
    154188  if (!triangles.empty())
    155     eLog() << Verbose(0) << "WARNING: Memory Leak! I " << *this << " am still connected to some triangles." << endl;
    156 };
     189    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *this << " am still connected to some triangles." << endl);
     190}
     191;
    157192
    158193/** Add triangle to TriangleMap of this boundary line.
    159194 * \param *triangle to add
    160195 */
    161 void BoundaryLineSet::AddTriangle(class BoundaryTriangleSet *triangle)
    162 {
    163   Log() << Verbose(6) << "Add " << triangle->Nr << " to line " << *this << "." << endl;
     196void BoundaryLineSet::AddTriangle(BoundaryTriangleSet * const triangle)
     197{
     198  Info FunctionInfo(__func__);
     199  DoLog(0) && (Log() << Verbose(0) << "Add " << triangle->Nr << " to line " << *this << "." << endl);
    164200  triangles.insert(TrianglePair(triangle->Nr, triangle));
    165 };
     201}
     202;
    166203
    167204/** Checks whether we have a common endpoint with given \a *line.
     
    169206 * \return true - common endpoint present, false - not connected
    170207 */
    171 bool BoundaryLineSet::IsConnectedTo(class BoundaryLineSet *line)
    172 {
     208bool BoundaryLineSet::IsConnectedTo(const BoundaryLineSet * const line) const
     209{
     210  Info FunctionInfo(__func__);
    173211  if ((endpoints[0] == line->endpoints[0]) || (endpoints[1] == line->endpoints[0]) || (endpoints[0] == line->endpoints[1]) || (endpoints[1] == line->endpoints[1]))
    174212    return true;
    175213  else
    176214    return false;
    177 };
     215}
     216;
    178217
    179218/** Checks whether the adjacent triangles of a baseline are convex or not.
     
    183222 * \return true - triangles are convex, false - concave or less than two triangles connected
    184223 */
    185 bool BoundaryLineSet::CheckConvexityCriterion()
    186 {
     224bool BoundaryLineSet::CheckConvexityCriterion() const
     225{
     226  Info FunctionInfo(__func__);
    187227  Vector BaseLineCenter, BaseLineNormal, BaseLine, helper[2], NormalCheck;
    188228  // get the two triangles
    189229  if (triangles.size() != 2) {
    190     Log() << Verbose(1) << "ERROR: Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl;
     230    DoeLog(0) && (eLog() << Verbose(0) << "Baseline " << *this << " is connected to less than two triangles, Tesselation incomplete!" << endl);
    191231    return true;
    192232  }
    193233  // check normal vectors
    194234  // have a normal vector on the base line pointing outwards
    195   //Log() << Verbose(3) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
     235  //Log() << Verbose(0) << "INFO: " << *this << " has vectors at " << *(endpoints[0]->node->node) << " and at " << *(endpoints[1]->node->node) << "." << endl;
    196236  BaseLineCenter.CopyVector(endpoints[0]->node->node);
    197237  BaseLineCenter.AddVector(endpoints[1]->node->node);
    198   BaseLineCenter.Scale(1./2.);
     238  BaseLineCenter.Scale(1. / 2.);
    199239  BaseLine.CopyVector(endpoints[0]->node->node);
    200240  BaseLine.SubtractVector(endpoints[1]->node->node);
    201   //Log() << Verbose(3) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
     241  //Log() << Verbose(0) << "INFO: Baseline is " << BaseLine << " and its center is at " << BaseLineCenter << "." << endl;
    202242
    203243  BaseLineNormal.Zero();
    204244  NormalCheck.Zero();
    205245  double sign = -1.;
    206   int i=0;
     246  int i = 0;
    207247  class BoundaryPointSet *node = NULL;
    208   for(TriangleMap::iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
    209     //Log() << Verbose(3) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
     248  for (TriangleMap::const_iterator runner = triangles.begin(); runner != triangles.end(); runner++) {
     249    //Log() << Verbose(0) << "INFO: NormalVector of " << *(runner->second) << " is " << runner->second->NormalVector << "." << endl;
    210250    NormalCheck.AddVector(&runner->second->NormalVector);
    211251    NormalCheck.Scale(sign);
    212252    sign = -sign;
    213253    if (runner->second->NormalVector.NormSquared() > MYEPSILON)
    214       BaseLineNormal.CopyVector(&runner->second->NormalVector);   // yes, copy second on top of first
     254      BaseLineNormal.CopyVector(&runner->second->NormalVector); // yes, copy second on top of first
    215255    else {
    216       Log() << Verbose(1) << "CRITICAL: Triangle " << *runner->second << " has zero normal vector!" << endl;
    217       exit(255);
     256      DoeLog(0) && (eLog() << Verbose(0) << "Triangle " << *runner->second << " has zero normal vector!" << endl);
    218257    }
    219258    node = runner->second->GetThirdEndpoint(this);
    220259    if (node != NULL) {
    221       //Log() << Verbose(3) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
     260      //Log() << Verbose(0) << "INFO: Third node for triangle " << *(runner->second) << " is " << *node << " at " << *(node->node->node) << "." << endl;
    222261      helper[i].CopyVector(node->node->node);
    223262      helper[i].SubtractVector(&BaseLineCenter);
    224       helper[i].MakeNormalVector(&BaseLine);  // we want to compare the triangle's heights' angles!
    225       //Log() << Verbose(4) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
     263      helper[i].MakeNormalVector(&BaseLine); // we want to compare the triangle's heights' angles!
     264      //Log() << Verbose(0) << "INFO: Height vector with respect to baseline is " << helper[i] << "." << endl;
    226265      i++;
    227266    } else {
    228       //Log() << Verbose(2) << "ERROR: I cannot find third node in triangle, something's wrong." << endl;
     267      DoeLog(1) && (eLog() << Verbose(1) << "I cannot find third node in triangle, something's wrong." << endl);
    229268      return true;
    230269    }
    231270  }
    232   //Log() << Verbose(3) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
     271  //Log() << Verbose(0) << "INFO: BaselineNormal is " << BaseLineNormal << "." << endl;
    233272  if (NormalCheck.NormSquared() < MYEPSILON) {
    234     Log() << Verbose(3) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl;
     273    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Normalvectors of both triangles are the same: convex." << endl);
    235274    return true;
    236275  }
     
    238277  double angle = GetAngle(helper[0], helper[1], BaseLineNormal);
    239278  if ((angle - M_PI) > -MYEPSILON) {
    240     Log() << Verbose(3) << "ACCEPT: Angle is greater than pi: convex." << endl;
     279    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Angle is greater than pi: convex." << endl);
    241280    return true;
    242281  } else {
    243     Log() << Verbose(3) << "REJECT: Angle is less than pi: concave." << endl;
     282    DoLog(0) && (Log() << Verbose(0) << "REJECT: Angle is less than pi: concave." << endl);
    244283    return false;
    245284  }
     
    250289 * \return true - point is of the line, false - is not
    251290 */
    252 bool BoundaryLineSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
    253 {
    254   for(int i=0;i<2;i++)
     291bool BoundaryLineSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
     292{
     293  Info FunctionInfo(__func__);
     294  for (int i = 0; i < 2; i++)
    255295    if (point == endpoints[i])
    256296      return true;
    257297  return false;
    258 };
     298}
     299;
    259300
    260301/** Returns other endpoint of the line.
     
    262303 * \return NULL - if endpoint not contained in BoundaryLineSet, or pointer to BoundaryPointSet otherwise
    263304 */
    264 class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(class BoundaryPointSet *point)
    265 {
     305class BoundaryPointSet *BoundaryLineSet::GetOtherEndpoint(const BoundaryPointSet * const point) const
     306{
     307  Info FunctionInfo(__func__);
    266308  if (endpoints[0] == point)
    267309    return endpoints[1];
     
    270312  else
    271313    return NULL;
    272 };
     314}
     315;
    273316
    274317/** output operator for BoundaryLineSet.
     
    276319 * \param &a boundary line
    277320 */
    278 ostream & operator <<(ostream &ost, const  BoundaryLineSet &a)
     321ostream & operator <<(ostream &ost, const BoundaryLineSet &a)
    279322{
    280323  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << "," << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "]";
    281324  return ost;
    282 };
     325}
     326;
    283327
    284328// ======================================== Triangles on Boundary =================================
     
    286330/** Constructor for BoundaryTriangleSet.
    287331 */
    288 BoundaryTriangleSet::BoundaryTriangleSet()
    289 {
    290   for (int i = 0; i < 3; i++)
    291     {
    292       endpoints[i] = NULL;
    293       lines[i] = NULL;
    294     }
    295   Nr = -1;
    296 };
     332BoundaryTriangleSet::BoundaryTriangleSet() :
     333  Nr(-1)
     334{
     335  Info FunctionInfo(__func__);
     336  for (int i = 0; i < 3; i++) {
     337    endpoints[i] = NULL;
     338    lines[i] = NULL;
     339  }
     340}
     341;
    297342
    298343/** Constructor for BoundaryTriangleSet with three lines.
     
    300345 * \param number number of triangle
    301346 */
    302 BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet *line[3], int number)
    303 {
     347BoundaryTriangleSet::BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number) :
     348  Nr(number)
     349{
     350  Info FunctionInfo(__func__);
    304351  // set number
    305   Nr = number;
    306352  // set lines
    307   Log() << Verbose(5) << "New triangle " << Nr << ":" << endl;
    308   for (int i = 0; i < 3; i++)
    309     {
    310       lines[i] = line[i];
    311       lines[i]->AddTriangle(this);
    312     }
     353  for (int i = 0; i < 3; i++) {
     354    lines[i] = line[i];
     355    lines[i]->AddTriangle(this);
     356  }
    313357  // get ascending order of endpoints
    314   map<int, class BoundaryPointSet *> OrderMap;
     358  PointMap OrderMap;
    315359  for (int i = 0; i < 3; i++)
    316360    // for all three lines
    317     for (int j = 0; j < 2; j++)
    318       { // for both endpoints
    319         OrderMap.insert(pair<int, class BoundaryPointSet *> (
    320             line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
    321         // and we don't care whether insertion fails
    322       }
     361    for (int j = 0; j < 2; j++) { // for both endpoints
     362      OrderMap.insert(pair<int, class BoundaryPointSet *> (line[i]->endpoints[j]->Nr, line[i]->endpoints[j]));
     363      // and we don't care whether insertion fails
     364    }
    323365  // set endpoints
    324366  int Counter = 0;
    325   Log() << Verbose(6) << " with end points ";
    326   for (map<int, class BoundaryPointSet *>::iterator runner = OrderMap.begin(); runner
    327       != OrderMap.end(); runner++)
    328     {
    329       endpoints[Counter] = runner->second;
    330       Log() << Verbose(0) << " " << *endpoints[Counter];
    331       Counter++;
    332     }
    333   if (Counter < 3)
    334     {
    335       eLog() << Verbose(0) << "ERROR! We have a triangle with only two distinct endpoints!"
    336           << endl;
    337       //exit(1);
    338     }
    339   Log() << Verbose(0) << "." << endl;
    340 };
     367  DoLog(0) && (Log() << Verbose(0) << "New triangle " << Nr << " with end points: " << endl);
     368  for (PointMap::iterator runner = OrderMap.begin(); runner != OrderMap.end(); runner++) {
     369    endpoints[Counter] = runner->second;
     370    DoLog(0) && (Log() << Verbose(0) << " " << *endpoints[Counter] << endl);
     371    Counter++;
     372  }
     373  if (Counter < 3) {
     374    DoeLog(0) && (eLog() << Verbose(0) << "We have a triangle with only two distinct endpoints!" << endl);
     375    performCriticalExit();
     376  }
     377}
     378;
    341379
    342380/** Destructor of BoundaryTriangleSet.
     
    346384BoundaryTriangleSet::~BoundaryTriangleSet()
    347385{
     386  Info FunctionInfo(__func__);
    348387  for (int i = 0; i < 3; i++) {
    349388    if (lines[i] != NULL) {
    350389      if (lines[i]->triangles.erase(Nr)) {
    351         //Log() << Verbose(5) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
     390        //Log() << Verbose(0) << "Triangle Nr." << Nr << " erased in line " << *lines[i] << "." << endl;
    352391      }
    353392      if (lines[i]->triangles.empty()) {
    354           //Log() << Verbose(5) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
    355           delete (lines[i]);
    356           lines[i] = NULL;
     393        //Log() << Verbose(0) << *lines[i] << " is no more attached to any triangle, erasing." << endl;
     394        delete (lines[i]);
     395        lines[i] = NULL;
    357396      }
    358397    }
    359398  }
    360   //Log() << Verbose(5) << "Erasing triangle Nr." << Nr << " itself." << endl;
    361 };
     399  //Log() << Verbose(0) << "Erasing triangle Nr." << Nr << " itself." << endl;
     400}
     401;
    362402
    363403/** Calculates the normal vector for this triangle.
     
    365405 * \param &OtherVector direction vector to make normal vector unique.
    366406 */
    367 void BoundaryTriangleSet::GetNormalVector(Vector &OtherVector)
    368 {
     407void BoundaryTriangleSet::GetNormalVector(const Vector &OtherVector)
     408{
     409  Info FunctionInfo(__func__);
    369410  // get normal vector
    370411  NormalVector.MakeNormalVector(endpoints[0]->node->node, endpoints[1]->node->node, endpoints[2]->node->node);
     
    373414  if (NormalVector.ScalarProduct(&OtherVector) > 0.)
    374415    NormalVector.Scale(-1.);
    375 };
    376 
    377 /** Finds the point on the triangle \a *BTS the line defined by \a *MolCenter and \a *x crosses through.
     416  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << NormalVector << "." << endl);
     417}
     418;
     419
     420/** Finds the point on the triangle \a *BTS through which the line defined by \a *MolCenter and \a *x crosses.
    378421 * We call Vector::GetIntersectionWithPlane() to receive the intersection point with the plane
    379  * This we test if it's really on the plane and whether it's inside the triangle on the plane or not.
     422 * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
    380423 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
    381424 * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
     
    387430 * \return true - \a *Intersection contains intersection on plane defined by triangle, false - zero vector if outside of triangle.
    388431 */
    389 bool BoundaryTriangleSet::GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection)
    390 {
     432bool BoundaryTriangleSet::GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const
     433{
     434  Info FunctionInfo(__func__);
    391435  Vector CrossPoint;
    392436  Vector helper;
    393437
    394438  if (!Intersection->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, MolCenter, x)) {
    395     Log() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl;
     439    DoeLog(1) && (eLog() << Verbose(1) << "Alas! Intersection with plane failed - at least numerically - the intersection is not on the plane!" << endl);
    396440    return false;
    397441  }
    398442
     443  DoLog(1) && (Log() << Verbose(1) << "INFO: Triangle is " << *this << "." << endl);
     444  DoLog(1) && (Log() << Verbose(1) << "INFO: Line is from " << *MolCenter << " to " << *x << "." << endl);
     445  DoLog(1) && (Log() << Verbose(1) << "INFO: Intersection is " << *Intersection << "." << endl);
     446
     447  if (Intersection->DistanceSquared(endpoints[0]->node->node) < MYEPSILON) {
     448    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with first endpoint." << endl);
     449    return true;
     450  } else if (Intersection->DistanceSquared(endpoints[1]->node->node) < MYEPSILON) {
     451    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with second endpoint." << endl);
     452    return true;
     453  } else if (Intersection->DistanceSquared(endpoints[2]->node->node) < MYEPSILON) {
     454    DoLog(1) && (Log() << Verbose(1) << "Intersection coindices with third endpoint." << endl);
     455    return true;
     456  }
    399457  // Calculate cross point between one baseline and the line from the third endpoint to intersection
    400   int i=0;
     458  int i = 0;
    401459  do {
    402     if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i%3]->node->node, endpoints[(i+1)%3]->node->node, endpoints[(i+2)%3]->node->node, Intersection, &NormalVector)) {
    403       helper.CopyVector(endpoints[(i+1)%3]->node->node);
    404       helper.SubtractVector(endpoints[i%3]->node->node);
    405     } else
     460    if (CrossPoint.GetIntersectionOfTwoLinesOnPlane(endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node, endpoints[(i + 2) % 3]->node->node, Intersection, &NormalVector)) {
     461      helper.CopyVector(endpoints[(i + 1) % 3]->node->node);
     462      helper.SubtractVector(endpoints[i % 3]->node->node);
     463      CrossPoint.SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
     464      const double s = CrossPoint.ScalarProduct(&helper) / helper.NormSquared();
     465      DoLog(1) && (Log() << Verbose(1) << "INFO: Factor s is " << s << "." << endl);
     466      if ((s < -MYEPSILON) || ((s - 1.) > MYEPSILON)) {
     467        DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << "outside of triangle." << endl);
     468        i = 4;
     469        break;
     470      }
    406471      i++;
    407     if (i>2)
     472    } else
    408473      break;
    409   } while (CrossPoint.NormSquared() < MYEPSILON);
    410   if (i==3) {
    411     Log() << Verbose(1) << "ERROR: Could not find any cross points, something's utterly wrong here!" << endl;
    412     exit(255);
    413   }
    414   CrossPoint.SubtractVector(endpoints[i%3]->node->node);  // cross point was returned as absolute vector
    415 
    416   // check whether intersection is inside or not by comparing length of intersection and length of cross point
    417   if ((CrossPoint.NormSquared() - helper.NormSquared()) < MYEPSILON) { // inside
     474  } while (i < 3);
     475  if (i == 3) {
     476    DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " inside of triangle." << endl);
    418477    return true;
    419   } else { // outside!
    420     Intersection->Zero();
     478  } else {
     479    DoLog(1) && (Log() << Verbose(1) << "INFO: Crosspoint " << CrossPoint << " outside of triangle." << endl);
    421480    return false;
    422481  }
    423 };
     482}
     483;
     484
     485/** Finds the point on the triangle to the point \a *x.
     486 * We call Vector::GetIntersectionWithPlane() with \a * and the center of the triangle to receive an intersection point.
     487 * Then we check the in-plane part (the part projected down onto plane). We check whether it crosses one of the
     488 * boundary lines. If it does, we return this intersection as closest point, otherwise the projected point down.
     489 * Thus we test if it's really on the plane and whether it's inside the triangle on the plane or not.
     490 * The latter is done as follows: We calculate the cross point of one of the triangle's baseline with the line
     491 * given by the intersection and the third basepoint. Then, we check whether it's on the baseline (i.e. between
     492 * the first two basepoints) or not.
     493 * \param *x point
     494 * \param *ClosestPoint desired closest point inside triangle to \a *x, is absolute vector
     495 * \return Distance squared between \a *x and closest point inside triangle
     496 */
     497double BoundaryTriangleSet::GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const
     498{
     499  Info FunctionInfo(__func__);
     500  Vector Direction;
     501
     502  // 1. get intersection with plane
     503  DoLog(1) && (Log() << Verbose(1) << "INFO: Looking for closest point of triangle " << *this << " to " << *x << "." << endl);
     504  GetCenter(&Direction);
     505  if (!ClosestPoint->GetIntersectionWithPlane(&NormalVector, endpoints[0]->node->node, x, &Direction)) {
     506    ClosestPoint->CopyVector(x);
     507  }
     508
     509  // 2. Calculate in plane part of line (x, intersection)
     510  Vector InPlane;
     511  InPlane.CopyVector(x);
     512  InPlane.SubtractVector(ClosestPoint); // points from plane intersection to straight-down point
     513  InPlane.ProjectOntoPlane(&NormalVector);
     514  InPlane.AddVector(ClosestPoint);
     515
     516  DoLog(2) && (Log() << Verbose(2) << "INFO: Triangle is " << *this << "." << endl);
     517  DoLog(2) && (Log() << Verbose(2) << "INFO: Line is from " << Direction << " to " << *x << "." << endl);
     518  DoLog(2) && (Log() << Verbose(2) << "INFO: In-plane part is " << InPlane << "." << endl);
     519
     520  // Calculate cross point between one baseline and the desired point such that distance is shortest
     521  double ShortestDistance = -1.;
     522  bool InsideFlag = false;
     523  Vector CrossDirection[3];
     524  Vector CrossPoint[3];
     525  Vector helper;
     526  for (int i = 0; i < 3; i++) {
     527    // treat direction of line as normal of a (cut)plane and the desired point x as the plane offset, the intersect line with point
     528    Direction.CopyVector(endpoints[(i + 1) % 3]->node->node);
     529    Direction.SubtractVector(endpoints[i % 3]->node->node);
     530    // calculate intersection, line can never be parallel to Direction (is the same vector as PlaneNormal);
     531    CrossPoint[i].GetIntersectionWithPlane(&Direction, &InPlane, endpoints[i % 3]->node->node, endpoints[(i + 1) % 3]->node->node);
     532    CrossDirection[i].CopyVector(&CrossPoint[i]);
     533    CrossDirection[i].SubtractVector(&InPlane);
     534    CrossPoint[i].SubtractVector(endpoints[i % 3]->node->node); // cross point was returned as absolute vector
     535    const double s = CrossPoint[i].ScalarProduct(&Direction) / Direction.NormSquared();
     536    DoLog(2) && (Log() << Verbose(2) << "INFO: Factor s is " << s << "." << endl);
     537    if ((s >= -MYEPSILON) && ((s - 1.) <= MYEPSILON)) {
     538      CrossPoint[i].AddVector(endpoints[i % 3]->node->node); // make cross point absolute again
     539      DoLog(2) && (Log() << Verbose(2) << "INFO: Crosspoint is " << CrossPoint[i] << ", intersecting BoundaryLine between " << *endpoints[i % 3]->node->node << " and " << *endpoints[(i + 1) % 3]->node->node << "." << endl);
     540      const double distance = CrossPoint[i].DistanceSquared(x);
     541      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
     542        ShortestDistance = distance;
     543        ClosestPoint->CopyVector(&CrossPoint[i]);
     544      }
     545    } else
     546      CrossPoint[i].Zero();
     547  }
     548  InsideFlag = true;
     549  for (int i = 0; i < 3; i++) {
     550    const double sign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 1) % 3]);
     551    const double othersign = CrossDirection[i].ScalarProduct(&CrossDirection[(i + 2) % 3]);
     552    ;
     553    if ((sign > -MYEPSILON) && (othersign > -MYEPSILON)) // have different sign
     554      InsideFlag = false;
     555  }
     556  if (InsideFlag) {
     557    ClosestPoint->CopyVector(&InPlane);
     558    ShortestDistance = InPlane.DistanceSquared(x);
     559  } else { // also check endnodes
     560    for (int i = 0; i < 3; i++) {
     561      const double distance = x->DistanceSquared(endpoints[i]->node->node);
     562      if ((ShortestDistance < 0.) || (ShortestDistance > distance)) {
     563        ShortestDistance = distance;
     564        ClosestPoint->CopyVector(endpoints[i]->node->node);
     565      }
     566    }
     567  }
     568  DoLog(1) && (Log() << Verbose(1) << "INFO: Closest Point is " << *ClosestPoint << " with shortest squared distance is " << ShortestDistance << "." << endl);
     569  return ShortestDistance;
     570}
     571;
    424572
    425573/** Checks whether lines is any of the three boundary lines this triangle contains.
     
    427575 * \return true - line is of the triangle, false - is not
    428576 */
    429 bool BoundaryTriangleSet::ContainsBoundaryLine(class BoundaryLineSet *line)
    430 {
    431   for(int i=0;i<3;i++)
     577bool BoundaryTriangleSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
     578{
     579  Info FunctionInfo(__func__);
     580  for (int i = 0; i < 3; i++)
    432581    if (line == lines[i])
    433582      return true;
    434583  return false;
    435 };
     584}
     585;
    436586
    437587/** Checks whether point is any of the three endpoints this triangle contains.
     
    439589 * \return true - point is of the triangle, false - is not
    440590 */
    441 bool BoundaryTriangleSet::ContainsBoundaryPoint(class BoundaryPointSet *point)
    442 {
    443   for(int i=0;i<3;i++)
     591bool BoundaryTriangleSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
     592{
     593  Info FunctionInfo(__func__);
     594  for (int i = 0; i < 3; i++)
    444595    if (point == endpoints[i])
    445596      return true;
    446597  return false;
    447 };
     598}
     599;
    448600
    449601/** Checks whether point is any of the three endpoints this triangle contains.
     
    451603 * \return true - point is of the triangle, false - is not
    452604 */
    453 bool BoundaryTriangleSet::ContainsBoundaryPoint(class TesselPoint *point)
    454 {
    455   for(int i=0;i<3;i++)
     605bool BoundaryTriangleSet::ContainsBoundaryPoint(const TesselPoint * const point) const
     606{
     607  Info FunctionInfo(__func__);
     608  for (int i = 0; i < 3; i++)
    456609    if (point == endpoints[i]->node)
    457610      return true;
    458611  return false;
    459 };
     612}
     613;
    460614
    461615/** Checks whether three given \a *Points coincide with triangle's endpoints.
     
    463617 * \return true - is the very triangle, false - is not
    464618 */
    465 bool BoundaryTriangleSet::IsPresentTupel(class BoundaryPointSet *Points[3])
    466 {
    467   return (((endpoints[0] == Points[0])
    468             || (endpoints[0] == Points[1])
    469             || (endpoints[0] == Points[2])
    470           ) && (
    471             (endpoints[1] == Points[0])
    472             || (endpoints[1] == Points[1])
    473             || (endpoints[1] == Points[2])
    474           ) && (
    475             (endpoints[2] == Points[0])
    476             || (endpoints[2] == Points[1])
    477             || (endpoints[2] == Points[2])
    478 
    479           ));
    480 };
     619bool BoundaryTriangleSet::IsPresentTupel(const BoundaryPointSet * const Points[3]) const
     620{
     621  Info FunctionInfo(__func__);
     622  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking " << Points[0] << "," << Points[1] << "," << Points[2] << " against " << endpoints[0] << "," << endpoints[1] << "," << endpoints[2] << "." << endl);
     623  return (((endpoints[0] == Points[0]) || (endpoints[0] == Points[1]) || (endpoints[0] == Points[2])) && ((endpoints[1] == Points[0]) || (endpoints[1] == Points[1]) || (endpoints[1] == Points[2])) && ((endpoints[2] == Points[0]) || (endpoints[2] == Points[1]) || (endpoints[2] == Points[2])
     624
     625  ));
     626}
     627;
    481628
    482629/** Checks whether three given \a *Points coincide with triangle's endpoints.
     
    484631 * \return true - is the very triangle, false - is not
    485632 */
    486 bool BoundaryTriangleSet::IsPresentTupel(class BoundaryTriangleSet *T)
    487 {
    488   return (((endpoints[0] == T->endpoints[0])
    489             || (endpoints[0] == T->endpoints[1])
    490             || (endpoints[0] == T->endpoints[2])
    491           ) && (
    492             (endpoints[1] == T->endpoints[0])
    493             || (endpoints[1] == T->endpoints[1])
    494             || (endpoints[1] == T->endpoints[2])
    495           ) && (
    496             (endpoints[2] == T->endpoints[0])
    497             || (endpoints[2] == T->endpoints[1])
    498             || (endpoints[2] == T->endpoints[2])
    499 
    500           ));
    501 };
     633bool BoundaryTriangleSet::IsPresentTupel(const BoundaryTriangleSet * const T) const
     634{
     635  Info FunctionInfo(__func__);
     636  return (((endpoints[0] == T->endpoints[0]) || (endpoints[0] == T->endpoints[1]) || (endpoints[0] == T->endpoints[2])) && ((endpoints[1] == T->endpoints[0]) || (endpoints[1] == T->endpoints[1]) || (endpoints[1] == T->endpoints[2])) && ((endpoints[2] == T->endpoints[0]) || (endpoints[2] == T->endpoints[1]) || (endpoints[2] == T->endpoints[2])
     637
     638  ));
     639}
     640;
    502641
    503642/** Returns the endpoint which is not contained in the given \a *line.
     
    505644 * \return pointer third endpoint or NULL if line does not belong to triangle.
    506645 */
    507 class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(class BoundaryLineSet *line)
    508 {
     646class BoundaryPointSet *BoundaryTriangleSet::GetThirdEndpoint(const BoundaryLineSet * const line) const
     647{
     648  Info FunctionInfo(__func__);
    509649  // sanity check
    510650  if (!ContainsBoundaryLine(line))
    511651    return NULL;
    512   for(int i=0;i<3;i++)
     652  for (int i = 0; i < 3; i++)
    513653    if (!line->ContainsBoundaryPoint(endpoints[i]))
    514654      return endpoints[i];
    515655  // actually, that' impossible :)
    516656  return NULL;
    517 };
     657}
     658;
    518659
    519660/** Calculates the center point of the triangle.
     
    521662 * \param *center central point on return.
    522663 */
    523 void BoundaryTriangleSet::GetCenter(Vector *center)
    524 {
     664void BoundaryTriangleSet::GetCenter(Vector * const center) const
     665{
     666  Info FunctionInfo(__func__);
    525667  center->Zero();
    526   for(int i=0;i<3;i++)
     668  for (int i = 0; i < 3; i++)
    527669    center->AddVector(endpoints[i]->node->node);
    528   center->Scale(1./3.);
     670  center->Scale(1. / 3.);
     671  DoLog(1) && (Log() << Verbose(1) << "INFO: Center is at " << *center << "." << endl);
    529672}
    530673
     
    535678ostream &operator <<(ostream &ost, const BoundaryTriangleSet &a)
    536679{
    537   ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
    538       << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
     680  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << "," << a.endpoints[1]->node->Name << "," << a.endpoints[2]->node->Name << "]";
     681  //  ost << "[" << a.Nr << "|" << a.endpoints[0]->node->Name << " at " << *a.endpoints[0]->node->node << ","
     682  //      << a.endpoints[1]->node->Name << " at " << *a.endpoints[1]->node->node << "," << a.endpoints[2]->node->Name << " at " << *a.endpoints[2]->node->node << "]";
    539683  return ost;
    540 };
     684}
     685;
     686
     687// ======================================== Polygons on Boundary =================================
     688
     689/** Constructor for BoundaryPolygonSet.
     690 */
     691BoundaryPolygonSet::BoundaryPolygonSet() :
     692  Nr(-1)
     693{
     694  Info FunctionInfo(__func__);
     695}
     696;
     697
     698/** Destructor of BoundaryPolygonSet.
     699 * Just clears endpoints.
     700 * \note When removing triangles from a class Tesselation, use RemoveTesselationTriangle()
     701 */
     702BoundaryPolygonSet::~BoundaryPolygonSet()
     703{
     704  Info FunctionInfo(__func__);
     705  endpoints.clear();
     706  DoLog(1) && (Log() << Verbose(1) << "Erasing polygon Nr." << Nr << " itself." << endl);
     707}
     708;
     709
     710/** Calculates the normal vector for this triangle.
     711 * Is made unique by comparison with \a OtherVector to point in the other direction.
     712 * \param &OtherVector direction vector to make normal vector unique.
     713 * \return allocated vector in normal direction
     714 */
     715Vector * BoundaryPolygonSet::GetNormalVector(const Vector &OtherVector) const
     716{
     717  Info FunctionInfo(__func__);
     718  // get normal vector
     719  Vector TemporaryNormal;
     720  Vector *TotalNormal = new Vector;
     721  PointSet::const_iterator Runner[3];
     722  for (int i = 0; i < 3; i++) {
     723    Runner[i] = endpoints.begin();
     724    for (int j = 0; j < i; j++) { // go as much further
     725      Runner[i]++;
     726      if (Runner[i] == endpoints.end()) {
     727        DoeLog(0) && (eLog() << Verbose(0) << "There are less than three endpoints in the polygon!" << endl);
     728        performCriticalExit();
     729      }
     730    }
     731  }
     732  TotalNormal->Zero();
     733  int counter = 0;
     734  for (; Runner[2] != endpoints.end();) {
     735    TemporaryNormal.MakeNormalVector((*Runner[0])->node->node, (*Runner[1])->node->node, (*Runner[2])->node->node);
     736    for (int i = 0; i < 3; i++) // increase each of them
     737      Runner[i]++;
     738    TotalNormal->AddVector(&TemporaryNormal);
     739  }
     740  TotalNormal->Scale(1. / (double) counter);
     741
     742  // make it always point inward (any offset vector onto plane projected onto normal vector suffices)
     743  if (TotalNormal->ScalarProduct(&OtherVector) > 0.)
     744    TotalNormal->Scale(-1.);
     745  DoLog(1) && (Log() << Verbose(1) << "Normal Vector is " << *TotalNormal << "." << endl);
     746
     747  return TotalNormal;
     748}
     749;
     750
     751/** Calculates the center point of the triangle.
     752 * Is third of the sum of all endpoints.
     753 * \param *center central point on return.
     754 */
     755void BoundaryPolygonSet::GetCenter(Vector * const center) const
     756{
     757  Info FunctionInfo(__func__);
     758  center->Zero();
     759  int counter = 0;
     760  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     761    center->AddVector((*Runner)->node->node);
     762    counter++;
     763  }
     764  center->Scale(1. / (double) counter);
     765  DoLog(1) && (Log() << Verbose(1) << "Center is at " << *center << "." << endl);
     766}
     767
     768/** Checks whether the polygons contains all three endpoints of the triangle.
     769 * \param *triangle triangle to test
     770 * \return true - triangle is contained polygon, false - is not
     771 */
     772bool BoundaryPolygonSet::ContainsBoundaryTriangle(const BoundaryTriangleSet * const triangle) const
     773{
     774  Info FunctionInfo(__func__);
     775  return ContainsPresentTupel(triangle->endpoints, 3);
     776}
     777;
     778
     779/** Checks whether the polygons contains both endpoints of the line.
     780 * \param *line line to test
     781 * \return true - line is of the triangle, false - is not
     782 */
     783bool BoundaryPolygonSet::ContainsBoundaryLine(const BoundaryLineSet * const line) const
     784{
     785  Info FunctionInfo(__func__);
     786  return ContainsPresentTupel(line->endpoints, 2);
     787}
     788;
     789
     790/** Checks whether point is any of the three endpoints this triangle contains.
     791 * \param *point point to test
     792 * \return true - point is of the triangle, false - is not
     793 */
     794bool BoundaryPolygonSet::ContainsBoundaryPoint(const BoundaryPointSet * const point) const
     795{
     796  Info FunctionInfo(__func__);
     797  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     798    DoLog(0) && (Log() << Verbose(0) << "Checking against " << **Runner << endl);
     799    if (point == (*Runner)) {
     800      DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
     801      return true;
     802    }
     803  }
     804  DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
     805  return false;
     806}
     807;
     808
     809/** Checks whether point is any of the three endpoints this triangle contains.
     810 * \param *point TesselPoint to test
     811 * \return true - point is of the triangle, false - is not
     812 */
     813bool BoundaryPolygonSet::ContainsBoundaryPoint(const TesselPoint * const point) const
     814{
     815  Info FunctionInfo(__func__);
     816  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     817    if (point == (*Runner)->node) {
     818      DoLog(0) && (Log() << Verbose(0) << " Contained." << endl);
     819      return true;
     820    }
     821  DoLog(0) && (Log() << Verbose(0) << " Not contained." << endl);
     822  return false;
     823}
     824;
     825
     826/** Checks whether given array of \a *Points coincide with polygons's endpoints.
     827 * \param **Points pointer to an array of BoundaryPointSet
     828 * \param dim dimension of array
     829 * \return true - set of points is contained in polygon, false - is not
     830 */
     831bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const
     832{
     833  Info FunctionInfo(__func__);
     834  int counter = 0;
     835  DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
     836  for (int i = 0; i < dim; i++) {
     837    DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << *Points[i] << endl);
     838    if (ContainsBoundaryPoint(Points[i])) {
     839      counter++;
     840    }
     841  }
     842
     843  if (counter == dim)
     844    return true;
     845  else
     846    return false;
     847}
     848;
     849
     850/** Checks whether given PointList coincide with polygons's endpoints.
     851 * \param &endpoints PointList
     852 * \return true - set of points is contained in polygon, false - is not
     853 */
     854bool BoundaryPolygonSet::ContainsPresentTupel(const PointSet &endpoints) const
     855{
     856  Info FunctionInfo(__func__);
     857  size_t counter = 0;
     858  DoLog(1) && (Log() << Verbose(1) << "Polygon is " << *this << endl);
     859  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++) {
     860    DoLog(1) && (Log() << Verbose(1) << " Testing endpoint " << **Runner << endl);
     861    if (ContainsBoundaryPoint(*Runner))
     862      counter++;
     863  }
     864
     865  if (counter == endpoints.size())
     866    return true;
     867  else
     868    return false;
     869}
     870;
     871
     872/** Checks whether given set of \a *Points coincide with polygons's endpoints.
     873 * \param *P pointer to BoundaryPolygonSet
     874 * \return true - is the very triangle, false - is not
     875 */
     876bool BoundaryPolygonSet::ContainsPresentTupel(const BoundaryPolygonSet * const P) const
     877{
     878  return ContainsPresentTupel((const PointSet) P->endpoints);
     879}
     880;
     881
     882/** Gathers all the endpoints' triangles in a unique set.
     883 * \return set of all triangles
     884 */
     885TriangleSet * BoundaryPolygonSet::GetAllContainedTrianglesFromEndpoints() const
     886{
     887  Info FunctionInfo(__func__);
     888  pair<TriangleSet::iterator, bool> Tester;
     889  TriangleSet *triangles = new TriangleSet;
     890
     891  for (PointSet::const_iterator Runner = endpoints.begin(); Runner != endpoints.end(); Runner++)
     892    for (LineMap::const_iterator Walker = (*Runner)->lines.begin(); Walker != (*Runner)->lines.end(); Walker++)
     893      for (TriangleMap::const_iterator Sprinter = (Walker->second)->triangles.begin(); Sprinter != (Walker->second)->triangles.end(); Sprinter++) {
     894        //Log() << Verbose(0) << " Testing triangle " << *(Sprinter->second) << endl;
     895        if (ContainsBoundaryTriangle(Sprinter->second)) {
     896          Tester = triangles->insert(Sprinter->second);
     897          if (Tester.second)
     898            DoLog(0) && (Log() << Verbose(0) << "Adding triangle " << *(Sprinter->second) << endl);
     899        }
     900      }
     901
     902  DoLog(1) && (Log() << Verbose(1) << "The Polygon of " << endpoints.size() << " endpoints has " << triangles->size() << " unique triangles in total." << endl);
     903  return triangles;
     904}
     905;
     906
     907/** Fills the endpoints of this polygon from the triangles attached to \a *line.
     908 * \param *line lines with triangles attached
     909 * \return true - polygon contains endpoints, false - line was NULL
     910 */
     911bool BoundaryPolygonSet::FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line)
     912{
     913  Info FunctionInfo(__func__);
     914  pair<PointSet::iterator, bool> Tester;
     915  if (line == NULL)
     916    return false;
     917  DoLog(1) && (Log() << Verbose(1) << "Filling polygon from line " << *line << endl);
     918  for (TriangleMap::const_iterator Runner = line->triangles.begin(); Runner != line->triangles.end(); Runner++) {
     919    for (int i = 0; i < 3; i++) {
     920      Tester = endpoints.insert((Runner->second)->endpoints[i]);
     921      if (Tester.second)
     922        DoLog(1) && (Log() << Verbose(1) << "  Inserting endpoint " << *((Runner->second)->endpoints[i]) << endl);
     923    }
     924  }
     925
     926  return true;
     927}
     928;
     929
     930/** output operator for BoundaryPolygonSet.
     931 * \param &ost output stream
     932 * \param &a boundary polygon
     933 */
     934ostream &operator <<(ostream &ost, const BoundaryPolygonSet &a)
     935{
     936  ost << "[" << a.Nr << "|";
     937  for (PointSet::const_iterator Runner = a.endpoints.begin(); Runner != a.endpoints.end();) {
     938    ost << (*Runner)->node->Name;
     939    Runner++;
     940    if (Runner != a.endpoints.end())
     941      ost << ",";
     942  }
     943  ost << "]";
     944  return ost;
     945}
     946;
    541947
    542948// =========================================================== class TESSELPOINT ===========================================
     
    546952TesselPoint::TesselPoint()
    547953{
     954  //Info FunctionInfo(__func__);
    548955  node = NULL;
    549956  nr = -1;
    550   Name =  NULL;
    551 };
     957  Name = NULL;
     958}
     959;
    552960
    553961/** Destructor for class TesselPoint.
     
    555963TesselPoint::~TesselPoint()
    556964{
    557 };
     965  //Info FunctionInfo(__func__);
     966}
     967;
    558968
    559969/** Prints LCNode to screen.
    560970 */
    561 ostream & operator << (ostream &ost, const TesselPoint &a)
     971ostream & operator <<(ostream &ost, const TesselPoint &a)
    562972{
    563973  ost << "[" << (a.Name) << "|" << a.Name << " at " << *a.node << "]";
    564974  return ost;
    565 };
     975}
     976;
    566977
    567978/** Prints LCNode to screen.
    568979 */
    569 ostream & TesselPoint::operator << (ostream &ost)
    570 {
    571   ost << "[" << (Name) << "|" << this << "]";
     980ostream & TesselPoint::operator <<(ostream &ost)
     981{
     982  Info FunctionInfo(__func__);
     983  ost << "[" << (nr) << "|" << this << "]";
    572984  return ost;
    573 };
    574 
     985}
     986;
    575987
    576988// =========================================================== class POINTCLOUD ============================================
     
    580992PointCloud::PointCloud()
    581993{
    582 
    583 };
     994  //Info FunctionInfo(__func__);
     995}
     996;
    584997
    585998/** Destructor for class PointCloud.
     
    5871000PointCloud::~PointCloud()
    5881001{
    589 
    590 };
     1002  //Info FunctionInfo(__func__);
     1003}
     1004;
    5911005
    5921006// ============================ CandidateForTesselation =============================
     
    5941008/** Constructor of class CandidateForTesselation.
    5951009 */
    596 CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) {
    597   point = candidate;
    598   BaseLine = line;
     1010CandidateForTesselation::CandidateForTesselation(BoundaryLineSet* line) :
     1011  BaseLine(line), ThirdPoint(NULL), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
     1012{
     1013  Info FunctionInfo(__func__);
     1014}
     1015;
     1016
     1017/** Constructor of class CandidateForTesselation.
     1018 */
     1019CandidateForTesselation::CandidateForTesselation(TesselPoint *candidate, BoundaryLineSet* line, BoundaryPointSet* point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter) :
     1020  BaseLine(line), ThirdPoint(point), T(NULL), ShortestAngle(2. * M_PI), OtherShortestAngle(2. * M_PI)
     1021{
     1022  Info FunctionInfo(__func__);
    5991023  OptCenter.CopyVector(&OptCandidateCenter);
    6001024  OtherOptCenter.CopyVector(&OtherOptCandidateCenter);
    601 };
     1025}
     1026;
    6021027
    6031028/** Destructor for class CandidateForTesselation.
    6041029 */
    605 CandidateForTesselation::~CandidateForTesselation() {
    606   point = NULL;
    607   BaseLine = NULL;
    608 };
     1030CandidateForTesselation::~CandidateForTesselation()
     1031{
     1032}
     1033;
     1034
     1035/** Checks validity of a given sphere of a candidate line.
     1036 * Sphere must touch all candidates and the baseline endpoints and there must be no other atoms inside.
     1037 * \param RADIUS radius of sphere
     1038 * \param *LC LinkedCell structure with other atoms
     1039 * \return true - sphere is valid, false - sphere contains other points
     1040 */
     1041bool CandidateForTesselation::CheckValidity(const double RADIUS, const LinkedCell *LC) const
     1042{
     1043  Info FunctionInfo(__func__);
     1044
     1045  const double radiusSquared = RADIUS * RADIUS;
     1046  list<const Vector *> VectorList;
     1047  VectorList.push_back(&OptCenter);
     1048  //VectorList.push_back(&OtherOptCenter);  // don't check the other (wrong) center
     1049
     1050  if (!pointlist.empty())
     1051    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains candidate list and baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
     1052  else
     1053    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere with no candidates contains baseline " << *BaseLine->endpoints[0] << "<->" << *BaseLine->endpoints[1] << " only ..." << endl);
     1054  // check baseline for OptCenter and OtherOptCenter being on sphere's surface
     1055  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1056    for (int i = 0; i < 2; i++) {
     1057      const double distance = fabs((*VRunner)->DistanceSquared(BaseLine->endpoints[i]->node->node) - radiusSquared);
     1058      if (distance > HULLEPSILON) {
     1059        DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << *BaseLine->endpoints[i] << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     1060        return false;
     1061      }
     1062    }
     1063  }
     1064
     1065  // check Candidates for OptCenter and OtherOptCenter being on sphere's surface
     1066  for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
     1067    const TesselPoint *Walker = *Runner;
     1068    for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1069      const double distance = fabs((*VRunner)->DistanceSquared(Walker->node) - radiusSquared);
     1070      if (distance > HULLEPSILON) {
     1071        DoeLog(1) && (eLog() << Verbose(1) << "Candidate " << *Walker << " is out of sphere at " << *(*VRunner) << " by " << distance << "." << endl);
     1072        return false;
     1073      } else {
     1074        DoLog(1) && (Log() << Verbose(1) << "Candidate " << *Walker << " is inside by " << distance << "." << endl);
     1075      }
     1076    }
     1077  }
     1078
     1079  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
     1080  bool flag = true;
     1081  for (list<const Vector *>::const_iterator VRunner = VectorList.begin(); VRunner != VectorList.end(); ++VRunner) {
     1082    // get all points inside the sphere
     1083    TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, (*VRunner));
     1084
     1085    DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << OtherOptCenter << ":" << endl);
     1086    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     1087      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&OtherOptCenter) << "." << endl);
     1088
     1089    // remove baseline's endpoints and candidates
     1090    for (int i = 0; i < 2; i++) {
     1091      DoLog(1) && (Log() << Verbose(1) << "INFO: removing baseline tesselpoint " << *BaseLine->endpoints[i]->node << "." << endl);
     1092      ListofPoints->remove(BaseLine->endpoints[i]->node);
     1093    }
     1094    for (TesselPointList::const_iterator Runner = pointlist.begin(); Runner != pointlist.end(); ++Runner) {
     1095      DoLog(1) && (Log() << Verbose(1) << "INFO: removing candidate tesselpoint " << *(*Runner) << "." << endl);
     1096      ListofPoints->remove(*Runner);
     1097    }
     1098    if (!ListofPoints->empty()) {
     1099      DoeLog(1) && (eLog() << Verbose(1) << "CheckValidity: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
     1100      flag = false;
     1101      DoeLog(1) && (eLog() << Verbose(1) << "External atoms inside of sphere at " << *(*VRunner) << ":" << endl);
     1102      for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     1103        DoeLog(1) && (eLog() << Verbose(1) << "  " << *(*Runner) << endl);
     1104    }
     1105    delete (ListofPoints);
     1106
     1107    // check with animate_sphere.tcl VMD script
     1108    if (ThirdPoint != NULL) {
     1109      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " " << ThirdPoint->Nr + 1 << " " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl);
     1110    } else {
     1111      DoLog(1) && (Log() << Verbose(1) << "Check by: ... missing third point ..." << endl);
     1112      DoLog(1) && (Log() << Verbose(1) << "Check by: animate_sphere 0 " << BaseLine->endpoints[0]->Nr + 1 << " " << BaseLine->endpoints[1]->Nr + 1 << " ??? " << RADIUS << " " << OldCenter.x[0] << " " << OldCenter.x[1] << " " << OldCenter.x[2] << " " << (*VRunner)->x[0] << " " << (*VRunner)->x[1] << " " << (*VRunner)->x[2] << endl);
     1113    }
     1114  }
     1115  return flag;
     1116}
     1117;
     1118
     1119/** output operator for CandidateForTesselation.
     1120 * \param &ost output stream
     1121 * \param &a boundary line
     1122 */
     1123ostream & operator <<(ostream &ost, const CandidateForTesselation &a)
     1124{
     1125  ost << "[" << a.BaseLine->Nr << "|" << a.BaseLine->endpoints[0]->node->Name << "," << a.BaseLine->endpoints[1]->node->Name << "] with ";
     1126  if (a.pointlist.empty())
     1127    ost << "no candidate.";
     1128  else {
     1129    ost << "candidate";
     1130    if (a.pointlist.size() != 1)
     1131      ost << "s ";
     1132    else
     1133      ost << " ";
     1134    for (TesselPointList::const_iterator Runner = a.pointlist.begin(); Runner != a.pointlist.end(); Runner++)
     1135      ost << *(*Runner) << " ";
     1136    ost << " at angle " << (a.ShortestAngle) << ".";
     1137  }
     1138
     1139  return ost;
     1140}
     1141;
    6091142
    6101143// =========================================================== class TESSELATION ===========================================
     
    6121145/** Constructor of class Tesselation.
    6131146 */
    614 Tesselation::Tesselation()
    615 {
    616   PointsOnBoundaryCount = 0;
    617   LinesOnBoundaryCount = 0;
    618   TrianglesOnBoundaryCount = 0;
    619   InternalPointer = PointsOnBoundary.begin();
    620   LastTriangle = NULL;
    621   TriangleFilesWritten = 0;
     1147Tesselation::Tesselation() :
     1148  PointsOnBoundaryCount(0), LinesOnBoundaryCount(0), TrianglesOnBoundaryCount(0), LastTriangle(NULL), TriangleFilesWritten(0), InternalPointer(PointsOnBoundary.begin())
     1149{
     1150  Info FunctionInfo(__func__);
    6221151}
    6231152;
     
    6281157Tesselation::~Tesselation()
    6291158{
    630   Log() << Verbose(1) << "Free'ing TesselStruct ... " << endl;
     1159  Info FunctionInfo(__func__);
     1160  DoLog(0) && (Log() << Verbose(0) << "Free'ing TesselStruct ... " << endl);
    6311161  for (TriangleMap::iterator runner = TrianglesOnBoundary.begin(); runner != TrianglesOnBoundary.end(); runner++) {
    6321162    if (runner->second != NULL) {
     
    6341164      runner->second = NULL;
    6351165    } else
    636       eLog() << Verbose(1) << "ERROR: The triangle " << runner->first << " has already been free'd." << endl;
    637   }
    638   Log() << Verbose(1) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl;
     1166      DoeLog(1) && (eLog() << Verbose(1) << "The triangle " << runner->first << " has already been free'd." << endl);
     1167  }
     1168  DoLog(0) && (Log() << Verbose(0) << "This envelope was written to file " << TriangleFilesWritten << " times(s)." << endl);
    6391169}
    6401170;
     
    6421172/** PointCloud implementation of GetCenter
    6431173 * Uses PointsOnBoundary and STL stuff.
    644  */   
     1174 */
    6451175Vector * Tesselation::GetCenter(ofstream *out) const
    6461176{
    647   Vector *Center = new Vector(0.,0.,0.);
    648   int num=0;
     1177  Info FunctionInfo(__func__);
     1178  Vector *Center = new Vector(0., 0., 0.);
     1179  int num = 0;
    6491180  for (GoToFirst(); (!IsEnd()); GoToNext()) {
    6501181    Center->AddVector(GetPoint()->node);
    6511182    num++;
    6521183  }
    653   Center->Scale(1./num);
     1184  Center->Scale(1. / num);
    6541185  return Center;
    655 };
     1186}
     1187;
    6561188
    6571189/** PointCloud implementation of GoPoint
    6581190 * Uses PointsOnBoundary and STL stuff.
    659  */   
     1191 */
    6601192TesselPoint * Tesselation::GetPoint() const
    6611193{
     1194  Info FunctionInfo(__func__);
    6621195  return (InternalPointer->second->node);
    663 };
     1196}
     1197;
    6641198
    6651199/** PointCloud implementation of GetTerminalPoint.
    6661200 * Uses PointsOnBoundary and STL stuff.
    667  */   
     1201 */
    6681202TesselPoint * Tesselation::GetTerminalPoint() const
    6691203{
     1204  Info FunctionInfo(__func__);
    6701205  PointMap::const_iterator Runner = PointsOnBoundary.end();
    6711206  Runner--;
    6721207  return (Runner->second->node);
    673 };
     1208}
     1209;
    6741210
    6751211/** PointCloud implementation of GoToNext.
    6761212 * Uses PointsOnBoundary and STL stuff.
    677  */   
     1213 */
    6781214void Tesselation::GoToNext() const
    6791215{
     1216  Info FunctionInfo(__func__);
    6801217  if (InternalPointer != PointsOnBoundary.end())
    6811218    InternalPointer++;
    682 };
     1219}
     1220;
    6831221
    6841222/** PointCloud implementation of GoToPrevious.
    6851223 * Uses PointsOnBoundary and STL stuff.
    686  */   
     1224 */
    6871225void Tesselation::GoToPrevious() const
    6881226{
     1227  Info FunctionInfo(__func__);
    6891228  if (InternalPointer != PointsOnBoundary.begin())
    6901229    InternalPointer--;
    691 };
     1230}
     1231;
    6921232
    6931233/** PointCloud implementation of GoToFirst.
    6941234 * Uses PointsOnBoundary and STL stuff.
    695  */   
     1235 */
    6961236void Tesselation::GoToFirst() const
    6971237{
     1238  Info FunctionInfo(__func__);
    6981239  InternalPointer = PointsOnBoundary.begin();
    699 };
     1240}
     1241;
    7001242
    7011243/** PointCloud implementation of GoToLast.
     
    7041246void Tesselation::GoToLast() const
    7051247{
     1248  Info FunctionInfo(__func__);
    7061249  InternalPointer = PointsOnBoundary.end();
    7071250  InternalPointer--;
    708 };
     1251}
     1252;
    7091253
    7101254/** PointCloud implementation of IsEmpty.
    7111255 * Uses PointsOnBoundary and STL stuff.
    712  */   
     1256 */
    7131257bool Tesselation::IsEmpty() const
    7141258{
     1259  Info FunctionInfo(__func__);
    7151260  return (PointsOnBoundary.empty());
    716 };
     1261}
     1262;
    7171263
    7181264/** PointCloud implementation of IsLast.
    7191265 * Uses PointsOnBoundary and STL stuff.
    720  */   
     1266 */
    7211267bool Tesselation::IsEnd() const
    7221268{
     1269  Info FunctionInfo(__func__);
    7231270  return (InternalPointer == PointsOnBoundary.end());
    724 };
    725 
     1271}
     1272;
    7261273
    7271274/** Gueses first starting triangle of the convex envelope.
     
    7301277 * \param PointsOnBoundary set of boundary points defining the convex envelope of the cluster
    7311278 */
    732 void
    733 Tesselation::GuessStartingTriangle()
    734 {
     1279void Tesselation::GuessStartingTriangle()
     1280{
     1281  Info FunctionInfo(__func__);
    7351282  // 4b. create a starting triangle
    7361283  // 4b1. create all distances
     
    7421289
    7431290  // with A chosen, take each pair B,C and sort
    744   if (A != PointsOnBoundary.end())
    745     {
    746       B = A;
    747       B++;
    748       for (; B != PointsOnBoundary.end(); B++)
    749         {
    750           C = B;
    751           C++;
    752           for (; C != PointsOnBoundary.end(); C++)
    753             {
    754               tmp = A->second->node->node->DistanceSquared(B->second->node->node);
    755               distance = tmp * tmp;
    756               tmp = A->second->node->node->DistanceSquared(C->second->node->node);
    757               distance += tmp * tmp;
    758               tmp = B->second->node->node->DistanceSquared(C->second->node->node);
    759               distance += tmp * tmp;
    760               DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
    761             }
    762         }
    763     }
     1291  if (A != PointsOnBoundary.end()) {
     1292    B = A;
     1293    B++;
     1294    for (; B != PointsOnBoundary.end(); B++) {
     1295      C = B;
     1296      C++;
     1297      for (; C != PointsOnBoundary.end(); C++) {
     1298        tmp = A->second->node->node->DistanceSquared(B->second->node->node);
     1299        distance = tmp * tmp;
     1300        tmp = A->second->node->node->DistanceSquared(C->second->node->node);
     1301        distance += tmp * tmp;
     1302        tmp = B->second->node->node->DistanceSquared(C->second->node->node);
     1303        distance += tmp * tmp;
     1304        DistanceMMap.insert(DistanceMultiMapPair(distance, pair<PointMap::iterator, PointMap::iterator> (B, C)));
     1305      }
     1306    }
     1307  }
    7641308  //    // listing distances
    7651309  //    Log() << Verbose(1) << "Listing DistanceMMap:";
     
    7711315  // 1. we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
    7721316  DistanceMultiMap::iterator baseline = DistanceMMap.begin();
    773   for (; baseline != DistanceMMap.end(); baseline++)
    774     {
    775       // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
    776       // 2. next, we have to check whether all points reside on only one side of the triangle
    777       // 3. construct plane vector
    778       PlaneVector.MakeNormalVector(A->second->node->node,
    779           baseline->second.first->second->node->node,
    780           baseline->second.second->second->node->node);
    781       Log() << Verbose(2) << "Plane vector of candidate triangle is ";
    782       PlaneVector.Output();
    783       Log() << Verbose(0) << endl;
    784       // 4. loop over all points
    785       double sign = 0.;
    786       PointMap::iterator checker = PointsOnBoundary.begin();
    787       for (; checker != PointsOnBoundary.end(); checker++)
    788         {
    789           // (neglecting A,B,C)
    790           if ((checker == A) || (checker == baseline->second.first) || (checker
    791               == baseline->second.second))
    792             continue;
    793           // 4a. project onto plane vector
    794           TrialVector.CopyVector(checker->second->node->node);
    795           TrialVector.SubtractVector(A->second->node->node);
    796           distance = TrialVector.ScalarProduct(&PlaneVector);
    797           if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
    798             continue;
    799           Log() << Verbose(3) << "Projection of " << checker->second->node->Name
    800               << " yields distance of " << distance << "." << endl;
    801           tmp = distance / fabs(distance);
    802           // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
    803           if ((sign != 0) && (tmp != sign))
    804             {
    805               // 4c. If so, break 4. loop and continue with next candidate in 1. loop
    806               Log() << Verbose(2) << "Current candidates: "
    807                   << A->second->node->Name << ","
    808                   << baseline->second.first->second->node->Name << ","
    809                   << baseline->second.second->second->node->Name << " leaves "
    810                   << checker->second->node->Name << " outside the convex hull."
    811                   << endl;
    812               break;
    813             }
    814           else
    815             { // note the sign for later
    816               Log() << Verbose(2) << "Current candidates: "
    817                   << A->second->node->Name << ","
    818                   << baseline->second.first->second->node->Name << ","
    819                   << baseline->second.second->second->node->Name << " leave "
    820                   << checker->second->node->Name << " inside the convex hull."
    821                   << endl;
    822               sign = tmp;
    823             }
    824           // 4d. Check whether the point is inside the triangle (check distance to each node
    825           tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
    826           int innerpoint = 0;
    827           if ((tmp < A->second->node->node->DistanceSquared(
    828               baseline->second.first->second->node->node)) && (tmp
    829               < A->second->node->node->DistanceSquared(
    830                   baseline->second.second->second->node->node)))
    831             innerpoint++;
    832           tmp = checker->second->node->node->DistanceSquared(
    833               baseline->second.first->second->node->node);
    834           if ((tmp < baseline->second.first->second->node->node->DistanceSquared(
    835               A->second->node->node)) && (tmp
    836               < baseline->second.first->second->node->node->DistanceSquared(
    837                   baseline->second.second->second->node->node)))
    838             innerpoint++;
    839           tmp = checker->second->node->node->DistanceSquared(
    840               baseline->second.second->second->node->node);
    841           if ((tmp < baseline->second.second->second->node->node->DistanceSquared(
    842               baseline->second.first->second->node->node)) && (tmp
    843               < baseline->second.second->second->node->node->DistanceSquared(
    844                   A->second->node->node)))
    845             innerpoint++;
    846           // 4e. If so, break 4. loop and continue with next candidate in 1. loop
    847           if (innerpoint == 3)
    848             break;
    849         }
    850       // 5. come this far, all on same side? Then break 1. loop and construct triangle
    851       if (checker == PointsOnBoundary.end())
    852         {
    853           Log() << Verbose(0) << "Looks like we have a candidate!" << endl;
    854           break;
    855         }
    856     }
    857   if (baseline != DistanceMMap.end())
    858     {
    859       BPS[0] = baseline->second.first->second;
    860       BPS[1] = baseline->second.second->second;
    861       BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    862       BPS[0] = A->second;
    863       BPS[1] = baseline->second.second->second;
    864       BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    865       BPS[0] = baseline->second.first->second;
    866       BPS[1] = A->second;
    867       BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    868 
    869       // 4b3. insert created triangle
    870       BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    871       TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    872       TrianglesOnBoundaryCount++;
    873       for (int i = 0; i < NDIM; i++)
    874         {
    875           LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
    876           LinesOnBoundaryCount++;
    877         }
    878 
    879       Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl;
    880     }
    881   else
    882     {
    883       Log() << Verbose(1) << "No starting triangle found." << endl;
    884       exit(255);
    885     }
     1317  for (; baseline != DistanceMMap.end(); baseline++) {
     1318    // we take from the smallest sum of squared distance as the base line BC (with peak A) onward as the triangle candidate
     1319    // 2. next, we have to check whether all points reside on only one side of the triangle
     1320    // 3. construct plane vector
     1321    PlaneVector.MakeNormalVector(A->second->node->node, baseline->second.first->second->node->node, baseline->second.second->second->node->node);
     1322    DoLog(2) && (Log() << Verbose(2) << "Plane vector of candidate triangle is " << PlaneVector << endl);
     1323    // 4. loop over all points
     1324    double sign = 0.;
     1325    PointMap::iterator checker = PointsOnBoundary.begin();
     1326    for (; checker != PointsOnBoundary.end(); checker++) {
     1327      // (neglecting A,B,C)
     1328      if ((checker == A) || (checker == baseline->second.first) || (checker == baseline->second.second))
     1329        continue;
     1330      // 4a. project onto plane vector
     1331      TrialVector.CopyVector(checker->second->node->node);
     1332      TrialVector.SubtractVector(A->second->node->node);
     1333      distance = TrialVector.ScalarProduct(&PlaneVector);
     1334      if (fabs(distance) < 1e-4) // we need to have a small epsilon around 0 which is still ok
     1335        continue;
     1336      DoLog(2) && (Log() << Verbose(2) << "Projection of " << checker->second->node->Name << " yields distance of " << distance << "." << endl);
     1337      tmp = distance / fabs(distance);
     1338      // 4b. Any have different sign to than before? (i.e. would lie outside convex hull with this starting triangle)
     1339      if ((sign != 0) && (tmp != sign)) {
     1340        // 4c. If so, break 4. loop and continue with next candidate in 1. loop
     1341        DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leaves " << checker->second->node->Name << " outside the convex hull." << endl);
     1342        break;
     1343      } else { // note the sign for later
     1344        DoLog(2) && (Log() << Verbose(2) << "Current candidates: " << A->second->node->Name << "," << baseline->second.first->second->node->Name << "," << baseline->second.second->second->node->Name << " leave " << checker->second->node->Name << " inside the convex hull." << endl);
     1345        sign = tmp;
     1346      }
     1347      // 4d. Check whether the point is inside the triangle (check distance to each node
     1348      tmp = checker->second->node->node->DistanceSquared(A->second->node->node);
     1349      int innerpoint = 0;
     1350      if ((tmp < A->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < A->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))
     1351        innerpoint++;
     1352      tmp = checker->second->node->node->DistanceSquared(baseline->second.first->second->node->node);
     1353      if ((tmp < baseline->second.first->second->node->node->DistanceSquared(A->second->node->node)) && (tmp < baseline->second.first->second->node->node->DistanceSquared(baseline->second.second->second->node->node)))
     1354        innerpoint++;
     1355      tmp = checker->second->node->node->DistanceSquared(baseline->second.second->second->node->node);
     1356      if ((tmp < baseline->second.second->second->node->node->DistanceSquared(baseline->second.first->second->node->node)) && (tmp < baseline->second.second->second->node->node->DistanceSquared(A->second->node->node)))
     1357        innerpoint++;
     1358      // 4e. If so, break 4. loop and continue with next candidate in 1. loop
     1359      if (innerpoint == 3)
     1360        break;
     1361    }
     1362    // 5. come this far, all on same side? Then break 1. loop and construct triangle
     1363    if (checker == PointsOnBoundary.end()) {
     1364      DoLog(2) && (Log() << Verbose(2) << "Looks like we have a candidate!" << endl);
     1365      break;
     1366    }
     1367  }
     1368  if (baseline != DistanceMMap.end()) {
     1369    BPS[0] = baseline->second.first->second;
     1370    BPS[1] = baseline->second.second->second;
     1371    BLS[0] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1372    BPS[0] = A->second;
     1373    BPS[1] = baseline->second.second->second;
     1374    BLS[1] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1375    BPS[0] = baseline->second.first->second;
     1376    BPS[1] = A->second;
     1377    BLS[2] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
     1378
     1379    // 4b3. insert created triangle
     1380    BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     1381    TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
     1382    TrianglesOnBoundaryCount++;
     1383    for (int i = 0; i < NDIM; i++) {
     1384      LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BTS->lines[i]));
     1385      LinesOnBoundaryCount++;
     1386    }
     1387
     1388    DoLog(1) && (Log() << Verbose(1) << "Starting triangle is " << *BTS << "." << endl);
     1389  } else {
     1390    DoeLog(0) && (eLog() << Verbose(0) << "No starting triangle found." << endl);
     1391  }
    8861392}
    8871393;
     
    9021408void Tesselation::TesselateOnBoundary(const PointCloud * const cloud)
    9031409{
     1410  Info FunctionInfo(__func__);
    9041411  bool flag;
    9051412  PointMap::iterator winner;
     
    9201427        // get peak point with respect to this base line's only triangle
    9211428        BTS = baseline->second->triangles.begin()->second; // there is only one triangle so far
    922         Log() << Verbose(2) << "Current baseline is between " << *(baseline->second) << "." << endl;
     1429        DoLog(0) && (Log() << Verbose(0) << "Current baseline is between " << *(baseline->second) << "." << endl);
    9231430        for (int i = 0; i < 3; i++)
    9241431          if ((BTS->endpoints[i] != baseline->second->endpoints[0]) && (BTS->endpoints[i] != baseline->second->endpoints[1]))
    9251432            peak = BTS->endpoints[i];
    926         Log() << Verbose(3) << " and has peak " << *peak << "." << endl;
     1433        DoLog(1) && (Log() << Verbose(1) << " and has peak " << *peak << "." << endl);
    9271434
    9281435        // prepare some auxiliary vectors
     
    9391446          CenterVector.AddVector(BTS->endpoints[i]->node->node);
    9401447        CenterVector.Scale(1. / 3.);
    941         Log() << Verbose(4) << "CenterVector of base triangle is " << CenterVector << endl;
     1448        DoLog(2) && (Log() << Verbose(2) << "CenterVector of base triangle is " << CenterVector << endl);
    9421449
    9431450        // normal vector of triangle
     
    9461453        BTS->GetNormalVector(NormalVector);
    9471454        NormalVector.CopyVector(&BTS->NormalVector);
    948         Log() << Verbose(4) << "NormalVector of base triangle is " << NormalVector << endl;
     1455        DoLog(2) && (Log() << Verbose(2) << "NormalVector of base triangle is " << NormalVector << endl);
    9491456
    9501457        // vector in propagation direction (out of triangle)
     
    9531460        TempVector.CopyVector(&CenterVector);
    9541461        TempVector.SubtractVector(baseline->second->endpoints[0]->node->node); // TempVector is vector on triangle plane pointing from one baseline egde towards center!
    955         //Log() << Verbose(2) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
     1462        //Log() << Verbose(0) << "Projection of propagation onto temp: " << PropagationVector.Projection(&TempVector) << "." << endl;
    9561463        if (PropagationVector.ScalarProduct(&TempVector) > 0) // make sure normal propagation vector points outward from baseline
    9571464          PropagationVector.Scale(-1.);
    958         Log() << Verbose(4) << "PropagationVector of base triangle is " << PropagationVector << endl;
     1465        DoLog(2) && (Log() << Verbose(2) << "PropagationVector of base triangle is " << PropagationVector << endl);
    9591466        winner = PointsOnBoundary.end();
    9601467
     
    9621469        for (PointMap::iterator target = PointsOnBoundary.begin(); target != PointsOnBoundary.end(); target++) {
    9631470          if ((target->second != baseline->second->endpoints[0]) && (target->second != baseline->second->endpoints[1])) { // don't take the same endpoints
    964             Log() << Verbose(3) << "Target point is " << *(target->second) << ":" << endl;
     1471            DoLog(1) && (Log() << Verbose(1) << "Target point is " << *(target->second) << ":" << endl);
    9651472
    9661473            // first check direction, so that triangles don't intersect
     
    9691476            VirtualNormalVector.ProjectOntoPlane(&NormalVector);
    9701477            TempAngle = VirtualNormalVector.Angle(&PropagationVector);
    971             Log() << Verbose(4) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl;
    972             if (TempAngle > (M_PI/2.)) { // no bends bigger than Pi/2 (90 degrees)
    973               Log() << Verbose(4) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl;
     1478            DoLog(2) && (Log() << Verbose(2) << "VirtualNormalVector is " << VirtualNormalVector << " and PropagationVector is " << PropagationVector << "." << endl);
     1479            if (TempAngle > (M_PI / 2.)) { // no bends bigger than Pi/2 (90 degrees)
     1480              DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", bad direction!" << endl);
    9741481              continue;
    9751482            } else
    976               Log() << Verbose(4) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl;
     1483              DoLog(2) && (Log() << Verbose(2) << "Angle on triangle plane between propagation direction and base line to " << *(target->second) << " is " << TempAngle << ", good direction!" << endl);
    9771484
    9781485            // check first and second endpoint (if any connecting line goes to target has at least not more than 1 triangle)
     
    9801487            LineChecker[1] = baseline->second->endpoints[1]->lines.find(target->first);
    9811488            if (((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[0]->second->triangles.size() == 2))) {
    982               Log() << Verbose(4) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl;
     1489              DoLog(2) && (Log() << Verbose(2) << *(baseline->second->endpoints[0]) << " has line " << *(LineChecker[0]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[0]->second->triangles.size() << " triangles." << endl);
    9831490              continue;
    9841491            }
    9851492            if (((LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (LineChecker[1]->second->triangles.size() == 2))) {
    986               Log() << Verbose(4) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl;
     1493              DoLog(2) && (Log() << Verbose(2) << *(baseline->second->endpoints[1]) << " has line " << *(LineChecker[1]->second) << " to " << *(target->second) << " as endpoint with " << LineChecker[1]->second->triangles.size() << " triangles." << endl);
    9871494              continue;
    9881495            }
     
    9901497            // check whether the envisaged triangle does not already exist (if both lines exist and have same endpoint)
    9911498            if ((((LineChecker[0] != baseline->second->endpoints[0]->lines.end()) && (LineChecker[1] != baseline->second->endpoints[1]->lines.end()) && (GetCommonEndpoint(LineChecker[0]->second, LineChecker[1]->second) == peak)))) {
    992               Log() << Verbose(4) << "Current target is peak!" << endl;
     1499              DoLog(4) && (Log() << Verbose(4) << "Current target is peak!" << endl);
    9931500              continue;
    9941501            }
     
    10011508            helper.ProjectOntoPlane(&TempVector);
    10021509            if (fabs(helper.NormSquared()) < MYEPSILON) {
    1003               Log() << Verbose(4) << "Chosen set of vectors is linear dependent." << endl;
     1510              DoLog(2) && (Log() << Verbose(2) << "Chosen set of vectors is linear dependent." << endl);
    10041511              continue;
    10051512            }
     
    10111518            TempVector.AddVector(baseline->second->endpoints[1]->node->node);
    10121519            TempVector.AddVector(target->second->node->node);
    1013             TempVector.Scale(1./3.);
     1520            TempVector.Scale(1. / 3.);
    10141521            TempVector.SubtractVector(Center);
    10151522            // make it always point outward
     
    10181525            // calculate angle
    10191526            TempAngle = NormalVector.Angle(&VirtualNormalVector);
    1020             Log() << Verbose(4) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl;
     1527            DoLog(2) && (Log() << Verbose(2) << "NormalVector is " << VirtualNormalVector << " and the angle is " << TempAngle << "." << endl);
    10211528            if ((SmallestAngle - TempAngle) > MYEPSILON) { // set to new possible winner
    10221529              SmallestAngle = TempAngle;
    10231530              winner = target;
    1024               Log() << Verbose(4) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1531              DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
    10251532            } else if (fabs(SmallestAngle - TempAngle) < MYEPSILON) { // check the angle to propagation, both possible targets are in one plane! (their normals have same angle)
    10261533              // hence, check the angles to some normal direction from our base line but in this common plane of both targets...
     
    10401547                SmallestAngle = TempAngle;
    10411548                winner = target;
    1042                 Log() << Verbose(4) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl;
     1549                DoLog(2) && (Log() << Verbose(2) << "New winner " << *winner->second->node << " due to smaller angle " << TempAngle << " to propagation direction." << endl);
    10431550              } else
    1044                 Log() << Verbose(4) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl;
     1551                DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle to propagation direction." << endl);
    10451552            } else
    1046               Log() << Verbose(4) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl;
     1553              DoLog(2) && (Log() << Verbose(2) << "Keeping old winner " << *winner->second->node << " due to smaller angle between normal vectors." << endl);
    10471554          }
    10481555        } // end of loop over all boundary points
     
    10501557        // 5b. The point of the above whose triangle has the greatest angle with the triangle the current line belongs to (it only belongs to one, remember!): New triangle
    10511558        if (winner != PointsOnBoundary.end()) {
    1052           Log() << Verbose(2) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl;
     1559          DoLog(0) && (Log() << Verbose(0) << "Winning target point is " << *(winner->second) << " with angle " << SmallestAngle << "." << endl);
    10531560          // create the lins of not yet present
    10541561          BLS[0] = baseline->second;
     
    10801587          TrianglesOnBoundaryCount++;
    10811588        } else {
    1082           Log() << Verbose(1) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl;
     1589          DoeLog(2) && (eLog() << Verbose(2) << "I could not determine a winner for this baseline " << *(baseline->second) << "." << endl);
    10831590        }
    10841591
    10851592        // 5d. If the set of lines is not yet empty, go to 5. and continue
    10861593      } else
    1087         Log() << Verbose(2) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl;
     1594        DoLog(0) && (Log() << Verbose(0) << "Baseline candidate " << *(baseline->second) << " has a triangle count of " << baseline->second->triangles.size() << "." << endl);
    10881595  } while (flag);
    10891596
    10901597  // exit
    1091   delete(Center);
    1092 };
     1598  delete (Center);
     1599}
     1600;
    10931601
    10941602/** Inserts all points outside of the tesselated surface into it by adding new triangles.
     
    11001608bool Tesselation::InsertStraddlingPoints(const PointCloud *cloud, const LinkedCell *LC)
    11011609{
     1610  Info FunctionInfo(__func__);
    11021611  Vector Intersection, Normal;
    11031612  TesselPoint *Walker = NULL;
    11041613  Vector *Center = cloud->GetCenter();
    1105   list<BoundaryTriangleSet*> *triangles = NULL;
     1614  TriangleList *triangles = NULL;
    11061615  bool AddFlag = false;
    11071616  LinkedCell *BoundaryPoints = NULL;
    11081617
    1109   Log() << Verbose(1) << "Begin of InsertStraddlingPoints" << endl;
    1110 
    11111618  cloud->GoToFirst();
    11121619  BoundaryPoints = new LinkedCell(this, 5.);
    1113   while (!cloud->IsEnd()) {  // we only have to go once through all points, as boundary can become only bigger
     1620  while (!cloud->IsEnd()) { // we only have to go once through all points, as boundary can become only bigger
    11141621    if (AddFlag) {
    1115       delete(BoundaryPoints);
     1622      delete (BoundaryPoints);
    11161623      BoundaryPoints = new LinkedCell(this, 5.);
    11171624      AddFlag = false;
    11181625    }
    11191626    Walker = cloud->GetPoint();
    1120     Log() << Verbose(2) << "Current point is " << *Walker << "." << endl;
     1627    DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Walker << "." << endl);
    11211628    // get the next triangle
    1122     triangles = FindClosestTrianglesToPoint(Walker->node, BoundaryPoints);
     1629    triangles = FindClosestTrianglesToVector(Walker->node, BoundaryPoints);
    11231630    BTS = triangles->front();
    11241631    if ((triangles == NULL) || (BTS->ContainsBoundaryPoint(Walker))) {
    1125       Log() << Verbose(2) << "No triangles found, probably a tesselation point itself." << endl;
     1632      DoLog(0) && (Log() << Verbose(0) << "No triangles found, probably a tesselation point itself." << endl);
    11261633      cloud->GoToNext();
    11271634      continue;
    11281635    } else {
    11291636    }
    1130     Log() << Verbose(2) << "Closest triangle is " << *BTS << "." << endl;
     1637    DoLog(0) && (Log() << Verbose(0) << "Closest triangle is " << *BTS << "." << endl);
    11311638    // get the intersection point
    11321639    if (BTS->GetIntersectionInsideTriangle(Center, Walker->node, &Intersection)) {
    1133       Log() << Verbose(2) << "We have an intersection at " << Intersection << "." << endl;
     1640      DoLog(0) && (Log() << Verbose(0) << "We have an intersection at " << Intersection << "." << endl);
    11341641      // we have the intersection, check whether in- or outside of boundary
    11351642      if ((Center->DistanceSquared(Walker->node) - Center->DistanceSquared(&Intersection)) < -MYEPSILON) {
    11361643        // inside, next!
    1137         Log() << Verbose(2) << *Walker << " is inside wrt triangle " << *BTS << "." << endl;
     1644        DoLog(0) && (Log() << Verbose(0) << *Walker << " is inside wrt triangle " << *BTS << "." << endl);
    11381645      } else {
    11391646        // outside!
    1140         Log() << Verbose(2) << *Walker << " is outside wrt triangle " << *BTS << "." << endl;
     1647        DoLog(0) && (Log() << Verbose(0) << *Walker << " is outside wrt triangle " << *BTS << "." << endl);
    11411648        class BoundaryLineSet *OldLines[3], *NewLines[3];
    11421649        class BoundaryPointSet *OldPoints[3], *NewPoint;
    11431650        // store the three old lines and old points
    1144         for (int i=0;i<3;i++) {
     1651        for (int i = 0; i < 3; i++) {
    11451652          OldLines[i] = BTS->lines[i];
    11461653          OldPoints[i] = BTS->endpoints[i];
     
    11481655        Normal.CopyVector(&BTS->NormalVector);
    11491656        // add Walker to boundary points
    1150         Log() << Verbose(2) << "Adding " << *Walker << " to BoundaryPoints." << endl;
     1657        DoLog(0) && (Log() << Verbose(0) << "Adding " << *Walker << " to BoundaryPoints." << endl);
    11511658        AddFlag = true;
    1152         if (AddBoundaryPoint(Walker,0))
     1659        if (AddBoundaryPoint(Walker, 0))
    11531660          NewPoint = BPS[0];
    11541661        else
    11551662          continue;
    11561663        // remove triangle
    1157         Log() << Verbose(2) << "Erasing triangle " << *BTS << "." << endl;
     1664        DoLog(0) && (Log() << Verbose(0) << "Erasing triangle " << *BTS << "." << endl);
    11581665        TrianglesOnBoundary.erase(BTS->Nr);
    1159         delete(BTS);
     1666        delete (BTS);
    11601667        // create three new boundary lines
    1161         for (int i=0;i<3;i++) {
     1668        for (int i = 0; i < 3; i++) {
    11621669          BPS[0] = NewPoint;
    11631670          BPS[1] = OldPoints[i];
    11641671          NewLines[i] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);
    1165           Log() << Verbose(3) << "Creating new line " << *NewLines[i] << "." << endl;
     1672          DoLog(1) && (Log() << Verbose(1) << "Creating new line " << *NewLines[i] << "." << endl);
    11661673          LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, NewLines[i])); // no need for check for unique insertion as BPS[0] is definitely a new one
    11671674          LinesOnBoundaryCount++;
    11681675        }
    11691676        // create three new triangle with new point
    1170         for (int i=0;i<3;i++) { // find all baselines
     1677        for (int i = 0; i < 3; i++) { // find all baselines
    11711678          BLS[0] = OldLines[i];
    11721679          int n = 1;
    1173           for (int j=0;j<3;j++) {
     1680          for (int j = 0; j < 3; j++) {
    11741681            if (NewLines[j]->IsConnectedTo(BLS[0])) {
    1175               if (n>2) {
    1176                 Log() << Verbose(1) << "ERROR: " << BLS[0] << " connects to all of the new lines?!" << endl;
     1682              if (n > 2) {
     1683                DoeLog(2) && (eLog() << Verbose(2) << BLS[0] << " connects to all of the new lines?!" << endl);
    11771684                return false;
    11781685              } else
     
    11851692          BTS->GetNormalVector(Normal);
    11861693          Normal.Scale(-1.);
    1187           Log() << Verbose(2) << "Created new triangle " << *BTS << "." << endl;
     1694          DoLog(0) && (Log() << Verbose(0) << "Created new triangle " << *BTS << "." << endl);
    11881695          TrianglesOnBoundary.insert(TrianglePair(TrianglesOnBoundaryCount, BTS));
    11891696          TrianglesOnBoundaryCount++;
     
    11911698      }
    11921699    } else { // something is wrong with FindClosestTriangleToPoint!
    1193       Log() << Verbose(1) << "ERROR: The closest triangle did not produce an intersection!" << endl;
     1700      DoeLog(1) && (eLog() << Verbose(1) << "The closest triangle did not produce an intersection!" << endl);
    11941701      return false;
    11951702    }
     
    11981705
    11991706  // exit
    1200   delete(Center);
    1201   Log() << Verbose(1) << "End of InsertStraddlingPoints" << endl;
     1707  delete (Center);
    12021708  return true;
    1203 };
     1709}
     1710;
    12041711
    12051712/** Adds a point to the tesselation::PointsOnBoundary list.
     
    12101717bool Tesselation::AddBoundaryPoint(TesselPoint * Walker, const int n)
    12111718{
     1719  Info FunctionInfo(__func__);
    12121720  PointTestPair InsertUnique;
    12131721  BPS[n] = new class BoundaryPointSet(Walker);
     
    12171725    return true;
    12181726  } else {
    1219     delete(BPS[n]);
     1727    delete (BPS[n]);
    12201728    BPS[n] = InsertUnique.first->second;
    12211729    return false;
     
    12311739void Tesselation::AddTesselationPoint(TesselPoint* Candidate, const int n)
    12321740{
     1741  Info FunctionInfo(__func__);
    12331742  PointTestPair InsertUnique;
    12341743  TPS[n] = new class BoundaryPointSet(Candidate);
     
    12381747  } else {
    12391748    delete TPS[n];
    1240     Log() << Verbose(4) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl;
     1749    DoLog(0) && (Log() << Verbose(0) << "Node " << *((InsertUnique.first)->second->node) << " is already present in PointsOnBoundary." << endl);
    12411750    TPS[n] = (InsertUnique.first)->second;
    12421751  }
     1752}
     1753;
     1754
     1755/** Sets point to a present Tesselation::PointsOnBoundary.
     1756 * Tesselation::TPS is set to the existing one or NULL if not found.
     1757 * @param Candidate point to set to
     1758 * @param n index for this point in Tesselation::TPS array
     1759 */
     1760void Tesselation::SetTesselationPoint(TesselPoint* Candidate, const int n) const
     1761{
     1762  Info FunctionInfo(__func__);
     1763  PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidate->nr);
     1764  if (FindPoint != PointsOnBoundary.end())
     1765    TPS[n] = FindPoint->second;
     1766  else
     1767    TPS[n] = NULL;
    12431768}
    12441769;
     
    12471772 * If successful it raises the line count and inserts the new line into the BLS,
    12481773 * if unsuccessful, it writes the line which had been present into the BLS, deleting the new constructed one.
     1774 * @param *OptCenter desired OptCenter if there are more than one candidate line
     1775 * @param *candidate third point of the triangle to be, for checking between multiple open line candidates
    12491776 * @param *a first endpoint
    12501777 * @param *b second endpoint
    12511778 * @param n index of Tesselation::BLS giving the line with both endpoints
    12521779 */
    1253 void Tesselation::AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n) {
     1780void Tesselation::AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     1781{
    12541782  bool insertNewLine = true;
    1255 
    1256   if (a->lines.find(b->node->nr) != a->lines.end()) {
    1257     LineMap::iterator FindLine = a->lines.find(b->node->nr);
    1258     pair<LineMap::iterator,LineMap::iterator> FindPair;
     1783  LineMap::iterator FindLine = a->lines.find(b->node->nr);
     1784  BoundaryLineSet *WinningLine = NULL;
     1785  if (FindLine != a->lines.end()) {
     1786    DoLog(1) && (Log() << Verbose(1) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl);
     1787
     1788    pair<LineMap::iterator, LineMap::iterator> FindPair;
    12591789    FindPair = a->lines.equal_range(b->node->nr);
    1260     Log() << Verbose(5) << "INFO: There is at least one line between " << *a << " and " << *b << ": " << *(FindLine->second) << "." << endl;
    1261 
    1262     for (FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     1790
     1791    for (FindLine = FindPair.first; (FindLine != FindPair.second) && (insertNewLine); FindLine++) {
     1792      DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
    12631793      // If there is a line with less than two attached triangles, we don't need a new line.
    1264       if (FindLine->second->triangles.size() < 2) {
    1265         insertNewLine = false;
    1266         Log() << Verbose(4) << "Using existing line " << *FindLine->second << endl;
    1267 
    1268         BPS[0] = FindLine->second->endpoints[0];
    1269         BPS[1] = FindLine->second->endpoints[1];
    1270         BLS[n] = FindLine->second;
    1271 
    1272         break;
     1794      if (FindLine->second->triangles.size() == 1) {
     1795        CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
     1796        if (!Finder->second->pointlist.empty())
     1797          DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
     1798        else
     1799          DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate." << endl);
     1800        // get open line
     1801        for (TesselPointList::const_iterator CandidateChecker = Finder->second->pointlist.begin(); CandidateChecker != Finder->second->pointlist.end(); ++CandidateChecker) {
     1802          if ((*(CandidateChecker) == candidate->node) && (OptCenter == NULL || OptCenter->DistanceSquared(&Finder->second->OptCenter) < MYEPSILON )) { // stop searching if candidate matches
     1803            DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Candidate " << *(*CandidateChecker) << " has the right center " << Finder->second->OptCenter << "." << endl);
     1804            insertNewLine = false;
     1805            WinningLine = FindLine->second;
     1806            break;
     1807          } else {
     1808            DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *(*CandidateChecker) << "'s center " << Finder->second->OptCenter << " does not match desired on " << *OptCenter << "." << endl);
     1809          }
     1810        }
    12731811      }
    12741812    }
     
    12761814
    12771815  if (insertNewLine) {
    1278     AlwaysAddTesselationTriangleLine(a, b, n);
     1816    AddNewTesselationTriangleLine(a, b, n);
     1817  } else {
     1818    AddExistingTesselationTriangleLine(WinningLine, n);
    12791819  }
    12801820}
     
    12891829 * @param n index of Tesselation::BLS giving the line with both endpoints
    12901830 */
    1291 void Tesselation::AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
    1292 {
    1293   Log() << Verbose(4) << "Adding line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl;
     1831void Tesselation::AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n)
     1832{
     1833  Info FunctionInfo(__func__);
     1834  DoLog(0) && (Log() << Verbose(0) << "Adding open line [" << LinesOnBoundaryCount << "|" << *(a->node) << " and " << *(b->node) << "." << endl);
    12941835  BPS[0] = a;
    12951836  BPS[1] = b;
    1296   BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount);  // this also adds the line to the local maps
     1837  BLS[n] = new class BoundaryLineSet(BPS, LinesOnBoundaryCount); // this also adds the line to the local maps
    12971838  // add line to global map
    12981839  LinesOnBoundary.insert(LinePair(LinesOnBoundaryCount, BLS[n]));
    12991840  // increase counter
    13001841  LinesOnBoundaryCount++;
    1301 };
     1842  // also add to open lines
     1843  CandidateForTesselation *CFT = new CandidateForTesselation(BLS[n]);
     1844  OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (BLS[n], CFT));
     1845}
     1846;
     1847
     1848/** Uses an existing line for a new triangle.
     1849 * Sets Tesselation::BLS[\a n] and removes the lines from Tesselation::OpenLines.
     1850 * \param *FindLine the line to add
     1851 * \param n index of the line to set in Tesselation::BLS
     1852 */
     1853void Tesselation::AddExistingTesselationTriangleLine(class BoundaryLineSet *Line, int n)
     1854{
     1855  Info FunctionInfo(__func__);
     1856  DoLog(0) && (Log() << Verbose(0) << "Using existing line " << *Line << endl);
     1857
     1858  // set endpoints and line
     1859  BPS[0] = Line->endpoints[0];
     1860  BPS[1] = Line->endpoints[1];
     1861  BLS[n] = Line;
     1862  // remove existing line from OpenLines
     1863  CandidateMap::iterator CandidateLine = OpenLines.find(BLS[n]);
     1864  if (CandidateLine != OpenLines.end()) {
     1865    DoLog(1) && (Log() << Verbose(1) << " Removing line from OpenLines." << endl);
     1866    delete (CandidateLine->second);
     1867    OpenLines.erase(CandidateLine);
     1868  } else {
     1869    DoeLog(1) && (eLog() << Verbose(1) << "Line exists and is attached to less than two triangles, but not in OpenLines!" << endl);
     1870  }
     1871}
     1872;
    13021873
    13031874/** Function adds triangle to global list.
     
    13061877void Tesselation::AddTesselationTriangle()
    13071878{
    1308   Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1879  Info FunctionInfo(__func__);
     1880  DoLog(1) && (Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl);
    13091881
    13101882  // add triangle to global map
     
    13161888
    13171889  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
    1318 };
     1890}
     1891;
    13191892
    13201893/** Function adds triangle to global list.
     
    13241897void Tesselation::AddTesselationTriangle(const int nr)
    13251898{
    1326   Log() << Verbose(1) << "Adding triangle to global TrianglesOnBoundary map." << endl;
     1899  Info FunctionInfo(__func__);
     1900  DoLog(0) && (Log() << Verbose(0) << "Adding triangle to global TrianglesOnBoundary map." << endl);
    13271901
    13281902  // add triangle to global map
     
    13331907
    13341908  // NOTE: add triangle to local maps is done in constructor of BoundaryTriangleSet
    1335 };
     1909}
     1910;
    13361911
    13371912/** Removes a triangle from the tesselation.
     
    13421917void Tesselation::RemoveTesselationTriangle(class BoundaryTriangleSet *triangle)
    13431918{
     1919  Info FunctionInfo(__func__);
    13441920  if (triangle == NULL)
    13451921    return;
    13461922  for (int i = 0; i < 3; i++) {
    13471923    if (triangle->lines[i] != NULL) {
    1348       Log() << Verbose(5) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl;
     1924      DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr." << triangle->Nr << " in line " << *triangle->lines[i] << "." << endl);
    13491925      triangle->lines[i]->triangles.erase(triangle->Nr);
    13501926      if (triangle->lines[i]->triangles.empty()) {
    1351           Log() << Verbose(5) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl;
    1352           RemoveTesselationLine(triangle->lines[i]);
     1927        DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is no more attached to any triangle, erasing." << endl);
     1928        RemoveTesselationLine(triangle->lines[i]);
    13531929      } else {
    1354         Log() << Verbose(5) << *triangle->lines[i] << " is still attached to another triangle: ";
    1355         for(TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
    1356           Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t";
    1357         Log() << Verbose(0) << endl;
    1358 //        for (int j=0;j<2;j++) {
    1359 //          Log() << Verbose(5) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
    1360 //          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
    1361 //            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
    1362 //          Log() << Verbose(0) << endl;
    1363 //        }
     1930        DoLog(0) && (Log() << Verbose(0) << *triangle->lines[i] << " is still attached to another triangle: ");
     1931        OpenLines.insert(pair<BoundaryLineSet *, CandidateForTesselation *> (triangle->lines[i], NULL));
     1932        for (TriangleMap::iterator TriangleRunner = triangle->lines[i]->triangles.begin(); TriangleRunner != triangle->lines[i]->triangles.end(); TriangleRunner++)
     1933          DoLog(0) && (Log() << Verbose(0) << "[" << (TriangleRunner->second)->Nr << "|" << *((TriangleRunner->second)->endpoints[0]) << ", " << *((TriangleRunner->second)->endpoints[1]) << ", " << *((TriangleRunner->second)->endpoints[2]) << "] \t");
     1934        DoLog(0) && (Log() << Verbose(0) << endl);
     1935        //        for (int j=0;j<2;j++) {
     1936        //          Log() << Verbose(0) << "Lines of endpoint " << *(triangle->lines[i]->endpoints[j]) << ": ";
     1937        //          for(LineMap::iterator LineRunner = triangle->lines[i]->endpoints[j]->lines.begin(); LineRunner != triangle->lines[i]->endpoints[j]->lines.end(); LineRunner++)
     1938        //            Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
     1939        //          Log() << Verbose(0) << endl;
     1940        //        }
    13641941      }
    1365       triangle->lines[i] = NULL;  // free'd or not: disconnect
     1942      triangle->lines[i] = NULL; // free'd or not: disconnect
    13661943    } else
    1367       eLog() << Verbose(0) << "ERROR: This line " << i << " has already been free'd." << endl;
     1944      DoeLog(1) && (eLog() << Verbose(1) << "This line " << i << " has already been free'd." << endl);
    13681945  }
    13691946
    13701947  if (TrianglesOnBoundary.erase(triangle->Nr))
    1371     Log() << Verbose(5) << "Removing triangle Nr. " << triangle->Nr << "." << endl;
    1372   delete(triangle);
    1373 };
     1948    DoLog(0) && (Log() << Verbose(0) << "Removing triangle Nr. " << triangle->Nr << "." << endl);
     1949  delete (triangle);
     1950}
     1951;
    13741952
    13751953/** Removes a line from the tesselation.
     
    13791957void Tesselation::RemoveTesselationLine(class BoundaryLineSet *line)
    13801958{
     1959  Info FunctionInfo(__func__);
    13811960  int Numbers[2];
    13821961
     
    13991978        for (LineMap::iterator Runner = erasor.first; Runner != erasor.second; Runner++)
    14001979          if ((*Runner).second == line) {
    1401             Log() << Verbose(5) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     1980            DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
    14021981            line->endpoints[i]->lines.erase(Runner);
    14031982            break;
     
    14051984      } else { // there's just a single line left
    14061985        if (line->endpoints[i]->lines.erase(line->Nr))
    1407           Log() << Verbose(5) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl;
     1986          DoLog(0) && (Log() << Verbose(0) << "Removing Line Nr. " << line->Nr << " in boundary point " << *line->endpoints[i] << "." << endl);
    14081987      }
    14091988      if (line->endpoints[i]->lines.empty()) {
    1410         Log() << Verbose(5) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl;
     1989        DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has no more lines it's attached to, erasing." << endl);
    14111990        RemoveTesselationPoint(line->endpoints[i]);
    14121991      } else {
    1413         Log() << Verbose(5) << *line->endpoints[i] << " has still lines it's attached to: ";
    1414         for(LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
    1415           Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t";
    1416         Log() << Verbose(0) << endl;
     1992        DoLog(0) && (Log() << Verbose(0) << *line->endpoints[i] << " has still lines it's attached to: ");
     1993        for (LineMap::iterator LineRunner = line->endpoints[i]->lines.begin(); LineRunner != line->endpoints[i]->lines.end(); LineRunner++)
     1994          DoLog(0) && (Log() << Verbose(0) << "[" << *(LineRunner->second) << "] \t");
     1995        DoLog(0) && (Log() << Verbose(0) << endl);
    14171996      }
    1418       line->endpoints[i] = NULL;  // free'd or not: disconnect
     1997      line->endpoints[i] = NULL; // free'd or not: disconnect
    14191998    } else
    1420       eLog() << Verbose(0) << "ERROR: Endpoint " << i << " has already been free'd." << endl;
     1999      DoeLog(1) && (eLog() << Verbose(1) << "Endpoint " << i << " has already been free'd." << endl);
    14212000  }
    14222001  if (!line->triangles.empty())
    1423     eLog() << Verbose(0) << "WARNING: Memory Leak! I " << *line << " am still connected to some triangles." << endl;
     2002    DoeLog(2) && (eLog() << Verbose(2) << "Memory Leak! I " << *line << " am still connected to some triangles." << endl);
    14242003
    14252004  if (LinesOnBoundary.erase(line->Nr))
    1426     Log() << Verbose(5) << "Removing line Nr. " << line->Nr << "." << endl;
    1427   delete(line);
    1428 };
     2005    DoLog(0) && (Log() << Verbose(0) << "Removing line Nr. " << line->Nr << "." << endl);
     2006  delete (line);
     2007}
     2008;
    14292009
    14302010/** Removes a point from the tesselation.
     
    14352015void Tesselation::RemoveTesselationPoint(class BoundaryPointSet *point)
    14362016{
     2017  Info FunctionInfo(__func__);
    14372018  if (point == NULL)
    14382019    return;
    14392020  if (PointsOnBoundary.erase(point->Nr))
    1440     Log() << Verbose(5) << "Removing point Nr. " << point->Nr << "." << endl;
    1441   delete(point);
    1442 };
     2021    DoLog(0) && (Log() << Verbose(0) << "Removing point Nr. " << point->Nr << "." << endl);
     2022  delete (point);
     2023}
     2024;
     2025
     2026/** Checks validity of a given sphere of a candidate line.
     2027 * \sa CandidateForTesselation::CheckValidity(), which is more evolved.
     2028 * We check CandidateForTesselation::OtherOptCenter
     2029 * \param &CandidateLine contains other degenerated candidates which we have to subtract as well
     2030 * \param RADIUS radius of sphere
     2031 * \param *LC LinkedCell structure with other atoms
     2032 * \return true - candidate triangle is degenerated, false - candidate triangle is not degenerated
     2033 */
     2034bool Tesselation::CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const
     2035{
     2036  Info FunctionInfo(__func__);
     2037
     2038  DoLog(1) && (Log() << Verbose(1) << "INFO: Checking whether sphere contains no others points ..." << endl);
     2039  bool flag = true;
     2040
     2041  DoLog(1) && (Log() << Verbose(1) << "Check by: draw sphere {" << CandidateLine.OtherOptCenter.x[0] << " " << CandidateLine.OtherOptCenter.x[1] << " " << CandidateLine.OtherOptCenter.x[2] << "} radius " << RADIUS << " resolution 30" << endl);
     2042  // get all points inside the sphere
     2043  TesselPointList *ListofPoints = LC->GetPointsInsideSphere(RADIUS, &CandidateLine.OtherOptCenter);
     2044
     2045  DoLog(1) && (Log() << Verbose(1) << "The following atoms are inside sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
     2046  for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     2047    DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl);
     2048
     2049  // remove triangles's endpoints
     2050  for (int i = 0; i < 2; i++)
     2051    ListofPoints->remove(CandidateLine.BaseLine->endpoints[i]->node);
     2052
     2053  // remove other candidates
     2054  for (TesselPointList::const_iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); ++Runner)
     2055    ListofPoints->remove(*Runner);
     2056
     2057  // check for other points
     2058  if (!ListofPoints->empty()) {
     2059    DoLog(1) && (Log() << Verbose(1) << "CheckDegeneracy: There are still " << ListofPoints->size() << " points inside the sphere." << endl);
     2060    flag = false;
     2061    DoLog(1) && (Log() << Verbose(1) << "External atoms inside of sphere at " << CandidateLine.OtherOptCenter << ":" << endl);
     2062    for (TesselPointList::const_iterator Runner = ListofPoints->begin(); Runner != ListofPoints->end(); ++Runner)
     2063      DoLog(1) && (Log() << Verbose(1) << "  " << *(*Runner) << " with distance " << (*Runner)->node->Distance(&CandidateLine.OtherOptCenter) << "." << endl);
     2064  }
     2065  delete (ListofPoints);
     2066
     2067  return flag;
     2068}
     2069;
    14432070
    14442071/** Checks whether the triangle consisting of the three points is already present.
     
    14512078 *                 triangles exist which is the maximum for three points
    14522079 */
    1453 int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) {
     2080int Tesselation::CheckPresenceOfTriangle(TesselPoint *Candidates[3]) const
     2081{
     2082  Info FunctionInfo(__func__);
    14542083  int adjacentTriangleCount = 0;
    14552084  class BoundaryPointSet *Points[3];
    14562085
    1457   Log() << Verbose(2) << "Begin of CheckPresenceOfTriangle" << endl;
    14582086  // builds a triangle point set (Points) of the end points
    14592087  for (int i = 0; i < 3; i++) {
    1460     PointMap::iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
     2088    PointMap::const_iterator FindPoint = PointsOnBoundary.find(Candidates[i]->nr);
    14612089    if (FindPoint != PointsOnBoundary.end()) {
    14622090      Points[i] = FindPoint->second;
     
    14712099      for (int j = i; j < 3; j++) {
    14722100        if (Points[j] != NULL) {
    1473           LineMap::iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
     2101          LineMap::const_iterator FindLine = Points[i]->lines.find(Points[j]->node->nr);
    14742102          for (; (FindLine != Points[i]->lines.end()) && (FindLine->first == Points[j]->node->nr); FindLine++) {
    14752103            TriangleMap *triangles = &FindLine->second->triangles;
    1476             Log() << Verbose(3) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl;
    1477             for (TriangleMap::iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
     2104            DoLog(1) && (Log() << Verbose(1) << "Current line is " << FindLine->first << ": " << *(FindLine->second) << " with triangles " << triangles << "." << endl);
     2105            for (TriangleMap::const_iterator FindTriangle = triangles->begin(); FindTriangle != triangles->end(); FindTriangle++) {
    14782106              if (FindTriangle->second->IsPresentTupel(Points)) {
    14792107                adjacentTriangleCount++;
    14802108              }
    14812109            }
    1482             Log() << Verbose(3) << "end." << endl;
     2110            DoLog(1) && (Log() << Verbose(1) << "end." << endl);
    14832111          }
    14842112          // Only one of the triangle lines must be considered for the triangle count.
    1485           //Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     2113          //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    14862114          //return adjacentTriangleCount;
    14872115        }
     
    14902118  }
    14912119
    1492   Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    1493   Log() << Verbose(2) << "End of CheckPresenceOfTriangle" << endl;
     2120  DoLog(0) && (Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl);
    14942121  return adjacentTriangleCount;
    1495 };
     2122}
     2123;
    14962124
    14972125/** Checks whether the triangle consisting of the three points is already present.
     
    15052133class BoundaryTriangleSet * Tesselation::GetPresentTriangle(TesselPoint *Candidates[3])
    15062134{
     2135  Info FunctionInfo(__func__);
    15072136  class BoundaryTriangleSet *triangle = NULL;
    15082137  class BoundaryPointSet *Points[3];
     
    15342163          }
    15352164          // Only one of the triangle lines must be considered for the triangle count.
    1536           //Log() << Verbose(2) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
     2165          //Log() << Verbose(0) << "Found " << adjacentTriangleCount << " adjacent triangles for the point set." << endl;
    15372166          //return adjacentTriangleCount;
    15382167        }
     
    15422171
    15432172  return triangle;
    1544 };
    1545 
     2173}
     2174;
    15462175
    15472176/** Finds the starting triangle for FindNonConvexBorder().
     
    15522181 * \param RADIUS radius of virtual rolling sphere
    15532182 * \param *LC LinkedCell structure with neighbouring TesselPoint's
    1554  */
    1555 void Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
    1556 {
    1557   Log() << Verbose(1) << "Begin of FindStartingTriangle\n";
     2183 * \return true - a starting triangle has been created, false - no valid triple of points found
     2184 */
     2185bool Tesselation::FindStartingTriangle(const double RADIUS, const LinkedCell *LC)
     2186{
     2187  Info FunctionInfo(__func__);
    15582188  int i = 0;
    1559   TesselPoint* FirstPoint = NULL;
    1560   TesselPoint* SecondPoint = NULL;
    15612189  TesselPoint* MaxPoint[NDIM];
     2190  TesselPoint* Temporary;
    15622191  double maxCoordinate[NDIM];
    1563   Vector Oben;
     2192  BoundaryLineSet *BaseLine = NULL;
    15642193  Vector helper;
    15652194  Vector Chord;
    15662195  Vector SearchDirection;
    1567 
    1568   Oben.Zero();
     2196  Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
     2197  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
     2198  Vector SphereCenter;
     2199  Vector NormalVector;
     2200
     2201  NormalVector.Zero();
    15692202
    15702203  for (i = 0; i < 3; i++) {
     
    15742207
    15752208  // 1. searching topmost point with respect to each axis
    1576   for (int i=0;i<NDIM;i++) { // each axis
    1577     LC->n[i] = LC->N[i]-1; // current axis is topmost cell
    1578     for (LC->n[(i+1)%NDIM]=0;LC->n[(i+1)%NDIM]<LC->N[(i+1)%NDIM];LC->n[(i+1)%NDIM]++)
    1579       for (LC->n[(i+2)%NDIM]=0;LC->n[(i+2)%NDIM]<LC->N[(i+2)%NDIM];LC->n[(i+2)%NDIM]++) {
    1580         const LinkedNodes *List = LC->GetCurrentCell();
    1581         //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     2209  for (int i = 0; i < NDIM; i++) { // each axis
     2210    LC->n[i] = LC->N[i] - 1; // current axis is topmost cell
     2211    for (LC->n[(i + 1) % NDIM] = 0; LC->n[(i + 1) % NDIM] < LC->N[(i + 1) % NDIM]; LC->n[(i + 1) % NDIM]++)
     2212      for (LC->n[(i + 2) % NDIM] = 0; LC->n[(i + 2) % NDIM] < LC->N[(i + 2) % NDIM]; LC->n[(i + 2) % NDIM]++) {
     2213        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
     2214        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    15822215        if (List != NULL) {
    1583           for (LinkedNodes::const_iterator Runner = List->begin();Runner != List->end();Runner++) {
     2216          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    15842217            if ((*Runner)->node->x[i] > maxCoordinate[i]) {
    1585               Log() << Verbose(2) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl;
     2218              DoLog(1) && (Log() << Verbose(1) << "New maximal for axis " << i << " node is " << *(*Runner) << " at " << *(*Runner)->node << "." << endl);
    15862219              maxCoordinate[i] = (*Runner)->node->x[i];
    15872220              MaxPoint[i] = (*Runner);
     
    15892222          }
    15902223        } else {
    1591           eLog() << Verbose(0) << "ERROR: The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl;
     2224          DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
    15922225        }
    15932226      }
    15942227  }
    15952228
    1596   Log() << Verbose(2) << "Found maximum coordinates: ";
    1597   for (int i=0;i<NDIM;i++)
    1598     Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t";
    1599   Log() << Verbose(0) << endl;
     2229  DoLog(1) && (Log() << Verbose(1) << "Found maximum coordinates: ");
     2230  for (int i = 0; i < NDIM; i++)
     2231    DoLog(0) && (Log() << Verbose(0) << i << ": " << *MaxPoint[i] << "\t");
     2232  DoLog(0) && (Log() << Verbose(0) << endl);
    16002233
    16012234  BTS = NULL;
    1602   CandidateList *OptCandidates = new CandidateList();
    1603   for (int k=0;k<NDIM;k++) {
    1604     Oben.Zero();
    1605     Oben.x[k] = 1.;
    1606     FirstPoint = MaxPoint[k];
    1607     Log() << Verbose(1) << "Coordinates of start node at " << *FirstPoint->node << "." << endl;
     2235  for (int k = 0; k < NDIM; k++) {
     2236    NormalVector.Zero();
     2237    NormalVector.x[k] = 1.;
     2238    BaseLine = new BoundaryLineSet();
     2239    BaseLine->endpoints[0] = new BoundaryPointSet(MaxPoint[k]);
     2240    DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
    16082241
    16092242    double ShortestAngle;
    1610     TesselPoint* OptCandidate = NULL;
    16112243    ShortestAngle = 999999.; // This will contain the angle, which will be always positive (when looking for second point), when looking for third point this will be the quadrant.
    16122244
    1613     FindSecondPointForTesselation(FirstPoint, Oben, OptCandidate, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
    1614     SecondPoint = OptCandidate;
    1615     if (SecondPoint == NULL)  // have we found a second point?
     2245    Temporary = NULL;
     2246    FindSecondPointForTesselation(BaseLine->endpoints[0]->node, NormalVector, Temporary, &ShortestAngle, RADIUS, LC); // we give same point as next candidate as its bonds are looked into in find_second_...
     2247    if (Temporary == NULL) {
     2248      // have we found a second point?
     2249      delete BaseLine;
    16162250      continue;
    1617 
    1618     helper.CopyVector(FirstPoint->node);
    1619     helper.SubtractVector(SecondPoint->node);
    1620     helper.Normalize();
    1621     Oben.ProjectOntoPlane(&helper);
    1622     Oben.Normalize();
    1623     helper.VectorProduct(&Oben);
    1624     ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    1625 
    1626     Chord.CopyVector(FirstPoint->node); // bring into calling function
    1627     Chord.SubtractVector(SecondPoint->node);
    1628     double radius = Chord.ScalarProduct(&Chord);
    1629     double CircleRadius = sqrt(RADIUS*RADIUS - radius/4.);
    1630     helper.CopyVector(&Oben);
    1631     helper.Scale(CircleRadius);
    1632     // Now, oben and helper are two orthonormalized vectors in the plane defined by Chord (not normalized)
     2251    }
     2252    BaseLine->endpoints[1] = new BoundaryPointSet(Temporary);
     2253
     2254    // construct center of circle
     2255    CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node);
     2256    CircleCenter.AddVector(BaseLine->endpoints[1]->node->node);
     2257    CircleCenter.Scale(0.5);
     2258
     2259    // construct normal vector of circle
     2260    CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node);
     2261    CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
     2262
     2263    double radius = CirclePlaneNormal.NormSquared();
     2264    double CircleRadius = sqrt(RADIUS * RADIUS - radius / 4.);
     2265
     2266    NormalVector.ProjectOntoPlane(&CirclePlaneNormal);
     2267    NormalVector.Normalize();
     2268    ShortestAngle = 2. * M_PI; // This will indicate the quadrant.
     2269
     2270    SphereCenter.CopyVector(&NormalVector);
     2271    SphereCenter.Scale(CircleRadius);
     2272    SphereCenter.AddVector(&CircleCenter);
     2273    // Now, NormalVector and SphereCenter are two orthonormalized vectors in the plane defined by CirclePlaneNormal (not normalized)
    16332274
    16342275    // look in one direction of baseline for initial candidate
    1635     SearchDirection.MakeNormalVector(&Chord, &Oben); // whether we look "left" first or "right" first is not important ...
     2276    SearchDirection.MakeNormalVector(&CirclePlaneNormal, &NormalVector); // whether we look "left" first or "right" first is not important ...
    16362277
    16372278    // adding point 1 and point 2 and add the line between them
    1638     Log() << Verbose(1) << "Coordinates of start node at " << *FirstPoint->node << "." << endl;
    1639     AddTesselationPoint(FirstPoint, 0);
    1640     Log() << Verbose(1) << "Found second point is at " << *SecondPoint->node << ".\n";
    1641     AddTesselationPoint(SecondPoint, 1);
    1642     AddTesselationLine(TPS[0], TPS[1], 0);
    1643 
    1644     //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << helper << ".\n";
    1645     FindThirdPointForTesselation(Oben, SearchDirection, helper, BLS[0], NULL, *&OptCandidates, &ShortestAngle, RADIUS, LC);
    1646     Log() << Verbose(1) << "List of third Points is ";
    1647     for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1648         Log() << Verbose(0) << " " << *(*it)->point;
    1649     }
    1650     Log() << Verbose(0) << endl;
    1651 
    1652     for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1653       // add third triangle point
    1654       AddTesselationPoint((*it)->point, 2);
    1655       // add the second and third line
    1656       AddTesselationLine(TPS[1], TPS[2], 1);
    1657       AddTesselationLine(TPS[0], TPS[2], 2);
    1658       // ... and triangles to the Maps of the Tesselation class
    1659       BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    1660       AddTesselationTriangle();
    1661       // ... and calculate its normal vector (with correct orientation)
    1662       (*it)->OptCenter.Scale(-1.);
    1663       Log() << Verbose(2) << "Anti-Oben is currently " << (*it)->OptCenter << "." << endl;
    1664       BTS->GetNormalVector((*it)->OptCenter);  // vector to compare with should point inwards
    1665       Log() << Verbose(0) << "==> Found starting triangle consists of " << *FirstPoint << ", " << *SecondPoint << " and "
    1666       << *(*it)->point << " with normal vector " << BTS->NormalVector << ".\n";
    1667 
    1668       // if we do not reach the end with the next step of iteration, we need to setup a new first line
    1669       if (it != OptCandidates->end()--) {
    1670         FirstPoint = (*it)->BaseLine->endpoints[0]->node;
    1671         SecondPoint = (*it)->point;
    1672         // adding point 1 and point 2 and the line between them
    1673         AddTesselationPoint(FirstPoint, 0);
    1674         AddTesselationPoint(SecondPoint, 1);
    1675         AddTesselationLine(TPS[0], TPS[1], 0);
    1676       }
    1677       Log() << Verbose(2) << "Projection is " << BTS->NormalVector.ScalarProduct(&Oben) << "." << endl;
    1678     }
    1679     if (BTS != NULL) // we have created one starting triangle
     2279    DoLog(0) && (Log() << Verbose(0) << "Coordinates of start node at " << *BaseLine->endpoints[0]->node << "." << endl);
     2280    DoLog(0) && (Log() << Verbose(0) << "Found second point is at " << *BaseLine->endpoints[1]->node << ".\n");
     2281
     2282    //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << helper << ".\n";
     2283    CandidateForTesselation OptCandidates(BaseLine);
     2284    FindThirdPointForTesselation(NormalVector, SearchDirection, SphereCenter, OptCandidates, NULL, RADIUS, LC);
     2285    DoLog(0) && (Log() << Verbose(0) << "List of third Points is:" << endl);
     2286    for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); it++) {
     2287      DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
     2288    }
     2289    if (!OptCandidates.pointlist.empty()) {
     2290      BTS = NULL;
     2291      AddCandidatePolygon(OptCandidates, RADIUS, LC);
     2292    } else {
     2293      delete BaseLine;
     2294      continue;
     2295    }
     2296
     2297    if (BTS != NULL) { // we have created one starting triangle
     2298      delete BaseLine;
    16802299      break;
    1681     else {
     2300    } else {
    16822301      // remove all candidates from the list and then the list itself
    1683       class CandidateForTesselation *remover = NULL;
    1684       for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1685         remover = *it;
    1686         delete(remover);
    1687       }
    1688       OptCandidates->clear();
    1689     }
    1690   }
    1691 
    1692   // remove all candidates from the list and then the list itself
    1693   class CandidateForTesselation *remover = NULL;
    1694   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1695     remover = *it;
    1696     delete(remover);
    1697   }
    1698   delete(OptCandidates);
    1699   Log() << Verbose(1) << "End of FindStartingTriangle\n";
    1700 };
    1701 
     2302      OptCandidates.pointlist.clear();
     2303    }
     2304    delete BaseLine;
     2305  }
     2306
     2307  return (BTS != NULL);
     2308}
     2309;
     2310
     2311/** Checks for a given baseline and a third point candidate whether baselines of the found triangle don't have even better candidates.
     2312 * This is supposed to prevent early closing of the tesselation.
     2313 * \param CandidateLine CandidateForTesselation with baseline and shortestangle , i.e. not \a *OptCandidate
     2314 * \param *ThirdNode third point in triangle, not in BoundaryLineSet::endpoints
     2315 * \param RADIUS radius of sphere
     2316 * \param *LC LinkedCell structure
     2317 * \return true - there is a better candidate (smaller angle than \a ShortestAngle), false - no better TesselPoint candidate found
     2318 */
     2319//bool Tesselation::HasOtherBaselineBetterCandidate(CandidateForTesselation &CandidateLine, const TesselPoint * const ThirdNode, double RADIUS, const LinkedCell * const LC) const
     2320//{
     2321//      Info FunctionInfo(__func__);
     2322//  bool result = false;
     2323//  Vector CircleCenter;
     2324//  Vector CirclePlaneNormal;
     2325//  Vector OldSphereCenter;
     2326//  Vector SearchDirection;
     2327//  Vector helper;
     2328//  TesselPoint *OtherOptCandidate = NULL;
     2329//  double OtherShortestAngle = 2.*M_PI; // This will indicate the quadrant.
     2330//  double radius, CircleRadius;
     2331//  BoundaryLineSet *Line = NULL;
     2332//  BoundaryTriangleSet *T = NULL;
     2333//
     2334//  // check both other lines
     2335//  PointMap::const_iterator FindPoint = PointsOnBoundary.find(ThirdNode->nr);
     2336//  if (FindPoint != PointsOnBoundary.end()) {
     2337//    for (int i=0;i<2;i++) {
     2338//      LineMap::const_iterator FindLine = (FindPoint->second)->lines.find(BaseRay->endpoints[0]->node->nr);
     2339//      if (FindLine != (FindPoint->second)->lines.end()) {
     2340//        Line = FindLine->second;
     2341//        Log() << Verbose(0) << "Found line " << *Line << "." << endl;
     2342//        if (Line->triangles.size() == 1) {
     2343//          T = Line->triangles.begin()->second;
     2344//          // construct center of circle
     2345//          CircleCenter.CopyVector(Line->endpoints[0]->node->node);
     2346//          CircleCenter.AddVector(Line->endpoints[1]->node->node);
     2347//          CircleCenter.Scale(0.5);
     2348//
     2349//          // construct normal vector of circle
     2350//          CirclePlaneNormal.CopyVector(Line->endpoints[0]->node->node);
     2351//          CirclePlaneNormal.SubtractVector(Line->endpoints[1]->node->node);
     2352//
     2353//          // calculate squared radius of circle
     2354//          radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
     2355//          if (radius/4. < RADIUS*RADIUS) {
     2356//            CircleRadius = RADIUS*RADIUS - radius/4.;
     2357//            CirclePlaneNormal.Normalize();
     2358//            //Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     2359//
     2360//            // construct old center
     2361//            GetCenterofCircumcircle(&OldSphereCenter, *T->endpoints[0]->node->node, *T->endpoints[1]->node->node, *T->endpoints[2]->node->node);
     2362//            helper.CopyVector(&T->NormalVector);  // normal vector ensures that this is correct center of the two possible ones
     2363//            radius = Line->endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
     2364//            helper.Scale(sqrt(RADIUS*RADIUS - radius));
     2365//            OldSphereCenter.AddVector(&helper);
     2366//            OldSphereCenter.SubtractVector(&CircleCenter);
     2367//            //Log() << Verbose(1) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
     2368//
     2369//            // construct SearchDirection
     2370//            SearchDirection.MakeNormalVector(&T->NormalVector, &CirclePlaneNormal);
     2371//            helper.CopyVector(Line->endpoints[0]->node->node);
     2372//            helper.SubtractVector(ThirdNode->node);
     2373//            if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
     2374//              SearchDirection.Scale(-1.);
     2375//            SearchDirection.ProjectOntoPlane(&OldSphereCenter);
     2376//            SearchDirection.Normalize();
     2377//            Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
     2378//            if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     2379//              // rotated the wrong way!
     2380//              DoeLog(1) && (eLog()<< Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
     2381//            }
     2382//
     2383//            // add third point
     2384//            FindThirdPointForTesselation(T->NormalVector, SearchDirection, OldSphereCenter, OptCandidates, ThirdNode, RADIUS, LC);
     2385//            for (TesselPointList::iterator it = OptCandidates.pointlist.begin(); it != OptCandidates.pointlist.end(); ++it) {
     2386//              if (((*it) == BaseRay->endpoints[0]->node) || ((*it) == BaseRay->endpoints[1]->node)) // skip if it's the same triangle than suggested
     2387//                continue;
     2388//              Log() << Verbose(0) << " Third point candidate is " << (*it)
     2389//              << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
     2390//              Log() << Verbose(0) << " Baseline is " << *BaseRay << endl;
     2391//
     2392//              // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
     2393//              TesselPoint *PointCandidates[3];
     2394//              PointCandidates[0] = (*it);
     2395//              PointCandidates[1] = BaseRay->endpoints[0]->node;
     2396//              PointCandidates[2] = BaseRay->endpoints[1]->node;
     2397//              bool check=false;
     2398//              int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
     2399//              // If there is no triangle, add it regularly.
     2400//              if (existentTrianglesCount == 0) {
     2401//                SetTesselationPoint((*it), 0);
     2402//                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
     2403//                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
     2404//
     2405//                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
     2406//                  OtherOptCandidate = (*it);
     2407//                  check = true;
     2408//                }
     2409//              } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
     2410//                SetTesselationPoint((*it), 0);
     2411//                SetTesselationPoint(BaseRay->endpoints[0]->node, 1);
     2412//                SetTesselationPoint(BaseRay->endpoints[1]->node, 2);
     2413//
     2414//                // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
     2415//                // i.e. at least one of the three lines must be present with TriangleCount <= 1
     2416//                if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
     2417//                  OtherOptCandidate = (*it);
     2418//                  check = true;
     2419//                }
     2420//              }
     2421//
     2422//              if (check) {
     2423//                if (ShortestAngle > OtherShortestAngle) {
     2424//                  Log() << Verbose(0) << "There is a better candidate than " << *ThirdNode << " with " << ShortestAngle << " from baseline " << *Line << ": " << *OtherOptCandidate << " with " << OtherShortestAngle << "." << endl;
     2425//                  result = true;
     2426//                  break;
     2427//                }
     2428//              }
     2429//            }
     2430//            delete(OptCandidates);
     2431//            if (result)
     2432//              break;
     2433//          } else {
     2434//            Log() << Verbose(0) << "Circumcircle for base line " << *Line << " and base triangle " << T << " is too big!" << endl;
     2435//          }
     2436//        } else {
     2437//          DoeLog(2) && (eLog()<< Verbose(2) << "Baseline is connected to two triangles already?" << endl);
     2438//        }
     2439//      } else {
     2440//        Log() << Verbose(1) << "No present baseline between " << BaseRay->endpoints[0] << " and candidate " << *ThirdNode << "." << endl;
     2441//      }
     2442//    }
     2443//  } else {
     2444//    DoeLog(1) && (eLog()<< Verbose(1) << "Could not find the TesselPoint " << *ThirdNode << "." << endl);
     2445//  }
     2446//
     2447//  return result;
     2448//};
    17022449
    17032450/** This function finds a triangle to a line, adjacent to an existing one.
    17042451 * @param out output stream for debugging
    1705  * @param Line current baseline to search from
     2452 * @param CandidateLine current cadndiate baseline to search from
    17062453 * @param T current triangle which \a Line is edge of
    17072454 * @param RADIUS radius of the rolling ball
     
    17092456 * @param *LC LinkedCell structure with neighbouring points
    17102457 */
    1711 bool Tesselation::FindNextSuitableTriangle(BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
    1712 {
    1713   Log() << Verbose(0) << "Begin of FindNextSuitableTriangle\n";
    1714   bool result = true;
    1715   CandidateList *OptCandidates = new CandidateList();
    1716 
     2458bool Tesselation::FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC)
     2459{
     2460  Info FunctionInfo(__func__);
    17172461  Vector CircleCenter;
    17182462  Vector CirclePlaneNormal;
    1719   Vector OldSphereCenter;
     2463  Vector RelativeSphereCenter;
    17202464  Vector SearchDirection;
    17212465  Vector helper;
    1722   TesselPoint *ThirdNode = NULL;
     2466  BoundaryPointSet *ThirdPoint = NULL;
    17232467  LineMap::iterator testline;
    1724   double ShortestAngle = 2.*M_PI; // This will indicate the quadrant.
    17252468  double radius, CircleRadius;
    17262469
    1727   Log() << Verbose(1) << "Current baseline is " << Line << " of triangle " << T << "." << endl;
    1728   for (int i=0;i<3;i++)
    1729     if ((T.endpoints[i]->node != Line.endpoints[0]->node) && (T.endpoints[i]->node != Line.endpoints[1]->node))
    1730       ThirdNode = T.endpoints[i]->node;
     2470  for (int i = 0; i < 3; i++)
     2471    if ((T.endpoints[i] != CandidateLine.BaseLine->endpoints[0]) && (T.endpoints[i] != CandidateLine.BaseLine->endpoints[1])) {
     2472      ThirdPoint = T.endpoints[i];
     2473      break;
     2474    }
     2475  DoLog(0) && (Log() << Verbose(0) << "Current baseline is " << *CandidateLine.BaseLine << " with ThirdPoint " << *ThirdPoint << " of triangle " << T << "." << endl);
     2476
     2477  CandidateLine.T = &T;
    17312478
    17322479  // construct center of circle
    1733   CircleCenter.CopyVector(Line.endpoints[0]->node->node);
    1734   CircleCenter.AddVector(Line.endpoints[1]->node->node);
     2480  CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     2481  CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    17352482  CircleCenter.Scale(0.5);
    17362483
    17372484  // construct normal vector of circle
    1738   CirclePlaneNormal.CopyVector(Line.endpoints[0]->node->node);
    1739   CirclePlaneNormal.SubtractVector(Line.endpoints[1]->node->node);
     2485  CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     2486  CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    17402487
    17412488  // calculate squared radius of circle
    17422489  radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    1743   if (radius/4. < RADIUS*RADIUS) {
    1744     CircleRadius = RADIUS*RADIUS - radius/4.;
     2490  if (radius / 4. < RADIUS * RADIUS) {
     2491    // construct relative sphere center with now known CircleCenter
     2492    RelativeSphereCenter.CopyVector(&T.SphereCenter);
     2493    RelativeSphereCenter.SubtractVector(&CircleCenter);
     2494
     2495    CircleRadius = RADIUS * RADIUS - radius / 4.;
    17452496    CirclePlaneNormal.Normalize();
    1746     //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
    1747 
    1748     // construct old center
    1749     GetCenterofCircumcircle(&OldSphereCenter, *T.endpoints[0]->node->node, *T.endpoints[1]->node->node, *T.endpoints[2]->node->node);
    1750     helper.CopyVector(&T.NormalVector);  // normal vector ensures that this is correct center of the two possible ones
    1751     radius = Line.endpoints[0]->node->node->DistanceSquared(&OldSphereCenter);
    1752     helper.Scale(sqrt(RADIUS*RADIUS - radius));
    1753     OldSphereCenter.AddVector(&helper);
    1754     OldSphereCenter.SubtractVector(&CircleCenter);
    1755     //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
    1756 
    1757     // construct SearchDirection
    1758     SearchDirection.MakeNormalVector(&T.NormalVector, &CirclePlaneNormal);
    1759     helper.CopyVector(Line.endpoints[0]->node->node);
    1760     helper.SubtractVector(ThirdNode->node);
     2497    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
     2498
     2499    DoLog(1) && (Log() << Verbose(1) << "INFO: OldSphereCenter is at " << T.SphereCenter << "." << endl);
     2500
     2501    // construct SearchDirection and an "outward pointer"
     2502    SearchDirection.MakeNormalVector(&RelativeSphereCenter, &CirclePlaneNormal);
     2503    helper.CopyVector(&CircleCenter);
     2504    helper.SubtractVector(ThirdPoint->node->node);
    17612505    if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)// ohoh, SearchDirection points inwards!
    17622506      SearchDirection.Scale(-1.);
    1763     SearchDirection.ProjectOntoPlane(&OldSphereCenter);
    1764     SearchDirection.Normalize();
    1765     Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    1766     if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
     2507    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
     2508    if (fabs(RelativeSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) {
    17672509      // rotated the wrong way!
    1768       eLog() << Verbose(0) << "ERROR: SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl;
     2510      DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are still not orthogonal!" << endl);
    17692511    }
    17702512
    17712513    // add third point
    1772     FindThirdPointForTesselation(T.NormalVector, SearchDirection, OldSphereCenter, &Line, ThirdNode, OptCandidates, &ShortestAngle, RADIUS, LC);
     2514    FindThirdPointForTesselation(T.NormalVector, SearchDirection, T.SphereCenter, CandidateLine, ThirdPoint, RADIUS, LC);
    17732515
    17742516  } else {
    1775     Log() << Verbose(1) << "Circumcircle for base line " << Line << " and base triangle " << T << " is too big!" << endl;
    1776   }
    1777 
    1778   if (OptCandidates->begin() == OptCandidates->end()) {
    1779     eLog() << Verbose(0) << "WARNING: Could not find a suitable candidate." << endl;
     2517    DoLog(0) && (Log() << Verbose(0) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and base triangle " << T << " is too big!" << endl);
     2518  }
     2519
     2520  if (CandidateLine.pointlist.empty()) {
     2521    DoeLog(2) && (eLog() << Verbose(2) << "Could not find a suitable candidate." << endl);
    17802522    return false;
    17812523  }
    1782   Log() << Verbose(1) << "Third Points are ";
    1783   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1784     Log() << Verbose(0) << " " << *(*it)->point;
    1785   }
    1786   Log() << Verbose(0) << endl;
    1787 
    1788   BoundaryLineSet *BaseRay = &Line;
    1789   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1790     Log() << Verbose(1) << " Third point candidate is " << *(*it)->point
    1791     << " with circumsphere's center at " << (*it)->OptCenter << "." << endl;
    1792     Log() << Verbose(1) << " Baseline is " << *BaseRay << endl;
    1793 
    1794     // check whether all edges of the new triangle still have space for one more triangle (i.e. TriangleCount <2)
    1795     TesselPoint *PointCandidates[3];
    1796     PointCandidates[0] = (*it)->point;
    1797     PointCandidates[1] = BaseRay->endpoints[0]->node;
    1798     PointCandidates[2] = BaseRay->endpoints[1]->node;
    1799     int existentTrianglesCount = CheckPresenceOfTriangle(PointCandidates);
    1800 
    1801     BTS = NULL;
    1802     // If there is no triangle, add it regularly.
    1803     if (existentTrianglesCount == 0) {
    1804       AddTesselationPoint((*it)->point, 0);
    1805       AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    1806       AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    1807 
    1808       if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const )TPS)) {
    1809         AddTesselationLine(TPS[0], TPS[1], 0);
    1810         AddTesselationLine(TPS[0], TPS[2], 1);
    1811         AddTesselationLine(TPS[1], TPS[2], 2);
    1812 
    1813         BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    1814         AddTesselationTriangle();
    1815         (*it)->OptCenter.Scale(-1.);
    1816         BTS->GetNormalVector((*it)->OptCenter);
    1817         (*it)->OptCenter.Scale(-1.);
    1818 
    1819         Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector
    1820           << " for this triangle ... " << endl;
    1821       //Log() << Verbose(1) << "We have "<< TrianglesOnBoundaryCount << " for line " << *BaseRay << "." << endl;
    1822       } else {
    1823         Log() << Verbose(1) << "WARNING: This triangle consisting of ";
    1824         Log() << Verbose(0) << *(*it)->point << ", ";
    1825         Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    1826         Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    1827         Log() << Verbose(0) << "exists and is not added, as it does not seem helpful!" << endl;
    1828         result = false;
     2524  DoLog(0) && (Log() << Verbose(0) << "Third Points are: " << endl);
     2525  for (TesselPointList::iterator it = CandidateLine.pointlist.begin(); it != CandidateLine.pointlist.end(); ++it) {
     2526    DoLog(0) && (Log() << Verbose(0) << " " << *(*it) << endl);
     2527  }
     2528
     2529  return true;
     2530}
     2531;
     2532
     2533/** Walks through Tesselation::OpenLines() and finds candidates for newly created ones.
     2534 * \param *&LCList atoms in LinkedCell list
     2535 * \param RADIUS radius of the virtual sphere
     2536 * \return true - for all open lines without candidates so far, a candidate has been found,
     2537 *         false - at least one open line without candidate still
     2538 */
     2539bool Tesselation::FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList)
     2540{
     2541  bool TesselationFailFlag = true;
     2542  CandidateForTesselation *baseline = NULL;
     2543  BoundaryTriangleSet *T = NULL;
     2544
     2545  for (CandidateMap::iterator Runner = OpenLines.begin(); Runner != OpenLines.end(); Runner++) {
     2546    baseline = Runner->second;
     2547    if (baseline->pointlist.empty()) {
     2548      assert((baseline->BaseLine->triangles.size() == 1) && ("Open line without exactly one attached triangle"));
     2549      T = (((baseline->BaseLine->triangles.begin()))->second);
     2550      DoLog(1) && (Log() << Verbose(1) << "Finding best candidate for open line " << *baseline->BaseLine << " of triangle " << *T << endl);
     2551      TesselationFailFlag = TesselationFailFlag && FindNextSuitableTriangle(*baseline, *T, RADIUS, LCList); //the line is there, so there is a triangle, but only one.
     2552    }
     2553  }
     2554  return TesselationFailFlag;
     2555}
     2556;
     2557
     2558/** Adds the present line and candidate point from \a &CandidateLine to the Tesselation.
     2559 * \param CandidateLine triangle to add
     2560 * \param RADIUS Radius of sphere
     2561 * \param *LC LinkedCell structure
     2562 * \NOTE we need the copy operator here as the original CandidateForTesselation is removed in
     2563 * AddTesselationLine() in AddCandidateTriangle()
     2564 */
     2565void Tesselation::AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC)
     2566{
     2567  Info FunctionInfo(__func__);
     2568  Vector Center;
     2569  TesselPoint * const TurningPoint = CandidateLine.BaseLine->endpoints[0]->node;
     2570  TesselPointList::iterator Runner;
     2571  TesselPointList::iterator Sprinter;
     2572
     2573  // fill the set of neighbours
     2574  TesselPointSet SetOfNeighbours;
     2575  SetOfNeighbours.insert(CandidateLine.BaseLine->endpoints[1]->node);
     2576  for (TesselPointList::iterator Runner = CandidateLine.pointlist.begin(); Runner != CandidateLine.pointlist.end(); Runner++)
     2577    SetOfNeighbours.insert(*Runner);
     2578  TesselPointList *connectedClosestPoints = GetCircleOfSetOfPoints(&SetOfNeighbours, TurningPoint, CandidateLine.BaseLine->endpoints[1]->node->node);
     2579
     2580  DoLog(0) && (Log() << Verbose(0) << "List of Candidates for Turning Point " << *TurningPoint << ":" << endl);
     2581  for (TesselPointList::iterator TesselRunner = connectedClosestPoints->begin(); TesselRunner != connectedClosestPoints->end(); ++TesselRunner)
     2582    DoLog(0) && (Log() << Verbose(0) << " " << **TesselRunner << endl);
     2583
     2584  // go through all angle-sorted candidates (in degenerate n-nodes case we may have to add multiple triangles)
     2585  Runner = connectedClosestPoints->begin();
     2586  Sprinter = Runner;
     2587  Sprinter++;
     2588  while (Sprinter != connectedClosestPoints->end()) {
     2589    DoLog(0) && (Log() << Verbose(0) << "Current Runner is " << *(*Runner) << " and sprinter is " << *(*Sprinter) << "." << endl);
     2590
     2591    AddTesselationPoint(TurningPoint, 0);
     2592    AddTesselationPoint(*Runner, 1);
     2593    AddTesselationPoint(*Sprinter, 2);
     2594
     2595    AddCandidateTriangle(CandidateLine, Opt);
     2596
     2597    Runner = Sprinter;
     2598    Sprinter++;
     2599    if (Sprinter != connectedClosestPoints->end()) {
     2600      // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
     2601      FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OptCenter); // Assume BTS contains last triangle
     2602      DoLog(0) && (Log() << Verbose(0) << " There are still more triangles to add." << endl);
     2603    }
     2604    // pick candidates for other open lines as well
     2605    FindCandidatesforOpenLines(RADIUS, LC);
     2606
     2607    // check whether we add a degenerate or a normal triangle
     2608    if (CheckDegeneracy(CandidateLine, RADIUS, LC)) {
     2609      // add normal and degenerate triangles
     2610      DoLog(1) && (Log() << Verbose(1) << "Triangle of endpoints " << *TPS[0] << "," << *TPS[1] << " and " << *TPS[2] << " is degenerated, adding both sides." << endl);
     2611      AddCandidateTriangle(CandidateLine, OtherOpt);
     2612
     2613      if (Sprinter != connectedClosestPoints->end()) {
     2614        // fill the internal open lines with its respective candidate (otherwise lines in degenerate case are not picked)
     2615        FindDegeneratedCandidatesforOpenLines(*Sprinter, &CandidateLine.OtherOptCenter);
    18292616      }
    1830     } else if ((existentTrianglesCount >= 1) && (existentTrianglesCount <= 3)) { // If there is a planar region within the structure, we need this triangle a second time.
    1831         AddTesselationPoint((*it)->point, 0);
    1832         AddTesselationPoint(BaseRay->endpoints[0]->node, 1);
    1833         AddTesselationPoint(BaseRay->endpoints[1]->node, 2);
    1834 
    1835         // We demand that at most one new degenerate line is created and that this line also already exists (which has to be the case due to existentTrianglesCount == 1)
    1836         // i.e. at least one of the three lines must be present with TriangleCount <= 1
    1837         if (CheckLineCriteriaForDegeneratedTriangle((const BoundaryPointSet ** const)TPS)) {
    1838           AddTesselationLine(TPS[0], TPS[1], 0);
    1839           AddTesselationLine(TPS[0], TPS[2], 1);
    1840           AddTesselationLine(TPS[1], TPS[2], 2);
    1841 
    1842           BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    1843           AddTesselationTriangle();  // add to global map
    1844 
    1845           (*it)->OtherOptCenter.Scale(-1.);
    1846           BTS->GetNormalVector((*it)->OtherOptCenter);
    1847           (*it)->OtherOptCenter.Scale(-1.);
    1848 
    1849           Log() << Verbose(0) << "--> WARNING: Special new triangle with " << *BTS << " and normal vector " << BTS->NormalVector
    1850           << " for this triangle ... " << endl;
    1851           Log() << Verbose(1) << "We have "<< BaseRay->triangles.size() << " for line " << BaseRay << "." << endl;
    1852         } else {
    1853           Log() << Verbose(1) << "WARNING: This triangle consisting of ";
    1854           Log() << Verbose(0) << *(*it)->point << ", ";
    1855           Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    1856           Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    1857           Log() << Verbose(0) << "exists and is not added, as it does not seem helpful!" << endl;
    1858           result = false;
    1859         }
    1860     } else {
    1861       Log() << Verbose(1) << "This triangle consisting of ";
    1862       Log() << Verbose(0) << *(*it)->point << ", ";
    1863       Log() << Verbose(0) << *BaseRay->endpoints[0]->node << " and ";
    1864       Log() << Verbose(0) << *BaseRay->endpoints[1]->node << " ";
    1865       Log() << Verbose(0) << "is invalid!" << endl;
    1866       result = false;
    1867     }
    1868 
    1869     // set baseline to new ray from ref point (here endpoints[0]->node) to current candidate (here (*it)->point))
    1870     BaseRay = BLS[0];
    1871     if ((BTS != NULL) && (BTS->NormalVector.NormSquared() < MYEPSILON)) {
    1872       Log() << Verbose(1) << "CRITICAL: Triangle " << *BTS << " has zero normal vector!" << endl;
    1873       exit(255);
    1874     }
    1875 
    1876   }
    1877 
    1878   // remove all candidates from the list and then the list itself
    1879   class CandidateForTesselation *remover = NULL;
    1880   for (CandidateList::iterator it = OptCandidates->begin(); it != OptCandidates->end(); ++it) {
    1881     remover = *it;
    1882     delete(remover);
    1883   }
    1884   delete(OptCandidates);
    1885   Log() << Verbose(0) << "End of FindNextSuitableTriangle\n";
    1886   return result;
     2617      // pick candidates for other open lines as well
     2618      FindCandidatesforOpenLines(RADIUS, LC);
     2619    }
     2620  }
     2621  delete (connectedClosestPoints);
    18872622};
     2623
     2624/** for polygons (multiple candidates for a baseline) sets internal edges to the correct next candidate.
     2625 * \param *Sprinter next candidate to which internal open lines are set
     2626 * \param *OptCenter OptCenter for this candidate
     2627 */
     2628void Tesselation::FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter)
     2629{
     2630  Info FunctionInfo(__func__);
     2631
     2632  pair<LineMap::iterator, LineMap::iterator> FindPair = TPS[0]->lines.equal_range(TPS[2]->node->nr);
     2633  for (LineMap::const_iterator FindLine = FindPair.first; FindLine != FindPair.second; FindLine++) {
     2634    DoLog(1) && (Log() << Verbose(1) << "INFO: Checking line " << *(FindLine->second) << " ..." << endl);
     2635    // If there is a line with less than two attached triangles, we don't need a new line.
     2636    if (FindLine->second->triangles.size() == 1) {
     2637      CandidateMap::iterator Finder = OpenLines.find(FindLine->second);
     2638      if (!Finder->second->pointlist.empty())
     2639        DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with candidate " << **(Finder->second->pointlist.begin()) << "." << endl);
     2640      else {
     2641        DoLog(1) && (Log() << Verbose(1) << "INFO: line " << *(FindLine->second) << " is open with no candidate, setting to next Sprinter" << (*Sprinter) << endl);
     2642        Finder->second->T = BTS;  // is last triangle
     2643        Finder->second->pointlist.push_back(Sprinter);
     2644        Finder->second->ShortestAngle = 0.;
     2645        Finder->second->OptCenter.CopyVector(OptCenter);
     2646      }
     2647    }
     2648  }
     2649};
     2650
     2651/** If a given \a *triangle is degenerated, this adds both sides.
     2652 * i.e. the triangle with same BoundaryPointSet's but NormalVector in opposite direction.
     2653 * Note that endpoints are stored in Tesselation::TPS
     2654 * \param CandidateLine CanddiateForTesselation structure for the desired BoundaryLine
     2655 * \param RADIUS radius of sphere
     2656 * \param *LC pointer to LinkedCell structure
     2657 */
     2658void Tesselation::AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC)
     2659{
     2660  Info FunctionInfo(__func__);
     2661  Vector Center;
     2662  CandidateMap::const_iterator CandidateCheck = OpenLines.end();
     2663  BoundaryTriangleSet *triangle = NULL;
     2664
     2665  /// 1. Create or pick the lines for the first triangle
     2666  DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for first triangle ..." << endl);
     2667  for (int i = 0; i < 3; i++) {
     2668    BLS[i] = NULL;
     2669    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2670    AddTesselationLine(&CandidateLine.OptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
     2671  }
     2672
     2673  /// 2. create the first triangle and NormalVector and so on
     2674  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding first triangle with center at " << CandidateLine.OptCenter << " ..." << endl);
     2675  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2676  AddTesselationTriangle();
     2677
     2678  // create normal vector
     2679  BTS->GetCenter(&Center);
     2680  Center.SubtractVector(&CandidateLine.OptCenter);
     2681  BTS->SphereCenter.CopyVector(&CandidateLine.OptCenter);
     2682  BTS->GetNormalVector(Center);
     2683  // give some verbose output about the whole procedure
     2684  if (CandidateLine.T != NULL)
     2685    DoLog(0) && (Log() << Verbose(0) << "--> New triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
     2686  else
     2687    DoLog(0) && (Log() << Verbose(0) << "--> New starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2688  triangle = BTS;
     2689
     2690  /// 3. Gather candidates for each new line
     2691  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding candidates to new lines ..." << endl);
     2692  for (int i = 0; i < 3; i++) {
     2693    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2694    CandidateCheck = OpenLines.find(BLS[i]);
     2695    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     2696      if (CandidateCheck->second->T == NULL)
     2697        CandidateCheck->second->T = triangle;
     2698      FindNextSuitableTriangle(*(CandidateCheck->second), *CandidateCheck->second->T, RADIUS, LC);
     2699    }
     2700  }
     2701
     2702  /// 4. Create or pick the lines for the second triangle
     2703  DoLog(0) && (Log() << Verbose(0) << "INFO: Creating/Picking lines for second triangle ..." << endl);
     2704  for (int i = 0; i < 3; i++) {
     2705    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2706    AddTesselationLine(&CandidateLine.OtherOptCenter, TPS[(i + 2) % 3], TPS[(i + 0) % 3], TPS[(i + 1) % 3], i);
     2707  }
     2708
     2709  /// 5. create the second triangle and NormalVector and so on
     2710  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangle with center at " << CandidateLine.OtherOptCenter << " ..." << endl);
     2711  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2712  AddTesselationTriangle();
     2713
     2714  BTS->SphereCenter.CopyVector(&CandidateLine.OtherOptCenter);
     2715  // create normal vector in other direction
     2716  BTS->GetNormalVector(&triangle->NormalVector);
     2717  BTS->NormalVector.Scale(-1.);
     2718  // give some verbose output about the whole procedure
     2719  if (CandidateLine.T != NULL)
     2720    DoLog(0) && (Log() << Verbose(0) << "--> New degenerate triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
     2721  else
     2722    DoLog(0) && (Log() << Verbose(0) << "--> New degenerate starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2723
     2724  /// 6. Adding triangle to new lines
     2725  DoLog(0) && (Log() << Verbose(0) << "INFO: Adding second triangles to new lines ..." << endl);
     2726  for (int i = 0; i < 3; i++) {
     2727    DoLog(0) && (Log() << Verbose(0) << "Current line is between " << *TPS[(i + 0) % 3] << " and " << *TPS[(i + 1) % 3] << ":" << endl);
     2728    CandidateCheck = OpenLines.find(BLS[i]);
     2729    if ((CandidateCheck != OpenLines.end()) && (CandidateCheck->second->pointlist.empty())) {
     2730      if (CandidateCheck->second->T == NULL)
     2731        CandidateCheck->second->T = BTS;
     2732    }
     2733  }
     2734}
     2735;
     2736
     2737/** Adds a triangle to the Tesselation structure from three given TesselPoint's.
     2738 * Note that endpoints are in Tesselation::TPS.
     2739 * \param CandidateLine CandidateForTesselation structure contains other information
     2740 * \param type which opt center to add (i.e. which side) and thus which NormalVector to take
     2741 */
     2742void Tesselation::AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type)
     2743{
     2744  Info FunctionInfo(__func__);
     2745  Vector Center;
     2746  Vector *OptCenter = (type == Opt) ? &CandidateLine.OptCenter : &CandidateLine.OtherOptCenter;
     2747
     2748  // add the lines
     2749  AddTesselationLine(OptCenter, TPS[2], TPS[0], TPS[1], 0);
     2750  AddTesselationLine(OptCenter, TPS[1], TPS[0], TPS[2], 1);
     2751  AddTesselationLine(OptCenter, TPS[0], TPS[1], TPS[2], 2);
     2752
     2753  // add the triangles
     2754  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
     2755  AddTesselationTriangle();
     2756
     2757  // create normal vector
     2758  BTS->GetCenter(&Center);
     2759  Center.SubtractVector(OptCenter);
     2760  BTS->SphereCenter.CopyVector(OptCenter);
     2761  BTS->GetNormalVector(Center);
     2762
     2763  // give some verbose output about the whole procedure
     2764  if (CandidateLine.T != NULL)
     2765    DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "triangle with " << *BTS << " and normal vector " << BTS->NormalVector << ", from " << *CandidateLine.T << " and angle " << CandidateLine.ShortestAngle << "." << endl);
     2766  else
     2767    DoLog(0) && (Log() << Verbose(0) << "--> New" << ((type == OtherOpt) ? " degenerate " : " ") << "starting triangle with " << *BTS << " and normal vector " << BTS->NormalVector << " and no top triangle." << endl);
     2768}
     2769;
    18882770
    18892771/** Checks whether the quadragon of the two triangles connect to \a *Base is convex.
     
    18962778class BoundaryPointSet *Tesselation::IsConvexRectangle(class BoundaryLineSet *Base)
    18972779{
     2780  Info FunctionInfo(__func__);
    18982781  class BoundaryPointSet *Spot = NULL;
    18992782  class BoundaryLineSet *OtherBase;
    19002783  Vector *ClosestPoint;
    19012784
    1902   int m=0;
    1903   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    1904     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2785  int m = 0;
     2786  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2787    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    19052788      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
    19062789        BPS[m++] = runner->second->endpoints[j];
    1907   OtherBase = new class BoundaryLineSet(BPS,-1);
    1908 
    1909   Log() << Verbose(3) << "INFO: Current base line is " << *Base << "." << endl;
    1910   Log() << Verbose(3) << "INFO: Other base line is " << *OtherBase << "." << endl;
     2790  OtherBase = new class BoundaryLineSet(BPS, -1);
     2791
     2792  DoLog(1) && (Log() << Verbose(1) << "INFO: Current base line is " << *Base << "." << endl);
     2793  DoLog(1) && (Log() << Verbose(1) << "INFO: Other base line is " << *OtherBase << "." << endl);
    19112794
    19122795  // get the closest point on each line to the other line
     
    19142797
    19152798  // delete the temporary other base line
    1916   delete(OtherBase);
     2799  delete (OtherBase);
    19172800
    19182801  // get the distance vector from Base line to OtherBase line
     
    19212804  BaseLine.CopyVector(Base->endpoints[1]->node->node);
    19222805  BaseLine.SubtractVector(Base->endpoints[0]->node->node);
    1923   for (int i=0;i<2;i++) {
     2806  for (int i = 0; i < 2; i++) {
    19242807    DistanceToIntersection[i].CopyVector(ClosestPoint);
    19252808    DistanceToIntersection[i].SubtractVector(Base->endpoints[i]->node->node);
    19262809    distance[i] = BaseLine.ScalarProduct(&DistanceToIntersection[i]);
    19272810  }
    1928   delete(ClosestPoint);
    1929   if ((distance[0] * distance[1]) > 0)  { // have same sign?
    1930     Log() << Verbose(3) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1]  << ". " << *Base << "' rectangle is concave." << endl;
     2811  delete (ClosestPoint);
     2812  if ((distance[0] * distance[1]) > 0) { // have same sign?
     2813    DoLog(1) && (Log() << Verbose(1) << "REJECT: Both SKPs have same sign: " << distance[0] << " and " << distance[1] << ". " << *Base << "' rectangle is concave." << endl);
    19312814    if (distance[0] < distance[1]) {
    19322815      Spot = Base->endpoints[0];
     
    19352818    }
    19362819    return Spot;
    1937   } else {  // different sign, i.e. we are in between
    1938     Log() << Verbose(3) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl;
     2820  } else { // different sign, i.e. we are in between
     2821    DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Rectangle of triangles of base line " << *Base << " is convex." << endl);
    19392822    return NULL;
    19402823  }
    19412824
    1942 };
     2825}
     2826;
    19432827
    19442828void Tesselation::PrintAllBoundaryPoints(ofstream *out) const
    19452829{
     2830  Info FunctionInfo(__func__);
    19462831  // print all lines
    1947   Log() << Verbose(1) << "Printing all boundary points for debugging:" << endl;
    1948   for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin();PointRunner != PointsOnBoundary.end(); PointRunner++)
    1949     Log() << Verbose(2) << *(PointRunner->second) << endl;
    1950 };
     2832  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary points for debugging:" << endl);
     2833  for (PointMap::const_iterator PointRunner = PointsOnBoundary.begin(); PointRunner != PointsOnBoundary.end(); PointRunner++)
     2834    DoLog(0) && (Log() << Verbose(0) << *(PointRunner->second) << endl);
     2835}
     2836;
    19512837
    19522838void Tesselation::PrintAllBoundaryLines(ofstream *out) const
    19532839{
     2840  Info FunctionInfo(__func__);
    19542841  // print all lines
    1955   Log() << Verbose(1) << "Printing all boundary lines for debugging:" << endl;
     2842  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary lines for debugging:" << endl);
    19562843  for (LineMap::const_iterator LineRunner = LinesOnBoundary.begin(); LineRunner != LinesOnBoundary.end(); LineRunner++)
    1957     Log() << Verbose(2) << *(LineRunner->second) << endl;
    1958 };
     2844    DoLog(0) && (Log() << Verbose(0) << *(LineRunner->second) << endl);
     2845}
     2846;
    19592847
    19602848void Tesselation::PrintAllBoundaryTriangles(ofstream *out) const
    19612849{
     2850  Info FunctionInfo(__func__);
    19622851  // print all triangles
    1963   Log() << Verbose(1) << "Printing all boundary triangles for debugging:" << endl;
     2852  DoLog(0) && (Log() << Verbose(0) << "Printing all boundary triangles for debugging:" << endl);
    19642853  for (TriangleMap::const_iterator TriangleRunner = TrianglesOnBoundary.begin(); TriangleRunner != TrianglesOnBoundary.end(); TriangleRunner++)
    1965     Log() << Verbose(2) << *(TriangleRunner->second) << endl;
    1966 };
     2854    DoLog(0) && (Log() << Verbose(0) << *(TriangleRunner->second) << endl);
     2855}
     2856;
    19672857
    19682858/** For a given boundary line \a *Base and its two triangles, picks the central baseline that is "higher".
     
    19732863double Tesselation::PickFarthestofTwoBaselines(class BoundaryLineSet *Base)
    19742864{
     2865  Info FunctionInfo(__func__);
    19752866  class BoundaryLineSet *OtherBase;
    19762867  Vector *ClosestPoint[2];
    19772868  double volume;
    19782869
    1979   int m=0;
    1980   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    1981     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2870  int m = 0;
     2871  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2872    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    19822873      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) // and neither of its endpoints
    19832874        BPS[m++] = runner->second->endpoints[j];
    1984   OtherBase = new class BoundaryLineSet(BPS,-1);
    1985 
    1986   Log() << Verbose(3) << "INFO: Current base line is " << *Base << "." << endl;
    1987   Log() << Verbose(3) << "INFO: Other base line is " << *OtherBase << "." << endl;
     2875  OtherBase = new class BoundaryLineSet(BPS, -1);
     2876
     2877  DoLog(0) && (Log() << Verbose(0) << "INFO: Current base line is " << *Base << "." << endl);
     2878  DoLog(0) && (Log() << Verbose(0) << "INFO: Other base line is " << *OtherBase << "." << endl);
    19882879
    19892880  // get the closest point on each line to the other line
     
    20002891
    20012892  // delete the temporary other base line and the closest points
    2002   delete(ClosestPoint[0]);
    2003   delete(ClosestPoint[1]);
    2004   delete(OtherBase);
     2893  delete (ClosestPoint[0]);
     2894  delete (ClosestPoint[1]);
     2895  delete (OtherBase);
    20052896
    20062897  if (Distance.NormSquared() < MYEPSILON) { // check for intersection
    2007     Log() << Verbose(3) << "REJECT: Both lines have an intersection: Nothing to do." << endl;
     2898    DoLog(0) && (Log() << Verbose(0) << "REJECT: Both lines have an intersection: Nothing to do." << endl);
    20082899    return false;
    20092900  } else { // check for sign against BaseLineNormal
     
    20112902    BaseLineNormal.Zero();
    20122903    if (Base->triangles.size() < 2) {
    2013       Log() << Verbose(2) << "ERROR: Less than two triangles are attached to this baseline!" << endl;
     2904      DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
    20142905      return 0.;
    20152906    }
    20162907    for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2017       Log() << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
     2908      DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
    20182909      BaseLineNormal.AddVector(&(runner->second->NormalVector));
    20192910    }
    2020     BaseLineNormal.Scale(1./2.);
     2911    BaseLineNormal.Scale(1. / 2.);
    20212912
    20222913    if (Distance.ScalarProduct(&BaseLineNormal) > MYEPSILON) { // Distance points outwards, hence OtherBase higher than Base -> flip
    2023       Log() << Verbose(2) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl;
     2914      DoLog(0) && (Log() << Verbose(0) << "ACCEPT: Other base line would be higher: Flipping baseline." << endl);
    20242915      // calculate volume summand as a general tetraeder
    20252916      return volume;
    2026     } else {  // Base higher than OtherBase -> do nothing
    2027       Log() << Verbose(2) << "REJECT: Base line is higher: Nothing to do." << endl;
     2917    } else { // Base higher than OtherBase -> do nothing
     2918      DoLog(0) && (Log() << Verbose(0) << "REJECT: Base line is higher: Nothing to do." << endl);
    20282919      return 0.;
    20292920    }
    20302921  }
    2031 };
     2922}
     2923;
    20322924
    20332925/** For a given baseline and its two connected triangles, flips the baseline.
     
    20402932class BoundaryLineSet * Tesselation::FlipBaseline(class BoundaryLineSet *Base)
    20412933{
     2934  Info FunctionInfo(__func__);
    20422935  class BoundaryLineSet *OldLines[4], *NewLine;
    20432936  class BoundaryPointSet *OldPoints[2];
    20442937  Vector BaseLineNormal;
    20452938  int OldTriangleNrs[2], OldBaseLineNr;
    2046   int i,m;
    2047 
    2048   Log() << Verbose(1) << "Begin of FlipBaseline" << endl;
     2939  int i, m;
    20492940
    20502941  // calculate NormalVector for later use
    20512942  BaseLineNormal.Zero();
    20522943  if (Base->triangles.size() < 2) {
    2053     Log() << Verbose(2) << "ERROR: Less than two triangles are attached to this baseline!" << endl;
     2944    DoeLog(1) && (eLog() << Verbose(1) << "Less than two triangles are attached to this baseline!" << endl);
    20542945    return NULL;
    20552946  }
    20562947  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2057     Log() << Verbose(4) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl;
     2948    DoLog(1) && (Log() << Verbose(1) << "INFO: Adding NormalVector " << runner->second->NormalVector << " of triangle " << *(runner->second) << "." << endl);
    20582949    BaseLineNormal.AddVector(&(runner->second->NormalVector));
    20592950  }
    2060   BaseLineNormal.Scale(-1./2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
     2951  BaseLineNormal.Scale(-1. / 2.); // has to point inside for BoundaryTriangleSet::GetNormalVector()
    20612952
    20622953  // get the two triangles
    20632954  // gather four endpoints and four lines
    2064   for (int j=0;j<4;j++)
     2955  for (int j = 0; j < 4; j++)
    20652956    OldLines[j] = NULL;
    2066   for (int j=0;j<2;j++)
     2957  for (int j = 0; j < 2; j++)
    20672958    OldPoints[j] = NULL;
    2068   i=0;
    2069   m=0;
    2070   Log() << Verbose(3) << "The four old lines are: ";
    2071   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2072     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2959  i = 0;
     2960  m = 0;
     2961  DoLog(0) && (Log() << Verbose(0) << "The four old lines are: ");
     2962  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2963    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    20732964      if (runner->second->lines[j] != Base) { // pick not the central baseline
    20742965        OldLines[i++] = runner->second->lines[j];
    2075         Log() << Verbose(0) << *runner->second->lines[j] << "\t";
     2966        DoLog(0) && (Log() << Verbose(0) << *runner->second->lines[j] << "\t");
    20762967      }
    2077   Log() << Verbose(0) << endl;
    2078   Log() << Verbose(3) << "The two old points are: ";
    2079   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
    2080     for (int j=0;j<3;j++) // all of their endpoints and baselines
     2968  DoLog(0) && (Log() << Verbose(0) << endl);
     2969  DoLog(0) && (Log() << Verbose(0) << "The two old points are: ");
     2970  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++)
     2971    for (int j = 0; j < 3; j++) // all of their endpoints and baselines
    20812972      if (!Base->ContainsBoundaryPoint(runner->second->endpoints[j])) { // and neither of its endpoints
    20822973        OldPoints[m++] = runner->second->endpoints[j];
    2083         Log() << Verbose(0) << *runner->second->endpoints[j] << "\t";
     2974        DoLog(0) && (Log() << Verbose(0) << *runner->second->endpoints[j] << "\t");
    20842975      }
    2085   Log() << Verbose(0) << endl;
     2976  DoLog(0) && (Log() << Verbose(0) << endl);
    20862977
    20872978  // check whether everything is in place to create new lines and triangles
    2088   if (i<4) {
    2089     Log() << Verbose(1) << "ERROR: We have not gathered enough baselines!" << endl;
     2979  if (i < 4) {
     2980    DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
    20902981    return NULL;
    20912982  }
    2092   for (int j=0;j<4;j++)
     2983  for (int j = 0; j < 4; j++)
    20932984    if (OldLines[j] == NULL) {
    2094       Log() << Verbose(1) << "ERROR: We have not gathered enough baselines!" << endl;
     2985      DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough baselines!" << endl);
    20952986      return NULL;
    20962987    }
    2097   for (int j=0;j<2;j++)
     2988  for (int j = 0; j < 2; j++)
    20982989    if (OldPoints[j] == NULL) {
    2099       Log() << Verbose(1) << "ERROR: We have not gathered enough endpoints!" << endl;
     2990      DoeLog(1) && (eLog() << Verbose(1) << "We have not gathered enough endpoints!" << endl);
    21002991      return NULL;
    21012992    }
    21022993
    21032994  // remove triangles and baseline removes itself
    2104   Log() << Verbose(3) << "INFO: Deleting baseline " << *Base << " from global list." << endl;
     2995  DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting baseline " << *Base << " from global list." << endl);
    21052996  OldBaseLineNr = Base->Nr;
    2106   m=0;
    2107   for(TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
    2108     Log() << Verbose(3) << "INFO: Deleting triangle " << *(runner->second) << "." << endl;
     2997  m = 0;
     2998  for (TriangleMap::iterator runner = Base->triangles.begin(); runner != Base->triangles.end(); runner++) {
     2999    DoLog(0) && (Log() << Verbose(0) << "INFO: Deleting triangle " << *(runner->second) << "." << endl);
    21093000    OldTriangleNrs[m++] = runner->second->Nr;
    21103001    RemoveTesselationTriangle(runner->second);
     
    21163007  NewLine = new class BoundaryLineSet(BPS, OldBaseLineNr);
    21173008  LinesOnBoundary.insert(LinePair(OldBaseLineNr, NewLine)); // no need for check for unique insertion as NewLine is definitely a new one
    2118   Log() << Verbose(3) << "INFO: Created new baseline " << *NewLine << "." << endl;
     3009  DoLog(0) && (Log() << Verbose(0) << "INFO: Created new baseline " << *NewLine << "." << endl);
    21193010
    21203011  // construct new triangles with flipped baseline
    2121   i=-1;
     3012  i = -1;
    21223013  if (OldLines[0]->IsConnectedTo(OldLines[2]))
    2123     i=2;
     3014    i = 2;
    21243015  if (OldLines[0]->IsConnectedTo(OldLines[3]))
    2125     i=3;
    2126   if (i!=-1) {
     3016    i = 3;
     3017  if (i != -1) {
    21273018    BLS[0] = OldLines[0];
    21283019    BLS[1] = OldLines[i];
     
    21313022    BTS->GetNormalVector(BaseLineNormal);
    21323023    AddTesselationTriangle(OldTriangleNrs[0]);
    2133     Log() << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
    2134 
    2135     BLS[0] = (i==2 ? OldLines[3] : OldLines[2]);
     3024    DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
     3025
     3026    BLS[0] = (i == 2 ? OldLines[3] : OldLines[2]);
    21363027    BLS[1] = OldLines[1];
    21373028    BLS[2] = NewLine;
     
    21393030    BTS->GetNormalVector(BaseLineNormal);
    21403031    AddTesselationTriangle(OldTriangleNrs[1]);
    2141     Log() << Verbose(3) << "INFO: Created new triangle " << *BTS << "." << endl;
     3032    DoLog(0) && (Log() << Verbose(0) << "INFO: Created new triangle " << *BTS << "." << endl);
    21423033  } else {
    2143     Log() << Verbose(1) << "The four old lines do not connect, something's utterly wrong here!" << endl;
     3034    DoeLog(0) && (eLog() << Verbose(0) << "The four old lines do not connect, something's utterly wrong here!" << endl);
    21443035    return NULL;
    21453036  }
    21463037
    2147   Log() << Verbose(1) << "End of FlipBaseline" << endl;
    21483038  return NewLine;
    2149 };
    2150 
     3039}
     3040;
    21513041
    21523042/** Finds the second point of starting triangle.
     
    21603050void Tesselation::FindSecondPointForTesselation(TesselPoint* a, Vector Oben, TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC)
    21613051{
    2162   Log() << Verbose(2) << "Begin of FindSecondPointForTesselation" << endl;
     3052  Info FunctionInfo(__func__);
    21633053  Vector AngleCheck;
    21643054  class TesselPoint* Candidate = NULL;
     
    21693059  int Nupper[NDIM];
    21703060
    2171   if (LC->SetIndexToNode(a)) {  // get cell for the starting point
    2172     for(int i=0;i<NDIM;i++) // store indices of this cell
     3061  if (LC->SetIndexToNode(a)) { // get cell for the starting point
     3062    for (int i = 0; i < NDIM; i++) // store indices of this cell
    21733063      N[i] = LC->n[i];
    21743064  } else {
    2175     eLog() << Verbose(0) << "ERROR: Point " << *a << " is not found in cell " << LC->index << "." << endl;
     3065    DoeLog(1) && (eLog() << Verbose(1) << "Point " << *a << " is not found in cell " << LC->index << "." << endl);
    21763066    return;
    21773067  }
    21783068  // then go through the current and all neighbouring cells and check the contained points for possible candidates
    2179   Log() << Verbose(3) << "LC Intervals from [";
    2180   for (int i=0;i<NDIM;i++) {
    2181   Log() << Verbose(0) << " " << N[i] << "<->" << LC->N[i];
    2182   }
    2183   Log() << Verbose(0) << "] :";
    2184   for (int i=0;i<NDIM;i++) {
    2185     Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
    2186     Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
    2187     Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
    2188   }
    2189   Log() << Verbose(0) << endl;
    2190 
     3069  for (int i = 0; i < NDIM; i++) {
     3070    Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
     3071    Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
     3072  }
     3073  DoLog(0) && (Log() << Verbose(0) << "LC Intervals from [" << N[0] << "<->" << LC->N[0] << ", " << N[1] << "<->" << LC->N[1] << ", " << N[2] << "<->" << LC->N[2] << "] :" << " [" << Nlower[0] << "," << Nupper[0] << "], " << " [" << Nlower[1] << "," << Nupper[1] << "], " << " [" << Nlower[2] << "," << Nupper[2] << "], " << endl);
    21913074
    21923075  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    21933076    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    21943077      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    2195         const LinkedNodes *List = LC->GetCurrentCell();
    2196         //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     3078        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
     3079        //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    21973080        if (List != NULL) {
    2198           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3081          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    21993082            Candidate = (*Runner);
    22003083            // check if we only have one unique point yet ...
     
    22223105              norm = aCandidate.Norm();
    22233106              // second point shall have smallest angle with respect to Oben vector
    2224               if (norm < RADIUS*2.) {
     3107              if (norm < RADIUS * 2.) {
    22253108                angle = AngleCheck.Angle(&Oben);
    22263109                if (angle < Storage[0]) {
    2227                   //Log() << Verbose(3) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
    2228                   Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n";
     3110                  //Log() << Verbose(1) << "Old values of Storage: %lf %lf \n", Storage[0], Storage[1]);
     3111                  DoLog(1) && (Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Is a better candidate with distance " << norm << " and angle " << angle << " to oben " << Oben << ".\n");
    22293112                  OptCandidate = Candidate;
    22303113                  Storage[0] = angle;
    2231                   //Log() << Verbose(3) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
     3114                  //Log() << Verbose(1) << "Changing something in Storage: %lf %lf. \n", Storage[0], Storage[2]);
    22323115                } else {
    2233                   //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
     3116                  //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Looses with angle " << angle << " to a better candidate " << *OptCandidate << endl;
    22343117                }
    22353118              } else {
    2236                 //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
     3119                //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Refused due to Radius " << norm << endl;
    22373120              }
    22383121            } else {
    2239               //Log() << Verbose(3) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
     3122              //Log() << Verbose(1) << "Current candidate is " << *Candidate << ": Candidate is equal to first endpoint." << *a << "." << endl;
    22403123            }
    22413124          }
    22423125        } else {
    2243           Log() << Verbose(3) << "Linked cell list is empty." << endl;
     3126          DoLog(0) && (Log() << Verbose(0) << "Linked cell list is empty." << endl);
    22443127        }
    22453128      }
    2246   Log() << Verbose(2) << "End of FindSecondPointForTesselation" << endl;
    2247 };
    2248 
     3129}
     3130;
    22493131
    22503132/** This recursive function finds a third point, to form a triangle with two given ones.
     
    22733155 * @param SearchDirection general direction where to search for the next point, relative to center of BaseLine
    22743156 * @param OldSphereCenter center of sphere for base triangle, relative to center of BaseLine, giving null angle for the parameter circle
    2275  * @param BaseLine BoundaryLineSet with the current base line
    2276  * @param ThirdNode third point to avoid in search
    2277  * @param candidates list of equally good candidates to return
    2278  * @param ShortestAngle the current path length on this circle band for the current OptCandidate
     3157 * @param CandidateLine CandidateForTesselation with the current base line and list of candidates and ShortestAngle
     3158 * @param ThirdPoint third point to avoid in search
    22793159 * @param RADIUS radius of sphere
    22803160 * @param *LC LinkedCell structure with neighbouring points
    22813161 */
    2282 void Tesselation::FindThirdPointForTesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint  *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC)
    2283 {
    2284   Vector CircleCenter;  // center of the circle, i.e. of the band of sphere's centers
     3162void Tesselation::FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet * const ThirdPoint, const double RADIUS, const LinkedCell *LC) const
     3163{
     3164  Info FunctionInfo(__func__);
     3165  Vector CircleCenter; // center of the circle, i.e. of the band of sphere's centers
    22853166  Vector CirclePlaneNormal; // normal vector defining the plane this circle lives in
    22863167  Vector SphereCenter;
    2287   Vector NewSphereCenter;   // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
    2288   Vector OtherNewSphereCenter;   // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
    2289   Vector NewNormalVector;   // normal vector of the Candidate's triangle
     3168  Vector NewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, first possibility
     3169  Vector OtherNewSphereCenter; // center of the sphere defined by the two points of BaseLine and the one of Candidate, second possibility
     3170  Vector NewNormalVector; // normal vector of the Candidate's triangle
    22903171  Vector helper, OptCandidateCenter, OtherOptCandidateCenter;
     3172  Vector RelativeOldSphereCenter;
     3173  Vector NewPlaneCenter;
    22913174  double CircleRadius; // radius of this circle
    22923175  double radius;
     3176  double otherradius;
    22933177  double alpha, Otheralpha; // angles (i.e. parameter for the circle).
    22943178  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
    22953179  TesselPoint *Candidate = NULL;
    2296   CandidateForTesselation *optCandidate = NULL;
    2297 
    2298   Log() << Verbose(1) << "Begin of FindThirdPointForTesselation" << endl;
    2299 
    2300   Log() << Verbose(2) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl;
     3180
     3181  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of BaseTriangle is " << NormalVector << "." << endl);
     3182
     3183  // copy old center
     3184  CandidateLine.OldCenter.CopyVector(&OldSphereCenter);
     3185  CandidateLine.ThirdPoint = ThirdPoint;
     3186  CandidateLine.pointlist.clear();
    23013187
    23023188  // construct center of circle
    2303   CircleCenter.CopyVector(BaseLine->endpoints[0]->node->node);
    2304   CircleCenter.AddVector(BaseLine->endpoints[1]->node->node);
     3189  CircleCenter.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     3190  CircleCenter.AddVector(CandidateLine.BaseLine->endpoints[1]->node->node);
    23053191  CircleCenter.Scale(0.5);
    23063192
    23073193  // construct normal vector of circle
    2308   CirclePlaneNormal.CopyVector(BaseLine->endpoints[0]->node->node);
    2309   CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
    2310 
    2311   // calculate squared radius TesselPoint *ThirdNode,f circle
    2312   radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    2313   if (radius/4. < RADIUS*RADIUS) {
    2314     CircleRadius = RADIUS*RADIUS - radius/4.;
     3194  CirclePlaneNormal.CopyVector(CandidateLine.BaseLine->endpoints[0]->node->node);
     3195  CirclePlaneNormal.SubtractVector(CandidateLine.BaseLine->endpoints[1]->node->node);
     3196
     3197  RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
     3198  RelativeOldSphereCenter.SubtractVector(&CircleCenter);
     3199
     3200  // calculate squared radius TesselPoint *ThirdPoint,f circle
     3201  radius = CirclePlaneNormal.NormSquared() / 4.;
     3202  if (radius < RADIUS * RADIUS) {
     3203    CircleRadius = RADIUS * RADIUS - radius;
    23153204    CirclePlaneNormal.Normalize();
    2316     //Log() << Verbose(2) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl;
     3205    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
    23173206
    23183207    // test whether old center is on the band's plane
    2319     if (fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    2320       eLog() << Verbose(0) << "ERROR: Something's very wrong here: OldSphereCenter is not on the band's plane as desired by " << fabs(OldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl;
    2321       OldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
    2322     }
    2323     radius = OldSphereCenter.ScalarProduct(&OldSphereCenter);
     3208    if (fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
     3209      DoeLog(1) && (eLog() << Verbose(1) << "Something's very wrong here: RelativeOldSphereCenter is not on the band's plane as desired by " << fabs(RelativeOldSphereCenter.ScalarProduct(&CirclePlaneNormal)) << "!" << endl);
     3210      RelativeOldSphereCenter.ProjectOntoPlane(&CirclePlaneNormal);
     3211    }
     3212    radius = RelativeOldSphereCenter.NormSquared();
    23243213    if (fabs(radius - CircleRadius) < HULLEPSILON) {
    2325       //Log() << Verbose(2) << "INFO: OldSphereCenter is at " << OldSphereCenter << "." << endl;
     3214      DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeOldSphereCenter is at " << RelativeOldSphereCenter << "." << endl);
    23263215
    23273216      // check SearchDirection
    2328       //Log() << Verbose(2) << "INFO: SearchDirection is " << SearchDirection << "." << endl;
    2329       if (fabs(OldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
    2330         eLog() << Verbose(0) << "ERROR: SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl;
     3217      DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
     3218      if (fabs(RelativeOldSphereCenter.ScalarProduct(&SearchDirection)) > HULLEPSILON) { // rotated the wrong way!
     3219        DoeLog(1) && (eLog() << Verbose(1) << "SearchDirection and RelativeOldSphereCenter are not orthogonal!" << endl);
    23313220      }
    23323221
    23333222      // get cell for the starting point
    23343223      if (LC->SetIndexToVector(&CircleCenter)) {
    2335         for(int i=0;i<NDIM;i++) // store indices of this cell
    2336         N[i] = LC->n[i];
    2337         //Log() << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     3224        for (int i = 0; i < NDIM; i++) // store indices of this cell
     3225          N[i] = LC->n[i];
     3226        //Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
    23383227      } else {
    2339         eLog() << Verbose(0) << "ERROR: Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl;
     3228        DoeLog(1) && (eLog() << Verbose(1) << "Vector " << CircleCenter << " is outside of LinkedCell's bounding box." << endl);
    23403229        return;
    23413230      }
    23423231      // then go through the current and all neighbouring cells and check the contained points for possible candidates
    2343       //Log() << Verbose(2) << "LC Intervals:";
    2344       for (int i=0;i<NDIM;i++) {
    2345         Nlower[i] = ((N[i]-1) >= 0) ? N[i]-1 : 0;
    2346         Nupper[i] = ((N[i]+1) < LC->N[i]) ? N[i]+1 : LC->N[i]-1;
     3232      //Log() << Verbose(1) << "LC Intervals:";
     3233      for (int i = 0; i < NDIM; i++) {
     3234        Nlower[i] = ((N[i] - 1) >= 0) ? N[i] - 1 : 0;
     3235        Nupper[i] = ((N[i] + 1) < LC->N[i]) ? N[i] + 1 : LC->N[i] - 1;
    23473236        //Log() << Verbose(0) << " [" << Nlower[i] << "," << Nupper[i] << "] ";
    23483237      }
     
    23513240        for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    23523241          for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    2353             const LinkedNodes *List = LC->GetCurrentCell();
    2354             //Log() << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     3242            const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
     3243            //Log() << Verbose(1) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
    23553244            if (List != NULL) {
    2356               for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3245              for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    23573246                Candidate = (*Runner);
    23583247
    23593248                // check for three unique points
    2360                 //Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " at " << Candidate->node << "." << endl;
    2361                 if ((Candidate != BaseLine->endpoints[0]->node) && (Candidate != BaseLine->endpoints[1]->node) ){
    2362 
    2363                   // construct both new centers
    2364                   GetCenterofCircumcircle(&NewSphereCenter, *BaseLine->endpoints[0]->node->node, *BaseLine->endpoints[1]->node->node, *Candidate->node);
    2365                   OtherNewSphereCenter.CopyVector(&NewSphereCenter);
    2366 
    2367                   if ((NewNormalVector.MakeNormalVector(BaseLine->endpoints[0]->node->node, BaseLine->endpoints[1]->node->node, Candidate->node))
    2368                   && (fabs(NewNormalVector.ScalarProduct(&NewNormalVector)) > HULLEPSILON)
    2369                   ) {
    2370                     helper.CopyVector(&NewNormalVector);
    2371                     //Log() << Verbose(2) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl;
    2372                     radius = BaseLine->endpoints[0]->node->node->DistanceSquared(&NewSphereCenter);
    2373                     if (radius < RADIUS*RADIUS) {
    2374                       helper.Scale(sqrt(RADIUS*RADIUS - radius));
    2375                       //Log() << Verbose(2) << "INFO: Distance of NewCircleCenter to NewSphereCenter is " << helper.Norm() << " with sphere radius " << RADIUS << "." << endl;
    2376                       NewSphereCenter.AddVector(&helper);
    2377                       NewSphereCenter.SubtractVector(&CircleCenter);
    2378                       //Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl;
    2379 
    2380                       // OtherNewSphereCenter is created by the same vector just in the other direction
    2381                       helper.Scale(-1.);
    2382                       OtherNewSphereCenter.AddVector(&helper);
    2383                       OtherNewSphereCenter.SubtractVector(&CircleCenter);
    2384                       //Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl;
    2385 
    2386                       alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    2387                       Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
    2388                       alpha = min(alpha, Otheralpha);
    2389                       // if there is a better candidate, drop the current list and add the new candidate
    2390                       // otherwise ignore the new candidate and keep the list
    2391                       if (*ShortestAngle > (alpha - HULLEPSILON)) {
    2392                         optCandidate = new CandidateForTesselation(Candidate, BaseLine, OptCandidateCenter, OtherOptCandidateCenter);
    2393                         if (fabs(alpha - Otheralpha) > MYEPSILON) {
    2394                           optCandidate->OptCenter.CopyVector(&NewSphereCenter);
    2395                           optCandidate->OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     3249                DoLog(2) && (Log() << Verbose(2) << "INFO: Current Candidate is " << *Candidate << " for BaseLine " << *CandidateLine.BaseLine << " with OldSphereCenter " << OldSphereCenter << "." << endl);
     3250                if ((Candidate != CandidateLine.BaseLine->endpoints[0]->node) && (Candidate != CandidateLine.BaseLine->endpoints[1]->node)) {
     3251
     3252                  // find center on the plane
     3253                  GetCenterofCircumcircle(&NewPlaneCenter, *CandidateLine.BaseLine->endpoints[0]->node->node, *CandidateLine.BaseLine->endpoints[1]->node->node, *Candidate->node);
     3254                  DoLog(1) && (Log() << Verbose(1) << "INFO: NewPlaneCenter is " << NewPlaneCenter << "." << endl);
     3255
     3256                  if (NewNormalVector.MakeNormalVector(CandidateLine.BaseLine->endpoints[0]->node->node, CandidateLine.BaseLine->endpoints[1]->node->node, Candidate->node) && (fabs(NewNormalVector.NormSquared()) > HULLEPSILON)) {
     3257                    DoLog(1) && (Log() << Verbose(1) << "INFO: NewNormalVector is " << NewNormalVector << "." << endl);
     3258                    radius = CandidateLine.BaseLine->endpoints[0]->node->node->DistanceSquared(&NewPlaneCenter);
     3259                    DoLog(1) && (Log() << Verbose(1) << "INFO: CircleCenter is at " << CircleCenter << ", CirclePlaneNormal is " << CirclePlaneNormal << " with circle radius " << sqrt(CircleRadius) << "." << endl);
     3260                    DoLog(1) && (Log() << Verbose(1) << "INFO: SearchDirection is " << SearchDirection << "." << endl);
     3261                    DoLog(1) && (Log() << Verbose(1) << "INFO: Radius of CircumCenterCircle is " << radius << "." << endl);
     3262                    if (radius < RADIUS * RADIUS) {
     3263                      otherradius = CandidateLine.BaseLine->endpoints[1]->node->node->DistanceSquared(&NewPlaneCenter);
     3264                      if (fabs(radius - otherradius) < HULLEPSILON) {
     3265                        // construct both new centers
     3266                        NewSphereCenter.CopyVector(&NewPlaneCenter);
     3267                        OtherNewSphereCenter.CopyVector(&NewPlaneCenter);
     3268                        helper.CopyVector(&NewNormalVector);
     3269                        helper.Scale(sqrt(RADIUS * RADIUS - radius));
     3270                        DoLog(2) && (Log() << Verbose(2) << "INFO: Distance of NewPlaneCenter " << NewPlaneCenter << " to either NewSphereCenter is " << helper.Norm() << " of vector " << helper << " with sphere radius " << RADIUS << "." << endl);
     3271                        NewSphereCenter.AddVector(&helper);
     3272                        DoLog(2) && (Log() << Verbose(2) << "INFO: NewSphereCenter is at " << NewSphereCenter << "." << endl);
     3273                        // OtherNewSphereCenter is created by the same vector just in the other direction
     3274                        helper.Scale(-1.);
     3275                        OtherNewSphereCenter.AddVector(&helper);
     3276                        DoLog(2) && (Log() << Verbose(2) << "INFO: OtherNewSphereCenter is at " << OtherNewSphereCenter << "." << endl);
     3277
     3278                        alpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, NewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
     3279                        Otheralpha = GetPathLengthonCircumCircle(CircleCenter, CirclePlaneNormal, CircleRadius, OtherNewSphereCenter, OldSphereCenter, NormalVector, SearchDirection);
     3280                        if ((ThirdPoint != NULL) && (Candidate == ThirdPoint->node)) { // in that case only the other circlecenter is valid
     3281                          if (OldSphereCenter.DistanceSquared(&NewSphereCenter) < OldSphereCenter.DistanceSquared(&OtherNewSphereCenter))
     3282                            alpha = Otheralpha;
     3283                        } else
     3284                          alpha = min(alpha, Otheralpha);
     3285
     3286                        // if there is a better candidate, drop the current list and add the new candidate
     3287                        // otherwise ignore the new candidate and keep the list
     3288                        if (CandidateLine.ShortestAngle > (alpha - HULLEPSILON)) {
     3289                          if (fabs(alpha - Otheralpha) > MYEPSILON) {
     3290                            CandidateLine.OptCenter.CopyVector(&NewSphereCenter);
     3291                            CandidateLine.OtherOptCenter.CopyVector(&OtherNewSphereCenter);
     3292                          } else {
     3293                            CandidateLine.OptCenter.CopyVector(&OtherNewSphereCenter);
     3294                            CandidateLine.OtherOptCenter.CopyVector(&NewSphereCenter);
     3295                          }
     3296                          // if there is an equal candidate, add it to the list without clearing the list
     3297                          if ((CandidateLine.ShortestAngle - HULLEPSILON) < alpha) {
     3298                            CandidateLine.pointlist.push_back(Candidate);
     3299                            DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found an equally good candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
     3300                          } else {
     3301                            // remove all candidates from the list and then the list itself
     3302                            CandidateLine.pointlist.clear();
     3303                            CandidateLine.pointlist.push_back(Candidate);
     3304                            DoLog(0) && (Log() << Verbose(0) << "ACCEPT: We have found a better candidate: " << *(Candidate) << " with " << alpha << " and circumsphere's center at " << CandidateLine.OptCenter << "." << endl);
     3305                          }
     3306                          CandidateLine.ShortestAngle = alpha;
     3307                          DoLog(0) && (Log() << Verbose(0) << "INFO: There are " << CandidateLine.pointlist.size() << " candidates in the list now." << endl);
    23963308                        } else {
    2397                           optCandidate->OptCenter.CopyVector(&OtherNewSphereCenter);
    2398                           optCandidate->OtherOptCenter.CopyVector(&NewSphereCenter);
     3309                          if ((Candidate != NULL) && (CandidateLine.pointlist.begin() != CandidateLine.pointlist.end())) {
     3310                            DoLog(1) && (Log() << Verbose(1) << "REJECT: Old candidate " << *(*CandidateLine.pointlist.begin()) << " with " << CandidateLine.ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl);
     3311                          } else {
     3312                            DoLog(1) && (Log() << Verbose(1) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl);
     3313                          }
    23993314                        }
    2400                         // if there is an equal candidate, add it to the list without clearing the list
    2401                         if ((*ShortestAngle - HULLEPSILON) < alpha) {
    2402                           candidates->push_back(optCandidate);
    2403                           Log() << Verbose(2) << "ACCEPT: We have found an equally good candidate: " << *(optCandidate->point) << " with "
    2404                             << alpha << " and circumsphere's center at " << optCandidate->OptCenter << "." << endl;
    2405                         } else {
    2406                           // remove all candidates from the list and then the list itself
    2407                           class CandidateForTesselation *remover = NULL;
    2408                           for (CandidateList::iterator it = candidates->begin(); it != candidates->end(); ++it) {
    2409                             remover = *it;
    2410                             delete(remover);
    2411                           }
    2412                           candidates->clear();
    2413                           candidates->push_back(optCandidate);
    2414                           Log() << Verbose(2) << "ACCEPT: We have found a better candidate: " << *(optCandidate->point) << " with "
    2415                             << alpha << " and circumsphere's center at " << optCandidate->OptCenter << "." << endl;
    2416                         }
    2417                         *ShortestAngle = alpha;
    2418                         //Log() << Verbose(2) << "INFO: There are " << candidates->size() << " candidates in the list now." << endl;
    24193315                      } else {
    2420                         if ((optCandidate != NULL) && (optCandidate->point != NULL)) {
    2421                           //Log() << Verbose(2) << "REJECT: Old candidate " << *(optCandidate->point) << " with " << *ShortestAngle << " is better than new one " << *Candidate << " with " << alpha << " ." << endl;
    2422                         } else {
    2423                           //Log() << Verbose(2) << "REJECT: Candidate " << *Candidate << " with " << alpha << " was rejected." << endl;
    2424                         }
     3316                        DoLog(1) && (Log() << Verbose(1) << "REJECT: Distance to center of circumcircle is not the same from each corner of the triangle: " << fabs(radius - otherradius) << endl);
    24253317                      }
    2426 
    24273318                    } else {
    2428                       //Log() << Verbose(2) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl;
     3319                      DoLog(1) && (Log() << Verbose(1) << "REJECT: NewSphereCenter " << NewSphereCenter << " for " << *Candidate << " is too far away: " << radius << "." << endl);
    24293320                    }
    24303321                  } else {
    2431                     //Log() << Verbose(2) << "REJECT: Three points from " << *BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl;
     3322                    DoLog(1) && (Log() << Verbose(1) << "REJECT: Three points from " << *CandidateLine.BaseLine << " and Candidate " << *Candidate << " are linear-dependent." << endl);
    24323323                  }
    24333324                } else {
    2434                   if (ThirdNode != NULL) {
    2435                     //Log() << Verbose(2) << "REJECT: Base triangle " << *BaseLine << " and " << *ThirdNode << " contains Candidate " << *Candidate << "." << endl;
     3325                  if (ThirdPoint != NULL) {
     3326                    DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " and " << *ThirdPoint << " contains Candidate " << *Candidate << "." << endl);
    24363327                  } else {
    2437                     //Log() << Verbose(2) << "REJECT: Base triangle " << *BaseLine << " contains Candidate " << *Candidate << "." << endl;
     3328                    DoLog(1) && (Log() << Verbose(1) << "REJECT: Base triangle " << *CandidateLine.BaseLine << " contains Candidate " << *Candidate << "." << endl);
    24383329                  }
    24393330                }
     
    24423333          }
    24433334    } else {
    2444       eLog() << Verbose(2) << "ERROR: The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;
     3335      DoeLog(1) && (eLog() << Verbose(1) << "The projected center of the old sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
    24453336    }
    24463337  } else {
    2447     if (ThirdNode != NULL)
    2448       Log() << Verbose(2) << "Circumcircle for base line " << *BaseLine << " and third node " << *ThirdNode << " is too big!" << endl;
     3338    if (ThirdPoint != NULL)
     3339      DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " and third node " << *ThirdPoint << " is too big!" << endl);
    24493340    else
    2450       Log() << Verbose(2) << "Circumcircle for base line " << *BaseLine << " is too big!" << endl;
    2451   }
    2452 
    2453   //Log() << Verbose(2) << "INFO: Sorting candidate list ..." << endl;
    2454   if (candidates->size() > 1) {
    2455     candidates->unique();
    2456     candidates->sort(SortCandidates);
    2457   }
    2458 
    2459   Log() << Verbose(1) << "End of FindThirdPointForTesselation" << endl;
    2460 };
     3341      DoLog(1) && (Log() << Verbose(1) << "Circumcircle for base line " << *CandidateLine.BaseLine << " is too big!" << endl);
     3342  }
     3343
     3344  DoLog(1) && (Log() << Verbose(1) << "INFO: Sorting candidate list ..." << endl);
     3345  if (CandidateLine.pointlist.size() > 1) {
     3346    CandidateLine.pointlist.unique();
     3347    CandidateLine.pointlist.sort(); //SortCandidates);
     3348  }
     3349
     3350  if ((!CandidateLine.pointlist.empty()) && (!CandidateLine.CheckValidity(RADIUS, LC))) {
     3351    DoeLog(0) && (eLog() << Verbose(0) << "There were other points contained in the rolling sphere as well!" << endl);
     3352    performCriticalExit();
     3353  }
     3354}
     3355;
    24613356
    24623357/** Finds the endpoint two lines are sharing.
     
    24673362class BoundaryPointSet *Tesselation::GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const
    24683363{
     3364  Info FunctionInfo(__func__);
    24693365  const BoundaryLineSet * lines[2] = { line1, line2 };
    24703366  class BoundaryPointSet *node = NULL;
    2471   map<int, class BoundaryPointSet *> OrderMap;
    2472   pair<map<int, class BoundaryPointSet *>::iterator, bool> OrderTest;
     3367  PointMap OrderMap;
     3368  PointTestPair OrderTest;
    24733369  for (int i = 0; i < 2; i++)
    24743370    // for both lines
    2475     for (int j = 0; j < 2; j++)
    2476       { // for both endpoints
    2477         OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (
    2478             lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
    2479         if (!OrderTest.second)
    2480           { // if insertion fails, we have common endpoint
    2481             node = OrderTest.first->second;
    2482             Log() << Verbose(5) << "Common endpoint of lines " << *line1
    2483                 << " and " << *line2 << " is: " << *node << "." << endl;
    2484             j = 2;
    2485             i = 2;
    2486             break;
     3371    for (int j = 0; j < 2; j++) { // for both endpoints
     3372      OrderTest = OrderMap.insert(pair<int, class BoundaryPointSet *> (lines[i]->endpoints[j]->Nr, lines[i]->endpoints[j]));
     3373      if (!OrderTest.second) { // if insertion fails, we have common endpoint
     3374        node = OrderTest.first->second;
     3375        DoLog(1) && (Log() << Verbose(1) << "Common endpoint of lines " << *line1 << " and " << *line2 << " is: " << *node << "." << endl);
     3376        j = 2;
     3377        i = 2;
     3378        break;
     3379      }
     3380    }
     3381  return node;
     3382}
     3383;
     3384
     3385/** Finds the boundary points that are closest to a given Vector \a *x.
     3386 * \param *out output stream for debugging
     3387 * \param *x Vector to look from
     3388 * \return map of BoundaryPointSet of closest points sorted by squared distance or NULL.
     3389 */
     3390DistanceToPointMap * Tesselation::FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const
     3391{
     3392  Info FunctionInfo(__func__);
     3393  PointMap::const_iterator FindPoint;
     3394  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
     3395
     3396  if (LinesOnBoundary.empty()) {
     3397    DoeLog(1) && (eLog() << Verbose(1) << "There is no tesselation structure to compare the point with, please create one first." << endl);
     3398    return NULL;
     3399  }
     3400
     3401  // gather all points close to the desired one
     3402  LC->SetIndexToVector(x); // ignore status as we calculate bounds below sensibly
     3403  for (int i = 0; i < NDIM; i++) // store indices of this cell
     3404    N[i] = LC->n[i];
     3405  DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
     3406  DistanceToPointMap * points = new DistanceToPointMap;
     3407  LC->GetNeighbourBounds(Nlower, Nupper);
     3408  //Log() << Verbose(1) << endl;
     3409  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
     3410    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
     3411      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
     3412        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
     3413        //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
     3414        if (List != NULL) {
     3415          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     3416            FindPoint = PointsOnBoundary.find((*Runner)->nr);
     3417            if (FindPoint != PointsOnBoundary.end()) {
     3418              points->insert(DistanceToPointPair(FindPoint->second->node->node->DistanceSquared(x), FindPoint->second));
     3419              DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *FindPoint->second << " into the list." << endl);
     3420            }
    24873421          }
     3422        } else {
     3423          DoeLog(1) && (eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << " is invalid!" << endl);
     3424        }
    24883425      }
    2489   return node;
    2490 };
     3426
     3427  // check whether we found some points
     3428  if (points->empty()) {
     3429    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
     3430    delete (points);
     3431    return NULL;
     3432  }
     3433  return points;
     3434}
     3435;
     3436
     3437/** Finds the boundary line that is closest to a given Vector \a *x.
     3438 * \param *out output stream for debugging
     3439 * \param *x Vector to look from
     3440 * \return closest BoundaryLineSet or NULL in degenerate case.
     3441 */
     3442BoundaryLineSet * Tesselation::FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const
     3443{
     3444  Info FunctionInfo(__func__);
     3445  // get closest points
     3446  DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
     3447  if (points == NULL) {
     3448    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
     3449    return NULL;
     3450  }
     3451
     3452  // for each point, check its lines, remember closest
     3453  DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryLine to " << *x << " ... " << endl);
     3454  BoundaryLineSet *ClosestLine = NULL;
     3455  double MinDistance = -1.;
     3456  Vector helper;
     3457  Vector Center;
     3458  Vector BaseLine;
     3459  for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
     3460    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
     3461      // calculate closest point on line to desired point
     3462      helper.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     3463      helper.AddVector((LineRunner->second)->endpoints[1]->node->node);
     3464      helper.Scale(0.5);
     3465      Center.CopyVector(x);
     3466      Center.SubtractVector(&helper);
     3467      BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     3468      BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3469      Center.ProjectOntoPlane(&BaseLine);
     3470      const double distance = Center.NormSquared();
     3471      if ((ClosestLine == NULL) || (distance < MinDistance)) {
     3472        // additionally calculate intersection on line (whether it's on the line section or not)
     3473        helper.CopyVector(x);
     3474        helper.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
     3475        helper.SubtractVector(&Center);
     3476        const double lengthA = helper.ScalarProduct(&BaseLine);
     3477        helper.CopyVector(x);
     3478        helper.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3479        helper.SubtractVector(&Center);
     3480        const double lengthB = helper.ScalarProduct(&BaseLine);
     3481        if (lengthB * lengthA < 0) { // if have different sign
     3482          ClosestLine = LineRunner->second;
     3483          MinDistance = distance;
     3484          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: New closest line is " << *ClosestLine << " with projected distance " << MinDistance << "." << endl);
     3485        } else {
     3486          DoLog(1) && (Log() << Verbose(1) << "REJECT: Intersection is outside of the line section: " << lengthA << " and " << lengthB << "." << endl);
     3487        }
     3488      } else {
     3489        DoLog(1) && (Log() << Verbose(1) << "REJECT: Point is too further away than present line: " << distance << " >> " << MinDistance << "." << endl);
     3490      }
     3491    }
     3492  }
     3493  delete (points);
     3494  // check whether closest line is "too close" :), then it's inside
     3495  if (ClosestLine == NULL) {
     3496    DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
     3497    return NULL;
     3498  }
     3499  return ClosestLine;
     3500}
     3501;
    24913502
    24923503/** Finds the triangle that is closest to a given Vector \a *x.
    24933504 * \param *out output stream for debugging
    24943505 * \param *x Vector to look from
    2495  * \return list of BoundaryTriangleSet of nearest triangles or NULL in degenerate case.
    2496  */
    2497 list<BoundaryTriangleSet*> * Tesselation::FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const
    2498 {
    2499   TesselPoint *trianglePoints[3];
    2500   TesselPoint *SecondPoint = NULL;
    2501   list<BoundaryTriangleSet*> *triangles = NULL;
    2502 
    2503   if (LinesOnBoundary.empty()) {
    2504     Log() << Verbose(0) << "Error: There is no tesselation structure to compare the point with, please create one first.";
     3506 * \return BoundaryTriangleSet of nearest triangle or NULL.
     3507 */
     3508TriangleList * Tesselation::FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const
     3509{
     3510  Info FunctionInfo(__func__);
     3511  // get closest points
     3512  DistanceToPointMap * points = FindClosestBoundaryPointsToVector(x, LC);
     3513  if (points == NULL) {
     3514    DoeLog(1) && (eLog() << Verbose(1) << "There is no nearest point: too far away from the surface." << endl);
    25053515    return NULL;
    25063516  }
    2507   Log() << Verbose(1) << "Finding closest Tesselpoint to " << *x << " ... " << endl;
    2508   trianglePoints[0] = FindClosestPoint(x, SecondPoint, LC);
    2509  
    2510   // check whether closest point is "too close" :), then it's inside
    2511   if (trianglePoints[0] == NULL) {
    2512     Log() << Verbose(2) << "Is the only point, no one else is closeby." << endl;
     3517
     3518  // for each point, check its lines, remember closest
     3519  DoLog(1) && (Log() << Verbose(1) << "Finding closest BoundaryTriangle to " << *x << " ... " << endl);
     3520  LineSet ClosestLines;
     3521  double MinDistance = 1e+16;
     3522  Vector BaseLineIntersection;
     3523  Vector Center;
     3524  Vector BaseLine;
     3525  Vector BaseLineCenter;
     3526  for (DistanceToPointMap::iterator Runner = points->begin(); Runner != points->end(); Runner++) {
     3527    for (LineMap::iterator LineRunner = Runner->second->lines.begin(); LineRunner != Runner->second->lines.end(); LineRunner++) {
     3528
     3529      BaseLine.CopyVector((LineRunner->second)->endpoints[0]->node->node);
     3530      BaseLine.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3531      const double lengthBase = BaseLine.NormSquared();
     3532
     3533      BaseLineIntersection.CopyVector(x);
     3534      BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[0]->node->node);
     3535      const double lengthEndA = BaseLineIntersection.NormSquared();
     3536
     3537      BaseLineIntersection.CopyVector(x);
     3538      BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3539      const double lengthEndB = BaseLineIntersection.NormSquared();
     3540
     3541      if ((lengthEndA > lengthBase) || (lengthEndB > lengthBase) || ((lengthEndA < MYEPSILON) || (lengthEndB < MYEPSILON))) { // intersection would be outside, take closer endpoint
     3542        const double lengthEnd = Min(lengthEndA, lengthEndB);
     3543        if (lengthEnd - MinDistance < -MYEPSILON) { // new best line
     3544          ClosestLines.clear();
     3545          ClosestLines.insert(LineRunner->second);
     3546          MinDistance = lengthEnd;
     3547          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[0]->node << " is closer with " << lengthEnd << "." << endl);
     3548        } else if (fabs(lengthEnd - MinDistance) < MYEPSILON) { // additional best candidate
     3549          ClosestLines.insert(LineRunner->second);
     3550          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Line " << *LineRunner->second << " to endpoint " << *LineRunner->second->endpoints[1]->node << " is equally good with " << lengthEnd << "." << endl);
     3551        } else { // line is worse
     3552          DoLog(1) && (Log() << Verbose(1) << "REJECT: Line " << *LineRunner->second << " to either endpoints is further away than present closest line candidate: " << lengthEndA << ", " << lengthEndB << ", and distance is longer than baseline:" << lengthBase << "." << endl);
     3553        }
     3554      } else { // intersection is closer, calculate
     3555        // calculate closest point on line to desired point
     3556        BaseLineIntersection.CopyVector(x);
     3557        BaseLineIntersection.SubtractVector((LineRunner->second)->endpoints[1]->node->node);
     3558        Center.CopyVector(&BaseLineIntersection);
     3559        Center.ProjectOntoPlane(&BaseLine);
     3560        BaseLineIntersection.SubtractVector(&Center);
     3561        const double distance = BaseLineIntersection.NormSquared();
     3562        if (Center.NormSquared() > BaseLine.NormSquared()) {
     3563          DoeLog(0) && (eLog() << Verbose(0) << "Algorithmic error: In second case we have intersection outside of baseline!" << endl);
     3564        }
     3565        if ((ClosestLines.empty()) || (distance < MinDistance)) {
     3566          ClosestLines.insert(LineRunner->second);
     3567          MinDistance = distance;
     3568          DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Intersection in between endpoints, new closest line " << *LineRunner->second << " is " << *ClosestLines.begin() << " with projected distance " << MinDistance << "." << endl);
     3569        } else {
     3570          DoLog(2) && (Log() << Verbose(2) << "REJECT: Point is further away from line " << *LineRunner->second << " than present closest line: " << distance << " >> " << MinDistance << "." << endl);
     3571        }
     3572      }
     3573    }
     3574  }
     3575  delete (points);
     3576
     3577  // check whether closest line is "too close" :), then it's inside
     3578  if (ClosestLines.empty()) {
     3579    DoLog(0) && (Log() << Verbose(0) << "Is the only point, no one else is closeby." << endl);
    25133580    return NULL;
    25143581  }
    2515   if (trianglePoints[0]->node->DistanceSquared(x) < MYEPSILON) {
    2516     Log() << Verbose(3) << "Point is right on a tesselation point, no nearest triangle." << endl;
    2517     PointMap::const_iterator PointRunner = PointsOnBoundary.find(trianglePoints[0]->nr);
    2518     triangles = new list<BoundaryTriangleSet*>;
    2519     if (PointRunner != PointsOnBoundary.end()) {
    2520       for(LineMap::iterator LineRunner = PointRunner->second->lines.begin(); LineRunner != PointRunner->second->lines.end(); LineRunner++)
    2521         for(TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
    2522           triangles->push_back(TriangleRunner->second);
    2523       triangles->sort();
    2524       triangles->unique();
    2525     } else {
    2526       PointRunner = PointsOnBoundary.find(SecondPoint->nr);
    2527       trianglePoints[0] = SecondPoint;
    2528       if (PointRunner != PointsOnBoundary.end()) {
    2529         for(LineMap::iterator LineRunner = PointRunner->second->lines.begin(); LineRunner != PointRunner->second->lines.end(); LineRunner++)
    2530           for(TriangleMap::iterator TriangleRunner = LineRunner->second->triangles.begin(); TriangleRunner != LineRunner->second->triangles.end(); TriangleRunner++)
    2531             triangles->push_back(TriangleRunner->second);
    2532         triangles->sort();
    2533         triangles->unique();
    2534       } else {
    2535         Log() << Verbose(1) << "ERROR: I cannot find a boundary point to the tessel point " << *trianglePoints[0] << "." << endl;
    2536         return NULL;
    2537       }
    2538     }
    2539   } else {
    2540     list<TesselPoint*> *connectedClosestPoints = GetCircleOfConnectedPoints(trianglePoints[0], x);
    2541     if (connectedClosestPoints != NULL) {
    2542       trianglePoints[1] = connectedClosestPoints->front();
    2543       trianglePoints[2] = connectedClosestPoints->back();
    2544       for (int i=0;i<3;i++) {
    2545         if (trianglePoints[i] == NULL) {
    2546           Log() << Verbose(1) << "ERROR: IsInnerPoint encounters serious error, point " << i << " not found." << endl;
    2547         }
    2548         //Log() << Verbose(2) << "List of triangle points:" << endl;
    2549         //Log() << Verbose(3) << *trianglePoints[i] << endl;
    2550       }
    2551 
    2552       triangles = FindTriangles(trianglePoints);
    2553       Log() << Verbose(2) << "List of possible triangles:" << endl;
    2554       for(list<BoundaryTriangleSet*>::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
    2555         Log() << Verbose(3) << **Runner << endl;
    2556 
    2557       delete(connectedClosestPoints);
    2558     } else {
    2559       triangles = NULL;
    2560       Log() << Verbose(1) << "There is no circle of connected points!" << endl;
    2561     }
    2562   }
    2563  
    2564   if ((triangles == NULL) || (triangles->empty())) {
    2565     Log() << Verbose(0) << "ERROR: There is no nearest triangle. Please check the tesselation structure.";
    2566     delete(triangles);
    2567     return NULL;
    2568   } else
    2569     return triangles;
    2570 };
     3582  TriangleList * candidates = new TriangleList;
     3583  for (LineSet::iterator LineRunner = ClosestLines.begin(); LineRunner != ClosestLines.end(); LineRunner++)
     3584    for (TriangleMap::iterator Runner = (*LineRunner)->triangles.begin(); Runner != (*LineRunner)->triangles.end(); Runner++) {
     3585      candidates->push_back(Runner->second);
     3586    }
     3587  return candidates;
     3588}
     3589;
    25713590
    25723591/** Finds closest triangle to a point.
     
    25743593 * \param *out output stream for debugging
    25753594 * \param *x Vector to look from
     3595 * \param &distance contains found distance on return
    25763596 * \return list of BoundaryTriangleSet of nearest triangles or NULL.
    25773597 */
    2578 class BoundaryTriangleSet * Tesselation::FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const
    2579 {
     3598class BoundaryTriangleSet * Tesselation::FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const
     3599{
     3600  Info FunctionInfo(__func__);
    25803601  class BoundaryTriangleSet *result = NULL;
    2581   list<BoundaryTriangleSet*> *triangles = FindClosestTrianglesToPoint(x, LC);
     3602  TriangleList *triangles = FindClosestTrianglesToVector(x, LC);
     3603  TriangleList candidates;
    25823604  Vector Center;
    2583 
    2584   if (triangles == NULL)
     3605  Vector helper;
     3606
     3607  if ((triangles == NULL) || (triangles->empty()))
    25853608    return NULL;
    25863609
    2587   if (triangles->size() == 1) { // there is no degenerate case
    2588     result = triangles->front();
    2589     Log() << Verbose(2) << "Normal Vector of this triangle is " << result->NormalVector << "." << endl;
    2590   } else {
    2591     result = triangles->front();
    2592     result->GetCenter(&Center);
    2593     Center.SubtractVector(x);
    2594     Log() << Verbose(2) << "Normal Vector of this front side is " << result->NormalVector << "." << endl;
    2595     if (Center.ScalarProduct(&result->NormalVector) < 0) {
    2596       result = triangles->back();
    2597       Log() << Verbose(2) << "Normal Vector of this back side is " << result->NormalVector << "." << endl;
    2598       if (Center.ScalarProduct(&result->NormalVector) < 0) {
    2599         Log() << Verbose(1) << "ERROR: Front and back side yield NormalVector in wrong direction!" << endl;
    2600       }
    2601     }
    2602   }
    2603   delete(triangles);
     3610  // go through all and pick the one with the best alignment to x
     3611  double MinAlignment = 2. * M_PI;
     3612  for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++) {
     3613    (*Runner)->GetCenter(&Center);
     3614    helper.CopyVector(x);
     3615    helper.SubtractVector(&Center);
     3616    const double Alignment = helper.Angle(&(*Runner)->NormalVector);
     3617    if (Alignment < MinAlignment) {
     3618      result = *Runner;
     3619      MinAlignment = Alignment;
     3620      DoLog(1) && (Log() << Verbose(1) << "ACCEPT: Triangle " << *result << " is better aligned with " << MinAlignment << "." << endl);
     3621    } else {
     3622      DoLog(1) && (Log() << Verbose(1) << "REJECT: Triangle " << *result << " is worse aligned with " << MinAlignment << "." << endl);
     3623    }
     3624  }
     3625  delete (triangles);
     3626
    26043627  return result;
    2605 };
    2606 
    2607 /** Checks whether the provided Vector is within the tesselation structure.
     3628}
     3629;
     3630
     3631/** Checks whether the provided Vector is within the Tesselation structure.
     3632 * Basically calls Tesselation::GetDistanceToSurface() and checks the sign of the return value.
     3633 * @param point of which to check the position
     3634 * @param *LC LinkedCell structure
     3635 *
     3636 * @return true if the point is inside the Tesselation structure, false otherwise
     3637 */
     3638bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
     3639{
     3640  Info FunctionInfo(__func__);
     3641  TriangleIntersectionList Intersections(&Point, this, LC);
     3642
     3643  return Intersections.IsInside();
     3644}
     3645;
     3646
     3647/** Returns the distance to the surface given by the tesselation.
     3648 * Calls FindClosestTriangleToVector() and checks whether the resulting triangle's BoundaryTriangleSet#NormalVector points
     3649 * towards or away from the given \a &Point. Additionally, we check whether it's normal to the normal vector, i.e. on the
     3650 * closest triangle's plane. Then, we have to check whether \a Point is inside the triangle or not to determine whether it's
     3651 * an inside or outside point. This is done by calling BoundaryTriangleSet::GetIntersectionInsideTriangle().
     3652 * In the end we additionally find the point on the triangle who was smallest distance to \a Point:
     3653 *  -# Separate distance from point to center in vector in NormalDirection and on the triangle plane.
     3654 *  -# Check whether vector on triangle plane points inside the triangle or crosses triangle bounds.
     3655 *  -# If inside, take it to calculate closest distance
     3656 *  -# If not, take intersection with BoundaryLine as distance
     3657 *
     3658 * @note distance is squared despite it still contains a sign to determine in-/outside!
    26083659 *
    26093660 * @param point of which to check the position
    26103661 * @param *LC LinkedCell structure
    26113662 *
    2612  * @return true if the point is inside the tesselation structure, false otherwise
    2613  */
    2614 bool Tesselation::IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const
    2615 {
    2616   class BoundaryTriangleSet *result = FindClosestTriangleToPoint(&Point, LC);
     3663 * @return >0 if outside, ==0 if on surface, <0 if inside
     3664 */
     3665double Tesselation::GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const
     3666{
     3667  Info FunctionInfo(__func__);
    26173668  Vector Center;
    2618 
    2619   if (result == NULL) {// is boundary point or only point in point cloud?
    2620     Log() << Verbose(1) << Point << " is the only point in vicinity." << endl;
    2621     return false;
    2622   }
    2623 
    2624   result->GetCenter(&Center);
    2625   Log() << Verbose(3) << "INFO: Central point of the triangle is " << Center << "." << endl;
    2626   Center.SubtractVector(&Point);
    2627   Log() << Verbose(3) << "INFO: Vector from center to point to test is " << Center << "." << endl;
    2628   if (Center.ScalarProduct(&result->NormalVector) > -MYEPSILON) {
    2629     Log() << Verbose(1) << Point << " is an inner point." << endl;
    2630     return true;
     3669  Vector helper;
     3670  Vector DistanceToCenter;
     3671  Vector Intersection;
     3672  double distance = 0.;
     3673
     3674  if (triangle == NULL) {// is boundary point or only point in point cloud?
     3675    DoLog(1) && (Log() << Verbose(1) << "No triangle given!" << endl);
     3676    return -1.;
    26313677  } else {
    2632     Log() << Verbose(1) << Point << " is NOT an inner point." << endl;
    2633     return false;
    2634   }
    2635 }
    2636 
    2637 /** Checks whether the provided TesselPoint is within the tesselation structure.
    2638  *
    2639  * @param *Point of which to check the position
    2640  * @param *LC Linked Cell structure
    2641  *
    2642  * @return true if the point is inside the tesselation structure, false otherwise
    2643  */
    2644 bool Tesselation::IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const
    2645 {
    2646   return IsInnerPoint(*(Point->node), LC);
    2647 }
     3678    DoLog(1) && (Log() << Verbose(1) << "INFO: Closest triangle found is " << *triangle << " with normal vector " << triangle->NormalVector << "." << endl);
     3679  }
     3680
     3681  triangle->GetCenter(&Center);
     3682  DoLog(2) && (Log() << Verbose(2) << "INFO: Central point of the triangle is " << Center << "." << endl);
     3683  DistanceToCenter.CopyVector(&Center);
     3684  DistanceToCenter.SubtractVector(&Point);
     3685  DoLog(2) && (Log() << Verbose(2) << "INFO: Vector from point to test to center is " << DistanceToCenter << "." << endl);
     3686
     3687  // check whether we are on boundary
     3688  if (fabs(DistanceToCenter.ScalarProduct(&triangle->NormalVector)) < MYEPSILON) {
     3689    // calculate whether inside of triangle
     3690    DistanceToCenter.CopyVector(&Point);
     3691    Center.CopyVector(&Point);
     3692    Center.SubtractVector(&triangle->NormalVector); // points towards MolCenter
     3693    DistanceToCenter.AddVector(&triangle->NormalVector); // points outside
     3694    DoLog(1) && (Log() << Verbose(1) << "INFO: Calling Intersection with " << Center << " and " << DistanceToCenter << "." << endl);
     3695    if (triangle->GetIntersectionInsideTriangle(&Center, &DistanceToCenter, &Intersection)) {
     3696      DoLog(1) && (Log() << Verbose(1) << Point << " is inner point: sufficiently close to boundary, " << Intersection << "." << endl);
     3697      return 0.;
     3698    } else {
     3699      DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point: on triangle plane but outside of triangle bounds." << endl);
     3700      return false;
     3701    }
     3702  } else {
     3703    // calculate smallest distance
     3704    distance = triangle->GetClosestPointInsideTriangle(&Point, &Intersection);
     3705    DoLog(1) && (Log() << Verbose(1) << "Closest point on triangle is " << Intersection << "." << endl);
     3706
     3707    // then check direction to boundary
     3708    if (DistanceToCenter.ScalarProduct(&triangle->NormalVector) > MYEPSILON) {
     3709      DoLog(1) && (Log() << Verbose(1) << Point << " is an inner point, " << distance << " below surface." << endl);
     3710      return -distance;
     3711    } else {
     3712      DoLog(1) && (Log() << Verbose(1) << Point << " is NOT an inner point, " << distance << " above surface." << endl);
     3713      return +distance;
     3714    }
     3715  }
     3716}
     3717;
     3718
     3719/** Calculates minimum distance from \a&Point to a tesselated surface.
     3720 * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
     3721 * \param &Point point to calculate distance from
     3722 * \param *LC needed for finding closest points fast
     3723 * \return distance squared to closest point on surface
     3724 */
     3725double Tesselation::GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const
     3726{
     3727  Info FunctionInfo(__func__);
     3728  TriangleIntersectionList Intersections(&Point, this, LC);
     3729
     3730  return Intersections.GetSmallestDistance();
     3731}
     3732;
     3733
     3734/** Calculates minimum distance from \a&Point to a tesselated surface.
     3735 * Combines \sa FindClosestTrianglesToVector() and \sa GetDistanceSquaredToTriangle().
     3736 * \param &Point point to calculate distance from
     3737 * \param *LC needed for finding closest points fast
     3738 * \return distance squared to closest point on surface
     3739 */
     3740BoundaryTriangleSet * Tesselation::GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const
     3741{
     3742  Info FunctionInfo(__func__);
     3743  TriangleIntersectionList Intersections(&Point, this, LC);
     3744
     3745  return Intersections.GetClosestTriangle();
     3746}
     3747;
    26483748
    26493749/** Gets all points connected to the provided point by triangulation lines.
     
    26533753 * @return set of the all points linked to the provided one
    26543754 */
    2655 set<TesselPoint*> * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
    2656 {
    2657   set<TesselPoint*> *connectedPoints = new set<TesselPoint*>;
     3755TesselPointSet * Tesselation::GetAllConnectedPoints(const TesselPoint* const Point) const
     3756{
     3757  Info FunctionInfo(__func__);
     3758  TesselPointSet *connectedPoints = new TesselPointSet;
    26583759  class BoundaryPointSet *ReferencePoint = NULL;
    26593760  TesselPoint* current;
    26603761  bool takePoint = false;
    2661 
    2662   Log() << Verbose(3) << "Begin of GetAllConnectedPoints" << endl;
    2663 
    26643762  // find the respective boundary point
    26653763  PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
     
    26673765    ReferencePoint = PointRunner->second;
    26683766  } else {
    2669     Log() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
     3767    DoeLog(2) && (eLog() << Verbose(2) << "GetAllConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
    26703768    ReferencePoint = NULL;
    26713769  }
     
    26733771  // little trick so that we look just through lines connect to the BoundaryPoint
    26743772  // OR fall-back to look through all lines if there is no such BoundaryPoint
    2675   const LineMap *Lines;;
     3773  const LineMap *Lines;
     3774  ;
    26763775  if (ReferencePoint != NULL)
    26773776    Lines = &(ReferencePoint->lines);
     
    26803779  LineMap::const_iterator findLines = Lines->begin();
    26813780  while (findLines != Lines->end()) {
    2682    takePoint = false;
    2683 
    2684    if (findLines->second->endpoints[0]->Nr == Point->nr) {
    2685      takePoint = true;
    2686      current = findLines->second->endpoints[1]->node;
    2687    } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
    2688      takePoint = true;
    2689      current = findLines->second->endpoints[0]->node;
    2690    }
    2691 
    2692    if (takePoint) {
    2693      Log() << Verbose(5) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl;
    2694      connectedPoints->insert(current);
    2695    }
    2696 
    2697    findLines++;
    2698   }
    2699 
    2700   if (connectedPoints->size() == 0) { // if have not found any points
    2701     Log() << Verbose(1) << "ERROR: We have not found any connected points to " << *Point<< "." << endl;
     3781    takePoint = false;
     3782
     3783    if (findLines->second->endpoints[0]->Nr == Point->nr) {
     3784      takePoint = true;
     3785      current = findLines->second->endpoints[1]->node;
     3786    } else if (findLines->second->endpoints[1]->Nr == Point->nr) {
     3787      takePoint = true;
     3788      current = findLines->second->endpoints[0]->node;
     3789    }
     3790
     3791    if (takePoint) {
     3792      DoLog(1) && (Log() << Verbose(1) << "INFO: Endpoint " << *current << " of line " << *(findLines->second) << " is enlisted." << endl);
     3793      connectedPoints->insert(current);
     3794    }
     3795
     3796    findLines++;
     3797  }
     3798
     3799  if (connectedPoints->empty()) { // if have not found any points
     3800    DoeLog(1) && (eLog() << Verbose(1) << "We have not found any connected points to " << *Point << "." << endl);
    27023801    return NULL;
    27033802  }
    27043803
    2705   Log() << Verbose(3) << "End of GetAllConnectedPoints" << endl;
    27063804  return connectedPoints;
    2707 };
    2708 
     3805}
     3806;
    27093807
    27103808/** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
     
    27153813 *
    27163814 * @param *out output stream for debugging
     3815 * @param *SetOfNeighbours all points for which the angle should be calculated
    27173816 * @param *Point of which get all connected points
    27183817 * @param *Reference Reference vector for zero angle or NULL for no preference
    27193818 * @return list of the all points linked to the provided one
    27203819 */
    2721 list<TesselPoint*> * Tesselation::GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference) const
    2722 {
     3820TesselPointList * Tesselation::GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
     3821{
     3822  Info FunctionInfo(__func__);
    27233823  map<double, TesselPoint*> anglesOfPoints;
    2724   set<TesselPoint*> *connectedPoints = GetAllConnectedPoints(Point);
    2725   list<TesselPoint*> *connectedCircle = new list<TesselPoint*>;
     3824  TesselPointList *connectedCircle = new TesselPointList;
     3825  Vector PlaneNormal;
     3826  Vector AngleZero;
     3827  Vector OrthogonalVector;
     3828  Vector helper;
     3829  const TesselPoint * const TrianglePoints[3] = { Point, NULL, NULL };
     3830  TriangleList *triangles = NULL;
     3831
     3832  if (SetOfNeighbours == NULL) {
     3833    DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
     3834    delete (connectedCircle);
     3835    return NULL;
     3836  }
     3837
     3838  // calculate central point
     3839  triangles = FindTriangles(TrianglePoints);
     3840  if ((triangles != NULL) && (!triangles->empty())) {
     3841    for (TriangleList::iterator Runner = triangles->begin(); Runner != triangles->end(); Runner++)
     3842      PlaneNormal.AddVector(&(*Runner)->NormalVector);
     3843  } else {
     3844    DoeLog(0) && (eLog() << Verbose(0) << "Could not find any triangles for point " << *Point << "." << endl);
     3845    performCriticalExit();
     3846  }
     3847  PlaneNormal.Scale(1.0 / triangles->size());
     3848  DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated PlaneNormal of all circle points is " << PlaneNormal << "." << endl);
     3849  PlaneNormal.Normalize();
     3850
     3851  // construct one orthogonal vector
     3852  if (Reference != NULL) {
     3853    AngleZero.CopyVector(Reference);
     3854    AngleZero.SubtractVector(Point->node);
     3855    AngleZero.ProjectOntoPlane(&PlaneNormal);
     3856  }
     3857  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
     3858    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
     3859    AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
     3860    AngleZero.SubtractVector(Point->node);
     3861    AngleZero.ProjectOntoPlane(&PlaneNormal);
     3862    if (AngleZero.NormSquared() < MYEPSILON) {
     3863      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
     3864      performCriticalExit();
     3865    }
     3866  }
     3867  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
     3868  if (AngleZero.NormSquared() > MYEPSILON)
     3869    OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
     3870  else
     3871    OrthogonalVector.MakeNormalVector(&PlaneNormal);
     3872  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
     3873
     3874  // go through all connected points and calculate angle
     3875  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
     3876    helper.CopyVector((*listRunner)->node);
     3877    helper.SubtractVector(Point->node);
     3878    helper.ProjectOntoPlane(&PlaneNormal);
     3879    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
     3880    DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl);
     3881    anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
     3882  }
     3883
     3884  for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
     3885    connectedCircle->push_back(AngleRunner->second);
     3886  }
     3887
     3888  return connectedCircle;
     3889}
     3890
     3891/** Gets all points connected to the provided point by triangulation lines, ordered such that we have the circle round the point.
     3892 * Maps them down onto the plane designated by the axis \a *Point and \a *Reference. The center of all points
     3893 * connected in the tesselation to \a *Point is mapped to spherical coordinates with the zero angle being given
     3894 * by the mapped down \a *Reference. Hence, the biggest and the smallest angles are those of the two shanks of the
     3895 * triangle we are looking for.
     3896 *
     3897 * @param *SetOfNeighbours all points for which the angle should be calculated
     3898 * @param *Point of which get all connected points
     3899 * @param *Reference Reference vector for zero angle or NULL for no preference
     3900 * @return list of the all points linked to the provided one
     3901 */
     3902TesselPointList * Tesselation::GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const
     3903{
     3904  Info FunctionInfo(__func__);
     3905  map<double, TesselPoint*> anglesOfPoints;
     3906  TesselPointList *connectedCircle = new TesselPointList;
    27263907  Vector center;
    27273908  Vector PlaneNormal;
     
    27303911  Vector helper;
    27313912
    2732   if (connectedPoints == NULL) {
    2733     Log() << Verbose(2) << "Could not find any connected points!" << endl;
    2734     delete(connectedCircle);
     3913  if (SetOfNeighbours == NULL) {
     3914    DoeLog(2) && (eLog() << Verbose(2) << "Could not find any connected points!" << endl);
     3915    delete (connectedCircle);
    27353916    return NULL;
    27363917  }
    2737   Log() << Verbose(2) << "Begin of GetCircleOfConnectedPoints" << endl;
    2738 
     3918
     3919  // check whether there's something to do
     3920  if (SetOfNeighbours->size() < 3) {
     3921    for (TesselPointSet::iterator TesselRunner = SetOfNeighbours->begin(); TesselRunner != SetOfNeighbours->end(); TesselRunner++)
     3922      connectedCircle->push_back(*TesselRunner);
     3923    return connectedCircle;
     3924  }
     3925
     3926  DoLog(1) && (Log() << Verbose(1) << "INFO: Point is " << *Point << " and Reference is " << *Reference << "." << endl);
    27393927  // calculate central point
    2740   for (set<TesselPoint*>::const_iterator TesselRunner = connectedPoints->begin(); TesselRunner != connectedPoints->end(); TesselRunner++)
    2741     center.AddVector((*TesselRunner)->node);
     3928  TesselPointSet::const_iterator TesselA = SetOfNeighbours->begin();
     3929  TesselPointSet::const_iterator TesselB = SetOfNeighbours->begin();
     3930  TesselPointSet::const_iterator TesselC = SetOfNeighbours->begin();
     3931  TesselB++;
     3932  TesselC++;
     3933  TesselC++;
     3934  int counter = 0;
     3935  while (TesselC != SetOfNeighbours->end()) {
     3936    helper.MakeNormalVector((*TesselA)->node, (*TesselB)->node, (*TesselC)->node);
     3937    DoLog(0) && (Log() << Verbose(0) << "Making normal vector out of " << *(*TesselA) << ", " << *(*TesselB) << " and " << *(*TesselC) << ":" << helper << endl);
     3938    counter++;
     3939    TesselA++;
     3940    TesselB++;
     3941    TesselC++;
     3942    PlaneNormal.AddVector(&helper);
     3943  }
    27423944  //Log() << Verbose(0) << "Summed vectors " << center << "; number of points " << connectedPoints.size()
    2743   //  << "; scale factor " << 1.0/connectedPoints.size();
    2744   center.Scale(1.0/connectedPoints->size());
    2745   Log() << Verbose(4) << "INFO: Calculated center of all circle points is " << center << "." << endl;
    2746 
    2747   // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
    2748   PlaneNormal.CopyVector(Point->node);
    2749   PlaneNormal.SubtractVector(&center);
    2750   PlaneNormal.Normalize();
    2751   Log() << Verbose(4) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl;
     3945  //  << "; scale factor " << counter;
     3946  PlaneNormal.Scale(1.0 / (double) counter);
     3947  //  Log() << Verbose(1) << "INFO: Calculated center of all circle points is " << center << "." << endl;
     3948  //
     3949  //  // projection plane of the circle is at the closes Point and normal is pointing away from center of all circle points
     3950  //  PlaneNormal.CopyVector(Point->node);
     3951  //  PlaneNormal.SubtractVector(&center);
     3952  //  PlaneNormal.Normalize();
     3953  DoLog(1) && (Log() << Verbose(1) << "INFO: Calculated plane normal of circle is " << PlaneNormal << "." << endl);
    27523954
    27533955  // construct one orthogonal vector
     
    27573959    AngleZero.ProjectOntoPlane(&PlaneNormal);
    27583960  }
    2759   if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON )) {
    2760     Log() << Verbose(4) << "Using alternatively " << *(*connectedPoints->begin())->node << " as angle 0 referencer." << endl;
    2761     AngleZero.CopyVector((*connectedPoints->begin())->node);
     3961  if ((Reference == NULL) || (AngleZero.NormSquared() < MYEPSILON)) {
     3962    DoLog(1) && (Log() << Verbose(1) << "Using alternatively " << *(*SetOfNeighbours->begin())->node << " as angle 0 referencer." << endl);
     3963    AngleZero.CopyVector((*SetOfNeighbours->begin())->node);
    27623964    AngleZero.SubtractVector(Point->node);
    27633965    AngleZero.ProjectOntoPlane(&PlaneNormal);
    27643966    if (AngleZero.NormSquared() < MYEPSILON) {
    2765       eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl;
     3967      DoeLog(0) && (eLog() << Verbose(0) << "CRITIAL: AngleZero is 0 even with alternative reference. The algorithm has to be changed here!" << endl);
    27663968      performCriticalExit();
    27673969    }
    27683970  }
    2769   Log() << Verbose(4) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl;
     3971  DoLog(1) && (Log() << Verbose(1) << "INFO: Reference vector on this plane representing angle 0 is " << AngleZero << "." << endl);
    27703972  if (AngleZero.NormSquared() > MYEPSILON)
    27713973    OrthogonalVector.MakeNormalVector(&PlaneNormal, &AngleZero);
    27723974  else
    27733975    OrthogonalVector.MakeNormalVector(&PlaneNormal);
    2774   Log() << Verbose(4) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl;
     3976  DoLog(1) && (Log() << Verbose(1) << "INFO: OrthogonalVector on plane is " << OrthogonalVector << "." << endl);
    27753977
    27763978  // go through all connected points and calculate angle
    2777   for (set<TesselPoint*>::iterator listRunner = connectedPoints->begin(); listRunner != connectedPoints->end(); listRunner++) {
     3979  pair<map<double, TesselPoint*>::iterator, bool> InserterTest;
     3980  for (TesselPointSet::iterator listRunner = SetOfNeighbours->begin(); listRunner != SetOfNeighbours->end(); listRunner++) {
    27783981    helper.CopyVector((*listRunner)->node);
    27793982    helper.SubtractVector(Point->node);
    27803983    helper.ProjectOntoPlane(&PlaneNormal);
    27813984    double angle = GetAngle(helper, AngleZero, OrthogonalVector);
    2782     Log() << Verbose(3) << "INFO: Calculated angle is " << angle << " for point " << **listRunner << "." << endl;
    2783     anglesOfPoints.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
    2784   }
    2785 
    2786   for(map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
     3985    if (angle > M_PI) // the correction is of no use here (and not desired)
     3986      angle = 2. * M_PI - angle;
     3987    DoLog(0) && (Log() << Verbose(0) << "INFO: Calculated angle between " << helper << " and " << AngleZero << " is " << angle << " for point " << **listRunner << "." << endl);
     3988    InserterTest = anglesOfPoints.insert(pair<double, TesselPoint*> (angle, (*listRunner)));
     3989    if (!InserterTest.second) {
     3990      DoeLog(0) && (eLog() << Verbose(0) << "GetCircleOfSetOfPoints() got two atoms with same angle: " << *((InserterTest.first)->second) << " and " << (*listRunner) << endl);
     3991      performCriticalExit();
     3992    }
     3993  }
     3994
     3995  for (map<double, TesselPoint*>::iterator AngleRunner = anglesOfPoints.begin(); AngleRunner != anglesOfPoints.end(); AngleRunner++) {
    27873996    connectedCircle->push_back(AngleRunner->second);
    27883997  }
    2789 
    2790   delete(connectedPoints);
    2791 
    2792   Log() << Verbose(2) << "End of GetCircleOfConnectedPoints" << endl;
    27933998
    27943999  return connectedCircle;
     
    28014006 * @return list of the all points linked to the provided one
    28024007 */
    2803 list<list<TesselPoint*> *> * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
    2804 {
     4008ListOfTesselPointList * Tesselation::GetPathsOfConnectedPoints(const TesselPoint* const Point) const
     4009{
     4010  Info FunctionInfo(__func__);
    28054011  map<double, TesselPoint*> anglesOfPoints;
    2806   list<list<TesselPoint*> *> *ListOfPaths = new list<list<TesselPoint*> *>;
    2807   list<TesselPoint*> *connectedPath = NULL;
     4012  list<TesselPointList *> *ListOfPaths = new list<TesselPointList *> ;
     4013  TesselPointList *connectedPath = NULL;
    28084014  Vector center;
    28094015  Vector PlaneNormal;
     
    28164022  class BoundaryLineSet *CurrentLine = NULL;
    28174023  class BoundaryLineSet *StartLine = NULL;
    2818 
    28194024  // find the respective boundary point
    28204025  PointMap::const_iterator PointRunner = PointsOnBoundary.find(Point->nr);
     
    28224027    ReferencePoint = PointRunner->second;
    28234028  } else {
    2824     Log() << Verbose(2) << "ERROR: GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl;
     4029    DoeLog(1) && (eLog() << Verbose(1) << "GetPathOfConnectedPoints() could not find the BoundaryPoint belonging to " << *Point << "." << endl);
    28254030    return NULL;
    28264031  }
    28274032
    2828   map <class BoundaryLineSet *, bool> TouchedLine;
    2829   map <class BoundaryTriangleSet *, bool> TouchedTriangle;
    2830   map <class BoundaryLineSet *, bool>::iterator LineRunner;
    2831   map <class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
     4033  map<class BoundaryLineSet *, bool> TouchedLine;
     4034  map<class BoundaryTriangleSet *, bool> TouchedTriangle;
     4035  map<class BoundaryLineSet *, bool>::iterator LineRunner;
     4036  map<class BoundaryTriangleSet *, bool>::iterator TriangleRunner;
    28324037  for (LineMap::iterator Runner = ReferencePoint->lines.begin(); Runner != ReferencePoint->lines.end(); Runner++) {
    2833     TouchedLine.insert( pair <class BoundaryLineSet *, bool>(Runner->second, false) );
     4038    TouchedLine.insert(pair<class BoundaryLineSet *, bool> (Runner->second, false));
    28344039    for (TriangleMap::iterator Sprinter = Runner->second->triangles.begin(); Sprinter != Runner->second->triangles.end(); Sprinter++)
    2835       TouchedTriangle.insert( pair <class BoundaryTriangleSet *, bool>(Sprinter->second, false) );
     4040      TouchedTriangle.insert(pair<class BoundaryTriangleSet *, bool> (Sprinter->second, false));
    28364041  }
    28374042  if (!ReferencePoint->lines.empty()) {
     
    28394044      LineRunner = TouchedLine.find(runner->second);
    28404045      if (LineRunner == TouchedLine.end()) {
    2841         Log() << Verbose(2) << "ERROR: I could not find " << *runner->second << " in the touched list." << endl;
     4046        DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *runner->second << " in the touched list." << endl);
    28424047      } else if (!LineRunner->second) {
    28434048        LineRunner->second = true;
    2844         connectedPath = new list<TesselPoint*>;
     4049        connectedPath = new TesselPointList;
    28454050        triangle = NULL;
    28464051        CurrentLine = runner->second;
    28474052        StartLine = CurrentLine;
    28484053        CurrentPoint = CurrentLine->GetOtherEndpoint(ReferencePoint);
    2849         Log() << Verbose(3)<< "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl;
     4054        DoLog(1) && (Log() << Verbose(1) << "INFO: Beginning path retrieval at " << *CurrentPoint << " of line " << *CurrentLine << "." << endl);
    28504055        do {
    28514056          // push current one
    2852           Log() << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     4057          DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
    28534058          connectedPath->push_back(CurrentPoint->node);
    28544059
    28554060          // find next triangle
    28564061          for (TriangleMap::iterator Runner = CurrentLine->triangles.begin(); Runner != CurrentLine->triangles.end(); Runner++) {
    2857             Log() << Verbose(3) << "INFO: Inspecting triangle " << *Runner->second << "." << endl;
     4062            DoLog(1) && (Log() << Verbose(1) << "INFO: Inspecting triangle " << *Runner->second << "." << endl);
    28584063            if ((Runner->second != triangle)) { // look for first triangle not equal to old one
    28594064              triangle = Runner->second;
     
    28624067                if (!TriangleRunner->second) {
    28634068                  TriangleRunner->second = true;
    2864                   Log() << Verbose(3) << "INFO: Connecting triangle is " << *triangle << "." << endl;
     4069                  DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting triangle is " << *triangle << "." << endl);
    28654070                  break;
    28664071                } else {
    2867                   Log() << Verbose(3) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl;
     4072                  DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *triangle << ", as we have already visited it." << endl);
    28684073                  triangle = NULL;
    28694074                }
    28704075              } else {
    2871                 Log() << Verbose(2) << "ERROR: I could not find " << *triangle << " in the touched list." << endl;
     4076                DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *triangle << " in the touched list." << endl);
    28724077                triangle = NULL;
    28734078              }
     
    28774082            break;
    28784083          // find next line
    2879           for (int i=0;i<3;i++) {
     4084          for (int i = 0; i < 3; i++) {
    28804085            if ((triangle->lines[i] != CurrentLine) && (triangle->lines[i]->ContainsBoundaryPoint(ReferencePoint))) { // not the current line and still containing Point
    28814086              CurrentLine = triangle->lines[i];
    2882               Log() << Verbose(3) << "INFO: Connecting line is " << *CurrentLine << "." << endl;
     4087              DoLog(1) && (Log() << Verbose(1) << "INFO: Connecting line is " << *CurrentLine << "." << endl);
    28834088              break;
    28844089            }
     
    28864091          LineRunner = TouchedLine.find(CurrentLine);
    28874092          if (LineRunner == TouchedLine.end())
    2888             Log() << Verbose(2) << "ERROR: I could not find " << *CurrentLine << " in the touched list." << endl;
     4093            DoeLog(1) && (eLog() << Verbose(1) << "I could not find " << *CurrentLine << " in the touched list." << endl);
    28894094          else
    28904095            LineRunner->second = true;
     
    28944099        } while (CurrentLine != StartLine);
    28954100        // last point is missing, as it's on start line
    2896         Log() << Verbose(3) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl;
     4101        DoLog(1) && (Log() << Verbose(1) << "INFO: Putting " << *CurrentPoint << " at end of path." << endl);
    28974102        if (StartLine->GetOtherEndpoint(ReferencePoint)->node != connectedPath->back())
    28984103          connectedPath->push_back(StartLine->GetOtherEndpoint(ReferencePoint)->node);
     
    29004105        ListOfPaths->push_back(connectedPath);
    29014106      } else {
    2902         Log() << Verbose(3) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl;
     4107        DoLog(1) && (Log() << Verbose(1) << "INFO: Skipping " << *runner->second << ", as we have already visited it." << endl);
    29034108      }
    29044109    }
    29054110  } else {
    2906     Log() << Verbose(1) << "ERROR: There are no lines attached to " << *ReferencePoint << "." << endl;
     4111    DoeLog(1) && (eLog() << Verbose(1) << "There are no lines attached to " << *ReferencePoint << "." << endl);
    29074112  }
    29084113
     
    29164121 * @return list of the closed paths
    29174122 */
    2918 list<list<TesselPoint*> *> * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
    2919 {
    2920   list<list<TesselPoint*> *> *ListofPaths = GetPathsOfConnectedPoints(Point);
    2921   list<list<TesselPoint*> *> *ListofClosedPaths = new list<list<TesselPoint*> *>;
    2922   list<TesselPoint*> *connectedPath = NULL;
    2923   list<TesselPoint*> *newPath = NULL;
     4123ListOfTesselPointList * Tesselation::GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const
     4124{
     4125  Info FunctionInfo(__func__);
     4126  list<TesselPointList *> *ListofPaths = GetPathsOfConnectedPoints(Point);
     4127  list<TesselPointList *> *ListofClosedPaths = new list<TesselPointList *> ;
     4128  TesselPointList *connectedPath = NULL;
     4129  TesselPointList *newPath = NULL;
    29244130  int count = 0;
    2925 
    2926 
    2927   list<TesselPoint*>::iterator CircleRunner;
    2928   list<TesselPoint*>::iterator CircleStart;
    2929 
    2930   for(list<list<TesselPoint*> *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
     4131  TesselPointList::iterator CircleRunner;
     4132  TesselPointList::iterator CircleStart;
     4133
     4134  for (list<TesselPointList *>::iterator ListRunner = ListofPaths->begin(); ListRunner != ListofPaths->end(); ListRunner++) {
    29314135    connectedPath = *ListRunner;
    29324136
    2933     Log() << Verbose(2) << "INFO: Current path is " << connectedPath << "." << endl;
     4137    DoLog(1) && (Log() << Verbose(1) << "INFO: Current path is " << connectedPath << "." << endl);
    29344138
    29354139    // go through list, look for reappearance of starting Point and count
    29364140    CircleStart = connectedPath->begin();
    2937 
    29384141    // go through list, look for reappearance of starting Point and create list
    2939     list<TesselPoint*>::iterator Marker = CircleStart;
     4142    TesselPointList::iterator Marker = CircleStart;
    29404143    for (CircleRunner = CircleStart; CircleRunner != connectedPath->end(); CircleRunner++) {
    29414144      if ((*CircleRunner == *CircleStart) && (CircleRunner != CircleStart)) { // is not the very first point
    29424145        // we have a closed circle from Marker to new Marker
    2943         Log() << Verbose(3) << count+1 << ". closed path consists of: ";
    2944         newPath = new list<TesselPoint*>;
    2945         list<TesselPoint*>::iterator CircleSprinter = Marker;
     4146        DoLog(1) && (Log() << Verbose(1) << count + 1 << ". closed path consists of: ");
     4147        newPath = new TesselPointList;
     4148        TesselPointList::iterator CircleSprinter = Marker;
    29464149        for (; CircleSprinter != CircleRunner; CircleSprinter++) {
    29474150          newPath->push_back(*CircleSprinter);
    2948           Log() << Verbose(0) << (**CircleSprinter) << " <-> ";
     4151          DoLog(0) && (Log() << Verbose(0) << (**CircleSprinter) << " <-> ");
    29494152        }
    2950         Log() << Verbose(0) << ".." << endl;
     4153        DoLog(0) && (Log() << Verbose(0) << ".." << endl);
    29514154        count++;
    29524155        Marker = CircleRunner;
     
    29574160    }
    29584161  }
    2959   Log() << Verbose(3) << "INFO: " << count << " closed additional path(s) have been created." << endl;
     4162  DoLog(1) && (Log() << Verbose(1) << "INFO: " << count << " closed additional path(s) have been created." << endl);
    29604163
    29614164  // delete list of paths
     
    29634166    connectedPath = *(ListofPaths->begin());
    29644167    ListofPaths->remove(connectedPath);
    2965     delete(connectedPath);
    2966   }
    2967   delete(ListofPaths);
     4168    delete (connectedPath);
     4169  }
     4170  delete (ListofPaths);
    29684171
    29694172  // exit
    29704173  return ListofClosedPaths;
    2971 };
    2972 
     4174}
     4175;
    29734176
    29744177/** Gets all belonging triangles for a given BoundaryPointSet.
     
    29774180 * \return pointer to allocated list of triangles
    29784181 */
    2979 set<BoundaryTriangleSet*> *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
    2980 {
    2981   set<BoundaryTriangleSet*> *connectedTriangles = new set<BoundaryTriangleSet*>;
     4182TriangleSet *Tesselation::GetAllTriangles(const BoundaryPointSet * const Point) const
     4183{
     4184  Info FunctionInfo(__func__);
     4185  TriangleSet *connectedTriangles = new TriangleSet;
    29824186
    29834187  if (Point == NULL) {
    2984     Log() << Verbose(1) << "ERROR: Point given is NULL." << endl;
     4188    DoeLog(1) && (eLog() << Verbose(1) << "Point given is NULL." << endl);
    29854189  } else {
    29864190    // go through its lines and insert all triangles
    29874191    for (LineMap::const_iterator LineRunner = Point->lines.begin(); LineRunner != Point->lines.end(); LineRunner++)
    29884192      for (TriangleMap::iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
    2989       connectedTriangles->insert(TriangleRunner->second);
    2990     }
     4193        connectedTriangles->insert(TriangleRunner->second);
     4194      }
    29914195  }
    29924196
    29934197  return connectedTriangles;
    2994 };
    2995 
     4198}
     4199;
    29964200
    29974201/** Removes a boundary point from the envelope while keeping it closed.
     
    30064210 * \return volume added to the volume inside the tesselated surface by the removal
    30074211 */
    3008 double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point) {
     4212double Tesselation::RemovePointFromTesselatedSurface(class BoundaryPointSet *point)
     4213{
    30094214  class BoundaryLineSet *line = NULL;
    30104215  class BoundaryTriangleSet *triangle = NULL;
     
    30144219
    30154220  if (point == NULL) {
    3016     Log() << Verbose(1) << "ERROR: Cannot remove the point " << point << ", it's NULL!" << endl;
     4221    DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << point << ", it's NULL!" << endl);
    30174222    return 0.;
    30184223  } else
    3019     Log() << Verbose(2) << "Removing point " << *point << " from tesselated boundary ..." << endl;
     4224    DoLog(0) && (Log() << Verbose(0) << "Removing point " << *point << " from tesselated boundary ..." << endl);
    30204225
    30214226  // copy old location for the volume
     
    30244229  // get list of connected points
    30254230  if (point->lines.empty()) {
    3026     Log() << Verbose(1) << "ERROR: Cannot remove the point " << *point << ", it's connected to no lines!" << endl;
     4231    DoeLog(1) && (eLog() << Verbose(1) << "Cannot remove the point " << *point << ", it's connected to no lines!" << endl);
    30274232    return 0.;
    30284233  }
    30294234
    3030   list<list<TesselPoint*> *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
    3031   list<TesselPoint*> *connectedPath = NULL;
     4235  list<TesselPointList *> *ListOfClosedPaths = GetClosedPathsOfConnectedPoints(point->node);
     4236  TesselPointList *connectedPath = NULL;
    30324237
    30334238  // gather all triangles
    30344239  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++)
    3035     count+=LineRunner->second->triangles.size();
    3036   map<class BoundaryTriangleSet *, int> Candidates;
     4240    count += LineRunner->second->triangles.size();
     4241  TriangleMap Candidates;
    30374242  for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    30384243    line = LineRunner->second;
    30394244    for (TriangleMap::iterator TriangleRunner = line->triangles.begin(); TriangleRunner != line->triangles.end(); TriangleRunner++) {
    30404245      triangle = TriangleRunner->second;
    3041       Candidates.insert( pair<class BoundaryTriangleSet *, int> (triangle, triangle->Nr) );
     4246      Candidates.insert(TrianglePair(triangle->Nr, triangle));
    30424247    }
    30434248  }
    30444249
    30454250  // remove all triangles
    3046   count=0;
     4251  count = 0;
    30474252  NormalVector.Zero();
    3048   for (map<class BoundaryTriangleSet *, int>::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
    3049     Log() << Verbose(3) << "INFO: Removing triangle " << *(Runner->first) << "." << endl;
    3050     NormalVector.SubtractVector(&Runner->first->NormalVector); // has to point inward
    3051     RemoveTesselationTriangle(Runner->first);
     4253  for (TriangleMap::iterator Runner = Candidates.begin(); Runner != Candidates.end(); Runner++) {
     4254    DoLog(1) && (Log() << Verbose(1) << "INFO: Removing triangle " << *(Runner->second) << "." << endl);
     4255    NormalVector.SubtractVector(&Runner->second->NormalVector); // has to point inward
     4256    RemoveTesselationTriangle(Runner->second);
    30524257    count++;
    30534258  }
    3054   Log() << Verbose(1) << count << " triangles were removed." << endl;
    3055 
    3056   list<list<TesselPoint*> *>::iterator ListAdvance = ListOfClosedPaths->begin();
    3057   list<list<TesselPoint*> *>::iterator ListRunner = ListAdvance;
    3058   map<class BoundaryTriangleSet *, int>::iterator NumberRunner = Candidates.begin();
    3059   list<TesselPoint*>::iterator StartNode, MiddleNode, EndNode;
     4259  DoLog(1) && (Log() << Verbose(1) << count << " triangles were removed." << endl);
     4260
     4261  list<TesselPointList *>::iterator ListAdvance = ListOfClosedPaths->begin();
     4262  list<TesselPointList *>::iterator ListRunner = ListAdvance;
     4263  TriangleMap::iterator NumberRunner = Candidates.begin();
     4264  TesselPointList::iterator StartNode, MiddleNode, EndNode;
    30604265  double angle;
    30614266  double smallestangle;
    30624267  Vector Point, Reference, OrthogonalVector;
    3063   if (count > 2) {  // less than three triangles, then nothing will be created
     4268  if (count > 2) { // less than three triangles, then nothing will be created
    30644269    class TesselPoint *TriangleCandidates[3];
    30654270    count = 0;
    3066     for ( ; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
     4271    for (; ListRunner != ListOfClosedPaths->end(); ListRunner = ListAdvance) { // go through all closed paths
    30674272      if (ListAdvance != ListOfClosedPaths->end())
    30684273        ListAdvance++;
    30694274
    30704275      connectedPath = *ListRunner;
    3071 
    30724276      // re-create all triangles by going through connected points list
    3073       list<class BoundaryLineSet *> NewLines;
    3074       for (;!connectedPath->empty();) {
     4277      LineList NewLines;
     4278      for (; !connectedPath->empty();) {
    30754279        // search middle node with widest angle to next neighbours
    30764280        EndNode = connectedPath->end();
    30774281        smallestangle = 0.;
    30784282        for (MiddleNode = connectedPath->begin(); MiddleNode != connectedPath->end(); MiddleNode++) {
    3079           Log() << Verbose(3) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
     4283          DoLog(1) && (Log() << Verbose(1) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
    30804284          // construct vectors to next and previous neighbour
    30814285          StartNode = MiddleNode;
     
    30984302          angle = GetAngle(Point, Reference, OrthogonalVector);
    30994303          //if (angle < M_PI)  // no wrong-sided triangles, please?
    3100             if(fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
    3101               smallestangle = angle;
    3102               EndNode = MiddleNode;
    3103             }
     4304          if (fabs(angle - M_PI) < fabs(smallestangle - M_PI)) { // get straightest angle (i.e. construct those triangles with smallest area first)
     4305            smallestangle = angle;
     4306            EndNode = MiddleNode;
     4307          }
    31044308        }
    31054309        MiddleNode = EndNode;
    31064310        if (MiddleNode == connectedPath->end()) {
    3107           Log() << Verbose(1) << "CRITICAL: Could not find a smallest angle!" << endl;
    3108           exit(255);
     4311          DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: Could not find a smallest angle!" << endl);
     4312          performCriticalExit();
    31094313        }
    31104314        StartNode = MiddleNode;
     
    31154319        if (EndNode == connectedPath->end())
    31164320          EndNode = connectedPath->begin();
    3117         Log() << Verbose(4) << "INFO: StartNode is " << **StartNode << "." << endl;
    3118         Log() << Verbose(4) << "INFO: MiddleNode is " << **MiddleNode << "." << endl;
    3119         Log() << Verbose(4) << "INFO: EndNode is " << **EndNode << "." << endl;
    3120         Log() << Verbose(3) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl;
     4321        DoLog(2) && (Log() << Verbose(2) << "INFO: StartNode is " << **StartNode << "." << endl);
     4322        DoLog(2) && (Log() << Verbose(2) << "INFO: MiddleNode is " << **MiddleNode << "." << endl);
     4323        DoLog(2) && (Log() << Verbose(2) << "INFO: EndNode is " << **EndNode << "." << endl);
     4324        DoLog(1) && (Log() << Verbose(1) << "INFO: Attempting to create triangle " << (*StartNode)->Name << ", " << (*MiddleNode)->Name << " and " << (*EndNode)->Name << "." << endl);
    31214325        TriangleCandidates[0] = *StartNode;
    31224326        TriangleCandidates[1] = *MiddleNode;
     
    31244328        triangle = GetPresentTriangle(TriangleCandidates);
    31254329        if (triangle != NULL) {
    3126           Log() << Verbose(1) << "WARNING: New triangle already present, skipping!" << endl;
     4330          DoeLog(0) && (eLog() << Verbose(0) << "New triangle already present, skipping!" << endl);
    31274331          StartNode++;
    31284332          MiddleNode++;
     
    31364340          continue;
    31374341        }
    3138         Log() << Verbose(5) << "Adding new triangle points."<< endl;
     4342        DoLog(3) && (Log() << Verbose(3) << "Adding new triangle points." << endl);
    31394343        AddTesselationPoint(*StartNode, 0);
    31404344        AddTesselationPoint(*MiddleNode, 1);
    31414345        AddTesselationPoint(*EndNode, 2);
    3142         Log() << Verbose(5) << "Adding new triangle lines."<< endl;
    3143         AddTesselationLine(TPS[0], TPS[1], 0);
    3144         AddTesselationLine(TPS[0], TPS[2], 1);
     4346        DoLog(3) && (Log() << Verbose(3) << "Adding new triangle lines." << endl);
     4347        AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     4348        AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
    31454349        NewLines.push_back(BLS[1]);
    3146         AddTesselationLine(TPS[1], TPS[2], 2);
     4350        AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    31474351        BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    31484352        BTS->GetNormalVector(NormalVector);
     
    31554359        // prepare nodes for next triangle
    31564360        StartNode = EndNode;
    3157         Log() << Verbose(4) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl;
     4361        DoLog(2) && (Log() << Verbose(2) << "Removing " << **MiddleNode << " from closed path, remaining points: " << connectedPath->size() << "." << endl);
    31584362        connectedPath->remove(*MiddleNode); // remove the middle node (it is surrounded by triangles)
    31594363        if (connectedPath->size() == 2) { // we are done
     
    31624366          break;
    31634367        } else if (connectedPath->size() < 2) { // something's gone wrong!
    3164           Log() << Verbose(1) << "CRITICAL: There are only two endpoints left!" << endl;
    3165           exit(255);
     4368          DoeLog(0) && (eLog() << Verbose(0) << "CRITICAL: There are only two endpoints left!" << endl);
     4369          performCriticalExit();
    31664370        } else {
    31674371          MiddleNode = StartNode;
     
    31774381      // maximize the inner lines (we preferentially created lines with a huge angle, which is for the tesselation not wanted though useful for the closing)
    31784382      if (NewLines.size() > 1) {
    3179         list<class BoundaryLineSet *>::iterator Candidate;
     4383        LineList::iterator Candidate;
    31804384        class BoundaryLineSet *OtherBase = NULL;
    31814385        double tmp, maxgain;
    31824386        do {
    31834387          maxgain = 0;
    3184           for(list<class BoundaryLineSet *>::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
     4388          for (LineList::iterator Runner = NewLines.begin(); Runner != NewLines.end(); Runner++) {
    31854389            tmp = PickFarthestofTwoBaselines(*Runner);
    31864390            if (maxgain < tmp) {
     
    31914395          if (maxgain != 0) {
    31924396            volume += maxgain;
    3193             Log() << Verbose(3) << "Flipping baseline with highest volume" << **Candidate << "." << endl;
     4397            DoLog(1) && (Log() << Verbose(1) << "Flipping baseline with highest volume" << **Candidate << "." << endl);
    31944398            OtherBase = FlipBaseline(*Candidate);
    31954399            NewLines.erase(Candidate);
     
    32004404
    32014405      ListOfClosedPaths->remove(connectedPath);
    3202       delete(connectedPath);
    3203     }
    3204     Log() << Verbose(1) << count << " triangles were created." << endl;
     4406      delete (connectedPath);
     4407    }
     4408    DoLog(0) && (Log() << Verbose(0) << count << " triangles were created." << endl);
    32054409  } else {
    32064410    while (!ListOfClosedPaths->empty()) {
     
    32084412      connectedPath = *ListRunner;
    32094413      ListOfClosedPaths->remove(connectedPath);
    3210       delete(connectedPath);
    3211     }
    3212     Log() << Verbose(1) << "No need to create any triangles." << endl;
    3213   }
    3214   delete(ListOfClosedPaths);
    3215 
    3216   Log() << Verbose(1) << "Removed volume is " << volume << "." << endl;
     4414      delete (connectedPath);
     4415    }
     4416    DoLog(0) && (Log() << Verbose(0) << "No need to create any triangles." << endl);
     4417  }
     4418  delete (ListOfClosedPaths);
     4419
     4420  DoLog(0) && (Log() << Verbose(0) << "Removed volume is " << volume << "." << endl);
    32174421
    32184422  return volume;
    3219 };
    3220 
    3221 
     4423}
     4424;
    32224425
    32234426/**
    32244427 * Finds triangles belonging to the three provided points.
    32254428 *
    3226  * @param *Points[3] list, is expected to contain three points
     4429 * @param *Points[3] list, is expected to contain three points (NULL means wildcard)
    32274430 *
    32284431 * @return triangles which belong to the provided points, will be empty if there are none,
    32294432 *         will usually be one, in case of degeneration, there will be two
    32304433 */
    3231 list<BoundaryTriangleSet*> *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
    3232 {
    3233   list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;
     4434TriangleList *Tesselation::FindTriangles(const TesselPoint* const Points[3]) const
     4435{
     4436  Info FunctionInfo(__func__);
     4437  TriangleList *result = new TriangleList;
    32344438  LineMap::const_iterator FindLine;
    32354439  TriangleMap::const_iterator FindTriangle;
    32364440  class BoundaryPointSet *TrianglePoints[3];
     4441  size_t NoOfWildcards = 0;
    32374442
    32384443  for (int i = 0; i < 3; i++) {
    3239     PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
    3240     if (FindPoint != PointsOnBoundary.end()) {
    3241       TrianglePoints[i] = FindPoint->second;
     4444    if (Points[i] == NULL) {
     4445      NoOfWildcards++;
     4446      TrianglePoints[i] = NULL;
    32424447    } else {
    3243       TrianglePoints[i] = NULL;
    3244     }
    3245   }
    3246 
    3247   // checks lines between the points in the Points for their adjacent triangles
    3248   for (int i = 0; i < 3; i++) {
    3249     if (TrianglePoints[i] != NULL) {
    3250       for (int j = i+1; j < 3; j++) {
    3251         if (TrianglePoints[j] != NULL) {
    3252           for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
    3253               (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr);
    3254               FindLine++) {
    3255             for (FindTriangle = FindLine->second->triangles.begin();
    3256                 FindTriangle != FindLine->second->triangles.end();
    3257                 FindTriangle++) {
    3258               if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
    3259                 result->push_back(FindTriangle->second);
     4448      PointMap::const_iterator FindPoint = PointsOnBoundary.find(Points[i]->nr);
     4449      if (FindPoint != PointsOnBoundary.end()) {
     4450        TrianglePoints[i] = FindPoint->second;
     4451      } else {
     4452        TrianglePoints[i] = NULL;
     4453      }
     4454    }
     4455  }
     4456
     4457  switch (NoOfWildcards) {
     4458    case 0: // checks lines between the points in the Points for their adjacent triangles
     4459      for (int i = 0; i < 3; i++) {
     4460        if (TrianglePoints[i] != NULL) {
     4461          for (int j = i + 1; j < 3; j++) {
     4462            if (TrianglePoints[j] != NULL) {
     4463              for (FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr); // is a multimap!
     4464              (FindLine != TrianglePoints[i]->lines.end()) && (FindLine->first == TrianglePoints[j]->node->nr); FindLine++) {
     4465                for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
     4466                  if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
     4467                    result->push_back(FindTriangle->second);
     4468                  }
     4469                }
    32604470              }
     4471              // Is it sufficient to consider one of the triangle lines for this.
     4472              return result;
    32614473            }
    32624474          }
    3263           // Is it sufficient to consider one of the triangle lines for this.
    3264           return result;
    32654475        }
    32664476      }
    3267     }
     4477      break;
     4478    case 1: // copy all triangles of the respective line
     4479    {
     4480      int i = 0;
     4481      for (; i < 3; i++)
     4482        if (TrianglePoints[i] == NULL)
     4483          break;
     4484      for (FindLine = TrianglePoints[(i + 1) % 3]->lines.find(TrianglePoints[(i + 2) % 3]->node->nr); // is a multimap!
     4485      (FindLine != TrianglePoints[(i + 1) % 3]->lines.end()) && (FindLine->first == TrianglePoints[(i + 2) % 3]->node->nr); FindLine++) {
     4486        for (FindTriangle = FindLine->second->triangles.begin(); FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
     4487          if (FindTriangle->second->IsPresentTupel(TrianglePoints)) {
     4488            result->push_back(FindTriangle->second);
     4489          }
     4490        }
     4491      }
     4492      break;
     4493    }
     4494    case 2: // copy all triangles of the respective point
     4495    {
     4496      int i = 0;
     4497      for (; i < 3; i++)
     4498        if (TrianglePoints[i] != NULL)
     4499          break;
     4500      for (LineMap::const_iterator line = TrianglePoints[i]->lines.begin(); line != TrianglePoints[i]->lines.end(); line++)
     4501        for (TriangleMap::const_iterator triangle = line->second->triangles.begin(); triangle != line->second->triangles.end(); triangle++)
     4502          result->push_back(triangle->second);
     4503      result->sort();
     4504      result->unique();
     4505      break;
     4506    }
     4507    case 3: // copy all triangles
     4508    {
     4509      for (TriangleMap::const_iterator triangle = TrianglesOnBoundary.begin(); triangle != TrianglesOnBoundary.end(); triangle++)
     4510        result->push_back(triangle->second);
     4511      break;
     4512    }
     4513    default:
     4514      DoeLog(0) && (eLog() << Verbose(0) << "Number of wildcards is greater than 3, cannot happen!" << endl);
     4515      performCriticalExit();
     4516      break;
    32684517  }
    32694518
    32704519  return result;
    32714520}
     4521
     4522struct BoundaryLineSetCompare
     4523{
     4524  bool operator()(const BoundaryLineSet * const a, const BoundaryLineSet * const b)
     4525  {
     4526    int lowerNra = -1;
     4527    int lowerNrb = -1;
     4528
     4529    if (a->endpoints[0] < a->endpoints[1])
     4530      lowerNra = 0;
     4531    else
     4532      lowerNra = 1;
     4533
     4534    if (b->endpoints[0] < b->endpoints[1])
     4535      lowerNrb = 0;
     4536    else
     4537      lowerNrb = 1;
     4538
     4539    if (a->endpoints[lowerNra] < b->endpoints[lowerNrb])
     4540      return true;
     4541    else if (a->endpoints[lowerNra] > b->endpoints[lowerNrb])
     4542      return false;
     4543    else { // both lower-numbered endpoints are the same ...
     4544      if (a->endpoints[(lowerNra + 1) % 2] < b->endpoints[(lowerNrb + 1) % 2])
     4545        return true;
     4546      else if (a->endpoints[(lowerNra + 1) % 2] > b->endpoints[(lowerNrb + 1) % 2])
     4547        return false;
     4548    }
     4549    return false;
     4550  }
     4551  ;
     4552};
     4553
     4554#define UniqueLines set < class BoundaryLineSet *, BoundaryLineSetCompare>
    32724555
    32734556/**
     
    32774560 *         in the list, once as key and once as value
    32784561 */
    3279 map<int, int> * Tesselation::FindAllDegeneratedLines()
    3280 {
    3281   map<int, class BoundaryLineSet *> AllLines;
    3282   map<int, int> * DegeneratedLines = new map<int, int>;
     4562IndexToIndex * Tesselation::FindAllDegeneratedLines()
     4563{
     4564  Info FunctionInfo(__func__);
     4565  UniqueLines AllLines;
     4566  IndexToIndex * DegeneratedLines = new IndexToIndex;
    32834567
    32844568  // sanity check
    32854569  if (LinesOnBoundary.empty()) {
    3286     Log() << Verbose(1) << "Warning: FindAllDegeneratedTriangles() was called without any tesselation structure.";
     4570    DoeLog(2) && (eLog() << Verbose(2) << "FindAllDegeneratedTriangles() was called without any tesselation structure.");
    32874571    return DegeneratedLines;
    32884572  }
    3289 
    32904573  LineMap::iterator LineRunner1;
    3291   pair<LineMap::iterator, bool> tester;
     4574  pair<UniqueLines::iterator, bool> tester;
    32924575  for (LineRunner1 = LinesOnBoundary.begin(); LineRunner1 != LinesOnBoundary.end(); ++LineRunner1) {
    3293     tester = AllLines.insert( pair<int,BoundaryLineSet *> (LineRunner1->second->endpoints[0]->Nr, LineRunner1->second) );
    3294     if ((!tester.second) && (tester.first->second->endpoints[1]->Nr == LineRunner1->second->endpoints[1]->Nr)) { // found degenerated line
    3295       DegeneratedLines->insert ( pair<int, int> (LineRunner1->second->Nr, tester.first->second->Nr) );
    3296       DegeneratedLines->insert ( pair<int, int> (tester.first->second->Nr, LineRunner1->second->Nr) );
     4576    tester = AllLines.insert(LineRunner1->second);
     4577    if (!tester.second) { // found degenerated line
     4578      DegeneratedLines->insert(pair<int, int> (LineRunner1->second->Nr, (*tester.first)->Nr));
     4579      DegeneratedLines->insert(pair<int, int> ((*tester.first)->Nr, LineRunner1->second->Nr));
    32974580    }
    32984581  }
     
    33004583  AllLines.clear();
    33014584
    3302   Log() << Verbose(1) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl;
    3303   map<int,int>::iterator it;
    3304   for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++)
    3305       Log() << Verbose(2) << (*it).first << " => " << (*it).second << endl;
     4585  DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedLines() found " << DegeneratedLines->size() << " lines." << endl);
     4586  IndexToIndex::iterator it;
     4587  for (it = DegeneratedLines->begin(); it != DegeneratedLines->end(); it++) {
     4588    const LineMap::const_iterator Line1 = LinesOnBoundary.find((*it).first);
     4589    const LineMap::const_iterator Line2 = LinesOnBoundary.find((*it).second);
     4590    if (Line1 != LinesOnBoundary.end() && Line2 != LinesOnBoundary.end())
     4591      DoLog(0) && (Log() << Verbose(0) << *Line1->second << " => " << *Line2->second << endl);
     4592    else
     4593      DoeLog(1) && (eLog() << Verbose(1) << "Either " << (*it).first << " or " << (*it).second << " are not in LinesOnBoundary!" << endl);
     4594  }
    33064595
    33074596  return DegeneratedLines;
     
    33144603 *         in the list, once as key and once as value
    33154604 */
    3316 map<int, int> * Tesselation::FindAllDegeneratedTriangles()
    3317 {
    3318   map<int, int> * DegeneratedLines = FindAllDegeneratedLines();
    3319   map<int, int> * DegeneratedTriangles = new map<int, int>;
    3320 
     4605IndexToIndex * Tesselation::FindAllDegeneratedTriangles()
     4606{
     4607  Info FunctionInfo(__func__);
     4608  IndexToIndex * DegeneratedLines = FindAllDegeneratedLines();
     4609  IndexToIndex * DegeneratedTriangles = new IndexToIndex;
    33214610  TriangleMap::iterator TriangleRunner1, TriangleRunner2;
    33224611  LineMap::iterator Liner;
    33234612  class BoundaryLineSet *line1 = NULL, *line2 = NULL;
    33244613
    3325   for (map<int, int>::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
     4614  for (IndexToIndex::iterator LineRunner = DegeneratedLines->begin(); LineRunner != DegeneratedLines->end(); ++LineRunner) {
    33264615    // run over both lines' triangles
    33274616    Liner = LinesOnBoundary.find(LineRunner->first);
     
    33334622    for (TriangleRunner1 = line1->triangles.begin(); TriangleRunner1 != line1->triangles.end(); ++TriangleRunner1) {
    33344623      for (TriangleRunner2 = line2->triangles.begin(); TriangleRunner2 != line2->triangles.end(); ++TriangleRunner2) {
    3335         if ((TriangleRunner1->second != TriangleRunner2->second)
    3336           && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
    3337           DegeneratedTriangles->insert( pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr) );
    3338           DegeneratedTriangles->insert( pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr) );
     4624        if ((TriangleRunner1->second != TriangleRunner2->second) && (TriangleRunner1->second->IsPresentTupel(TriangleRunner2->second))) {
     4625          DegeneratedTriangles->insert(pair<int, int> (TriangleRunner1->second->Nr, TriangleRunner2->second->Nr));
     4626          DegeneratedTriangles->insert(pair<int, int> (TriangleRunner2->second->Nr, TriangleRunner1->second->Nr));
    33394627        }
    33404628      }
    33414629    }
    33424630  }
    3343   delete(DegeneratedLines);
    3344 
    3345   Log() << Verbose(1) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl;
    3346   map<int,int>::iterator it;
     4631  delete (DegeneratedLines);
     4632
     4633  DoLog(0) && (Log() << Verbose(0) << "FindAllDegeneratedTriangles() found " << DegeneratedTriangles->size() << " triangles:" << endl);
     4634  IndexToIndex::iterator it;
    33474635  for (it = DegeneratedTriangles->begin(); it != DegeneratedTriangles->end(); it++)
    3348       Log() << Verbose(2) << (*it).first << " => " << (*it).second << endl;
     4636    DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
    33494637
    33504638  return DegeneratedTriangles;
     
    33574645void Tesselation::RemoveDegeneratedTriangles()
    33584646{
    3359   map<int, int> * DegeneratedTriangles = FindAllDegeneratedTriangles();
     4647  Info FunctionInfo(__func__);
     4648  IndexToIndex * DegeneratedTriangles = FindAllDegeneratedTriangles();
    33604649  TriangleMap::iterator finder;
    33614650  BoundaryTriangleSet *triangle = NULL, *partnerTriangle = NULL;
    3362   int count  = 0;
    3363 
    3364   Log() << Verbose(1) << "Begin of RemoveDegeneratedTriangles" << endl;
    3365 
    3366   for (map<int, int>::iterator TriangleKeyRunner = DegeneratedTriangles->begin();
    3367     TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner
    3368   ) {
     4651  int count = 0;
     4652
     4653  for (IndexToIndex::iterator TriangleKeyRunner = DegeneratedTriangles->begin(); TriangleKeyRunner != DegeneratedTriangles->end(); ++TriangleKeyRunner) {
    33694654    finder = TrianglesOnBoundary.find(TriangleKeyRunner->first);
    33704655    if (finder != TrianglesOnBoundary.end())
     
    33834668        trianglesShareLine = trianglesShareLine || triangle->lines[i] == partnerTriangle->lines[j];
    33844669
    3385     if (trianglesShareLine
    3386       && (triangle->endpoints[1]->LinesCount > 2)
    3387       && (triangle->endpoints[2]->LinesCount > 2)
    3388       && (triangle->endpoints[0]->LinesCount > 2)
    3389     ) {
     4670    if (trianglesShareLine && (triangle->endpoints[1]->LinesCount > 2) && (triangle->endpoints[2]->LinesCount > 2) && (triangle->endpoints[0]->LinesCount > 2)) {
    33904671      // check whether we have to fix lines
    33914672      BoundaryTriangleSet *Othertriangle = NULL;
     
    34074688            // the line of triangle receives the degenerated ones
    34084689            triangle->lines[i]->triangles.erase(Othertriangle->Nr);
    3409             triangle->lines[i]->triangles.insert( TrianglePair( partnerTriangle->Nr, partnerTriangle) );
    3410             for (int k=0;k<3;k++)
     4690            triangle->lines[i]->triangles.insert(TrianglePair(partnerTriangle->Nr, partnerTriangle));
     4691            for (int k = 0; k < 3; k++)
    34114692              if (triangle->lines[i] == Othertriangle->lines[k]) {
    34124693                Othertriangle->lines[k] = partnerTriangle->lines[j];
     
    34144695              }
    34154696            // the line of partnerTriangle receives the non-degenerated ones
    3416             partnerTriangle->lines[j]->triangles.erase( partnerTriangle->Nr);
    3417             partnerTriangle->lines[j]->triangles.insert( TrianglePair( Othertriangle->Nr, Othertriangle) );
     4697            partnerTriangle->lines[j]->triangles.erase(partnerTriangle->Nr);
     4698            partnerTriangle->lines[j]->triangles.insert(TrianglePair(Othertriangle->Nr, Othertriangle));
    34184699            partnerTriangle->lines[j] = triangle->lines[i];
    34194700          }
     
    34214702      // erase the pair
    34224703      count += (int) DegeneratedTriangles->erase(triangle->Nr);
    3423       Log() << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl;
     4704      DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *triangle << "." << endl);
    34244705      RemoveTesselationTriangle(triangle);
    34254706      count += (int) DegeneratedTriangles->erase(partnerTriangle->Nr);
    3426       Log() << Verbose(1) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl;
     4707      DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removes triangle " << *partnerTriangle << "." << endl);
    34274708      RemoveTesselationTriangle(partnerTriangle);
    34284709    } else {
    3429       Log() << Verbose(1) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle
    3430         << " and its partner " << *partnerTriangle << " because it is essential for at"
    3431         << " least one of the endpoints to be kept in the tesselation structure." << endl;
    3432     }
    3433   }
    3434   delete(DegeneratedTriangles);
    3435 
    3436   Log() << Verbose(1) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl;
    3437   Log() << Verbose(1) << "End of RemoveDegeneratedTriangles" << endl;
     4710      DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() does not remove triangle " << *triangle << " and its partner " << *partnerTriangle << " because it is essential for at" << " least one of the endpoints to be kept in the tesselation structure." << endl);
     4711    }
     4712  }
     4713  delete (DegeneratedTriangles);
     4714  if (count > 0)
     4715    LastTriangle = NULL;
     4716
     4717  DoLog(0) && (Log() << Verbose(0) << "RemoveDegeneratedTriangles() removed " << count << " triangles:" << endl);
    34384718}
    34394719
     
    34484728void Tesselation::AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC)
    34494729{
    3450   Log() << Verbose(2) << "Begin of AddBoundaryPointByDegeneratedTriangle" << endl;
    3451 
     4730  Info FunctionInfo(__func__);
    34524731  // find nearest boundary point
    34534732  class TesselPoint *BackupPoint = NULL;
    3454   class TesselPoint *NearestPoint = FindClosestPoint(point->node, BackupPoint, LC);
     4733  class TesselPoint *NearestPoint = FindClosestTesselPoint(point->node, BackupPoint, LC);
    34554734  class BoundaryPointSet *NearestBoundaryPoint = NULL;
    34564735  PointMap::iterator PointRunner;
     
    34624741    NearestBoundaryPoint = PointRunner->second;
    34634742  } else {
    3464     Log() << Verbose(1) << "ERROR: I cannot find the boundary point." << endl;
     4743    DoeLog(1) && (eLog() << Verbose(1) << "I cannot find the boundary point." << endl);
    34654744    return;
    34664745  }
    3467   Log() << Verbose(2) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl;
     4746  DoLog(0) && (Log() << Verbose(0) << "Nearest point on boundary is " << NearestPoint->Name << "." << endl);
    34684747
    34694748  // go through its lines and find the best one to split
     
    34804759    CenterToPoint.SubtractVector(point->node);
    34814760    angle = CenterToPoint.Angle(&BaseLine);
    3482     if (fabs(angle - M_PI/2.) < fabs(BestAngle - M_PI/2.)) {
     4761    if (fabs(angle - M_PI / 2.) < fabs(BestAngle - M_PI / 2.)) {
    34834762      BestAngle = angle;
    34844763      BestLine = Runner->second;
     
    34904769  BestLine->triangles.erase(TempTriangle->Nr);
    34914770  int nr = -1;
    3492   for (int i=0;i<3; i++) {
     4771  for (int i = 0; i < 3; i++) {
    34934772    if (TempTriangle->lines[i] == BestLine) {
    34944773      nr = i;
     
    34984777
    34994778  // create new triangle to connect point (connects automatically with the missing spot of the chosen line)
    3500   Log() << Verbose(5) << "Adding new triangle points."<< endl;
     4779  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
    35014780  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    35024781  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    35034782  AddTesselationPoint(point, 2);
    3504   Log() << Verbose(5) << "Adding new triangle lines."<< endl;
    3505   AddTesselationLine(TPS[0], TPS[1], 0);
    3506   AddTesselationLine(TPS[0], TPS[2], 1);
    3507   AddTesselationLine(TPS[1], TPS[2], 2);
     4783  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
     4784  AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     4785  AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     4786  AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    35084787  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    35094788  BTS->GetNormalVector(TempTriangle->NormalVector);
    35104789  BTS->NormalVector.Scale(-1.);
    3511   Log() << Verbose(3) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl;
     4790  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of new triangle is " << BTS->NormalVector << "." << endl);
    35124791  AddTesselationTriangle();
    35134792
    35144793  // create other side of this triangle and close both new sides of the first created triangle
    3515   Log() << Verbose(5) << "Adding new triangle points."<< endl;
     4794  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle points." << endl);
    35164795  AddTesselationPoint((BestLine->endpoints[0]->node), 0);
    35174796  AddTesselationPoint((BestLine->endpoints[1]->node), 1);
    35184797  AddTesselationPoint(point, 2);
    3519   Log() << Verbose(5) << "Adding new triangle lines."<< endl;
    3520   AddTesselationLine(TPS[0], TPS[1], 0);
    3521   AddTesselationLine(TPS[0], TPS[2], 1);
    3522   AddTesselationLine(TPS[1], TPS[2], 2);
     4798  DoLog(2) && (Log() << Verbose(2) << "Adding new triangle lines." << endl);
     4799  AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     4800  AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     4801  AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
    35234802  BTS = new class BoundaryTriangleSet(BLS, TrianglesOnBoundaryCount);
    35244803  BTS->GetNormalVector(TempTriangle->NormalVector);
    3525   Log() << Verbose(3) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl;
     4804  DoLog(1) && (Log() << Verbose(1) << "INFO: NormalVector of other new triangle is " << BTS->NormalVector << "." << endl);
    35264805  AddTesselationTriangle();
    35274806
    35284807  // add removed triangle to the last open line of the second triangle
    3529   for (int i=0;i<3;i++) { // look for the same line as BestLine (only it's its degenerated companion)
     4808  for (int i = 0; i < 3; i++) { // look for the same line as BestLine (only it's its degenerated companion)
    35304809    if ((BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[0])) && (BTS->lines[i]->ContainsBoundaryPoint(BestLine->endpoints[1]))) {
    3531       if (BestLine == BTS->lines[i]){
    3532         Log() << Verbose(1) << "CRITICAL: BestLine is same as found line, something's wrong here!" << endl;
    3533         exit(255);
     4810      if (BestLine == BTS->lines[i]) {
     4811        DoeLog(0) && (eLog() << Verbose(0) << "BestLine is same as found line, something's wrong here!" << endl);
     4812        performCriticalExit();
    35344813      }
    3535       BTS->lines[i]->triangles.insert( pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle) );
     4814      BTS->lines[i]->triangles.insert(pair<int, class BoundaryTriangleSet *> (TempTriangle->Nr, TempTriangle));
    35364815      TempTriangle->lines[nr] = BTS->lines[i];
    35374816      break;
    35384817    }
    35394818  }
    3540 
    3541   // exit
    3542   Log() << Verbose(2) << "End of AddBoundaryPointByDegeneratedTriangle" << endl;
    3543 };
     4819}
     4820;
    35444821
    35454822/** Writes the envelope to file.
     
    35504827void Tesselation::Output(const char *filename, const PointCloud * const cloud)
    35514828{
     4829  Info FunctionInfo(__func__);
    35524830  ofstream *tempstream = NULL;
    35534831  string NameofTempFile;
     
    35554833
    35564834  if (LastTriangle != NULL) {
    3557     sprintf(NumberName, "-%04d-%s_%s_%s", (int)TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);
     4835    sprintf(NumberName, "-%04d-%s_%s_%s", (int) TrianglesOnBoundary.size(), LastTriangle->endpoints[0]->node->Name, LastTriangle->endpoints[1]->node->Name, LastTriangle->endpoints[2]->node->Name);
    35584836    if (DoTecplotOutput) {
    35594837      string NameofTempFile(filename);
    35604838      NameofTempFile.append(NumberName);
    3561       for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
    3562       NameofTempFile.erase(npos, 1);
     4839      for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
     4840        NameofTempFile.erase(npos, 1);
    35634841      NameofTempFile.append(TecplotSuffix);
    3564       Log() << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     4842      DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
    35654843      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    35664844      WriteTecplotFile(tempstream, this, cloud, TriangleFilesWritten);
    35674845      tempstream->close();
    35684846      tempstream->flush();
    3569       delete(tempstream);
     4847      delete (tempstream);
    35704848    }
    35714849
     
    35734851      string NameofTempFile(filename);
    35744852      NameofTempFile.append(NumberName);
    3575       for(size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
    3576       NameofTempFile.erase(npos, 1);
     4853      for (size_t npos = NameofTempFile.find_first_of(' '); npos != string::npos; npos = NameofTempFile.find(' ', npos))
     4854        NameofTempFile.erase(npos, 1);
    35774855      NameofTempFile.append(Raster3DSuffix);
    3578       Log() << Verbose(1) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n";
     4856      DoLog(0) && (Log() << Verbose(0) << "Writing temporary non convex hull to file " << NameofTempFile << ".\n");
    35794857      tempstream = new ofstream(NameofTempFile.c_str(), ios::trunc);
    35804858      WriteRaster3dFile(tempstream, this, cloud);
     
    35824860      tempstream->close();
    35834861      tempstream->flush();
    3584       delete(tempstream);
     4862      delete (tempstream);
    35854863    }
    35864864  }
    35874865  if (DoTecplotOutput || DoRaster3DOutput)
    35884866    TriangleFilesWritten++;
     4867}
     4868;
     4869
     4870struct BoundaryPolygonSetCompare
     4871{
     4872  bool operator()(const BoundaryPolygonSet * s1, const BoundaryPolygonSet * s2) const
     4873  {
     4874    if (s1->endpoints.size() < s2->endpoints.size())
     4875      return true;
     4876    else if (s1->endpoints.size() > s2->endpoints.size())
     4877      return false;
     4878    else { // equality of number of endpoints
     4879      PointSet::const_iterator Walker1 = s1->endpoints.begin();
     4880      PointSet::const_iterator Walker2 = s2->endpoints.begin();
     4881      while ((Walker1 != s1->endpoints.end()) || (Walker2 != s2->endpoints.end())) {
     4882        if ((*Walker1)->Nr < (*Walker2)->Nr)
     4883          return true;
     4884        else if ((*Walker1)->Nr > (*Walker2)->Nr)
     4885          return false;
     4886        Walker1++;
     4887        Walker2++;
     4888      }
     4889      return false;
     4890    }
     4891  }
    35894892};
     4893
     4894#define UniquePolygonSet set < BoundaryPolygonSet *, BoundaryPolygonSetCompare>
     4895
     4896/** Finds all degenerated polygons and calls ReTesselateDegeneratedPolygon()/
     4897 * \return number of polygons found
     4898 */
     4899int Tesselation::CorrectAllDegeneratedPolygons()
     4900{
     4901  Info FunctionInfo(__func__);
     4902  /// 2. Go through all BoundaryPointSet's, check their triangles' NormalVector
     4903  IndexToIndex *DegeneratedTriangles = FindAllDegeneratedTriangles();
     4904  set<BoundaryPointSet *> EndpointCandidateList;
     4905  pair<set<BoundaryPointSet *>::iterator, bool> InsertionTester;
     4906  pair<map<int, Vector *>::iterator, bool> TriangleInsertionTester;
     4907  for (PointMap::const_iterator Runner = PointsOnBoundary.begin(); Runner != PointsOnBoundary.end(); Runner++) {
     4908    DoLog(0) && (Log() << Verbose(0) << "Current point is " << *Runner->second << "." << endl);
     4909    map<int, Vector *> TriangleVectors;
     4910    // gather all NormalVectors
     4911    DoLog(1) && (Log() << Verbose(1) << "Gathering triangles ..." << endl);
     4912    for (LineMap::const_iterator LineRunner = (Runner->second)->lines.begin(); LineRunner != (Runner->second)->lines.end(); LineRunner++)
     4913      for (TriangleMap::const_iterator TriangleRunner = (LineRunner->second)->triangles.begin(); TriangleRunner != (LineRunner->second)->triangles.end(); TriangleRunner++) {
     4914        if (DegeneratedTriangles->find(TriangleRunner->second->Nr) == DegeneratedTriangles->end()) {
     4915          TriangleInsertionTester = TriangleVectors.insert(pair<int, Vector *> ((TriangleRunner->second)->Nr, &((TriangleRunner->second)->NormalVector)));
     4916          if (TriangleInsertionTester.second)
     4917            DoLog(1) && (Log() << Verbose(1) << " Adding triangle " << *(TriangleRunner->second) << " to triangles to check-list." << endl);
     4918        } else {
     4919          DoLog(1) && (Log() << Verbose(1) << " NOT adding triangle " << *(TriangleRunner->second) << " as it's a simply degenerated one." << endl);
     4920        }
     4921      }
     4922    // check whether there are two that are parallel
     4923    DoLog(1) && (Log() << Verbose(1) << "Finding two parallel triangles ..." << endl);
     4924    for (map<int, Vector *>::iterator VectorWalker = TriangleVectors.begin(); VectorWalker != TriangleVectors.end(); VectorWalker++)
     4925      for (map<int, Vector *>::iterator VectorRunner = VectorWalker; VectorRunner != TriangleVectors.end(); VectorRunner++)
     4926        if (VectorWalker != VectorRunner) { // skip equals
     4927          const double SCP = VectorWalker->second->ScalarProduct(VectorRunner->second); // ScalarProduct should result in -1. for degenerated triangles
     4928          DoLog(1) && (Log() << Verbose(1) << "Checking " << *VectorWalker->second << " against " << *VectorRunner->second << ": " << SCP << endl);
     4929          if (fabs(SCP + 1.) < ParallelEpsilon) {
     4930            InsertionTester = EndpointCandidateList.insert((Runner->second));
     4931            if (InsertionTester.second)
     4932              DoLog(0) && (Log() << Verbose(0) << " Adding " << *Runner->second << " to endpoint candidate list." << endl);
     4933            // and break out of both loops
     4934            VectorWalker = TriangleVectors.end();
     4935            VectorRunner = TriangleVectors.end();
     4936            break;
     4937          }
     4938        }
     4939  }
     4940  delete (DegeneratedTriangles);
     4941  /// 3. Find connected endpoint candidates and put them into a polygon
     4942  UniquePolygonSet ListofDegeneratedPolygons;
     4943  BoundaryPointSet *Walker = NULL;
     4944  BoundaryPointSet *OtherWalker = NULL;
     4945  BoundaryPolygonSet *Current = NULL;
     4946  stack<BoundaryPointSet*> ToCheckConnecteds;
     4947  while (!EndpointCandidateList.empty()) {
     4948    Walker = *(EndpointCandidateList.begin());
     4949    if (Current == NULL) { // create a new polygon with current candidate
     4950      DoLog(0) && (Log() << Verbose(0) << "Starting new polygon set at point " << *Walker << endl);
     4951      Current = new BoundaryPolygonSet;
     4952      Current->endpoints.insert(Walker);
     4953      EndpointCandidateList.erase(Walker);
     4954      ToCheckConnecteds.push(Walker);
     4955    }
     4956
     4957    // go through to-check stack
     4958    while (!ToCheckConnecteds.empty()) {
     4959      Walker = ToCheckConnecteds.top(); // fetch ...
     4960      ToCheckConnecteds.pop(); // ... and remove
     4961      for (LineMap::const_iterator LineWalker = Walker->lines.begin(); LineWalker != Walker->lines.end(); LineWalker++) {
     4962        OtherWalker = (LineWalker->second)->GetOtherEndpoint(Walker);
     4963        DoLog(1) && (Log() << Verbose(1) << "Checking " << *OtherWalker << endl);
     4964        set<BoundaryPointSet *>::iterator Finder = EndpointCandidateList.find(OtherWalker);
     4965        if (Finder != EndpointCandidateList.end()) { // found a connected partner
     4966          DoLog(1) && (Log() << Verbose(1) << " Adding to polygon." << endl);
     4967          Current->endpoints.insert(OtherWalker);
     4968          EndpointCandidateList.erase(Finder); // remove from candidates
     4969          ToCheckConnecteds.push(OtherWalker); // but check its partners too
     4970        } else {
     4971          DoLog(1) && (Log() << Verbose(1) << " is not connected to " << *Walker << endl);
     4972        }
     4973      }
     4974    }
     4975
     4976    DoLog(0) && (Log() << Verbose(0) << "Final polygon is " << *Current << endl);
     4977    ListofDegeneratedPolygons.insert(Current);
     4978    Current = NULL;
     4979  }
     4980
     4981  const int counter = ListofDegeneratedPolygons.size();
     4982
     4983  DoLog(0) && (Log() << Verbose(0) << "The following " << counter << " degenerated polygons have been found: " << endl);
     4984  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++)
     4985    DoLog(0) && (Log() << Verbose(0) << " " << **PolygonRunner << endl);
     4986
     4987  /// 4. Go through all these degenerated polygons
     4988  for (UniquePolygonSet::iterator PolygonRunner = ListofDegeneratedPolygons.begin(); PolygonRunner != ListofDegeneratedPolygons.end(); PolygonRunner++) {
     4989    stack<int> TriangleNrs;
     4990    Vector NormalVector;
     4991    /// 4a. Gather all triangles of this polygon
     4992    TriangleSet *T = (*PolygonRunner)->GetAllContainedTrianglesFromEndpoints();
     4993
     4994    // check whether number is bigger than 2, otherwise it's just a simply degenerated one and nothing to do.
     4995    if (T->size() == 2) {
     4996      DoLog(1) && (Log() << Verbose(1) << " Skipping degenerated polygon, is just a (already simply degenerated) triangle." << endl);
     4997      delete (T);
     4998      continue;
     4999    }
     5000
     5001    // check whether number is even
     5002    // If this case occurs, we have to think about it!
     5003    // The Problem is probably due to two degenerated polygons being connected by a bridging, non-degenerated polygon, as somehow one node has
     5004    // connections to either polygon ...
     5005    if (T->size() % 2 != 0) {
     5006      DoeLog(0) && (eLog() << Verbose(0) << " degenerated polygon contains an odd number of triangles, probably contains bridging non-degenerated ones, too!" << endl);
     5007      performCriticalExit();
     5008    }
     5009    TriangleSet::iterator TriangleWalker = T->begin(); // is the inner iterator
     5010    /// 4a. Get NormalVector for one side (this is "front")
     5011    NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     5012    DoLog(1) && (Log() << Verbose(1) << "\"front\" defining triangle is " << **TriangleWalker << " and Normal vector of \"front\" side is " << NormalVector << endl);
     5013    TriangleWalker++;
     5014    TriangleSet::iterator TriangleSprinter = TriangleWalker; // is the inner advanced iterator
     5015    /// 4b. Remove all triangles whose NormalVector is in opposite direction (i.e. "back")
     5016    BoundaryTriangleSet *triangle = NULL;
     5017    while (TriangleSprinter != T->end()) {
     5018      TriangleWalker = TriangleSprinter;
     5019      triangle = *TriangleWalker;
     5020      TriangleSprinter++;
     5021      DoLog(1) && (Log() << Verbose(1) << "Current triangle to test for removal: " << *triangle << endl);
     5022      if (triangle->NormalVector.ScalarProduct(&NormalVector) < 0) { // if from other side, then delete and remove from list
     5023        DoLog(1) && (Log() << Verbose(1) << " Removing ... " << endl);
     5024        TriangleNrs.push(triangle->Nr);
     5025        T->erase(TriangleWalker);
     5026        RemoveTesselationTriangle(triangle);
     5027      } else
     5028        DoLog(1) && (Log() << Verbose(1) << " Keeping ... " << endl);
     5029    }
     5030    /// 4c. Copy all "front" triangles but with inverse NormalVector
     5031    TriangleWalker = T->begin();
     5032    while (TriangleWalker != T->end()) { // go through all front triangles
     5033      DoLog(1) && (Log() << Verbose(1) << " Re-creating triangle " << **TriangleWalker << " with NormalVector " << (*TriangleWalker)->NormalVector << endl);
     5034      for (int i = 0; i < 3; i++)
     5035        AddTesselationPoint((*TriangleWalker)->endpoints[i]->node, i);
     5036      AddTesselationLine(NULL, NULL, TPS[0], TPS[1], 0);
     5037      AddTesselationLine(NULL, NULL, TPS[0], TPS[2], 1);
     5038      AddTesselationLine(NULL, NULL, TPS[1], TPS[2], 2);
     5039      if (TriangleNrs.empty())
     5040        DoeLog(0) && (eLog() << Verbose(0) << "No more free triangle numbers!" << endl);
     5041      BTS = new BoundaryTriangleSet(BLS, TriangleNrs.top()); // copy triangle ...
     5042      AddTesselationTriangle(); // ... and add
     5043      TriangleNrs.pop();
     5044      BTS->NormalVector.CopyVector(&(*TriangleWalker)->NormalVector);
     5045      BTS->NormalVector.Scale(-1.);
     5046      TriangleWalker++;
     5047    }
     5048    if (!TriangleNrs.empty()) {
     5049      DoeLog(0) && (eLog() << Verbose(0) << "There have been less triangles created than removed!" << endl);
     5050    }
     5051    delete (T); // remove the triangleset
     5052  }
     5053  IndexToIndex * SimplyDegeneratedTriangles = FindAllDegeneratedTriangles();
     5054  DoLog(0) && (Log() << Verbose(0) << "Final list of simply degenerated triangles found, containing " << SimplyDegeneratedTriangles->size() << " triangles:" << endl);
     5055  IndexToIndex::iterator it;
     5056  for (it = SimplyDegeneratedTriangles->begin(); it != SimplyDegeneratedTriangles->end(); it++)
     5057    DoLog(0) && (Log() << Verbose(0) << (*it).first << " => " << (*it).second << endl);
     5058  delete (SimplyDegeneratedTriangles);
     5059  /// 5. exit
     5060  UniquePolygonSet::iterator PolygonRunner;
     5061  while (!ListofDegeneratedPolygons.empty()) {
     5062    PolygonRunner = ListofDegeneratedPolygons.begin();
     5063    delete (*PolygonRunner);
     5064    ListofDegeneratedPolygons.erase(PolygonRunner);
     5065  }
     5066
     5067  return counter;
     5068}
     5069;
  • src/tesselation.hpp

    re5ad5c ree7e25  
    2323#include <list>
    2424#include <set>
     25#include <stack>
    2526
    2627#include "atom_particleinfo.hpp"
     
    4243#define DoTecplotOutput 1
    4344#define DoRaster3DOutput 1
    44 #define DoVRMLOutput 1
     45#define DoVRMLOutput 0
    4546#define TecplotSuffix ".dat"
    4647#define Raster3DSuffix ".r3d"
    4748#define VRMLSUffix ".wrl"
    4849
     50#define ParallelEpsilon 1e-3
     51
    4952// ======================================================= some template functions =========================================
    5053
     54#define IndexToIndex map <int, int>
     55
    5156#define PointMap map < int, class BoundaryPointSet * >
     57#define PointSet set < class BoundaryPointSet * >
     58#define PointList list < class BoundaryPointSet * >
    5259#define PointPair pair < int, class BoundaryPointSet * >
    5360#define PointTestPair pair < PointMap::iterator, bool >
     61
    5462#define CandidateList list <class CandidateForTesselation *>
     63#define CandidateMap map <class BoundaryLineSet *, class CandidateForTesselation *>
    5564
    5665#define LineMap multimap < int, class BoundaryLineSet * >
     66#define LineSet set < class BoundaryLineSet * >
     67#define LineList list < class BoundaryLineSet * >
    5768#define LinePair pair < int, class BoundaryLineSet * >
    5869#define LineTestPair pair < LineMap::iterator, bool >
    5970
    6071#define TriangleMap map < int, class BoundaryTriangleSet * >
     72#define TriangleSet set < class BoundaryTriangleSet * >
     73#define TriangleList list < class BoundaryTriangleSet * >
    6174#define TrianglePair pair < int, class BoundaryTriangleSet * >
    6275#define TriangleTestPair pair < TrianglePair::iterator, bool >
    6376
     77#define PolygonMap map < int, class BoundaryPolygonSet * >
     78#define PolygonSet set < class BoundaryPolygonSet * >
     79#define PolygonList list < class BoundaryPolygonSet * >
     80
     81#define DistanceToPointMap multimap <double, class BoundaryPointSet * >
     82#define DistanceToPointPair pair <double, class BoundaryPointSet * >
     83
    6484#define DistanceMultiMap multimap <double, pair < PointMap::iterator, PointMap::iterator> >
    6585#define DistanceMultiMapPair pair <double, pair < PointMap::iterator, PointMap::iterator> >
     86
     87#define TesselPointList list <TesselPoint *>
     88#define TesselPointSet set <TesselPoint *>
     89
     90#define ListOfTesselPointList list<list <TesselPoint *> *>
     91
     92enum centers {Opt, OtherOpt};
    6693
    6794/********************************************** declarations *******************************/
     
    83110  public:
    84111    BoundaryPointSet();
    85     BoundaryPointSet(TesselPoint * Walker);
     112    BoundaryPointSet(TesselPoint * const Walker);
    86113    ~BoundaryPointSet();
    87114
    88     void AddLine(class BoundaryLineSet *line);
     115    void AddLine(BoundaryLineSet * const line);
    89116
    90117    LineMap lines;
     
    102129  public:
    103130    BoundaryLineSet();
    104     BoundaryLineSet(class BoundaryPointSet *Point[2], const int number);
     131    BoundaryLineSet(BoundaryPointSet * const Point[2], const int number);
     132    BoundaryLineSet(BoundaryPointSet * const Point1, BoundaryPointSet * const Point2, const int number);
    105133    ~BoundaryLineSet();
    106134
    107     void AddTriangle(class BoundaryTriangleSet *triangle);
    108     bool IsConnectedTo(class BoundaryLineSet *line);
    109     bool ContainsBoundaryPoint(class BoundaryPointSet *point);
    110     bool CheckConvexityCriterion();
    111     class BoundaryPointSet *GetOtherEndpoint(class BoundaryPointSet *);
     135    void AddTriangle(BoundaryTriangleSet * const triangle);
     136    bool IsConnectedTo(const BoundaryLineSet * const line) const;
     137    bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
     138    bool CheckConvexityCriterion() const;
     139    class BoundaryPointSet *GetOtherEndpoint(const BoundaryPointSet * const point) const;
    112140
    113141    class BoundaryPointSet *endpoints[2];
    114142    TriangleMap triangles;
    115143    int Nr;
     144    bool skipped;
    116145};
    117146
     
    123152  public:
    124153    BoundaryTriangleSet();
    125     BoundaryTriangleSet(class BoundaryLineSet *line[3], int number);
     154    BoundaryTriangleSet(class BoundaryLineSet * const line[3], const int number);
    126155    ~BoundaryTriangleSet();
    127156
    128     void GetNormalVector(Vector &NormalVector);
    129     void GetCenter(Vector *center);
    130     bool GetIntersectionInsideTriangle(Vector *MolCenter, Vector *x, Vector *Intersection);
    131     bool ContainsBoundaryLine(class BoundaryLineSet *line);
    132     bool ContainsBoundaryPoint(class BoundaryPointSet *point);
    133     bool ContainsBoundaryPoint(class TesselPoint *point);
    134     class BoundaryPointSet *GetThirdEndpoint(class BoundaryLineSet *line);
    135     bool IsPresentTupel(class BoundaryPointSet *Points[3]);
    136     bool IsPresentTupel(class BoundaryTriangleSet *T);
     157    void GetNormalVector(const Vector &NormalVector);
     158    void GetCenter(Vector * const center) const;
     159    bool GetIntersectionInsideTriangle(const Vector * const MolCenter, const Vector * const x, Vector * const Intersection) const;
     160    double GetClosestPointInsideTriangle(const Vector * const x, Vector * const ClosestPoint) const;
     161    bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
     162    bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
     163    bool ContainsBoundaryPoint(const TesselPoint * const point) const;
     164    class BoundaryPointSet *GetThirdEndpoint(const BoundaryLineSet * const line) const;
     165    bool IsPresentTupel(const BoundaryPointSet * const Points[3]) const;
     166    bool IsPresentTupel(const BoundaryTriangleSet * const T) const;
    137167
    138168    class BoundaryPointSet *endpoints[3];
    139169    class BoundaryLineSet *lines[3];
    140170    Vector NormalVector;
     171    Vector SphereCenter;
    141172    int Nr;
    142173};
    143174
    144175ostream & operator << (ostream &ost, const BoundaryTriangleSet &a);
     176
     177
     178// ======================================================== class BoundaryTriangleSet =======================================
     179
     180/** Set of BoundaryPointSet.
     181 * This is just meant as a container for a group of endpoints, extending the node, line, triangle concept. However, this has
     182 * only marginally something to do with the tesselation. Hence, there is no incorporation into the bookkeeping of the Tesselation
     183 * class (i.e. no allocation, no deletion).
     184 * \note we assume that the set of endpoints reside (more or less) on a plane.
     185 */
     186class BoundaryPolygonSet {
     187  public:
     188    BoundaryPolygonSet();
     189    ~BoundaryPolygonSet();
     190
     191    Vector * GetNormalVector(const Vector &NormalVector) const;
     192    void GetCenter(Vector *center) const;
     193    bool ContainsBoundaryLine(const BoundaryLineSet * const line) const;
     194    bool ContainsBoundaryPoint(const BoundaryPointSet * const point) const;
     195    bool ContainsBoundaryPoint(const TesselPoint * const point) const;
     196    bool ContainsBoundaryTriangle(const BoundaryTriangleSet * const point) const;
     197    bool ContainsPresentTupel(const BoundaryPointSet * const * Points, const int dim) const;
     198    bool ContainsPresentTupel(const BoundaryPolygonSet * const P) const;
     199    bool ContainsPresentTupel(const PointSet &endpoints) const;
     200    TriangleSet * GetAllContainedTrianglesFromEndpoints() const;
     201    bool FillPolygonFromTrianglesOfLine(const BoundaryLineSet * const line);
     202
     203    PointSet endpoints;
     204    int Nr;
     205};
     206
     207ostream & operator << (ostream &ost, const BoundaryPolygonSet &a);
    145208
    146209// =========================================================== class TESSELPOINT ===========================================
     
    170233  virtual ~PointCloud();
    171234
     235  virtual const char * const GetName() const { return "unknown"; };
    172236  virtual Vector *GetCenter() const { return NULL; };
    173237  virtual TesselPoint *GetPoint() const { return NULL; };
    174238  virtual TesselPoint *GetTerminalPoint() const { return NULL; };
     239  virtual int GetMaxId() const { return 0; };
    175240  virtual void GoToNext() const {};
    176241  virtual void GoToPrevious() const {};
    177242  virtual void GoToFirst() const {};
    178243  virtual void GoToLast() const {};
    179   virtual bool IsEmpty() const { return false; };
    180   virtual bool IsEnd() const { return false; };
     244  virtual bool IsEmpty() const { return true; };
     245  virtual bool IsEnd() const { return true; };
    181246};
    182247
     
    185250class CandidateForTesselation {
    186251  public :
    187   CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
     252  CandidateForTesselation(BoundaryLineSet* currentBaseLine);
     253  CandidateForTesselation(TesselPoint* candidate, BoundaryLineSet* currentBaseLine, BoundaryPointSet *point, Vector OptCandidateCenter, Vector OtherOptCandidateCenter);
    188254  ~CandidateForTesselation();
    189255
    190   TesselPoint *point;
    191   BoundaryLineSet *BaseLine;
     256  bool CheckValidity(const double RADIUS, const LinkedCell *LC) const;
     257
     258  TesselPointList pointlist;
     259  const BoundaryLineSet * BaseLine;
     260  const BoundaryPointSet * ThirdPoint;
     261  const BoundaryTriangleSet *T;
     262  Vector OldCenter;
    192263  Vector OptCenter;
    193264  Vector OtherOptCenter;
    194 };
     265  double ShortestAngle;
     266  double OtherShortestAngle;
     267};
     268
     269ostream & operator <<(ostream &ost, const  CandidateForTesselation &a);
    195270
    196271// =========================================================== class TESSELATION ===========================================
     
    205280
    206281    void AddTesselationPoint(TesselPoint* Candidate, const int n);
    207     void AddTesselationLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
    208     void AlwaysAddTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
     282    void SetTesselationPoint(TesselPoint* Candidate, const int n) const;
     283    void AddTesselationLine(const Vector * const OptCenter, const BoundaryPointSet * const candidate, class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
     284    void AddNewTesselationTriangleLine(class BoundaryPointSet *a, class BoundaryPointSet *b, const int n);
     285    void AddExistingTesselationTriangleLine(class BoundaryLineSet *FindLine, int n);
    209286    void AddTesselationTriangle();
    210287    void AddTesselationTriangle(const int nr);
     288    void AddCandidateTriangle(CandidateForTesselation &CandidateLine, enum centers type);
     289    void AddDegeneratedTriangle(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC);
     290    void AddCandidatePolygon(CandidateForTesselation CandidateLine, const double RADIUS, const LinkedCell *LC);
    211291    void RemoveTesselationTriangle(class BoundaryTriangleSet *triangle);
    212292    void RemoveTesselationLine(class BoundaryLineSet *line);
    213293    void RemoveTesselationPoint(class BoundaryPointSet *point);
     294    bool CheckDegeneracy(CandidateForTesselation &CandidateLine, const double RADIUS, const LinkedCell *LC) const;
    214295
    215296
    216297    // concave envelope
    217     void FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
     298    bool FindStartingTriangle(const double RADIUS, const LinkedCell *LC);
    218299    void FindSecondPointForTesselation(class TesselPoint* a, Vector Oben, class TesselPoint*& OptCandidate, double Storage[3], double RADIUS, const LinkedCell *LC);
    219     void FindThirdPointForTesselation(Vector NormalVector, Vector SearchDirection, Vector OldSphereCenter, class BoundaryLineSet *BaseLine, class TesselPoint *ThirdNode, CandidateList* &candidates, double *ShortestAngle, const double RADIUS, const LinkedCell *LC);
    220     bool FindNextSuitableTriangle(BoundaryLineSet &Line, BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
    221     int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]);
     300    void FindThirdPointForTesselation(const Vector &NormalVector, const Vector &SearchDirection, const Vector &OldSphereCenter, CandidateForTesselation &CandidateLine, const class BoundaryPointSet  * const ThirdNode, const double RADIUS, const LinkedCell *LC) const;
     301    bool FindNextSuitableTriangle(CandidateForTesselation &CandidateLine, const BoundaryTriangleSet &T, const double& RADIUS, const LinkedCell *LC);
     302    bool FindCandidatesforOpenLines(const double RADIUS, const LinkedCell *&LCList);
     303    int CheckPresenceOfTriangle(class TesselPoint *Candidates[3]) const;
    222304    class BoundaryTriangleSet * GetPresentTriangle(TesselPoint *Candidates[3]);
    223305
     
    230312    double PickFarthestofTwoBaselines(class BoundaryLineSet *Base);
    231313    class BoundaryPointSet *IsConvexRectangle(class BoundaryLineSet *Base);
    232     map<int, int> * FindAllDegeneratedTriangles();
    233     map<int, int> * FindAllDegeneratedLines();
     314    IndexToIndex * FindAllDegeneratedTriangles();
     315    IndexToIndex * FindAllDegeneratedLines();
    234316    void RemoveDegeneratedTriangles();
    235317    void AddBoundaryPointByDegeneratedTriangle(class TesselPoint *point, LinkedCell *LC);
    236 
    237     set<TesselPoint*> * GetAllConnectedPoints(const TesselPoint* const Point) const;
    238     set<BoundaryTriangleSet*> *GetAllTriangles(const BoundaryPointSet * const Point) const;
    239     list<list<TesselPoint*> *> * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
    240     list<list<TesselPoint*> *> * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
    241     list<TesselPoint*> * GetCircleOfConnectedPoints(const TesselPoint* const Point, const Vector * const Reference = NULL) const;
    242     class BoundaryPointSet *GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
    243     list<BoundaryTriangleSet*> *FindTriangles(const TesselPoint* const Points[3]) const;
    244     list<BoundaryTriangleSet*> * FindClosestTrianglesToPoint(const Vector *x, const LinkedCell* LC) const;
    245     class BoundaryTriangleSet * FindClosestTriangleToPoint(const Vector *x, const LinkedCell* LC) const;
     318    int CorrectAllDegeneratedPolygons();
     319
     320    TesselPointSet * GetAllConnectedPoints(const TesselPoint* const Point) const;
     321    TriangleSet * GetAllTriangles(const BoundaryPointSet * const Point) const;
     322    ListOfTesselPointList * GetPathsOfConnectedPoints(const TesselPoint* const Point) const;
     323    ListOfTesselPointList * GetClosedPathsOfConnectedPoints(const TesselPoint* const Point) const;
     324    TesselPointList * GetCircleOfSetOfPoints(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference = NULL) const;
     325    TesselPointList * GetCircleOfConnectedTriangles(TesselPointSet *SetOfNeighbours, const TesselPoint* const Point, const Vector * const Reference) const;
     326    class BoundaryPointSet * GetCommonEndpoint(const BoundaryLineSet * line1, const BoundaryLineSet * line2) const;
     327    TriangleList * FindTriangles(const TesselPoint* const Points[3]) const;
     328    TriangleList * FindClosestTrianglesToVector(const Vector *x, const LinkedCell* LC) const;
     329    BoundaryTriangleSet * FindClosestTriangleToVector(const Vector *x, const LinkedCell* LC) const;
    246330    bool IsInnerPoint(const Vector &Point, const LinkedCell* const LC) const;
    247     bool IsInnerPoint(const TesselPoint * const Point, const LinkedCell* const LC) const;
     331    double GetDistanceSquaredToTriangle(const Vector &Point, const BoundaryTriangleSet* const triangle) const;
     332    double GetDistanceToSurface(const Vector &Point, const LinkedCell* const LC) const;
     333    BoundaryTriangleSet * GetClosestTriangleOnSurface(const Vector &Point, const LinkedCell* const LC) const;
    248334    bool AddBoundaryPoint(TesselPoint * Walker, const int n);
     335    DistanceToPointMap * FindClosestBoundaryPointsToVector(const Vector *x, const LinkedCell* LC) const;
     336    BoundaryLineSet * FindClosestBoundaryLineToVector(const Vector *x, const LinkedCell* LC) const;
    249337
    250338    // print for debugging
     
    258346    PointMap PointsOnBoundary;
    259347    LineMap LinesOnBoundary;
     348    CandidateMap OpenLines;
    260349    TriangleMap TrianglesOnBoundary;
    261350    int PointsOnBoundaryCount;
     
    281370
    282371  private:
    283     class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
     372    mutable class BoundaryPointSet *TPS[3]; //this is a Storage for pointers to triangle points, this and BPS[2] needed due to AddLine restrictions
    284373
    285374    mutable PointMap::const_iterator InternalPointer;
     375
     376    //bool HasOtherBaselineBetterCandidate(const BoundaryLineSet * const BaseRay, const TesselPoint * const OptCandidate, double ShortestAngle, double RADIUS, const LinkedCell * const LC) const;
     377    void FindDegeneratedCandidatesforOpenLines(TesselPoint * const Sprinter, const Vector * const OptCenter);
    286378};
    287379
  • src/tesselationhelpers.cpp

    re5ad5c ree7e25  
    88#include <fstream>
    99
     10#include "info.hpp"
    1011#include "linkedcell.hpp"
    1112#include "log.hpp"
     
    1516#include "verbose.hpp"
    1617
    17 double DetGet(gsl_matrix * const A, const int inPlace) {
     18double DetGet(gsl_matrix * const A, const int inPlace)
     19{
     20        Info FunctionInfo(__func__);
    1821  /*
    1922  inPlace = 1 => A is replaced with the LU decomposed copy.
     
    4548void GetSphere(Vector * const center, const Vector &a, const Vector &b, const Vector &c, const double RADIUS)
    4649{
     50        Info FunctionInfo(__func__);
    4751  gsl_matrix *A = gsl_matrix_calloc(3,3);
    4852  double m11, m12, m13, m14;
     
    7781
    7882  if (fabs(m11) < MYEPSILON)
    79     eLog() << Verbose(0) << "ERROR: three points are colinear." << endl;
     83    DoeLog(1) && (eLog()<< Verbose(1) << "three points are colinear." << endl);
    8084
    8185  center->x[0] =  0.5 * m12/ m11;
     
    8488
    8589  if (fabs(a.Distance(center) - RADIUS) > MYEPSILON)
    86     eLog() << Verbose(0) << "ERROR: The given center is further way by " << fabs(a.Distance(center) - RADIUS) << " from a than RADIUS." << endl;
     90    DoeLog(1) && (eLog()<< Verbose(1) << "The given center is further way by " << fabs(a.Distance(center) - RADIUS) << " from a than RADIUS." << endl);
    8791
    8892  gsl_matrix_free(A);
     
    111115    const double HalfplaneIndicator, const double AlternativeIndicator, const double alpha, const double beta, const double gamma, const double RADIUS, const double Umkreisradius)
    112116{
     117        Info FunctionInfo(__func__);
    113118  Vector TempNormal, helper;
    114119  double Restradius;
    115120  Vector OtherCenter;
    116   Log() << Verbose(3) << "Begin of GetCenterOfSphere.\n";
    117121  Center->Zero();
    118122  helper.CopyVector(&a);
     
    128132  Center->Scale(1./(sin(2.*alpha) + sin(2.*beta) + sin(2.*gamma)));
    129133  NewUmkreismittelpunkt->CopyVector(Center);
    130   Log() << Verbose(4) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n";
     134  DoLog(1) && (Log() << Verbose(1) << "Center of new circumference is " << *NewUmkreismittelpunkt << ".\n");
    131135  // Here we calculated center of circumscribing circle, using barycentric coordinates
    132   Log() << Verbose(4) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n";
     136  DoLog(1) && (Log() << Verbose(1) << "Center of circumference is " << *Center << " in direction " << *Direction << ".\n");
    133137
    134138  TempNormal.CopyVector(&a);
     
    139143  if (fabs(HalfplaneIndicator) < MYEPSILON)
    140144    {
    141       if ((TempNormal.ScalarProduct(AlternativeDirection) <0 and AlternativeIndicator >0) or (TempNormal.ScalarProduct(AlternativeDirection) >0 and AlternativeIndicator <0))
     145      if ((TempNormal.ScalarProduct(AlternativeDirection) <0 && AlternativeIndicator >0) || (TempNormal.ScalarProduct(AlternativeDirection) >0 && AlternativeIndicator <0))
    142146        {
    143147          TempNormal.Scale(-1);
     
    146150  else
    147151    {
    148       if (TempNormal.ScalarProduct(Direction)<0 && HalfplaneIndicator >0 || TempNormal.ScalarProduct(Direction)>0 && HalfplaneIndicator<0)
     152      if (((TempNormal.ScalarProduct(Direction)<0) && (HalfplaneIndicator >0)) || ((TempNormal.ScalarProduct(Direction)>0) && (HalfplaneIndicator<0)))
    149153        {
    150154          TempNormal.Scale(-1);
     
    154158  TempNormal.Normalize();
    155159  Restradius = sqrt(RADIUS*RADIUS - Umkreisradius*Umkreisradius);
    156   Log() << Verbose(4) << "Height of center of circumference to center of sphere is " << Restradius << ".\n";
     160  DoLog(1) && (Log() << Verbose(1) << "Height of center of circumference to center of sphere is " << Restradius << ".\n");
    157161  TempNormal.Scale(Restradius);
    158   Log() << Verbose(4) << "Shift vector to sphere of circumference is " << TempNormal << ".\n";
     162  DoLog(1) && (Log() << Verbose(1) << "Shift vector to sphere of circumference is " << TempNormal << ".\n");
    159163
    160164  Center->AddVector(&TempNormal);
    161   Log() << Verbose(0) << "Center of sphere of circumference is " << *Center << ".\n";
     165  DoLog(1) && (Log() << Verbose(1) << "Center of sphere of circumference is " << *Center << ".\n");
    162166  GetSphere(&OtherCenter, a, b, c, RADIUS);
    163   Log() << Verbose(0) << "OtherCenter of sphere of circumference is " << OtherCenter << ".\n";
    164   Log() << Verbose(3) << "End of GetCenterOfSphere.\n";
     167  DoLog(1) && (Log() << Verbose(1) << "OtherCenter of sphere of circumference is " << OtherCenter << ".\n");
    165168};
    166169
     
    174177void GetCenterofCircumcircle(Vector * const Center, const Vector &a, const Vector &b, const Vector &c)
    175178{
     179        Info FunctionInfo(__func__);
    176180  Vector helper;
    177181  double alpha, beta, gamma;
     
    186190  beta = M_PI - SideC.Angle(&SideA);
    187191  gamma = M_PI - SideA.Angle(&SideB);
    188   //Log() << Verbose(3) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;
    189   if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON)
    190     eLog() << Verbose(0) << "GetCenterofCircumcircle: Sum of angles " << (alpha+beta+gamma)/M_PI*180. << " > 180 degrees by " << fabs(M_PI - alpha - beta - gamma)/M_PI*180. << "!" << endl;
     192  //Log() << Verbose(1) << "INFO: alpha = " << alpha/M_PI*180. << ", beta = " << beta/M_PI*180. << ", gamma = " << gamma/M_PI*180. << "." << endl;
     193  if (fabs(M_PI - alpha - beta - gamma) > HULLEPSILON) {
     194    DoeLog(2) && (eLog()<< Verbose(2) << "GetCenterofCircumcircle: Sum of angles " << (alpha+beta+gamma)/M_PI*180. << " > 180 degrees by " << fabs(M_PI - alpha - beta - gamma)/M_PI*180. << "!" << endl);
     195  }
    191196
    192197  Center->Zero();
     
    218223double GetPathLengthonCircumCircle(const Vector &CircleCenter, const Vector &CirclePlaneNormal, const double CircleRadius, const Vector &NewSphereCenter, const Vector &OldSphereCenter, const Vector &NormalVector, const Vector &SearchDirection)
    219224{
     225        Info FunctionInfo(__func__);
    220226  Vector helper;
    221227  double radius, alpha;
    222 
    223   helper.CopyVector(&NewSphereCenter);
     228  Vector RelativeOldSphereCenter;
     229  Vector RelativeNewSphereCenter;
     230
     231  RelativeOldSphereCenter.CopyVector(&OldSphereCenter);
     232  RelativeOldSphereCenter.SubtractVector(&CircleCenter);
     233  RelativeNewSphereCenter.CopyVector(&NewSphereCenter);
     234  RelativeNewSphereCenter.SubtractVector(&CircleCenter);
     235  helper.CopyVector(&RelativeNewSphereCenter);
    224236  // test whether new center is on the parameter circle's plane
    225237  if (fabs(helper.ScalarProduct(&CirclePlaneNormal)) > HULLEPSILON) {
    226     eLog() << Verbose(0) << "ERROR: Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct(&CirclePlaneNormal))  << "!" << endl;
     238    DoeLog(1) && (eLog()<< Verbose(1) << "Something's very wrong here: NewSphereCenter is not on the band's plane as desired by " <<fabs(helper.ScalarProduct(&CirclePlaneNormal))  << "!" << endl);
    227239    helper.ProjectOntoPlane(&CirclePlaneNormal);
    228240  }
    229   radius = helper.ScalarProduct(&helper);
     241  radius = helper.NormSquared();
    230242  // test whether the new center vector has length of CircleRadius
    231243  if (fabs(radius - CircleRadius) > HULLEPSILON)
    232     eLog() << Verbose(1) << "ERROR: The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl;
    233   alpha = helper.Angle(&OldSphereCenter);
     244    DoeLog(1) && (eLog()<< Verbose(1) << "The projected center of the new sphere has radius " << radius << " instead of " << CircleRadius << "." << endl);
     245  alpha = helper.Angle(&RelativeOldSphereCenter);
    234246  // make the angle unique by checking the halfplanes/search direction
    235247  if (helper.ScalarProduct(&SearchDirection) < -HULLEPSILON)  // acos is not unique on [0, 2.*M_PI), hence extra check to decide between two half intervals
    236248    alpha = 2.*M_PI - alpha;
    237   //Log() << Verbose(2) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << OldSphereCenter << " and resulting angle is " << alpha << "." << endl;
    238   radius = helper.Distance(&OldSphereCenter);
     249  DoLog(1) && (Log() << Verbose(1) << "INFO: RelativeNewSphereCenter is " << helper << ", RelativeOldSphereCenter is " << RelativeOldSphereCenter << " and resulting angle is " << alpha << "." << endl);
     250  radius = helper.Distance(&RelativeOldSphereCenter);
    239251  helper.ProjectOntoPlane(&NormalVector);
    240252  // check whether new center is somewhat away or at least right over the current baseline to prevent intersecting triangles
    241253  if ((radius > HULLEPSILON) || (helper.Norm() < HULLEPSILON)) {
    242     //Log() << Verbose(2) << "INFO: Distance between old and new center is " << radius << " and between new center and baseline center is " << helper.Norm() << "." << endl;
     254    DoLog(1) && (Log() << Verbose(1) << "INFO: Distance between old and new center is " << radius << " and between new center and baseline center is " << helper.Norm() << "." << endl);
    243255    return alpha;
    244256  } else {
    245     //Log() << Verbose(1) << "INFO: NewSphereCenter " << helper << " is too close to OldSphereCenter" << OldSphereCenter << "." << endl;
     257    DoLog(1) && (Log() << Verbose(1) << "INFO: NewSphereCenter " << RelativeNewSphereCenter << " is too close to RelativeOldSphereCenter" << RelativeOldSphereCenter << "." << endl);
    246258    return 2.*M_PI;
    247259  }
     
    263275double MinIntersectDistance(const gsl_vector * x, void *params)
    264276{
     277        Info FunctionInfo(__func__);
    265278  double retval = 0;
    266279  struct Intersection *I = (struct Intersection *)params;
     
    283296
    284297  retval = HeightA.ScalarProduct(&HeightA) + HeightB.ScalarProduct(&HeightB);
    285   //Log() << Verbose(2) << "MinIntersectDistance called, result: " << retval << endl;
     298  //Log() << Verbose(1) << "MinIntersectDistance called, result: " << retval << endl;
    286299
    287300  return retval;
     
    303316bool existsIntersection(const Vector &point1, const Vector &point2, const Vector &point3, const Vector &point4)
    304317{
     318        Info FunctionInfo(__func__);
    305319  bool result;
    306320
     
    350364
    351365        if (status == GSL_SUCCESS) {
    352           Log() << Verbose(2) << "converged to minimum" <<  endl;
     366          DoLog(1) && (Log() << Verbose(1) << "converged to minimum" <<  endl);
    353367        }
    354368    } while (status == GSL_CONTINUE && iter < 100);
     
    375389  t2 = HeightB.ScalarProduct(&SideB)/SideB.ScalarProduct(&SideB);
    376390
    377   Log() << Verbose(2) << "Intersection " << intersection << " is at "
     391  Log() << Verbose(1) << "Intersection " << intersection << " is at "
    378392    << t1 << " for (" << point1 << "," << point2 << ") and at "
    379393    << t2 << " for (" << point3 << "," << point4 << "): ";
    380394
    381395  if (((t1 >= 0) && (t1 <= 1)) && ((t2 >= 0) && (t2 <= 1))) {
    382     Log() << Verbose(0) << "true intersection." << endl;
     396    DoLog(1) && (Log() << Verbose(1) << "true intersection." << endl);
    383397    result = true;
    384398  } else {
    385     Log() << Verbose(0) << "intersection out of region of interest." << endl;
     399    DoLog(1) && (Log() << Verbose(1) << "intersection out of region of interest." << endl);
    386400    result = false;
    387401  }
     
    406420double GetAngle(const Vector &point, const Vector &reference, const Vector &OrthogonalVector)
    407421{
     422        Info FunctionInfo(__func__);
    408423  if (reference.IsZero())
    409424    return M_PI;
     
    417432  }
    418433
    419   Log() << Verbose(4) << "INFO: " << point << " has angle " << phi << " with respect to reference " << reference << "." << endl;
     434  DoLog(1) && (Log() << Verbose(1) << "INFO: " << point << " has angle " << phi << " with respect to reference " << reference << "." << endl);
    420435
    421436  return phi;
     
    432447double CalculateVolumeofGeneralTetraeder(const Vector &a, const Vector &b, const Vector &c, const Vector &d)
    433448{
     449        Info FunctionInfo(__func__);
    434450  Vector Point, TetraederVector[3];
    435451  double volume;
     
    455471bool CheckLineCriteriaForDegeneratedTriangle(const BoundaryPointSet * const nodes[3])
    456472{
     473        Info FunctionInfo(__func__);
    457474  bool result = false;
    458475  int counter = 0;
     
    461478  for (int i=0;i<3;i++)
    462479    for (int j=i+1; j<3; j++) {
    463       if (nodes[i]->lines.find(nodes[j]->node->nr) != nodes[i]->lines.end()) {  // there already is a line
     480      if (nodes[i] == NULL) {
     481        DoLog(1) && (Log() << Verbose(1) << "Node nr. " << i << " is not yet present." << endl);
     482        result = true;
     483      } else if (nodes[i]->lines.find(nodes[j]->node->nr) != nodes[i]->lines.end()) {  // there already is a line
    464484        LineMap::const_iterator FindLine;
    465485        pair<LineMap::const_iterator,LineMap::const_iterator> FindPair;
     
    473493        }
    474494      } else { // no line
    475         Log() << Verbose(1) << "The line between " << *nodes[i] << " and " << *nodes[j] << " is not yet present, hence no need for a degenerate triangle." << endl;
     495        DoLog(1) && (Log() << Verbose(1) << "The line between " << *nodes[i] << " and " << *nodes[j] << " is not yet present, hence no need for a degenerate triangle." << endl);
    476496        result = true;
    477497      }
    478498    }
    479499  if ((!result) && (counter > 1)) {
    480     Log() << Verbose(2) << "INFO: Degenerate triangle is ok, at least two, here " << counter << ", existing lines are used." << endl;
     500    DoLog(1) && (Log() << Verbose(1) << "INFO: Degenerate triangle is ok, at least two, here " << counter << ", existing lines are used." << endl);
    481501    result = true;
    482502  }
     
    485505
    486506
    487 /** Sort function for the candidate list.
    488  */
    489 bool SortCandidates(const CandidateForTesselation* candidate1, const CandidateForTesselation* candidate2)
    490 {
    491   Vector BaseLineVector, OrthogonalVector, helper;
    492   if (candidate1->BaseLine != candidate2->BaseLine) {  // sanity check
    493     Log() << Verbose(0) << "ERROR: sortCandidates was called for two different baselines: " << candidate1->BaseLine << " and " << candidate2->BaseLine << "." << endl;
    494     //return false;
    495     exit(1);
    496   }
    497   // create baseline vector
    498   BaseLineVector.CopyVector(candidate1->BaseLine->endpoints[1]->node->node);
    499   BaseLineVector.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
    500   BaseLineVector.Normalize();
    501 
    502   // create normal in-plane vector to cope with acos() non-uniqueness on [0,2pi] (note that is pointing in the "right" direction already, hence ">0" test!)
    503   helper.CopyVector(candidate1->BaseLine->endpoints[0]->node->node);
    504   helper.SubtractVector(candidate1->point->node);
    505   OrthogonalVector.CopyVector(&helper);
    506   helper.VectorProduct(&BaseLineVector);
    507   OrthogonalVector.SubtractVector(&helper);
    508   OrthogonalVector.Normalize();
    509 
    510   // calculate both angles and correct with in-plane vector
    511   helper.CopyVector(candidate1->point->node);
    512   helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
    513   double phi = BaseLineVector.Angle(&helper);
    514   if (OrthogonalVector.ScalarProduct(&helper) > 0) {
    515     phi = 2.*M_PI - phi;
    516   }
    517   helper.CopyVector(candidate2->point->node);
    518   helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
    519   double psi = BaseLineVector.Angle(&helper);
    520   if (OrthogonalVector.ScalarProduct(&helper) > 0) {
    521     psi = 2.*M_PI - psi;
    522   }
    523 
    524   Log() << Verbose(2) << *candidate1->point << " has angle " << phi << endl;
    525   Log() << Verbose(2) << *candidate2->point << " has angle " << psi << endl;
    526 
    527   // return comparison
    528   return phi < psi;
    529 };
     507///** Sort function for the candidate list.
     508// */
     509//bool SortCandidates(const CandidateForTesselation* candidate1, const CandidateForTesselation* candidate2)
     510//{
     511//      Info FunctionInfo(__func__);
     512//  Vector BaseLineVector, OrthogonalVector, helper;
     513//  if (candidate1->BaseLine != candidate2->BaseLine) {  // sanity check
     514//    DoeLog(1) && (eLog()<< Verbose(1) << "sortCandidates was called for two different baselines: " << candidate1->BaseLine << " and " << candidate2->BaseLine << "." << endl);
     515//    //return false;
     516//    exit(1);
     517//  }
     518//  // create baseline vector
     519//  BaseLineVector.CopyVector(candidate1->BaseLine->endpoints[1]->node->node);
     520//  BaseLineVector.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
     521//  BaseLineVector.Normalize();
     522//
     523//  // create normal in-plane vector to cope with acos() non-uniqueness on [0,2pi] (note that is pointing in the "right" direction already, hence ">0" test!)
     524//  helper.CopyVector(candidate1->BaseLine->endpoints[0]->node->node);
     525//  helper.SubtractVector(candidate1->point->node);
     526//  OrthogonalVector.CopyVector(&helper);
     527//  helper.VectorProduct(&BaseLineVector);
     528//  OrthogonalVector.SubtractVector(&helper);
     529//  OrthogonalVector.Normalize();
     530//
     531//  // calculate both angles and correct with in-plane vector
     532//  helper.CopyVector(candidate1->point->node);
     533//  helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
     534//  double phi = BaseLineVector.Angle(&helper);
     535//  if (OrthogonalVector.ScalarProduct(&helper) > 0) {
     536//    phi = 2.*M_PI - phi;
     537//  }
     538//  helper.CopyVector(candidate2->point->node);
     539//  helper.SubtractVector(candidate1->BaseLine->endpoints[0]->node->node);
     540//  double psi = BaseLineVector.Angle(&helper);
     541//  if (OrthogonalVector.ScalarProduct(&helper) > 0) {
     542//    psi = 2.*M_PI - psi;
     543//  }
     544//
     545//  Log() << Verbose(1) << *candidate1->point << " has angle " << phi << endl;
     546//  Log() << Verbose(1) << *candidate2->point << " has angle " << psi << endl;
     547//
     548//  // return comparison
     549//  return phi < psi;
     550//};
    530551
    531552/**
     
    537558 * @return point which is second closest to the provided one
    538559 */
    539 TesselPoint* FindSecondClosestPoint(const Vector* Point, const LinkedCell* const LC)
    540 {
     560TesselPoint* FindSecondClosestTesselPoint(const Vector* Point, const LinkedCell* const LC)
     561{
     562        Info FunctionInfo(__func__);
    541563  TesselPoint* closestPoint = NULL;
    542564  TesselPoint* secondClosestPoint = NULL;
     
    549571  for(int i=0;i<NDIM;i++) // store indices of this cell
    550572    N[i] = LC->n[i];
    551   Log() << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     573  DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
    552574
    553575  LC->GetNeighbourBounds(Nlower, Nupper);
    554   //Log() << Verbose(0) << endl;
     576  //Log() << Verbose(1) << endl;
    555577  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    556578    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    557579      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    558         const LinkedNodes *List = LC->GetCurrentCell();
    559         //Log() << Verbose(3) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
     580        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
     581        //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    560582        if (List != NULL) {
    561           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     583          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    562584            helper.CopyVector(Point);
    563585            helper.SubtractVector((*Runner)->node);
     
    574596          }
    575597        } else {
    576           eLog() << Verbose(0) << "ERROR: The current cell " << LC->n[0] << "," << LC->n[1] << ","
     598          eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << ","
    577599            << LC->n[2] << " is invalid!" << endl;
    578600        }
     
    591613 * @return point which is closest to the provided one, NULL if none found
    592614 */
    593 TesselPoint* FindClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC)
    594 {
     615TesselPoint* FindClosestTesselPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC)
     616{
     617        Info FunctionInfo(__func__);
    595618  TesselPoint* closestPoint = NULL;
    596619  SecondPoint = NULL;
     
    603626  for(int i=0;i<NDIM;i++) // store indices of this cell
    604627    N[i] = LC->n[i];
    605   Log() << Verbose(3) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     628  DoLog(1) && (Log() << Verbose(1) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl);
    606629
    607630  LC->GetNeighbourBounds(Nlower, Nupper);
    608   //Log() << Verbose(0) << endl;
     631  //Log() << Verbose(1) << endl;
    609632  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
    610633    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
    611634      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
    612         const LinkedNodes *List = LC->GetCurrentCell();
    613         //Log() << Verbose(3) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
     635        const LinkedCell::LinkedNodes *List = LC->GetCurrentCell();
     636        //Log() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
    614637        if (List != NULL) {
    615           for (LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     638          for (LinkedCell::LinkedNodes::const_iterator Runner = List->begin(); Runner != List->end(); Runner++) {
    616639            helper.CopyVector(Point);
    617640            helper.SubtractVector((*Runner)->node);
    618             double currentNorm = helper. Norm();
     641            double currentNorm = helper.NormSquared();
    619642            if (currentNorm < distance) {
    620643              secondDistance = distance;
     
    622645              distance = currentNorm;
    623646              closestPoint = (*Runner);
    624               //Log() << Verbose(2) << "INFO: New Nearest Neighbour is " << *closestPoint << "." << endl;
     647              //Log() << Verbose(1) << "INFO: New Nearest Neighbour is " << *closestPoint << "." << endl;
    625648            } else if (currentNorm < secondDistance) {
    626649              secondDistance = currentNorm;
    627650              SecondPoint = (*Runner);
    628               //Log() << Verbose(2) << "INFO: New Second Nearest Neighbour is " << *SecondPoint << "." << endl;
     651              //Log() << Verbose(1) << "INFO: New Second Nearest Neighbour is " << *SecondPoint << "." << endl;
    629652            }
    630653          }
    631654        } else {
    632           eLog() << Verbose(0) << "ERROR: The current cell " << LC->n[0] << "," << LC->n[1] << ","
     655          eLog() << Verbose(1) << "The current cell " << LC->n[0] << "," << LC->n[1] << ","
    633656            << LC->n[2] << " is invalid!" << endl;
    634657        }
     
    636659  // output
    637660  if (closestPoint != NULL) {
    638     Log() << Verbose(2) << "Closest point is " << *closestPoint;
     661    DoLog(1) && (Log() << Verbose(1) << "Closest point is " << *closestPoint);
    639662    if (SecondPoint != NULL)
    640       Log() << Verbose(0) << " and second closest is " << *SecondPoint;
    641     Log() << Verbose(0) << "." << endl;
     663      DoLog(0) && (Log() << Verbose(0) << " and second closest is " << *SecondPoint);
     664    DoLog(0) && (Log() << Verbose(0) << "." << endl);
    642665  }
    643666  return closestPoint;
     
    652675Vector * GetClosestPointBetweenLine(const BoundaryLineSet * const Base, const BoundaryLineSet * const OtherBase)
    653676{
     677        Info FunctionInfo(__func__);
    654678  // construct the plane of the two baselines (i.e. take both their directional vectors)
    655679  Vector Normal;
     
    662686  Normal.VectorProduct(&OtherBaseline);
    663687  Normal.Normalize();
    664   Log() << Verbose(4) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl;
     688  DoLog(1) && (Log() << Verbose(1) << "First direction is " << Baseline << ", second direction is " << OtherBaseline << ", normal of intersection plane is " << Normal << "." << endl);
    665689
    666690  // project one offset point of OtherBase onto this plane (and add plane offset vector)
     
    679703  Normal.CopyVector(Intersection);
    680704  Normal.SubtractVector(Base->endpoints[0]->node->node);
    681   Log() << Verbose(3) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl;
     705  DoLog(1) && (Log() << Verbose(1) << "Found closest point on " << *Base << " at " << *Intersection << ", factor in line is " << fabs(Normal.ScalarProduct(&Baseline)/Baseline.NormSquared()) << "." << endl);
    682706
    683707  return Intersection;
     
    692716double DistanceToTrianglePlane(const Vector *x, const BoundaryTriangleSet * const triangle)
    693717{
     718        Info FunctionInfo(__func__);
    694719  double distance = 0.;
    695720  if (x == NULL) {
     
    708733void WriteVrmlFile(ofstream * const vrmlfile, const Tesselation * const Tess, const PointCloud * const cloud)
    709734{
     735        Info FunctionInfo(__func__);
    710736  TesselPoint *Walker = NULL;
    711737  int i;
     
    738764    }
    739765  } else {
    740     eLog() << Verbose(0) << "ERROR: Given vrmlfile is " << vrmlfile << "." << endl;
     766    DoeLog(1) && (eLog()<< Verbose(1) << "Given vrmlfile is " << vrmlfile << "." << endl);
    741767  }
    742768  delete(center);
     
    751777void IncludeSphereinRaster3D(ofstream * const rasterfile, const Tesselation * const Tess, const PointCloud * const cloud)
    752778{
     779        Info FunctionInfo(__func__);
    753780  Vector helper;
    754   // include the current position of the virtual sphere in the temporary raster3d file
    755   Vector *center = cloud->GetCenter();
    756   // make the circumsphere's center absolute again
    757   helper.CopyVector(Tess->LastTriangle->endpoints[0]->node->node);
    758   helper.AddVector(Tess->LastTriangle->endpoints[1]->node->node);
    759   helper.AddVector(Tess->LastTriangle->endpoints[2]->node->node);
    760   helper.Scale(1./3.);
    761   helper.SubtractVector(center);
    762   // and add to file plus translucency object
    763   *rasterfile << "# current virtual sphere\n";
    764   *rasterfile << "8\n  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0\n";
    765   *rasterfile << "2\n  " << helper.x[0] << " " << helper.x[1] << " " << helper.x[2] << "\t" << 5. << "\t1 0 0\n";
    766   *rasterfile << "9\n  terminating special property\n";
    767   delete(center);
     781
     782  if (Tess->LastTriangle != NULL) {
     783    // include the current position of the virtual sphere in the temporary raster3d file
     784    Vector *center = cloud->GetCenter();
     785    // make the circumsphere's center absolute again
     786    helper.CopyVector(Tess->LastTriangle->endpoints[0]->node->node);
     787    helper.AddVector(Tess->LastTriangle->endpoints[1]->node->node);
     788    helper.AddVector(Tess->LastTriangle->endpoints[2]->node->node);
     789    helper.Scale(1./3.);
     790    helper.SubtractVector(center);
     791    // and add to file plus translucency object
     792    *rasterfile << "# current virtual sphere\n";
     793    *rasterfile << "8\n  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0\n";
     794    *rasterfile << "2\n  " << helper.x[0] << " " << helper.x[1] << " " << helper.x[2] << "\t" << 5. << "\t1 0 0\n";
     795    *rasterfile << "9\n  terminating special property\n";
     796    delete(center);
     797  }
    768798};
    769799
     
    776806void WriteRaster3dFile(ofstream * const rasterfile, const Tesselation * const Tess, const PointCloud * const cloud)
    777807{
     808        Info FunctionInfo(__func__);
    778809  TesselPoint *Walker = NULL;
    779810  int i;
     
    808839    *rasterfile << "9\n#  terminating special property\n";
    809840  } else {
    810     eLog() << Verbose(0) << "ERROR: Given rasterfile is " << rasterfile << "." << endl;
     841    DoeLog(1) && (eLog()<< Verbose(1) << "Given rasterfile is " << rasterfile << "." << endl);
    811842  }
    812843  IncludeSphereinRaster3D(rasterfile, Tess, cloud);
     
    821852void WriteTecplotFile(ofstream * const tecplot, const Tesselation * const TesselStruct, const PointCloud * const cloud, const int N)
    822853{
     854        Info FunctionInfo(__func__);
    823855  if ((tecplot != NULL) && (TesselStruct != NULL)) {
    824856    // write header
    825857    *tecplot << "TITLE = \"3D CONVEX SHELL\"" << endl;
    826858    *tecplot << "VARIABLES = \"X\" \"Y\" \"Z\" \"U\"" << endl;
    827     *tecplot << "ZONE T=\"" << N << "-";
    828     for (int i=0;i<3;i++)
    829       *tecplot << (i==0 ? "" : "_") << TesselStruct->LastTriangle->endpoints[i]->node->Name;
     859    *tecplot << "ZONE T=\"";
     860    if (N < 0) {
     861      *tecplot << cloud->GetName();
     862    } else {
     863      *tecplot << N << "-";
     864      if (TesselStruct->LastTriangle != NULL) {
     865        for (int i=0;i<3;i++)
     866          *tecplot << (i==0 ? "" : "_") << TesselStruct->LastTriangle->endpoints[i]->node->Name;
     867      } else {
     868        *tecplot << "none";
     869      }
     870    }
    830871    *tecplot << "\", N=" << TesselStruct->PointsOnBoundary.size() << ", E=" << TesselStruct->TrianglesOnBoundary.size() << ", DATAPACKING=POINT, ZONETYPE=FETRIANGLE" << endl;
    831     int i=0;
    832     for (cloud->GoToFirst(); !cloud->IsEnd(); cloud->GoToNext(), i++);
     872    int i=cloud->GetMaxId();
    833873    int *LookupList = new int[i];
    834874    for (cloud->GoToFirst(), i=0; !cloud->IsEnd(); cloud->GoToNext(), i++)
     
    836876
    837877    // print atom coordinates
    838     Log() << Verbose(2) << "The following triangles were created:";
    839878    int Counter = 1;
    840879    TesselPoint *Walker = NULL;
     
    846885    *tecplot << endl;
    847886    // print connectivity
     887    DoLog(1) && (Log() << Verbose(1) << "The following triangles were created:" << endl);
    848888    for (TriangleMap::const_iterator runner = TesselStruct->TrianglesOnBoundary.begin(); runner != TesselStruct->TrianglesOnBoundary.end(); runner++) {
    849       Log() << Verbose(0) << " " << runner->second->endpoints[0]->node->Name << "<->" << runner->second->endpoints[1]->node->Name << "<->" << runner->second->endpoints[2]->node->Name;
     889      DoLog(1) && (Log() << Verbose(1) << " " << runner->second->endpoints[0]->node->Name << "<->" << runner->second->endpoints[1]->node->Name << "<->" << runner->second->endpoints[2]->node->Name << endl);
    850890      *tecplot << LookupList[runner->second->endpoints[0]->node->nr] << " " << LookupList[runner->second->endpoints[1]->node->nr] << " " << LookupList[runner->second->endpoints[2]->node->nr] << endl;
    851891    }
    852892    delete[] (LookupList);
    853     Log() << Verbose(0) << endl;
    854893  }
    855894};
     
    862901void CalculateConcavityPerBoundaryPoint(const Tesselation * const TesselStruct)
    863902{
     903        Info FunctionInfo(__func__);
    864904  class BoundaryPointSet *point = NULL;
    865905  class BoundaryLineSet *line = NULL;
    866906
    867   //Log() << Verbose(2) << "Begin of CalculateConcavityPerBoundaryPoint" << endl;
    868907  // calculate remaining concavity
    869908  for (PointMap::const_iterator PointRunner = TesselStruct->PointsOnBoundary.begin(); PointRunner != TesselStruct->PointsOnBoundary.end(); PointRunner++) {
    870909    point = PointRunner->second;
    871     Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl;
     910    DoLog(1) && (Log() << Verbose(1) << "INFO: Current point is " << *point << "." << endl);
    872911    point->value = 0;
    873912    for (LineMap::iterator LineRunner = point->lines.begin(); LineRunner != point->lines.end(); LineRunner++) {
    874913      line = LineRunner->second;
    875       //Log() << Verbose(2) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
     914      //Log() << Verbose(1) << "INFO: Current line of point " << *point << " is " << *line << "." << endl;
    876915      if (!line->CheckConvexityCriterion())
    877916        point->value += 1;
    878917    }
    879918  }
    880   //Log() << Verbose(2) << "End of CalculateConcavityPerBoundaryPoint" << endl;
    881919};
    882920
     
    889927bool CheckListOfBaselines(const Tesselation * const TesselStruct)
    890928{
     929        Info FunctionInfo(__func__);
    891930  LineMap::const_iterator testline;
    892931  bool result = false;
    893932  int counter = 0;
    894933
    895   Log() << Verbose(1) << "Check: List of Baselines with not two connected triangles:" << endl;
     934  DoLog(1) && (Log() << Verbose(1) << "Check: List of Baselines with not two connected triangles:" << endl);
    896935  for (testline = TesselStruct->LinesOnBoundary.begin(); testline != TesselStruct->LinesOnBoundary.end(); testline++) {
    897936    if (testline->second->triangles.size() != 2) {
    898       Log() << Verbose(1) << *testline->second << "\t" << testline->second->triangles.size() << endl;
     937      DoLog(2) && (Log() << Verbose(2) << *testline->second << "\t" << testline->second->triangles.size() << endl);
    899938      counter++;
    900939    }
    901940  }
    902941  if (counter == 0) {
    903     Log() << Verbose(1) << "None." << endl;
     942    DoLog(1) && (Log() << Verbose(1) << "None." << endl);
    904943    result = true;
    905944  }
     
    907946}
    908947
     948/** Counts the number of triangle pairs that contain the given polygon.
     949 * \param *P polygon with endpoints to look for
     950 * \param *T set of triangles to create pairs from containing \a *P
     951 */
     952int CountTrianglePairContainingPolygon(const BoundaryPolygonSet * const P, const TriangleSet * const T)
     953{
     954  Info FunctionInfo(__func__);
     955  // check number of endpoints in *P
     956  if (P->endpoints.size() != 4) {
     957    DoeLog(1) && (eLog()<< Verbose(1) << "CountTrianglePairContainingPolygon works only on polygons with 4 nodes!" << endl);
     958    return 0;
     959  }
     960
     961  // check number of triangles in *T
     962  if (T->size() < 2) {
     963    DoeLog(1) && (eLog()<< Verbose(1) << "Not enough triangles to have pairs!" << endl);
     964    return 0;
     965  }
     966
     967  DoLog(0) && (Log() << Verbose(0) << "Polygon is " << *P << endl);
     968  // create each pair, get the endpoints and check whether *P is contained.
     969  int counter = 0;
     970  PointSet Trianglenodes;
     971  class BoundaryPolygonSet PairTrianglenodes;
     972  for(TriangleSet::iterator Walker = T->begin(); Walker != T->end(); Walker++) {
     973    for (int i=0;i<3;i++)
     974      Trianglenodes.insert((*Walker)->endpoints[i]);
     975
     976    for(TriangleSet::iterator PairWalker = Walker; PairWalker != T->end(); PairWalker++) {
     977      if (Walker != PairWalker) { // skip first
     978        PairTrianglenodes.endpoints = Trianglenodes;
     979        for (int i=0;i<3;i++)
     980          PairTrianglenodes.endpoints.insert((*PairWalker)->endpoints[i]);
     981        const int size = PairTrianglenodes.endpoints.size();
     982        if (size == 4) {
     983          DoLog(0) && (Log() << Verbose(0) << " Current pair of triangles: " << **Walker << "," << **PairWalker << " with " << size << " distinct endpoints:" << PairTrianglenodes << endl);
     984          // now check
     985          if (PairTrianglenodes.ContainsPresentTupel(P)) {
     986            counter++;
     987            DoLog(0) && (Log() << Verbose(0) << "  ACCEPT: Matches with " << *P << endl);
     988          } else {
     989            DoLog(0) && (Log() << Verbose(0) << "  REJECT: No match with " << *P << endl);
     990          }
     991        } else {
     992          DoLog(0) && (Log() << Verbose(0) << "  REJECT: Less than four endpoints." << endl);
     993        }
     994      }
     995    }
     996    Trianglenodes.clear();
     997  }
     998  return counter;
     999};
     1000
     1001/** Checks whether two give polygons have two or more points in common.
     1002 * \param *P1 first polygon
     1003 * \param *P2 second polygon
     1004 * \return true - are connected, false = are note
     1005 */
     1006bool ArePolygonsEdgeConnected(const BoundaryPolygonSet * const P1, const BoundaryPolygonSet * const P2)
     1007{
     1008  Info FunctionInfo(__func__);
     1009  int counter = 0;
     1010  for(PointSet::const_iterator Runner = P1->endpoints.begin(); Runner != P1->endpoints.end(); Runner++) {
     1011    if (P2->ContainsBoundaryPoint((*Runner))) {
     1012      counter++;
     1013      DoLog(1) && (Log() << Verbose(1) << *(*Runner) << " of second polygon is found in the first one." << endl);
     1014      return true;
     1015    }
     1016  }
     1017  return false;
     1018};
     1019
     1020/** Combines second into the first and deletes the second.
     1021 * \param *P1 first polygon, contains all nodes on return
     1022 * \param *&P2 second polygon, is deleted.
     1023 */
     1024void CombinePolygons(BoundaryPolygonSet * const P1, BoundaryPolygonSet * &P2)
     1025{
     1026  Info FunctionInfo(__func__);
     1027  pair <PointSet::iterator, bool> Tester;
     1028  for(PointSet::iterator Runner = P2->endpoints.begin(); Runner != P2->endpoints.end(); Runner++) {
     1029    Tester = P1->endpoints.insert((*Runner));
     1030    if (Tester.second)
     1031      DoLog(0) && (Log() << Verbose(0) << "Inserting endpoint " << *(*Runner) << " into first polygon." << endl);
     1032  }
     1033  P2->endpoints.clear();
     1034  delete(P2);
     1035};
     1036
  • src/tesselationhelpers.hpp

    re5ad5c ree7e25  
    5959bool CheckLineCriteriaForDegeneratedTriangle(const BoundaryPointSet * const nodes[3]);
    6060bool SortCandidates(const CandidateForTesselation* candidate1, const CandidateForTesselation *candidate2);
    61 TesselPoint* FindClosestPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC);
    62 TesselPoint* FindSecondClosestPoint(const Vector*, const LinkedCell* const LC);
     61TesselPoint* FindClosestTesselPoint(const Vector* Point, TesselPoint *&SecondPoint, const LinkedCell* const LC);
     62TesselPoint* FindSecondClosestTesselPoint(const Vector*, const LinkedCell* const LC);
    6363Vector * GetClosestPointBetweenLine(const BoundaryLineSet * const Base, const BoundaryLineSet * const OtherBase);
    6464
     
    7272bool CheckListOfBaselines(const Tesselation * const TesselStruct);
    7373
     74int CountTrianglePairContainingPolygon(const BoundaryPolygonSet * const P, const TriangleSet * const T);
     75bool ArePolygonsEdgeConnected(const BoundaryPolygonSet * const P1, const BoundaryPolygonSet * const P2);
     76void CombinePolygons(BoundaryPolygonSet * const P1, BoundaryPolygonSet * &P2);
     77
    7478
    7579#endif /* TESSELATIONHELPERS_HPP_ */
  • src/unittests/AnalysisCorrelationToPointUnitTest.cpp

    re5ad5c ree7e25  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13
     14#include <cstring>
    1315
    1416#include "analysis_correlation.hpp"
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp

    re5ad5c ree7e25  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13
     14#include <cstring>
    1315
    1416#include "analysis_correlation.hpp"
     
    5860
    5961  // construct molecule (tetraeder of hydrogens) base
     62  TestSurfaceMolecule = new molecule(tafel);
     63  Walker = new atom();
     64  Walker->type = hydrogen;
     65  Walker->node->Init(1., 0., 1. );
     66  TestSurfaceMolecule->AddAtom(Walker);
     67  Walker = new atom();
     68  Walker->type = hydrogen;
     69  Walker->node->Init(0., 1., 1. );
     70  TestSurfaceMolecule->AddAtom(Walker);
     71  Walker = new atom();
     72  Walker->type = hydrogen;
     73  Walker->node->Init(1., 1., 0. );
     74  TestSurfaceMolecule->AddAtom(Walker);
     75  Walker = new atom();
     76  Walker->type = hydrogen;
     77  Walker->node->Init(0., 0., 0. );
     78  TestSurfaceMolecule->AddAtom(Walker);
     79
     80  // check that TestMolecule was correctly constructed
     81  CPPUNIT_ASSERT_EQUAL( TestSurfaceMolecule->AtomCount, 4 );
     82
     83  TestList = new MoleculeListClass;
     84  TestSurfaceMolecule->ActiveFlag = true;
     85  TestList->insert(TestSurfaceMolecule);
     86
     87  // init tesselation and linked cell
     88  Surface = new Tesselation;
     89  LC = new LinkedCell(TestSurfaceMolecule, 5.);
     90  FindNonConvexBorder(TestSurfaceMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
     91
     92  // add outer atoms
    6093  TestMolecule = new molecule(tafel);
    6194  Walker = new atom();
    62   Walker->type = hydrogen;
    63   Walker->node->Init(1., 0., 1. );
    64   TestMolecule->AddAtom(Walker);
    65   Walker = new atom();
    66   Walker->type = hydrogen;
    67   Walker->node->Init(0., 1., 1. );
    68   TestMolecule->AddAtom(Walker);
    69   Walker = new atom();
    70   Walker->type = hydrogen;
    71   Walker->node->Init(1., 1., 0. );
    72   TestMolecule->AddAtom(Walker);
    73   Walker = new atom();
    74   Walker->type = hydrogen;
    75   Walker->node->Init(0., 0., 0. );
    76   TestMolecule->AddAtom(Walker);
    77 
    78   // check that TestMolecule was correctly constructed
    79   CPPUNIT_ASSERT_EQUAL( TestMolecule->AtomCount, 4 );
    80 
    81   TestList = new MoleculeListClass;
     95  Walker->type = carbon;
     96  Walker->node->Init(4., 0., 4. );
     97  TestMolecule->AddAtom(Walker);
     98  Walker = new atom();
     99  Walker->type = carbon;
     100  Walker->node->Init(0., 4., 4. );
     101  TestMolecule->AddAtom(Walker);
     102  Walker = new atom();
     103  Walker->type = carbon;
     104  Walker->node->Init(4., 4., 0. );
     105  TestMolecule->AddAtom(Walker);
     106  // add inner atoms
     107  Walker = new atom();
     108  Walker->type = carbon;
     109  Walker->node->Init(0.5, 0.5, 0.5 );
     110  TestMolecule->AddAtom(Walker);
    82111  TestMolecule->ActiveFlag = true;
    83112  TestList->insert(TestMolecule);
    84 
    85   // init tesselation and linked cell
    86   Surface = new Tesselation;
    87   FindNonConvexBorder(TestMolecule, Surface, (const LinkedCell *&)LC, 2.5, NULL);
    88   LC = new LinkedCell(TestMolecule, 5.);
    89   CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
    90   CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
    91   CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
    92 
    93   // add outer atoms
    94   Walker = new atom();
    95   Walker->type = carbon;
    96   Walker->node->Init(4., 0., 4. );
    97   TestMolecule->AddAtom(Walker);
    98   Walker = new atom();
    99   Walker->type = carbon;
    100   Walker->node->Init(0., 4., 4. );
    101   TestMolecule->AddAtom(Walker);
    102   Walker = new atom();
    103   Walker->type = carbon;
    104   Walker->node->Init(4., 4., 0. );
    105   TestMolecule->AddAtom(Walker);
    106   // add inner atoms
    107   Walker = new atom();
    108   Walker->type = carbon;
    109   Walker->node->Init(0.5, 0.5, 0.5 );
    110   TestMolecule->AddAtom(Walker);
    111113
    112114  // init maps
     
    134136
    135137
     138/** Checks whether setup() does the right thing.
     139 */
     140void AnalysisCorrelationToSurfaceUnitTest::SurfaceTest()
     141{
     142  CPPUNIT_ASSERT_EQUAL( 4, TestSurfaceMolecule->AtomCount );
     143  CPPUNIT_ASSERT_EQUAL( 4, TestMolecule->AtomCount );
     144  CPPUNIT_ASSERT_EQUAL( (size_t)2, TestList->ListOfMolecules.size() );
     145  CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->PointsOnBoundary.size() );
     146  CPPUNIT_ASSERT_EQUAL( (size_t)6, Surface->LinesOnBoundary.size() );
     147  CPPUNIT_ASSERT_EQUAL( (size_t)4, Surface->TrianglesOnBoundary.size() );
     148};
     149
    136150void AnalysisCorrelationToSurfaceUnitTest::CorrelationToSurfaceTest()
    137151{
    138152  // do the pair correlation
    139153  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
     154//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    140155  CPPUNIT_ASSERT( surfacemap != NULL );
    141156  CPPUNIT_ASSERT_EQUAL( (size_t)4, surfacemap->size() );
     
    147162  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
    148163  // put pair correlation into bins and check with no range
     164//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    149165  binmap = BinData( surfacemap, 0.5, 0., 0. );
    150166  CPPUNIT_ASSERT_EQUAL( (size_t)1, binmap->size() );
    151   //OutputCorrelation ( binmap );
     167  OutputCorrelation ( (ofstream *)&cout, binmap );
    152168  tester = binmap->begin();
    153169  CPPUNIT_ASSERT_EQUAL( 0., tester->first );
     
    160176  BinPairMap::iterator tester;
    161177  surfacemap = CorrelationToSurface( TestList, hydrogen, Surface, LC );
     178//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    162179  // ... and check with [0., 2.] range
    163180  binmap = BinData( surfacemap, 0.5, 0., 2. );
    164181  CPPUNIT_ASSERT_EQUAL( (size_t)5, binmap->size() );
    165   //OutputCorrelation ( binmap );
     182//  OutputCorrelation ( (ofstream *)&cout, binmap );
    166183  tester = binmap->begin();
    167184  CPPUNIT_ASSERT_EQUAL( 0., tester->first );
     
    177194  BinPairMap::iterator tester;
    178195  surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
     196//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    179197  // put pair correlation into bins and check with no range
    180198  binmap = BinData( surfacemap, 0.5, 0., 0. );
     
    182200  OutputCorrelation ( (ofstream *)&cout, binmap );
    183201  // inside point is first and must have negative value
    184   tester = binmap->lower_bound(2.95); // start depends on the min value and
     202  tester = binmap->lower_bound(4.25-0.5); // start depends on the min value and
    185203  CPPUNIT_ASSERT( tester != binmap->end() );
    186204  CPPUNIT_ASSERT_EQUAL( 3, tester->second );
    187205  // inner point
    188   tester = binmap->lower_bound(-0.5);
     206  tester = binmap->lower_bound(0.);
    189207  CPPUNIT_ASSERT( tester != binmap->end() );
    190208  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
     
    195213  BinPairMap::iterator tester;
    196214  surfacemap = CorrelationToSurface( TestList, carbon, Surface, LC );
     215//  OutputCorrelationToSurface ( (ofstream *)&cout, surfacemap );
    197216  // ... and check with [0., 2.] range
    198217  binmap = BinData( surfacemap, 0.5, -2., 4. );
    199218  CPPUNIT_ASSERT_EQUAL( (size_t)13, binmap->size() );
    200   OutputCorrelation ( (ofstream *)&cout, binmap );
     219//  OutputCorrelation ( (ofstream *)&cout, binmap );
    201220  // three outside points
    202   tester = binmap->lower_bound(3.);
     221  tester = binmap->lower_bound(4.25-0.5);
    203222  CPPUNIT_ASSERT( tester != binmap->end() );
    204223  CPPUNIT_ASSERT_EQUAL( 3, tester->second );
    205224  // inner point
    206   tester = binmap->lower_bound(-0.5);
     225  tester = binmap->lower_bound(0.);
    207226  CPPUNIT_ASSERT( tester != binmap->end() );
    208227  CPPUNIT_ASSERT_EQUAL( 1, tester->second );
    209 
    210228};
    211229
  • src/unittests/AnalysisCorrelationToSurfaceUnitTest.hpp

    re5ad5c ree7e25  
    2323{
    2424    CPPUNIT_TEST_SUITE( AnalysisCorrelationToSurfaceUnitTest ) ;
     25    CPPUNIT_TEST ( SurfaceTest );
    2526    CPPUNIT_TEST ( CorrelationToSurfaceTest );
    2627    CPPUNIT_TEST ( CorrelationToSurfaceHydrogenBinNoRangeTest );
     
    3334      void setUp();
    3435      void tearDown();
     36      void SurfaceTest();
    3537      void CorrelationToSurfaceTest();
    3638      void CorrelationToSurfaceHydrogenBinNoRangeTest();
     
    4345      MoleculeListClass *TestList;
    4446      molecule *TestMolecule;
     47      molecule *TestSurfaceMolecule;
    4548      element *hydrogen;
    4649      element *carbon;
  • src/unittests/AnalysisPairCorrelationUnitTest.cpp

    re5ad5c ree7e25  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13
     14#include <cstring>
    1315
    1416#include "analysis_correlation.hpp"
  • src/unittests/Makefile.am

    re5ad5c ree7e25  
    44AM_CXXFLAGS = $(CPPUNIT_CFLAGS)
    55
    6 TESTS = ActOnAllUnitTest AnalysisCorrelationToPointUnitTest AnalysisCorrelationToSurfaceUnitTest AnalysisPairCorrelationUnitTest BondGraphUnitTest ListOfBondsUnitTest LogUnitTest MemoryUsageObserverUnitTest MemoryAllocatorUnitTest StackClassUnitTest VectorUnitTest
     6TESTS = \
     7  ActOnAllUnitTest \
     8  AnalysisBondsUnitTests \
     9  AnalysisCorrelationToPointUnitTest \
     10  AnalysisCorrelationToSurfaceUnitTest \
     11  AnalysisPairCorrelationUnitTest \
     12  BondGraphUnitTest \
     13  CountBondsUnitTest \
     14  GSLMatrixSymmetricUnitTest \
     15  GSLMatrixUnitTest \
     16  GSLVectorUnitTest \
     17  InfoUnitTest \
     18  LinearSystemOfEquationsUnitTest \
     19  LinkedCellUnitTest \
     20  ListOfBondsUnitTest \
     21  LogUnitTest \
     22  MemoryUsageObserverUnitTest \
     23  MemoryAllocatorUnitTest \
     24  StackClassUnitTest \
     25  TesselationUnitTest \
     26  Tesselation_BoundaryTriangleUnitTest \
     27  Tesselation_InOutsideUnitTest \
     28  VectorUnitTest
     29 
    730check_PROGRAMS = $(TESTS)
    831noinst_PROGRAMS = $(TESTS)
    932
    1033ActOnAllUnitTest_SOURCES = ../test/ActOnAllTest.hpp ActOnAllUnitTest.cpp ActOnAllUnitTest.hpp
    11 ActOnAllUnitTest_LDADD = ../libmolecuilder.a
     34ActOnAllUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     35
     36AnalysisBondsUnitTests_SOURCES = analysisbondsunittest.cpp analysisbondsunittest.hpp
     37AnalysisBondsUnitTests_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    1238
    1339AnalysisCorrelationToPointUnitTest_SOURCES = analysis_correlation.hpp AnalysisCorrelationToPointUnitTest.cpp AnalysisCorrelationToPointUnitTest.hpp
    14 AnalysisCorrelationToPointUnitTest_LDADD = ../libmolecuilder.a
     40AnalysisCorrelationToPointUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    1541
    1642AnalysisCorrelationToSurfaceUnitTest_SOURCES = analysis_correlation.hpp AnalysisCorrelationToSurfaceUnitTest.cpp AnalysisCorrelationToSurfaceUnitTest.hpp
    17 AnalysisCorrelationToSurfaceUnitTest_LDADD = ../libmolecuilder.a
     43AnalysisCorrelationToSurfaceUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    1844
    1945AnalysisPairCorrelationUnitTest_SOURCES = analysis_correlation.hpp AnalysisPairCorrelationUnitTest.cpp AnalysisPairCorrelationUnitTest.hpp
    20 AnalysisPairCorrelationUnitTest_LDADD = ../libmolecuilder.a
     46AnalysisPairCorrelationUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    2147
    2248BondGraphUnitTest_SOURCES = bondgraphunittest.cpp bondgraphunittest.hpp
    23 BondGraphUnitTest_LDADD = ../libmolecuilder.a
     49BondGraphUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     50
     51CountBondsUnitTest_SOURCES = CountBondsUnitTest.cpp CountBondsUnitTest.hpp
     52CountBondsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     53
     54GSLMatrixSymmetricUnitTest_SOURCES = gslmatrixsymmetricunittest.cpp gslmatrixsymmetricunittest.hpp
     55GSLMatrixSymmetricUnitTest_LDADD = ../libgslwrapper.a
     56
     57GSLMatrixUnitTest_SOURCES = gslmatrixunittest.cpp gslmatrixunittest.hpp
     58GSLMatrixUnitTest_LDADD = ../libgslwrapper.a
     59
     60GSLVectorUnitTest_SOURCES = gslvectorunittest.cpp gslvectorunittest.hpp
     61GSLVectorUnitTest_LDADD = ../libgslwrapper.a
     62
     63InfoUnitTest_SOURCES = infounittest.cpp infounittest.hpp
     64InfoUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     65
     66LinearSystemOfEquationsUnitTest_SOURCES = linearsystemofequationsunittest.cpp linearsystemofequationsunittest.hpp
     67LinearSystemOfEquationsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     68
     69LinkedCellUnitTest_SOURCES = LinkedCellUnitTest.cpp LinkedCellUnitTest.hpp
     70LinkedCellUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    2471
    2572ListOfBondsUnitTest_SOURCES = listofbondsunittest.cpp listofbondsunittest.hpp
    26 ListOfBondsUnitTest_LDADD = ../libmolecuilder.a
     73ListOfBondsUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    2774
    2875LogUnitTest_SOURCES = logunittest.cpp logunittest.hpp
    29 LogUnitTest_LDADD = ../libmolecuilder.a
     76LogUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    3077
    3178MemoryAllocatorUnitTest_SOURCES = memoryallocatorunittest.cpp memoryallocatorunittest.hpp
    32 MemoryAllocatorUnitTest_LDADD = ../libmolecuilder.a
     79MemoryAllocatorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    3380
    3481MemoryUsageObserverUnitTest_SOURCES = memoryusageobserverunittest.cpp memoryusageobserverunittest.hpp
    35 MemoryUsageObserverUnitTest_LDADD = ../libmolecuilder.a
     82MemoryUsageObserverUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    3683
    3784StackClassUnitTest_SOURCES = stackclassunittest.cpp stackclassunittest.hpp
    38 StackClassUnitTest_LDADD = ../libmolecuilder.a
     85StackClassUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     86
     87TesselationUnitTest_SOURCES = tesselationunittest.cpp tesselationunittest.hpp
     88TesselationUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     89
     90Tesselation_BoundaryTriangleUnitTest_SOURCES = tesselation_boundarytriangleunittest.cpp tesselation_boundarytriangleunittest.hpp
     91Tesselation_BoundaryTriangleUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
     92
     93Tesselation_InOutsideUnitTest_SOURCES = tesselation_insideoutsideunittest.cpp tesselation_insideoutsideunittest.hpp
     94Tesselation_InOutsideUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    3995
    4096VectorUnitTest_SOURCES = vectorunittest.cpp vectorunittest.hpp
    41 VectorUnitTest_LDADD = ../libmolecuilder.a
     97VectorUnitTest_LDADD = ../libmolecuilder.a ../libgslwrapper.a
    4298
    4399
  • src/unittests/bondgraphunittest.cpp

    re5ad5c ree7e25  
    1414#include <iostream>
    1515#include <stdio.h>
     16#include <cstring>
    1617
    1718#include "atom.hpp"
     
    8889  test << "H\t1.\t1.2\n";
    8990  test << "C\t1.2\t1.5\n";
     91  test.close();
    9092  BG = new BondGraph(true);
    9193};
  • src/unittests/bondgraphunittest.hpp

    re5ad5c ree7e25  
    1111#include <cppunit/extensions/HelperMacros.h>
    1212
    13 #include "bondgraph.hpp"
    1413
     14class BondGraph;
    1515class element;
    1616class molecule;
  • src/unittests/listofbondsunittest.cpp

    re5ad5c ree7e25  
    1111#include <cppunit/extensions/TestFactoryRegistry.h>
    1212#include <cppunit/ui/text/TestRunner.h>
     13
     14#include <cstring>
    1315
    1416#include "listofbondsunittest.hpp"
  • src/unittests/logunittest.cpp

    re5ad5c ree7e25  
    3535{
    3636  logger::getInstance()->setVerbosity(2);
    37   Log() << Verbose(0) << "Verbosity level is set to 2." << endl;
    38   Log() << Verbose(0) << "Test level 0" << endl;
    39   Log() << Verbose(1) << "Test level 1" << endl;
    40   Log() << Verbose(2) << "Test level 2" << endl;
    41   Log() << Verbose(3) << "Test level 3" << endl;
    42   Log() << Verbose(4) << "Test level 4" << endl;
     37  DoLog(0) && (Log() << Verbose(0) << "Verbosity level is set to 2." << endl);
     38  DoLog(0) && (Log() << Verbose(0) << "Test level 0" << endl);
     39  DoLog(1) && (Log() << Verbose(1) << "Test level 1" << endl);
     40  DoLog(2) && (Log() << Verbose(2) << "Test level 2" << endl);
     41  DoLog(3) && (Log() << Verbose(3) << "Test level 3" << endl);
     42  DoLog(4) && (Log() << Verbose(4) << "Test level 4" << endl);
    4343
    44   Log() << Verbose(0) << "Output a log message." << endl;
    45   eLog() << Verbose(0) << "Output an error message." << endl;
     44  DoLog(0) && (Log() << Verbose(0) << "Output a log message." << endl);
     45  DoeLog(0) && (eLog()<< Verbose(0) << "Output an error message." << endl);
    4646  setVerbosity(3);
    47   Log() << Verbose(4) << "This should not be printed." << endl;
    48   eLog() << Verbose(4) << "This should not be printed." << endl;
     47  DoLog(4) && (Log() << Verbose(4) << "This should not be printed." << endl);
     48  DoeLog(4) && (eLog()<< Verbose(4) << "This should not be printed." << endl);
    4949};
    5050
  • src/unittests/memoryallocatorunittest.cpp

    re5ad5c ree7e25  
    4646  char* buffer3 = NULL;
    4747  buffer3 = Malloc<char>(4, "");
    48   Log() << Verbose(0) << buffer3 << endl;
     48  DoLog(0) && (Log() << Verbose(0) << buffer3 << endl);
    4949  Free(&buffer3);
    5050
  • src/unittests/tesselationunittest.cpp

    re5ad5c ree7e25  
    1212#include <cppunit/extensions/TestFactoryRegistry.h>
    1313#include <cppunit/ui/text/TestRunner.h>
     14
     15#include <cstring>
    1416
    1517#include "defs.hpp"
     
    3032  class TesselPoint *Walker;
    3133  Walker = new TesselPoint;
    32   Walker->node = new Vector(1., 0., 0.);
    33   Walker->Name = new char[3];
     34  Walker->node = new Vector(1., 0., -1.);
     35  Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
    3436  strcpy(Walker->Name, "1");
    3537  Walker->nr = 1;
    3638  Corners.push_back(Walker);
    3739  Walker = new TesselPoint;
    38   Walker->node = new Vector(-1., 1., 0.);
    39   Walker->Name = new char[3];
     40  Walker->node = new Vector(-1., 1., -1.);
     41  Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
    4042  strcpy(Walker->Name, "2");
    4143  Walker->nr = 2;
    4244  Corners.push_back(Walker);
    4345  Walker = new TesselPoint;
    44   Walker->node = new Vector(-1., -1., 0.);
    45   Walker->Name = new char[3];
     46  Walker->node = new Vector(-1., -1., -1.);
     47  Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
    4648  strcpy(Walker->Name, "3");
    4749  Walker->nr = 3;
     
    4951  Walker = new TesselPoint;
    5052  Walker->node = new Vector(-1., 0., 1.);
    51   Walker->Name = new char[3];
     53  Walker->Name = Malloc<char>(3, "TesselationTest::setUp");
    5254  strcpy(Walker->Name, "4");
    5355  Walker->nr = 4;
     
    5961  // create tesselation
    6062  TesselStruct = new Tesselation;
    61   TesselStruct->PointsOnBoundary.clear();
    62   TesselStruct->LinesOnBoundary.clear();
    63   TesselStruct->TrianglesOnBoundary.clear();
     63  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->PointsOnBoundary.empty() );
     64  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->LinesOnBoundary.empty() );
     65  CPPUNIT_ASSERT_EQUAL( true, TesselStruct->TrianglesOnBoundary.empty() );
    6466  TesselStruct->FindStartingTriangle(SPHERERADIUS, LinkedList);
    65   bool flag = false;
    6667
    67   LineMap::iterator baseline = TesselStruct->LinesOnBoundary.begin();
    68   while (baseline != TesselStruct->LinesOnBoundary.end()) {
    69     if (baseline->second->triangles.size() == 1) {
    70       flag = TesselStruct->FindNextSuitableTriangle(*(baseline->second), *(((baseline->second->triangles.begin()))->second), SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
     68  CandidateForTesselation *baseline = NULL;
     69  BoundaryTriangleSet *T = NULL;
     70  bool OneLoopWithoutSuccessFlag = true;
     71  bool TesselationFailFlag = false;
     72  while ((!TesselStruct->OpenLines.empty()) && (OneLoopWithoutSuccessFlag)) {
     73    // 2a. fill all new OpenLines
     74    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
     75      baseline = Runner->second;
     76      if (baseline->pointlist.empty()) {
     77        T = (((baseline->BaseLine->triangles.begin()))->second);
     78        TesselationFailFlag = TesselStruct->FindNextSuitableTriangle(*baseline, *T, SPHERERADIUS, LinkedList); //the line is there, so there is a triangle, but only one.
     79      }
    7180    }
    72     baseline++;
    73     if ((baseline == TesselStruct->LinesOnBoundary.end()) && (flag)) {
    74       baseline = TesselStruct->LinesOnBoundary.begin();   // restart if we reach end due to newly inserted lines
    75       flag = false;
     81
     82    // 2b. search for smallest ShortestAngle among all candidates
     83    double ShortestAngle = 4.*M_PI;
     84    for (CandidateMap::iterator Runner = TesselStruct->OpenLines.begin(); Runner != TesselStruct->OpenLines.end(); Runner++) {
     85      if (Runner->second->ShortestAngle < ShortestAngle) {
     86        baseline = Runner->second;
     87        ShortestAngle = baseline->ShortestAngle;
     88      }
     89    }
     90    if ((ShortestAngle == 4.*M_PI) || (baseline->pointlist.empty()))
     91      OneLoopWithoutSuccessFlag = false;
     92    else {
     93      TesselStruct->AddCandidatePolygon(*baseline, SPHERERADIUS, LinkedList);
    7694    }
    7795  }
     
    83101  delete(LinkedList);
    84102  delete(TesselStruct);
    85   for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
    86     delete[]((*Runner)->Name);
     103  for (LinkedCell::LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++) {
    87104    delete((*Runner)->node);
    88105    delete(*Runner);
    89106  }
    90107  Corners.clear();
    91 };
    92 
    93 /** UnitTest for Tesselation::IsInnerPoint()
    94  */
    95 void TesselationTest::IsInnerPointTest()
    96 {
    97   // true inside points
    98   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.,0.), LinkedList) );
    99   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.5,0.,0.), LinkedList) );
    100   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.5,0.), LinkedList) );
    101   CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint(Vector(0.,0.,0.5), LinkedList) );
    102 
    103   // corners
    104   for (LinkedNodes::iterator Runner = Corners.begin(); Runner != Corners.end(); Runner++)
    105     CPPUNIT_ASSERT_EQUAL( true, TesselStruct->IsInnerPoint((*Runner), LinkedList) );
    106 
    107   // true outside points
    108   CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(0.,5.,0.), LinkedList) );
    109   CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(0.,0.,5.), LinkedList) );
    110   CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(1.,1.,1.), LinkedList) );
    111 
    112   // tricky point, there are three equally close triangles
    113   CPPUNIT_ASSERT_EQUAL( false, TesselStruct->IsInnerPoint(Vector(5.,0.,0.), LinkedList) );
    114 
     108  MemoryUsageObserver::purgeInstance();
     109  logger::purgeInstance();
     110  errorLogger::purgeInstance();
    115111};
    116112
  • src/unittests/tesselationunittest.hpp

    re5ad5c ree7e25  
    2121{
    2222    CPPUNIT_TEST_SUITE( TesselationTest) ;
    23     CPPUNIT_TEST ( IsInnerPointTest );
    2423    CPPUNIT_TEST ( GetAllTrianglesTest );
    2524    CPPUNIT_TEST ( ContainmentTest );
     
    2928      void setUp();
    3029      void tearDown();
    31       void IsInnerPointTest();
    3230      void GetAllTrianglesTest();
    3331      void ContainmentTest();
     
    3634private:
    3735      class Tesselation *TesselStruct;
    38       LinkedNodes Corners;
     36      LinkedCell::LinkedNodes Corners;
    3937      class LinkedCell *LinkedList;
    4038};
  • src/vector.cpp

    re5ad5c ree7e25  
    88#include "defs.hpp"
    99#include "helpers.hpp"
    10 #include "memoryallocator.hpp"
     10#include "info.hpp"
     11#include "gslmatrix.hpp"
    1112#include "leastsquaremin.hpp"
    1213#include "log.hpp"
     14#include "memoryallocator.hpp"
    1315#include "vector.hpp"
    1416#include "verbose.hpp"
     17#include "World.hpp"
     18
     19#include <gsl/gsl_linalg.h>
     20#include <gsl/gsl_matrix.h>
     21#include <gsl/gsl_permutation.h>
     22#include <gsl/gsl_vector.h>
    1523
    1624/************************************ Functions for class vector ************************************/
     
    1927 */
    2028Vector::Vector() { x[0] = x[1] = x[2] = 0.; };
     29
     30/** Constructor of class vector.
     31 */
     32Vector::Vector(const Vector * const a)
     33{
     34  x[0] = a->x[0];
     35  x[1] = a->x[1];
     36  x[2] = a->x[2];
     37};
     38
     39/** Constructor of class vector.
     40 */
     41Vector::Vector(const Vector &a)
     42{
     43  x[0] = a.x[0];
     44  x[1] = a.x[1];
     45  x[2] = a.x[2];
     46};
    2147
    2248/** Constructor of class vector.
     
    215241 * \param *Origin first vector of line
    216242 * \param *LineVector second vector of line
    217  * \return true -  \a this contains intersection point on return, false - line is parallel to plane
     243 * \return true -  \a this contains intersection point on return, false - line is parallel to plane (even if in-plane)
    218244 */
    219245bool Vector::GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector)
    220246{
     247  Info FunctionInfo(__func__);
    221248  double factor;
    222249  Vector Direction, helper;
     
    226253  Direction.SubtractVector(Origin);
    227254  Direction.Normalize();
    228   //Log() << Verbose(4) << "INFO: Direction is " << Direction << "." << endl;
     255  DoLog(1) && (Log() << Verbose(1) << "INFO: Direction is " << Direction << "." << endl);
     256  //Log() << Verbose(1) << "INFO: PlaneNormal is " << *PlaneNormal << " and PlaneOffset is " << *PlaneOffset << "." << endl;
    229257  factor = Direction.ScalarProduct(PlaneNormal);
    230   if (factor < MYEPSILON) { // Uniqueness: line parallel to plane?
    231     Log() << Verbose(2) << "WARNING: Line is parallel to plane, no intersection." << endl;
     258  if (fabs(factor) < MYEPSILON) { // Uniqueness: line parallel to plane?
     259    DoLog(1) && (Log() << Verbose(1) << "BAD: Line is parallel to plane, no intersection." << endl);
    232260    return false;
    233261  }
     
    235263  helper.SubtractVector(Origin);
    236264  factor = helper.ScalarProduct(PlaneNormal)/factor;
    237   if (factor < MYEPSILON) { // Origin is in-plane
    238     //Log() << Verbose(2) << "Origin of line is in-plane, simple." << endl;
     265  if (fabs(factor) < MYEPSILON) { // Origin is in-plane
     266    DoLog(1) && (Log() << Verbose(1) << "GOOD: Origin of line is in-plane." << endl);
    239267    CopyVector(Origin);
    240268    return true;
     
    243271  Direction.Scale(factor);
    244272  CopyVector(Origin);
    245   //Log() << Verbose(4) << "INFO: Scaled direction is " << Direction << "." << endl;
     273  DoLog(1) && (Log() << Verbose(1) << "INFO: Scaled direction is " << Direction << "." << endl);
    246274  AddVector(&Direction);
    247275
     
    250278  helper.SubtractVector(PlaneOffset);
    251279  if (helper.ScalarProduct(PlaneNormal) < MYEPSILON) {
    252     //Log() << Verbose(2) << "INFO: Intersection at " << *this << " is good." << endl;
     280    DoLog(1) && (Log() << Verbose(1) << "GOOD: Intersection is " << *this << "." << endl);
    253281    return true;
    254282  } else {
    255     Log() << Verbose(2) << "WARNING: Intersection point " << *this << " is not on plane." << endl;
     283    DoeLog(2) && (eLog()<< Verbose(2) << "Intersection point " << *this << " is not on plane." << endl);
    256284    return false;
    257285  }
    258286};
    259287
    260 /** Calculates the minimum distance of this vector to the plane.
     288/** Calculates the minimum distance vector of this vector to the plane.
    261289 * \param *out output stream for debugging
    262290 * \param *PlaneNormal normal of plane
    263291 * \param *PlaneOffset offset of plane
    264  * \return distance to plane
    265  */
    266 double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const
     292 * \return distance vector onto to plane
     293 */
     294Vector Vector::GetDistanceVectorToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const
    267295{
    268296  Vector temp;
     
    282310    sign = 0.;
    283311
    284   return (temp.Norm()*sign);
     312  temp.Normalize();
     313  temp.Scale(sign);
     314  return temp;
     315};
     316
     317/** Calculates the minimum distance of this vector to the plane.
     318 * \sa Vector::GetDistanceVectorToPlane()
     319 * \param *out output stream for debugging
     320 * \param *PlaneNormal normal of plane
     321 * \param *PlaneOffset offset of plane
     322 * \return distance to plane
     323 */
     324double Vector::DistanceToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const
     325{
     326  return GetDistanceVectorToPlane(PlaneNormal,PlaneOffset).Norm();
    285327};
    286328
    287329/** Calculates the intersection of the two lines that are both on the same plane.
    288  * We construct auxiliary plane with its vector normal to one line direction and the PlaneNormal, then a vector
    289  * from the first line's offset onto the plane. Finally, scale by factor is 1/cos(angle(line1,line2..)) = 1/SP(...), and
    290  * project onto the first line's direction and add its offset.
     330 * This is taken from Weisstein, Eric W. "Line-Line Intersection." From MathWorld--A Wolfram Web Resource. http://mathworld.wolfram.com/Line-LineIntersection.html
    291331 * \param *out output stream for debugging
    292332 * \param *Line1a first vector of first line
     
    299339bool Vector::GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *PlaneNormal)
    300340{
    301   bool result = true;
    302   Vector Direction, OtherDirection;
    303   Vector AuxiliaryNormal;
    304   Vector Distance;
    305   const Vector *Normal = NULL;
    306   Vector *ConstructedNormal = NULL;
    307   bool FreeNormal = false;
    308 
    309   // construct both direction vectors
    310   Zero();
    311   Direction.CopyVector(Line1b);
    312   Direction.SubtractVector(Line1a);
    313   if (Direction.IsZero())
     341  Info FunctionInfo(__func__);
     342
     343  GSLMatrix *M = new GSLMatrix(4,4);
     344
     345  M->SetAll(1.);
     346  for (int i=0;i<3;i++) {
     347    M->Set(0, i, Line1a->x[i]);
     348    M->Set(1, i, Line1b->x[i]);
     349    M->Set(2, i, Line2a->x[i]);
     350    M->Set(3, i, Line2b->x[i]);
     351  }
     352 
     353  //Log() << Verbose(1) << "Coefficent matrix is:" << endl;
     354  //ostream &output = Log() << Verbose(1);
     355  //for (int i=0;i<4;i++) {
     356  //  for (int j=0;j<4;j++)
     357  //    output << "\t" << M->Get(i,j);
     358  //  output << endl;
     359  //}
     360  if (fabs(M->Determinant()) > MYEPSILON) {
     361    DoLog(1) && (Log() << Verbose(1) << "Determinant of coefficient matrix is NOT zero." << endl);
    314362    return false;
    315   OtherDirection.CopyVector(Line2b);
    316   OtherDirection.SubtractVector(Line2a);
    317   if (OtherDirection.IsZero())
     363  }
     364  DoLog(1) && (Log() << Verbose(1) << "INFO: Line1a = " << *Line1a << ", Line1b = " << *Line1b << ", Line2a = " << *Line2a << ", Line2b = " << *Line2b << "." << endl);
     365
     366
     367  // constuct a,b,c
     368  Vector a;
     369  Vector b;
     370  Vector c;
     371  Vector d;
     372  a.CopyVector(Line1b);
     373  a.SubtractVector(Line1a);
     374  b.CopyVector(Line2b);
     375  b.SubtractVector(Line2a);
     376  c.CopyVector(Line2a);
     377  c.SubtractVector(Line1a);
     378  d.CopyVector(Line2b);
     379  d.SubtractVector(Line1b);
     380  DoLog(1) && (Log() << Verbose(1) << "INFO: a = " << a << ", b = " << b << ", c = " << c << "." << endl);
     381  if ((a.NormSquared() < MYEPSILON) || (b.NormSquared() < MYEPSILON)) {
     382   Zero();
     383   DoLog(1) && (Log() << Verbose(1) << "At least one of the lines is ill-defined, i.e. offset equals second vector." << endl);
     384   return false;
     385  }
     386
     387  // check for parallelity
     388  Vector parallel;
     389  double factor = 0.;
     390  if (fabs(a.ScalarProduct(&b)*a.ScalarProduct(&b)/a.NormSquared()/b.NormSquared() - 1.) < MYEPSILON) {
     391    parallel.CopyVector(Line1a);
     392    parallel.SubtractVector(Line2a);
     393    factor = parallel.ScalarProduct(&a)/a.Norm();
     394    if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {
     395      CopyVector(Line2a);
     396      DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl);
     397      return true;
     398    } else {
     399      parallel.CopyVector(Line1a);
     400      parallel.SubtractVector(Line2b);
     401      factor = parallel.ScalarProduct(&a)/a.Norm();
     402      if ((factor >= -MYEPSILON) && (factor - 1. < MYEPSILON)) {
     403        CopyVector(Line2b);
     404        DoLog(1) && (Log() << Verbose(1) << "Lines conincide." << endl);
     405        return true;
     406      }
     407    }
     408    DoLog(1) && (Log() << Verbose(1) << "Lines are parallel." << endl);
     409    Zero();
    318410    return false;
    319 
    320   Direction.Normalize();
    321   OtherDirection.Normalize();
    322 
    323   //Log() << Verbose(4) << "INFO: Normalized Direction " << Direction << " and OtherDirection " << OtherDirection << "." << endl;
    324 
    325   if (fabs(OtherDirection.ScalarProduct(&Direction) - 1.) < MYEPSILON) { // lines are parallel
    326     if ((Line1a == Line2a) || (Line1a == Line2b))
    327       CopyVector(Line1a);
    328     else if ((Line1b == Line2b) || (Line1b == Line2b))
    329         CopyVector(Line1b);
    330     else
    331       return false;
    332     Log() << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
    333     return true;
    334   } else {
    335     // check whether we have a plane normal vector
    336     if (PlaneNormal == NULL) {
    337       ConstructedNormal = new Vector;
    338       ConstructedNormal->MakeNormalVector(&Direction, &OtherDirection);
    339       Normal = ConstructedNormal;
    340       FreeNormal = true;
    341     } else
    342       Normal = PlaneNormal;
    343 
    344     AuxiliaryNormal.MakeNormalVector(&OtherDirection, Normal);
    345     //Log() << Verbose(4) << "INFO: PlaneNormal is " << *Normal << " and AuxiliaryNormal " << AuxiliaryNormal << "." << endl;
    346 
    347     Distance.CopyVector(Line2a);
    348     Distance.SubtractVector(Line1a);
    349     //Log() << Verbose(4) << "INFO: Distance is " << Distance << "." << endl;
    350     if (Distance.IsZero()) {
    351       // offsets are equal, match found
    352       CopyVector(Line1a);
    353       result = true;
    354     } else {
    355       CopyVector(Distance.Projection(&AuxiliaryNormal));
    356       //Log() << Verbose(4) << "INFO: Projected Distance is " << *this << "." << endl;
    357       double factor = Direction.ScalarProduct(&AuxiliaryNormal);
    358       //Log() << Verbose(4) << "INFO: Scaling factor is " << factor << "." << endl;
    359       Scale(1./(factor*factor));
    360       //Log() << Verbose(4) << "INFO: Scaled Distance is " << *this << "." << endl;
    361       CopyVector(Projection(&Direction));
    362       //Log() << Verbose(4) << "INFO: Distance, projected into Direction, is " << *this << "." << endl;
    363       if (this->IsZero())
    364         result = false;
    365       else
    366         result = true;
    367       AddVector(Line1a);
    368     }
    369 
    370     if (FreeNormal)
    371       delete(ConstructedNormal);
    372   }
    373   if (result)
    374     Log() << Verbose(4) << "INFO: Intersection is " << *this << "." << endl;
    375 
    376   return result;
     411  }
     412
     413  // obtain s
     414  double s;
     415  Vector temp1, temp2;
     416  temp1.CopyVector(&c);
     417  temp1.VectorProduct(&b);
     418  temp2.CopyVector(&a);
     419  temp2.VectorProduct(&b);
     420  DoLog(1) && (Log() << Verbose(1) << "INFO: temp1 = " << temp1 << ", temp2 = " << temp2 << "." << endl);
     421  if (fabs(temp2.NormSquared()) > MYEPSILON)
     422    s = temp1.ScalarProduct(&temp2)/temp2.NormSquared();
     423  else
     424    s = 0.;
     425  DoLog(1) && (Log() << Verbose(1) << "Factor s is " << temp1.ScalarProduct(&temp2) << "/" << temp2.NormSquared() << " = " << s << "." << endl);
     426
     427  // construct intersection
     428  CopyVector(&a);
     429  Scale(s);
     430  AddVector(Line1a);
     431  DoLog(1) && (Log() << Verbose(1) << "Intersection is at " << *this << "." << endl);
     432
     433  return true;
    377434};
    378435
     
    480537  else
    481538    return false;
     539};
     540
     541/** Checks whether vector is normal to \a *normal.
     542 * @return true - vector is normalized, false - vector is not
     543 */
     544bool Vector::IsEqualTo(const Vector * const a) const
     545{
     546  bool status = true;
     547  for (int i=0;i<NDIM;i++) {
     548    if (fabs(x[i] - a->x[i]) > MYEPSILON)
     549      status = false;
     550  }
     551  return status;
    482552};
    483553
     
    632702void Vector::Output() const
    633703{
    634   Log() << Verbose(0) << "(";
     704  DoLog(0) && (Log() << Verbose(0) << "(");
    635705  for (int i=0;i<NDIM;i++) {
    636     Log() << Verbose(0) << x[i];
     706    DoLog(0) && (Log() << Verbose(0) << x[i]);
    637707    if (i != 2)
    638       Log() << Verbose(0) << ",";
    639   }
    640   Log() << Verbose(0) << ")";
     708      DoLog(0) && (Log() << Verbose(0) << ",");
     709  }
     710  DoLog(0) && (Log() << Verbose(0) << ")");
    641711};
    642712
     
    747817      x[i] = C.x[i];
    748818  } else {
    749     eLog() << Verbose(0) << "ERROR: inverse of matrix does not exists: det A = " << detA << "." << endl;
     819    DoeLog(1) && (eLog()<< Verbose(1) << "inverse of matrix does not exists: det A = " << detA << "." << endl);
    750820  }
    751821};
     
    773843  projection = ScalarProduct(n)/n->ScalarProduct(n);    // remove constancy from n (keep as logical one)
    774844  // withdraw projected vector twice from original one
    775   Log() << Verbose(1) << "Vector: ";
     845  DoLog(1) && (Log() << Verbose(1) << "Vector: ");
    776846  Output();
    777   Log() << Verbose(0) << "\t";
     847  DoLog(0) && (Log() << Verbose(0) << "\t");
    778848  for (int i=NDIM;i--;)
    779849    x[i] -= 2.*projection*n->x[i];
    780   Log() << Verbose(0) << "Projected vector: ";
     850  DoLog(0) && (Log() << Verbose(0) << "Projected vector: ");
    781851  Output();
    782   Log() << Verbose(0) << endl;
     852  DoLog(0) && (Log() << Verbose(0) << endl);
    783853};
    784854
     
    799869  x2.SubtractVector(y2);
    800870  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    801     Log() << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl;
     871    DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl);
    802872    return false;
    803873  }
     
    833903  Zero();
    834904  if ((fabs(x1.Norm()) < MYEPSILON) || (fabs(x2.Norm()) < MYEPSILON) || (fabs(x1.Angle(&x2)) < MYEPSILON)) {
    835     Log() << Verbose(4) << "WARNING: Given vectors are linear dependent." << endl;
     905    DoeLog(2) && (eLog()<< Verbose(2) << "Given vectors are linear dependent." << endl);
    836906    return false;
    837907  }
     
    884954  double norm;
    885955
    886   Log() << Verbose(4);
     956  DoLog(4) && (Log() << Verbose(4));
    887957  GivenVector->Output();
    888   Log() << Verbose(0) << endl;
     958  DoLog(0) && (Log() << Verbose(0) << endl);
    889959  for (j=NDIM;j--;)
    890960    Components[j] = -1;
     
    893963    if (fabs(GivenVector->x[j]) > MYEPSILON)
    894964      Components[Last++] = j;
    895   Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl;
     965  DoLog(4) && (Log() << Verbose(4) << Last << " Components != 0: (" << Components[0] << "," << Components[1] << "," << Components[2] << ")" << endl);
    896966
    897967  switch(Last) {
     
    9431013
    9441014  for (j=0;j<num;j++) {
    945     Log() << Verbose(1) << j << "th atom's vector: ";
     1015    DoLog(1) && (Log() << Verbose(1) << j << "th atom's vector: ");
    9461016    (vectors[j])->Output();
    947     Log() << Verbose(0) << endl;
     1017    DoLog(0) && (Log() << Verbose(0) << endl);
    9481018  }
    9491019
     
    10651135    j += i+1;
    10661136    do {
    1067       Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: ";
     1137      DoLog(0) && (Log() << Verbose(0) << coords[i] << "[0.." << cell_size[j] << "]: ");
    10681138      cin >> x[i];
    10691139    } while (((x[i] < 0) || (x[i] >= cell_size[j])) && (check));
     
    10961166  B2 = cos(beta) * x2->Norm() * c;
    10971167  C = c * c;
    1098   Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl;
     1168  DoLog(2) && (Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl);
    10991169  int flag = 0;
    11001170  if (fabs(x1->x[0]) < MYEPSILON) { // check for zero components for the later flipping and back-flipping
     
    11351205  D2 = -y->x[0]/x1->x[0]*x1->x[2]+y->x[2];
    11361206  D3 = y->x[0]/x1->x[0]*A-B1;
    1137   Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n";
     1207  DoLog(2) && (Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n");
    11381208  if (fabs(D1) < MYEPSILON) {
    1139     Log() << Verbose(2) << "D1 == 0!\n";
     1209    DoLog(2) && (Log() << Verbose(2) << "D1 == 0!\n");
    11401210    if (fabs(D2) > MYEPSILON) {
    1141       Log() << Verbose(3) << "D2 != 0!\n";
     1211      DoLog(3) && (Log() << Verbose(3) << "D2 != 0!\n");
    11421212      x[2] = -D3/D2;
    11431213      E1 = A/x1->x[0] + x1->x[2]/x1->x[0]*D3/D2;
    11441214      E2 = -x1->x[1]/x1->x[0];
    1145       Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n";
     1215      DoLog(3) && (Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n");
    11461216      F1 = E1*E1 + 1.;
    11471217      F2 = -E1*E2;
    11481218      F3 = E1*E1 + D3*D3/(D2*D2) - C;
    1149       Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n";
     1219      DoLog(3) && (Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n");
    11501220      if (fabs(F1) < MYEPSILON) {
    1151         Log() << Verbose(4) << "F1 == 0!\n";
    1152         Log() << Verbose(4) << "Gleichungssystem linear\n";
     1221        DoLog(4) && (Log() << Verbose(4) << "F1 == 0!\n");
     1222        DoLog(4) && (Log() << Verbose(4) << "Gleichungssystem linear\n");
    11531223        x[1] = F3/(2.*F2);
    11541224      } else {
    11551225        p = F2/F1;
    11561226        q = p*p - F3/F1;
    1157         Log() << Verbose(4) << "p " << p << "\tq " << q << endl;
     1227        DoLog(4) && (Log() << Verbose(4) << "p " << p << "\tq " << q << endl);
    11581228        if (q < 0) {
    1159           Log() << Verbose(4) << "q < 0" << endl;
     1229          DoLog(4) && (Log() << Verbose(4) << "q < 0" << endl);
    11601230          return false;
    11611231        }
     
    11641234      x[0] =  A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2];
    11651235    } else {
    1166       Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n";
     1236      DoLog(2) && (Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n");
    11671237      return false;
    11681238    }
     
    11701240    E1 = A/x1->x[0]+x1->x[1]/x1->x[0]*D3/D1;
    11711241    E2 = x1->x[1]/x1->x[0]*D2/D1 - x1->x[2];
    1172     Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n";
     1242    DoLog(2) && (Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n");
    11731243    F1 = E2*E2 + D2*D2/(D1*D1) + 1.;
    11741244    F2 = -(E1*E2 + D2*D3/(D1*D1));
    11751245    F3 = E1*E1 + D3*D3/(D1*D1) - C;
    1176     Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n";
     1246    DoLog(2) && (Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n");
    11771247    if (fabs(F1) < MYEPSILON) {
    1178       Log() << Verbose(3) << "F1 == 0!\n";
    1179       Log() << Verbose(3) << "Gleichungssystem linear\n";
     1248      DoLog(3) && (Log() << Verbose(3) << "F1 == 0!\n");
     1249      DoLog(3) && (Log() << Verbose(3) << "Gleichungssystem linear\n");
    11801250      x[2] = F3/(2.*F2);
    11811251    } else {
    11821252      p = F2/F1;
    11831253      q = p*p - F3/F1;
    1184       Log() << Verbose(3) << "p " << p << "\tq " << q << endl;
     1254      DoLog(3) && (Log() << Verbose(3) << "p " << p << "\tq " << q << endl);
    11851255      if (q < 0) {
    1186         Log() << Verbose(3) << "q < 0" << endl;
     1256        DoLog(3) && (Log() << Verbose(3) << "q < 0" << endl);
    11871257        return false;
    11881258      }
     
    12221292    for (j=2;j>=0;j--) {
    12231293      k = (i & pot(2,j)) << j;
    1224       Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl;
     1294      DoLog(2) && (Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl);
    12251295      sign[j] = (k == 0) ? 1. : -1.;
    12261296    }
    1227     Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n";
     1297    DoLog(2) && (Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n");
    12281298    // apply sign matrix
    12291299    for (j=NDIM;j--;)
     
    12311301    // calculate angle and check
    12321302    ang = x2->Angle (this);
    1233     Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t";
     1303    DoLog(1) && (Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t");
    12341304    if (fabs(ang - cos(beta)) < MYEPSILON) {
    12351305      break;
  • src/vector.hpp

    re5ad5c ree7e25  
    2727
    2828  Vector();
     29  Vector(const Vector * const a);
     30  Vector(const Vector &a);
    2931  Vector(const double x1, const double x2, const double x3);
    3032  ~Vector();
     
    4244  bool IsOne() const;
    4345  bool IsNormalTo(const Vector * const normal) const;
     46  bool IsEqualTo(const Vector * const a) const;
    4447
    4548  void AddVector(const Vector * const y);
     
    6669  void LinearCombinationOfVectors(const Vector * const x1, const Vector * const x2, const Vector * const x3, const double * const factors);
    6770  double CutsPlaneAt(const Vector * const A, const Vector * const B, const Vector * const C) const;
     71  Vector GetDistanceVectorToPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset) const;
    6872  bool GetIntersectionWithPlane(const Vector * const PlaneNormal, const Vector * const PlaneOffset, const Vector * const Origin, const Vector * const LineVector);
    6973  bool GetIntersectionOfTwoLinesOnPlane(const Vector * const Line1a, const Vector * const Line1b, const Vector * const Line2a, const Vector * const Line2b, const Vector *Normal = NULL);
  • src/verbose.cpp

    re5ad5c ree7e25  
    11using namespace std;
    22
     3#include "info.hpp"
    34#include "verbose.hpp"
    45
     
    910ostream& Verbose::print (ostream &ost) const
    1011{
    11   for (int i=Verbosity;i--;)
     12  for (int i=Verbosity+Info::verbosity;i--;)
    1213    ost.put('\t');
    1314  //Log() << Verbose(0) << "Verbose(.) called." << endl;
     
    1617
    1718/** States whether current output message should be print or not.
    18  * Compares Verbose::Verbosity against \a verbosityLevel.
     19 * Compares Verbose::Verbosity plus Info::verbosity against \a verbosityLevel.
    1920 * \param verbosityLevel given global level of verbosity
    2021 * \return true - do output, false - don't
     
    2223bool Verbose::DoOutput(int verbosityLevel) const
    2324{
     25  return (verbosityLevel >= Verbosity+Info::verbosity);
     26};
     27
     28/** States whether current error output message should be print or not.
     29 * Compares Verbose::Verbosity against \a verbosityLevel.
     30 * \param verbosityLevel given global level of verbosity
     31 * \return true - do output, false - don't
     32 */
     33bool Verbose::DoErrorOutput(int verbosityLevel) const
     34{
    2435  return (verbosityLevel >= Verbosity);
    2536};
    26 
    2737
    2838/** Operator for the Verbose(arg) call.
  • src/verbose.hpp

    re5ad5c ree7e25  
    2929    Verbose(int value) : Verbosity(value) { }
    3030
     31    // allow access to private variable Verbose::Verbosity
     32    friend ostream& operator<<(class errorLogger& l, const Verbose& v);
     33    friend ostream& operator<<(class errorLogger* l, const Verbose& v);
     34    friend ostream& operator<<(class logger& l, const Verbose& v);
     35    friend ostream& operator<<(class logger* l, const Verbose& v);
     36
    3137    ostream& print (ostream &ost) const;
    3238    bool DoOutput(int verbosityLevel) const;
     39    bool DoErrorOutput(int verbosityLevel) const;
    3340  private:
    3441    int Verbosity;
  • tests/Makefile.am

    re5ad5c ree7e25  
    22EXTRA_DIST = testsuite.at $(TESTSUITE) atlocal.in regression
    33TESTSUITE = $(srcdir)/testsuite
     4
     5SUBDIRS = Tesselations
    46
    57check-local: atconfig atlocal package.m4 $(TESTSUITE)
  • tests/regression/Tesselation/1/post/NonConvexEnvelope.dat

    re5ad5c ree7e25  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H08_ H09_ H11", N=8, E=12, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="test", N=8, E=12, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    449.78209 2.64589 2.64589 0
    559.78209 2.64589 4.42589 0
     
    13131 3 4
    14141 4 7
     154 6 7
    15163 4 5
    16 1 7 8
    17 1 2 8
    18 4 6 7
     174 5 6
    19182 3 5
    20 4 5 6
    21 6 7 8
    22 1 2 3
    23192 5 8
    24205 6 8
     216 7 8
     222 7 8
     231 2 7
     241 2 3
  • tests/regression/Tesselation/1/post/NonConvexEnvelope.r3d

    re5ad5c ree7e25  
    3434  1.37419 -0.89433 -0.89        0.12489 1.24767 -0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
    35351
    36   2.26414 0.364321 -4.44089e-16         0.12489 1.24767 -0.89   0.12489 1.24767 0.89    1. 0. 0.
    37 1
    38   1.37419 -0.89433 -0.89        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    39 1
    40   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 0.89  1. 0. 0.
    41 1
    4236  0.12489 1.24767 -0.89         -2.01426 0.364321 -4.44089e-16  -1.12431 -0.89433 -0.89         1. 0. 0.
    43371
    44   1.37419 -0.89433 0.89         2.26414 0.364321 -4.44089e-16   0.12489 1.24767 0.89    1. 0. 0.
     38  2.26414 0.364321 -4.44089e-16         0.12489 1.24767 -0.89   0.12489 1.24767 0.89    1. 0. 0.
    45391
    4640  0.12489 1.24767 -0.89         0.12489 1.24767 0.89    -2.01426 0.364321 -4.44089e-16  1. 0. 0.
    47411
    48   -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    49 1
    50   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
     42  1.37419 -0.89433 0.89         2.26414 0.364321 -4.44089e-16   0.12489 1.24767 0.89    1. 0. 0.
    51431
    5244  1.37419 -0.89433 0.89         0.12489 1.24767 0.89    -1.12431 -0.89433 0.89  1. 0. 0.
    53451
    5446  0.12489 1.24767 0.89  -2.01426 0.364321 -4.44089e-16  -1.12431 -0.89433 0.89  1. 0. 0.
     471
     48  -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
     491
     50  1.37419 -0.89433 0.89         -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
     511
     52  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
     531
     54  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
    55559
    5656#  terminating special property
     
    5959  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0
    60602
    61   -1.00456 0.23922 0.593333     5       1 0 0
     61  1.67084 -0.47478 -8.88178e-16 5       1 0 0
    62629
    6363  terminating special property
  • tests/regression/Tesselation/2/post/ConvexEnvelope.dat

    re5ad5c ree7e25  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H08_ H09_ H11", N=8, E=12, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="test", N=8, E=12, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    449.78209 2.64589 2.64589 0
    559.78209 2.64589 4.42589 0
     
    13131 3 4
    14141 4 7
     154 6 7
    15163 4 5
    16 1 7 8
    17 1 2 8
    18 4 6 7
     174 5 6
    19182 3 5
    20 4 5 6
    21 6 7 8
    22 1 2 3
    23192 5 8
    24205 6 8
     216 7 8
     222 7 8
     231 2 7
     241 2 3
  • tests/regression/Tesselation/2/post/ConvexEnvelope.r3d

    re5ad5c ree7e25  
    3434  1.37419 -0.89433 -0.89        0.12489 1.24767 -0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
    35351
    36   2.26414 0.364321 -4.44089e-16         0.12489 1.24767 -0.89   0.12489 1.24767 0.89    1. 0. 0.
    37 1
    38   1.37419 -0.89433 -0.89        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    39 1
    40   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 0.89  1. 0. 0.
    41 1
    4236  0.12489 1.24767 -0.89         -2.01426 0.364321 -4.44089e-16  -1.12431 -0.89433 -0.89         1. 0. 0.
    43371
    44   1.37419 -0.89433 0.89         2.26414 0.364321 -4.44089e-16   0.12489 1.24767 0.89    1. 0. 0.
     38  2.26414 0.364321 -4.44089e-16         0.12489 1.24767 -0.89   0.12489 1.24767 0.89    1. 0. 0.
    45391
    4640  0.12489 1.24767 -0.89         0.12489 1.24767 0.89    -2.01426 0.364321 -4.44089e-16  1. 0. 0.
    47411
    48   -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    49 1
    50   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
     42  1.37419 -0.89433 0.89         2.26414 0.364321 -4.44089e-16   0.12489 1.24767 0.89    1. 0. 0.
    51431
    5244  1.37419 -0.89433 0.89         0.12489 1.24767 0.89    -1.12431 -0.89433 0.89  1. 0. 0.
    53451
    5446  0.12489 1.24767 0.89  -2.01426 0.364321 -4.44089e-16  -1.12431 -0.89433 0.89  1. 0. 0.
     471
     48  -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
     491
     50  1.37419 -0.89433 0.89         -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
     511
     52  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
     531
     54  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
    55559
    5656#  terminating special property
     
    5959  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0
    60602
    61   -1.00456 0.23922 0.593333     5       1 0 0
     61  1.67084 -0.47478 -8.88178e-16 5       1 0 0
    62629
    6363  terminating special property
  • tests/regression/Tesselation/2/post/NonConvexEnvelope.dat

    re5ad5c ree7e25  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H08_ H09_ H11", N=8, E=12, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="test", N=8, E=12, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    449.78209 2.64589 2.64589 0
    559.78209 2.64589 4.42589 0
     
    13131 3 4
    14141 4 7
     154 6 7
    15163 4 5
    16 1 7 8
    17 1 2 8
    18 4 6 7
     174 5 6
    19182 3 5
    20 4 5 6
    21 6 7 8
    22 1 2 3
    23192 5 8
    24205 6 8
     216 7 8
     222 7 8
     231 2 7
     241 2 3
  • tests/regression/Tesselation/2/post/NonConvexEnvelope.r3d

    re5ad5c ree7e25  
    3434  1.37419 -0.89433 -0.89        0.12489 1.24767 -0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
    35351
    36   2.26414 0.364321 -4.44089e-16         0.12489 1.24767 -0.89   0.12489 1.24767 0.89    1. 0. 0.
    37 1
    38   1.37419 -0.89433 -0.89        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    39 1
    40   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 0.89  1. 0. 0.
    41 1
    4236  0.12489 1.24767 -0.89         -2.01426 0.364321 -4.44089e-16  -1.12431 -0.89433 -0.89         1. 0. 0.
    43371
    44   1.37419 -0.89433 0.89         2.26414 0.364321 -4.44089e-16   0.12489 1.24767 0.89    1. 0. 0.
     38  2.26414 0.364321 -4.44089e-16         0.12489 1.24767 -0.89   0.12489 1.24767 0.89    1. 0. 0.
    45391
    4640  0.12489 1.24767 -0.89         0.12489 1.24767 0.89    -2.01426 0.364321 -4.44089e-16  1. 0. 0.
    47411
    48   -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
    49 1
    50   1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
     42  1.37419 -0.89433 0.89         2.26414 0.364321 -4.44089e-16   0.12489 1.24767 0.89    1. 0. 0.
    51431
    5244  1.37419 -0.89433 0.89         0.12489 1.24767 0.89    -1.12431 -0.89433 0.89  1. 0. 0.
    53451
    5446  0.12489 1.24767 0.89  -2.01426 0.364321 -4.44089e-16  -1.12431 -0.89433 0.89  1. 0. 0.
     471
     48  -2.01426 0.364321 -4.44089e-16        -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
     491
     50  1.37419 -0.89433 0.89         -1.12431 -0.89433 -0.89         -1.12431 -0.89433 0.89  1. 0. 0.
     511
     52  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   -1.12431 -0.89433 -0.89         1. 0. 0.
     531
     54  1.37419 -0.89433 -0.89        1.37419 -0.89433 0.89   2.26414 0.364321 -4.44089e-16   1. 0. 0.
    55559
    5656#  terminating special property
     
    5959  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0
    60602
    61   -1.00456 0.23922 0.593333     5       1 0 0
     61  1.67084 -0.47478 -8.88178e-16 5       1 0 0
    62629
    6363  terminating special property
  • tests/regression/Tesselation/3/post/NonConvexEnvelope.dat

    re5ad5c ree7e25  
    11TITLE = "3D CONVEX SHELL"
    22VARIABLES = "X" "Y" "Z" "U"
    3 ZONE T="0- H49_ H50_ H51", N=44, E=86, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
     3ZONE T="test", N=44, E=86, DATAPACKING=POINT, ZONETYPE=FETRIANGLE
    446.9077 1.1106 0.1214 1
    550.3612 -3.628 1.323 1
     
    28282.8131 1.4776 2.5103 0
    29293.9137 2.2936 1.3739 0
    30 2.159 2.5738 1.2698 2
     302.159 2.5738 1.2698 5
    31313.6606 -0.4593 2.1396 2
    32323.2007 -1.4419 0.7311 4
    33 -3.3002 2.3589 0.0094 5
     33-3.3002 2.3589 0.0094 8
    3434-4.377 1.6962 -1.2433 3
    35355.2593 1.4547 -1.7445 0
     
    40405.2727 1.6068 1.2828 2
    4141-6.2394 4.6427 0.0632 0
    42 -4.4738 4.5591 -0.1458 1
     42-4.4738 4.5591 -0.1458 3
    4343-5.5506 3.8964 -1.3985 0
    4444-6.7081 0.9923 0.6224 2
     
    49491 32 44
    50501 32 35
    51 32 33 44
    52511 34 35
    535223 32 35
    54 23 32 33
     5317 23 35
     548 17 35
     558 10 17
     563 8 10
     573 8 35
     583 4 35
     594 29 35
     6029 34 35
     612 3 4
     622 4 29
     632 15 29
     6415 28 29
     6528 29 34
     662 7 15
     677 14 15
     6814 15 28
     6914 25 28
     7025 28 37
     7128 34 37
     721 34 37
     731 37 44
     7425 26 37
     7525 26 27
     7626 27 33
    557726 33 44
    56 1 34 37
    57 29 34 35
    58 17 23 35
    59 18 23 33
    60 26 27 33
    617826 37 44
    62 1 37 44
    63 28 34 37
    64 28 29 34
    65 4 29 35
    66 17 18 23
    67 8 17 35
    68 18 27 33
    69 25 26 27
    70 25 26 37
    71 25 28 37
    72 15 28 29
    73 2 4 29
    74 3 4 35
    75 9 17 18
    76 8 10 17
    77 3 8 35
    78 16 18 27
    797914 25 27
    80 14 25 28
    81 14 15 28
    82 2 15 29
    83 2 3 4
    84 9 10 17
    85 9 18 31
    86 3 8 10
    87 16 18 30
    88 16 27 30
    898014 27 30
    90 7 14 15
    91 2 7 15
    92 2 3 5
    93 9 10 12
    94 9 19 31
    95 18 30 31
    96 3 10 12
    97816 14 30
     826 24 30
     8324 30 36
     8430 36 39
     8527 30 39
     866 7 24
    98876 7 14
    99 2 5 7
    100 3 5 12
    101 9 12 13
    102 9 13 19
    103 13 19 31
    104 30 31 39
    105 6 24 30
    106 6 7 24
    107 5 7 11
    108 5 12 22
    109 12 13 21
    110 13 21 31
    111 27 30 39
    112 31 39 40
    113 24 30 36
    114887 11 24
    115 5 11 22
    116 12 21 22
    117 21 31 43
    118 31 40 43
    119 40 42 43
    120 41 42 43
    121 21 41 43
    122 20 21 41
     8911 20 24
    1239020 24 41
    1249124 36 41
    1259236 41 42
     9311 20 22
     945 11 22
     955 7 11
     962 5 7
     9727 30 39
     9816 27 30
     9916 18 30
     10016 18 27
     10118 27 33
     10218 23 33
     10336 38 39
    12610436 38 42
     10518 30 31
     10630 31 39
     10731 39 40
     1089 18 31
     1099 17 18
     11017 18 23
     1119 19 31
     1129 13 19
     11313 19 31
     11413 21 31
     11521 31 43
     11631 40 43
     1179 12 13
     1189 10 12
     1199 10 17
     12012 13 21
     12112 21 22
     1225 12 22
     1233 5 12
     1242 3 5
     1253 10 12
     12620 21 22
     12720 21 41
     12821 41 43
     12941 42 43
     13023 32 33
     13132 33 44
     13240 42 43
    12713338 40 42
    12813438 39 40
    129 36 38 39
    130 30 36 39
    131 27 30 39
    132 11 20 24
    133 11 20 22
    134 20 21 22
  • tests/regression/Tesselation/3/post/NonConvexEnvelope.r3d

    re5ad5c ree7e25  
    160160  7.33693 1.04442 0.0886712     5.68853 1.38852 -1.77723        5.55043 -0.952879 -0.490929     1. 0. 0.
    1611611
     162  7.33693 1.04442 0.0886712     6.17523 -0.969279 1.17127       5.55043 -0.952879 -0.490929     1. 0. 0.
     1631
     164  3.62023 1.25552 -2.86813      5.68853 1.38852 -1.77723        5.55043 -0.952879 -0.490929     1. 0. 0.
     1651
     166  1.76663 -0.360379 -2.99373    3.62023 1.25552 -2.86813        5.55043 -0.952879 -0.490929     1. 0. 0.
     1671
     168  2.19193 -1.51408 -0.867629    1.76663 -0.360379 -2.99373      5.55043 -0.952879 -0.490929     1. 0. 0.
     1691
     170  2.19193 -1.51408 -0.867629    0.450934 -2.72908 -2.23353      1.76663 -0.360379 -2.99373      1. 0. 0.
     1711
     172  0.917634 -3.66448 -0.484829   2.19193 -1.51408 -0.867629      0.450934 -2.72908 -2.23353      1. 0. 0.
     1731
     174  0.917634 -3.66448 -0.484829   2.19193 -1.51408 -0.867629      5.55043 -0.952879 -0.490929     1. 0. 0.
     1751
     176  0.917634 -3.66448 -0.484829   1.92773 -2.57738 0.498071       5.55043 -0.952879 -0.490929     1. 0. 0.
     1771
     178  1.92773 -2.57738 0.498071     3.62993 -1.50808 0.698371       5.55043 -0.952879 -0.490929     1. 0. 0.
     1791
     180  3.62993 -1.50808 0.698371     6.17523 -0.969279 1.17127       5.55043 -0.952879 -0.490929     1. 0. 0.
     1811
     182  0.790434 -3.69418 1.29027     0.917634 -3.66448 -0.484829     1.92773 -2.57738 0.498071       1. 0. 0.
     1831
     184  0.790434 -3.69418 1.29027     1.92773 -2.57738 0.498071       3.62993 -1.50808 0.698371       1. 0. 0.
     1851
     186  0.790434 -3.69418 1.29027     2.06173 -1.39848 1.79787        3.62993 -1.50808 0.698371       1. 0. 0.
     1871
     188  2.06173 -1.39848 1.79787      4.08983 -0.525479 2.10687       3.62993 -1.50808 0.698371       1. 0. 0.
     1891
     190  4.08983 -0.525479 2.10687     3.62993 -1.50808 0.698371       6.17523 -0.969279 1.17127       1. 0. 0.
     1911
     192  0.790434 -3.69418 1.29027     -0.287266 -1.67078 2.48017      2.06173 -1.39848 1.79787        1. 0. 0.
     1931
     194  -0.287266 -1.67078 2.48017    1.46453 0.112321 2.50927        2.06173 -1.39848 1.79787        1. 0. 0.
     1951
     196  1.46453 0.112321 2.50927      2.06173 -1.39848 1.79787        4.08983 -0.525479 2.10687       1. 0. 0.
     1971
     198  1.46453 0.112321 2.50927      3.24233 1.41142 2.47757         4.08983 -0.525479 2.10687       1. 0. 0.
     1991
     200  3.24233 1.41142 2.47757       4.08983 -0.525479 2.10687       5.70193 1.54062 1.25007         1. 0. 0.
     2011
     202  4.08983 -0.525479 2.10687     6.17523 -0.969279 1.17127       5.70193 1.54062 1.25007         1. 0. 0.
     2031
     204  7.33693 1.04442 0.0886712     6.17523 -0.969279 1.17127       5.70193 1.54062 1.25007         1. 0. 0.
     2051
     206  7.33693 1.04442 0.0886712     5.70193 1.54062 1.25007         7.56833 1.97852 -0.00632877     1. 0. 0.
     2071
     208  3.24233 1.41142 2.47757       4.34293 2.22742 1.34117         5.70193 1.54062 1.25007         1. 0. 0.
     2091
     210  3.24233 1.41142 2.47757       4.34293 2.22742 1.34117         2.58823 2.50762 1.23707         1. 0. 0.
     2111
     212  4.34293 2.22742 1.34117       2.58823 2.50762 1.23707         5.11553 2.70122 -0.710229       1. 0. 0.
     2131
     214  4.34293 2.22742 1.34117       5.11553 2.70122 -0.710229       7.56833 1.97852 -0.00632877     1. 0. 0.
     2151
     216  4.34293 2.22742 1.34117       5.70193 1.54062 1.25007         7.56833 1.97852 -0.00632877     1. 0. 0.
     2171
     218  1.46453 0.112321 2.50927      3.24233 1.41142 2.47757         2.58823 2.50762 1.23707         1. 0. 0.
     2191
     220  1.46453 0.112321 2.50927      2.58823 2.50762 1.23707         -2.87097 2.29272 -0.0233288     1. 0. 0.
     2211
     222  -0.759066 -0.265179 1.48487   1.46453 0.112321 2.50927        -2.87097 2.29272 -0.0233288     1. 0. 0.
     2231
     224  -0.759066 -0.265179 1.48487   -3.66127 0.565021 1.57007       -2.87097 2.29272 -0.0233288     1. 0. 0.
     2251
     226  -3.66127 0.565021 1.57007     -2.87097 2.29272 -0.0233288     -4.83487 2.76522 1.41487        1. 0. 0.
     2271
     228  -2.87097 2.29272 -0.0233288   -4.83487 2.76522 1.41487        -4.04457 4.49292 -0.178529      1. 0. 0.
     2291
     230  2.58823 2.50762 1.23707       -2.87097 2.29272 -0.0233288     -4.04457 4.49292 -0.178529      1. 0. 0.
     2311
     232  -0.759066 -0.265179 1.48487   -0.287266 -1.67078 2.48017      -3.66127 0.565021 1.57007       1. 0. 0.
     2331
     234  -0.759066 -0.265179 1.48487   -0.287266 -1.67078 2.48017      1.46453 0.112321 2.50927        1. 0. 0.
     2351
     236  -0.287266 -1.67078 2.48017    -2.45927 -1.63678 1.72157       -3.66127 0.565021 1.57007       1. 0. 0.
     2371
     238  -2.45927 -1.63678 1.72157     -4.75167 -1.93408 0.935971      -3.66127 0.565021 1.57007       1. 0. 0.
     2391
     240  -4.75167 -1.93408 0.935971    -3.66127 0.565021 1.57007       -6.27887 0.926121 0.589671      1. 0. 0.
     2411
     242  -3.66127 0.565021 1.57007     -4.83487 2.76522 1.41487        -6.27887 0.926121 0.589671      1. 0. 0.
     2431
     244  -4.83487 2.76522 1.41487      -6.27887 0.926121 0.589671      -7.11497 2.49352 0.479071       1. 0. 0.
     2451
     246  -2.45927 -1.63678 1.72157     -4.75167 -1.93408 0.935971      -3.90927 -3.49908 0.839771      1. 0. 0.
     2471
     248  -1.52417 -3.64138 0.503471    -2.45927 -1.63678 1.72157       -3.90927 -3.49908 0.839771      1. 0. 0.
     2491
     250  -1.52417 -3.64138 0.503471    -0.287266 -1.67078 2.48017      -2.45927 -1.63678 1.72157       1. 0. 0.
     2511
     252  0.790434 -3.69418 1.29027     -1.52417 -3.64138 0.503471      -0.287266 -1.67078 2.48017      1. 0. 0.
     2531
     254  2.58823 2.50762 1.23707       -2.87097 2.29272 -0.0233288     -4.04457 4.49292 -0.178529      1. 0. 0.
     2551
     256  1.15633 1.11082 0.326671      2.58823 2.50762 1.23707         -2.87097 2.29272 -0.0233288     1. 0. 0.
     2571
     258  1.15633 1.11082 0.326671      1.03283 1.01972 -2.14533        -2.87097 2.29272 -0.0233288     1. 0. 0.
     2591
     260  1.15633 1.11082 0.326671      1.03283 1.01972 -2.14533        2.58823 2.50762 1.23707         1. 0. 0.
     2611
     262  1.03283 1.01972 -2.14533      2.58823 2.50762 1.23707         5.11553 2.70122 -0.710229       1. 0. 0.
     2631
     264  1.03283 1.01972 -2.14533      3.62023 1.25552 -2.86813        5.11553 2.70122 -0.710229       1. 0. 0.
     2651
     266  -4.83487 2.76522 1.41487      -5.81017 4.57652 0.0304712      -4.04457 4.49292 -0.178529      1. 0. 0.
     2671
     268  -4.83487 2.76522 1.41487      -5.81017 4.57652 0.0304712      -7.11497 2.49352 0.479071       1. 0. 0.
     2691
     270  1.03283 1.01972 -2.14533      -2.87097 2.29272 -0.0233288     -3.94777 1.63002 -1.27603       1. 0. 0.
     2711
     272  -2.87097 2.29272 -0.0233288   -3.94777 1.63002 -1.27603       -4.04457 4.49292 -0.178529      1. 0. 0.
     2731
     274  -3.94777 1.63002 -1.27603     -4.04457 4.49292 -0.178529      -5.12137 3.83022 -1.43123       1. 0. 0.
     2751
     276  -0.573766 -1.42458 -2.91753   1.03283 1.01972 -2.14533        -3.94777 1.63002 -1.27603       1. 0. 0.
     2771
     278  -0.573766 -1.42458 -2.91753   1.76663 -0.360379 -2.99373      1.03283 1.01972 -2.14533        1. 0. 0.
     2791
     280  1.76663 -0.360379 -2.99373    1.03283 1.01972 -2.14533        3.62023 1.25552 -2.86813        1. 0. 0.
     2811
     282  -0.573766 -1.42458 -2.91753   -2.77417 -0.570279 -1.12083     -3.94777 1.63002 -1.27603       1. 0. 0.
     2831
     284  -0.573766 -1.42458 -2.91753   -2.49667 -2.18078 -1.79993      -2.77417 -0.570279 -1.12083     1. 0. 0.
     2851
     286  -2.49667 -2.18078 -1.79993    -2.77417 -0.570279 -1.12083     -3.94777 1.63002 -1.27603       1. 0. 0.
     2871
     288  -2.49667 -2.18078 -1.79993    -4.17327 -2.53828 -0.635229     -3.94777 1.63002 -1.27603       1. 0. 0.
     2891
     290  -4.17327 -2.53828 -0.635229   -3.94777 1.63002 -1.27603       -6.42617 1.74722 -0.982629      1. 0. 0.
     2911
     292  -3.94777 1.63002 -1.27603     -5.12137 3.83022 -1.43123       -6.42617 1.74722 -0.982629      1. 0. 0.
     2931
     294  -0.573766 -1.42458 -2.91753   -1.62867 -3.74268 -1.79493      -2.49667 -2.18078 -1.79993      1. 0. 0.
     2951
     296  -0.573766 -1.42458 -2.91753   0.450934 -2.72908 -2.23353      -1.62867 -3.74268 -1.79493      1. 0. 0.
     2971
     298  -0.573766 -1.42458 -2.91753   0.450934 -2.72908 -2.23353      1.76663 -0.360379 -2.99373      1. 0. 0.
     2991
     300  -1.62867 -3.74268 -1.79493    -2.49667 -2.18078 -1.79993      -4.17327 -2.53828 -0.635229     1. 0. 0.
     3011
     302  -1.62867 -3.74268 -1.79493    -4.17327 -2.53828 -0.635229     -3.90927 -3.49908 0.839771      1. 0. 0.
     3031
     304  -1.52417 -3.64138 0.503471    -1.62867 -3.74268 -1.79493      -3.90927 -3.49908 0.839771      1. 0. 0.
     3051
     306  0.917634 -3.66448 -0.484829   -1.52417 -3.64138 0.503471      -1.62867 -3.74268 -1.79493      1. 0. 0.
     3071
     308  0.790434 -3.69418 1.29027     0.917634 -3.66448 -0.484829     -1.52417 -3.64138 0.503471      1. 0. 0.
     3091
     310  0.917634 -3.66448 -0.484829   0.450934 -2.72908 -2.23353      -1.62867 -3.74268 -1.79493      1. 0. 0.
     3111
     312  -4.75167 -1.93408 0.935971    -4.17327 -2.53828 -0.635229     -3.90927 -3.49908 0.839771      1. 0. 0.
     3131
     314  -4.75167 -1.93408 0.935971    -4.17327 -2.53828 -0.635229     -6.27887 0.926121 0.589671      1. 0. 0.
     3151
     316  -4.17327 -2.53828 -0.635229   -6.27887 0.926121 0.589671      -6.42617 1.74722 -0.982629      1. 0. 0.
     3171
     318  -6.27887 0.926121 0.589671    -7.11497 2.49352 0.479071       -6.42617 1.74722 -0.982629      1. 0. 0.
     3191
     320  3.62023 1.25552 -2.86813      5.68853 1.38852 -1.77723        5.11553 2.70122 -0.710229       1. 0. 0.
     3211
    162322  5.68853 1.38852 -1.77723      5.11553 2.70122 -0.710229       7.56833 1.97852 -0.00632877     1. 0. 0.
    1633231
    164   7.33693 1.04442 0.0886712     6.17523 -0.969279 1.17127       5.55043 -0.952879 -0.490929     1. 0. 0.
    165 1
    166   3.62023 1.25552 -2.86813      5.68853 1.38852 -1.77723        5.55043 -0.952879 -0.490929     1. 0. 0.
    167 1
    168   3.62023 1.25552 -2.86813      5.68853 1.38852 -1.77723        5.11553 2.70122 -0.710229       1. 0. 0.
    169 1
    170   4.34293 2.22742 1.34117       5.11553 2.70122 -0.710229       7.56833 1.97852 -0.00632877     1. 0. 0.
    171 1
    172   7.33693 1.04442 0.0886712     6.17523 -0.969279 1.17127       5.70193 1.54062 1.25007         1. 0. 0.
    173 1
    174   3.62993 -1.50808 0.698371     6.17523 -0.969279 1.17127       5.55043 -0.952879 -0.490929     1. 0. 0.
    175 1
    176   1.76663 -0.360379 -2.99373    3.62023 1.25552 -2.86813        5.55043 -0.952879 -0.490929     1. 0. 0.
    177 1
    178   1.03283 1.01972 -2.14533      3.62023 1.25552 -2.86813        5.11553 2.70122 -0.710229       1. 0. 0.
    179 1
    180   4.34293 2.22742 1.34117       2.58823 2.50762 1.23707         5.11553 2.70122 -0.710229       1. 0. 0.
    181 1
    182   4.34293 2.22742 1.34117       5.70193 1.54062 1.25007         7.56833 1.97852 -0.00632877     1. 0. 0.
    183 1
    184   7.33693 1.04442 0.0886712     5.70193 1.54062 1.25007         7.56833 1.97852 -0.00632877     1. 0. 0.
    185 1
    186   4.08983 -0.525479 2.10687     6.17523 -0.969279 1.17127       5.70193 1.54062 1.25007         1. 0. 0.
    187 1
    188   4.08983 -0.525479 2.10687     3.62993 -1.50808 0.698371       6.17523 -0.969279 1.17127       1. 0. 0.
    189 1
    190   1.92773 -2.57738 0.498071     3.62993 -1.50808 0.698371       5.55043 -0.952879 -0.490929     1. 0. 0.
    191 1
    192   1.76663 -0.360379 -2.99373    1.03283 1.01972 -2.14533        3.62023 1.25552 -2.86813        1. 0. 0.
    193 1
    194   2.19193 -1.51408 -0.867629    1.76663 -0.360379 -2.99373      5.55043 -0.952879 -0.490929     1. 0. 0.
    195 1
    196   1.03283 1.01972 -2.14533      2.58823 2.50762 1.23707         5.11553 2.70122 -0.710229       1. 0. 0.
    197 1
    198   3.24233 1.41142 2.47757       4.34293 2.22742 1.34117         2.58823 2.50762 1.23707         1. 0. 0.
    199 1
    200   3.24233 1.41142 2.47757       4.34293 2.22742 1.34117         5.70193 1.54062 1.25007         1. 0. 0.
    201 1
    202   3.24233 1.41142 2.47757       4.08983 -0.525479 2.10687       5.70193 1.54062 1.25007         1. 0. 0.
    203 1
    204   2.06173 -1.39848 1.79787      4.08983 -0.525479 2.10687       3.62993 -1.50808 0.698371       1. 0. 0.
    205 1
    206   0.790434 -3.69418 1.29027     1.92773 -2.57738 0.498071       3.62993 -1.50808 0.698371       1. 0. 0.
    207 1
    208   0.917634 -3.66448 -0.484829   1.92773 -2.57738 0.498071       5.55043 -0.952879 -0.490929     1. 0. 0.
    209 1
    210   -0.573766 -1.42458 -2.91753   1.76663 -0.360379 -2.99373      1.03283 1.01972 -2.14533        1. 0. 0.
    211 1
    212   2.19193 -1.51408 -0.867629    0.450934 -2.72908 -2.23353      1.76663 -0.360379 -2.99373      1. 0. 0.
    213 1
    214   0.917634 -3.66448 -0.484829   2.19193 -1.51408 -0.867629      5.55043 -0.952879 -0.490929     1. 0. 0.
    215 1
    216   1.15633 1.11082 0.326671      1.03283 1.01972 -2.14533        2.58823 2.50762 1.23707         1. 0. 0.
    217 1
    218   1.46453 0.112321 2.50927      3.24233 1.41142 2.47757         2.58823 2.50762 1.23707         1. 0. 0.
    219 1
    220   1.46453 0.112321 2.50927      3.24233 1.41142 2.47757         4.08983 -0.525479 2.10687       1. 0. 0.
    221 1
    222   1.46453 0.112321 2.50927      2.06173 -1.39848 1.79787        4.08983 -0.525479 2.10687       1. 0. 0.
    223 1
    224   0.790434 -3.69418 1.29027     2.06173 -1.39848 1.79787        3.62993 -1.50808 0.698371       1. 0. 0.
    225 1
    226   0.790434 -3.69418 1.29027     0.917634 -3.66448 -0.484829     1.92773 -2.57738 0.498071       1. 0. 0.
    227 1
    228   -0.573766 -1.42458 -2.91753   0.450934 -2.72908 -2.23353      1.76663 -0.360379 -2.99373      1. 0. 0.
    229 1
    230   -0.573766 -1.42458 -2.91753   1.03283 1.01972 -2.14533        -3.94777 1.63002 -1.27603       1. 0. 0.
    231 1
    232   0.917634 -3.66448 -0.484829   2.19193 -1.51408 -0.867629      0.450934 -2.72908 -2.23353      1. 0. 0.
    233 1
    234   1.15633 1.11082 0.326671      1.03283 1.01972 -2.14533        -2.87097 2.29272 -0.0233288     1. 0. 0.
    235 1
    236   1.15633 1.11082 0.326671      2.58823 2.50762 1.23707         -2.87097 2.29272 -0.0233288     1. 0. 0.
    237 1
    238   1.46453 0.112321 2.50927      2.58823 2.50762 1.23707         -2.87097 2.29272 -0.0233288     1. 0. 0.
    239 1
    240   -0.287266 -1.67078 2.48017    1.46453 0.112321 2.50927        2.06173 -1.39848 1.79787        1. 0. 0.
    241 1
    242   0.790434 -3.69418 1.29027     -0.287266 -1.67078 2.48017      2.06173 -1.39848 1.79787        1. 0. 0.
    243 1
    244   0.790434 -3.69418 1.29027     0.917634 -3.66448 -0.484829     -1.52417 -3.64138 0.503471      1. 0. 0.
    245 1
    246   -0.573766 -1.42458 -2.91753   0.450934 -2.72908 -2.23353      -1.62867 -3.74268 -1.79493      1. 0. 0.
    247 1
    248   -0.573766 -1.42458 -2.91753   -2.77417 -0.570279 -1.12083     -3.94777 1.63002 -1.27603       1. 0. 0.
    249 1
    250   1.03283 1.01972 -2.14533      -2.87097 2.29272 -0.0233288     -3.94777 1.63002 -1.27603       1. 0. 0.
    251 1
    252   0.917634 -3.66448 -0.484829   0.450934 -2.72908 -2.23353      -1.62867 -3.74268 -1.79493      1. 0. 0.
    253 1
    254   -0.759066 -0.265179 1.48487   1.46453 0.112321 2.50927        -2.87097 2.29272 -0.0233288     1. 0. 0.
    255 1
    256   -0.759066 -0.265179 1.48487   -0.287266 -1.67078 2.48017      1.46453 0.112321 2.50927        1. 0. 0.
    257 1
    258   0.790434 -3.69418 1.29027     -1.52417 -3.64138 0.503471      -0.287266 -1.67078 2.48017      1. 0. 0.
    259 1
    260   0.917634 -3.66448 -0.484829   -1.52417 -3.64138 0.503471      -1.62867 -3.74268 -1.79493      1. 0. 0.
    261 1
    262   -0.573766 -1.42458 -2.91753   -1.62867 -3.74268 -1.79493      -2.49667 -2.18078 -1.79993      1. 0. 0.
    263 1
    264   -0.573766 -1.42458 -2.91753   -2.49667 -2.18078 -1.79993      -2.77417 -0.570279 -1.12083     1. 0. 0.
    265 1
    266   -2.49667 -2.18078 -1.79993    -2.77417 -0.570279 -1.12083     -3.94777 1.63002 -1.27603       1. 0. 0.
    267 1
    268   -2.87097 2.29272 -0.0233288   -3.94777 1.63002 -1.27603       -4.04457 4.49292 -0.178529      1. 0. 0.
    269 1
    270   -0.759066 -0.265179 1.48487   -3.66127 0.565021 1.57007       -2.87097 2.29272 -0.0233288     1. 0. 0.
    271 1
    272   -0.759066 -0.265179 1.48487   -0.287266 -1.67078 2.48017      -3.66127 0.565021 1.57007       1. 0. 0.
    273 1
    274   -1.52417 -3.64138 0.503471    -0.287266 -1.67078 2.48017      -2.45927 -1.63678 1.72157       1. 0. 0.
    275 1
    276   -1.52417 -3.64138 0.503471    -1.62867 -3.74268 -1.79493      -3.90927 -3.49908 0.839771      1. 0. 0.
    277 1
    278   -1.62867 -3.74268 -1.79493    -2.49667 -2.18078 -1.79993      -4.17327 -2.53828 -0.635229     1. 0. 0.
    279 1
    280   -2.49667 -2.18078 -1.79993    -4.17327 -2.53828 -0.635229     -3.94777 1.63002 -1.27603       1. 0. 0.
    281 1
    282   2.58823 2.50762 1.23707       -2.87097 2.29272 -0.0233288     -4.04457 4.49292 -0.178529      1. 0. 0.
    283 1
    284   -3.94777 1.63002 -1.27603     -4.04457 4.49292 -0.178529      -5.12137 3.83022 -1.43123       1. 0. 0.
    285 1
    286   -3.66127 0.565021 1.57007     -2.87097 2.29272 -0.0233288     -4.83487 2.76522 1.41487        1. 0. 0.
    287 1
    288   -0.287266 -1.67078 2.48017    -2.45927 -1.63678 1.72157       -3.66127 0.565021 1.57007       1. 0. 0.
    289 1
    290   -1.52417 -3.64138 0.503471    -2.45927 -1.63678 1.72157       -3.90927 -3.49908 0.839771      1. 0. 0.
    291 1
    292   -1.62867 -3.74268 -1.79493    -4.17327 -2.53828 -0.635229     -3.90927 -3.49908 0.839771      1. 0. 0.
    293 1
    294   -4.17327 -2.53828 -0.635229   -3.94777 1.63002 -1.27603       -6.42617 1.74722 -0.982629      1. 0. 0.
    295 1
    296   -3.94777 1.63002 -1.27603     -5.12137 3.83022 -1.43123       -6.42617 1.74722 -0.982629      1. 0. 0.
    297 1
    298324  -5.12137 3.83022 -1.43123     -7.11497 2.49352 0.479071       -6.42617 1.74722 -0.982629      1. 0. 0.
    2993251
    300   -6.27887 0.926121 0.589671    -7.11497 2.49352 0.479071       -6.42617 1.74722 -0.982629      1. 0. 0.
    301 1
    302   -4.17327 -2.53828 -0.635229   -6.27887 0.926121 0.589671      -6.42617 1.74722 -0.982629      1. 0. 0.
    303 1
    304   -4.75167 -1.93408 0.935971    -4.17327 -2.53828 -0.635229     -6.27887 0.926121 0.589671      1. 0. 0.
    305 1
    306   -4.75167 -1.93408 0.935971    -3.66127 0.565021 1.57007       -6.27887 0.926121 0.589671      1. 0. 0.
    307 1
    308   -3.66127 0.565021 1.57007     -4.83487 2.76522 1.41487        -6.27887 0.926121 0.589671      1. 0. 0.
    309 1
    310   -4.83487 2.76522 1.41487      -6.27887 0.926121 0.589671      -7.11497 2.49352 0.479071       1. 0. 0.
    311 1
    312   -4.83487 2.76522 1.41487      -5.81017 4.57652 0.0304712      -7.11497 2.49352 0.479071       1. 0. 0.
    313 1
    314326  -5.81017 4.57652 0.0304712    -5.12137 3.83022 -1.43123       -7.11497 2.49352 0.479071       1. 0. 0.
    3153271
    316328  -5.81017 4.57652 0.0304712    -4.04457 4.49292 -0.178529      -5.12137 3.83022 -1.43123       1. 0. 0.
    317 1
    318   -4.83487 2.76522 1.41487      -5.81017 4.57652 0.0304712      -4.04457 4.49292 -0.178529      1. 0. 0.
    319 1
    320   -2.87097 2.29272 -0.0233288   -4.83487 2.76522 1.41487        -4.04457 4.49292 -0.178529      1. 0. 0.
    321 1
    322   2.58823 2.50762 1.23707       -2.87097 2.29272 -0.0233288     -4.04457 4.49292 -0.178529      1. 0. 0.
    323 1
    324   -2.45927 -1.63678 1.72157     -4.75167 -1.93408 0.935971      -3.66127 0.565021 1.57007       1. 0. 0.
    325 1
    326   -2.45927 -1.63678 1.72157     -4.75167 -1.93408 0.935971      -3.90927 -3.49908 0.839771      1. 0. 0.
    327 1
    328   -4.75167 -1.93408 0.935971    -4.17327 -2.53828 -0.635229     -3.90927 -3.49908 0.839771      1. 0. 0.
    3293299
    330330#  terminating special property
     
    333333  25.0    0.6     -1.0 -1.0 -1.0     0.2        0 0 0 0
    3343342
    335   -4.27807 -2.65715 0.380171    5       1 0 0
     335  -4.99203 4.29989 -0.526429    5       1 0 0
    3363369
    337337  terminating special property
  • tests/testsuite.at

    re5ad5c ree7e25  
    1212AT_CHECK([pwd],[ignore],[ignore])
    1313AT_CHECK([../../molecuilder -v], 0, [stdout], [ignore])
    14 AT_CHECK([fgrep molecuilder stdout], 0, [ignore], [ignore])
     14AT_CHECK([fgrep olecuilder stdout], 0, [ignore], [ignore])
    1515AT_CHECK([../../molecuilder -h], 0, [stdout], [ignore])
    1616AT_CHECK([fgrep "Give this help screen" stdout], 0, [ignore], [ignore])
    17 AT_CHECK([../../molecuilder -e], 0, [ignore], [stderr])
     17AT_CHECK([../../molecuilder -e], 255, [ignore], [stderr])
    1818AT_CHECK([fgrep "Not enough or invalid arguments" stderr], 0, [ignore], [ignore])
    1919AT_CHECK([../../molecuilder test.conf], 0, [stdout], [stderr])
     
    7878AT_SETUP([Simple configuration - invalid commands on present configs])
    7979AT_CHECK([/bin/cp -f ${abs_top_srcdir}/${AUTOTEST_PATH}/regression/Simple_configuration/7/pre/test.conf .], 0)
    80 AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -t -s -b -E -c -b -a -U -T -u], 255, [ignore], [stderr])
    81 AT_CHECK([fgrep -c "Not enough or invalid" stderr], 0, [9
    82 ], [ignore])
     80AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -t], 255, [ignore], [stderr])
     81AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     82AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -s -b -E -c -b -a -U -T -u], 255, [ignore], [stderr])
     83AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     84AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -b -E -c -b -a -U -T -u], 255, [ignore], [stderr])
     85AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     86AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -E -c -b -a -U -T -u], 255, [ignore], [stderr])
     87AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     88AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -c -b -a -U -T -u], 255, [ignore], [stderr])
     89AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     90AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -b -a -U -T -u], 255, [ignore], [stderr])
     91AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     92AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -a -U -T -u], 255, [ignore], [stderr])
     93AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     94AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -U -T -u], 255, [ignore], [stderr])
     95AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     96AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -T -u], 255, [ignore], [stderr])
     97AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
     98AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -u], 255, [ignore], [stderr])
     99AT_CHECK([fgrep -c "CRITICAL: Not enough or invalid" stderr], 0, [ignore], [ignore])
    83100AT_CLEANUP
    84101
     
    88105AT_SETUP([Graph - DFS analysis])
    89106AT_CHECK([/bin/cp -f ${abs_top_srcdir}/${AUTOTEST_PATH}/regression/Graph/1/pre/test.conf .], 0)
    90 AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -D 2.], 0, [stdout], [stderr])
     107AT_CHECK([../../molecuilder test.conf -e ${abs_top_srcdir}/src/ -vvv -D 2.], 0, [stdout], [stderr])
    91108AT_CHECK([fgrep -c "No rings were detected in the molecular structure." stdout], 0, [1
    92109], [ignore])
     
    134151AT_CHECK([file=ConvexEnvelope.dat; diff $file ${abs_top_srcdir}/${AUTOTEST_PATH}/regression/Tesselation/2/post/$file], 0, [ignore], [ignore])
    135152AT_CHECK([file=ConvexEnvelope.r3d; diff $file ${abs_top_srcdir}/${AUTOTEST_PATH}/regression/Tesselation/2/post/$file], 0, [ignore], [ignore])
    136 AT_CHECK([fgrep "RESULT: The summed volume is 16.401577 angstrom^3" stdout], 0, [ignore], [ignore])
     153AT_CHECK([fgrep "tesselated volume area is 16.4016 angstrom^3" stdout], 0, [ignore], [ignore])
    137154AT_CHECK([diff ConvexEnvelope.dat NonConvexEnvelope.dat], 0, [ignore], [ignore])
    138155AT_CLEANUP
     
    152169#AT_CHECK([file=ConvexEnvelope.dat; diff $file ${abs_top_srcdir}/${AUTOTEST_PATH}/regression/Tesselation/4/post/$file], 0, [ignore], [ignore])
    153170#AT_CHECK([file=ConvexEnvelope.r3d; diff $file ${abs_top_srcdir}/${AUTOTEST_PATH}/regression/Tesselation/4/post/$file], 0, [ignore], [ignore])
    154 #AT_CHECK([fgrep "RESULT: The summed volume is 16.401577 angstrom^3" stdout], 0, [ignore], [ignore])
     171#AT_CHECK([fgrep "tesselated volume area is 16.4016 angstrom^3" stdout], 0, [ignore], [ignore])
    155172#AT_CLEANUP
    156173
Note: See TracChangeset for help on using the changeset viewer.