Skip to content

Commit 845b8b0

Browse files
committed
Refactor: Operator for PW base, still remain soc and davidson not fixed
1 parent 3d7cd44 commit 845b8b0

23 files changed

+660
-429
lines changed

source/module_base/global_function.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include "global_variable.h"
1919
#include "global_function-func_each_2.h" // Peize Lin add 2016-09-07
2020

21+
#include "blas_connector.h"
22+
2123
namespace ModuleBase
2224
{
2325
namespace GlobalFunc
@@ -167,6 +169,23 @@ static inline void DCOPY( const T &a, T &b, const int &dim)
167169
for (int i=0; i<dim; ++i) b[i] = a[i];
168170
}
169171

172+
template<typename T>
173+
inline void COPYARRAY(const T* a, T* b, const long dim);
174+
175+
template<>
176+
inline void COPYARRAY(const std::complex<double>* a, std::complex<double>* b, const long dim)
177+
{
178+
const int one = 1;
179+
zcopy_(&dim, a, &one, b, &one);
180+
}
181+
182+
template<>
183+
inline void COPYARRAY(const double* a, double* b, const long dim)
184+
{
185+
const int one = 1;
186+
dcopy_(&dim, a, &one, b, &one);
187+
}
188+
170189
void BLOCK_HERE( const std::string &description );
171190

172191
//==========================================================
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
add_subdirectory(ks_pw)
2+
13
add_library(
24
hamilt
35
OBJECT
46
hamilt_pw.cpp
5-
ekinetic_pw.cpp
6-
veff_pw.cpp
7-
nonlocal_pw.cpp
8-
meta_pw.cpp
97
hamilt_lcao.cpp
8+
ks_pw/ekinetic_pw.cpp
9+
ks_pw/veff_pw.cpp
10+
ks_pw/nonlocal_pw.cpp
11+
ks_pw/meta_pw.cpp
1012
)

source/module_hamilt/ekinetic_pw.cpp

Lines changed: 0 additions & 74 deletions
This file was deleted.

source/module_hamilt/ekinetic_pw.h

Lines changed: 0 additions & 37 deletions
This file was deleted.

source/module_hamilt/hamilt.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class Hamilt
3333

3434
int non_first_scf=0;
3535

36-
protected:
37-
// array, save operations from each operators
38-
std::vector<Operator*> ops;
36+
// first node operator, add operations from each operators
37+
Operator* ops = nullptr;
3938
};
4039

4140
} // namespace hamilt

source/module_hamilt/hamilt_pw.cpp

Lines changed: 43 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,109 +7,102 @@
77
#include "src_parallel/parallel_reduce.h"
88
#include "src_pw/global.h"
99

10-
#include "veff_pw.h"
11-
#include "ekinetic_pw.h"
12-
#include "meta_pw.h"
13-
#include "nonlocal_pw.h"
10+
#include "ks_pw/veff_pw.h"
11+
#include "ks_pw/ekinetic_pw.h"
12+
#include "ks_pw/meta_pw.h"
13+
#include "ks_pw/nonlocal_pw.h"
1414

