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