| 1 | /*
 | 
|---|
| 2 |  * LinkedCell_Model.hpp
 | 
|---|
| 3 |  *
 | 
|---|
| 4 |  *  Created on: Nov 15, 2011
 | 
|---|
| 5 |  *      Author: heber
 | 
|---|
| 6 |  */
 | 
|---|
| 7 | 
 | 
|---|
| 8 | #ifndef LINKEDCELL_MODEL_HPP_
 | 
|---|
| 9 | #define LINKEDCELL_MODEL_HPP_
 | 
|---|
| 10 | 
 | 
|---|
| 11 | // include config.h
 | 
|---|
| 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
| 13 | #include <config.h>
 | 
|---|
| 14 | #endif
 | 
|---|
| 15 | 
 | 
|---|
| 16 | #include <boost/multi_array.hpp>
 | 
|---|
| 17 | #include <map>
 | 
|---|
| 18 | 
 | 
|---|
| 19 | #include "CodePatterns/Observer/Observer.hpp"
 | 
|---|
| 20 | #include "LinearAlgebra/defs.hpp"
 | 
|---|
| 21 | #include "LinearAlgebra/RealSpaceMatrix.hpp"
 | 
|---|
| 22 | #include "LinkedCell/tripleIndex.hpp"
 | 
|---|
| 23 | #include "LinkedCell/types.hpp"
 | 
|---|
| 24 | 
 | 
|---|
| 25 | class Box;
 | 
|---|
| 26 | class IPointCloud;
 | 
|---|
| 27 | class LinkedCell_ModelTest;
 | 
|---|
| 28 | class TesselPoint;
 | 
|---|
| 29 | class Vector;
 | 
|---|
| 30 | 
 | 
