3 #include "../misc/serializable.hpp" 11 outer_(outer), speed_(speed), RoundSpeed_(RoundSpeed),
12 mode_(mode), Rmin_(Rmin) {}
19 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
20 vector<double> R(static_cast<size_t>(nproc));
23 for (
size_t i = 0; i < static_cast<size_t>(nproc); ++i)
24 R[i] = tproc.
GetWidth(static_cast<int>(i));
29 double dxround = 0, dyround = 0;
30 if (d > 0.1*R[static_cast<size_t>(rank)])
32 dxround = RoundSpeed_*speed_*(CM.
x - point.
x);
33 dyround = RoundSpeed_*speed_*(CM.
y - point.
y);
37 vector<int> NPerProc(static_cast<size_t>(nproc));
39 MPI_Gather(&mypointnumber, 1, MPI_INT, &NPerProc[0], 1, MPI_INT, 0, MPI_COMM_WORLD);
40 MPI_Bcast(&NPerProc[0], nproc, MPI_INT, 0, MPI_COMM_WORLD);
42 for (
size_t i = 0; i < static_cast<size_t>(nproc); ++i)
43 IdealPerProc += NPerProc[i];
44 IdealPerProc /= nproc;
46 if (mode_ == 1 || mode_ == 3)
48 for (
size_t i = 0; i < static_cast<size_t>(nproc); ++i)
50 if (i == static_cast<size_t>(rank))
53 double dist = sqrt((point.x - otherpoint.
x)*(point.x - otherpoint.
x) +
54 (point.y - otherpoint.
y)*(point.y - otherpoint.
y) + 0.5*R[static_cast<size_t>(rank)] * R[i]);
55 double temp = (NPerProc[i] -IdealPerProc)*R[static_cast<size_t>(rank)] * R[i]*
56 (point.x - otherpoint.
x) / (pow(dist, 3)*IdealPerProc);
58 temp = (NPerProc[i] - IdealPerProc)*R[static_cast<size_t>(rank)] * R[i]*
59 (point.y - otherpoint.
y) / (pow(dist, 3)*IdealPerProc);
68 if (mode_ == 1 || mode_ == 2)
70 const double neigheps = 0.2;
72 for (
size_t i = 0; i < neigh.size(); ++i)
80 if (dist < neigheps*
std::min(R[static_cast<size_t>(rank)], R[static_cast<size_t>(neigh[i])]))
82 dx += neigheps*(point.x - tproc.
GetMeshPoint(neigh[i]).
x)*
std::min(R[static_cast<size_t>(rank)], R[
static_cast<size_t>(neigh[i])]) / dist;
83 dy += neigheps*(point.y - tproc.
GetMeshPoint(neigh[i]).
y)*
std::min(R[static_cast<size_t>(rank)], R[
static_cast<size_t>(neigh[i])]) / dist;
87 dx -= (NPerProc[
static_cast<size_t>(rank)] - NPerProc[static_cast<size_t>(neigh[i])])*(otherpoint.
x - point.x)*R[
static_cast<size_t>(rank)] / (IdealPerProc*dist);
88 dy -= (NPerProc[
static_cast<size_t>(rank)] - NPerProc[static_cast<size_t>(neigh[i])])*(otherpoint.
y - point.y)*R[
static_cast<size_t>(rank)] / (IdealPerProc*dist);
92 const double FarFraction = 0.65;
93 old_dx = (old_dx>0) ?
std::min(old_dx, FarFraction*speed_*R[static_cast<size_t>(rank)]) : -
std::min(-old_dx, FarFraction*speed_*R[static_cast<size_t>(rank)]);
94 old_dy = (old_dy > 0) ?
std::min(old_dy, FarFraction*speed_*R[static_cast<size_t>(rank)]) : -
std::min(-old_dy, FarFraction*speed_*R[static_cast<size_t>(rank)]);
95 dx = (dx > 0) ?
std::min(dx, speed_*R[static_cast<size_t>(rank)]) : -
std::min(-dx, speed_*R[static_cast<size_t>(rank)]);
96 dy = (dy > 0) ?
std::min(dy, speed_*R[static_cast<size_t>(rank)]) : -
std::min(-dy, speed_*R[static_cast<size_t>(rank)]);
106 const double close = 0.999;
107 const double wx = tproc.
GetWidth(rank);
108 const double wy = wx;
113 dx = -wx*(1 - close);
125 dy = -wy*(1 - close);
141 for (
size_t i = 0; i < Norglocal; ++i)
143 MPI_Allreduce(MPI_IN_PLACE, &Rmin_1, 1, MPI_DOUBLE, MPI_MAX, MPI_COMM_WORLD);
144 if (
abs(cor) * Rmin_1 < 1.05)
145 cor = cor * 1.01 / (Rmin_1 *
abs(cor));
148 vector<double> tosend = list_serialize(vector<Vector2D>(1, cor));
149 vector<double> torecv(static_cast<size_t>(nproc) * 2);
150 MPI_Gather(&tosend[0], 2, MPI_DOUBLE, &torecv[0], 2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
151 MPI_Bcast(&torecv[0], nproc * 2, MPI_DOUBLE, 0, MPI_COMM_WORLD);
152 vector<Vector2D> cortemp = list_unserialize(torecv, cor);
double distance(Vector2D const &v1) const
Caluclates the distance from the Vector to v1.
virtual vector< int > Update(const vector< Vector2D > &points, bool HilbertOrder=false)=0
Update the tessellation.
Abstract class for tessellation.
virtual int GetPointNo(void) const =0
Get Total number of mesh generating points.
virtual Vector2D const & GetCellCM(int index) const =0
Returns Position of Cell's CM.
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 class that tries to maintain a constant number of points per processor by solving eq 68 in AREPO's ...
~ConstNumberPerProc(void)
Class destructor.
virtual double GetWidth(int index) const =0
Returns the effective width of a cell.
void Update(Tessellation &tproc, Tessellation const &tlocal) const
Updates the load balance, does one iteration.
double min(vector< double > const &v)
Returns the minimal term in a vector.
ConstNumberPerProc(OuterBoundary const &outer, double speed=0.03, double RoundSpeed=2, int mode=2, bool Rmin=false)
Class constructor.
double abs(Vector3D const &v)
Norm of a vector.
Abstract class for geometric boundary conditions for the tessellation.
virtual vector< int > GetNeighbors(int index) const =0
Returns the indeces of the neighbors.
virtual double GetGridBoundary(Directions dir) const =0
Returns the boundary coordinate.
double x
Component in the x direction.