Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions source/module_hamilt_lcao/module_deepks/deepks_force.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ void DeePKS_domain::cal_f_delta(const std::vector<std::vector<TK>>& dm,
int dRz = 0;
if constexpr (std::is_same<TK, std::complex<double>>::value) // for multi-k
{
dRx = dR2.x - dR1.x;
dRy = dR2.y - dR1.y;
dRz = dR2.z - dR1.z;
dRx = dR1.x - dR2.x;
dRy = dR1.y - dR2.y;
dRz = dR1.z - dR2.z;
}
ModuleBase::Vector3<double> dR(dRx, dRy, dRz);

Expand Down
9 changes: 5 additions & 4 deletions source/module_hamilt_lcao/module_deepks/deepks_fpre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ void DeePKS_domain::cal_gdmx(const int lmaxd,
int dRz = 0;
if constexpr (std::is_same<TK, std::complex<double>>::value)
{
dRx = (dR2 - dR1).x;
dRy = (dR2 - dR1).y;
dRz = (dR2 - dR1).z;
dRx = (dR1 - dR2).x;
dRy = (dR1 - dR2).y;
dRz = (dR1 - dR2).z;
}
ModuleBase::Vector3<double> dR(dRx, dRy, dRz);

hamilt::AtomPair<double> dm_pair(ibt1, ibt2, dRx, dRy, dRz, &pv);
dm_pair.allocate(nullptr, 1);
dm_pair.allocate(nullptr, true);
// not support nspin = 2 now
for (int ik = 0; ik < nks; ik++)
{
TK kphase = TK(0);
Expand Down
8 changes: 4 additions & 4 deletions source/module_hamilt_lcao/module_deepks/deepks_orbpre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ void DeePKS_domain::cal_orbital_precalc(const std::vector<TH>& dm_hl,
{
hamilt::AtomPair<double> dm_pair(ibt1,
ibt2,
(dR2 - dR1).x,
(dR2 - dR1).y,
(dR2 - dR1).z,
(dR1 - dR2).x,
(dR1 - dR2).y,
(dR1 - dR2).z,
&pv);

dm_pair.allocate(&dm_array[ik * row_size * col_size], 0);

const double arg
= -(kvec_d[ik] * ModuleBase::Vector3<double>(dR2 - dR1)) * ModuleBase::TWO_PI;
= -(kvec_d[ik] * ModuleBase::Vector3<double>(dR1 - dR2)) * ModuleBase::TWO_PI;

double sinp, cosp;

Expand Down
51 changes: 33 additions & 18 deletions source/module_hamilt_lcao/module_deepks/deepks_pdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,36 +273,51 @@ void DeePKS_domain::cal_pdm(bool& init_pdm,
}
}
// prepare DM from DMR
std::vector<double> dm_array(row_size * col_size, 0.0);
const double* dm_current = nullptr;
int dRx = 0, dRy = 0, dRz = 0;
if constexpr (std::is_same<TK, std::complex<double>>::value)
{
dRx = dR2.x - dR1.x;
dRy = dR2.y - dR1.y;
dRz = dR2.z - dR1.z;
dRx = dR1.x - dR2.x;
dRy = dR1.y - dR2.y;
dRz = dR1.z - dR2.z;
}
// dm_k
ModuleBase::Vector3<double> dR(dRx, dRy, dRz);

hamilt::AtomPair<double> dm_pair(ibt1, ibt2, dRx, dRy, dRz, &pv);
dm_pair.allocate(nullptr, true);
auto dm_k = dm->get_DMK_vector();
const int nrow = pv.nrow;
for (int ir = 0; ir < row_size; ir++)

if constexpr (std::is_same<TK, double>::value) // for gamma-only
{
for (int is = 0; is < dm_k.size(); is++)
{
if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver))
{
dm_pair.add_from_matrix(dm_k[is].data(), pv.get_row_size(), 1.0, 1);
}
else
{
dm_pair.add_from_matrix(dm_k[is].data(), pv.get_col_size(), 1.0, 0);
}
}
}
else // for multi-k
{
for (int ic = 0; ic < col_size; ic++)
for (int ik = 0; ik < dm_k.size(); ik++)
{
int iglob = (pv.atom_begin_row[ibt1] + ir) + nrow * (pv.atom_begin_col[ibt2] + ic);
int iloc = ir * col_size + ic;
std::complex<double> tmp = 0.0;
for(int ik = 0; ik < dm_k.size(); ik++) // dm_k.size() == _nk * _nspin
const double arg = -(kvec_d[ik] * dR) * ModuleBase::TWO_PI;
const std::complex<double> kphase = std::complex<double>(cos(arg), sin(arg));
if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver))
{
dm_pair.add_from_matrix(dm_k[ik].data(), pv.get_row_size(), kphase, 1);
}
else
{
const double arg = (kvec_d[ik] * ModuleBase::Vector3<double>(dR1 - dR2)) * ModuleBase::TWO_PI;
const std::complex<double> kphase = std::complex<double>(cos(arg), sin(arg));
tmp += dm_k[ik][iglob] * kphase;
dm_pair.add_from_matrix(dm_k[ik].data(), pv.get_col_size(), kphase, 0);
}
dm_array[iloc] += tmp.real();
}
}

