Skip to content

Commit d9eac9e

Browse files
committed
Merge branch 'lishui' into develop
2 parents 821a947 + 5fccb05 commit d9eac9e

File tree

13 files changed

+369
-274
lines changed

13 files changed

+369
-274
lines changed

source/module_hamilt_general/operator.cpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ Operator<T, Device>::~Operator()
1616
{
1717
delete this->hpsi;
1818
}
19+
1920
Operator* last = this->next_op;
2021
Operator* last_sub = this->next_sub_op;
22+
2123
while (last != nullptr || last_sub != nullptr)
2224
{
2325
if (last_sub != nullptr)
@@ -58,7 +60,6 @@ typename Operator<T, Device>::hpsi_info Operator<T, Device>::hPsi(hpsi_info& inp
5860
T* hpsi_pointer = std::get<2>(input);
5961
if (this->in_place)
6062
{
61-
// ModuleBase::GlobalFunc::COPYARRAY(this->hpsi->get_pointer(), hpsi_pointer, this->hpsi->size());
6263
syncmem_op()(hpsi_pointer, this->hpsi->get_pointer(), this->hpsi->size());
6364
delete this->hpsi;
6465
this->hpsi = new psi::Psi<T, Device>(hpsi_pointer,
@@ -78,31 +79,35 @@ typename Operator<T, Device>::hpsi_info Operator<T, Device>::hPsi(hpsi_info& inp
7879
psi_input->get_nbasis(),
7980
true);
8081

81-
switch (op->get_act_type())
82-
{
83-
case 2:
84-
op->act(psi_wrapper, *this->hpsi, nbands);
85-
break;
86-
default:
87-
op->act(nbands,
88-
psi_input->get_nbasis(),
89-
psi_input->get_npol(),
90-
tmpsi_in,
91-
this->hpsi->get_pointer(),
92-
psi_input->get_current_nbas(),
93-
is_first_node);
94-
break;
95-
}
82+
switch (op->get_act_type())
83+
{
84+
case 2:
85+
op->act(psi_wrapper, *this->hpsi, nbands);
86+
break;
87+
default:
88+
op->act(nbands,
89+
psi_input->get_nbasis(),
90+
psi_input->get_npol(),
91+
tmpsi_in,
92+
this->hpsi->get_pointer(),
93+
psi_input->get_current_nbas(),
94+
is_first_node);
95+
break;
96+
}
9697
};
9798

9899
ModuleBase::timer::tick("Operator", "hPsi");
100+
99101
call_act(this, true); // first node
102+
100103
Operator* node((Operator*)this->next_op);
104+
101105
while (node != nullptr)
102106
{
103107
call_act(node, false); // other nodes
104108
node = (Operator*)(node->next_op);
105109
}
110+
106111
ModuleBase::timer::tick("Operator", "hPsi");
107112

108113
return hpsi_info(this->hpsi, psi::Range(1, 0, 0, nbands / psi_input->get_npol()), hpsi_pointer);
@@ -157,6 +162,7 @@ void Operator<T, Device>::add(Operator* next)
157162
}
158163
}
159164

165+
160166
template <typename T, typename Device>
161167
T* Operator<T, Device>::get_hpsi(const hpsi_info& info) const
162168
{

source/module_hamilt_general/operator.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ class Operator
7373

7474
/// developer-friendly interfaces for act() function
7575
/// interface type 2: input and change the Psi-type HPsi
76-
// virtual void act(const psi::Psi<T, Device>& psi_in, psi::Psi<T, Device>& psi_out) const {};
77-
virtual void act(const psi::Psi<T, Device>& psi_in, psi::Psi<T, Device>& psi_out, const int nbands) const {};
76+
// virtual void act(const psi::Psi<T, Device>& psi_in, psi::Psi<T, Device>& psi_out) const {};
77+
virtual void act(const psi::Psi<T, Device>& psi_in,
78+
psi::Psi<T, Device>& psi_out,
79+
const int nbands) const {};
7880

7981
/// interface type 3: return a Psi-type HPsi
8082
// virtual psi::Psi<T> act(const psi::Psi<T,Device>& psi_in) const { return psi_in; };
@@ -125,4 +127,4 @@ class Operator
125127

126128
} // end namespace hamilt
127129

128-
#endif
130+
#endif

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp

Lines changed: 50 additions & 41 deletions
Large diffs are not rendered by default.

source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_HAMILT_LCAODFT_HAMILT_LCAO_H
2-
#define W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_HAMILT_LCAODFT_HAMILT_LCAO_H
1+
#ifndef HAMILT_LCAO_H
2+
#define HAMILT_LCAO_H
33

44
#include "module_basis/module_nao/two_center_bundle.h"
55
#include "module_cell/klist.h"
@@ -25,24 +25,30 @@ namespace hamilt
2525
{
2626

2727
// template first for type of k space H matrix elements
28-
// template second for type of temporary matrix, gamma_only fix-gamma-matrix + S-gamma, multi-k fix-Real + S-Real
28+
// template second for type of temporary matrix,
29+
// gamma_only fix-gamma-matrix + S-gamma,
30+
// multi-k fix-Real + S-Real
2931
template <typename TK, typename TR>
3032
class HamiltLCAO : public Hamilt<TK>
3133
{
3234
public:
35+
36+
37+
using TAC = std::pair<int, std::array<int, 3>>;
38+
39+
3340
/**
3441
* @brief Constructor of Hamiltonian for LCAO base
3542
* HR and SR will be allocated with Operators
3643
*/
37-
using TAC = std::pair<int, std::array<int, 3>>;
3844
HamiltLCAO(Gint_Gamma* GG_in,
3945
Gint_k* GK_in,
4046
const UnitCell& ucell,
4147
const Grid_Driver& grid_d,
42-
const Parallel_Orbitals* paraV,
43-
elecstate::Potential* pot_in,
44-
const K_Vectors& kv_in,
45-
const TwoCenterBundle& two_center_bundle,
48+
const Parallel_Orbitals* paraV,
49+
elecstate::Potential* pot_in,
50+
const K_Vectors& kv,
51+
const TwoCenterBundle& two_center_bundle,
4652
const LCAO_Orbitals& orb,
4753
elecstate::DensityMatrix<TK, double>* DM_in
4854
#ifdef __DEEPKS
@@ -57,13 +63,14 @@ class HamiltLCAO : public Hamilt<TK>
5763
std::vector<std::map<int, std::map<TAC, RI::Tensor<std::complex<double>>>>>* Hexxc = nullptr
5864
#endif
5965
);
66+
6067
/**
6168
* @brief Constructor of vacuum Operators, only HR and SR will be initialed as empty HContainer
6269
*/
6370
HamiltLCAO(const UnitCell& ucell,
6471
const Grid_Driver& grid_d,
6572
const Parallel_Orbitals* paraV,
66-
const K_Vectors& kv_in,
73+
const K_Vectors& kv,
6774
const TwoCenterIntegrator& intor_overlap_orb,
6875
const std::vector<double>& orb_cutoff);
6976

@@ -80,82 +87,93 @@ class HamiltLCAO : public Hamilt<TK>
8087

8188
/// get pointer of Operator<TK> ops
8289
Operator<TK>*& getOperator();
83-
/// get hk-pointer
90+
91+
/// get H(k) pointer
8492
TK* getHk() const
8593
{
8694
return this->hsk->get_hk();
8795
}
88-
/// get sk-pointer
96+
97+
/// get S(k) pointer
8998
TK* getSk() const
9099
{
91100
return this->hsk->get_sk();
92101
}
102+
93103
int get_size_hsk() const
94104
{
95105
return this->hsk->get_size();
96106
}
107+
97108
/// get HR pointer of *this->hR, which is a HContainer<TR> and contains H(R)
98109
HContainer<TR>*& getHR()
99110
{
100111
return this->hR;
101112
}
113+
102114
/// get SR pointer of *this->sR, which is a HContainer<TR> and contains S(R)
103115
HContainer<TR>*& getSR()
104116
{
105117
return this->sR;
106118
}
119+
107120
#ifdef __DEEPKS
108121
/// get V_delta_R pointer of *this->V_delta_R, which is a HContainer<TR> and contains V_delta(R)
109122
HContainer<TR>*& get_V_delta_R()
110123
{
111124
return this->V_delta_R;
112125
}
113126
#endif
127+
114128
/// refresh the status of HR
115129
void refresh() override;
116130

117131
// for target K point, update consequence of hPsi() and matrix()
118-
virtual void updateHk(const int ik) override;
132+
void updateHk(const int ik, const int isk);
119133

120134
/**
121135
* @brief special for LCAO, update SK only
122136
*
123137
* @param ik target K point
138+
* @param kvec_d: direct coordinates of k-points
124139
* @param hk_type 0: SK is row-major, 1: SK is collumn-major
125140
* @return void
126141
*/
127-
void updateSk(const int ik, const int hk_type = 0);
142+
void updateSk(const int ik,
143+
const ModuleBase::Vector3<double>& kvec_d,
144+
const int hk_type = 0);
128145

129146
// core function: return H(k) and S(k) matrixs for direct solving eigenvalues.
130147
// not used in PW base
131-
// void matrix(MatrixBlock<std::complex<double>> &hk_in, MatrixBlock<std::complex<double>> &sk_in) override;
132148
void matrix(MatrixBlock<TK>& hk_in, MatrixBlock<TK>& sk_in) override;
133149

134150
private:
135-
const K_Vectors* kv = nullptr;
136151

137-
// Real space Hamiltonian
152+
//! Real space Hamiltonian H(R), where R is the Bravis lattice vector
138153
HContainer<TR>* hR = nullptr;
154+
155+
//! Real space overlap matrix S(R), where R is the Bravis lattice vector
139156
HContainer<TR>* sR = nullptr;
140157

141158
#ifdef __DEEPKS
142159
HContainer<TR>* V_delta_R = nullptr;
143160
#endif
144161

162+
//! Hamiltonian and overlap matrices for a specific k point
145163
HS_Matrix_K<TK>* hsk = nullptr;
164+
146165
// special case for NSPIN=2 , data of HR should be separated into two parts
147166
// save them in this->hRS2;
148167
std::vector<TR> hRS2;
168+
149169
int refresh_times = 1;
150170

151-
/// current_spin for NSPIN=2, 0: hamiltonian for spin up, 1: hamiltonian for spin down
171+
//! current_spin for NSPIN=2 case
172+
//! 0: Hamiltonian for spin up,
173+
//! 1: Hamiltonian for spin down
152174
int current_spin = 0;
153175

154176
const int istep = 0;
155-
156-
// sk and hk will be refactored to HamiltLCAO later
157-
// std::vector<TK> sk;
158-
// std::vector<TK> hk;
159177
};
160178

161179
} // namespace hamilt

source/module_hamilt_lcao/hamilt_lcaodft/hs_matrix_k.hpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef ABACUS_HS_MATRIX_K_HPP
2-
#define ABACUS_HS_MATRIX_K_HPP
1+
#ifndef HS_MATRIX_K_HPP
2+
#define HS_MATRIX_K_HPP
33

44
#include "module_basis/module_ao/parallel_orbitals.h"
55

@@ -9,6 +9,7 @@ namespace hamilt
99
template <typename TK>
1010
class HS_Matrix_K
1111
{
12+
1213
public:
1314
HS_Matrix_K(const Parallel_Orbitals* paraV, bool no_s=false){
1415
hk.resize(paraV->nloc);
@@ -18,17 +19,27 @@ namespace hamilt
1819
}
1920
this->pv = paraV;
2021
}
22+
2123
TK* get_hk() {return hk.data();}
24+
2225
TK* get_sk() {return sk.data();}
26+
2327
int get_size() {return hk.size();}
28+
2429
void set_zero_hk() {hk.assign(hk.size(), 0);}
30+
2531
void set_zero_sk() {sk.assign(sk.size(), 0);}
32+
2633
const Parallel_Orbitals* get_pv() const {return this->pv;}
34+
2735
private:
36+
2837
std::vector<TK> hk;
38+
2939
std::vector<TK> sk;
40+
3041
const Parallel_Orbitals* pv = nullptr;
3142
};
3243
}
3344

