SynAPSE  0.6.0
Synergistic Analysis of Phase Space Evolution
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
Grid.hh
1 #ifndef GRID_HH
2 #define GRID_HH
3 
4 // C++ includes
5 #include <iostream>
6 #include <ctime>
7 #include <cmath>
8 #include <vector>
9 
10 // ROOT includes
11 #include "TPolyLine.h"
12 
13 // Additional includes
14 #include "Matrix.hh"
15 #include "Vertex.hh"
16 
19 class Grid {
20  public:
22  Grid();
23 
28  Grid(const std::vector<Vertex>& vertices);
29 
35  Grid(const Matrix<double>& mat,
36  const std::vector<double>& vec);
37 
45  Grid(double (*fcn)(const std::vector<double>& val),
46  const std::vector<size_t>& number,
47  const std::vector<double>& lower,
48  const std::vector<double>& upper);
49 
57  Grid(const std::vector<size_t>& number,
58  const std::vector<double>& lower,
59  const std::vector<double>& upper,
60  const std::string algo="flat");
61 
63  Grid(const Grid& grid);
64 
66  Grid& operator=(const Grid& grid);
67 
69  bool operator!() const { return !bool(_dim); }
70 
72  Vertex& operator[](const size_t id) { return _vertices[id]; }
73 
75  const Vertex& operator[](const size_t id) const { return _vertices[id]; }
76 
78  Vertex& operator[](const std::vector<size_t> indices) { return _vertices[ID(indices)]; }
79 
81  const Vertex& operator[](const std::vector<size_t> indices) const
82  { return _vertices[ID(indices)]; }
83 
85  ~Grid();
86 
88  const size_t size() const { return _vertices.size(); }
89 
91  void Initialize();
92 
98  void InitializeFromMatrix(const Matrix<double>& mat, const std::vector<double>& vec);
99 
104  void InitializeFromFunction(double (*fcn)(const std::vector<double>& val));
105 
110  void InitializeRandom(const std::string& algo);
111 
118  Grid GetBestCell(const std::vector<double>& v) const;
119 
121  std::vector<size_t> GetLowerIndices(const std::vector<double>& v) const;
122 
124  Grid GetCell(const std::vector<size_t>& indices) const;
125 
127  std::vector<Grid> GetCellArray() const;
128 
130  double GetCellVolume() const;
131 
133  const size_t& GetDimension() const { return _dim; }
134 
136  const std::vector<size_t>& GetNpointsArray() const { return _number; }
137 
139  const size_t& GetNpoints(const size_t i) const { return _number[i]; }
140 
142  const std::vector<size_t>& GetStepArray() const { return _step; }
143 
145  const size_t& GetStep(const size_t i) const { return _step[i]; }
146 
148  const std::vector<double>& GetPeriodArray() const { return _period; }
149 
151  const double& GetPeriod(const size_t i) const { return _period[i]; }
152 
154  const std::vector<double>& GetLowerBoundArray() const { return _lower; }
155 
157  const double& GetLowerBound(const size_t i) const { return _lower[i]; }
158 
160  const std::vector<double>& GetUpperBoundArray() const { return _upper; }
161 
163  const double& GetUpperBound(const size_t i) const { return _upper[i]; }
164 
166  void SetVertex(const std::vector<size_t>& indices, const Vertex& vertex)
167  { _vertices[ID(indices)] = vertex; }
168 
170  const std::vector<Vertex>& GetVertexArray() const { return _vertices; }
171 
173  std::vector<Vertex>& GetVertexArray() { return _vertices; }
174 
176  const std::vector<double>& GetPositionArray(const size_t id) const
177  { return _vertices[id].GetCoordinates(); }
178 
180  double GetPosition(const size_t i, const size_t id) const;
181 
183  std::vector<double> GetPosition(const std::vector<size_t>& vi,
184  const std::vector<size_t>& ids) const;
185 
187  double GetVolume() const;
188 
190  size_t ID(const std::vector<size_t>& indices) const;
191 
193  std::vector<size_t> Indices(size_t id) const;
194 
196  bool IsInside(const std::vector<double>& v) const;
197 
199  std::vector<TPolyLine*> Polygons() const;
200 
201  private:
202  size_t _dim;
203  std::vector<Vertex> _vertices;
204  std::vector<size_t> _number;
205  std::vector<size_t> _step;
206  std::vector<double> _period;
207  std::vector<double> _lower;
208  std::vector<double> _upper;
209 };
210 
211 #endif
std::vector< double > _upper
n-vector, upper bounds of the grid
Definition: Grid.hh:208
void InitializeFromFunction(double(*fcn)(const std::vector< double > &val))
Initializes the grid, provided a scalar function defined within boundaries.
Definition: Grid.cc:158
const size_t & GetDimension() const
Returns the dimension of the space in which the grid is constructed.
Definition: Grid.hh:133
double GetPosition(const size_t i, const size_t id) const
Returns the position in dimension i for a point index id in this dimension.
Definition: Grid.cc:356
std::vector< Vertex > & GetVertexArray()
Returns the array of all the vertices, allows modifications.
Definition: Grid.hh:173
Grid GetCell(const std::vector< size_t > &indices) const
Returns a cell of the grid given the lower bound indicies.
Definition: Grid.cc:302
void SetVertex(const std::vector< size_t > &indices, const Vertex &vertex)
Sets the coordinates of the vertex.
Definition: Grid.hh:166
bool IsInside(const std::vector< double > &v) const
Returns the indices of the element within the vertex matrix.
Definition: Grid.cc:402
const Vertex & operator[](const size_t id) const
Returns the vertex.
Definition: Grid.hh:75
Grid()
Default constructor, initilizes everything to 0.
Definition: Grid.cc:3
Data structure for a grid of points and their mapping onto a scalar field.
Definition: Grid.hh:19
const size_t & GetNpoints(const size_t i) const
Returns the number of points in dimension i.
Definition: Grid.hh:139
double GetCellVolume() const
Returns the volume of one of the cell of the grid.
Definition: Grid.cc:347
std::vector< size_t > _number
n-vector, number of steps on each axis
Definition: Grid.hh:204
std::vector< size_t > GetLowerIndices(const std::vector< double > &v) const
Find the IDs of the points on the grid that directly preceed v.
Definition: Grid.cc:280
const double & GetUpperBound(const size_t i) const
Returns the upper bound in dimension i.
Definition: Grid.hh:163
size_t ID(const std::vector< size_t > &indices) const
Returns the id of the element within the vertex matrix.
Definition: Grid.cc:380
std::vector< Vertex > _vertices
N_1*...*N_n-vector of vertices (Vertex object)
Definition: Grid.hh:203
std::vector< double > _lower
n-vector, lower bounds of the grid
Definition: Grid.hh:207
const size_t size() const
Returns the dimension of the vector field in which the vertex is defined.
Definition: Grid.hh:88
std::vector< size_t > _step
n-vector, stepping of each axis
Definition: Grid.hh:205
std::vector< Grid > GetCellArray() const
Returns all the cells of the grid in an array.
Definition: Grid.cc:324
const Vertex & operator[](const std::vector< size_t > indices) const
Subscript operator.
Definition: Grid.hh:81
const std::vector< double > & GetLowerBoundArray() const
Returns the array of lower bounds in each dimension.
Definition: Grid.hh:154
const std::vector< size_t > & GetNpointsArray() const
Returns the array of number of points in each dimension.
Definition: Grid.hh:136
const double & GetPeriod(const size_t i) const
Returns the period size in dimension i.
Definition: Grid.hh:151
const double & GetLowerBound(const size_t i) const
Returns the lower bound in dimension i.
Definition: Grid.hh:157
Vertex & operator[](const size_t id)
Returns the vertex.
Definition: Grid.hh:72
Vertex & operator[](const std::vector< size_t > indices)
Subscript operator.
Definition: Grid.hh:78
const size_t & GetStep(const size_t i) const
Returns the step size in dimension i.
Definition: Grid.hh:145
std::vector< TPolyLine * > Polygons() const
Returns an array of polygons to be drawn in ROOT (only 2D)
Definition: Grid.cc:412
void Initialize()
Initializes the grid.
Definition: Grid.cc:82
Grid & operator=(const Grid &grid)
Equality operator.
Definition: Grid.cc:65
Grid GetBestCell(const std::vector< double > &v) const
Find the closest cell of the grid to a given point of coordinates v.
Definition: Grid.cc:274
size_t _dim
Dimension of the space.
Definition: Grid.hh:202
const std::vector< double > & GetPositionArray(const size_t id) const
Returns the position of a point of index id.
Definition: Grid.hh:176
void InitializeFromMatrix(const Matrix< double > &mat, const std::vector< double > &vec)
Initializes the grid, provided a matrix of vertices and their mapping.
Definition: Grid.cc:136
const std::vector< double > & GetPeriodArray() const
Returns the array of period size in each dimension.
Definition: Grid.hh:148
void InitializeRandom(const std::string &algo)
Initializes the grid to random values of scalar field.
Definition: Grid.cc:214
std::vector< double > _period
n-vector, length of a period of each axis
Definition: Grid.hh:206
const std::vector< double > & GetUpperBoundArray() const
Returns the array of upper bounds in each dimension.
Definition: Grid.hh:160
double GetVolume() const
Returns the volume occupied by the grid.
Definition: Grid.cc:371
bool operator!() const
Not operator.
Definition: Grid.hh:69
std::vector< size_t > Indices(size_t id) const
Returns the indices of the element within the vertex matrix.
Definition: Grid.cc:389
const std::vector< size_t > & GetStepArray() const
Returns the array of step sizes in each dimension.
Definition: Grid.hh:142
const std::vector< Vertex > & GetVertexArray() const
Returns the array of all the vertices.
Definition: Grid.hh:170
Defines an n-dimensional vertex and its mapping onto a sclar field.
Definition: Vertex.hh:13
~Grid()
Destructor.
Definition: Grid.cc:80