Пример #1
0
int main()
{
#  include "assoc_legendre_p.ipp"

   add_data(assoc_legendre_p);

   unsigned data_total = data.size();

   screen_data([](const std::vector<double>& v){  return boost::math::legendre_p(v[0], v[1], v[2]);  }, [](const std::vector<double>& v){ return v[3];  });


#if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
   screen_data([](const std::vector<double>& v){  return std::tr1::assoc_legendre(v[0], v[1], v[2]);  }, [](const std::vector<double>& v){ return v[3];  });
#endif
#if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
   screen_data([](const std::vector<double>& v){  return gsl_sf_legendre_Plm(v[0], v[1], v[2]);  }, [](const std::vector<double>& v){ return v[3];  });
#endif

   unsigned data_used = data.size();
   std::string function = "assoc_legendre[br](" + boost::lexical_cast<std::string>(data_used) + "/" + boost::lexical_cast<std::string>(data_total) + " tests selected)";
   std::string function_short = "assoc_legendre";

   double time;

   time = exec_timed_test([](const std::vector<double>& v){  return boost::math::legendre_p(v[0], v[1], v[2]);  });
   std::cout << time << std::endl;
#if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL)  || defined(TEST_RMATH))
   report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name());
#endif
   report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name());
   //
   // Boost again, but with promotion to long double turned off:
   //
#if !defined(COMPILER_COMPARISON_TABLES)
   if(sizeof(long double) != sizeof(double))
   {
      time = exec_timed_test([](const std::vector<double>& v){  return boost::math::legendre_p(v[0], v[1], v[2], boost::math::policies::make_policy(boost::math::policies::promote_double<false>()));  });
      std::cout << time << std::endl;
#if !defined(COMPILER_COMPARISON_TABLES) && (defined(TEST_GSL) || defined(TEST_RMATH))
      report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, boost_name() + "[br]promote_double<false>");
#endif
      report_execution_time(time, std::string("Compiler Comparison on ") + std::string(platform_name()), function_short, compiler_name() + std::string("[br]") + boost_name() + "[br]promote_double<false>");
   }
#endif


#if defined(TEST_LIBSTDCXX) && !defined(COMPILER_COMPARISON_TABLES)
   time = exec_timed_test([](const std::vector<double>& v){  return std::tr1::assoc_legendre(v[0], v[1], v[2]);  });
   std::cout << time << std::endl;
   report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "tr1/cmath");
#endif
#if defined(TEST_GSL) && !defined(COMPILER_COMPARISON_TABLES)
   time = exec_timed_test([](const std::vector<double>& v){  return gsl_sf_legendre_Plm(v[0], v[1], v[2]);  });
   std::cout << time << std::endl;
   report_execution_time(time, std::string("Library Comparison with ") + std::string(compiler_name()) + std::string(" on ") + platform_name(), function, "GSL " GSL_VERSION);
#endif

   return 0;
}
Пример #2
0
/*
 * Generate basis transformation matrix for a harmonic oscillator with
 * frequency switch: S
 *
 * rho_t = S * rho_t0 * S'
 *
 */
