Skip to content

Commit 0b60db9

Browse files
committed
refactor use_paw
1 parent 0ecfbc4 commit 0b60db9

File tree

4 files changed

+121
-64
lines changed

4 files changed

+121
-64
lines changed

source/module_hsolver/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ list(APPEND objects
99
hsolver_pw_sdft.cpp
1010
diago_iter_assist.cpp
1111
hsolver.cpp
12+
pawcode_in_hsolverpw.cpp
1213
)
1314

1415
if(ENABLE_LCAO)

source/module_hsolver/hsolver_pw.cpp

Lines changed: 4 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -21,76 +21,16 @@
2121
#ifdef USE_PAW
2222
#include "module_cell/module_paw/paw_cell.h"
2323
#include "module_hamilt_pw/hamilt_pwdft/global.h"
24-
// #include "module_base/parallel_global.h" // for MPI
25-
// #include "module_hamilt_pw/hamilt_pwdft/hamilt_pw.h"
2624
#endif
25+
2726
namespace hsolver
2827
{
2928

3029
#ifdef USE_PAW
31-
template <typename T, typename Device>
32-
void HSolverPW<T, Device>::paw_func_in_kloop(const int ik)
33-
{
34-
if (this->use_paw)
35-
{
36-
const int npw = this->wfc_basis->npwk[ik];
37-
ModuleBase::Vector3<double>* _gk = new ModuleBase::Vector3<double>[npw];
38-
for (int ig = 0; ig < npw; ig++)
39-
{
40-
_gk[ig] = this->wfc_basis->getgpluskcar(ik, ig);
41-
}
42-
43-
std::vector<double> kpt(3, 0);
44-
kpt[0] = this->wfc_basis->kvec_c[ik].x;
45-
kpt[1] = this->wfc_basis->kvec_c[ik].y;
46-
kpt[2] = this->wfc_basis->kvec_c[ik].z;
47-
48-
double** kpg;
49-
double** gcar;
50-
kpg = new double*[npw];
51-
gcar = new double*[npw];
52-
for (int ipw = 0; ipw < npw; ipw++)
53-
{
54-
kpg[ipw] = new double[3];
55-
kpg[ipw][0] = _gk[ipw].x;
56-
kpg[ipw][1] = _gk[ipw].y;
57-
kpg[ipw][2] = _gk[ipw].z;
58-
59-
gcar[ipw] = new double[3];
60-
gcar[ipw][0] = this->wfc_basis->getgcar(ik, ipw).x;
61-
gcar[ipw][1] = this->wfc_basis->getgcar(ik, ipw).y;
62-
gcar[ipw][2] = this->wfc_basis->getgcar(ik, ipw).z;
63-
}
64-
65-
GlobalC::paw_cell.set_paw_k(npw,
66-
wfc_basis->npwk_max,
67-
kpt.data(),
68-
this->wfc_basis->get_ig2ix(ik).data(),
69-
this->wfc_basis->get_ig2iy(ik).data(),
70-
this->wfc_basis->get_ig2iz(ik).data(),
71-
(const double**)kpg,
72-
GlobalC::ucell.tpiba,
73-
(const double**)gcar);
74-
75-
std::vector<double>().swap(kpt);
76-
for (int ipw = 0; ipw < npw; ipw++)
77-
{
78-
delete[] kpg[ipw];
79-
delete[] gcar[ipw];
80-
}
81-
delete[] kpg;
82-
delete[] gcar;
83-
84-
GlobalC::paw_cell.get_vkb();
85-
86-
GlobalC::paw_cell.set_currentk(ik);
87-
}
88-
}
89-
9030
template <typename T, typename Device>
9131
void HSolverPW<T, Device>::call_paw_cell_set_currentk(const int ik)
9232
{
93-
if (this->use_paw)
33+
if (PARAM.inp.use_paw)
9434
{
9535
GlobalC::paw_cell.set_currentk(ik);
9636
}
@@ -99,7 +39,7 @@ void HSolverPW<T, Device>::call_paw_cell_set_currentk(const int ik)
9939
template <typename T, typename Device>
10040
void HSolverPW<T, Device>::paw_func_after_kloop(psi::Psi<T, Device>& psi, elecstate::ElecState* pes)
10141
{
102-
if (this->use_paw)
42+
if (PARAM.inp.use_paw)
10343
{
10444
if (typeid(Real) != typeid(double))
10545
{
@@ -204,9 +144,9 @@ void HSolverPW<T, Device>::paw_func_after_kloop(psi::Psi<T, Device>& psi, elecst
204144
GlobalC::paw_cell.get_nhat(pes->charge->nhat, nhatgr);
205145
}
206146
}
207-
208147
#endif
209148

149+
210150
template <typename T, typename Device>
211151
void HSolverPW<T, Device>::cal_ethr_band(const double& wk,
212152
const double* wg,
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#include "hsolver_pw.h"
2+
3+
// #include "pawcode_in_hsolverpw.h"
4+
5+
#include "module_base/global_variable.h"
6+
#include "module_base/timer.h"
7+
#include "module_base/tool_quit.h"
8+
#include "module_elecstate/elecstate_pw.h"
9+
#include "module_hamilt_general/hamilt.h"
10+
#include "module_hamilt_pw/hamilt_pwdft/wavefunc.h"
11+
#include "module_parameter/parameter.h"
12+
#include "module_psi/psi.h"
13+
14+
#include <algorithm>
15+
#include <vector>
16+
17+
#ifdef USE_PAW
18+
#include "module_cell/module_paw/paw_cell.h"
19+
#include "module_hamilt_pw/hamilt_pwdft/global.h"
20+
#endif
21+
22+
#ifdef USE_PAW
23+
24+
namespace hsolver
25+
{
26+
27+
template <typename T, typename Device>
28+
void HSolverPW<T, Device>::paw_func_in_kloop(const int ik)
29+
{
30+
if (PARAM.inp.use_paw)
31+
{
32+
const int npw = this->wfc_basis->npwk[ik];
33+
ModuleBase::Vector3<double>* _gk = new ModuleBase::Vector3<double>[npw];
34+
for (int ig = 0; ig < npw; ig++)
35+
{
36+
_gk[ig] = this->wfc_basis->getgpluskcar(ik, ig);
37+
}
38+
39+
std::vector<double> kpt(3, 0);
40+
kpt[0] = this->wfc_basis->kvec_c[ik].x;
41+
kpt[1] = this->wfc_basis->kvec_c[ik].y;
42+
kpt[2] = this->wfc_basis->kvec_c[ik].z;
43+
44+
double** kpg;
45+
double** gcar;
46+
kpg = new double*[npw];
47+
gcar = new double*[npw];
48+
for (int ipw = 0; ipw < npw; ipw++)
49+
{
50+
kpg[ipw] = new double[3];
51+
kpg[ipw][0] = _gk[ipw].x;
52+
kpg[ipw][1] = _gk[ipw].y;
53+
kpg[ipw][2] = _gk[ipw].z;
54+
55+
gcar[ipw] = new double[3];
56+
gcar[ipw][0] = this->wfc_basis->getgcar(ik, ipw).x;
57+
gcar[ipw][1] = this->wfc_basis->getgcar(ik, ipw).y;
58+
gcar[ipw][2] = this->wfc_basis->getgcar(ik, ipw).z;
59+
}
60+
61+
GlobalC::paw_cell.set_paw_k(npw,
62+
wfc_basis->npwk_max,
63+
kpt.data(),
64+
this->wfc_basis->get_ig2ix(ik).data(),
65+
this->wfc_basis->get_ig2iy(ik).data(),
66+
this->wfc_basis->get_ig2iz(ik).data(),
67+
(const double**)kpg,
68+
GlobalC::ucell.tpiba,
69+
(const double**)gcar);
70+
71+
std::vector<double>().swap(kpt);
72+
for (int ipw = 0; ipw < npw; ipw++)
73+
{
74+
delete[] kpg[ipw];
75+
delete[] gcar[ipw];
76+
}
77+
delete[] kpg;
78+
delete[] gcar;
79+
80+
GlobalC::paw_cell.get_vkb();
81+
82+
GlobalC::paw_cell.set_currentk(ik);
83+
}
84+
}
85+
86+
87+
} // namespace hsolver
88+
89+
#endif
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// #ifndef PAW_CODE_IN_HSOLVER
2+
// #define PAW_CODE_IN_HSOLVER
3+
4+
// #include "module_base/global_variable.h"
5+
// #include "module_base/timer.h"
6+
// #include "module_base/tool_quit.h"
7+
// #include "module_elecstate/elecstate_pw.h"
8+
// #include "module_hamilt_general/hamilt.h"
9+
// #include "module_hamilt_pw/hamilt_pwdft/wavefunc.h"
10+
// #include "module_parameter/parameter.h"
11+
// #include "module_psi/psi.h"
12+
// #include "module_base/macros.h"
13+
// #include "module_basis/module_pw/pw_basis_k.h"
14+
// #include "module_hamilt_pw/hamilt_pwdft/wavefunc.h"
15+
16+
// #ifdef USE_PAW
17+
18+
// namespace hsolver
19+
// {
20+
21+
// void paw_func_in_kloop(const int ik, ModulePW::PW_Basis_K* wfc_basis);
22+
23+
// }
24+
25+
// #endif
26+
27+
// #endif

0 commit comments

Comments
 (0)