/* * 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 "CodePatterns/Observer/Observable.hpp" #include "LinearAlgebra/VectorSet.hpp" #include "Box_BoundaryConditions.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 Observable { public: enum NotificationType { BoundaryConditionsChanged, MatrixChanged, NotificationType_MAX // denotes the maximum of available notification types }; 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 enforceBoundaryConditions(const Vector &point) const; /** * Checks whether a given vector is inside the box not accounting for boundary conditions. */ bool isInside(const Vector &point) const; /** * Checks whether a given vector is inside the box under the given boundary conditions. */ bool isValid(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 vector of two points in the periodic space * defined by this box */ const Vector periodicDistanceVector(const Vector &point1,const Vector &point2) 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 std::string getConditionNames() const; const BoundaryConditions::Conditions_t & getConditions() const; const BoundaryConditions::BoundaryCondition_t getCondition(size_t i) const; void setCondition(size_t i,const BoundaryConditions::BoundaryCondition_t _condition); void setConditions(const BoundaryConditions::Conditions_t & _conditions); void setConditions(const std::string & _conditions); void setConditions(const std::vector< std::string >& _conditions); 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; BoundaryConditions::BCContainer 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_ */