OpenWalnut 1.2.5
|
00001 //--------------------------------------------------------------------------- 00002 // 00003 // Project: OpenWalnut ( http://www.openwalnut.org ) 00004 // 00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS 00006 // For more information see http://www.openwalnut.org/copying 00007 // 00008 // This file is part of OpenWalnut. 00009 // 00010 // OpenWalnut is free software: you can redistribute it and/or modify 00011 // it under the terms of the GNU Lesser General Public License as published by 00012 // the Free Software Foundation, either version 3 of the License, or 00013 // (at your option) any later version. 00014 // 00015 // OpenWalnut is distributed in the hope that it will be useful, 00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 // GNU Lesser General Public License for more details. 00019 // 00020 // You should have received a copy of the GNU Lesser General Public License 00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>. 00022 // 00023 //--------------------------------------------------------------------------- 00024 00025 #ifndef WDATASETVECTOR_TEST_H 00026 #define WDATASETVECTOR_TEST_H 00027 00028 #include <vector> 00029 00030 #include <boost/array.hpp> 00031 00032 #include <cxxtest/TestSuite.h> 00033 00034 #include "../../common/WLogger.h" 00035 #include "../WDataSetVector.h" 00036 00037 /** 00038 * Test basic functionality of WDataSetVector. 00039 */ 00040 class WDataSetVectorTest : public CxxTest::TestSuite 00041 { 00042 public: 00043 /** 00044 * Constructs unit test environment. 00045 */ 00046 void setUp( void ) 00047 { 00048 WLogger::startup(); 00049 } 00050 00051 /** 00052 * An interpolate of an vector is as if every components were interpolated 00053 */ 00054 void testInterpolate( void ) 00055 { 00056 boost::shared_ptr< WGrid > grid = boost::shared_ptr< WGrid >( new WGridRegular3D( 5, 3, 3 ) ); 00057 boost::shared_ptr< std::vector< double > > data = boost::shared_ptr< std::vector< double > >( new std::vector< double >( grid->size() * 3 ) ); 00058 for( size_t i = 0; i < grid->size() * 3; ++i ) 00059 { 00060 ( *data )[i] = i; 00061 } 00062 boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) ); 00063 WDataSetVector ds( valueSet, grid ); 00064 00065 bool success = false; 00066 00067 TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[0], ( *data )[0] ); 00068 TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[1], ( *data )[1] ); 00069 TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0, 0, 0 ), &success )[2], ( *data )[2] ); 00070 TS_ASSERT( success ); 00071 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[0], ( *data )[3], 1e-9 ); 00072 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[1], ( *data )[4], 1e-9 ); 00073 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 0 ), &success )[2], ( *data )[5], 1e-9 ); 00074 TS_ASSERT( success ); 00075 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[0], ( *data )[15], 1e-9 ); 00076 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[1], ( *data )[16], 1e-9 ); 00077 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 0 ), &success )[2], ( *data )[17], 1e-9 ); 00078 TS_ASSERT( success ); 00079 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[0], ( *data )[18], 1e-9 ); 00080 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[1], ( *data )[19], 1e-9 ); 00081 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 0 ), &success )[2], ( *data )[20], 1e-9 ); 00082 TS_ASSERT( success ); 00083 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[0], ( *data )[45], 1e-9 ); 00084 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[1], ( *data )[46], 1e-9 ); 00085 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 0, 1 ), &success )[2], ( *data )[47], 1e-9 ); 00086 TS_ASSERT( success ); 00087 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[0], ( *data )[48], 1e-9 ); 00088 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[1], ( *data )[49], 1e-9 ); 00089 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 0, 1 ), &success )[2], ( *data )[50], 1e-9 ); 00090 TS_ASSERT( success ); 00091 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[0], ( *data )[60], 1e-9 ); 00092 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[1], ( *data )[61], 1e-9 ); 00093 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0, 1, 1 ), &success )[2], ( *data )[62], 1e-9 ); 00094 TS_ASSERT( success ); 00095 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[0], ( *data )[63], 1e-9 ); 00096 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[1], ( *data )[64], 1e-9 ); 00097 TS_ASSERT_DELTA( ds.interpolate( WPosition( 1, 1, 1 ), &success )[2], ( *data )[65], 1e-9 ); 00098 TS_ASSERT( success ); 00099 00100 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[0], 29.4, 1e-9 ); 00101 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[1], 30.4, 1e-9 ); 00102 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.3, 0.4, 0.5 ), &success )[2], 31.4, 1e-9 ); 00103 TS_ASSERT( success ); 00104 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[0], 31.5, 1e-9 ); 00105 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[1], 32.5, 1e-9 ); 00106 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success )[2], 33.5, 1e-9 ); 00107 TS_ASSERT( success ); 00108 } 00109 00110 /** 00111 * Checks if the reorientation of the vectors is applied in eigenVectorInterpolate(). 00112 \verbatim 00113 v_6( 1, 0, 0 ) v_7( 1, 0, 0 ) 00114 /----------------------------/ 00115 z A /| /| 00116 | / | / | 00117 |/ | / | 00118 /---+------------------------/ | 00119 v_4( 1, 0, 0 ) v_5( 1, 0, 0 ) 00120 | | | | 00121 | | | | 00122 | | | | 00123 | | y | | 00124 | | / | | 00125 | | / | | 00126 | | / | | 00127 | | v_2( 1, 0, 0 ) | | v_3( 1, 0, 0 ) 00128 | /------------------------+---/ 00129 | / | / 00130 | / | / 00131 |/ |/ 00132 /----------------------------/------------------> x 00133 v_0( -1, 0, 0) v_1( 1, 0, 0 ) 00134 00135 \endverbatim 00136 */ 00137 void testEigenVectorInterpolate( void ) 00138 { 00139 boost::shared_ptr< WGrid > grid = boost::shared_ptr< WGrid >( new WGridRegular3D( 2, 2, 2 ) ); 00140 boost::shared_ptr< std::vector< double > > data( new std::vector< double > ); 00141 boost::array< WPosition, 8 > d = { { WPosition( -1, 0, 0 ), // NOLINT braces 00142 WPosition( 1, 0, 0 ), 00143 WPosition( 1, 0, 0 ), 00144 WPosition( 1, 0, 0 ), 00145 WPosition( 1, 0, 0 ), 00146 WPosition( 1, 0, 0 ), 00147 WPosition( 1, 0, 0 ), 00148 WPosition( 1, 0, 0 ) } }; // NOLINT braces 00149 00150 for( size_t i = 0; i < grid->size(); ++i ) 00151 { 00152 data->push_back( d[i][0] ); 00153 data->push_back( d[i][1] ); 00154 data->push_back( d[i][2] ); 00155 } 00156 boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) ); 00157 WDataSetVector ds( valueSet, grid ); 00158 00159 bool success = false; 00160 TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0.0, 0.0, 0.0 ), &success ), d[0] ); 00161 TS_ASSERT( success ); 00162 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[0], d[7][0], 1e-9 ); 00163 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[1], d[7][1], 1e-9 ); 00164 TS_ASSERT_DELTA( ds.interpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[2], d[7][2], 1e-9 ); 00165 TS_ASSERT( success ); 00166 WPosition expected( 0.75, 0.0, 0.0 ); 00167 TS_ASSERT_EQUALS( ds.interpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), expected ); 00168 TS_ASSERT( success ); 00169 TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( WPosition( 0.0, 0.0, 0.0 ), &success ), d[0] ); 00170 TS_ASSERT( success ); 00171 expected = WPosition( -1.0, 0.0, 0.0 ); 00172 TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[0], expected[0], 1e-9 ); 00173 TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[1], expected[1], 1e-9 ); 00174 TS_ASSERT_DELTA( ds.eigenVectorInterpolate( WPosition( 0.9999, 0.9999, 0.9999 ), &success )[2], expected[2], 1e-9 ); 00175 TS_ASSERT( success ); 00176 expected = WPosition( -1.0, 0.0, 0.0 ); 00177 TS_ASSERT_EQUALS( ds.eigenVectorInterpolate( WPosition( 0.5, 0.5, 0.5 ), &success ), expected ); 00178 TS_ASSERT( success ); 00179 } 00180 00181 /** 00182 * Using interpolate on Positions on the boundary of the grid the success flag is true but there should not be any segfaults. 00183 * See ticket #313 for more informations. 00184 */ 00185 void testBoundary_ticket313( void ) 00186 { 00187 boost::shared_ptr< WGridRegular3D > grid = boost::shared_ptr< WGridRegular3D >( new WGridRegular3D( 3, 4, 5 ) ); 00188 bool success = false; 00189 boost::shared_ptr< std::vector< double > > data = boost::shared_ptr< std::vector< double > >( new std::vector< double >( grid->size() * 3 ) ); 00190 for( size_t i = 0; i < grid->size() * 3; ++i ) 00191 { 00192 ( *data )[i] = i; 00193 } 00194 boost::shared_ptr< WValueSet< double > > valueSet( new WValueSet< double >( 1, 3, data, W_DT_DOUBLE ) ); 00195 WDataSetVector ds( valueSet, grid ); 00196 ds.interpolate( WPosition( 2.0, 3.0, 4.0 ), &success ); 00197 TS_ASSERT( !success ); 00198 } 00199 }; 00200 00201 #endif // WDATASETVECTOR_TEST_H