Version: SMASH-2.0
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 
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 
112  Grid(const std::pair<std::array<double, 3>, std::array<double, 3>>
113  &min_and_length,
114  const Particles &particles, double min_cell_length,
115  double timestep_duration,
117 
134  void iterate_cells(
135  const std::function<void(const ParticleList &)> &search_cell_callback,
136  const std::function<void(const ParticleList &, const ParticleList &)>
137  &neighbor_cell_callback) const;
138 
142  double cell_volume() const { return cell_volume_; }
143 
144  private:
150 
155  SizeType make_index(std::array<SizeType, 3> idx) const {
156  return make_index(idx[0], idx[1], idx[2]);
157  }
158 
160  const std::array<double, 3> length_;
161 
163  double cell_volume_;
164 
166  std::array<int, 3> number_of_cells_;
167 
169  std::vector<ParticleList> cells_;
170 };
171 
172 } // namespace smash
173 
174 #endif // SRC_INCLUDE_SMASH_GRID_H_
smash
Definition: action.h:24
smash::CellSizeStrategy::Optimal
Look for optimal cell size.
smash::GridOptions
GridOptions
Identifies the mode of the Grid.
Definition: grid.h:25
smash::CellSizeStrategy
CellSizeStrategy
Indentifies the strategy of determining the cell size.
Definition: grid.h:33
smash::GridOptions::Normal
Without ghost cells.
forwarddeclarations.h
smash::Grid::number_of_cells_
std::array< int, 3 > number_of_cells_
The number of cells in x, y, and z direction.
Definition: grid.h:166
smash::Grid::iterate_cells
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...
smash::Grid
Abstracts a list of cells that partition the particles in the experiment into regions of space that c...
Definition: grid.h:79
smash::Grid::make_index
SizeType make_index(std::array< SizeType, 3 > idx) const
Definition: grid.h:155
smash::Grid::cells_
std::vector< ParticleList > cells_
The cell storage.
Definition: grid.h:169
smash::CellSizeStrategy::Largest
Make cells as large as possible.
smash::Grid::length_
const std::array< double, 3 > length_
The 3 lengths of the complete grid. Used for periodic boundary wrapping.
Definition: grid.h:160
smash::GridBase::SizeType
int SizeType
A type to store the sizes.
Definition: grid.h:53
particles.h
smash::Grid::cell_volume_
double cell_volume_
The volume of a single cell.
Definition: grid.h:163
smash::GridBase
Base class for Grid to host common functions that do not depend on the GridOptions parameter.
Definition: grid.h:50
smash::Particles
Definition: particles.h:33
smash::Grid::Grid
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
smash::GridOptions::PeriodicBoundaries
With ghost cells for periodic boundaries.
smash::Grid::cell_volume
double cell_volume() const
Definition: grid.h:142
smash::GridBase::find_min_and_length
static std::pair< std::array< double, 3 >, std::array< double, 3 > > find_min_and_length(const Particles &particles)
Definition: grid.cc:72
smash::Grid::make_index
SizeType make_index(SizeType x, SizeType y, SizeType z) const
Definition: grid.cc:275