2 #include "../../tessellation/calc_face_vertex_velocity.hpp" 3 #include "../../tessellation/HilbertOrder.hpp" 14 throw UniversalError(
"Something went wrong in Hydrodynamics2D::get_other_index");
38 const Vector2D r = calc_representing_point(tess, index, cm_flag);
46 class CellInitializer :
public LazyList<Primitive>
57 tess_(tess), cm_flag_(cm_flag),
60 xvelocity_(xvelocity),
61 yvelocity_(yvelocity),
66 return initialize_single_cell(tess_,
76 size_t size(
void)
const 78 return static_cast<size_t>(tess_.GetPointNo());
81 ~CellInitializer(
void) {}
105 (tess, cm_value, density,
106 pressure, xvelocity, yvelocity, eos));
110 class IntensiveInitializer :
public LazyList<Conserved>
114 explicit IntensiveInitializer(vector<Primitive>
const& cells) :
122 size_t size(
void)
const 124 return cells_.size();
128 vector<Primitive>
const& cells_;
133 (vector<Primitive>
const& cells)
140 class CellEdgesGetter :
public LazyList<Edge>
147 size_t size(
void)
const 149 return edge_indices_.size();
152 Edge operator[](
size_t i)
const 154 return tess_.GetEdge(edge_indices_[i]);
159 const vector<int> edge_indices_;
162 class ExtensiveInitializer :
public LazyList<Conserved>
166 ExtensiveInitializer(
const vector<Conserved>& intensive,
169 intensive_(intensive), tess_(tess), pg_(pg) {}
173 return pg_.calcVolume(
serial_generate(CellEdgesGetter(tess_, static_cast<int>(n))))*
177 size_t size(
void)
const 179 return static_cast<size_t>(tess_.GetPointNo());
183 const vector<Conserved>& intensive_;
190 (
const vector<Conserved>& cons_int,
198 vector<Vector2D>
const& face_velocites)
201 for (
size_t i = 0; i < face_velocites.size(); ++i)
207 class NewPointPosition :
public LazyList<Vector2D>
212 vector<Vector2D>
const& point_velocity,
215 point_velocity_(point_velocity),
220 return tess_.GetMeshPoint(static_cast<int>(n)) + dt_*point_velocity_[n];
223 size_t size(
void)
const 225 return static_cast<size_t>(tess_.GetPointNo());
230 vector<Vector2D>
const& point_velocity_;
238 if (oldpoints.empty())
239 oldpoints =
serial_generate(NewPointPosition(tessellation, pointvelocity, dt));
242 for (
size_t i = 0; i < oldpoints.size(); ++i)
243 oldpoints[i] += pointvelocity[i] * dt;
245 vector<int> indeces = tessellation.
Update(oldpoints, reorder);
253 vector<Vector2D> oldpoints)
255 if (oldpoints.empty())
256 oldpoints =
serial_generate(NewPointPosition(tessellation, pointvelocity, dt));
259 for (
size_t i = 0; i < oldpoints.size(); ++i)
260 oldpoints[i] += pointvelocity[i] * dt;
262 vector<int> indeces = tessellation.
Update(oldpoints, vproc, reorder);
268 class IntensiveCalculator :
public LazyList<Conserved>
273 const vector<Conserved>& extensive,
275 tess_(tess), extensive_(extensive), pg_(pg) {}
277 size_t size(
void)
const 279 return extensive_.size();
284 return extensive_[i] /
285 pg_.calcVolume(
serial_generate(CellEdgesGetter(tess_, static_cast<int>(i))));
290 const vector<Conserved>& extensive_;
297 const vector<Conserved>& extensive,
304 vector<Conserved>
const& conservedextensive,
305 vector<Conserved>& conservedintensive)
307 conservedintensive.resize(conservedextensive.size());
308 for (
int i = 0; i < tessellation.
GetPointNo(); i++) {
309 conservedintensive[
static_cast<size_t>(i)] = conservedextensive[static_cast<size_t>(i)] /
343 const double normal_speed =
Projection(edge_velocity, normaldir);
344 const Conserved res = rs(rotated_left, rotated_right, normal_speed);
352 const vector<ComputationalCell>& cells,
353 const vector<Extensive>& fluxes,
354 const vector<Vector2D>& point_velocities,
358 vector<Extensive>& extensives,
361 const vector<Extensive> diff = force(tess, pg, cd, cells, fluxes, point_velocities, t,tracerstickernames);
362 for (
size_t i = 0; i < static_cast<size_t>(tess.
GetPointNo()); ++i)
364 extensives[i].mass += dt*diff[i].mass;
365 extensives[i].momentum += dt*diff[i].momentum;
366 extensives[i].energy += dt*diff[i].energy;
367 assert(extensives[i].tracers.size()==diff[i].tracers.size());
368 size_t N = diff[i].tracers.size();
369 for (
size_t j = 0; j < N; ++j)
370 extensives[i].tracers[j] += dt*diff[i].tracers[j];
377 vector<Vector2D> res(static_cast<size_t>(tess.
GetPointNo()));
378 for (
int i = 0; i < static_cast<int>(tess.
GetPointNo()); ++i)
384 (vector<Primitive>
const& vp,
387 vector<Primitive> res = vp;
388 for (
int i = 0; i < static_cast<int>(vp.size()); ++i)
394 vector<double>
const& g)
397 int n = int(g.size());
398 res.resize(static_cast<size_t>(n));
399 for (
int i = 0; i < n; ++i)
400 res[static_cast<size_t>(i)] = g[
static_cast<size_t>(i)] * tess.
GetWidth(i);
405 vector<double> scalar_mult(
const vector<double>& v,
409 return vector<double>();
410 vector<double> res(v.size());
411 for (
size_t i = 0; i < v.size(); ++i)
418 class ExtensiveTracerCalculator :
public LazyList<vector<double> >
422 ExtensiveTracerCalculator(
const vector<vector<double> >& tracers,
424 const vector<Primitive>& cells,
426 tracers_(tracers), tess_(tess), cells_(cells), pg_(pg) {}
428 size_t size(
void)
const 430 if (tracers_.empty())
433 return static_cast<size_t>(tess_.GetPointNo());
436 vector<double> operator[](
size_t i)
const 440 pg_.calcVolume(
serial_generate(CellEdgesGetter(tess_, static_cast<int>(i))))*
445 const vector<vector<double> >& tracers_;
447 const vector<Primitive>& cells_;
453 (
const vector<vector<double> >& intensive_tracer,
455 const vector<Primitive>& cells,
466 vector<Primitive>
const& cells,
467 vector<vector<double> > &result)
469 const size_t n =
static_cast<size_t>(tess.
GetPointNo());
471 for (
size_t i = 0; i < n; ++i)
472 result[i] = scalar_mult(tracer[i],
473 tess.
GetVolume(static_cast<int>(i))*cells[i].Density);
477 double R, vector<int> & PointToRemove,
int Inner)
480 PointToRemove.clear();
481 for (
int i = Inner; i < n; ++i)
486 for (
int j = 0; j < static_cast<int>(neigh.size()); ++j)
487 if (neigh[static_cast<size_t>(j)] >= Inner)
491 PointToRemove.push_back(i);
497 vector<Conserved>
const& intensive,
Tessellation const& tessold,
498 Tessellation const& tessnew, vector<Vector2D>
const& facevelocity,
499 double dt, vector<Vector2D>
const& )
503 vector<double> Rold(static_cast<size_t>(npoints)), Rnew(static_cast<size_t>(npoints));
504 vector<vector<Vector2D> > pold(static_cast<size_t>(npoints)), pnew(static_cast<size_t>(npoints));
505 for (
int i = 0; i < npoints; ++i)
507 Rold[
static_cast<size_t>(i)] = tessold.
GetWidth(i);
508 Rnew[
static_cast<size_t>(i)] = tessnew.
GetWidth(i);
509 ConvexHull(pold[static_cast<size_t>(i)], tessold, i);
510 ConvexHull(pnew[static_cast<size_t>(i)], tessnew, i);
515 for (
int i = 0; i < n; ++i)
520 if (n0 < 0 || n1 < 0)
523 norm = norm /
abs(norm);
525 double dv_dt =
ScalarProd(facevelocity[static_cast<size_t>(i)], norm)*dt;
541 extensive[
static_cast<size_t>(n0)] += (real_dv0 - dv_dt)*intensive[
static_cast<size_t>(tessold.
GetOriginalIndex(n1))];
542 extensive[
static_cast<size_t>(n0)] -= real_dv1*intensive[static_cast<size_t>(tessold.
GetOriginalIndex(n0))];
546 extensive[
static_cast<size_t>(n1)] += (dv_dt - real_dv0)*intensive[
static_cast<size_t>(tessold.
GetOriginalIndex(n1))];
547 extensive[
static_cast<size_t>(n1)] += real_dv1*intensive[static_cast<size_t>(tessold.
GetOriginalIndex(n0))];
554 extensive[
static_cast<size_t>(n0)] -= (real_dv1 + dv_dt)*intensive[
static_cast<size_t>(tessold.
GetOriginalIndex(n0))];
555 extensive[
static_cast<size_t>(n0)] += real_dv0*intensive[static_cast<size_t>(tessold.
GetOriginalIndex(n1))];
559 extensive[
static_cast<size_t>(n1)] -= (-dv_dt - real_dv1)*intensive[
static_cast<size_t>(tessold.
GetOriginalIndex(n0))];
560 extensive[
static_cast<size_t>(n1)] -= real_dv0*intensive[static_cast<size_t>(tessold.
GetOriginalIndex(n1))];
571 double dt = hydro_time_step;
575 dt =
std::min(end_time - current_time, dt);
Set of conserved variables (extensive)
Vector2D Momentum
Momentum.
virtual vector< int > Update(const vector< Vector2D > &points, bool HilbertOrder=false)=0
Update the tessellation.
double SoundSpeed
Speed of sound.
double TimeStepForCell(Primitive const &cell, double width, vector< Vector2D > const &face_velocites)
Calculates the time step for a cell.
double determine_time_step(double hydro_time_step, double external_dt, double current_time, double end_time)
Determines the time step.
Abstract class for tessellation.
void GetPointToRemove(Tessellation const &tess, Vector2D const &point, double R, vector< int > &PointToRemove, int Inner)
Makes a list of points to remove.
vector< Conserved > CalcConservedIntensive(vector< Primitive > const &cells)
Calculates the intensive conserved variables.
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.
Primitive CalcPrimitive(double density, double pressure, Vector2D const &velocity, EquationOfState const &eos)
Calculates the primitive variables.
double Projection(Vector3D const &v1, Vector3D const &v2)
Calculates the projection of one vector in the direction of the second.
vector< T > serial_generate(const LazyList< T > &ll)
Creates a vector from an LazyList.
vector< vector< double > > calc_extensive_tracer(const vector< vector< double > > &intensive_tracer, const Tessellation &tess, const vector< Primitive > &cells, const PhysicalGeometry &pg)
Calculates extensive tracers.
Vector2D Velocity
Velocity.
Interface between two cells.
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
void FixAdvection(vector< Conserved > &extensive, vector< Conserved > const &intensive, Tessellation const &tessold, Tessellation const &tessnew, vector< Vector2D > const &facevelocity, double dt, vector< Vector2D > const &pointvelocity)
Applies a correction to the extensive variables due to the change in volume during time step...
vector< Primitive > InitialiseCells(SpatialDistribution const &density, SpatialDistribution const &pressure, SpatialDistribution const &xvelocity, SpatialDistribution const &yvelocity, EquationOfState const &eos, Tessellation const &tess, bool CMvalue=true)
Initialize computational cells.
vector< Conserved > calc_conserved_intensive(const Tessellation &tess, const vector< Conserved > &extensive, const PhysicalGeometry &pg)
Calculates the intensive conserved variables.
double max(vector< double > const &v)
returns the maximal term in a vector
double y
Component in the y direction.
Ordered list whose terms are evaluated lazily.
Spatial distribution for initial conditions.
virtual Edge const & GetEdge(int index) const =0
Returns edge (interface between cells)
Abstract class for external forces.
Base class for Riemann solver.
virtual T operator[](const size_t i) const =0
Returns a single member of the list.
Conserved Primitive2Conserved(Primitive const &p)
Converts primitive variables to conserved intensive.
Primitive make_eos_consistent(Primitive const &p, EquationOfState const &eos)
Takes a set of primitive variables that do not necessarily satisfy the equation of state...
void ConvexHull(vector< Vector2D > &result, Tessellation const &tess, int index)
Returns the ConvexHull for a set of points.
int get_other_index(const Edge &edge, const int index)
Given an edge and an index of one neighbor, returns the index of another neighbor.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
vector< Vector2D > get_all_mesh_points(Tessellation const &tess)
Returns the position of all mesh generating points.
vector< double > GetForceEnergy(Tessellation const &tess, vector< double > const &g)
Returns the energies due to external potentials.
Base class for equation of state.
void ExternalForceContribution(const Tessellation &tess, const PhysicalGeometry &pg, const CacheData &cd, const vector< ComputationalCell > &cells, const vector< Extensive > &fluxes, const vector< Vector2D > &point_velocities, const SourceTerm &source, double t, double dt, vector< Extensive > &extensives, TracerStickerNames const &tracerstickernames)
Adds force contribution to the extensive conserved variables.
Container for cache data.
virtual double GetWidth(int index) const =0
Returns the effective width of a cell.
void reorder(vector< T > &v, vector< size_t > const &order)
Reorder a vector according to an index vector (obtained from the 'ordered' function) ...
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.
Class for keeping the names of the tracers and stickers.
void Set(double ix, double iy)
Set vector components.
vector< Conserved > CalcConservedExtensive(const vector< Conserved > &cons_int, const Tessellation &tess, const PhysicalGeometry &pg)
Calculates the extensive conserved variables.
virtual int GetTotalSidesNumber(void) const =0
Returns the total number of faces.
std::pair< int, int > neighbors
Neighboring cells.
Conserved RotateFluxBack(const Conserved &c, const Vector2D &n, const Vector2D &p)
Rotates flux from the edge frame back to the lab frame.
Various manipulations of hydrodynamic variables.
Conserved FluxInBulk(Vector2D const &normaldir, Vector2D const ¶ldir, Primitive const &left, Primitive const &right, Vector2D const &edge_velocity, RiemannSolver const &rs)
Calculates the flux in the bulk of the fluid.
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.
Primitive hydrodynamic variables.
void UpdateConservedIntensive(Tessellation const &tessellation, vector< Conserved > const &conservedextensive, vector< Conserved > &conservedintensive)
Updates the intensive conserved variables.
double GetLength(void) const
Returns the length of the edge.
vector< int > MoveMeshPoints(vector< Vector2D > const &pointvelocity, double dt, Tessellation &tessellation, bool reorder, vector< Vector2D > oldpoints=vector< Vector2D >())
Move mesh points.
virtual vector< int > GetNeighbors(int index) const =0
Returns the indeces of the neighbors.
Base class for physical geometry.
virtual size_t size(void) const =0
Returns the length of the list.
double x
Component in the x direction.
double polygon_overlap_area(vector< Vector2D > const &ch1, vector< Vector2D > const &ch2, double R0, double R1)
Calculates the area overlaped between two convex polygons.
void MakeTracerExtensive(vector< vector< double > > const &tracer, Tessellation const &tess, vector< Primitive > const &cells, vector< vector< double > > &result)
Calculates the extensive tracer.
Primitive RotatePrimitive(const Vector2D &normaldir, const Vector2D ¶ldir, const Primitive &p)
Rotates primitive variables to align with edge.