source: src/vector.cpp@ 923b6c

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 Candidate_v1.7.0 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
Last change on this file since 923b6c was 923b6c, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Used BLAS support of GSL to calculate scalarProducts

  • Property mode set to 100644
File size: 18.2 KB
Line 
1/** \file vector.cpp
2 *
3 * Function implementations for the class vector.
4 *
5 */
6
7#include "Helpers/MemDebug.hpp"
8
9#include "vector.hpp"
10#include "verbose.hpp"
11#include "World.hpp"
12#include "Helpers/Assert.hpp"
13#include "Helpers/fast_functions.hpp"
14
15#include <iostream>
16#include <gsl/gsl_blas.h>
17
18
19using namespace std;
20
21
22/************************************ Functions for class vector ************************************/
23
24/** Constructor of class vector.
25 */
26Vector::Vector()
27{
28 content = gsl_vector_calloc (NDIM);
29};
30
31/**
32 * Copy constructor
33 */
34
35Vector::Vector(const Vector& src)
36{
37 content = gsl_vector_alloc(NDIM);
38 gsl_vector_memcpy(content, src.content);
39}
40
41/** Constructor of class vector.
42 */
43Vector::Vector(const double x1, const double x2, const double x3)
44{
45 content = gsl_vector_alloc(NDIM);
46 gsl_vector_set(content,0,x1);
47 gsl_vector_set(content,1,x2);
48 gsl_vector_set(content,2,x3);
49};
50
51/**
52 * Assignment operator
53 */
54Vector& Vector::operator=(const Vector& src){
55 // check for self assignment
56 if(&src!=this){
57 gsl_vector_memcpy(content, src.content);
58 }
59 return *this;
60}
61
62/** Desctructor of class vector.
63 */
64Vector::~Vector() {
65 gsl_vector_free(content);
66};
67
68/** Calculates square of distance between this and another vector.
69 * \param *y array to second vector
70 * \return \f$| x - y |^2\f$
71 */
72double Vector::DistanceSquared(const Vector &y) const
73{
74 double res = 0.;
75 for (int i=NDIM;i--;)
76 res += (at(i)-y[i])*(at(i)-y[i]);
77 return (res);
78};
79
80/** Calculates distance between this and another vector.
81 * \param *y array to second vector
82 * \return \f$| x - y |\f$
83 */
84double Vector::distance(const Vector &y) const
85{
86 return (sqrt(DistanceSquared(y)));
87};
88
89Vector Vector::getClosestPoint(const Vector &point) const{
90 // the closest point to a single point space is always the single point itself
91 return *this;
92}
93
94/** Calculates distance between this and another vector in a periodic cell.
95 * \param *y array to second vector
96 * \param *cell_size 6-dimensional array with (xx, xy, yy, xz, yz, zz) entries specifying the periodic cell
97 * \return \f$| x - y |\f$
98 */
99double Vector::PeriodicDistance(const Vector &y, const double * const cell_size) const
100{
101 double res = distance(y), tmp, matrix[NDIM*NDIM];
102 Vector Shiftedy, TranslationVector;
103 int N[NDIM];
104 matrix[0] = cell_size[0];
105 matrix[1] = cell_size[1];
106 matrix[2] = cell_size[3];
107 matrix[3] = cell_size[1];
108 matrix[4] = cell_size[2];
109 matrix[5] = cell_size[4];
110 matrix[6] = cell_size[3];
111 matrix[7] = cell_size[4];
112 matrix[8] = cell_size[5];
113 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells
114 for (N[0]=-1;N[0]<=1;N[0]++)
115 for (N[1]=-1;N[1]<=1;N[1]++)
116 for (N[2]=-1;N[2]<=1;N[2]++) {
117 // create the translation vector
118 TranslationVector.Zero();
119 for (int i=NDIM;i--;)
120 TranslationVector[i] = (double)N[i];
121 TranslationVector.MatrixMultiplication(matrix);
122 // add onto the original vector to compare with
123 Shiftedy = y + TranslationVector;
124 // get distance and compare with minimum so far
125 tmp = distance(Shiftedy);
126 if (tmp < res) res = tmp;
127 }
128 return (res);
129};
130
131/** Calculates distance between this and another vector in a periodic cell.
132 * \param *y array to second vector
133 * \param *cell_size 6-dimensional array with (xx, xy, yy, xz, yz, zz) entries specifying the periodic cell
134 * \return \f$| x - y |^2\f$
135 */
136double Vector::PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const
137{
138 double res = DistanceSquared(y), tmp, matrix[NDIM*NDIM];
139 Vector Shiftedy, TranslationVector;
140 int N[NDIM];
141 matrix[0] = cell_size[0];
142 matrix[1] = cell_size[1];
143 matrix[2] = cell_size[3];
144 matrix[3] = cell_size[1];
145 matrix[4] = cell_size[2];
146 matrix[5] = cell_size[4];
147 matrix[6] = cell_size[3];
148 matrix[7] = cell_size[4];
149 matrix[8] = cell_size[5];
150 // in order to check the periodic distance, translate one of the vectors into each of the 27 neighbouring cells
151 for (N[0]=-1;N[0]<=1;N[0]++)
152 for (N[1]=-1;N[1]<=1;N[1]++)
153 for (N[2]=-1;N[2]<=1;N[2]++) {
154 // create the translation vector
155 TranslationVector.Zero();
156 for (int i=NDIM;i--;)
157 TranslationVector[i] = (double)N[i];
158 TranslationVector.MatrixMultiplication(matrix);
159 // add onto the original vector to compare with
160 Shiftedy = y + TranslationVector;
161 // get distance and compare with minimum so far
162 tmp = DistanceSquared(Shiftedy);
163 if (tmp < res) res = tmp;
164 }
165 return (res);
166};
167
168/** Keeps the vector in a periodic cell, defined by the symmetric \a *matrix.
169 * \param *out ofstream for debugging messages
170 * Tries to translate a vector into each adjacent neighbouring cell.
171 */
172void Vector::KeepPeriodic(const double * const matrix)
173{
174 // int N[NDIM];
175 // bool flag = false;
176 //vector Shifted, TranslationVector;
177 // Log() << Verbose(1) << "Begin of KeepPeriodic." << endl;
178 // Log() << Verbose(2) << "Vector is: ";
179 // Output(out);
180 // Log() << Verbose(0) << endl;
181 InverseMatrixMultiplication(matrix);
182 for(int i=NDIM;i--;) { // correct periodically
183 if (at(i) < 0) { // get every coefficient into the interval [0,1)
184 at(i) += ceil(at(i));
185 } else {
186 at(i) -= floor(at(i));
187 }
188 }
189 MatrixMultiplication(matrix);
190 // Log() << Verbose(2) << "New corrected vector is: ";
191 // Output(out);
192 // Log() << Verbose(0) << endl;
193 // Log() << Verbose(1) << "End of KeepPeriodic." << endl;
194};
195
196/** Calculates scalar product between this and another vector.
197 * \param *y array to second vector
198 * \return \f$\langle x, y \rangle\f$
199 */
200double Vector::ScalarProduct(const Vector &y) const
201{
202 double res = 0.;
203 gsl_blas_ddot(content, y.content, &res);
204 return (res);
205};
206
207
208/** Calculates VectorProduct between this and another vector.
209 * -# returns the Product in place of vector from which it was initiated
210 * -# ATTENTION: Only three dim.
211 * \param *y array to vector with which to calculate crossproduct
212 * \return \f$ x \times y \f&
213 */
214void Vector::VectorProduct(const Vector &y)
215{
216 Vector tmp;
217 for(int i=NDIM;i--;)
218 tmp[i] = at((i+1)%NDIM)*y[(i+2)%NDIM] - at((i+2)%NDIM)*y[(i+1)%NDIM];
219 (*this) = tmp;
220};
221
222
223/** projects this vector onto plane defined by \a *y.
224 * \param *y normal vector of plane
225 * \return \f$\langle x, y \rangle\f$
226 */
227void Vector::ProjectOntoPlane(const Vector &y)
228{
229 Vector tmp;
230 tmp = y;
231 tmp.Normalize();
232 tmp.Scale(ScalarProduct(tmp));
233 *this -= tmp;
234};
235
236/** Calculates the minimum distance of this vector to the plane.
237 * \sa Vector::GetDistanceVectorToPlane()
238 * \param *out output stream for debugging
239 * \param *PlaneNormal normal of plane
240 * \param *PlaneOffset offset of plane
241 * \return distance to plane
242 */
243double Vector::DistanceToSpace(const Space &space) const
244{
245 return space.distance(*this);
246};
247
248/** Calculates the projection of a vector onto another \a *y.
249 * \param *y array to second vector
250 */
251void Vector::ProjectIt(const Vector &y)
252{
253 (*this) += (-ScalarProduct(y))*y;
254};
255
256/** Calculates the projection of a vector onto another \a *y.
257 * \param *y array to second vector
258 * \return Vector
259 */
260Vector Vector::Projection(const Vector &y) const
261{
262 Vector helper = y;
263 helper.Scale((ScalarProduct(y)/y.NormSquared()));
264
265 return helper;
266};
267
268/** Calculates norm of this vector.
269 * \return \f$|x|\f$
270 */
271double Vector::Norm() const
272{
273 return (sqrt(NormSquared()));
274};
275
276/** Calculates squared norm of this vector.
277 * \return \f$|x|^2\f$
278 */
279double Vector::NormSquared() const
280{
281 return (ScalarProduct(*this));
282};
283
284/** Normalizes this vector.
285 */
286void Vector::Normalize()
287{
288 double factor = Norm();
289 (*this) *= 1/factor;
290};
291
292/** Zeros all components of this vector.
293 */
294void Vector::Zero()
295{
296 at(0)=at(1)=at(2)=0;
297};
298
299/** Zeros all components of this vector.
300 */
301void Vector::One(const double one)
302{
303 at(0)=at(1)=at(2)=one;
304};
305
306/** Checks whether vector has all components zero.
307 * @return true - vector is zero, false - vector is not
308 */
309bool Vector::IsZero() const
310{
311 return (fabs(at(0))+fabs(at(1))+fabs(at(2)) < MYEPSILON);
312};
313
314/** Checks whether vector has length of 1.
315 * @return true - vector is normalized, false - vector is not
316 */
317bool Vector::IsOne() const
318{
319 return (fabs(Norm() - 1.) < MYEPSILON);
320};
321
322/** Checks whether vector is normal to \a *normal.
323 * @return true - vector is normalized, false - vector is not
324 */
325bool Vector::IsNormalTo(const Vector &normal) const
326{
327 if (ScalarProduct(normal) < MYEPSILON)
328 return true;
329 else
330 return false;
331};
332
333/** Checks whether vector is normal to \a *normal.
334 * @return true - vector is normalized, false - vector is not
335 */
336bool Vector::IsEqualTo(const Vector &a) const
337{
338 bool status = true;
339 for (int i=0;i<NDIM;i++) {
340 if (fabs(at(i) - a[i]) > MYEPSILON)
341 status = false;
342 }
343 return status;
344};
345
346/** Calculates the angle between this and another vector.
347 * \param *y array to second vector
348 * \return \f$\acos\bigl(frac{\langle x, y \rangle}{|x||y|}\bigr)\f$
349 */
350double Vector::Angle(const Vector &y) const
351{
352 double norm1 = Norm(), norm2 = y.Norm();
353 double angle = -1;
354 if ((fabs(norm1) > MYEPSILON) && (fabs(norm2) > MYEPSILON))
355 angle = this->ScalarProduct(y)/norm1/norm2;
356 // -1-MYEPSILON occured due to numerical imprecision, catch ...
357 //Log() << Verbose(2) << "INFO: acos(-1) = " << acos(-1) << ", acos(-1+MYEPSILON) = " << acos(-1+MYEPSILON) << ", acos(-1-MYEPSILON) = " << acos(-1-MYEPSILON) << "." << endl;
358 if (angle < -1)
359 angle = -1;
360 if (angle > 1)
361 angle = 1;
362 return acos(angle);
363};
364
365
366double& Vector::operator[](size_t i){
367 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
368 return *gsl_vector_ptr (content, i);
369}
370
371const double& Vector::operator[](size_t i) const{
372 ASSERT(i<=NDIM && i>=0,"Vector Index out of Range");
373 return *gsl_vector_ptr (content, i);
374}
375
376double& Vector::at(size_t i){
377 return (*this)[i];
378}
379
380const double& Vector::at(size_t i) const{
381 return (*this)[i];
382}
383
384gsl_vector* Vector::get(){
385 return content;
386}
387
388/** Compares vector \a to vector \a b component-wise.
389 * \param a base vector
390 * \param b vector components to add
391 * \return a == b
392 */
393bool Vector::operator==(const Vector& b) const
394{
395 return IsEqualTo(b);
396};
397
398bool Vector::operator!=(const Vector& b) const
399{
400 return !IsEqualTo(b);
401}
402
403/** Sums vector \a to this lhs component-wise.
404 * \param a base vector
405 * \param b vector components to add
406 * \return lhs + a
407 */
408const Vector& Vector::operator+=(const Vector& b)
409{
410 this->AddVector(b);
411 return *this;
412};
413
414/** Subtracts vector \a from this lhs component-wise.
415 * \param a base vector
416 * \param b vector components to add
417 * \return lhs - a
418 */
419const Vector& Vector::operator-=(const Vector& b)
420{
421 this->SubtractVector(b);
422 return *this;
423};
424
425/** factor each component of \a a times a double \a m.
426 * \param a base vector
427 * \param m factor
428 * \return lhs.x[i] * m
429 */
430const Vector& operator*=(Vector& a, const double m)
431{
432 a.Scale(m);
433 return a;
434};
435
436/** Sums two vectors \a and \b component-wise.
437 * \param a first vector
438 * \param b second vector
439 * \return a + b
440 */
441Vector const Vector::operator+(const Vector& b) const
442{
443 Vector x = *this;
444 x.AddVector(b);
445 return x;
446};
447
448/** Subtracts vector \a from \b component-wise.
449 * \param a first vector
450 * \param b second vector
451 * \return a - b
452 */
453Vector const Vector::operator-(const Vector& b) const
454{
455 Vector x = *this;
456 x.SubtractVector(b);
457 return x;
458};
459
460/** Factors given vector \a a times \a m.
461 * \param a vector
462 * \param m factor
463 * \return m * a
464 */
465Vector const operator*(const Vector& a, const double m)
466{
467 Vector x(a);
468 x.Scale(m);
469 return x;
470};
471
472/** Factors given vector \a a times \a m.
473 * \param m factor
474 * \param a vector
475 * \return m * a
476 */
477Vector const operator*(const double m, const Vector& a )
478{
479 Vector x(a);
480 x.Scale(m);
481 return x;
482};
483
484ostream& operator<<(ostream& ost, const Vector& m)
485{
486 ost << "(";
487 for (int i=0;i<NDIM;i++) {
488 ost << m[i];
489 if (i != 2)
490 ost << ",";
491 }
492 ost << ")";
493 return ost;
494};
495
496
497void Vector::ScaleAll(const double *factor)
498{
499 for (int i=NDIM;i--;)
500 at(i) *= factor[i];
501};
502
503
504
505void Vector::Scale(const double factor)
506{
507 gsl_vector_scale(content,factor);
508};
509
510/** Given a box by its matrix \a *M and its inverse *Minv the vector is made to point within that box.
511 * \param *M matrix of box
512 * \param *Minv inverse matrix
513 */
514void Vector::WrapPeriodically(const double * const M, const double * const Minv)
515{
516 MatrixMultiplication(Minv);
517 // truncate to [0,1] for each axis
518 for (int i=0;i<NDIM;i++) {
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 }
525 MatrixMultiplication(M);
526};
527
528std::pair<Vector,Vector> Vector::partition(const Vector &rhs) const{
529 double factor = ScalarProduct(rhs)/rhs.NormSquared();
530 Vector res= factor * rhs;
531 return make_pair(res,(*this)-res);
532}
533
534std::pair<pointset,Vector> Vector::partition(const pointset &points) const{
535 Vector helper = *this;
536 pointset res;
537 for(pointset::const_iterator iter=points.begin();iter!=points.end();++iter){
538 pair<Vector,Vector> currPart = helper.partition(*iter);
539 res.push_back(currPart.first);
540 helper = currPart.second;
541 }
542 return make_pair(res,helper);
543}
544
545/** Do a matrix multiplication.
546 * \param *matrix NDIM_NDIM array
547 */
548void Vector::MatrixMultiplication(const double * const M)
549{
550 Vector tmp;
551 // do the matrix multiplication
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;
556};
557
558/** Do a matrix multiplication with the \a *A' inverse.
559 * \param *matrix NDIM_NDIM array
560 */
561bool Vector::InverseMatrixMultiplication(const double * const A)
562{
563 double B[NDIM*NDIM];
564 double detA = RDET3(A);
565 double detAReci;
566
567 // calculate the inverse B
568 if (fabs(detA) > MYEPSILON) {; // RDET3(A) yields precisely zero if A irregular
569 detAReci = 1./detA;
570 B[0] = detAReci*RDET2(A[4],A[5],A[7],A[8]); // A_11
571 B[1] = -detAReci*RDET2(A[1],A[2],A[7],A[8]); // A_12
572 B[2] = detAReci*RDET2(A[1],A[2],A[4],A[5]); // A_13
573 B[3] = -detAReci*RDET2(A[3],A[5],A[6],A[8]); // A_21
574 B[4] = detAReci*RDET2(A[0],A[2],A[6],A[8]); // A_22
575 B[5] = -detAReci*RDET2(A[0],A[2],A[3],A[5]); // A_23
576 B[6] = detAReci*RDET2(A[3],A[4],A[6],A[7]); // A_31
577 B[7] = -detAReci*RDET2(A[0],A[1],A[6],A[7]); // A_32
578 B[8] = detAReci*RDET2(A[0],A[1],A[3],A[4]); // A_33
579
580 MatrixMultiplication(B);
581
582 return true;
583 } else {
584 return false;
585 }
586};
587
588
589/** Creates this vector as the b y *factors' components scaled linear combination of the given three.
590 * this vector = x1*factors[0] + x2* factors[1] + x3*factors[2]
591 * \param *x1 first vector
592 * \param *x2 second vector
593 * \param *x3 third vector
594 * \param *factors three-component vector with the factor for each given vector
595 */
596void Vector::LinearCombinationOfVectors(const Vector &x1, const Vector &x2, const Vector &x3, const double * const factors)
597{
598 (*this) = (factors[0]*x1) +
599 (factors[1]*x2) +
600 (factors[2]*x3);
601};
602
603/** Calculates orthonormal vector to one given vectors.
604 * Just subtracts the projection onto the given vector from this vector.
605 * The removed part of the vector is Vector::Projection()
606 * \param *x1 vector
607 * \return true - success, false - vector is zero
608 */
609bool Vector::MakeNormalTo(const Vector &y1)
610{
611 bool result = false;
612 double factor = y1.ScalarProduct(*this)/y1.NormSquared();
613 Vector x1 = factor * y1;
614 SubtractVector(x1);
615 for (int i=NDIM;i--;)
616 result = result || (fabs(at(i)) > MYEPSILON);
617
618 return result;
619};
620
621/** Creates this vector as one of the possible orthonormal ones to the given one.
622 * Just scan how many components of given *vector are unequal to zero and
623 * try to get the skp of both to be zero accordingly.
624 * \param *vector given vector
625 * \return true - success, false - failure (null vector given)
626 */
627bool Vector::GetOneNormalVector(const Vector &GivenVector)
628{
629 int Components[NDIM]; // contains indices of non-zero components
630 int Last = 0; // count the number of non-zero entries in vector
631 int j; // loop variables
632 double norm;
633
634 for (j=NDIM;j--;)
635 Components[j] = -1;
636
637 // in two component-systems we need to find the one position that is zero
638 int zeroPos = -1;
639 // find two components != 0
640 for (j=0;j<NDIM;j++){
641 if (fabs(GivenVector[j]) > MYEPSILON)
642 Components[Last++] = j;
643 else
644 // this our zero Position
645 zeroPos = j;
646 }
647
648 switch(Last) {
649 case 3: // threecomponent system
650 // the position of the zero is arbitrary in three component systems
651 zeroPos = Components[2];
652 case 2: // two component system
653 norm = sqrt(1./(GivenVector[Components[1]]*GivenVector[Components[1]]) + 1./(GivenVector[Components[0]]*GivenVector[Components[0]]));
654 at(zeroPos) = 0.;
655 // in skp both remaining parts shall become zero but with opposite sign and third is zero
656 at(Components[1]) = -1./GivenVector[Components[1]] / norm;
657 at(Components[0]) = 1./GivenVector[Components[0]] / norm;
658 return true;
659 break;
660 case 1: // one component system
661 // set sole non-zero component to 0, and one of the other zero component pendants to 1
662 at((Components[0]+2)%NDIM) = 0.;
663 at((Components[0]+1)%NDIM) = 1.;
664 at(Components[0]) = 0.;
665 return true;
666 break;
667 default:
668 return false;
669 }
670};
671
672/** Adds vector \a *y componentwise.
673 * \param *y vector
674 */
675void Vector::AddVector(const Vector &y)
676{
677 gsl_vector_add(content, y.content);
678}
679
680/** Adds vector \a *y componentwise.
681 * \param *y vector
682 */
683void Vector::SubtractVector(const Vector &y)
684{
685 gsl_vector_sub(content, y.content);
686}
687
688/**
689 * Checks whether this vector is within the parallelepiped defined by the given three vectors and
690 * their offset.
691 *
692 * @param offest for the origin of the parallelepiped
693 * @param three vectors forming the matrix that defines the shape of the parallelpiped
694 */
695bool Vector::IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const
696{
697 Vector a = (*this)-offset;
698 a.InverseMatrixMultiplication(parallelepiped);
699 bool isInside = true;
700
701 for (int i=NDIM;i--;)
702 isInside = isInside && ((a[i] <= 1) && (a[i] >= 0));
703
704 return isInside;
705}
706
707
708// some comonly used vectors
709const Vector zeroVec(0,0,0);
710const Vector e1(1,0,0);
711const Vector e2(0,1,0);
712const Vector e3(0,0,1);
Note: See TracBrowser for help on using the repository browser.