Memosa-FVM  0.2
ShockTube< T > Class Template Reference

#include <ShockTube.h>

Collaboration diagram for ShockTube< T >:

Public Types

typedef Vector< T, 3 > Vec3
 

Public Member Functions

 ShockTube (const int nCells)
 
getPressure (const Vec3 &q)
 
Vec3 getConservedVars (const T rho, const T p, const T u)
 
Vec3 getFlux (const Vec3 &q)
 
Vec3 getRoeFlux_Frink (const Vec3 &q0, const Vec3 &q1)
 
Vec3 getRoeFlux (const Vec3 &q0, const Vec3 &q1)
 
void init ()
 
void solve (const double dt, const int nsteps)
 
ArrayBasegetSolution ()
 
ArrayBasegetPressure ()
 
ArrayBasegetDensity ()
 
ArrayBasegetVelocity ()
 
ArrayBasegetMachNumber ()
 

Public Attributes

pL
 
pR
 
rhoL
 
rhoR
 
uL
 
uR
 
const int _nCells
 
_gmm
 
const int _nStages
 
Array< double > _stageCoeffs
 
Array< Vec3q
 
Array< T > pressure
 
Array< T > rho
 
Array< T > u
 
Array< T > M
 

Detailed Description

template<class T>
class ShockTube< T >

Definition at line 12 of file ShockTube.h.

Member Typedef Documentation

template<class T >
typedef Vector<T,3> ShockTube< T >::Vec3

Definition at line 16 of file ShockTube.h.

Constructor & Destructor Documentation

template<class T >
ShockTube< T >::ShockTube ( const int  nCells)
inline

Definition at line 18 of file ShockTube.h.

References ShockTube< T >::_stageCoeffs.

18  :
19  pL(10.0),
20  pR(1.0),
21  rhoL(8.0),
22  rhoR(1.0),
23  uL(0),
24  uR(0),
25  _nCells(nCells),
26  _gmm(0.4),
27  _nStages(5),
28  _stageCoeffs(5),
29  q(_nCells),
31  rho(nCells),
32  u(nCells),
33  M(nCells)
34  {
35  _stageCoeffs[0] = 0.25;
36  _stageCoeffs[1] = 1.0/6.0;
37  _stageCoeffs[2] = 0.375;
38  _stageCoeffs[3] = 0.5;
39  _stageCoeffs[4] = 1;
40  }
Array< double > _stageCoeffs
Definition: ShockTube.h:249
Array< T > pressure
Definition: ShockTube.h:251
Array< Vec3 > q
Definition: ShockTube.h:250
const int _nStages
Definition: ShockTube.h:248
const int _nCells
Definition: ShockTube.h:246
Array< T > M
Definition: ShockTube.h:254
Array< T > rho
Definition: ShockTube.h:252
Array< T > u
Definition: ShockTube.h:253

Member Function Documentation

template<class T >
Vec3 ShockTube< T >::getConservedVars ( const T  rho,
const T  p,
const T  u 
)
inline

Definition at line 48 of file ShockTube.h.

References ShockTube< T >::_gmm, ShockTube< T >::q, ShockTube< T >::rho, and ShockTube< T >::u.

Referenced by ShockTube< T >::init().

49  {
50  Vec3 q;
51  q[0] = rho;
52  q[1] = rho*u;
53  q[2] = p/_gmm + 0.5*rho*u*u;
54  return q;
55  }
Array< Vec3 > q
Definition: ShockTube.h:250
Vector< T, 3 > Vec3
Definition: ShockTube.h:16
Array< T > rho
Definition: ShockTube.h:252
Array< T > u
Definition: ShockTube.h:253
template<class T >
ArrayBase& ShockTube< T >::getDensity ( )
inline

Definition at line 234 of file ShockTube.h.

References ShockTube< T >::rho.

234 {return rho;}
Array< T > rho
Definition: ShockTube.h:252
template<class T >
Vec3 ShockTube< T >::getFlux ( const Vec3 q)
inline

Definition at line 57 of file ShockTube.h.

References ShockTube< T >::getPressure(), and ShockTube< T >::u.

Referenced by ShockTube< T >::getRoeFlux(), and ShockTube< T >::getRoeFlux_Frink().

