Skip to content

Commit cc94424

Browse files
committed
Change int pointer inl_l to vector inl2l in DeePKS.
1 parent 4463106 commit cc94424

21 files changed

+74
-78
lines changed

source/module_esolver/esolver_ks_lcao.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ void ESolver_KS_LCAO<TK, TR>::before_all_runners(UnitCell& ucell, const Input_pa
223223
ucell.nat,
224224
orb_.Alpha[0].getTotal_nchi() * ucell.nat,
225225
ld.lmaxd,
226-
ld.inl_l,
226+
ld.inl2l,
227227
*orb_.Alpha,
228228
ld.pdm);
229229
}

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
169169
DeePKS_domain::cal_pdm<TK>(this->ld->init_pdm,
170170
inlmax,
171171
this->ld->lmaxd,
172-
this->ld->inl_l,
172+
this->ld->inl2l,
173173
this->ld->inl_index,
174174
this->DM,
175175
this->ld->phialpha,
@@ -182,7 +182,7 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
182182
std::vector<torch::Tensor> descriptor;
183183
DeePKS_domain::cal_descriptor(this->ucell->nat,
184184
inlmax,
185-
this->ld->inl_l,
185+
this->ld->inl2l,
186186
this->ld->pdm,
187187
descriptor,
188188
this->ld->des_per_atom);
@@ -193,7 +193,7 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
193193
this->ld->nmaxd,
194194
inlmax,
195195
this->ld->des_per_atom,
196-
this->ld->inl_l,
196+
this->ld->inl2l,
197197
descriptor,
198198
this->ld->gedm,
199199
this->ld->E_delta,
@@ -204,7 +204,7 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
204204
DeePKS_domain::cal_edelta_gedm(this->ucell->nat,
205205
inlmax,
206206
this->ld->des_per_atom,
207-
this->ld->inl_l,
207+
this->ld->inl2l,
208208
descriptor,
209209
this->ld->pdm,
210210
this->ld->model_deepks,

source/module_hamilt_lcao/module_deepks/LCAO_deepks.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ template <typename T>
2020
LCAO_Deepks<T>::LCAO_Deepks()
2121
{
2222
inl_index = new ModuleBase::IntArray[1];
23-
inl_l = nullptr;
2423
gedm = nullptr;
2524
this->phialpha.resize(1);
2625
}
@@ -30,7 +29,6 @@ template <typename T>
3029
LCAO_Deepks<T>::~LCAO_Deepks()
3130
{
3231
delete[] inl_index;
33-
delete[] inl_l;
3432

3533
//=======1. to use deepks, pdm is required==========
3634
pdm.clear();
@@ -106,7 +104,7 @@ void LCAO_Deepks<T>::init(const LCAO_Orbitals& orb,
106104
// init pdm
107105
for (int inl = 0; inl < this->inlmax; inl++)
108106
{
109-
int nm = 2 * inl_l[inl] + 1;
107+
int nm = 2 * inl2l[inl] + 1;
110108
pdm_size += nm * nm;
111109
this->pdm[inl] = torch::zeros({nm, nm}, torch::kFloat64);
112110
}
@@ -142,9 +140,7 @@ void LCAO_Deepks<T>::init_index(const int ntype,
142140
{
143141
delete[] this->inl_index;
144142
this->inl_index = new ModuleBase::IntArray[ntype];
145-
delete[] this->inl_l;
146-
this->inl_l = new int[this->inlmax];
147-
ModuleBase::GlobalFunc::ZEROS(this->inl_l, this->inlmax);
143+
this->inl2l.resize(this->inlmax, 0);
148144

149145
int inl = 0;
150146
int alpha = 0;
@@ -162,7 +158,7 @@ void LCAO_Deepks<T>::init_index(const int ntype,
162158
for (int n = 0; n < orb.Alpha[0].getNchi(l); n++)
163159
{
164160
this->inl_index[it](ia, l, n) = inl;
165-
this->inl_l[inl] = l;
161+
this->inl2l[inl] = l;
166162
inl++;
167163
}
168164
}

source/module_hamilt_lcao/module_deepks/LCAO_deepks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class LCAO_Deepks
7373
int inlmax = 0; // tot. number {i,n,l} - atom, n, l
7474
int n_descriptor; // natoms * des_per_atom, size of descriptor(projector) basis set
7575
int des_per_atom; // \sum_L{Nchi(L)*(2L+1)}
76-
int* inl_l; // inl_l[inl_index] = l of descriptor with inl_index
76+
std::vector<int> inl2l; // inl2l[inl] = l of descriptor with inl_index
7777
ModuleBase::IntArray* inl_index; // caoyu add 2021-05-07
7878

7979
bool init_pdm = false; // for DeePKS NSCF calculation, set init_pdm to skip the calculation of pdm in SCF iteration

source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
4444
const int nmaxd = ld->nmaxd;
4545

4646
const int des_per_atom = ld->des_per_atom;
47-
const int* inl_l = ld->inl_l;
47+
const std::vector<int> inl2l = ld->inl2l;
4848
const ModuleBase::IntArray* inl_index = ld->inl_index;
4949
const std::vector<hamilt::HContainer<double>*> phialpha = ld->phialpha;
5050

@@ -62,16 +62,16 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
6262
// this part is for integrated test of deepks
6363
// so it is printed no matter even if deepks_out_labels is not used
6464
DeePKS_domain::cal_pdm<
65-
TK>(init_pdm, inlmax, lmaxd, inl_l, inl_index, dm, phialpha, ucell, orb, GridD, *ParaV, pdm);
65+
TK>(init_pdm, inlmax, lmaxd, inl2l, inl_index, dm, phialpha, ucell, orb, GridD, *ParaV, pdm);
6666

67-
DeePKS_domain::check_pdm(inlmax, inl_l, pdm); // print out the projected dm for NSCF calculaiton
67+
DeePKS_domain::check_pdm(inlmax, inl2l, pdm); // print out the projected dm for NSCF calculaiton
6868

6969
std::vector<torch::Tensor> descriptor;
70-
DeePKS_domain::cal_descriptor(nat, inlmax, inl_l, pdm, descriptor,
70+
DeePKS_domain::cal_descriptor(nat, inlmax, inl2l, pdm, descriptor,
7171
des_per_atom); // final descriptor
7272
DeePKS_domain::check_descriptor(inlmax,
7373
des_per_atom,
74-
inl_l,
74+
inl2l,
7575
ucell,
7676
PARAM.globalv.global_out_dir,
7777
descriptor,
@@ -82,7 +82,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
8282
LCAO_deepks_io::save_npy_d(nat,
8383
des_per_atom,
8484
inlmax,
85-
inl_l,
85+
inl2l,
8686
PARAM.inp.deepks_equiv,
8787
descriptor,
8888
PARAM.globalv.global_out_dir,
@@ -100,7 +100,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
100100
nmaxd,
101101
inlmax,
102102
des_per_atom,
103-
inl_l,
103+
inl2l,
104104
descriptor,
105105
ld->gedm,
106106
E_delta,
@@ -111,7 +111,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
111111
DeePKS_domain::cal_edelta_gedm(nat,
112112
inlmax,
113113
des_per_atom,
114-
inl_l,
114+
inl2l,
115115
descriptor,
116116
pdm,
117117
ld->model_deepks,
@@ -131,7 +131,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
131131
std::vector<torch::Tensor> gevdm;
132132
if (PARAM.inp.deepks_scf)
133133
{
134-
DeePKS_domain::cal_gevdm(nat, inlmax, inl_l, pdm, gevdm);
134+
DeePKS_domain::cal_gevdm(nat, inlmax, inl2l, pdm, gevdm);
135135
}
136136

137137
// Energy Part
@@ -163,7 +163,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
163163
TK>(lmaxd, inlmax, nks, kvec_d, phialpha, inl_index, dm_vec, ucell, orb, *ParaV, GridD, gdmx);
164164

165165
torch::Tensor gvx;
166-
DeePKS_domain::cal_gvx(ucell.nat, inlmax, des_per_atom, inl_l, gevdm, gdmx, gvx, rank);
166+
DeePKS_domain::cal_gvx(ucell.nat, inlmax, des_per_atom, inl2l, gevdm, gdmx, gvx, rank);
167167
const std::string file_gradvx = PARAM.globalv.global_out_dir + "deepks_gradvx.npy";
168168
LCAO_deepks_io::save_tensor2npy<double>(file_gradvx, gvx, rank);
169169

@@ -187,7 +187,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
187187
TK>(lmaxd, inlmax, nks, kvec_d, phialpha, inl_index, dm_vec, ucell, orb, *ParaV, GridD, gdmepsl);
188188

189189
torch::Tensor gvepsl;
190-
DeePKS_domain::cal_gvepsl(ucell.nat, inlmax, des_per_atom, inl_l, gevdm, gdmepsl, gvepsl, rank);
190+
DeePKS_domain::cal_gvepsl(ucell.nat, inlmax, des_per_atom, inl2l, gevdm, gdmepsl, gvepsl, rank);
191191
const std::string file_gvepsl = PARAM.globalv.global_out_dir + "deepks_gvepsl.npy";
192192
LCAO_deepks_io::save_tensor2npy<double>(file_gvepsl, gvepsl, rank);
193193

@@ -253,7 +253,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
253253
inlmax,
254254
nat,
255255
nks,
256-
inl_l,
256+
inl2l,
257257
kvec_d,
258258
phialpha,
259259
gevdm,
@@ -381,7 +381,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
381381
inlmax,
382382
nat,
383383
nks,
384-
inl_l,
384+
inl2l,
385385
kvec_d,
386386
phialpha,
387387
gevdm,
@@ -430,7 +430,7 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
430430
{
431431
LCAO_deepks_io::print_dm(nks, PARAM.globalv.nlocal, ParaV->nrow, dm->get_DMK_vector());
432432

433-
DeePKS_domain::check_gedm(inlmax, inl_l, ld->gedm);
433+
DeePKS_domain::check_gedm(inlmax, inl2l, ld->gedm);
434434

435435
std::ofstream ofs("E_delta_bands.dat");
436436
ofs << std::setprecision(10) << e_delta_band;

source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ void LCAO_deepks_io::load_npy_gedm(const int nat,
7777
void LCAO_deepks_io::save_npy_d(const int nat,
7878
const int des_per_atom,
7979
const int inlmax,
80-
const int* inl_l,
80+
const std::vector<int>& inl2l,
8181
const bool deepks_equiv,
8282
const std::vector<torch::Tensor>& descriptor,
8383
const std::string& out_dir,
@@ -98,7 +98,7 @@ void LCAO_deepks_io::save_npy_d(const int nat,
9898
for (int inl = 0; inl < inlmax; ++inl)
9999
{
100100
auto accessor = descriptor[inl].accessor<double, 1>();
101-
int nm = 2 * inl_l[inl] + 1;
101+
int nm = 2 * inl2l[inl] + 1;
102102
for (int im = 0; im < nm; im++)
103103
{
104104
npy_des.push_back(accessor[im]);

source/module_hamilt_lcao/module_deepks/LCAO_deepks_io.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void load_npy_gedm(const int nat, const int des_per_atom, double** gedm, double&
4242
void save_npy_d(const int nat,
4343
const int des_per_atom,
4444
const int inlmax,
45-
const int* inl_l,
45+
const std::vector<int>& inl2l,
4646
const bool deepks_equiv,
4747
const std::vector<torch::Tensor>& descriptor,
4848
const std::string& out_dir,

source/module_hamilt_lcao/module_deepks/deepks_basic.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// Dimension is different for each inl, so there's a vector of tensors
1313
void DeePKS_domain::cal_gevdm(const int nat,
1414
const int inlmax,
15-
const int* inl_l,
15+
const std::vector<int>& inl2l,
1616
const std::vector<torch::Tensor>& pdm,
1717
std::vector<torch::Tensor>& gevdm)
1818
{
@@ -26,7 +26,7 @@ void DeePKS_domain::cal_gevdm(const int nat,
2626
for (int iat = 0; iat < nat; ++iat)
2727
{
2828
int inl = iat * nlmax + nl;
29-
int nm = 2 * inl_l[inl] + 1;
29+
int nm = 2 * inl2l[inl] + 1;
3030
// repeat each block for nm times in an additional dimension
3131
torch::Tensor tmp_x = pdm[inl].reshape({nm, nm}).unsqueeze(0).repeat({nm, 1, 1});
3232
// torch::Tensor tmp_y = std::get<0>(torch::symeig(tmp_x, true));
@@ -127,7 +127,7 @@ void DeePKS_domain::cal_edelta_gedm_equiv(const int nat,
127127
const int nmaxd,
128128
const int inlmax,
129129
const int des_per_atom,
130-
const int* inl_l,
130+
const std::vector<int>& inl2l,
131131
const std::vector<torch::Tensor>& descriptor,
132132
double** gedm,
133133
double& E_delta,
@@ -139,7 +139,7 @@ void DeePKS_domain::cal_edelta_gedm_equiv(const int nat,
139139
LCAO_deepks_io::save_npy_d(nat,
140140
des_per_atom,
141141
inlmax,
142-
inl_l,
142+
inl2l,
143143
PARAM.inp.deepks_equiv,
144144
descriptor,
145145
PARAM.globalv.global_out_dir,
@@ -169,7 +169,7 @@ void DeePKS_domain::cal_edelta_gedm_equiv(const int nat,
169169
void DeePKS_domain::cal_edelta_gedm(const int nat,
170170
const int inlmax,
171171
const int des_per_atom,
172-
const int* inl_l,
172+
const std::vector<int>& inl2l,
173173
const std::vector<torch::Tensor>& descriptor,
174174
const std::vector<torch::Tensor>& pdm,
175175
torch::jit::script::Module& model_deepks,
@@ -201,7 +201,7 @@ void DeePKS_domain::cal_edelta_gedm(const int nat,
201201
// gedm_tensor(Hartree) to gedm(Ry)
202202
for (int inl = 0; inl < inlmax; ++inl)
203203
{
204-
int nm = 2 * inl_l[inl] + 1;
204+
int nm = 2 * inl2l[inl] + 1;
205205
auto accessor = gedm_tensor[inl].accessor<double, 2>();
206206
for (int m1 = 0; m1 < nm; ++m1)
207207
{
@@ -216,13 +216,13 @@ void DeePKS_domain::cal_edelta_gedm(const int nat,
216216
return;
217217
}
218218

219-
void DeePKS_domain::check_gedm(const int inlmax, const int* inl_l, double** gedm)
219+
void DeePKS_domain::check_gedm(const int inlmax, const std::vector<int>& inl2l, double** gedm)
220220
{
221221
std::ofstream ofs("gedm.dat");
222222

223223
for (int inl = 0; inl < inlmax; inl++)
224224
{
225-
int nm = 2 * inl_l[inl] + 1;
225+
int nm = 2 * inl2l[inl] + 1;
226226
for (int m1 = 0; m1 < nm; ++m1)
227227
{
228228
for (int m2 = 0; m2 < nm; ++m2)

source/module_hamilt_lcao/module_deepks/deepks_basic.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,27 +30,27 @@ void load_model(const std::string& model_file, torch::jit::script::Module& model
3030
// calculate gevdm
3131
void cal_gevdm(const int nat,
3232
const int inlmax,
33-
const int* inl_l,
33+
const std::vector<int>& inl2l,
3434
const std::vector<torch::Tensor>& pdm,
3535
std::vector<torch::Tensor>& gevdm);
3636

3737
/// calculate partial of energy correction to descriptors
3838
void cal_edelta_gedm(const int nat,
3939
const int inlmax,
4040
const int des_per_atom,
41-
const int* inl_l,
41+
const std::vector<int>& inl2l,
4242
const std::vector<torch::Tensor>& descriptor,
4343
const std::vector<torch::Tensor>& pdm,
4444
torch::jit::script::Module& model_deepks,
4545
double** gedm,
4646
double& E_delta);
47-
void check_gedm(const int inlmax, const int* inl_l, double** gedm);
47+
void check_gedm(const int inlmax, const std::vector<int>& inl2l, double** gedm);
4848
void cal_edelta_gedm_equiv(const int nat,
4949
const int lmaxd,
5050
const int nmaxd,
5151
const int inlmax,
5252
const int des_per_atom,
53-
const int* inl_l,
53+
const std::vector<int>& inl2l,
5454
const std::vector<torch::Tensor>& descriptor,
5555
double** gedm,
5656
double& E_delta,

source/module_hamilt_lcao/module_deepks/deepks_descriptor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void DeePKS_domain::cal_descriptor_equiv(const int nat,
3737
// calculates descriptors from projected density matrices
3838
void DeePKS_domain::cal_descriptor(const int nat,
3939
const int inlmax,
40-
const int* inl_l,
40+
const std::vector<int>& inl2l,
4141
const std::vector<torch::Tensor>& pdm,
4242
std::vector<torch::Tensor>& descriptor,
4343
const int des_per_atom = -1)
@@ -53,7 +53,7 @@ void DeePKS_domain::cal_descriptor(const int nat,
5353

5454
for (int inl = 0; inl < inlmax; ++inl)
5555
{
56-
const int nm = 2 * inl_l[inl] + 1;
56+
const int nm = 2 * inl2l[inl] + 1;
5757
pdm[inl].requires_grad_(true);
5858
descriptor.push_back(torch::ones({nm}, torch::requires_grad(true)));
5959
}
@@ -74,7 +74,7 @@ void DeePKS_domain::cal_descriptor(const int nat,
7474

7575
void DeePKS_domain::check_descriptor(const int inlmax,
7676
const int des_per_atom,
77-
const int* inl_l,
77+
const std::vector<int>& inl2l,
7878
const UnitCell& ucell,
7979
const std::string& out_dir,
8080
const std::vector<torch::Tensor>& descriptor,
@@ -104,7 +104,7 @@ void DeePKS_domain::check_descriptor(const int inlmax,
104104
int id = 0;
105105
for (int inl = 0; inl < inlmax / ucell.nat; inl++)
106106
{
107-
int nm = 2 * inl_l[inl] + 1;
107+
int nm = 2 * inl2l[inl] + 1;
108108
const int ind = iat * inlmax / ucell.nat + inl;
109109
auto accessor = descriptor[ind].accessor<double, 1>();
110110
for (int im = 0; im < nm; im++)

0 commit comments

Comments
 (0)