main.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #include <iostream>
  2. #include <fstream>
  3. #include <limits>
  4. #include <mpi.h>
  5. #include "superdirectivity.h"
  6. #include "sph_bessel.h"
  7. #include "jade.h"
  8. using namespace std;
  9. int main(int argc, char* argv[]) {
  10. // directivity calculation
  11. /**/
  12. {
  13. cout.precision(15);
  14. int ni = 3, ND = 30;
  15. Real kz, wl, wv, dir;
  16. vector<Real> kR;
  17. vector<Complex> eps;
  18. wl = 0.455; wv = 2*_pi/wl;
  19. sphere_ml sph(ND);
  20. // kR.push_back(2*_pi/0.455*0.07985);
  21. // eps.push_back(pow(Real(6.325),2));
  22. // eps.push_back(Real(1));
  23. /**
  24. kR.push_back(2*_pi*0.0486056995345798/0.455);
  25. kR.push_back(2*_pi*0.0824637171512022/0.455);
  26. kR.push_back(2*_pi*0.08645/0.455);
  27. eps.push_back(pow(Real(4.98055106546034),2));
  28. eps.push_back(pow(Real(5.0),2));
  29. eps.push_back(pow(Real(3.34491667760117),2));
  30. eps.push_back(Real(1));
  31. /**/
  32. kR.push_back(0.023666594336234 * wv);
  33. kR.push_back(0.136411859930056 * wv);
  34. kR.push_back(0.1365 * wv);
  35. eps.push_back(pow(Real(1.0),2));
  36. eps.push_back(pow(Real(7.97246729336805),2));
  37. eps.push_back(pow(Real(5.17006034408423),2));
  38. eps.push_back(Real(1)); // premittivity of the supprounding medium
  39. // dependence of the directivity from the dipole position
  40. ofstream out_dir("e:/Alexey/03 - code/data/directivity/dir.dat");
  41. for (kz=0.01*kR[2]; kz<1.5*kR[2]; kz+=.01*kR[2]) {
  42. out_dir << kz << " " << sph.get_directivity_edipole_x(kz,kR,eps) << endl;
  43. }
  44. // single directivity evaluation
  45. kz = 2*_pi*0.299; //0.5 * (kR[0] + kR[1]);
  46. dir = sph.get_directivity_edipole_x(kz,kR,eps);
  47. cout << "directivity at position kz = " << kz << " equals to " << dir << endl;
  48. // get amplitude vector from the last directivity calculation:
  49. vector<Complex> v_amp = sph.get_last_ampl();
  50. cout << "amplitudes of e-waves (m = 1):\n";
  51. for (int n=0; n<ND; ++n) cout << n+1 << " " << (v_amp[3*n]) << endl;
  52. cout << "amplitudes of h-waves (m = 1):\n";
  53. for (int n=0; n<ND; ++n) cout << n+1 << " " << (v_amp[3*n+1]) << endl;
  54. cout << "amplitudes of h-waves (m = 0):\n";
  55. for (int n=0; n<ND; ++n) cout << n+1 << " " << (v_amp[3*n+2]) << endl;
  56. // radiation pattern based on the last directivity calculation
  57. vector<Complex> E_par, E_perp;
  58. ofstream out_pat("e:/Alexey/03 - code/data/directivity/pat.dat");
  59. for (Real th=0; th<361; th+=1) {
  60. E_par = sph.ampl_far(th*_pi/180, Real(0));
  61. E_perp = sph.ampl_far(th*_pi/180, 0.5*_pi);
  62. out_pat << th+90 << " " << (norm(E_par[0])) << " " << (norm(E_perp[1])) << endl;
  63. }
  64. return 0;
  65. }
  66. /**/
  67. /**/
  68. /**/
  69. // directivity optimization section
  70. /**/
  71. {
  72. int ni = 3; // number of spherical interfaces
  73. Real kr_max = Real(1); // maximum kr
  74. Real eps_max = Real(225); // maximum epsilon
  75. sphere_ml_parallel cls_sph; // class for calculation of directivity
  76. vector<Real> vb_min, vb_max; // parameter boundaries
  77. // boundaries for all optimization parameters:
  78. vb_min.push_back(Real(0.01)); vb_max.push_back(Real(1.5)*kr_max); // dipole position
  79. for (int i=0; i<ni; ++i)
  80. vb_min.push_back(Real(0.01)); vb_max.push_back(Real(1.5)*kr_max); // radii
  81. for (int i=0; i<ni; ++i)
  82. vb_min.push_back(Real(1)); vb_max.push_back(eps_max); // real permittivities
  83. ofstream out_opt("e:/Alexey/03 - code/data/directivity/opt.dat");
  84. MPI_Init(&argc, &argv);
  85. int rank;
  86. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  87. // Settings for optimization algorithm;
  88. int dimension = 2*ni+1; /// Number of parameters to optimize.
  89. int total_population = 3*dimension; /// Total number of individuals in population.
  90. jade::SubPopulation sub_population;
  91. sub_population.Init(total_population, dimension);
  92. sub_population.FitnessFunction_p = &get_directivity_sphml_dZx_epsRe_parallel;
  93. /// Low and upper bound for all dimensions;
  94. //sub_population.SetAllBoundsVectors({0.005, 0.005}, {0.05, 0.02});
  95. sub_population.SetAllBoundsVectors(vb_min, vb_max);
  96. //sub_population.SetTargetToMinimum();
  97. sub_population.SetTargetToMaximum();
  98. sub_population.SetTotalGenerationsMax(10000);
  99. sub_population.SetBestShareP(0.05);
  100. sub_population.SetAdapitonFrequencyC(0.1);
  101. sub_population.SetDistributionLevel(0);
  102. //sub_population.PrintParameters("f1");
  103. //sub_population.RunOptimization(out_opt, reinterpret_cast<void*>(&cls_sph));
  104. sub_population.RunOptimization(cout, reinterpret_cast<void*>(&cls_sph));
  105. sub_population.PrintResult("directivity function ");
  106. MPI_Finalize();
  107. return 0;
  108. }
  109. /**/
  110. }