2 #include "../../../misc/utils.hpp" 5 #include "../../../mpi/mpi_commands.hpp" 12 void GetNeighborMesh(
Tessellation const& tess, vector<const Edge *>
const& edges,
size_t cell_index,
13 vector<Vector2D> &res)
15 res.resize(edges.size());
16 const size_t nloop = edges.size();
17 for (
size_t i = 0; i < nloop; ++i)
19 const int neigh0 = edges[i]->neighbors.first;
20 const int neigh1 = edges[i]->neighbors.second;
21 if (neigh0 == static_cast<int>(cell_index))
28 void GetNeighborCM(
Tessellation const& tess, vector<const Edge*>
const& edges,
size_t cell_index,
29 vector<Vector2D> &res)
31 res.resize(edges.size());
32 const size_t nloop = edges.size();
33 for (
size_t i = 0; i < nloop; ++i)
35 const int neigh0 = edges[i]->neighbors.first;
36 const int neigh1 = edges[i]->neighbors.second;
37 if (neigh0 == static_cast<int>(cell_index))
44 vector<ComputationalCell const*> GetNeighborCells(vector<const Edge *>
const& edges,
size_t cell_index,
45 vector<ComputationalCell>
const& cells)
47 vector<ComputationalCell const*> res(edges.size());
48 const size_t nloop = edges.size();
49 for (
size_t i = 0; i < nloop; ++i)
51 size_t other_cell = (edges[i]->neighbors.first ==
static_cast<int>(cell_index)) ?
static_cast<size_t> 52 (edges[i]->neighbors.second) : static_cast<size_t> (edges[i]->neighbors.first);
53 res[i] = &cells.at(other_cell);
59 vector<int>
const& edge_indices, vector<const Edge*> &res)
62 res.reserve(edge_indices.size());
63 const size_t nloop = edge_indices.size();
64 for (
size_t i = 0; i < nloop; ++i)
65 res.push_back(&tess.
GetEdge(edge_indices[i]));
69 Vector2D const& center,
Vector2D const& cell_cm,
double cell_volume, vector<ComputationalCell const*>
const& neighbors,
70 vector<Vector2D>
const& neighbor_centers, vector<Vector2D>
const& neigh_cm, vector<const Edge*>
const& edge_list,
73 size_t n = edge_list.size();
77 eo.AddEntry(
"Cell x cor", center.
x);
78 eo.AddEntry(
"Cell y cor", center.
y);
82 vector<double> m(4, 0);
83 for (
size_t i = 0; i < edge_list.size(); ++i)
86 const double e_length = edge_list[i]->GetLength();
88 m[0] -= c_ij.
x*r_ij.
x;
89 m[1] -= c_ij.
y*r_ij.
x;
90 m[2] -= c_ij.
x*r_ij.
y;
91 m[3] -= c_ij.
y*r_ij.
y;
94 ReplaceComputationalCell(vec_compare.
xderivative, cell);
95 ReplaceComputationalCell(vec_compare.
yderivative, cell);
101 ComputationalCellAddMult(vec_compare.
xderivative, cell, r_ij.
x*0.5);
102 ComputationalCellAddMult(vec_compare.
yderivative, cell, r_ij.
y*0.5);
104 ComputationalCellAddMult(vec_compare.
yderivative, *neighbors[i], r_ij.
y*0.5);
105 ComputationalCellAddMult(vec_compare.
xderivative, *neighbors[i], r_ij.
x*0.5);
110 const double det = m[0] * m[3] - m[1] * m[2];
112 if (
std::abs(det) < 1e-10*cell_volume*cell_volume)
115 eo.AddEntry(
"Cell x cor", center.
x);
116 eo.AddEntry(
"Cell y cor", center.
y);
117 eo.AddEntry(
"Cell volume", cell_volume);
118 eo.AddEntry(
"Det was", det);
122 std::array<double,4> m_inv;
123 const double det_inv = 1.0 / det;
124 m_inv[0] = m[3] * det_inv;
125 m_inv[1] = -m[1] * det_inv;
126 m_inv[2] = -m[2] * det_inv;
127 m_inv[3] = m[0] * det_inv;
137 double PressureRatio(
ComputationalCell cell, vector<ComputationalCell const*>
const& neigh)
141 for (
size_t i = 0; i < neigh.size(); ++i)
143 if (p > neigh[i]->pressure)
144 res =
std::min(res, neigh[i]->pressure / p);
146 res =
std::min(res, p / neigh[i]->pressure);
151 bool is_shock(
Slope const& naive_slope,
double cell_width,
double shock_ratio,
152 ComputationalCell const& cell, vector<ComputationalCell const*>
const& neighbor_list,
double pressure_ratio,
double cs)
155 cell_width < (-shock_ratio)*cs;
156 const bool cond2 = PressureRatio(cell, neighbor_list) < pressure_ratio;
157 return cond1 || cond2;
163 ReplaceComputationalCell(res, cell);
164 ComputationalCellAddMult(res, slope.
xderivative, target.
x - cm.
x);
165 ComputationalCellAddMult(res, slope.
yderivative, target.
y - cm.
y);
171 ComputationalCellAddMult(res, slope.
xderivative, target.
x - cm.
x);
172 ComputationalCellAddMult(res, slope.
yderivative, target.
y - cm.
y);
176 vector<ComputationalCell const*>
const& neighbors, vector<const Edge*>
const& edge_list,
183 string const& skip_key,
191 ReplaceComputationalCell(cmax, cell);
192 ReplaceComputationalCell(cmin, cell);
194 size_t nloop = neighbors.size();
195 for (
size_t i = 0; i < nloop; ++i)
212 for (
size_t j = 0; j < cell_temp.
tracers.size(); ++j)
218 ReplaceComputationalCell(maxdiff, cmax);
220 ReplaceComputationalCell(mindiff, cmin);
223 interp(centroid_val, cell, slope,
CalcCentroid(*edge_list[0]), cm);
224 ReplaceComputationalCellDiff(dphi, centroid_val, cell);
225 psi.resize(4 + cell.
tracers.size());
226 psi.assign(psi.size(), 1);
227 const size_t nedges = edge_list.size();
228 for (
size_t i = 0; i < nedges; ++i)
234 ReplaceComputationalCell(centroid_val, cell);
235 interp2(centroid_val, slope,
CalcCentroid(*edge_list[i]), cm);
236 ReplaceComputationalCell(dphi, centroid_val);
278 for (
size_t j = 0; j < dphi.
tracers.size(); ++j)
280 double cell_tracer = cell.
tracers[j];
281 double diff_tracer = maxdiff.
tracers[j];
283 centroid_val.
tracers[j] * cell_tracer < 0))
308 if ((vcell + maxadd) > maxv)
310 double factor = (maxv - vcell) / maxadd;
320 for (
size_t k = 0; k < N; ++k)
330 vector<ComputationalCell const*>
const& neighbors, vector<const Edge*>
const& edge_list,
338 ReplaceComputationalCell(cmax, cell);
339 ReplaceComputationalCell(cmin, cell);
341 for (
size_t i = 0; i < neighbors.size(); ++i)
356 for (
size_t j = 0; j < cell_temp.
tracers.size(); ++j)
362 ReplaceComputationalCellDiff(maxdiff, cmax, cell);
363 ReplaceComputationalCellDiff(mindiff, cmin, cell);
365 psi.resize(4 + cell.
tracers.size());
366 psi.assign(psi.size(), 1);
367 for (
size_t i = 0; i<edge_list.size(); ++i)
371 interp(centroid_val,cell, slope,
CalcCentroid(*edge_list[i]), cm);
374 ReplaceComputationalCellDiff(dphi,centroid_val,cell);
401 for (
size_t j = 0; j < dphi.
tracers.size(); ++j)
403 double cell_tracer = cell.
tracers[j];
404 double diff_tracer = maxdiff.
tracers[j];
405 double centroid_tracer = centroid_val.
tracers[j];
407 centroid_tracer*cell_tracer < 0)
410 psi[4 + counter] =
std::min(psi[4 + counter],
411 std::max(diffusecoeff*(neighbors[i]->tracers[j] - cell_tracer) / dphi.
tracers[j], 0.0));
431 if ((vcell + maxadd) > maxv)
433 double factor = (maxv - vcell) / maxadd;
450 vector<ComputationalCell const*>
const& neighbors, vector<Vector2D>
const& neigh_cm,
453 size_t Nneigh = neigh_cm.size();
457 double SxSy(0), Sy2(0), Sx2(0);
458 for (
size_t i = 0; i < Nneigh; ++i)
460 PhiSy += (*neighbors[i] - cell)*(neigh_cm[i].y - cell_cm.
y);
461 PhiSx += (*neighbors[i] - cell)*(neigh_cm[i].x - cell_cm.
x);
462 SxSy += (neigh_cm[i].y - cell_cm.
y)*(neigh_cm[i].x - cell_cm.
x);
463 Sx2 += (neigh_cm[i].x - cell_cm.
x)*(neigh_cm[i].x - cell_cm.
x);
464 Sy2 += (neigh_cm[i].y - cell_cm.
y)*(neigh_cm[i].y - cell_cm.
y);
466 res.
xderivative = (PhiSy*SxSy - PhiSx*Sy2) / (SxSy*SxSy - Sx2*Sy2);
468 res.
yderivative = (PhiSx*SxSy - PhiSy*Sx2) / (SxSy*SxSy - Sx2*Sy2);
475 vector<ComputationalCell>
const& cells,
480 double pressure_ratio,
482 const vector<string>& calc_tracers,
492 vector<const Edge *>
const& edge_list,
493 vector<Vector2D> &neighbor_mesh_list,
494 vector<Vector2D> &neighbor_cm_list,
496 string const& skip_key,
497 vector<double> &psi,
bool SR)
499 GetNeighborMesh(tess, edge_list, cell_index, neighbor_mesh_list);
500 GetNeighborCM(tess, edge_list, cell_index, neighbor_cm_list);
501 vector<ComputationalCell const*> neighbor_list = GetNeighborCells(edge_list, cell_index, cells);
504 bool boundary_slope =
false;
505 size_t Nneigh = neighbor_list.size();
506 for (
size_t i = 0; i < Nneigh; ++i)
509 boundary_slope =
true;
513 GetBoundarySlope(cell, tess.
GetCellCM(static_cast<int>(cell_index)),
514 neighbor_list, neighbor_cm_list, res);
516 calc_naive_slope(cell, tess.
GetMeshPoint(static_cast<int>(cell_index)), tess.
GetCellCM(static_cast<int>(cell_index)),
517 tess.
GetVolume(static_cast<int>(cell_index)), neighbor_list, neighbor_mesh_list, neighbor_cm_list, edge_list,
522 for (
size_t i = 0; i < res.xderivative.tracers.size(); ++i)
524 if (std::find(calc_tracers.begin(), calc_tracers.end(), tracerstickernames.
tracer_names[i]) == calc_tracers.end())
527 res.yderivative.tracers[i] = 0;
533 if (!is_shock(res, tess.
GetWidth(static_cast<int>(cell_index)), shockratio, cell, neighbor_list, pressure_ratio,
534 eos.
dp2c(cell.density, cell.pressure, cell.tracers,tracerstickernames.
tracer_names)))
536 slope_limit(cell, tess.
GetCellCM(static_cast<int>(cell_index)), neighbor_list, edge_list, res, temp2, temp3,
537 temp4, temp5,tracerstickernames,skip_key,tess,psi,temp6,temp7,SR);
541 shocked_slope_limit(cell, tess.
GetCellCM(static_cast<int>(cell_index)), neighbor_list, edge_list, res, diffusecoeff,tracerstickernames,skip_key,temp2,temp3,temp4,temp5,psi,temp6,temp7, SR);
551 interp(res,cell, rslopes_[cell_index], target, cm);
562 const vector<string>& calc_tracers,
570 shockratio_(delta_v),
571 diffusecoeff_(theta),
572 pressure_ratio_(delta_P),
573 calc_tracers_(calc_tracers),
581 void exchange_ghost_slopes(
Tessellation const& tess, vector<Slope> & slopes)
583 MPI_exchange_data(tess, slopes,
true);
589 const vector<ComputationalCell>& cells,
double time, vector<pair<ComputationalCell, ComputationalCell> > &res,
592 const size_t CellNumber =
static_cast<size_t>(tess.
GetPointNo());
593 vector<int> boundaryedges;
595 boost::container::flat_map<size_t, ComputationalCell> ghost_cells = ghost_.operator()(tess, cells, time, tracerstikersnames);
597 vector<ComputationalCell> new_cells(cells);
599 for (boost::container::flat_map<size_t, ComputationalCell>::const_iterator it = ghost_cells.begin(); it !=
600 ghost_cells.end(); ++it)
601 new_cells[it->first] = it->second;
604 size_t Nall = new_cells.size();
605 for (
size_t j = 0; j < Nall; ++j)
607 double gamma = 1.0 / std::sqrt(1 -
ScalarProd(new_cells[j].velocity, new_cells[j].velocity));
608 new_cells[j].velocity *= gamma;
612 rslopes_.resize(CellNumber,
Slope(cells[0], cells[0]));
613 naive_rslopes_.resize(CellNumber);
614 Slope temp1(cells[0], cells[0]);
622 vector<const Edge *> edge_list;
623 vector<Vector2D> neighbor_mesh_list;
624 vector<Vector2D> neighbor_cm_list;
625 for (
size_t i = 0; i < CellNumber; ++i)
627 vector<int>
const& edge_index = tess.
GetCellEdges(static_cast<int>(i));
628 GetEdgeList(tess, edge_index, edge_list);
629 calc_slope(tess, new_cells, i, slf_, shockratio_, diffusecoeff_, pressure_ratio_, eos_,
630 calc_tracers_, naive_rslopes_[i], rslopes_[i], temp1, temp2, temp3, temp4, temp5,temp6,temp7, edge_list,
631 neighbor_mesh_list, neighbor_cm_list, tracerstikersnames,skip_key_,psi,SR_);
632 const size_t nloop = edge_index.size();
633 for (
size_t j = 0; j < nloop; ++j)
635 Edge const& edge = *edge_list[j];
636 if (edge.
neighbors.first == static_cast<int>(i))
638 ReplaceComputationalCell(res[static_cast<size_t>(edge_index[j])].first,new_cells[i]);
639 interp2(res[static_cast<size_t>(edge_index[j])].first,
641 if (edge.
neighbors.second > static_cast<int>(CellNumber))
642 boundaryedges.push_back(edge_index[j]);
646 ReplaceComputationalCell(res[static_cast<size_t>(edge_index[j])].second,new_cells[i]);
647 interp2(res[static_cast<size_t>(edge_index[j])].second,
649 if (edge.
neighbors.first > static_cast<int>(CellNumber))
650 boundaryedges.push_back(edge_index[j]);
656 exchange_ghost_slopes(tess, rslopes_);
659 for (
size_t i = 0; i < boundaryedges.size(); ++i)
662 if (edge.
neighbors.first > static_cast<int>(CellNumber))
664 res[
static_cast<size_t>(boundaryedges[i])].first = new_cells[static_cast<size_t>(edge.
neighbors.first)];
667 interp2(res[static_cast<size_t>(boundaryedges[i])].first,
670 interp(res[static_cast<size_t>(boundaryedges[i])].first,res[static_cast<size_t>(boundaryedges[i])].first,
674 interp(res[static_cast<size_t>(boundaryedges[i])].first,res[static_cast<size_t>(boundaryedges[i])].first,
681 res[
static_cast<size_t>(boundaryedges[i])].second = new_cells[static_cast<size_t>(edge.
neighbors.second)];
684 interp2(res[static_cast<size_t>(boundaryedges[i])].second,
687 interp(res[static_cast<size_t>(boundaryedges[i])].second, res[static_cast<size_t>(boundaryedges[i])].second,
691 interp(res[static_cast<size_t>(boundaryedges[i])].second,res[static_cast<size_t>(boundaryedges[i])].second,
700 size_t N = res.size();
701 for (
size_t i = 0; i < N; ++i)
703 double factor = 1.0 / std::sqrt(1 +
ScalarProd(res[i].first.velocity, res[i].first.velocity));
704 res[i].first.velocity *= factor;
705 factor = 1.0 / std::sqrt(1 +
ScalarProd(res[i].second.velocity, res[i].second.velocity));
706 res[i].second.velocity *= factor;
719 return naive_rslopes_;
vector< Slope > & GetSlopes(void) const
Returns the gradients.
vector< Slope > & GetSlopesUnlimited(void) const
Returns the unsloped limtied gradients.
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.
virtual Vector2D const & GetCellCM(int index) const =0
Returns Position of Cell's CM.
virtual int GetOriginalIndex(int point) const
Returns the original index of the duplicated point.
Container for error reports.
ComputationalCell Interp(ComputationalCell const &cell, size_t cell_index, Vector2D const &cm, Vector2D const &target) const
Interpolates a cell.
Interface between two cells.
virtual Slope GetGhostGradient(const Tessellation &tess, const vector< ComputationalCell > &cells, const vector< Slope > &gradients, size_t ghost_index, double time, const Edge &edge, TracerStickerNames const &tracerstickernames) const =0
Calculates the gradients for the ghost cells.
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
Class for spatial interpolations.
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 creating ghost 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)
LinearGaussImproved(EquationOfState const &eos, GhostPointGenerator const &ghost, bool slf=true, double delta_v=0.2, double theta=0.5, double delta_P=0.7, const vector< string > &calc_tracers=vector< string >(), string skip_key=string(), bool SR=false)
Class constructor.
ComputationalCell xderivative
Slope in the x direction.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Base class for equation of state.
virtual int GetTotalPointNumber(void) const =0
Returns the total number of points (including ghost)
Container for cache data.
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.
vector< T >::const_reference safe_retrieve(vector< T > const &data, vector< S > const &keys, const S &key)
Checks for existence and retrieves entry from flat map.
svector stickers
Stickers (stick to the same cell)
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.
Vector2D normalize(const Vector2D &v)
Normalized a vector.
Class for keeping the names of the tracers and stickers.
std::pair< int, int > neighbors
Neighboring cells.
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.
Linear interpolation that guarantees compliance with the equation of state and calcualtes the GG grad...
void operator()(const Tessellation &tess, const vector< ComputationalCell > &cells, double time, vector< pair< ComputationalCell, ComputationalCell > > &res, TracerStickerNames const &tracerstickersnames, CacheData const &cd) const
interpolates values on both sides of each interface
Vector2D CalcCentroid(Edge const &edge)
Calculates the central point of the edge.
double x
Component in the x direction.
ComputationalCell yderivative
Slope in the y direction.