Skip to content

Commit 13431e5

Browse files
committed
Merge branch 'develop' of https://github.com/mohanchen/abacus-mc into develop
2 parents dc9f852 + 5f97360 commit 13431e5

File tree

15 files changed

+48
-121
lines changed

15 files changed

+48
-121
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
- [lcao\_dr](#lcao_dr)
5353
- [lcao\_rmax](#lcao_rmax)
5454
- [search\_radius](#search_radius)
55-
- [search\_pbc](#search_pbc)
5655
- [bx, by, bz](#bx-by-bz)
5756
- [elpa\_num\_thread](#elpa_num_thread)
5857
- [num\_stream](#num_stream)
@@ -924,12 +923,6 @@ These variables are used to control the numerical atomic orbitals related parame
924923
- **Default**: -1
925924
- **Unit**: Bohr
926925

927-
### search_pbc
928-
929-
- **Type**: Boolean
930-
- **Description**: If True, periodic images will be included in searching for the neighbouring atoms. If False, periodic images will be ignored.
931-
- **Default**: True
932-
933926
### bx, by, bz
934927

935928
- **Type**: Integer
@@ -3586,19 +3579,23 @@ These variables are used to control berry phase and wannier90 interface paramete
35863579
- **Type**: Real
35873580
- **Description**:
35883581
`td_lcut1` is the lower bound of the interval in the length gauge RT-TDDFT, where $x$ is the fractional coordinate:
3582+
35893583
$$
35903584
E(x)=\begin{cases}E_0, & \mathtt{cut1}\leqslant x \leqslant \mathtt{cut2} \\-E_0\left(\dfrac{1}{\mathtt{cut1}+1-\mathtt{cut2}}-1\right), & 0 < x < \mathtt{cut1~~or~~cut2} < x < 1 \end{cases}
35913585
$$
3586+
35923587
- **Default**: 0.05
35933588

35943589
### td_lcut2
35953590

35963591
- **Type**: Real
35973592
- **Description**:
35983593
`td_lcut2` is the upper bound of the interval in the length gauge RT-TDDFT, where $x$ is the fractional coordinate:
3594+
35993595
$$
36003596
E(x)=\begin{cases}E_0, & \mathtt{cut1}\leqslant x \leqslant \mathtt{cut2} \\-E_0\left(\dfrac{1}{\mathtt{cut1}+1-\mathtt{cut2}}-1\right), & 0 < x < \mathtt{cut1~~or~~cut2} < x < 1 \end{cases}
36013597
$$
3598+
36023599
- **Default**: 0.95
36033600

36043601
### td_gauss_freq

source/module_esolver/esolver_gets.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
9090

9191
Grid_Driver gd;
9292

93-
atom_arrange::search(PARAM.inp.search_pbc,
93+
atom_arrange::search(PARAM.globalv.search_pbc,
9494
GlobalV::ofs_running,
9595
gd,
9696
ucell,
@@ -133,7 +133,7 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
133133
if (PARAM.inp.out_mat_r)
134134
{
135135
cal_r_overlap_R r_matrix;
136-
r_matrix.init(ucell,pv, orb_);
136+
r_matrix.init(ucell, pv, orb_);
137137
r_matrix.out_rR(ucell, gd, istep);
138138
}
139139

@@ -142,20 +142,23 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
142142
LCAO_HS_Arrays HS_Arrays; // store sparse arrays
143143
//! Print out sparse matrix
144144
ModuleIO::output_dSR(istep,
145-
ucell,
146-
this->pv,
147-
HS_Arrays,
148-
gd, // mohan add 2024-04-06
149-
two_center_bundle_,
150-
orb_,
151-
kv);
145+
ucell,
146+
this->pv,
147+
HS_Arrays,
148+
gd, // mohan add 2024-04-06
149+
two_center_bundle_,
150+
orb_,
151+
kv);
152152
}
153153

154154
ModuleBase::timer::tick("ESolver_GetS", "runner");
155155
}
156156

157157
void ESolver_GetS::after_all_runners(UnitCell& ucell) {};
158-
double ESolver_GetS::cal_energy() { return 0.0; };
158+
double ESolver_GetS::cal_energy()
159+
{
160+
return 0.0;
161+
};
159162
void ESolver_GetS::cal_force(UnitCell& ucell, ModuleBase::matrix& force) {};
160163
void ESolver_GetS::cal_stress(UnitCell& ucell, ModuleBase::matrix& stress) {};
161164

source/module_esolver/esolver_lj.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void ESolver_LJ::before_all_runners(UnitCell& ucell, const Input_para& inp)
3333
void ESolver_LJ::runner(UnitCell& ucell, const int istep)
3434
{
3535
Grid_Driver grid_neigh(PARAM.inp.test_deconstructor, PARAM.inp.test_grid);
36-
atom_arrange::search(PARAM.inp.search_pbc,
36+
atom_arrange::search(PARAM.globalv.search_pbc,
3737
GlobalV::ofs_running,
3838
grid_neigh,
3939
ucell,

source/module_esolver/lcao_after_scf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
476476
/*test_deconstructor=*/PARAM.inp.test_deconstructor,
477477
/*test_grid=*/PARAM.inp.test_grid,
478478
/*test_atom_input=*/PARAM.inp.test_atom_input,
479-
/*search_pbc=*/PARAM.inp.search_pbc,
479+
/*search_pbc=*/PARAM.globalv.search_pbc,
480480
/*ofs=*/&GlobalV::ofs_running,
481481
/*rank=*/GlobalV::MY_RANK
482482
);

source/module_esolver/lcao_before_scf.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ void ESolver_KS_LCAO<TK, TR>::before_scf(UnitCell& ucell, const int istep)
5353
PARAM.globalv.gamma_only_local);
5454

5555
//! 3) use search_radius to search adj atoms
56-
atom_arrange::search(PARAM.inp.search_pbc,
56+
atom_arrange::search(PARAM.globalv.search_pbc,
5757
GlobalV::ofs_running,
5858
this->gd,
5959
ucell,

source/module_esolver/lcao_others.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
6767
// test_search_neighbor();
6868
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "testing neighbour");
6969
double search_radius = PARAM.inp.search_radius;
70-
atom_arrange::search(PARAM.inp.search_pbc,
70+
atom_arrange::search(PARAM.globalv.search_pbc,
7171
GlobalV::ofs_running,
7272
this->gd,
7373
ucell,
@@ -86,7 +86,7 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
8686
ucell.infoNL.get_rcutmax_Beta(),
8787
PARAM.globalv.gamma_only_local);
8888

89-
atom_arrange::search(PARAM.inp.search_pbc,
89+
atom_arrange::search(PARAM.globalv.search_pbc,
9090
GlobalV::ofs_running,
9191
this->gd,
9292
ucell,

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.cpp

Lines changed: 21 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,6 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driv
6868

6969
this->adjs_all.clear();
7070
this->adjs_all.reserve(this->ucell->nat);
71-
bool pre_cal_nlm = false;
72-
if (ucell->nat < 100) // less than 100 atom , cost memory for high performance
73-
{ // pre calculate nlm in initialization
74-
this->nlm_tot.resize(ucell->nat);
75-
pre_cal_nlm = true;
76-
}
77-
else
78-
{ // calculate nlm on the fly
79-
this->nlm_tot.resize(1);
80-
}
8171

8272
for (int iat0 = 0; iat0 < ucell->nat; iat0++)
8373
{
@@ -135,10 +125,6 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::initialize_HR(const Grid_Driv
135125
// }
136126
}
137127
}
138-
if (pre_cal_nlm)
139-
{
140-
this->pre_calculate_nlm(iat0, nlm_tot[iat0]);
141-
}
142128
}
143129
// allocate the memory of BaseMatrix in HR, and set the new values to zero
144130
// if (std::is_same<TK, double>::value)
@@ -234,70 +220,15 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
234220

235221
#ifdef __DEEPKS
236222

237-
template <typename TK, typename TR>
238-
void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::pre_calculate_nlm(
239-
const int iat0,
240-
std::vector<std::unordered_map<int, std::vector<double>>>& nlm_in)
241-
{
242-
const Parallel_Orbitals* paraV = this->hR->get_paraV();
243-
const int npol = this->ucell->get_npol();
244-
auto tau0 = ucell->get_tau(iat0);
245-
int T0 = 0;
246-
int I0 = 0;
247-
ucell->iat2iait(iat0, &I0, &T0);
248-
AdjacentAtomInfo& adjs = this->adjs_all[iat0];
249-
nlm_in.resize(adjs.adj_num + 1);
250-
251-
for (int ad = 0; ad < adjs.adj_num + 1; ++ad)
252-
{
253-
const int T1 = adjs.ntype[ad];
254-
const int I1 = adjs.natom[ad];
255-
const int iat1 = ucell->itia2iat(T1, I1);
256-
const ModuleBase::Vector3<double>& tau1 = adjs.adjacent_tau[ad];
257-
const Atom* atom1 = &ucell->atoms[T1];
258-
259-
auto all_indexes = paraV->get_indexes_row(iat1);
260-
auto col_indexes = paraV->get_indexes_col(iat1);
261-
// insert col_indexes into all_indexes to get universal set with no repeat elements
262-
all_indexes.insert(all_indexes.end(), col_indexes.begin(), col_indexes.end());
263-
std::sort(all_indexes.begin(), all_indexes.end());
264-
all_indexes.erase(std::unique(all_indexes.begin(), all_indexes.end()), all_indexes.end());
265-
for (int iw1l = 0; iw1l < all_indexes.size(); iw1l += npol)
266-
{
267-
const int iw1 = all_indexes[iw1l] / npol;
268-
std::vector<std::vector<double>> nlm;
269-
// nlm is a vector of vectors, but size of outer vector is only 1 here
270-
// If we are calculating force, we need also to store the gradient
271-
// and size of outer vector is then 4
272-
// inner loop : all projectors (L0,M0)
273-
274-
int L1 = atom1->iw2l[iw1];
275-
int N1 = atom1->iw2n[iw1];
276-
int m1 = atom1->iw2m[iw1];
277-
278-
// convert m (0,1,...2l) to M (-l, -l+1, ..., l-1, l)
279-
int M1 = (m1 % 2 == 0) ? -m1 / 2 : (m1 + 1) / 2;
280-
281-
ModuleBase::Vector3<double> dtau = tau0 - tau1;
282-
intor_orb_alpha_->snap(T1, L1, N1, M1, 0, dtau * ucell->lat0, false /*calc_deri*/, nlm);
283-
nlm_in[ad].insert({all_indexes[iw1l], nlm[0]});
284-
if (npol == 2)
285-
{
286-
nlm_in[ad].insert({all_indexes[iw1l + 1], nlm[0]});
287-
}
288-
}
289-
}
290-
}
291-
292223
template <typename TK, typename TR>
293224
void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
294225
{
295226
ModuleBase::TITLE("DeePKS", "calculate_HR");
227+
ModuleBase::timer::tick("DeePKS", "calculate_HR");
296228
if (this->V_delta_R->size_atom_pairs() == 0)
297229
{
298230
return;
299231
}
300-
ModuleBase::timer::tick("DeePKS", "calculate_HR");
301232

302233
const Parallel_Orbitals* paraV = this->V_delta_R->get_paraV();
303234
const int npol = this->ucell->get_npol();
@@ -361,18 +292,6 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
361292
const int trace_alpha_size = trace_alpha_row.size();
362293
//--------------------------------------------------
363294

364-
// if nlm_tot is not calculated already, calculate it on the fly now
365-
std::vector<std::unordered_map<int, std::vector<double>>> nlm_on_the_fly;
366-
const bool is_on_the_fly = (nlm_tot.size() != this->ucell->nat);
367-
368-
if (is_on_the_fly)
369-
{
370-
this->pre_calculate_nlm(iat0, nlm_on_the_fly);
371-
}
372-
373-
std::vector<std::unordered_map<int, std::vector<double>>>& nlm_iat
374-
= is_on_the_fly ? nlm_on_the_fly : nlm_tot[iat0];
375-
376295
// 2. calculate <phi_I|beta>D<beta|phi_{J,R}> for each pair of <IJR> atoms
377296
for (int ad1 = 0; ad1 < adjs.adj_num + 1; ++ad1)
378297
{
@@ -386,11 +305,17 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
386305
{
387306
continue;
388307
}
308+
ModuleBase::Vector3<int> dR1(adjs.box[ad1].x, adjs.box[ad1].y, adjs.box[ad1].z);
309+
if (this->ld->phialpha[0]->find_matrix(iat0, iat1, dR1.x, dR1.y, dR1.z) == nullptr)
310+
{
311+
continue;
312+
}
389313

390314
std::vector<double> s_1t(trace_alpha_size * row_size);
391315
for (int irow = 0; irow < row_size; irow++)
392316
{
393-
const double* row_ptr = nlm_iat[ad1][row_indexes[irow]].data();
317+
const hamilt::BaseMatrix<double>* overlap_1 = this->ld->phialpha[0]->find_matrix(iat0, iat1, dR1);
318+
const double* row_ptr = overlap_1->get_pointer() + row_indexes[irow] * overlap_1->get_col_size();
394319
double* ps1t = &s_1t[irow * trace_alpha_size];
395320
for (int i = 0; i < trace_alpha_size; i++)
396321
{
@@ -415,11 +340,23 @@ void hamilt::DeePKS<hamilt::OperatorLCAO<TK, TR>>::calculate_HR()
415340
}
416341
auto col_indexes = paraV->get_indexes_col(iat2);
417342
const int col_size = col_indexes.size();
343+
344+
if (col_size == 0)
345+
{
346+
continue;
347+
}
348+
ModuleBase::Vector3<int> dR2(adjs.box[ad2].x, adjs.box[ad2].y, adjs.box[ad2].z);
349+
if (this->ld->phialpha[0]->find_matrix(iat0, iat2, dR2.x, dR2.y, dR2.z) == nullptr)
350+
{
351+
continue;
352+
}
353+
418354
std::vector<double> hr_current(row_size * col_size, 0);
419355
std::vector<double> s_2t(trace_alpha_size * col_size);
420356
for (int icol = 0; icol < col_size; icol++)
421357
{
422-
const double* col_ptr = nlm_iat[ad2][col_indexes[icol]].data();
358+
const hamilt::BaseMatrix<double>* overlap_2 = this->ld->phialpha[0]->find_matrix(iat0, iat2, dR2);
359+
const double* col_ptr = overlap_2->get_pointer() + col_indexes[icol] * overlap_2->get_col_size();
423360
double* ps2t = &s_2t[icol * trace_alpha_size];
424361
for (int i = 0; i < trace_alpha_size; i++)
425362
{

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/deepks_lcao.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,6 @@ class DeePKS<OperatorLCAO<TK, TR>> : public OperatorLCAO<TK, TR>
101101
*/
102102
void cal_HR_IJR(const double* hr_in, const int& row_size, const int& col_size, TR* data_pointer);
103103

104-
void pre_calculate_nlm(const int iat0, std::vector<std::unordered_map<int, std::vector<double>>>& nlm_in);
105-
std::vector<std::vector<std::unordered_map<int, std::vector<double>>>> nlm_tot;
106104
/**
107105
* @brief initialize V_delta_R, search the nearest neighbor atoms
108106
* used for calculate the DeePKS real space Hamiltonian correction with specific <I,J,R> atom-pairs

source/module_hamilt_lcao/module_deepks/test/LCAO_deepks_test_prep.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void test_deepks<T>::prep_neighbour()
171171
ucell.infoNL.get_rcutmax_Beta(),
172172
PARAM.sys.gamma_only_local);
173173

174-
atom_arrange::search(PARAM.inp.search_pbc,
174+
atom_arrange::search(PARAM.globalv.search_pbc,
175175
GlobalV::ofs_running,
176176
Test_Deepks::GridD,
177177
ucell,

source/module_io/read_input_item_elec_stru.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -712,12 +712,6 @@ void ReadInput::item_elec_stru()
712712
read_sync_double(input.search_radius);
713713
this->add_item(item);
714714
}
715-
{
716-
Input_Item item("search_pbc");
717-
item.annotation = "input periodic boundary condition";
718-
read_sync_bool(input.search_pbc);
719-
this->add_item(item);
720-
}
721715
{
722716
Input_Item item("bx");
723717
item.annotation = "division of an element grid in FFT grid along x";

0 commit comments

Comments
 (0)