round_cells.cpp
1 
2 #include "round_cells.hpp"
3 #ifdef RICH_MPI
4 #include <mpi.h>
5 #endif
6 
7 RoundCells::RoundCells(const PointMotion& pm, const EquationOfState& eos, OuterBoundary const& outer, double chi,
8  double eta, bool cold, double cold_speed) : pm_(pm), eos_(eos), pouter_(-1, 1, 1, -1), outer_(outer), chi_(chi), eta_(eta), cold_(cold), cold_speed_(cold_speed) {}
9 
10 RoundCells::RoundCells(const PointMotion& pm, const EquationOfState& eos, double chi,
11  double eta, bool cold, double cold_speed) : pm_(pm), eos_(eos), pouter_(-1, 1, 1, -1), outer_(pouter_), chi_(chi), eta_(eta),cold_(cold), cold_speed_(cold_speed) {}
12 
13 
14 namespace
15 {
16  void CorrectPointsOverShoot(vector<Vector2D> &v, double dt,Tessellation const& tess,OuterBoundary const&
17  outer)
18  {
19  bool halfperiodic = outer.GetBoundaryType() == HalfPeriodic;
20  // check that we don't go outside grid
21  size_t n = static_cast<size_t>(tess.GetPointNo());
22  const double inv_dt = 1.0 / dt;
23  for (size_t i = 0; i < n; ++i)
24  {
25  Vector2D point(tess.GetMeshPoint(static_cast<int>(i)));
26  double R = tess.GetWidth(static_cast<int>(i));
27  if (!halfperiodic)
28  {
29  if ((v[i].x*dt * 2 + point.x)>outer.GetGridBoundary(Right))
30  {
31  double factor = 0.25*(outer.GetGridBoundary(Right) - point.x)*inv_dt / abs(v[i]);
32  if (R*0.1 > (outer.GetGridBoundary(Right) - point.x))
33  factor *= -0.1;
34  v[i] = v[i] * factor;
35  }
36  if ((v[i].x*dt * 2 + point.x) < outer.GetGridBoundary(Left))
37  {
38  double factor = 0.25*(point.x - outer.GetGridBoundary(Left))*inv_dt / abs(v[i]);
39  if (R*0.1 > (point.x - outer.GetGridBoundary(Left)))
40  factor *= -0.1;
41  v[i] = v[i] * factor;
42  }
43  }
44  if ((v[i].y*dt * 2 + point.y)>outer.GetGridBoundary(Up))
45  {
46  double factor = 0.25*(outer.GetGridBoundary(Up) - point.y)*inv_dt / abs(v[i]);
47  if (R*0.1 > (outer.GetGridBoundary(Up) - point.y))
48  factor *= -0.1;
49  v[i] = v[i] * factor;
50  }
51  if ((v[i].y*dt * 2 + point.y)<outer.GetGridBoundary(Down))
52  {
53  double factor = 0.25*(point.y - outer.GetGridBoundary(Down))* inv_dt / abs(v[i]);
54  if (R*0.1 > (point.y - outer.GetGridBoundary(Down)))
55  factor *= -0.1;
56  v[i] = v[i] * factor;
57  }
58  }
59  return;
60  }
61 }
62 
63 Vector2D RoundCells::calc_dw(size_t i, const Tessellation& tess, const vector<ComputationalCell>& cells,
64  TracerStickerNames const& tracerstickernames) const
65 {
66  const Vector2D r = tess.GetMeshPoint(static_cast<int>(i));
67  const Vector2D s = tess.GetCellCM(static_cast<int>(i));
68  const double d = abs(s - r);
69  const double R = tess.GetWidth(static_cast<int>(i));
70  if (d < 0.9*eta_*R)
71  return Vector2D(0, 0);
72  const double c = std::max(eos_.dp2c(cells[i].density, cells[i].pressure,
73  cells[i].tracers,tracerstickernames.tracer_names), abs(cells[i].velocity));
74  return chi_*c*(s - r) / R;
75 }
76 
77 Vector2D RoundCells::calc_dw(size_t i, const Tessellation& tess, double dt,vector<ComputationalCell> const& cells,
78  TracerStickerNames const& tracerstickernames)const
79 {
80  const Vector2D r = tess.GetMeshPoint(static_cast<int>(i));
81  const Vector2D s = tess.GetCellCM(static_cast<int>(i));
82  const double d = abs(s - r);
83  const double R = tess.GetWidth(static_cast<int>(i));
84  if (d < 0.9*eta_*R)
85  return Vector2D(0, 0);
86  vector<int> neigh = tess.GetNeighbors(static_cast<int>(i));
87  size_t N = neigh.size();
88  double cs = eos_.dp2c(cells[i].density, cells[i].pressure, cells[i].tracers,tracerstickernames.tracer_names);
89  for (size_t j = 0; j < N; ++j)
90  {
91  if (tess.GetOriginalIndex(neigh[j]) == static_cast<int>(i) || neigh[j]>static_cast<int>(N))
92  continue;
93  cs = std::max(cs, eos_.dp2c(cells[static_cast<size_t>(neigh[j])].density, cells[static_cast<size_t>(neigh[j])].pressure,
94  cells[static_cast<size_t>(neigh[j])].tracers));
95  cs = std::max(cs, abs(cells[static_cast<size_t>(neigh[j])].velocity - cells[i].velocity));
96  }
97  const double c_dt = cold_speed_ * d / dt;
98  return chi_*std::max(c_dt, cs)*(s - r) / R;
99 }
100 
101 vector<Vector2D> RoundCells::operator()(const Tessellation& tess, const vector<ComputationalCell>& cells,
102  double time, TracerStickerNames const& tracerstickernames) const
103 {
104  vector<Vector2D> res = pm_(tess, cells, time,tracerstickernames);
105  res.resize(static_cast<size_t>(tess.GetPointNo()));
106  size_t N = static_cast<size_t>(tess.GetPointNo());
107  if (!cold_)
108  {
109  for (size_t i = 0; i < N; ++i)
110  {
111  res[i] += calc_dw(i, tess, cells,tracerstickernames);
112  }
113  }
114  return res;
115 }
116 
117 vector<Vector2D> RoundCells::ApplyFix(Tessellation const& tess, vector<ComputationalCell> const& cells, double time,
118  double dt, vector<Vector2D>const & velocities, TracerStickerNames const& tracerstickernames)const
119 {
120  vector<Vector2D> res = pm_.ApplyFix(tess, cells, time, dt, velocities,tracerstickernames);
121  res.resize(static_cast<size_t>(tess.GetPointNo()));
122  if (cold_)
123  {
124  const size_t n = res.size();
125  for (size_t i = 0; i < n; ++i)
126  {
127  res.at(i) += calc_dw(i, tess, dt,cells,tracerstickernames);
128  }
129  }
130  if (outer_.GetBoundaryType()!=Periodic)
131  CorrectPointsOverShoot(res, dt, tess,outer_);
132  return res;
133 }
Abstract class for tessellation.
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&#39;s CM.
virtual int GetOriginalIndex(int point) const
Returns the original index of the duplicated point.
Definition: tessellation.cpp:5
virtual Vector2D GetMeshPoint(int index) const =0
Returns Position of mesh generating point.
Correction to point velocities that keeps cells round.
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 max(vector< double > const &v)
returns the maximal term in a vector
Definition: utils.cpp:52
Abstract class for motion of mesh generating points.
vector< Vector2D > operator()(const Tessellation &tess, const vector< ComputationalCell > &cells, double time, TracerStickerNames const &tracerstickernames) const
Calculates the velocity of all mesh points.
virtual BoundaryType GetBoundaryType(void) const =0
Returns the boundary type.
Base class for equation of state.
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.
Class for keeping the names of the tracers and stickers.
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.
virtual 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: point_motion.cpp:5
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
Abstract class for geometric boundary conditions for the tessellation.
2D Mathematical vector
Definition: geometry.hpp:15
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.
RoundCells(const PointMotion &pm, const EquationOfState &eos, OuterBoundary const &outer, double chi=0.15, double eta=0.02, bool cold=false, double cold_speed=0.15)
Class constructor.
Definition: round_cells.cpp:7