COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
utest-math-variablesdescriptor.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::math::VariablesDescriptor"
9 
10 #include <boost/test/unit_test.hpp>
11 
12 #include "common/OptionList.hpp"
13 
15 
16 
17 using namespace cf3;
18 using namespace cf3::common;
19 using namespace cf3::math;
20 
22 
23 BOOST_AUTO_TEST_SUITE( VariablesDescriptorSuite )
24 
25 
27 // Add a single scalar variable
28 BOOST_AUTO_TEST_CASE( PushBackScalar )
29 {
30  boost::shared_ptr<VariablesDescriptor> descriptor = allocate_component<VariablesDescriptor>("descriptor");
32 
33  descriptor->options().set(common::Tags::dimension(), 3u);
34 
35  BOOST_CHECK_EQUAL(descriptor->size(), 1);
36  BOOST_CHECK_EQUAL(descriptor->user_variable_name("a"), "a");
37 
38  descriptor->options().set("a_variable_name", std::string("b"));
39 
40  BOOST_CHECK_EQUAL(descriptor->user_variable_name("a"), "b");
41 }
42 
43 // Test vector and tensor behavior under changing dimensions, as well as description generator
44 BOOST_AUTO_TEST_CASE( PushBackVectors )
45 {
46  boost::shared_ptr<VariablesDescriptor> descriptor = allocate_component<VariablesDescriptor>("descriptor");
47 
48  descriptor->options().set(common::Tags::dimension(), 2u);
49 
53 
54  BOOST_CHECK_EQUAL(descriptor->size(), 8);
55  BOOST_CHECK_EQUAL(descriptor->size("v1"), 2);
56  BOOST_CHECK_EQUAL(descriptor->size("v2"), 2);
57  BOOST_CHECK_EQUAL(descriptor->size("t1"), 4);
58  BOOST_CHECK_EQUAL(descriptor->offset("v1"), 0);
59  BOOST_CHECK_EQUAL(descriptor->offset("v2"), 2);
60  BOOST_CHECK_EQUAL(descriptor->offset("t1"), 4);
61 
62  descriptor->options().set(common::Tags::dimension(), 3u);
63  BOOST_CHECK_EQUAL(descriptor->size(), 15);
64  BOOST_CHECK_EQUAL(descriptor->size("v1"), 3);
65  BOOST_CHECK_EQUAL(descriptor->size("v2"), 3);
66  BOOST_CHECK_EQUAL(descriptor->size("t1"), 9);
67  BOOST_CHECK_EQUAL(descriptor->offset("v1"), 0);
68  BOOST_CHECK_EQUAL(descriptor->offset("v2"), 3);
69  BOOST_CHECK_EQUAL(descriptor->offset("t1"), 6);
70 
72  BOOST_CHECK_EQUAL(descriptor->description(), "v1[vector],v2[vector],t1[tensor],s[scalar]");
73 }
74 
75 // Test parsing of string to batch-add variables
76 BOOST_AUTO_TEST_CASE( ParseString )
77 {
78  boost::shared_ptr<VariablesDescriptor> descriptor = allocate_component<VariablesDescriptor>("descriptor");
79 
80  descriptor->options().set(common::Tags::dimension(), 2u);
81 
82  // Add a scalar, vector and tensor
83  descriptor->set_variables("a, b[v], c[t]");
84 
85  BOOST_CHECK_EQUAL(descriptor->size(), 7);
86  BOOST_CHECK_EQUAL(descriptor->description(), "a[scalar],b[vector],c[tensor]");
87 
88  BOOST_CHECK_EQUAL(descriptor->dimensionality("a"), VariablesDescriptor::Dimensionalities::SCALAR);
89  BOOST_CHECK_EQUAL(descriptor->dimensionality("b"), VariablesDescriptor::Dimensionalities::VECTOR);
90  BOOST_CHECK_EQUAL(descriptor->dimensionality("c"), VariablesDescriptor::Dimensionalities::TENSOR);
91 }
92 
93 // Test parsing of string to batch-add variables, adding many scalars at a time
94 BOOST_AUTO_TEST_CASE( ParseStringArray )
95 {
96  boost::shared_ptr<VariablesDescriptor> descriptor = allocate_component<VariablesDescriptor>("descriptor");
97 
98  descriptor->options().set(common::Tags::dimension(), 2u);
99 
100  // Add 5 scalars
101  descriptor->set_variables("a[5]");
102 
103  BOOST_CHECK_EQUAL(descriptor->size(), 5);
104  BOOST_CHECK_EQUAL(descriptor->description(), "a1[scalar],a2[scalar],a3[scalar],a4[scalar],a5[scalar]");
105 }
106 
108 
109 BOOST_AUTO_TEST_SUITE_END()
110 
111 
Basic Classes for Mathematical applications used by COOLFluiD.
BOOST_AUTO_TEST_CASE(PushBackScalar)
static const char * dimension()
Tag for options related to the dimension of something.
Definition: Tags.cpp:14
Top-level namespace for coolfluid.
Definition: Action.cpp:18
Most basic kernel library.
Definition: Action.cpp:19
Send comments to:
COOLFluiD Web Admin