15 for (
size_t i = 0; i < cell.
tracers.size(); ++i)
20 int GetEdgeIndex(
Tessellation const& tessnew,
int n0,
int n1,
int cell_index)
22 vector<int>
const& edges = tessnew.
GetCellEdges(cell_index);
23 for (
size_t j = 0; j<edges.size(); ++j)
49 void GetAdjacentNeigh(
Tessellation const& tessold,
Edge const& edge,
int cell_index,
50 Vector2D const& added,
int &n0other,
int &n1other)
52 vector<int>
const& edges = tessold.
GetCellEdges(cell_index);
55 dist.reserve(edges.size());
56 for (
size_t i = 0; i < edges.size(); ++i)
78 Edge const& edge,
int other_index)
85 GetAdjacentNeigh(tessold, edge, cell_index,
Vector2D(0, 0), n0, n1);
87 if (rigid && (n0 == cell_index || n1 == cell_index))
99 for (
size_t i = 0; i < newedges.size(); ++i)
101 Edge const& newedge = tessnew.
GetEdge(newedges[i]);
110 for (
size_t i = 0; i < edges.size(); ++i)
114 if (n0new == n1 || n1new == n1)
122 GetAdjacentNeigh(tessnew, tessnew.
GetEdge(res), n0,
Vector2D(0, 0), n0new, n1new);
123 if ((n0new == cell_index&&n1new == other_index) || (n1new == cell_index&&other_index == n0new))
131 edgenew.
vertices.first += edge_added;
132 edgenew.
vertices.second += edge_added;
133 const double R = 1e-8*tessnew.
GetWidth(cell);
135 for (
size_t i = 0; i < edges.size(); ++i)
152 vector<int>
const& edges = tess.
GetCellEdges(cell_index);
153 for (
size_t i = 0; i < edges.size(); ++i)
164 std::pair<Vector2D, Vector2D> TrianglesArea(
Edge const& eold,
Edge const &enew,
Tessellation const& tessnew,
168 std::pair<Vector2D, Vector2D> res;
169 boost::array<Vector2D, 4> points;
170 double area_scale = 0;
191 points[3] = enew.
vertices.first + new_edge_added;
192 points[2] = enew.
vertices.second + new_edge_added;
196 points[2] = enew.
vertices.first + new_edge_added;
197 points[3] = enew.
vertices.second + new_edge_added;
200 Vector2D toadd = new_edge_added - cell_index_added;
201 bool first = FirstVertice(enew, tessnew, cell_index, toadd);
208 points[0] = points[1];
220 third_point = (first ? enew.
vertices.second : enew.
vertices.first) + new_edge_added;
228 Edge otheredge = FindOtherEdge(tessold, cell_index, other);
234 first = FirstVertice(eold, tessold, other, added);
236 if (newrigid&&enew.
neighbors.first > npoints)
257 if (
std::abs(sum) > 1e-5*area_scale)
260 eo.AddEntry(
"area_scale", area_scale);
261 eo.AddEntry(
"sum", sum);
262 eo.AddEntry(
"old neigh 0", eold.
neighbors.first);
263 eo.AddEntry(
"old neigh 1", eold.
neighbors.second);
271 vector<int>
const& edges = tessold.
GetCellEdges(cell_index);
272 for (
size_t i = 0; i < edges.size(); ++i)
283 void GetCellIndex(
Edge const& edge,
Tessellation const& tess,
int &cell_index,
int &other_index)
298 double GetdAFlux(
int mid_index,
Tessellation const& tessmid,
double dt,
299 int other_index, vector<Vector2D>
const& fv)
313 void AreaFixEdgeDisappear(
Tessellation const& tessold,
Tessellation const& tessnew,
int cell_index,
int other_index,
314 Edge const& edge,
OuterBoundary const& outer,
int npoints, vector<Vector2D>
const& pointvelocity,
double dt,
315 double dA_flux,
int mid_index,
Tessellation const& tessmid, vector<Vector2D>
const& fv,
316 vector<ComputationalCell>
const& cells,
EquationOfState const& eos, vector<Extensive> &res,
317 std::set<std::pair<int, int > > &flipped_set,
Vector2D const& cell_added)
320 int new_edge = NewEdgeIndex(tessold, tessnew, cell_index, edge, other_index);
325 if (flipped_set.count(neighbors) > 0)
335 pointvelocity[
static_cast<size_t>(edge_new.
neighbors.first)], -dt, outer);
336 addedother += FixNewEdgeLeap(tessold, edge_new.
neighbors.first, cell_index);
341 pointvelocity[
static_cast<size_t>(edge_new.
neighbors.second)], -dt, outer);
342 addedother += FixNewEdgeLeap(tessold, edge_new.
neighbors.second, cell_index);
345 std::pair<Vector2D, Vector2D> areas = TrianglesArea(edge, edge_new, tessnew, tessold, addedother, cell_index,
347 vector<double> dA(4);
352 dA[0] = areas.first.x - dA_flux;
353 dA[1] = areas.first.y + dA_flux;
354 dA[2] = areas.second.x;
355 dA[3] = areas.second.y;
369 Extensive TotalRemoved(cells[0].tracers);
370 double total_added_area = 0;
373 Extensive toremove = ComputationalCell2Extensive(cells[
376 TotalRemoved += toremove;
379 total_added_area += dA[0];
382 Extensive toremove = ComputationalCell2Extensive(cells[
385 TotalRemoved += toremove;
388 total_added_area += dA[1];
392 Extensive toremove = ComputationalCell2Extensive(cells[
395 TotalRemoved += toremove;
398 total_added_area += dA[2];
401 Extensive toremove = ComputationalCell2Extensive(cells[
404 TotalRemoved += toremove;
407 total_added_area += dA[3];
421 res[
static_cast<size_t>(tessnew.
GetOriginalIndex(edge_new.
neighbors.second))] += (dA[3] / total_added_area)*TotalRemoved;
424 flipped_set.insert(neighbors);
425 std::pair<int, int> neigh_temp(neighbors.second, neighbors.first);
426 flipped_set.insert(neigh_temp);
433 boost::array<Vector2D, 4> edge_points;
440 edge_points[1] = e1.
vertices.second;
445 edge_points[0] = e1.
vertices.second;
450 edge_points[3] = e2.
vertices.second;
455 edge_points[2] = e2.
vertices.second;
469 if (ratio<2 && ratio>0.5)
479 if (ratio<2 && ratio>0.5)
489 if (ratio<2 && ratio>0.5)
499 if (ratio<2 && ratio>0.5)
508 for (
size_t i = 0; i < c0.
tracers.size(); ++i)
511 if (ratio<2 && ratio>0.5)
524 Tessellation const& tessnew, vector<Vector2D>
const& pointvelocity,
double dt,
525 vector<ComputationalCell>
const& cells, vector<Extensive>
const& ,
528 size_t npoints =
static_cast<size_t>(tessold.
GetPointNo());
529 vector<Extensive> res(static_cast<size_t>(npoints),
Extensive(cells[0].tracers));
532 std::set<std::pair<int, int > > flipped_set, only_mid;
534 for (
size_t i = 0; i < nedgesold; ++i)
536 Edge const& edge = tessold.
GetEdge(static_cast<int>(i));
538 int cell_index, other_index;
539 GetCellIndex(edge, tessold, cell_index, other_index);
540 int mid_index = GetEdgeIndex(tessmid, cell_index, other_index, cell_index);
541 int new_index = GetEdgeIndex(tessnew, cell_index, other_index, cell_index);
542 double dA_flux = GetdAFlux(mid_index, tessmid, dt, other_index, fv);
549 added = FixPeriodicLeap(real_p, pointvelocity[static_cast<size_t>(cell_index)], dt, outer);
554 AreaFixEdgeDisappear(tessold, tessnew, cell_index, other_index, edge, outer, static_cast<int>(npoints), pointvelocity, dt,
555 dA_flux, mid_index, tessmid, fv, cells, eos, res, flipped_set, added);
563 edge_other.
vertices.second += added;
566 double area = EdgesArea(edge, edge_other, real_p, real_p_new);
567 ComputationalCell p_mid = GetDonorCell(cells[static_cast<size_t>(cell_index)], cells[static_cast<size_t>(other_index)],
568 (area - dA_flux)>0, eos);
569 Extensive toadd = ComputationalCell2Extensive(p_mid, (-dA_flux + area), eos);
572 res[
static_cast<size_t>(other_index)] -= toadd;
574 res[
static_cast<size_t>(cell_index)] += toadd;
578 int mid_edge = NewEdgeIndex(tessold, tessmid, cell_index, edge, other_index);
593 std::pair<int, int> mid_neigh2(mid_neigh.second, mid_neigh.first);
594 if (only_mid.count(mid_neigh) == 0)
596 only_mid.insert(mid_neigh);
597 only_mid.insert(mid_neigh2);
void sort_index(const vector< T > &arr, vector< int > &res)
Returns the indeces of a sort.
Abstract class for tessellation.
virtual int GetPointNo(void) const =0
Get Total number of mesh generating points.
Fixes the area inconsistency problem.
virtual int GetOriginalIndex(int point) const
Returns the original index of the duplicated point.
Vector2D momentum
momentum, in relativity it is = rho*h*gamma*v
Container for error reports.
double mass
rest mass times gamma
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 energy
energy, in relativity it is = rho*h*gamma^2-P-rho
double y
Component in the y direction.
A collection of three identical references.
tvector tracers
Tracers (can transfer from one cell to another)
virtual Edge const & GetEdge(int index) const =0
Returns edge (interface between cells)
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
virtual BoundaryType GetBoundaryType(void) const =0
Returns the boundary type.
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.
double min(vector< double > const &v)
Returns the minimal term in a vector.
virtual int GetTotalSidesNumber(void) const =0
Returns the total number of faces.
std::pair< int, int > neighbors
Neighboring cells.
virtual double dp2e(double d, double p, tvector const &tracers=tvector(), vector< string > const &tracernames=vector< string >()) const =0
Calculates the thermal energy per unit mass.
const T & first
Reference to first item.
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.
Vector2D velocity
Velocity.
Abstract class for geometric boundary conditions for the tessellation.
double GetLength(void) const
Returns the length of the edge.
virtual double GetGridBoundary(Directions dir) const =0
Returns the boundary coordinate.
double orient2d(const TripleConstRef< Vector2D > &points)
Checks whether 3 given points are on a counterclockwise circle, clockwise circle or colinear...
vector< Extensive > FluxFix2(Tessellation const &tessold, Tessellation const &tessmid, Tessellation const &tessnew, vector< Vector2D > const &pointvelocity, double dt, vector< ComputationalCell > const &cells, vector< Extensive > const &fluxes, vector< Vector2D > const &fv, OuterBoundary const &outer, EquationOfState const &eos)
Fixes the flux to propely converge second order.
double x
Component in the x direction.