Skip to content

Commit 4c63669

Browse files
authored
Merge branch 'develop' into fft_float2
2 parents 1f66367 + fcadc37 commit 4c63669

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+662
-904
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
- [out\_mat\_hs2](#out_mat_hs2)
154154
- [out\_mat\_t](#out_mat_t)
155155
- [out\_mat\_dh](#out_mat_dh)
156+
- [out\_mat\_ds](#out_mat_ds)
156157
- [out\_mat\_xc](#out_mat_xc)
157158
- [out\_mat\_xc2](#out_mat_xc2)
158159
- [out\_mat\_l](#out_mat_l)
@@ -1801,6 +1802,13 @@ These variables are used to control the output of properties.
18011802
- **Description**: Whether to print files containing the derivatives of the Hamiltonian matrix (in Ry/Bohr). The format will be the same as the Hamiltonian matrix $H(R)$ and overlap matrix $S(R)$ as mentioned in [out_mat_hs2](#out_mat_hs2). The name of the files will be `data-dHRx-sparse_SPIN0.csr` and so on. Also controled by [out_interval](#out_interval) and [out_app_flag](#out_app_flag).
18021803
- **Default**: False
18031804

1805+
### out_mat_ds
1806+
1807+
- **Type**: Boolean
1808+
- **Availability**: Numerical atomic orbital basis (not gamma-only algorithm)
1809+
- **Description**: Whether to print files containing the derivatives of the Overlap matrix (in Ry/Bohr). The format will be the same as the Overlap matrix $dH(R)$ as mentioned in [out_mat_dh](#out_mat_dh). The name of the files will be `data-dSRx-sparse_SPIN0.csr` and so on. Also controled by [out_interval](#out_interval) and [out_app_flag](#out_app_flag). This feature can be used with `calculation get_S`.
1810+
- **Default**: False
1811+
18041812
### out_mat_xc
18051813

18061814
- **Type**: Boolean

source/module_cell/klist.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,12 +1413,6 @@ void K_Vectors::set_after_vc(const int& nspin_in,
14131413
ModuleBase::Matrix3 RT = latvec.Transpose();
14141414
for (int i = 0; i < nks; i++)
14151415
{
1416-
// std::cout << " ik=" << i
1417-
// << " kvec.x=" << kvec_c[i].x
1418-
// << " kvec.y=" << kvec_c[i].y
1419-
// << " kvec.z=" << kvec_c[i].z << std::endl;
1420-
// wrong! kvec_d[i] = RT * kvec_c[i];
1421-
// mohan fixed bug 2011-03-07
14221416
kvec_d[i] = kvec_c[i] * RT;
14231417
}
14241418
kd_done = true;

source/module_esolver/esolver_gets.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
137137
r_matrix.out_rR(ucell, gd, istep);
138138
}
139139

140+
if (PARAM.inp.out_mat_ds)
141+
{
142+
LCAO_HS_Arrays HS_Arrays; // store sparse arrays
143+
//! Print out sparse matrix
144+
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);
152+
}
153+
140154
ModuleBase::timer::tick("ESolver_GetS", "runner");
141155
}
142156

source/module_esolver/lcao_after_scf.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
305305
//! Print out sparse matrix
306306
ModuleIO::output_mat_sparse(PARAM.inp.out_mat_hs2,
307307
PARAM.inp.out_mat_dh,
308+
PARAM.inp.out_mat_ds,
308309
PARAM.inp.out_mat_t,
309310
PARAM.inp.out_mat_r,
310311
istep,

source/module_esolver/lcao_others.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,10 +345,10 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
345345
else if (cal_type == "get_wf")
346346
{
347347
std::cout << FmtCore::format("\n * * * * * *\n << Start %s.\n", "getting wave function");
348-
IState_Envelope wavefunc(this->pelec);
348+
Get_wf_lcao get_wf(this->pelec);
349349
if (PARAM.globalv.gamma_only_local)
350350
{
351-
wavefunc.begin(ucell,
351+
get_wf.begin(ucell,
352352
this->psi,
353353
this->pw_rhod,
354354
this->pw_wfc,
@@ -370,7 +370,7 @@ void ESolver_KS_LCAO<TK, TR>::others(UnitCell& ucell, const int istep)
370370
}
371371
else
372372
{
373-
wavefunc.begin(ucell,
373+
get_wf.begin(ucell,
374374
this->psi,
375375
this->pw_rhod,
376376
this->pw_wfc,

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/hamilt_lcaodft/spar_dh.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,52 @@
44
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h"
55
#include <vector>
66

7+
void sparse_format::cal_dS(const UnitCell& ucell,
8+
const Parallel_Orbitals& pv,
9+
LCAO_HS_Arrays& HS_Arrays,
10+
const Grid_Driver& grid,
11+
const TwoCenterBundle& two_center_bundle,
12+
const LCAO_Orbitals& orb,
13+
const double& sparse_thr)
14+
{
15+
ModuleBase::TITLE("sparse_format", "cal_dS");
16+
17+
sparse_format::set_R_range(HS_Arrays.all_R_coor, grid);
18+
const int nnr = pv.nnr;
19+
20+
ForceStressArrays fsr_dh;
21+
fsr_dh.DHloc_fixedR_x = new double[nnr];
22+
fsr_dh.DHloc_fixedR_y = new double[nnr];
23+
fsr_dh.DHloc_fixedR_z = new double[nnr];
24+
ModuleBase::GlobalFunc::ZEROS(fsr_dh.DHloc_fixedR_x, nnr);
25+
ModuleBase::GlobalFunc::ZEROS(fsr_dh.DHloc_fixedR_y, nnr);
26+
ModuleBase::GlobalFunc::ZEROS(fsr_dh.DHloc_fixedR_z, nnr);
27+
// the pointers of dS is different from dH, use the dh pointers to reuse the print functions
28+
fsr_dh.DSloc_Rx = fsr_dh.DHloc_fixedR_x;
29+
fsr_dh.DSloc_Ry = fsr_dh.DHloc_fixedR_y;
30+
fsr_dh.DSloc_Rz = fsr_dh.DHloc_fixedR_z;
31+
// cal dS=<phi|dphi> in LCAO
32+
const bool cal_deri = true;
33+
const bool cal_stress = false;
34+
LCAO_domain::build_ST_new(fsr_dh,
35+
'S',
36+
cal_deri,
37+
cal_stress,
38+
ucell,
39+
orb,
40+
pv,
41+
two_center_bundle,
42+
&grid,
43+
nullptr,
44+
false); // delete unused parameter lm.Hloc_fixedR
45+
46+
sparse_format::cal_dSTN_R(ucell,pv, HS_Arrays, fsr_dh, grid, orb.cutoffs(), 0, sparse_thr);
47+
delete[] fsr_dh.DHloc_fixedR_x;
48+
delete[] fsr_dh.DHloc_fixedR_y;
49+
delete[] fsr_dh.DHloc_fixedR_z;
50+
return;
51+
}
52+
753
void sparse_format::cal_dH(const UnitCell& ucell,
854
const Parallel_Orbitals& pv,
955
LCAO_HS_Arrays& HS_Arrays,

source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ void cal_dH(const UnitCell& ucell,
2121
const double& sparse_thr,
2222
Gint_k& gint_k);
2323

24+
// calculated the derivative of the overlap matrix: <phi|dphi>
25+
void cal_dS(const UnitCell& ucell,
26+
const Parallel_Orbitals& pv,
27+
LCAO_HS_Arrays& HS_Arrays,
28+
const Grid_Driver& grid,
29+
const TwoCenterBundle& two_center_bundle,
30+
const LCAO_Orbitals& orb,
31+
const double& sparse_thr);
32+
2433
// be called by 'cal_dH_sparse'
2534
void set_R_range(std::set<Abfs::Vector3_Order<int>>& all_R_coor, const Grid_Driver& grid);
2635

source/module_hamilt_lcao/module_deepks/LCAO_deepks_interface.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ void LCAO_Deepks_Interface<TK, TR>::out_deepks_labels(const double& etot,
6464
{
6565
// this part is for integrated test of deepks
6666
// so it is printed no matter even if deepks_out_labels is not used
67+
DeePKS_domain::update_dmr(kvec_d, dm->get_DMK_vector(), ucell, orb, *ParaV, GridD, dmr);
68+
6769
DeePKS_domain::cal_pdm<
6870
TK>(init_pdm, inlmax, lmaxd, inl2l, inl_index, kvec_d, dmr, phialpha, ucell, orb, GridD, *ParaV, pdm);
6971

0 commit comments

Comments
 (0)