CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ChainMesh.h
Go to the documentation of this file.
1 /********************************************************************
2  * Copyright (C) 2010 by Federico Marulli and Alfonso Veropalumbo *
3  * federico.marulli3@unibo.it *
4  * *
5  * This program is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU General Public License as *
7  * published by the Free Software Foundation; either version 2 of *
8  * the License, or (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public *
16  * License along with this program; if not, write to the Free *
17  * Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  *******************************************************************/
20 
34 #include "Kernel.h"
35 
36 #ifndef __CHAINMESH__
37 #define __CHAINMESH__
38 
39 
40 namespace cbl {
41 
50  namespace chainmesh {
51 
60  class ChainMesh {
61 
62  protected:
63 
65  int m_nDim;
66 
68  std::vector<long> m_cell_to_index;
69 
71  double m_cell_size;
72 
74  std::vector<long> m_List;
75 
77  std::vector<long> m_Label;
78 
80  std::vector<std::vector<long> > m_List_index;
81 
83  std::vector<std::vector<double> > m_Lim;
84 
86  std::vector<double> m_Delta;
87 
89  std::vector<long> m_nCell;
90 
92  std::vector<long> m_search_region;
93 
96 
99 
101  std::vector<long> m_NonEmpty_Cells;
102 
104  std::vector<long> m_multCell;
105 
107  std::vector<std::vector<double>> m_points;
108 
110  std::vector<double> m_values;
111 
113  std::vector<std::vector<double>> m_extremals;
114 
116  std::vector<double> m_delta;
117 
119  double m_rMAX;
120 
122  double m_rMIN;
123 
124  public:
125 
130  ChainMesh () = default;
131 
138  ChainMesh (const double cell_size, const long nDim);
139 
143  ~ChainMesh () = default;
144 
150  void set_par (const double cell_size, const long nDim);
151 
156  long nCell() const { return m_nCell_tot; }
157 
162  long nCell_NonEmpty() const { return m_nCell_NonEmpty; }
163 
168  std::vector<long> NonEmpty_Cells() const { return m_NonEmpty_Cells; }
169 
175  long pos_to_index (const std::vector<double> center) const;
176 
182  long inds_to_index (const std::vector<long> indx) const;
183 
190  void index_to_inds (const long index, const std::vector<long> nn, std::vector<long> &indx) const;
191 
200  void create_chain_mesh (const std::vector<std::vector<double> > data, const double rMax, const double rMin=-1., const long nMAX=300, const long nMIN=10);
201 
206  void create_chain_mesh_m2 (const std::vector<std::vector<double> > data);
207 
214  void get_searching_region (const double r_max, const double r_min=-1.);
215 
222  std::vector<long> close_objects_cell (const int cell_index, long ii=-1) const;
223 
230  std::vector<long> close_objects (std::vector<double> center, long ii=-1) const;
231 
243  void normalize (std::vector<std::vector<double>> points, std::vector<double> values, const double rMAX);
244 
257  double interpolate (std::vector<double> xi, const int distNum);
258 
276  std::vector<double> interpolate (std::vector<std::vector<double>> points, std::vector<double> values, std::vector<std::vector<double>> xi, const int distNum, const double rMAX);
277 
286  std::vector<long> get_list (const long cell_index) const;
287 
288  };
289 
290 
299  class ChainMesh1D : public ChainMesh
300  {
301  public:
306  ChainMesh1D () = default;
307 
311  ~ChainMesh1D () = default;
312 
322  void set_par (const double cell_size, const std::vector<double> xx, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0);
323 
333  ChainMesh1D (const double cell_size, const std::vector<double> xx, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0);
334  };
335 
344  class ChainMesh2D : public ChainMesh
345  {
346  public:
351  ChainMesh2D () = default;
352 
356  ~ChainMesh2D () = default;
357 
368  void set_par (const double cell_size, const std::vector<double> xx, const std::vector<double> yy, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0);
369 
380  ChainMesh2D (const double cell_size, const std::vector<double> xx, const std::vector<double> yy, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0);
381  };
382 
391  class ChainMesh3D : public ChainMesh
392  {
393  public:
394 
399  ChainMesh3D () = default;
400 
404  ~ChainMesh3D () = default;
405 
419  void set_par (const double cell_size, const std::vector<double> xx, const std::vector<double> yy, const std::vector<double> zz, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0);
420 
434  ChainMesh3D (const double cell_size, const std::vector<double> xx, const std::vector<double> yy, const std::vector<double> zz, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0);
435  };
436 
437  }
438 }
439 
440 #endif
Useful generic functions.
The class ChainMesh1D.
Definition: ChainMesh.h:300
ChainMesh1D()=default
default constructor
void set_par(const double cell_size, const std::vector< double > xx, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0)
function that set parameters for the chain-mesh
Definition: ChainMesh.cpp:543
~ChainMesh1D()=default
default destructor
The class ChainMesh2D.
Definition: ChainMesh.h:345
ChainMesh2D()=default
default constructor 1D
~ChainMesh2D()=default
default destructor
void set_par(const double cell_size, const std::vector< double > xx, const std::vector< double > yy, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0)
function that set parameters for the chain-mesh
Definition: ChainMesh.cpp:565
The class ChainMesh3D.
Definition: ChainMesh.h:392
ChainMesh3D()=default
default constructor
~ChainMesh3D()=default
default destructor
void set_par(const double cell_size, const std::vector< double > xx, const std::vector< double > yy, const std::vector< double > zz, const double rMAX, const double rMIN=-1., const long nMAX=300, const long nMIN=0)
function that set parameters for the chain-mesh
Definition: ChainMesh.cpp:588
The class ChainMesh.
Definition: ChainMesh.h:60
std::vector< double > m_values
the vector containing the values of the n-dim function on the sample points
Definition: ChainMesh.h:110
std::vector< long > close_objects(std::vector< double > center, long ii=-1) const
get the indeces of the objects close to an object
Definition: ChainMesh.cpp:298
void create_chain_mesh(const std::vector< std::vector< double > > data, const double rMax, const double rMin=-1., const long nMAX=300, const long nMIN=10)
create the chain mesh
Definition: ChainMesh.cpp:133
std::vector< long > m_nCell
number of cell(s) for variable(s)
Definition: ChainMesh.h:89
std::vector< long > m_search_region
the list of cell around a generic center
Definition: ChainMesh.h:92
double interpolate(std::vector< double > xi, const int distNum)
N-dim interpolation of a set of N coordinates on a normalised grid (see normalize)
Definition: ChainMesh.cpp:387
std::vector< long > m_multCell
multiplicative factor to compute the projected number of cells
Definition: ChainMesh.h:104
std::vector< std::vector< long > > m_List_index
index list of internal use
Definition: ChainMesh.h:80
std::vector< double > m_Delta
Max-Min of variable(s) used for the chain-mesh.
Definition: ChainMesh.h:86
double m_cell_size
the size of the cell in unit of the interested quantity
Definition: ChainMesh.h:71
int m_nDim
the number of dimension
Definition: ChainMesh.h:65
std::vector< double > m_delta
vetors of differences between the extremals of the sample points coordinates
Definition: ChainMesh.h:116
long nCell() const
get the private member ChainMesh::m_nCell_tot
Definition: ChainMesh.h:156
std::vector< std::vector< double > > m_Lim
Min,Max limits of variable(s) used for the chain-mesh.
Definition: ChainMesh.h:83
std::vector< long > m_Label
array containing the last particle of the chain-mesh in each cell
Definition: ChainMesh.h:77
void set_par(const double cell_size, const long nDim)
function that set parameters for the chain-mesh
Definition: ChainMesh.cpp:45
void create_chain_mesh_m2(const std::vector< std::vector< double > > data)
create the chain mesh
Definition: ChainMesh.cpp:196
ChainMesh()=default
default constructor
std::vector< std::vector< double > > m_points
the vector containing the sample points for the n-dim interpolation
Definition: ChainMesh.h:107
std::vector< long > m_cell_to_index
indexes in the i-th cell
Definition: ChainMesh.h:68
std::vector< long > m_List
list of internal use
Definition: ChainMesh.h:74
void get_searching_region(const double r_max, const double r_min=-1.)
set the internal variable m_search_region, the list of cell around a generic center
Definition: ChainMesh.cpp:226
double m_rMAX
the maximum radius for the search of close points in the chain mesh
Definition: ChainMesh.h:119
std::vector< long > NonEmpty_Cells() const
get the private member ChainMesh::m_NonEmpty_Cells
Definition: ChainMesh.h:168
long pos_to_index(const std::vector< double > center) const
get the index of the cell given the object coordinates
Definition: ChainMesh.cpp:73
void normalize(std::vector< std::vector< double >> points, std::vector< double > values, const double rMAX)
function to set a normalized (square/cubic) grid from a sample of points, used for the N-dim interpol...
Definition: ChainMesh.cpp:349
std::vector< std::vector< double > > m_extremals
the vector containing the extremals of the sample points coordinates
Definition: ChainMesh.h:113
void index_to_inds(const long index, const std::vector< long > nn, std::vector< long > &indx) const
get the n indices given the unique index
Definition: ChainMesh.cpp:112
double m_rMIN
the minimum radius for the search of close points in the chain mesh
Definition: ChainMesh.h:122
std::vector< long > m_NonEmpty_Cells
the total number of non-empty cells
Definition: ChainMesh.h:101
long nCell_NonEmpty() const
get the private member ChainMesh::m_nCell_NonEmpty
Definition: ChainMesh.h:162
std::vector< long > get_list(const long cell_index) const
get the index of the object inside a cell
Definition: ChainMesh.cpp:526
long m_nCell_NonEmpty
the number of non-empty cells
Definition: ChainMesh.h:98
std::vector< long > close_objects_cell(const int cell_index, long ii=-1) const
get the indeces of the objects close to a cell
Definition: ChainMesh.cpp:271
long m_nCell_tot
the total number of cells
Definition: ChainMesh.h:95
~ChainMesh()=default
default destructor
long inds_to_index(const std::vector< long > indx) const
get the unique index of the cell given the n indices
Definition: ChainMesh.cpp:95
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38