1515
namespace hamilt
1616
{
1717

1818
HamiltPW::HamiltPW()
1919
{
2020
this->classname = "HamiltPW";
21-
this->ops.resize(0);
22-
const int npwx = GlobalC::wf.npwx;
23-
const int npol = GlobalV::NPOL;
2421
const double tpiba2 = GlobalC::ucell.tpiba2;
25-
const int* ngk = GlobalC::kv.ngk.data();
2622
const int* isk = GlobalC::kv.isk.data();
2723
const double* gk2 = GlobalC::wfcpw->gk2;
2824

2925
if (GlobalV::T_IN_H)
3026
{
31-
Operator* ekinetic = new EkineticPW(
32-
npwx,
33-
npol,
27+
Operator* ekinetic = new Ekinetic<OperatorPW>(
3428
tpiba2,
35-
ngk,
3629
gk2
3730
);
38-
this->ops.push_back(ekinetic);
31+
if(this->ops == nullptr)
32+
{
33+
this->ops = ekinetic;
34+
}
35+
else
36+
{
37+
this->ops->add(ekinetic);
38+
}
3939
}
4040
if (GlobalV::VL_IN_H)
4141
{
42-
Operator* veff = new VeffPW(
43-
npwx,
44-
npol,
45-
ngk,
42+
Operator* veff = new Veff<OperatorPW>(
4643
isk,
4744
&(GlobalC::pot.vr_eff),
4845
GlobalC::wfcpw
4946
);
50-
this->ops.push_back(veff);
47+
if(this->ops == nullptr)
48+
{
49+
this->ops = veff;
50+
}
51+
else
52+
{
53+
this->ops->add(veff);
54+
}
5155
}
5256
if (GlobalV::VNL_IN_H)
5357
{
54-
Operator* nonlocal = new NonlocalPW(
55-
npwx,
56-
npol,
57-
ngk,
58+
Operator* nonlocal = new Nonlocal<OperatorPW>(
5859
isk,
5960
&GlobalC::ppcell,
6061
&GlobalC::ucell
6162
);
62-
this->ops.push_back(nonlocal);
63+
if(this->ops == nullptr)
64+
{
65+
this->ops = nonlocal;
66+
}
67+
else
68+
{
69+
this->ops->add(nonlocal);
70+
}
6371
}
64-
Operator* meta = new MetaPW(
65-
npwx,
66-
npol,
72+
Operator* meta = new Meta<OperatorPW>(
6773
tpiba2,
68-
ngk,
6974
isk,
7075
&GlobalC::pot.vofk,
7176
GlobalC::wfcpw
7277
);
73-
this->ops.push_back(meta);
78+
if(this->ops == nullptr)
79+
{
80+
this->ops = meta;
81+
}
82+
else
83+
{
84+
this->ops->add(meta);
85+
}
7486
}
7587

7688
HamiltPW::~HamiltPW()
7789
{
7890
int index = 0;
79-
if (GlobalV::T_IN_H)
80-
{
81-
delete (EkineticPW*)this->ops[index++];
82-
}
83-
if (GlobalV::VL_IN_H)
84-
{
85-
delete (VeffPW*)this->ops[index++];
86-
}
87-
if (GlobalV::VNL_IN_H)
88-
{
89-
delete (NonlocalPW*)this->ops[index++];
90-
}
91-
delete (MetaPW*)this->ops[index++];
91+
delete this->ops;
9292
}
9393

9494
void HamiltPW::updateHk(const int ik)
9595
{
9696
ModuleBase::TITLE("HamiltPW","updateHk");
9797

98-
for(int iter = 0; iter < this->ops.size(); ++iter)
99-
{
100-
this->ops[iter]->init(ik);
101-
}
98+
this->ops->init(ik);
10299

103100
return;
104101
}
105102

106103
void HamiltPW::hPsi(const std::complex<double> *psi_in, std::complex<double> *hpsi, const size_t size) const
107104
{
108105
ModuleBase::timer::tick("HamiltPW", "h_psi");
109-
for(int iter = 0; iter < this->ops.size(); ++iter)
110-
{
111-
this->ops[iter]->act(psi_in, hpsi, size);
112-
}
113106
ModuleBase::timer::tick("HamiltPW", "h_psi");
114107
return;
115108
}
@@ -121,10 +114,7 @@ void HamiltPW::sPsi
121114
size_t size
122115
) const
123116
{
124-
for (size_t i=0; i<size; i++)
125-
{
126-
spsi[i] = psi[i];
127-
}
117+
ModuleBase::GlobalFunc::COPYARRAY(psi, spsi, size);
128118
return;
129119
}
130120

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_library(
2+
operator_ks_pw
3+
OBJECT
4+
ekinetic_pw.cpp
5+
veff_pw.cpp
6+
nonlocal_pw.cpp
7+
meta_pw.cpp
8+
)

0 commit comments

Comments
 (0)