| 1 | /*
 | 
|---|
| 2 |  * Box.hpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Jun 30, 2010
 | 
|---|
| 5 |  *      Author: crueger
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #ifndef BOX_HPP_
 | 
|---|
| 9 | #define BOX_HPP_
 | 
|---|
| 10 | 
 | 
|---|
| 11 | class Matrix;
 | 
|---|
| 12 | class Vector;
 | 
|---|
| 13 | class Shape;
 | 
|---|
| 14 | class Plane;
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <list>
 | 
|---|
| 17 | #include <vector>
 | 
|---|
| 18 | #include "LinearAlgebra/VectorSet.hpp"
 | 
|---|
| 19 | 
 | 
|---|
| 20 | /**
 | 
|---|
| 21 |  * A simple class that can be used to store periodic Boxes
 | 
|---|
| 22 |  * in the form of a parallelepiped.
 | 
|---|
| 23 |  *
 | 
|---|
| 24 |  * Stores a matrix that can be used to translate from periodic
 | 
|---|
| 25 |  * [0,1) space as well as the inverse that is needed to
 | 
|---|
| 26 |  * translate back to that space.
 | 
|---|
| 27 |  */
 | 
|---|
| 28 | class Box
 | 
|---|
| 29 | {
 | 
|---|
| 30 | public:
 | 
|---|
| 31 |   typedef enum{
 | 
|---|
| 32 |     Wrap,
 | 
|---|
| 33 |     Bounce,
 | 
|---|
| 34 |     Ignore
 | 
|---|
| 35 |   } BoundaryCondition_t;
 | 
|---|
| 36 | 
 | 
|---|
| 37 |   typedef vector<BoundaryCondition_t> Conditions_t;
 | 
|---|
| 38 | 
 | 
|---|
| 39 |   Box();
 | 
|---|
| 40 |   Box(const Box&);
 | 
|---|
| 41 |   virtual ~Box();
 | 
|---|
| 42 | 
 | 
|---|
| 43 |   /**
 | 
|---|
| 44 |    * Get the matrix describing the form of the parallelepiped
 | 
|---|
| 45 |    */
 | 
|---|
| 46 |   const Matrix &getM() const;
 | 
|---|
| 47 | 
 | 
|---|
| 48 |   /**
 | 
|---|
| 49 |    * Get the inverse of the matrix M (see above).
 | 
|---|
| 50 |    */
 | 
|---|
| 51 |   const Matrix &getMinv() const;
 | 
|---|
| 52 | 
 | 
|---|
| 53 |   /**
 | 
|---|
| 54 |    * Set the form of the parallelepiped.
 | 
|---|
| 55 |    */
 | 
|---|
| 56 |   void setM(Matrix);
 | 
|---|
| 57 | 
 | 
|---|
| 58 |   Box &operator=(const Box&);
 | 
|---|
| 59 |   Box &operator=(const Matrix&);
 | 
|---|
| 60 | 
 | 
|---|
| 61 |   /**
 | 
|---|
| 62 |    * Translate a point from [0,1) to the boxed space.
 | 
|---|
| 63 |    */
 | 
|---|
| 64 |   Vector translateIn(const Vector &point) const;
 | 
|---|
| 65 | 
 | 
|---|
| 66 |   /**
 | 
|---|
| 67 |    * Translate a point from the boxed space to the [0,1) space.
 | 
|---|
| 68 |    */
 | 
|---|
| 69 |   Vector translateOut(const Vector &point) const;
 | 
|---|
| 70 | 
 | 
|---|
| 71 |   /**
 | 
|---|
| 72 |    * Wrap a point so that it will lie within the space defined by the box.
 | 
|---|
| 73 |    */
 | 
|---|
| 74 |   Vector WrapPeriodically(const Vector &point) const;
 | 
|---|
| 75 | 
 | 
|---|
| 76 |   /**
 | 
|---|
| 77 |    * Checks whether a given vector is inside the box.
 | 
|---|
| 78 |    */
 | 
|---|
| 79 |   bool isInside(const Vector &point) const;
 | 
|---|
| 80 | 
 | 
|---|
| 81 |   /**
 | 
|---|
| 82 |    * Produce corresponding points in several adjacent boxes.
 | 
|---|
| 83 |    *
 | 
|---|
| 84 |    * n specifies the number of times the point is expanded.
 | 
|---|
| 85 |    * Carefull, needs O(n^3) time and produces as many vectors.
 | 
|---|
| 86 |    */
 | 
|---|
| 87 |   VECTORSET(std::list) explode(const Vector &point,int n) const;
 | 
|---|
| 88 |   VECTORSET(std::list) explode(const Vector &point) const;
 | 
|---|
| 89 | 
 | 
|---|
| 90 |   /**
 | 
|---|
| 91 |    * Calculate the distance of two points in the periodic space
 | 
|---|
| 92 |    * defined by this box
 | 
|---|
| 93 |    */
 | 
|---|
| 94 |   double periodicDistanceSquared(const Vector &point1,const Vector &point2) const;
 | 
|---|
| 95 | 
 | 
|---|
| 96 |   /**
 | 
|---|
| 97 |    * Calculate the distance of two points in the periodic space
 | 
|---|
| 98 |    * defined by this box
 | 
|---|
| 99 |    */
 | 
|---|
| 100 |   double periodicDistance(const Vector &point1,const Vector &point2) const;
 | 
|---|
| 101 | 
 | 
|---|
| 102 |   Shape getShape() const;
 | 
|---|
| 103 |   const Conditions_t getConditions();
 | 
|---|
| 104 |   void setCondition(int,BoundaryCondition_t);
 | 
|---|
| 105 | 
 | 
|---|
| 106 |   const vector<pair<Plane,Plane> > getBoundingPlanes();
 | 
|---|
| 107 | 
 | 
|---|
| 108 |   void setCuboid(const Vector&);
 | 
|---|
| 109 | 
 | 
|---|
| 110 | private:
 | 
|---|
| 111 |   Conditions_t conditions;
 | 
|---|
| 112 |   Matrix *M;    //!< Defines the layout of the box
 | 
|---|
| 113 |   Matrix *Minv; //!< Inverse of M to avoid recomputation
 | 
|---|
| 114 | };
 | 
|---|
| 115 | 
 | 
|---|
| 116 | #endif /* BOX_HPP_ */
 | 
|---|