OpenWalnut  1.5.0dev
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 "../WValue.h"
43 
44 #include "../WGeometryFunctions.h"
45 #include "../WSymmetricSphericalHarmonic.h"
46 #include "../WTensorSym.h"
47 #include "../WTensorFunctions.h"
48 
49 #include "WMatrixTraits.h"
50 
51 /**
52  * Testsuite for WSymmetricSphericalHarmonic.
53  */
54 class WSymmetricSphericalHarmonicTest : public CxxTest::TestSuite
55 {
56 public:
57  /**
58  * testCalcFRTMatrix
59  *
60  */
61  void testCalcFRTMatrix( void )
62  {
64  WMatrix<double> reference( 15, 15 );
65  reference.setZero();
66  // j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
67  // lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4
68  reference( 0, 0 ) = 2.0 * pi();
69  for( size_t i = 1; i <= 5; i++ )
70  {
71  reference( i, i ) = -2.0 * pi() * 1.0 / 2.0;
72  }
73  for( size_t i = 6; i <= 14; i++ )
74  {
75  reference( i, i ) = 2.0 * pi() * 3.0 / 8.0;
76  }
77 
78  for( size_t i = 0; i < 15; ++i )
79  {
80  for( size_t j = 0; j < 15; ++j )
81  {
82  TS_ASSERT_DELTA( result( i, j ), reference( i, j ), 1e-9 );
83  }
84  }
85  }
86 
87  /**
88  * testCalcSmoothingMatrix
89  *
90  */
92  {
94  WMatrix<double> reference( 15, 15 );
95  reference.setZero();
96  // j 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15
97  // lj 0 2 2 2 2 2 4 4 4 4 4 4 4 4 4
98  reference( 0, 0 ) = 0.0;
99  for( size_t i = 1; i <= 5; i++ )
100  {
101  reference( i, i ) = 36.0;
102  }
103  for( size_t i = 6; i <= 14; i++ )
104  {
105  reference( i, i ) = 400.0;
106  }
107 
108  for( size_t i = 0; i < 15; ++i )
109  {
110  for( size_t j = 0; j < 15; ++j )
111  {
112  TS_ASSERT_DELTA( result( i, j ), reference( i, j ), 1e-9 );
113  }
114  }
115  }
116 
117  // TODO(reichenbach, philips): repair the following to tests
118  /**
119  * The matrix calculated by the calcSHToTensorSymMatrix function should produce tensors that
120  * evaluate to the same values as the respective spherical harmonics.
121  */
122  // void testCalcSHtoTensorMatrix()
123  // {
124  // WValue<double> w( 6 );
125  // for( int i = 0; i < 6; ++i )
126  // {
127  // w[ i ] = exp( i / 6.0 );
128  // }
129 
130  // WSymmetricSphericalHarmonic i( w );
131 
132  // std::vector< WUnitSphereCoordinates > orientations;
133  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 1.0, 0.0, 0.0 ) ) ) );
134  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.6, -0.1, 0.2 ) ) ) );
135  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 1.0, 1.0, 1.0 ) ) ) );
136  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( -0.1, -0.3, 0.5 ) ) ) );
137  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.56347, 0.374, 0.676676 ) ) ) );
138  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.56347, 0.374, -0.676676 ) ) ) );
139  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.0, 0.0, -4.0 ) ) ) );
140  // orientations.push_back( WUnitSphereCoordinates( normalize( WVector3d( 0.0, 4.0, 1.0 ) ) ) );
141 
142  // WMatrix<double> SHToTensor = WSymmetricSphericalHarmonic::calcSHToTensorSymMatrix( 2, orientations );
143  // // TODO(all): remove the WValue from the following line, when WTensorSym supports WVector_2
144  // WTensorSym< 2, 3, double > t( WValue<double>( SHToTensor * w ) );
145 
146  // for( std::vector< WUnitSphereCoordinates >::iterator it = orientations.begin();
147  // it != orientations.end();
148  // ++it )
149  // {
150  // TS_ASSERT_DELTA( i.getValue( *it ), evaluateSphericalFunction( t, it->getEuclidean() ), 0.001 );
151  // }
152  // }
153 
154  /**
155  * Test complex SH coefficient conversion.
156  */
157  // void testComplex()
158  // {
159  // // calc a conversion matrix
160  // std::vector< WVector3d > grad;
161  // std::vector< unsigned int > edges;
162  // tesselateIcosahedron( &grad, &edges, 3 );
163  // edges.clear();
164 
165  // std::vector< WUnitSphereCoordinates > orientations;
166  // for( std::size_t i = 0; i < grad.size(); ++i )
167  // {
168  // if( grad[ i ][ 0 ] > 0.0 )
169  // {
170  // orientations.push_back( WUnitSphereCoordinates( grad[ i ] ) );
171  // }
172  // }
173  // grad.clear();
174 
175  // WVector_2 values( 15 );
176  // for( std::size_t i = 0; i < 15; ++i )
177  // {
178  // values[ i ] = i / 15.0;
179  // }
180  // WSymmetricSphericalHarmonic sh( values );
181 
182  // WVectorComplex_2 values2 = sh.getCoefficientsComplex();
183 
184  // WMatrixComplex_2 complexBaseMatrix = WSymmetricSphericalHarmonic::calcComplexBaseMatrix( orientations, 4 );
185 
186  // WVectorComplex_2 res = complexBaseMatrix * values2;
187 
188  // for( std::size_t k = 0; k < orientations.size(); ++k )
189  // {
190  // TS_ASSERT_DELTA( res[ k ].imag(), 0.0, 1e-15 );
191  // TS_ASSERT_DELTA( res[ k ].real(), sh.getValue( orientations[ k ] ), 1e-15 );
192  // }
193  // }
194 };
195 
196 #endif // WSYMMETRICSPHERICALHARMONIC_TEST_H
void setZero()
Resets the matrix components to zero.
Definition: WMatrix.h:208
Testsuite for WSymmetricSphericalHarmonic.
void testCalcSmoothingMatrix(void)
testCalcSmoothingMatrix
Class for symmetric spherical harmonics The index scheme of the coefficients/basis values is like in ...