cell_updater_2d.cpp
1 #include "cell_updater_2d.hpp"
2 #include <iostream>
3 
5 
6 namespace
7 {
8  class SolveVelocity
9  {
10 
11  public:
12  double a0_, a1_, a2_, a3_, a4_;
13 
14  SolveVelocity(double a0, double a1, double a2, double a3, double a4) :a0_(a0), a1_(a1), a2_(a2), a3_(a3), a4_(a4) {}
15 
16  double operator()(const double v) const
17  {
18  return v * v*(a4_*v*v + a3_ * v + a2_) +v*a1_ +a0_;
19  //return a4_ * v*v*v*v + a3_ * v*v*v + a2_ * v*v + a1_ * v + a0_;
20  }
21 
22  double Deriv(const double v) const
23  {
24  return v * v*(4 * a4_*v + a3_ * 3) + 2 * a2_*v + a1_;
25  //return 4 * a4_*v*v*v + 3 * a3_*v*v + 2 * a2_ * v + a1_;
26  }
27  };
28 
29  double DoNewtonRapshon(SolveVelocity const& solve, double val)
30  {
31  size_t counter = 1;
32  double f0 = solve(val);
33  double new_val = val - f0 / solve.Deriv(val);
34  while (std::abs(new_val - val) > 1e-12 && (std::abs(f0) > (1e-12*solve.a0_)))
35  {
36  ++counter;
37  val = new_val;
38  f0 = solve(val);
39  new_val = std::min(1.0, val - f0 / solve.Deriv(val));
40  if (counter > 99)
41  {
42  std::cout << "Bad convergence in simple cell updater, too mant iterations in finding velocity";
43  //std::cout << "E = " << E << " M = " << M << " D = " << cell.mass << std::endl;
44  throw;
45  }
46  }
47  return new_val;
48  }
49 }
50 
51 double GetVelocity(Extensive const& cell, double G)
52 {
53  double M = std::sqrt(ScalarProd(cell.momentum, cell.momentum));
54  // Add rest mass energy
55  double E = cell.energy + cell.mass;
56  SolveVelocity tosolve(M*M, -2 * G*M*E, G*G*E*E + 2 * (G - 1)*M*M - (G - 1)*(G - 1)*cell.mass*cell.mass, -2 * G*(G - 1)*M*E, (G - 1)*(G - 1)*(cell.mass*cell.mass + M * M));
57 
58  double vmin = (1e6*M < cell.mass) ? 0 : (G*E - std::sqrt((G*E)*(G*E) - 4 * (G - 1)*M*M)) / (2 * M*(G - 1));
59  if((G*E)*(G*E) - 4 * (G - 1)*M*M < 0)
60  vmin = 0;
61  double vmax = std::min(1.0, M / E + 1e-6);
62  return DoNewtonRapshon(tosolve, 0.5*(vmin + vmax));
63 }
Extensive variables.
Definition: extensive.hpp:18
Vector2D momentum
momentum, in relativity it is = rho*h*gamma*v
Definition: extensive.hpp:31
double mass
rest mass times gamma
Definition: extensive.hpp:25
double energy
energy, in relativity it is = rho*h*gamma^2-P-rho
Definition: extensive.hpp:28
double GetVelocity(Extensive const &cell, double G)
Calculates velocity from extensive in SR.
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Definition: Vector3D.cpp:185
Base class for cell update scheme.
virtual ~CellUpdater(void)
Class destructor.
double min(vector< double > const &v)
Returns the minimal term in a vector.
Definition: utils.cpp:44
virtual vector< ComputationalCell > operator()(const Tessellation &tess, const PhysicalGeometry &pg, const EquationOfState &eos, vector< Extensive > &extensives, const vector< ComputationalCell > &old, const CacheData &cd, const TracerStickerNames &tracerstickername, double time) const =0
Calculates the computational cells.
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44