OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WSymmetricSphericalHarmonic_test.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
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.
14 //
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.
19 //
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/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WSYMMETRICSPHERICALHARMONIC_TEST_H
26 #define WSYMMETRICSPHERICALHARMONIC_TEST_H
27 
28 #include <vector>
29 
30 // the following block is only for the last termporarly test
31 // #include <boost/nondet_random.hpp>
32 // #include <boost/random.hpp>
33 // #include <boost/random/normal_distribution.hpp>
34 // #include <boost/random/uniform_real.hpp>
35 // #include <boost/random/linear_congruential.hpp>
36 // #include <boost/random/uniform_real.hpp>
37 // #include <boost/random/variate_generator.hpp>
38 
39 #include <cxxtest/TestSuite.h>
40 
41 #include "../WMatrix.h"
42 #include "../linearAlgebra/WLinearAlgebra.h"
43 #include "../WValue.h"
44 
45 #include "../WGeometryFunctions.h"
46 #include "../WSymmetricSphericalHarmonic.h"
47 #include "../WTensorSym.h"
48 #include "../WTensorFunctions.h"
49 
50 #include "WMatrixTraits.h"
51 
52 /**
53  * Testsuite for WPosition.
54  */
55 class WSymmetricSphericalHarmonicTest : public CxxTest::TestSuite
56 {
57 public:
58  /**
59  * testCalcFRTMatrix
60  *
61  */
62  void testCalcFRTMatrix( void )
63  {
65  WMatrix<double> reference( 15, 15 );
66  reference.setZero();
67  // j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
68  // lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4
69  reference( 0, 0 ) = 2.0 * piDouble;
70  for( size_t i = 1; i <= 5; i++ )
71  {
72  reference( i, i ) = -2.0 * piDouble * 1.0 / 2.0;
73  }
74  for( size_t i = 6; i <= 14; i++ )
75  {
76  reference( i, i ) = 2.0 * piDouble * 3.0 / 8.0;
77  }
78 
79  for( size_t i = 0; i < 15; ++i )
80  {
81  for( size_t j = 0; j < 15; ++j )
82  {
83  TS_ASSERT_DELTA( result( i, j ), reference( i, j ), 1e-9 );
84  }
85  }
86  }
87 
88  /**
89  * testCalcSmoothingMatrix
90  *
91  */
93  {
95  WMatrix<double> reference( 15, 15 );
96  reference.setZero();
97  // j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
98  // lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4
99  reference( 0, 0 ) = 0.0;
100  for( size_t i = 1; i <= 5; i++ )
101  {
102  reference( i, i ) = 36.0;
103  }
104  for( size_t i = 6; i <= 14; i++ )
105  {
106  reference( i, i ) = 400.0;
107  }
108 
109  for( size_t i = 0; i < 15; ++i )
110  {
111  for( size_t j = 0; j < 15; ++j )
112  {
113  TS_ASSERT_DELTA( result( i, j ), reference( i, j ), 1e-9 );
114  }
115  }
116  }
117 
118  // TODO(reichenbach, philips): repair the following to tests
119  /**
120  * The matrix calculated by the calcSHToTensorSymMatrix function should produce tensors that
121  * evaluate to the same values as the respective spherical harmonics.
122  */
123  // void testCalcSHtoTensorMatrix()
124  // {
125  // WValue<double> w( 6 );
126  // for( int i = 0; i < 6; ++i )
127  // {
128  // w[ i ] = exp( i / 6.0 );
129  // }
130 
131  // WSymmetricSphericalHarmonic i( w );
132 
133  // std::vector< WUnitSphereCoordinates > orientations;
134  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 1.0, 0.0, 0.0 ) ) ) );
135  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.6, -0.1, 0.2 ) ) ) );
136  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 1.0, 1.0, 1.0 ) ) ) );
137  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( -0.1, -0.3, 0.5 ) ) ) );
138  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.56347, 0.374, 0.676676 ) ) ) );
139  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.56347, 0.374, -0.676676 ) ) ) );
140  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.0, 0.0, -4.0 ) ) ) );
141  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.0, 4.0, 1.0 ) ) ) );
142 
143  // WMatrix<double> SHToTensor = WSymmetricSphericalHarmonic::calcSHToTensorSymMatrix( 2, orientations );
144  // // TODO(all): remove the WValue from the following line, when WTensorSym supports WVector_2
145  // WTensorSym< 2, 3, double > t( WValue<double>( SHToTensor * w ) );
146 
147  // for( std::vector< WUnitSphereCoordinates >::iterator it = orientations.begin();
148  // it != orientations.end();
149  // ++it )
150  // {
151  // TS_ASSERT_DELTA( i.getValue( *it ), evaluateSphericalFunction( t, it->getEuclidean() ), 0.001 );
152  // }
153  // }
154 
155  /**
156  * Test complex SH coefficient conversion.
157  */
158  // void testComplex()
159  // {
160  // // calc a conversion matrix
161  // std::vector< WVector3d > grad;
162  // std::vector< unsigned int > edges;
163  // tesselateIcosahedron( &grad, &edges, 3 );
164  // edges.clear();
165 
166  // std::vector< WUnitSphereCoordinates > orientations;
167  // for( std::size_t i = 0; i < grad.size(); ++i )
168  // {
169  // if( grad[ i ][ 0 ] > 0.0 )
170  // {
171  // orientations.push_back( WUnitSphereCoordinates( grad[ i ] ) );
172  // }
173  // }
174  // grad.clear();
175 
176  // WVector_2 values( 15 );
177  // for( std::size_t i = 0; i < 15; ++i )
178  // {
179  // values[ i ] = i / 15.0;
180  // }
181  // WSymmetricSphericalHarmonic sh( values );
182 
183  // WVectorComplex_2 values2 = sh.getCoefficientsComplex();
184 
185  // WMatrixComplex_2 complexBaseMatrix = WSymmetricSphericalHarmonic::calcComplexBaseMatrix( orientations, 4 );
186 
187  // WVectorComplex_2 res = complexBaseMatrix * values2;
188 
189  // for( std::size_t k = 0; k < orientations.size(); ++k )
190  // {
191  // TS_ASSERT_DELTA( res[ k ].imag(), 0.0, 1e-15 );
192  // TS_ASSERT_DELTA( res[ k ].real(), sh.getValue( orientations[ k ] ), 1e-15 );
193  // }
194  // }
195 };
196 
197 #endif // WSYMMETRICSPHERICALHARMONIC_TEST_H