ConservativeForce.cpp
1 #include "ConservativeForce.hpp"
2 #include "../../../misc/lazy_list.hpp"
3 
4 using std::min;
5 using std::sqrt;
6 
7 namespace
8 {
9  Vector2D MassFlux(Tessellation const& tess, int point,
10  vector<Extensive> const& fluxes)
11  {
12  Vector2D dm;
13  vector<int> edge_index = tess.GetCellEdges(point);
14  //Vector2D center = tess.GetCellCM(point);
15  Vector2D center = tess.GetMeshPoint(point);
16  int n = static_cast<int>(edge_index.size());
17  Edge edge;
18  for (int i = 0; i < n; ++i)
19  {
20  edge = tess.GetEdge(edge_index[static_cast<size_t>(i)]);
21  if (point == edge.neighbors.first)
22  {
23  dm -= edge.GetLength() * fluxes[static_cast<size_t>(edge_index[static_cast<size_t>(i)])].mass *
24  //(center - 0.5*(edge.vertices.first + edge.vertices.second));
25  (center - tess.GetMeshPoint(edge.neighbors.second));
26  }
27  else
28  if (point == edge.neighbors.second)
29  {
30  dm += edge.GetLength() * fluxes[static_cast<size_t>(edge_index[static_cast<size_t>(i)])].mass *
31  //(center - 0.5*(edge.vertices.first + edge.vertices.second));
32  (center - tess.GetMeshPoint(edge.neighbors.first));
33  }
34  else
35  throw UniversalError("Error in ConservativeForce MassFlux: Cell and edge are not mutual neighbors");
36  }
37  return dm;
38  }
39 }
40 
42  acc_(acc), mass_flux_(mass_flux) {}
43 
45 
46 vector<Extensive> ConservativeForce::operator()
47 (const Tessellation& tess,
48  const PhysicalGeometry& /*pg*/,
49  const CacheData& cd,
50  const vector<ComputationalCell>& cells,
51  const vector<Extensive>& fluxes,
52  const vector<Vector2D>& point_velocities,
53  const double t,
54  TracerStickerNames const& tracerstickernames) const
55 {
56  vector<Extensive> res(static_cast<size_t>(tess.GetPointNo()));
57  for (size_t i = 0; i < res.size(); ++i)
58  {
59  const Vector2D acc = acc_(tess, cells, fluxes, t, static_cast<int>(i),tracerstickernames);
60  const double volume = cd.volumes[i];
61  res[i].mass = 0;
62  res[i].momentum = volume*cells[i].density*acc;
63  if (!mass_flux_)
64  res[i].energy = volume*cells[i].density*ScalarProd(acc, cells[i].velocity);
65  else
66  {
67  const Vector2D mass_flux = MassFlux(tess, static_cast<int>(i), fluxes);
68  res[i].energy = volume*cells[i].density*ScalarProd(point_velocities[i], acc) +
69  0.5*ScalarProd(mass_flux, acc);
70  }
71  res[i].tracers.resize(tracerstickernames.tracer_names.size(),0);
72  }
73  return res;
74 }
75 
76 Acceleration::~Acceleration(void) {}
Abstract class for tessellation.
virtual int GetPointNo(void) const =0
Get Total number of mesh generating points.
Container for error reports.
Physical acceleration.
Interface between two cells.
Definition: Edge.hpp:13
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
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
ConservativeForce(const Acceleration &acc, bool mass_flux=false)
Class constructor.
Container for cache data.
Definition: cache_data.hpp:14
double min(vector< double > const &v)
Returns the minimal term in a vector.
Definition: utils.cpp:44
Class for keeping the names of the tracers and stickers.
~ConservativeForce(void)
Class destructor.
Abstract class for conservative force&#39;s acceleration.
std::pair< int, int > neighbors
Neighboring cells.
Definition: Edge.hpp:21
virtual vector< int > const & GetCellEdges(int index) const =0
Returns the indexes of a cell&#39;s edges.
2D Mathematical vector
Definition: geometry.hpp:15
double GetLength(void) const
Returns the length of the edge.
Definition: Edge.cpp:26
Base class for physical geometry.