Changes in / [0dbddc:2319ed]
- Location:
- src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
src/atom.cpp
r0dbddc r2319ed 108 108 }; 109 109 110 ostream & operator << (ostream &ost, const atom &a) 110 ostream & operator << (ostream &ost, const atom &a) 111 111 { 112 112 ost << "[" << a.Name << "|" << &a << "]"; … … 118 118 * \return true - this one's is smaller, false - not 119 119 */ 120 bool atom::Compare( constatom &ptr)120 bool atom::Compare(atom &ptr) 121 121 { 122 122 if (nr < ptr.nr) -
src/boundary.cpp
r0dbddc r2319ed 1152 1152 FillerDistance.InverseMatrixMultiplication(M); 1153 1153 for(int i=0;i<NDIM;i++) 1154 N[i] = (int)ceil(1./FillerDistance.x[i]);1154 N[i] = ceil(1./FillerDistance.x[i]); 1155 1155 1156 1156 // go over [0,1]^3 filler grid … … 1164 1164 FillIt = true; 1165 1165 for (MoleculeList::iterator ListRunner = List->ListOfMolecules.begin(); ListRunner != List->ListOfMolecules.end(); ListRunner++) { 1166 //FillIt = FillIt && (!(*ListRunner)->TesselStruct->IsInside(&CurrentPosition));1166 FillIt = FillIt && (!(*ListRunner)->TesselStruct->IsInside(&CurrentPosition)); 1167 1167 } 1168 1168 … … 2181 2181 */ 2182 2182 int Tesselation::CheckPresenceOfTriangle(ofstream *out, atom *Candidates[3]) { 2183 // TODO: use findTriangles here and return result.size();2184 2183 LineMap::iterator FindLine; 2185 2184 PointMap::iterator FindPoint; … … 3124 3123 */ 3125 3124 bool sortCandidates(CandidateForTesselation* candidate1, CandidateForTesselation* candidate2) { 3126 // TODO: use get angle and remove duplicate code3127 3125 Vector BaseLineVector, OrthogonalVector, helper; 3128 3129 3130 3131 3132 3133 3134 3135 3136 3126 if (candidate1->BaseLine != candidate2->BaseLine) { // sanity check 3127 cout << Verbose(0) << "ERROR: sortCandidates was called for two different baselines: " << candidate1->BaseLine << " and " << candidate2->BaseLine << "." << endl; 3128 //return false; 3129 exit(1); 3130 } 3131 // create baseline vector 3132 BaseLineVector.CopyVector(&(candidate1->BaseLine->endpoints[1]->node->x)); 3133 BaseLineVector.SubtractVector(&(candidate1->BaseLine->endpoints[0]->node->x)); 3134 BaseLineVector.Normalize(); 3137 3135 3138 3136 // 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!) … … 3163 3161 // return comparison 3164 3162 return phi < psi; 3165 }3166 3167 /**3168 * Checks whether the provided atom is within the tesselation structure.3169 *3170 * @param atom of which to check the position3171 * @param tesselation structure3172 *3173 * @return true if the atom is inside the tesselation structure, false otherwise3174 */3175 bool IsInnerAtom(atom *Atom, class Tesselation *Tess, LinkedCell* LC) {3176 if (Tess->LinesOnBoundary.begin() == Tess->LinesOnBoundary.end()) {3177 cout << Verbose(0) << "Error: There is no tesselation structure to compare the atom with, "3178 << "please create one first.";3179 exit(1);3180 }3181 3182 class atom *trianglePoints[3];3183 trianglePoints[0] = findClosestAtom(Atom, LC);3184 // check whether closest atom is "too close" :), then it's inside3185 if (trianglePoints[0]->x.DistanceSquared(&Atom->x) < MYEPSILON)3186 return true;3187 list<atom*> *connectedClosestAtoms = Tess->getClosestConnectedAtoms(trianglePoints[0], Atom);3188 trianglePoints[1] = connectedClosestAtoms->front();3189 trianglePoints[2] = connectedClosestAtoms->back();3190 for (int i=0;i<3;i++) {3191 if (trianglePoints[i] == NULL) {3192 cout << Verbose(1) << "IsInnerAtom encounters serious error, point " << i << " not found." << endl;3193 }3194 3195 cout << Verbose(1) << "List of possible atoms:" << endl;3196 cout << *trianglePoints[i] << endl;3197 3198 // for(list<atom*>::iterator runner = connectedClosestAtoms->begin(); runner != connectedClosestAtoms->end(); runner++)3199 // cout << Verbose(2) << *(*runner) << endl;3200 }3201 delete(connectedClosestAtoms);3202 3203 list<BoundaryTriangleSet*> *triangles = Tess->FindTriangles(trianglePoints);3204 3205 if (triangles->empty()) {3206 cout << Verbose(0) << "Error: There is no nearest triangle. Please check the tesselation structure.";3207 exit(1);3208 }3209 3210 Vector helper;3211 helper.CopyVector(&Atom->x);3212 3213 // Only in case of degeneration, there will be two different scalar products.3214 // If at least one scalar product is positive, the point is considered to be outside.3215 bool status = (helper.ScalarProduct(&triangles->front()->NormalVector) < 0)3216 && (helper.ScalarProduct(&triangles->back()->NormalVector) < 0);3217 delete(triangles);3218 return status;3219 }3220 3221 /**3222 * Finds the atom which is closest to the provided one.3223 *3224 * @param atom to which to find the closest other atom3225 * @param linked cell structure3226 *3227 * @return atom which is closest to the provided one3228 */3229 atom* findClosestAtom(const atom* Atom, LinkedCell* LC) {3230 LinkedAtoms *List = NULL;3231 atom* closestAtom = NULL;3232 double distance = 1e16;3233 Vector helper;3234 int N[NDIM], Nlower[NDIM], Nupper[NDIM];3235 3236 LC->SetIndexToVector(&Atom->x); // ignore status as we calculate bounds below sensibly3237 for(int i=0;i<NDIM;i++) // store indices of this cell3238 N[i] = LC->n[i];3239 //cout << Verbose(2) << "INFO: Center cell is " << N[0] << ", " << N[1] << ", " << N[2] << " with No. " << LC->index << "." << endl;3240 3241 LC->GetNeighbourBounds(Nlower, Nupper);3242 //cout << endl;3243 for (LC->n[0] = Nlower[0]; LC->n[0] <= Nupper[0]; LC->n[0]++)3244 for (LC->n[1] = Nlower[1]; LC->n[1] <= Nupper[1]; LC->n[1]++)3245 for (LC->n[2] = Nlower[2]; LC->n[2] <= Nupper[2]; LC->n[2]++) {3246 List = LC->GetCurrentCell();3247 //cout << "The current cell " << LC->n[0] << "," << LC->n[1] << "," << LC->n[2] << endl;3248 if (List != NULL) {3249 for (LinkedAtoms::iterator Runner = List->begin(); Runner != List->end(); Runner++) {3250 helper.CopyVector(&Atom->x);3251 helper.SubtractVector(&(*Runner)->x);3252 double currentNorm = helper. Norm();3253 if (currentNorm < distance) {3254 distance = currentNorm;3255 closestAtom = (*Runner);3256 }3257 }3258 } else {3259 cerr << "ERROR: The current cell " << LC->n[0] << "," << LC->n[1] << ","3260 << LC->n[2] << " is invalid!" << endl;3261 }3262 }3263 3264 return closestAtom;3265 }3266 3267 /**3268 * Gets all atoms connected to the provided atom by triangulation lines.3269 *3270 * @param atom of which get all connected atoms3271 * @param atom to be checked whether it is an inner atom3272 *3273 * @return list of the two atoms linked to the provided one and closest to the atom to be checked,3274 */3275 list<atom*> * Tesselation::getClosestConnectedAtoms(atom* Atom, atom* AtomToCheck) {3276 list<atom*> connectedAtoms;3277 map<double, atom*> anglesOfAtoms;3278 map<double, atom*>::iterator runner;3279 LineMap::iterator findLines = LinesOnBoundary.begin();3280 list<atom*>::iterator listRunner;3281 Vector center, planeNorm, currentPoint, OrthogonalVector, helper;3282 atom* current;3283 bool takeAtom = false;3284 3285 planeNorm.CopyVector(&Atom->x);3286 planeNorm.SubtractVector(&AtomToCheck->x);3287 planeNorm.Normalize();3288 3289 while (findLines != LinesOnBoundary.end()) {3290 takeAtom = false;3291 3292 if (findLines->second->endpoints[0]->Nr == Atom->nr) {3293 takeAtom = true;3294 current = findLines->second->endpoints[1]->node;3295 } else if (findLines->second->endpoints[1]->Nr == Atom->nr) {3296 takeAtom = true;3297 current = findLines->second->endpoints[0]->node;3298 }3299 3300 if (takeAtom) {3301 connectedAtoms.push_back(current);3302 currentPoint.CopyVector(¤t->x);3303 currentPoint.ProjectOntoPlane(&planeNorm);3304 center.AddVector(¤tPoint);3305 }3306 3307 findLines++;3308 }3309 3310 cout << "Summed vectors " << center << "; number of atoms " << connectedAtoms.size()3311 << "; scale factor " << 1.0/connectedAtoms.size();3312 3313 center.Scale(1.0/connectedAtoms.size());3314 listRunner = connectedAtoms.begin();3315 3316 cout << " calculated center " << center << endl;3317 3318 // construct one orthogonal vector3319 helper.CopyVector(&AtomToCheck->x);3320 helper.ProjectOntoPlane(&planeNorm);3321 OrthogonalVector.MakeNormalVector(¢er, &helper, &(*listRunner)->x);3322 while (listRunner != connectedAtoms.end()) {3323 double angle = getAngle((*listRunner)->x, AtomToCheck->x, center, OrthogonalVector);3324 cout << "Calculated angle " << angle << " for atom " << **listRunner << endl;3325 anglesOfAtoms.insert(pair<double, atom*>(angle, (*listRunner)));3326 listRunner++;3327 }3328 3329 list<atom*> *result = new list<atom*>;3330 runner = anglesOfAtoms.begin();3331 cout << "First value is " << *runner->second << endl;3332 result->push_back(runner->second);3333 runner = anglesOfAtoms.end();3334 runner--;3335 cout << "Second value is " << *runner->second << endl;3336 result->push_back(runner->second);3337 3338 cout << "List of closest atoms has " << result->size() << " elements, which are "3339 << *(result->front()) << " and " << *(result->back()) << endl;3340 3341 return result;3342 }3343 3344 /**3345 * Finds triangles belonging to the three provided atoms.3346 *3347 * @param atom list, is expected to contain three atoms3348 *3349 * @return triangles which belong to the provided atoms, will be empty if there are none,3350 * will usually be one, in case of degeneration, there will be two3351 */3352 list<BoundaryTriangleSet*> *Tesselation::FindTriangles(atom* Points[3]) {3353 list<BoundaryTriangleSet*> *result = new list<BoundaryTriangleSet*>;3354 LineMap::iterator FindLine;3355 PointMap::iterator FindPoint;3356 TriangleMap::iterator FindTriangle;3357 class BoundaryPointSet *TrianglePoints[3];3358 3359 for (int i = 0; i < 3; i++) {3360 FindPoint = PointsOnBoundary.find(Points[i]->nr);3361 if (FindPoint != PointsOnBoundary.end()) {3362 TrianglePoints[i] = FindPoint->second;3363 } else {3364 TrianglePoints[i] = NULL;3365 }3366 }3367 3368 // checks lines between the points in the Points for their adjacent triangles3369 for (int i = 0; i < 3; i++) {3370 if (TrianglePoints[i] != NULL) {3371 for (int j = i; j < 3; j++) {3372 if (TrianglePoints[j] != NULL) {3373 FindLine = TrianglePoints[i]->lines.find(TrianglePoints[j]->node->nr);3374 if (FindLine != TrianglePoints[i]->lines.end()) {3375 for (; FindLine->first == TrianglePoints[j]->node->nr; FindLine++) {3376 FindTriangle = FindLine->second->triangles.begin();3377 for (; FindTriangle != FindLine->second->triangles.end(); FindTriangle++) {3378 if ((3379 (FindTriangle->second->endpoints[0] == TrianglePoints[0])3380 || (FindTriangle->second->endpoints[0] == TrianglePoints[1])3381 || (FindTriangle->second->endpoints[0] == TrianglePoints[2])3382 ) && (3383 (FindTriangle->second->endpoints[1] == TrianglePoints[0])3384 || (FindTriangle->second->endpoints[1] == TrianglePoints[1])3385 || (FindTriangle->second->endpoints[1] == TrianglePoints[2])3386 ) && (3387 (FindTriangle->second->endpoints[2] == TrianglePoints[0])3388 || (FindTriangle->second->endpoints[2] == TrianglePoints[1])3389 || (FindTriangle->second->endpoints[2] == TrianglePoints[2])3390 )3391 ) {3392 result->push_back(FindTriangle->second);3393 }3394 }3395 }3396 // Is it sufficient to consider one of the triangle lines for this.3397 return result;3398 3399 }3400 }3401 }3402 }3403 }3404 3405 return result;3406 }3407 3408 /**3409 * Gets the angle between a point and a reference relative to the provided center.3410 *3411 * @param point to calculate the angle for3412 * @param reference to which to calculate the angle3413 * @param center for which to calculate the angle between the vectors3414 * @param OrthogonalVector helps discern between [0,pi] and [pi,2pi] in acos()3415 *3416 * @return angle between point and reference3417 */3418 double getAngle(Vector point, Vector reference, Vector center, Vector OrthogonalVector) {3419 Vector ReferenceVector, helper;3420 cout << Verbose(2) << reference << " is our reference " << endl;3421 cout << Verbose(2) << center << " is our center " << endl;3422 // create baseline vector3423 ReferenceVector.CopyVector(&reference);3424 ReferenceVector.SubtractVector(¢er);3425 if (ReferenceVector.IsNull())3426 return M_PI;3427 3428 // calculate both angles and correct with in-plane vector3429 helper.CopyVector(&point);3430 helper.SubtractVector(¢er);3431 if (helper.IsNull())3432 return M_PI;3433 double phi = ReferenceVector.Angle(&helper);3434 if (OrthogonalVector.ScalarProduct(&helper) > 0) {3435 phi = 2.*M_PI - phi;3436 }3437 3438 cout << Verbose(2) << point << " has angle " << phi << endl;3439 3440 return phi;3441 }3442 3443 /**3444 * Checks whether the provided point is within the tesselation structure.3445 *3446 * This is a wrapper function for IsInnerAtom, so it can be used with a simple3447 * vector, too.3448 *3449 * @param point of which to check the position3450 * @param tesselation structure3451 *3452 * @return true if the point is inside the tesselation structure, false otherwise3453 */3454 bool IsInnerPoint(Vector Point, class Tesselation *Tess, LinkedCell* LC) {3455 atom *temp_atom = new atom;3456 bool status = false;3457 temp_atom->x.CopyVector(&Point);3458 3459 status = IsInnerAtom(temp_atom, Tess, LC);3460 delete(temp_atom);3461 3462 return status;3463 3163 } 3464 3164 … … 3548 3248 cout << Verbose(2) << "None." << endl; 3549 3249 3550 // Tests the IsInnerAtom() function.3551 Vector x (0, 0, 0);3552 cout << Verbose(0) << "Point to check: " << x << endl;3553 cout << Verbose(0) << "Check: IsInnerPoint() returns " << IsInnerPoint(x, Tess, LCList)3554 << "for vector " << x << "." << endl;3555 atom* a = Tess->PointsOnBoundary.begin()->second->node;3556 cout << Verbose(0) << "Point to check: " << *a << " (on boundary)." << endl;3557 cout << Verbose(0) << "Check: IsInnerAtom() returns " << IsInnerAtom(a, Tess, LCList)3558 << "for atom " << a << " (on boundary)." << endl;3559 LinkedAtoms *List = NULL;3560 for (int i=0;i<NDIM;i++) { // each axis3561 LCList->n[i] = LCList->N[i]-1; // current axis is topmost cell3562 for (LCList->n[(i+1)%NDIM]=0;LCList->n[(i+1)%NDIM]<LCList->N[(i+1)%NDIM];LCList->n[(i+1)%NDIM]++)3563 for (LCList->n[(i+2)%NDIM]=0;LCList->n[(i+2)%NDIM]<LCList->N[(i+2)%NDIM];LCList->n[(i+2)%NDIM]++) {3564 List = LCList->GetCurrentCell();3565 //cout << Verbose(2) << "Current cell is " << LC->n[0] << ", " << LC->n[1] << ", " << LC->n[2] << " with No. " << LC->index << "." << endl;3566 if (List != NULL) {3567 for (LinkedAtoms::iterator Runner = List->begin();Runner != List->end();Runner++) {3568 if (Tess->PointsOnBoundary.find((*Runner)->nr) == Tess->PointsOnBoundary.end()) {3569 a = *Runner;3570 i=3;3571 for (int j=0;j<NDIM;j++)3572 LCList->n[j] = LCList->N[j];3573 break;3574 }3575 }3576 }3577 }3578 }3579 cout << Verbose(0) << "Check: IsInnerAtom() returns " << IsInnerAtom(a, Tess, LCList)3580 << "for atom " << a << " (inside)." << endl;3581 3582 3583 3250 if (freeTess) 3584 3251 delete(Tess); -
src/boundary.hpp
r0dbddc r2319ed 114 114 bool InsertStraddlingPoints(ofstream *out, molecule *mol); 115 115 bool CorrectConcaveBaselines(ofstream *out); 116 list<atom*> *getClosestConnectedAtoms(atom* Atom, atom* AtomToCheck);117 list<BoundaryTriangleSet*> *FindTriangles(atom* TrianglePoints[3]);118 116 119 117 PointMap PointsOnBoundary; … … 146 144 bool existsIntersection(Vector point1, Vector point2, Vector point3, Vector point4); 147 145 bool sortCandidates(CandidateForTesselation* candidate1, CandidateForTesselation* candidate2); 148 bool IsInnerPoint(Vector Point, class Tesselation *Tess, LinkedCell* LC);149 bool IsInnerAtom(atom *Atom, class Tesselation *Tess, LinkedCell* LC);150 atom* findClosestAtom(const atom* Atom, LinkedCell* LC);151 double getAngle(Vector point, Vector reference, Vector center, Vector OrthogonalVector);152 146 153 147 #endif /*BOUNDARY_HPP_*/ -
src/linkedcell.cpp
r0dbddc r2319ed 129 129 130 130 /** Calculates the index for a given atom *Walker. 131 * \param Walker atom to set index to131 * \param *Walker atom to set index to 132 132 * \return if the atom is also found in this cell - true, else - false 133 133 */ 134 bool LinkedCell::SetIndexToAtom( const atom &Walker)134 bool LinkedCell::SetIndexToAtom(atom *Walker) 135 135 { 136 136 bool status = false; 137 137 for (int i=0;i<NDIM;i++) { 138 n[i] = (int)floor((Walker .x.x[i] - min.x[i])/RADIUS);138 n[i] = (int)floor((Walker->x.x[i] - min.x[i])/RADIUS); 139 139 } 140 140 index = n[0] * N[1] * N[2] + n[1] * N[2] + n[2]; 141 141 if (CheckBounds()) { 142 142 for (LinkedAtoms::iterator Runner = LC[index].begin(); Runner != LC[index].end(); Runner++) 143 status = status || ((*Runner) == &Walker);143 status = status || ((*Runner) == Walker); 144 144 return status; 145 145 } else { 146 cerr << Verbose(1) << "ERROR: Atom "<< Walker << " at " << Walker.x << " is out of bounds." << endl;146 cerr << Verbose(1) << "ERROR: Atom "<< *Walker << " at " << Walker->x << " is out of bounds." << endl; 147 147 return false; 148 }149 };150 151 /** Calculates the interval bounds of the linked cell grid.152 * \param *lower lower bounds153 * \param *upper upper bounds154 */155 void LinkedCell::GetNeighbourBounds(int lower[NDIM], int upper[NDIM])156 {157 for (int i=0;i<NDIM;i++) {158 lower[i] = ((n[i]-1) >= 0) ? n[i]-1 : 0;159 upper[i] = ((n[i]+1) < N[i]) ? n[i]+1 : N[i]-1;160 //cout << " [" << Nlower[i] << "," << Nupper[i] << "] ";161 // check for this axis whether the point is outside of our grid162 if (n[i] < 0)163 upper[i] = lower[i];164 if (n[i] > N[i])165 lower[i] = upper[i];166 167 //cout << "axis " << i << " has bounds [" << lower[i] << "," << upper[i] << "]" << endl;168 148 } 169 149 }; … … 173 153 * \return Vector is inside bounding box - true, else - false 174 154 */ 175 bool LinkedCell::SetIndexToVector( constVector *x)155 bool LinkedCell::SetIndexToVector(Vector *x) 176 156 { 177 157 bool status = true; -
src/linkedcell.hpp
r0dbddc r2319ed 25 25 ~LinkedCell(); 26 26 LinkedAtoms* GetCurrentCell(); 27 bool SetIndexToAtom( const atom &Walker);28 bool SetIndexToVector( constVector *x);27 bool SetIndexToAtom(atom *Walker); 28 bool SetIndexToVector(Vector *x); 29 29 bool CheckBounds(); 30 void GetNeighbourBounds(int lower[NDIM], int upper[NDIM]);31 30 32 31 // not implemented yet -
src/molecules.hpp
r0dbddc r2319ed 156 156 bool OutputXYZLine(ofstream *out) const; 157 157 atom *GetTrueFather(); 158 bool Compare( constatom &ptr);158 bool Compare(atom &ptr); 159 159 160 160 private: -
src/vector.cpp
r0dbddc r2319ed 348 348 }; 349 349 350 /** Checks whether vector has all components zero.351 * @return true - vector is zero, false - vector is not352 */353 bool Vector::IsNull()354 {355 return (fabs(x[0]+x[1]+x[2]) < MYEPSILON);356 };357 358 350 /** Calculates the angle between this and another vector. 359 351 * \param *y array to second vector … … 464 456 }; 465 457 466 ostream& operator<<(ostream& ost, constVector& m)458 ostream& operator<<(ostream& ost,Vector& m) 467 459 { 468 460 ost << "("; -
src/vector.hpp
r0dbddc r2319ed 24 24 double NormSquared() const; 25 25 double Angle(const Vector *y) const; 26 bool IsNull();27 26 28 27 void AddVector(const Vector *y); … … 59 58 }; 60 59 61 ostream & operator << (ostream& ost, constVector &m);60 ostream & operator << (ostream& ost, Vector &m); 62 61 //Vector& operator+=(Vector& a, const Vector& b); 63 62 //Vector& operator*=(Vector& a, const double m);
Note:
See TracChangeset
for help on using the changeset viewer.