qdpack_operator_t *
basis_transform(qdpack_simulation_t *sim, qdpack_hilbert_space_t *qs, int n, ho_w_func_t ho_w_cb, double t)
{
    qdpack_complex z;
    qdpack_operator_t *S;
    int i, j, ns, mm, ll;
    double r, w0, wt, sij;
    qdpack_operator_list_t op_list;

    ns = qs->nstates[n];

    if ((S = qdpack_operator_alloc(qs)) == NULL)
    {
        fprintf(stderr, "basis_transform_ho: Failed to allocate basis tranformation matrix (Out of memory?).\n");
 
    }
    qdpack_operator_set_zero(S);
    
    w0 = ho_w_cb(0.0, sim);
    wt = ho_w_cb(t, sim);    

    r = 2 * sqrt(w0 * wt) / (wt + w0);
    if (r > 1.0)
        r = 1.0;
    else if (r < -1.0)
        r = -1.0;
    
    //printf("DEBUG: basis_transform: r = %f (%f, %f): %f\n", r, w0, wt, t);
    
    for (j = 0; j < ns; j++)
    {
        for (i = j; i < ns; i++)
        {
            if ((i == j) || ((i+j)%2 == 0))
            {
                ll = (i+j)/2;
                mm = abs(i-j)/2;
                sij = fact_sqrt(MIN(i,j)) / fact_sqrt(MAX(i,j)) * sqrt(r) * gsl_sf_legendre_Plm(ll, mm, r);
                //if (wt > w0)
                QDPACK_SET_COMPLEX(&z, sij, 0.0);
                //else    
                //    QDPACK_SET_COMPLEX(&z, -sij, 0.0);
                qdpack_operator_set(S, i, j, z);
                
                if (i != j)
                {
                    sij = pow(-1.0, (j-i)/2.0) * sij;
                    QDPACK_SET_COMPLEX(&z, sij, 0.0);
                    qdpack_operator_set(S, j, i, z);
                }
            }
        }
    }

    if (qs->nsubsys > 1)
    {
        qdpack_operator_list_init(&op_list);

        for (i = 0; i < qs->nsubsys; i++)
        {
            qdpack_operator_t *M;
            qdpack_hilbert_space_t *qs_sub = qdpack_hilbert_space_new();
            qdpack_hilbert_space_add(qs_sub, qs->nstates[i]);

            M = qdpack_operator_alloc(qs_sub);

            if (i != n)
            {
                operator_unit(M, qs, i);
            }
            else
            {
                M = S;
            }

            qdpack_operator_list_append(&op_list, M);

            // XXX: free qs, free M
        }
        qdpack_operator_tensor(S, qs, &op_list);
        qdpack_operator_list_free_entries(&op_list);
    }
    
    return S;
}
int main( int argc, const char *argv[] )
{
	FILE*  fp;
	int    i,j,k,ii,p,q,x,y,z,u,g,mmm;
	int    s=0,o=0,v=0;
	const int    l=137,n=5,r=2,h=17,num=50,m=5;
	int    lll[h],llll[m],mm[h],cc[10];
	double t1[n],t2[n],t3[n],t4[n],t5[n],t6[n],namda[h],bl[h];
	double ss[h][h],ssr[h][h],sss[h][h],cs[n],kkk[h];
	double uss[h][h][n][n][n],ussr[h][h][n][n][n];
	double jc[n][n],jcr[n][n],jjj[n][n][n][h],jj[r][h],jj1[n][n][n][h];
	double jjr[n][n][n][h],jjr1[n][n][n][h],pp[h][n],jjjj[h][h][h][h];
	const double rr=0.12,pi=3.141592365,aa=0.0288997;
	const double a=0.0,b=1.0,c=0.0,d=1.0,e=0.0,f=1.0;
	const double node[n]={-0.9061798459,-0.5384693101,0.0,0.5384693101,0.9061798459};
	const double w[n]={0.2369268851,0.4786286705,0.5688888889,0.4786286705,0.2369268851};
	const double kk[l]={3.142, 4.493, 5.764, 6.283, 6.988, 7.725, 8.183, 9.095, 9.356, 9.425,10.417, 10.513, 10.904, 11.657, 11.705,12.323,12.566, 12.781,12.967,13.698, 13.916, 14.066, 14.207, 15.0335, 15.040, 15.4313,15.515, 15.708,16.1447,16.355,16.641, 16.924, 17.2208, 17.2505,17.648, 17.8386, 18.301,18.3513, 18.689, 18.8496, 18.923, 19.0259, 19.4477, 19.653, 20.1218,20.1825, 20.2039, 20.5402, 20.984, 21.374, 21.4285, 21.5254, 21.6292,21.8539, 21.991, 22.2953, 22.5368, 22.6627, 22.715, 22.9046, 23.3042,23.5195, 23.5913, 23.6933, 23.7978, 23.8865, 24.2628, 24.7276, 24.8438, 24.8732, 24.878, 25.0128, 25.101,25.1327, 25.6029, 25.9557, 25.989, 26.1278, 26.1428, 26.3072, 26.4768, 26.6661, 26.927, 27.0311, 27.1294,27.4013, 27.5058,27.5079, 27.9165, 28.1043, 28.1678, 28.2371, 28.2653,28.2743, 28.6498, 28.6974, 28.8704, 29.1756, 29.3326, 29.3971,29.5346, 29.6426, 29.8116, 29.8828, 29.8893, 30.2173, 30.5251,30.7304, 30.8208, 31.0624, 31.0939, 31.1206, 31.3127, 31.3201, 31.4159, 31.5502, 31.6496, 32.0967, 32.1112, 32.2366, 32.3444, 32.3789, 32.5247, 32.7708, 32.8037, 32.8705, 32.9564, 33.3632, 33.4058, 33.4432, 33.4768, 33.5613, 33.8888,33.9371, 34.1795,34.2654, 34.4705};
	const int ll[l]={0, 1, 2, 0, 3, 1, 4, 2, 5, 0, 3, 6, 1, 7, 4, 2, 0, 8, 5, 3, 9, 1, 6, 10, 4, 7, 2, 0, 11, 5, 8, 3, 1, 12, 6, 9, 4, 13, 2, 0, 7, 10, 14, 5, 3, 8, 11, 15, 6, 12, 9, 4, 16, 2, 0, 7, 13, 10, 17, 5, 3, 1, 8, 14, 18, 11, 6, 4, 15, 9, 19, 2, 12, 0, 7, 20, 16, 5, 10, 13, 3, 1, 8, 21, 17, 11, 14, 6, 4, 22, 2, 9, 18, 0, 12, 15, 7, 23, 5, 19, 10, 3, 1,16, 13, 8, 20, 6, 11, 17, 4, 14, 25, 2, 0, 9, 21, 12, 7, 18, 15, 26,5, 22, 3, 10, 1, 13, 19, 27, 8, 16, 23, 6, 11, 4, 2};
	#pragma omp parallel
	printf("%f\n",kk[136]);
//===============================Gauss Legendre Integrate============================
	for ( i=0; i<n; i++)
	{
		t1[i]=(rr+a)/2.0+(rr+a)*node[i]/2.0;
		t2[i]=(rr+c)/2.0+(rr-c)*node[i]/2.0;
		t3[i]=(e+f)/2.0+(f-e)*node[i]/2.0;
		t4[i]=(b+rr)/2.0+(b-rr)*node[i]/2.0;
		t5[i]=(d+rr)/2.0+(d-rr)*node[i]/2.0;
		t6[i]=(e+f)/2.0+(f-e)*node[i]/2.0;
		/*printf("%d\n",t3[i]);*/
	}
//==================================Qutanum Number===================================
	for ( i=0; i<m; i++)
	{
		llll[i]=2*ll[i]+1;
		/*printf("%d\n",llll[i]);*/
	}

	for ( i=0; i<m; i++)
	{
		for ( j=0; j<llll[i] ; j++)
		{
			lll[s]=ll[i];
			/*printf("%d\n",lll[s]);*/
			s=s+1;
		}
	}

	for ( i=0; i<m; i++)
	{
	mmm=-ll[i];
		for ( j=0; j<llll[i]; j++)
		{
			mm[o]=mmm;
			/*printf ("%d\n",mm[o]);*/
			mmm=mmm+1;
			o=o+1;
		}
	}

	for ( i=0; i<m; i++)
	{
		for ( j=0; j<llll[i] ; j++)
		{
			kkk[v]=kk[i];
			/*printf ("%f\n",kkk[v]);*/
			v=v+1;
		}
	}

//====================================Radial wave function============================
	for ( i=0; i<r; i++)
	{
		for ( j=0; j<h ; j++)
		{
		if (lll[j]-pow((-1),i)==-1)
		{
			jj[i][j]=cos(kkk[j])/kkk[j];
			/*printf("%f\n",jj[i][j]);*/
		}
		else
		{
			jj[i][j]=gsl_sf_bessel_jl ( lll[j]-pow((-1),i),  kkk[j]);
			/*printf("%f\n",jj[i][j]);*/
		}
		}
	}
/*printf("%f\n",jj[1][2]);*/

	for ( i=0; i<n; i++)
		for ( j=0; j<n ; j++)
			for ( k=0; k<n; k++)
				for ( q=0; q<h; q++)
				{
					jjr[i][j][k][q]=gsl_sf_bessel_jl(kkk[q]*(sqrt(t1[i]*t1[i]+0.25*t2[j]*t2[j]-t1[i]*t2[j]*t3[k])),lll[q]);
					jjr1[i][j][k][q]=gsl_sf_bessel_jl(kkk[q]*(sqrt(t1[i]*t1[i]+0.25*t2[j]*t2[j]+t1[i]*t2[j]*t3[k])),lll[q]);
					jjj[i][j][k][q]=gsl_sf_bessel_jl(kkk[q]*(sqrt(t4[i]*t4[i]+0.25*t5[j]*t5[j]-t4[i]*t5[j]*t6[k])),lll[q]);
					jj1[i][j][k][q]=gsl_sf_bessel_jl(kkk[q]*(sqrt(t4[i]*t4[i]+0.25*t5[j]*t5[j]+t4[i]*t5[j]*t6[k])),lll[q]);
					/*printf("%f\n",jjr[i][j][k][q]);*/
				}
//====================================Angular wave function============================
	cc[0]=1;
	for ( i=1; i<10; i++)
	{
		cc[i]=cc[i-1]*(i);
		/*printf ("%d\n",cc[i]);*/
	}

	for ( i=0; i<h; i++)
		for ( q=0; q<n; q++)
		{
			if (mm[i]>=0)
			{
				pp[i][q]=gsl_sf_legendre_Plm (lll[i], mm[i], t3[q]);
				/*printf ("%f\n",pp[i][q]);*/
			}
			else
			{
				pp[i][q]=pow((-1),-mm[i])*cc[lll[i]+mm[i]]/cc[lll[i]-mm[i]]*gsl_sf_legendre_Plm (lll[i], -mm[i], t3[q]);
				/*printf ("%f\n",pp[i][q]);*/
			}
		}

//==========================================Initial===================================
	for ( i=0; i<h; i++)
	{
		bl[i]=sqrt(num*pow(0.5,i));
		/*printf ("%f\n",bl[i]);*/
	}
//========================================Interaction=================================
	for ( i=0; i<n; i++)
		for ( j=0; j<n ; j++)
		{
			jcr[i][j]=0.5*80*(-2)*(2*pi*t1[i]*t2[j])*(2*pi*t1[i]*t2[j]);
			jc[i][j]=-0.5*40/3.14*(-2)*(2*pi*t1[i]*t2[j])*(2*pi*t1[i]*t2[j])*pow(t5[j]/rr,-6);
			/*printf("%f\n",jc[i][j]);*/
		}
//===================================Matrix Element(four)============================
	for ( x=0; x<h; x++)
		for ( y=0; y<h ; y++)
			for ( z=0; z<h; z++)
				for ( u=0; u<h; u++)
				{
				jjjj[x][y][z][u]=jj[1][x]*jj[0][x]*jj[1][y]*jj[0][y]*jj[1][z]*jj[0][z]*jj[1][u]*jj[0][u];
				/*printf ("%.10f\n",jjjj[x][y][z][u]);*/
				}



	for ( x=0; x<h; x++)
		for ( y=0; y<h ; y++)
			for ( g=0; g<n; g++)
				for ( q=0; q<n; q++)
					for ( p=0; p<n ; p++)
						for ( z=0; z<h; z++)
							for ( u=0; u<h; u++)
							{
ussr[x][y][p][q][g]=ussr[x][y][p][q][g]+4*jjr[p][q][g][x]*jjr[p][q][g][y]*jjr1[p][q][g][z]*jjr1[p][q][g][u]*bl[z]*bl[u]*pp[x][g]*pp[y][g]*pp[z][g]*pp[u][g]/jjjj[x][y][z][u];
uss[x][y][p][q][g]=uss[x][y][p][q][g]+4*jjj[p][q][g][x]*jjj[p][q][g][y]*jj1[p][q][g][z]*jj1[p][q][g][u]*bl[z]*bl[u]*pp[x][g]*pp[y][g]*pp[z][g]*pp[u][g]/jjjj[x][y][z][u];
							/*printf ("%f\n",ussr[x][y][p][q][g]);*/
							/*printf ("%f\n",jjr[p][q][g][u]);*/
							/*printf ("%f\n",jjr1[p][q][g][x]);*/
							/*printf ("%f\n",bl[z]);*/
							/*printf ("%f\n",pp[y][g]);*/
							/*printf ("%f\n",jj[2][z]);*/
							}

//===================================Matrix Element(two)============================
	for ( x=0; x<h; x++)
		for ( y=0; y<h ; y++)
			for ( p=0; p<n; p++)
				for ( q=0; q<n; q++)
					for ( g=0; g<n; g++)
						{
							ssr[x][y]=ssr[x][y]+jcr[p][q]*ussr[x][y][p][q][g]*w[p]*w[q]*w[g];
							sss[x][y]=sss[x][y]+jc[p][q]*uss[x][y][p][q][g]*w[p]*w[q]*w[g];
							/*printf ("%f\n",ussr[0][4][p][q][g]*jcr[p][q]*w[p]*w[q]*w[g]);*/
							/*printf ("%.10f\n",jcr[i][j]);*/
							/*printf ("%f\n",w[g]);*/
							/*printf ("%f\n",sss[x][y]);*/
						}

	for ( x=0; x<h; x++)
		for ( y=0; y<h; y++)
printf("%.8f\n",sss[x][y]);
//======================================Diagnal======================================
	for ( x=0; x<h; x++)
		for ( y=0; y<h; y++)
			{
			if ( x==y )
			{
				ssr[x][y]=ssr[x][y]*(rr-a)/2.0*(rr-c)/2.0*(f-e)/2.0;
				sss[x][y]=sss[x][y]*(b-rr)/2.0*(d-rr)/2.0*(f-e)/2.0;
				ss[x][y]=sss[x][y]+ssr[x][y]+aa*kkk[y]*kkk[y];
			}
			if ( x!=y )
			{
				ssr[x][y]=ssr[x][y]*(rr-a)/2.0*(rr-c)/2.0*(f-e)/2.0;
				sss[x][y]=sss[x][y]*(b-rr)/2.0*(d-rr)/2.0*(f-e)/2.0;
				ss[x][y]=sss[x][y]+ssr[x][y];
			}
			}

	/*打开文本文件以写入内容*/
	fp = fopen("test.txt", "w");
	if (!fp)
	{
		perror("cannot open file");
		//exit(-1);
	}

	/*把二维数组的内容写入文件*/
	for (i = 0; i < h; i++)
	{
		for (j = 0; j < h; j++)
		{
		fprintf(fp, "%f ", ss[i][j]);
		}
	fputc('\n', fp);
	}
	fclose(fp);



	return 0;

}