Skip to content

Commit 9cda7a1

Browse files
authored
Merge branch 'develop' into fft6
2 parents 4e12e56 + 0f37fe5 commit 9cda7a1

File tree

4 files changed

+82
-51
lines changed

4 files changed

+82
-51
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -989,7 +989,7 @@ calculations.
989989

990990
- **Type**: String
991991
- **Description**: In our package, the XC functional can either be set explicitly using the `dft_functional` keyword in `INPUT` file. If `dft_functional` is not specified, ABACUS will use the xc functional indicated in the pseudopotential file.
992-
On the other hand, if dft_functional is specified, it will overwrite the functional from pseudopotentials and performs calculation with whichever functional the user prefers. We further offer two ways of supplying exchange-correlation functional. The first is using 'short-hand' names such as 'LDA', 'PBE', 'SCAN'. A complete list of 'short-hand' expressions can be found in [the source code](../../../source/module_hamilt_general/module_xc/xc_functional.cpp). The other way is only available when ***compiling with LIBXC***, and it allows for supplying exchange-correlation functionals as combinations of LIBXC keywords for functional components, joined by a plus sign, for example, 'dft_functional='LDA_X_1D_EXPONENTIAL+LDA_C_1D_CSC'. The list of LIBXC keywords can be found on its [website](https://www.tddft.org/programs/libxc/functionals/). In this way, **we support all the LDA,GGA and mGGA functionals provided by LIBXC**.
992+
On the other hand, if dft_functional is specified, it will overwrite the functional from pseudopotentials and performs calculation with whichever functional the user prefers. We further offer two ways of supplying exchange-correlation functional. The first is using 'short-hand' names such as 'LDA', 'PBE', 'SCAN'. A complete list of 'short-hand' expressions can be found in [the source code](../../../source/module_hamilt_general/module_xc/xc_functional.cpp). The other way is only available when ***compiling with LIBXC***, and it allows for supplying exchange-correlation functionals as combinations of LIBXC keywords for functional components, joined by a plus sign, for example, dft_functional='LDA_X_1D_EXPONENTIAL+LDA_C_1D_CSC'. The list of LIBXC keywords can be found on its [website](https://libxc.gitlab.io/functionals/). In this way, **we support all the LDA,GGA and mGGA functionals provided by LIBXC**.
993993

994994
Furthermore, the old INPUT parameter exx_hybrid_type for hybrid functionals has been absorbed into dft_functional. Options are `hf` (pure Hartree-Fock), `pbe0`(PBE0), `hse` (Note: in order to use HSE functional, LIBXC is required). Note also that HSE has been tested while PBE0 has NOT been fully tested yet, and the maximum CPU cores for running exx in parallel is $N(N+1)/2$, with N being the number of atoms. And forces for hybrid functionals are not supported yet.
995995

@@ -1760,14 +1760,14 @@ The band (KS orbital) energy for each (k-point, spin, band) will be printed in t
17601760

17611761
- **Type**: Boolean
17621762
- **Availability**: Numerical atomic orbital basis
1763-
- **Description**: Whether to print Hamiltonian matrices H(R)/density matrics DM(R) in npz format. This feature does not work for gamma-only calculations. Currently only intended for internal usage.
1763+
- **Description**: Whether to print Hamiltonian matrices $H(R)$/density matrics $DM(R)$ in npz format. This feature does not work for gamma-only calculations. Currently only intended for internal usage.
17641764
- **Default**: False
17651765

17661766
### dm_to_rho
17671767

17681768
- **Type**: Boolean
17691769
- **Availability**: Numerical atomic orbital basis
1770-
- **Description**: Reads density matrix DM(R) in npz format and creates electron density on grids. This feature does not work for gamma-only calculations. Only supports serial calculations. Currently only intended for internal usage.
1770+
- **Description**: Reads density matrix $DM(R)$ in npz format and creates electron density on grids. This feature does not work for gamma-only calculations. Only supports serial calculations. Currently only intended for internal usage.
17711771
- **Default**: False
17721772

17731773
### out_app_flag

source/module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.hpp

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
//=======================
2-
// AUTHOR : Peize Lin
31
#include "module_parameter/parameter.h"
4-
// DATE : 2022-09-13
5-
//=======================
62

73
#ifndef LCAO_HAMILT_HPP
84
#define LCAO_HAMILT_HPP
@@ -23,6 +19,7 @@
2319

2420
#ifdef __EXX
2521
// Peize Lin add 2022.09.13
22+
2623
template <typename Tdata>
2724
void sparse_format::cal_HR_exx(
2825
const Parallel_Orbitals& pv,
@@ -31,8 +28,8 @@ void sparse_format::cal_HR_exx(
3128
const double& sparse_threshold,
3229
const int (&nmp)[3],
3330
const std::vector<std::map<int,
34-
std::map<std::pair<int, std::array<int, 3>>,
35-
RI::Tensor<Tdata>>>>& Hexxs) {
31+
std::map<std::pair<int, std::array<int, 3>>,
32+
RI::Tensor<Tdata>>>>& Hexxs) {
3633
ModuleBase::TITLE("sparse_format", "cal_HR_exx");
3734
ModuleBase::timer::tick("sparse_format", "cal_HR_exx");
3835

@@ -45,7 +42,7 @@ void sparse_format::cal_HR_exx(
4542
.tau[GlobalC::ucell.iat2ia[iat]]);
4643
}
4744
const std::array<std::array<double, 3>, 3> latvec
48-
= {RI_Util::Vector3_to_array3(GlobalC::ucell.a1),
45+
= {RI_Util::Vector3_to_array3(GlobalC::ucell.a1), // too bad to use GlobalC here,
4946
RI_Util::Vector3_to_array3(GlobalC::ucell.a2),
5047
RI_Util::Vector3_to_array3(GlobalC::ucell.a3)};
5148

@@ -58,18 +55,22 @@ void sparse_format::cal_HR_exx(
5855
? std::vector<int>{current_spin}
5956
: std::vector<int>{0, 1, 2, 3};
6057

61-
for (const int is: is_list) {
58+
for (const int is: is_list)
59+
{
6260
int is0_b = 0;
6361
int is1_b = 0;
6462
std::tie(is0_b, is1_b) = RI_2D_Comm::split_is_block(is);
6563

66-
if (Hexxs.empty()) {
64+
if (Hexxs.empty())
65+
{
6766
break;
6867
}
6968

70-
for (const auto& HexxA: Hexxs[is]) {
69+
for (const auto& HexxA: Hexxs[is])
70+
{
7171
const int iat0 = HexxA.first;
72-
for (const auto& HexxB: HexxA.second) {
72+
for (const auto& HexxB: HexxA.second)
73+
{
7374
const int iat1 = HexxB.first.first;
7475

7576
const Abfs::Vector3_Order<int> R = RI_Util::array3_to_Vector3(
@@ -81,47 +82,60 @@ void sparse_format::cal_HR_exx(
8182

8283
const RI::Tensor<Tdata>& Hexx = HexxB.second;
8384

84-
for (size_t iw0 = 0; iw0 < Hexx.shape[0]; ++iw0) {
85+
for (size_t iw0 = 0; iw0 < Hexx.shape[0]; ++iw0)
86+
{
8587
const int iwt0 = RI_2D_Comm::get_iwt(iat0, iw0, is0_b);
8688
const int iwt0_local = pv.global2local_row(iwt0);
8789

88-
if (iwt0_local < 0) {
90+
if (iwt0_local < 0)
91+
{
8992
continue;
9093
}
9194

92-
for (size_t iw1 = 0; iw1 < Hexx.shape[1]; ++iw1) {
95+
for (size_t iw1 = 0; iw1 < Hexx.shape[1]; ++iw1)
96+
{
9397
const int iwt1 = RI_2D_Comm::get_iwt(iat1, iw1, is1_b);
9498
const int iwt1_local = pv.global2local_col(iwt1);
9599

96-
if (iwt1_local < 0) {
100+
if (iwt1_local < 0)
101+
{
97102
continue;
98103
}
99104

100-
if (std::abs(Hexx(iw0, iw1)) > sparse_threshold) {
101-
if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2) {
105+
if (std::abs(Hexx(iw0, iw1)) > sparse_threshold)
106+
{
107+
if (PARAM.inp.nspin == 1 || PARAM.inp.nspin == 2)
108+
{
102109
auto& HR_sparse_ptr
103110
= HS_Arrays
104111
.HR_sparse[current_spin][R][iwt0];
105112
double& HR_sparse = HR_sparse_ptr[iwt1];
106113
HR_sparse += RI::Global_Func::convert<double>(
107114
frac * Hexx(iw0, iw1));
108-
if (std::abs(HR_sparse) <= sparse_threshold) {
115+
if (std::abs(HR_sparse) <= sparse_threshold)
116+
{
109117
HR_sparse_ptr.erase(iwt1);
110118
}
111-
} else if (PARAM.inp.nspin == 4) {
119+
}
120+
else if (PARAM.inp.nspin == 4)
121+
{
112122
auto& HR_sparse_ptr
113123
= HS_Arrays.HR_soc_sparse[R][iwt0];
124+
114125
std::complex<double>& HR_sparse
115126
= HR_sparse_ptr[iwt1];
127+
116128
HR_sparse += RI::Global_Func::convert<
117-
std::complex<double>>(frac
118-
* Hexx(iw0, iw1));
119-
if (std::abs(HR_sparse) <= sparse_threshold) {
129+
std::complex<double>>(frac * Hexx(iw0, iw1));
130+
131+
if (std::abs(HR_sparse) <= sparse_threshold)
132+
{
120133
HR_sparse_ptr.erase(iwt1);
121134
}
122-
} else {
123-
throw std::invalid_argument(
124-
std::string(__FILE__) + " line "
135+
}
136+
else
137+
{
138+
throw std::invalid_argument(std::string(__FILE__) + " line "
125139
+ std::to_string(__LINE__));
126140
}
127141
}

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,19 @@ namespace hamilt {
1111
template <typename TK, typename TR>
1212
class OperatorLCAO : public Operator<TK> {
1313
public:
14+
1415
OperatorLCAO(
1516
HS_Matrix_K<TK>* hsk_in,
16-
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
17-
HContainer<TR>* hR_in)
17+
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in, //! k-point vectors
18+
HContainer<TR>* hR_in) //! H(R) matrix, R is the Bravis lattice vector
1819
: hsk(hsk_in), kvec_d(kvec_d_in), hR(hR_in){}
20+
1921
virtual ~OperatorLCAO()
2022
{
21-
if (this->allocated_smatrix) {
23+
if (this->allocated_smatrix)
24+
{
2225
delete[] this->smatrix_k;
23-
}
26+
}
2427
}
2528

2629
/* Function init(k) is used for update HR and HK ,
@@ -47,7 +50,8 @@ class OperatorLCAO : public Operator<TK> {
4750
Gamma_only case (TK = double), SK would not changed during one SCF loop, a template triangle matrix SK_temp is used
4851
for accelerating. General case (TK = std::complex<double>), only pointers of HK and SK saved in OperatorLCAO
4952
*/
50-
void matrixHk(MatrixBlock<TK>& hk_in, MatrixBlock<TK>& sk_in) {
53+
void matrixHk(MatrixBlock<TK>& hk_in, MatrixBlock<TK>& sk_in)
54+
{
5155
this->get_hs_pointers();
5256
#ifdef __MPI
5357
hk_in = MatrixBlock<TK>{hmatrix_k,
@@ -59,8 +63,15 @@ class OperatorLCAO : public Operator<TK> {
5963
(size_t)this->hsk->get_pv()->ncol,
6064
this->hsk->get_pv()->desc};
6165
#else
62-
hk_in = MatrixBlock<TK>{hmatrix_k, (size_t)this->hsk->get_pv()->nrow, (size_t)this->hsk->get_pv()->ncol, nullptr};
63-
sk_in = MatrixBlock<TK>{smatrix_k, (size_t)this->hsk->get_pv()->nrow, (size_t)this->hsk->get_pv()->ncol, nullptr};
66+
hk_in = MatrixBlock<TK>{hmatrix_k,
67+
(size_t)this->hsk->get_pv()->nrow,
68+
(size_t)this->hsk->get_pv()->ncol,
69+
nullptr};
70+
71+
sk_in = MatrixBlock<TK>{smatrix_k,
72+
(size_t)this->hsk->get_pv()->nrow,
73+
(size_t)this->hsk->get_pv()->ncol,
74+
nullptr};
6475
#endif
6576
}
6677

@@ -77,7 +88,7 @@ class OperatorLCAO : public Operator<TK> {
7788
virtual void set_HR_fixed(void*) { return; }
7889

7990
/**
80-
* @brief reset hr_done status
91+
* @brief reset the status of 'hr_done' (if H(R) is calculated)
8192
*/
8293
void set_hr_done(bool hr_done_in);
8394

@@ -87,32 +98,33 @@ class OperatorLCAO : public Operator<TK> {
8798
void set_current_spin(const int current_spin_in);
8899

89100
// protected:
90-
// Hamiltonian matrix which are calculated in OperatorLCAO
101+
// Hamiltonian matrices which are calculated in OperatorLCAO
91102
HS_Matrix_K<TK>* hsk = nullptr;
92103
const std::vector<ModuleBase::Vector3<double>>& kvec_d;
93104

94105
protected:
95106
bool new_e_iteration = true;
96107

97-
// Real space Hamiltonian pointer
108+
//! Real-space Hamiltonian pointer
98109
hamilt::HContainer<TR>* hR = nullptr;
99110

100-
// current spin index
111+
//! current spin index
101112
int current_spin = 0;
102113

103-
// if HR is calculated
114+
//! if H(R) is calculated
104115
bool hr_done = false;
105116

106117
private:
118+
107119
void get_hs_pointers();
108120

109-
// there are H and S matrix for each k point in reciprocal space
110-
// type double for gamma_only case, type complex<double> for multi-k-points
111-
// case
121+
//! there are H and S matrix for each k point in reciprocal space
122+
//! 'double' type for gamma_only case,
123+
//! 'complex<double>' type for multi k-points case
112124
TK* hmatrix_k = nullptr;
113125
TK* smatrix_k = nullptr;
114126

115-
// only used for Gamma_only case
127+
//! only used for Gamma_only case
116128
bool allocated_smatrix = false;
117129
};
118130

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/overlap_new.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ void hamilt::OverlapNew<hamilt::OperatorLCAO<TK, TR>>::initialize_SR(Grid_Driver
4141
for (int iat1 = 0; iat1 < ucell->nat; iat1++)
4242
{
4343
auto tau1 = ucell->get_tau(iat1);
44-
int T1, I1;
44+
int T1=0;
45+
int I1=0;
4546
ucell->iat2iait(iat1, &I1, &T1);
4647
AdjacentAtomInfo adjs;
4748
GridD->Find_atom(*ucell, tau1, T1, I1, &adjs);
@@ -84,8 +85,8 @@ void hamilt::OverlapNew<hamilt::OperatorLCAO<TK, TR>>::calculate_SR()
8485
for (int iap = 0; iap < this->SR->size_atom_pairs(); ++iap)
8586
{
8687
hamilt::AtomPair<TR>& tmp = this->SR->get_atom_pair(iap);
87-
int iat1 = tmp.get_atom_i();
88-
int iat2 = tmp.get_atom_j();
88+
const int iat1 = tmp.get_atom_i();
89+
const int iat2 = tmp.get_atom_j();
8990
const Parallel_Orbitals* paraV = tmp.get_paraV();
9091

9192
for (int iR = 0; iR < tmp.get_R_size(); ++iR)
@@ -116,9 +117,11 @@ void hamilt::OverlapNew<hamilt::OperatorLCAO<TK, TR>>::cal_SR_IJR(const int& iat
116117
// ---------------------------------------------
117118
// get info of orbitals of atom1 and atom2 from ucell
118119
// ---------------------------------------------
119-
int T1, I1;
120+
int T1=0;
121+
int I1=0;
120122
this->ucell->iat2iait(iat1, &I1, &T1);
121-
int T2, I2;
123+
int T2=0;
124+
int I2=0;
122125
this->ucell->iat2iait(iat2, &I2, &T2);
123126
Atom& atom1 = this->ucell->atoms[T1];
124127
Atom& atom2 = this->ucell->atoms[T2];
@@ -188,14 +191,15 @@ void hamilt::OverlapNew<hamilt::OperatorLCAO<TK, TR>>::contributeHR()
188191
template <typename TK, typename TR>
189192
void hamilt::OverlapNew<hamilt::OperatorLCAO<TK, TR>>::contributeHk(int ik)
190193
{
191-
// if k vector is not changed, then do nothing and return, only for gamma_only case
194+
//! if k vector is not changed, then do nothing and return, only for gamma_only case
192195
if (this->kvec_d[ik] == this->kvec_d_old && std::is_same<TK, double>::value)
193196
{
194197
return;
195198
}
196199
ModuleBase::TITLE("OverlapNew", "contributeHk");
197200
ModuleBase::timer::tick("OverlapNew", "contributeHk");
198-
// set SK to zero and then calculate SK for each k vector
201+
202+
//! set SK to zero and then calculate SK for each k vector
199203
this->hsk->set_zero_sk();
200204
if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver))
201205
{
@@ -207,6 +211,7 @@ void hamilt::OverlapNew<hamilt::OperatorLCAO<TK, TR>>::contributeHk(int ik)
207211
const int ncol = this->SR->get_atom_pair(0).get_paraV()->get_col_size();
208212
hamilt::folding_HR(*this->SR, this->hsk->get_sk(), this->kvec_d[ik], ncol, 0);
209213
}
214+
210215
// update kvec_d_old
211216
this->kvec_d_old = this->kvec_d[ik];
212217

0 commit comments

Comments
 (0)