1
//---------------------------------------------------------------------------
3
// Project: OpenWalnut ( http://www.openwalnut.org )
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
8
// This file is part of OpenWalnut.
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
23
//---------------------------------------------------------------------------
25
#ifndef WDATASETVECTOR_TEST_H
26
#define WDATASETVECTOR_TEST_H
30
#include <boost/array.hpp>
32
#include <cxxtest/TestSuite.h>
34
#include "../../common/WLogger.h"
35
#include "../WDataSetVector.h"
38
* Test basic functionality of WDataSetVector.
40
class WDataSetVectorTest : public CxxTest::TestSuite
44
* Constructs unit test environment.
52
* An interpolate of an vector is as if every components were interpolated
54
void testInterpolate( void )
56
boost::shared_ptr< WGrid > grid = boost::shared_ptr< WGrid >( new WGridRegular3D( 5, 3, 3 ) );
57
boost::shared_ptr< std::vector< double > > data = boost::shared_ptr< std::vector< double > >( new std::vector< double >( grid->size() * 3 ) );
58
for( size_t i = 0; i < grid->size() * 3; ++i )
62
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
63
WDataSetVector ds( valueSet, grid );
67
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[0], ( *data )[0] );
68
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[1], ( *data )[1] );
69
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[2], ( *data )[2] );
71
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[0], ( *data )[3], 1e-9 );
72
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[1], ( *data )[4], 1e-9 );
73
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[2], ( *data )[5], 1e-9 );
75
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[0], ( *data )[15], 1e-9 );
76
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[1], ( *data )[16], 1e-9 );
77
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[2], ( *data )[17], 1e-9 );
79
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[0], ( *data )[18], 1e-9 );
80
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[1], ( *data )[19], 1e-9 );
81
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[2], ( *data )[20], 1e-9 );
83
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[0], ( *data )[45], 1e-9 );
84
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[1], ( *data )[46], 1e-9 );
85
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[2], ( *data )[47], 1e-9 );
87
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[0], ( *data )[48], 1e-9 );
88
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[1], ( *data )[49], 1e-9 );
89
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[2], ( *data )[50], 1e-9 );
91
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[0], ( *data )[60], 1e-9 );
92
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[1], ( *data )[61], 1e-9 );
93
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[2], ( *data )[62], 1e-9 );
95
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[0], ( *data )[63], 1e-9 );
96
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[1], ( *data )[64], 1e-9 );
97
TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[2], ( *data )[65], 1e-9 );
100
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[0], 29.4, 1e-9 );
101
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[1], 30.4, 1e-9 );
102
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[2], 31.4, 1e-9 );
103
TS_ASSERT( success );
104
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[0], 31.5, 1e-9 );
105
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[1], 32.5, 1e-9 );
106
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[2], 33.5, 1e-9 );
107
TS_ASSERT( success );
111
* Checks if the reorientation of the vectors is applied in eigenVectorInterpolate().
113
v_6( 1, 0, 0 ) v_7( 1, 0, 0 )
114
/----------------------------/
118
/---+------------------------/ |
119
v_4( 1, 0, 0 ) v_5( 1, 0, 0 )
127
| | v_2( 1, 0, 0 ) | | v_3( 1, 0, 0 )
128
| /------------------------+---/
132
/----------------------------/------------------> x
133
v_0( -1, 0, 0) v_1( 1, 0, 0 )
137
void testEigenVectorInterpolate( void )
139
boost::shared_ptr< WGrid > grid = boost::shared_ptr< WGrid >( new WGridRegular3D( 2, 2, 2 ) );
140
boost::shared_ptr< std::vector< double > > data( new std::vector< double > );
141
boost::array< WPosition, 8 > d = { { WPosition( -1, 0, 0 ), // NOLINT braces
142
WPosition( 1, 0, 0 ),
143
WPosition( 1, 0, 0 ),
144
WPosition( 1, 0, 0 ),
145
WPosition( 1, 0, 0 ),
146
WPosition( 1, 0, 0 ),
147
WPosition( 1, 0, 0 ),
148
WPosition( 1, 0, 0 ) } }; // NOLINT braces
150
for( size_t i = 0; i < grid->size(); ++i )
152
data->push_back( d[i][0] );
153
data->push_back( d[i][1] );
154
data->push_back( d[i][2] );
156
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
157
WDataSetVector ds( valueSet, grid );
159
bool success = false;
160
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0.0, 0.0, 0.0 ), &success ), d[0] );
161
TS_ASSERT( success );
162
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[0], d[7][0], 1e-9 );
163
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[1], d[7][1], 1e-9 );
164
TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[2], d[7][2], 1e-9 );
165
TS_ASSERT( success );
166
WPosition expected( 0.75, 0.0, 0.0 );
167
TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), expected );
168
TS_ASSERT( success );
169
TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( WPosition( 0.0, 0.0, 0.0 ), &success ), d[0] );
170
TS_ASSERT( success );
171
expected = WPosition( -1.0, 0.0, 0.0 );
172
TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[0], expected[0], 1e-9 );
173
TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[1], expected[1], 1e-9 );
174
TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[2], expected[2], 1e-9 );
175
TS_ASSERT( success );
176
expected = WPosition( -1.0, 0.0, 0.0 );
177
TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), expected );
178
TS_ASSERT( success );
182
* Using interpolate on Positions on the boundary of the grid the success flag is true but there should not be any segfaults.
183
* See ticket #313 for more informations.
185
void testBoundary_ticket313( void )
187
boost::shared_ptr< WGridRegular3D > grid = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( 3, 4, 5 ) );
188
bool success = false;
189
boost::shared_ptr< std::vector< double > > data = boost::shared_ptr< std::vector< double > >( new std::vector< double >( grid->size() * 3 ) );
190
for( size_t i = 0; i < grid->size() * 3; ++i )
194
boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) );
195
WDataSetVector ds( valueSet, grid );
196
ds.interpolate( WPosition( 2.0, 3.0, 4.0 ), &success );
197
TS_ASSERT( !success );
201
#endif // WDATASETVECTOR_TEST_H