faunus
celllist.h
1 #pragma once
2 
13 namespace Faunus {
14 
15 namespace CellList {
16 
17 namespace Grid {
21 template <typename T> using GridTypeOf = typename T::GridType;
22 template <typename T> using IndexOf = typename T::CellIndex;
23 template <typename T> using CoordOf = typename T::CellCoord;
24 template <typename T> using SpaceAxisOf = typename T::SpaceAxis;
25 template <typename T> using PointOf = typename T::Point;
26 
34 template <unsigned int VDimension, std::integral TCellIndex = int,
35  std::floating_point TSpaceAxis = double>
36 struct GridType
37 {
38  constexpr static unsigned int Dimension =
39  VDimension;
40  using SpaceAxis = TSpaceAxis;
41  using CellIndex =
42  TCellIndex;
43  using Point = Eigen::Array<SpaceAxis, Dimension, 1>;
44  using CellCoord = Eigen::Array<CellIndex, Dimension, 1>;
45 };
46 
49 
55 {
56  using CellCoord = CoordOf<Grid3DType>;
57  using CellIndex = IndexOf<Grid3DType>;
58  public:
59  const std::vector<CellCoord> self{{0, 0, 0}};
60  std::vector<CellCoord> neighbors;
61  std::vector<CellCoord> forward_neighbors;
62  CellIndex distance;
63 
67  explicit GridOffsets3D(CellIndex distance);
68 
69  private:
70  void initNeighbors();
71  void initForwardNeighbors();
72 };
73 } // namespace Grid
74 
75 namespace Container {
79 template <typename T> using ContainerTypeOf = typename T::ContainerType;
80 template <typename T> using IndexOf = typename ContainerTypeOf<T>::Index;
81 template <typename T> using MemberOf = typename ContainerTypeOf<T>::Member;
82 template <typename T> using MembersOf = typename ContainerTypeOf<T>::Members;
83 
93 template <typename TMember, typename TIndex> struct AbstractContainer
94 {
96  using Index = TIndex;
97  using Member = TMember;
98  using Members = std::vector<Member>;
99 
101  virtual const Members& get(TIndex) const = 0;
103  virtual Members& get(TIndex) = 0;
105  virtual const Members& getEmpty() const = 0;
108  virtual std::vector<TIndex> indices() const = 0;
109  virtual ~AbstractContainer() = default;
110 };
111 } // namespace Container
112 
116 template <typename T> using ContainerOf = typename T::Container;
117 template <typename T> using GridOf = typename T::Grid;
118 using Container::ContainerTypeOf;
119 using Grid::GridTypeOf;
120 template <typename T>
121 using IndexOf = typename Grid::IndexOf<GridTypeOf<typename T::AbstractCellList>>;
122 template <typename T>
123 using CoordOf = typename Grid::CoordOf<GridTypeOf<typename T::AbstractCellList>>;
124 template <typename T>
125 using PointOf = typename Grid::PointOf<GridTypeOf<typename T::AbstractCellList>>;
126 template <typename T>
127 using SpaceAxisOf = typename Grid::SpaceAxisOf<GridTypeOf<typename T::AbstractCellList>>;
128 template <typename T> using MemberOf = typename Container::MemberOf<typename T::AbstractCellList>;
129 template <typename T> using MembersOf = typename Container::MembersOf<typename T::AbstractCellList>;
130 
137 template <class TContainerType, class TGridType> struct AbstractImmutableCellList
138 {
140  using ContainerType = TContainerType;
141  using GridType = TGridType;
142  using Members = typename Container::MembersOf<ContainerType>;
143  using Member = typename Container::MemberOf<ContainerType>;
144  using CellIndex = typename Grid::IndexOf<GridType>;
145  using CellCoord = typename Grid::CoordOf<GridType>;
146 
148  virtual const Members& getMembers(const CellCoord&) = 0;
150  virtual const Members& getNeighborMembers(const CellCoord&, const CellCoord&) = 0;
152  virtual CellIndex gridSize() const = 0; // todo check if needed
155  virtual std::vector<CellCoord> getCells() const = 0;
156  virtual ~AbstractImmutableCellList() = default;
157 };
158 
167 template <class TContainerType, class TGridType>
169  : virtual public AbstractImmutableCellList<TContainerType, TGridType>
170 {
172  using typename AbstractCellList::CellCoord;
173  using typename AbstractCellList::Members;
174 
176  virtual const Members& getSortedMembers(const CellCoord&) = 0;
177  virtual const Members& getNeighborSortedMembers(const CellCoord&, const CellCoord&) = 0;
178  virtual ~AbstractSortableCellList() = default;
179 };
180 } // namespace CellList
181 } // namespace Faunus
static constexpr unsigned int Dimension
number of dimmensions, e.g., 3 for the real 3D world
Definition: celllist.h:38
ContainerTypeOf< TContainer > ContainerType
abstract container types
Definition: celllist.h:140
Cell list class templates implementation.
TIndex Index
the cell index (key) type
Definition: celllist.h:96
An interface of a container.
Definition: celllist.h:93
Containers store members in individual cells with a common minimalistic interface.
A simple data holder for common offsets in 3D grids, e.g., nearest neighbors or forward neighbors...
Definition: celllist.h:54
Eigen::Array< SpaceAxis, Dimension, 1 > Point
a point in the VDimensional space
Definition: celllist.h:43
TCellIndex CellIndex
a single coordinate in cell space, e.g., int; also an absolute cell index
Definition: celllist.h:42
TSpaceAxis SpaceAxis
a single coordinate in physical space, e.g., double
Definition: celllist.h:40
std::vector< CellCoord > neighbors
all neighbors (excluding self); (1 + 2×distance)³ - 1
Definition: celllist.h:60
typename Container::MemberOf< ContainerType > Member
member type
Definition: celllist.h:143
std::vector< CellCoord > forward_neighbors
only the preceding half of all neighbors
Definition: celllist.h:61
Cell list class templates.
Definition: actions.cpp:11
GridTypeOf< TGrid > GridType
abstract grid type
Definition: celllist.h:141
typename Container::MembersOf< ContainerType > Members
members type
Definition: celllist.h:142
typename Grid::CoordOf< GridType > CellCoord
grid (cell) coordinates type
Definition: celllist.h:145
TMember Member
the cell member (primitive value) type
Definition: celllist.h:97
std::vector< Member > Members
the cell members type
Definition: celllist.h:98
Eigen::Array< CellIndex, Dimension, 1 > CellCoord
VDimensional cell coordinates.
Definition: celllist.h:44
typename Grid::IndexOf< GridType > CellIndex
grid (cell) index type
Definition: celllist.h:144
CellIndex distance
maximal distance of neighbours (1 for the nearest neighbors)
Definition: celllist.h:62
An interface of a immutable cell list.
Definition: celllist.h:137
A cell grid type declarations.
Definition: celllist.h:36
An interface to a cell list that can return cell&#39;s members in sorted order.
Definition: celllist.h:168