/* * LinkedCell_Model.hpp * * Created on: Nov 15, 2011 * Author: heber */ #ifndef LINKEDCELL_MODEL_HPP_ #define LINKEDCELL_MODEL_HPP_ // include config.h #ifdef HAVE_CONFIG_H #include #endif #include #include #include "CodePatterns/Observer/Observable.hpp" #include "CodePatterns/Observer/Observer.hpp" #include "LinearAlgebra/defs.hpp" #include "LinearAlgebra/RealSpaceMatrix.hpp" #include "LinkedCell/tripleIndex.hpp" #include "LinkedCell/types.hpp" class Box; class IPointCloud; class LinkedCell_ModelTest; class LinkedCell_ViewTest; class TesselPoint; class Vector; namespace LinkedCell { class LinkedCell_Controller; /** This is the model in the MVC ansatz for the LinkedCell structure. * * \sa linkedcell * * The model represents a certain linked cell structure with a specific mesh * size (i.e. edge length). Note that all coordinates are internally always * transformed to [0,1]^3, hence we require the domain (\ref Box) for the * transformation matrices. * * This class stores internally list of particles in three-dimensional arrays. * */ class LinkedCell_Model : public Observer { //!> grant our own unit test access to internal structure friend class ::LinkedCell_ModelTest; //!> grant view's unit test access to internal structure (used as stub there) friend class ::LinkedCell_ViewTest; public: ~LinkedCell_Model(); typedef std::pair LinkedCellNeighborhoodBounds; const tripleIndex getIndexToVector(const Vector &position) const; const LinkedCellNeighborhoodBounds getNeighborhoodBounds(const tripleIndex &index, const tripleIndex &step = NearestNeighbors) const; const tripleIndex getStep(const double distance) const; const LinkedCell& getCell(const tripleIndex &index) const; bool checkArrayBounds(const tripleIndex &index) const; void applyBoundaryConditions(tripleIndex &index) const; bool empty() const { return CellLookup.size() == 0; } void addNode(const TesselPoint *Walker); void deleteNode(const TesselPoint *Walker); void moveNode(const TesselPoint *Walker); void setPartition(double distance); void insertPointCloud(IPointCloud &set); const Box& getDomain() const { return domain; } //!> static indices to get nearest neighbors as default argument static tripleIndex NearestNeighbors; protected: void update(Observable *publisher); void recieveNotification(Observable *publisher, Notification_ptr notification); void subjectKilled(Observable *publisher); private: friend class LinkedCell_Controller; // don't allow any one else beside controller to create new models LinkedCell_Model(const double radius, const Box &_domain); LinkedCell_Model(IPointCloud &set, const double radius, const Box &_domain); LinkedCell_Model(const LinkedCell_Model&); LinkedCell_Model& operator=(const LinkedCell_Model&); private: void AllocateCells(); void Reset(); void startListening(); void stopListening(); // forward declaration for external Update class, containing update ops. class Update; // forward declaration for external changeModel class, containing change queue. class changeModel; //!> changeModel instance that contains a queue(map) with all changes to do. changeModel *Changes; void addNode_internal(const TesselPoint *Walker); void deleteNode_internal(const TesselPoint *Walker); void moveNode_internal(const TesselPoint *Walker); LinkedCellArray::index getSize(const size_t dim) const; typedef LinkedCellArray::size_type size_type; typedef LinkedCellArray::iterator iterator3; typedef boost::subarray_gen::type::iterator iterator2; typedef boost::subarray_gen::type::iterator iterator1; typedef std::map MapPointToCell; //!> internal shape of multi_array size_type *internal_Sizes; //!> internal index of current cell, this makes going through linked cell faster tripleIndex internal_index; //!> Lookup map to get the cell for a given TesselPoint MapPointToCell CellLookup; //!> edge length per axis boost::array EdgeLength; // forward declaration for LinkedCellArrayContainer, containing cached LinkedCellArray class LinkedCellArrayCache; //!> Linked cell array cache LinkedCellArrayCache *N; //!> matrix to divide Box with RealSpaceMatrix Dimensions; //!> matrix to transform normal position to obtain partitioned position RealSpaceMatrix Partition; //!> Box with matrix transformations and boundary conditions const Box &domain; }; } #endif /* LINKEDCELL_MODEL_HPP_ */