COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-physics-euler.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 
7 #define BOOST_TEST_DYN_LINK
8 #define BOOST_TEST_MODULE "Test module for cf3::Euler"
9 
10 #include <iostream>
11 #include <boost/test/unit_test.hpp>
12 
13 #include "math/Defs.hpp"
14 
15 #include "cf3/common/Log.hpp"
16 #include "cf3/common/Core.hpp"
20 
21 using namespace std;
22 using namespace cf3;
23 using namespace cf3::common;
24 using namespace cf3::physics::euler;
25 
27 
28 BOOST_AUTO_TEST_SUITE( Euler_Suite )
29 
30 
32 BOOST_AUTO_TEST_CASE( Test_Euler1D_convection )
33 {
35  p.gamma=1.4;
36  p.R=287.05;
37 
39  prim << 1.225, 30, 101300;
40  p.compute_from_primitive(prim);
41 
42  euler1d::ColVector_NDIM normal; normal << 1.;
44  Real wave_speed;
45  compute_convective_flux( p, normal, flux , wave_speed );
46 
47  BOOST_CHECK_CLOSE( flux[0] , p.rho*p.u , 1e-10);
48  BOOST_CHECK_CLOSE( flux[1] , p.rho*p.u*p.u + p.p , 1e-10);
49  BOOST_CHECK_CLOSE( flux[2] , (p.rho*p.E+p.p)*p.u , 1e-6);
50 }
51 
53 
54 BOOST_AUTO_TEST_CASE( Test_Euler1D_riemann )
55 {
56  euler1d::Data pL, pR;
57 
58  pL.gamma=1.4; pR.gamma=1.4;
59  pL.R=287.05; pR.R=287.05;
60 
61  euler1d::RowVector_NEQS prim_left, prim_right;
62  prim_left << 4.696, 0, 404400; pL.compute_from_primitive(prim_left);
63  prim_right << 1.408, 0, 101100; pR.compute_from_primitive(prim_right);
64 
65  BOOST_CHECK_EQUAL(pL.rho,4.696);
66  BOOST_CHECK_EQUAL(pL.u,0);
67  BOOST_CHECK_EQUAL(pL.p,404400);
68  BOOST_CHECK_CLOSE(pL.c2, (pL.gamma-1.)*(pL.H-0.5*pL.u2),1e-8);
69  euler1d::RowVector_NEQS flux_pos, flux_neg;
70  euler1d::ColVector_NDIM normal; normal << 1.;
71  Real wave_speed;
72 
73  compute_rusanov_flux( pL, pR, normal, flux_pos , wave_speed );
74  std::cout << flux_pos << std::endl;
75 
76  compute_rusanov_flux( pR, pL, -normal, flux_neg , wave_speed );
77  std::cout << flux_neg << std::endl;
78 
79  BOOST_CHECK_EQUAL ( flux_pos, -flux_neg );
80 
81  compute_roe_flux( pL, pR, normal, flux_pos , wave_speed );
82  std::cout << flux_pos << std::endl;
83 
84  compute_roe_flux( pR, pL, -normal, flux_neg , wave_speed );
85  std::cout << flux_neg << std::endl;
86 
87  BOOST_CHECK_EQUAL ( flux_pos, -flux_neg );
88 
89  compute_hlle_flux( pL, pR, normal, flux_pos , wave_speed );
90  std::cout << flux_pos << std::endl;
91 
92  compute_hlle_flux( pR, pL, -normal, flux_neg , wave_speed );
93  std::cout << flux_neg << std::endl;
94 
95  BOOST_CHECK_EQUAL ( flux_pos, -flux_neg );
96 
97 }
98 
99 
100 
101 BOOST_AUTO_TEST_CASE( Test_Euler2D_convection )
102 {
104  p.gamma=1.4;
105  p.R=287.05;
106 
108  prim << 1.225, 30, 30, 101300;
109  p.compute_from_primitive(prim);
110 
111  euler2d::ColVector_NDIM normal; normal << 1., 1.; normal.normalize();
113  Real wave_speed;
114  compute_convective_flux( p, normal, flux , wave_speed );
115 
116  Real un = p.U.dot(normal);
117  BOOST_CHECK_CLOSE( flux[0] , p.rho*un , 1e-10);
118  BOOST_CHECK_CLOSE( flux[1] , p.rho*p.U[XX]*un + p.p*normal[XX] , 1e-10);
119  BOOST_CHECK_CLOSE( flux[2] , p.rho*p.U[YY]*un + p.p*normal[YY] , 1e-10);
120  BOOST_CHECK_CLOSE( flux[3] , (p.rho*p.E+p.p)*un , 1e-6);
121 }
122 
124 
125 BOOST_AUTO_TEST_CASE( Test_Euler2D_riemann )
126 {
127  euler2d::Data pL, pR;
128 
129  pL.gamma=1.4; pR.gamma=1.4;
130  pL.R=287.05; pR.R=287.05;
131 
132  euler2d::RowVector_NEQS prim_left, prim_right;
133  prim_left << 4.696, 0, 0, 404400; pL.compute_from_primitive(prim_left);
134  prim_right << 1.408, 0, 0, 101100; pR.compute_from_primitive(prim_right);
135 
136  BOOST_CHECK_EQUAL(pL.rho,4.696);
137  BOOST_CHECK_EQUAL(pL.U[XX],0);
138  BOOST_CHECK_EQUAL(pL.U[YY],0);
139  BOOST_CHECK_EQUAL(pL.p,404400);
140  BOOST_CHECK_CLOSE(pL.c2, (pL.gamma-1.)*(pL.H-0.5*pL.U2),1e-8);
141  euler2d::RowVector_NEQS flux_pos, flux_neg;
142  euler2d::ColVector_NDIM normal; normal << 0.,1.; normal.normalize();
143  Real wave_speed;
144 
145  compute_rusanov_flux( pL, pR, normal, flux_pos , wave_speed );
146  std::cout << flux_pos << std::endl;
147 
148  compute_rusanov_flux( pR, pL, -normal, flux_neg , wave_speed );
149  std::cout << flux_neg << std::endl;
150 
151  BOOST_CHECK_EQUAL ( flux_pos, -flux_neg );
152 
153  compute_roe_flux( pL, pR, normal, flux_pos , wave_speed );
154  std::cout << flux_pos << std::endl;
155 
156  compute_roe_flux( pR, pL, -normal, flux_neg , wave_speed );
157  std::cout << flux_neg << std::endl;
158 
159  BOOST_CHECK_EQUAL ( flux_pos, -flux_neg );
160 
161  compute_hlle_flux( pL, pR, normal, flux_pos , wave_speed );
162  std::cout << flux_pos << std::endl;
163 
164  compute_hlle_flux( pR, pL, -normal, flux_neg , wave_speed );
165  std::cout << flux_neg << std::endl;
166 
167  BOOST_CHECK_EQUAL ( flux_pos, -flux_neg );
168 
169 }
170 
171 BOOST_AUTO_TEST_CASE( Test_Euler2D_SymmetryBCs )
172 {
173  euler2d::Data pL, pR, pAvg;
174 
175  pL.gamma=1.4; pR.gamma=1.4;
176  pL.R=287.05; pR.R=287.05;
177 
178  Real rho = 1.408;
179  Real u = 50;
180  Real v = 20;
181  Real p = 101100;
182  euler2d::RowVector_NEQS prim_left, prim_right;
183  prim_left << rho, u, v, p; pL.compute_from_primitive(prim_left);
184  prim_right << rho, -u, v, p; pR.compute_from_primitive(prim_right);
185 
186  Real H = pL.H;
187 
188  BOOST_CHECK_EQUAL( pL.rho , rho );
189  BOOST_CHECK_EQUAL( pL.p , p );
190 
191 
192  compute_roe_average( pL, pR, pAvg );
193 
194  BOOST_CHECK_EQUAL( pAvg.gamma , 1.4 );
195  BOOST_CHECK_EQUAL( pAvg.rho , rho );
196  BOOST_CHECK_EQUAL( pAvg.H , pL.H );
197  BOOST_CHECK_EQUAL( pAvg.U[XX] , 0. );
198  BOOST_CHECK_EQUAL( pAvg.U[YY] , v );
199  BOOST_CHECK_EQUAL( pAvg.U2 , v*v );
200 
202  euler2d::ColVector_NDIM normal; normal << 1., 0.;
203  Real wave_speed;
204 
207 
208  compute_convective_flux( pL, normal, fluxL, wave_speed );
209  std::cout << "convective_flux left = " << fluxL << std::endl;
210  compute_convective_flux( pR, normal, fluxR, wave_speed );
211  std::cout << "convective_flux right = " << fluxR << std::endl;
212  flux = 0.5*(fluxL+fluxR);
213 
214 
215  std::cout << "symmetry_wall_flux (Central) = " << flux << std::endl;
216  BOOST_CHECK_EQUAL( fluxL[0] , (rho*u) );
217  BOOST_CHECK_EQUAL( fluxL[1] , (rho*u)*u + p);
218  BOOST_CHECK_EQUAL( fluxL[2] , (rho*u)*v );
219  BOOST_CHECK_EQUAL( fluxL[3] , (rho*u)*H );
220 
221  BOOST_CHECK_EQUAL( fluxR[0] , (-rho*u) );
222  BOOST_CHECK_EQUAL( fluxR[1] , (-rho*u)*(-u) + p);
223  BOOST_CHECK_EQUAL( fluxR[2] , (-rho*u)*v );
224  BOOST_CHECK_EQUAL( fluxR[3] , (-rho*u)*H );
225 
226  BOOST_CHECK_EQUAL( flux[0] , 0. );
227  BOOST_CHECK_EQUAL( flux[1] , rho*u*u + p );
228  BOOST_CHECK_EQUAL( flux[2] , 0. );
229  BOOST_CHECK_EQUAL( flux[3] , 0. );
230 
231  compute_rusanov_flux( pL, pR, normal, flux, wave_speed );
232  std::cout << "symmetry_wall_flux (Rusanov) = " << flux << std::endl;
233 
234  compute_roe_flux( pL, pR, normal, flux, wave_speed );
235  std::cout << "symmetry_wall_flux (Roe) = " << flux << std::endl;
236 
237  compute_convective_flux( pAvg, normal, flux, wave_speed );
238  std::cout << "convective_flux (RoeAvg) = " << flux << std::endl;
239 
240 
241 
242 }
243 
245 
246 BOOST_AUTO_TEST_SUITE_END()
247 
248 
boost::proto::terminal< SFOp< NormalOp > >::type const normal
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
Real U2
velocity squared
Definition: Data.hpp:39
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_from_primitive(const RowVector_NEQS &prim)
Compute the data given primitive state.
Definition: Data.cpp:34
void compute_from_primitive(const RowVector_NEQS &prim)
Compute the data given primitive state.
Definition: Data.cpp:32
ColVector_NDIM U
velocity
Definition: Data.hpp:38
STL namespace.
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
Definition: Defs.hpp:17
MatrixTypes< NDIM, NEQS >::RowVector_NEQS RowVector_NEQS
Definition: Types.hpp:22
Real H
specific enthalpy
Definition: Data.hpp:40
Real c2
square of speed of sound, very commonly used
Definition: Data.hpp:41
Real H
specific enthalpy
Definition: Data.hpp:35
Real c2
square of speed of sound, very commonly used
Definition: Data.hpp:36
MatrixTypes< NDIM, NEQS >::ColVector_NDIM ColVector_NDIM
Definition: Types.hpp:23
Real u
velocity along XX
Definition: Data.hpp:33
Top-level namespace for coolfluid.
Definition: Action.cpp:18
BOOST_AUTO_TEST_CASE(Test_Euler1D_convection)
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 E
specific total energy
Definition: Data.hpp:40
Real E
specific total energy
Definition: Data.hpp:45
Real u2
velocity along XX squared
Definition: Data.hpp:34
Real gamma
specific heat ratio
Definition: Data.hpp:33
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
Definition: Defs.hpp:17
MatrixTypes< NDIM, NEQS >::RowVector_NEQS RowVector_NEQS
Definition: Types.hpp:22
Most basic kernel library.
Definition: Action.cpp:19
Physics Euler classes
Definition: Data.cpp:11
Send comments to:
COOLFluiD Web Admin