CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ChainMesh_Catalogue.cpp
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 "ChainMesh_Catalogue.h"
35 
36 using namespace std;
37 
38 using namespace cbl;
39 using namespace catalogue;
40 using namespace chainmesh;
41 
42 
43 // ============================================================================
44 
45 
46 void cbl::chainmesh::ChainMesh_Catalogue::set_par (const double cell_size, std::shared_ptr<Catalogue> cat, const double rmax, const double rmin)
47 {
48  ChainMesh::set_par(cell_size, 3);
49 
50  m_catalogue = cat;
51 
52  vector<vector<double>> data = { m_catalogue->var(Var::_X_), m_catalogue->var(Var::_Y_), m_catalogue->var(Var::_Z_) };
53 
54  create_chain_mesh(data, rmax, rmin);
55 
56  vector<int> order;
57  get_order(order);
58  m_catalogue->Order(order);
59 
60  data.erase(data.begin(), data.end());
61  data = { m_catalogue->var(Var::_X_), m_catalogue->var(Var::_Y_), m_catalogue->var(Var::_Z_) };
62 
63  create_chain_mesh(data, rmax, rmin);
64 }
65 
66 
67 // ============================================================================
68 
69 
70 void cbl::chainmesh::ChainMesh_Catalogue::get_order (vector<int> &order) const
71 {
72  order.erase(order.begin(), order.end());
73  vector<long> Label_temp = m_Label;
74  vector<long> List_temp = m_List;
75 
76  for (int i=0; i<m_nCell_tot; i++) {
77  vector<int> vv;
78  int j = Label_temp[i];
79  while (j>-1) {
80  vv.push_back(j);
81  j = List_temp[j];
82  }
83 
84  reverse(vv.begin(), vv.end());
85 
86  for (size_t j=0; j<vv.size(); j++)
87  order.push_back(vv[j]);
88  }
89 }
90 
91 
92 // ============================================================================
93 
94 
95 vector<std::shared_ptr<Object> > cbl::chainmesh::ChainMesh_Catalogue::object_list (std::shared_ptr<Object> object, const int ii)
96 {
97  vector<shared_ptr<Object> > obj_list;
98 
99  vector<double> center = object->coords();
100  int center_indx = pos_to_index(center);
101 
102  for (size_t i=0; i<m_search_region.size(); i++) {
103  int k = min(max(m_search_region[i]+center_indx, (long)0), m_nCell_tot-1);
104  int j = m_Label[k];
105 
106  while (j>-1 && j>=ii) {
107  obj_list.push_back(m_catalogue->catalogue_object(j));
108  j = m_List[j];
109  }
110 
111  }
112 
113  return obj_list;
114 }
115 
Implementation of the chain-mesh data structure.
std::vector< std::shared_ptr< catalogue::Object > > object_list(std::shared_ptr< catalogue::Object > object, const int ii=-1)
get list of objects close to the input
void set_par(const double cell_size, std::shared_ptr< catalogue::Catalogue > cat, const double rmax, const double rmin=-1.)
function that set parameters for the chain-mesh
void get_order(std::vector< int > &order) const
order the catalogue according to the input vector
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38