• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //  (C) Copyright John Maddock 2007.
2 //  Use, modification and distribution are subject to the
3 //  Boost Software License, Version 1.0. (See accompanying file
4 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <boost/math/special_functions/spherical_harmonic.hpp>
7 #include <fstream>
8 #include <boost/math/tools/test_data.hpp>
9 #include <boost/random.hpp>
10 #include "mp_t.hpp"
11 
12 using namespace boost::math::tools;
13 using namespace boost::math;
14 using namespace std;
15 
16 float extern_val;
17 // confuse the compilers optimiser, and force a truncation to float precision:
truncate_to_float(float const * pf)18 float truncate_to_float(float const * pf)
19 {
20    extern_val = *pf;
21    return *pf;
22 }
23 
24 
25 
26 template<class T>
spherical_harmonic_data(T i)27 boost::math::tuple<T, T, T, T, T, T> spherical_harmonic_data(T i)
28 {
29    static boost::mt19937 r;
30 
31    int n = real_cast<int>(floor(i));
32    boost::uniform_int<> ui(0, (std::min)(n, 40));
33    int m = ui(r);
34 
35    boost::uniform_real<float> ur(-2*constants::pi<float>(), 2*constants::pi<float>());
36    float _theta = ur(r);
37    float _phi = ur(r);
38    T theta = truncate_to_float(&_theta);
39    T phi = truncate_to_float(&_phi);
40 
41    T r1 = spherical_harmonic_r(n, m, theta, phi);
42    T r2 = spherical_harmonic_i(n, m, theta, phi);
43    return boost::math::make_tuple(n, m, theta, phi, r1, r2);
44 }
45 
main(int argc,char * argv[])46 int main(int argc, char*argv [])
47 {
48    using namespace boost::math::tools;
49 
50    parameter_info<mp_t> arg1, arg2, arg3;
51    test_data<mp_t> data;
52 
53    bool cont;
54    std::string line;
55 
56    if(argc < 1)
57       return 1;
58 
59    do{
60       if(0 == get_user_parameter_info(arg1, "n"))
61          return 1;
62       arg1.type |= dummy_param;
63       arg2.type |= dummy_param;
64       arg3 = arg2;
65 
66       data.insert(&spherical_harmonic_data<mp_t>, arg1);
67 
68       std::cout << "Any more data [y/n]?";
69       std::getline(std::cin, line);
70       boost::algorithm::trim(line);
71       cont = (line == "y");
72    }while(cont);
73 
74    std::cout << "Enter name of test data file [default=spherical_harmonic.ipp]";
75    std::getline(std::cin, line);
76    boost::algorithm::trim(line);
77    if(line == "")
78       line = "spherical_harmonic.ipp";
79    std::ofstream ofs(line.c_str());
80    line.erase(line.find('.'));
81    ofs << std::scientific << std::setprecision(40);
82    write_code(ofs, data, line.c_str());
83 
84    return 0;
85 }
86 
87