void fillArrays( const int nmin, const int nmax )
    {
        {
            double jp1( gsl_sf_bessel_jl( nmax+1, x ) );
            double j( gsl_sf_bessel_jl( nmax, x ) );

            sjArray[nmax-nmin] = j;

            for( int n( nmax ); n >= nmin+1; --n )
            {
                const double jm1( ( n + n + 1.0 ) * x_r * j - jp1 );

                sjArray[n-nmin-1] = jm1;
                jp1 = j;
                j = jm1;
            }
        }

        {
            double y( gsl_sf_bessel_yl( nmin+1, x ) );
            double ym1( gsl_sf_bessel_yl( nmin, x ) );
            syArray[0] = ym1;
            syArray[1] = y;


            for( int n( nmin+1 ); n < nmax; ++n )
            {
                const double yp1( ( n + n + 1.0 ) * x_r * y - ym1 );

                syArray[n-nmin+1] = yp1;
                ym1 = y;
                y = yp1;
            }
        }
    }
Example #2
0
// #include"reaction.h"
int main()
{

////////Input Parameters of the potential (fit parameters) /////
//This finds the natural orbits, and also the actual density
std::string parameters_filename="Input.inp";

NuclearParameters Nu = read_nucleus_parameters( "Input/pca40.inp" );

double Ef=Nu.Ef;
int lmax=6;
double z0=20.0;
double zp0;
double A0=40.0;
double tz=0.5;

int type=1;
int mvolume = 4;
int AsyVolume = 1;

double A = 40.0;

if (tz>0) { zp0=1;}
else {zp0=0;}

double ph_gap = Nu.ph_gap;
double  rStart = .05;
double  rmax = 12.;
double  ham_pts = 720; 

double  rdelt = rmax / ham_pts;
double  rdelt_p = rdelt / 1.025641026;

// Construct Parameters Object
Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, zp0 );
// Construct Potential Object
pot pottt = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
pot * pott = &pottt;
// store coulomb potential in order to compare with

//creating boundspace object
boundRspace initiate(rmax , ham_pts , Ef, ph_gap , lmax , Nu.Z , zp0 , Nu.A , pott);


double tol=.01;
double estart=Ef;
double Emax=2*-4.7;
double Emin=-200.0+Emax;

 // Create momentum space grid
std::vector<double> kmesh;
std::vector<double> kweights;
double const kmax = 5.0;
int const kpts = ham_pts;
kmesh.resize( kpts );
kweights.resize( kpts );
GausLeg( 0., kmax, kmesh, kweights );

///// Making rmesh///

vector<double> rmesh= initiate.make_rmesh();
vector <double> rmesh_p = initiate.make_rmesh_point();

std::vector< lj_eigen_t > bound_levels = initiate.get_bound_levels( rmesh, tol );

std::vector< mesh_t > emesh_vec =
        initiate.get_emeshes( rmesh, Emin, Emax, bound_levels );

cout<<"emesh_vec = "<<emesh_vec.size()<<endl;

std::vector< prop_t > prop_vec = initiate.get_propagators( rmesh, emesh_vec );

vector <double> pdist = initiate.point_distribution(rmesh,Emax,emesh_vec,prop_vec,bound_levels);

vector <double> kdist = initiate.point_dist_k(rmesh,Emax,emesh_vec,prop_vec,bound_levels);

double part=0;
double kpart=0;
double nat=0.0;
double occ=0.0;
double J;

double p_part=0;
double k_part=0;
vector <double> natden;
natden.assign(rmesh.size(),0);
vector<double> p_dist;
p_dist.assign( rmesh.size(), 0 );
vector<double> k_dist;
k_dist.assign( kmesh.size(), 0 );

for(int L=0;L<lmax+1;L++){
	for(int s=0;s<2;s++){	
		J=L-0.5+s;
		if(J<0){
			s=1;
			J=0.5;
		}
	
		string jlab;
		if(J==0.5){
			jlab="12";
		}else if(J==1.5){
			jlab="32";
		}else if(J==2.5){
			jlab="52";
		}else if(J==3.5){
			jlab="72";
		}else if(J==4.5){
			jlab="92";
		}else if(J==5.5){
			jlab="112";
		}

		string llab;
		if(L==0){
			llab="s";
		}else if(L==1){
			llab="p";
		}else if(L==2){
			llab="d";
		}else if(L==3){
			llab="f";
		}else if(L==4){
			llab="g";
		}else if(L==5){
			llab="h";
		}

		// Create Bessel Function matrix in k and r
    matrix_t bess_mtx( kmesh.size(), rmesh.size() );
		bess_mtx.clear();
    for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
	    for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {
	      double rho = kmesh[nk] * rmesh_p[nr];
        bess_mtx( nk, nr ) = gsl_sf_bessel_jl( L, rho );
      }
    }		

		cout<<"eigenvalues now"<<endl;		
		cout<<"L = "<<L<<", J = "<<J<<endl;

		int index=initiate.index_from_LJ(L,J);

		const prop_t &propE = prop_vec.at(index);

		const mesh_t &emesh = emesh_vec.at(index);

		matrix_t d_mtx( rmesh.size(), rmesh.size() ); // density matrix
		d_mtx.clear();

		const lj_eigen_t &levels = bound_levels.at( index );

		cout<<"levels.size() = "<<levels.size()<<endl;

		//Remember that propE is actually G*r*r'*rdelt
		for(unsigned int n=0;n<emesh.size();++n){	
			double Edelt=emesh[n].second;
		  for( unsigned int i = 0; i < rmesh.size(); ++i ) {
				for( unsigned int j = 0; j < rmesh.size(); ++j ) {
					d_mtx(i,j) -= Edelt * imag(propE[n](i,j)) / M_PI;  
				} 
			} 
		}		

		for ( unsigned int N = 0; N < levels.size(); ++N ){   
    	if ( ( levels[N].first <= Ef ) && 
      ( levels[N].first > Emax ) ) {

				// Quasiparticle energy
       	double QPE = levels[N].first; 

        // Quasiparticle wavefunction
        const std::vector<double> &QPF = levels[N].second;				

        // Spectroscopic Factor
        double S = initiate.sfactor( rmesh, QPE, L, J, QPF );

        for ( unsigned int i = 0; i < rmesh.size(); ++i ) {
					for(int j=0;j<rmesh.size();j++){
	          d_mtx(i,j) +=  S * QPF[i] * QPF[j] * rmesh[i]*rmesh[j]*rdelt;
          }
				}
        cout << "added to charge density "<<N<<" "<< L << " " << J << " " << QPE << " "<< S << std::endl;

     	} // endif

		} // End loop over N

		vector <eigen_t> eig = initiate.real_eigvecs(d_mtx);

		string dest = "waves/";

		string eiglab = dest + "eig" + llab+jlab+".txt";

		ofstream fval(eiglab.c_str());

		double Nmax=10;

		for(int N=0;N<Nmax;N++){

			double spot = rmesh.size()-N-1;

			double norm=0;

			for(int i=0;i<rmesh.size();++i){
				norm += rdelt * pow( eig[spot].second[i],2);
			}

			if(eig[spot].second[0]<0){
				for(int i=0;i<rmesh.size();i++){
					eig[spot].second[i] *= -1.0;
				}
			}

			//Transforming natural orbits to k-space
			vector <double> knat;
			knat.assign(kmesh.size(),0);
			for(int ik=0;ik<kmesh.size();ik++){
				double kn=0;
				for(int ir=0;ir<rmesh.size();ir++){
					kn += rdelt_p * sqrt(2.0/M_PI) * bess_mtx(ik,ir) * eig[spot].second[ir]/sqrt(norm) / rmesh[ir] 
					* pow(rmesh_p[ir],2);
				}
				knat[ik] = kn;		
			}

		
			double normk = 0;
			for(int i=0;i<kmesh.size();i++){
				normk += kweights[i] * pow(knat[i]*kmesh[i],2);
			}

			//for(int i=0;i<kmesh.size();i++){
				//knat[i] = knat[i]/sqrt(normk);
			//}

			occ += eig[spot].first*(2*J+1);

			for(int i=0;i<rmesh.size();i++){
				natden[i] += eig[spot].first*pow(eig[spot].second[i]/rmesh[i]/sqrt(norm),2)*(2*J+1)/(4*M_PI);
				k_dist[i] += eig[spot].first * pow(knat[i],2) * (2*J+1) / (4*M_PI);
			} 

			string Nlab;
			ostringstream convert;
			convert << N;
			Nlab = convert.str();

			string veclab = dest + "eig" + llab + jlab + Nlab + ".txt";

			std::ofstream feig(veclab.c_str());

			fval<<eig[spot].first<<endl;
			//cout<<eig[spot].first<<endl;

			for(int i=0;i<rmesh.size();++i){
				//want to give R(r), so print out u(r)/r
				feig<<rmesh[i]<<" "<<eig[spot].second[i]/sqrt(norm)/rmesh[i]<<endl;
				//feig<<kmesh[i]<<" "<<knat[i]<<endl;			
			}

		} //ending loop over N

	}  //ending loop over s
} //ending loop over L

ofstream fdenr("waves/natden.txt");
ofstream fdenk("waves/natdenk.txt");
ofstream kden("waves/denk.txt");
ofstream fpoint("waves/pdist.txt");
ofstream kpoint("waves/kdist.txt");

for(int i=0;i<rmesh.size();i++){
	nat += natden[i] * rdelt_p * pow(rmesh_p[i],2) * 4*M_PI;
	part += pdist[i] * rdelt_p * pow(rmesh_p[i],2) * 4 * M_PI;
}

for(int i=0;i<rmesh.size();i++){
	fdenr<<rmesh_p[i]<<" "<<natden[i]/nat<<endl;
	fpoint<<rmesh_p[i]<<" "<<pdist[i]<<endl;
}

for(int i=0;i<kmesh.size();i++){
	kpart += kdist[i] * kweights[i] * pow(kmesh[i],2) * 4 * M_PI;
	k_part += k_dist[i] * kweights[i] * pow(kmesh[i],2) * 4 * M_PI;
}

for(int i=0;i<kmesh.size();i++){
	fdenk<<kmesh[i]<<" "<<k_dist[i]/k_part<<endl;
	kpoint<<kmesh[i]<<" "<<kdist[i]<<endl;
}

