1 | #ifndef VECTOR_HPP_
|
---|
2 | #define VECTOR_HPP_
|
---|
3 |
|
---|
4 | using namespace std;
|
---|
5 |
|
---|
6 | /*********************************************** includes ***********************************/
|
---|
7 |
|
---|
8 | // include config.h
|
---|
9 | #ifdef HAVE_CONFIG_H
|
---|
10 | #include <config.h>
|
---|
11 | #endif
|
---|
12 |
|
---|
13 | #include <iostream>
|
---|
14 | #include <gsl/gsl_vector.h>
|
---|
15 | #include <gsl/gsl_multimin.h>
|
---|
16 |
|
---|
17 | #include <memory>
|
---|
18 |
|
---|
19 | #include "defs.hpp"
|
---|
20 |
|
---|
21 | /********************************************** declarations *******************************/
|
---|
22 |
|
---|
23 | /** Single vector.
|
---|
24 | * basically, just a x[3] but with helpful functions
|
---|
25 | */
|
---|
26 | class Vector {
|
---|
27 | protected:
|
---|
28 | // this struct is used to indicate calls to the Baseconstructor from inside vectors.
|
---|
29 | struct Baseconstructor{};
|
---|
30 | public:
|
---|
31 |
|
---|
32 | Vector();
|
---|
33 | Vector(const double x1, const double x2, const double x3);
|
---|
34 | Vector(const Vector& src);
|
---|
35 | virtual ~Vector();
|
---|
36 |
|
---|
37 | // Method implemented by forwarding to the Representation
|
---|
38 |
|
---|
39 | virtual double DistanceSquared(const Vector &y) const;
|
---|
40 | virtual double DistanceToPlane(const Vector &PlaneNormal, const Vector &PlaneOffset) const;
|
---|
41 | virtual double PeriodicDistance(const Vector &y, const double * const cell_size) const;
|
---|
42 | virtual double PeriodicDistanceSquared(const Vector &y, const double * const cell_size) const;
|
---|
43 | virtual double ScalarProduct(const Vector &y) const;
|
---|
44 | virtual double Angle(const Vector &y) const;
|
---|
45 | virtual bool IsZero() const;
|
---|
46 | virtual bool IsOne() const;
|
---|
47 | virtual bool IsNormalTo(const Vector &normal) const;
|
---|
48 | virtual bool IsEqualTo(const Vector &a) const;
|
---|
49 |
|
---|
50 | virtual void AddVector(const Vector &y);
|
---|
51 | virtual void SubtractVector(const Vector &y);
|
---|
52 | virtual void VectorProduct(const Vector &y);
|
---|
53 | virtual void ProjectOntoPlane(const Vector &y);
|
---|
54 | virtual void ProjectIt(const Vector &y);
|
---|
55 | virtual Vector Projection(const Vector &y) const;
|
---|
56 | virtual void Mirror(const Vector &x);
|
---|
57 | virtual void ScaleAll(const double *factor);
|
---|
58 | virtual void Scale(const double factor);
|
---|
59 | virtual void MatrixMultiplication(const double * const M);
|
---|
60 | virtual bool InverseMatrixMultiplication(const double * const M);
|
---|
61 | virtual void KeepPeriodic(const double * const matrix);
|
---|
62 | virtual bool GetOneNormalVector(const Vector &x1);
|
---|
63 | virtual bool MakeNormalTo(const Vector &y1);
|
---|
64 | virtual bool IsInParallelepiped(const Vector &offset, const double * const parallelepiped) const;
|
---|
65 | virtual void WrapPeriodically(const double * const M, const double * const Minv);
|
---|
66 |
|
---|
67 | // Accessors ussually come in pairs... and sometimes even more than that
|
---|
68 | virtual double& operator[](size_t i);
|
---|
69 | virtual const double& operator[](size_t i) const;
|
---|
70 | double& at(size_t i);
|
---|
71 | const double& at(size_t i) const;
|
---|
72 |
|
---|
73 | // Assignment operator
|
---|
74 | virtual Vector &operator=(const Vector& src);
|
---|
75 |
|
---|
76 | // Access to internal structure
|
---|
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);
|
---|
87 |
|
---|
88 | // operators for mathematical operations
|
---|
89 | bool operator==(const Vector& b) const;
|
---|
90 | const Vector& operator+=(const Vector& b);
|
---|
91 | const Vector& operator-=(const Vector& b);
|
---|
92 | Vector const operator+(const Vector& b) const;
|
---|
93 | Vector const operator-(const Vector& b) const;
|
---|
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 |
|
---|
101 | private:
|
---|
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;
|
---|
108 |
|
---|
109 | };
|
---|
110 |
|
---|
111 | ostream & operator << (ostream& ost, const Vector &m);
|
---|
112 | const Vector& operator*=(Vector& a, const double m);
|
---|
113 | Vector const operator*(const Vector& a, const double m);
|
---|
114 | Vector const operator*(const double m, const Vector& a);
|
---|
115 |
|
---|
116 | #endif /*VECTOR_HPP_*/
|
---|