Skip to content

Commit e403672

Browse files
committed
Change contributeHR in deepks_lcao into template.
1 parent afc31b1 commit e403672

File tree

3 files changed

+10
-69
lines changed

3 files changed

+10
-69
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -149,85 +149,26 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driv
149149
}
150150
#endif
151151

152-
template <>
153-
void DeePKS<OperatorLCAO<double, double>>::contributeHR()
154-
{
155-
ModuleBase::TITLE("DeePKS", "contributeHR");
156-
#ifdef __DEEPKS
157-
if (GlobalC::ld.get_hr_cal())
158-
{
159-
ModuleBase::timer::tick("DeePKS", "contributeHR");
160-
const Parallel_Orbitals* pv = this->hsk->get_pv();
161-
GlobalC::ld.cal_projected_DM<double>(this->DM, *this->ucell, *ptr_orb_, *(this->gd));
162-
GlobalC::ld.cal_descriptor(this->ucell->nat);
163-
GlobalC::ld.cal_gedm(this->ucell->nat);
164-
// recalculate the H_V_delta
165-
this->H_V_delta->set_zero();
166-
this->calculate_HR();
167-
168-
GlobalC::ld.set_hr_cal(false);
169-
170-
ModuleBase::timer::tick("DeePKS", "contributeHR");
171-
}
172-
// save H_V_delta to hR
173-
this->hR->add(*this->H_V_delta);
174-
#endif
175-
}
176-
177-
template <>
178-
void DeePKS<OperatorLCAO<std::complex<double>, double>>::contributeHR()
179-
{
180-
#ifdef __DEEPKS
181-
ModuleBase::TITLE("DeePKS", "contributeHR");
182-
// if DM_K changed, HR of DeePKS need to refresh.
183-
// the judgement is based on the status of HR in GlobalC::ld
184-
// this operator should be informed that DM_K has changed and HR need to recalculate.
185-
if (GlobalC::ld.get_hr_cal())
186-
{
187-
ModuleBase::timer::tick("DeePKS", "contributeHR");
188-
189-
GlobalC::ld.cal_projected_DM<std::complex<double>>(this->DM, *this->ucell, *ptr_orb_, *this->gd);
190-
GlobalC::ld.cal_descriptor(this->ucell->nat);
191-
// calculate dE/dD
192-
GlobalC::ld.cal_gedm(this->ucell->nat);
193-
194-
// recalculate the H_V_delta
195-
if (this->H_V_delta == nullptr)
196-
{
197-
this->H_V_delta = new hamilt::HContainer<double>(*this->hR);
198-
}
199-
this->H_V_delta->set_zero();
200-
this->calculate_HR();
201-
202-
GlobalC::ld.set_hr_cal(false);
203-
204-
ModuleBase::timer::tick("DeePKS", "contributeHR");
205-
}
206-
// save H_V_delta to hR
207-
this->hR->add(*this->H_V_delta);
208-
#endif
209-
}
210-
template <>
211-
void DeePKS<OperatorLCAO<std::complex<double>, std::complex<double>>>::contributeHR()
152+
template <typename TK, typename TR>
153+
void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
212154
{
213155
#ifdef __DEEPKS
214156
ModuleBase::TITLE("DeePKS", "contributeHR");
215-
// if DM_K changed, HR of DeePKS need to refresh.
157+
// if DM changed, HR of DeePKS need to refresh.
216158
// the judgement is based on the status of HR in GlobalC::ld
217-
// this operator should be informed that DM_K has changed and HR need to recalculate.
159+
// this operator should be informed that DM has changed and HR need to recalculate.
218160
if (GlobalC::ld.get_hr_cal())
219161
{
220162
ModuleBase::timer::tick("DeePKS", "contributeHR");
221163

222-
GlobalC::ld.cal_projected_DM<std::complex<double>>(this->DM, *this->ucell, *ptr_orb_, *this->gd);
164+
GlobalC::ld.cal_projected_DM<TK>(this->DM, *this->ucell, *ptr_orb_, *(this->gd));
223165
GlobalC::ld.cal_descriptor(this->ucell->nat);
224-
// calculate dE/dD
225166
GlobalC::ld.cal_gedm(this->ucell->nat);
226167

227168
// recalculate the H_V_delta
228169
if (this->H_V_delta == nullptr)
229170
{
230-
this->H_V_delta = new hamilt::HContainer<std::complex<double>>(*this->hR);
171+
this->H_V_delta = new hamilt::HContainer<TR>(*this->hR);
231172
}
232173
this->H_V_delta->set_zero();
233174
this->calculate_HR();
@@ -238,7 +179,6 @@ void DeePKS<OperatorLCAO<std::complex<double>, std::complex<double>>>::contribut
238179
}
239180
// save H_V_delta to hR
240181
this->hR->add(*this->H_V_delta);
241-
242182
#endif
243183
}
244184

@@ -537,9 +477,7 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::contributeHk(int ik)
537477
#endif
538478

539479
template class DeePKS<OperatorLCAO<double, double>>;
540-
541480
template class DeePKS<OperatorLCAO<std::complex<double>, double>>;
542-
543481
template class DeePKS<OperatorLCAO<std::complex<double>, std::complex<double>>>;
544482

545483
} // namespace hamilt

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "module_cell/module_neighbor/sltk_grid_driver.h"
66
#include "module_elecstate/module_dm/density_matrix.h"
77
#include "module_hamilt_lcao/module_hcontainer/hcontainer.h"
8+
#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h"
89
#include "operator_lcao.h"
910

1011
namespace hamilt
@@ -57,6 +58,8 @@ class DeePKS<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
5758
private:
5859
elecstate::DensityMatrix<TK, double>* DM;
5960

61+
LCAO_Deepks* ld = nullptr;
62+
6063
const UnitCell* ucell = nullptr;
6164

6265
const Grid_Driver* gd = nullptr;

source/module_hamilt_lcao/module_deepks/deepks_force.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// which is defind as sum_mu,nu rho_mu,nu d/dX (<chi_mu|alpha>V(D)<alpha|chi_nu>)
55

66
// There are 2 subroutines in this file:
7-
// 1. cal_f_delta_gamma, which is used for gamma point calculation
7+
// 1. cal_f_delta, which calculates F_delta
88
// 2. check_f_delta, which prints F_delta into F_delta.dat for checking
99

1010
#ifdef __DEEPKS

0 commit comments

Comments
 (0)