Version: SMASH-2.1
grid.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2020
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_GRID_H_
11 #define SRC_INCLUDE_SMASH_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 
55 enum class CellNumberLimitation : char {
57  None,
58 
61 };
62 
67 class GridBase {
68  public:
70  typedef int SizeType;
71 
72  protected:
79  static std::pair<std::array<double, 3>, std::array<double, 3>>
80  find_min_and_length(const Particles &particles);
81 };
82 
95 template <GridOptions Options = GridOptions::Normal>
96 class Grid : public GridBase {
97  public:
111  Grid(const Particles &particles, double min_cell_length,
112  double timestep_duration, CellNumberLimitation limit,
114  : Grid{find_min_and_length(particles),
115  std::move(particles),
116  min_cell_length,
117  timestep_duration,
118  limit,
119  strategy} {}
120 
135  Grid(const std::pair<std::array<double, 3>, std::array<double, 3>>
136  &min_and_length,
137  const Particles &particles, double min_cell_length,
138  double timestep_duration, CellNumberLimitation limit,
140 
158  const std::function<void(const ParticleList &)> &search_cell_callback,
159  const std::function<void(const ParticleList &, const ParticleList &)>
160  &neighbor_cell_callback) const;
161 
165  double cell_volume() const { return cell_volume_; }
166 
167  private:
173 
178  SizeType make_index(std::array<SizeType, 3> idx) const {
179  return make_index(idx[0], idx[1], idx[2]);
180  }
181 
183  const std::array<double, 3> length_;
184 
186  double cell_volume_;
187 
189  std::array<int, 3> number_of_cells_;
190 
192  std::vector<ParticleList> cells_;
193 };
194 
195 } // namespace smash
196 
197 #endif // SRC_INCLUDE_SMASH_GRID_H_
Base class for Grid to host common functions that do not depend on the GridOptions parameter.
Definition: grid.h:67
int SizeType
A type to store the sizes.
Definition: grid.h:70
static std::pair< std::array< double, 3 >, std::array< double, 3 > > find_min_and_length(const Particles &particles)
Definition: grid.cc:72
Abstracts a list of cells that partition the particles in the experiment into regions of space that c...
Definition: grid.h:96
const std::array< double, 3 > length_
The 3 lengths of the complete grid. Used for periodic boundary wrapping.
Definition: grid.h:183
std::array< int, 3 > number_of_cells_
The number of cells in x, y, and z direction.
Definition: grid.h:189
double cell_volume() const
Definition: grid.h:165
double cell_volume_
The volume of a single cell.
Definition: grid.h:186
std::vector< ParticleList > cells_
The cell storage.
Definition: grid.h:192
SizeType make_index(std::array< SizeType, 3 > idx) const
Definition: grid.h:178
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...
Grid(const Particles &particles, double min_cell_length, double timestep_duration, CellNumberLimitation limit, CellSizeStrategy strategy=CellSizeStrategy::Optimal)
Constructs a grid from the given particle list particles.
Definition: grid.h:111
SizeType make_index(SizeType x, SizeType y, SizeType z) const
Definition: grid.cc:255
The Particles class abstracts the storage and manipulation of particles.
Definition: particles.h:33
Definition: action.h:24
CellNumberLimitation
Identifies whether the number of cells should be limited.
Definition: grid.h:55
@ ParticleNumber
Limit the number of cells to the number of particles.
@ None
No cell number limitation.
GridOptions
Identifies the mode of the Grid.
Definition: grid.h:25
@ Normal
Without ghost cells.
@ PeriodicBoundaries
With ghost cells for periodic boundaries.
CellSizeStrategy
Indentifies the strategy of determining the cell size.
Definition: grid.h:33
@ Optimal
Look for optimal cell size.
@ Largest
Make cells as large as possible.