RoundGrid.cpp
1 #include "RoundGrid.hpp"
2 #include "HilbertOrder.hpp"
3 
4 vector<Vector2D> RoundGrid(vector<Vector2D> const& points,
5  OuterBoundary const* bc,int NumberIt,
6  #ifdef RICH_MPI
7  Tessellation const* tproc,
8  #endif
9  Tessellation *tess)
10 {
11  vector<int> indeces = HilbertOrder(points, static_cast<int>(points.size()));
12  vector<Vector2D> res(points);
13  res = VectorValues(res, indeces);
14  VoronoiMesh default_tess;
15  if(tess==0)
16  tess=&default_tess;
17 #ifdef RICH_MPI
18  if(tproc==0)
19  tess->Initialise(points,bc);
20  else
21  tess->Initialise(points,*tproc,bc);
22 #else
23  tess->Initialise(points,bc);
24 #endif
25  double pi= 3.141592653;
26  double eta_=0.02,chi_=1;
27  int N=tess->GetPointNo();
28 
29  // Copy the points
30  for(int i=0;i<N;++i)
31  res[static_cast<size_t>(i)]=tess->GetMeshPoint(i);
32 
33  for(int j=0;j<NumberIt;++j)
34  {
35 #ifdef RICH_MPI
36  N=tess->GetPointNo();
37  res=tess->GetMeshPoints();
38  res.resize(static_cast<size_t>(N));
39 #endif
40  for(int i=0;i<N;++i)
41  {
42  double R = sqrt(tess->GetVolume(i)/pi);
43  Vector2D s = tess->GetCellCM(i);
44  Vector2D r = tess->GetMeshPoint(i);
45  double d = abs(s-r);
46  Vector2D dw;
47  if(d/eta_/R<0.95)
48  dw = 0*s;
49  else
50  dw = chi_*0.5*(s-r);
51  res[static_cast<size_t>(i)]=tess->GetMeshPoint(i)+dw;
52  }
53 #ifdef RICH_MPI
54  if(tproc==0)
55  tess->Update(res);
56  else
57  tess->Update(res,*tproc);
58 #else
59  tess->Update(res);
60 #endif
61  }
62 #ifdef RICH_MPI
63  N=tess->GetPointNo();
64  res=tess->GetMeshPoints();
65  res.resize(static_cast<size_t>(N));
66 #endif
67  return res;
68 }
Voronoi tessellation class.
Definition: VoronoiMesh.hpp:29
vector< T > VectorValues(vector< T > const &v, vector< int > const &index)
Returns only the values with indeces in index.
Definition: utils.hpp:326
Abstract class for tessellation.
Makes the initial cells rounder.
vector< Vector2D > RoundGrid(vector< Vector2D > const &points, OuterBoundary const *bc, int NumberIt=10, Tessellation const *tproc=0, Tessellation *tess=0)
Makes the cells rounder.
Definition: RoundGrid.cpp:4
Hilbert space filling curve.
void Initialise(vector< Vector2D > const &points, Tessellation const &vproc, OuterBoundary const *outer, bool reorder=true)
Initialise the tessellation.
vector< int > HilbertOrder(vector< Vector2D > const &cor, int num, int innernum=0)
Returns the Hilber curve ordering.
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
Abstract class for geometric boundary conditions for the tessellation.
2D Mathematical vector
Definition: geometry.hpp:15