source: src/vector.cpp@ 93987b

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
Last change on this file since 93987b was 93987b, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Made the Vector use more gsl-operations internally

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