34-
#endif
45+
#endif

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ class OperatorLCAO : public Operator<TK> {
100100
// protected:
101101
// Hamiltonian matrices which are calculated in OperatorLCAO
102102
HS_Matrix_K<TK>* hsk = nullptr;
103+
104+
// kvec_d
103105
const std::vector<ModuleBase::Vector3<double>>& kvec_d;
104106

105107
protected:

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/td_ekinetic_lcao.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ TDEkinetic<OperatorLCAO<TK, TR>>::TDEkinetic(HS_Matrix_K<TK>* hsk_in,
3131
// initialize HR to get adjs info.
3232
this->initialize_HR(Grid);
3333
}
34+
3435
template <typename TK, typename TR>
3536
TDEkinetic<OperatorLCAO<TK, TR>>::~TDEkinetic()
3637
{
@@ -40,12 +41,14 @@ TDEkinetic<OperatorLCAO<TK, TR>>::~TDEkinetic()
4041
}
4142
TD_Velocity::td_vel_op = nullptr;
4243
}
44+
4345
// term A^2*S
4446
template <typename TK, typename TR>
4547
void TDEkinetic<OperatorLCAO<TK, TR>>::td_ekinetic_scalar(std::complex<double>* Hloc,const TR& overlap, int nnr)
4648
{
4749
return;
4850
}
51+
4952
// term A^2*S
5053
template <>
5154
void TDEkinetic<OperatorLCAO<std::complex<double>, double>>::td_ekinetic_scalar(std::complex<double>* Hloc,
@@ -57,6 +60,7 @@ void TDEkinetic<OperatorLCAO<std::complex<double>, double>>::td_ekinetic_scalar(
5760
Hloc[nnr] += tmp;
5861
return;
5962
}
63+
6064
// term A dot ∇
6165
template <typename TK, typename TR>
6266
void TDEkinetic<OperatorLCAO<TK, TR>>::td_ekinetic_grad(std::complex<double>* Hloc,
@@ -384,8 +388,11 @@ void TDEkinetic<OperatorLCAO<std::complex<double>, double>>::contributeHk(int ik
384388
const Parallel_Orbitals* paraV = this->hR_tmp->get_atom_pair(0).get_paraV();
385389
// save HR data for output
386390
int spin_tot = PARAM.inp.nspin;
391+
387392
if (spin_tot == 4)
388-
;
393+
{
394+
395+
}
389396
else if (!output_hR_done && TD_Velocity::out_mat_R)
390397
{
391398
for (int spin_now = 0; spin_now < spin_tot; spin_now++)
@@ -398,6 +405,7 @@ void TDEkinetic<OperatorLCAO<std::complex<double>, double>>::contributeHk(int ik
398405
}
399406
output_hR_done = true;
400407
}
408+
401409
// folding inside HR to HK
402410
if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.inp.ks_solver))
403411
{

0 commit comments

Comments
 (0)