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