/* * Box.hpp * * Created on: Jun 30, 2010 * Author: crueger */ #ifndef BOX_HPP_ #define BOX_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif class RealSpaceMatrix; class Vector; class Shape; class Plane; #include #include #include "LinearAlgebra/VectorSet.hpp" /** * A simple class that can be used to store periodic Boxes * in the form of a parallelepiped. * * Stores a matrix that can be used to translate from periodic * [0,1) space as well as the inverse that is needed to * translate back to that space. */ class Box { public: typedef enum{ Wrap, Bounce, Ignore } BoundaryCondition_t; typedef std::vector Conditions_t; Box(); Box(const Box&); Box(RealSpaceMatrix _M); virtual ~Box(); /** * Get the matrix describing the form of the parallelepiped */ const RealSpaceMatrix &getM() const; /** * Get the inverse of the matrix M (see above). */ const RealSpaceMatrix &getMinv() const; /** * Set the form of the parallelepiped. */ void setM(RealSpaceMatrix); Box &operator=(const Box&); Box &operator=(const RealSpaceMatrix&); /** * Translate a point from [0,1) to the boxed space. */ Vector translateIn(const Vector &point) const; /** * Translate a point from the boxed space to the [0,1) space. */ Vector translateOut(const Vector &point) const; /** * Wrap a point so that it will lie within the space defined by the box. */ Vector WrapPeriodically(const Vector &point) const; /** * Checks whether a given vector is inside the box. */ bool isInside(const Vector &point) const; /** * Produce corresponding points in several adjacent boxes. * * n specifies the number of times the point is expanded. * Carefull, needs O(n^3) time and produces as many vectors. */ VECTORSET(std::vector) explode(const Vector &point,int n) const; VECTORSET(std::vector) explode(const Vector &point) const; /** * Calculate the distance of two points in the periodic space * defined by this box */ double periodicDistanceSquared(const Vector &point1,const Vector &point2) const; /** * Calculate the distance of two points in the periodic space * defined by this box */ double periodicDistance(const Vector &point1,const Vector &point2) const; /** * Calculates the minimum distance to the boundary of the periodic * space defined by this box. */ double DistanceToBoundary(const Vector &point) const; Shape getShape() const; const Conditions_t getConditions() const; void setCondition(int,BoundaryCondition_t); const std::vector > getBoundingPlanes() const; void setCuboid(const Vector&); private: /** Internal explode function that works on the staticly present internal_list * * \todo Note that is not thread-safe! * * Most of the time of explode is consumed by memory allocation if it is called * repeatedly. * * @param point point to explode * @param n neighbour shells to explode */ void internal_explode(const Vector &point,int n) const; //!> Internal vector list for exploding vectors used in Box::internal_explode(). mutable VECTORSET(std::vector) internal_list; //!> Internal vector for coordinates used in Box::internal_explode() mutable std::vector coords; //!> Internal vector for indices used in Box::internal_explode() mutable std::vector index; Conditions_t conditions; RealSpaceMatrix *M; //!< Defines the layout of the box RealSpaceMatrix *Minv; //!< Inverse of M to avoid recomputation }; std::ostream & operator << (std::ostream& ost, const Box &m); #endif /* BOX_HPP_ */