cout<<"Particle Number from dist (r) = "<<part<<endl;
cout<<"Particle Number from dist (k) = "<<kpart<<endl;
cout<<"particle number from natural (r) = "<<nat<<endl;
cout<<"particle number from natural (k) = "<<k_part<<endl;

}
Example #3
0
static Real _j(UnsignedInteger n, Real z)
{
    return gsl_sf_bessel_jl(n, z);
}
Example #4
0
int main() {

    double hbarc = 197.327; // hbar * c in [MeV fm]
    double Mass = 938; // nucleon mass in MeV

    std::string input_dir = "Input/";

    // Read Nucleus File
    std::string nucleus_string;
    std::ifstream nucleus_file( "domgen.config" );

    nucleus_file >> nucleus_string;

    nucleus_file.close();
    nucleus_file.clear();

    // Read Configuration file
    std::string config_filename = nucleus_string + ".config";
    std::ifstream config_file( config_filename.c_str() );

    std::string parameters_string;
    int fit_ph;
    double rmax;
    int rpts;
    int lmax;
    config_file >> parameters_string >> fit_ph;
    config_file >> rmax >> rpts >> lmax;

    int num_lj;
    config_file >> num_lj;
    // Knowing the expected number of bound states is useful when
    // looking for particle states that are near the continuum

    // These maps hold the number of bound states for each lj
    std::map<std::string, int> n_lj_map; // neutrons
    std::map<std::string, int> p_lj_map; // protons
    std::vector< std::map< std::string, int > > map_vec;
    for ( int n = 0; n < num_lj; ++n ) {

        std::string key;
        int n_num_bound, p_num_bound;
        config_file >> key >> n_num_bound >> p_num_bound;

        std::pair< std::map< std::string, int >::iterator, bool > n_ret;
        std::pair< std::map< std::string, int >::iterator, bool > p_ret;
        n_ret = n_lj_map.insert ( std::make_pair( key, n_num_bound ) );
        p_ret = p_lj_map.insert ( std::make_pair( key, p_num_bound ) );

        if ( n_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << n_ret.first->second << std::endl;
        }

        if ( p_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << p_ret.first->second << std::endl;
        }
    }

    map_vec.push_back( n_lj_map );
    map_vec.push_back( p_lj_map );



    config_file.close();
    config_file.clear();

  //  std::string output_dir = "Output_" + parameters_string + "/Ener/";
  //  std::string parameters_filename = parameters_string + ".inp";

    std::string output_dir = "Output_test/S/";
   // std::string parameters_filename = "Output_hosfit/roott/Nov26/hosfitupdated.inp";
    std::string parameters_filename = "Input.inp";

    std::cout << "rmax = " << rmax << std::endl;
    std::cout << "rpts = " << rpts << std::endl;
    std::cout << "lmax = " << lmax << std::endl;

    std::string n_string = "n" + nucleus_string;
    std::string p_string = "p" + nucleus_string;

    std::string n_filename = input_dir + n_string + ".inp";
    std::string p_filename = input_dir + p_string + ".inp";

    // Create Nuclear Parameter Objects
    NuclearParameters Nu_n = read_nucleus_parameters( n_filename );
    NuclearParameters Nu_p = read_nucleus_parameters( p_filename );

    std::vector< NuclearParameters > Nu_vec;
    Nu_vec.push_back( Nu_n );
    Nu_vec.push_back( Nu_p );


    // Read in DOM parameters
    std::ifstream pfile( parameters_filename.c_str() );
    if ( pfile.is_open() !=1 ) {
        std::cout << "could not open file " << parameters_filename << std::endl;
        std::abort();
    }
    pfile.close();
    pfile.clear();

    std::string L_array[8] = { "s", "p", "d", "f", "g", "h", "i", "j" };
    std::string J_array[8] = { "1", "3", "5", "7", "9", "11", "13", "15" };

    // Create momentum space grid
    std::vector<double> kmesh;
    std::vector<double> kweights;
    double const kmax = 6.0;
    int const kpts = 104;
    kmesh.resize( kpts );
    kweights.resize( kpts );
    GausLeg( 0., kmax, kmesh, kweights );

    // Create radial grid
    std::vector<double> rmesh;
    std::vector<double> rweights;
    double rdelt = rmax / rpts;
    for( int i = 0; i < rpts; ++i ) {

        rmesh.push_back( ( i + 0.5 ) * rdelt );
        rweights.push_back( rdelt );
    }

    // Prepare stuff for output files
    std::vector< std::string > np_strings;
    np_strings.push_back( n_string );
    np_strings.push_back( p_string );

    double total_energy = 0;
    double calc_A = 0;

    //Potential specifications
    int type = 1; // 1 is P.B. form (average), 0 is V.N. form
    int mvolume = 4;
    int AsyVolume = 1;

    // --- CALCULATIONS --- //

        std::string lj_particleN_share = output_dir + "ParticleN_shares.out";
        std::ofstream particleNumber_file( lj_particleN_share.c_str() );
    // Loop over protons and neutrons
    double Zp; // number of protons in projectile

    for ( unsigned int nu = 0; nu < Nu_vec.size(); ++nu ) {
        
        std::map< std::string, int > lj_map = map_vec[nu];

        double tz = nu - 0.5; // +0.5 for protons, -0.5 for neutrons
        if ( tz < 0 ) {Zp = 0;} else { Zp = 1;}
         particleNumber_file << tz << std::endl;

        // Nucleus Object
        const NuclearParameters &Nu = Nu_vec[nu];

        // Construct Parameters Object
        Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, Zp );

        // Construct Potential Object
        pot U = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
        pot *U1 = &U;
       // lmax = 0;
        // Construct boundRspace Object
//      double Emax = Nu.Ef - Nu.Wgap * p.fGap_B; // energy < Ef where imaginary part begins
        double Emax =  Nu.Ef;
        double Emin = -200 + Emax;
        boundRspace B( rmax, rpts, Nu.Ef, Nu.ph_gap, lmax , Nu.Z, Zp, Nu.A, U1 );

        double tol = 0.01;
        std::vector< lj_eigen_t > bound_levels = B.get_bound_levels( rmesh, tol );

        std::vector< mesh_t > emesh_vec = B.get_emeshes( rmesh, Emin, Emax, bound_levels );

        std::vector<double> n_of_k;
        n_of_k.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_qh;
        n_of_k_qh.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_c_tot;
        n_of_k_c_tot.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_qh_peak_tot;
        n_of_k_qh_peak_tot.assign( kmesh.size(), 0 );

        // Loop over lj channels
        for ( int l = 0; l < lmax + 1 ; ++l ) {

            // Create Bessel Function matrix in k and r
            matrix_t bess_mtx( kmesh.size(), rmesh.size() );
            for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
            for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {

                double rho = kmesh[nk] * rmesh[nr];

                bess_mtx( nk, nr ) = gsl_sf_bessel_jl( l, rho );
            }
            }

            for( int up = -1; up < 2; up+=2 ) {

                double xj = l + up / 2.0;
                int j_index = ( up - 1 ) / 2;
                if ( xj < 0 ) continue;

                std::string j_string;
                if ( l == 0 ) j_string = J_array[ l ];
                else j_string = J_array[ l + j_index ];

                int index = B.index_from_LJ( l, xj );
                mesh_t &emesh = emesh_vec[index];
                std::vector< eigen_t > &bound_info = bound_levels[index];

                std::string lj_string = L_array[l] + j_string + "2";

                std::vector<double> n_of_k_c_lj;
                std::vector<double> n_of_k_qh_lj;
                std::vector<double> n_of_k_qh_peak;
                std::vector<std::vector<double> > n_of_k_qh_peak_Matrice;
                n_of_k_c_lj.assign( kmesh.size(), 0 );
                n_of_k_qh_lj.assign( kmesh.size(), 0 );
                n_of_k_qh_peak.assign( kmesh.size(), 0 );

	        matrix_t Slj(kmesh.size(),kmesh.size());
		for (int i=0;i<kmesh.size();++i){for (int j=0;j<kmesh.size();++j){Slj(i,j) = 0.;}}
	        matrix_t n_r_lj(rmesh.size(),rmesh.size());
		for (int i=0;i<rmesh.size();++i){for (int j=0;j<rmesh.size();++j){n_r_lj(i,j) = 0.;}}

                // Find self-consistent solutions
                 std::cout << "lj = " << l << " " << xj << std::endl;
                 std::vector<cmatrix_t> G;  
		 double E;
		 vector<double> Edelt;
                for ( unsigned int m = 0; m < emesh.size(); ++m ) {
                    
                     E = emesh[m].first;
       		     Edelt.push_back(emesh[m].second);
                    // Propagator
	            G.push_back( B.propagator( rmesh, E, l, xj));
	        }
                // Loop over energy
		    for (int i = 0 ; i < rmesh.size(); ++i){
		         for (int j = 0 ; j < rmesh.size(); ++j){
			     double sumnr = 0.;
                             for ( unsigned int m = 0; m < emesh.size(); ++m ) {
			            sumnr += rmesh[i] * rmesh[j] * imag(G[m](i,j)) * Edelt[m];
		            }
		    n_r_lj(i,j) = sumnr;	
		         }
                    }
                  //  for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
                    for( unsigned int mk = 0; mk < kmesh.size(); ++mk ) {
                         double rsums = 0;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                            double jl1 = bess_mtx( mk, i );
                        for( unsigned int j = 0; j < rmesh.size(); ++j ) {
                            double jl2 = bess_mtx( mk, j );
                            
                            rsums -= n_r_lj(i,j) * jl1 * jl2 * rdelt;
                        }
                        } // end loop over radial coordinates
		//	Slj(nk,mk) = 2./M_PI/M_PI * rsums * ( 2 * xj + 1 )/( 4 * M_PI ); 		
			 n_of_k_c_lj[mk] += 2./M_PI/M_PI * rsums * ( 2 * xj + 1 )/( 4 * M_PI ); 		
		    }
                   // }    // integral over k
                     
                      // end loop over k
                 // end loop over energy
//                for (int nk = 0 ; nk < kmesh.size() ; ++nk){
//		     n_of_k_c_lj[nk] = Slj(nk,nk);} 
                // loop over the orbitals and write out the 
                // bound state information to a file
                for ( unsigned int N = 0; N < bound_info.size(); ++N ) {
                    // Quasiparticle energy
                    double QPE = bound_info[N].first; 

                    // Quasiparticle wavefunction
                    std::vector<double> &QPF = bound_info[N].second;

                    // Transform wavefunction to momentum space
                    std::vector<double> kQPF;
                    for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {

                        double sum = 0;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {

                           sum += std::sqrt( 2 / M_PI ) * rweights[i] 
                                * std::pow( rmesh[i], 2 ) * QPF[i] * bess_mtx( nk, i );
                        }
                        kQPF.push_back( sum );
                      }

                    // This should automatically be normalized to N or Z
                    // since the wavefunctions are normalized to 1
                    if ( QPE < Nu.Ef ) {
                        for ( unsigned int kk = 0; kk < kmesh.size(); ++kk ) {

                            n_of_k_qh_lj[kk] += ( 2 * xj + 1 ) / ( 4 * M_PI ) * kQPF[kk] * kQPF[kk]; 
                        } // end loop over k
                    } 
                } // end loop over N 
                // Write Out Momentum Distribution for each lj channel
                // Also, add up the contribution from each channel to get 
                // the total momentum distribution
                std::string n_of_k_lj_filename = output_dir + "n_of_k_" 
                                               + np_strings[nu] 
                                               + "_" + L_array[l] + j_string 
                                               + "2.out";
                std::ofstream n_of_k_lj_file( n_of_k_lj_filename.c_str() );
		double NOFK_lj = 0;
                for ( unsigned int i = 0; i < kmesh.size(); ++i ) {
                    double n_of_k_lj = n_of_k_c_lj[i] + n_of_k_qh_peak[i];

                    n_of_k_lj_file << kmesh[i] << " " << n_of_k_lj 
                                   << " " << n_of_k_qh_lj[i] << std::endl;

                    n_of_k[i] += n_of_k_lj;
                    n_of_k_qh[i] += n_of_k_qh_lj[i];
                    n_of_k_qh_peak_tot[i] += n_of_k_qh_peak[i];
                    n_of_k_c_tot[i] += n_of_k_c_lj[i];

		    //Particle contribution to each state
		    // 
		    NOFK_lj += 4 * M_PI * kweights[i] * std::pow( kmesh[i], 2 ) * n_of_k_lj;
                }

                particleNumber_file <<index <<" " << "l= "<< l << " " <<"j= " << xj <<" " << NOFK_lj   << std::endl; 
				  //  <<" " <<n_of_k_qh_peak_tot[sarekar-1] <<" " <<n_of_k_c_tot[sarekar-1] <<std::endl;

                n_of_k_lj_file.close();
                n_of_k_lj_file.clear();
	    }//up
         }//lj
        // Output Files
        std::string strength_filename = output_dir + np_strings[nu] 
                                      + "_k_strength.out";
        std::ofstream strength_file( strength_filename.c_str() );

        std::string n_of_k_filename = output_dir + np_strings[nu]
                                    + "_momentum_dist.out";
        std::ofstream n_of_k_file( n_of_k_filename.c_str() ); 

        // Calculate Particle Number and Kinetic Energy
        double norm = 0;
        for ( unsigned int n = 0; n < kmesh.size(); ++n ) {
            norm += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) * n_of_k[n];
        }
        // Energetics
        double N_or_Z; // actual number of neutrons or protons
        if( tz > 0 ) { 
            N_or_Z = Nu.Z;
        }
        else {
            N_or_Z = Nu.N();
        }

        calc_A += norm;
        double k_strength = 0;
        double qh_strength = 0;
        for ( unsigned int n = 0; n < kmesh.size(); ++n ) {
            n_of_k_file << kmesh[n] << " " << n_of_k[n] / norm        
                                    << " " << n_of_k_qh[n] / N_or_Z 
                                    << std::endl;

            //verify that n_of_k_qh is normalized to N or Z
            qh_strength += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                     * n_of_k_qh[n] / N_or_Z;

            k_strength += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                        * n_of_k[n] / norm;
            
            strength_file << kmesh[n] << " " << k_strength 
                                      << " " << qh_strength << std::endl;
        }

        strength_file << " " << std::endl;
        strength_file << "norm = " << norm << std::endl;
        strength_file << "N or Z = " << N_or_Z << std::endl;

        n_of_k_file.close();
        n_of_k_file.clear();
        strength_file.close();
        strength_file.clear();

