- Timestamp:
- Apr 28, 2010, 2:52:56 PM (15 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- 8cbb97
- Parents:
- 1bd79e
- Location:
- src
- Files:
-
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Helpers/fast_functions.hpp
r1bd79e r753f02 8 8 #ifndef FAST_FUNCTIONS_HPP_ 9 9 #define FAST_FUNCTIONS_HPP_ 10 11 #include "defs.hpp" 10 12 11 13 /** -
src/Makefile.am
r1bd79e r753f02 9 9 gslvector.cpp \ 10 10 linearsystemofequations.cpp \ 11 SingleVector.cpp \12 11 vector.cpp 13 12 … … 15 14 gslvector.hpp \ 16 15 linearsystemofequations.hpp \ 17 SingleVector.hpp \18 16 vector.hpp 19 17 -
src/vector.cpp
r1bd79e r753f02 6 6 7 7 8 #include " SingleVector.hpp"8 #include "vector.hpp" 9 9 #include "Helpers/Assert.hpp" 10 #include "Helpers/fast_functions.hpp" 10 11 11 12 #include <iostream> … … 18 19 /** Constructor of class vector. 19 20 */ 20 Vector::Vector() : 21 rep(new SingleVector()) 22 {}; 23 24 Vector::Vector(Baseconstructor) // used by derived objects to construct their bases 25 {} 26 27 Vector::Vector(Baseconstructor,const Vector* v) : 28 rep(v->clone()) 29 {} 30 31 Vector Vector::VecFromRep(const Vector* v){ 32 return Vector(Baseconstructor(),v); 33 } 34 35 /** Constructor of class vector. 36 */ 37 Vector::Vector(const double x1, const double x2, const double x3) : 38 rep(new SingleVector(x1,x2,x3)) 39 {}; 21 Vector::Vector() 22 { 23 x[0] = x[1] = x[2] = 0.; 24 }; 40 25 41 26 /** 42 27 * Copy constructor 43 28 */ 44 Vector::Vector(const Vector& src) : 45 rep(src.rep->clone()) 46 {} 29 30 Vector::Vector(const Vector& src) 31 { 32 x[0] = src[0]; 33 x[1] = src[1]; 34 x[2] = src[2]; 35 } 36 37 /** Constructor of class vector. 38 */ 39 Vector::Vector(const double x1, const double x2, const double x3) 40 { 41 x[0] = x1; 42 x[1] = x2; 43 x[2] = x3; 44 }; 47 45 48 46 /** … … 50 48 */ 51 49 Vector& Vector::operator=(const Vector& src){ 52 ASSERT(isBaseClass(),"Operator used on Derived Vector object");53 50 // check for self assignment 54 51 if(&src!=this){ 55 rep.reset(src.rep->clone()); 52 x[0] = src[0]; 53 x[1] = src[1]; 54 x[2] = src[2]; 56 55 } 57 56 return *this; … … 68 67 double Vector::DistanceSquared(const Vector &y) const 69 68 { 70 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 71 return rep->DistanceSquared(y); 69 double res = 0.; 70 for (int i=NDIM;i--;) 71 res += (x[i]-y[i])*(x[i]-y[i]); 72 return (res); 72 73 }; 73 74 … … 88 89 double Vector::PeriodicDistance(const Vector &y, const double * const cell_size) const 89 90 { 90 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 91 return rep->PeriodicDistance(y,cell_size); 91 double res = Distance(y), tmp, matrix[NDIM*NDIM]; 92 Vector Shiftedy, TranslationVector; 93 int N[NDIM]; 94 matrix[0] = cell_size[0]; 95 matrix[1] = cell_size[1]; 96 matrix[2] = cell_size[3]; 97 matrix[3] = cell_size[1]; 98 matrix[4] = cell_size[2]; 99 matrix[5] = cell_size[4]; 100 matrix[6] = cell_size[3]; 101 matrix[7] = cell_size[4]; 102 matrix[8] = cell_size[5]; 103 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells 104 for (N[0]=-1;N[0]<=1;N[0]++) 105 for (N[1]=-1;N[1]<=1;N[1]++) 106 for (N[2]=-1;N[2]<=1;N[2]++) { 107 // create the translation vector 108 TranslationVector.Zero(); 109 for (int i=NDIM;i--;) 110 TranslationVector[i] = (double)N[i]; 111 TranslationVector.MatrixMultiplication(matrix); 112 // add onto the original vector to compare with 113 Shiftedy = y + TranslationVector; 114 // get distance and compare with minimum so far 115 tmp = Distance(Shiftedy); 116 if (tmp < res) res = tmp; 117 } 118 return (res); 92 119 }; 93 120 … … 99 126 double Vector::PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const 100 127 { 101 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 102 return rep->PeriodicDistanceSquared(y,cell_size); 128 double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM]; 129 Vector Shiftedy, TranslationVector; 130 int N[NDIM]; 131 matrix[0] = cell_size[0]; 132 matrix[1] = cell_size[1]; 133 matrix[2] = cell_size[3]; 134 matrix[3] = cell_size[1]; 135 matrix[4] = cell_size[2]; 136 matrix[5] = cell_size[4]; 137 matrix[6] = cell_size[3]; 138 matrix[7] = cell_size[4]; 139 matrix[8] = cell_size[5]; 140 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells 141 for (N[0]=-1;N[0]<=1;N[0]++) 142 for (N[1]=-1;N[1]<=1;N[1]++) 143 for (N[2]=-1;N[2]<=1;N[2]++) { 144 // create the translation vector 145 TranslationVector.Zero(); 146 for (int i=NDIM;i--;) 147 TranslationVector[i] = (double)N[i]; 148 TranslationVector.MatrixMultiplication(matrix); 149 // add onto the original vector to compare with 150 Shiftedy = y + TranslationVector; 151 // get distance and compare with minimum so far 152 tmp = DistanceSquared(Shiftedy); 153 if (tmp < res) res = tmp; 154 } 155 return (res); 103 156 }; 104 157 … … 109 162 void Vector::KeepPeriodic(const double * const matrix) 110 163 { 111 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 112 rep->KeepPeriodic(matrix); 164 // int N[NDIM]; 165 // bool flag = false; 166 //vector Shifted, TranslationVector; 167 // Log() << Verbose(1) << "Begin of KeepPeriodic." << endl; 168 // Log() << Verbose(2) << "Vector is: "; 169 // Output(out); 170 // Log() << Verbose(0) << endl; 171 InverseMatrixMultiplication(matrix); 172 for(int i=NDIM;i--;) { // correct periodically 173 if (at(i) < 0) { // get every coefficient into the interval [0,1) 174 at(i) += ceil(at(i)); 175 } else { 176 at(i) -= floor(at(i)); 177 } 178 } 179 MatrixMultiplication(matrix); 180 // Log() << Verbose(2) << "New corrected vector is: "; 181 // Output(out); 182 // Log() << Verbose(0) << endl; 183 // Log() << Verbose(1) << "End of KeepPeriodic." << endl; 113 184 }; 114 185 … … 119 190 double Vector::ScalarProduct(const Vector &y) const 120 191 { 121 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 122 return rep->ScalarProduct(y); 192 double res = 0.; 193 for (int i=NDIM;i--;) 194 res += x[i]*y[i]; 195 return (res); 123 196 }; 124 197 … … 132 205 void Vector::VectorProduct(const Vector &y) 133 206 { 134 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 135 rep->VectorProduct(y); 207 Vector tmp; 208 tmp[0] = x[1]* (y[2]) - x[2]* (y[1]); 209 tmp[1] = x[2]* (y[0]) - x[0]* (y[2]); 210 tmp[2] = x[0]* (y[1]) - x[1]* (y[0]); 211 (*this) = tmp; 136 212 }; 137 213 … … 143 219 void Vector::ProjectOntoPlane(const Vector &y) 144 220 { 145 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 146 rep->ProjectOntoPlane(y); 221 Vector tmp; 222 tmp = y; 223 tmp.Normalize(); 224 tmp.Scale(ScalarProduct(tmp)); 225 *this -= tmp; 147 226 }; 148 227 … … 155 234 double Vector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const 156 235 { 157 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 158 return rep->DistanceToPlane(PlaneNormal,PlaneOffset); 236 // first create part that is orthonormal to PlaneNormal with withdraw 237 Vector temp = (*this) - PlaneOffset; 238 temp.MakeNormalTo(PlaneNormal); 239 temp.Scale(-1.); 240 // then add connecting vector from plane to point 241 temp += (*this)-PlaneOffset; 242 double sign = temp.ScalarProduct(PlaneNormal); 243 if (fabs(sign) > MYEPSILON) 244 sign /= fabs(sign); 245 else 246 sign = 0.; 247 248 return (temp.Norm()*sign); 159 249 }; 160 250 … … 164 254 void Vector::ProjectIt(const Vector &y) 165 255 { 166 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 167 rep->ProjectIt(y); 256 (*this) += (-ScalarProduct(y))*y; 168 257 }; 169 258 … … 174 263 Vector Vector::Projection(const Vector &y) const 175 264 { 176 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 177 return rep->Projection(y); 265 Vector helper = y; 266 helper.Scale((ScalarProduct(y)/y.NormSquared())); 267 268 return helper; 178 269 }; 179 270 … … 206 297 void Vector::Zero() 207 298 { 208 rep.reset(new SingleVector());299 at(0)=at(1)=at(2)=0; 209 300 }; 210 301 … … 213 304 void Vector::One(const double one) 214 305 { 215 rep.reset(new SingleVector(one,one,one));306 at(0)=at(1)=at(2)=one; 216 307 }; 217 308 … … 221 312 bool Vector::IsZero() const 222 313 { 223 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 224 return rep->IsZero(); 314 return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON); 225 315 }; 226 316 … … 230 320 bool Vector::IsOne() const 231 321 { 232 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 233 return rep->IsOne(); 322 return (fabs(Norm() - 1.) < MYEPSILON); 234 323 }; 235 324 … … 239 328 bool Vector::IsNormalTo(const Vector &normal) const 240 329 { 241 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 242 return rep->IsNormalTo(normal); 330 if (ScalarProduct(normal) < MYEPSILON) 331 return true; 332 else 333 return false; 243 334 }; 244 335 … … 248 339 bool Vector::IsEqualTo(const Vector &a) const 249 340 { 250 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 251 return rep->IsEqualTo(a); 341 bool status = true; 342 for (int i=0;i<NDIM;i++) { 343 if (fabs(x[i] - a[i]) > MYEPSILON) 344 status = false; 345 } 346 return status; 252 347 }; 253 348 … … 258 353 double Vector::Angle(const Vector &y) const 259 354 { 260 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 261 return rep->Angle(y); 355 double norm1 = Norm(), norm2 = y.Norm(); 356 double angle = -1; 357 if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON)) 358 angle = this->ScalarProduct(y)/norm1/norm2; 359 // -1-MYEPSILON occured due to numerical imprecision, catch ... 360 //Log() << Verbose(2) << "INFO: acos(-1) = " << acos(-1) << ", acos(-1+MYEPSILON) = " << acos(-1+MYEPSILON) << ", acos(-1-MYEPSILON) = " << acos(-1-MYEPSILON) << "." << endl; 361 if (angle < -1) 362 angle = -1; 363 if (angle > 1) 364 angle = 1; 365 return acos(angle); 262 366 }; 263 367 264 368 265 369 double& Vector::operator[](size_t i){ 266 ASSERT( (rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");267 return (*rep)[i];370 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); 371 return x[i]; 268 372 } 269 373 270 374 const double& Vector::operator[](size_t i) const{ 271 ASSERT( (rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");272 return (*rep)[i];375 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); 376 return x[i]; 273 377 } 274 378 … … 282 386 283 387 double* Vector::get(){ 284 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 285 return rep->get(); 388 return x; 286 389 } 287 390 … … 293 396 bool Vector::operator==(const Vector& b) const 294 397 { 295 ASSERT(isBaseClass(),"Operator used on Derived Vector object");296 398 return IsEqualTo(b); 297 399 }; … … 337 439 Vector const Vector::operator+(const Vector& b) const 338 440 { 339 ASSERT(isBaseClass(),"Operator used on Derived Vector object");340 441 Vector x = *this; 341 442 x.AddVector(b); … … 350 451 Vector const Vector::operator-(const Vector& b) const 351 452 { 352 ASSERT(isBaseClass(),"Operator used on Derived Vector object");353 453 Vector x = *this; 354 454 x.SubtractVector(b); … … 395 495 void Vector::ScaleAll(const double *factor) 396 496 { 397 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");398 rep->ScaleAll(factor);497 for (int i=NDIM;i--;) 498 x[i] *= factor[i]; 399 499 }; 400 500 … … 403 503 void Vector::Scale(const double factor) 404 504 { 405 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");406 rep->Scale(factor);505 for (int i=NDIM;i--;) 506 x[i] *= factor; 407 507 }; 408 508 … … 413 513 void Vector::WrapPeriodically(const double * const M, const double * const Minv) 414 514 { 415 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 416 rep->WrapPeriodically(M,Minv); 515 MatrixMultiplication(Minv); 516 // truncate to [0,1] for each axis 517 for (int i=0;i<NDIM;i++) { 518 x[i] += 0.5; // set to center of box 519 while (x[i] >= 1.) 520 x[i] -= 1.; 521 while (x[i] < 0.) 522 x[i] += 1.; 523 } 524 MatrixMultiplication(M); 417 525 }; 418 526 … … 422 530 void Vector::MatrixMultiplication(const double * const M) 423 531 { 424 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 425 rep->MatrixMultiplication(M); 532 // do the matrix multiplication 533 at(0) = M[0]*x[0]+M[3]*x[1]+M[6]*x[2]; 534 at(1) = M[1]*x[0]+M[4]*x[1]+M[7]*x[2]; 535 at(2) = M[2]*x[0]+M[5]*x[1]+M[8]*x[2]; 426 536 }; 427 537 … … 431 541 bool Vector::InverseMatrixMultiplication(const double * const A) 432 542 { 433 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 434 return rep->InverseMatrixMultiplication(A); 543 double B[NDIM*NDIM]; 544 double detA = RDET3(A); 545 double detAReci; 546 547 // calculate the inverse B 548 if (fabs(detA) > MYEPSILON) {; // RDET3(A) yields precisely zero if A irregular 549 detAReci = 1./detA; 550 B[0] = detAReci*RDET2(A[4],A[5],A[7],A[8]); // A_11 551 B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]); // A_12 552 B[2] = detAReci*RDET2(A[1],A[2],A[4],A[5]); // A_13 553 B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]); // A_21 554 B[4] = detAReci*RDET2(A[0],A[2],A[6],A[8]); // A_22 555 B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]); // A_23 556 B[6] = detAReci*RDET2(A[3],A[4],A[6],A[7]); // A_31 557 B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]); // A_32 558 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33 559 560 // do the matrix multiplication 561 at(0) = B[0]*x[0]+B[3]*x[1]+B[6]*x[2]; 562 at(1) = B[1]*x[0]+B[4]*x[1]+B[7]*x[2]; 563 at(2) = B[2]*x[0]+B[5]*x[1]+B[8]*x[2]; 564 565 return true; 566 } else { 567 return false; 568 } 435 569 }; 436 570 … … 455 589 void Vector::Mirror(const Vector &n) 456 590 { 457 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 458 rep->Mirror(n); 591 double projection; 592 projection = ScalarProduct(n)/n.NormSquared(); // remove constancy from n (keep as logical one) 593 // withdraw projected vector twice from original one 594 for (int i=NDIM;i--;) 595 x[i] -= 2.*projection*n[i]; 459 596 }; 460 597 … … 468 605 bool Vector::MakeNormalTo(const Vector &y1) 469 606 { 470 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 471 return rep->MakeNormalTo(y1); 607 bool result = false; 608 double factor = y1.ScalarProduct(*this)/y1.NormSquared(); 609 Vector x1; 610 x1 = factor * y1; 611 SubtractVector(x1); 612 for (int i=NDIM;i--;) 613 result = result || (fabs(x[i]) > MYEPSILON); 614 615 return result; 472 616 }; 473 617 … … 480 624 bool Vector::GetOneNormalVector(const Vector &GivenVector) 481 625 { 482 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 483 return rep->GetOneNormalVector(GivenVector); 626 int Components[NDIM]; // contains indices of non-zero components 627 int Last = 0; // count the number of non-zero entries in vector 628 int j; // loop variables 629 double norm; 630 631 for (j=NDIM;j--;) 632 Components[j] = -1; 633 // find two components != 0 634 for (j=0;j<NDIM;j++) 635 if (fabs(GivenVector[j]) > MYEPSILON) 636 Components[Last++] = j; 637 638 switch(Last) { 639 case 3: // threecomponent system 640 case 2: // two component system 641 norm = sqrt(1./(GivenVector[Components[1]]*GivenVector[Components[1]]) + 1./(GivenVector[Components[0]]*GivenVector[Components[0]])); 642 x[Components[2]] = 0.; 643 // in skp both remaining parts shall become zero but with opposite sign and third is zero 644 x[Components[1]] = -1./GivenVector[Components[1]] / norm; 645 x[Components[0]] = 1./GivenVector[Components[0]] / norm; 646 return true; 647 break; 648 case 1: // one component system 649 // set sole non-zero component to 0, and one of the other zero component pendants to 1 650 x[(Components[0]+2)%NDIM] = 0.; 651 x[(Components[0]+1)%NDIM] = 1.; 652 x[Components[0]] = 0.; 653 return true; 654 break; 655 default: 656 return false; 657 } 484 658 }; 485 659 … … 489 663 void Vector::AddVector(const Vector &y) 490 664 { 491 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");492 rep->AddVector(y);665 for(int i=NDIM;i--;) 666 x[i] += y[i]; 493 667 } 494 668 … … 498 672 void Vector::SubtractVector(const Vector &y) 499 673 { 500 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type");501 rep->SubtractVector(y);674 for(int i=NDIM;i--;) 675 x[i] -= y[i]; 502 676 } 503 677 … … 511 685 bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const 512 686 { 513 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 514 return rep->IsInParallelepiped(offset, parallelepiped); 515 } 516 517 bool Vector::isBaseClass() const{ 518 return true; 519 } 520 521 Vector* Vector::clone() const{ 522 ASSERT(false, "Cannot clone a base Vector object"); 523 return 0; 524 } 687 Vector a = (*this)-offset; 688 a.InverseMatrixMultiplication(parallelepiped); 689 bool isInside = true; 690 691 for (int i=NDIM;i--;) 692 isInside = isInside && ((a[i] <= 1) && (a[i] >= 0)); 693 694 return isInside; 695 } -
src/vector.hpp
r1bd79e r753f02 37 37 // Method implemented by forwarding to the Representation 38 38 39 virtualdouble DistanceSquared(const Vector &y) const;40 virtualdouble DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;41 virtualdouble PeriodicDistance(const Vector &y, const double * const cell_size) const;42 virtualdouble PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const;43 virtualdouble ScalarProduct(const Vector &y) const;44 virtualdouble Angle(const Vector &y) const;45 virtualbool IsZero() const;46 virtualbool IsOne() const;47 virtualbool IsNormalTo(const Vector &normal) const;48 virtualbool IsEqualTo(const Vector &a) const;39 double DistanceSquared(const Vector &y) const; 40 double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const; 41 double PeriodicDistance(const Vector &y, const double * const cell_size) const; 42 double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const; 43 double ScalarProduct(const Vector &y) const; 44 double Angle(const Vector &y) const; 45 bool IsZero() const; 46 bool IsOne() const; 47 bool IsNormalTo(const Vector &normal) const; 48 bool IsEqualTo(const Vector &a) const; 49 49 50 v irtual void AddVector(const Vector &y);51 v irtual void SubtractVector(const Vector &y);52 v irtual void VectorProduct(const Vector &y);53 v irtual void ProjectOntoPlane(const Vector &y);54 v irtual void ProjectIt(const Vector &y);55 virtualVector Projection(const Vector &y) const;56 v irtual void Mirror(const Vector &x);57 v irtual void ScaleAll(const double *factor);58 v irtual void Scale(const double factor);59 v irtual void MatrixMultiplication(const double * const M);60 virtualbool InverseMatrixMultiplication(const double * const M);61 v irtual void KeepPeriodic(const double * const matrix);62 virtualbool GetOneNormalVector(const Vector &x1);63 virtualbool MakeNormalTo(const Vector &y1);64 virtualbool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;65 v irtual void WrapPeriodically(const double * const M, const double * const Minv);50 void AddVector(const Vector &y); 51 void SubtractVector(const Vector &y); 52 void VectorProduct(const Vector &y); 53 void ProjectOntoPlane(const Vector &y); 54 void ProjectIt(const Vector &y); 55 Vector Projection(const Vector &y) const; 56 void Mirror(const Vector &x); 57 void ScaleAll(const double *factor); 58 void Scale(const double factor); 59 void MatrixMultiplication(const double * const M); 60 bool InverseMatrixMultiplication(const double * const M); 61 void KeepPeriodic(const double * const matrix); 62 bool GetOneNormalVector(const Vector &x1); 63 bool MakeNormalTo(const Vector &y1); 64 bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 65 void WrapPeriodically(const double * const M, const double * const Minv); 66 66 67 67 // Accessors ussually come in pairs... and sometimes even more than that 68 virtualdouble& operator[](size_t i);69 virtualconst double& operator[](size_t i) const;68 double& operator[](size_t i); 69 const double& operator[](size_t i) const; 70 70 double& at(size_t i); 71 71 const double& at(size_t i) const; 72 72 73 73 // Assignment operator 74 virtualVector &operator=(const Vector& src);74 Vector &operator=(const Vector& src); 75 75 76 76 // Access to internal structure 77 virtualdouble* get();77 double* get(); 78 78 79 79 // Methods that are derived directly from other methods … … 94 94 95 95 protected: 96 typedef std::auto_ptr<Vector> rep_ptr;97 Vector(Baseconstructor);98 Vector(Baseconstructor,const Vector*);99 static Vector VecFromRep(const Vector*);100 96 101 97 private: 102 // method used for protection, i.e. to avoid infinite recursion 103 // when our internal rep becomes messed up 104 virtual bool isBaseClass() const; 105 virtual Vector* clone() const; 106 // this is used to represent the vector internally 107 rep_ptr rep; 98 double x[NDIM]; 108 99 109 100 };
Note:
See TracChangeset
for help on using the changeset viewer.