Skip to content

Commit

Permalink
....band fion updates...EJB
Browse files Browse the repository at this point in the history
  • Loading branch information
ebylaska committed Sep 18, 2024
1 parent 4fe59d5 commit 238d9d1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 40 deletions.
67 changes: 34 additions & 33 deletions Nwpw/band/lib/cpsp/CPseudopotential.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,7 +1855,7 @@ void CPseudopotential::v_nonlocal_fion(double *psi, double *Hpsi,
// generate projectors
if (nprj[ia] > 0)
{
mystrfac->strfac_pack_cxr(nbq1,nbq, ii, exi);
mystrfac->strfac_pack_cxr(nbq1,nbq,ii,exi);
for (auto l=0; l<nprj[ia]; ++l)
{
bool sd_function = !(l_projector[ia][l] & 1);
Expand Down Expand Up @@ -2044,33 +2044,31 @@ void CPseudopotential::v_nonlocal_fion(double *psi, double *Hpsi,
void CPseudopotential::f_nonlocal_fion(double *psi, double *fion)
{
nwpw_timing_function ftimer(6);
bool done;
int ia, nshift0, sd_function, i, n;
int jstart, jend, nprjall;


double *exi;
double *prjtmp, *zsw1, *zsw2, *prj, *vnlprj;
double *prjtmp, *zsw1, *zsw2;
double *Gx, *Gy, *Gz, *xtmp, *sum;

double ff[3];
Parallel *parall;

double omega = mypneb->lattice->omega();
// double scal = 1.0/lattice_omega();
double scal = 1.0 / omega;
int one = 1;
int three = 3;
int ntmp, nshift, nn, ispin;

double rone = 1.0;
double rmone = -1.0;
double rone[2] = {1.0,0.0};
double rmone[2] = {-1.0,0.0};

nn = mypneb->neq[0] + mypneb->neq[1];
ispin = mypneb->ispin;
nshift0 = mypneb->npack1_max();
nshift = 2 * mypneb->npack1_max();
exi = new (std::nothrow) double[nshift]();
prjtmp = new (std::nothrow) double[nprj_max * nshift]();
zsw1 = new (std::nothrow) double[nn * nprj_max]();
zsw2 = new (std::nothrow) double[nn * nprj_max]();
auto nn = mypneb->neq[0] + mypneb->neq[1];
auto ispin = mypneb->ispin;
auto nshift0 = mypneb->npack1_max();
auto nshift = 2*mypneb->npack1_max();

exi = new (std::nothrow) double[nshift]();
prjtmp = new (std::nothrow) double[nprj_max*nshift]();
zsw1 = new (std::nothrow) double[2*nn*nprj_max]();
zsw2 = new (std::nothrow) double[2*nn*nprj_max]();

// Copy psi to device
//mypneb->c3db::mygdevice.psi_copy_host2gpu(nshift, nn, psi);
Expand All @@ -2080,7 +2078,8 @@ void CPseudopotential::f_nonlocal_fion(double *psi, double *fion)

for (auto nbq=0; nbq<mypneb->nbrillq; ++nbq)
{
int nbq1 = nbq + 1;
auto nbq1 = nbq + 1;
auto npack1 = mypneb->npack(nbq1);

// Copy psi to device
mypneb->c3db::mygdevice.psi_copy_host2gpu(nshift0, nn, psi+nbq*nshift*nn);
Expand All @@ -2095,29 +2094,31 @@ void CPseudopotential::f_nonlocal_fion(double *psi, double *fion)
auto ii = 0;
while (ii < (myion->nion))
{
ia = myion->katm[ii];
nprjall = 0;
jstart = ii;
done = false;
auto ia = myion->katm[ii];
auto nprjall = 0;
auto jstart = ii;
bool done = false;
while (!done)
{
// generate projectors
if (nprj[ia] > 0)
{
mystrfac->strfac_pack(1, ii, exi);
//mystrfac->strfac_pack(1, ii, exi);
mystrfac->strfac_pack_cxr(nbq1,nbq,ii,exi);
for (auto l=0; l<nprj[ia]; ++l)
{
sd_function = !(l_projector[ia][l] & 1);
prj = prjtmp + ((l+nprjall)*nshift);
vnlprj = vnl[ia] + (l + nbq*nprj[ia])*nshift0;
bool sd_function = !(l_projector[ia][l] & 1);
double *prj = prjtmp + (l+nprjall)*nshift;
double *vnlprj = vnl[ia] + (l + nbq*nprj[ia])*nshift0;
if (sd_function)
mypneb->tcc_pack_Mul(nbq, vnlprj, exi, prj);
mypneb->tcc_pack_Mul(nbq1, vnlprj, exi, prj);
else
mypneb->tcc_pack_iMul(nbq, vnlprj, exi, prj);
mypneb->tcc_pack_iMul(nbq1, vnlprj, exi, prj);

for (n = 0; n < nn; ++n)
for (auto n=0; n<nn; ++n)
{
mypneb->cct_pack_iconjgMul(nbq1, prj, psi + n*nshift + nbq*nshift*nn, xtmp);
//mypneb->cct_pack_iconjgMul(nbq1, prj, psi + n*nshift + nbq*nshift*nn, xtmp);
mypneb->zccr_pack_iconjgMul(nbq1, zsw2+2*(l*nn+n), prj, psi+n*nshift+nbq*nn*nshift, xtmp);
sum[3*n + 3*nn*(l+nprjall)] = mypneb->tt_pack_idot(nbq1, Gx, xtmp);
sum[3*n + 1 + 3*nn*(l+nprjall)] = mypneb->tt_pack_idot(nbq1, Gy, xtmp);
sum[3*n + 2 + 3*nn*(l+nprjall)] = mypneb->tt_pack_idot(nbq1, Gz, xtmp);
Expand All @@ -2136,7 +2137,7 @@ void CPseudopotential::f_nonlocal_fion(double *psi, double *fion)
done = true;
}
}
jend = ii;
auto jend = ii;
mypneb->cc_pack_inprjzdot(nbq1, nn, nprjall, psi + nbq*nshift*nn, prjtmp, zsw1);
parall->Vector_SumAll(1, 2*nn*nprjall, zsw1);
parall->Vector_SumAll(1, 3*nn*nprjall, sum);
Expand All @@ -2155,7 +2156,7 @@ void CPseudopotential::f_nonlocal_fion(double *psi, double *fion)
}
}

ntmp = 2*nn * nprjall;
auto ntmp = 2*nn*nprjall;
DSCAL_PWDFT(ntmp, scal, zsw2, one);

mypneb->c3db::mygdevice.T_free();
Expand Down
6 changes: 3 additions & 3 deletions Nwpw/band/minimizer/band_minimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,9 @@ int band_minimizer(MPI_Comm comm_world0, std::string &rtdbstring, std::ostream &

// write energy results to the json
auto rtdbjson = json::parse(rtdbstring);
rtdbjson["band"]["energy"] = 0.0; //EV;
rtdbjson["band"]["energies"] = 0.0; //mymolecule.E;
rtdbjson["band"]["eigenvalues"] = 0.0; //mymolecule.eig_vector();
rtdbjson["band"]["energy"] = EV;
rtdbjson["band"]["energies"] = mysolid.E;
rtdbjson["band"]["eigenvalues"] = mysolid.eig_vector();

// calculate fion
if (flag == 2)
Expand Down
9 changes: 5 additions & 4 deletions Nwpw/nwpw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ int main(int argc, char *argv[]) {
}
}
}
std::cout << "TASK=" << task << std::endl;


// Tasks
Expand Down Expand Up @@ -1000,11 +1001,11 @@ int main(int argc, char *argv[]) {
}

/* Energy or Gradient task */
if ((task == 10) || (task ==11))
if ((task == 11) || (task ==12))
{
if (oprint)
std::cout << std::endl
<< "Running energy calculation - rtdbstr = " << rtdbstr
<< "Running band energy calculation - rtdbstr = " << rtdbstr
<< std::endl
<< std::endl;
MPI_Barrier(MPI_COMM_WORLD);
Expand All @@ -1016,7 +1017,7 @@ int main(int argc, char *argv[]) {
{
if (oprint)
std::cout << std::endl
<< "Running geometry optimization calculation - rtdbstr = "
<< "Running band geometry optimization calculation - rtdbstr = "
<< rtdbstr << std::endl
<< std::endl;
MPI_Barrier(MPI_COMM_WORLD);
Expand All @@ -1028,7 +1029,7 @@ int main(int argc, char *argv[]) {
{
if (oprint)
std::cout << std::endl
<< "Running frequency calculation - rtdbstr = " << rtdbstr
<< "Running band frequency calculation - rtdbstr = " << rtdbstr
<< std::endl
<< std::endl;
}
Expand Down

0 comments on commit 238d9d1

Please sign in to comment.