std::cout<< "HELLO tz LOOP" <<std::endl;
    }//tz
particleNumber_file.close();
return 1;
}
Example #5
0
double FC_FUNC_(oct_sph_bessel, OCT_SPH_BESSEL)
     (const int *l, const double*x)
{
  return gsl_sf_bessel_jl(*l, *x);
}
Example #6
0
// #include"reaction.h"
int main(){

////////Input Parameters of the potential (fit parameters) /////
std::string parameters_filename="Input.inp";

NuclearParameters Nu = read_nucleus_parameters( "Input/nca40.inp" );

double Ef=Nu.Ef;
int lmax=6;
double z0=20.0;
double zp0;
double A0=40.0;
double tz=-0.5;

int type=1;
int mvolume = 4;
int AsyVolume = 1;

double A = 40.0;

if (tz>0) { zp0=1;}
else {zp0=0;}

double ph_gap = Nu.ph_gap;
cout<<"ph_gap = "<<Nu.ph_gap<<endl;
double  rStart = .05;
double  rmax = 12.;
double  ham_pts = 180; 

double  rdelt = rmax / ham_pts;

//THIS IS ANOTHER CHANGE FROM THE OLD TOO////////////////
double  rdelt_p = rdelt / 1.025641026;

        // Construct Parameters Object
        Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, zp0 );

        // Construct Potential Object
        pot pottt = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
	pot * pott = &pottt;

        // store coulomb potential in order to compare with




 boundRspace initiate(rmax , ham_pts , Ef, ph_gap , lmax , Nu.Z , zp0 , Nu.A , pott);


  
 double Elower = -11.61818;
 double Eupper = -9.4;
 double jj = .5;
 int ll = 0;
 int Ifine = 1;
 initiate.searchNonLoc( Elower, Eupper, jj,  ll,  Ifine);
 initiate.exteriorWaveFunct(ll);
 initiate.normalizeWF();


double tol=.01;
double estart=Ef;

///// Making rmesh///

//THIS IS THE DIFFERENCE FROM SKYRMEOLD////////////////////////////////
//vector <double> rmesh_p = initiate.make_rmesh();
std::vector<double> rmesh_p= initiate.make_rmesh_point();
std::vector<double> rmesh= initiate.make_rmesh();

// Create momentum space grid
std::vector<double> kmesh;
std::vector<double> kweights;
double const kmax = 5.0;
int const kpts = rmesh.size();
kmesh.resize( kpts );
kweights.resize( kpts );
GausLeg( 0., kmax, kmesh, kweights );

double J =0.5;

double Emax=2*-4.7;
double Emin=-200.0 + Emax;

std::ofstream filee("waves/neutron/natural/wave.out");
std::cout<<Elower<<std::endl;

//Generating the propagator

std::vector< lj_eigen_t > bound_levels = initiate.get_bound_levels( rmesh, tol );

std::vector< mesh_t > emesh_vec =
        initiate.get_emeshes( rmesh, Emin, Emax, bound_levels );

cout<<"emesh_vec = "<<emesh_vec.size()<<endl;

std::vector< prop_t > prop_vec = initiate.get_propagators( rmesh, emesh_vec );

double onum=0.0;
double num=0.0;
double part=0;
double kpart=0;
vector<double> denk;
denk.assign( kmesh.size(), 0 );
vector<double> k_dist;
k_dist.assign( kmesh.size(), 0 );
vector <double> natden;
natden.assign(rmesh.size(),0);
vector <double> natdenk;
natdenk.assign(kmesh.size(),0);
vector <double> ktest;
ktest.assign(kmesh.size(),0);
vector <double> diag;
diag.assign(kmesh.size(),0);

double dom=0;
double expo=0;

int Nmax=5;

string stable = "waves/neutron/natural/table.txt";
ofstream ftable(stable.c_str());

string presky = "waves/neutron/data/n";

