Version: SMASH-1.5
grid.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2018
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_GRID_H_
11 #define SRC_INCLUDE_GRID_H_
12 
13 #include <array>
14 #include <cmath>
15 #include <functional>
16 #include <utility>
17 #include <vector>
18 
19 #include "forwarddeclarations.h"
20 #include "particles.h"
21 
22 namespace smash {
23 
25 enum class GridOptions : char {
27  Normal = 0,
30 };
31 
33 enum class CellSizeStrategy : char {
35  Optimal,
36 
43  Largest
44 };
45 
50 class GridBase {
51  public:
53  typedef int SizeType;
54 
55  protected:
62  static std::pair<std::array<double, 3>, std::array<double, 3>>
63  find_min_and_length(const Particles &particles);
64 };
65 
78 template <GridOptions Options = GridOptions::Normal>
79 class Grid : public GridBase {
80  public:
90  Grid(const Particles &particles, double min_cell_length,
92  : Grid{find_min_and_length(particles), std::move(particles),
93  min_cell_length, strategy} {}
94 
106  Grid(const std::pair<std::array<double, 3>, std::array<double, 3>>
107  &min_and_length,
108  const Particles &particles, double min_cell_length,
110 
127  void iterate_cells(
128  const std::function<void(const ParticleList &)> &search_cell_callback,
129  const std::function<void(const ParticleList &, const ParticleList &)>
130  &neighbor_cell_callback) const;
131 
132  private:
138 
143  SizeType make_index(std::array<SizeType, 3> idx) const {
144  return make_index(idx[0], idx[1], idx[2]);
145  }
146 
148  const std::array<double, 3> length_;
149 
151  std::array<int, 3> number_of_cells_;
152 
154  std::vector<ParticleList> cells_;
155 };
156 
157 } // namespace smash
158 
159 #endif // SRC_INCLUDE_GRID_H_
With ghost cells for periodic boundaries.
Without ghost cells.
Look for optimal cell size.
std::vector< ParticleList > cells_
The cell storage.
Definition: grid.h:154
SizeType make_index(std::array< SizeType, 3 > idx) const
Definition: grid.h:143
void iterate_cells(const std::function< void(const ParticleList &)> &search_cell_callback, const std::function< void(const ParticleList &, const ParticleList &)> &neighbor_cell_callback) const
Iterates over all cells in the grid and calls the callback arguments with a search cell and 0 to 13 n...
std::array< int, 3 > number_of_cells_
The number of cells in x, y, and z direction.
Definition: grid.h:151
int SizeType
A type to store the sizes.
Definition: grid.h:53
static std::pair< std::array< double, 3 >, std::array< double, 3 > > find_min_and_length(const Particles &particles)
Definition: grid.cc:71
CellSizeStrategy
Indentifies the strategy of determining the cell size.
Definition: grid.h:33
Base class for Grid to host common functions that do not depend on the GridOptions parameter...
Definition: grid.h:50
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
Grid(const Particles &particles, double min_cell_length, CellSizeStrategy strategy=CellSizeStrategy::Optimal)
Constructs a grid from the given particle list particles.
Definition: grid.h:90
Abstracts a list of cells that partition the particles in the experiment into regions of space that c...
Definition: grid.h:79
Make cells as large as possible.
SizeType make_index(SizeType x, SizeType y, SizeType z) const
Definition: grid.cc:244
const std::array< double, 3 > length_
The 3 lengths of the complete grid. Used for periodic boundary wrapping.
Definition: grid.h:148
Definition: action.h:24
GridOptions
Identifies the mode of the Grid.
Definition: grid.h:25