Version: SMASH-3.1
grid.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2014-2015,2017-2022
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:
113  Grid(const Particles &particles, double min_cell_length,
114  double timestep_duration, CellNumberLimitation limit,
115  const bool include_unformed_particles = false,
117  : Grid{find_min_and_length(particles),
118  std::move(particles),
119  min_cell_length,
120  timestep_duration,
121  limit,
122  include_unformed_particles,
123  strategy} {}
124 
141  Grid(const std::pair<std::array<double, 3>, std::array<double, 3>>
142  &min_and_length,
143  const Particles &particles, double min_cell_length,
144  double timestep_duration, CellNumberLimitation limit,
145  const bool include_unformed_particles = false,
147 
165  const std::function<void(const ParticleList &)> &search_cell_callback,
166  const std::function<void(const ParticleList &, const ParticleList &)>
167  &neighbor_cell_callback) const;
168 
172  double cell_volume() const { return cell_volume_; }
173 
174  private:
180 
185  SizeType make_index(std::array<SizeType, 3> idx) const {
186  return make_index(idx[0], idx[1], idx[2]);
187  }
188 
190  const std::array<double, 3> length_;
191 
193  double cell_volume_;
194 
196  std::array<int, 3> number_of_cells_;
197 
199  std::vector<ParticleList> cells_;
200 };
201 
202 } // namespace smash
203 
204 #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:87
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:190
std::array< int, 3 > number_of_cells_
The number of cells in x, y, and z direction.
Definition: grid.h:196
double cell_volume() const
Definition: grid.h:172
double cell_volume_
The volume of a single cell.
Definition: grid.h:193
std::vector< ParticleList > cells_
The cell storage.
Definition: grid.h:199
SizeType make_index(std::array< SizeType, 3 > idx) const
Definition: grid.h:185
Grid(const Particles &particles, double min_cell_length, double timestep_duration, CellNumberLimitation limit, const bool include_unformed_particles=false, CellSizeStrategy strategy=CellSizeStrategy::Optimal)
Constructs a grid from the given particle list particles.
Definition: grid.h:113
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...
SizeType make_index(SizeType x, SizeType y, SizeType z) const
Definition: grid.cc:290
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.