jomega_ai

Untitled

Feb 5th, 2024 (edited)
144
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.25 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <complex>
  3. #include <iomanip>
  4.  
  5. #include <eigen3/Eigen/Dense>
  6. #include <gsl/gsl_sf_legendre.h>
  7.  
  8. int main(int argc, char* argv[])
  9. {
  10.     std::cout << std::fixed << std::setprecision(16);
  11.  
  12.     const double pi                                     = 3.141592653589793238;
  13.  
  14.     std::complex<double> complex_j                      = std::complex<double>(0.0, 1.0);
  15.  
  16.     int I                                               = 17;
  17.     int J                                               = 9;            
  18.     int I_new                                           = 23;
  19.     int J_new                                           = 12;
  20.     int K                                               = 11;
  21.  
  22.     Eigen::MatrixXcd grid                               = Eigen::MatrixXcd(J, I);
  23.     Eigen::MatrixXcd fourier_coefficients               = Eigen::MatrixXcd(J,       (2*K) + 1);
  24.     Eigen::MatrixXcd spherical_coefficients             = Eigen::MatrixXcd((2*K)+1,    K  + 1);
  25.     Eigen::MatrixXcd filtered_fourier_coefficients      = Eigen::MatrixXcd(J_new,   (2*K) + 1);
  26.     Eigen::MatrixXcd filterd_grid                       = Eigen::MatrixXcd(J_new,    I_new);
  27.     Eigen::MatrixXcd computed_grid                      = Eigen::MatrixXcd(J_new, I_new);
  28.  
  29.     Eigen::VectorXd gauss_nodes                         = Eigen::VectorXd(J);
  30.     gauss_nodes(0)                                      = -0.9681602395076261;
  31.     gauss_nodes(1)                                      = -0.8360311073266358;
  32.     gauss_nodes(2)                                      = -0.6133714327005904;
  33.     gauss_nodes(3)                                      = -0.3242534234038089;
  34.     gauss_nodes(4)                                      =  0.0000000000000000;
  35.     gauss_nodes(5)                                      =  0.3242534234038089;
  36.     gauss_nodes(6)                                      =  0.6133714327005904;
  37.     gauss_nodes(7)                                      =  0.8360311073266358;
  38.     gauss_nodes(8)                                      =  0.9681602395076261;
  39.  
  40.     Eigen::VectorXd gauss_weights                       = Eigen::VectorXd(J);
  41.     gauss_weights(0)                                    = 0.0812743883615744;
  42.     gauss_weights(1)                                    = 0.1806481606948574;
  43.     gauss_weights(2)                                    = 0.2606106964029354;
  44.     gauss_weights(3)                                    = 0.3123470770400029;
  45.     gauss_weights(4)                                    = 0.3302393550012598;
  46.     gauss_weights(5)                                    = 0.3123470770400029;
  47.     gauss_weights(6)                                    = 0.2606106964029354;
  48.     gauss_weights(7)                                    = 0.1806481606948574;
  49.     gauss_weights(8)                                    = 0.0812743883615744;
  50.  
  51.     Eigen::VectorXd gauss_nodes_new                     = Eigen::VectorXd(J_new);
  52.     gauss_nodes_new(0)                                  = -0.9815606342467192;
  53.     gauss_nodes_new(1)                                  = -0.9041172563704749;
  54.     gauss_nodes_new(2)                                  = -0.7699026741943047;
  55.     gauss_nodes_new(3)                                  = -0.5873179542866175;
  56.     gauss_nodes_new(4)                                  = -0.3678314989981802;
  57.     gauss_nodes_new(5)                                  = -0.1252334085114689;
  58.     gauss_nodes_new(6)                                  =  0.1252334085114689;
  59.     gauss_nodes_new(7)                                  =  0.3678314989981802;
  60.     gauss_nodes_new(8)                                  =  0.5873179542866175;
  61.     gauss_nodes_new(9)                                  =  0.7699026741943047;
  62.     gauss_nodes_new(10)                                 =  0.9041172563704749;
  63.     gauss_nodes_new(11)                                 =  0.9815606342467192;
  64.  
  65.     for (int j=0; j<J_new; ++j)
  66.     {
  67.         double theta                                    = acos(gauss_nodes_new(j));  
  68.  
  69.         for (int i = 0; i<I_new; ++i)
  70.         {  
  71.             double phi                                  = (2.0*pi*i) / I_new;
  72.             computed_grid(j, i)                         = cos(3.0 * theta) * sin(2.0 * phi);    
  73.         }
  74.     }
  75.  
  76.     for (int j=0; j<J; ++j)
  77.     {
  78.         double theta                                    = acos(gauss_nodes(j));    
  79.  
  80.         for (int i = 0; i<I; ++i)
  81.         {  
  82.             double phi                                  = (2.0*pi*i) / I;
  83.             grid(j, i)                                  = cos(3.0 * theta) * sin(2.0 * phi);
  84.         }
  85.     }    
  86.  
  87.     for (int j=0; j<J; j++)
  88.     {    
  89.         for (int m=-K; m<=K; ++m)
  90.         {
  91.             for (int i=0; i<I; i++)
  92.             {  
  93.                 double phi                              = (2.0*pi*i) / I;
  94.                 std::complex<double> exponent           = ( cos(-m*phi) + (complex_j * sin(-m*phi)) );
  95.                 fourier_coefficients(j, m+K)            += ( grid(j, i) *  exponent );
  96.             }  
  97.             fourier_coefficients(j, m+K)                *= ( sqrt(2.0 * pi) / static_cast<double>(I) );
  98.         }
  99.     }    
  100.  
  101.     for (int m=-K; m<=K; ++m)
  102.     {
  103.         for (int n=abs(m); n<=K; ++n)
  104.         {      
  105.             for (int j=0; j<J; j++)
  106.             {
  107.                 double theta                            = acos(gauss_nodes(j));                
  108.                 double w_j                              = gauss_weights(j);    
  109.                 double na_legendre                      = gsl_sf_legendre_sphPlm(n, abs(m), cos(theta));
  110.  
  111.                 spherical_coefficients(m+K, n)          += (fourier_coefficients(j, m+K) *
  112.                                                             na_legendre                  *
  113.                                                             w_j);
  114.             }            
  115.         }
  116.     }
  117.  
  118.     for (int j=0; j<J_new; j++)
  119.     {
  120.         double theta                                    = acos(gauss_nodes_new(j));
  121.  
  122.         for (int m=-K; m<=K; ++m)
  123.         {
  124.             for (int n=abs(m); n<=K; ++n)
  125.             {                
  126.                 double na_legendre                      = gsl_sf_legendre_sphPlm(n, abs(m), cos(theta));
  127.  
  128.                 filtered_fourier_coefficients(j, m+K)   += (spherical_coefficients(m+K, n) *
  129.                                                             na_legendre);
  130.             }            
  131.         }        
  132.     }
  133.  
  134.     for (int j=0; j<J_new; j++)
  135.     {    
  136.         for (int i=0; i<I_new; i++)
  137.         {            
  138.             for (int m=-K; m<=K; ++m)
  139.             {  
  140.                 double phi                              = (2.0 * pi * i) / I_new;
  141.  
  142.                 std::complex<double> exponent           = ( cos(m*phi) + (complex_j * sin(m*phi)) );
  143.  
  144.                 filterd_grid(j, i)                      += ( sqrt(2.0 * pi) * filtered_fourier_coefficients(j, m+K) * exponent);
  145.             }
  146.         }
  147.     }
  148.    
  149.     for (int j=0; j<J_new; ++j)
  150.     {
  151.         for (int i=0; i<I_new; ++i)
  152.         {
  153.             std::cout <<filterd_grid(j, i).real()<<"\t"<<filterd_grid(j, i).imag()<<std::endl;
  154.         }
  155.         std::cout << std::endl;
  156.     }
  157.  
  158.     for (int j=0; j<J_new; ++j)
  159.     {
  160.         for (int i = 0; i<I_new; ++i)
  161.         {  
  162.             std::cout <<computed_grid(j, i).real()<<"\t"<<computed_grid(j, i).imag()<<std::endl;
  163.         }
  164.         std::cout << std::endl;
  165.     }
  166. }
Comments
Add Comment
Please, Sign In to add comment