58  {
59  const T u = q[1]/q[0];
60  const T p = getPressure(q);
61  Vec3 flux;
62  flux[0] = q[1];
63  flux[1] = q[0]*u*u + p;
64  flux[2] = (q[2]+p)*u;
65  return flux;
66  }
ArrayBase & getPressure()
Definition: ShockTube.h:233
Array< Vec3 > q
Definition: ShockTube.h:250
Vector< T, 3 > Vec3
Definition: ShockTube.h:16
Array< T > u
Definition: ShockTube.h:253
template<class T >
ArrayBase& ShockTube< T >::getMachNumber ( )
inline

Definition at line 236 of file ShockTube.h.

References ShockTube< T >::M.

236 {return M;}
Array< T > M
Definition: ShockTube.h:254
template<class T >
T ShockTube< T >::getPressure ( const Vec3 q)
inline

Definition at line 42 of file ShockTube.h.

References ShockTube< T >::_gmm, and ShockTube< T >::u.

43  {
44  const T u = q[1]/q[0];
45  return (q[2] - 0.5*(q[0]*u*u))*_gmm;
46  }
Array< Vec3 > q
Definition: ShockTube.h:250
Array< T > u
Definition: ShockTube.h:253
template<class T >
ArrayBase& ShockTube< T >::getPressure ( )
inline
template<class T >
Vec3 ShockTube< T >::getRoeFlux ( const Vec3 q0,
const Vec3 q1 
)
inline

Definition at line 120 of file ShockTube.h.

References ShockTube< T >::_gmm, fabs(), ShockTube< T >::getFlux(), ShockTube< T >::getPressure(), and sqrt().

Referenced by ShockTube< T >::solve().

121  {
122  const T half(0.5);
123 
124  const T sr0 = sqrt(q0[0]);
125  const T sr1 = sqrt(q1[0]);
126 
127  const T sr0psr1 = sr0 + sr1;
128  const T u0 = q0[1]/q0[0];
129  const T u1 = q1[1]/q1[0];
130 
131  const T p0 = getPressure(q0);
132  const T p1 = getPressure(q1);
133 
134  const T h0 = (q0[2]+p0) / q0[0];
135  const T h1 = (q1[2]+p1) / q1[0];
136 
137  const T rho_f = sr0 * sr1;
138  const T u_f = (sr0*u0 + sr1*u1) / sr0psr1;
139  const T h_f = (sr0*h0 + sr1*h1) / sr0psr1;
140 
141  const T c_f = sqrt( _gmm * (h_f - half*u_f*u_f));
142 
143  const T abs_uf = fabs(u_f);
144  const T abs_upc = fabs(u_f + c_f);
145  const T abs_umc = fabs(u_f - c_f);
146 
147 
148  const Vec3 flux0 = getFlux(q0);
149  const Vec3 flux1 = getFlux(q1);
150 
151  const T dr = q1[0]-q0[0];
152  const T rdu = rho_f*(u1-u0);
153 
154  const T dp = p1-p0;
155 
156  const T dpbyc2 = dp/(c_f*c_f);
157 
158  const T a0 = half*(dpbyc2 + rdu/c_f)*abs_upc;
159  const T a4 = half*(dpbyc2 - rdu/c_f)*abs_umc;
160 
161  const T drmdpbyc2 = dr-dpbyc2;
162  Vec3 dFlux;
163 
164  dFlux[0] = abs_uf*drmdpbyc2 + a0 + a4;
165  dFlux[1] = abs_uf*drmdpbyc2*u_f + a0*(u_f+c_f) + a4*(u_f-c_f);
166  dFlux[2] = abs_uf*(half*drmdpbyc2*u_f*u_f) + a0*(h_f+u_f*c_f)
167  + a4*(h_f-u_f*c_f);
168 
169  Vec3 flux(flux0+flux1-dFlux);
170  return half*flux;
171  }
ArrayBase & getPressure()
Definition: ShockTube.h:233
Tangent sqrt(const Tangent &a)
Definition: Tangent.h:317
Vector< T, 3 > Vec3
Definition: ShockTube.h:16
Tangent fabs(const Tangent &a)
Definition: Tangent.h:312
Vec3 getFlux(const Vec3 &q)
Definition: ShockTube.h:57
template<class T >
Vec3 ShockTube< T >::getRoeFlux_Frink ( const Vec3 q0,
const Vec3 q1 
)
inline

Definition at line 68 of file ShockTube.h.

References ShockTube< T >::_gmm, fabs(), ShockTube< T >::getFlux(), ShockTube< T >::getPressure(), and sqrt().