vector<double> kdist;
kdist.assign(rmesh.size(),0);
lmax=0;
//Starting loop over L and J to go through all the orbitals
for(int L=0;L<lmax+1;L++){
	for(int s=0;s<2;s++){	
		J=L-0.5+s;
		if(J<0){
			J=0.5;
			s=1;
		}	
	
		cout<<"L = "<<L<<" J = "<<J<<endl;

		string jlab;
		if(J==0.5){
			jlab="12";
		}else if(J==1.5){
			jlab="32";
		}else if(J==2.5){
			jlab="52";
		}else if(J==3.5){
			jlab="72";
		}else if(J==4.5){
			jlab="92";
		}else if(J==5.5){
			jlab="112";
		}else if(J==6.5){
			jlab="132";
		}

		string llab;
		if(L==0){
			llab="s";
		}else if(L==1){
			llab="p";
		}else if(L==2){
			llab="d";
		}else if(L==3){
			llab="f";
		}else if(L==4){
			llab="g";
		}else if(L==5){
			llab="h";
		}else if(L==6){
			llab="i";
		}

/*
		int Nmax=10;
		if(L>1){
			Nmax=9;
		}
		if(L>3){
			Nmax=8;
		}
		if(L==6 && J == 5.5){
			Nmax=7;
		}	
*/
		Nmax=4;
		if(L>3) Nmax = 1;


		int Mmax=Nmax;


		ftable<<endl;
		ftable<<llab<<jlab<<endl;
		ftable<<"     ";
		for(int i=0;i<Mmax;i++){
			ftable<<i<<"            ";
		}
		ftable<<endl;

		string dest = "waves/neutron/natural/";

		int index=initiate.index_from_LJ(L,J);

		const prop_t &propE = prop_vec.at(index);

		const mesh_t &emesh = emesh_vec.at(index);

// Create Bessel Function matrix in k and r
    matrix_t bess_mtx( kmesh.size(), rmesh.size() );
		bess_mtx.clear();
		matrix_t bess_mtx_sky(kmesh.size(),rmesh.size());
		bess_mtx_sky.clear();
    for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
	    for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {
	      double rho = kmesh[nk] * rmesh_p[nr];
        bess_mtx( nk, nr ) = gsl_sf_bessel_jl( L, rho );
				bess_mtx_sky(nk,nr) = gsl_sf_bessel_jl(L, kmesh[nk]*rmesh[nr]);
      }
    }		

		matrix_t d_mtx( rmesh.size(), rmesh.size() ); // density matrix
		d_mtx.clear();

//Remember that propE is actually G*r*r'*rdelt
		for(unsigned int n=0;n<emesh.size();++n){	
			double Edelt=emesh[n].second;
		  for( unsigned int i = 0; i < rmesh.size(); ++i ) {
				for( unsigned int j = 0; j < rmesh.size(); ++j ) {
					d_mtx(i,j) -= Edelt * imag(propE[n](i,j)) / M_PI;  
				} 
			} 
		}		

		const lj_eigen_t &levels = bound_levels.at(index);


//this adds the QP peaks to the particle number
		for ( unsigned int N = 0; N < levels.size(); ++N ){   
    	if ( ( levels[N].first <= Ef ) && 
      ( levels[N].first > Emax ) ) {
      	double QPE = levels[N].first;
      	const std::vector<double> &QPF = levels[N].second;
      	double S = initiate.sfactor( rmesh, QPE, L, J, QPF );
				for ( unsigned int i = 0; i < rmesh.size(); ++i ) {
					for(int j=0;j<rmesh.size();j++){
	          d_mtx(i,j) +=  S * QPF[i] * QPF[j] * rmesh[i]*rmesh[j]*rdelt;
          }
				}
			}
		}

		

		matrix_t k_mtx( rmesh.size(), rmesh.size() ); // density matrix
		k_mtx.clear();
		matrix_t mtx(rmesh.size(),rmesh.size() );
		mtx.clear();
		matrix_t diff_mtx(rmesh.size(),rmesh.size());
		diff_mtx.clear();
		matrix_t r_mtx( rmesh.size(), rmesh.size() ); // testing to see if this is the same as the original
		r_mtx.clear();

		double maxR = rmesh[rmesh.size()-1];
		double minR = rmesh[0];

	/*		for(int i=0;i<rmesh.size();i++){
			for(int j=0;j<rmesh.size();j++){
				//d_mtx(i,j) = exp(-pow(rmesh[i]-rmesh[j],2));
				//mtx(i,j) = (1.0 / pow(kmesh[i]*kmesh[j],2) ) * (cos(kmesh[i]*maxR) - cos(kmesh[i]*minR) ) * (cos(kmesh[j]*maxR) - cos(kmesh[i]*minR) ) * (2.0/M_PI);
			}
			f4[i] = mtx(i,i);
		}  */

		for(int i=0;i<rmesh.size();i++){
			if(i%30==0) cout<<i<<endl;
			for(int j=0;j<rmesh.size();j++){
				double kd=0;
				double kr;
				double kr2;
				for(int ii=0;ii<rmesh.size();ii++){
					for(int jj=0;jj<rmesh.size();jj++){
						//dmtx already has r*r'*dr
						kd += d_mtx(ii,jj) * bess_mtx(i,ii) * bess_mtx(j,jj) /( rmesh[ii] * rmesh[jj] * rdelt) * pow( rdelt_p * rmesh_p[ii] * rmesh_p[jj], 2) * (2.0/M_PI);
						//kd += d_mtx(ii,jj) * bess_mtx(i,ii) * bess_mtx(j,jj) * pow(rdelt * rmesh[ii] * rmesh[jj],2) * (2.0/M_PI);
						kr = kmesh[i] * rmesh[ii];
						kr2 = kmesh[j] * rmesh[jj];
						//kd += d_mtx(ii,jj) * sin(kr)/kr * sin(kr2)/kr2 * pow(rdelt * rmesh[ii] * rmesh[jj], 2) * (2.0/M_PI);
						//kd += d_mtx(ii,jj) * sin(kr)/kr * sin(kr2)/kr2 / ( rmesh[ii] * rmesh[jj] * rdelt) * pow( rdelt_p * rmesh_p[ii] * rmesh_p[jj], 2) * (2.0/M_PI);
					}
				}
			//including this for diagonalization
			k_mtx(i,j) = kd * kmesh[i] * kmesh[j] * kweights[i];			
			}
			//f2[i] = k_mtx(i,i);
			kdist[i] += k_mtx(i,i) * (2*J+1) / (4*M_PI);
		}

		for(int i=0;i<rmesh.size();i++){
			if(i%30==0) cout<<i<<endl;
			for(int j=0;j<rmesh.size();j++){
				double kd=0;
				double kr;
				double kr2;
				for(int ii=0;ii<rmesh.size();ii++){
					for(int jj=0;jj<rmesh.size();jj++){
						//already includes kk'dk
						kd += k_mtx(ii,jj) * bess_mtx(ii,i) * bess_mtx(jj,j) * kmesh[ii] * kmesh[jj] * kweights[jj] * (2.0/M_PI);
					}
				}
			//including this for diagonalization
			r_mtx(i,j) = kd * rmesh[i] * rmesh[j] * rdelt;			
			}
		}


		vector <eigen_t> eig = initiate.real_eigvecs(d_mtx);
		vector <eigen_t> eigr = initiate.real_eigvecs(r_mtx);
		vector <eigen_t> eigk = initiate.real_eigvecs(k_mtx);
		vector <eigen_t> eigm = initiate.real_eigvecs(mtx);

		ofstream diff("waves/diff.txt");
		
		for(int i=0;i<rmesh.size();i++){
			diff<<rmesh[i]<<" "<<eig[rmesh.size()-1].second[i]/rmesh[i]<<" "<<eigr[rmesh.size()-1].second[i]/rmesh[i]<<endl;
		}


		cout<<"maxR = "<<maxR<<endl;
		cout<<"minR = "<<minR<<endl;
		cout<<"kmesh[10] = "<<kmesh[100]<<endl;

		double eignorm=0;
		double reignorm=0;
		double keignorm=0;

		ofstream feval("waves/evals.txt");
		for(int i=0;i<rmesh.size();i++){
			double spot=rmesh.size()-1-i;
			feval<<eig[spot].first<<" "<<eigr[spot].first<<endl;
			eignorm += pow(eig[spot].first,2);
			reignorm += pow(eigr[spot].first,2);
			keignorm += pow(eigk[spot].first,2);
		}

	//	cout<<"eigval d_mtx[0] = "<<eig[0].first<<endl;
		cout<<"eigval d_mtx[N] = "<<eig[rmesh.size()-1].first<<endl;
		cout<<"eigval r_mtx[N] = "<<eigr[rmesh.size()-1].first<<endl;
	//	cout<<"eigval k_mtx[0] = "<<eigk[0].first<<endl;
		cout<<"eigval k_mtx[N] = "<<eigk[rmesh.size()-1].first<<endl;
		cout<<"eigval mtx[N] = "<<eigm[rmesh.size()-1].first<<endl;
		cout<<"k_mtx(10,10) = "<<k_mtx(100,100)<<endl;
		cout<<"mtx(10,10) = "<<mtx(100,100)<<endl;

		vector <double> f(rmesh.size());
		vector <double> f2(rmesh.size());
		vector <double> f3(rmesh.size());
		vector <double> f4(rmesh.size());
		for(int i=0;i<rmesh.size();i++){
			f[i] = eig[rmesh.size()-1].second[i]/rmesh_p[i]; 
		}

		double fk;

		for(int i=0;i<rmesh.size();i++){
			fk=0;
			for(int j=0;j<rmesh.size();j++){
				fk += f[j] * sin(rmesh[j] * kmesh[i])/(rmesh[j]*kmesh[i]) * pow(rmesh[j],2) * rdelt * sqrt(2.0/M_PI);
			}
			f2[i] = fk;
			f4[i] = 1.0/pow(kmesh[i],2) * (cos(minR*kmesh[i]) - cos(maxR*kmesh[i]) );
		}

		for(int i=0;i<rmesh.size();i++){
			fk=0;
			for(int j=0;j<rmesh.size();j++){
				fk += f2[j] * sin(rmesh[i] * kmesh[j])/(rmesh[i]*kmesh[j]) * pow(kmesh[j],2) * kweights[j] * sqrt(2.0/M_PI);
			}
			f3[i] = fk;
		}
				
		ofstream compk("waves/compk.txt");
		for(int i=0;i<rmesh.size();i++){
			compk<<kmesh[i]<<" "<<f2[i]<<" "<<f4[i]<<endl;
		}

		ofstream compr("waves/compr.txt");
		for(int i=0;i<rmesh.size();i++){
			compr<<rmesh[i]<<" "<<f[i]<<" "<<f3[i]<<endl;
		}

		double ksum=0;
		double rsum=0;

		for(int i=0;i<kmesh.size()-1;i++){

			if(eigk[i].first > 0.5 && eigk[i].first < 2){
				cout <<"eigk = " << eig[i].first << endl;
			}

			rsum += eig[i].first;
			ksum += eigk[i].first;

		}

		rsum += eig[rmesh.size()-1].first;

		cout<<"ksum = "<<ksum<<endl;
		cout<<"rsum = "<<rsum<<endl;

		//Transforming natural orbits to k-space
			vector <double> knat;
			knat.assign(kmesh.size(),0);
			for(int ik=0;ik<kmesh.size();ik++){
				double kn=0;
				for(int ir=0;ir<rmesh.size();ir++){
					kn += rdelt_p * sqrt(2.0/M_PI) * bess_mtx(ik,ir) * eig[rmesh.size()-1].second[ir] / rmesh[ir]
					* pow(rmesh_p[ir],2);
				}
				knat[ik] = kn;		
			}
			
		double fnorm=0;
		double fnorm2=0;

		for(int i =0;i<rmesh.size();i++){
			fnorm += pow(knat[i] * kmesh[i],2) * kweights[i];
			fnorm2 += pow(eigk[kmesh.size()-1].second[i] * kmesh[i], 2) * kweights[i];
		}

		cout<<"fnorm = "<<fnorm<<endl;
		cout<<"fnorm2 = "<<fnorm2<<endl;



		string eiglab = dest + "eig" + llab+jlab+".txt";

		ofstream fval(eiglab.c_str());

		matrix_t sky_mtx(Mmax, Mmax); // density matrix
		sky_mtx.clear();


//Starting loop over N
		for(int N=0;N<Nmax;N++){
			string Nlab;
			ostringstream convert;
			convert << N;
			Nlab = convert.str();

			ftable<<Nlab<<"   ";

			double spot = rmesh.size()-N-1;

			double enorm=0;

			for(int i=0;i<rmesh.size();++i){
				enorm += rdelt * pow( eig[spot].second[i],2);
			}

			string veclab = dest + "eig" + llab + jlab + Nlab + ".txt";

			std::ofstream feig(veclab.c_str());

			//opening skyrme file which gives u(r)
			string skyfile0 = presky + llab + jlab + Nlab + ".txt";
			std::ifstream filein0(skyfile0.c_str());
			double sky0[rmesh.size()];
			std::string line0;
			int i;
			i=0;
			while(getline(filein0,line0)){
				sky0[i]=atof(line0.c_str());
				i++;
			}
			filein0.close();

		//flipping the natural orbits if they are upside down
		//	if((eig[spot].second[1]<0 && sky0[1]>0) || (eig[spot].second[1]>0 && sky0[1]<0)){	
			//	for(int i=0;i<rmesh.size();i++){
				//	eig[spot].second[i] *= -1.0;
				//}
			//}

			for(int i=0;i<rmesh.size();++i){
				//want to give R(r), so print out u(r)/r
				feig<<rmesh[i]<<" "<<eig[spot].second[i]/sqrt(enorm)/rmesh[i]<<" "<<sky0[i]/rmesh[i]<<endl;		
			}			

			//Transforming natural orbits to k-space
			vector <double> knat;
			knat.assign(kmesh.size(),0);
			for(int ik=0;ik<kmesh.size();ik++){
				double kn=0;
				for(int ir=0;ir<rmesh.size();ir++){
					kn += rdelt_p * sqrt(2.0/M_PI) * bess_mtx(ik,ir) * eig[spot].second[ir] / sqrt(enorm) / rmesh[ir]
					* pow(rmesh_p[ir],2);
				}
				knat[ik] = kn;		
			}

			double nnorm=0;
			for(int i=0;i<kmesh.size();i++){
				nnorm += pow(knat[i]*kmesh[i],2) * kweights[i];
			}
			
		//	double newnorm=0;

			//for(int i=0;i<kmesh.size();i++){
				//knat[i] /= sqrt(nnorm);
			//	newnorm += pow(knat[i],2);
			//}

			//cout<<"newnorm = "<<nnorm<<endl;

			for(int i=0;i<rmesh.size();i++){
				natden[i] += eig[spot].first*pow(eig[spot].second[i]/rmesh[i]/sqrt(enorm),2)*(2*J+1)/(4*M_PI);
				natdenk[i] += eig[spot].first * pow(knat[i],2) * (2*J+1) / (4*M_PI);
			} 

			vector <double> wave;
			wave.assign(kmesh.size(),0);
			vector <double> waver;
			waver.assign(rmesh.size(),0);
			double csquare=0;

//beginning loop over M to sum over skyrme wave functions
			for(int M=0;M<Mmax;M++){
				string Mlab;
				ostringstream convert;
				convert << M;
				Mlab = convert.str();
				
//opening skyrme file which gives u(r)
				string skyfile = presky + llab + jlab + Mlab + ".txt";
				std::ifstream filein(skyfile.c_str());
				double skyrme[rmesh.size()];
				std::string line;
				int i;
				i=0;
				while(getline(filein,line)){
					skyrme[i]=atof(line.c_str());
					i++;
				}
				filein.close();

		//Transforming skyrme wavefunctions to k-space
				vector <double> ksky;
				ksky.assign(kmesh.size(),0);
				for(int ik=0;ik<kmesh.size();ik++){
					double ks=0;
					for(int ir=0;ir<rmesh.size();ir++){
						ks += rdelt * sqrt(2.0/M_PI) * bess_mtx_sky(ik,ir) * skyrme[ir] * rmesh[ir];
					}
					ksky[ik] = ks;
				}

				if(M==N){
					string test = "waves/neutron/natural/wave" + llab + jlab + Mlab + ".txt";
					ofstream ftest(test.c_str());
					for(int i=0;i<kmesh.size();i++){
						ftest<<kmesh[i]<<" "<<knat[i]<<" "<<ksky[i]<<endl;
					}
				}

				int M2max=Mmax;

				double proj=0;
				for(int i=0;i<kmesh.size();i++){
					proj += ksky[i] * knat[i] * pow(kmesh[i],2) * kweights[i];
				}

				ftable<<proj<<"   ";
		
				for(int M2=0;M2<M2max;M2++){
					string M2lab;
					ostringstream convert;
					convert << M2;
					M2lab = convert.str();

					string skyfile2 = presky + llab + jlab + M2lab + ".txt";
					std::ifstream filein2(skyfile2.c_str());
					double skyrme2[rmesh.size()];
					std::string line2;
					int i;
					i=0;
					while(getline(filein2,line2)){
						skyrme2[i]=atof(line2.c_str());
						i++;
					}
					filein2.close();

					if(N==0){

					//creating matrix in skyrme space
					double sky=0;
					for(int i=0;i<rmesh.size();i++){
						for(int j=0;j<rmesh.size();j++){
							sky += skyrme[i] * skyrme2[j] * d_mtx(i,j) * rdelt;
						}
					}

					sky_mtx(M,M2) = sky;

					}

					//Transforming skyrme wavefunctions to k-space
					vector <double> ksky2;
					ksky2.assign(kmesh.size(),0);
					for(int ik=0;ik<kmesh.size();ik++){
						double ks2=0;
						for(int ir=0;ir<rmesh.size();ir++){
							ks2 += rdelt * sqrt(2.0/M_PI) * bess_mtx_sky(ik,ir) * skyrme2[ir] * rmesh[ir];
						}
						ksky2[ik] = ks2;		
					}

					double proj2=0;
					for(int i=0;i<kmesh.size();i++){
						proj2 += ksky2[i] * knat[i] * pow(kmesh[i],2) * kweights[i];
					}

					//if(M != M2){
						//cout<<"proj1 = "<<proj<<endl;
						//cout<<"proj2 = "<<proj2<<endl;
					//}

					for(int i=0;i<kmesh.size();i++){
						denk[i] += eig[spot].first * (2*J+1) / (4*M_PI) * ksky[i] * ksky2[i] * proj * proj2;
						if(M != M2){
							ktest[i] += eig[spot].first * (2*J+1) / (4*M_PI) * ksky[i] * ksky2[i] * proj * proj2;
						}							
					} 

				} //end loop over M2
				
				for(int i=0;i<kmesh.size();i++){
					wave[i] +=  skyrme[i] * proj;
				}

				csquare += pow(proj,2);

			} //ending loop over M

			ftable<<endl;

		if(L==0){
			dom += eig[spot].first * (2*J+1) / (4*M_PI) * pow(knat[0],2);
			expo += eig[spot].first * (2*J+1) / (4*M_PI) * pow(wave[0],2);
		}

			for(int i=0;i<kmesh.size();i++){
				diag[i] += eig[spot].first * (2*J+1) / (4*M_PI) * pow(wave[i],2);
			}

			double overlap=0;
			for(int i=0;i<kmesh.size();i++){
				overlap += knat[i] * wave[i] * pow(kmesh[i],2) * kweights[i];
			}
			//ut<<" N = "<<N<<" overlap = "<<overlap<<endl;
			//cout<<"N = "<<N<<" csquare = "<<csquare<<endl;

			string comp = "waves/neutron/natural/comp" + llab + jlab + Nlab + ".txt";
			ofstream fcomp(comp.c_str());

			double wavenorm=0;
			double natnorm=0;

			for(int i=0;i<rmesh.size();i++){
				wavenorm += pow(wave[i],2) * rdelt;
			}

			for(int i=0;i<kmesh.size();i++){
				fcomp<<rmesh[i]<<" "<<wave[i]/sqrt(wavenorm)/rmesh[i]<<endl;
			}

		} //ending loop over N
		//ftable.close();

		vector <eigen_t> eigsky = initiate.real_eigvecs(sky_mtx);

		cout<<"Mmax = "<<Mmax<<endl;

		for(int M=0;M<Mmax;M++){
			string Mlab;
			ostringstream convert;
			convert << M;
			Mlab = convert.str();

			int spot = Mmax - M - 1;

			string fname = "waves/eigvec" + llab + jlab + Mlab + ".txt";
			ofstream feigsky(fname.c_str());

			//the eigenvector is already normalized
			for(int i=0;i<Nmax;i++){
				feigsky << eigsky[spot].second[i] << endl;
			}

			cout << "eigval = " << eigsky[spot].first << endl;

			vector<double> qpf;
			qpf.assign(rmesh.size(),0);
		
			for(int j=0;j<Mmax;j++){
		
				string Nlab;
				ostringstream convert;
				convert << j;
				Nlab = convert.str();
				string skyfile = presky + llab + jlab + Nlab + ".txt";
				std::ifstream filein(skyfile.c_str());
				double skyrme[rmesh.size()];
				std::string line;
				int i;
				i=0;
				while(getline(filein,line)){
					skyrme[i]=atof(line.c_str());
					i++;
				}
				filein.close();
				for(int i=0;i<rmesh.size();i++){
					qpf[i] += eigsky[spot].second[j] * skyrme[i];
				}
			}

			string qpname = "waves/nat" + llab + jlab + Mlab + ".txt";
			ofstream qpfile(qpname.c_str());

			double norm=0;

			for(int i=0;i<rmesh.size();i++){
				norm += pow(qpf[i],2) * rdelt;
			}

			double fac;
		
			if(qpf[10] < 0){
				fac = -1.0;
			}else{
				fac = 1.0;
			}


			for(int i=0;i<rmesh.size();i++){
				qpfile << rmesh[i] <<" "<< qpf[i] / sqrt(norm) / rmesh[i] * fac << endl;
			}

		}



	}		//ending loop over j
} 		//ending loop over L

