COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Functions.cpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
8 #include "cf3/math/Defs.hpp"
9 
10 namespace cf3 {
11 namespace physics {
12 namespace euler {
13 namespace euler2d {
14 
16 
18  RowVector_NEQS& flux, Real& wave_speed )
19 {
20  const Real un = p.U.dot(normal);
21  const Real rho_un = p.rho * un;
22  flux[0] = rho_un;
23  flux[1] = rho_un * p.U[XX] + p.p * normal[XX];
24  flux[2] = rho_un * p.U[YY] + p.p * normal[YY];
25  flux[3] = rho_un * p.H;
26  wave_speed=std::abs(un)+p.c;
27 }
28 
30  RowVector_NEQS& flux )
31 {
32  const Real un = p.U.dot(normal);
33  const Real rho_un = p.rho * un;
34  flux[0] = rho_un;
35  flux[1] = rho_un * p.U[XX] + p.p * normal[XX];
36  flux[2] = rho_un * p.U[YY] + p.p * normal[YY];
37  flux[3] = rho_un * p.H;
38 }
39 
41  Real& wave_speed )
42 {
43  wave_speed=std::abs(p.U.dot(normal))+p.c;
44 }
45 
47  RowVector_NEQS& eigen_values )
48 {
49  const Real un = p.U.dot(normal);
50  eigen_values <<
51  un,
52  un,
53  un+p.c,
54  un-p.c;
55 }
56 
58  Matrix_NEQSxNEQS& right_eigenvectors )
59 {
60  const Real& u = p.U[XX];
61  const Real& v = p.U[YY];
62  const Real& nx = normal[XX];
63  const Real& ny = normal[YY];
64  const Real un = p.U.dot(normal);
65  const Real us = u*ny - v*nx;
66  right_eigenvectors <<
67  1., 0, 1, 1,
68  u, ny, u+p.c*nx, u-p.c*nx,
69  v, -nx, v+p.c*ny, v-p.c*ny,
70  0.5*p.U2, us, p.H+p.c*un, p.H-p.c*un;
71 }
72 
74  Matrix_NEQSxNEQS& left_eigenvectors )
75 {
76  const Real& u = p.U[XX];
77  const Real& v = p.U[YY];
78  const Real& nx = normal[XX];
79  const Real& ny = normal[YY];
80  const Real un = p.U.dot(normal);
81  const Real us = u*ny - v*nx;
82  const Real gm1 = p.gamma-1;
83  const Real inv_c = 1. / p.c;
84  const Real inv_c2 = inv_c * inv_c;
85 
86  // matrix of left eigenvectors (rows) = Rv.inverse()
87  left_eigenvectors <<
88  2.-gm1*p.H*inv_c2, u*gm1*inv_c2, v*gm1*inv_c2, -gm1*inv_c2,
89  -us, ny, -nx, 0,
90  0.5*inv_c2*(0.5*gm1*p.U2+p.c*un), -0.5*inv_c2*(gm1*u-p.c*nx), -0.5*inv_c2*(gm1*v-p.c*ny), 0.5*gm1*inv_c2,
91  0.5*inv_c2*(0.5*gm1*p.U2-p.c*un), -0.5*inv_c2*(gm1*u+p.c*nx), -0.5*inv_c2*(gm1*v+p.c*ny), 0.5*gm1*inv_c2;
92 }
93 
94 
95 void compute_rusanov_flux( const Data& left, const Data& right, const ColVector_NDIM& normal,
96  RowVector_NEQS& flux, Real& wave_speed )
97 {
98  RowVector_NEQS left_flux, right_flux;
99  Real left_wave_speed, right_wave_speed;
100  compute_convective_flux( left, normal, left_flux, left_wave_speed );
101  compute_convective_flux( right, normal, right_flux, right_wave_speed);
102  wave_speed = std::max(left_wave_speed,right_wave_speed);
103  flux = 0.5*(left_flux+right_flux);
104  flux -= 0.5*wave_speed*(right.cons - left.cons);
105 }
106 
107 void compute_roe_average( const Data& left, const Data& right,
108  Data& roe )
109 {
110  const Real sqrt_rhoL = std::sqrt(left.rho);
111  const Real sqrt_rhoR = std::sqrt(right.rho);
112  roe.gamma = 0.5*(left.gamma+right.gamma);
113  roe.rho = sqrt_rhoL*sqrt_rhoR;
114  roe.U = (sqrt_rhoL*left.U + sqrt_rhoR*right.U) / (sqrt_rhoL + sqrt_rhoR);
115  roe.H = (sqrt_rhoL*left.H + sqrt_rhoR*right.H) / (sqrt_rhoL + sqrt_rhoR);
116  roe.U2 = roe.U.squaredNorm();
117  roe.c2 = (roe.gamma-1.)*(roe.H-0.5*roe.U2);
118  roe.p = roe.c2 * roe.rho / roe.gamma;
119  roe.c = std::sqrt(roe.c2);
120 }
121 
122 void compute_roe_flux( const Data& left, const Data& right, const ColVector_NDIM& normal,
123  RowVector_NEQS& flux, Real& wave_speed )
124 {
125  // Compute Roe average
126  Data roe;
127  compute_roe_average(left,right,roe);
128 
129  // Compute the wave strengths dW
130  RowVector_NEQS dW;
131  ColVector_NDIM s;
132  s << normal[YY], -normal[XX];
133  const ColVector_NDIM dU = (right.U - left.U);
134  const Real drho = (right.rho - left.rho);
135  const Real dp = (right.p - left.p);
136  const Real dun = dU.dot(normal);
137  const Real dus = dU.dot(s);
138 
139  dW[0] = drho - dp/roe.c2;
140  dW[1] = dus * roe.rho;
141  dW[2] = 0.5*(dp/roe.c2 + dun*roe.rho/roe.c);
142  dW[3] = 0.5*(dp/roe.c2 - dun*roe.rho/roe.c);
143 
144  // Compute the wave speeds
145  RowVector_NEQS lambda;
146  compute_convective_eigenvalues(roe, normal, lambda);
147 
150 
151  RowVector_NEQS flux_left, flux_right;
152  compute_convective_flux(left,normal,flux_left);
153  compute_convective_flux(right,normal,flux_right);
154  flux.noalias() = 0.5*(flux_left+flux_right);
155  for (Uint k=0; k<NEQS; ++k)
156  {
157  for (Uint eq=0; eq<NEQS; ++eq)
158  flux[eq] -= 0.5*std::abs(lambda[k]) * dW[k] * R(eq,k);
159  }
160 
161  compute_convective_wave_speed(roe, normal, wave_speed);
162 }
163 
164 void compute_hlle_flux( const Data& left, const Data& right, const ColVector_NDIM& normal,
165  RowVector_NEQS& flux, Real& wave_speed )
166 {
167  // Compute Roe average
168  Data roe;
169  compute_roe_average(left,right,roe);
170 
171  RowVector_NEQS lambda_left, lambda_right, lambda_roe;
172  compute_convective_eigenvalues(left, normal, lambda_left);
173  compute_convective_eigenvalues(right, normal, lambda_right);
174  compute_convective_eigenvalues(roe, normal, lambda_roe);
175 
176  Real wave_speed_left, wave_speed_right;
177  wave_speed_left = std::min(lambda_left.minCoeff(), lambda_roe.minCoeff()); // u - c
178  wave_speed_right = std::max(lambda_right.maxCoeff(), lambda_roe.maxCoeff()); // u + c
179 
180  if (wave_speed_left >= 0.) // supersonic to the right
181  {
182  compute_convective_flux(left,normal,flux);
183  }
184  else if (wave_speed_right <= 0.) // supersonic to the left
185  {
186  compute_convective_flux(right,normal,flux);
187  }
188  else // intermediate state
189  {
190  RowVector_NEQS flux_left, flux_right;
191  compute_convective_flux(left, normal, flux_left );
192  compute_convective_flux(right, normal, flux_right);
193  for (Uint eq=0; eq<NEQS; ++eq)
194  {
195  flux[eq] = (wave_speed_right*flux_left[eq]-wave_speed_left*flux_right[eq]);
196  flux[eq] += (wave_speed_left*wave_speed_right)*(right.cons[eq]-left.cons[eq]);
197  flux[eq] /= (wave_speed_right-wave_speed_left);
198  }
199  }
200  compute_convective_wave_speed(roe,normal,wave_speed);
201 }
202 
203 void compute_specific_entropy( const Data& p, Real& specific_entropy)
204 {
205  // Compute specific entropy from primitive variables
206  specific_entropy = p.R/(p.gamma-1.)*log(p.p) - p.gamma*p.R/(p.gamma-1.)*p.R*log(p.rho);
207 }
208 
210 {
211  dcons_dprim <<
212  1., 0., 0., 0.,
213  p.U[XX], p.rho, 0., 0.,
214  p.U[YY], 0., p.rho, 0.,
215  1./2.*p.U2, p.rho*p.U[XX], p.rho*p.U[YY], 1./(p.gamma-1.);
216  }
217 
219 {
220  dprim_dcons <<
221  1., 0., 0., 0.,
222  -p.U[XX]/p.rho, 1./p.rho, 0., 0.,
223  -p.U[YY]*p.rho, 0., 1./p.rho, 0.,
224  1./2.*(p.gamma-1.)*p.U2, p.U[XX]*(1.-p.gamma), p.U[YY]*(1.-p.gamma), p.gamma-1.;
225 }
226 
228 
229 } // euler2d
230 } // euler
231 } // physics
232 } // cf3
void compute_convective_right_eigenvectors(const Data &p, const ColVector_NDIM &normal, Matrix_NEQSxNEQS &right_eigenvectors)
Right eigenvectors projected on a given normal.
Definition: Functions.cpp:57
void compute_convective_wave_speed(const Data &p, const ColVector_NDIM &normal, Real &wave_speed)
Maximum absolute wave speed.
Definition: Functions.cpp:40
boost::proto::terminal< SFOp< NormalOp > >::type const normal
Real R()
Definition of the ideal gas constant [J/mol K].
Definition: Consts.hpp:36
void compute_rusanov_flux(const Data &left, const Data &right, const ColVector_NDIM &normal, RowVector_NEQS &flux, Real &wave_speed)
Rusanov Approximate Riemann solver.
Definition: Functions.cpp:95
Real U2
velocity squared
Definition: Data.hpp:39
ColVector_NDIM U
velocity
Definition: Data.hpp:38
void compute_hlle_flux(const Data &left, const Data &right, const ColVector_NDIM &normal, RowVector_NEQS &flux, Real &wave_speed)
HLLE Approximate Riemann solver.
Definition: Functions.cpp:164
Real max(const Real a, const Real b)
Maximum between two scalars.
Definition: Terminals.hpp:228
void compute_convective_left_eigenvectors(const Data &p, const ColVector_NDIM &normal, Matrix_NEQSxNEQS &left_eigenvectors)
Left eigenvectors projected on a given normal.
Definition: Functions.cpp:73
Definition: Defs.hpp:17
Real min(const Real a, const Real b)
Minimum between two scalars.
Definition: Terminals.hpp:234
Real H
specific enthalpy
Definition: Data.hpp:40
Real c2
square of speed of sound, very commonly used
Definition: Data.hpp:41
MatrixTypes< NDIM, NEQS >::ColVector_NDIM ColVector_NDIM
Definition: Types.hpp:23
Top-level namespace for coolfluid.
Definition: Action.cpp:18
void compute_roe_flux(const Data &left, const Data &right, const ColVector_NDIM &normal, RowVector_NEQS &flux, Real &wave_speed)
Roe Approximate Riemann solver.
Definition: Functions.cpp:122
Real c
speed of sound
Definition: Data.hpp:42
void compute_convective_flux(const Data &p, const ColVector_NDIM &normal, RowVector_NEQS &flux, Real &wave_speed)
Convective flux in conservative form, and maximum absolute wave speed.
Definition: Functions.cpp:17
void compute_roe_average(const Data &left, const Data &right, Data &roe)
Linearize a left and right state using the Roe average.
Definition: Functions.cpp:107
void compute_convective_eigenvalues(const Data &p, const ColVector_NDIM &normal, RowVector_NEQS &eigen_values)
Eigenvalues or wave speeds projected on a given normal.
Definition: Functions.cpp:46
void compute_jacobian_conservative_wrt_primitive(const Data &p, Matrix_NEQSxNEQS &dcons_dprim)
Calculate the Jacobian of the conserved variables with respect to the primitive variables.
Definition: Functions.cpp:209
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
MatrixTypes< NDIM, NEQS >::Matrix_NEQSxNEQS Matrix_NEQSxNEQS
Definition: Types.hpp:24
void compute_jacobian_primitive_wrt_conservative(const Data &p, Matrix_NEQSxNEQS &dprim_dcons)
Calculate the Jacobian of the primitive variables with respect to the conservative variables...
Definition: Functions.cpp:218
void compute_specific_entropy(const Data &p, Real &specific_entropy)
Compute the specific entropy from the primitive variables.
Definition: Functions.cpp:203
Real gamma
specific heat ratio
Definition: Data.hpp:33
Definition: Defs.hpp:17
MatrixTypes< NDIM, NEQS >::RowVector_NEQS RowVector_NEQS
Definition: Types.hpp:22
Send comments to:
COOLFluiD Web Admin