Changeset 1bd79e
- Timestamp:
- Apr 15, 2010, 10:54:26 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:
- 753f02
- Parents:
- 273382
- Location:
- src
- Files:
-
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Makefile.am
r273382 r1bd79e 9 9 gslvector.cpp \ 10 10 linearsystemofequations.cpp \ 11 SingleVector.cpp \ 11 12 vector.cpp 12 13 … … 14 15 gslvector.hpp \ 15 16 linearsystemofequations.hpp \ 17 SingleVector.hpp \ 16 18 vector.hpp 17 19 … … 122 124 periodentafel.cpp \ 123 125 Plane.cpp \ 124 SingleVector.cpp \125 126 tesselation.cpp \ 126 127 tesselationhelpers.cpp \ … … 158 159 periodentafel.hpp \ 159 160 Plane.hpp \ 160 SingleVector.hpp \161 161 stackclass.hpp \ 162 162 tesselation.hpp \ -
src/SingleVector.cpp
r273382 r1bd79e 21 21 #include <gsl/gsl_vector.h> 22 22 23 #include <iostream> 24 25 using namespace std; 26 23 27 /************************************ Functions for class vector ************************************/ 24 28 25 29 /** Constructor of class vector. 26 30 */ 27 SingleVector::SingleVector() 31 SingleVector::SingleVector() : 32 Vector(Baseconstructor()) 28 33 { 29 34 x[0] = x[1] = x[2] = 0.; … … 32 37 /** Constructor of class vector. 33 38 */ 34 SingleVector::SingleVector(const double x1, const double x2, const double x3) 39 SingleVector::SingleVector(const double x1, const double x2, const double x3) : 40 Vector(Baseconstructor()) 35 41 { 36 42 x[0] = x1; … … 42 48 * Copy constructor 43 49 */ 44 SingleVector::SingleVector(const Vector& src) 50 SingleVector::SingleVector(const Vector& src) : 51 Vector(Baseconstructor()) 45 52 { 46 53 x[0] = src[0]; … … 49 56 } 50 57 51 /** 52 * Assignment operator 53 */ 54 Vector& SingleVector::operator=(const Vector& src){ 55 // check for self assignment 56 if(&src!=this){ 57 x[0] = src[0]; 58 x[1] = src[1]; 59 x[2] = src[2]; 60 } 61 return *this; 58 SingleVector* SingleVector::clone() const{ 59 return new SingleVector(x[0],x[1],x[2]); 62 60 } 63 61 … … 76 74 res += (x[i]-y[i])*(x[i]-y[i]); 77 75 return (res); 78 };79 80 /** Calculates distance between this and another vector.81 * \param *y array to second vector82 * \return \f$| x - y |\f$83 */84 double SingleVector::Distance(const Vector &y) const85 {86 double res = 0.;87 for (int i=NDIM;i--;)88 res += (x[i]-y[i])*(x[i]-y[i]);89 return (sqrt(res));90 76 }; 91 77 … … 173 159 // bool flag = false; 174 160 //vector Shifted, TranslationVector; 175 Vector TestVector;176 161 // Log() << Verbose(1) << "Begin of KeepPeriodic." << endl; 177 162 // Log() << Verbose(2) << "Vector is: "; 178 163 // Output(out); 179 164 // Log() << Verbose(0) << endl; 180 TestVector = *this;165 SingleVector TestVector(*this); 181 166 TestVector.InverseMatrixMultiplication(matrix); 182 167 for(int i=NDIM;i--;) { // correct periodically … … 208 193 209 194 195 void SingleVector::AddVector(const Vector &y) { 196 for(int i=NDIM;i--;) 197 x[i] += y[i]; 198 } 199 200 void SingleVector::SubtractVector(const Vector &y){ 201 for(int i=NDIM;i--;) 202 x[i] -= y[i]; 203 } 204 210 205 /** Calculates VectorProduct between this and another vector. 211 206 * -# returns the Product in place of vector from which it was initiated … … 216 211 void SingleVector::VectorProduct(const Vector &y) 217 212 { 218 Vector tmp;213 SingleVector tmp; 219 214 tmp[0] = x[1]* (y[2]) - x[2]* (y[1]); 220 215 tmp[1] = x[2]* (y[0]) - x[0]* (y[2]); 221 216 tmp[2] = x[0]* (y[1]) - x[1]* (y[0]); 222 (*this) = tmp;217 CopyVector(tmp); 223 218 }; 224 219 … … 245 240 double SingleVector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const 246 241 { 247 Vector temp;248 249 242 // first create part that is orthonormal to PlaneNormal with withdraw 250 temp = (*this)- PlaneOffset;243 Vector temp = VecFromRep(this)- PlaneOffset; 251 244 temp.MakeNormalTo(PlaneNormal); 252 245 temp.Scale(-1.); 253 246 // then add connecting vector from plane to point 254 temp += (*this)-PlaneOffset;247 temp += VecFromRep(this)-PlaneOffset; 255 248 double sign = temp.ScalarProduct(PlaneNormal); 256 249 if (fabs(sign) > MYEPSILON) … … 282 275 283 276 return helper; 284 };285 286 /** Calculates norm of this vector.287 * \return \f$|x|\f$288 */289 double SingleVector::Norm() const290 {291 double res = 0.;292 for (int i=NDIM;i--;)293 res += this->x[i]*this->x[i];294 return (sqrt(res));295 };296 297 /** Calculates squared norm of this vector.298 * \return \f$|x|^2\f$299 */300 double SingleVector::NormSquared() const301 {302 return (ScalarProduct(*this));303 };304 305 /** Normalizes this vector.306 */307 void SingleVector::Normalize()308 {309 double res = 0.;310 for (int i=NDIM;i--;)311 res += this->x[i]*this->x[i];312 if (fabs(res) > MYEPSILON)313 res = 1./sqrt(res);314 Scale(&res);315 };316 317 /** Zeros all components of this vector.318 */319 void SingleVector::Zero()320 {321 for (int i=NDIM;i--;)322 this->x[i] = 0.;323 };324 325 /** Zeros all components of this vector.326 */327 void SingleVector::One(const double one)328 {329 for (int i=NDIM;i--;)330 this->x[i] = one;331 };332 333 /** Initialises all components of this vector.334 */335 void SingleVector::Init(const double x1, const double x2, const double x3)336 {337 x[0] = x1;338 x[1] = x2;339 x[2] = x3;340 277 }; 341 278 … … 410 347 } 411 348 412 double& SingleVector::at(size_t i){413 return (*this)[i];414 }415 416 const double& SingleVector::at(size_t i) const{417 return (*this)[i];418 }419 420 349 double* SingleVector::get(){ 421 350 return x; … … 424 353 * \param *factor pointer to scaling factor 425 354 */ 426 void SingleVector::Scale(const double ** const factor) 427 { 428 for (int i=NDIM;i--;) 429 x[i] *= (*factor)[i]; 430 }; 431 432 void SingleVector::Scale(const double * const factor) 433 { 434 for (int i=NDIM;i--;) 435 x[i] *= *factor; 355 void SingleVector::ScaleAll(const double *factor) 356 { 357 for (int i=NDIM;i--;) 358 x[i] *= factor[i]; 436 359 }; 437 360 … … 440 363 for (int i=NDIM;i--;) 441 364 x[i] *= factor; 442 };443 444 /** Translate atom by given vector.445 * \param trans[] translation vector.446 */447 void SingleVector::Translate(const Vector &trans)448 {449 for (int i=NDIM;i--;)450 x[i] += trans[i];451 365 }; 452 366 … … 474 388 void SingleVector::MatrixMultiplication(const double * const M) 475 389 { 476 Vector C;390 SingleVector C; 477 391 // do the matrix multiplication 478 392 C[0] = M[0]*x[0]+M[3]*x[1]+M[6]*x[2]; … … 480 394 C[2] = M[2]*x[0]+M[5]*x[1]+M[8]*x[2]; 481 395 482 *this = C;396 CopyVector(C); 483 397 }; 484 398 … … 488 402 bool SingleVector::InverseMatrixMultiplication(const double * const A) 489 403 { 490 Vector C;404 SingleVector C; 491 405 double B[NDIM*NDIM]; 492 406 double detA = RDET3(A); … … 511 425 C[2] = B[2]*x[0]+B[5]*x[1]+B[8]*x[2]; 512 426 513 *this = C;427 CopyVector(C); 514 428 return true; 515 429 } else { … … 518 432 }; 519 433 520 521 /** Creates this vector as the b y *factors' components scaled linear combination of the given three.522 * this vector = x1*factors[0] + x2* factors[1] + x3*factors[2]523 * \param *x1 first vector524 * \param *x2 second vector525 * \param *x3 third vector526 * \param *factors three-component vector with the factor for each given vector527 */528 void SingleVector::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)529 {530 for(int i=NDIM;i--;)531 x[i] = factors[0]*x1[i] + factors[1]*x2[i] + factors[2]*x3[i];532 };533 434 534 435 /** Mirrors atom against a given plane. … … 615 516 bool SingleVector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const 616 517 { 617 Vector a = (*this) - offset; 518 Vector a = VecFromRep(this); 519 a -= offset; 618 520 a.InverseMatrixMultiplication(parallelepiped); 619 521 bool isInside = true; … … 624 526 return isInside; 625 527 } 528 529 530 void SingleVector::CopyVector(SingleVector& vec) { 531 for(int i =NDIM; i--;) 532 x[i]=vec.x[i]; 533 } 534 535 bool SingleVector::isBaseClass() const{ 536 return false; 537 } -
src/SingleVector.hpp
r273382 r1bd79e 31 31 virtual ~SingleVector(); 32 32 33 virtual double Distance(const Vector &y) const;34 33 virtual double DistanceSquared(const Vector &y) const; 35 34 virtual double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const; … … 37 36 virtual double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const; 38 37 virtual double ScalarProduct(const Vector &y) const; 39 virtual double Norm() const;40 virtual double NormSquared() const;41 38 virtual double Angle(const Vector &y) const; 42 39 virtual bool IsZero() const; … … 45 42 virtual bool IsEqualTo(const Vector &a) const; 46 43 44 virtual void AddVector(const Vector &y); 45 virtual void SubtractVector(const Vector &y); 47 46 virtual void VectorProduct(const Vector &y); 48 47 virtual void ProjectOntoPlane(const Vector &y); 49 48 virtual void ProjectIt(const Vector &y); 50 49 virtual Vector Projection(const Vector &y) const; 51 virtual void Zero();52 virtual void One(const double one);53 virtual void Init(const double x1, const double x2, const double x3);54 virtual void Normalize();55 virtual void Translate(const Vector &x);56 50 virtual void Mirror(const Vector &x); 57 virtual void Scale(const double ** const factor); 58 virtual void Scale(const double * const factor); 51 virtual void ScaleAll(const double *factor); 59 52 virtual void Scale(const double factor); 60 53 virtual void MatrixMultiplication(const double * const M); 61 54 virtual bool InverseMatrixMultiplication(const double * const M); 62 55 virtual void KeepPeriodic(const double * const matrix); 63 virtual void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors);64 56 virtual bool GetOneNormalVector(const Vector &x1); 65 57 virtual bool MakeNormalTo(const Vector &y1); 66 //bool SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c);67 58 virtual bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 68 59 virtual void WrapPeriodically(const double * const M, const double * const Minv); … … 71 62 virtual double& operator[](size_t i); 72 63 virtual const double& operator[](size_t i) const; 73 virtual double& at(size_t i);74 virtual const double& at(size_t i) const;75 76 // Assignment operator77 virtual Vector &operator=(const Vector& src);78 64 79 65 // Access to internal structure 80 66 virtual double* get(); 67 protected: 81 68 82 69 private: 70 // method used for protection, i.e. to avoid infinite recursion 71 // when our internal rep becomes messed up 72 virtual bool isBaseClass() const; 73 virtual SingleVector *clone() const; 74 void CopyVector(SingleVector &rhs); 83 75 double x[NDIM]; 84 76 -
src/boundary.cpp
r273382 r1bd79e 827 827 828 828 // calculate filler grid in [0,1]^3 829 FillerDistance .Init(distance[0], distance[1], distance[2]);829 FillerDistance = Vector(distance[0], distance[1], distance[2]); 830 830 FillerDistance.InverseMatrixMultiplication(M); 831 831 for(int i=0;i<NDIM;i++) … … 841 841 for (n[2] = 0; n[2] < N[2]; n[2]++) { 842 842 // calculate position of current grid vector in untransformed box 843 CurrentPosition .Init((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]);843 CurrentPosition = Vector((double)n[0]/(double)N[0], (double)n[1]/(double)N[1], (double)n[2]/(double)N[2]); 844 844 CurrentPosition.MatrixMultiplication(M); 845 845 Log() << Verbose(2) << "INFO: Current Position is " << CurrentPosition << "." << endl; -
src/builder.cpp
r273382 r1bd79e 1644 1644 first = World::getInstance().createAtom(); 1645 1645 first->type = periode->FindElement(1); 1646 first->x .Init(0.441, -0.143, 0.);1646 first->x = Vector(0.441, -0.143, 0.); 1647 1647 filler->AddAtom(first); 1648 1648 second = World::getInstance().createAtom(); 1649 1649 second->type = periode->FindElement(1); 1650 second->x .Init(-0.464, 1.137, 0.0);1650 second->x = Vector(-0.464, 1.137, 0.0); 1651 1651 filler->AddAtom(second); 1652 1652 third = World::getInstance().createAtom(); 1653 1653 third->type = periode->FindElement(8); 1654 third->x .Init(-0.464, 0.177, 0.);1654 third->x = Vector(-0.464, 0.177, 0.); 1655 1655 filler->AddAtom(third); 1656 1656 filler->AddBond(first, third, 1); -
src/ellipsoid.cpp
r273382 r1bd79e 59 59 Matrix[8] = cos(theta); 60 60 helper.MatrixMultiplication(Matrix); 61 helper.Scale (InverseLength);61 helper.ScaleAll(InverseLength); 62 62 //Log() << Verbose(4) << "Transformed RefPoint is at " << helper << "." << endl; 63 63 … … 70 70 theta = -EllipsoidAngle[1]; 71 71 phi = -EllipsoidAngle[2]; 72 helper.Scale (EllipsoidLength);72 helper.ScaleAll(EllipsoidLength); 73 73 Matrix[0] = cos(psi)*cos(phi) - sin(psi)*cos(theta)*sin(phi); 74 74 Matrix[1] = -cos(psi)*sin(phi) - sin(psi)*cos(theta)*cos(phi); -
src/molecule.cpp
r273382 r1bd79e 239 239 matrix = ReturnFullMatrixforSymmetric(cell_size); 240 240 Orthovector1.MatrixMultiplication(matrix); 241 InBondvector .SubtractVector(Orthovector1); // subtract just the additional translation241 InBondvector -= Orthovector1; // subtract just the additional translation 242 242 Free(&matrix); 243 243 bondlength = InBondvector.Norm(); … … 272 272 FirstOtherAtom->father = NULL; // if we replace hydrogen, we mark it as our father, otherwise we are just an added hydrogen with no father 273 273 } 274 InBondvector .Scale(&BondRescale); // rescale the distance vector to Hydrogen bond length274 InBondvector *= BondRescale; // rescale the distance vector to Hydrogen bond length 275 275 FirstOtherAtom->x = TopOrigin->x; // set coordination to origin ... 276 276 FirstOtherAtom->x = InBondvector; // ... and add distance vector to replacement atom … … 356 356 SecondOtherAtom->x[i] = InBondvector[i] * cos(bondangle) + Orthovector1[i] * (-sin(bondangle)); 357 357 } 358 FirstOtherAtom->x .Scale(&BondRescale); // rescale by correct BondDistance359 SecondOtherAtom->x .Scale(&BondRescale);358 FirstOtherAtom->x *= BondRescale; // rescale by correct BondDistance 359 SecondOtherAtom->x *= BondRescale; 360 360 //Log() << Verbose(3) << "ReScaleCheck: " << FirstOtherAtom->x.Norm() << " and " << SecondOtherAtom->x.Norm() << "." << endl; 361 361 for(int i=NDIM;i--;) { // and make relative to origin atom -
src/molecule_geometry.cpp
r273382 r1bd79e 191 191 /** Scales all atoms by \a *factor. 192 192 * \param *factor pointer to scaling factor 193 * 194 * TODO: Is this realy what is meant, i.e. 195 * x=(x[0]*factor[0],x[1]*factor[1],x[2]*factor[2]) (current impl) 196 * or rather 197 * x=(**factor) * x (as suggested by comment) 193 198 */ 194 199 void molecule::Scale(const double ** const factor) … … 199 204 ptr = ptr->next; 200 205 for (int j=0;j<MDSteps;j++) 201 ptr->Trajectory.R.at(j).Scale (factor);202 ptr->x.Scale (factor);206 ptr->Trajectory.R.at(j).ScaleAll(*factor); 207 ptr->x.ScaleAll(*factor); 203 208 } 204 209 }; … … 214 219 ptr = ptr->next; 215 220 for (int j=0;j<MDSteps;j++) 216 ptr->Trajectory.R.at(j) .Translate(*trans);217 ptr->x .Translate(*trans);221 ptr->Trajectory.R.at(j) += (*trans); 222 ptr->x += (*trans); 218 223 } 219 224 }; -
src/tesselationhelpers.cpp
r273382 r1bd79e 427 427 double volume; 428 428 429 TetraederVector[0] .CopyVector(a);430 TetraederVector[1] .CopyVector(b);431 TetraederVector[2] .CopyVector(c);429 TetraederVector[0] = a; 430 TetraederVector[1] = b; 431 TetraederVector[2] = c; 432 432 for (int j=0;j<3;j++) 433 433 TetraederVector[j].SubtractVector(d); 434 Point .CopyVector(TetraederVector[0]);434 Point = TetraederVector[0]; 435 435 Point.VectorProduct(TetraederVector[1]); 436 436 volume = 1./6. * fabs(Point.ScalarProduct(TetraederVector[2])); -
src/unittests/ActOnAllUnitTest.cpp
r273382 r1bd79e 70 70 71 71 // scaling by value 72 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 2.);72 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, factor ); 73 73 CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); 74 74 75 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, 0.5 ); 76 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 77 78 // scaling by ref 79 VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&factor ); 80 CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); 81 82 VL.ActOnAll( (void (Vector::*)(const double * const)) &Vector::Scale, (const double * const)&inverse ); 75 VL.ActOnAll( (void (Vector::*)(const double)) &Vector::Scale, inverse ); 83 76 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 84 77 … … 90 83 inverses[i] = 1./factors[i]; 91 84 } 92 VL.ActOnAll ( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&factors );85 VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, factors ); 93 86 CPPUNIT_ASSERT_EQUAL( VL == Ref , false ); 94 87 95 VL.ActOnAll ( (void (Vector::*)(const double ** const)) &Vector::Scale, (const double ** const)&inverses );88 VL.ActOnAll<Vector,void,const double*>(&Vector::ScaleAll, inverses ); 96 89 CPPUNIT_ASSERT_EQUAL( VL == Ref , true ); 97 90 Free(factors); -
src/unittests/AnalysisCorrelationToPointUnitTest.cpp
r273382 r1bd79e 64 64 Walker = World::getInstance().createAtom(); 65 65 Walker->type = hydrogen; 66 Walker->node->Init(1., 0., 1. );66 *Walker->node = Vector(1., 0., 1. ); 67 67 TestMolecule->AddAtom(Walker); 68 68 Walker = World::getInstance().createAtom(); 69 69 Walker->type = hydrogen; 70 Walker->node->Init(0., 1., 1. );70 *Walker->node = Vector(0., 1., 1. ); 71 71 TestMolecule->AddAtom(Walker); 72 72 Walker = World::getInstance().createAtom(); 73 73 Walker->type = hydrogen; 74 Walker->node->Init(1., 1., 0. );74 *Walker->node = Vector(1., 1., 0. ); 75 75 TestMolecule->AddAtom(Walker); 76 76 Walker = World::getInstance().createAtom(); 77 77 Walker->type = hydrogen; 78 Walker->node->Init(0., 0., 0. );78 *Walker->node = Vector(0., 0., 0. ); 79 79 TestMolecule->AddAtom(Walker); 80 80 -
src/unittests/AnalysisCorrelationToSurfaceUnitTest.cpp
r273382 r1bd79e 40 40 void AnalysisCorrelationToSurfaceUnitTest::setUp() 41 41 { 42 ASSERT_DO(Assert::Throw);42 //ASSERT_DO(Assert::Throw); 43 43 44 44 atom *Walker = NULL; … … 73 73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 Walker->node->Init(1., 0., 1. );76 TestMolecule->AddAtom(Walker); 77 Walker = World::getInstance().createAtom(); 78 Walker->type = hydrogen; 79 Walker->node->Init(0., 1., 1. );80 TestMolecule->AddAtom(Walker); 81 Walker = World::getInstance().createAtom(); 82 Walker->type = hydrogen; 83 Walker->node->Init(1., 1., 0. );84 TestMolecule->AddAtom(Walker); 85 Walker = World::getInstance().createAtom(); 86 Walker->type = hydrogen; 87 Walker->node->Init(0., 0., 0. );75 *Walker->node = Vector(1., 0., 1. ); 76 TestMolecule->AddAtom(Walker); 77 Walker = World::getInstance().createAtom(); 78 Walker->type = hydrogen; 79 *Walker->node = Vector(0., 1., 1. ); 80 TestMolecule->AddAtom(Walker); 81 Walker = World::getInstance().createAtom(); 82 Walker->type = hydrogen; 83 *Walker->node = Vector(1., 1., 0. ); 84 TestMolecule->AddAtom(Walker); 85 Walker = World::getInstance().createAtom(); 86 Walker->type = hydrogen; 87 *Walker->node = Vector(0., 0., 0. ); 88 88 TestMolecule->AddAtom(Walker); 89 89 … … 106 106 Walker = World::getInstance().createAtom(); 107 107 Walker->type = carbon; 108 Walker->node->Init(4., 0., 4. );109 TestMolecule->AddAtom(Walker); 110 Walker = World::getInstance().createAtom(); 111 Walker->type = carbon; 112 Walker->node->Init(0., 4., 4. );113 TestMolecule->AddAtom(Walker); 114 Walker = World::getInstance().createAtom(); 115 Walker->type = carbon; 116 Walker->node->Init(4., 4., 0. );108 *Walker->node = Vector(4., 0., 4. ); 109 TestMolecule->AddAtom(Walker); 110 Walker = World::getInstance().createAtom(); 111 Walker->type = carbon; 112 *Walker->node = Vector(0., 4., 4. ); 113 TestMolecule->AddAtom(Walker); 114 Walker = World::getInstance().createAtom(); 115 Walker->type = carbon; 116 *Walker->node = Vector(4., 4., 0. ); 117 117 TestMolecule->AddAtom(Walker); 118 118 // add inner atoms 119 119 Walker = World::getInstance().createAtom(); 120 120 Walker->type = carbon; 121 Walker->node->Init(0.5, 0.5, 0.5 );121 *Walker->node = Vector(0.5, 0.5, 0.5 ); 122 122 TestMolecule->AddAtom(Walker); 123 123 -
src/unittests/AnalysisPairCorrelationUnitTest.cpp
r273382 r1bd79e 63 63 Walker = World::getInstance().createAtom(); 64 64 Walker->type = hydrogen; 65 Walker->node->Init(1., 0., 1. );65 *Walker->node = Vector(1., 0., 1. ); 66 66 TestMolecule->AddAtom(Walker); 67 67 Walker = World::getInstance().createAtom(); 68 68 Walker->type = hydrogen; 69 Walker->node->Init(0., 1., 1. );69 *Walker->node = Vector(0., 1., 1. ); 70 70 TestMolecule->AddAtom(Walker); 71 71 Walker = World::getInstance().createAtom(); 72 72 Walker->type = hydrogen; 73 Walker->node->Init(1., 1., 0. );73 *Walker->node = Vector(1., 1., 0. ); 74 74 TestMolecule->AddAtom(Walker); 75 75 Walker = World::getInstance().createAtom(); 76 76 Walker->type = hydrogen; 77 Walker->node->Init(0., 0., 0. );77 *Walker->node = Vector(0., 0., 0. ); 78 78 TestMolecule->AddAtom(Walker); 79 79 -
src/unittests/analysisbondsunittest.cpp
r273382 r1bd79e 69 69 Walker = World::getInstance().createAtom(); 70 70 Walker->type = hydrogen; 71 Walker->node->Init(1.5, 0., 1.5 );71 *Walker->node = Vector(1.5, 0., 1.5 ); 72 72 TestMolecule->AddAtom(Walker); 73 73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 Walker->node->Init(0., 1.5, 1.5 );75 *Walker->node = Vector(0., 1.5, 1.5 ); 76 76 TestMolecule->AddAtom(Walker); 77 77 Walker = World::getInstance().createAtom(); 78 78 Walker->type = hydrogen; 79 Walker->node->Init(1.5, 1.5, 0. );79 *Walker->node = Vector(1.5, 1.5, 0. ); 80 80 TestMolecule->AddAtom(Walker); 81 81 Walker = World::getInstance().createAtom(); 82 82 Walker->type = hydrogen; 83 Walker->node->Init(0., 0., 0. );83 *Walker->node = Vector(0., 0., 0. ); 84 84 TestMolecule->AddAtom(Walker); 85 85 Walker = World::getInstance().createAtom(); 86 86 Walker->type = carbon; 87 Walker->node->Init(0.5, 0.5, 0.5 );87 *Walker->node = Vector(0.5, 0.5, 0.5 ); 88 88 TestMolecule->AddAtom(Walker); 89 89 -
src/unittests/bondgraphunittest.cpp
r273382 r1bd79e 65 65 Walker = World::getInstance().createAtom(); 66 66 Walker->type = hydrogen; 67 Walker->node->Init(1., 0., 1. );67 *Walker->node = Vector(1., 0., 1. ); 68 68 TestMolecule->AddAtom(Walker); 69 69 Walker = World::getInstance().createAtom(); 70 70 Walker->type = hydrogen; 71 Walker->node->Init(0., 1., 1. );71 *Walker->node = Vector(0., 1., 1. ); 72 72 TestMolecule->AddAtom(Walker); 73 73 Walker = World::getInstance().createAtom(); 74 74 Walker->type = hydrogen; 75 Walker->node->Init(1., 1., 0. );75 *Walker->node = Vector(1., 1., 0. ); 76 76 TestMolecule->AddAtom(Walker); 77 77 Walker = World::getInstance().createAtom(); 78 78 Walker->type = hydrogen; 79 Walker->node->Init(0., 0., 0. );79 *Walker->node = Vector(0., 0., 0. ); 80 80 TestMolecule->AddAtom(Walker); 81 81 -
src/unittests/listofbondsunittest.cpp
r273382 r1bd79e 58 58 Walker = World::getInstance().createAtom(); 59 59 Walker->type = hydrogen; 60 Walker->node->Init(1., 0., 1. );61 TestMolecule->AddAtom(Walker); 62 Walker = World::getInstance().createAtom(); 63 Walker->type = hydrogen; 64 Walker->node->Init(0., 1., 1. );65 TestMolecule->AddAtom(Walker); 66 Walker = World::getInstance().createAtom(); 67 Walker->type = hydrogen; 68 Walker->node->Init(1., 1., 0. );69 TestMolecule->AddAtom(Walker); 70 Walker = World::getInstance().createAtom(); 71 Walker->type = hydrogen; 72 Walker->node->Init(0., 0., 0. );60 *Walker->node = Vector(1., 0., 1. ); 61 TestMolecule->AddAtom(Walker); 62 Walker = World::getInstance().createAtom(); 63 Walker->type = hydrogen; 64 *Walker->node = Vector(0., 1., 1. ); 65 TestMolecule->AddAtom(Walker); 66 Walker = World::getInstance().createAtom(); 67 Walker->type = hydrogen; 68 *Walker->node = Vector(1., 1., 0. ); 69 TestMolecule->AddAtom(Walker); 70 Walker = World::getInstance().createAtom(); 71 Walker->type = hydrogen; 72 *Walker->node = Vector(0., 0., 0. ); 73 73 TestMolecule->AddAtom(Walker); 74 74 -
src/unittests/tesselation_boundarytriangleunittest.cpp
r273382 r1bd79e 86 86 87 87 // simple test on y line 88 Point .Init(-1.,0.5,0.);89 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 90 Point .Init(0.,0.5,0.);91 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 92 Point .Init(-4.,0.5,0.);88 Point = Vector(-1.,0.5,0.); 89 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 90 Point = Vector(0.,0.5,0.); 91 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 92 Point = Vector(-4.,0.5,0.); 93 93 CPPUNIT_ASSERT_EQUAL( 16., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 94 Point .Init(0.,0.5,0.);94 Point = Vector(0.,0.5,0.); 95 95 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 96 96 97 97 // simple test on x line 98 Point .Init(0.5,-1.,0.);99 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 100 Point .Init(0.5,0.,0.);101 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 102 Point .Init(0.5,-6.,0.);98 Point = Vector(0.5,-1.,0.); 99 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 100 Point = Vector(0.5,0.,0.); 101 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 102 Point = Vector(0.5,-6.,0.); 103 103 CPPUNIT_ASSERT_EQUAL( 36., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 104 Point .Init(0.5,0.,0.);104 Point = Vector(0.5,0.,0.); 105 105 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 106 106 107 107 // simple test on slanted line 108 Point .Init(1.,1.,0.);108 Point = Vector(1.,1.,0.); 109 109 CPPUNIT_ASSERT_EQUAL( 0.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 110 Point .Init(0.5,0.5,0.);111 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 112 Point .Init(5.,5.,0.);110 Point = Vector(0.5,0.5,0.); 111 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 112 Point = Vector(5.,5.,0.); 113 113 CPPUNIT_ASSERT_EQUAL( 40.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 114 Point .Init(0.5,0.5,0.);114 Point = Vector(0.5,0.5,0.); 115 115 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 116 116 117 117 // simple test on first node 118 Point .Init(-1.,-1.,0.);118 Point = Vector(-1.,-1.,0.); 119 119 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 120 Point .Init(0.,0.,0.);120 Point = Vector(0.,0.,0.); 121 121 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 122 122 123 123 // simple test on second node 124 Point .Init(0.,2.,0.);125 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 126 Point .Init(0.,1.,0.);124 Point = Vector(0.,2.,0.); 125 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 126 Point = Vector(0.,1.,0.); 127 127 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 128 128 129 129 // simple test on third node 130 Point .Init(2.,0.,0.);131 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 132 Point .Init(1.,0.,0.);130 Point = Vector(2.,0.,0.); 131 CPPUNIT_ASSERT_EQUAL( 1., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 132 Point = Vector(1.,0.,0.); 133 133 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 134 134 }; … … 142 142 143 143 // straight down/up 144 Point .Init(1./3.,1./3.,+5.);144 Point = Vector(1./3.,1./3.,+5.); 145 145 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 146 Point .Init(1./3.,1./3.,0.);147 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 148 Point .Init(1./3.,1./3.,-5.);146 Point = Vector(1./3.,1./3.,0.); 147 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 148 Point = Vector(1./3.,1./3.,-5.); 149 149 CPPUNIT_ASSERT_EQUAL( 25. , triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 150 Point .Init(1./3.,1./3.,0.);150 Point = Vector(1./3.,1./3.,0.); 151 151 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 152 152 153 153 // simple test on y line 154 Point .Init(-1.,0.5,+2.);154 Point = Vector(-1.,0.5,+2.); 155 155 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 156 Point .Init(0.,0.5,0.);157 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 158 Point .Init(-1.,0.5,-3.);156 Point = Vector(0.,0.5,0.); 157 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 158 Point = Vector(-1.,0.5,-3.); 159 159 CPPUNIT_ASSERT_EQUAL( 10., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 160 Point .Init(0.,0.5,0.);160 Point = Vector(0.,0.5,0.); 161 161 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 162 162 163 163 // simple test on x line 164 Point .Init(0.5,-1.,+1.);164 Point = Vector(0.5,-1.,+1.); 165 165 CPPUNIT_ASSERT_EQUAL( 2., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 166 Point .Init(0.5,0.,0.);167 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 168 Point .Init(0.5,-1.,-2.);166 Point = Vector(0.5,0.,0.); 167 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 168 Point = Vector(0.5,-1.,-2.); 169 169 CPPUNIT_ASSERT_EQUAL( 5., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 170 Point .Init(0.5,0.,0.);170 Point = Vector(0.5,0.,0.); 171 171 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 172 172 173 173 // simple test on slanted line 174 Point .Init(1.,1.,+3.);174 Point = Vector(1.,1.,+3.); 175 175 CPPUNIT_ASSERT_EQUAL( 9.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 176 Point .Init(0.5,0.5,0.);177 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 178 Point .Init(1.,1.,-4.);176 Point = Vector(0.5,0.5,0.); 177 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 178 Point = Vector(1.,1.,-4.); 179 179 CPPUNIT_ASSERT_EQUAL( 16.5, triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 180 Point .Init(0.5,0.5,0.);180 Point = Vector(0.5,0.5,0.); 181 181 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 182 182 183 183 // simple test on first node 184 Point .Init(-1.,-1.,5.);184 Point = Vector(-1.,-1.,5.); 185 185 CPPUNIT_ASSERT_EQUAL( 27., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 186 Point .Init(0.,0.,0.);186 Point = Vector(0.,0.,0.); 187 187 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 188 188 189 189 // simple test on second node 190 Point .Init(0.,2.,5.);190 Point = Vector(0.,2.,5.); 191 191 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 192 Point .Init(0.,1.,0.);192 Point = Vector(0.,1.,0.); 193 193 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 194 194 195 195 // simple test on third node 196 Point .Init(2.,0.,5.);196 Point = Vector(2.,0.,5.); 197 197 CPPUNIT_ASSERT_EQUAL( 26., triangle->GetClosestPointInsideTriangle(&Point, &TestIntersection) ); 198 Point .Init(1.,0.,0.);199 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 200 }; 198 Point = Vector(1.,0.,0.); 199 CPPUNIT_ASSERT_EQUAL( true , Point == TestIntersection ); 200 }; -
src/unittests/vectorunittest.cpp
r273382 r1bd79e 26 26 #endif /*HAVE_TESTRUNNER*/ 27 27 28 #include <iostream> 29 30 using namespace std; 31 28 32 /********************************************** Test classes **************************************/ 29 33 … … 34 38 void VectorTest::setUp() 35 39 { 36 zero .Init(0.,0.,0.);37 unit .Init(1.,0.,0.);38 otherunit .Init(0.,1.,0.);39 notunit .Init(0.,1.,1.);40 two .Init(2.,1.,0.);40 zero = Vector(0.,0.,0.); 41 unit = Vector(1.,0.,0.); 42 otherunit = Vector(0.,1.,0.); 43 notunit = Vector(0.,1.,1.); 44 two = Vector(2.,1.,0.); 41 45 }; 42 46 … … 69 73 double factor; 70 74 // copy vector 71 fixture .Init(2.,3.,4.);75 fixture = Vector(2.,3.,4.); 72 76 CPPUNIT_ASSERT_EQUAL( Vector(2.,3.,4.), fixture ); 73 77 // summation and scaling … … 223 227 void VectorTest::VectorRotationTest() 224 228 { 225 fixture .Init(-1.,0.,0.);229 fixture = Vector(-1.,0.,0.); 226 230 227 231 // zero vector does not change … … 266 270 parallelepiped[8] = 1; 267 271 268 fixture .CopyVector(zero);269 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 270 fixture .Init(2.5,2.5,2.5);272 fixture = zero; 273 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 274 fixture = Vector(2.5,2.5,2.5); 271 275 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 272 fixture .Init(1.,1.,1.);273 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 274 fixture .Init(3.5,3.5,3.5);275 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 276 fixture .Init(2.,2.,2.);276 fixture = Vector(1.,1.,1.); 277 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 278 fixture = Vector(3.5,3.5,3.5); 279 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 280 fixture = Vector(2.,2.,2.); 277 281 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 278 fixture .Init(2.,3.,2.);282 fixture = Vector(2.,3.,2.); 279 283 CPPUNIT_ASSERT_EQUAL( true, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 280 fixture .Init(-2.,2.,-1.);281 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 282 } 283 284 fixture = Vector(-2.,2.,-1.); 285 CPPUNIT_ASSERT_EQUAL( false, fixture.IsInParallelepiped(Vector(2.,2.,2.), parallelepiped) ); 286 } 287 -
src/vector.cpp
r273382 r1bd79e 6 6 7 7 8 #include "defs.hpp" 9 #include "gslmatrix.hpp" 10 #include "leastsquaremin.hpp" 11 #include "memoryallocator.hpp" 12 #include "vector.hpp" 13 #include "Helpers/fast_functions.hpp" 8 #include "SingleVector.hpp" 14 9 #include "Helpers/Assert.hpp" 15 #include "Plane.hpp" 16 #include "Exceptions/LinearDependenceException.hpp" 17 18 #include <gsl/gsl_linalg.h> 19 #include <gsl/gsl_matrix.h> 20 #include <gsl/gsl_permutation.h> 21 #include <gsl/gsl_vector.h> 10 11 #include <iostream> 12 13 using namespace std; 14 22 15 23 16 /************************************ Functions for class vector ************************************/ … … 25 18 /** Constructor of class vector. 26 19 */ 27 Vector::Vector() 28 { 29 x[0] = x[1] = x[2] = 0.; 30 }; 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 } 31 34 32 35 /** Constructor of class vector. 33 36 */ 34 Vector::Vector(const double x1, const double x2, const double x3) 35 { 36 x[0] = x1; 37 x[1] = x2; 38 x[2] = x3; 39 }; 37 Vector::Vector(const double x1, const double x2, const double x3) : 38 rep(new SingleVector(x1,x2,x3)) 39 {}; 40 40 41 41 /** 42 42 * Copy constructor 43 43 */ 44 Vector::Vector(const Vector& src) 45 { 46 x[0] = src[0]; 47 x[1] = src[1]; 48 x[2] = src[2]; 49 } 44 Vector::Vector(const Vector& src) : 45 rep(src.rep->clone()) 46 {} 50 47 51 48 /** … … 53 50 */ 54 51 Vector& Vector::operator=(const Vector& src){ 52 ASSERT(isBaseClass(),"Operator used on Derived Vector object"); 55 53 // check for self assignment 56 54 if(&src!=this){ 57 x[0] = src[0]; 58 x[1] = src[1]; 59 x[2] = src[2]; 55 rep.reset(src.rep->clone()); 60 56 } 61 57 return *this; … … 72 68 double Vector::DistanceSquared(const Vector &y) const 73 69 { 74 double res = 0.; 75 for (int i=NDIM;i--;) 76 res += (x[i]-y[i])*(x[i]-y[i]); 77 return (res); 70 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 71 return rep->DistanceSquared(y); 78 72 }; 79 73 … … 94 88 double Vector::PeriodicDistance(const Vector &y, const double * const cell_size) const 95 89 { 96 double res = Distance(y), tmp, matrix[NDIM*NDIM]; 97 Vector Shiftedy, TranslationVector; 98 int N[NDIM]; 99 matrix[0] = cell_size[0]; 100 matrix[1] = cell_size[1]; 101 matrix[2] = cell_size[3]; 102 matrix[3] = cell_size[1]; 103 matrix[4] = cell_size[2]; 104 matrix[5] = cell_size[4]; 105 matrix[6] = cell_size[3]; 106 matrix[7] = cell_size[4]; 107 matrix[8] = cell_size[5]; 108 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells 109 for (N[0]=-1;N[0]<=1;N[0]++) 110 for (N[1]=-1;N[1]<=1;N[1]++) 111 for (N[2]=-1;N[2]<=1;N[2]++) { 112 // create the translation vector 113 TranslationVector.Zero(); 114 for (int i=NDIM;i--;) 115 TranslationVector.x[i] = (double)N[i]; 116 TranslationVector.MatrixMultiplication(matrix); 117 // add onto the original vector to compare with 118 Shiftedy = y + TranslationVector; 119 // get distance and compare with minimum so far 120 tmp = Distance(Shiftedy); 121 if (tmp < res) res = tmp; 122 } 123 return (res); 90 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 91 return rep->PeriodicDistance(y,cell_size); 124 92 }; 125 93 … … 131 99 double Vector::PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const 132 100 { 133 double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM]; 134 Vector Shiftedy, TranslationVector; 135 int N[NDIM]; 136 matrix[0] = cell_size[0]; 137 matrix[1] = cell_size[1]; 138 matrix[2] = cell_size[3]; 139 matrix[3] = cell_size[1]; 140 matrix[4] = cell_size[2]; 141 matrix[5] = cell_size[4]; 142 matrix[6] = cell_size[3]; 143 matrix[7] = cell_size[4]; 144 matrix[8] = cell_size[5]; 145 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells 146 for (N[0]=-1;N[0]<=1;N[0]++) 147 for (N[1]=-1;N[1]<=1;N[1]++) 148 for (N[2]=-1;N[2]<=1;N[2]++) { 149 // create the translation vector 150 TranslationVector.Zero(); 151 for (int i=NDIM;i--;) 152 TranslationVector.x[i] = (double)N[i]; 153 TranslationVector.MatrixMultiplication(matrix); 154 // add onto the original vector to compare with 155 Shiftedy = y + TranslationVector; 156 // get distance and compare with minimum so far 157 tmp = DistanceSquared(Shiftedy); 158 if (tmp < res) res = tmp; 159 } 160 return (res); 101 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 102 return rep->PeriodicDistanceSquared(y,cell_size); 161 103 }; 162 104 … … 167 109 void Vector::KeepPeriodic(const double * const matrix) 168 110 { 169 // int N[NDIM]; 170 // bool flag = false; 171 //vector Shifted, TranslationVector; 172 Vector TestVector; 173 // Log() << Verbose(1) << "Begin of KeepPeriodic." << endl; 174 // Log() << Verbose(2) << "Vector is: "; 175 // Output(out); 176 // Log() << Verbose(0) << endl; 177 TestVector = (*this); 178 TestVector.InverseMatrixMultiplication(matrix); 179 for(int i=NDIM;i--;) { // correct periodically 180 if (TestVector.x[i] < 0) { // get every coefficient into the interval [0,1) 181 TestVector.x[i] += ceil(TestVector.x[i]); 182 } else { 183 TestVector.x[i] -= floor(TestVector.x[i]); 184 } 185 } 186 TestVector.MatrixMultiplication(matrix); 187 (*this) = TestVector; 188 // Log() << Verbose(2) << "New corrected vector is: "; 189 // Output(out); 190 // Log() << Verbose(0) << endl; 191 // Log() << Verbose(1) << "End of KeepPeriodic." << endl; 111 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 112 rep->KeepPeriodic(matrix); 192 113 }; 193 114 … … 198 119 double Vector::ScalarProduct(const Vector &y) const 199 120 { 200 double res = 0.; 201 for (int i=NDIM;i--;) 202 res += x[i]*y[i]; 203 return (res); 121 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 122 return rep->ScalarProduct(y); 204 123 }; 205 124 … … 213 132 void Vector::VectorProduct(const Vector &y) 214 133 { 215 Vector tmp; 216 tmp[0] = x[1]* (y[2]) - x[2]* (y[1]); 217 tmp[1] = x[2]* (y[0]) - x[0]* (y[2]); 218 tmp[2] = x[0]* (y[1]) - x[1]* (y[0]); 219 (*this) = tmp; 134 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 135 rep->VectorProduct(y); 220 136 }; 221 137 … … 227 143 void Vector::ProjectOntoPlane(const Vector &y) 228 144 { 229 Vector tmp = y; 230 tmp.Normalize(); 231 tmp *= ScalarProduct(tmp); 232 (*this) -= tmp; 145 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 146 rep->ProjectOntoPlane(y); 233 147 }; 234 148 … … 241 155 double Vector::DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const 242 156 { 243 // first create part that is orthonormal to PlaneNormal with withdraw 244 Vector temp = (*this) - PlaneOffset; 245 temp.MakeNormalTo(PlaneNormal); 246 temp *= -1.; 247 // then add connecting vector from plane to point 248 temp += (*this); 249 temp -= PlaneOffset; 250 double sign = temp.ScalarProduct(PlaneNormal); 251 if (fabs(sign) > MYEPSILON) 252 sign /= fabs(sign); 253 else 254 sign = 0.; 255 256 return (temp.Norm()*sign); 157 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 158 return rep->DistanceToPlane(PlaneNormal,PlaneOffset); 257 159 }; 258 160 … … 262 164 void Vector::ProjectIt(const Vector &y) 263 165 { 264 Vector helper = y; 265 helper.Scale(-(ScalarProduct(y))); 266 AddVector(helper); 166 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 167 rep->ProjectIt(y); 267 168 }; 268 169 … … 273 174 Vector Vector::Projection(const Vector &y) const 274 175 { 275 Vector helper = y; 276 helper.Scale((ScalarProduct(y)/y.NormSquared())); 277 278 return helper; 176 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 177 return rep->Projection(y); 279 178 }; 280 179 … … 299 198 void Vector::Normalize() 300 199 { 301 double res = 0.; 302 for (int i=NDIM;i--;) 303 res += this->x[i]*this->x[i]; 304 if (fabs(res) > MYEPSILON) 305 res = 1./sqrt(res); 306 Scale(&res); 200 double factor = Norm(); 201 (*this) *= 1/factor; 307 202 }; 308 203 … … 311 206 void Vector::Zero() 312 207 { 313 for (int i=NDIM;i--;) 314 this->x[i] = 0.; 208 rep.reset(new SingleVector()); 315 209 }; 316 210 … … 319 213 void Vector::One(const double one) 320 214 { 321 for (int i=NDIM;i--;) 322 this->x[i] = one; 323 }; 324 325 /** Initialises all components of this vector. 326 */ 327 void Vector::Init(const double x1, const double x2, const double x3) 328 { 329 x[0] = x1; 330 x[1] = x2; 331 x[2] = x3; 215 rep.reset(new SingleVector(one,one,one)); 332 216 }; 333 217 … … 337 221 bool Vector::IsZero() const 338 222 { 339 return (fabs(x[0])+fabs(x[1])+fabs(x[2]) < MYEPSILON); 223 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 224 return rep->IsZero(); 340 225 }; 341 226 … … 345 230 bool Vector::IsOne() const 346 231 { 347 return (fabs(Norm() - 1.) < MYEPSILON); 232 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 233 return rep->IsOne(); 348 234 }; 349 235 … … 353 239 bool Vector::IsNormalTo(const Vector &normal) const 354 240 { 355 if (ScalarProduct(normal) < MYEPSILON) 356 return true; 357 else 358 return false; 241 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 242 return rep->IsNormalTo(normal); 359 243 }; 360 244 … … 364 248 bool Vector::IsEqualTo(const Vector &a) const 365 249 { 366 bool status = true; 367 for (int i=0;i<NDIM;i++) { 368 if (fabs(x[i] - a[i]) > MYEPSILON) 369 status = false; 370 } 371 return status; 250 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 251 return rep->IsEqualTo(a); 372 252 }; 373 253 … … 378 258 double Vector::Angle(const Vector &y) const 379 259 { 380 double norm1 = Norm(), norm2 = y.Norm(); 381 double angle = -1; 382 if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON)) 383 angle = this->ScalarProduct(y)/norm1/norm2; 384 // -1-MYEPSILON occured due to numerical imprecision, catch ... 385 //Log() << Verbose(2) << "INFO: acos(-1) = " << acos(-1) << ", acos(-1+MYEPSILON) = " << acos(-1+MYEPSILON) << ", acos(-1-MYEPSILON) = " << acos(-1-MYEPSILON) << "." << endl; 386 if (angle < -1) 387 angle = -1; 388 if (angle > 1) 389 angle = 1; 390 return acos(angle); 260 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 261 return rep->Angle(y); 391 262 }; 392 263 393 264 394 265 double& Vector::operator[](size_t i){ 395 ASSERT( i<=NDIM && i>=0,"Vector Index out of Range");396 return x[i];266 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 267 return (*rep)[i]; 397 268 } 398 269 399 270 const double& Vector::operator[](size_t i) const{ 400 ASSERT( i<=NDIM && i>=0,"Vector Index out of Range");401 return x[i];271 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 272 return (*rep)[i]; 402 273 } 403 274 … … 411 282 412 283 double* Vector::get(){ 413 return x; 284 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 285 return rep->get(); 414 286 } 415 287 … … 421 293 bool Vector::operator==(const Vector& b) const 422 294 { 423 bool status = true; 424 for (int i=0;i<NDIM;i++) 425 status = status && (fabs((*this)[i] - b[i]) < MYEPSILON); 426 return status; 295 ASSERT(isBaseClass(),"Operator used on Derived Vector object"); 296 return IsEqualTo(b); 427 297 }; 428 298 … … 467 337 Vector const Vector::operator+(const Vector& b) const 468 338 { 339 ASSERT(isBaseClass(),"Operator used on Derived Vector object"); 469 340 Vector x = *this; 470 341 x.AddVector(b); … … 479 350 Vector const Vector::operator-(const Vector& b) const 480 351 { 352 ASSERT(isBaseClass(),"Operator used on Derived Vector object"); 481 353 Vector x = *this; 482 354 x.SubtractVector(b); … … 520 392 }; 521 393 522 /** Scales each atom coordinate by an individual \a factor. 523 * \param *factor pointer to scaling factor 524 */ 525 void Vector::Scale(const double ** const factor) 526 { 527 for (int i=NDIM;i--;) 528 x[i] *= (*factor)[i]; 529 }; 530 531 void Vector::Scale(const double * const factor) 532 { 533 for (int i=NDIM;i--;) 534 x[i] *= *factor; 535 }; 394 395 void Vector::ScaleAll(const double *factor) 396 { 397 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 398 rep->ScaleAll(factor); 399 }; 400 401 536 402 537 403 void Vector::Scale(const double factor) 538 404 { 539 for (int i=NDIM;i--;) 540 x[i] *= factor; 541 }; 542 543 /** Translate atom by given vector. 544 * \param trans[] translation vector. 545 */ 546 void Vector::Translate(const Vector &trans) 547 { 548 for (int i=NDIM;i--;) 549 x[i] += trans[i]; 405 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 406 rep->Scale(factor); 550 407 }; 551 408 … … 556 413 void Vector::WrapPeriodically(const double * const M, const double * const Minv) 557 414 { 558 MatrixMultiplication(Minv); 559 // truncate to [0,1] for each axis 560 for (int i=0;i<NDIM;i++) { 561 x[i] += 0.5; // set to center of box 562 while (x[i] >= 1.) 563 x[i] -= 1.; 564 while (x[i] < 0.) 565 x[i] += 1.; 566 } 567 MatrixMultiplication(M); 415 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 416 rep->WrapPeriodically(M,Minv); 568 417 }; 569 418 … … 573 422 void Vector::MatrixMultiplication(const double * const M) 574 423 { 575 Vector C; 576 // do the matrix multiplication 577 C.x[0] = M[0]*x[0]+M[3]*x[1]+M[6]*x[2]; 578 C.x[1] = M[1]*x[0]+M[4]*x[1]+M[7]*x[2]; 579 C.x[2] = M[2]*x[0]+M[5]*x[1]+M[8]*x[2]; 580 // transfer the result into this 581 for (int i=NDIM;i--;) 582 x[i] = C.x[i]; 424 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 425 rep->MatrixMultiplication(M); 583 426 }; 584 427 … … 588 431 bool Vector::InverseMatrixMultiplication(const double * const A) 589 432 { 590 Vector C; 591 double B[NDIM*NDIM]; 592 double detA = RDET3(A); 593 double detAReci; 594 595 // calculate the inverse B 596 if (fabs(detA) > MYEPSILON) {; // RDET3(A) yields precisely zero if A irregular 597 detAReci = 1./detA; 598 B[0] = detAReci*RDET2(A[4],A[5],A[7],A[8]); // A_11 599 B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]); // A_12 600 B[2] = detAReci*RDET2(A[1],A[2],A[4],A[5]); // A_13 601 B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]); // A_21 602 B[4] = detAReci*RDET2(A[0],A[2],A[6],A[8]); // A_22 603 B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]); // A_23 604 B[6] = detAReci*RDET2(A[3],A[4],A[6],A[7]); // A_31 605 B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]); // A_32 606 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33 607 608 // do the matrix multiplication 609 C.x[0] = B[0]*x[0]+B[3]*x[1]+B[6]*x[2]; 610 C.x[1] = B[1]*x[0]+B[4]*x[1]+B[7]*x[2]; 611 C.x[2] = B[2]*x[0]+B[5]*x[1]+B[8]*x[2]; 612 // transfer the result into this 613 for (int i=NDIM;i--;) 614 x[i] = C.x[i]; 615 return true; 616 } else { 617 return false; 618 } 433 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 434 return rep->InverseMatrixMultiplication(A); 619 435 }; 620 436 … … 639 455 void Vector::Mirror(const Vector &n) 640 456 { 641 double projection; 642 projection = ScalarProduct(n)/n.NormSquared(); // remove constancy from n (keep as logical one) 643 // withdraw projected vector twice from original one 644 for (int i=NDIM;i--;) 645 x[i] -= 2.*projection*n[i]; 457 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 458 rep->Mirror(n); 646 459 }; 647 460 … … 655 468 bool Vector::MakeNormalTo(const Vector &y1) 656 469 { 657 bool result = false; 658 double factor = y1.ScalarProduct(*this)/y1.NormSquared(); 659 Vector x1 = factor * y1 ; 660 SubtractVector(x1); 661 for (int i=NDIM;i--;) 662 result = result || (fabs(x[i]) > MYEPSILON); 663 664 return result; 470 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 471 return rep->MakeNormalTo(y1); 665 472 }; 666 473 … … 673 480 bool Vector::GetOneNormalVector(const Vector &GivenVector) 674 481 { 675 int Components[NDIM]; // contains indices of non-zero components 676 int Last = 0; // count the number of non-zero entries in vector 677 int j; // loop variables 678 double norm; 679 680 for (j=NDIM;j--;) 681 Components[j] = -1; 682 // find two components != 0 683 for (j=0;j<NDIM;j++) 684 if (fabs(GivenVector[j]) > MYEPSILON) 685 Components[Last++] = j; 686 687 switch(Last) { 688 case 3: // threecomponent system 689 case 2: // two component system 690 norm = sqrt(1./(GivenVector[Components[1]]*GivenVector[Components[1]]) + 1./(GivenVector[Components[0]]*GivenVector[Components[0]])); 691 x[Components[2]] = 0.; 692 // in skp both remaining parts shall become zero but with opposite sign and third is zero 693 x[Components[1]] = -1./GivenVector[Components[1]] / norm; 694 x[Components[0]] = 1./GivenVector[Components[0]] / norm; 695 return true; 696 break; 697 case 1: // one component system 698 // set sole non-zero component to 0, and one of the other zero component pendants to 1 699 x[(Components[0]+2)%NDIM] = 0.; 700 x[(Components[0]+1)%NDIM] = 1.; 701 x[Components[0]] = 0.; 702 return true; 703 break; 704 default: 705 return false; 706 } 482 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 483 return rep->GetOneNormalVector(GivenVector); 707 484 }; 708 485 … … 712 489 void Vector::AddVector(const Vector &y) 713 490 { 714 for (int i=NDIM;i--;)715 this->x[i] += y[i];491 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 492 rep->AddVector(y); 716 493 } 717 494 … … 721 498 void Vector::SubtractVector(const Vector &y) 722 499 { 723 for (int i=NDIM;i--;) 724 this->x[i] -= y[i]; 725 } 726 727 /** Copy vector \a y componentwise. 728 * \param y vector 729 */ 730 void Vector::CopyVector(const Vector &y) 731 { 732 // check for self assignment 733 if(&y!=this) { 734 for (int i=NDIM;i--;) 735 this->x[i] = y.x[i]; 736 } 737 } 738 739 // this function is completely unused so it is deactivated until new uses arrive and a new 740 // place can be found 741 #if 0 742 /** Solves a vectorial system consisting of two orthogonal statements and a norm statement. 743 * This is linear system of equations to be solved, however of the three given (skp of this vector\ 744 * with either of the three hast to be zero) only two are linear independent. The third equation 745 * is that the vector should be of magnitude 1 (orthonormal). This all leads to a case-based solution 746 * where very often it has to be checked whether a certain value is zero or not and thus forked into 747 * another case. 748 * \param *x1 first vector 749 * \param *x2 second vector 750 * \param *y third vector 751 * \param alpha first angle 752 * \param beta second angle 753 * \param c norm of final vector 754 * \return a vector with \f$\langle x1,x2 \rangle=A\f$, \f$\langle x1,y \rangle = B\f$ and with norm \a c. 755 * \bug this is not yet working properly 756 */ 757 bool Vector::SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c) 758 { 759 double D1,D2,D3,E1,E2,F1,F2,F3,p,q=0., A, B1, B2, C; 760 double ang; // angle on testing 761 double sign[3]; 762 int i,j,k; 763 A = cos(alpha) * x1->Norm() * c; 764 B1 = cos(beta + M_PI/2.) * y->Norm() * c; 765 B2 = cos(beta) * x2->Norm() * c; 766 C = c * c; 767 Log() << Verbose(2) << "A " << A << "\tB " << B1 << "\tC " << C << endl; 768 int flag = 0; 769 if (fabs(x1->x[0]) < MYEPSILON) { // check for zero components for the later flipping and back-flipping 770 if (fabs(x1->x[1]) > MYEPSILON) { 771 flag = 1; 772 } else if (fabs(x1->x[2]) > MYEPSILON) { 773 flag = 2; 774 } else { 775 return false; 776 } 777 } 778 switch (flag) { 779 default: 780 case 0: 781 break; 782 case 2: 783 flip(x1->x[0],x1->x[1]); 784 flip(x2->x[0],x2->x[1]); 785 flip(y->x[0],y->x[1]); 786 //flip(x[0],x[1]); 787 flip(x1->x[1],x1->x[2]); 788 flip(x2->x[1],x2->x[2]); 789 flip(y->x[1],y->x[2]); 790 //flip(x[1],x[2]); 791 case 1: 792 flip(x1->x[0],x1->x[1]); 793 flip(x2->x[0],x2->x[1]); 794 flip(y->x[0],y->x[1]); 795 //flip(x[0],x[1]); 796 flip(x1->x[1],x1->x[2]); 797 flip(x2->x[1],x2->x[2]); 798 flip(y->x[1],y->x[2]); 799 //flip(x[1],x[2]); 800 break; 801 } 802 // now comes the case system 803 D1 = -y->x[0]/x1->x[0]*x1->x[1]+y->x[1]; 804 D2 = -y->x[0]/x1->x[0]*x1->x[2]+y->x[2]; 805 D3 = y->x[0]/x1->x[0]*A-B1; 806 Log() << Verbose(2) << "D1 " << D1 << "\tD2 " << D2 << "\tD3 " << D3 << "\n"; 807 if (fabs(D1) < MYEPSILON) { 808 Log() << Verbose(2) << "D1 == 0!\n"; 809 if (fabs(D2) > MYEPSILON) { 810 Log() << Verbose(3) << "D2 != 0!\n"; 811 x[2] = -D3/D2; 812 E1 = A/x1->x[0] + x1->x[2]/x1->x[0]*D3/D2; 813 E2 = -x1->x[1]/x1->x[0]; 814 Log() << Verbose(3) << "E1 " << E1 << "\tE2 " << E2 << "\n"; 815 F1 = E1*E1 + 1.; 816 F2 = -E1*E2; 817 F3 = E1*E1 + D3*D3/(D2*D2) - C; 818 Log() << Verbose(3) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n"; 819 if (fabs(F1) < MYEPSILON) { 820 Log() << Verbose(4) << "F1 == 0!\n"; 821 Log() << Verbose(4) << "Gleichungssystem linear\n"; 822 x[1] = F3/(2.*F2); 823 } else { 824 p = F2/F1; 825 q = p*p - F3/F1; 826 Log() << Verbose(4) << "p " << p << "\tq " << q << endl; 827 if (q < 0) { 828 Log() << Verbose(4) << "q < 0" << endl; 829 return false; 830 } 831 x[1] = p + sqrt(q); 832 } 833 x[0] = A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2]; 834 } else { 835 Log() << Verbose(2) << "Gleichungssystem unterbestimmt\n"; 836 return false; 837 } 838 } else { 839 E1 = A/x1->x[0]+x1->x[1]/x1->x[0]*D3/D1; 840 E2 = x1->x[1]/x1->x[0]*D2/D1 - x1->x[2]; 841 Log() << Verbose(2) << "E1 " << E1 << "\tE2 " << E2 << "\n"; 842 F1 = E2*E2 + D2*D2/(D1*D1) + 1.; 843 F2 = -(E1*E2 + D2*D3/(D1*D1)); 844 F3 = E1*E1 + D3*D3/(D1*D1) - C; 845 Log() << Verbose(2) << "F1 " << F1 << "\tF2 " << F2 << "\tF3 " << F3 << "\n"; 846 if (fabs(F1) < MYEPSILON) { 847 Log() << Verbose(3) << "F1 == 0!\n"; 848 Log() << Verbose(3) << "Gleichungssystem linear\n"; 849 x[2] = F3/(2.*F2); 850 } else { 851 p = F2/F1; 852 q = p*p - F3/F1; 853 Log() << Verbose(3) << "p " << p << "\tq " << q << endl; 854 if (q < 0) { 855 Log() << Verbose(3) << "q < 0" << endl; 856 return false; 857 } 858 x[2] = p + sqrt(q); 859 } 860 x[1] = (-D2 * x[2] - D3)/D1; 861 x[0] = A/x1->x[0] - x1->x[1]/x1->x[0]*x[1] + x1->x[2]/x1->x[0]*x[2]; 862 } 863 switch (flag) { // back-flipping 864 default: 865 case 0: 866 break; 867 case 2: 868 flip(x1->x[0],x1->x[1]); 869 flip(x2->x[0],x2->x[1]); 870 flip(y->x[0],y->x[1]); 871 flip(x[0],x[1]); 872 flip(x1->x[1],x1->x[2]); 873 flip(x2->x[1],x2->x[2]); 874 flip(y->x[1],y->x[2]); 875 flip(x[1],x[2]); 876 case 1: 877 flip(x1->x[0],x1->x[1]); 878 flip(x2->x[0],x2->x[1]); 879 flip(y->x[0],y->x[1]); 880 //flip(x[0],x[1]); 881 flip(x1->x[1],x1->x[2]); 882 flip(x2->x[1],x2->x[2]); 883 flip(y->x[1],y->x[2]); 884 flip(x[1],x[2]); 885 break; 886 } 887 // one z component is only determined by its radius (without sign) 888 // thus check eight possible sign flips and determine by checking angle with second vector 889 for (i=0;i<8;i++) { 890 // set sign vector accordingly 891 for (j=2;j>=0;j--) { 892 k = (i & pot(2,j)) << j; 893 Log() << Verbose(2) << "k " << k << "\tpot(2,j) " << pot(2,j) << endl; 894 sign[j] = (k == 0) ? 1. : -1.; 895 } 896 Log() << Verbose(2) << i << ": sign matrix is " << sign[0] << "\t" << sign[1] << "\t" << sign[2] << "\n"; 897 // apply sign matrix 898 for (j=NDIM;j--;) 899 x[j] *= sign[j]; 900 // calculate angle and check 901 ang = x2->Angle (this); 902 Log() << Verbose(1) << i << "th angle " << ang << "\tbeta " << cos(beta) << " :\t"; 903 if (fabs(ang - cos(beta)) < MYEPSILON) { 904 break; 905 } 906 // unapply sign matrix (is its own inverse) 907 for (j=NDIM;j--;) 908 x[j] *= sign[j]; 909 } 910 return true; 911 }; 912 913 #endif 500 ASSERT((rep.get()) && (!rep->isBaseClass()),"Representation stored in vector Object was not of derived type"); 501 rep->SubtractVector(y); 502 } 914 503 915 504 /** … … 922 511 bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const 923 512 { 924 Vector a = (*this) - offset; 925 a.InverseMatrixMultiplication(parallelepiped); 926 bool isInside = true; 927 928 for (int i=NDIM;i--;) 929 isInside = isInside && ((a.x[i] <= 1) && (a.x[i] >= 0)); 930 931 return isInside; 932 } 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 } -
src/vector.hpp
r273382 r1bd79e 15 15 #include <gsl/gsl_multimin.h> 16 16 17 #include <memory> 18 17 19 #include "defs.hpp" 18 20 … … 26 28 // this struct is used to indicate calls to the Baseconstructor from inside vectors. 27 29 struct Baseconstructor{}; 28 30 public: 29 31 30 32 Vector(); … … 33 35 virtual ~Vector(); 34 36 35 virtual double Distance(const Vector &y) const; 37 // Method implemented by forwarding to the Representation 38 36 39 virtual double DistanceSquared(const Vector &y) const; 37 40 virtual double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const; … … 39 42 virtual double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const; 40 43 virtual double ScalarProduct(const Vector &y) const; 41 virtual double Norm() const;42 virtual double NormSquared() const;43 44 virtual double Angle(const Vector &y) const; 44 45 virtual bool IsZero() const; … … 49 50 virtual void AddVector(const Vector &y); 50 51 virtual void SubtractVector(const Vector &y); 51 virtual void CopyVector(const Vector &y);52 52 virtual void VectorProduct(const Vector &y); 53 53 virtual void ProjectOntoPlane(const Vector &y); 54 54 virtual void ProjectIt(const Vector &y); 55 55 virtual Vector Projection(const Vector &y) const; 56 virtual void Zero();57 virtual void One(const double one);58 virtual void Init(const double x1, const double x2, const double x3);59 virtual void Normalize();60 virtual void Translate(const Vector &x);61 56 virtual void Mirror(const Vector &x); 62 virtual void Scale(const double ** const factor); 63 virtual void Scale(const double * const factor); 57 virtual void ScaleAll(const double *factor); 64 58 virtual void Scale(const double factor); 65 59 virtual void MatrixMultiplication(const double * const M); 66 60 virtual bool InverseMatrixMultiplication(const double * const M); 67 61 virtual void KeepPeriodic(const double * const matrix); 68 virtual void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors);69 62 virtual bool GetOneNormalVector(const Vector &x1); 70 63 virtual bool MakeNormalTo(const Vector &y1); 71 //bool SolveSystem(Vector * x1, Vector * x2, Vector * y, const double alpha, const double beta, const double c);72 64 virtual bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const; 73 65 virtual void WrapPeriodically(const double * const M, const double * const Minv); … … 76 68 virtual double& operator[](size_t i); 77 69 virtual const double& operator[](size_t i) const; 78 virtualdouble& at(size_t i);79 virtualconst double& at(size_t i) const;70 double& at(size_t i); 71 const double& at(size_t i) const; 80 72 81 73 // Assignment operator … … 84 76 // Access to internal structure 85 77 virtual double* get(); 78 79 // Methods that are derived directly from other methods 80 double Distance(const Vector &y) const; 81 double Norm() const; 82 double NormSquared() const; 83 void Normalize(); 84 void Zero(); 85 void One(const double one); 86 void LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors); 86 87 87 88 // operators for mathematical operations … … 92 93 Vector const operator-(const Vector& b) const; 93 94 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 94 101 private: 95 double x[NDIM]; 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; 96 108 97 109 }; -
src/vector_ops.cpp
r273382 r1bd79e 120 120 Vector res; 121 121 // normalise this vector with respect to axis 122 a .CopyVector(vec);122 a = vec; 123 123 a.ProjectOntoPlane(axis); 124 124 // construct normal vector
Note:
See TracChangeset
for help on using the changeset viewer.