Changeset d466f0
- Timestamp:
- Jun 2, 2010, 10:46:31 AM (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:
- d690fa
- Parents:
- 27ac00
- Location:
- src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/vector.cpp
r27ac00 rd466f0 23 23 Vector::Vector() 24 24 { 25 x[0] = x[1] = x[2] = 0.;25 content[0]=content[1]=content[2]=0; 26 26 }; 27 27 … … 32 32 Vector::Vector(const Vector& src) 33 33 { 34 x[0] =src[0];35 x[1] =src[1];36 x[2] =src[2];34 content[0]=src[0]; 35 content[1]=src[1]; 36 content[2]=src[2]; 37 37 } 38 38 … … 41 41 Vector::Vector(const double x1, const double x2, const double x3) 42 42 { 43 x[0] =x1;44 x[1] =x2;45 x[2] =x3;43 content[0]=x1; 44 content[1]=x2; 45 content[2]=x3; 46 46 }; 47 47 … … 52 52 // check for self assignment 53 53 if(&src!=this){ 54 x[0] =src[0];55 x[1] =src[1];56 x[2] =src[2];54 content[0]=src[0]; 55 content[1]=src[1]; 56 content[2]=src[2]; 57 57 } 58 58 return *this; … … 61 61 /** Desctructor of class vector. 62 62 */ 63 Vector::~Vector() {}; 63 Vector::~Vector() { 64 }; 64 65 65 66 /** Calculates square of distance between this and another vector. … … 71 72 double res = 0.; 72 73 for (int i=NDIM;i--;) 73 res += ( x[i]-y[i])*(x[i]-y[i]);74 res += (at(i)-y[i])*(at(i)-y[i]); 74 75 return (res); 75 76 }; … … 199 200 double res = 0.; 200 201 for (int i=NDIM;i--;) 201 res += x[i]*y[i];202 res += at(i)*y[i]; 202 203 return (res); 203 204 }; … … 213 214 { 214 215 Vector tmp; 215 tmp[0] = x[1]* y[2] - x[2]* y[1]; 216 tmp[1] = x[2]* y[0] - x[0]* y[2]; 217 tmp[2] = x[0]* y[1] - x[1]* y[0]; 216 for(int i=NDIM;i--;) 217 tmp[i] = at((i+1)%NDIM)*y[(i+2)%NDIM] - at((i+2)%NDIM)*y[(i+1)%NDIM]; 218 218 (*this) = tmp; 219 219 }; … … 308 308 bool Vector::IsZero() const 309 309 { 310 return (fabs( x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON);310 return (fabs(at(0))+fabs(at(1))+fabs(at(2)) < MYEPSILON); 311 311 }; 312 312 … … 337 337 bool status = true; 338 338 for (int i=0;i<NDIM;i++) { 339 if (fabs( x[i]- a[i]) > MYEPSILON)339 if (fabs(at(i) - a[i]) > MYEPSILON) 340 340 status = false; 341 341 } … … 365 365 double& Vector::operator[](size_t i){ 366 366 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); 367 return x[i];367 return content[i]; 368 368 } 369 369 370 370 const double& Vector::operator[](size_t i) const{ 371 371 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range"); 372 return x[i];372 return content[i]; 373 373 } 374 374 … … 382 382 383 383 double* Vector::get(){ 384 return x;384 return content; 385 385 } 386 386 … … 497 497 { 498 498 for (int i=NDIM;i--;) 499 x[i]*= factor[i];499 at(i) *= factor[i]; 500 500 }; 501 501 … … 505 505 { 506 506 for (int i=NDIM;i--;) 507 x[i]*= factor;507 at(i) *= factor; 508 508 }; 509 509 … … 517 517 // truncate to [0,1] for each axis 518 518 for (int i=0;i<NDIM;i++) { 519 x[i]+= 0.5; // set to center of box520 while ( x[i]>= 1.)521 x[i]-= 1.;522 while ( x[i]< 0.)523 x[i]+= 1.;519 at(i) += 0.5; // set to center of box 520 while (at(i) >= 1.) 521 at(i) -= 1.; 522 while (at(i) < 0.) 523 at(i) += 1.; 524 524 } 525 525 MatrixMultiplication(M); … … 548 548 void Vector::MatrixMultiplication(const double * const M) 549 549 { 550 Vector tmp; 550 551 // do the matrix multiplication 551 at(0) = M[0]*x[0]+M[3]*x[1]+M[6]*x[2]; 552 at(1) = M[1]*x[0]+M[4]*x[1]+M[7]*x[2]; 553 at(2) = M[2]*x[0]+M[5]*x[1]+M[8]*x[2]; 552 for(int i=NDIM;i--;) 553 tmp[i] = M[i]*at(0)+M[i+3]*at(1)+M[i+6]*at(2); 554 555 (*this) = tmp; 554 556 }; 555 557 … … 576 578 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33 577 579 578 // do the matrix multiplication 579 at(0) = B[0]*x[0]+B[3]*x[1]+B[6]*x[2]; 580 at(1) = B[1]*x[0]+B[4]*x[1]+B[7]*x[2]; 581 at(2) = B[2]*x[0]+B[5]*x[1]+B[8]*x[2]; 580 MatrixMultiplication(B); 582 581 583 582 return true; … … 615 614 SubtractVector(x1); 616 615 for (int i=NDIM;i--;) 617 result = result || (fabs( x[i]) > MYEPSILON);616 result = result || (fabs(at(i)) > MYEPSILON); 618 617 619 618 return result; … … 677 676 { 678 677 for(int i=NDIM;i--;) 679 x[i]+= y[i];678 at(i) += y[i]; 680 679 } 681 680 … … 686 685 { 687 686 for(int i=NDIM;i--;) 688 x[i]-= y[i];687 at(i) -= y[i]; 689 688 } 690 689 -
src/vector.hpp
r27ac00 rd466f0 31 31 */ 32 32 class Vector : public Space{ 33 protected:34 // this struct is used to indicate calls to the Baseconstructor from inside vectors.35 struct Baseconstructor{};36 33 public: 37 34 … … 107 104 108 105 private: 109 double x[NDIM];106 double content[NDIM]; 110 107 111 108 };
Note:
See TracChangeset
for help on using the changeset viewer.