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 #include "cf3/math/Consts.hpp"
10 
11 namespace cf3 {
12 namespace physics {
13 namespace euler {
14 namespace euler1d {
15 
17 
19  RowVector_NEQS& flux, Real& wave_speed )
20 {
21  const Real un = p.u * normal[XX];
22  const Real rho_un = p.rho * un;
23  flux[0] = rho_un;
24  flux[1] = rho_un * p.u + p.p * normal[XX];
25  flux[2] = rho_un * p.H;
26  wave_speed=std::abs(un)+p.c*std::abs(normal[XX]);
27 }
28 
30  RowVector_NEQS& flux )
31 {
32  const Real un = p.u * normal[XX];
33  const Real rho_un = p.rho * un;
34  flux[0] = rho_un;
35  flux[1] = rho_un * p.u + p.p *normal[XX];
36  flux[2] = rho_un * p.H;
37 }
38 
40  Real& wave_speed )
41 {
42  wave_speed=std::abs(p.u * normal[XX])+p.c*std::abs(normal[XX]);
43 }
44 
46  RowVector_NEQS& eigen_values )
47 {
48  const Real un = p.u * normal[XX];
49  const Real cn = p.c * normal[XX];
50  eigen_values[0] = un;
51  eigen_values[1] = un+cn;
52  eigen_values[2] = un-cn;
53 }
54 
56  Matrix_NEQSxNEQS& right_eigenvectors )
57 {
58  right_eigenvectors <<
59  1., 1, 1,
60  p.u, p.u+p.c, p.u-p.c,
61  0.5*p.u*p.u, p.H+p.c*p.u, p.H-p.c*p.u;
62 }
63 
65  Matrix_NEQSxNEQS& left_eigenvectors )
66 {
67  const Real nx = normal[XX];
68  const Real gm1 = p.gamma-1;
69  const Real inv_c = 1. / p.c;
70  const Real inv_c2 = inv_c * inv_c;
71  const Real M = p.u*inv_c;
72  const Real M2 = M*M;
73 
74  // matrix of left eigenvectors (rows) = Rv.inverse()
75  left_eigenvectors <<
76  1.-0.5*gm1*M2, p.u*gm1*inv_c2, -gm1*inv_c2,
77  0.25*gm1*M2-0.5*M, -0.5*inv_c2*(gm1*p.u-p.c), 0.5*gm1*inv_c2,
78  0.25*gm1*M2+0.5*M, -0.5*inv_c2*(gm1*p.u+p.c), 0.5*gm1*inv_c2;
79 }
80 
81 
82 void compute_rusanov_flux( const Data& left, const Data& right, const ColVector_NDIM& normal,
83  RowVector_NEQS& flux, Real& wave_speed )
84 {
85  RowVector_NEQS left_flux, right_flux;
86  Real left_wave_speed, right_wave_speed;
87  compute_convective_flux( left, normal, left_flux, left_wave_speed );
88  compute_convective_flux( right, normal, right_flux, right_wave_speed);
89  wave_speed = std::max(left_wave_speed,right_wave_speed);
90  flux = 0.5*(left_flux+right_flux);
91  flux -= 0.5*wave_speed*(right.cons - left.cons);
92 }
93 
94 void compute_roe_average( const Data& left, const Data& right,
95  Data& roe )
96 {
97  // Iterative solvers could temporarily create negative density.
98  // Clip it to zero only in computation of the Roe average
99  const Real sqrt_rhoL = std::sqrt(std::abs(left.rho));//,math::Consts::eps()));
100  const Real sqrt_rhoR = std::sqrt(std::abs(right.rho));//,math::Consts::eps()));
101  roe.gamma = 0.5*(left.gamma+right.gamma);
102  roe.rho = sqrt_rhoL*sqrt_rhoR;
103  roe.u = (sqrt_rhoL*left.u + sqrt_rhoR*right.u) / (sqrt_rhoL + sqrt_rhoR);
104  roe.H = (sqrt_rhoL*std::abs(left.H) + sqrt_rhoR*std::abs(right.H)) / (sqrt_rhoL + sqrt_rhoR);
105  roe.c2 = (roe.gamma-1.)*(roe.H-0.5*roe.u*roe.u);
106  roe.p = roe.c2 * roe.rho / roe.gamma;
107  roe.c = std::sqrt(roe.c2);
108 }
109 
110 void compute_roe_flux( const Data& left, const Data& right, const ColVector_NDIM& normal,
111  RowVector_NEQS& flux, Real& wave_speed )
112 {
113  if (left.rho<0 || right.rho<0)
114  {
115  throw common::BadValue(FromHere(), "negative density");
116  }
117  // Compute Roe average
118  Data roe;
119  compute_roe_average(left,right,roe);
120 
121  // Compute the wave strengths dW
122  RowVector_NEQS dW;
123  const Real drho = (right.rho - left.rho);
124  const Real du = (right.u - left.u);
125  const Real dp = (right.p - left.p);
126  dW[0] = drho - dp/roe.c2;
127  dW[1] = 0.5*(dp/roe.c2 + du*roe.rho/roe.c);
128  dW[2] = 0.5*(dp/roe.c2 - du*roe.rho/roe.c);
129 
130  // Compute the wave speeds
131  RowVector_NEQS lambda;
132  compute_convective_eigenvalues(roe, normal, lambda);
133 
136 
137  RowVector_NEQS flux_left, flux_right;
138  compute_convective_flux(left,normal,flux_left);
139  compute_convective_flux(right,normal,flux_right);
140 
141  flux.noalias() = 0.5*(flux_left+flux_right);
142  for (Uint k=0; k<NEQS; ++k)
143  {
144  for (Uint eq=0; eq<NEQS; ++eq)
145  flux[eq] -= 0.5*std::abs(lambda[k]) * dW[k] * R(eq,k);
146  }
147 
148  compute_convective_wave_speed(roe, normal, wave_speed);
149 
150  // Previous calculation should be equivalent but faster than:
151  // Matrix_NEQSxNEQS R;
152  // compute_convective_right_eigenvectors(roe, normal, R);
153  // Matrix_NEQSxNEQS L;
154  // compute_convective_left_eigenvectors(roe, normal, L);
155  // RowVector_NEQS upwind = 0.5*(R*lambda.cwiseAbs().asDiagonal()*L*((right.cons-left.cons).transpose()));
156  // flux = 0.5*(flux_left+flux_right)-upwind;
157 }
158 
159 void compute_hlle_flux( const Data& left, const Data& right, const ColVector_NDIM& normal,
160  RowVector_NEQS& flux, Real& wave_speed )
161 {
162  // Compute Roe average
163  Data roe;
164  compute_roe_average(left,right,roe);
165 
166  RowVector_NEQS lambda_left, lambda_right, lambda_roe;
167  compute_convective_eigenvalues(left, normal, lambda_left);
168  compute_convective_eigenvalues(right, normal, lambda_right);
169  compute_convective_eigenvalues(roe, normal, lambda_roe);
170 
171  Real wave_speed_left, wave_speed_right;
172  wave_speed_left = std::min(lambda_left.minCoeff(), lambda_roe.minCoeff()); // u - c
173  wave_speed_right = std::max(lambda_right.maxCoeff(), lambda_roe.maxCoeff()); // u + c
174 
175  if (wave_speed_left >= 0.) // supersonic to the right
176  {
177  compute_convective_flux(left,normal,flux);
178  }
179  else if (wave_speed_right <= 0.) // supersonic to the left
180  {
181  compute_convective_flux(right,normal,flux);
182  }
183  else // intermediate state
184  {
185  RowVector_NEQS flux_left, flux_right;
186  compute_convective_flux(left, normal, flux_left );
187  compute_convective_flux(right, normal, flux_right);
188  for (Uint eq=0; eq<NEQS; ++eq)
189  {
190  flux[eq] = (wave_speed_right*flux_left[eq]-wave_speed_left*flux_right[eq]);
191  flux[eq] += (wave_speed_left*wave_speed_right)*(right.cons[eq]-left.cons[eq]);
192  flux[eq] /= (wave_speed_right-wave_speed_left);
193  }
194  }
195  compute_convective_wave_speed(roe,normal,wave_speed);
196 }
198 
199 } // euler1D
200 } // euler
201 } // physics
202 } // cf3
boost::proto::terminal< SFOp< NormalOp > >::type const normal
Real R()
Definition of the ideal gas constant [J/mol K].
Definition: Consts.hpp:36
MatrixTypes< NDIM, NEQS >::ColVector_NDIM ColVector_NDIM
Definition: Types.hpp:23
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:94
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:110
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:18
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:45
MatrixTypes< NDIM, NEQS >::Matrix_NEQSxNEQS Matrix_NEQSxNEQS
Definition: Types.hpp:24
Real max(const Real a, const Real b)
Maximum between two scalars.
Definition: Terminals.hpp:228
Definition: Defs.hpp:17
MatrixTypes< NDIM, NEQS >::RowVector_NEQS RowVector_NEQS
Definition: Types.hpp:22
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:55
void compute_convective_wave_speed(const Data &p, const ColVector_NDIM &normal, Real &wave_speed)
Maximum absolute wave speed.
Definition: Functions.cpp:39
Real min(const Real a, const Real b)
Minimum between two scalars.
Definition: Terminals.hpp:234
Real H
specific enthalpy
Definition: Data.hpp:35
Real c2
square of speed of sound, very commonly used
Definition: Data.hpp:36
Real u
velocity along XX
Definition: Data.hpp:33
Top-level namespace for coolfluid.
Definition: Action.cpp:18
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:82
Real c
speed of sound
Definition: Data.hpp:37
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
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:64
Real gamma
specific heat ratio
Definition: Data.hpp:28
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:159
#define FromHere()
Send comments to:
COOLFluiD Web Admin