Version: SMASH-1.6
grid.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2019
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:
93  Grid(const Particles &particles, double min_cell_length,
94  double timestep_duration,
96  : Grid{find_min_and_length(particles), std::move(particles),
97  min_cell_length, timestep_duration, strategy} {}
98 
111  Grid(const std::pair<std::array<double, 3>, std::array<double, 3>>
112  &min_and_length,
113  const Particles &particles, double min_cell_length,
114  double timestep_duration,
116 
133  void iterate_cells(
134  const std::function<void(const ParticleList &)> &search_cell_callback,
135  const std::function<void(const ParticleList &, const ParticleList &)>
136  &neighbor_cell_callback) const;
137 
138  private:
143  SizeType make_index(SizeType x, SizeType y, SizeType z) const;
144 
149  SizeType make_index(std::array<SizeType, 3> idx) const {
150  return make_index(idx[0], idx[1], idx[2]);
151  }
152 
154  const std::array<double, 3> length_;
155 
157  std::array<int, 3> number_of_cells_;
158 
160  std::vector<ParticleList> cells_;
161 };
162 
163 } // namespace smash
164 
165 #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:160
Grid(const Particles &particles, double min_cell_length, double timestep_duration, CellSizeStrategy strategy=CellSizeStrategy::Optimal)
Constructs a grid from the given particle list particles.
Definition: grid.h:93
std::array< int, 3 > number_of_cells_
The number of cells in x, y, and z direction.
Definition: grid.h:157
int SizeType
A type to store the sizes.
Definition: grid.h:53
SizeType make_index(std::array< SizeType, 3 > idx) const
Definition: grid.h:149
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
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.
const std::array< double, 3 > length_
The 3 lengths of the complete grid. Used for periodic boundary wrapping.
Definition: grid.h:154
Definition: action.h:24
GridOptions
Identifies the mode of the Grid.
Definition: grid.h:25