2 #include "../../../tessellation/ConvexHull.hpp" 3 #include "../../../misc/simple_io.hpp" 4 #include "../../../tessellation/VoronoiMesh.hpp" 7 #include "../../../mpi/mpi_commands.hpp" 12 void ConvexIndeces(vector<Vector2D>
const& points,
Vector2D const& meshpoint,vector<size_t> &convex_index)
15 size_t n = points.size();
16 vector<double> angles(n);
17 for (
size_t i = 0; i<n; ++i)
18 angles.at(i) = atan2(points.at(i).y - meshpoint.
y, points.at(i).x - meshpoint.
x);
22 void GetConvexPoints(vector<Vector2D> &chull,
Vector2D meshpoint,
double R,
23 vector<Vector2D> &res)
26 res.resize(chull.size());
28 for (
size_t i = 0; i < res.size(); ++i)
30 Vector2D normal = chull[
static_cast<size_t>(i)] - meshpoint;
31 normal = normal /
abs(normal);
32 e1.
vertices.first = 0.5*(chull[
static_cast<size_t>(i)] + meshpoint);
35 normal = chull[
static_cast<size_t>((i+1)%res.size())] - meshpoint;
36 normal = normal /
abs(normal);
37 e2.
vertices.first = 0.5*(chull[
static_cast<size_t>((i + 1) % res.size())] + meshpoint);
47 for (
size_t j = 0; j < res.size(); ++j)
48 meshpoint += chull[j];
49 meshpoint *= (1.0/
static_cast<double>(res.size()));
50 vector<size_t> convex_indeces;
51 ConvexIndeces(chull, meshpoint, convex_indeces);
59 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
60 eo.AddEntry(
"Rank", rank);
62 eo.AddEntry(
"mesh.x", meshpoint.
x);
63 eo.AddEntry(
"mesh.y", meshpoint.
y);
65 for (
size_t k = 0; k < chull.size(); ++k)
67 eo.AddEntry(
"chull x", chull[k].x);
68 eo.AddEntry(
"chull y", chull[k].y);
70 eo.AddEntry(
"e1.vertices.first.x", e1.
vertices.first.x);
71 eo.AddEntry(
"e1.vertices.first.y", e1.
vertices.first.y);
72 eo.AddEntry(
"e1.vertices.second.x", e1.
vertices.second.x);
73 eo.AddEntry(
"e1.vertices.second.y", e1.
vertices.second.y);
74 eo.AddEntry(
"e2.vertices.first.x", e2.
vertices.first.x);
75 eo.AddEntry(
"e2.vertices.first.y", e2.
vertices.first.y);
76 eo.AddEntry(
"e2.vertices.second.x", e2.
vertices.second.x);
77 eo.AddEntry(
"e2.vertices.second.y", e2.
vertices.second.y);
88 for (
size_t i = 0; i < chull.size(); ++i)
92 res += (area_temp / 3.)*(meshpoint+chull[i]+ chull[(i + 1) % chull.size()]);
97 void GetOrgChullPoints(
Tessellation const& tess,vector<size_t>
const& indeces, vector<Vector2D> &res)
99 res.resize(indeces.size());
100 for (
size_t i = 0; i < indeces.size(); ++i)
101 res[i] = tess.
GetMeshPoint(static_cast<int>(indeces[i]));
104 void GetChullVelocity(
Tessellation const & tess, vector<Vector2D>
const& orgvel,
105 vector<size_t>
const& indeces,
111 ,vector<Vector2D> &res)
113 res.resize(indeces.size());
114 const size_t N =
static_cast<size_t>(tess.
GetPointNo());
115 for (
size_t i = 0; i < indeces.size(); ++i)
118 res[i] = orgvel[indeces[i]];
121 if (tess.
GetOriginalIndex(static_cast<int>(indeces[i]) == static_cast<int>(indeces[i])))
124 normal = normal /
abs(normal);
126 res[i] = vel - 2*normal*
ScalarProd(vel,normal);
130 res[i] = orgvel[indeces[i]];
132 res[i] = orgvel[
static_cast<size_t>(tess.
GetOriginalIndex(static_cast<int>(indeces[i])))];
142 Vector2D temp = cm - meshpoint - dt*w;
144 return (cm - meshpoint) / dt;
145 const double distance_reduce =
std::min(
abs(temp) / R,1.0);
146 const double toadd_velocity = reduce_factor*distance_reduce *
std::max(
abs(w),
148 return (w + temp*(toadd_velocity /
abs(temp)));
154 for (
size_t i = 0; i < toignore.size(); ++i)
169 for (
int i = 0; i < N; ++i)
178 void SlowNearBoundary(vector<Vector2D> &res, vector<int>
const&edges,
Tessellation const& tess,
double dt)
180 size_t N = edges.size();
184 for (
size_t i = 0; i < N; ++i)
190 vel_index =
static_cast<size_t>(edge.
neighbors.first);
195 vel_index =
static_cast<size_t>(edge.
neighbors.second);
198 double dx =
ScalarProd(n, res[vel_index] * dt) / l;
200 res[vel_index] += ((0.1*l- dx)/(dt*l))*n;
204 vector<Vector2D> GetCorrectedVelocities(
Tessellation const& tess,vector<Vector2D>
const& w,
double dt,
205 double reduce_factor,
size_t Niter,vector<ComputationalCell>
const& cells,
EquationOfState const& eos,
208 size_t N =
static_cast<size_t>(tess.
GetPointNo());
209 vector<Vector2D> res(N);
210 vector<Vector2D> cur_w(w);
211 vector<size_t> convex_index;
212 vector<vector<size_t> > neighbor_indeces(N);
213 vector<Vector2D> chull,chull2,hull_vel;
214 for (
size_t i = 0; i < N; ++i)
216 vector<int> neigh = tess.
GetNeighbors(static_cast<int>(i));
217 for (
size_t j = 0; j < neigh.size(); ++j)
218 neighbor_indeces[i].push_back(static_cast<size_t>(neigh[j]));
220 for (
size_t j = 0; j < Niter; ++j)
222 for (
size_t i = 0; i < N; ++i)
224 if (!ShouldCalc(toignore, cells[i],tracerstickernames))
226 GetOrgChullPoints(tess, neighbor_indeces[i],chull);
227 ConvexIndeces(chull, tess.
GetMeshPoint(static_cast<int>(i)), convex_index);
229 GetChullVelocity(tess, cur_w,
VectorValues(neighbor_indeces[i], convex_index)
230 , static_cast<int>(i), hull_vel);
231 chull = chull + dt*hull_vel;
232 GetConvexPoints(chull, tess.
GetMeshPoint(static_cast<int>(i)) + cur_w[i] * dt,
233 tess.
GetWidth(static_cast<int>(i)),chull2);
235 res[i] = GetCorrectedVelociy(cm, tess.
GetMeshPoint(static_cast<int>(i)), w[i], dt, reduce_factor,
236 tess.
GetWidth(static_cast<int>(i)),eos,cells[i],tracerstickernames);
240 MPI_exchange_data(tess, cur_w,
true);
243 vector<int> edges = GetBoundaryEdges(tess);
244 SlowNearBoundary(res, edges, tess, dt);
246 for (
size_t i = 0; i < res.size(); ++i)
248 if (tess.
GetWidth(static_cast<int>(i)) <
abs(res[i]) * dt &&
abs(cells[i].velocity)*2 <
abs(res[i]))
256 vector<string> toignore) :
257 bpm_(bpm),reduce_factor_(reduction_factor),eos_(eos),niter_(niter),toignore_(toignore){}
262 vector<Vector2D> res=bpm_(tess, cells, time, tracerstickernames);
267 double dt, vector<Vector2D>
const & velocities,
TracerStickerNames const& tracerstickernames)
const 269 return GetCorrectedVelocities(tess, velocities, dt, reduce_factor_, niter_,cells,eos_,toignore_,
vector< T > VectorValues(vector< T > const &v, vector< int > const &index)
Returns only the values with indeces in index.
void sort_index(const vector< T > &arr, vector< int > &res)
Returns the indeces of a sort.
bool SegmentIntersection(Edge const &edge1, Edge const &edge2, Vector2D &Intersection, double eps=1e-8)
Calculates the intersection of two edges.
std::vector< std::string > sticker_names
The names of the stickers.
Abstract class for tessellation.
virtual int GetPointNo(void) const =0
Get Total number of mesh generating points.
CentroidMotion(PointMotion const &bpm, double reduction_factor, EquationOfState const &eos, size_t niter=2, vector< string > toignore=vector< string >())
Class constructor.
virtual int GetOriginalIndex(int point) const
Returns the original index of the duplicated point.
Container for error reports.
bool PointInCell(vector< Vector2D > const &cpoints, Vector2D const &vec)
Checks if a point is inside a Voronoi cell.
Interface between two cells.
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
vector< Vector2D > ApplyFix(Tessellation const &tess, vector< ComputationalCell > const &cells, double time, double dt, vector< Vector2D > const &velocities, TracerStickerNames const &tracerstickernames) const
Applies a small fix to the velocity of all mesh points once the time step is known.
virtual double dp2c(double d, double p, tvector const &tracers=tvector(), vector< string > const &tracernames=vector< string >()) const =0
Calculates the speed of sound.
double max(vector< double > const &v)
returns the maximal term in a vector
Abstract class for motion of mesh generating points.
double y
Component in the y direction.
tvector tracers
Tracers (can transfer from one cell to another)
virtual Edge const & GetEdge(int index) const =0
Returns edge (interface between cells)
Correction to point velocities that keeps cells round by prediction of cell center.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Base class for equation of state.
std::pair< Vector2D, Vector2D > vertices
Points at the ends of the edge.
virtual double GetWidth(int index) const =0
Returns the effective width of a cell.
std::vector< std::string > tracer_names
The names of the tracers.
svector stickers
Stickers (stick to the same cell)
double min(vector< double > const &v)
Returns the minimal term in a vector.
Class for keeping the names of the tracers and stickers.
void Set(double ix, double iy)
Set vector components.
virtual int GetTotalSidesNumber(void) const =0
Returns the total number of faces.
std::pair< int, int > neighbors
Neighboring cells.
vector< Vector2D > operator()(const Tessellation &tess, const vector< ComputationalCell > &cells, double time, TracerStickerNames const &tracerstickernames) const
Calculates the velocity of all mesh points.
double abs(Vector3D const &v)
Norm of a vector.
Iter binary_find(Iter begin, Iter end, T val)
Binary search that return iterator of found object or end if not found.
virtual vector< int > GetNeighbors(int index) const =0
Returns the indeces of the neighbors.
double x
Component in the x direction.
Vector2D zcross(Vector2D const &v)
Cross product of a vector in x,y plane with a unit vector in the z direction.