Changes in / [edb93c:ab1932]


Ignore:
Location:
src
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • src/atom.cpp

    redb93c rab1932  
    113113};
    114114
    115 ostream & operator << (ostream &ost, const atom &a) 
     115ostream & operator << (ostream &ost, const atom &a)
    116116{
    117117  ost << "[" << a.Name << "|" << &a << "]";
     
    123123 * \return true - this one's is smaller, false - not
    124124 */
    125 bool atom::Compare(atom &ptr)
     125bool atom::Compare(const atom &ptr)
    126126{
    127127  if (nr < ptr.nr)
  • src/atom.hpp

    redb93c rab1932  
    5454  bool OutputXYZLine(ofstream *out) const;
    5555  atom *GetTrueFather();
    56   bool Compare(atom &ptr);
     56  bool Compare(const atom &ptr);
    5757
    5858  private:
  • src/boundary.cpp

    redb93c rab1932  
    739739  FillerDistance.InverseMatrixMultiplication(M);
    740740  for(int i=0;i<NDIM;i++)
    741     N[i] = ceil(1./FillerDistance.x[i]);
     741    N[i] = (int) ceil(1./FillerDistance.x[i]);
    742742
    743743  // go over [0,1]^3 filler grid
     
    813813  return Filling;
    814814};
     815
    815816
    816817/** Tesselates the non convex boundary by rolling a virtual sphere along the surface of the molecule.
     
    956957    cout << Verbose(2) << "None." << endl;
    957958
     959  // Tests the IsInnerAtom() function.
     960  Vector x (0, 0, 0);
     961  cout << Verbose(0) << "Point to check: " << x << endl;
     962  cout << Verbose(0) << "Check: IsInnerPoint() returns " << IsInnerPoint(x, Tess, LCList)
     963    << "for vector " << x << "." << endl;
     964  TesselPoint* a = Tess->PointsOnBoundary.begin()->second->node;
     965  cout << Verbose(0) << "Point to check: " << *a << " (on boundary)." << endl;
     966  cout << Verbose(0) << "Check: IsInnerAtom() returns " << IsInnerPoint(a, Tess, LCList)
     967    << "for atom " << a << " (on boundary)." << endl;
     968  LinkedNodes *List = NULL;
     969  for (int i=0;i<NDIM;i++) { // each axis
     970    LCList->n[i] = LCList->N[i]-1; // current axis is topmost cell
     971    for (LCList->n[(i+1)%NDIM]=0;LCList->n[(i+1)%NDIM]<LCList->N[(i+1)%NDIM];LCList->n[(i+1)%NDIM]++)
     972      for (LCList->n[(i+2)%NDIM]=0;LCList->n[(i+2)%NDIM]<LCList->N[(i+2)%NDIM];LCList->n[(i+2)%NDIM]++) {
     973        List = LCList->GetCurrentCell();
     974        //cout << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;
     975        if (List != NULL) {
     976          for (LinkedNodes::iterator Runner = List->begin();Runner != List->end();Runner++) {
     977            if (Tess->PointsOnBoundary.find((*Runner)->nr) == Tess->PointsOnBoundary.end()) {
     978              a = *Runner;
     979              i=3;
     980              for (int j=0;j<NDIM;j++)
     981                LCList->n[j] = LCList->N[j];
     982              break;
     983            }
     984          }
     985        }
     986      }
     987  }
     988  cout << Verbose(0) << "Check: IsInnerPoint() returns " << IsInnerPoint(a, Tess, LCList)
     989    << "for atom " << a << " (inside)." << endl;
     990
     991
    958992  if (freeTess)
    959993    delete(Tess);
  • src/linkedcell.cpp

    redb93c rab1932  
    147147 * \return if the atom is also found in this cell - true, else - false
    148148 */
    149 bool LinkedCell::SetIndexToNode(TesselPoint *Walker)
     149bool LinkedCell::SetIndexToNode(const TesselPoint *Walker)
    150150{
    151151  bool status = false;
     
    164164};
    165165
     166/** Calculates the interval bounds of the linked cell grid.
     167 * \param *lower lower bounds
     168 * \param *upper upper bounds
     169 */
     170void LinkedCell::GetNeighbourBounds(int lower[NDIM], int upper[NDIM])
     171{
     172  for (int i=0;i<NDIM;i++) {
     173    lower[i] = ((n[i]-1) >= 0) ? n[i]-1 : 0;
     174    upper[i] = ((n[i]+1) < N[i]) ? n[i]+1 : N[i]-1;
     175    //cout << " [" << Nlower[i] << "," << Nupper[i] << "] ";
     176    // check for this axis whether the point is outside of our grid
     177    if (n[i] < 0)
     178      upper[i] = lower[i];
     179    if (n[i] > N[i])
     180      lower[i] = upper[i];
     181
     182    //cout << "axis " << i << " has bounds [" << lower[i] << "," << upper[i] << "]" << endl;
     183  }
     184};
     185
    166186/** Calculates the index for a given Vector *x.
    167187 * \param *x Vector with coordinates
    168188 * \return Vector is inside bounding box - true, else - false
    169189 */
    170 bool LinkedCell::SetIndexToVector(Vector *x)
     190bool LinkedCell::SetIndexToVector(const Vector *x)
    171191{
    172192  bool status = true;
  • src/linkedcell.hpp

    redb93c rab1932  
    4646    ~LinkedCell();
    4747    LinkedNodes* GetCurrentCell();
    48     bool SetIndexToNode(TesselPoint *Walker);
    49     bool SetIndexToVector(Vector *x);
     48    bool SetIndexToNode(const TesselPoint *Walker);
     49    bool SetIndexToVector(const Vector *x);
    5050    bool CheckBounds();
     51    void GetNeighbourBounds(int lower[NDIM], int upper[NDIM]);
    5152
    5253    // not implemented yet
  • src/molecules.hpp

    redb93c rab1932  
    104104  element *type;
    105105};
    106 
    107106
    108107#define MaxThermostats 6      //!< maximum number of thermostat entries in Ions#ThermostatNames and Ions#ThermostatImplemented
     
    140139
    141140  molecule(periodentafel *teil);
    142   ~molecule();
     141  virtual ~molecule();
    143142
    144143  // re-definition of virtual functions from PointCloud
  • src/parser.hpp

    redb93c rab1932  
    5555 
    5656  MatrixContainer();
    57   ~MatrixContainer();
     57  virtual ~MatrixContainer();
    5858 
    5959  bool InitialiseIndices(class MatrixContainer *Matrix = NULL);
  • src/tesselation.cpp

    redb93c rab1932  
    16931693  CirclePlaneNormal.SubtractVector(BaseLine->endpoints[1]->node->node);
    16941694
    1695   // calculate squared radius atom *ThirdNode,f circle
     1695  // calculate squared radius TesselPoint *ThirdNode,f circle
    16961696  radius = CirclePlaneNormal.ScalarProduct(&CirclePlaneNormal);
    16971697  if (radius/4. < RADIUS*RADIUS) {
     
    19141914/** Sort function for the candidate list.
    19151915 */
    1916 bool sortCandidates(CandidateForTesselation* candidate1, CandidateForTesselation* candidate2) {
     1916bool sortCandidates(CandidateForTesselation* candidate1, CandidateForTesselation* candidate2)
     1917{
    19171918  Vector BaseLineVector, OrthogonalVector, helper;
    19181919  if (candidate1->BaseLine != candidate2->BaseLine) {  // sanity check
     
    19541955  return phi < psi;
    19551956};
     1957
     1958
     1959/**
     1960 * Checks whether the provided atom is within the tesselation structure.
     1961 *
     1962 * @param *Atom of which to check the position
     1963 * @param tesselation structure
     1964 *
     1965 * @return true if the atom is inside the tesselation structure, false otherwise
     1966 */
     1967bool IsInnerPoint(TesselPoint *Atom, class Tesselation *Tess, LinkedCell* LC)
     1968{
     1969  if (Tess->LinesOnBoundary.begin() == Tess->LinesOnBoundary.end()) {
     1970    cout << Verbose(0) << "Error: There is no tesselation structure to compare the point with, "
     1971        << "please create one first.";
     1972    exit(1);
     1973  }
     1974
     1975  class TesselPoint *trianglePoints[3];
     1976  trianglePoints[0] = findClosestAtom(Atom, LC);
     1977  // check whether closest atom is "too close" :), then it's inside
     1978  if (trianglePoints[0]->node->DistanceSquared(Atom->node) < MYEPSILON)
     1979    return true;
     1980  list<TesselPoint*> *connectedClosestPoints = Tess->getClosestConnectedAtoms(trianglePoints[0], Atom);
     1981  trianglePoints[1] = connectedClosestPoints->front();
     1982  trianglePoints[2] = connectedClosestPoints->back();
     1983  for (int i=0;i<3;i++) {
     1984    if (trianglePoints[i] == NULL) {
     1985      cout << Verbose(1) << "IsInnerPoint encounters serious error, point " << i << " not found." << endl;
     1986    }
     1987
     1988    cout << Verbose(1) << "List of possible atoms:" << endl;
     1989    cout << *trianglePoints[i] << endl;
     1990
     1991//    for(list<TesselPoint*>::iterator runner = connectedClosestPoints->begin(); runner != connectedClosestPoints->end(); runner++)
     1992//      cout << Verbose(2) << *(*runner) << endl;
     1993  }
     1994  delete(connectedClosestPoints);
     1995
     1996  list<BoundaryTriangleSet*> *triangles = Tess->FindTriangles(trianglePoints);
     1997
     1998  if (triangles->empty()) {
     1999    cout << Verbose(0) << "Error: There is no nearest triangle. Please check the tesselation structure.";
     2000    exit(1);
     2001  }
     2002
     2003  Vector helper;
     2004  helper.CopyVector(Atom->node);
     2005
     2006  // Only in case of degeneration, there will be two different scalar products.
     2007  // If at least one scalar product is positive, the point is considered to be outside.
     2008  bool status = (helper.ScalarProduct(&triangles->front()->NormalVector) < 0)
     2009      && (helper.ScalarProduct(&triangles->back()->NormalVector) < 0);
     2010  delete(triangles);
     2011  return status;
     2012}
     2013
     2014/**
     2015 * Finds the atom which is closest to the provided one.
     2016 *
     2017 * @param atom to which to find the closest other atom
     2018 * @param linked cell structure
     2019 *
     2020 * @return atom which is closest to the provided one
     2021 */
     2022TesselPoint* findClosestAtom(const TesselPoint* Atom, LinkedCell* LC)
     2023{
     2024  LinkedNodes *List = NULL;
     2025  TesselPoint* closestAtom = NULL;
     2026  double distance = 1e16;
     2027  Vector helper;
     2028  int N[NDIM], Nlower[NDIM], Nupper[NDIM];
     2029
     2030  LC->SetIndexToVector(Atom->node); // ignore status as we calculate bounds below sensibly
     2031  for(int i=0;i<NDIM;i++) // store indices of this cell
     2032    N[i] = LC->n[i];
     2033  //cout << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;
     2034
     2035  LC->GetNeighbourBounds(Nlower, Nupper);
     2036  //cout << endl;
     2037  for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)
     2038    for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)
     2039      for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {
     2040        List = LC->GetCurrentCell();
     2041        //cout << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;
     2042        if (List != NULL) {
     2043          for (LinkedNodes::iterator Runner = List->begin(); Runner != List->end(); Runner++) {
     2044            helper.CopyVector(Atom->node);
     2045            helper.SubtractVector((*Runner)->node);
     2046            double currentNorm = helper. Norm();
     2047            if (currentNorm < distance) {
     2048              distance = currentNorm;
     2049              closestAtom = (*Runner);
     2050            }
     2051          }
     2052        } else {
     2053          cerr << "ERROR: The current cell " << LC->n[0] << "," << LC->n[1] << ","
     2054            << LC->n[2] << " is invalid!" << endl;
     2055        }
     2056      }
     2057
     2058  return closestAtom;
     2059}
     2060
     2061/**
     2062 * Gets all atoms connected to the provided atom by triangulation lines.
     2063 *
     2064 * @param atom of which get all connected atoms
     2065 * @param atom to be checked whether it is an inner atom
     2066 *
     2067 * @return list of the two atoms linked to the provided one and closest to the atom to be checked,
     2068 */
     2069list<TesselPoint*> * Tesselation::getClosestConnectedAtoms(TesselPoint* Atom, TesselPoint* AtomToCheck)
     2070{
     2071  list<TesselPoint*> connectedAtoms;
     2072  map<double, TesselPoint*> anglesOfAtoms;
     2073  map<double, TesselPoint*>::iterator runner;
     2074  LineMap::iterator findLines = LinesOnBoundary.begin();
     2075  list<TesselPoint*>::iterator listRunner;
     2076  Vector center, planeNorm, currentPoint, OrthogonalVector, helper;
     2077  TesselPoint* current;
     2078  bool takeAtom = false;
     2079
     2080  planeNorm.CopyVector(Atom->node);
     2081  planeNorm.SubtractVector(AtomToCheck->node);
     2082  planeNorm.Normalize();
     2083
     2084  while (findLines != LinesOnBoundary.end()) {
     2085    takeAtom = false;
     2086
     2087    if (findLines->second->endpoints[0]->Nr == Atom->nr) {
     2088      takeAtom = true;
     2089      current = findLines->second->endpoints[1]->node;
     2090    } else if (findLines->second->endpoints[1]->Nr == Atom->nr) {
     2091      takeAtom = true;
     2092      current = findLines->second->endpoints[0]->node;
     2093    }
     2094
     2095    if (takeAtom) {
     2096      connectedAtoms.push_back(current);
     2097      currentPoint.CopyVector(current->node);
     2098      currentPoint.ProjectOntoPlane(&planeNorm);
     2099      center.AddVector(&currentPoint);
     2100    }
     2101
     2102    findLines++;
     2103  }
     2104
     2105  cout << "Summed vectors " << center << "; number of atoms " << connectedAtoms.size()
     2106    << "; scale factor " << 1.0/connectedAtoms.size();
     2107
     2108  center.Scale(1.0/connectedAtoms.size());
     2109  listRunner = connectedAtoms.begin();
     2110
     2111  cout << " calculated center " << center <<  endl;
     2112
     2113  // construct one orthogonal vector
     2114  helper.CopyVector(AtomToCheck->node);
     2115  helper.ProjectOntoPlane(&planeNorm);
     2116  OrthogonalVector.MakeNormalVector(&center, &helper, (*listRunner)->node);
     2117  while (listRunner != connectedAtoms.end()) {
     2118    double angle = getAngle(*((*listRunner)->node), *(AtomToCheck->node), center, OrthogonalVector);
     2119    cout << "Calculated angle " << angle << " for atom " << **listRunner << endl;
     2120    anglesOfAtoms.insert(pair<double, TesselPoint*>(angle, (*listRunner)));
     2121    listRunner++;
     2122  }
     2123
     2124  list<TesselPoint*> *result = new list<TesselPoint*>;
     2125  runner = anglesOfAtoms.begin();
     2126  cout << "First value is " << *runner->second << endl;
     2127  result->push_back(runner->second);
     2128  runner = anglesOfAtoms.end();
     2129  runner--;
     2130  cout << "Second value is " << *runner->second << endl;
     2131  result->push_back(runner->second);
     2132
     2133  cout << "List of closest atoms has " << result->size() << " elements, which are "
     2134    << *(result->front()) << " and " << *(result->back()) << endl;
     2135
     2136  return result;
     2137}
     2138
     2139/**
     2140 * Finds triangles belonging to the three provided atoms.
     2141 *
     2142 * @param atom list, is expected to contain three atoms
     2143 *
     2144 * @return triangles which belong to the provided atoms, will be empty if there are none,
     2145 *         will usually be one, in case of degeneration, there will be two
     2146 */
     2147list<BoundaryTriangleSet*> *Tesselation::FindTriangles(TesselPoint* Points[3])
     2148{
     2149  list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;
     2150  LineMap::iterator FindLine;
     2151  PointMap::iterator FindPoint;
     2152  TriangleMap::iterator FindTriangle;
     2153  class BoundaryPointSet *TrianglePoints[3];
     2154
     2155  for (int i = 0; i < 3; i++) {
     2156    FindPoint = PointsOnBoundary.find(Points[i]->nr);
     2157    if (FindPoint != PointsOnBoundary.end()) {
     2158      TrianglePoints[i] = FindPoint->second;
     2159    } else {
     2160      TrianglePoints[i] = NULL;
     2161    }
     2162  }
     2163
     2164  // checks lines between the points in the Points for their adjacent triangles
     2165  for (int i = 0; i < 3; i++) {
     2166    if (TrianglePoints[i] != NULL) {
     2167      for (int j = i; j < 3; j++) {
     2168        if (TrianglePoints[j] != NULL) {
     2169          FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr);
     2170          if (FindLine != TrianglePoints[i]->lines.end()) {
     2171            for (; FindLine->first == TrianglePoints[j]->node->nr; FindLine++) {
     2172              FindTriangle = FindLine->second->triangles.begin();
     2173              for (; FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {
     2174                if ((
     2175                  (FindTriangle->second->endpoints[0] == TrianglePoints[0])
     2176                    || (FindTriangle->second->endpoints[0] == TrianglePoints[1])
     2177                    || (FindTriangle->second->endpoints[0] == TrianglePoints[2])
     2178                  ) && (
     2179                    (FindTriangle->second->endpoints[1] == TrianglePoints[0])
     2180                    || (FindTriangle->second->endpoints[1] == TrianglePoints[1])
     2181                    || (FindTriangle->second->endpoints[1] == TrianglePoints[2])
     2182                  ) && (
     2183                    (FindTriangle->second->endpoints[2] == TrianglePoints[0])
     2184                    || (FindTriangle->second->endpoints[2] == TrianglePoints[1])
     2185                    || (FindTriangle->second->endpoints[2] == TrianglePoints[2])
     2186                  )
     2187                ) {
     2188                  result->push_back(FindTriangle->second);
     2189                }
     2190              }
     2191            }
     2192            // Is it sufficient to consider one of the triangle lines for this.
     2193            return result;
     2194
     2195          }
     2196        }
     2197      }
     2198    }
     2199  }
     2200
     2201  return result;
     2202}
     2203
     2204/**
     2205 * Gets the angle between a point and a reference relative to the provided center.
     2206 *
     2207 * @param point to calculate the angle for
     2208 * @param reference to which to calculate the angle
     2209 * @param center for which to calculate the angle between the vectors
     2210 * @param OrthogonalVector helps discern between [0,pi] and [pi,2pi] in acos()
     2211 *
     2212 * @return angle between point and reference
     2213 */
     2214double getAngle(Vector point, Vector reference, Vector center, Vector OrthogonalVector)
     2215{
     2216  Vector ReferenceVector, helper;
     2217  cout << Verbose(2) << reference << " is our reference " << endl;
     2218  cout << Verbose(2) << center << " is our center " << endl;
     2219  // create baseline vector
     2220  ReferenceVector.CopyVector(&reference);
     2221  ReferenceVector.SubtractVector(&center);
     2222  if (ReferenceVector.IsNull())
     2223    return M_PI;
     2224
     2225  // calculate both angles and correct with in-plane vector
     2226  helper.CopyVector(&point);
     2227  helper.SubtractVector(&center);
     2228  if (helper.IsNull())
     2229    return M_PI;
     2230  double phi = ReferenceVector.Angle(&helper);
     2231  if (OrthogonalVector.ScalarProduct(&helper) > 0) {
     2232    phi = 2.*M_PI - phi;
     2233  }
     2234
     2235  cout << Verbose(2) << point << " has angle " << phi << endl;
     2236
     2237  return phi;
     2238}
     2239
     2240/**
     2241 * Checks whether the provided point is within the tesselation structure.
     2242 *
     2243 * This is a wrapper function for IsInnerAtom, so it can be used with a simple
     2244 * vector, too.
     2245 *
     2246 * @param point of which to check the position
     2247 * @param tesselation structure
     2248 *
     2249 * @return true if the point is inside the tesselation structure, false otherwise
     2250 */
     2251bool IsInnerPoint(Vector Point, class Tesselation *Tess, LinkedCell* LC)
     2252{
     2253  TesselPoint *temp_atom = new TesselPoint;
     2254  bool status = false;
     2255  temp_atom->node->CopyVector(&Point);
     2256
     2257  status = IsInnerPoint(temp_atom, Tess, LC);
     2258  delete(temp_atom);
     2259
     2260  return status;
     2261}
     2262
  • src/tesselation.hpp

    redb93c rab1932  
    150150public:
    151151  PointCloud();
    152   ~PointCloud();
     152  virtual ~PointCloud();
    153153
    154154  virtual Vector *GetCenter(ofstream *out) { return NULL; };
     
    208208    bool CorrectConcaveBaselines(ofstream *out);
    209209
     210    list<TesselPoint*> * getClosestConnectedAtoms(TesselPoint* Atom, TesselPoint* AtomToCheck);
     211    list<BoundaryTriangleSet*> *FindTriangles(TesselPoint* Points[3]);
     212
    210213    PointMap PointsOnBoundary;
    211214    LineMap LinesOnBoundary;
     
    224227bool CheckLineCriteriaforDegeneratedTriangle(class BoundaryPointSet *nodes[3]);
    225228bool sortCandidates(class CandidateForTesselation* candidate1, class CandidateForTesselation* candidate2);
    226 
     229TesselPoint* findClosestAtom(const TesselPoint* Atom, LinkedCell* LC);
     230double getAngle(Vector point, Vector reference, Vector center, Vector OrthogonalVector);
     231bool IsInnerPoint(Vector Point, class Tesselation *Tess, LinkedCell* LC) ;
     232bool IsInnerPoint(TesselPoint *Atom, class Tesselation *Tess, LinkedCell* LC);
    227233
    228234#endif /* TESSELATION_HPP_ */
  • src/vector.cpp

    redb93c rab1932  
    349349};
    350350
     351/** Checks whether vector has all components zero.
     352 * @return true - vector is zero, false - vector is not
     353 */
     354bool Vector::IsNull()
     355{
     356  return (fabs(x[0]+x[1]+x[2]) < MYEPSILON);
     357};
     358
    351359/** Calculates the angle between this and another vector.
    352360 * \param *y array to second vector
     
    457465};
    458466
    459 ostream& operator<<(ostream& ost,Vector& m)
     467ostream& operator<<(ostream& ost, const Vector& m)
    460468{
    461469  ost << "(";
  • src/vector.hpp

    redb93c rab1932  
    2828  double NormSquared() const;
    2929  double Angle(const Vector *y) const;
     30  bool IsNull();
    3031
    3132  void AddVector(const Vector *y);
     
    6263};
    6364
    64 ostream & operator << (ostream& ost, Vector &m);
     65ostream & operator << (ostream& ost, const Vector &m);
    6566//Vector& operator+=(Vector& a, const Vector& b);
    6667//Vector& operator*=(Vector& a, const double m);
Note: See TracChangeset for help on using the changeset viewer.