FirstOrderHydroFlux.cpp
2 
3 namespace
4 {
5 
6  bool approx_equal(double a, double b, double thres=1e-9)
7  {
8  return thres>std::abs(a-b);
9  }
10 
11  Vector3D normalize(const Vector3D& v)
12  {
13  return v/abs(v);
14  }
15 
16  Vector3D GetParallel(Vector3D const& vel,Vector3D const& normal)
17  {
18  Vector3D parallel = vel-ScalarProd(vel,normal)*normal;
19  const double p=abs(parallel);
20  const double v=abs(vel);
21  if(approx_equal(v,0))
22  return parallel;
23  if(p<1e-8*v)
24  parallel=parallel/v;
25  else
26  parallel=parallel/p;
27  return parallel;
28  }
29  Primitive calc_primitive(const ComputationalCell& cc,
30  const EquationOfState& eos,
31  const Vector3D& normal)
32  {
34  normal),abs(cc.velocity-ScalarProd(cc.velocity,normal)*normal)),
35  eos.dp2e(cc.density,cc.pressure),eos.dp2c(cc.density,cc.pressure));
36  }
37 
38  Conserved3D CalcRigidWall(const Tessellation3D& tess,
39  const vector<ComputationalCell>& cells,const EquationOfState& eos,
40  size_t index,RiemannSolver const& rs)
41  {
42  Face const& f = tess.GetFace(index);
43  const size_t real_index = tess.IsGhostPoint(f.neighbors.first) ? 1 : 0;
44  const size_t real_cell = (real_index==1) ? f.neighbors.second : f.neighbors.first;
45  const Vector3D normal=normalize(tess.Normal(index));
46  Primitive preal=calc_primitive(cells[real_cell],eos, normal);
47  const Vector3D parallel = GetParallel(cells[real_cell].velocity,normal);
48  ComputationalCell other=cells[real_cell];
49  other.velocity=Reflect(cells[real_cell].velocity,normal);
50  Primitive pghost = calc_primitive(other,eos,normal);
51  const double fv=0;
52  Conserved sol;
53  if(real_index==0)
54  sol = rs(preal,pghost,fv);
55  else
56  sol = rs(pghost,preal,fv);
57  Conserved3D res(sol.Mass,sol.Momentum.x*normal+sol.Momentum.y*parallel,
58  sol.Energy);
59  if(!other.tracers.empty())
60  res.tracers.resize(other.tracers.size(),0);
61  return res;
62  }
63 
64  Conserved3D CalcSingleFluxInBulk(const Tessellation3D& tess,
65  const vector<ComputationalCell>& cells,const EquationOfState& eos,
66  size_t index,RiemannSolver const& rs,Vector3D const& face_vel)
67  {
68  Face const& face = tess.GetFace(index);
69  const Vector3D normal=normalize(tess.Normal(index));
70  const double fv=ScalarProd(face_vel,normal);
71  const Conserved sol = rs(calc_primitive(cells[face.neighbors.first],
72  eos,normal),calc_primitive(cells[face.neighbors.second],
73  eos,normal),fv);
74  const ComputationalCell& donor = cells[sol.Mass>0 ? face.neighbors.first :
75  face.neighbors.second];
76  const Vector3D parallel = GetParallel(donor.velocity,normal);
77  Conserved3D res(sol.Mass,sol.Momentum.x*normal+sol.Momentum.y*parallel,
78  sol.Energy);
79  if(!donor.tracers.empty())
80  res.tracers = (sol.Mass>0 ? 1 : -1)*res.mass*donor.tracers;
81  return res;
82  }
83 
84  Conserved3D CalcSingleFlux(const Tessellation3D& tess,
85  const vector<ComputationalCell>& cells,const EquationOfState& eos,
86  size_t index,RiemannSolver const& rs,Vector3D const& face_vel)
87  {
88  if(tess.BoundaryFace(index))
89  return CalcRigidWall(tess,cells,eos,index,rs);
90  return CalcSingleFluxInBulk(tess,cells,eos,index,rs,face_vel);
91  }
92 }
93 
95 
97 
98 vector<Conserved3D> FirstOrderHydroFlux::operator()(const Tessellation3D& tess,
99  const vector<ComputationalCell>& cells,const EquationOfState& eos,
100  const vector<Vector3D>& point_velocities) const
101 {
102  vector<Conserved3D> res(tess.GetTotalFacesNumber());
103  for(size_t i=0;i<res.size();++i)
104  {
105  Vector3D fv;
106  if(!tess.BoundaryFace(i))
107  {
108  Face const& f=tess.GetFace(i);
109  fv=tess.CalcFaceVelocity(f.neighbors.first,f.neighbors.second,
110  point_velocities[f.neighbors.first],point_velocities[f.neighbors.second]);
111  }
112  res[i]=CalcSingleFlux(tess,cells,eos,i,rs_,fv);
113  }
114  return res;
115 }
116 
Set of conserved variables (extensive)
Vector2D Momentum
Momentum.
std::pair< size_t, size_t > neighbors
Neighboring cells.
Definition: Face.hpp:23
Abstract class for tessellation in 3D.
virtual Vector3D CalcFaceVelocity(size_t p0, size_t p1, Vector3D const &v0, Vector3D const &v1) const =0
Calculates the velocity of a face.
virtual Vector3D Normal(size_t faceindex) const =0
Returns a vector normal to the face whose magnitude is the seperation between the neighboring points...
Vector3D Reflect(Vector3D const &v, Vector3D const &normal)
Reflect vector.
Definition: Vector3D.cpp:203
virtual bool IsGhostPoint(size_t index) const =0
Checks if a point is a ghost point or not.
Container for the hydrodynamic variables.
virtual double dp2c(double d, double p, tvector const &tracers=tvector(), vector< string > const &tracernames=vector< string >()) const =0
Calculates the speed of sound.
~FirstOrderHydroFlux(void)
Class destructor.
double Energy
Total energy (kinetic + thermal)
double y
Component in the y direction.
Definition: geometry.hpp:48
Class for flux calculator for first order hydro. Assumes rigid walls as default.
FirstOrderHydroFlux(RiemannSolver const &rs)
Class constructor.
Base class for Riemann solver.
3D Mathematical vector
Definition: Vector3D.hpp:15
double ScalarProd(Vector3D const &v1, Vector3D const &v2)
Scalar product of two vectors.
Definition: Vector3D.cpp:185
Base class for equation of state.
virtual Face const & GetFace(size_t index) const =0
Returns Face (interface between cells)
Vector2D normalize(const Vector2D &v)
Normalized a vector.
Definition: geometry.cpp:158
virtual bool BoundaryFace(size_t index) const =0
Returns if the face is a boundary one.
virtual double dp2e(double d, double p, tvector const &tracers=tvector(), vector< string > const &tracernames=vector< string >()) const =0
Calculates the thermal energy per unit mass.
virtual size_t GetTotalFacesNumber(void) const =0
Returns the total number of faces.
double abs(Vector3D const &v)
Norm of a vector.
Definition: Vector3D.cpp:44
Primitive hydrodynamic variables.
vector< Conserved3D > operator()(const Tessellation3D &tess, const vector< ComputationalCell > &cells, const EquationOfState &eos, const vector< Vector3D > &point_velocities) const
Calculates the fluxes.
2D Mathematical vector
Definition: geometry.hpp:15
Conserved variables for a 3D computational cell.
Definition: conserved_3d.hpp:7
Interface between two cells.
Definition: Face.hpp:15
double x
Component in the x direction.
Definition: geometry.hpp:45