double knum=0;
double kdiag=0;
double kdistnum=0;

ofstream fdiag("waves/neutron/natural/diagk.txt");
ofstream sdenk("waves/neutron/natural/skydenk.txt");
ofstream fdenr("waves/neutron/natural/natden.txt");
ofstream fdenk("waves/neutron/natural/natdenk.txt");
ofstream fdist("waves/kdist.txt");

double k_part=0;
kpart=0;
for(int i=0;i<kmesh.size();i++){
	kpart += denk[i] * pow(kmesh[i],2) * kweights[i] * 4 * M_PI;
	knum += ktest[i] * pow(kmesh[i],2) * kweights[i] * 4 * M_PI;
	k_part += natdenk[i] * kweights[i] * pow(kmesh[i],2) * 4 * M_PI;
	kdiag += diag[i] * kweights[i] * pow(kmesh[i],2) * 4 * M_PI;
	kdistnum += kdist[i] * pow(kmesh[i],2) * kweights[i] * 4 * M_PI;
}

for(int i=0;i<kmesh.size();i++){
	sdenk<<kmesh[i]<<" "<<denk[i]<<endl;
	fdenk<<kmesh[i]<<" "<<natdenk[i]<<endl;
	fdiag<<kmesh[i]<<" "<<diag[i]/kdiag<<endl;
	fdist<<kmesh[i]<<" "<<kdist[i]/kdistnum<<endl;
}

double nat=0;
for(int i=0;i<rmesh.size();i++){
	nat += natden[i] * rdelt_p * pow(rmesh_p[i],2) * 4*M_PI;
}

for(int i=0;i<rmesh.size();i++){
	fdenr<<rmesh_p[i]<<" "<<natden[i]/nat<<endl;
}