dm_current = dm_array.data();
const double* dm_current = dm_pair.get_pointer();
// use s_2t and dm_current to get g_1dmt
// dgemm_: C = alpha * A * B + beta * C
// C = g_1dmt, A = dm_current, B = s_2t
Expand Down
6 changes: 3 additions & 3 deletions source/module_hamilt_lcao/module_deepks/deepks_spre.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ void DeePKS_domain::cal_gdmepsl(const int lmaxd,
int dRz = 0;
if constexpr (std::is_same<TK, std::complex<double>>::value)
{
dRx = (dR2 - dR1).x;
dRy = (dR2 - dR1).y;
dRz = (dR2 - dR1).z;
dRx = (dR1 - dR2).x;
dRy = (dR1 - dR2).y;
dRz = (dR1 - dR2).z;
}
ModuleBase::Vector3<double> dR(dRx, dRy, dRz);

Expand Down
4 changes: 2 additions & 2 deletions source/module_hamilt_lcao/module_hcontainer/atom_pair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ void AtomPair<T>::add_from_matrix(const std::complex<T>* hk,
hk_real_pointer = (T*)hk_tmp;
hk_imag_pointer = hk_real_pointer+1;
BlasConnector::axpy(this->col_size, kphase.real(), hk_real_pointer, 2, hr_tmp, 1);
BlasConnector::axpy(this->col_size, kphase.imag(), hk_imag_pointer, 2, hr_tmp, 1);
BlasConnector::axpy(this->col_size, -kphase.imag(), hk_imag_pointer, 2, hr_tmp, 1);
hk_tmp += ld_hk;
hr_tmp += this->col_size;
}
Expand All @@ -715,7 +715,7 @@ void AtomPair<T>::add_from_matrix(const std::complex<T>* hk,
hk_real_pointer = (T*)hk_tmp;
hk_imag_pointer = hk_real_pointer+1;
BlasConnector::axpy(this->col_size, kphase.real(), hk_real_pointer, ld_hk_2, hr_tmp, 1);
BlasConnector::axpy(this->col_size, kphase.imag(), hk_imag_pointer, ld_hk_2, hr_tmp, 1);
BlasConnector::axpy(this->col_size, -kphase.imag(), hk_imag_pointer, ld_hk_2, hr_tmp, 1);
hk_tmp ++;
hr_tmp += this->col_size;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/deepks/603_NO_deepks_H2O_multik/result.ref
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
etotref -466.8143178204656
etotperatomref -155.6047726068
totalforceref 10.244182
totaltimeref 7.52
etotref -466.8999964506086
etotperatomref -155.6333321502
totalforceref 10.047085
totaltimeref 6.22