3 #include "../../misc/universal_error.hpp" 8 Primitive Derivative(vector<double>
const& grid,
9 vector<Primitive>
const& cells,
12 return (cells[idx]-cells[idx-1])/
13 (0.5*(grid[idx+1]-grid[idx-1]));
17 Primitive SymmetricDerivative(vector<double>
const& grid,
18 vector<Primitive>
const& cells,
21 const double xr = 0.5*(grid[idx+2]+grid[idx+1]);
22 const double xl = 0.5*(grid[idx]+grid[idx-1]);
23 return (cells[idx+1]-cells[idx-1])/(xr-xl);
26 bool effectively_zero(
double x)
37 else if(effectively_zero(x))
45 double my_min(
double x,
double y,
double z)
50 double minmod(
double x,
double y,
double z)
52 return 0.125*(sgn(x)+sgn(y))*
64 res[i] = minmod(p1[i],p2[i],p3[i]);
70 bool slope_limiter_flag):
71 second_order_time_(second_order_time),
72 slope_limiter_flag_(slope_limiter_flag) {}
75 (vector<double>
const& vp,
76 vector<Primitive>
const& hv,
79 int dir,
double dt)
const 84 else if(idx==vp.size()-1)
85 return hv[vp.size()-2];
87 throw UniversalError(
"Error in PLM1D::InterpState\n Target of interpolation lies outside grid, on the left side");
89 Primitive slope_left = Derivative(vp,hv,idx-1);
90 Primitive slope_center = Derivative(vp,hv,idx);
91 Primitive slope_symmetric = SymmetricDerivative(vp,hv,idx-1);
92 Primitive slope = minmod(slope_left,slope_center,2*slope_symmetric);
93 double dx = vp[idx]-vp[idx-1];
94 if(!slope_limiter_flag_)
95 return hv[idx-1]+slope_center*dx/2;
96 if(second_order_time_)
97 return hv[idx-1]+slope*(dx/2-hv[idx-1].SoundSpeed*dt/2);
99 return hv[idx-1]+slope*dx/2;
104 return hv[vp.size()-2];
107 else if(idx==vp.size()-1)
108 throw UniversalError(
"Error in PLM1D::InterpState\n Target of interpolation lies outside grid, on the right side");
110 Primitive slope_right = Derivative(vp,hv,idx+1);
111 Primitive slope_center = Derivative(vp,hv,idx);
112 Primitive slope_symmetric = SymmetricDerivative(vp,hv,idx);
113 Primitive slope = minmod(slope_center,slope_right,2*slope_symmetric);
114 double dx = vp[idx+1]-vp[idx];
115 if(!slope_limiter_flag_)
116 return hv[idx]-slope_center*dx/2;
117 if(second_order_time_)
118 return hv[idx]-slope*(dx/2-hv[idx].SoundSpeed*dt/2);
120 return hv[idx]-slope*dx/2;
PLM1D(bool second_order_time=false, bool slope_limiter_flag=true)
Class constructor.
int GetVarNo(void) const
Returns the numbers of members.
Container for error reports.
double min(vector< double > const &v)
Returns the minimal term in a vector.
Piecewise linear method for spatial reconstruction.
double abs(Vector3D const &v)
Norm of a vector.
Primitive hydrodynamic variables.