spherical_harmonic_data.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. #include <boost/math/special_functions/spherical_harmonic.hpp>
  6. #include <fstream>
  7. #include <boost/math/tools/test_data.hpp>
  8. #include <boost/random.hpp>
  9. #include "mp_t.hpp"
  10. using namespace boost::math::tools;
  11. using namespace boost::math;
  12. using namespace std;
  13. float extern_val;
  14. // confuse the compilers optimiser, and force a truncation to float precision:
  15. float truncate_to_float(float const * pf)
  16. {
  17. extern_val = *pf;
  18. return *pf;
  19. }
  20. template<class T>
  21. boost::math::tuple<T, T, T, T, T, T> spherical_harmonic_data(T i)
  22. {
  23. static boost::mt19937 r;
  24. int n = real_cast<int>(floor(i));
  25. boost::uniform_int<> ui(0, (std::min)(n, 40));
  26. int m = ui(r);
  27. boost::uniform_real<float> ur(-2*constants::pi<float>(), 2*constants::pi<float>());
  28. float _theta = ur(r);
  29. float _phi = ur(r);
  30. T theta = truncate_to_float(&_theta);
  31. T phi = truncate_to_float(&_phi);
  32. T r1 = spherical_harmonic_r(n, m, theta, phi);
  33. T r2 = spherical_harmonic_i(n, m, theta, phi);
  34. return boost::math::make_tuple(n, m, theta, phi, r1, r2);
  35. }
  36. int main(int argc, char*argv [])
  37. {
  38. using namespace boost::math::tools;
  39. parameter_info<mp_t> arg1, arg2, arg3;
  40. test_data<mp_t> data;
  41. bool cont;
  42. std::string line;
  43. if(argc < 1)
  44. return 1;
  45. do{
  46. if(0 == get_user_parameter_info(arg1, "n"))
  47. return 1;
  48. arg1.type |= dummy_param;
  49. arg2.type |= dummy_param;
  50. arg3 = arg2;
  51. data.insert(&spherical_harmonic_data<mp_t>, arg1);
  52. std::cout << "Any more data [y/n]?";
  53. std::getline(std::cin, line);
  54. boost::algorithm::trim(line);
  55. cont = (line == "y");
  56. }while(cont);
  57. std::cout << "Enter name of test data file [default=spherical_harmonic.ipp]";
  58. std::getline(std::cin, line);
  59. boost::algorithm::trim(line);
  60. if(line == "")
  61. line = "spherical_harmonic.ipp";
  62. std::ofstream ofs(line.c_str());
  63. line.erase(line.find('.'));
  64. ofs << std::scientific << std::setprecision(40);
  65. write_code(ofs, data, line.c_str());
  66. return 0;
  67. }