void MO_matrix_standard::init() {
  moCoeff.Resize(nmo, totbasis);

  single_write(cout, "Standard MO\n");
  ifstream ORB(orbfile.c_str());
  if(!ORB)
  {
    error("couldn't find orb file ", orbfile);
  }

  single_write(cout,"Reading orbitals from ",orbfile, "\n");
  Array3 <int> coeffmat;
  Array1 <doublevar> coeff;
  int tempint=readorb(ORB,centers,nmo, maxbasis,kpoint, coeffmat, coeff);
  ORB.close();
  single_write(cout, tempint," unique MO coefficients found.\n\n");

  //Fill moCoeff

  int totfunc=0;
  for(int ion=0; ion<centers.size(); ion++)
  {
    int f=0;
    doublevar dot=0;
    for(int d=0; d<3; d++) dot+=centers.centers_displacement(ion,d)*kpoint(d);
    
    cout << "kptfac " << cos(dot*pi) << "  displacement " 
        << centers.centers_displacement(ion,0) << "   "
        << endl;            
    doublevar kptfac=cos(dot*pi);
    
    for(int n=0; n< centers.nbasis(ion); n++)
    {

      //evaluate atomic orbital
      int fnum=centers.basis(ion,n);

      int imax=basis(fnum)->nfunc();

      for(int i=0; i<imax; i++)
      { //sum over the symmetries
        for(int mo=0; mo<nmo; mo++)
        {	      //and the MO's
          //cout << "ion " << ion;
          //cout << "  i " << i << " mo " << mo << "  fnum " << fnum << endl;
          //cout << "coeffmat " << coeffmat(mo,ion, f) << endl;
          //moCoeff(ion, f, mo)=coeff(coeffmat(mo,ion,f));
          if(coeffmat(mo,ion, f) == -1) {
            cout << "missing MO pointer: mo# " << mo << " ion # " << ion
            << " function on ion: " << f << endl;
            error("In the orb file, there is a missing pointer. It might "
                  "be a badly structured file.");
          }
          doublevar temp=coeff(coeffmat(mo,ion,f));
          moCoeff(mo, totfunc)=magnification_factor*kptfac*temp;

        }//mo
        f++;  //keep a total of functions on center
        totfunc++;
      } //i
    } //n
  }  //ion

}
Exemplo n.º 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;

}
void MO_matrix_blas::init() {


  //mo_counter.Resize(nmo);
  //mo_counter=0.0;
  //n_calls=0;

  //Determine where to cut off the basis functions
  
  cutoff.Resize(totbasis);
  int basiscounter=0;
  for(int i=0; i< centers.size(); i++)
  {
    for(int j=0; j< centers.nbasis(i); j++)
    {
      Basis_function* tempbasis=basis(centers.basis(i,j));
      for(int n=0; n< tempbasis->nfunc(); n++)
      {
        //cout << "cutoff " << endl;
        cutoff(basiscounter)=tempbasis->cutoff(n);
        //cout << "rcut(" << basiscounter << ") "
        //     << cutoff(basiscounter) << endl;
        basiscounter++;
      }
    }
  }

  obj_cutoff.Resize(basis.GetDim(0));
  for(int b=0; b< basis.GetDim(0); b++) {
    int nf=basis(b)->nfunc();
    doublevar maxcut=basis(b)->cutoff(0);
    for(int n=1; n< nf; n++) {
      doublevar cut=basis(b)->cutoff(n);
      if(cut > maxcut) maxcut=cut;
    }
    obj_cutoff(b)=maxcut;
  }
  
  
  nfunctions.Resize(basis.GetDim(0));
  for(int b=0; b< basis.GetDim(0); b++) {
    nfunctions(b)=basis(b)->nfunc();
  }
  

  moCoeff.Resize(totbasis, nmo);


  ifstream ORB(orbfile.c_str());
  if(!ORB) error("couldn't find orb file ", orbfile);

  Array3 <int> coeffmat;
  Array1 <doublevar> coeff;
  readorb(ORB,centers, nmo, maxbasis, kpoint,coeffmat, coeff);
  string in;
  ORB.close();

  //Find the cutoffs

  int totfunc=0;

  for(int ion=0; ion<centers.size(); ion++) {
    int f=0;
    doublevar dot=0;
    for(int d=0; d<3; d++) dot+=centers.centers_displacement(ion,d)*kpoint(d);
    
    //cout << "kptfac " << cos(dot*pi) << "  displacement " 
    //    << centers.centers_displacement(ion,0) << "   "
    //    << endl;            
    doublevar kptfac=cos(dot*pi);
        
    for(int n=0; n< centers.nbasis(ion); n++) {

      int fnum=centers.basis(ion,n);
      int imax=basis(fnum)->nfunc();

      for(int i=0; i<imax; i++){ 
        for(int mo=0; mo<nmo; mo++) {	   

          if(coeffmat(mo,ion, f) == -1) {
            moCoeff(totfunc,mo)=0.0;
            //cout << "missing MO pointer: mo# " << mo << " ion # " << ion
            //<< " function on ion: " << f << endl;
            //error("In the orb file, there is a missing pointer. It might "
            //      "be a badly structured file.");
          }
          else moCoeff(totfunc, mo)=magnification_factor*kptfac*coeff(coeffmat(mo,ion,f));
        }//mo
        f++;  //keep a total of functions on center
        totfunc++;
      } //i
    } //n
  }  //ion


  //output_array(moCoeff);

}