cout<<"expoansion = "<<expo/kpart<<endl;
cout<<"natural = "<<dom/k_part<<endl;
cout<<"ktest = "<<knum<<endl;
cout<<"kdiag = "<<kdiag<<endl;
cout<<"particle number from sky density (k) = "<<kpart<<endl;
cout<<"particle number from natural (r) = "<<nat<<endl;
cout<<"particle number from natural (k) = "<<k_part<<endl;
cout<<"particle number from kdist (k) = "<<kdistnum<<endl;

}
Example #7
0
/* compile with gcc test_gsl.c -lgsl -lgslcblas -L<location of gsl library> */ 
int main (void)
{
  double rmin=0.7,rmax=1.;
  double alpha = 1.,delta_alpha=1.;
  double falpha,ss,err,oldss;
  int ell_min=6,ell_max=8;
  int iter=0,Nzeros=5;
  int iell;
  double ERR = 1.e-12;
  double zeros[Nzeros];
  int ell=0,izeros;
  FILE *in,*out,*fout;
  /* --------------------- */
  in = fopen("alpha_in_tex.dat","w");
  fout = fopen("alpha_in.dat","w");
  fprintf(in," %d %d %f %f \n",ell_min,ell_max,rmin,rmax);
  fprintf(fout," %d %d %f %f \n",ell_min,ell_max,rmin,rmax);
  for(iell=ell_min;iell<ell_max+1;iell++){
    ell=iell;
    printf("Legendrel=%d \n",ell);
    alpha = 1.;
    izeros = 0;
    while(izeros<Nzeros){
      falpha = gsl_sf_bessel_jl(ell,alpha*rmin)*gsl_sf_bessel_yl(ell,alpha*rmax)-
        gsl_sf_bessel_jl(ell,alpha*rmax)*gsl_sf_bessel_yl(ell,alpha*rmin);
      err = fabs(falpha);
      oldss =   falpha/err;
      delta_alpha = 1.;
      while(err>ERR){
        alpha = alpha+delta_alpha;
        falpha =  gsl_sf_bessel_jl(ell,alpha*rmin)*gsl_sf_bessel_yl(ell,alpha*rmax)-
          gsl_sf_bessel_jl(ell,alpha*rmax)*gsl_sf_bessel_yl(ell,alpha*rmin);
        err = fabs(falpha);
        ss =   falpha/err;
        if(ss!=oldss) {
          delta_alpha = -delta_alpha/2.;}
        else{}
        iter = iter+1;
        printf("ell=%d alpha=%le, falpha=%le, delta_alpha=%le, ss=%le, iter=%d, err=%le \n",
             ell,alpha,falpha,delta_alpha,ss,iter,err);
        oldss = ss;
      }
    printf("convergence achieved \n");
    printf("Legendrel=%d alpha=%le, falpha=%le, delta_alpha=%le,ss=%le, iter=%d, err=%le \n",
           ell,alpha,falpha,delta_alpha,ss,iter,err);
    zeros[izeros] = alpha;
    alpha = (double) (ceil(alpha));
    izeros = izeros+1;
    }
    printf("==========Legendrel = %d ================\n",ell);
    printf("%d  \t",ell);
    fprintf(in,"%d  \t ",ell);
    for(izeros=0;izeros<Nzeros;izeros++){
      printf("  %le ",zeros[izeros]);
      fprintf(in,"  & %f ",zeros[izeros]);
    }
    printf("\n");
    fprintf(in,"\\\\ \n");
/* ---------------------------------------- */
    fprintf(fout,"%d ",ell);
    for(izeros=0;izeros<Nzeros;izeros++){
      fprintf(fout,"   %f ",zeros[izeros]);
    }
   fprintf(fout,"\n");
  }
  
  return 0;
}
Example #8
0
int main( ) {

   std::string input_dir = "Input/";

   // Read Nucleus File
   std::string nucleus_string;
   std::ifstream nucleus_file( "domgen.config" );

   nucleus_file >> nucleus_string;

   nucleus_file.close();
   nucleus_file.clear();

   // Read Configuration file
   std::string config_filename = nucleus_string + ".config";
   std::ifstream config_file( config_filename.c_str() );

   std::string parameters_string;
   int fit_ph;
   double rmax;
   int rpts;
   int lmax;

   config_file >> parameters_string >> fit_ph;
   config_file >> rmax >> rpts >> lmax;

   cout<<"parameters_string = "<<parameters_string<<endl;

   int num_lj;
   config_file >> num_lj;

   config_file.close();
   config_file.clear();

   // Read in normalization
   double calc_Z = 20;
   double calc_N = 20;
   //std::cout << "Enter calculated Z: " << std::endl;
   //std::cin >> calc_Z; 

   //std::cout << "Enter calculated N: " << std::endl;
   //std::cin >> calc_N;

   std::string output_dir = "Output_" + parameters_string + "/Spectral_functions_kE/";
   std::string parameters_filename = parameters_string + ".inp";

   std::cout << "rmax = " << rmax << std::endl;
   std::cout << "rpts = " << rpts << std::endl;
   std::cout << "lmax = " << lmax << std::endl;

   std::string n_string = "n" + nucleus_string;
   std::string p_string = "p" + nucleus_string;

   std::string n_filename = input_dir + n_string + ".inp";
   std::string p_filename = input_dir + p_string + ".inp";

   // Create Nuclear Parameter Objects
   NuclearParameters Nu_n = read_nucleus_parameters( n_filename );
   NuclearParameters Nu_p = read_nucleus_parameters( p_filename );

   std::vector< NuclearParameters > Nu_vec;
   Nu_vec.push_back( Nu_n );
   Nu_vec.push_back( Nu_p );


   // Read in DOM parameters
   std::ifstream pfile( parameters_filename.c_str() );
   if ( pfile.is_open() !=1 ) {
      std::cout << "could not open file " << parameters_filename << std::endl;
      std::abort();
   }
   pfile.close();
   pfile.clear();

   // Create radial grid
   std::vector<double> rmesh;
   std::vector<double> rweights;
   double rdelt = rmax / rpts;
   for( int i = 0; i < rpts; ++i ) {

      rmesh.push_back( ( i + 0.5 ) * rdelt );
      rweights.push_back( rdelt );

   }

   // Create momentum space grid for k-slice
   std::vector<double> kmesh1;
   double kmax1 = 6.0;
   int kpts1 = 100;
   double deltak1 = kmax1 / kpts1;

   for ( int i = 0; i < kpts1; ++i ) {

      kmesh1.push_back( ( i + 0.5 ) * deltak1 );
   }

   // Create momentum space grid for E-slice
   std::vector<double> kmesh2; // wave number in units of fm^{-1}
std::vector<double> pmesh; // momentum in units of MeV / c
double pmin = 170; 
double pmax = 650;
double deltap = 40;
int ppts = static_cast<int> ( ( pmax - pmin ) / deltap ) + 1;

for ( int i = 0; i < ppts; ++i ) {

   double p = pmin + i * deltap;
   pmesh.push_back( p );

   double k = p / hbarc;
   kmesh2.push_back( k );
}

// Prepare stuff for output files
std::vector< std::string > np_strings;
np_strings.push_back( n_string );
np_strings.push_back( p_string );

// create L and J strings for output files
std::string L_array[8] = { "s", "p", "d", "f", "g", "h", "i", "j" };
std::string J_array[8] = { "1", "3", "5", "7", "9", "11", "13", "15" };

//Potential specifications
int type = 1; // 1 is P.B. form (average), 0 is V.N. form
int mvolume = 4;
int AsyVolume = 1;


/* CALCULATIONS */


// Loop over protons and neutrons
double Zp; // number of protons in projectile
omp_set_nested(1);
#pragma omp parallel num_threads(2)
{
#pragma omp for
   for ( unsigned int nu = 0; nu < Nu_vec.size(); ++nu ) {

      double tz = nu - 0.5; // +0.5 for protons, -0.5 for neutrons
      double calc_norm;
      if ( tz < 0 ) {

         Zp = 0;
         calc_norm = calc_N;
      }
      else { 

         Zp = 1;
         calc_norm = calc_Z;
      }

      // Nucleus Object
      const NuclearParameters &Nu = Nu_vec[nu];

      // Construct Parameters Object
      Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, Zp );

      // Construct Potential Object
      pot U = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
      pot *U1 = &U;

      // Construct Object for calculating bound-state properties
      boundRspace B( rmax, rpts, Nu.Ef, Nu.ph_gap, lmax, Nu.Z, Zp, Nu.A, U1 );

      // Create Energy Grid for k-slice
      double Emin1 = -225;
      double Emax1 = -25;
      double deltaE1 = 25;
      int epts1 = static_cast<int>( ( Emax1 - Emin1 ) / deltaE1 ) + 1;
      std::vector<double> emesh1;
      for ( int i = 0; i < epts1; ++i ) {

         emesh1.push_back( Emin1 + i * deltaE1 );
      }

      // Create Energy grid for E-slice
      double Emin2 = -300;
      double Emax2 = -25;
      double deltaE2 = 2;
      int epts2 = static_cast<int>( ( Emax2 - Emin2 ) / deltaE2 ) + 1;
      std::vector<double> emesh2;
      for ( int i = 0; i < epts2; ++i ) {

         emesh2.push_back( Emin2 + i * deltaE2 );
      }

      matrix_t S_of_kE_mtx1( kmesh1.size(), emesh1.size() );
      matrix_t S_of_kE_mtx2( kmesh2.size(), emesh2.size() );

      // intialize matrices to zero
      for ( unsigned int i = 0; i < kmesh1.size(); ++i ) {
         for ( unsigned int j = 0; j < emesh1.size(); ++j ) {

            S_of_kE_mtx1( i, j ) = 0;
         }
      }

      for ( unsigned int i = 0; i < kmesh2.size(); ++i ) {
         for ( unsigned int j = 0; j < emesh2.size(); ++j ) {

            S_of_kE_mtx2( i, j ) = 0;
         }
      }

      std::vector< matrix_t > S_of_kE_mtx2_lj_vec;

      // Loop over lj channels
      for ( int L = 0; L < lmax + 1; ++L ) {
         cout<<"l = "<<L<<endl;

         for( int up = -1; up < 2; up+=2 ) {

            double xj = L + up / 2.0;
            int j_index = ( up - 1 ) / 2;
            if ( xj < 0 ) continue;

            std::string j_string;
            if ( L == 0 ) j_string = J_array[ L ];
            else j_string = J_array[ L + j_index ];

            std::string lj_string = L_array[L] + j_string + "2";

            // Create Bessel Function matrix in k and r
            matrix_t bess_mtx1( kmesh1.size(), rmesh.size() );
            for( unsigned int nk = 0; nk < kmesh1.size(); ++nk ) {
               for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {

                  double rho = kmesh1[nk] * rmesh[nr];

                  bess_mtx1( nk, nr ) = gsl_sf_bessel_jl( L, rho );
               }
            }

            // Create Bessel Function matrix in k and r
            matrix_t bess_mtx2( kmesh2.size(), rmesh.size() );
            for( unsigned int nk = 0; nk < kmesh2.size(); ++nk ) {
               for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {

                  double rho = kmesh2[nk] * rmesh[nr];

                  bess_mtx2( nk, nr ) = gsl_sf_bessel_jl( L, rho );
               }
            }

            // Calculate S( k; E ) for k-slice 
            for ( unsigned int m = 0; m < emesh1.size(); ++m ) {

               double E = emesh1[m];

               /*
                  std::ostringstream e_strm;
                  e_strm << "m" << std::abs( E );
                  std::string s_of_kE_lj_filename1 = 
                  output_dir + np_strings[nu] + "_s_of_k_" + 
                  "E_at_" + e_strm.str() + "MeV_" + L_array[L] 
                  + j_string + "2.out";

                  std::ofstream file1( s_of_kE_lj_filename1.c_str() );
                  */
               // Propagator
               cmatrix_t G = B.propagator( rmesh, E, L, xj );

               // Spectral Function in momentum space, S( k; E ) 
               for( unsigned int nk = 0; nk < kmesh1.size(); ++nk ) {

                  double rsums = 0;
                  for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                     double jl1 = bess_mtx1( nk, i );

                     for( unsigned int j = 0; j < rmesh.size(); ++j ) {
                        double jl2 = bess_mtx1( nk, j );

                        rsums -= rmesh[i] * jl1 * imag( G( i, j ) ) 
                           * rmesh[j] * jl2 * rdelt * 2 / M_PI / M_PI;
                     }
                  } // end loop over radial coordinates

                  //                        file1 << kmesh1[nk] << " " << rsums << std::endl;

                  S_of_kE_mtx1( nk, m ) += ( 2 * xj + 1 ) * rsums;

               } // end loop over k

               //                    file1.close();
               //                    file1.clear();

               // r-space spectral functions

            } // end loop over energy

            // Calculate S( k; E ) for E-slice 
            matrix_t S_of_kE_mtx_lj( kmesh2.size(), emesh2.size() );
            for ( unsigned int m = 0; m < emesh2.size(); ++m ) {

               double E = emesh2[m];

               // Propagator
               cmatrix_t G = B.propagator( rmesh, E, L, xj );

               // Spectral Function in momentum space, S( k; E ) 
               for( unsigned int nk = 0; nk < kmesh2.size(); ++nk ) {

                  double rsums = 0;
                  for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                     double jl1 = bess_mtx2( nk, i );

                     for( unsigned int j = 0; j < rmesh.size(); ++j ) {
                        double jl2 = bess_mtx2( nk, j );

                        rsums -= rmesh[i] * jl1 * imag( G( i, j ) ) 
                           * rmesh[j] * jl2 * rdelt * 2 / M_PI / M_PI;
                     }
                  } // end loop over radial coordinates

                  S_of_kE_mtx_lj( nk, m ) = ( 2 * xj + 1 ) * rsums;
                  S_of_kE_mtx2( nk, m ) += ( 2 * xj + 1 ) * rsums;

               } // end loop over k

            } // end loop over energy

            S_of_kE_mtx2_lj_vec.push_back( S_of_kE_mtx_lj );

         }// end loop over j

      } // end loop over L

      // write out results summed over the lj combinations
      for ( unsigned int j = 0; j < emesh1.size(); ++j ) {

         std::ostringstream e_strm;
         e_strm << "m" << std::abs( emesh1[j] );
         std::string s_of_kE_filename1 = 
            output_dir + np_strings[nu] + "_s_of_k_" + 
            "E_at_" + e_strm.str() + "MeV.out"; 

         std::ofstream file3( s_of_kE_filename1.c_str() );

         for ( unsigned int i = 0; i < kmesh1.size(); ++i ) {

            file3 << kmesh1[i] << " " << S_of_kE_mtx1( i, j ) << std::endl;
         }

         file3.close();
         file3.clear();
      }

      // write in units of MeV^-4 sr^-1
      double fac = std::pow( hbarc, 3 ) * 4 * M_PI;
      for ( unsigned int i = 0; i < kmesh2.size(); ++i ) {
         std::ostringstream k_strm;
         k_strm << pmesh[i];
         std::string s_of_kE_filename2 = 
            output_dir + np_strings[nu] + "_s_of_E_" + 
            "p_at_" + k_strm.str() + "MeV_over_c.out"; 

         std::ofstream file4( s_of_kE_filename2.c_str() );

         for ( unsigned int j = 0; j < emesh2.size(); ++j ) {

            // write energy in terms of missing energy
            // and in units of GeV
            file4 << std::abs( emesh2[j]/1000) << " " 
               << S_of_kE_mtx2( i, j ) / fac << " "
               << S_of_kE_mtx2( i, j ) / fac / calc_norm << std::endl;
         }

         file4.close();
         file4.clear();
      }

      // write in units of MeV^-4 sr^-1
      for ( unsigned int nk = 0; nk < kmesh2.size(); ++nk ) {

         for ( int L = 0; L < lmax + 1; ++L ) {

            std::ostringstream k_strm;
            k_strm << pmesh[nk];

            std::string s_of_kE_lj_filename2 = 
               output_dir + np_strings[nu] + "_s_of_E_p_at_" 
               + k_strm.str() + "MeV_over_c_" + L_array[L] 
               + ".out";

            std::ofstream file2( s_of_kE_lj_filename2.c_str() );
            for ( unsigned int m = 0; m < emesh2.size(); ++m ) {

               // write energy in terms of missing energy
               // and in units of GeV
               if ( L == 0 ) {
                  file2 << std::abs( emesh2[m]/1000 ) << " " 
                     << S_of_kE_mtx2_lj_vec[0]( nk, m ) / fac 
                     << std::endl;
               }
               else {

                  double jg = S_of_kE_mtx2_lj_vec[2*L]( nk, m );
                  double jl = S_of_kE_mtx2_lj_vec[2*L- 1]( nk, m );

                  file2 << std::abs( emesh2[m]/1000) << " " 
                     << jg / fac << " " << jl / fac << " "
                     << ( jg + jl ) / fac << std::endl;
               }
            }

            file2.close();
            file2.clear();

         } // end loop over L

      } // end loop over momentum

   } // end loop over tz
}                                               /* end of pragma loop */

