Hllc_SR.cpp
1 #include "Hllc_SR.hpp"
2 #include <cmath>
3 #include "../newtonian/common/hydrodynamic_variables.hpp"
4 #include "../misc/universal_error.hpp"
5 #include "../misc/utils.hpp"
6 
8 {}
9 
10 
11 
12 using namespace std;
13 
14 namespace {
15  class WaveSpeeds
16  {
17  public:
18 
19  WaveSpeeds(double left_i,
20  double center_i,
21  double right_i) :
22  left(left_i),
23  center(center_i),
24  right(right_i) {}
25 
26  const double left;
27  const double center;
28  const double right;
29  };
30 }
31 
32 namespace
33 {
34  WaveSpeeds estimate_wave_speeds(Primitive const& left, Primitive const& right,double &pstar)
35  {
36  const double sig_left = left.SoundSpeed*left.SoundSpeed*(1 - ScalarProd(left.Velocity, left.Velocity)) / (1 - left.SoundSpeed*left.SoundSpeed);
37  double disct = std::sqrt(sig_left*(1 - left.Velocity.x*left.Velocity.x + sig_left));
38  const double lamda_minus_left = (left.Velocity.x - disct) / (1 + sig_left);
39  const double lamda_plus_left = (left.Velocity.x + disct) / (1 + sig_left);
40  const double sig_right = right.SoundSpeed*right.SoundSpeed*(1 - ScalarProd(right.Velocity, right.Velocity)) / (1 - right.SoundSpeed*right.SoundSpeed);
41  disct = std::sqrt(sig_right*(1 - right.Velocity.x*right.Velocity.x + sig_right));
42  const double lamda_minus_right = (right.Velocity.x - disct) / (1 + sig_right);
43  const double lamda_plus_right = (right.Velocity.x + disct) / (1 + sig_right);
44  const double sl = std::min(lamda_minus_right, lamda_minus_left);
45  const double sr = std::max(lamda_plus_left, lamda_plus_right);
46  // calculate hll flux components
47  const double El = (left.Energy+1)*left.Density / (1 - ScalarProd(left.Velocity, left.Velocity)) - left.Pressure;
48  const double Er = (right.Energy+1)*right.Density / (1 - ScalarProd(right.Velocity, right.Velocity)) - right.Pressure;
49  const double mxl = (El + left.Pressure)*left.Velocity.x;
50  const double mxr = (Er + right.Pressure)*right.Velocity.x;;
51  const double E_hll = (sr*Er - sl * El + mxl - mxr) / (sr - sl);
52  const double mx_hll = (sr*mxr - sl * mxl + (mxl*left.Velocity.x + left.Pressure) - (mxr*right.Velocity.x + right.Pressure)) / (sr - sl);
53  const double F_E = (sr * mxl - sl * mxr + sr * sl*(Er - El)) / (sr - sl);
54  const double F_mx = (sr * (mxl*left.Velocity.x + left.Pressure) - sl * (mxr*right.Velocity.x + right.Pressure) + sr * sl*(mxr - mxl)) / (sr - sl);
55  const double b = -(E_hll + F_mx);
56  const double ss = (std::abs(F_E) < std::max(1e-7*E_hll, 1e-30)) ? -mx_hll / b : (-b - std::sqrt(b*b - 4 * mx_hll*F_E)) / (2 * F_E);
57  //const double ss= (1e6*std::abs(F_E) < std::abs(E_hll+F_mx)) ? mx_hll/(E_hll+F_mx) : (((E_hll + F_mx) - std::sqrt((E_hll + F_mx)*(E_hll + F_mx) - 4 * mx_hll*F_E)) / (2 * F_E));
58  pstar = -F_E * ss + F_mx;
59  assert(sr > sl);
60  assert(sr > ss);
61  assert(ss > sl);
62  return WaveSpeeds(sl, ss, sr);
63  }
64 }
65 
66 namespace
67 {
68  UniversalError invalid_wave_speeds(Primitive const& left,
69  Primitive const& right,
70  double velocity,
71  double left_wave_speed,
72  double center_wave_speed,
73  double right_wave_speed)
74  {
75  UniversalError res("Invalid wave speeds in hllc solver");
76  res.AddEntry("left density", left.Density);
77  res.AddEntry("left pressure", left.Pressure);
78  res.AddEntry("left x velocity", left.Velocity.x);
79  res.AddEntry("left y velocity", left.Velocity.y);
80  res.AddEntry("left sound speed", left.SoundSpeed);
81  res.AddEntry("left Energy", (left.Energy+1));
82  res.AddEntry("right density", right.Density);
83  res.AddEntry("right pressure", right.Pressure);
84  res.AddEntry("right x velocity", right.Velocity.x);
85  res.AddEntry("right y velocity", right.Velocity.y);
86  res.AddEntry("right sound speed", right.SoundSpeed);
87  res.AddEntry("right Energy", (right.Energy+1));
88  res.AddEntry("interface velocity", velocity);
89  res.AddEntry("left wave speed", left_wave_speed);
90  res.AddEntry("center wave speed", center_wave_speed);
91  res.AddEntry("right wave speed", right_wave_speed);
92  return res;
93  }
94 }
95 
96 namespace
97 {
98  Conserved SR_Primitive2Flux(Primitive const& p,double edge_vel)
99  {
100  const double g_2 = 1.0 / (1 - ScalarProd(p.Velocity, p.Velocity));
101  double gamma =std::sqrt(g_2);
102  return Conserved(p.Density*gamma*(p.Velocity.x-edge_vel),Vector2D(p.Density*(p.Energy+1)*g_2*p.Velocity.x*(p.Velocity.x-edge_vel) + p.Pressure, p.Density*(p.Energy+1)*g_2*p.Velocity.y*(p.Velocity.x-edge_vel)),
103  p.Density*p.Energy*g_2*p.Velocity.x +p.Density*p.Velocity.x*(g_2-gamma)
104  -edge_vel*(p.Density*p.Energy*g_2-p.Pressure+p.Density*(g_2-gamma)));
105  }
106 
107  Conserved starred_flux(Primitive const& state, double lambda_star, double lambda,double edge_vel,double pstar)
108  {
109  const double g_2 = 1.0/(1-ScalarProd(state.Velocity,state.Velocity));
110  const double dlambda_1 = 1.0 / (lambda - lambda_star);
111  const double d = state.Density*(lambda-state.Velocity.x)*dlambda_1*std::sqrt(g_2);
112  const double mx = (state.Density*(state.Energy+1)*state.Velocity.x*g_2*(lambda - state.Velocity.x) + pstar - state.Pressure)*dlambda_1;
113  const double my = (state.Density*(state.Energy+1)*state.Velocity.y*g_2*(lambda - state.Velocity.x))*dlambda_1;
114  const double E = ((state.Density*(state.Energy+1)*g_2 - state.Pressure)*(lambda - state.Velocity.x) + pstar * lambda_star - state.Pressure*state.Velocity.x)*dlambda_1;
115  Conserved res(d*(lambda_star - edge_vel), Vector2D(mx*(lambda_star - edge_vel) + pstar,
116  my*(lambda_star - edge_vel)), (lambda_star - edge_vel)*(E - d) + pstar * lambda_star);
117  return res;
118  }
119 
120 /* Conserved Hll_flux(Primitive const& left, Primitive const& right, double ll, double lr)
121  {
122  Conserved Fl = SR_Primitive2Flux(left,0);
123  Conserved Fr = SR_Primitive2Flux(right,0);
124  double g_2l = 1.0 / (1 - ScalarProd(left.Velocity, left.Velocity));
125  Conserved Ul(left.Density*std::sqrt(g_2l), g_2l*left.Density*(left.Energy + 1)*left.Velocity, g_2l*left.Density*(left.Energy + 1)-left.Pressure);
126  double g_2r = 1.0 / (1 - ScalarProd(right.Velocity, right.Velocity));
127  Conserved Ur(right.Density*std::sqrt(g_2r), g_2r*right.Density*(right.Energy + 1)*right.Velocity, g_2r*right.Density*(right.Energy + 1)-right.Pressure);
128  return (lr*Fl - ll * Fr + ll * lr*(Ur - Ul)) / (lr - ll);
129  }*/
130 }
131 
132 Conserved Hllc_SR::operator()(Primitive const& left,Primitive const& right, double velocity) const
133 {
134  if (is_nan(right.Velocity.x))
135  throw UniversalError("Hllc_SR::Solved entered with nan");
136  double pstar = 0;
137  WaveSpeeds ws = estimate_wave_speeds(left,right,pstar);
138 
139  Conserved f_gr;
140  if (ws.left > velocity)
141  f_gr = SR_Primitive2Flux(left, velocity);
142  else if (ws.left <= velocity && ws.center >= velocity)
143  f_gr = starred_flux(left, ws.center, ws.left, velocity,pstar);
144  //f_gr = Hll_flux(left, right, ws.left, ws.right);
145  else if (ws.center < velocity &&ws.right >= velocity)
146  f_gr = starred_flux(right, ws.center, ws.right, velocity,pstar);
147  //f_gr = Hll_flux(left, right, ws.left, ws.right);
148  else if (ws.right < velocity)
149  f_gr = SR_Primitive2Flux(right, velocity);
150  else
151  throw invalid_wave_speeds(left,
152  right,
153  velocity,
154  ws.left,
155  ws.center,
156  ws.right);
157  // Remove rest mass Energy
158  //f_gr.Energy -= f_gr.Mass;
159  return f_gr;
160 }
Set of conserved variables (extensive)
Hllc_SR()
Class constructor.
Definition: Hllc_SR.cpp:7
double Density
Density.
double SoundSpeed
Speed of sound.
Container for error reports.
Vector2D Velocity
Velocity.
double max(vector< double > const &v)
returns the maximal term in a vector
Definition: utils.cpp:52
double y
Component in the y direction.
Definition: geometry.hpp:48
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Definition: Vector3D.cpp:185
double min(vector< double > const &v)
Returns the minimal term in a vector.
Definition: utils.cpp:44
Conserved operator()(Primitive const &left, Primitive const &right, double velocity) const
Solve Riemann porblme.
Definition: Hllc_SR.cpp:132
HLLC riemann solver for special relativity based on Mignone & Bodo 2005.
double Pressure
Pressure.
double Energy
Thermal energy per unit mass, entahalpy in relativistic case.
bool is_nan(double x)
Checks whether a number is a nan.
Definition: utils.cpp:19
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
void AddEntry(std::string const &field, double value)
Adds an entry to the list.
Primitive hydrodynamic variables.
2D Mathematical vector
Definition: geometry.hpp:15
double x
Component in the x direction.
Definition: geometry.hpp:45