2 #include "../../tessellation/VoronoiMesh.hpp" 4 #include "../../mpi/mpi_commands.hpp" 26 const double mass = volume*cell.
density;
30 for (
size_t i = 0; i < N; ++i)
44 const double mass = volume * cell.
density*gamma;
48 for (
size_t i = 0; i < N; ++i)
54 res.
energy = (gamma*enthalpy + (gamma - 1))* mass - cell.
pressure*volume;
64 for (
size_t i = 0; i < toskip_.size(); ++i)
68 const double vol_inv = 1.0 / volume;
71 size_t N = extensive.
tracers.size();
73 for (
size_t i = 0; i < N;++i)
85 for (
size_t i = 0; i < tracerstickernames.
tracer_names.size(); ++i)
97 for (
size_t i = 0; i < toskip_.size(); ++i)
102 volume = 1.0 / volume;
105 throw UniversalError(
"Negative density in SimpleAMRCellUpdaterSR");
110 size_t N = extensive.
tracers.size();
112 for (
size_t i = 0; i < extensive.
tracers.size(); ++i)
119 + (1.0 / gamma_1 - 1)*res.
density);
127 vector<vector<int> > GetSentIndeces(
Tessellation const& tess, vector<size_t>
const& ToRemove,vector<vector<size_t> > &
132 vector<vector<int> > sort_indeces(sentpoints.size());
133 vector<vector<int> > res(sentpoints.size());
134 RemoveIndex.resize(sentpoints.size());
135 int Nprocs =
static_cast<int>(sentpoints.size());
137 for (
int i = 0; i < Nprocs; ++i)
140 sort(sentpoints[i].begin(), sentpoints[i].end());
143 int Nremove =
static_cast<int>(ToRemove.size());
144 for (
int i = 0; i < Nremove; ++i)
146 for (
int j = 0; j < Nprocs; ++j)
148 vector<int>::const_iterator it = std::lower_bound(sentpoints[static_cast<size_t>(j)].begin(), sentpoints[static_cast<size_t>(j)].end(),
149 ToRemove[static_cast<size_t>(i)]);
150 if ((it != sentpoints[static_cast<size_t>(j)].end()) && (*it == static_cast<int>(ToRemove[static_cast<size_t>(i)])))
152 res[
static_cast<size_t>(j)].push_back(sort_indeces[static_cast<size_t>(j)][
static_cast<size_t>(it -
153 sentpoints[
static_cast<size_t>(j)].begin())]);
154 RemoveIndex[
static_cast<size_t>(j)].push_back(static_cast<size_t>(i));
161 void SendRecvOuterMerits(
Tessellation const& tess, vector<vector<int> > &sent_indeces,vector<double>
const& merits,
162 vector<vector<size_t> >
const& RemoveIndex,vector<vector<int> > &recv_indeces,vector<vector<double> > &recv_mertis)
164 vector<vector<double> > send_merits(sent_indeces.size());
165 size_t Nproc = send_merits.size();
166 for (
size_t i = 0; i < Nproc; ++i)
172 vector<size_t> KeepMPINeighbors(
Tessellation const& tess, vector<size_t>
const& ToRemove,vector<double>
const& merits,
173 vector<vector<int> > &recv_indeces,vector<vector<double> > &recv_mertis)
176 size_t Nproc = recv_indeces.size();
177 for (
size_t i = 0; i < Nproc; ++i)
179 recv_indeces[i] =
VectorValues(Nghost[i], recv_indeces[i]);
180 vector<size_t> temp =
sort_index(recv_indeces[i]);
181 sort(recv_indeces[i].begin(), recv_indeces[i].end());
186 size_t Nremove = ToRemove.size();
188 vector<size_t> RemoveFinal;
189 for (
size_t i = 0; i < Nremove; ++i)
192 tess.
GetNeighbors(static_cast<int>(ToRemove[i]), neigh);
193 size_t Nneigh = neigh.size();
194 for (
size_t j = 0; j < Nneigh; ++j)
198 for (
size_t k = 0; k < Nproc; ++k)
200 vector<int>::const_iterator it =
binary_find(recv_indeces[k].begin(), recv_indeces[k].end(),neigh[j]);
201 if (it != recv_indeces[k].end())
203 if (recv_mertis[k][static_cast<size_t>(it - recv_indeces[k].begin())] > merits[i])
215 RemoveFinal.push_back(ToRemove[i]);
220 void ExchangeOuterRemoveData(
Tessellation const& tess, vector<size_t>
const& ToRemove,vector<vector<int> >
221 &to_check,vector<vector<Vector2D> > &chulls_res,vector<Extensive>
const& extensives,vector<Extensive> & mpi_extensives,
226 mpi_extensives.clear();
228 vector<vector<int> > sort_indeces(Nghost.size());
229 int Nprocs =
static_cast<int>(Nghost.size());
231 for (
int i = 0; i < Nprocs; ++i)
234 sort(Nghost[i].begin(), Nghost[i].end());
236 vector<vector<Extensive> > myremove(Nprocs);
237 vector<vector<vector<Vector2D> > > chulls(Nprocs);
238 vector<vector<vector<int> > > remove_neigh(Nprocs);
239 size_t Nremove = ToRemove.size();
242 vector<Vector2D> tempV2D;
243 for (
size_t i = 0; i < Nremove; ++i)
245 bool calculated =
false;
246 tess.
GetNeighbors(static_cast<int>(ToRemove[i]), neigh);
247 size_t Nneigh = neigh.size();
248 for (
size_t k = 0; k < static_cast<size_t>(Nprocs); ++k)
250 vector<int> temp_add;
251 bool should_add=
false;
252 for (
size_t j = 0; j < Nneigh; ++j)
254 if (neigh[j] >= Np && tess.
GetOriginalIndex(neigh[j]) !=
static_cast<int>(ToRemove[i]))
256 vector<int>::const_iterator it =
binary_find(Nghost[k].begin(), Nghost[k].end(), neigh[j]);
257 if (it != Nghost[k].end())
262 ConvexHull(tempV2D, tess, static_cast<int>(ToRemove[i]));
265 temp_add.push_back(sort_indeces[k][static_cast<size_t>(it - Nghost[k].begin())]);
271 chulls[k].push_back(tempV2D);
272 remove_neigh[k].push_back(temp_add);
273 myremove[k].push_back((1.0/cd.
volumes[ToRemove[i]]) * extensives[ToRemove[i]]);
278 chulls=MPI_exchange_data(tess, chulls, tess.
GetMeshPoint(0));
279 remove_neigh=MPI_exchange_data(tess, remove_neigh);
280 vector<vector<Extensive> > mpi_recv_extensives = MPI_exchange_data(tess.
GetDuplicatedProcs(), myremove,extensives[0]);
290 for (
size_t i = 0; i < static_cast<size_t>(Nprocs); ++i)
292 for (
size_t j = 0; j < remove_neigh[i].size(); ++j)
294 for (
size_t k = 0; k < remove_neigh[i][j].size(); ++k)
302 remove_neigh[i][j][k]=duplicated_points[i][remove_neigh[i][j][k]];
310 void DealWithMPINeighbors(
Tessellation const& tess, vector<size_t> &ToRemove, vector<double> &merits,
311 vector<vector<int> > &to_check, vector<vector<Vector2D> > &chulls_res,
312 vector<Extensive>
const& extensives, vector<Extensive> & mpi_extensives,
CacheData const& cd)
314 vector<vector<size_t> > RemoveIndex;
315 vector<vector<int> > sent_indeces = GetSentIndeces(tess, ToRemove, RemoveIndex);
316 vector<vector<int> > recv_indeces;
317 vector<vector<double> > recv_mertis;
318 SendRecvOuterMerits(tess, sent_indeces, merits, RemoveIndex, recv_indeces, recv_mertis);
319 ToRemove = KeepMPINeighbors(tess, ToRemove, merits, recv_indeces, recv_mertis);
320 ExchangeOuterRemoveData(tess, ToRemove, to_check, chulls_res,extensives, mpi_extensives,cd);
324 double AreaOverlap(vector<Vector2D>
const& poly0, vector<Vector2D>
const& poly1,
PhysicalGeometry const& pg)
327 using namespace ClipperLib;
328 Paths subj(1), clip(1), solution;
331 for (
size_t i = 0; i < poly0.size(); ++i)
333 cm0 = cm0/
static_cast<double>(poly0.size());
334 for (
size_t i = 0; i < poly0.size(); ++i)
336 for (
size_t i = 0; i < poly1.size(); ++i)
338 int maxscale =
static_cast<int>(log10(maxi) + 10);
340 subj[0].resize(poly0.size());
341 clip[0].resize(poly1.size());
342 for (
size_t i = 0; i < poly0.size(); ++i)
343 subj[0][i] = IntPoint(static_cast<cInt>((poly0[i].x-cm0.
x)*pow(10.0, 18 - maxscale)),
static_cast<cInt
>((poly0[i].y-cm0.
y)*pow(10.0, 18 - maxscale)));
344 for (
size_t i = 0; i < poly1.size(); ++i)
345 clip[0][i] = IntPoint(static_cast<cInt>((poly1[i].x-cm0.
x)*pow(10.0, 18 - maxscale)),
static_cast<cInt
>((poly1[i].y-cm0.
y)*pow(10.0, 18 - maxscale)));
349 c.AddPaths(subj, ptSubject,
true);
350 c.AddPaths(clip, ptClip,
true);
351 c.Execute(ctIntersection, solution, pftNonZero, pftNonZero);
352 if (!solution.empty())
354 if (solution[0].size() > 2)
356 vector<Vector2D> inter(solution[0].size());
357 double factor = pow(10.0, maxscale - 18);
358 for (
size_t i = 0; i < solution[0].size(); ++i)
359 inter[i].Set(static_cast<double>(solution[0][i].X) * factor + cm0.
x,
static_cast<double>(solution[0][i].Y) * factor + cm0.
y);
395 double GetAspectRatio(
Tessellation const& tess,
int index)
399 for (
size_t i = 0; i < edges.size(); ++i)
401 return 4 * 3.14*tess.
GetVolume(index) / (L*L);
404 void RemoveNeighbors(vector<double> &merits, vector<size_t> &candidates,
Tessellation const& tess)
406 vector<size_t> candidates_new;
407 vector<double> merits_new;
408 if (merits.size() != candidates.size())
409 throw UniversalError(
"Merits and Candidates don't have same size in RemoveNeighbors");
411 vector<size_t> bad_neigh;
413 for (
size_t i = 0; i < merits.size(); ++i)
416 tess.
GetNeighbors(static_cast<int>(candidates[i]),neigh);
417 size_t nneigh = neigh.size();
418 if (find(bad_neigh.begin(), bad_neigh.end(), candidates[i]) !=
423 for (
size_t j = 0; j < nneigh; ++j)
425 if (binary_search(candidates.begin(), candidates.end(), tess.
GetOriginalIndex(neigh[j])))
427 if (merits[i] < merits[static_cast<size_t>(lower_bound(candidates.begin(), candidates.end(),
433 if (fabs(merits[i] - merits[static_cast<size_t>(lower_bound(candidates.begin(), candidates.end(),
436 if (find(bad_neigh.begin(), bad_neigh.end(), tess.
GetOriginalIndex(neigh[j])) == bad_neigh.end())
444 candidates_new.push_back(candidates[i]);
445 merits_new.push_back(merits[i]);
448 candidates = candidates_new;
452 Extensive GetNewExtensive(vector<Extensive>
const& extensives,
Tessellation const& tess,
size_t N,
size_t location,
453 vector<Vector2D>
const& moved,vector<int>
const& real_neigh,vector<vector<Vector2D> >
const& Chull,
458 Extensive NewExtensive(extensives[0].tracers);
459 vector<Vector2D> temp;
460 ConvexHull(temp, tess, static_cast<int>(N + location));
461 temp = temp + moved[location];
462 const double vv = cd.
volumes[N + location];
464 stack<vector<Vector2D> > tocheck_hull;
465 vector<int> checked(real_neigh);
466 vector<int> neightemp;
467 for (
size_t j = 0; j < Chull.size(); ++j)
469 double v = AreaOverlap(temp, Chull[j],pg);
479 for (
size_t k = 0; k < neightemp.size(); ++k)
485 if (std::find(checked.begin(), checked.end(), oldtess.
GetOriginalIndex(neightemp[k])) == checked.end())
487 vector<Vector2D> temp2;
490 tocheck_hull.push(temp2);
496 while (!tocheck.empty())
498 vector<Vector2D> chull = tocheck_hull.top();
499 int cur_check=tocheck.top();
502 double v = AreaOverlap(temp, chull,pg);
508 for (
size_t k = 0; k < neightemp.size(); ++k)
514 if (std::find(checked.begin(), checked.end(), oldtess.
GetOriginalIndex(neightemp[k])) == checked.end())
516 vector<Vector2D> temp2;
519 tocheck_hull.push(temp2);
525 const double eps = periodic ? 1e-2 : 1e-5;
526 if (vv > (1 + eps)*TotalVolume || vv < (1 - eps)*TotalVolume)
528 std::cout <<
"In refine Real volume: " << vv <<
" AMR volume: " << TotalVolume << std::endl;
531 eo.
AddEntry(
"location",static_cast<double>(location));
538 void GetToCheck(
Tessellation const& tess,
int ToRefine, vector<int> &real_neigh, vector<vector<Vector2D> > &Chull)
541 vector<Vector2D> temp;
542 ConvexHull(temp, tess, static_cast<int>(ToRefine));
543 Chull.push_back(temp);
544 real_neigh.push_back(static_cast<int>(ToRefine));
545 size_t N =
static_cast<size_t>(tess.
GetPointNo());
546 vector<Vector2D> moved;
548 for (
size_t j = 0; j < neigh.size(); ++j)
550 if (neigh[j] < static_cast<int>(N))
552 real_neigh.push_back(neigh[j]);
554 Chull.push_back(temp);
567 Chull.push_back(temp);
574 const size_t NN = real_neigh.size();
575 vector<int> neigh_temp;
576 for (
size_t j = 0; j < NN; ++j)
579 for (
size_t i = 0; i < neigh_temp.size(); ++i)
581 if (std::find(real_neigh.begin(), real_neigh.end(), tess.
GetOriginalIndex(neigh_temp[i])) == real_neigh.end())
583 if (neigh_temp[i] < static_cast<int>(N))
585 real_neigh.push_back(neigh_temp[i]);
587 Chull.push_back(temp+moved[j]);
593 if (tess.
GetOriginalIndex(neigh_temp[i]) !=
static_cast<int>(real_neigh[j]))
599 Chull.push_back(temp);
609 size_t location, vector<vector<Vector2D> > &Chull, vector<int> &real_neigh,vector<Vector2D>
const& Moved,
613 int newindex =
static_cast<int>(location) + oldpointnumber;
615 vector<int> neighcopy(real_neigh);
616 sort(neighcopy.begin(), neighcopy.end());
617 vector<Vector2D> temp;
618 for (
size_t i = 0; i < neigh.size(); ++i)
627 if (binary_search(neighcopy.begin(), neighcopy.end(), tess.
GetOriginalIndex(neigh[i])))
635 Chull.push_back(temp);
641 vector<pair<size_t, Vector2D> >
const& NewPoints, vector<Extensive>
const& extensives,
645 vector<int> real_neigh;
646 vector<vector<Vector2D> > Chull;
647 GetToCheck(oldtess, static_cast<int>(ToRefine),real_neigh,Chull);
648 size_t N =
static_cast<size_t>(oldtess.
GetPointNo());
649 while (location < NewPoints.size() && NewPoints[location].first == ToRefine)
651 AddCurrentNeigh(tess,location, Chull, real_neigh, moved, oldtess);
652 double TotalVolume=0;
653 Extensive NewExtensive = GetNewExtensive(extensives, tess, N, location, moved, real_neigh, Chull,
654 cells, eos, eu,TotalVolume,oldtess,periodic,tracerstickernames,pg,cd);
661 eo.
AddEntry(
"ToRefine", static_cast<double>(ToRefine));
675 vector<std::pair<size_t, Vector2D> > &NewPoints, vector<Vector2D> &Moved,
678 const double small = 1e-3;
680 NewPoints.reserve(ToRefine.size());
682 Moved.reserve(ToRefine.size());
684 for (
size_t i = 0; i < ToRefine.size(); ++i)
687 const double R = tess.
GetWidth(static_cast<int>(ToRefine[i]));
690 if (GetAspectRatio(tess, static_cast<int>(ToRefine[i])) < 0.65)
697 for (
size_t j = 1; j < neigh.size(); ++j)
700 if (otherpoint.
distance(mypoint) > otherdist)
703 otherdist = otherpoint.
distance(mypoint);
707 Vector2D candidate = mypoint+small*direction/
abs(direction);
708 Moved.push_back(FixInDomain(obc, candidate));
709 NewPoints.push_back(std::pair<size_t, Vector2D>(ToRefine[i], candidate));
715 vector<std::pair<size_t, Vector2D> > &NewPoints, vector<Vector2D> &Moved,
718 , vector<Vector2D>
const& proc_chull
723 size_t N =
static_cast<size_t>(tess.
GetPointNo());
725 NewPoints.reserve(ToRefine.size() * 7);
727 Moved.reserve(ToRefine.size() * 7);
729 for (
size_t i = 0; i < ToRefine.size(); ++i)
732 const double R = tess.
GetWidth(static_cast<int>(ToRefine[i]));
734 if (GetAspectRatio(tess, static_cast<int>(ToRefine[i])) < 0.3)
738 vector<int>
const& edges = tess.
GetCellEdges(static_cast<int>(ToRefine[i]));
739 for (
size_t j = 0; j < neigh.size(); ++j)
742 if (otherpoint.
distance(mypoint) < 1.25*R)
746 Vector2D candidate = 0.75*mypoint + 0.25*otherpoint;
752 if (std::binary_search(ToRefine.begin(), ToRefine.end(),
static_cast<size_t>(neigh[j])))
754 if (static_cast<size_t>(neigh[j]) > ToRefine[i])
756 candidate = 0.5*mypoint + 0.5*otherpoint;
773 Moved.push_back(FixInDomain(obc, candidate));
774 NewPoints.push_back(std::pair<size_t, Vector2D>(ToRefine[i], candidate));
779 ConservativeAMR::ConservativeAMR
788 scu_(vector<string>()),
804 vector<ComputationalCell> &cells,
806 vector<Extensive> &extensives,
815 size_t N =
static_cast<size_t>(tess.
GetPointNo());
817 vector<std::pair<size_t, Vector2D> > NewPoints;
818 vector<Vector2D> Moved;
819 vector<size_t> ToRefine = refine_.ToRefine(tess, cells, time,tracerstickernames);
821 if (ToRefine.empty())
824 sort(ToRefine.begin(), ToRefine.end());
825 ToRefine=
unique(ToRefine);
827 vector<double> merit;
828 ToRefine = RemoveNearBoundaryPoints(ToRefine, tess,merit);
829 vector<Vector2D> chull;
831 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
834 GetNewPoints(ToRefine, tess, NewPoints, Moved, obc
840 boost::scoped_ptr<Tessellation> oldtess(tess.
clone());
847 for (
size_t i = 0; i < NewPoints.size(); ++i)
848 cor.push_back(NewPoints[i].second);
854 tess.
Update(cor, proctess);
865 for (
size_t i = 0; i < ToRefine.size(); ++i)
866 ConservedSingleCell(*oldtess, tess, ToRefine[i], location, interp_, eos, cells, NewPoints, extensives, *eu_,
867 *cu_,Moved,periodic_,tracerstickernames,pg,cd);
868 extensives.resize(N + NewPoints.size());
869 for (
size_t i = 0; i < N + NewPoints.size(); ++i)
870 extensives[i] = eu_->ConvertPrimitveToExtensive(cells[i], eos, cd.
volumes[i],tracerstickernames);
872 MPI_exchange_data(tess, cells,
true);
877 OuterBoundary const& , vector<ComputationalCell> &cells, vector<Extensive> &extensives,
886 size_t N =
static_cast<size_t>(tess.
GetPointNo());
891 std::pair<vector<size_t>, vector<double> > ToRemovepair = remove_.ToRemove(tess, cells, time,tracerstickernames);
893 if (ToRemovepair.first.empty())
900 sort(ToRemovepair.first.begin(), ToRemovepair.first.end());
901 ToRemovepair.second =
VectorValues(ToRemovepair.second, indeces);
903 ToRemovepair.first =
unique(ToRemovepair.first);
904 ToRemovepair.second =
VectorValues(ToRemovepair.second, indeces);
905 RemoveNeighbors(ToRemovepair.second, ToRemovepair.first, tess);
907 vector<vector<int> > mpi_check;
908 vector<vector<Vector2D> > chulls_mpi;
909 vector<Extensive> mpi_extensives;
910 DealWithMPINeighbors(tess, ToRemovepair.first, ToRemovepair.second, mpi_check, chulls_mpi,extensives, mpi_extensives,cd);
914 boost::scoped_ptr<Tessellation> oldtess(tess.
clone());
915 vector<double> old_vol(ToRemovepair.first.size());
916 for (
size_t i = 0; i < ToRemovepair.first.size(); ++i)
917 old_vol[i] = cd.
volumes[ToRemovepair.first[i]];
925 tess.
Update(cor, proctess);
935 vector<Vector2D> temp;
936 vector<Vector2D> chull;
937 for (
size_t i = 0; i < ToRemovepair.first.size(); ++i)
939 vector<int> neigh = oldtess->GetNeighbors(static_cast<int>(ToRemovepair.first[i]));
940 ConvexHull(chull, *oldtess, static_cast<int>(ToRemovepair.first[i]));
941 const double TotalV = old_vol[i];
944 for (
size_t j = 0; j < neigh.size(); ++j)
946 size_t toadd =
static_cast<size_t>(lower_bound(ToRemovepair.first.begin(), ToRemovepair.first.end(),
947 oldtess->GetOriginalIndex(neigh[j])) - ToRemovepair.first.begin());
949 if (neigh[j] < static_cast<int>(N))
951 ConvexHull(temp, tess, static_cast<int>(static_cast<size_t>(neigh[j]) - toadd));
955 if (oldtess->GetOriginalIndex(neigh[j]) !=
static_cast<int>(ToRemovepair.first[i]))
960 ConvexHull(temp, tess, static_cast<int>(static_cast<size_t>(
961 oldtess->GetOriginalIndex(neigh[j]) )- toadd));
962 temp = temp + (oldtess->GetMeshPoint(neigh[j]) -
963 oldtess->GetMeshPoint(oldtess->GetOriginalIndex(neigh[j])));
968 const double v = AreaOverlap(chull, temp,pg);
970 extensives[
static_cast<size_t>(oldtess->GetOriginalIndex(neigh[j]))] += (v / TotalV)*extensives[ToRemovepair.first[i]];
980 for (
size_t i = 0; i < mpi_check.size(); ++i)
982 for (
size_t j = 0; j < mpi_check[i].size(); ++j)
984 size_t toadd =
static_cast<size_t>(lower_bound(ToRemovepair.first.begin(), ToRemovepair.first.end(),
985 oldtess->GetOriginalIndex(mpi_check[i][j])) - ToRemovepair.first.begin());
986 ConvexHull(chull, tess, mpi_check[i][j]-static_cast<int>(toadd));
987 const double v = AreaOverlap(chull, chulls_mpi[i], pg);
988 extensives[
static_cast<size_t>(mpi_check[i][j])] += v*mpi_extensives[i];
997 cells.resize(static_cast<size_t>(tess.
GetPointNo()));
998 for (
size_t i = 0; i < N; ++i)
999 cells[i] = cu_->ConvertExtensiveToPrimitve(extensives[i], eos,cd.
volumes[i], cells[i],tracerstickernames);
1001 MPI_exchange_data(tess, cells,
true);
1025 NonConservativeAMR::NonConservativeAMR
1030 refine_(refine), remove_(
remove), scu_(vector<string>()),
1031 seu_(),interp_(slopes),
1040 vector<Extensive> &extensives,
double time,
1048 vector<size_t> ToRefine = refine_.ToRefine(tess, cells, time,tracerstickernames);
1050 if (ToRefine.empty())
1053 sort(ToRefine.begin(), ToRefine.end());
1054 vector<std::pair<size_t, Vector2D> > NewPoints;
1055 vector<Vector2D> Moved;
1057 vector<Vector2D> chull;
1059 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
1062 GetNewPoints(ToRefine, tess, NewPoints, Moved, obc
1067 size_t N =
static_cast<size_t>(tess.
GetPointNo());
1071 extensives.resize(N + NewPoints.size());
1073 for (
size_t i = 0; i < NewPoints.size(); ++i)
1075 cor.push_back(NewPoints[i].second);
1076 cells.push_back(cells[NewPoints[i].first]);
1078 interp_->GetSlopesUnlimited().push_back(interp_->GetSlopesUnlimited()[NewPoints[i].first]);
1082 tess.
Update(cor, proctess);
1088 for (
size_t i = 0; i < N + NewPoints.size(); ++i)
1089 extensives[i] = eu_->ConvertPrimitveToExtensive(cells[i], eos, cd.
volumes[i],tracerstickernames);
1091 MPI_exchange_data(tess, cells,
true);
1096 OuterBoundary const& , vector<ComputationalCell> &cells, vector<Extensive> &extensives,
1105 std::pair<vector<size_t>, vector<double> > ToRemovepair = remove_.ToRemove(tess, cells, time,tracerstickernames);
1106 vector<size_t> ToRemove = ToRemovepair.first;
1108 if (ToRemove.empty())
1111 size_t N =
static_cast<size_t>(tess.
GetPointNo());
1121 tess.
Update(cor, proctess);
1127 extensives.resize(cells.size());
1128 for (
size_t i = 0; i < extensives.size(); ++i)
1129 extensives[i] = eu_->ConvertPrimitveToExtensive(cells[i], eos, cd.
volumes[i],tracerstickernames);
1131 MPI_exchange_data(tess, cells,
true);
1159 vector<double> merittemp;
1160 for (
size_t i = 0; i < ToRemove.size(); ++i)
1163 vector<int> neigh = tess.
GetNeighbors(static_cast<int>(ToRemove[i]));
1164 for (
size_t j = 0; j < neigh.size(); ++j)
1176 for (
size_t k = 0; k < neigh2.size(); ++k)
1193 res.push_back(ToRemove[i]);
1195 merittemp.push_back(merits.at(i));
void operator()(hdsim &sim)
Runs the AMR.
vector< T > unique(vector< T > const &v)
Returns a vector containing only unique elements.
const Tessellation & GetProcTessellation(void) const
Returns the processor tessellation.
ComputationalCell ConvertExtensiveToPrimitve(const Extensive &extensive, const EquationOfState &eos, double volume, ComputationalCell const &old_cell, TracerStickerNames const &tracerstickernames) const
Calculates the computational cell.
double distance(Vector2D const &v1) const
Caluclates the distance from the Vector to v1.
vector< T > VectorValues(vector< T > const &v, vector< int > const &index)
Returns only the values with indeces in index.
void operator()(hdsim &sim)
Runs the AMR.
virtual ~AMRCellUpdater(void)
Class destructor.
virtual vector< int > GetDuplicatedProcs(void) const =0
Returns the indeces of the processors with whom ghost points where exchanged.
virtual vector< int > Update(const vector< Vector2D > &points, bool HilbertOrder=false)=0
Update the tessellation.
void reset(void) const
Marks all items for recalculation.
void sort_index(const vector< T > &arr, vector< int > &res)
Returns the indeces of a sort.
vector< Slope > & GetSlopesUnlimited(void) const
Returns the unsloped limtied gradients.
std::vector< std::string > sticker_names
The names of the stickers.
void RemoveVector(vector< T > &v, vector< int > &indeces)
Removes the elements in v given by indeces.
Abstract class for tessellation.
vector< vector< T > > CombineVectors(vector< vector< vector< T > > > const &data)
Reduces the dimension of the input vector.
Abstract class for extensive update scheme in amr.
virtual ~CellsToRefine(void)
Virtual destructor.
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.
virtual double de2p(double d, double e, tvector const &tracers=tvector(), vector< string > const &tracernames=vector< string >()) const =0
Calculates the pressure.
Vector2D momentum
momentum, in relativity it is = rho*h*gamma*v
Container for error reports.
bool PointInCell(vector< Vector2D > const &cpoints, Vector2D const &vec)
Checks if a point is inside a Voronoi cell.
Newtonian hydrodynamic simulation.
Extensive ConvertPrimitveToExtensive(const ComputationalCell &cell, const EquationOfState &eos, double volume, TracerStickerNames const &tracerstickernames) const
Calculates the computational cell.
virtual double calcVolume(const vector< Edge > &edge_list) const =0
Calculates the physical volume of a cell.
double getTime(void) const
Returns the time.
double mass
rest mass times gamma
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
const Tessellation & getTessellation(void) const
Returns the tessellation.
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)
virtual ~AMRExtensiveUpdater(void)
Class destructor.
double GetVelocity(Extensive const &cell, double G)
Calculates velocity from extensive in SR.
TracerStickerNames const & GetTracerStickerNames(void) const
Returns the TracerStickerNames.
void GetNewPoints2(vector< size_t > const &ToRefine, Tessellation const &tess, vector< std::pair< size_t, Vector2D > > &NewPoints, vector< Vector2D > &Moved, OuterBoundary const &obc) const
Calculates the positions of the new points like AREPO.
ComputationalCell ConvertExtensiveToPrimitve(const Extensive &extensive, const EquationOfState &eos, double volume, ComputationalCell const &old_cell, TracerStickerNames const &tracerstickernames) const
Calculates the computational cell.
const PhysicalGeometry & getPhysicalGeometry(void) const
Access to physical geometry.
SimpleAMRCellUpdater(vector< string > toskip)
class constructor
const CacheData & getCacheData(void) const
Returns reference to the cached data.
virtual vector< Vector2D > & GetMeshPoints(void)=0
Returns a reference to the point vector.
void ConvexHull(vector< Vector2D > &result, Tessellation const &tess, int index)
Returns the ConvexHull for a set of points.
void GetNewPoints(vector< size_t > const &ToRefine, Tessellation const &tess, vector< std::pair< size_t, Vector2D > > &NewPoints, vector< Vector2D > &Moved, OuterBoundary const &obc, vector< Vector2D > const &proc_chull) const
Calculates the positions of the new points.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
vector< size_t > RemoveNearBoundaryPoints(vector< size_t > const &ToRemove, Tessellation const &tess, vector< double > &merits) const
Removes points because they are near the edge of a cpu domain.
virtual Extensive ConvertPrimitveToExtensive(const ComputationalCell &cell, const EquationOfState &eos, double volume, TracerStickerNames const &tracerstickernames) const =0
Calculates the computational cell.
Linear gauss interpolation.
virtual ~CellsToRemove(void)
Virtual destructor.
Base class for equation of state.
void UpdateCellsRefine(Tessellation &tess, OuterBoundary const &obc, vector< ComputationalCell > &cells, EquationOfState const &eos, vector< Extensive > &extensives, double time, Tessellation const &proctess, TracerStickerNames const &tracerstickernames, CacheData const &cd, PhysicalGeometry const &pg) const
Runs the refine.
const CachedLazyList< double > volumes
List of cell volumes.
Container for cache data.
virtual double GetWidth(int index) const =0
Returns the effective width of a cell.
Simulation output to hdf5 file format.
std::vector< std::string > tracer_names
The names of the tracers.
const EquationOfState & getEos(void) const
Access to the equation of state.
Abstract class for cell update scheme in amr.
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.
void UpdateCellsRemove(Tessellation &tess, OuterBoundary const &obc, vector< ComputationalCell > &cells, vector< Extensive > &extensives, EquationOfState const &eos, double time, Tessellation const &proctess, TracerStickerNames const &tracerstickernames, CacheData const &cd, PhysicalGeometry const &pg) const
Runs the removal.
Extensive ConvertPrimitveToExtensive(const ComputationalCell &cell, const EquationOfState &eos, double volume, TracerStickerNames const &tracerstickernames) const
Calculates the computational cell.
svector stickers
Stickers (stick to the same cell)
virtual double GetVolume(int index) const =0
Returns the volume of a cell.
SimpleAMRCellUpdaterSR(double G, vector< string > toskip)
class constructor
virtual ComputationalCell ConvertExtensiveToPrimitve(const Extensive &extensive, const EquationOfState &eos, double volume, ComputationalCell const &old_cell, TracerStickerNames const &tracerstickernames) const =0
Calculates the computational cell.
Chooses which cells should be remove.
Class for keeping the names of the tracers and stickers.
vector< int > unique_index(vector< T > const &v)
Returns a vector containing only indeces of unique elements.
Chooses which cells should be refined.
virtual Tessellation * clone(void) const =0
Cloning function.
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.
void WriteTess(Tessellation const &tess, string const &filename)
Writes the tessellation data into an HDF5 file.
virtual ~AMR(void)
Virtual destructor.
virtual vector< vector< int > > & GetDuplicatedPoints(void)=0
Returns the indeces of the points that where sent to other processors as ghost points.
void UpdateCellsRemove(Tessellation &tess, OuterBoundary const &obc, vector< ComputationalCell > &cells, vector< Extensive > &extensives, EquationOfState const &eos, double time, Tessellation const &proctess, TracerStickerNames const &tracerstickernames, CacheData const &cd, PhysicalGeometry const &pg) const
Runs the removal.
double abs(Vector3D const &v)
Norm of a vector.
void UpdateCellsRefine(Tessellation &tess, OuterBoundary const &obc, vector< ComputationalCell > &cells, EquationOfState const &eos, vector< Extensive > &extensives, double time, Tessellation const &proctess, TracerStickerNames const &tracerstickernames, CacheData const &cd, PhysicalGeometry const &pg) const
Runs the refine.
void AddEntry(std::string const &field, double value)
Adds an entry to the list.
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.
const vector< ComputationalCell > & getAllCells(void) const
Returns a list of all computational cells.
Iter binary_find(Iter begin, Iter end, T val)
Binary search that return iterator of found object or end if not found.
virtual vector< vector< int > > & GetGhostIndeces(void)=0
Returns the indeces of each ghost point in the vector of points that the tessellation holds...
double GetLength(void) const
Returns the length of the edge.
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.
Base class for physical geometry.
double fastabs(Vector2D const &v)
Norm of a vector, less accurate.
double x
Component in the x direction.
const OuterBoundary & getOuterBoundary(void) const
Access to the geometric outer boundary.
const vector< Extensive > & getAllExtensives(void) const
Returns a list of extensive variables.