return 1;
}
Example #9
0
int main() {

    double hbarc = 197.327; // hbar * c in [MeV fm]
    double Mass = 938; // nucleon mass in MeV

    std::string input_dir = "Input/";

    // Read Nucleus File
    std::string nucleus_string;
    std::ifstream nucleus_file( "domgen.config" );

    nucleus_file >> nucleus_string;

    nucleus_file.close();
    nucleus_file.clear();

    // Read Configuration file
    std::string config_filename = nucleus_string + ".config";
    std::ifstream config_file( config_filename.c_str() );

    std::string parameters_string;
    int fit_ph;
    double rmax;
    int rpts;
    int lmax;
    config_file >> parameters_string >> fit_ph;
    config_file >> rmax >> rpts >> lmax;

    int num_lj;
    config_file >> num_lj;
    // Knowing the expected number of bound states is useful when
    // looking for particle states that are near the continuum

    // These maps hold the number of bound states for each lj
    std::map<std::string, int> n_lj_map; // neutrons
    std::map<std::string, int> p_lj_map; // protons
    std::vector< std::map< std::string, int > > map_vec;
    for ( int n = 0; n < num_lj; ++n ) {

        std::string key;
        int n_num_bound, p_num_bound;
        config_file >> key >> n_num_bound >> p_num_bound;

        std::pair< std::map< std::string, int >::iterator, bool > n_ret;
        std::pair< std::map< std::string, int >::iterator, bool > p_ret;
        n_ret = n_lj_map.insert ( std::make_pair( key, n_num_bound ) );
        p_ret = p_lj_map.insert ( std::make_pair( key, p_num_bound ) );

        if ( n_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << n_ret.first->second << std::endl;
        }

        if ( p_ret.second == false ) {
            
            std::cout << "element " << key << " already exists "; 
            std::cout << "with a value of " << p_ret.first->second << std::endl;
        }
    }

    map_vec.push_back( n_lj_map );
    map_vec.push_back( p_lj_map );



    config_file.close();
    config_file.clear();

  //  std::string output_dir = "Output_" + parameters_string + "/Ener/";
    std::cout<< std::endl; 
   // std::string parameters_filename = parameters_string + ".inp";
   // std::string parameters_filename ="Output_hosfit/roott/Oct31/hoskhooboo_int.inp";
    std::string parameters_filename ="Output_hosfit/roott/Oct31/root.inp";
    std::cout<< "Input file is" <<" "<< " : " <<" " <<parameters_filename<<std::endl; 

    std::string output_dir = "Output_test/New/Ener/";
    std::cout<< "Output folder is" <<" "<<":"<<" "<< output_dir <<std::endl; 
    std::cout<< std::endl; 

    std::cout << "rmax = " << rmax << std::endl;
    std::cout << "rpts = " << rpts << std::endl;
    std::cout << "lmax = " << lmax << std::endl;

    std::string n_string = "n" + nucleus_string;
    std::string p_string = "p" + nucleus_string;

    std::string n_filename = input_dir + n_string + ".inp";
    std::string p_filename = input_dir + p_string + ".inp";

    // Create Nuclear Parameter Objects
    NuclearParameters Nu_n = read_nucleus_parameters( n_filename );
    NuclearParameters Nu_p = read_nucleus_parameters( p_filename );

    std::vector< NuclearParameters > Nu_vec;
    Nu_vec.push_back( Nu_n );
    Nu_vec.push_back( Nu_p );


    // Read in DOM parameters
    std::ifstream pfile( parameters_filename.c_str() );
    if ( pfile.is_open() !=1 ) {
        std::cout << "could not open file " << parameters_filename << std::endl;
        std::abort();
    }
    pfile.close();
    pfile.clear();

    std::string L_array[8] = { "s", "p", "d", "f", "g", "h", "i", "j" };
    std::string J_array[8] = { "1", "3", "5", "7", "9", "11", "13", "15" };

    // Create momentum space grid
    std::vector<double> kmesh;
    std::vector<double> kweights;
   // double const kmax = 1.4;
    double const kmax = 6.;
    int const kpts = 104;
    kmesh.resize( kpts );
    kweights.resize( kpts );
    GausLeg( 0., kmax, kmesh, kweights );

    // Create radial grid
    std::vector<double> rmesh;
    std::vector<double> rweights;
    double rdelt = rmax / rpts;
    for( int i = 0; i < rpts; ++i ) {

        rmesh.push_back( ( i + 0.5 ) * rdelt );
        rweights.push_back( rdelt );
    }

    // Prepare stuff for output files
    std::vector< std::string > np_strings;
    np_strings.push_back( n_string );
    np_strings.push_back( p_string );

    std::string energy_filename = output_dir + nucleus_string + "_energy.out";
    std::ofstream energy_file( energy_filename.c_str() );
    double total_energy = 0;
    double calc_A = 0;

    //Potential specifications
    int type = 1; // 1 is P.B. form (average), 0 is V.N. form
    int mvolume = 4;
    int AsyVolume = 1;

    // --- CALCULATIONS --- //

    // Loop over protons and neutrons
    double Zp; // number of protons in projectile

    for ( unsigned int nu = 0; nu < Nu_vec.size(); ++nu ) {
        
        std::map< std::string, int > lj_map = map_vec[nu];

        double tz = nu - 0.5; // +0.5 for protons, -0.5 for neutrons
        double Elim;

        if ( tz < 0 ) {
            Zp = 0;
            Elim = -62; // below 0s1/2 level for neutrons in 40Ca
        }
        else {
            Zp = 1;
            Elim = -56; // below 0s1/2 level for protons in 40Ca
        }

        // Nucleus Object
        const NuclearParameters &Nu = Nu_vec[nu];

        // Construct Parameters Object
        Parameters p = get_parameters( parameters_filename, Nu.A, Nu.Z, Zp );

        // Construct Potential Object
        pot U = get_bobs_pot2( type, mvolume, AsyVolume, tz, Nu, p );
        pot *U1 = &U;

        // Construct boundRspace Object
//        double Emax = Nu.Ef - Nu.Wgap * p.fGap_B; // energy < Ef where imaginary part begins
        double Emax = 2.* Nu.Ef;
        double Emin = -200 + Emax;
        boundRspace B( rmax, rpts, Nu.Ef, Nu.ph_gap, lmax, Nu.Z, Zp, Nu.A, U1 );

        double tol = 0.01;
        std::vector< lj_eigen_t > bound_levels = 
            B.get_bound_levels( rmesh, tol );

        std::vector< mesh_t > emesh_vec = 
            B.get_emeshes( rmesh, Emin, Emax, bound_levels );

        double T_plus_2V = 0; // for total energy calculation
        double T_plus_2V_qh_peak_tot = 0;
        double T_plus_2V_c_tot = 0;
        std::vector< double > T_plus_2V_c_lj_vec;
        std::vector< double > T_plus_2V_c_Elim_lj_vec;
        std::vector< double > e_kin_c_lj_vec;
        std::vector< double > e_kin_peak_lj_vec;
        std::vector< double > e_kin_c_Elim_lj_vec;

        std::vector<double> n_of_k;
        n_of_k.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_qh;
        n_of_k_qh.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_Elim;
        n_of_k_Elim.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_c_tot;
        n_of_k_c_tot.assign( kmesh.size(), 0 );
        std::vector<double> n_of_k_qh_peak_tot;
        n_of_k_qh_peak_tot.assign( kmesh.size(), 0 );




        // Loop over lj channels
        for ( int l = 0; l < lmax + 1; ++l ) {

            // Create Bessel Function matrix in k and r
            matrix_t bess_mtx( kmesh.size(), rmesh.size() );
            for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
            for( unsigned int nr = 0; nr < rmesh.size(); ++nr ) {

                double rho = kmesh[nk] * rmesh[nr];

                bess_mtx( nk, nr ) = gsl_sf_bessel_jl( l, rho );
            }
            }

            for( int up = -1; up < 2; up+=2 ) {

                double xj = l + up / 2.0;
                int j_index = ( up - 1 ) / 2;
                if ( xj < 0 ) continue;

                std::string j_string;
                if ( l == 0 ) j_string = J_array[ l ];
                else j_string = J_array[ l + j_index ];

                int index = B.index_from_LJ( l, xj );
                mesh_t &emesh = emesh_vec[index];
                std::vector< eigen_t > &bound_info = bound_levels[index];

                std::string lj_string = L_array[l] + j_string + "2";

                double T_plus_2V_c = 0; // contribution from continuum
                double T_plus_2V_qh = 0; // contribution from quasiholes
                double T_plus_2V_c_Elim = 0; // contribution for E < Elim

                std::vector<double> n_of_k_c_lj;
                std::vector<double> n_of_k_c_Elim_lj;
                std::vector<double> n_of_k_qh_lj;
                std::vector<double> n_of_k_qh_peak;
                n_of_k_c_lj.assign( kmesh.size(), 0 );
                n_of_k_c_Elim_lj.assign( kmesh.size(), 0 );
                n_of_k_qh_lj.assign( kmesh.size(), 0 );
                n_of_k_qh_peak.assign( kmesh.size(), 0 );

	        matrix_t n_r_lj(rmesh.size(),rmesh.size());
	        matrix_t k_r_lj(rmesh.size(),rmesh.size());
		for (int i=0;i<rmesh.size();++i){
		     for (int j=0;j<rmesh.size();++j){n_r_lj(i,j) = 0.;k_r_lj(i,j) = 0.;}}

                // Find self-consistent solutions

                std::cout << "lj = " << l << " " << xj << std::endl;

                // Loop over energy
                double Esum = 0.;
                double Esum2 = 0.; // sum for energies up to E = Elim
		vector<cmatrix_t> G;
	        vector<double> E;
	        vector<double> Edelt;
                for ( unsigned int m = 0; m < emesh.size(); ++m ) {
                    
                    E.push_back(emesh[m].first);
                    Edelt.push_back(emesh[m].second);
                    // Propagator
                    G.push_back(B.propagator( rmesh, E[m], l, xj ));
                  } // end loop over energy
	         for (int i = 0 ; i < rmesh.size(); ++i){
		         for (int j = 0 ; j < rmesh.size(); ++j){
			     double sumnr = 0.;
                             double ksum = 0;
			     double r_r = rmesh[i] * rmesh[j]; 	
                             for ( unsigned int m = 0; m < emesh.size(); ++m ) {
			            sumnr += r_r * imag(G[m](i,j)) * Edelt[m];
			            ksum += r_r * imag(G[m](i,j)) * E[m] * Edelt[m];
		            }
		    n_r_lj(i,j) = sumnr;	
		    k_r_lj(i,j) = ksum;	
		         }
                  }
                 // Spectral Function in momentum space    
                 // Integrate E * S( k; E ) over k and E for 
                 // calculation of total energy
                 for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {
                        double rsums = 0.;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {
                            double jl1 = bess_mtx( nk, i );
                        for( unsigned int j = 0; j < rmesh.size(); ++j ) {
                            double jl2 = bess_mtx( nk, j );
                            
                            Esum  -= kweights[nk] * std::pow( kmesh[nk], 2 ) * k_r_lj(i,j) * jl1 * jl2 * rdelt;;
                            rsums -= n_r_lj(i,j) * jl1 * jl2 * rdelt;
                        }
                        } // end loop over radial coordinates

                        n_of_k_c_lj[nk] += rsums * ( 2 * xj + 1 )/( 4 * M_PI ) * 2 / M_PI / M_PI;

                      //   if ( E < Elim ) { n_of_k_c_Elim_lj[nk] += rsums * ( 2 * xj + 1 )
                      //                                            / ( 4 * M_PI );}

                        // integral over k
                } // end loop over k

                // integral over energy
                Esum = Esum * 2.0 / M_PI / M_PI;
                T_plus_2V_c = Esum;
                T_plus_2V_c_Elim = Esum2;
                T_plus_2V_c_lj_vec.push_back( ( 2 * xj + 1 ) * T_plus_2V_c );
                T_plus_2V_c_Elim_lj_vec.push_back(( 2 * xj + 1 ) * T_plus_2V_c_Elim );

                // loop over the orbitals and write out the 
                // bound state information to a file
                for ( unsigned int N = 0; N < bound_info.size(); ++N ) {
                    // Quasiparticle energy
                    double QPE = bound_info[N].first; 

                    // Quasiparticle wavefunction
                    std::vector<double> &QPF = bound_info[N].second;

                    // Spectroscopic Factor
                    double S = B.sfactor( rmesh, QPE, l, xj, QPF );

                    // Transform wavefunction to momentum space
                    std::vector<double> kQPF;
                    for( unsigned int nk = 0; nk < kmesh.size(); ++nk ) {

                        double sum = 0;
                        for( unsigned int i = 0; i < rmesh.size(); ++i ) {

                           sum += std::sqrt( 2 / M_PI ) * rweights[i] 
                                * std::pow( rmesh[i], 2 ) * QPF[i] * bess_mtx( nk, i );
                        }
                        kQPF.push_back( sum );
                      }

                    // This should automatically be normalized to N or Z
                    // since the wavefunctions are normalized to 1
                    if ( QPE < Nu.Ef ) {
                        for ( unsigned int kk = 0; kk < kmesh.size(); ++kk ) {

                            n_of_k_qh_lj[kk] += ( 2 * xj + 1 ) / ( 4 * M_PI ) * kQPF[kk] * kQPF[kk]; 
                        } // end loop over k
                    }
                    // Peak contributions
                    if ( ( QPE > Emax ) && ( QPE < Nu.Ef ) ) {

                        T_plus_2V_qh += S * QPE;

                        // This needs to be added to the continuum part
                        for ( unsigned int kk = 0; kk < kmesh.size(); ++kk ) {

                            n_of_k_qh_peak[kk] += ( 2 * xj + 1 ) / ( 4 * M_PI ) * S * kQPF[kk] * kQPF[kk];
                        } // end loop over k

                        // Add peak contributions to the momentum distribution
                        std::cout << "added to momentum distribution " 
                                  << N << " " << l << " " << xj << " " 
                                  << QPE << " " << S << std::endl;

                    } // endif

                } // end loop over N 
                T_plus_2V += ( 2 * xj + 1 ) * ( T_plus_2V_c + T_plus_2V_qh );

                T_plus_2V_qh_peak_tot += ( 2 * xj + 1 ) * T_plus_2V_qh;
                T_plus_2V_c_tot += ( 2 * xj + 1 ) * T_plus_2V_c;


                // Write Out Momentum Distribution for each lj channel
                // Also, add up the contribution from each channel to get 
                // the total momentum distribution
                std::string n_of_k_lj_filename = output_dir + "n_of_k_" 
                                               + np_strings[nu] 
                                               + "_" + L_array[l] + j_string 
                                               + "2.out";
                std::ofstream n_of_k_lj_file( n_of_k_lj_filename.c_str() );

                double e_kin_c_lj = 0;
                double e_kin_c_Elim_lj = 0;
                double e_kin_peak_lj = 0;
                for ( unsigned int i = 0; i < kmesh.size(); ++i ) {
                    double n_of_k_lj = n_of_k_c_lj[i] + n_of_k_qh_peak[i];

                    n_of_k_lj_file << kmesh[i] << " " << n_of_k_lj 
                                   << " " << n_of_k_qh_lj[i] << std::endl;

                    n_of_k[i] += n_of_k_lj;
                    n_of_k_qh[i] += n_of_k_qh_lj[i];
                    n_of_k_Elim[i] += n_of_k_c_Elim_lj[i];
                    n_of_k_qh_peak_tot[i] += n_of_k_qh_peak[i];
                    n_of_k_c_tot[i] += n_of_k_c_lj[i];

                    e_kin_c_lj += kweights[i] * std::pow( kmesh[i], 4 ) 
                                * std::pow( hbarc, 2 ) / ( 2 * Mass ) 
                                * n_of_k_c_lj[i] * 4 * M_PI; 

                    e_kin_peak_lj += kweights[i] * std::pow( kmesh[i], 4 ) 
                                   * std::pow( hbarc, 2 ) / ( 2 * Mass ) 
                                   * n_of_k_qh_peak[i] * 4 * M_PI; 

                    e_kin_c_Elim_lj += kweights[i] * std::pow( kmesh[i], 4 ) 
                                     * std::pow( hbarc, 2 ) / ( 2 * Mass ) 
                                     * n_of_k_c_Elim_lj[i] * 4 * M_PI;

                }

                n_of_k_lj_file.close();
                n_of_k_lj_file.clear();

                e_kin_c_lj_vec.push_back( e_kin_c_lj );
                e_kin_peak_lj_vec.push_back( e_kin_peak_lj );
                e_kin_c_Elim_lj_vec.push_back( e_kin_c_Elim_lj );
	    }//up
         }//lj


        // Output Files
        std::string strength_filename = output_dir + np_strings[nu] 
                                      + "_k_strength.out";
        std::ofstream strength_file( strength_filename.c_str() );

        std::string n_of_k_filename = output_dir + np_strings[nu]
                                    + "_momentum_dist.out";
        std::ofstream n_of_k_file( n_of_k_filename.c_str() ); 

        // Calculate Particle Number and Kinetic Energy
        double norm = 0;
        double kineticE = 0;
        double kineticE_c = 0;
        double kineticE_peak = 0;
        for ( unsigned int n = 0; n < kmesh.size(); ++n ) {
            norm += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                  * n_of_k[n];

            kineticE += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 4 ) 
                      * n_of_k[n] * std::pow( hbarc, 2 ) / ( 2 * Mass );

            kineticE_c += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 4 ) 
                        * n_of_k_c_tot[n] * std::pow( hbarc, 2 ) / ( 2 * Mass );

            kineticE_peak += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 4 ) 
                           * n_of_k_qh_peak_tot[n] 
                           * std::pow( hbarc, 2 ) / ( 2 * Mass );

        }

        // Energetics
        double E_total = ( kineticE + T_plus_2V ) / 2;
        double E_potential = ( T_plus_2V - kineticE ) / 2;

        double E_total_c4 = ( kineticE_c + T_plus_2V_c_tot ) / 2;
        double E_total_peak = ( kineticE_peak + T_plus_2V_qh_peak_tot ) / 2;

        if ( tz > 0 ) energy_file << "Protons " << std::endl;
        else energy_file << "Neutrons " << std::endl;

        energy_file << " " << std::endl;
        energy_file << "Total Energy: " << E_total << std::endl;
        energy_file << "Kinetic Energy: " << kineticE << std::endl;
        energy_file << "Potential Energy: " << E_potential << std::endl;
        energy_file << "T_plus_2V: " << T_plus_2V << std::endl;
        energy_file << " " << std::endl;
        energy_file << "Kinetic Energy from continuum: " << kineticE_c 
                    << std::endl;
        energy_file << "Kinetic Energy from qh delta peaks: " << kineticE_peak 
                    << std::endl;
        energy_file << "T_plus_2V from continuum: " << T_plus_2V_c_tot 
                    << std::endl;
        energy_file << "T_plus_2V from qh delta peaks: " << T_plus_2V_qh_peak_tot 
                    << std::endl;
        energy_file << "Total energy from continuum: " << E_total_c4 
                    << std::endl;
        energy_file << "Total energy from qh delta peaks: " << E_total_peak 
                    << std::endl;

        energy_file << " " << std::endl;
        double N_or_Z; // actual number of neutrons or protons
        if( tz > 0 ) { 
            energy_file << "E / Z = " << E_total / norm << std::endl;
            energy_file << "Z = " << norm << std::endl;
            N_or_Z = Nu.Z;
        }
        else {
            energy_file << "E / N = " << E_total / norm << std::endl;
            energy_file << "N = " << norm << std::endl;
            N_or_Z = Nu.N();
        }

        total_energy += E_total;
        calc_A += norm;

        energy_file << " " << std::endl;
        energy_file << "// --- Continuum Contributions to energy --- //" 
                    << std::endl;
        energy_file << "L  j  KE  KE [-inf,-50]  Total E  Total E [-inf,-50]"
                    << std::endl;

        
        double E_total_c = 0;
        double E_total_c2 = 0;
        double E_total_c3 = 0;
        double kineticE2_check = 0;

        for ( int L = 0; L < lmax + 1; ++L ) {
        for ( int nj = -1; nj <= 0; ++nj ) {
            
            double xj = L + 0.5 + nj;
            int lj_index = 2 * L + nj;
            if ( lj_index < 0 ) continue;

            double ekin = e_kin_c_lj_vec.at( lj_index );
            double ekin_Elim = e_kin_c_Elim_lj_vec.at( lj_index );
            double T_plus_2V_c = T_plus_2V_c_lj_vec.at( lj_index );
            double T_plus_2V_c_Elim = T_plus_2V_c_Elim_lj_vec.at( lj_index );

            double total = ( ekin + T_plus_2V_c ) / 2.0;
            double total_Elim = ( ekin_Elim + T_plus_2V_c_Elim ) / 2.0;
            energy_file << L << " " << xj << " " << ekin << " " << ekin_Elim 
                        << " " << total << " " << total_Elim << std::endl;

            E_total_c += total; // Should be the same as Etotal
            kineticE2_check += ekin_Elim;

            if ( L == 0 ) E_total_c2 += total_Elim;
            else E_total_c2 += total;

            E_total_c3 += total_Elim;
        }
        }

        energy_file << "Total Continuum Contribution = " 
                    << E_total_c << ", " << E_total_c / E_total * 100 
                    << "\%" << std::endl;

        energy_file << "Total Continuum Contribution ( s wave, " 
                    << "Emax = " << Elim << " ) = " << E_total_c2 
                    << ", " << E_total_c2 / E_total * 100 
                    << "\%" << std::endl;

        energy_file << "Total Continuum Contribution ( " 
                    << "Emax = " << Elim << " ) = " << E_total_c3 
                    << ", " << E_total_c3 / E_total * 100 
                    << "\%" << std::endl;

        energy_file << " " << std::endl;
        energy_file << "-----------------------------------------" << std::endl;
        energy_file << " " << std::endl;

        // Momentum Distribution and strength
        double k_strength = 0;
        double qh_strength = 0;
        for ( unsigned int n = 0; n < kmesh.size(); ++n ) {
            n_of_k_file << kmesh[n] << " " << n_of_k[n] / norm        
                                    << " " << n_of_k_qh[n] / N_or_Z 
                                    << std::endl;

            //verify that n_of_k_qh is normalized to N or Z
            qh_strength += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                     * n_of_k_qh[n] / N_or_Z;

            k_strength += 4 * M_PI * kweights[n] * std::pow( kmesh[n], 2 ) 
                        * n_of_k[n] / norm;
            
            strength_file << kmesh[n] << " " << k_strength 
                                      << " " << qh_strength << std::endl;
        }

        strength_file << " " << std::endl;
        strength_file << "norm = " << norm << std::endl;
        strength_file << "N or Z = " << N_or_Z << std::endl;

        n_of_k_file.close();
        n_of_k_file.clear();
        strength_file.close();
        strength_file.clear();


    }//tz
return 1;
}
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;

}