Skip to content

Commit

Permalink
Update operator_lcao.h (#5584)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanchen authored Nov 25, 2024
1 parent 1fb3347 commit 0f37fe5
Showing 1 changed file with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,19 @@ namespace hamilt {
template <typename TK, typename TR>
class OperatorLCAO : public Operator<TK> {
public:

OperatorLCAO(
HS_Matrix_K<TK>* hsk_in,
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in,
HContainer<TR>* hR_in)
const std::vector<ModuleBase::Vector3<double>>& kvec_d_in, //! k-point vectors
HContainer<TR>* hR_in) //! H(R) matrix, R is the Bravis lattice vector
: hsk(hsk_in), kvec_d(kvec_d_in), hR(hR_in){}

virtual ~OperatorLCAO()
{
if (this->allocated_smatrix) {
if (this->allocated_smatrix)
{
delete[] this->smatrix_k;
}
}
}

/* Function init(k) is used for update HR and HK ,
Expand All @@ -47,7 +50,8 @@ class OperatorLCAO : public Operator<TK> {
Gamma_only case (TK = double), SK would not changed during one SCF loop, a template triangle matrix SK_temp is used
for accelerating. General case (TK = std::complex<double>), only pointers of HK and SK saved in OperatorLCAO
*/
void matrixHk(MatrixBlock<TK>& hk_in, MatrixBlock<TK>& sk_in) {
void matrixHk(MatrixBlock<TK>& hk_in, MatrixBlock<TK>& sk_in)
{
this->get_hs_pointers();
#ifdef __MPI
hk_in = MatrixBlock<TK>{hmatrix_k,
Expand All @@ -59,8 +63,15 @@ class OperatorLCAO : public Operator<TK> {
(size_t)this->hsk->get_pv()->ncol,
this->hsk->get_pv()->desc};
#else
hk_in = MatrixBlock<TK>{hmatrix_k, (size_t)this->hsk->get_pv()->nrow, (size_t)this->hsk->get_pv()->ncol, nullptr};
sk_in = MatrixBlock<TK>{smatrix_k, (size_t)this->hsk->get_pv()->nrow, (size_t)this->hsk->get_pv()->ncol, nullptr};
hk_in = MatrixBlock<TK>{hmatrix_k,
(size_t)this->hsk->get_pv()->nrow,
(size_t)this->hsk->get_pv()->ncol,
nullptr};

sk_in = MatrixBlock<TK>{smatrix_k,
(size_t)this->hsk->get_pv()->nrow,
(size_t)this->hsk->get_pv()->ncol,
nullptr};
#endif
}

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

/**
* @brief reset hr_done status
* @brief reset the status of 'hr_done' (if H(R) is calculated)
*/
void set_hr_done(bool hr_done_in);

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

// protected:
// Hamiltonian matrix which are calculated in OperatorLCAO
// Hamiltonian matrices which are calculated in OperatorLCAO
HS_Matrix_K<TK>* hsk = nullptr;
const std::vector<ModuleBase::Vector3<double>>& kvec_d;

protected:
bool new_e_iteration = true;

// Real space Hamiltonian pointer
//! Real-space Hamiltonian pointer
hamilt::HContainer<TR>* hR = nullptr;

// current spin index
//! current spin index
int current_spin = 0;

// if HR is calculated
//! if H(R) is calculated
bool hr_done = false;

private:

void get_hs_pointers();

// there are H and S matrix for each k point in reciprocal space
// type double for gamma_only case, type complex<double> for multi-k-points
// case
//! there are H and S matrix for each k point in reciprocal space
//! 'double' type for gamma_only case,
//! 'complex<double>' type for multi k-points case
TK* hmatrix_k = nullptr;
TK* smatrix_k = nullptr;

// only used for Gamma_only case
//! only used for Gamma_only case
bool allocated_smatrix = false;
};

Expand Down

0 comments on commit 0f37fe5

Please sign in to comment.