Skip to content

Commit

Permalink
...EJB
Browse files Browse the repository at this point in the history
  • Loading branch information
ebylaska committed Jul 23, 2024
1 parent e935b63 commit 5828a18
Show file tree
Hide file tree
Showing 18 changed files with 1,266 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Nwpw/band/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
# files in the band library
file(GLOB_RECURSE src_band_minimizer minimizer/*.hpp minimizer/*.cpp)
file(GLOB_RECURSE src_band_cpsd cpsd/*.hpp cpsd/*.cpp)
file(GLOB_RECURSE src_solid lib/solid/*.hpp lib/solid/*.cpp)
file(GLOB_RECURSE src_cKinetic lib/cKinetic/*.hpp lib/cKinetic/*.cpp)
file(GLOB_RECURSE src_cCoulomb lib/cCoulomb/*.hpp lib/cCoulomb/*.cpp)
file(GLOB_RECURSE src_cExchange-Correlation lib/cExchange-Correlation/*.hpp lib/cExchange-Correlation/*.cpp)
file(GLOB_RECURSE src_cpsp lib/cpsp/*.hpp lib/cpsp/*.cpp)
file(GLOB_RECURSE src_cElectron lib/cElectron/*.hpp lib/cElectron/*.cpp)
file(GLOB_RECURSE src_cpsi lib/cpsi/*.hpp lib/cpsi/*.cpp)
file(GLOB_RECURSE src_solid lib/solid/*.hpp lib/solid/*.cpp)

# create to the band library
add_library(band ${src_band_minimizer} ${src_band_cpsd} ${src_cKinetic} ${src_cCoulomb} ${src_cExchange-Correlation} ${src_cpsp} ${src_cElectron} ${src_cpsi} ${src_solid})
add_library(band ${src_band_minimizer} ${src_band_cpsd} ${src_solid} ${src_cKinetic} ${src_cCoulomb} ${src_cExchange-Correlation} ${src_cpsp} ${src_cElectron} ${src_cpsi} )

# interface nwpwlib library to pspw library
target_link_libraries(band nwpwlib)
Expand Down
6 changes: 3 additions & 3 deletions Nwpw/band/lib/cElectron/cElectron.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ cElectron_Operators::cElectron_Operators(Cneb *mygrid0, cKinetic_Operator *myke0
neall = mygrid->neq[0] + mygrid->neq[1];

/* allocate memory */
Hpsi = mygrid->g_allocate(1);
psi_r = mygrid->h_allocate();
Hpsi = mygrid->g_allocate_nbrillq_all();
psi_r = mygrid->h_allocate_nbrillq_all();
xcp = mygrid->r_nalloc(ispin);
xce = mygrid->r_nalloc(ispin);

Expand All @@ -48,7 +48,7 @@ cElectron_Operators::cElectron_Operators(Cneb *mygrid0, cKinetic_Operator *myke0
vc = mygrid->c_pack_allocate(0);
vcall = mygrid->c_pack_allocate(0);

hmltmp = mygrid->m_allocate(-1, 1);
hmltmp = mygrid->w_allocate_nbrillq_all();

omega = mygrid->lattice->omega();
scal1 = 1.0/((double)((mygrid->nx)*(mygrid->ny)*(mygrid->nz)));
Expand Down
38 changes: 22 additions & 16 deletions Nwpw/band/lib/solid/Solid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace pwdft {

/********************************************
* *
* Molecule::Molecule *
* Solid::Solid *
* *
********************************************/
Solid::Solid(char *infilename, bool wvfnc_initialize, Cneb *mygrid0,
Expand All @@ -28,6 +28,8 @@ Solid::Solid(char *infilename, bool wvfnc_initialize, Cneb *mygrid0,
myelectron = myelectron0;
mypsp = mypsp0;

nbrillouin = mygrid->nbrillouin;
nbrillq = mygrid->nbrillq;
ispin = mygrid->ispin;
neall = mygrid->neq[0] + mygrid->neq[1];
ne[0] = mygrid->ne[0];
Expand All @@ -38,36 +40,41 @@ Solid::Solid(char *infilename, bool wvfnc_initialize, Cneb *mygrid0,
for (int i = 0; i < 60; ++i)
E[i] = 0.0;

psi1 = mygrid->g_allocate(1);
psi2 = mygrid->g_allocate(1);
//psi1 = mygrid->g_allocate(1);
//psi2 = mygrid->g_allocate(1);
psi1 = mygrid->g_allocate_nbrillq_all();
psi2 = mygrid->g_allocate_nbrillq_all();
rho1 = mygrid->r_nalloc(ispin);
rho2 = mygrid->r_nalloc(ispin);
rho1_all = mygrid->r_nalloc(ispin);
rho2_all = mygrid->r_nalloc(ispin);
dng1 = mygrid->c_pack_allocate(0);
dng2 = mygrid->c_pack_allocate(0);

lmbda = mygrid->m_allocate(-1, 1);
hml = mygrid->m_allocate(-1, 1);
eig = new double[mygrid->ne[0] + mygrid->ne[1]];
//lmbda = mygrid->m_allocate(-1, 1);
//hml = mygrid->m_allocate(-1, 1);
hml = mygrid->w_allocate_nbrillq_all();
lmbda = mygrid->w_allocate_nbrillq_all();
eig = new double[nbrillq*(ne[0]+ne[1])];

omega = mygrid->lattice->omega();
scal1 = 1.0 / ((double)((mygrid->nx) * (mygrid->ny) * (mygrid->nz)));
scal2 = 1.0 / omega;
dv = omega * scal1;

n2ft3d = (mygrid->n2ft3d);
shift1 = 2 * (mygrid->npack(1));
//shift1 = 2 * (mygrid->npack(1));
shift1 = 2 * (mygrid->npack1_max());
shift2 = (mygrid->n2ft3d);

//newpsi = psi_read(mygrid, infilename, wvfnc_initialize, psi1, coutput);
newpsi = cpsi_read(mygrid, infilename, wvfnc_initialize, psi1, coutput);

myelectron->gen_vl_potential();

/*---------------------- testing Electron Operators ---------------------- */
/*
/*
double sum1;
std::cout << "Molecule: Testing Electron Operators " << std::endl;
std::cout << "Solid: Testing Electron Operators " << std::endl;
myelectron->run(psi1,rho1,dng1,rho1_all);
sum1 = myelectron->energy(psi1,rho1,dng1,rho1_all);
Expand All @@ -77,12 +84,11 @@ Solid::Solid(char *infilename, bool wvfnc_initialize, Cneb *mygrid0,
std::cout << "electron ehartr = " << myelectron->ehartree(dng1) <<
std::endl; std::cout << "electron exc = " << myelectron->exc(rho1_all)
<< std::endl; std::cout << "electron pxc = " << myelectron->pxc(rho1)
<< std::endl; std::cout << "B electron ehartr = " <<
myelectron->ehartree(dng1) << std::endl; std::cout << "electron vl_ave =
" << myelectron->vl_ave(dng1) << std::endl; std::cout << "electron vnl ave
= " << myelectron->vnl_ave(psi1) << std::endl;
*/
<< std::endl;
std::cout << "B electron ehartr = " << myelectron->ehartree(dng1) << std::endl;
std::cout << "electron vl_ave = " << myelectron->vl_ave(dng1) << std::endl;
std::cout << "electron vnl ave =" << myelectron->vnl_ave(psi1) << std::endl;
*/
/*---------------------- testing Electron Operators ---------------------- */
}

Expand Down
71 changes: 45 additions & 26 deletions Nwpw/band/lib/solid/Solid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Solid {

double omega, scal2, scal1, dv;

int ispin, ne[2], neall, n2ft3d, shift1, shift2;
int ispin, ne[2], neall, nbrillq, nbrillouin, n2ft3d, shift1, shift2;
int nfft[3];
int version = 3;

Expand Down Expand Up @@ -95,13 +95,13 @@ class Solid {
delete[] eig;
}

/* write psi molecule */
/* write psi solid */
void writepsi(char *output_filename, std::ostream &coutput) {
//psi_write(mygrid,&version,nfft,mygrid->lattice->unita_ptr(),&ispin,ne,
// psi1,output_filename,coutput);
}

/* molecule energy */
/* solid energy */
double energy() {
myelectron->run(psi1, rho1, dng1, rho1_all);
E[0] = (myelectron->energy(psi1, rho1, dng1, rho1_all) + myewald->energy());
Expand All @@ -114,20 +114,22 @@ class Solid {
return E[0];
}

/* molecule energy and eigenvalues */
/* solid energy and eigenvalues */
double energy_eigenvalues() {
myelectron->run(psi1, rho1, dng1, rho1_all);
E[0] = (myelectron->energy(psi1, rho1, dng1, rho1_all) + myewald->energy());

/* generate eigenvalues */
myelectron->gen_hml(psi1, hml);
mygrid->m_diagonalize(hml, eig);
//mygrid->m_diagonalize(hml, eig);
mygrid->w_diagonalize(hml, eig);

return E[0];
}

/* molecule energy and eigenvalues and other energies and en */
double gen_all_energies() {
/* solid energy and eigenvalues and other energies and en */
double gen_all_energies()
{
myelectron->run(psi1, rho1, dng1, rho1_all);
myelectron->gen_energies_en(psi1, rho1, dng1, rho1_all, E, en);

Expand All @@ -148,7 +150,8 @@ class Solid {

/* generate eigenvalues */
myelectron->gen_hml(psi1, hml);
mygrid->m_diagonalize(hml, eig);
//mygrid->m_diagonalize(hml, eig);
mygrid->w_diagonalize(hml, eig);

/* generate dipole */
//mypsp->mydipole->gen_dipole(rho1);
Expand All @@ -171,13 +174,13 @@ class Solid {
return ee;
}

/* molecule - generate current hamiltonian */
/* solid - generate current hamiltonian */
void gen_hml() { myelectron->gen_hml(psi1, hml); }

/* molecule - diagonalize the current hamiltonian */
void diagonalize() { mygrid->m_diagonalize(hml, eig); }
/* solid - diagonalize the current hamiltonian */
void diagonalize() { mygrid->w_diagonalize(hml, eig); }

/* molecule - call phafacs and gen_vl_potential and semicore */
/* solid - call phafacs and gen_vl_potential and semicore */
void phafacs_vl_potential_semicore() {
mystrfac->phafac();
myewald->phafac();
Expand Down Expand Up @@ -298,7 +301,7 @@ class Solid {
std::ios init(NULL);
init.copyfmt(os);
std::string eoln = "\n";
os << " ============= energy results (Molecule object) =============" << eoln;
os << " ============= energy results (Solid object) =============" << eoln;
os << eoln << eoln;

os << std::fixed << " number of electrons: spin up= " << std::setw(11)
Expand Down Expand Up @@ -338,19 +341,35 @@ class Solid {
os << " spring bondings : " << Efmt(19,10) << mysolid.E[71] << " ("
<< Efmt(15,5) << mysolid.E[71]/mysolid.myion->nion << " /ion)" << std::endl;
}
os << eoln;
os << eoln;
os << " orbital energy:" << eoln;
int nn = mysolid.ne[0] - mysolid.ne[1];
double ev = 27.2116;
for (int i=0; i<nn; ++i)
os << eig1stream(mysolid.eig[i], mysolid.eig[i] * ev);
for (int i=0; i<mysolid.ne[1]; ++i)
os << eig2stream(mysolid.eig[i+nn],
mysolid.eig[i+nn]*ev,
mysolid.eig[i+(mysolid.ispin-1)*mysolid.ne[0]],
mysolid.eig[i+(mysolid.ispin-1)*mysolid.ne[0]]*ev);
os << eoln;
for (auto nb=0; nb<mysolid.nbrillouin; ++nb)
{
int nbq = mysolid.mygrid->ktoindex(nb);
int pk = mysolid.mygrid->ktop(nb);

int n = mysolid.ne[0] + mysolid.ne[1];
double tmpeig[n];
std:memset(tmpeig,0,n*sizeof(double));
if (pk==mysolid.mygrid->c3db::parall->taskid_k())
std::memcpy(tmpeig,mysolid.eig+nbq*n,n*sizeof(double));
mysolid.mygrid->c3db::parall->Vector_SumAll(3,n,tmpeig);
//std::memcpy(tmpeig,mysolid.eig+nbq*n,n*sizeof(double));

os << eoln;
os << eoln;
os << mysolid.mygrid->mybrillouin->print_zone_point(nb);
os << eoln;
os << " orbital energies:" << eoln;
int nn = mysolid.ne[0] - mysolid.ne[1];
double ev = 27.2116;
for (int i=0; i<nn; ++i)
os << eig1stream(tmpeig[mysolid.ne[0]-1-i], tmpeig[mysolid.ne[0]-1-i] * ev);
for (int i=0; i<mysolid.ne[1]; ++i)
os << eig2stream(tmpeig[i+nn],
tmpeig[i+nn]*ev,
tmpeig[i+(mysolid.ispin-1)*mysolid.ne[0]],
tmpeig[i+(mysolid.ispin-1)*mysolid.ne[0]]*ev);
os << eoln;
}

// write dipoles
//os << mysolid.mypsp->mydipole->shortprint_dipole();
Expand Down
Loading

0 comments on commit 5828a18

Please sign in to comment.