COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-function-parser.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 function parser"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include <boost/assign/list_of.hpp>
13 
15 
16 using namespace std;
17 using namespace boost;
18 using namespace cf3;
19 using namespace cf3::math;
20 using namespace cf3::common;
21 
23 
25 {
27 
29 };
30 
32 
33 BOOST_FIXTURE_TEST_SUITE( FunctionParser_TestSuite, FunctionParser_Fixture )
34 
35 
37 BOOST_AUTO_TEST_CASE( Constructors )
38 {
39  FunctionParser fp;
40  fp.Parse("sqrt(x*x + y*y)", "x,y");
41  double variables[2] = { 1.5, 2.9 };
42  double result = fp.Eval(variables);
43 
44  BOOST_CHECK_CLOSE( result, sqrt(1.5*1.5 + 2.9*2.9) , 1e-6);
45 }
46 
48 {
49  FunctionParser fp;
50  fp.Parse("x/y", "x,y");
51  double variables[2] = { 1.5, 2.9 };
52  double result = fp.Eval(variables);
53 
54  BOOST_CHECK_CLOSE( result, 1.5/2.9 , 1e-6);
55 }
56 
57 BOOST_AUTO_TEST_CASE( function_1 )
58 {
59  cf3::math::VectorialFunction f ("[x/y]","x,y");
60 
61  RealVector r(1);
62  cf3::math::VectorialFunction::VariablesT u = boost::assign::list_of(1.0)(3.0);
63 
64  r = f(u);
65 
66  BOOST_CHECK_CLOSE( r[0], 1./3. , 1e-6);
67 
68 }
69 
70 BOOST_AUTO_TEST_CASE( function_2 )
71 {
72  cf3::math::VectorialFunction f ("[x+y][5*z]","x,y,z");
73 
74  RealVector r(2);
75  cf3::math::VectorialFunction::VariablesT u = boost::assign::list_of(2.0)(3.0)(7.0);
76 
77  r = f(u);
78 
79  BOOST_CHECK_CLOSE( r[0], 5.0 , 1e-6);
80  BOOST_CHECK_CLOSE( r[1], 35.0 , 1e-6);
81 
82 }
83 
84 
85 
87 
88 BOOST_AUTO_TEST_SUITE_END()
89 
90 
external boost library namespace
Basic Classes for Mathematical applications used by COOLFluiD.
STL namespace.
Real e()
Definition of the Unit charge [C].
Definition: Consts.hpp:30
Eigen::Matrix< Real, Eigen::Dynamic, 1 > RealVector
Dynamic sized column vector.
Definition: MatrixTypes.hpp:25
Top-level namespace for coolfluid.
Definition: Action.cpp:18
BOOST_AUTO_TEST_CASE(Constructors)
Most basic kernel library.
Definition: Action.cpp:19
std::vector< Real > VariablesT
Variable storage.
Send comments to:
COOLFluiD Web Admin