simple_flux_calculator.cpp
2 #include "../common/hydrodynamics.hpp"
3 #include "../../tessellation/geometry.hpp"
4 #include "../../misc/utils.hpp"
5 
7  rs_(rs) {}
8 
10  const EquationOfState& eos,TracerStickerNames const& tracerstickernames)
11 {
12  const double energy = eos.dp2e(cell.density, cell.pressure, cell.tracers,tracerstickernames.tracer_names);
13  const double sound_speed = eos.dp2c(cell.density, cell.pressure, cell.tracers,tracerstickernames.tracer_names);
14  return Primitive(cell.density, cell.pressure, cell.velocity, energy, sound_speed);
15 }
16 
18  const Vector2D& axis)
19 {
20  return Primitive(p.Density,
21  p.Pressure,
22  Reflect(p.Velocity, axis),
23  p.Energy,
24  p.SoundSpeed);
25 }
26 
28  const Vector2D& p)
29 {
30  return v - p*ScalarProd(v, p) / ScalarProd(p, p);
31 }
32 
33 namespace
34 {
35  template<class S, class T> class Transform
36  {
37  public:
38 
39  virtual T operator()(const S& s) const = 0;
40 
41  virtual ~Transform(void) {}
42  };
43 
44  class CellIndexValidator : public Transform<int, bool>
45  {
46  public:
47 
48  explicit CellIndexValidator(const int point_no) :
49  point_no_(point_no) {}
50 
51  bool operator()(const int& index) const
52  {
53  return index >= 0 && index < point_no_;
54  }
55 
56  private:
57  const int point_no_;
58  };
59 
60  template<class S, class T> std::pair<T, T> transform_pair
61  (const std::pair<S, S>& s, const Transform<S, T>& t)
62  {
63  return std::pair<T, T>(t(s.first), t(s.second));
64  }
65 
66  class RiemannProblemInput
67  {
68  public:
69 
70  Primitive left;
71  Primitive right;
72  double velocity;
73  Vector2D n;
74  Vector2D p;
75 
76  RiemannProblemInput(void) :
77  left(), right(), velocity(0), n(), p() {}
78  };
79 
80  RiemannProblemInput riemann_reduce
81  (const Tessellation& tess,
82  const vector<Vector2D>& edge_velocities,
83  const vector<ComputationalCell>& cells,
84  const EquationOfState& eos,
85  const size_t& edge_index,
86  TracerStickerNames const& tracerstickernames)
87  {
88  const Edge& edge = tess.getAllEdges().at
89  (edge_index);
90  RiemannProblemInput res;
91  res.p = Parallel(edge);
92  res.p *= 1.0/abs(res.p);
93  res.n = tess.GetMeshPoint(edge.neighbors.second) -
94  tess.GetMeshPoint(edge.neighbors.first);
95  res.n *= 1.0 / abs(res.n);
96  const std::pair<bool, bool> flags = transform_pair
97  (edge.neighbors, CellIndexValidator(tess.GetPointNo()));
98  assert(flags.first || flags.second);
99  if (!flags.first)
100  {
101  res.right = convert_to_primitive
102  (cells[static_cast<size_t>(edge.neighbors.second)], eos,tracerstickernames);
103  if (tess.GetOriginalIndex(edge.neighbors.second) == tess.GetOriginalIndex(edge.neighbors.first))
104  res.left = reflect(res.right, res.p);
105  else
106  res.left = convert_to_primitive(cells[static_cast<size_t>(edge.neighbors.first)], eos,tracerstickernames);
107  }
108  else if (!flags.second) {
109  res.left = convert_to_primitive
110  (cells[static_cast<size_t>(edge.neighbors.first)], eos,tracerstickernames);
111  if (tess.GetOriginalIndex(edge.neighbors.second) == tess.GetOriginalIndex(edge.neighbors.first))
112  res.right = reflect(res.left, res.p);
113  else
114  res.right = convert_to_primitive
115  (cells[static_cast<size_t>(edge.neighbors.second)], eos,tracerstickernames);
116  }
117  else
118  {
119  const size_t left_index = static_cast<size_t>(edge.neighbors.first);
120  const size_t right_index = static_cast<size_t>(edge.neighbors.second);
121  res.left = convert_to_primitive(cells[left_index], eos,tracerstickernames);
122  res.right = convert_to_primitive(cells[right_index], eos,tracerstickernames);
123  }
124  res.velocity = ScalarProd
125  (res.n, edge_velocities.at(edge_index)) /
126  abs(res.n);
127  return res;
128  }
129 }
130 
131 namespace {
132  Primitive rotate(const Primitive& primitive,
133  const Vector2D& n,
134  const Vector2D& p)
135  {
136  return Primitive(primitive.Density,
137  primitive.Pressure,
138  Vector2D(Projection(primitive.Velocity, n),
139  Projection(primitive.Velocity, p)),
140  primitive.Energy,
141  primitive.SoundSpeed);
142  }
143 
144  Conserved rotate_back(const Conserved& c,
145  const Vector2D& n,
146  const Vector2D& p)
147  {
148  return Conserved(c.Mass,
149  c.Momentum.x*n +
150  c.Momentum.y*p ,
151  c.Energy);
152  }
153 }
154 
156 (const RiemannSolver& rs,
157  const Primitive& left,
158  const Primitive& right,
159  const double velocity,
160  const Vector2D& n,
161  const Vector2D& p)
162 {
163  return rotate_back(rs(rotate(left, n, p),
164  rotate(right, n, p),
165  velocity),
166  n, p);
167 }
168 
169 Conserved SimpleFluxCalculator::calcHydroFlux
170 (const Tessellation& tess,
171  const vector<Vector2D>& edge_velocities,
172  const vector<ComputationalCell>& cells,
173  const EquationOfState& eos,
174  const size_t i,
175  TracerStickerNames const& tracerstickernames) const
176 {
177  RiemannProblemInput rpi = riemann_reduce
178  (tess,
179  edge_velocities,
180  cells,
181  eos,
182  i,
183  tracerstickernames);
185  (rs_,
186  rpi.left,
187  rpi.right,
188  rpi.velocity,
189  rpi.n,
190  rpi.p);
191 }
192 
193 namespace
194 {
195  double calc_tracer_flux(size_t i,
196  const Tessellation& tess,
197  const vector<ComputationalCell>& cells,
198  size_t tracer_index,
199  const Conserved& hf)
200  {
201  const Edge& edge = tess.GetEdge(static_cast<int>(i));
202  if (hf.Mass > 0 &&
203  edge.neighbors.first >= 0 &&
204  (edge.neighbors.first < tess.GetPointNo() || tess.GetOriginalIndex(edge.neighbors.first) !=
205  tess.GetOriginalIndex(edge.neighbors.second)))
206  return hf.Mass*
207  cells[static_cast<size_t>(edge.neighbors.first)].tracers.at(tracer_index);
208  if (hf.Mass < 0 &&
209  edge.neighbors.second >= 0 &&
210  (edge.neighbors.second < tess.GetPointNo() || tess.GetOriginalIndex(edge.neighbors.first) !=
211  tess.GetOriginalIndex(edge.neighbors.second)))
212  return hf.Mass*
213  cells[static_cast<size_t>(edge.neighbors.second)].tracers.at(tracer_index);
214  return 0;
215  }
216 }
217 
218 vector<Extensive> SimpleFluxCalculator::operator()
219 (const Tessellation& tess,
220  const vector<Vector2D>& edge_velocities,
221  const vector<ComputationalCell>& cells,
222  const vector<Extensive>& /*extensives_*/,
223  const CacheData& /*cd*/,
224  const EquationOfState& eos,
225  const double /*time*/,
226  const double /*dt*/,
227  TracerStickerNames const& tracerstickernames) const
228 {
229  vector<Extensive> res(tess.getAllEdges().size());
230  for (size_t i = 0; i < tess.getAllEdges().size(); ++i)
231  {
232  const Conserved hydro_flux = calcHydroFlux
233  (tess, edge_velocities, cells, eos, i,tracerstickernames);
234  res[i].mass = hydro_flux.Mass;
235  res[i].momentum = hydro_flux.Momentum;
236  res[i].energy = hydro_flux.Energy;
237  size_t N = cells[0].tracers.size();
238  if (N > 0)
239  {
240  res[i].tracers.resize(N);
241  for (size_t j = 0; j < N; ++j)
242  res[i].tracers[j] = calc_tracer_flux(i, tess, cells, j, hydro_flux);
243  }
244  }
245  return res;
246 }
Set of conserved variables (extensive)
Vector2D Momentum
Momentum.
double Density
Density.
double SoundSpeed
Speed of sound.
Vector2D remove_parallel_component(const Vector2D &v, const Vector2D &p)
Remove parallel component of a vector.
Vector2D Parallel(Edge const &edge)
Calculates a unit vector parallel to an edge.
Definition: Edge.cpp:83
Abstract class for tessellation.
virtual int GetPointNo(void) const =0
Get Total number of mesh generating points.
virtual int GetOriginalIndex(int point) const
Returns the original index of the duplicated point.
Definition: tessellation.cpp:5
Vector3D Reflect(Vector3D const &v, Vector3D const &normal)
Reflect vector.
Definition: Vector3D.cpp:203
Primitive convert_to_primitive(const ComputationalCell &cell, const EquationOfState &eos, TracerStickerNames const &tracerstickernames)
Converts computational cell to primitive variables.
double Projection(Vector3D const &v1, Vector3D const &v2)
Calculates the projection of one vector in the direction of the second.
Definition: Vector3D.cpp:193
Vector2D Velocity
Velocity.
Interface between two cells.
Definition: Edge.hpp:13
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
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 Energy
Total energy (kinetic + thermal)
double y
Component in the y direction.
Definition: geometry.hpp:48
tvector tracers
Tracers (can transfer from one cell to another)
Simple flux calculator.
virtual Edge const & GetEdge(int index) const =0
Returns edge (interface between cells)
SimpleFluxCalculator(const RiemannSolver &rs)
Class constructor.
double pressure
Pressure.
Base class for Riemann solver.
Conserved rotate_solve_rotate_back(const RiemannSolver &rs, const Primitive &left, const Primitive &right, const double velocity, const Vector2D &n, const Vector2D &p)
Rotates, solve riemann problem and rotates results back.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Definition: Vector3D.cpp:185
virtual const vector< Edge > & getAllEdges(void) const =0
Returns reference to the list of all edges.
Base class for equation of state.
Primitive reflect(const Primitive &p, const Vector2D &axis)
Reflects velocity about axis.
Container for cache data.
Definition: cache_data.hpp:14
std::vector< std::string > tracer_names
The names of the tracers.
vector< Extensive > operator()(const Tessellation &tess, const vector< Vector2D > &edge_velocities, const vector< ComputationalCell > &cells, const vector< Extensive > &extensives, const CacheData &cd, const EquationOfState &eos, const double time, const double dt, const TracerStickerNames &tracerstickernames) const
Calculates fluxes.
Class for keeping the names of the tracers and stickers.
std::pair< int, int > neighbors
Neighboring cells.
Definition: Edge.hpp:21
double Pressure
Pressure.
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.
double Energy
Thermal energy per unit mass, entahalpy in relativistic case.
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
Primitive hydrodynamic variables.
Vector2D velocity
Velocity.
2D Mathematical vector
Definition: geometry.hpp:15
double x
Component in the x direction.
Definition: geometry.hpp:45
Computational cell.