2 #include "../misc/mesh_generator.hpp" 5 typedef boost::mt19937_64 gen_type;
10 boost::array<double,4> FindMaxEdges(
Tessellation const& tess)
13 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
15 const int n=
static_cast<int>(edge_index.size());
16 boost::array<double,4> res;
25 for(
size_t i=1;i<static_cast<size_t>(n);++i)
40 boost::array<double,4> GetBindingArc(vector<Vector2D>
const& cpoints,
46 double mincellR=
abs(cpoints[0]-center);
47 double maxcellR(mincellR);
49 int npoints=
static_cast<int>(cpoints.size());
50 for(
size_t i=1;i<static_cast<size_t>(npoints);++i)
52 double temp=
abs(cpoints[i]-center);
53 maxcellR=
max(maxcellR,temp);
55 etemp.
vertices.second=cpoints[(i+1)%static_cast<size_t>(npoints)];
59 double maxangle,minangle;
68 const Vector2D tocenter=procpoint-center;
69 const double Rcenter=
abs(tocenter);
70 boost::array<Vector2D,3> tocheck;
73 double minusval=0,plusval=0;
74 int minusloc=0,plusloc=0;
75 for(
size_t i=0;i<static_cast<size_t>(npoints);++i)
77 tocheck[2]=cpoints[i];
78 const Vector2D tocpoint=cpoints[i]-center;
79 const double angle=acos(
ScalarProd(tocenter,tocpoint)/(
abs(tocpoint)*Rcenter));
86 plusloc=
static_cast<int>(i);
94 minusloc=
static_cast<int>(i);
99 minangle=atan2(cpoints[static_cast<size_t>(minusloc)].y-center.y,cpoints[static_cast<size_t>(minusloc)].x-center.x);
100 minangle=(minangle<0) ? (minangle+2*M_PI) : minangle;
101 maxangle=atan2(cpoints[static_cast<size_t>(plusloc)].y-center.y,cpoints[static_cast<size_t>(plusloc)].x-center.x);
102 maxangle=(maxangle<0) ? (maxangle+2*M_PI) : maxangle;
103 if(maxangle<minangle)
106 boost::array<double,4> res;
118 boost::array<double,4> tessEdges=FindMaxEdges(tess);
119 if (tessEdges[0]>upperright.
x || tessEdges[1]<lowerleft.
x || tessEdges[2]>upperright.
y ||
120 tessEdges[3] < lowerleft.
y)
121 return vector<Vector2D>();
123 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
124 const double myarea = tess.
GetVolume(rank);
125 const double Area = (upperright.
x - lowerleft.
x)*(upperright.
y - lowerleft.
y);
126 int mypoints=
static_cast<int>(floor(npoints*myarea/Area+0.5));
127 vector<Vector2D> res;
128 res.reserve(static_cast<size_t>(mypoints));
129 vector<std::pair<Vector2D, Vector2D> > cpoints;
132 gen_type gen(static_cast<size_t>(rank));
133 boost::random::uniform_real_distribution<> dist;
135 while(static_cast<int>(res.size())<mypoints)
137 ran[0]=dist(gen)*(tessEdges[1]-tessEdges[0])+tessEdges[0];
138 ran[1]=dist(gen)*(tessEdges[3]-tessEdges[2])+tessEdges[2];
149 const double widthx = (upperright.
x-lowerleft.
x)/static_cast<double>(nx);
150 const double widthy = (upperright.
y-lowerleft.
y)/static_cast<double>(ny);
151 const boost::array<double,4> tessEdges=FindMaxEdges(tess);
152 nx=
static_cast<int>(floor((tessEdges[1]-tessEdges[0])/widthx+2));
153 ny=
static_cast<int>(floor((tessEdges[3]-tessEdges[2])/widthy+2));
154 vector<Vector2D> res;
155 res.reserve(static_cast<size_t>(nx*ny));
156 const int nx0=
static_cast<int>(floor((tessEdges[0]-lowerleft.
x)/widthx-0.5));
157 const int ny0=
static_cast<int>(floor((tessEdges[2]-lowerleft.
y)/widthy-0.5));
160 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
161 vector< std::pair<Vector2D, Vector2D> > cpoints;
163 for(
int i=0;i<nx;i++)
165 for(
int j=0;j<ny;j++)
167 point.
x = (
static_cast<double>(i)+0.5+nx0)*widthx+lowerleft.
x;
168 point.
y = (
static_cast<double>(j)+0.5+ny0)*widthy+lowerleft.
y;
169 if((point.
x<lowerleft.
x)||(point.
x>upperright.
x)||
170 (point.
y<lowerleft.
y)||(point.
y>upperright.
y))
173 res.push_back(point);
184 double A=sqrt(M_PI*(Rmax*Rmax-Rmin*Rmin)/PointNum);
185 int Nr=int((Rmax-Rmin)/A);
186 double dr=(Rmax-Rmin)/Nr;
188 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
189 vector< std::pair < Vector2D, Vector2D> >cpoints;
190 vector<Vector2D> cpoints2;
193 boost::array<double,4> arc=GetBindingArc(cpoints2,
Vector2D(xc,yc),
195 double mincellR=
max(
min(arc[0],Rmax),Rmin);
196 double maxcellR=
max(
min(arc[1],Rmax),Rmin);
197 double minangle=arc[2];
198 double maxangle=arc[3];
199 int nrmin=
static_cast<int>((mincellR-Rmin)/dr);
200 int nrmax=
static_cast<int>((maxcellR-Rmin)/dr+0.5);
201 vector<Vector2D> res;
202 for(
int i=nrmin;i<nrmax;++i)
206 int phimin=
static_cast<int>(minangle/dphi);
207 int phimax=
static_cast<int>(maxangle/dphi+0.5);
208 for(
int j=phimin;j<phimax;++j)
219 double xc,
double yc,
double alpha,
Tessellation const& tess)
221 double N0=sqrt(PointNum*4*M_PI*(alpha+1)/(pow(Rmax,2*(alpha+1))-
222 pow(Rmin,2*(alpha+1))));
224 vector<Vector2D> res;
226 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
227 vector< std::pair < Vector2D, Vector2D> >cpoints;
228 vector<Vector2D> cpoints2;
231 boost::array<double, 4> arc = GetBindingArc(cpoints2,
Vector2D(xc, yc),
233 double mincellR=
max(
min(arc[0],Rmax),Rmin);
234 double maxcellR=
max(
min(arc[1],Rmax),Rmin);
235 double minangle=arc[2];
236 double maxangle=arc[3];
237 int nrmin=
static_cast<int>((pow(
max(mincellR,Rmin),alpha+1)-pow(Rmin,alpha+1))/(2*M_PI*(alpha+1)/N0));
238 int nrmax=
static_cast<int>((pow(
min(maxcellR,Rmax),alpha+1)-pow(Rmin,alpha+1))/(2*M_PI*(alpha+1)/N0)+0.5);
239 for(
int i=nrmin;i<nrmax;++i)
241 const double r=pow(2*M_PI*i*(alpha+1)/N0+pow(Rmin,alpha+1),1.0/(alpha+1));
242 const int Nphi=int(floor(N0*pow(r,1+alpha)+1.5));
243 const double dphi=2*M_PI/Nphi;
244 int phimin=
static_cast<int>(minangle/dphi);
245 int phimax=
static_cast<int>(maxangle/dphi+1);
246 for(
int j=phimin;j<phimax;++j)
248 pos.
Set(r*cos(dphi*j)+xc,r*sin(dphi*j)+yc);
259 vector<Vector2D> res;
261 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
262 vector<std::pair<Vector2D, Vector2D> > cpoints;
264 for(
int i=0;i<point_number;++i)
266 const double angle = 2*M_PI*double(i)/double(point_number);
Generates grids for parallel simulations.
vector< Vector2D > CirclePointsRmaxM(int PointNum, double Rmin, double Rmax, Vector2D const &bottomleft, Vector2D const &topright, Tessellation const &tess, double xc=0, double yc=0)
Generates a round grid with constant point density.
vector< Vector2D > SquareMeshM(int nx, int ny, Tessellation const &tess, Vector2D const &lower_left, Vector2D const &upper_right)
Creates a cartesian mesh for MPI.
Abstract class for tessellation.
bool PointInCell(vector< Vector2D > const &cpoints, Vector2D const &vec)
Checks if a point is inside a Voronoi cell.
vector< Vector2D > CirclePointsRmax_aM(int PointNum, double Rmin, double Rmax, double xc, double yc, double alpha, Tessellation const &tess)
Generates a round grid with r^alpha point density.
Interface between two cells.
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
double max(vector< double > const &v)
returns the maximal term in a vector
double y
Component in the y direction.
A collection of three identical references.
virtual Edge const & GetEdge(int index) const =0
Returns edge (interface between cells)
vector< Vector2D > circle_circumferenceM(int point_number, double radius, Vector2D const ¢er, Tessellation const &tproc)
Creates a circle of evenly spaced points.
void ConvexHull(vector< Vector2D > &result, Tessellation const &tess, int index)
Returns the ConvexHull for a set of points.
Vector2D pol2cart(double radius, double angle)
Converts from polar coordinates to cartesian coordinates.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
std::pair< Vector2D, Vector2D > vertices
Points at the ends of the edge.
double min(vector< double > const &v)
Returns the minimal term in a vector.
virtual double GetVolume(int index) const =0
Returns the volume of a cell.
void Set(double ix, double iy)
Set vector components.
std::vector< Vector2D > RandSquare(int PointNum, Vector2D const &lowerleft, Vector2D const &upperright)
Generates a random rectangular grid with uniform point density and a constant seed.
double DistanceToEdge(Vector2D const &point, Edge const &edge)
Calculates the distance of a point to an edge.
double abs(Vector3D const &v)
Norm of a vector.
virtual vector< int > const & GetCellEdges(int index) const =0
Returns the indexes of a cell's edges.
double orient2d(const TripleConstRef< Vector2D > &points)
Checks whether 3 given points are on a counterclockwise circle, clockwise circle or colinear...
double x
Component in the x direction.