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