Skip to content

Commit 7755248

Browse files
Merge: HSolver to develop, diagonalization for PW and LCAO has finished. (#848)
* refactor : add base class in module_hsolver, module_hamilt, module_psi, module_elecstate compiling for diagocg.cpp, hamiltpw.cpp, elecstatepw.cpp, psi.cpp is passed. * fix psi.h compiling error * refactor : add DiagoCG class in HSolver module, modified Psi, Hamilt, ElecState, Charge, PW_Basis classes * fix : delete useless variable Bec and fix compiling bug * Refactor: added diagodavid.cpp and iterdiagcon.cpp to module_hsolver * Fix: bug in psi.h * Refactor: move diagH_subspace and diagH_LAPACK to IterDiagControl, lcao_in_pw with exx is not supported yet * Refactor: finished diag() function in diagocg.cpp and diagodavid.cpp * Fix: bug in hsolverpw.cpp, psi not update for each k point * Fix: compiling error * Fix: compiler error for mutable pointer in const function * Refactor: temporary deleted interface init and update in HSolver * Refactor: changed use of NBANDS to psi.get_nbands() * Refactor: added HSolverLCAO class * Refactor: added example of template class with virtual function * Fix: matrix() in HamiltLCAO * Refactor: added fixed realspace matrix to HamiltLCAO * Fix: modified Psi class constructor for UT, some update for hamiltlcao * Fix: removed PW_Basis dependency in DiagoCG and DiagoDavid * Fix: template function only can be defined explicitly in cpp files, fixed psi.h * Fix: int* ngk in psi.h should be const type * UT of diagocg (not successful) * Fix: bug in diagodavid.h * Fix: bug in psi.h * Fix: template function in hamiltlcao.cpp should be modified * UT of cg in HSolver (successful but fragile) * add unit test of DAVIDSON diagonalization for HSolver * Refactor: T, NL, S matrix calculation for HamiltLCAO * fix the bug of getpsi() in diao_mock.h * Fix: allocate matrix with correct size in HamiltLCAO class * Fix: compiling error in HamiltLCAO class * Refactor: move diag_scalapack_gvx to module_hsolver/diagosca * Refactor: added DiagoElpa and HSolverLCAO to HSolver module * Fix: conflict with CUDA has fixed for merge into develop branch * Fix: add template<> for .cpp files * Fix: change namespace name for hsolver, hamilt, elecstate, psi * Fix: bug of psi and added template class specify in cpp * Refactor: modified name of files in new modules * Refactor: format the code Co-authored-by: root <hongriTianqi> Co-authored-by: xingliang <[email protected]> Co-authored-by: pxlxingliang <[email protected]>
1 parent b794b28 commit 7755248

Some content is hidden

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

57 files changed

+4254
-324
lines changed

source/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ add_subdirectory(module_base)
22
add_subdirectory(module_cell)
33
add_subdirectory(module_symmetry)
44
add_subdirectory(module_neighbor)
5+
add_subdirectory(module_psi)
6+
add_subdirectory(module_elecstate)
7+
add_subdirectory(module_hamilt)
8+
add_subdirectory(module_hsolver)
59
add_subdirectory(module_orbital)
610
add_subdirectory(module_md)
711
add_subdirectory(module_deepks)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
add_library(
2+
elecstate
3+
OBJECT
4+
elecstate_pw.cpp
5+
)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef ELECSTATE_H
2+
#define ELECSTATE_H
3+
4+
#include "module_hamilt/matrixblock.h"
5+
#include "module_psi/psi.h"
6+
#include "src_pw/charge.h"
7+
8+
namespace elecstate
9+
{
10+
11+
class ElecState
12+
{
13+
public:
14+
virtual void init(Charge *chg_in
15+
/*const Basis &basis, const Cell &cell*/)
16+
= 0;
17+
18+
// return current electronic density rho, as a input for constructing Hamiltonian
19+
virtual const hamilt::MatrixBlock<double> getRho() const = 0;
20+
21+
// calculate electronic charge density on grid points or density matrix in real space
22+
// the consequence charge density rho saved into rho_out, preparing for charge mixing.
23+
virtual void updateRhoK(const psi::Psi<std::complex<double>> &psi) = 0;
24+
virtual void updateRhoK(const psi::Psi<double> &psi)
25+
{
26+
return;
27+
}
28+
29+
// update charge density for next scf step
30+
// in this function, 1. input rho for construct Hamilt and 2. calculated rho from Psi will mix to 3. new charge
31+
// density rho among these rho,
32+
// 1. input rho would be store to file for restart
33+
// 2. calculated rho should be near with input rho when convergence has achieved
34+
// 3. new rho should be input rho for next scf step.
35+
virtual void getNewRho() = 0;
36+
};
37+
38+
} // namespace elecstate
39+
#endif
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include "elecstate_pw.h"
2+
3+
namespace elecstate
4+
{
5+
6+
void ElecStatePW::init(Charge* chg_in)
7+
{
8+
this->pchg = chg_in;
9+
}
10+
11+
const hamilt::MatrixBlock<double> ElecStatePW::getRho() const
12+
{
13+
hamilt::MatrixBlock<double> temp{&(this->pchg->rho[0][0]), 1, 1}; // this->chr->get_nspin(), this->chr->get_nrxx()};
14+
return temp;
15+
}
16+
17+
void ElecStatePW::updateRhoK(const psi::Psi<std::complex<double>>& psi)
18+
{
19+
this->pchg->sum_band_k(/*psi*/);
20+
return;
21+
}
22+
23+
void ElecStatePW::getNewRho()
24+
{
25+
return;
26+
}
27+
28+
} // namespace elecstate
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#ifndef ELECSTATEPW_H
2+
#define ELECSTATEPW_H
3+
4+
#include "elecstate.h"
5+
#include "module_hamilt/hamilt.h"
6+
#include "module_psi/psi.h"
7+
8+
namespace elecstate
9+
{
10+
11+
class ElecStatePW : public ElecState
12+
{
13+
public:
14+
void init(Charge* chg_in
15+
/*const Basis &basis, const Cell &cell*/) override;
16+
17+
// return current electronic density rho, as a input for constructing Hamiltonian
18+
const hamilt::MatrixBlock<double> getRho() const override;
19+
20+
// calculate electronic charge density on grid points or density matrix in real space
21+
// the consequence charge density rho saved into rho_out, preparing for charge mixing.
22+
void updateRhoK(const psi::Psi<std::complex<double>>& psi) override;
23+
24+
// update charge density for next scf step
25+
void getNewRho() override;
26+
27+
private:
28+
Charge* pchg;
29+
};
30+
31+
} // namespace elecstate
32+
33+
#endif
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
add_library(
2+
hamilt
3+
OBJECT
4+
hamilt_pw.cpp
5+
hamilt_lcao.cpp
6+
)

source/module_hamilt/hamilt.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef MODULEHAMILT_H
2+
#define MODULEHAMILT_H
3+
4+
#include "matrixblock.h"
5+
#include "module_psi/psi.h"
6+
7+
#include <complex>
8+
9+
namespace hamilt
10+
{
11+
12+
class Hamilt
13+
{
14+
public:
15+
// construct Hamiltonian matrix with inputed electonic density
16+
virtual void constructHamilt(const int iter, const MatrixBlock<double> rho) = 0;
17+
18+
// for target K point, update consequence of hPsi() and matrix()
19+
virtual void updateHk(const int ik) = 0;
20+
21+
// core function: for solving eigenvalues of Hamiltonian with iterative method
22+
virtual void hPsi(const psi::Psi<std::complex<double>>& psi, psi::Psi<std::complex<double>>& hpsi) const = 0;
23+
24+
// core function: return H(k) and S(k) matrixs for direct solving eigenvalues.
25+
virtual void matrix(MatrixBlock<std::complex<double>> hk_in, MatrixBlock<std::complex<double>> sk_in) = 0;
26+
virtual void matrix(MatrixBlock<double> hk_in, MatrixBlock<double> sk_in) = 0;
27+
28+
protected:
29+
// array, save operations from each operators
30+
// would be implemented later
31+
// vector<Operator*> p_operators;
32+
};
33+
34+
} // namespace hamilt
35+
36+
#endif
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
#include "hamilt_lcao.h"
2+
3+
#include "module_base/global_variable.h"
4+
#include "module_base/timer.h"
5+
#include "src_lcao/global_fp.h"
6+
#include "src_pw/global.h"
7+
8+
namespace hamilt
9+
{
10+
// case for nspin<4, gamma-only k-point
11+
template class HamiltLCAO<double, double>;
12+
// case for nspin<4, multi-k-points
13+
template class HamiltLCAO<std::complex<double>, double>;
14+
15+
template <typename T, typename T1> void HamiltLCAO<T, T1>::constructFixedReal()
16+
{
17+
// update the flag
18+
if (HamiltLCAO<T, T1>::isFixedDone)
19+
return;
20+
else
21+
HamiltLCAO<T, T1>::isFixedDone = true;
22+
23+
if (GlobalV::GAMMA_ONLY_LOCAL)
24+
this->fixedRealM.resize(this->LM->ParaV->nloc, T1(0));
25+
else
26+
this->fixedRealM.resize(this->LM->ParaV->nnr, T1(0));
27+
28+
ModuleBase::TITLE("HamiltLCAO", "constructFixedReal");
29+
ModuleBase::timer::tick("HamiltLCAO", "constructFixedReal");
30+
31+
// (9) compute S, T, Vnl, Vna matrix.
32+
this->genH->calculate_S_no(this->fixedRealM.getS());
33+
34+
if (GlobalV::VNL_IN_H)
35+
{
36+
this->genH->calculate_NL_no(this->fixedRealM.getH());
37+
}
38+
39+
if (GlobalV::T_IN_H)
40+
{
41+
this->genH->calculate_T_no(this->fixedRealM.getH());
42+
}
43+
44+
ModuleBase::timer::tick("HamiltLCAO", "constructFixedReal");
45+
return;
46+
47+
return;
48+
}
49+
50+
template <typename T, typename T1> void HamiltLCAO<T, T1>::constructUpdateReal()
51+
{
52+
return;
53+
}
54+
55+
template <typename T, typename T1> void HamiltLCAO<T, T1>::hk_fixed_mock(const int ik)
56+
{
57+
if (GlobalV::GAMMA_ONLY_LOCAL)
58+
this->kM.resize(this->LM->ParaV->nloc, T(0));
59+
else
60+
this->kM.resize(this->LM->ParaV->nnr, T(0));
61+
62+
// folding_fixedH() should be refactored to there,
63+
// but now deepks code in this function, should be moved to another place
64+
return;
65+
}
66+
67+
template <typename T, typename T1> void HamiltLCAO<T, T1>::hk_update_mock(const int ik)
68+
{
69+
// update_Hk and update_Hgamma should be refactored to there
70+
return;
71+
}
72+
73+
template <typename T, typename T1> void HamiltLCAO<T, T1>::getMatrix(MatrixBlock<T> &hk_in, MatrixBlock<T> &sk_in)
74+
{
75+
hk_in = MatrixBlock<T>{kM.hloc.data(),
76+
(size_t)this->LM->ParaV->nrow,
77+
(size_t)this->LM->ParaV->ncol,
78+
this->LM->ParaV->desc};
79+
sk_in = MatrixBlock<T>{kM.sloc.data(),
80+
(size_t)this->LM->ParaV->nrow,
81+
(size_t)this->LM->ParaV->ncol,
82+
this->LM->ParaV->desc};
83+
}
84+
85+
// case for nspin==4
86+
/*void HamiltLCAO<std::complex<double>, std::complex<double>>::matrix(MatrixBlock<std::complex<double>> hk_in,
87+
MatrixBlock<std::complex<double>> sk_in)const
88+
{
89+
this->getMatrix(hk_in, sk_in);
90+
}*/
91+
// case for nspin<4, multi-k-points
92+
template <>
93+
void HamiltLCAO<std::complex<double>, double>::matrix(MatrixBlock<std::complex<double>> hk_in,
94+
MatrixBlock<std::complex<double>> sk_in)
95+
{
96+
this->getMatrix(hk_in, sk_in);
97+
}
98+
99+
// case for nspin<4, gamma_only
100+
template <> void HamiltLCAO<double, double>::matrix(MatrixBlock<double> hk_in, MatrixBlock<double> sk_in)
101+
{
102+
this->getMatrix(hk_in, sk_in);
103+
}
104+
105+
// nspin==4 case not supported yet
106+
/*void HamiltLCAO<std::complex<double>, std::complex<double>>::constructHamilt(const int iter, const MatrixBlock<double>
107+
rho)
108+
{
109+
this->constructFixedReal();
110+
this->constructUpdateReal();
111+
}*/
112+
template <typename T, typename T1>
113+
void HamiltLCAO<T, T1>::constructHamilt(const int iter, const MatrixBlock<double> rho)
114+
{
115+
this->constructFixedReal();
116+
this->constructUpdateReal();
117+
}
118+
/*template<>
119+
void HamiltLCAO<double, double>::constructHamilt(const int iter, const MatrixBlock<double> rho)
120+
{
121+
this->constructFixedReal();
122+
this->constructUpdateReal();
123+
}*/
124+
125+
/*void HamiltLCAO<std::complex<double>, std::complex<double>>::updateHk(const int ik)
126+
{
127+
this->hk_fixed_mock(ik);
128+
this->hk_update_mock(ik);
129+
};*/
130+
template <typename T, typename T1> void HamiltLCAO<T, T1>::updateHk(const int ik)
131+
{
132+
this->hk_fixed_mock(ik);
133+
this->hk_update_mock(ik);
134+
}
135+
/*template<>
136+
void HamiltLCAO<double, double>::updateHk(const int ik)
137+
{
138+
this->hk_fixed_mock(ik);
139+
this->hk_update_mock(ik);
140+
}*/
141+
142+
} // namespace hamilt

0 commit comments

Comments
 (0)