Lmotion.cpp
1 #include "Lmotion.hpp"
2 #include <iostream>
3 #include "../simple_flux_calculator.hpp"
4 #include "../../../misc/utils.hpp"
5 #ifdef RICH_MPI
6 #include "../../../mpi/mpi_commands.hpp"
7 #endif //RICH_MPI
8 
9 namespace
10 {
11  double GetWs(Primitive const& left,Primitive const& right)
12  {
13  const double dl = left.Density;
14  const double pl = left.Pressure;
15  const double vl = left.Velocity.x;
16  const double cl = left.SoundSpeed;
17  const double dr = right.Density;
18  const double pr = right.Pressure;
19  const double vr = right.Velocity.x;
20  const double cr = right.SoundSpeed;
21  const double sl = std::min(vl - cl, vr - cr);
22  const double sr = std::max(vl + cl, vr + cr);
23  const double ss = (pr - pl + dl*vl*(sl - vl) - dr*vr*(sr - vr)) /
24  (dl*(sl - vl) - dr*(sr - vr));
25  return ss;
26  }
27 }
28 
29 LMotion::LMotion(SpatialReconstruction const& interp, EquationOfState const& eos /*,EdgeVelocityCalculator const& evc*/) :interp_(interp), eos_(eos) /*,evc_(evc)*/ {}
30 
31 vector<Vector2D> LMotion::operator()(const Tessellation& tess, const vector<ComputationalCell>& cells,
32 double /*time*/, TracerStickerNames const& /*tracerstickernames*/) const
33 {
34  size_t N = static_cast<size_t>(tess.GetPointNo());
35  vector<Vector2D> res(N, Vector2D(0, 0));
36  for (size_t i = 0; i < N; ++i)
37  res[i] = cells[i].velocity;
38  return res;
39 }
40 
41 vector<Vector2D> LMotion::ApplyFix(Tessellation const& tess, vector<ComputationalCell> const& cells, double time,
42 double dt, vector<Vector2D> const& /*velocities*/, TracerStickerNames const& tracerstickernames)const
43 {
44  int N = tess.GetPointNo();
45  vector<Vector2D> res(static_cast<size_t>(N), Vector2D(0, 0));
46  std::vector<double> TotalArea(static_cast<size_t>(N), 0);
47  vector<std::pair<ComputationalCell, ComputationalCell> > edge_values;
48  edge_values.resize(static_cast<size_t>(tess.GetTotalSidesNumber()),
49  pair<ComputationalCell, ComputationalCell>(cells[0], cells[0]));
50  SlabSymmetry pg;
51  CacheData cd(tess, pg);
52  interp_(tess, cells, time, edge_values, tracerstickernames, cd);
53  size_t Nedges = edge_values.size();
54  vector<double> ws(Nedges, 0), edge_length(Nedges);
55  std::vector<Vector2D> normals(Nedges);
56  for (size_t j = 0; j < Nedges; ++j)
57  {
58  Edge const& edge = tess.GetEdge(static_cast<int>(j));
59  edge_length[j] = cd.areas[j];
60  if (edge.neighbors.first < N)
61  TotalArea[static_cast<size_t>(edge.neighbors.first)] += edge_length[j];
62  if (edge.neighbors.second < N)
63  TotalArea[static_cast<size_t>(edge.neighbors.second)] += edge_length[j];
64  Primitive left = convert_to_primitive(edge_values[j].first, eos_, tracerstickernames);
65  Primitive right = convert_to_primitive(edge_values[j].second, eos_, tracerstickernames);
66  Vector2D p = normalize(Parallel(edge));
67  normals[j] = normalize(tess.GetMeshPoint(edge.neighbors.second) - tess.GetMeshPoint(edge.neighbors.first));
68  left.Velocity = Vector2D(ScalarProd(left.Velocity, normals[j]), ScalarProd(left.Velocity, p));
69  right.Velocity = Vector2D(ScalarProd(right.Velocity, normals[j]), ScalarProd(right.Velocity, p));
70  ws[j] = GetWs(left, right);
71  }
72  vector<int> edges;
73  size_t indexX = static_cast<size_t>(binary_find(tracerstickernames.tracer_names.begin(), tracerstickernames.tracer_names.end(),
74  string("AreaX")) - tracerstickernames.tracer_names.begin());
75  size_t indexY = static_cast<size_t>(binary_find(tracerstickernames.tracer_names.begin(), tracerstickernames.tracer_names.end(),
76  string("AreaY")) - tracerstickernames.tracer_names.begin());
77  size_t Ntracers = tracerstickernames.tracer_names.size();
78  for (size_t i = 0; i < static_cast<size_t>(N); ++i)
79  {
80  edges = tess.GetCellEdges(static_cast<int>(i));
81  double A = cd.volumes[i];
82  Vector2D CM = A*cd.CMs[i];
83  for (size_t j = 0; j < edges.size(); ++j)
84  {
85  double Atemp = edge_length[static_cast<size_t>(edges[j])] *
86  dt*ws[static_cast<size_t>(edges[j])];
87  double sign = 1;
88  if (tess.GetEdge(edges[j]).neighbors.second == static_cast<int>(i))
89  sign = -1;
90  Vector2D CMtemp = (tess.GetEdge(edges[j]).vertices.first + tess.GetEdge(edges[j]).vertices.second)*0.5 + ws[static_cast<size_t>(edges[j])] *0.5*
91  normals[static_cast<size_t>(edges[j])]*dt;
92  CM += sign*Atemp*CMtemp;
93  A += sign*Atemp;
94  }
95  double ratio = fastabs(cd.CMs[i] - tess.GetMeshPoint(static_cast<int>(i))) / (tess.GetWidth(static_cast<int>(i)));
96  double factor = std::min(0.2*ratio*ratio,0.1);
97  res[i] = (CM / A - (tess.GetMeshPoint(static_cast<int>(i))*factor+cd.CMs[i]*(1-factor)))/dt;
98  if (indexX < Ntracers && indexY < Ntracers)
99  {
100  double m = 2.5*cells[i].density*cd.volumes[i]/(dt*TotalArea[i]);
101  Vector2D toadd(m*cells[i].tracers[indexX], m*cells[i].tracers[indexY]);
102  double v = abs(res[i]);
103  double t = abs(toadd);
104  if (t > 0.05*v)
105  toadd = toadd*(0.05*v / t);
106  res[i] += toadd;
107  }
108  }
109  return res;
110 }
double Density
Density.
vector< Vector2D > operator()(const Tessellation &tess, const vector< ComputationalCell > &cells, double time, TracerStickerNames const &tracerstickernames) const
Calculates the velocity of all mesh points.
Definition: Lmotion.cpp:31
Slab symmetry.
double SoundSpeed
Speed of sound.
Vector2D Parallel(Edge const &edge)
Calculates a unit vector parallel to an edge.
Definition: Edge.cpp:83
Spatial reconstruction of the primitive functions.
Abstract class for tessellation.
virtual int GetPointNo(void) const =0
Get Total number of mesh generating points.
Primitive convert_to_primitive(const ComputationalCell &cell, const EquationOfState &eos, TracerStickerNames const &tracerstickernames)
Converts computational cell to primitive variables.
const CachedLazyList< Vector2D > CMs
List of center of masses of the cells.
Definition: cache_data.hpp:87
Vector2D Velocity
Velocity.
Interface between two cells.
Definition: Edge.hpp:13
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
const CachedLazyList< double > areas
List of areas of interfaces.
Definition: cache_data.hpp:84
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.
Definition: Lmotion.cpp:41
double max(vector< double > const &v)
returns the maximal term in a vector
Definition: utils.cpp:52
LMotion(SpatialReconstruction const &interp, EquationOfState const &eos)
Class constructor.
Definition: Lmotion.cpp:29
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.
Definition: Vector3D.cpp:185
Base class for equation of state.
std::pair< Vector2D, Vector2D > vertices
Points at the ends of the edge.
Definition: Edge.hpp:18
const CachedLazyList< double > volumes
List of cell volumes.
Definition: cache_data.hpp:81
Container for cache data.
Definition: cache_data.hpp:14
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.
double min(vector< double > const &v)
Returns the minimal term in a vector.
Definition: utils.cpp:44
Vector2D normalize(const Vector2D &v)
Normalized a vector.
Definition: geometry.cpp:158
Class for keeping the names of the tracers and stickers.
virtual int GetTotalSidesNumber(void) const =0
Returns the total number of faces.
std::pair< int, int > neighbors
Neighboring cells.
Definition: Edge.hpp:21
double Pressure
Pressure.
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
virtual vector< int > const & GetCellEdges(int index) const =0
Returns the indexes of a cell&#39;s edges.
Primitive hydrodynamic variables.
Iter binary_find(Iter begin, Iter end, T val)
Binary search that return iterator of found object or end if not found.
Definition: utils.hpp:709
2D Mathematical vector
Definition: geometry.hpp:15
double fastabs(Vector2D const &v)
Norm of a vector, less accurate.
Definition: geometry.cpp:24
double x
Component in the x direction.
Definition: geometry.hpp:45