69  {
70  const T half(0.5);
71 
72  const T sr0 = sqrt(q0[0]);
73  const T sr1 = sqrt(q1[0]);
74 
75  const T sr0psr1 = sr0 + sr1;
76  const T u0 = q0[1]/q0[0];
77  const T u1 = q1[1]/q1[0];
78 
79  const T p0 = getPressure(q0);
80  const T p1 = getPressure(q1);
81 
82  const T h0 = (q0[2]+p0) / q0[0];
83  const T h1 = (q1[2]+p1) / q1[0];
84 
85  const T rho_f = sr0 * sr1;
86  const T u_f = (sr0*u0 + sr1*u1) / sr0psr1;
87  const T h_f = (sr0*h0 + sr1*h1) / sr0psr1;
88 
89  const T c_f = sqrt( _gmm * (h_f - half*u_f*u_f));
90 
91  const T abs_uf = fabs(u_f);
92  const T abs_upc = fabs(u_f + c_f);
93  const T abs_umc = fabs(u_f - c_f);
94 
95 
96  const Vec3 flux0 = getFlux(q0);
97  const Vec3 flux1 = getFlux(q1);
98 
99  const T dr = q1[0]-q0[0];
100  const T rdu = rho_f*(u1-u0);
101 
102  const T dp = p1-p0;
103 
104  const T dpc2 = dp*c_f*c_f;
105 
106  const T a0 = half*(dpc2 + rdu*c_f)*abs_upc;
107  const T a4 = half*(dpc2 - rdu*c_f)*abs_umc;
108 
109  const T drmdpc2 = dr-dpc2;
110  Vec3 dFlux;
111 
112  dFlux[0] = abs_uf*drmdpc2 + a0 + a4;
113  dFlux[1] = abs_uf*drmdpc2*u_f + a0*(u_f+c_f) + a4*(u_f-c_f);
114  dFlux[2] = abs_uf*(half*drmdpc2*u_f*u_f) + a0*(h_f+u_f*c_f) + a4*(h_f-u_f*c_f);
115 
116  Vec3 flux(flux0+flux1-dFlux);
117  return half*flux;
118  }
ArrayBase & getPressure()
Definition: ShockTube.h:233
Tangent sqrt(const Tangent &a)
Definition: Tangent.h:317
Vector< T, 3 > Vec3
Definition: ShockTube.h:16
Tangent fabs(const Tangent &a)
Definition: Tangent.h:312
Vec3 getFlux(const Vec3 &q)
Definition: ShockTube.h:57
template<class T >
ArrayBase& ShockTube< T >::getSolution ( )
inline

Definition at line 232 of file ShockTube.h.

References ShockTube< T >::q.

232 {return q;}
Array< Vec3 > q
Definition: ShockTube.h:250
template<class T >
ArrayBase& ShockTube< T >::getVelocity ( )
inline

Definition at line 235 of file ShockTube.h.

References ShockTube< T >::u.

235 {return u;}
Array< T > u
Definition: ShockTube.h:253
template<class T >
void ShockTube< T >::init ( )
inline

Definition at line 174 of file ShockTube.h.

References ShockTube< T >::_nCells, ShockTube< T >::getConservedVars(), ShockTube< T >::pL, ShockTube< T >::pR, ShockTube< T >::q, ShockTube< T >::rhoL, ShockTube< T >::rhoR, ShockTube< T >::uL, and ShockTube< T >::uR.

175  {
176  Vec3 qL(getConservedVars(rhoL, pL, uL));
177  Vec3 qR(getConservedVars(rhoR, pR, uR));
178 
179  for(int i=0; i<_nCells/2; i++)
180  q[i] = qL;
181 
182  for(int i=_nCells/2; i<_nCells; i++)
183  q[i] = qR;
184  }
Vec3 getConservedVars(const T rho, const T p, const T u)
Definition: ShockTube.h:48
Array< Vec3 > q
Definition: ShockTube.h:250
const int _nCells
Definition: ShockTube.h:246
Vector< T, 3 > Vec3
Definition: ShockTube.h:16
template<class T >
void ShockTube< T >::solve ( const double  dt,
const int  nsteps 
)
inline

Definition at line 186 of file ShockTube.h.

