source: src/vector.cpp@ 325390

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 325390 was 325390, checked in by Tillmann Crueger <crueger@…>, 15 years ago

Started work on basic matrix class to be used with Vector class

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