|---|
| 31 | namespace LinkedCell {
 | 
|---|
| 32 | 
 | 
|---|
| 33 |   /** This is the model in the MVC ansatz for the LinkedCell structure.
 | 
|---|
| 34 |    *
 | 
|---|
| 35 |    * \sa linkedcell
 | 
|---|
| 36 |    *
 | 
|---|
| 37 |    * The model represents a certain linked cell structure with a specific mesh
 | 
|---|
| 38 |    * size (i.e. edge length). Note that all coordinates are internally always
 | 
|---|
| 39 |    * transformed to [0,1]^3, hence we require the domain (\ref Box) for the
 | 
|---|
| 40 |    * transformation matrices.
 | 
|---|
| 41 |    *
 | 
|---|
| 42 |    * This class stores internally list of particles in three-dimensional arrays.
 | 
|---|
| 43 |    *
 | 
|---|
| 44 |    */
 | 
|---|
| 45 |   class LinkedCell_Model : public Observer
 | 
|---|
| 46 |   {
 | 
|---|
| 47 |     //!> grant unit test access to internal structure
 | 
|---|
| 48 |     friend class ::LinkedCell_ModelTest;
 | 
|---|
| 49 |   public:
 | 
|---|
| 50 |     LinkedCell_Model(const double radius, const Box &_domain);
 | 
|---|
| 51 |     LinkedCell_Model(IPointCloud &set, const double radius, const Box &_domain);
 | 
|---|
| 52 |     ~LinkedCell_Model();
 | 
|---|
| 53 | 
 | 
|---|
| 54 |     typedef std::pair<tripleIndex,tripleIndex> LinkedCellNeighborhoodBounds;
 | 
|---|
| 55 | 
 | 
|---|
| 56 |     const tripleIndex getIndexToVector(const Vector &position) const;
 | 
|---|
| 57 |     const LinkedCellNeighborhoodBounds getNeighborhoodBounds(const tripleIndex &index, const tripleIndex &step = NearestNeighbors) const;
 | 
|---|
| 58 |     const tripleIndex getStep(const double distance) const;
 | 
|---|
| 59 |     const LinkedCell& getCell(const tripleIndex &index) const;
 | 
|---|
| 60 |     bool checkArrayBounds(const tripleIndex &index) const;
 | 
|---|
| 61 |     void applyBoundaryConditions(tripleIndex &index) const;
 | 
|---|
| 62 |     bool empty() const { return CellLookup.size() == 0; }
 | 
|---|
| 63 | 
 | 
|---|
| 64 |     void addNode(const TesselPoint *Walker);
 | 
|---|
| 65 |     void deleteNode(const TesselPoint *Walker);
 | 
|---|
| 66 |     void moveNode(const TesselPoint *Walker);
 | 
|---|
| 67 | 
 | 
|---|
| 68 |     void setPartition(double distance);
 | 
|---|
| 69 | 
 | 
|---|
| 70 |     void insertPointCloud(IPointCloud &set);
 | 
|---|
| 71 | 
 | 
|---|
| 72 |     //!> static indices to get nearest neighbors as default argument
 | 
|---|
| 73 |     static tripleIndex NearestNeighbors;
 | 
|---|
| 74 | 
 | 
|---|
| 75 |   protected:
 | 
|---|
| 76 |     void update(Observable *publisher);
 | 
|---|
| 77 |     void recieveNotification(Observable *publisher, Notification_ptr notification);
 | 
|---|
| 78 |     void subjectKilled(Observable *publisher);
 | 
|---|
| 79 | 
 | 
|---|
| 80 |   private:
 | 
|---|
| 81 |     void AllocateCells();
 | 
|---|
| 82 |     void Reset();
 | 
|---|
| 83 | 
 | 
|---|
| 84 |     void startListening();
 | 
|---|
| 85 |     void stopListening();
 | 
|---|
| 86 | 
 | 
|---|
| 87 |     void addNode_internal(const TesselPoint *Walker);
 | 
|---|
| 88 |     void deleteNode_internal(const TesselPoint *Walker);
 | 
|---|
| 89 |     void moveNode_internal(const TesselPoint *Walker);
 | 
|---|
| 90 | 
 | 
|---|
| 91 |     LinkedCellArray::index getSize(const size_t dim) const;
 | 
|---|
| 92 | 
 | 
|---|
| 93 |     typedef LinkedCellArray::size_type size_type;
 | 
|---|
| 94 |     typedef LinkedCellArray::iterator iterator3;
 | 
|---|
| 95 |     typedef boost::subarray_gen<LinkedCellArray, NDIM-1>::type::iterator iterator2;
 | 
|---|
| 96 |     typedef boost::subarray_gen<LinkedCellArray, NDIM-2>::type::iterator iterator1;
 | 
|---|
| 97 | 
 | 
|---|
| 98 |     typedef std::map<const TesselPoint *, LinkedCell *> MapPointToCell;
 | 
|---|
| 99 | 
 | 
|---|
| 100 |     //!> internal shape of multi_array
 | 
|---|
| 101 |     size_type *internal_Sizes;
 | 
|---|
| 102 | 
 | 
|---|
| 103 |     //!> internal index of current cell, this makes going through linked cell faster
 | 
|---|
| 104 |     tripleIndex internal_index;
 | 
|---|
| 105 | 
 | 
|---|
| 106 |     //!> Lookup map to get the cell for a given TesselPoint
 | 
|---|
| 107 |     MapPointToCell CellLookup;
 | 
|---|
| 108 | 
 | 
|---|
| 109 |     //!> edge length per axis
 | 
|---|
| 110 |     boost::array<double, 3> EdgeLength;
 | 
|---|
| 111 | 
 | 
|---|
| 112 |     //!> Linked cell array
 | 
|---|
| 113 |     LinkedCellArray N;
 | 
|---|
| 114 | 
 | 
|---|
| 115 |     //!> matrix to divide Box with
 | 
|---|
| 116 |     RealSpaceMatrix Dimensions;
 | 
|---|
| 117 | 
 | 
|---|
| 118 |     //!> matrix to transform normal position to obtain partitioned position
 | 
|---|
| 119 |     RealSpaceMatrix Partition;
 | 
|---|
| 120 | 
 | 
|---|
| 121 |     //!> Box with matrix transformations and boundary conditions
 | 
|---|
| 122 |     const Box &domain;
 | 
|---|
| 123 |   };
 | 
|---|
| 124 | 
 | 
|---|
| 125 | }
 | 
|---|
| 126 | 
 | 
|---|
| 127 | // inlined functions
 | 
|---|
| 128 | #include "LinkedCell_Model_inline.hpp"
 | 
|---|
| 129 | 
 | 
|---|
| 130 | #endif /* LINKEDCELL_MODEL_HPP_ */
 | 
|---|