References ShockTube< T >::_gmm, ShockTube< T >::_nCells, ShockTube< T >::_nStages, ShockTube< T >::_stageCoeffs, ShockTube< T >::getPressure(), ShockTube< T >::getRoeFlux(), ShockTube< T >::M, ShockTube< T >::pressure, ShockTube< T >::q, ShockTube< T >::rho, sqrt(), ShockTube< T >::u, and Array< T >::zero().

187  {
188  const T dx = T(1.0)/_nCells;
189 
190  Array<Vec3> R(_nCells);
191 
192  Array<Vec3> qN(_nCells);
193 
194  for(int n=0; n<nsteps; n++)
195  {
196  cout << "step " << n << endl;
197  qN = q;
198  for(int s=0; s<_nStages; s++)
199  {
200  R.zero();
201 
202  for(int f=1; f<_nCells; f++)
203  {
204  int c0 = f-1;
205  int c1 = f;
206  const Vec3 flux = getRoeFlux(q[c0], q[c1]);
207  R[c0] += flux;
208  R[c1] -= flux;
209  }
210 
211  R[0] -= getRoeFlux(q[0],q[0]);
212  R[_nCells-1] += getRoeFlux(q[_nCells-1],q[_nCells-1]);
213 
214  const T sCoeff = _stageCoeffs[s]*dt/dx;
215  for(int c=0; c<_nCells; c++)
216  {
217  q[c] = qN[c] - sCoeff*R[c];
218  }
219  }
220  }
221 
222  for(int c=0; c<_nCells; c++)
223  {
224  rho[c] = q[c][0];
225  pressure[c] = getPressure(q[c]);
226  u[c] = q[c][1]/q[c][0];
227  T soundSpeed = sqrt((_gmm+1)*pressure[c]/rho[c]);
228  M[c] = u[c]/soundSpeed;
229  }
230  }
Array< double > _stageCoeffs
Definition: ShockTube.h:249
Array< T > pressure
Definition: ShockTube.h:251
ArrayBase & getPressure()
Definition: ShockTube.h:233
Array< Vec3 > q
Definition: ShockTube.h:250
Tangent sqrt(const Tangent &a)
Definition: Tangent.h:317
const int _nStages
Definition: ShockTube.h:248
const int _nCells
Definition: ShockTube.h:246
Vector< T, 3 > Vec3
Definition: ShockTube.h:16
Definition: Array.h:14
Array< T > M
Definition: ShockTube.h:254
Vec3 getRoeFlux(const Vec3 &q0, const Vec3 &q1)
Definition: ShockTube.h:120
Array< T > rho
Definition: ShockTube.h:252
Array< T > u
Definition: ShockTube.h:253

Member Data Documentation

template<class T >
const int ShockTube< T >::_nCells

Definition at line 246 of file ShockTube.h.

Referenced by ShockTube< T >::init(), and ShockTube< T >::solve().

template<class T >
const int ShockTube< T >::_nStages

Definition at line 248 of file ShockTube.h.

Referenced by ShockTube< T >::solve().

template<class T >
Array<double> ShockTube< T >::_stageCoeffs

Definition at line 249 of file ShockTube.h.

Referenced by ShockTube< T >::ShockTube(), and ShockTube< T >::solve().

template<class T >
Array<T> ShockTube< T >::M

Definition at line 254 of file ShockTube.h.

Referenced by ShockTube< T >::getMachNumber(), and ShockTube< T >::solve().

template<class T >
T ShockTube< T >::pL

Definition at line 239 of file ShockTube.h.

Referenced by ShockTube< T >::init().

template<class T >
T ShockTube< T >::pR

Definition at line 240 of file ShockTube.h.

Referenced by ShockTube< T >::init().

template<class T >
Array<T> ShockTube< T >::pressure

Definition at line 251 of file ShockTube.h.

Referenced by ShockTube< T >::getPressure(), and ShockTube< T >::solve().

template<class T >
Array<T> ShockTube< T >::rho
template<class T >
T ShockTube< T >::rhoL

Definition at line 241 of file ShockTube.h.

Referenced by ShockTube< T >::init().

template<class T >
T ShockTube< T >::rhoR

Definition at line 242 of file ShockTube.h.

Referenced by ShockTube< T >::init().

template<class T >
T ShockTube< T >::uL

Definition at line 243 of file ShockTube.h.

Referenced by ShockTube< T >::init().

template<class T >
T ShockTube< T >::uR

Definition at line 244 of file ShockTube.h.

Referenced by ShockTube< T >::init().


The documentation for this class was generated from the following file: