CosmoBolognaLib
Free Software C++/Python libraries for cosmological calculations
ChainMesh.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.h"
35 
36 
37 using namespace std;
38 
39 using namespace cbl;
40 
41 
42 // ============================================================================
43 
44 
45 void cbl::chainmesh::ChainMesh::set_par (const double cell_size, const long nDim)
46 {
47  m_nDim = nDim;
48  m_cell_size = cell_size;
49 
50  if (m_cell_size<=0)
51  ErrorCBL("forbidden value for cell_size = "+conv(cell_size, par::fDP2), "set_par", "ChainMesh.cpp");
52 
53  m_Lim.resize(m_nDim, vector<double> (2,0));
54  m_Delta.resize(m_nDim);
55  m_nCell.resize(m_nDim);
56  m_cell_to_index.resize(m_nDim);
57  m_nCell_tot = 1;
58 }
59 
60 
61 // ============================================================================
62 
63 
64 cbl::chainmesh::ChainMesh::ChainMesh (const double cell_size, const long nDim) : m_nDim(nDim), m_cell_size(cell_size)
65 {
66  set_par(cell_size, nDim);
67 }
68 
69 
70 // ============================================================================
71 
72 
73 long cbl::chainmesh::ChainMesh::pos_to_index (const vector<double> center) const
74 {
75  vector<long> indx(m_nDim);
76 
77  for (long j=0; j<m_nDim; j++)
78  indx[j] = min(long((center[j]-m_Lim[j][0])/m_cell_size), m_nCell[j]-1);
79 
80  long indx_tot = indx[m_nDim-1];
81 
82  for (long j=m_nDim-2; j>-1; j--) {
83  long mult = 1;
84  for (long k=j+1; k<m_nDim; k++) mult *= m_nCell[k];
85  indx_tot += mult*indx[j];
86  }
87 
88  return indx_tot;
89 }
90 
91 
92 // ============================================================================
93 
94 
95 long cbl::chainmesh::ChainMesh::inds_to_index (const vector<long> indx) const
96 {
97  long indx_tot = indx[m_nDim-1];
98 
99  for (int j=m_nDim-2; j>-1; j--) {
100  long mult = 1;
101  for (int k=j+1; k<m_nDim; k++) mult *= m_nCell[k];
102  indx_tot += mult*indx[j];
103  }
104 
105  return indx_tot;
106 }
107 
108 
109 // ============================================================================
110 
111 
112 void cbl::chainmesh::ChainMesh::index_to_inds (const long index, const vector<long> nn, vector<long> &indx) const
113 {
114  indx.resize(m_nDim, 0);
115  long mult = 1;
116  long sum = 0;
117  for (int i=1; i<m_nDim; i++) mult *= nn[i];
118  indx[0] = floor((index-sum)/mult);
119  sum = indx[0]*mult;
120 
121  for (int i=1; i<m_nDim; i++) {
122  mult = 1;
123  for (int k=i+1; k<m_nDim; k++) mult *= nn[k];
124  indx[i] = floor((index-sum)/mult);
125  sum += indx[i]*mult;
126  }
127 }
128 
129 
130 // ============================================================================
131 
132 
133 void cbl::chainmesh::ChainMesh::create_chain_mesh (const vector<vector<double> > data, const double rMAX, const double rMIN, const long nMAX, const long nMIN)
134 {
135  // setting stuff, generalized for n(=nDim) dimensions
136 
137  m_rMAX = rMAX;
138  m_rMIN = rMIN;
139 
140  long nObj = data[0].size();
141  m_List.erase(m_List.begin(), m_List.end()); m_List.resize(nObj, -1);
142  m_NonEmpty_Cells.erase(m_NonEmpty_Cells.begin(), m_NonEmpty_Cells.end());
143 
144  m_nCell_tot = pow(nMAX,3)+1;
145  m_nCell_NonEmpty = 0;
146  m_multCell.erase(m_multCell.begin(), m_multCell.end()); m_multCell.resize(m_nDim, 1);
147 
148  double fact = 1.;
149 
150  check_memory(3.0, true, "cbl::chainmesh::ChainMesh::create_chain_mesh of ChainMesh.cpp");
151 
152  while (m_nCell_tot>pow(nMAX, 3) || m_nCell_tot<nMIN
153  || !check_memory(3.0, false, "cbl::chainmesh::ChainMesh::create_chain_mesh of ChainMesh.cpp")) {
154 
155  m_nCell_tot = 1;
156  m_cell_size *= fact;
157  for (int i=0; i<m_nDim; i++) {
158  m_Lim[i][0] = Min(data[i])-1.05*rMAX;
159  m_Lim[i][1] = Max(data[i])+1.05*rMAX;
160  m_Delta[i] = m_Lim[i][1]-m_Lim[i][0];
161  m_nCell[i] = nint(m_Delta[i]/m_cell_size);
162  m_nCell_tot *= m_nCell[i];
163  m_cell_to_index[i] = m_Delta[i]/m_nCell[i];
164  }
165  for (int i=1; i<m_nDim; i++)
166  m_multCell[m_nDim-1-i] = m_nCell[m_nDim-i]*m_multCell[i-1];
167 
168  fact *= 1.1;
169 
170  m_Label.erase(m_Label.begin(), m_Label.end());
171 
172  }
173 
174  m_Label.resize(m_nCell_tot, -1);
175 
176  for (long i=0; i<nObj; i++) {
177  vector<double> center(m_nDim);
178  for (int j=0; j<m_nDim; j++)
179  center[j] = data[j][i];
180  long indx_tot = pos_to_index(center);
181  m_NonEmpty_Cells.push_back(indx_tot);
182  m_List[i] = m_Label[indx_tot];
183  m_Label[indx_tot] = i;
184  }
185 
186  get_searching_region(rMAX, rMIN);
187  m_NonEmpty_Cells = different_elements (m_NonEmpty_Cells);
188  m_nCell_NonEmpty = (long)m_NonEmpty_Cells.size();
189 
190 }
191 
192 
193 // ============================================================================
194 
195 
196 void cbl::chainmesh::ChainMesh::create_chain_mesh_m2 (const vector<vector<double> > data)
197 {
198  // setting stuff, generalized for n(=nDim) dimensions
199  long nObj = data[0].size();
200 
201  for (int i=0; i<m_nDim; i++) {
202  m_Lim[i][0] = Min(data[i]); m_Lim[i][1] = Max(data[i]);
203  m_Delta[i] = m_Lim[i][1]-m_Lim[i][0];
204  m_nCell[i] = nint(m_Delta[i]/m_cell_size);
205  m_nCell_tot *= m_nCell[i];
206  }
207 
208  m_List_index.erase(m_List_index.begin(),m_List_index.end()); m_List_index.resize(m_nCell_tot);
209  m_NonEmpty_Cells.erase(m_NonEmpty_Cells.begin(), m_NonEmpty_Cells.end());
210  m_nCell_NonEmpty = 0;
211 
212  for (long i=0; i<nObj; i++) {
213  long indx_tot = pos_to_index(data[i]);
214  m_NonEmpty_Cells.push_back(indx_tot);
215  m_List_index[indx_tot].push_back(i);
216  }
217 
218  m_NonEmpty_Cells = different_elements (m_NonEmpty_Cells);
219  m_nCell_NonEmpty = (long)m_NonEmpty_Cells.size();
220 }
221 
222 
223 // ============================================================================
224 
225 
226 void cbl::chainmesh::ChainMesh::get_searching_region (const double r_max, const double r_min)
227 {
228 
229  int n_max = nint(r_max/m_cell_size);
230  n_max = (n_max*m_cell_size<r_max) ? n_max+1 : n_max;
231 
232  int n_min = nint(r_min/m_cell_size)-2; // exclusive
233  vector<long> n_incl(m_nDim);
234 
235  for (int i=0; i<m_nDim; i++)
236  n_incl[i] = 2*n_max+1;
237 
238  long sz_region = pow(2*n_max+1, m_nDim);
239 
240  m_search_region.erase(m_search_region.begin(),m_search_region.end());
241  m_search_region.resize(sz_region,0);
242 
243  for (long i=0; i<sz_region; i++) {
244  vector<long> indx(m_nDim);
245  index_to_inds(i,n_incl,indx);
246  for (int i=0; i<m_nDim; i++) indx[i]-=n_max;
247  m_search_region[i] = inds_to_index(indx);
248  }
249 
250  if (r_min>0 && n_min>0) {
251  vector<long> n_excl(m_nDim);
252  for (int i=0; i<m_nDim; i++)
253  n_excl[i] = 2*n_min+1;
254 
255  long sz_excl_region = pow(2*n_min+1,m_nDim);
256 
257  for (long i=0; i<sz_excl_region; i++) {
258  vector<long> indx(m_nDim);
259  index_to_inds(i, n_excl, indx);
260  for (int i=0; i<m_nDim; i++) indx[i] -= n_min;
261  long veto = inds_to_index(indx);
262  m_search_region.erase(remove(m_search_region.begin(), m_search_region.end(), veto), m_search_region.end());
263  }
264  }
265 }
266 
267 
268 // ============================================================================
269 
270 
271 vector<long> cbl::chainmesh::ChainMesh::close_objects_cell (const int cell_index, const long ii) const
272 {
273  // r2 != -1 ---> search in a nDim annulus from r1 to r2
274  // r2 == -1 ---> search in a nDim sphere from center to r1
275 
276  vector<long> list;
277 
278  for (size_t i=0; i<m_search_region.size(); i++) {
279 
280  long k = min(max(m_search_region[i]+cell_index, (long)0), m_nCell_tot-1);
281 
282  if (k!=ii) {
283  long j = m_Label[k];
284  while (j>-1) {
285  list.push_back(j);
286  j = m_List[j];
287  }
288  }
289  }
290 
291  return list;
292 }
293 
294 
295 // ============================================================================
296 
297 
298 vector<long> cbl::chainmesh::ChainMesh::close_objects (const vector<double> center, const long ii) const
299 {
300  vector<long> list;
301 
302  if (long(center.size())!=m_nDim) ErrorCBL("point must have same dimensions of the chain-mesh", "close_objects", "ChainMesh.cpp");
303 
304  long center_indx = pos_to_index(center);
305 
306  for (unsigned long i=0; i<m_search_region.size(); i++) {
307 
308  long k = min(max(m_search_region[i]+center_indx, (long)0), m_nCell_tot-1);
309  long j = m_Label[k];
310 
311  // NEW PART -> consider only the cells inside the searching radius (+ those intersected)
312  if (m_cell_size>=m_rMAX/m_nDim) {
313  vector<int> indx(m_nDim, 0);
314 
315  for (int ii=0; ii<m_nDim; ii++) {
316  indx[ii] = floor(k/m_multCell[ii]);
317  k -= m_multCell[ii]*indx[ii];
318  }
319 
320  double dist = 0.;
321  for (int ii=0; ii<m_nDim; ii++)
322  dist += ((indx[ii]+0.5)*m_cell_size-center[ii]+m_Lim[ii][0])*((indx[ii]+0.5)*m_cell_size-center[ii]+m_Lim[ii][0]);
323 
324  dist = sqrt(dist);
325 
326  double half_diag = m_cell_size*0.5*sqrt(m_nDim);
327  double max_radius = m_rMAX+half_diag;
328  double min_radius = (m_rMIN>0.) ? m_rMIN-half_diag : 0.;
329 
330  if (dist<max_radius && dist>min_radius)
331  while (j>-1 && j>ii) {
332  list.push_back(j);
333  j = m_List[j];
334  }
335  }
336  else
337  while (j>-1 && j>ii) {
338  list.push_back(j);
339  j = m_List[j];
340  }
341  }
342 
343  return list;
344 }
345 
346 // ============================================================================
347 
348 
349 void cbl::chainmesh::ChainMesh::normalize (std::vector<std::vector<double>> points, std::vector<double> values, const double rMAX)
350 {
351  if (points[0].size()!=values.size()) ErrorCBL("the size of points is different from the size of values", "norm_grid", "ChainMesh.cpp");
352 
353  const int nparams = points.size();
354 
355  m_values = values;
356  m_rMAX = rMAX;
357 
358  std::vector<std::vector<double>> extremals(2, std::vector<double> (nparams, 0));
359  std::vector<double> delta (nparams, 0.);
360 
361  for(int N=0; N<nparams; N++) {
362  extremals[0][N] = cbl::Max(points[N]);
363  extremals[1][N] = cbl::Min(points[N]);
364  }
365 
366  for(int N=0; N<nparams; N++) {
367  delta[N] = extremals[0][N]-extremals[1][N];
368  if (delta[N]==0) ErrorCBL("the grid cannot be normalised", "norm_grid", "ChainMesh.cpp");
369  for(size_t ii=0; ii<points[0].size(); ii++){
370  points[N][ii] = 100. - (200./(delta[N]))*(extremals[0][N] - points[N][ii]);
371  }
372  }
373 
374  m_points = points;
375  m_delta = delta;
376  m_extremals = extremals;
377 
378  long nMAX = floor(200/m_cell_size)+10*rMAX;
379 
380  create_chain_mesh(m_points, m_rMAX, -1., nMAX, 0);
381 }
382 
383 
384 // ============================================================================
385 
386 
387 double cbl::chainmesh::ChainMesh::interpolate (std::vector<double> xi, const int distNum)
388 {
389  if (m_points.size() != xi.size()) ErrorCBL("the dimension of points is different from the dimension of xi", "interp_coord", "ChainMesh.cpp");
390  if (m_delta.size()==0.) ErrorCBL("the chain mesh grid is not normalised!", "interp_coord", "ChainMesh.cpp");
391 
392  const int nparams = m_points.size();
393 
394  // stretch the interpolation sample
395  for (int N=0; N<nparams; N++)
396  xi[N] = 100. - (200./(m_delta[N]))*(m_extremals[0][N] - xi[N]);
397 
398  double interp_value = cbl::Min(m_values);
399  std::vector<long> close;
400  std::vector<double> distances;
401  std::vector<double> indices;
402  double dist, sum = 0.;
403  double sum_distances = 0.;
404  int npoints = 0;
405 
406  close = close_objects(xi);
407 
408  if (close.size()>0) {
409  for (auto&&k : close) {
410  dist = 0.;
411  for(int N=0; N<nparams; N++)
412  dist += pow((xi[N]-m_points[N][k]), 2);
413  dist = sqrt(dist);
414  distances.push_back(dist);
415  indices.push_back(k);
416  }
417 
418  cbl::sort_2vectors(distances.begin(), indices.begin(), distances.size());
419 
420  for (auto&&k : indices) {
421  if (distances[npoints]>0.) {
422  sum += m_values[k]/distances[npoints];
423  sum_distances += 1./distances[npoints];
424  npoints++;
425  }
426  if (npoints>distNum) break;
427  }
428 
429  interp_value = sum/sum_distances;
430  }
431 
432  distances.clear();
433  indices.clear();
434 
435  return interp_value;
436 }
437 
438 
439 // ============================================================================
440 
441 
442 vector<double> cbl::chainmesh::ChainMesh::interpolate (std::vector<std::vector<double>> points, std::vector<double> values, std::vector<std::vector<double>> xi, const int distNum, const double rMAX)
443 {
444  if (points.size() != xi.size()) ErrorCBL("the dimension of points is different from the dimension of xi", "interpolate", "ChainMesh.cpp");
445  if (points[0].size() != values.size()) ErrorCBL("the size of points is different from the size of values", "interpolate", "ChainMesh.cpp");
446 
447  const int nparams = points.size();
448  const int points_values = points[0].size();
449  const int xi_values = xi[0].size();
450  std::vector<std::vector<double>> unique_vect(nparams, std::vector<double> (points_values+xi_values, 0));
451 
452  std::vector<std::vector<double>> extremals(2, std::vector<double> (nparams, 0));
453  double delta = 0.;
454  for (int N=0; N<nparams; N++) {
455  extremals[0][N] = std::max(cbl::Max(points[N]), cbl::Max(xi[N]));
456  extremals[1][N] = std::min(cbl::Min(points[N]), cbl::Min(xi[N]));
457  }
458 
459  for (int N=0; N<nparams; N++){
460  delta = extremals[0][N]-extremals[1][N];
461 
462  for (int ii=0; ii<xi_values; ii++) {
463  xi[N][ii] = 100. - (200./(delta))*(extremals[0][N] - xi[N][ii]);
464  unique_vect[N][ii] = xi[N][ii];
465  }
466 
467  for (int ii=0; ii<points_values; ii++) {
468  points[N][ii] = 100. - (200./(delta))*(extremals[0][N] - points[N][ii]);
469  unique_vect[N][xi_values+ii] = points[N][ii];
470  }
471 
472  }
473 
474  long nMAX = floor(200/m_cell_size)+10*rMAX;
475 
476  std::vector<double> interp_values(xi_values, cbl::Min(values));
477 
478  create_chain_mesh(unique_vect, rMAX, -1., nMAX, 0);
479 
480 #pragma omp parallel num_threads(omp_get_max_threads())
481  {
482  std::vector<double> center(nparams);
483  std::vector<long> close;
484  std::vector<double> distances;
485  std::vector<double> indices;
486  double dist, sum_posterior = 0.;
487  int npoints = 0;
488 
489 #pragma omp for schedule(dynamic)
490  for (int ii=0; ii<xi_values; ii++) {
491  sum_posterior = 0.;
492  npoints = 0;
493  for (int N=0; N<nparams; N++) center[N] = xi[N][ii];
494  close = close_objects(center, xi_values);
495  if (close.size()>0) {
496  for (auto&&k : close) {
497  dist = 0.;
498  for (int N=0; N<nparams; N++) dist += pow((center[N]-unique_vect[N][k]), 2);
499  dist = sqrt(dist);
500  distances.push_back(dist);
501  indices.push_back(k-xi_values);
502  }
503 
504  cbl::sort_2vectors(distances.begin(), indices.begin(), distances.size());
505 
506  for (auto&&k : indices) {
507  sum_posterior += values[k];
508  npoints++;
509  if (npoints>distNum) break;
510  }
511  interp_values[ii] = sum_posterior/npoints;
512  }
513 
514  distances.clear();
515  indices.clear();
516  }
517  }
518 
519  return interp_values;
520 }
521 
522 
523 // ============================================================================
524 
525 
526 vector<long> cbl::chainmesh::ChainMesh::get_list (const long cell_index) const
527 {
528  vector<long> list;
529  long j = m_Label[cell_index];
530 
531  while (j>-1) {
532  list.push_back(j);
533  j = m_List[j];
534  }
535 
536  return list;
537 }
538 
539 
540 // ============================================================================
541 
542 
543 void cbl::chainmesh::ChainMesh1D::set_par (const double cell_size, const vector<double> xx, const double rMAX, const double rMIN, const long nMAX, const long nMIN)
544 {
545  ChainMesh::set_par(cell_size, 1);
546 
547  vector<vector<double>> data;
548  data.push_back(xx);
549  create_chain_mesh(data, rMAX, rMIN, nMAX, nMIN);
550 }
551 
552 
553 // ============================================================================
554 
555 
556 cbl::chainmesh::ChainMesh1D::ChainMesh1D (const double cell_size, const std::vector<double> xx, const double rMAX, const double rMIN, const long nMAX, const long nMIN) : ChainMesh(cell_size,1)
557 {
558  set_par(cell_size, xx, rMAX, rMIN, nMAX, nMIN);
559 }
560 
561 
562 // ============================================================================
563 
564 
565 void cbl::chainmesh::ChainMesh2D::set_par (const double cell_size, const std::vector<double> xx, const std::vector<double> yy, const double rMAX, const double rMIN, const long nMAX, const long nMIN)
566 {
567  ChainMesh::set_par(cell_size, 2);
568 
569  vector<vector<double>> data;
570  data.push_back(xx);
571  data.push_back(yy);
572  create_chain_mesh(data, rMAX, rMIN, nMAX, nMIN);
573 }
574 
575 
576 // ============================================================================
577 
578 
579 cbl::chainmesh::ChainMesh2D::ChainMesh2D (const double cell_size, const std::vector<double> xx, const std::vector<double> yy, const double rMAX, const double rMIN, const long nMAX, const long nMIN) : ChainMesh(cell_size,2)
580 {
581  set_par(cell_size, xx, yy, rMAX, rMIN, nMAX, nMIN);
582 }
583 
584 
585 // ============================================================================
586 
587 
588 void cbl::chainmesh::ChainMesh3D::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, const long nMAX, const long nMIN)
589 {
590  ChainMesh::set_par(cell_size, 3);
591  vector<vector<double>> data;
592  data.push_back(xx);
593  data.push_back(yy);
594  data.push_back(zz);
595  create_chain_mesh(data, rMAX, rMIN, nMAX, nMIN);
596 }
597 
598 
599 // ============================================================================
600 
601 
602 cbl::chainmesh::ChainMesh3D::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, const long nMAX, const long nMIN) : ChainMesh(cell_size, 3)
603 {
604  set_par(cell_size, xx, yy, zz, rMAX, rMIN, nMAX, nMIN);
605 }
Implementation of the chain-mesh data structure.
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
ChainMesh2D()=default
default constructor 1D
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
ChainMesh3D()=default
default constructor
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< 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
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
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
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
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
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
std::vector< long > get_list(const long cell_index) const
get the index of the object inside a cell
Definition: ChainMesh.cpp:526
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 inds_to_index(const std::vector< long > indx) const
get the unique index of the cell given the n indices
Definition: ChainMesh.cpp:95
static const char fDP2[]
conversion symbol for: double -> std::string
Definition: Constants.h:133
The global namespace of the CosmoBolognaLib
Definition: CAMB.h:38
T Min(const std::vector< T > vect)
minimum element of a std::vector
Definition: Kernel.h:1324
std::string conv(const T val, const char *fact)
convert a number to a std::string
Definition: Kernel.h:903
std::vector< T > different_elements(const std::vector< T > vect_input)
get the unique elements of a std::vector
Definition: Kernel.h:1349
int ErrorCBL(const std::string msg, const std::string functionCBL, const std::string fileCBL, const cbl::glob::ExitCode exitCode=cbl::glob::ExitCode::_error_)
throw an exception: it is used for handling exceptions inside the CosmoBolognaLib
Definition: Kernel.h:780
T Max(const std::vector< T > vect)
maximum element of a std::vector
Definition: Kernel.h:1336
int nint(const T val)
the nearest integer
Definition: Kernel.h:915
void sort_2vectors(std::vector< double >::iterator p1, std::vector< double >::iterator p2, const int dim)
sort the elements of a std::vectors, and the elements of a second std::vector according to the first ...
Definition: Kernel.cpp:323
int check_memory(const double frac, const bool exit=true, const std::string func="", const int type=1)
check if the memory used by current process is larger than a given fraction of the available memory
Definition: Kernel.cpp:252