From 3086ca68e5e0b0acace6fa8ef2e8c9f76fca528d Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Mon, 17 Apr 2023 20:28:14 +0800 Subject: [PATCH 1/8] New propagator for better Convergence --- .../module_esolver/esolver_ks_lcao_tddft.cpp | 205 ++++------- source/module_hamilt_general/hamilt.h | 4 + .../hamilt_lcaodft/LCAO_matrix.cpp | 17 +- .../hamilt_lcaodft/LCAO_matrix.h | 7 +- .../hamilt_lcaodft/hamilt_lcao.cpp | 30 +- .../hamilt_lcaodft/hamilt_lcao.h | 6 +- .../operator_lcao/operator_lcao.cpp | 14 + .../operator_lcao/operator_lcao.h | 30 ++ .../module_tddft/ELEC_evolve.cpp | 7 +- .../module_tddft/LCAO_evolve.cpp | 327 +++++++++++++++--- .../module_tddft/LCAO_evolve.h | 20 +- 11 files changed, 455 insertions(+), 212 deletions(-) diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index 1899cb9dfd..e4b7afe9a3 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -5,7 +5,6 @@ #include "module_io/rho_io.h" #include "module_io/dipole_io.h" #include "module_io/write_HS_R.h" -#include "module_io/write_HS.h" //--------------temporary---------------------------- #include "module_base/blas_connector.h" @@ -177,7 +176,13 @@ void ESolver_KS_LCAO_TDDFT::eachiterinit(const int istep, const int iter) if (!GlobalV::GAMMA_ONLY_LOCAL) { - this->UHM.GK.renew(); + if (this->UHM.GK.get_spin() != -1) + { + int start_spin = -1; + this->UHM.GK.reset_spin(start_spin); + this->UHM.GK.destroy_pvpR(); + this->UHM.GK.allocate_pvpR(); + } } } @@ -274,75 +279,10 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) { - //print Hamiltonian and Overlap matrix - if (this->conv_elec) - { - if (!GlobalV::GAMMA_ONLY_LOCAL) - { - this->UHM.GK.renew(true); - } - for (int ik = 0; ik < GlobalC::kv.nks; ++ik) - { - if(hsolver::HSolverLCAO::out_mat_hs) - { - this->p_hamilt->updateHk(ik); - } - bool bit = false; // LiuXh, 2017-03-21 - // if set bit = true, there would be error in soc-multi-core calculation, noted by zhengdy-soc - if (this->psi != nullptr) - { - hamilt::MatrixBlock> h_mat, s_mat; - this->p_hamilt->matrix(h_mat, s_mat); - ModuleIO::saving_HS(h_mat.p, - s_mat.p, - bit, - hsolver::HSolverLCAO::out_mat_hs, - "data-" + std::to_string(ik), - this->LOWF.ParaV[0], - 1); // LiuXh, 2017-03-21 - } - else if (this->psid != nullptr) - { - hamilt::MatrixBlock h_mat, s_mat; - this->p_hamilt->matrix(h_mat, s_mat); - ModuleIO::saving_HS(h_mat.p, - s_mat.p, - bit, - hsolver::HSolverLCAO::out_mat_hs, - "data-" + std::to_string(ik), - this->LOWF.ParaV[0], - 1); // LiuXh, 2017-03-21 - } - } - } - - if (this->conv_elec) - { - if (elecstate::ElecStateLCAO::out_wfc_lcao) - { - elecstate::ElecStateLCAO::out_wfc_flag = 1; - } - for (int ik = 0; ik < GlobalC::kv.nks; ik++) - { - if (this->psi != nullptr) - { - this->psi[0].fix_k(ik); - this->pelec->print_psi(this->psi[0]); - } - else - { - this->psid[0].fix_k(ik); - this->pelec->print_psi(this->psid[0]); - } - } - elecstate::ElecStateLCAO::out_wfc_flag = 0; - } - // (9) Calculate new potential according to new Charge Density. if (!this->conv_elec) { - if(GlobalV::NSPIN==4) GlobalC::ucell.cal_ux(); this->pelec->pot->update_from_charge(this->pelec->charge, &GlobalC::ucell); GlobalC::en.delta_escf(this->pelec); } @@ -364,7 +304,6 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) this->psi_laststep = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); #endif - for (int ik = 0; ik < GlobalC::kv.nks; ++ik) { this->psi->fix_k(ik); @@ -373,11 +312,17 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) for (int index = 0; index < size0; ++index) psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; } - if (istep > 1 && ELEC_evolve::td_edm == 0) this->cal_edm_tddft(); } - + //store Hk_last by zhaoht + if (istep >= 2 && this->conv_elec) + { + for (int ik = 0; ik < GlobalC::kv.nks; ++ik){ + this->LM.update_Hl(ik); + } + } + //above if (this->conv_elec) { GlobalV::ofs_running @@ -414,27 +359,10 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) for (int is = 0; is < GlobalV::NSPIN; is++) { const int precision = 3; + std::stringstream ssc; - ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG.cube"; - double& ef_tmp = GlobalC::en.get_ef(is,GlobalV::TWO_EFERMI); - ModuleIO::write_rho( -#ifdef __MPI - GlobalC::bigpw->bz, - GlobalC::bigpw->nbz, - GlobalC::rhopw->nplane, - GlobalC::rhopw->startz_current, -#endif - pelec->charge->rho_save[is], - is, - GlobalV::NSPIN, - 0, - ssc.str(), - GlobalC::rhopw->nx, - GlobalC::rhopw->ny, - GlobalC::rhopw->nz, - ef_tmp, - &(GlobalC::ucell), - precision); + ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG"; + ModuleIO::write_rho(pelec->charge->rho_save[is], is, 0, ssc.str()); // mohan add 2007-10-17 if (ELEC_evolve::out_dipole == 1) { @@ -452,26 +380,16 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) { ssd << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DM_R"; } + ModuleIO::write_dm(is, 0, ssd.str(), precision, this->LOC.out_dm, this->LOC.DM); - ModuleIO::write_dm( -#ifdef __MPI - GlobalC::GridT.trace_lo, -#endif - is, - 0, - ssd.str(), - precision, - this->LOC.out_dm, - this->LOC.DM, - ef_tmp, - &(GlobalC::ucell)); - - if (GlobalV::out_pot == 1) // LiuXh add 20200701 - { - std::stringstream ssp; - ssp << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT.cube"; - this->pelec->pot->write_potential(is, 0, ssp.str(), this->pelec->pot->get_effective_v(), precision); - } + /* Broken, please fix it + if (GlobalV::out_pot == 1) // LiuXh add 20200701 + { + std::stringstream ssp; + ssp << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT"; + this->pelec->pot->write_potential(is, 0, ssp.str(), this->pelec->pot->get_effective_v(), precision); + } + */ } if (this->conv_elec) @@ -505,38 +423,43 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) std::cout << " !! CONVERGENCE HAS NOT BEEN ACHIEVED !!" << std::endl; } - if( GlobalV::CALCULATION != "md" || (istep % hsolver::HSolverLCAO::out_hsR_interval == 0)) + if (hsolver::HSolverLCAO::out_mat_hsR) { - if (hsolver::HSolverLCAO::out_mat_hsR) + if (!(GlobalV::CALCULATION == "md" && (istep % hsolver::HSolverLCAO::out_hsR_interval != 0))) { ModuleIO::output_HS_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 } + } - if (hsolver::HSolverLCAO::out_mat_t) + if (hsolver::HSolverLCAO::out_mat_t) + { + if (!(GlobalV::CALCULATION == "md" && (istep % hsolver::HSolverLCAO::out_hsR_interval != 0))) { ModuleIO::output_T_R(istep, this->UHM); // LiuXh add 2019-07-15 } + } - if (hsolver::HSolverLCAO::out_mat_dh) + if (hsolver::HSolverLCAO::out_mat_dh) + { + if (!(GlobalV::CALCULATION == "md" && (istep % hsolver::HSolverLCAO::out_hsR_interval != 0))) { ModuleIO::output_dH_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 } + } - // add by jingan for out r_R matrix 2019.8.14 - if (INPUT.out_mat_r) - { - cal_r_overlap_R r_matrix; - r_matrix.init(*this->LOWF.ParaV); + // add by jingan for out r_R matrix 2019.8.14 + if (INPUT.out_mat_r) + { + cal_r_overlap_R r_matrix; + r_matrix.init(*this->LOWF.ParaV); - if (hsolver::HSolverLCAO::out_mat_hsR) - { - r_matrix.out_rR_other(istep, this->LM.output_R_coor); - } - else - { - r_matrix.out_rR(istep); - - } + if (hsolver::HSolverLCAO::out_mat_hsR) + { + r_matrix.out_rR_other(istep, this->LM.output_R_coor); + } + else + { + r_matrix.out_rR(istep); } } } @@ -610,14 +533,14 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &info); const char N_char = 'N', T_char = 'T'; - const complex one_float = {1.0, 0.0}, zero_float = {0.0, 0.0}; - const complex half_float = {0.5, 0.0}; + const double one_float[2] = {1.0, 0.0}, zero_float[2] = {0.0, 0.0}; + const complex half_float[2] = {0.5, 0.0}; pzgemm_(&T_char, &T_char, &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float, + &one_float[0], this->LOC.dm_k[ik].c, &one_int, &one_int, @@ -626,7 +549,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float, + &zero_float[0], tmp1, &one_int, &one_int, @@ -637,7 +560,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float, + &one_float[0], tmp1, &one_int, &one_int, @@ -646,7 +569,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float, + &zero_float[0], tmp2, &one_int, &one_int, @@ -657,7 +580,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float, + &one_float[0], Sinv, &one_int, &one_int, @@ -666,7 +589,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float, + &zero_float[0], tmp3, &one_int, &one_int, @@ -677,7 +600,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float, + &one_float[0], tmp3, &one_int, &one_int, @@ -686,7 +609,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float, + &zero_float[0], tmp4, &one_int, &one_int, @@ -695,12 +618,12 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() pzgeadd_(&N_char, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &half_float, + &half_float[0], tmp2, &one_int, &one_int, this->LOC.ParaV->desc, - &half_float, + &half_float[0], tmp4, &one_int, &one_int, @@ -708,12 +631,12 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() pztranu_(&GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float, + &one_float[0], tmp4, &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float, + &zero_float[0], tmp5, &one_int, &one_int, diff --git a/source/module_hamilt_general/hamilt.h b/source/module_hamilt_general/hamilt.h index 65962311fa..13573e9fc2 100644 --- a/source/module_hamilt_general/hamilt.h +++ b/source/module_hamilt_general/hamilt.h @@ -24,9 +24,13 @@ class Hamilt virtual void hPsi(const std::complex *psi_in, std::complex *hpsi, const size_t size) const{return;} virtual void sPsi(const std::complex *psi_in, std::complex *spsi, const size_t size) const{return;} + // core function: return H(k) and S(k) matrixs for direct solving eigenvalues. virtual void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in){return;} virtual void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in){return;} + // used for tddft evolve, added by zhaoht + virtual void matrix_l(MatrixBlock> &hk_in, MatrixBlock> &hk_last_in, MatrixBlock> &sk_in){return;} + virtual void matrix_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in){return;} std::string classname = "none"; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp index 1a4fb745da..cea2470b32 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp @@ -101,10 +101,13 @@ void LCAO_Matrix::allocate_HS_k(const long &nloc) this->Sloc2.resize(nloc); this->Hloc_fixed2.resize(nloc); this->Hloc2.resize(nloc); + //added by zhaoht for test + this->Hloc2_last.resize(nloc); ModuleBase::GlobalFunc::ZEROS(Sloc2.data(),nloc); ModuleBase::GlobalFunc::ZEROS(Hloc_fixed2.data(),nloc); ModuleBase::GlobalFunc::ZEROS(Hloc2.data(),nloc); + ModuleBase::GlobalFunc::ZEROS(Hloc2_last.data(),nloc); return; } @@ -594,8 +597,20 @@ void LCAO_Matrix::update_Hloc2(const int &ik) return; } +//added by zhaoht for test +void LCAO_Matrix::update_Hl(const int &ik) +{ +#ifdef _OPENMP +#pragma omp parallel for schedule(static, 1024) +#endif + for (long i = 0; i < this->ParaV->nloc; i++) + { + Hloc2_last[i]=Hloc2[i]; + } - + return; +} +//above void LCAO_Matrix::output_HSk(const char &mtype, std::string &fn) { ModuleBase::TITLE("LCAO_Matrix","output_HSk"); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h index dd33df593c..e341af9ca0 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h @@ -5,7 +5,7 @@ #include "module_base/global_variable.h" #include "module_base/vector3.h" #include "module_base/complexmatrix.h" -#include "module_basis/module_ao/parallel_orbitals.h" +#include "module_orbital/parallel_orbitals.h" // add by jingan for map<> in 2021-12-2, will be deleted in the future #include "module_base/abfs-vector3_order.h" @@ -23,7 +23,7 @@ class LCAO_Matrix // folding the fixed Hamiltonian (T+Vnl) if // k-point algorithm is used. - void folding_fixedH(const int &ik, bool cal_syns = false); + void folding_fixedH(const int &ik); Parallel_Orbitals *ParaV; @@ -54,6 +54,7 @@ class LCAO_Matrix // diagonalize. //------------------------------ std::vector> Hloc2; + std::vector> Hloc2_last; std::vector> Sloc2; std::vector> Hloc_fixed2; //with soc, zhengdy-soc @@ -201,6 +202,8 @@ class LCAO_Matrix void print_HSk(const char &mtype, const char &vtype = 'C', const double &accuracy = 1.0e-5, std::ostream &os=std::cout); void update_Hloc(void); void update_Hloc2(const int &ik); + //added by zhaoht for test + void update_Hl(const int &ik); void allocate_HS_R(const int &nnr); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp index 978e0dd61c..7f9b9ee4ca 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -240,14 +240,7 @@ HamiltLCAO::HamiltLCAO( &(LM_in->SlocR), &(LM_in->Sloc2) ); - if(this->ops == nullptr) - { - this->ops = overlap; - } - else - { - this->ops->add(overlap); - } + this->ops->add(overlap); // kinetic term (), // in general case, target HR is LCAO_Matrix::Hloc_fixedR, while target HK is LCAO_Matrix::Hloc2 @@ -311,12 +304,31 @@ void HamiltLCAO>::matrix(MatrixBlock> } // case for nspin<4, gamma_only -template <> void HamiltLCAO::matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) +template <> +void HamiltLCAO::matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) { auto op = dynamic_cast*>(this->opsd); assert(op != NULL); op->matrixHk(hk_in, sk_in); } +void HamiltLCAO>::matrix_l(MatrixBlock> &hk_in, + MatrixBlock> &hk_last_in, + MatrixBlock> &sk_in) +{ + auto op = dynamic_cast>*>(this->ops); + assert(op != NULL); + op->matrixHk_l(hk_in, hk_last_in, sk_in); +} +void HamiltLCAO::matrix_l(MatrixBlock &hk_in, + MatrixBlock &hk_last_in, + MatrixBlock &sk_in) +{ + auto op = dynamic_cast*>(this->opsd); + assert(op != NULL); + op->matrixHk_l(hk_in, hk_last_in, sk_in); +} + + template <> void HamiltLCAO::updateHk(const int ik) { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h index 77e353dcb2..9ee36602a7 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h @@ -5,8 +5,8 @@ #include "module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.h" #include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" #include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" -#include "module_hamilt_lcao/module_gint/gint_gamma.h" -#include "module_hamilt_lcao/module_gint/gint_k.h" +#include "module_gint/gint_gamma.h" +#include "module_gint/gint_k.h" #include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" #include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" #include "module_elecstate/potentials/potential_new.h" @@ -51,6 +51,8 @@ template class HamiltLCAO : public Hamilt // not used in PW base //void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in) override; void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) override; + void matrix_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in) override; + }; } // namespace hamilt diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp index 5f8f668b17..4086b7b070 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp @@ -39,6 +39,20 @@ void OperatorLCAO>::get_hs_pointers() this->smatrix_k = this->LM->Sloc2.data(); } +template<> +void OperatorLCAO::get_hls_pointers() +{ + return; +} +template<> +void OperatorLCAO>::get_hls_pointers() +{ + ModuleBase::timer::tick("OperatorLCAO", "get_hs_pointers"); + this->hmatrix_k = this->LM->Hloc2.data(); + this->hmatrix_k_last = this->LM->Hloc2_last.data(); + this->smatrix_k = this->LM->Sloc2.data(); +} + template<> void OperatorLCAO::refresh_h() { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h index 81f9f900db..8fb478c05b 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h @@ -64,6 +64,34 @@ class OperatorLCAO : public Operator nullptr}; #endif } + //use for tddft evolve,added by zaotian + void matrixHk_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in) + { + this->get_hls_pointers(); +#ifdef __MPI + hk_in = MatrixBlock{hmatrix_k, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + this->LM->ParaV->desc}; + hk_last_in = MatrixBlock{hmatrix_k_last, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + this->LM->ParaV->desc}; + sk_in = MatrixBlock{smatrix_k, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + this->LM->ParaV->desc}; +#else + hk_in = MatrixBlock{hmatrix_k, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + nullptr}; + sk_in = MatrixBlock{smatrix_k, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + nullptr}; +#endif + } /* Function contributeHk() is defined in derived class, for constructing (K) */ @@ -81,10 +109,12 @@ class OperatorLCAO : public Operator private: void get_hs_pointers(); + void get_hls_pointers(); // there are H and S matrix for each k point in reciprocal space // type double for gamma_only case, type complex for multi-k-points case T* hmatrix_k = nullptr; + T* hmatrix_k_last = nullptr; T* smatrix_k = nullptr; //only used for Gamma_only case diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp index 66a8fcb1a7..b7ffc3c7e8 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp @@ -39,7 +39,12 @@ void ELEC_evolve::evolve_psi(const int& istep, Evolve_LCAO_Matrix ELM(lowf.ParaV); psi->fix_k(ik); psi_laststep->fix_k(ik); - ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, &(ekb(ik, 0))); + if(istep<3){ + ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, &(ekb(ik, 0)));} + //added by zhaoht for test + else{ + ELM.evolve_complex_matrix_1(ik, phm, psi, psi_laststep, &(ekb(ik, 0))); + } ModuleBase::timer::tick("Efficience", "evolve_k"); } // end k diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp index 66325ee7cf..cf2a77a378 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp @@ -52,7 +52,37 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, return; } +//added by zhaoht for test +void Evolve_LCAO_Matrix::evolve_complex_matrix_1(const int& ik, + hamilt::Hamilt* p_hamilt, + psi::Psi>* psi_k, + psi::Psi>* psi_k_laststep, + double* ekb) const +{ + ModuleBase::TITLE("Evolve_LCAO_Matrix", "evolve_complex_matrix"); + time_t time_start = time(NULL); + GlobalV::ofs_running << " Start Time : " << ctime(&time_start); + + if (GlobalV::ESOLVER_TYPE == "tddft") + { +#ifdef __MPI + this->using_ScaLAPACK_complex_1(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), p_hamilt, psi_k[0].get_pointer(), ekb); +#else + this->using_LAPACK_complex(ik, p_hamilt, psi_k[0].get_pointer(), psi_k_laststep[0].get_pointer(), ekb); +#endif + } + else + { + ModuleBase::WARNING_QUIT("Evolve_LCAO_Matrix::evolve_complex_matrix", + "only esolver_type == tddft cando evolve"); + } + + time_t time_end = time(NULL); + ModuleBase::GlobalFunc::OUT_TIME("evolve(std::complex)", time_start, time_end); + return; +} +//test above void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, hamilt::Hamilt* p_hamilt, std::complex* psi_k, @@ -185,7 +215,7 @@ void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, int lwork = 3 * GlobalV::NLOCAL - 1; // tmp std::complex* work = new std::complex[lwork]; ModuleBase::GlobalFunc::ZEROS(work, lwork); - int* ipiv = new int[GlobalV::NLOCAL]; + int ipiv[GlobalV::NLOCAL]; LapackConnector::zgetrf(GlobalV::NLOCAL, GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, &info); LapackConnector::zgetri(GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, work, lwork, &info); @@ -333,7 +363,7 @@ void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, */ delete[] work; - delete[] ipiv; + // delete[] ipiv; return; } @@ -361,7 +391,7 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( complex* Htmp = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); - + complex* U_operator = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); @@ -374,19 +404,106 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( // (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + complex* psi_not_norm = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(psi_not_norm, this->ParaV->nloc); + /// @brief apply U_operator to the wave function of the previous step for new wave function /// @input U_operator, psi_k_laststep + /// @output psi_k, psi_not_norm (used by norm_wfc) + U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k, psi_not_norm); + +// (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief normalize psi_k + /// @input Stmp, psi_not_norm, psi_k, print_matrix /// @output psi_k - U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k); + norm_wfc(nband, nlocal, Stmp, psi_not_norm, psi_k, print_matrix); + +// (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + /// @brief compute ekb + /// @input Htmp, psi_k + /// @output ekb + compute_ekb(nband, nlocal, Htmp, psi_k, ekb); + + delete[] Stmp; + delete[] Htmp; + delete[] U_operator; + delete[] psi_not_norm; + + return; +} + +//added by zhaoht for test +void Evolve_LCAO_Matrix::using_ScaLAPACK_complex_1( + const int nband, + const int nlocal, + const std::complex* psi_k_laststep, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + double* ekb) const +{ + ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_ScaLAPACK_complex"); + + int print_matrix = 0; + hamilt::MatrixBlock> h_mat, h_mat_last, s_mat; + p_hamilt->matrix_l(h_mat, h_mat_last, s_mat); + + complex* Stmp = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Stmp, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, s_mat.p, 1, Stmp, 1); + + complex* Htmp_last = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Htmp_last, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, h_mat_last.p, 1, Htmp_last, 1); + + complex* Htmp = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); + + complex mixing = {0.5, 0.0}; + ScalapackConnector::geadd( + 'N', + nlocal, + nlocal, + mixing, + Htmp_last, + 1, + 1, + this->ParaV->desc, + mixing, + Htmp, + 1, + 1, + this->ParaV->desc + ); + complex* U_operator = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); + +// (1)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief compute U_operator + /// @input Stmp, Htmp, print_matrix + /// @output U_operator + compute_U_operator(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); + +// (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + complex* psi_not_norm = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(psi_not_norm, this->ParaV->nloc); + + /// @brief apply U_operator to the wave function of the previous step for new wave function + /// @input U_operator, psi_k_laststep + /// @output psi_k, psi_not_norm (used by norm_wfc) + U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k, psi_not_norm); // (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /// @brief normalize psi_k /// @input Stmp, psi_not_norm, psi_k, print_matrix /// @output psi_k - norm_wfc(nband, nlocal, Stmp, psi_k, print_matrix); + norm_wfc(nband, nlocal, Stmp, psi_not_norm, psi_k, print_matrix); // (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @@ -399,9 +516,11 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( delete[] Stmp; delete[] Htmp; delete[] U_operator; + delete[] psi_not_norm; + return; } - +//test above void Evolve_LCAO_Matrix::compute_U_operator( const int nband, @@ -448,8 +567,8 @@ void Evolve_LCAO_Matrix::compute_U_operator( // ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // (2) compute Numerator & Denominator by GEADD - // Numerator = Stmp - i*para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt - // Denominator = Stmp + i*para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt + // Numerator = Stmp - para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt + // Denominator = Stmp + para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt complex alpha = {1.0, 0.0}; complex beta1 = {0.0, -0.25 * INPUT.mdp.md_dt}; complex beta2 = {0.0, 0.25 * INPUT.mdp.md_dt}; @@ -502,7 +621,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // (3) Next, invert Denominator int* ipiv = new int[this->ParaV->nloc]; - int info = 0; + int info; // (3.1) compute ipiv ScalapackConnector::getrf( nlocal, @@ -512,7 +631,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( 1, this->ParaV->desc, ipiv, - &info + info ); int lwork = -1; int liwotk = -1; @@ -530,7 +649,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( &lwork, iwork.data(), &liwotk, - &info + info ); lwork = work[0].real(); work.resize(lwork, 0); @@ -548,7 +667,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( &lwork, iwork.data(), &liwotk, - &info + info ); assert(0 == info); @@ -557,7 +676,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( // (4) U_operator = Denominator * Numerator; ScalapackConnector::gemm( 'N', - 'N', + 'T', nlocal, nlocal, nlocal, @@ -576,7 +695,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( 1, this->ParaV->desc ); - + //zaotian added for test if (print_matrix) { GlobalV::ofs_running << " fenmu^-1:" << endl; @@ -630,30 +749,50 @@ void Evolve_LCAO_Matrix::U_to_wfc( const int nlocal, const std::complex* U_operator, const std::complex* psi_k_laststep, - std::complex* psi_k) const + std::complex* psi_k, + std::complex* psi_not_norm) const { + complex* psi_not_norm_trans = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(psi_not_norm_trans, this->ParaV->nloc); ScalapackConnector::gemm( - 'N', - 'N', - nlocal, + 'T', + 'T', nband, nlocal, + nlocal, 1.0, + psi_k_laststep, + 1, + 1, + this->ParaV->desc_wfc, U_operator, 1, 1, this->ParaV->desc, - psi_k_laststep, + 0.0, + psi_not_norm, 1, 1, - this->ParaV->desc_wfc, + this->ParaV->desc + ); + ScalapackConnector::tranu( + nlocal, + nlocal, + 1.0, + psi_not_norm, + 1, + 1, + this->ParaV->desc, 0.0, - psi_k, + psi_not_norm_trans, 1, 1, - this->ParaV->desc_wfc + this->ParaV->desc ); + BlasConnector::copy(this->ParaV->nloc_wfc, psi_not_norm_trans, 1, psi_k, 1); + + delete[] psi_not_norm_trans; } @@ -661,38 +800,57 @@ void Evolve_LCAO_Matrix::norm_wfc( const int nband, const int nlocal, const std::complex* Stmp, + const std::complex* psi_not_norm, std::complex* psi_k, const int print_matrix) const { - complex* tmp1 = new complex[this->ParaV->nloc_wfc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); - + complex* tmp1 = new complex[this->ParaV->nloc]; + complex* tmp2 = new complex[this->ParaV->nloc]; + complex* tmp3 = new complex[this->ParaV->nloc_wfc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp2, this->ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp3, this->ParaV->nloc_wfc); + complex* Cij = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Cij, this->ParaV->nloc); - + + ScalapackConnector::gemm( + 'T', 'N', - 'N', - nlocal, nband, nlocal, + nlocal, 1.0, - Stmp, - 1, - 1, - this->ParaV->desc, psi_k, 1, 1, this->ParaV->desc_wfc, + Stmp, + 1, + 1, + this->ParaV->desc, 0.0, tmp1, 1, 1, - this->ParaV->desc_wfc + this->ParaV->desc ); - - + ScalapackConnector::tranu( + nlocal, + nlocal, + 1.0, + tmp1, + 1, + 1, + this->ParaV->desc, + 0.0, + tmp2, + 1, + 1, + this->ParaV->desc + ); + BlasConnector::copy(this->ParaV->nloc_wfc, tmp2, 1, tmp3, 1); ScalapackConnector::gemm( 'C', 'N', @@ -704,7 +862,7 @@ void Evolve_LCAO_Matrix::norm_wfc( 1, 1, this->ParaV->desc_wfc, - tmp1, + tmp3, 1, 1, this->ParaV->desc_wfc, @@ -757,19 +915,18 @@ void Evolve_LCAO_Matrix::norm_wfc( // std::cout << "nlocal" << nlocal << std::endl; // std::cout << "GlobalV::NLOCAL" << GlobalV::NLOCAL << std::endl; - BlasConnector::copy(this->ParaV->nloc_wfc, psi_k, 1, tmp1, 1); ScalapackConnector::gemm( + 'T', 'N', - 'N', - nlocal, + GlobalV::NLOCAL, nband, nband, 1.0, - tmp1, + psi_not_norm, 1, 1, - this->ParaV->desc_wfc, + this->ParaV->desc, Cij, 1, 1, @@ -781,7 +938,6 @@ void Evolve_LCAO_Matrix::norm_wfc( this->ParaV->desc_wfc ); - if (print_matrix) { GlobalV::ofs_running << " Cij:" << endl; @@ -789,11 +945,27 @@ void Evolve_LCAO_Matrix::norm_wfc( { for (int j = 0; j < this->ParaV->nrow; j++) { - GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" << Cij[i * this->ParaV->ncol_bands + j].imag() << "i "; + GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" << Cij[i * this->ParaV->ncol + j].imag() << "i "; } GlobalV::ofs_running << endl; } GlobalV::ofs_running << endl; + // GlobalV::ofs_running << " psi_k_laststep:" << endl; + // for (int i = 0; i < this->ParaV->ncol_bands; i++) + // { + // for (int j = 0; j < this->ParaV->nrow; j++) + // { + // double aa, bb; + // aa = psi_k_laststep[i * this->ParaV->ncol + j].real(); + // bb = psi_k_laststep[i * this->ParaV->ncol + j].imag(); + // if (abs(aa) < 1e-8) + // aa = 0.0; + // if (abs(bb) < 1e-8) + // bb = 0.0; + // GlobalV::ofs_running << aa << "+" << bb << "i "; + // } + // GlobalV::ofs_running << endl; + // } GlobalV::ofs_running << endl; GlobalV::ofs_running << " psi_k:" << endl; for (int i = 0; i < this->ParaV->ncol_bands; i++) @@ -818,8 +990,8 @@ void Evolve_LCAO_Matrix::norm_wfc( for (int j = 0; j < this->ParaV->ncol; j++) { double aa, bb; - aa = tmp1[i * this->ParaV->ncol + j].real(); - bb = tmp1[i * this->ParaV->ncol + j].imag(); + aa = psi_not_norm[i * this->ParaV->ncol + j].real(); + bb = psi_not_norm[i * this->ParaV->ncol + j].imag(); if (abs(aa) < 1e-8) aa = 0.0; if (abs(bb) < 1e-8) @@ -830,10 +1002,29 @@ void Evolve_LCAO_Matrix::norm_wfc( } GlobalV::ofs_running << endl; GlobalV::ofs_running << endl; + // GlobalV::ofs_running << " psi_k nlocal*nlocal transpose:" << endl; + // for (int i = 0; i < this->ParaV->ncol; i++) + // { + // for (int j = 0; j < this->ParaV->ncol; j++) + // { + // double aa, bb; + // aa = psi_not_norm_trans[i * this->ParaV->ncol + j].real(); + // bb = psi_not_norm_trans[i * this->ParaV->ncol + j].imag(); + // if (abs(aa) < 1e-8) + // aa = 0.0; + // if (abs(bb) < 1e-8) + // bb = 0.0; + // GlobalV::ofs_running << aa << "+" << bb << "i "; + // } + // GlobalV::ofs_running << endl; + // } + // GlobalV::ofs_running << endl; } delete[] tmp1; + delete[] tmp2; + delete[] tmp3; delete[] Cij; } @@ -847,33 +1038,52 @@ void Evolve_LCAO_Matrix::compute_ekb( double* ekb) const { - complex* tmp1 = new complex[this->ParaV->nloc_wfc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); + complex* tmp1 = new complex[this->ParaV->nloc]; + complex* tmp2 = new complex[this->ParaV->nloc]; + complex* tmp3 = new complex[this->ParaV->nloc_wfc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp2, this->ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp3, this->ParaV->nloc_wfc); complex* Eij = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Eij, this->ParaV->nloc); ScalapackConnector::gemm( + 'T', 'N', - 'N', - nlocal, nband, nlocal, + nlocal, 1.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, Htmp, 1, 1, this->ParaV->desc, - psi_k, + 0.0, + tmp1, 1, 1, - this->ParaV->desc_wfc, - 0.0, + this->ParaV->desc + ); + ScalapackConnector::tranu( + nlocal, + nlocal, + 1.0, tmp1, 1, 1, - this->ParaV->desc_wfc + this->ParaV->desc, + 0.0, + tmp2, + 1, + 1, + this->ParaV->desc ); + BlasConnector::copy(this->ParaV->nloc_wfc, tmp2, 1, tmp3, 1); ScalapackConnector::gemm( 'C', @@ -886,7 +1096,7 @@ void Evolve_LCAO_Matrix::compute_ekb( 1, 1, this->ParaV->desc_wfc, - tmp1, + tmp3, 1, 1, this->ParaV->desc_wfc, @@ -934,7 +1144,12 @@ void Evolve_LCAO_Matrix::compute_ekb( MPI_Comm_rank(this->ParaV->comm_2D, &myid); double* Eii = new double[nband]; - ModuleBase::GlobalFunc::ZEROS(Eii, nband); + + + for (int i = 0; i < nband; i++) + { + Eii[i] = 0.0; + } for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) { for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) @@ -968,6 +1183,8 @@ void Evolve_LCAO_Matrix::compute_ekb( info = MPI_Allreduce(Eii, ekb, nband, MPI_DOUBLE, MPI_SUM, this->ParaV->comm_2D); delete[] tmp1; + delete[] tmp2; + delete[] tmp3; delete[] Eij; delete[] Eii; } diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h index dd13e45e2f..6d84a29b38 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h @@ -23,6 +23,13 @@ class Evolve_LCAO_Matrix psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, double* ekb) const; + //added by zhaoht for test + void evolve_complex_matrix_1(const int& ik, + hamilt::Hamilt* p_hamilt, + psi::Psi>* psi_k, + psi::Psi>* psi_k_laststep, + double* ekb) const; + //above private: // LCAO_Matrix* LM; @@ -41,6 +48,15 @@ class Evolve_LCAO_Matrix hamilt::Hamilt* p_hamilt, std::complex* psi_k, double* ekb) const; +//added by zhaoht for test + void using_ScaLAPACK_complex_1( + const int nband, + const int nlocal, + const std::complex* psi_k_laststep, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + double* ekb) const; +//above void compute_U_operator( const int nband, @@ -55,12 +71,14 @@ class Evolve_LCAO_Matrix const int nlocal, const std::complex* U_operator, const std::complex* psi_k_laststep, - std::complex* psi_k) const; + std::complex* psi_k, + std::complex* psi_not_norm) const; void norm_wfc( const int nband, const int nlocal, const std::complex* Stmp, + const std::complex* psi_not_norm, std::complex* psi_k, const int print_matrix) const; From f48c2a613980f7fc5f759636b2c4f9ff0ca35216 Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Mon, 17 Apr 2023 21:00:45 +0800 Subject: [PATCH 2/8] Add files via upload --- .../module_esolver/esolver_ks_lcao_tddft.cpp | 205 ++++++++++----- source/module_hamilt_general/hamilt.h | 4 +- .../hamilt_lcaodft/LCAO_matrix.cpp | 4 +- .../hamilt_lcaodft/LCAO_matrix.h | 6 +- .../hamilt_lcaodft/hamilt_lcao.cpp | 15 +- .../hamilt_lcaodft/hamilt_lcao.h | 5 +- .../operator_lcao/operator_lcao.h | 2 - .../module_tddft/ELEC_evolve.cpp | 1 - .../module_tddft/LCAO_evolve.cpp | 235 +++++------------- .../module_tddft/LCAO_evolve.h | 8 +- 10 files changed, 224 insertions(+), 261 deletions(-) diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index e4b7afe9a3..f6feaf5bab 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -5,6 +5,7 @@ #include "module_io/rho_io.h" #include "module_io/dipole_io.h" #include "module_io/write_HS_R.h" +#include "module_io/write_HS.h" //--------------temporary---------------------------- #include "module_base/blas_connector.h" @@ -176,13 +177,7 @@ void ESolver_KS_LCAO_TDDFT::eachiterinit(const int istep, const int iter) if (!GlobalV::GAMMA_ONLY_LOCAL) { - if (this->UHM.GK.get_spin() != -1) - { - int start_spin = -1; - this->UHM.GK.reset_spin(start_spin); - this->UHM.GK.destroy_pvpR(); - this->UHM.GK.allocate_pvpR(); - } + this->UHM.GK.renew(); } } @@ -279,10 +274,75 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) { + //print Hamiltonian and Overlap matrix + if (this->conv_elec) + { + if (!GlobalV::GAMMA_ONLY_LOCAL) + { + this->UHM.GK.renew(true); + } + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) + { + if(hsolver::HSolverLCAO::out_mat_hs) + { + this->p_hamilt->updateHk(ik); + } + bool bit = false; // LiuXh, 2017-03-21 + // if set bit = true, there would be error in soc-multi-core calculation, noted by zhengdy-soc + if (this->psi != nullptr) + { + hamilt::MatrixBlock> h_mat, s_mat; + this->p_hamilt->matrix(h_mat, s_mat); + ModuleIO::saving_HS(h_mat.p, + s_mat.p, + bit, + hsolver::HSolverLCAO::out_mat_hs, + "data-" + std::to_string(ik), + this->LOWF.ParaV[0], + 1); // LiuXh, 2017-03-21 + } + else if (this->psid != nullptr) + { + hamilt::MatrixBlock h_mat, s_mat; + this->p_hamilt->matrix(h_mat, s_mat); + ModuleIO::saving_HS(h_mat.p, + s_mat.p, + bit, + hsolver::HSolverLCAO::out_mat_hs, + "data-" + std::to_string(ik), + this->LOWF.ParaV[0], + 1); // LiuXh, 2017-03-21 + } + } + } + + if (this->conv_elec) + { + if (elecstate::ElecStateLCAO::out_wfc_lcao) + { + elecstate::ElecStateLCAO::out_wfc_flag = 1; + } + for (int ik = 0; ik < GlobalC::kv.nks; ik++) + { + if (this->psi != nullptr) + { + this->psi[0].fix_k(ik); + this->pelec->print_psi(this->psi[0]); + } + else + { + this->psid[0].fix_k(ik); + this->pelec->print_psi(this->psid[0]); + } + } + elecstate::ElecStateLCAO::out_wfc_flag = 0; + } + // (9) Calculate new potential according to new Charge Density. if (!this->conv_elec) { + if(GlobalV::NSPIN==4) GlobalC::ucell.cal_ux(); this->pelec->pot->update_from_charge(this->pelec->charge, &GlobalC::ucell); GlobalC::en.delta_escf(this->pelec); } @@ -304,6 +364,7 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) this->psi_laststep = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); #endif + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) { this->psi->fix_k(ik); @@ -312,17 +373,13 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) for (int index = 0; index < size0; ++index) psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; } - if (istep > 1 && ELEC_evolve::td_edm == 0) - this->cal_edm_tddft(); - } - //store Hk_last by zhaoht - if (istep >= 2 && this->conv_elec) - { for (int ik = 0; ik < GlobalC::kv.nks; ++ik){ this->LM.update_Hl(ik); } + if (istep > 1 && ELEC_evolve::td_edm == 0) + this->cal_edm_tddft(); } - //above + if (this->conv_elec) { GlobalV::ofs_running @@ -359,10 +416,27 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) for (int is = 0; is < GlobalV::NSPIN; is++) { const int precision = 3; - std::stringstream ssc; - ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG"; - ModuleIO::write_rho(pelec->charge->rho_save[is], is, 0, ssc.str()); // mohan add 2007-10-17 + ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG.cube"; + double& ef_tmp = GlobalC::en.get_ef(is,GlobalV::TWO_EFERMI); + ModuleIO::write_rho( +#ifdef __MPI + GlobalC::bigpw->bz, + GlobalC::bigpw->nbz, + GlobalC::rhopw->nplane, + GlobalC::rhopw->startz_current, +#endif + pelec->charge->rho_save[is], + is, + GlobalV::NSPIN, + 0, + ssc.str(), + GlobalC::rhopw->nx, + GlobalC::rhopw->ny, + GlobalC::rhopw->nz, + ef_tmp, + &(GlobalC::ucell), + precision); if (ELEC_evolve::out_dipole == 1) { @@ -380,16 +454,26 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) { ssd << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DM_R"; } - ModuleIO::write_dm(is, 0, ssd.str(), precision, this->LOC.out_dm, this->LOC.DM); - /* Broken, please fix it - if (GlobalV::out_pot == 1) // LiuXh add 20200701 - { - std::stringstream ssp; - ssp << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT"; - this->pelec->pot->write_potential(is, 0, ssp.str(), this->pelec->pot->get_effective_v(), precision); - } - */ + ModuleIO::write_dm( +#ifdef __MPI + GlobalC::GridT.trace_lo, +#endif + is, + 0, + ssd.str(), + precision, + this->LOC.out_dm, + this->LOC.DM, + ef_tmp, + &(GlobalC::ucell)); + + if (GlobalV::out_pot == 1) // LiuXh add 20200701 + { + std::stringstream ssp; + ssp << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT.cube"; + this->pelec->pot->write_potential(is, 0, ssp.str(), this->pelec->pot->get_effective_v(), precision); + } } if (this->conv_elec) @@ -423,43 +507,38 @@ void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) std::cout << " !! CONVERGENCE HAS NOT BEEN ACHIEVED !!" << std::endl; } - if (hsolver::HSolverLCAO::out_mat_hsR) + if( GlobalV::CALCULATION != "md" || (istep % hsolver::HSolverLCAO::out_hsR_interval == 0)) { - if (!(GlobalV::CALCULATION == "md" && (istep % hsolver::HSolverLCAO::out_hsR_interval != 0))) + if (hsolver::HSolverLCAO::out_mat_hsR) { ModuleIO::output_HS_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 } - } - if (hsolver::HSolverLCAO::out_mat_t) - { - if (!(GlobalV::CALCULATION == "md" && (istep % hsolver::HSolverLCAO::out_hsR_interval != 0))) + if (hsolver::HSolverLCAO::out_mat_t) { ModuleIO::output_T_R(istep, this->UHM); // LiuXh add 2019-07-15 } - } - if (hsolver::HSolverLCAO::out_mat_dh) - { - if (!(GlobalV::CALCULATION == "md" && (istep % hsolver::HSolverLCAO::out_hsR_interval != 0))) + if (hsolver::HSolverLCAO::out_mat_dh) { ModuleIO::output_dH_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 } - } - // add by jingan for out r_R matrix 2019.8.14 - if (INPUT.out_mat_r) - { - cal_r_overlap_R r_matrix; - r_matrix.init(*this->LOWF.ParaV); - - if (hsolver::HSolverLCAO::out_mat_hsR) - { - r_matrix.out_rR_other(istep, this->LM.output_R_coor); - } - else + // add by jingan for out r_R matrix 2019.8.14 + if (INPUT.out_mat_r) { - r_matrix.out_rR(istep); + cal_r_overlap_R r_matrix; + r_matrix.init(*this->LOWF.ParaV); + + if (hsolver::HSolverLCAO::out_mat_hsR) + { + r_matrix.out_rR_other(istep, this->LM.output_R_coor); + } + else + { + r_matrix.out_rR(istep); + + } } } } @@ -533,14 +612,14 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &info); const char N_char = 'N', T_char = 'T'; - const double one_float[2] = {1.0, 0.0}, zero_float[2] = {0.0, 0.0}; - const complex half_float[2] = {0.5, 0.0}; + const complex one_float = {1.0, 0.0}, zero_float = {0.0, 0.0}; + const complex half_float = {0.5, 0.0}; pzgemm_(&T_char, &T_char, &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float[0], + &one_float, this->LOC.dm_k[ik].c, &one_int, &one_int, @@ -549,7 +628,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float[0], + &zero_float, tmp1, &one_int, &one_int, @@ -560,7 +639,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float[0], + &one_float, tmp1, &one_int, &one_int, @@ -569,7 +648,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float[0], + &zero_float, tmp2, &one_int, &one_int, @@ -580,7 +659,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float[0], + &one_float, Sinv, &one_int, &one_int, @@ -589,7 +668,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float[0], + &zero_float, tmp3, &one_int, &one_int, @@ -600,7 +679,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &GlobalV::NLOCAL, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float[0], + &one_float, tmp3, &one_int, &one_int, @@ -609,7 +688,7 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float[0], + &zero_float, tmp4, &one_int, &one_int, @@ -618,12 +697,12 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() pzgeadd_(&N_char, &GlobalV::NLOCAL, &GlobalV::NLOCAL, - &half_float[0], + &half_float, tmp2, &one_int, &one_int, this->LOC.ParaV->desc, - &half_float[0], + &half_float, tmp4, &one_int, &one_int, @@ -631,12 +710,12 @@ void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() pztranu_(&GlobalV::NLOCAL, &GlobalV::NLOCAL, - &one_float[0], + &one_float, tmp4, &one_int, &one_int, this->LOC.ParaV->desc, - &zero_float[0], + &zero_float, tmp5, &one_int, &one_int, diff --git a/source/module_hamilt_general/hamilt.h b/source/module_hamilt_general/hamilt.h index 13573e9fc2..0e01c75ee8 100644 --- a/source/module_hamilt_general/hamilt.h +++ b/source/module_hamilt_general/hamilt.h @@ -24,14 +24,12 @@ class Hamilt virtual void hPsi(const std::complex *psi_in, std::complex *hpsi, const size_t size) const{return;} virtual void sPsi(const std::complex *psi_in, std::complex *spsi, const size_t size) const{return;} - // core function: return H(k) and S(k) matrixs for direct solving eigenvalues. virtual void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in){return;} virtual void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in){return;} - // used for tddft evolve, added by zhaoht + // used for tddft evolve virtual void matrix_l(MatrixBlock> &hk_in, MatrixBlock> &hk_last_in, MatrixBlock> &sk_in){return;} virtual void matrix_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in){return;} - std::string classname = "none"; int non_first_scf=0; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp index cea2470b32..31ed633313 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp @@ -101,7 +101,6 @@ void LCAO_Matrix::allocate_HS_k(const long &nloc) this->Sloc2.resize(nloc); this->Hloc_fixed2.resize(nloc); this->Hloc2.resize(nloc); - //added by zhaoht for test this->Hloc2_last.resize(nloc); ModuleBase::GlobalFunc::ZEROS(Sloc2.data(),nloc); @@ -597,7 +596,6 @@ void LCAO_Matrix::update_Hloc2(const int &ik) return; } -//added by zhaoht for test void LCAO_Matrix::update_Hl(const int &ik) { #ifdef _OPENMP @@ -610,7 +608,7 @@ void LCAO_Matrix::update_Hl(const int &ik) return; } -//above + void LCAO_Matrix::output_HSk(const char &mtype, std::string &fn) { ModuleBase::TITLE("LCAO_Matrix","output_HSk"); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h index e341af9ca0..3a8731ede4 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h @@ -5,7 +5,7 @@ #include "module_base/global_variable.h" #include "module_base/vector3.h" #include "module_base/complexmatrix.h" -#include "module_orbital/parallel_orbitals.h" +#include "module_basis/module_ao/parallel_orbitals.h" // add by jingan for map<> in 2021-12-2, will be deleted in the future #include "module_base/abfs-vector3_order.h" @@ -23,7 +23,7 @@ class LCAO_Matrix // folding the fixed Hamiltonian (T+Vnl) if // k-point algorithm is used. - void folding_fixedH(const int &ik); + void folding_fixedH(const int &ik, bool cal_syns = false); Parallel_Orbitals *ParaV; @@ -202,7 +202,7 @@ class LCAO_Matrix void print_HSk(const char &mtype, const char &vtype = 'C', const double &accuracy = 1.0e-5, std::ostream &os=std::cout); void update_Hloc(void); void update_Hloc2(const int &ik); - //added by zhaoht for test + void update_Hl(const int &ik); void allocate_HS_R(const int &nnr); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp index 7f9b9ee4ca..05659e9439 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -240,7 +240,14 @@ HamiltLCAO::HamiltLCAO( &(LM_in->SlocR), &(LM_in->Sloc2) ); - this->ops->add(overlap); + if(this->ops == nullptr) + { + this->ops = overlap; + } + else + { + this->ops->add(overlap); + } // kinetic term (), // in general case, target HR is LCAO_Matrix::Hloc_fixedR, while target HK is LCAO_Matrix::Hloc2 @@ -304,8 +311,7 @@ void HamiltLCAO>::matrix(MatrixBlock> } // case for nspin<4, gamma_only -template <> -void HamiltLCAO::matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) +template <> void HamiltLCAO::matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) { auto op = dynamic_cast*>(this->opsd); assert(op != NULL); @@ -327,9 +333,6 @@ void HamiltLCAO::matrix_l(MatrixBlock &hk_in, assert(op != NULL); op->matrixHk_l(hk_in, hk_last_in, sk_in); } - - - template <> void HamiltLCAO::updateHk(const int ik) { ModuleBase::TITLE("HamiltLCAO", "updateHk"); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h index 9ee36602a7..24ab48673c 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h @@ -5,8 +5,8 @@ #include "module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.h" #include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" #include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" -#include "module_gint/gint_gamma.h" -#include "module_gint/gint_k.h" +#include "module_hamilt_lcao/module_gint/gint_gamma.h" +#include "module_hamilt_lcao/module_gint/gint_k.h" #include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" #include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" #include "module_elecstate/potentials/potential_new.h" @@ -52,7 +52,6 @@ template class HamiltLCAO : public Hamilt //void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in) override; void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) override; void matrix_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in) override; - }; } // namespace hamilt diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h index 8fb478c05b..55a8d4d755 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h @@ -64,7 +64,6 @@ class OperatorLCAO : public Operator nullptr}; #endif } - //use for tddft evolve,added by zaotian void matrixHk_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in) { this->get_hls_pointers(); @@ -92,7 +91,6 @@ class OperatorLCAO : public Operator nullptr}; #endif } - /* Function contributeHk() is defined in derived class, for constructing (K) */ virtual void contributeHk(int ik) diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp index b7ffc3c7e8..2a196c1f77 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp @@ -41,7 +41,6 @@ void ELEC_evolve::evolve_psi(const int& istep, psi_laststep->fix_k(ik); if(istep<3){ ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, &(ekb(ik, 0)));} - //added by zhaoht for test else{ ELM.evolve_complex_matrix_1(ik, phm, psi, psi_laststep, &(ekb(ik, 0))); } diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp index cf2a77a378..df572932bd 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp @@ -52,7 +52,7 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, return; } -//added by zhaoht for test +//usenew propagator void Evolve_LCAO_Matrix::evolve_complex_matrix_1(const int& ik, hamilt::Hamilt* p_hamilt, psi::Psi>* psi_k, @@ -82,7 +82,7 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix_1(const int& ik, return; } -//test above + void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, hamilt::Hamilt* p_hamilt, std::complex* psi_k, @@ -215,7 +215,7 @@ void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, int lwork = 3 * GlobalV::NLOCAL - 1; // tmp std::complex* work = new std::complex[lwork]; ModuleBase::GlobalFunc::ZEROS(work, lwork); - int ipiv[GlobalV::NLOCAL]; + int* ipiv = new int[GlobalV::NLOCAL]; LapackConnector::zgetrf(GlobalV::NLOCAL, GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, &info); LapackConnector::zgetri(GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, work, lwork, &info); @@ -363,7 +363,7 @@ void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, */ delete[] work; - // delete[] ipiv; + delete[] ipiv; return; } @@ -391,7 +391,7 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( complex* Htmp = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); - + complex* U_operator = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); @@ -404,20 +404,19 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( // (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - complex* psi_not_norm = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(psi_not_norm, this->ParaV->nloc); - /// @brief apply U_operator to the wave function of the previous step for new wave function /// @input U_operator, psi_k_laststep - /// @output psi_k, psi_not_norm (used by norm_wfc) - U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k, psi_not_norm); + /// @output psi_k + U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k); + + // (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /// @brief normalize psi_k /// @input Stmp, psi_not_norm, psi_k, print_matrix /// @output psi_k - norm_wfc(nband, nlocal, Stmp, psi_not_norm, psi_k, print_matrix); + norm_wfc(nband, nlocal, Stmp, psi_k, print_matrix); // (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @@ -430,12 +429,10 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( delete[] Stmp; delete[] Htmp; delete[] U_operator; - delete[] psi_not_norm; - return; } -//added by zhaoht for test + void Evolve_LCAO_Matrix::using_ScaLAPACK_complex_1( const int nband, const int nlocal, @@ -490,20 +487,19 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex_1( // (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - complex* psi_not_norm = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(psi_not_norm, this->ParaV->nloc); - /// @brief apply U_operator to the wave function of the previous step for new wave function /// @input U_operator, psi_k_laststep - /// @output psi_k, psi_not_norm (used by norm_wfc) - U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k, psi_not_norm); + /// @output psi_k + U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k); + + // (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /// @brief normalize psi_k /// @input Stmp, psi_not_norm, psi_k, print_matrix /// @output psi_k - norm_wfc(nband, nlocal, Stmp, psi_not_norm, psi_k, print_matrix); + norm_wfc(nband, nlocal, Stmp, psi_k, print_matrix); // (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> @@ -516,11 +512,8 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex_1( delete[] Stmp; delete[] Htmp; delete[] U_operator; - delete[] psi_not_norm; - return; } -//test above void Evolve_LCAO_Matrix::compute_U_operator( const int nband, @@ -567,8 +560,8 @@ void Evolve_LCAO_Matrix::compute_U_operator( // ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // (2) compute Numerator & Denominator by GEADD - // Numerator = Stmp - para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt - // Denominator = Stmp + para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt + // Numerator = Stmp - i*para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt + // Denominator = Stmp + i*para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt complex alpha = {1.0, 0.0}; complex beta1 = {0.0, -0.25 * INPUT.mdp.md_dt}; complex beta2 = {0.0, 0.25 * INPUT.mdp.md_dt}; @@ -621,7 +614,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( //->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> // (3) Next, invert Denominator int* ipiv = new int[this->ParaV->nloc]; - int info; + int info = 0; // (3.1) compute ipiv ScalapackConnector::getrf( nlocal, @@ -631,7 +624,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( 1, this->ParaV->desc, ipiv, - info + &info ); int lwork = -1; int liwotk = -1; @@ -649,7 +642,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( &lwork, iwork.data(), &liwotk, - info + &info ); lwork = work[0].real(); work.resize(lwork, 0); @@ -667,7 +660,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( &lwork, iwork.data(), &liwotk, - info + &info ); assert(0 == info); @@ -676,7 +669,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( // (4) U_operator = Denominator * Numerator; ScalapackConnector::gemm( 'N', - 'T', + 'N', nlocal, nlocal, nlocal, @@ -695,7 +688,7 @@ void Evolve_LCAO_Matrix::compute_U_operator( 1, this->ParaV->desc ); - //zaotian added for test + if (print_matrix) { GlobalV::ofs_running << " fenmu^-1:" << endl; @@ -749,50 +742,30 @@ void Evolve_LCAO_Matrix::U_to_wfc( const int nlocal, const std::complex* U_operator, const std::complex* psi_k_laststep, - std::complex* psi_k, - std::complex* psi_not_norm) const + std::complex* psi_k) const { - complex* psi_not_norm_trans = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(psi_not_norm_trans, this->ParaV->nloc); ScalapackConnector::gemm( - 'T', - 'T', - nband, + 'N', + 'N', nlocal, + nband, nlocal, 1.0, - psi_k_laststep, - 1, - 1, - this->ParaV->desc_wfc, U_operator, 1, 1, this->ParaV->desc, - 0.0, - psi_not_norm, - 1, - 1, - this->ParaV->desc - ); - ScalapackConnector::tranu( - nlocal, - nlocal, - 1.0, - psi_not_norm, + psi_k_laststep, 1, 1, - this->ParaV->desc, + this->ParaV->desc_wfc, 0.0, - psi_not_norm_trans, + psi_k, 1, 1, - this->ParaV->desc + this->ParaV->desc_wfc ); - BlasConnector::copy(this->ParaV->nloc_wfc, psi_not_norm_trans, 1, psi_k, 1); - - delete[] psi_not_norm_trans; } @@ -800,57 +773,38 @@ void Evolve_LCAO_Matrix::norm_wfc( const int nband, const int nlocal, const std::complex* Stmp, - const std::complex* psi_not_norm, std::complex* psi_k, const int print_matrix) const { - complex* tmp1 = new complex[this->ParaV->nloc]; - complex* tmp2 = new complex[this->ParaV->nloc]; - complex* tmp3 = new complex[this->ParaV->nloc_wfc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp2, this->ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp3, this->ParaV->nloc_wfc); - + complex* tmp1 = new complex[this->ParaV->nloc_wfc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); + complex* Cij = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Cij, this->ParaV->nloc); - - + ScalapackConnector::gemm( - 'T', 'N', - nband, + 'N', nlocal, + nband, nlocal, 1.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, Stmp, 1, 1, this->ParaV->desc, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, 0.0, tmp1, 1, 1, - this->ParaV->desc + this->ParaV->desc_wfc ); - ScalapackConnector::tranu( - nlocal, - nlocal, - 1.0, - tmp1, - 1, - 1, - this->ParaV->desc, - 0.0, - tmp2, - 1, - 1, - this->ParaV->desc - ); - BlasConnector::copy(this->ParaV->nloc_wfc, tmp2, 1, tmp3, 1); + + ScalapackConnector::gemm( 'C', 'N', @@ -862,7 +816,7 @@ void Evolve_LCAO_Matrix::norm_wfc( 1, 1, this->ParaV->desc_wfc, - tmp3, + tmp1, 1, 1, this->ParaV->desc_wfc, @@ -915,18 +869,19 @@ void Evolve_LCAO_Matrix::norm_wfc( // std::cout << "nlocal" << nlocal << std::endl; // std::cout << "GlobalV::NLOCAL" << GlobalV::NLOCAL << std::endl; + BlasConnector::copy(this->ParaV->nloc_wfc, psi_k, 1, tmp1, 1); ScalapackConnector::gemm( - 'T', 'N', - GlobalV::NLOCAL, + 'N', + nlocal, nband, nband, 1.0, - psi_not_norm, + tmp1, 1, 1, - this->ParaV->desc, + this->ParaV->desc_wfc, Cij, 1, 1, @@ -938,6 +893,7 @@ void Evolve_LCAO_Matrix::norm_wfc( this->ParaV->desc_wfc ); + if (print_matrix) { GlobalV::ofs_running << " Cij:" << endl; @@ -945,27 +901,11 @@ void Evolve_LCAO_Matrix::norm_wfc( { for (int j = 0; j < this->ParaV->nrow; j++) { - GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" << Cij[i * this->ParaV->ncol + j].imag() << "i "; + GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" << Cij[i * this->ParaV->ncol_bands + j].imag() << "i "; } GlobalV::ofs_running << endl; } GlobalV::ofs_running << endl; - // GlobalV::ofs_running << " psi_k_laststep:" << endl; - // for (int i = 0; i < this->ParaV->ncol_bands; i++) - // { - // for (int j = 0; j < this->ParaV->nrow; j++) - // { - // double aa, bb; - // aa = psi_k_laststep[i * this->ParaV->ncol + j].real(); - // bb = psi_k_laststep[i * this->ParaV->ncol + j].imag(); - // if (abs(aa) < 1e-8) - // aa = 0.0; - // if (abs(bb) < 1e-8) - // bb = 0.0; - // GlobalV::ofs_running << aa << "+" << bb << "i "; - // } - // GlobalV::ofs_running << endl; - // } GlobalV::ofs_running << endl; GlobalV::ofs_running << " psi_k:" << endl; for (int i = 0; i < this->ParaV->ncol_bands; i++) @@ -990,8 +930,8 @@ void Evolve_LCAO_Matrix::norm_wfc( for (int j = 0; j < this->ParaV->ncol; j++) { double aa, bb; - aa = psi_not_norm[i * this->ParaV->ncol + j].real(); - bb = psi_not_norm[i * this->ParaV->ncol + j].imag(); + aa = tmp1[i * this->ParaV->ncol + j].real(); + bb = tmp1[i * this->ParaV->ncol + j].imag(); if (abs(aa) < 1e-8) aa = 0.0; if (abs(bb) < 1e-8) @@ -1002,29 +942,10 @@ void Evolve_LCAO_Matrix::norm_wfc( } GlobalV::ofs_running << endl; GlobalV::ofs_running << endl; - // GlobalV::ofs_running << " psi_k nlocal*nlocal transpose:" << endl; - // for (int i = 0; i < this->ParaV->ncol; i++) - // { - // for (int j = 0; j < this->ParaV->ncol; j++) - // { - // double aa, bb; - // aa = psi_not_norm_trans[i * this->ParaV->ncol + j].real(); - // bb = psi_not_norm_trans[i * this->ParaV->ncol + j].imag(); - // if (abs(aa) < 1e-8) - // aa = 0.0; - // if (abs(bb) < 1e-8) - // bb = 0.0; - // GlobalV::ofs_running << aa << "+" << bb << "i "; - // } - // GlobalV::ofs_running << endl; - // } - // GlobalV::ofs_running << endl; } delete[] tmp1; - delete[] tmp2; - delete[] tmp3; delete[] Cij; } @@ -1038,52 +959,33 @@ void Evolve_LCAO_Matrix::compute_ekb( double* ekb) const { - complex* tmp1 = new complex[this->ParaV->nloc]; - complex* tmp2 = new complex[this->ParaV->nloc]; - complex* tmp3 = new complex[this->ParaV->nloc_wfc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp2, this->ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp3, this->ParaV->nloc_wfc); + complex* tmp1 = new complex[this->ParaV->nloc_wfc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); complex* Eij = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Eij, this->ParaV->nloc); ScalapackConnector::gemm( - 'T', 'N', - nband, + 'N', nlocal, + nband, nlocal, 1.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, Htmp, 1, 1, this->ParaV->desc, - 0.0, - tmp1, - 1, - 1, - this->ParaV->desc - ); - ScalapackConnector::tranu( - nlocal, - nlocal, - 1.0, - tmp1, + psi_k, 1, 1, - this->ParaV->desc, + this->ParaV->desc_wfc, 0.0, - tmp2, + tmp1, 1, 1, - this->ParaV->desc + this->ParaV->desc_wfc ); - BlasConnector::copy(this->ParaV->nloc_wfc, tmp2, 1, tmp3, 1); ScalapackConnector::gemm( 'C', @@ -1096,7 +998,7 @@ void Evolve_LCAO_Matrix::compute_ekb( 1, 1, this->ParaV->desc_wfc, - tmp3, + tmp1, 1, 1, this->ParaV->desc_wfc, @@ -1144,12 +1046,7 @@ void Evolve_LCAO_Matrix::compute_ekb( MPI_Comm_rank(this->ParaV->comm_2D, &myid); double* Eii = new double[nband]; - - - for (int i = 0; i < nband; i++) - { - Eii[i] = 0.0; - } + ModuleBase::GlobalFunc::ZEROS(Eii, nband); for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) { for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) @@ -1183,8 +1080,6 @@ void Evolve_LCAO_Matrix::compute_ekb( info = MPI_Allreduce(Eii, ekb, nband, MPI_DOUBLE, MPI_SUM, this->ParaV->comm_2D); delete[] tmp1; - delete[] tmp2; - delete[] tmp3; delete[] Eij; delete[] Eii; } diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h index 6d84a29b38..83bb1d40dd 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h @@ -23,13 +23,11 @@ class Evolve_LCAO_Matrix psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, double* ekb) const; - //added by zhaoht for test void evolve_complex_matrix_1(const int& ik, hamilt::Hamilt* p_hamilt, psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, double* ekb) const; - //above private: // LCAO_Matrix* LM; @@ -48,7 +46,6 @@ class Evolve_LCAO_Matrix hamilt::Hamilt* p_hamilt, std::complex* psi_k, double* ekb) const; -//added by zhaoht for test void using_ScaLAPACK_complex_1( const int nband, const int nlocal, @@ -56,7 +53,6 @@ class Evolve_LCAO_Matrix hamilt::Hamilt* p_hamilt, std::complex* psi_k, double* ekb) const; -//above void compute_U_operator( const int nband, @@ -71,14 +67,12 @@ class Evolve_LCAO_Matrix const int nlocal, const std::complex* U_operator, const std::complex* psi_k_laststep, - std::complex* psi_k, - std::complex* psi_not_norm) const; + std::complex* psi_k) const; void norm_wfc( const int nband, const int nlocal, const std::complex* Stmp, - const std::complex* psi_not_norm, std::complex* psi_k, const int print_matrix) const; From ad00f67954ee1da47e29ef1e0e10fcded178b5c0 Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Mon, 17 Apr 2023 21:13:52 +0800 Subject: [PATCH 3/8] Add files via upload --- source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp index 05659e9439..ff394cb625 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -317,6 +317,7 @@ template <> void HamiltLCAO::matrix(MatrixBlock &hk_in, MatrixBl assert(op != NULL); op->matrixHk(hk_in, sk_in); } +template <> void HamiltLCAO>::matrix_l(MatrixBlock> &hk_in, MatrixBlock> &hk_last_in, MatrixBlock> &sk_in) @@ -325,6 +326,7 @@ void HamiltLCAO>::matrix_l(MatrixBlock assert(op != NULL); op->matrixHk_l(hk_in, hk_last_in, sk_in); } +template <> void HamiltLCAO::matrix_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in) From 32b2f5d577308d37a245f70d9dcb3d6a72d0103a Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Tue, 18 Apr 2023 19:29:34 +0800 Subject: [PATCH 4/8] Modified the code's implementation approach. I have modified the implementation approach of the code, and this one involves less changes to the original code. It also includes handling for multiple k-points. --- module_esolver/esolver_ks_lcao_tddft.cpp | 779 +++++++++++++ module_esolver/esolver_ks_lcao_tddft.h | 38 + module_hamilt_general/hamilt.h | 43 + .../hamilt_lcaodft/LCAO_matrix.cpp | 1002 ++++++++++++++++ .../hamilt_lcaodft/LCAO_matrix.h | 221 ++++ .../hamilt_lcaodft/hamilt_lcao.cpp | 352 ++++++ .../hamilt_lcaodft/hamilt_lcao.h | 58 + .../operator_lcao/operator_lcao.cpp | 189 +++ .../operator_lcao/operator_lcao.h | 101 ++ .../module_tddft/ELEC_evolve.cpp | 49 + module_hamilt_lcao/module_tddft/ELEC_evolve.h | 51 + .../module_tddft/LCAO_evolve.cpp | 1022 +++++++++++++++++ module_hamilt_lcao/module_tddft/LCAO_evolve.h | 79 ++ 13 files changed, 3984 insertions(+) create mode 100644 module_esolver/esolver_ks_lcao_tddft.cpp create mode 100644 module_esolver/esolver_ks_lcao_tddft.h create mode 100644 module_hamilt_general/hamilt.h create mode 100644 module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp create mode 100644 module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h create mode 100644 module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp create mode 100644 module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h create mode 100644 module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp create mode 100644 module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h create mode 100644 module_hamilt_lcao/module_tddft/ELEC_evolve.cpp create mode 100644 module_hamilt_lcao/module_tddft/ELEC_evolve.h create mode 100644 module_hamilt_lcao/module_tddft/LCAO_evolve.cpp create mode 100644 module_hamilt_lcao/module_tddft/LCAO_evolve.h diff --git a/module_esolver/esolver_ks_lcao_tddft.cpp b/module_esolver/esolver_ks_lcao_tddft.cpp new file mode 100644 index 0000000000..4276cb5fb3 --- /dev/null +++ b/module_esolver/esolver_ks_lcao_tddft.cpp @@ -0,0 +1,779 @@ +#include "esolver_ks_lcao_tddft.h" + +#include "module_io/cal_r_overlap_R.h" +#include "module_io/dm_io.h" +#include "module_io/rho_io.h" +#include "module_io/dipole_io.h" +#include "module_io/write_HS_R.h" +#include "module_io/write_HS.h" + +//--------------temporary---------------------------- +#include "module_base/blas_connector.h" +#include "module_base/global_function.h" +#include "module_base/scalapack_connector.h" +#include "module_elecstate/module_charge/symmetry_rho.h" +#include "module_elecstate/occupy.h" +#include "module_hamilt_lcao/module_tddft/ELEC_evolve.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_io/print_info.h" + +//-----HSolver ElecState Hamilt-------- +#include "module_elecstate/elecstate_lcao.h" +#include "module_elecstate/elecstate_lcao_tddft.h" +#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" +#include "module_hsolver/hsolver_lcao.h" +#include "module_psi/psi.h" + +//-----force& stress------------------- +#include "module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h" + +//--------------------------------------------------- + +namespace ModuleESolver +{ + +ESolver_KS_LCAO_TDDFT::ESolver_KS_LCAO_TDDFT() +{ + classname = "ESolver_KS_LCAO_TDDFT"; + basisname = "LCAO"; +} +ESolver_KS_LCAO_TDDFT::~ESolver_KS_LCAO_TDDFT() +{ + // this->orb_con.clear_after_ions(GlobalC::UOT, GlobalC::ORB, GlobalV::deepks_setorb, GlobalC::ucell.infoNL.nproj); + delete psi_laststep; + for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ + delete Hk_laststep[ik];} + delete Hk_laststep; +} + +void ESolver_KS_LCAO_TDDFT::Init(Input& inp, UnitCell& ucell) +{ + ESolver_KS::Init(inp, ucell); + + // Initialize the FFT. + // this function belongs to cell LOOP + + // output is GlobalC::ppcell.vloc 3D local pseudopotentials + // without structure factors + // this function belongs to cell LOOP + GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, GlobalC::rhopw); + + if (this->pelec == nullptr) + { + this->pelec = new elecstate::ElecStateLCAO_TDDFT(&(chr), + &(GlobalC::kv), + GlobalC::kv.nks, + &(this->LOC), + &(this->UHM), + &(this->LOWF)); + } + + //------------------init Basis_lcao---------------------- + // Init Basis should be put outside of Ensolver. + // * reading the localized orbitals/projectors + // * construct the interpolation tables. + this->Init_Basis_lcao(this->orb_con, inp, ucell); + //------------------init Basis_lcao---------------------- + + //------------------init Hamilt_lcao---------------------- + // * allocate H and S matrices according to computational resources + // * set the 'trace' between local H/S and global H/S + this->LM.divide_HS_in_frag(GlobalV::GAMMA_ONLY_LOCAL, orb_con.ParaV); + //------------------init Hamilt_lcao---------------------- + + // pass Hamilt-pointer to Operator + this->UHM.genH.LM = this->UHM.LM = &this->LM; + // pass basis-pointer to EState and Psi + this->LOC.ParaV = this->LOWF.ParaV = this->LM.ParaV; + + // init Psi, HSolver, ElecState, Hamilt + if (this->phsol == nullptr) + { + this->phsol = new hsolver::HSolverLCAO(this->LOWF.ParaV); + this->phsol->method = GlobalV::KS_SOLVER; + } + + // Inititlize the charge density. + this->pelec->charge->allocate(GlobalV::NSPIN, GlobalC::rhopw->nrxx, GlobalC::rhopw->npw); + + // Initializee the potential. + this->pelec->pot = new elecstate::Potential(GlobalC::rhopw, + &GlobalC::ucell, + &(GlobalC::ppcell.vloc), + &(GlobalC::sf.strucFac), + &(GlobalC::en.etxc), + &(GlobalC::en.vtxc)); + this->pelec_td = dynamic_cast(this->pelec); +} + +void ESolver_KS_LCAO_TDDFT::eachiterinit(const int istep, const int iter) +{ + // mohan add 2010-07-16 + // used for pulay mixing. + if (iter == 1) + GlobalC::CHR_MIX.reset(); + + // mohan update 2012-06-05 + GlobalC::en.deband_harris = GlobalC::en.delta_e(this->pelec); + + // mohan move it outside 2011-01-13 + // first need to calculate the weight according to + // electrons number. + // mohan add iter > 1 on 2011-04-02 + // because the GlobalC::en.ekb has not value now. + // so the smearing can not be done. + // if (iter > 1 && istep <= 1 && GlobalV::ocp == 0) + // Occupy::calculate_weights(); + + if (GlobalC::wf.init_wfc == "file") + { + if (iter == 1) + { + std::cout << " WAVEFUN -> CHARGE " << std::endl; + + // The occupation should be read in together. + // Occupy::calculate_weights(); //mohan add 2012-02-15 + + // calculate the density matrix using read in wave functions + // and the ncalculate the charge density on grid. + if (this->psi != nullptr) + { + if (istep >= 2) + { + this->pelec_td->psiToRho_td(this->psi[0]); + } + else + { + this->pelec_td->psiToRho(this->psi[0]); + } + } + else + { + this->pelec_td->psiToRho(this->psid[0]); + } + + // calculate the local potential(rho) again. + // the grid integration will do in later grid integration. + + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + // a puzzle remains here. + // if I don't renew potential, + // The scf_thr is very small. + // OneElectron, Hartree and + // Exc energy are all correct + // except the band energy. + // + // solved by mohan 2010-09-10 + // there are there rho here: + // rho1: formed by read in orbitals. + // rho2: atomic rho, used to construct H + // rho3: generated by after diagonalize + // here converged because rho3 and rho1 + // are very close. + // so be careful here, make sure + // rho1 and rho2 are the same rho. + // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + this->pelec->pot->init_pot(istep, this->pelec->charge); + GlobalC::en.delta_escf(this->pelec); + } + } + + if (!GlobalV::GAMMA_ONLY_LOCAL) + { + this->UHM.GK.renew(); + } +} + +void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) +{ + + pelec->charge->save_rho_before_sum_band(); + + if (GlobalV::ESOLVER_TYPE == "tddft" && istep >= 2 && !GlobalV::GAMMA_ONLY_LOCAL) + { + ELEC_evolve::evolve_psi(istep, this->p_hamilt, this->LOWF, this->psi, this->psi_laststep, this->Hk_laststep, this->pelec_td->ekb); + this->pelec_td->psiToRho_td(this->psi[0]); + // this->pelec_td->psiToRho(this->psi[0]); + } + // using HSolverLCAO::solve() + else if (this->phsol != nullptr) + { + // reset energy + this->pelec_td->eband = 0.0; + this->pelec_td->demet = 0.0; + this->pelec_td->ef = 0.0; + GlobalC::en.ef_up = 0.0; + GlobalC::en.ef_dw = 0.0; + if (this->psi != nullptr) + { + this->phsol->solve(this->p_hamilt, this->psi[0], this->pelec_td, GlobalV::KS_SOLVER); + } + else if (this->psid != nullptr) + { + this->phsol->solve(this->p_hamilt, this->psid[0], this->pelec_td, GlobalV::KS_SOLVER); + } + } + else + { + ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "HSolver has not been initialed!"); + } + + if (iter == 1 && istep <= 2) + { + GlobalV::ofs_running + << "------------------------------------------------------------------------------------------------" + << endl; + GlobalV::ofs_running << "occupation : " << endl; + GlobalV::ofs_running << "ik iband occ " << endl; + GlobalV::ofs_running << std::setprecision(6); + GlobalV::ofs_running << std::setiosflags(ios::showpoint); + for (int ik = 0; ik < GlobalC::kv.nks; ik++) + { + for (int ib = 0; ib < GlobalV::NBANDS; ib++) + { + std::setprecision(6); + GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " " << this->pelec_td->wg(ik, ib) << endl; + } + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running + << "------------------------------------------------------------------------------------------------" + << endl; + } + + // transform energy for print + GlobalC::en.eband = this->pelec_td->eband; + GlobalC::en.demet = this->pelec_td->demet; + GlobalC::en.ef = this->pelec_td->ef; + + // (3) sum bands to calculate charge density + // if (istep <= 1 ) Occupy::calculate_weights(); + + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) + { + this->pelec_td->print_band(ik, GlobalC::en.printe, iter); + } + + // (4) mohan add 2010-06-24 + // using new charge density. + GlobalC::en.calculate_harris(); + + // (5) symmetrize the charge density + if (istep <= 1) + { + Symmetry_rho srho; + for (int is = 0; is < GlobalV::NSPIN; is++) + { + srho.begin(is, *(pelec->charge), GlobalC::rhopw, GlobalC::Pgrid, GlobalC::symm); + } + } + + // (6) compute magnetization, only for spin==2 + GlobalC::ucell.magnet.compute_magnetization(pelec->charge, pelec->nelec_spin.data()); + + // (7) calculate delta energy + GlobalC::en.deband = GlobalC::en.delta_e(this->pelec); +} + +void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) +{ + //print Hamiltonian and Overlap matrix + if (this->conv_elec) + { + if (!GlobalV::GAMMA_ONLY_LOCAL) + { + this->UHM.GK.renew(true); + } + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) + { + if(hsolver::HSolverLCAO::out_mat_hs) + { + this->p_hamilt->updateHk(ik); + } + bool bit = false; // LiuXh, 2017-03-21 + // if set bit = true, there would be error in soc-multi-core calculation, noted by zhengdy-soc + if (this->psi != nullptr) + { + hamilt::MatrixBlock> h_mat, s_mat; + this->p_hamilt->matrix(h_mat, s_mat); + ModuleIO::saving_HS(h_mat.p, + s_mat.p, + bit, + hsolver::HSolverLCAO::out_mat_hs, + "data-" + std::to_string(ik), + this->LOWF.ParaV[0], + 1); // LiuXh, 2017-03-21 + } + else if (this->psid != nullptr) + { + hamilt::MatrixBlock h_mat, s_mat; + this->p_hamilt->matrix(h_mat, s_mat); + ModuleIO::saving_HS(h_mat.p, + s_mat.p, + bit, + hsolver::HSolverLCAO::out_mat_hs, + "data-" + std::to_string(ik), + this->LOWF.ParaV[0], + 1); // LiuXh, 2017-03-21 + } + } + } + + if (this->conv_elec) + { + if (elecstate::ElecStateLCAO::out_wfc_lcao) + { + elecstate::ElecStateLCAO::out_wfc_flag = 1; + } + for (int ik = 0; ik < GlobalC::kv.nks; ik++) + { + if (this->psi != nullptr) + { + this->psi[0].fix_k(ik); + this->pelec->print_psi(this->psi[0]); + } + else + { + this->psid[0].fix_k(ik); + this->pelec->print_psi(this->psid[0]); + } + } + elecstate::ElecStateLCAO::out_wfc_flag = 0; + } + + // (9) Calculate new potential according to new Charge Density. + + if (!this->conv_elec) + { + if(GlobalV::NSPIN==4) GlobalC::ucell.cal_ux(); + this->pelec->pot->update_from_charge(this->pelec->charge, &GlobalC::ucell); + GlobalC::en.delta_escf(this->pelec); + } + else + { + GlobalC::en.cal_converged(this->pelec); + } + + // store wfc and Hk laststep + if (istep >= 1 && this->conv_elec) + { + if (this->psi_laststep == nullptr) +#ifdef __MPI + this->psi_laststep = new psi::Psi>(GlobalC::kv.nks, + this->LOWF.ParaV->ncol_bands, + this->LOWF.ParaV->nrow, + nullptr); +#else + this->psi_laststep + = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); +#endif + if (this->Hk_laststep == nullptr){ + this->Hk_laststep = new std::complex*[GlobalC::kv.nks]; + for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ + this->Hk_laststep[ik] = new std::complex[this->LOC.ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Hk_laststep[ik], this->LOC.ParaV->nloc); + } + } + + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) + { + this->psi->fix_k(ik); + this->psi_laststep->fix_k(ik); + int size0 = psi->get_nbands() * psi->get_nbasis(); + for (int index = 0; index < size0; ++index) + psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; + //use for new propagator + this->p_hamilt->updateHk(ik); + //store Hk laststep + hamilt::MatrixBlock> h_mat, s_mat; + this->p_hamilt->matrix(h_mat, s_mat); + BlasConnector::copy(this->LOC.ParaV->nloc, h_mat.p, 1, Hk_laststep[ik], 1); + } + + + if (istep > 1 && ELEC_evolve::td_edm == 0) + this->cal_edm_tddft(); + } + + if (this->conv_elec) + { + GlobalV::ofs_running + << "------------------------------------------------------------------------------------------------" + << endl; + GlobalV::ofs_running << "Eii : " << endl; + GlobalV::ofs_running << "ik iband Eii (eV)" << endl; + GlobalV::ofs_running << std::setprecision(6); + GlobalV::ofs_running << std::setiosflags(ios::showpoint); + for (int ik = 0; ik < GlobalC::kv.nks; ik++) + { + for (int ib = 0; ib < GlobalV::NBANDS; ib++) + { + GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " " + << this->pelec_td->ekb(ik, ib) * ModuleBase::Ry_to_eV << endl; + } + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running + << "------------------------------------------------------------------------------------------------" + << endl; + } +} + +void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) +{ + // if (this->conv_elec || iter == GlobalV::SCF_NMAX) + // { + //-------------------------------------- + // 1. output charge density for converged, + // 0 means don't need to consider iter, + //-------------------------------------- + + for (int is = 0; is < GlobalV::NSPIN; is++) + { + const int precision = 3; + std::stringstream ssc; + ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG.cube"; + double& ef_tmp = GlobalC::en.get_ef(is,GlobalV::TWO_EFERMI); + ModuleIO::write_rho( +#ifdef __MPI + GlobalC::bigpw->bz, + GlobalC::bigpw->nbz, + GlobalC::rhopw->nplane, + GlobalC::rhopw->startz_current, +#endif + pelec->charge->rho_save[is], + is, + GlobalV::NSPIN, + 0, + ssc.str(), + GlobalC::rhopw->nx, + GlobalC::rhopw->ny, + GlobalC::rhopw->nz, + ef_tmp, + &(GlobalC::ucell), + precision); + + if (ELEC_evolve::out_dipole == 1) + { + std::stringstream ss_dipole; + ss_dipole << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DIPOLE"; + ModuleIO::write_dipole(pelec->charge->rho_save[is], is, istep, ss_dipole.str()); + } + + std::stringstream ssd; + if (GlobalV::GAMMA_ONLY_LOCAL) + { + ssd << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DM"; + } + else + { + ssd << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DM_R"; + } + + ModuleIO::write_dm( +#ifdef __MPI + GlobalC::GridT.trace_lo, +#endif + is, + 0, + ssd.str(), + precision, + this->LOC.out_dm, + this->LOC.DM, + ef_tmp, + &(GlobalC::ucell)); + + if (GlobalV::out_pot == 1) // LiuXh add 20200701 + { + std::stringstream ssp; + ssp << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT.cube"; + this->pelec->pot->write_potential(is, 0, ssp.str(), this->pelec->pot->get_effective_v(), precision); + } + } + + if (this->conv_elec) + { + GlobalV::ofs_running << "\n charge density convergence is achieved" << std::endl; + GlobalV::ofs_running << " final etot is " << GlobalC::en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; + } + + if (GlobalV::OUT_LEVEL != "m") + { + // this->pelec->print_eigenvalue(GlobalV::ofs_running); + } + + if (this->conv_elec) + { + // xiaohui add "OUT_LEVEL", 2015-09-16 + if (GlobalV::OUT_LEVEL != "m") + GlobalV::ofs_running << std::setprecision(16); + if (GlobalV::OUT_LEVEL != "m") + GlobalV::ofs_running << " EFERMI = " << GlobalC::en.ef * ModuleBase::Ry_to_eV << " eV" << std::endl; + if (GlobalV::OUT_LEVEL == "ie") + { + GlobalV::ofs_running << " " << GlobalV::global_out_dir << " final etot is " + << GlobalC::en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; + } + } + else + { + GlobalV::ofs_running << " !! convergence has not been achieved @_@" << std::endl; + if (GlobalV::OUT_LEVEL == "ie" || GlobalV::OUT_LEVEL == "m") // xiaohui add "m" option, 2015-09-16 + std::cout << " !! CONVERGENCE HAS NOT BEEN ACHIEVED !!" << std::endl; + } + + if( GlobalV::CALCULATION != "md" || (istep % hsolver::HSolverLCAO::out_hsR_interval == 0)) + { + if (hsolver::HSolverLCAO::out_mat_hsR) + { + ModuleIO::output_HS_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 + } + + if (hsolver::HSolverLCAO::out_mat_t) + { + ModuleIO::output_T_R(istep, this->UHM); // LiuXh add 2019-07-15 + } + + if (hsolver::HSolverLCAO::out_mat_dh) + { + ModuleIO::output_dH_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 + } + + // add by jingan for out r_R matrix 2019.8.14 + if (INPUT.out_mat_r) + { + cal_r_overlap_R r_matrix; + r_matrix.init(*this->LOWF.ParaV); + + if (hsolver::HSolverLCAO::out_mat_hsR) + { + r_matrix.out_rR_other(istep, this->LM.output_R_coor); + } + else + { + r_matrix.out_rR(istep); + + } + } + } +} + +// use the original formula (Hamiltonian matrix) to calculate energy density matrix +void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() +{ + this->LOC.edm_k_tddft.resize(GlobalC::kv.nks); + for (int ik = 0; ik < GlobalC::kv.nks; ++ik) + { +#ifdef __MPI + this->LOC.edm_k_tddft[ik].create(this->LOC.ParaV->ncol, this->LOC.ParaV->nrow); + complex* Htmp = new complex[this->LOC.ParaV->nloc]; + complex* Sinv = new complex[this->LOC.ParaV->nloc]; + complex* tmp1 = new complex[this->LOC.ParaV->nloc]; + complex* tmp2 = new complex[this->LOC.ParaV->nloc]; + complex* tmp3 = new complex[this->LOC.ParaV->nloc]; + complex* tmp4 = new complex[this->LOC.ParaV->nloc]; + complex* tmp5 = new complex[this->LOC.ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Htmp, this->LOC.ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(Sinv, this->LOC.ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp1, this->LOC.ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp2, this->LOC.ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp3, this->LOC.ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp4, this->LOC.ParaV->nloc); + ModuleBase::GlobalFunc::ZEROS(tmp5, this->LOC.ParaV->nloc); + const int inc = 1; + int nrow = this->LOC.ParaV->nrow; + int ncol = this->LOC.ParaV->ncol; + hamilt::MatrixBlock> h_mat, s_mat; + p_hamilt->matrix(h_mat, s_mat); + zcopy_(&this->LOC.ParaV->nloc, h_mat.p, &inc, Htmp, &inc); + zcopy_(&this->LOC.ParaV->nloc, s_mat.p, &inc, Sinv, &inc); + + int* ipiv = new int[this->LOC.ParaV->nloc]; + int info; + const int one_int = 1; + pzgetrf_(&GlobalV::NLOCAL, &GlobalV::NLOCAL, Sinv, &one_int, &one_int, this->LOC.ParaV->desc, ipiv, &info); + + int LWORK = -1, liWORK = -1; + std::vector> WORK(1, 0); + std::vector iWORK(1, 0); + + pzgetri_(&GlobalV::NLOCAL, + Sinv, + &one_int, + &one_int, + this->LOC.ParaV->desc, + ipiv, + WORK.data(), + &LWORK, + iWORK.data(), + &liWORK, + &info); + + LWORK = WORK[0].real(); + WORK.resize(LWORK, 0); + liWORK = iWORK[0]; + iWORK.resize(liWORK, 0); + + pzgetri_(&GlobalV::NLOCAL, + Sinv, + &one_int, + &one_int, + this->LOC.ParaV->desc, + ipiv, + WORK.data(), + &LWORK, + iWORK.data(), + &liWORK, + &info); + + const char N_char = 'N', T_char = 'T'; + const complex one_float = {1.0, 0.0}, zero_float = {0.0, 0.0}; + const complex half_float = {0.5, 0.0}; + pzgemm_(&T_char, + &T_char, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &one_float, + this->LOC.dm_k[ik].c, + &one_int, + &one_int, + this->LOC.ParaV->desc, + Htmp, + &one_int, + &one_int, + this->LOC.ParaV->desc, + &zero_float, + tmp1, + &one_int, + &one_int, + this->LOC.ParaV->desc); + + pzgemm_(&N_char, + &N_char, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &one_float, + tmp1, + &one_int, + &one_int, + this->LOC.ParaV->desc, + Sinv, + &one_int, + &one_int, + this->LOC.ParaV->desc, + &zero_float, + tmp2, + &one_int, + &one_int, + this->LOC.ParaV->desc); + + pzgemm_(&N_char, + &T_char, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &one_float, + Sinv, + &one_int, + &one_int, + this->LOC.ParaV->desc, + Htmp, + &one_int, + &one_int, + this->LOC.ParaV->desc, + &zero_float, + tmp3, + &one_int, + &one_int, + this->LOC.ParaV->desc); + + pzgemm_(&N_char, + &T_char, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &one_float, + tmp3, + &one_int, + &one_int, + this->LOC.ParaV->desc, + this->LOC.dm_k[ik].c, + &one_int, + &one_int, + this->LOC.ParaV->desc, + &zero_float, + tmp4, + &one_int, + &one_int, + this->LOC.ParaV->desc); + + pzgeadd_(&N_char, + &GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &half_float, + tmp2, + &one_int, + &one_int, + this->LOC.ParaV->desc, + &half_float, + tmp4, + &one_int, + &one_int, + this->LOC.ParaV->desc); + + pztranu_(&GlobalV::NLOCAL, + &GlobalV::NLOCAL, + &one_float, + tmp4, + &one_int, + &one_int, + this->LOC.ParaV->desc, + &zero_float, + tmp5, + &one_int, + &one_int, + this->LOC.ParaV->desc); + zcopy_(&this->LOC.ParaV->nloc, tmp5, &inc, this->LOC.edm_k_tddft[ik].c, &inc); + + delete[] Htmp; + delete[] Sinv; + delete[] tmp1; + delete[] tmp2; + delete[] tmp3; + delete[] tmp4; + delete[] tmp5; + delete[] ipiv; +#else + this->LOC.edm_k_tddft[ik].create(this->LOC.ParaV->ncol, this->LOC.ParaV->nrow); + ModuleBase::ComplexMatrix Sinv(GlobalV::NLOCAL, GlobalV::NLOCAL); + ModuleBase::ComplexMatrix Htmp(GlobalV::NLOCAL, GlobalV::NLOCAL); + hamilt::MatrixBlock> h_mat, s_mat; + p_hamilt->matrix(h_mat, s_mat); + // cout<<"hmat "<* WORK = new std::complex[LWORK]; + ModuleBase::GlobalFunc::ZEROS(WORK, LWORK); + int IPIV[GlobalV::NLOCAL]; + + LapackConnector::zgetrf(GlobalV::NLOCAL, GlobalV::NLOCAL, Sinv, GlobalV::NLOCAL, IPIV, &INFO); + LapackConnector::zgetri(GlobalV::NLOCAL, Sinv, GlobalV::NLOCAL, IPIV, WORK, LWORK, &INFO); + + this->LOC.edm_k_tddft[ik] = 0.5 * (Sinv * Htmp * this->LOC.dm_k[ik] + this->LOC.dm_k[ik] * Htmp * Sinv); + delete[] WORK; +#endif + } + return; +} +} // namespace ModuleESolver \ No newline at end of file diff --git a/module_esolver/esolver_ks_lcao_tddft.h b/module_esolver/esolver_ks_lcao_tddft.h new file mode 100644 index 0000000000..6f9da4a185 --- /dev/null +++ b/module_esolver/esolver_ks_lcao_tddft.h @@ -0,0 +1,38 @@ +#ifndef ESOLVER_KS_LCAO_TDDFT_H +#define ESOLVER_KS_LCAO_TDDFT_H +#include "esolver_ks.h" +#include "esolver_ks_lcao.h" +#include "module_basis/module_ao/ORB_control.h" +#include "module_psi/psi.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" +#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" +#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" +#include "module_hamilt_lcao/hamilt_lcaodft/record_adj.h" +#include "module_elecstate/elecstate_lcao_tddft.h" + + +namespace ModuleESolver +{ + +class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO +{ + public: + ESolver_KS_LCAO_TDDFT(); + ~ESolver_KS_LCAO_TDDFT(); + void Init(Input& inp, UnitCell& cell) override; + + psi::Psi>* psi_laststep = nullptr; + std::complex** Hk_laststep = nullptr; + //same as pelec + elecstate::ElecStateLCAO_TDDFT* pelec_td = nullptr; + + protected: + virtual void hamilt2density(const int istep, const int iter, const double ethr) override; + virtual void eachiterinit(const int istep, const int iter) override; + virtual void updatepot(const int istep, const int iter) override; + virtual void afterscf(const int istep) override; + void cal_edm_tddft(); +}; + +} // namespace ModuleESolver +#endif diff --git a/module_hamilt_general/hamilt.h b/module_hamilt_general/hamilt.h new file mode 100644 index 0000000000..65962311fa --- /dev/null +++ b/module_hamilt_general/hamilt.h @@ -0,0 +1,43 @@ +#ifndef MODULEHAMILT_H +#define MODULEHAMILT_H + +#include "matrixblock.h" +#include "module_psi/psi.h" +#include "operator.h" + +#include +#include + +namespace hamilt +{ + +template +class Hamilt +{ + public: + virtual ~Hamilt(){}; + + // for target K point, update consequence of hPsi() and matrix() + virtual void updateHk(const int ik){return;} + + // core function: for solving eigenvalues of Hamiltonian with iterative method + virtual void hPsi(const std::complex *psi_in, std::complex *hpsi, const size_t size) const{return;} + virtual void sPsi(const std::complex *psi_in, std::complex *spsi, const size_t size) const{return;} + + // core function: return H(k) and S(k) matrixs for direct solving eigenvalues. + virtual void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in){return;} + virtual void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in){return;} + + std::string classname = "none"; + + int non_first_scf=0; + + // first node operator, add operations from each operators + Operator, Device>* ops = nullptr; + Operator* opsd = nullptr; + +}; + +} // namespace hamilt + +#endif \ No newline at end of file diff --git a/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp b/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp new file mode 100644 index 0000000000..1a4fb745da --- /dev/null +++ b/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp @@ -0,0 +1,1002 @@ +#include "LCAO_matrix.h" +#include "module_hamilt_lcao/hamilt_lcaodft/global_fp.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_base/tool_threading.h" +#ifdef __DEEPKS +#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h" +#endif + +LCAO_Matrix::LCAO_Matrix() +{ +} + +LCAO_Matrix::~LCAO_Matrix() +{ +} + + +void LCAO_Matrix::divide_HS_in_frag(const bool isGamma, Parallel_Orbitals &pv) +{ + ModuleBase::TITLE("LCAO_Matrix","divide_HS_in_frag"); + + //(1), (2): set up matrix division have been moved into ORB_control + //just pass `ParaV` as pointer is enough + this->ParaV = &pv; + // (3) allocate for S, H_fixed, H, and S_diag + if(isGamma) + { + allocate_HS_gamma(this->ParaV->nloc); + } + else + { + allocate_HS_k(this->ParaV->nloc); + } +#ifdef __DEEPKS + //wenfei 2021-12-19 + //preparation for DeePKS + + if (GlobalV::deepks_out_labels || GlobalV::deepks_scf) + { + //allocate relevant data structures for calculating descriptors + std::vector na; + na.resize(GlobalC::ucell.ntype); + for(int it=0;itSloc.resize(nloc); + this->Hloc_fixed.resize(nloc); + this->Hloc.resize(nloc); + + ModuleBase::GlobalFunc::ZEROS(Sloc.data(),nloc); + ModuleBase::GlobalFunc::ZEROS(Hloc_fixed.data(),nloc); + ModuleBase::GlobalFunc::ZEROS(Hloc.data(),nloc); + + return; +} + + +void LCAO_Matrix::allocate_HS_k(const long &nloc) +{ + ModuleBase::TITLE("LCAO_Matrix","allocate_HS_k"); + + ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"nloc",nloc); + if(nloc==0) return; //mohan fix bug 2012-05-25 + + // because we initilize in the constructor function + // with dimension '1', so here we reconstruct these + // matrices + this->Sloc2.resize(nloc); + this->Hloc_fixed2.resize(nloc); + this->Hloc2.resize(nloc); + + ModuleBase::GlobalFunc::ZEROS(Sloc2.data(),nloc); + ModuleBase::GlobalFunc::ZEROS(Hloc_fixed2.data(),nloc); + ModuleBase::GlobalFunc::ZEROS(Hloc2.data(),nloc); + + return; +} + +void LCAO_Matrix::allocate_HS_R(const int &nnR) +{ + if(GlobalV::NSPIN!=4) + { + this->SlocR.resize(nnR); + if(GlobalV::CALCULATION!="get_S") this->Hloc_fixedR.resize(nnR); + + ModuleBase::GlobalFunc::ZEROS(SlocR.data(), nnR); + if(GlobalV::CALCULATION!="get_S") ModuleBase::GlobalFunc::ZEROS(Hloc_fixedR.data(), nnR); + } + else + { + this->SlocR_soc.resize(nnR); + if(GlobalV::CALCULATION!="get_S") this->Hloc_fixedR_soc.resize(nnR); + + ModuleBase::GlobalFunc::ZEROS(SlocR_soc.data(), nnR); + if(GlobalV::CALCULATION!="get_S") ModuleBase::GlobalFunc::ZEROS(Hloc_fixedR_soc.data(), nnR); + + } + + return; +} + +//------------------------------------------------------ +// DESCRIPTION: +// set 'dtype' matrix element (iw1_all, iw2_all) with +// an input value 'v' +//------------------------------------------------------ +void LCAO_Matrix::set_HSgamma( + const int &iw1_all, // index i for atomic orbital (row) + const int &iw2_all, // index j for atomic orbital (column) + const double &v, // value for matrix element (i,j) + const char &dtype, // type of the matrix + double* HSloc) //input pointer for store the matrix +{ + // use iw1_all and iw2_all to set Hloc + // becareful! The ir and ic may be < 0 !!! + const int ir = this->ParaV->trace_loc_row[ iw1_all ]; + const int ic = this->ParaV->trace_loc_col[ iw2_all ]; + + //const int index = ir * ParaO.ncol + ic; + long index=0; + + // save the matrix as column major format + if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()) + { + index=ic*this->ParaV->nrow+ir; + } + else + { + index=ir*this->ParaV->ncol+ic; + } + + if( index >= this->ParaV->nloc) + { + std::cout << " iw1_all = " << iw1_all << std::endl; + std::cout << " iw2_all = " << iw2_all << std::endl; + std::cout << " ir = " << ir << std::endl; + std::cout << " ic = " << ic << std::endl; + std::cout << " index = " << index << std::endl; + std::cout << " this->ParaV->nloc = " << this->ParaV->nloc << std::endl; + ModuleBase::WARNING_QUIT("LCAO_Matrix","set_HSgamma"); + } + + //using input pointer HSloc + HSloc[index] += v; + + return; +} + +void LCAO_Matrix::set_HSk(const int &iw1_all, const int &iw2_all, const std::complex &v, const char &dtype, const int spin) +{ + // use iw1_all and iw2_all to set Hloc + // becareful! The ir and ic may < 0!!!!!!!!!!!!!!!! + const int ir = this->ParaV->trace_loc_row[ iw1_all ]; + const int ic = this->ParaV->trace_loc_col[ iw2_all ]; + //const int index = ir * this->ParaV->ncol + ic; + long index; + if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()) + { + index=ic*this->ParaV->nrow+ir; + } + else + { + index=ir*this->ParaV->ncol+ic; + } + assert(index < this->ParaV->nloc); + if (dtype=='S')//overlap Hamiltonian. + { + this->Sloc2[index] += v; + } + else if (dtype=='T' || dtype=='N')// kinetic and nonlocal Hamiltonian. + { + this->Hloc_fixed2[index] += v; // because kinetic and nonlocal Hamiltonian matrices are already block-cycle staraged after caculated in lcao_nnr.cpp + // this statement will not be used. + } + else if (dtype=='L') // Local potential Hamiltonian. + { + this->Hloc2[index] += v; + } + else + { + ModuleBase::WARNING_QUIT("LCAO_Matrix","set_HSk"); + } + + return; +} + +void LCAO_Matrix::set_force +( + const int &iw1_all, + const int &iw2_all, + const double& vx, + const double& vy, + const double& vz, + const char &dtype) +{ + // use iw1_all and iw2_all to set Hloc + // becareful! The ir and ic may < 0!!!!!!!!!!!!!!!! + const int ir = this->ParaV->trace_loc_row[ iw1_all ]; + const int ic = this->ParaV->trace_loc_col[ iw2_all ]; + const long index = ir * this->ParaV->ncol + ic; + + if( index >= this->ParaV->nloc) + { + std::cout << " iw1_all = " << iw1_all << std::endl; + std::cout << " iw2_all = " << iw2_all << std::endl; + std::cout << " ir = " << ir << std::endl; + std::cout << " ic = " << ic << std::endl; + std::cout << " index = " << index << std::endl; + std::cout << " this->ParaV->nloc = " << this->ParaV->nloc << std::endl; + ModuleBase::WARNING_QUIT("LCAO_Matrix","set_force"); + } + + if (dtype == 'S') + { + this->DSloc_x[index] += vx; + this->DSloc_y[index] += vy; + this->DSloc_z[index] += vz; + } + else if (dtype == 'T') + { + // notice, the sign is '-', minus. + this->DHloc_fixed_x[index] -= vx; + this->DHloc_fixed_y[index] -= vy; + this->DHloc_fixed_z[index] -= vz; + } + else if (dtype == 'N') + { + this->DHloc_fixed_x[index] += vx; + this->DHloc_fixed_y[index] += vy; + this->DHloc_fixed_z[index] += vz; + } + + return; +} + +void LCAO_Matrix::set_stress +( + const int &iw1_all, + const int &iw2_all, + const double& vx, + const double& vy, + const double& vz, + const char &dtype, + const ModuleBase::Vector3 &dtau) +{ + // use iw1_all and iw2_all to set Hloc + // becareful! The ir and ic may < 0!!!!!!!!!!!!!!!! + const int ir = this->ParaV->trace_loc_row[ iw1_all ]; + const int ic = this->ParaV->trace_loc_col[ iw2_all ]; + const long index = ir * this->ParaV->ncol + ic; + + if( index >= this->ParaV->nloc) + { + std::cout << " iw1_all = " << iw1_all << std::endl; + std::cout << " iw2_all = " << iw2_all << std::endl; + std::cout << " ir = " << ir << std::endl; + std::cout << " ic = " << ic << std::endl; + std::cout << " index = " << index << std::endl; + std::cout << " this->ParaV->nloc = " << this->ParaV->nloc << std::endl; + ModuleBase::WARNING_QUIT("LCAO_Matrix","set_stress"); + } + + if (dtype == 'S') + { + this->DSloc_11[index] += vx * dtau.x; + this->DSloc_12[index] += vx * dtau.y; + this->DSloc_13[index] += vx * dtau.z; + this->DSloc_22[index] += vy * dtau.y; + this->DSloc_23[index] += vy * dtau.z; + this->DSloc_33[index] += vz * dtau.z; + } + else if (dtype == 'T') + { + // notice, the sign is '-', minus. + this->DHloc_fixed_11[index] -= vx * dtau.x; + this->DHloc_fixed_12[index] -= vx * dtau.y; + this->DHloc_fixed_13[index] -= vx * dtau.z; + this->DHloc_fixed_22[index] -= vy * dtau.y; + this->DHloc_fixed_23[index] -= vy * dtau.z; + this->DHloc_fixed_33[index] -= vz * dtau.z; + } + else if (dtype == 'N') + { + this->DHloc_fixed_11[index] += vx * dtau.x; + this->DHloc_fixed_12[index] += vx * dtau.y; + this->DHloc_fixed_13[index] += vx * dtau.z; + this->DHloc_fixed_22[index] += vy * dtau.y; + this->DHloc_fixed_23[index] += vy * dtau.z; + this->DHloc_fixed_33[index] += vz * dtau.z; + } + + return; +} + +void LCAO_Matrix::zeros_HSgamma(const char &mtype) +{ + auto zeros_HSgamma_ker = [&](int num_threads, int thread_id) + { + long long beg, len; + if (mtype=='S') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Sloc.size(), (long long)512, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->Sloc.data() + beg, len); + } + else if (mtype=='T') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc_fixed.size(), (long long)512, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->Hloc_fixed.data() + beg, len); + } + else if (mtype=='H') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc.size(), (long long)512, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->Hloc.data() + beg, len); + } + }; + ModuleBase::OMP_PARALLEL(zeros_HSgamma_ker); + return; +} + +void LCAO_Matrix::zeros_HSk(const char &mtype) +{ + auto zeros_HSk_ker = [&](int num_threads, int thread_id) + { + long long beg, len; + if (mtype=='S') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Sloc2.size(), (long long)256, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->Sloc2.data() + beg, len); + } + else if (mtype=='T') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc_fixed2.size(), (long long)256, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->Hloc_fixed2.data() + beg, len); + } + else if (mtype=='H') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc2.size(), (long long)256, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->Hloc2.data() + beg, len); + } + }; + ModuleBase::OMP_PARALLEL(zeros_HSk_ker); + return; +} + +void LCAO_Matrix::zeros_HSR(const char &mtype) +{ + auto zeros_HSR_ker = [&](int num_threads, int thread_id) + { + long long beg, len; + if(GlobalV::NSPIN!=4) + { + if (mtype=='S') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->SlocR.size(), (long long)512, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->SlocR.data() + beg, len); + } + else if (mtype=='T') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc_fixedR.size(), (long long)512, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->Hloc_fixedR.data() + beg, len); + } + } + else + { + if (mtype=='S') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->SlocR_soc.size(), (long long)256, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->SlocR_soc.data() + beg, len); + } + else if (mtype=='T') + { + ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc_fixedR_soc.size(), (long long)256, beg, len); + ModuleBase::GlobalFunc::ZEROS(this->Hloc_fixedR_soc.data() + beg, len); + } + } + }; + ModuleBase::OMP_PARALLEL(zeros_HSR_ker); + return; +} + +// Peize Lin add vtype='A' 2018-11-30 +void LCAO_Matrix::print_HSk(const char &mtype, const char &vtype, const double &accuracy, std::ostream &os) +{ + ModuleBase::TITLE("LCAO_Matrix","print_HSk"); + if(mtype=='S') os << "Sloc2 matrix" << std::endl; + else if(mtype=='T') os << "Hloc_fixed2 matrix" << std::endl; + else if(mtype=='H') os << "Hloc2 matrix" << std::endl; + else + { + ModuleBase::WARNING_QUIT("LCAO_Matrix::print_HSk","Check input parameter: mtype."); + } + + if(vtype=='C') os << " Output norm." << std::endl; + else if(vtype=='R') os << " Output real part." << std::endl; + else if(vtype=='I') os << " Output imag part." << std::endl; + else if(vtype=='A') os << " Output std::complex." << std::endl; + + + os << std::setprecision(8) << std::endl; + for(int i=0; iParaV->nrow; i++) + { + os << " " ; + for(int j=0; jParaV->ncol; j++) + { + const int index = i * this->ParaV->ncol + j; + if(vtype=='A') + { + std::complex v; + if(mtype=='S') v = Sloc2[index]; + else if(mtype=='T') v = Hloc_fixed2[index]; + else if(mtype=='H') v = Hloc2[index]; + auto threshold = [accuracy]( const double v ){ return abs(v)>accuracy ? v : 0.0; }; + os << '(' << threshold(v.real()) << ',' << threshold(v.imag()) << "\t"; + } + else + { + double v=-888.888;//wrong number + if(vtype=='R') + { + if(mtype=='S') v = Sloc2[index].real(); + else if(mtype=='T') v = Hloc_fixed2[index].real(); + else if(mtype=='H') v = Hloc2[index].real(); + } + else if(vtype=='C') + { + if(mtype=='S') v = sqrt( norm ( Sloc2[index] ) ); + else if(mtype=='T') v = sqrt( norm ( Hloc_fixed2[index] ) ); + else if(mtype=='H') v = sqrt( norm ( Hloc2[index] ) ); + } + else if(vtype=='I') + { + if(mtype=='S') v = Sloc2[index].imag(); + else if(mtype=='T') v = Hloc_fixed2[index].imag(); + else if(mtype=='H') v = Hloc2[index].imag(); + } + + if( abs(v) > accuracy ) + { + // os << std::setw(15) << v; + os << v << "\t"; + } + else + { + // os << std::setw(15) << "0"; + os << "0" << "\t"; + } + } + } + os << std::endl; + } + os << std::endl; + os << std::setprecision(6) << std::endl; + return; +} + + +void LCAO_Matrix::print_HSgamma(const char &mtype, std::ostream &os) +{ + ModuleBase::TITLE("LCAO_Matrix","print_HSgamma"); + + GlobalV::ofs_running << " " << mtype << " matrix" << std::endl; + GlobalV::ofs_running << " nrow=" << this->ParaV->nrow << std::endl; + GlobalV::ofs_running << " ncol=" << this->ParaV->ncol << std::endl; + GlobalV::ofs_running << " element number = " << this->ParaV->ncol << std::endl; + + if (mtype=='S') + { + os << std::setprecision(8); + os << " print Sloc" << std::endl; + for(int i=0; iParaV->ncol+j]; + if( abs(v) > 1.0e-8) + { + os << std::setw(15) << v; + } + else + { + os << std::setw(15) << "0"; + } + }//end j + os << std::endl; + }//end i + } + if (mtype=='T') + { + os << " print Hloc_fixed" << std::endl; + for(int i=0; iParaV->ncol+j]; + if( abs(v) > 1.0e-8) + { + os << std::setw(15) << v; + } + else + { + os << std::setw(15) << "0"; + } + }//end j + os << std::endl; + }//end i + } + if (mtype=='H') + { + os << " print Hloc" << std::endl; + for(int i=0; iParaV->ncol+j]; + if( abs(v) > 1.0e-8) + { + os << std::setw(15) << v; + } + else + { + os << std::setw(15) << "0"; + } + }//end j + os << std::endl; + }//end i + } + + return; +} + +// becareful! Update Hloc, we add new members to it. +void LCAO_Matrix::update_Hloc(void) +{ + ModuleBase::TITLE("LCAO_Matrix","update_Hloc"); +#ifdef _OPENMP +#pragma omp parallel for schedule(static, 1024) +#endif + for (long i=0; iParaV->nloc; i++) + { + Hloc[i] += Hloc_fixed[i]; + } + return; +} + +void LCAO_Matrix::update_Hloc2(const int &ik) +{ + ModuleBase::TITLE("LCAO_Matrix","update_Hloc2"); +#ifdef _OPENMP +#pragma omp parallel for schedule(static, 1024) +#endif + for (long i = 0; i < this->ParaV->nloc; i++) + { + Hloc2[i] += Hloc_fixed2[i]; +#ifdef __DEEPKS + if(GlobalV::deepks_scf) + { + Hloc2[i] += GlobalC::ld.H_V_delta_k[ik][i]; + } +#endif + } + + return; +} + + +void LCAO_Matrix::output_HSk(const char &mtype, std::string &fn) +{ + ModuleBase::TITLE("LCAO_Matrix","output_HSk"); + std::stringstream ss; + ss << GlobalV::global_out_dir << fn; + std::ofstream ofs(ss.str().c_str()); + ofs << GlobalV::NLOCAL << std::endl; + for(int i=0; iParaV->nloc]; + //HR_tr[ix][iy][iz] = new double[this->ParaV->nloc]; + //SlocR_tr[ix][iy][iz] = new double[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Hloc_fixedR_tr[ix][iy][iz], this->ParaV->nloc); + //ModuleBase::GlobalFunc::ZEROS(HR_tr[ix][iy][iz], this->ParaV->nloc); + //ModuleBase::GlobalFunc::ZEROS(SlocR_tr[ix][iy][iz], this->ParaV->nloc); + } + } + } + } + else + { + Hloc_fixedR_tr_soc = new std::complex***[R_x]; + //HR_tr = new double***[R_x]; + //SlocR_tr = new double***[R_x]; + for(int ix=0; ix**[R_y]; + //HR_tr[ix] = new double**[R_y]; + //SlocR_tr[ix] = new double**[R_y]; + for(int iy=0; iy*[R_z]; + //HR_tr[ix][iy] = new double*[R_z]; + //SlocR_tr[ix][iy] = new double*[R_z]; + for(int iz=0; iz[this->ParaV->nloc]; + //HR_tr[ix][iy][iz] = new double[this->ParaV->nloc]; + //SlocR_tr[ix][iy][iz] = new double[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Hloc_fixedR_tr_soc[ix][iy][iz], this->ParaV->nloc); + //ModuleBase::GlobalFunc::ZEROS(HR_tr[ix][iy][iz], this->ParaV->nloc); + //ModuleBase::GlobalFunc::ZEROS(SlocR_tr[ix][iy][iz], this->ParaV->nloc); + } + } + } + } +//std::cout<<"R_x: "<ParaV->nloc: "<ParaV->nloc<ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(HR_tr[ix][iy][iz], this->ParaV->nloc); + } + } + } + } + else + { + HR_tr_soc = new std::complex***[R_x]; + for(int ix=0; ix**[R_y]; + for(int iy=0; iy*[R_z]; + for(int iz=0; iz[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(HR_tr_soc[ix][iy][iz], this->ParaV->nloc); + } + } + } + } + + return; +} + +void LCAO_Matrix::allocate_SlocR_tr(void) +{ + ModuleBase::TITLE("LCAO_Matrix","allocate_SlocR_tr"); + + //int R_x = 10; + //int R_y = 10; + //int R_z = 10; + int R_x = GlobalC::GridD.getCellX(); + int R_y = GlobalC::GridD.getCellY(); + int R_z = GlobalC::GridD.getCellZ(); + + if(GlobalV::NSPIN!=4) + { + SlocR_tr = new double***[R_x]; + for(int ix=0; ixParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(SlocR_tr[ix][iy][iz], this->ParaV->nloc); + } + } + } + } + else + { + SlocR_tr_soc = new std::complex***[R_x]; + for(int ix=0; ix**[R_y]; + for(int iy=0; iy*[R_z]; + for(int iz=0; iz[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(SlocR_tr_soc[ix][iy][iz], this->ParaV->nloc); + } + } + } + } + + return; +} + +void LCAO_Matrix::destroy_Hloc_fixedR_tr(void) +{ + ModuleBase::TITLE("LCAO_Matrix","destroy_Hloc_fixed2_R"); + + //int R_x = 10; + //int R_y = 10; + //int R_z = 10; + int R_x = GlobalC::GridD.getCellX(); + int R_y = GlobalC::GridD.getCellY(); + int R_z = GlobalC::GridD.getCellZ(); + + if(GlobalV::NSPIN!=4) + { + for(int ix=0; ixParaV->trace_loc_row[ iw1_all ]; + const int ic = this->ParaV->trace_loc_col[ iw2_all ]; + +//std::cout<<"ir: "<ParaV->nrow+ir; +//std::cout<<"index: "<ParaV->ncol+ic; +//std::cout<<"index: "<ParaV->nloc: "<ParaV->nloc<ParaV->nloc); +//std::cout<<"Rx: "< &v) +{ + const int ir = this->ParaV->trace_loc_row[ iw1_all ]; + const int ic = this->ParaV->trace_loc_col[ iw2_all ]; + +//std::cout<<"ir: "<ParaV->nrow+ir; +//std::cout<<"index: "<ParaV->ncol+ic; +//std::cout<<"index: "<ParaV->nloc: "<ParaV->nloc<ParaV->nloc); +//std::cout<<"Rx: "<, std::map>> empty_HR_sparse_up; + std::map, std::map>> empty_HR_sparse_down; + std::map, std::map>> empty_SR_sparse; + HR_sparse[0].swap(empty_HR_sparse_up); + HR_sparse[1].swap(empty_HR_sparse_down); + SR_sparse.swap(empty_SR_sparse); + } + else + { + std::map, std::map>>> empty_HR_soc_sparse; + std::map, std::map>>> empty_SR_soc_sparse; + HR_soc_sparse.swap(empty_HR_soc_sparse); + SR_soc_sparse.swap(empty_SR_soc_sparse); + } + + // 'all_R_coor' has a small memory requirement and does not need to be deleted. + // std::set> empty_all_R_coor; + // all_R_coor.swap(empty_all_R_coor); + + return; +} + +void LCAO_Matrix::destroy_T_R_sparse(void) +{ + ModuleBase::TITLE("LCAO_Matrix","destroy_T_R_sparse"); + + if (GlobalV::NSPIN != 4) + { + std::map, std::map>> empty_TR_sparse; + TR_sparse.swap(empty_TR_sparse); + } + else + { + std::map, std::map>>> empty_TR_soc_sparse; + TR_soc_sparse.swap(empty_TR_soc_sparse); + } + return; +} + +void LCAO_Matrix::destroy_dH_R_sparse(void) +{ + ModuleBase::TITLE("LCAO_Matrix","destroy_dH_R_sparse"); + + if (GlobalV::NSPIN != 4) + { + std::map, std::map>> empty_dHRx_sparse_up; + std::map, std::map>> empty_dHRx_sparse_down; + std::map, std::map>> empty_dHRy_sparse_up; + std::map, std::map>> empty_dHRy_sparse_down; + std::map, std::map>> empty_dHRz_sparse_up; + std::map, std::map>> empty_dHRz_sparse_down; + + dHRx_sparse[0].swap(empty_dHRx_sparse_up); + dHRx_sparse[1].swap(empty_dHRx_sparse_down); + dHRy_sparse[0].swap(empty_dHRy_sparse_up); + dHRy_sparse[1].swap(empty_dHRy_sparse_down); + dHRz_sparse[0].swap(empty_dHRz_sparse_up); + dHRz_sparse[1].swap(empty_dHRz_sparse_down); + } + else + { + std::map, std::map>>> empty_dHRx_soc_sparse; + std::map, std::map>>> empty_dHRy_soc_sparse; + std::map, std::map>>> empty_dHRz_soc_sparse; + + dHRx_soc_sparse.swap(empty_dHRx_soc_sparse); + dHRy_soc_sparse.swap(empty_dHRy_soc_sparse); + dHRz_soc_sparse.swap(empty_dHRz_soc_sparse); + } + + return; +} \ No newline at end of file diff --git a/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h b/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h new file mode 100644 index 0000000000..dd33df593c --- /dev/null +++ b/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h @@ -0,0 +1,221 @@ +#ifndef LCAO_MATRIX_H +#define LCAO_MATRIX_H + +#include "module_base/global_function.h" +#include "module_base/global_variable.h" +#include "module_base/vector3.h" +#include "module_base/complexmatrix.h" +#include "module_basis/module_ao/parallel_orbitals.h" + +// add by jingan for map<> in 2021-12-2, will be deleted in the future +#include "module_base/abfs-vector3_order.h" + +class LCAO_Matrix +{ + friend class Mulliken_Charge; + + public: + + LCAO_Matrix(); + ~LCAO_Matrix(); + + void divide_HS_in_frag(const bool isGamma, Parallel_Orbitals& pv); + + // folding the fixed Hamiltonian (T+Vnl) if + // k-point algorithm is used. + void folding_fixedH(const int &ik, bool cal_syns = false); + + Parallel_Orbitals *ParaV; + + void allocate_HS_k(const long &nloc); + +private: + + void allocate_HS_gamma(const long &nloc); + + + public: + //------------------------------ + // H, S, Hfixed + // used in gamma only algorithm. + // thse matrix are used to + // diagonalize. + //------------------------------ + std::vector Hloc; + std::vector Sloc; + std::vector Hloc_fixed; + + //------------------------------ + // 1. Hamiltonian(vl), + // 2. overlap matrix Sloc2 + // 3. fixed (vna+T+Vnl) matrix. + // used in kpoint algorithm. + // these matrix are used to + // diagonalize. + //------------------------------ + std::vector> Hloc2; + std::vector> Sloc2; + std::vector> Hloc_fixed2; + //with soc, zhengdy-soc +/* ModuleBase::ComplexMatrix Hloc2_soc; + ModuleBase::ComplexMatrix Sloc2_soc; + ModuleBase::ComplexMatrix Hloc_fixed2_soc;*/ + + + //------------------------------ + // Store H(mu,nu') + // nu' : nu in near unitcell R. + // used in kpoint algorithm. + // these matrixed are used + // for 'folding_matrix' in lcao_nnr, + // HlocR -> Hloc2, + // SlocR -> Sloc2, + //------------------------------ + std::vector SlocR; + std::vector Hloc_fixedR; + + //with soc, zhengdy-soc + std::vector> SlocR_soc; + std::vector> Hloc_fixedR_soc; + + //LiuXh add 2019-07-15 + double ****Hloc_fixedR_tr; + double ****SlocR_tr; + double ****HR_tr; + + + std::complex ****Hloc_fixedR_tr_soc; + std::complex ****SlocR_tr_soc; + std::complex ****HR_tr_soc; + + // jingan add 2021-6-4, modify 2021-12-2 + // Sparse form of HR and SR, the format is [R_direct_coor][orbit_row][orbit_col] + + // For HR_sparse[2], when nspin=1, only 0 is valid, when nspin=2, 0 means spin up, 1 means spin down + std::map, std::map>> HR_sparse[2]; + std::map, std::map>> SR_sparse; + std::map, std::map>> TR_sparse; + + std::map, std::map>> dHRx_sparse[2]; + std::map, std::map>> dHRy_sparse[2]; + std::map, std::map>> dHRz_sparse[2]; + + // For nspin = 4 + std::map, std::map>>> HR_soc_sparse; + std::map, std::map>>> SR_soc_sparse; + std::map, std::map>>> TR_soc_sparse; + + std::map, std::map>>> dHRx_soc_sparse; + std::map, std::map>>> dHRy_soc_sparse; + std::map, std::map>>> dHRz_soc_sparse; + + // Record all R direct coordinate information, even if HR or SR is a zero matrix + std::set> all_R_coor; + + // Records the R direct coordinates of HR and SR output, This variable will be filled with data when HR and SR files are output. + std::set> output_R_coor; + + + //======================================== + // FORCE + //======================================== + + //----------------------------------------- + // force in LCAO + // used in gamma only algorithm. + //----------------------------------------- + double* DSloc_x; + double* DSloc_y; + double* DSloc_z; + + //----------------------------------------- + // force in LCAO + // used in k-points algorithm. + //----------------------------------------- + double* DSloc_Rx; + double* DSloc_Ry; + double* DSloc_Rz; + + //----------------------------------------- + // dT + part of dVNL + // used in gamma only algorithm. + //----------------------------------------- + double* DHloc_fixed_x; + double* DHloc_fixed_y; + double* DHloc_fixed_z; + + //----------------------------------------- + // dT + part of dVNL + // used in kpoint algorithm. + //----------------------------------------- + double* DHloc_fixedR_x; + double* DHloc_fixedR_y; + double* DHloc_fixedR_z; + + //---------------------------------------- + // r_mu - r_nu + //---------------------------------------- + + double* DH_r;//zhengdy added 2017-07 + + + double* stvnl11; + double* stvnl12; + double* stvnl13; + double* stvnl22; + double* stvnl23; + double* stvnl33; + + double* DSloc_11; + double* DSloc_12; + double* DSloc_13; + double* DSloc_22; + double* DSloc_23; + double* DSloc_33; + + double* DHloc_fixed_11; + double* DHloc_fixed_12; + double* DHloc_fixed_13; + double* DHloc_fixed_22; + double* DHloc_fixed_23; + double* DHloc_fixed_33; + + + void set_HSgamma(const int &iw1_all, const int &iw2_all, const double &v, const char &dtype, double* HSloc); + void set_HSk(const int &iw1_all, const int &iw2_all, const std::complex &v, const char &dtype, const int spin = 0); + + void set_force (const int& iw1_all, const int& iw2_all, const double& vx, const double& vy, + const double& vz, const char &dtype); + void set_stress (const int& iw1_all, const int& iw2_all, const double& vx, const double& vy, + const double& vz, const char &dtype, const ModuleBase::Vector3 &dtau); + + void set_HR_tr(const int &Rx, const int &Ry, const int &Rz, const int &iw1_all, const int &iw2_all, const double &v); + void set_HR_tr_soc(const int &Rx, const int &Ry, const int &Rz, + const int &iw1_all, const int &iw2_all, const std::complex &v); //LiuXh add 2019-07-16 + + void zeros_HSgamma(const char &mtype); + void zeros_HSk(const char &mtype); + void zeros_HSR(const char &mtype); + + void print_HSgamma(const char &mtype, std::ostream &os=std::cout); + void print_HSk(const char &mtype, const char &vtype = 'C', const double &accuracy = 1.0e-5, std::ostream &os=std::cout); + void update_Hloc(void); + void update_Hloc2(const int &ik); + + void allocate_HS_R(const int &nnr); + + void output_HSk(const char &mtype, std::string &fn); + //LiuXh add 2019-07-15 + void allocate_Hloc_fixedR_tr(void); + void allocate_HR_tr(void); + void allocate_SlocR_tr(void); + void destroy_Hloc_fixedR_tr(void); + + // jingan add 2021-6-4, modify 2021-12-2 + void destroy_HS_R_sparse(void); + void destroy_T_R_sparse(void); + void destroy_dH_R_sparse(void); + +}; + +#endif diff --git a/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp new file mode 100644 index 0000000000..978e0dd61c --- /dev/null +++ b/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -0,0 +1,352 @@ +#include "hamilt_lcao.h" + +#include "module_base/global_variable.h" +#include "module_base/timer.h" +#include "module_hamilt_lcao/module_dftu/dftu.h" +#include "module_hamilt_lcao/hamilt_lcaodft/global_fp.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#ifdef __DEEPKS +#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h" +#include "operator_lcao/deepks_lcao.h" +#endif +#ifdef __ELPA +#include "module_hsolver/diago_elpa.h" +#endif +#include "operator_lcao/op_dftu_lcao.h" +#include "operator_lcao/ekinetic_lcao.h" +#include "operator_lcao/meta_lcao.h" +#include "operator_lcao/nonlocal_lcao.h" +#include "operator_lcao/op_exx_lcao.h" +#include "operator_lcao/overlap_lcao.h" +#include "operator_lcao/veff_lcao.h" +#include "module_hsolver/hsolver_lcao.h" +#include "module_hamilt_general/module_xc/xc_functional.h" + +namespace hamilt +{ + +template +HamiltLCAO::HamiltLCAO( + Gint_Gamma* GG_in, + LCAO_gen_fixedH* genH_in, + LCAO_Matrix* LM_in, + Local_Orbital_Charge* loc_in, + elecstate::Potential* pot_in) +{ + this->classname = "HamiltLCAO"; + //reset fixed Hamiltonian matrix in real space + LM_in->zeros_HSgamma('T'); + //reset Overlap matrix in real space + LM_in->zeros_HSgamma('S'); + + // initial operator for Gamma_only case + // overlap term () is indispensable + // in Gamma_only case, target SR is LCAO_Matrix::Sloc, which is same as SK + this->opsd = new Overlap>( + genH_in, + LM_in, + &(LM_in->Sloc), + &(LM_in->Sloc) + ); + + // kinetic term (), + // in Gamma_only case, target HR is LCAO_Matrix::Hloc_fixed, while target HK is LCAO_Matrix::Hloc + // LCAO_Matrix::Hloc_fixed2 is used for storing + if(GlobalV::T_IN_H) + { + Operator* ekinetic = new Ekinetic>( + genH_in, + LM_in, + &(LM_in->Hloc_fixed), + &(LM_in->Hloc) + ); + this->opsd->add(ekinetic); + } + + // nonlocal term (D) + // in general case, target HR is LCAO_Matrix::Hloc_fixedR, while target HK is LCAO_Matrix::Hloc + if(GlobalV::VNL_IN_H) + { + Operator* nonlocal = new Nonlocal>( + genH_in, + LM_in, + &(LM_in->Hloc_fixed), + &(LM_in->Hloc) + ); + this->opsd->add(nonlocal); + } + + // Effective potential term (\sum_r ) + // in general case, target HR is Gint::pvpR_grid, while target HK is LCAO_Matrix::Hloc + if(GlobalV::VL_IN_H) + { + std::vector pot_register_in; + if (GlobalV::VION_IN_H) + { + pot_register_in.push_back("local"); + } + if (GlobalV::VH_IN_H) + { + pot_register_in.push_back("hartree"); + } + pot_register_in.push_back("xc"); + if (GlobalV::imp_sol) + { + pot_register_in.push_back("surchem"); + } + if (GlobalV::EFIELD_FLAG) + { + pot_register_in.push_back("efield"); + } + if (GlobalV::GATE_FLAG) + { + pot_register_in.push_back("gatefield"); + } + pot_register_in.push_back("tddft"); + //only Potential is not empty, Veff and Meta are available + if(pot_register_in.size()>0) + { + //register Potential by gathered operator + pot_in->pot_register(pot_register_in); + //effective potential term + Operator* veff = new Veff>( + GG_in, + loc_in, + LM_in, + pot_in, + nullptr, // no explicit call yet + &(LM_in->Hloc) // no explicit call yet + ); + this->opsd->add(veff); + + // Meta term + Operator* meta = new Meta>( + GG_in, + loc_in, + LM_in, + nullptr, // no explicit call yet + &(LM_in->Hloc) // no explicit call yet + ); + this->opsd->add(meta); + } + } + +#ifdef __DEEPKS + if (GlobalV::deepks_scf) + { + Operator* deepks = new DeePKS>( + loc_in, + LM_in, + nullptr,// no explicit call yet + &(LM_in->Hloc) + ); + this->opsd->add(deepks); + } +#endif + + //end node should be OperatorDFTU + if (GlobalV::dft_plus_u) + { + Operator* dftu = new OperatorDFTU>( + LM_in, + nullptr,// no explicit call yet + &(LM_in->Hloc) + ); + this->opsd->add(dftu); + } + return; +} + +template +HamiltLCAO::HamiltLCAO( + Gint_k* GK_in, + LCAO_gen_fixedH* genH_in, + LCAO_Matrix* LM_in, + Local_Orbital_Charge* loc_in, + elecstate::Potential* pot_in) +{ + this->classname = "HamiltLCAO"; + + //reset fixed Hamiltonian matrix in real space + LM_in->zeros_HSR('T'); + //reset Overlap matrix in real space + LM_in->zeros_HSR('S'); + + // Effective potential term (\sum_r ) + // Meta potential term (\sum_r ) + // in general case, target HR is Gint::pvpR_reduced, while target HK is LCAO_Matrix::Hloc2 + if(GlobalV::VL_IN_H) + { + std::vector pot_register_in; + if (GlobalV::VION_IN_H) + { + pot_register_in.push_back("local"); + } + if (GlobalV::VH_IN_H) + { + pot_register_in.push_back("hartree"); + } + pot_register_in.push_back("xc"); + if (GlobalV::imp_sol) + { + pot_register_in.push_back("surchem"); + } + if (GlobalV::EFIELD_FLAG) + { + pot_register_in.push_back("efield"); + } + if (GlobalV::GATE_FLAG) + { + pot_register_in.push_back("gatefield"); + } + pot_register_in.push_back("tddft"); + //only Potential is not empty, Veff and Meta are available + if(pot_register_in.size()>0) + { + //register Potential by gathered operator + pot_in->pot_register(pot_register_in); + //Veff term + this->ops = new Veff>>( + GK_in, + loc_in, + LM_in, + pot_in, + nullptr, // no explicit call yet + &(LM_in->Hloc2) // no explicit call yet + ); + //reset spin index and real space Hamiltonian matrix + int start_spin = -1; + GK_in->reset_spin(start_spin); + GK_in->destroy_pvpR(); + GK_in->allocate_pvpR(); + + // Meta term + Operator>* meta = new Meta>>( + GK_in, + loc_in, + LM_in, + nullptr, // no explicit call yet + &(LM_in->Hloc2) // no explicit call yet + ); + this->ops->add(meta); + } + } + + // initial operator for multi-k case + // overlap term is indispensable + Operator>* overlap = new Overlap>>( + genH_in, + LM_in, + &(LM_in->SlocR), + &(LM_in->Sloc2) + ); + if(this->ops == nullptr) + { + this->ops = overlap; + } + else + { + this->ops->add(overlap); + } + + // kinetic term (), + // in general case, target HR is LCAO_Matrix::Hloc_fixedR, while target HK is LCAO_Matrix::Hloc2 + if(GlobalV::T_IN_H) + { + Operator>* ekinetic = new Ekinetic>>( + genH_in, + LM_in, + &(LM_in->Hloc_fixedR), + &(LM_in->Hloc2) + ); + this->ops->add(ekinetic); + } + + // nonlocal term (D) + // in general case, target HR is LCAO_Matrix::Hloc_fixedR, while target HK is LCAO_Matrix::Hloc2 + if(GlobalV::VNL_IN_H) + { + Operator>* nonlocal = new Nonlocal>>( + genH_in, + LM_in, + &(LM_in->Hloc_fixedR), + &(LM_in->Hloc2) + ); + this->ops->add(nonlocal); + } + +#ifdef __DEEPKS + if (GlobalV::deepks_scf) + { + Operator>* deepks = new DeePKS>>( + loc_in, + LM_in, + nullptr,// no explicit call yet + &(LM_in->Hloc2) + ); + this->ops->add(deepks); + } +#endif + //end node should be OperatorDFTU + if (GlobalV::dft_plus_u) + { + Operator>* dftu = new OperatorDFTU>>( + LM_in, + nullptr,// no explicit call yet + &(LM_in->Hloc2) + ); + this->ops->add(dftu); + } + +} + +// case for multi-k-points +template <> +void HamiltLCAO>::matrix(MatrixBlock> &hk_in, + MatrixBlock> &sk_in) +{ + auto op = dynamic_cast>*>(this->ops); + assert(op != NULL); + op->matrixHk(hk_in, sk_in); +} + +// case for nspin<4, gamma_only +template <> void HamiltLCAO::matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) +{ + auto op = dynamic_cast*>(this->opsd); + assert(op != NULL); + op->matrixHk(hk_in, sk_in); +} + +template <> void HamiltLCAO::updateHk(const int ik) +{ + ModuleBase::TITLE("HamiltLCAO", "updateHk"); + ModuleBase::timer::tick("HamiltLCAO", "updateHk"); + //update global spin index + if (GlobalV::NSPIN == 2) + { + GlobalV::CURRENT_SPIN = GlobalC::kv.isk[ik]; + } + this->opsd->init(ik); + ModuleBase::timer::tick("HamiltLCAO", "updateHk"); +} + +template <> void HamiltLCAO>::updateHk(const int ik) +{ + ModuleBase::TITLE("HamiltLCAO", "updateHk"); + ModuleBase::timer::tick("HamiltLCAO", "updateHk"); + //update global spin index + if (GlobalV::NSPIN == 2) + { + GlobalV::CURRENT_SPIN = GlobalC::kv.isk[ik]; + } + this->ops->init(ik); + ModuleBase::timer::tick("HamiltLCAO", "updateHk"); +} + +// case for nspin<4, gamma-only k-point +template class HamiltLCAO; +// case for nspin<4, multi-k-points +// case for nspin == 4, non-collinear spin case +template class HamiltLCAO>; +} // namespace hamilt diff --git a/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h b/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h new file mode 100644 index 0000000000..77e353dcb2 --- /dev/null +++ b/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h @@ -0,0 +1,58 @@ +#ifndef HAMILTLCAO_H +#define HAMILTLCAO_H + +#include "module_hamilt_general/hamilt.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" +#include "module_hamilt_lcao/module_gint/gint_gamma.h" +#include "module_hamilt_lcao/module_gint/gint_k.h" +#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" +#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" +#include "module_elecstate/potentials/potential_new.h" + +namespace hamilt +{ + +// template first for type of k space H matrix elements +// template second for type of temporary matrix, gamma_only fix-gamma-matrix + S-gamma, multi-k fix-Real + S-Real +template class HamiltLCAO : public Hamilt +{ + public: + HamiltLCAO( + Gint_Gamma* GG_in, + LCAO_gen_fixedH* genH_in, + LCAO_Matrix* LM_in, + Local_Orbital_Charge* loc_in, + elecstate::Potential* pot_in); + + HamiltLCAO( + Gint_k* GK_in, + LCAO_gen_fixedH* genH_in, + LCAO_Matrix* LM_in, + Local_Orbital_Charge* loc_in, + elecstate::Potential* pot_in); + + ~HamiltLCAO(){ + if(this->ops!= nullptr) + { + delete this->ops; + } + if(this->opsd!= nullptr) + { + delete this->opsd; + } + }; + + // for target K point, update consequence of hPsi() and matrix() + virtual void updateHk(const int ik) override; + + // core function: return H(k) and S(k) matrixs for direct solving eigenvalues. + // not used in PW base + //void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in) override; + void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) override; +}; + +} // namespace hamilt + +#endif \ No newline at end of file diff --git a/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp b/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp new file mode 100644 index 0000000000..5f8f668b17 --- /dev/null +++ b/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp @@ -0,0 +1,189 @@ +#include "operator_lcao.h" +#include "module_base/timer.h" +#include "module_base/tool_title.h" +#include "module_hsolver/hsolver_lcao.h" + +#ifdef __ELPA +#include "module_hsolver/diago_elpa.h" +#endif + +namespace hamilt +{ + +template<> +void OperatorLCAO::get_hs_pointers() +{ + ModuleBase::timer::tick("OperatorLCAO", "get_hs_pointers"); + this->hmatrix_k = this->LM->Hloc.data(); + if ((this->new_e_iteration && ik == 0) || hsolver::HSolverLCAO::out_mat_hs) + { + if (this->smatrix_k == nullptr) + { + this->smatrix_k = new double[this->LM->Sloc.size()]; + this->allocated_smatrix = true; + } + const int inc = 1; + BlasConnector::copy(this->LM->Sloc.size(), this->LM->Sloc.data(), inc, this->smatrix_k, inc); +#ifdef __ELPA + hsolver::DiagoElpa::DecomposedState = 0; +#endif + this->new_e_iteration = false; + } +} + +template<> +void OperatorLCAO>::get_hs_pointers() +{ + ModuleBase::timer::tick("OperatorLCAO", "get_hs_pointers"); + this->hmatrix_k = this->LM->Hloc2.data(); + this->smatrix_k = this->LM->Sloc2.data(); +} + +template<> +void OperatorLCAO::refresh_h() +{ + // Set the matrix 'H' to zero. + this->LM->zeros_HSgamma('H'); +} + +template<> +void OperatorLCAO>::refresh_h() +{ + // Set the matrix 'H' to zero. + this->LM->zeros_HSk('H'); +} + +template<> +void OperatorLCAO::folding_fixed(const int ik) +{ + ModuleBase::TITLE("OperatorLCAO", "folding_fixed"); + ModuleBase::timer::tick("OperatorLCAO", "folding_fixed"); + //add T+VNL matrix. + this->LM->update_Hloc(); + ModuleBase::timer::tick("OperatorLCAO", "folding_fixed"); +} + +template<> +void OperatorLCAO>::folding_fixed(const int ik) +{ + ModuleBase::TITLE("OperatorLCAO", "folding_fixed"); + ModuleBase::timer::tick("OperatorLCAO", "folding_fixed"); + //----------------------------------------- + // folding matrix here: S(k) (SlocR->Sloc2) + // folding matrix here: T(k)+Vnl(k) + // (Hloc_fixed->Hloc_fixed2) + //----------------------------------------- + this->LM->zeros_HSk('S'); + this->LM->zeros_HSk('T'); + this->LM->folding_fixedH(ik); + + //------------------------------------------ + // Add T(k)+Vnl(k)+Vlocal(k) + // (Hloc2 += Hloc_fixed2), (std::complex matrix) + //------------------------------------------ + this->LM->update_Hloc2(ik); + ModuleBase::timer::tick("OperatorLCAO", "folding_fixed"); +} + +template +void OperatorLCAO::init(const int ik_in) +{ + ModuleBase::TITLE("OperatorLCAO", "init"); + ModuleBase::timer::tick("OperatorLCAO", "init"); + if(this->is_first_node) + { + this->refresh_h(); + } + switch(this->cal_type) + { + case lcao_fixed: + { + //cal_type=lcao_fixed refer to fixed matrix operators, which are only rely on stucture, and not changed during SCF + + //update HR first + //in cal_type=lcao_fixed, HR should be updated by each sub-chain nodes + OperatorLCAO* last = this; + while(last != nullptr) + { + last->contributeHR(); + last = dynamic_cast*>(last->next_sub_op); + } + + //update HK next + //in cal_type=lcao_fixed, HK only need to update together in folding_fixed() + + break; + } + case lcao_gint: + { + //cal_type=lcao_gint refer to grid integral operators, which are relied on stucture and potential based on real space grids + //and should be updated each SCF steps + + OperatorLCAO* last = this; + while(last != nullptr) + { + //update HR first + //in cal_type=lcao_gint, HR should be updated by every sub-node. + last->contributeHR(); + + //update HK next + //in cal_type=lcao_gint, HK should be updated by every sub-node. + last->contributeHk(ik_in); + + last = dynamic_cast*>(last->next_sub_op); + } + + break; + } + case lcao_deepks: + { + //update HR first + //in cal_type=lcao_deepks, HR should be updated + this->contributeHR(); + + //update HK next + //in cal_type=lcao_deepks, HK should be updated + this->contributeHk(ik_in); + + break; + + } + case lcao_dftu: + { + //only HK should be updated when cal_type=lcao_dftu + //in cal_type=lcao_dftu, HK only need to update from one node + //dftu is a special operator, it should be the last node of chain + //Overlap matrix for ik is used by it, do folding first and then return + this->folding_fixed(ik_in); + this->contributeHk(ik_in); + return; + + break; + } + case lcao_exx: + { + //update HR first + //in cal_type=lcao_exx, HR should be updated by most priority sub-chain nodes + this->contributeHR(); + + //update HK next + //in cal_type=lcao_exx, HK only need to update from one node + this->contributeHk(ik_in); + + break; + } + } + if(this->next_op != nullptr) + {//it is not the last node, loop next init() function + this->next_op->init(ik_in); + } + else + {//it is the last node, do folding process together + this->folding_fixed(ik_in); + } + + ModuleBase::timer::tick("OperatorLCAO", "init"); +} +template class OperatorLCAO; +template class OperatorLCAO>; +} // namespace hamilt diff --git a/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h b/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h new file mode 100644 index 0000000000..81f9f900db --- /dev/null +++ b/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h @@ -0,0 +1,101 @@ +#ifndef OPERATORLCAO_H +#define OPERATORLCAO_H +#include"module_hamilt_general/operator.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" +#include "module_hamilt_general/matrixblock.h" + +namespace hamilt +{ + +template +class OperatorLCAO : public Operator +{ + public: + virtual ~OperatorLCAO() + { + if(this->allocated_smatrix) delete[] this->smatrix_k; + }; + + /* Function init(k) is used for update HR and HK , + data pointers of HR and HK are not passed by this function, but passed by constructors of every derived classes. + No need to override init() in base class, but must override in derived class */ + virtual void init(const int ik_in)override; + + void refresh_h(); + + /* Function getHR() is designed to update HR matrix only, it will loop all contributeHR() functions in chain table. + Detail of this function is still in developed, HR matrix has two form: HR_all_spin and HR_one_spin. + For NSPIN=2 case, HR_one_spin for spin-up and spin-down is not constructed at same time. + */ + //void getHR(T* hr_pointer); + + /* Function contributeHR() is defined in derived class, for constructing + */ + virtual void contributeHR() + { + return; + } + + /* Function matrixHk() is used for get information of HK matrix and SK matrix for diagolization. + Matrixes HK and SK come from LCAO_Matrix class. + Gamma_only case (T = double), SK would not changed during one SCF loop, a template triangle matrix SK_temp is used for accelerating. + General case (T = std::complex), only pointers of HK and SK saved in OperatorLCAO + */ + void matrixHk(MatrixBlock &hk_in, MatrixBlock &sk_in) + { + this->get_hs_pointers(); +#ifdef __MPI + hk_in = MatrixBlock{hmatrix_k, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + this->LM->ParaV->desc}; + sk_in = MatrixBlock{smatrix_k, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + this->LM->ParaV->desc}; +#else + hk_in = MatrixBlock{hmatrix_k, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + nullptr}; + sk_in = MatrixBlock{smatrix_k, + (size_t)this->LM->ParaV->nrow, + (size_t)this->LM->ParaV->ncol, + nullptr}; +#endif + } + + /* Function contributeHk() is defined in derived class, for constructing (K) + */ + virtual void contributeHk(int ik) + { + return; + } + + //protected: + // Hamiltonian matrix which are stored in LCAO_Matrix and calculated in OperatorLCAO + LCAO_Matrix* LM = nullptr; + + protected: + bool new_e_iteration = true; + + 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 for multi-k-points case + T* hmatrix_k = nullptr; + T* smatrix_k = nullptr; + + //only used for Gamma_only case + bool allocated_smatrix = false; + + //fixed HR matrix folding to HK + void folding_fixed(const int ik); + + +}; + +}//end namespace hamilt + +#endif \ No newline at end of file diff --git a/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp new file mode 100644 index 0000000000..3cfdd30b1d --- /dev/null +++ b/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp @@ -0,0 +1,49 @@ +#include "ELEC_evolve.h" + +#include "module_base/timer.h" +#include "module_base/parallel_reduce.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "module_elecstate/module_charge/symmetry_rho.h" +#include "LCAO_evolve.h" +#include "module_hamilt_lcao/module_dftu/dftu.h" +#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" + +ELEC_evolve::ELEC_evolve(){}; +ELEC_evolve::~ELEC_evolve(){}; + +double ELEC_evolve::td_force_dt; +bool ELEC_evolve::td_vext; +std::vector ELEC_evolve::td_vext_dire_case; +bool ELEC_evolve::out_dipole; +bool ELEC_evolve::out_efield; +double ELEC_evolve::td_print_eij; // the threshold to output Eij elements +int ELEC_evolve::td_edm; // 0: new edm method 1: old edm method + +// this routine only serves for TDDFT using LCAO basis set +void ELEC_evolve::evolve_psi(const int& istep, + hamilt::Hamilt* phm, + Local_Orbital_wfc& lowf, + psi::Psi>* psi, + psi::Psi>* psi_laststep, + std::complex** Hk_laststep, + ModuleBase::matrix& ekb) +{ + ModuleBase::TITLE("ELEC_evolve", "eveolve_psi"); + ModuleBase::timer::tick("ELEC_evolve", "evolve_psi"); + + // pool parallization in future -- mohan note 2021-02-09 + for (int ik = 0; ik < GlobalC::kv.nks; ik++) + { + phm->updateHk(ik); + + ModuleBase::timer::tick("Efficience", "evolve_k"); + Evolve_LCAO_Matrix ELM(lowf.ParaV); + psi->fix_k(ik); + psi_laststep->fix_k(ik); + ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, Hk_laststep[ik], &(ekb(ik, 0))); + ModuleBase::timer::tick("Efficience", "evolve_k"); + } // end k + + ModuleBase::timer::tick("ELEC_evolve", "evolve_psi"); + return; +} diff --git a/module_hamilt_lcao/module_tddft/ELEC_evolve.h b/module_hamilt_lcao/module_tddft/ELEC_evolve.h new file mode 100644 index 0000000000..eb647b83c3 --- /dev/null +++ b/module_hamilt_lcao/module_tddft/ELEC_evolve.h @@ -0,0 +1,51 @@ +#ifndef ELEC_EVOLVE_H +#define ELEC_EVOLVE_H + +#include "module_base/global_function.h" +#include "module_base/global_variable.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" +#include "module_esolver/esolver_ks_lcao.h" +#include "module_esolver/esolver_ks_lcao_tddft.h" +#include "module_psi/psi.h" +#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" + +//----------------------------------------------------------- +// mohan add 2021-02-09 +// This class is used to evolve the electronic wave functions +// in TDDFT in terms of the multiple k points +// k is the index for the points in the first Brillouin zone +//----------------------------------------------------------- + +class ELEC_evolve +{ + + friend class ELEC_scf; + friend class ModuleESolver::ESolver_KS_LCAO; + friend class ModuleESolver::ESolver_KS_LCAO_TDDFT; + + public: + ELEC_evolve(); + ~ELEC_evolve(); + + // fuxiang add 2021-05-25 + + static double td_force_dt; + static bool td_vext; + static std::vector td_vext_dire_case; + static bool out_dipole; + static bool out_efield; + + static double td_print_eij; // the threshold to output Eij elements + static int td_edm; // 0: new edm method 1: old edm method + + private: + static void evolve_psi(const int& istep, + hamilt::Hamilt* phm, + Local_Orbital_wfc& lowf, + psi::Psi>* psi, + psi::Psi>* psi_laststep, + std::complex** Hk_laststep, + ModuleBase::matrix& ekb); +}; + +#endif diff --git a/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp b/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp new file mode 100644 index 0000000000..49b190f6af --- /dev/null +++ b/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp @@ -0,0 +1,1022 @@ +#include "LCAO_evolve.h" + +#include "module_io/input.h" +#include "module_base/scalapack_connector.h" +#include "module_base/lapack_connector.h" +#include "module_io/write_HS.h" +#include "module_hamilt_pw/hamilt_pwdft/global.h" +#include "ELEC_evolve.h" +#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" + +#include +// fuxiang add 2016-10-28 + +Evolve_LCAO_Matrix::~Evolve_LCAO_Matrix() +{ +} + +inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) +{ + int iblock, gIndex; + iblock = localindex / nblk; + gIndex = (iblock * nprocs + myproc) * nblk + localindex % nblk; + return gIndex; +} + +void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, + hamilt::Hamilt* p_hamilt, + psi::Psi>* psi_k, + psi::Psi>* psi_k_laststep, + std::complex* Hk_laststep, + double* ekb) const +{ + ModuleBase::TITLE("Evolve_LCAO_Matrix", "evolve_complex_matrix"); + time_t time_start = time(NULL); + GlobalV::ofs_running << " Start Time : " << ctime(&time_start); + + if (GlobalV::ESOLVER_TYPE == "tddft") + { +#ifdef __MPI + this->using_ScaLAPACK_complex(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), Hk_laststep, p_hamilt, psi_k[0].get_pointer(), ekb); +#else + this->using_LAPACK_complex(ik, p_hamilt, psi_k[0].get_pointer(), psi_k_laststep[0].get_pointer(), ekb); +#endif + } + else + { + ModuleBase::WARNING_QUIT("Evolve_LCAO_Matrix::evolve_complex_matrix", + "only esolver_type == tddft cando evolve"); + } + + time_t time_end = time(NULL); + ModuleBase::GlobalFunc::OUT_TIME("evolve(std::complex)", time_start, time_end); + + return; +} + +void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + std::complex* psi_k_laststep, + double* ekb) const +{ + ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_LAPACK_complex"); + + // Calculate the U operator + + ModuleBase::ComplexMatrix Htmp(GlobalV::NLOCAL, GlobalV::NLOCAL); + ModuleBase::ComplexMatrix Stmp(GlobalV::NLOCAL, GlobalV::NLOCAL); + hamilt::MatrixBlock> h_mat, s_mat; + p_hamilt->matrix(h_mat, s_mat); + for (int i = 0; i < GlobalV::NLOCAL; i++) + { + for (int j = 0; j < GlobalV::NLOCAL; j++) + { + Htmp(i, j) = h_mat.p[i * GlobalV::NLOCAL + j]; + // Htmp(i,j) = (this->LM->Hloc2[i*GlobalV::NLOCAL+j] +this->LM->Hloc2_laststep[i*GlobalV::NLOCAL+j])/2.0; + Stmp(i, j) = s_mat.p[i * GlobalV::NLOCAL + j]; + } + } + + ModuleBase::ComplexMatrix wfc_tmp(GlobalV::NBANDS, GlobalV::NLOCAL, true); + ModuleBase::ComplexMatrix wfc_laststep_tmp(GlobalV::NBANDS, GlobalV::NLOCAL, true); + // wfc_laststep_tmp.c = psi_k_laststep; + + for (int i = 0; i < GlobalV::NBANDS; i++) + { + for (int j = 0; j < GlobalV::NLOCAL; j++) + { + wfc_laststep_tmp.c[i * GlobalV::NLOCAL + j] = psi_k_laststep[i * GlobalV::NLOCAL + j]; + } + } + + /* + GlobalV::ofs_running << " Htmp: " < * work = new std::complex[lwork]; + ModuleBase::GlobalFunc::ZEROS(work, lwork); + int IPIV[GlobalV::NLOCAL]; + + LapackConnector::zgetrf( GlobalV::NLOCAL, GlobalV::NLOCAL, Stmp, GlobalV::NLOCAL, IPIV, &INFO); + LapackConnector::zgetri( GlobalV::NLOCAL, Stmp, GlobalV::NLOCAL, IPIV, work, lwork, &INFO); + */ + /* + std::cout << " S^-1: " <( -S_plus_H(i,j).imag(), S_plus_H(i,j).real() ); + } + } + + ModuleBase::ComplexMatrix Idmat(GlobalV::NLOCAL,GlobalV::NLOCAL); + for(int i=0; i(1.0, 0.0); + else Idmat(i,j) = std::complex(0.0, 0.0); + } + } + */ + ModuleBase::ComplexMatrix Numerator(GlobalV::NLOCAL, GlobalV::NLOCAL); + // Numerator = Idmat - 0.5*INPUT.mdp.md_dt*41.34*Denominator; + // Denominator = Idmat + 0.5*INPUT.mdp.md_dt*41.34*Denominator; + + complex para = {0.0, 1.0}; + para = para * 0.25 * INPUT.mdp.md_dt; + Numerator = Stmp - para * Htmp; + Denominator = Stmp + para * Htmp; + + int info; + int lwork = 3 * GlobalV::NLOCAL - 1; // tmp + std::complex* work = new std::complex[lwork]; + ModuleBase::GlobalFunc::ZEROS(work, lwork); + int* ipiv = new int[GlobalV::NLOCAL]; + + LapackConnector::zgetrf(GlobalV::NLOCAL, GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, &info); + LapackConnector::zgetri(GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, work, lwork, &info); + + ModuleBase::ComplexMatrix U_operator(GlobalV::NLOCAL, GlobalV::NLOCAL); + /* + GlobalV::ofs_running << " Numerator: " <* psi_k_laststep, + const std::complex* Hk_laststep, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + double* ekb) const +{ + ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_ScaLAPACK_complex"); + + int print_matrix = 0; + hamilt::MatrixBlock> h_mat, s_mat; + p_hamilt->matrix(h_mat, s_mat); + + complex* Stmp = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Stmp, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, s_mat.p, 1, Stmp, 1); + + complex* Htmp = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); + + //print test + /*GlobalV::ofs_running << " H(t) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Hk_laststep[i * this->ParaV->ncol + j].real() << "+" << Hk_laststep[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;} + GlobalV::ofs_running << " H(t+dt) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;} + // +*/ + + complex mixing = {0.5, 0.0}; + ScalapackConnector::geadd( + 'N', + nlocal, + nlocal, + mixing, + Hk_laststep, + 1, + 1, + this->ParaV->desc, + mixing, + Htmp, + 1, + 1, + this->ParaV->desc + ); + /*GlobalV::ofs_running << " H(t+dt/2) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;}*/ + complex* U_operator = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); + +// (1)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief compute U_operator + /// @input Stmp, Htmp, print_matrix + /// @output U_operator + compute_U_operator(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); + +// (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief apply U_operator to the wave function of the previous step for new wave function + /// @input U_operator, psi_k_laststep + /// @output psi_k + U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k); + + + +// (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief normalize psi_k + /// @input Stmp, psi_not_norm, psi_k, print_matrix + /// @output psi_k + norm_wfc(nband, nlocal, Stmp, psi_k, print_matrix); + + +// (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + /// @brief compute ekb + /// @input Htmp, psi_k + /// @output ekb + compute_ekb(nband, nlocal, Htmp, psi_k, ekb); + + delete[] Stmp; + delete[] Htmp; + delete[] U_operator; + return; +} + + +void Evolve_LCAO_Matrix::compute_U_operator( + const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix) const +{ + // (1) copy Htmp to Numerator & Denominator + complex* Numerator = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Numerator, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, Htmp, 1, Numerator, 1); + + complex* Denominator = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Denominator, this->ParaV->nloc); + BlasConnector::copy(this->ParaV->nloc, Htmp, 1, Denominator, 1); + + if (print_matrix) + { + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " S matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" << Stmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " H matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" << Numerator[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + } + +// ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // (2) compute Numerator & Denominator by GEADD + // Numerator = Stmp - i*para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt + // Denominator = Stmp + i*para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt + complex alpha = {1.0, 0.0}; + complex beta1 = {0.0, -0.25 * INPUT.mdp.md_dt}; + complex beta2 = {0.0, 0.25 * INPUT.mdp.md_dt}; + + ScalapackConnector::geadd( + 'N', + nlocal, + nlocal, + alpha, + Stmp, + 1, + 1, + this->ParaV->desc, + beta1, + Numerator, + 1, + 1, + this->ParaV->desc + ); + ScalapackConnector::geadd( + 'N', + nlocal, + nlocal, + alpha, + Stmp, + 1, + 1, + this->ParaV->desc, + beta2, + Denominator, + 1, + 1, + this->ParaV->desc + ); + + if (print_matrix) + { + GlobalV::ofs_running << " fenmu:" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" << Denominator[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + } + +//->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + // (3) Next, invert Denominator + int* ipiv = new int[this->ParaV->nloc]; + int info = 0; + // (3.1) compute ipiv + ScalapackConnector::getrf( + nlocal, + nlocal, + Denominator, + 1, + 1, + this->ParaV->desc, + ipiv, + &info + ); + int lwork = -1; + int liwotk = -1; + std::vector> work(1, 0); + std::vector iwork(1, 0); + // (3.2) compute work + ScalapackConnector::getri( + nlocal, + Denominator, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info + ); + lwork = work[0].real(); + work.resize(lwork, 0); + liwotk = iwork[0]; + iwork.resize(liwotk, 0); + // (3.3) compute inverse matrix of matrix_A + ScalapackConnector::getri( + nlocal, + Denominator, + 1, + 1, + this->ParaV->desc, + ipiv, + work.data(), + &lwork, + iwork.data(), + &liwotk, + &info + ); + assert(0 == info); + +//->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> + + // (4) U_operator = Denominator * Numerator; + ScalapackConnector::gemm( + 'N', + 'N', + nlocal, + nlocal, + nlocal, + 1.0, + Denominator, + 1, + 1, + this->ParaV->desc, + Numerator, + 1, + 1, + this->ParaV->desc, + 0.0, + U_operator, + 1, + 1, + this->ParaV->desc + ); + + if (print_matrix) + { + GlobalV::ofs_running << " fenmu^-1:" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" << Denominator[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " fenzi:" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" << Numerator[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " U operator:" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + double aa, bb; + aa = U_operator[i * this->ParaV->ncol + j].real(); + bb = U_operator[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << endl; + } + } + +// cout << "U_operator Success!!!" <* U_operator, + const std::complex* psi_k_laststep, + std::complex* psi_k) const +{ + + ScalapackConnector::gemm( + 'N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + U_operator, + 1, + 1, + this->ParaV->desc, + psi_k_laststep, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc + ); +} + + +void Evolve_LCAO_Matrix::norm_wfc( + const int nband, + const int nlocal, + const std::complex* Stmp, + std::complex* psi_k, + const int print_matrix) const +{ + complex* tmp1 = new complex[this->ParaV->nloc_wfc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); + + complex* Cij = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Cij, this->ParaV->nloc); + + ScalapackConnector::gemm( + 'N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + Stmp, + 1, + 1, + this->ParaV->desc, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + tmp1, + 1, + 1, + this->ParaV->desc_wfc + ); + + + ScalapackConnector::gemm( + 'C', + 'N', + nband, + nband, + nlocal, + 1.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, + tmp1, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + Cij, + 1, + 1, + this->ParaV->desc + ); + + int info; + int myid; + MPI_Comm_rank(this->ParaV->comm_2D, &myid); + int naroc[2]; // maximum number of row or column + + for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) + { + for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) + { + const int coord[2] = {iprow, ipcol}; + int src_rank; + info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); + if (myid == src_rank) + { + naroc[0] = this->ParaV->nrow; + naroc[1] = this->ParaV->ncol; + for (int j = 0; j < naroc[1]; ++j) + { + int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); + if (igcol >= nband) + continue; + for (int i = 0; i < naroc[0]; ++i) + { + int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); + if (igrow >= nband) + continue; + if (igcol == igrow) + { + Cij[j * naroc[0] + i] = {1.0 / sqrt(Cij[j * naroc[0] + i].real()), 0.0}; + } + else + { + Cij[j * naroc[0] + i] = {0.0, 0.0}; + } + } + } + } + } // loop ipcol + } // loop iprow + + // std::cout << "nlocal" << nlocal << std::endl; + // std::cout << "GlobalV::NLOCAL" << GlobalV::NLOCAL << std::endl; + BlasConnector::copy(this->ParaV->nloc_wfc, psi_k, 1, tmp1, 1); + + ScalapackConnector::gemm( + 'N', + 'N', + nlocal, + nband, + nband, + 1.0, + tmp1, + 1, + 1, + this->ParaV->desc_wfc, + Cij, + 1, + 1, + this->ParaV->desc, + 0.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc + ); + + + if (print_matrix) + { + GlobalV::ofs_running << " Cij:" << endl; + for (int i = 0; i < this->ParaV->ncol; i++) + { + for (int j = 0; j < this->ParaV->nrow; j++) + { + GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" << Cij[i * this->ParaV->ncol_bands + j].imag() << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " psi_k:" << endl; + for (int i = 0; i < this->ParaV->ncol_bands; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + double aa, bb; + aa = psi_k[i * this->ParaV->ncol + j].real(); + bb = psi_k[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << " psi_k nlocal*nlocal:" << endl; + for (int i = 0; i < this->ParaV->ncol; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + double aa, bb; + aa = tmp1[i * this->ParaV->ncol + j].real(); + bb = tmp1[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < 1e-8) + aa = 0.0; + if (abs(bb) < 1e-8) + bb = 0.0; + GlobalV::ofs_running << aa << "+" << bb << "i "; + } + GlobalV::ofs_running << endl; + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running << endl; + } + + + delete[] tmp1; + delete[] Cij; + +} + + +void Evolve_LCAO_Matrix::compute_ekb( + const int nband, + const int nlocal, + const std::complex* Htmp, + const std::complex* psi_k, + double* ekb) const +{ + + complex* tmp1 = new complex[this->ParaV->nloc_wfc]; + ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); + + complex* Eij = new complex[this->ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Eij, this->ParaV->nloc); + + ScalapackConnector::gemm( + 'N', + 'N', + nlocal, + nband, + nlocal, + 1.0, + Htmp, + 1, + 1, + this->ParaV->desc, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + tmp1, + 1, + 1, + this->ParaV->desc_wfc + ); + + ScalapackConnector::gemm( + 'C', + 'N', + nband, + nband, + nlocal, + 1.0, + psi_k, + 1, + 1, + this->ParaV->desc_wfc, + tmp1, + 1, + 1, + this->ParaV->desc_wfc, + 0.0, + Eij, + 1, + 1, + this->ParaV->desc + ); + + + if (ELEC_evolve::td_print_eij > 0.0) + { + GlobalV::ofs_running + << "------------------------------------------------------------------------------------------------" + << endl; + GlobalV::ofs_running << " Eij:" << endl; + for (int i = 0; i < this->ParaV->ncol; i++) + { + for (int j = 0; j < this->ParaV->nrow; j++) + { + double aa, bb; + aa = Eij[i * this->ParaV->ncol + j].real(); + bb = Eij[i * this->ParaV->ncol + j].imag(); + if (abs(aa) < ELEC_evolve::td_print_eij) + aa = 0.0; + if (abs(bb) < ELEC_evolve::td_print_eij) + bb = 0.0; + if (aa > 0.0 || bb > 0.0) + { + GlobalV::ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << endl; + } + } + } + GlobalV::ofs_running << endl; + GlobalV::ofs_running + << "------------------------------------------------------------------------------------------------" + << endl; + } + + + int info; + int myid; + int naroc[2]; + MPI_Comm_rank(this->ParaV->comm_2D, &myid); + + double* Eii = new double[nband]; + ModuleBase::GlobalFunc::ZEROS(Eii, nband); + for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) + { + for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) + { + const int coord[2] = {iprow, ipcol}; + int src_rank; + info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); + if (myid == src_rank) + { + naroc[0] = this->ParaV->nrow; + naroc[1] = this->ParaV->ncol; + for (int j = 0; j < naroc[1]; ++j) + { + int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); + if (igcol >= nband) + continue; + for (int i = 0; i < naroc[0]; ++i) + { + int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); + if (igrow >= nband) + continue; + if (igcol == igrow) + { + Eii[igcol] = Eij[j * naroc[0] + i].real(); + } + } + } + } + } // loop ipcol + } // loop iprow + info = MPI_Allreduce(Eii, ekb, nband, MPI_DOUBLE, MPI_SUM, this->ParaV->comm_2D); + + delete[] tmp1; + delete[] Eij; + delete[] Eii; +} + + +#endif diff --git a/module_hamilt_lcao/module_tddft/LCAO_evolve.h b/module_hamilt_lcao/module_tddft/LCAO_evolve.h new file mode 100644 index 0000000000..1f1f4e1fc0 --- /dev/null +++ b/module_hamilt_lcao/module_tddft/LCAO_evolve.h @@ -0,0 +1,79 @@ +#ifndef EVOLVE_LCAO_MATRIX_H +#define EVOLVE_LCAO_MATRIX_H + +#include "module_base/complexmatrix.h" +#include "module_base/global_function.h" +#include "module_base/global_variable.h" +#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" +#include "module_psi/psi.h" +#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" +#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" + +class Evolve_LCAO_Matrix +{ + public: + Evolve_LCAO_Matrix(const Parallel_Orbitals* pv) + { + this->ParaV = pv; + } + ~Evolve_LCAO_Matrix(); + + void evolve_complex_matrix(const int& ik, + hamilt::Hamilt* p_hamilt, + psi::Psi>* psi_k, + psi::Psi>* psi_k_laststep, + std::complex* Hk_laststep, + double* ekb) const; + + private: + // LCAO_Matrix* LM; + const Parallel_Orbitals* ParaV; + + void using_LAPACK_complex(const int& ik, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + std::complex* psi_k_laststep, + double* ekb) const; +#ifdef __MPI + void using_ScaLAPACK_complex( + const int nband, + const int nlocal, + const std::complex* psi_k_laststep, + const std::complex* Hk_laststep, + hamilt::Hamilt* p_hamilt, + std::complex* psi_k, + double* ekb) const; + + void compute_U_operator( + const int nband, + const int nlocal, + const std::complex* Stmp, + const std::complex* Htmp, + std::complex* U_operator, + const int print_matrix) const; + + void U_to_wfc( + const int nband, + const int nlocal, + const std::complex* U_operator, + const std::complex* psi_k_laststep, + std::complex* psi_k) const; + + void norm_wfc( + const int nband, + const int nlocal, + const std::complex* Stmp, + std::complex* psi_k, + const int print_matrix) const; + + + void compute_ekb( + const int nband, + const int nlocal, + const std::complex* Htmp, + const std::complex* psi_k, + double* ekb) const; + +#endif +}; +#endif From ceec1762daed1cb1fceb475b8992e15673a7b0f9 Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Tue, 18 Apr 2023 21:02:34 +0800 Subject: [PATCH 5/8] Delete module_esolver directory --- module_esolver/esolver_ks_lcao_tddft.cpp | 779 ----------------------- module_esolver/esolver_ks_lcao_tddft.h | 38 -- 2 files changed, 817 deletions(-) delete mode 100644 module_esolver/esolver_ks_lcao_tddft.cpp delete mode 100644 module_esolver/esolver_ks_lcao_tddft.h diff --git a/module_esolver/esolver_ks_lcao_tddft.cpp b/module_esolver/esolver_ks_lcao_tddft.cpp deleted file mode 100644 index 4276cb5fb3..0000000000 --- a/module_esolver/esolver_ks_lcao_tddft.cpp +++ /dev/null @@ -1,779 +0,0 @@ -#include "esolver_ks_lcao_tddft.h" - -#include "module_io/cal_r_overlap_R.h" -#include "module_io/dm_io.h" -#include "module_io/rho_io.h" -#include "module_io/dipole_io.h" -#include "module_io/write_HS_R.h" -#include "module_io/write_HS.h" - -//--------------temporary---------------------------- -#include "module_base/blas_connector.h" -#include "module_base/global_function.h" -#include "module_base/scalapack_connector.h" -#include "module_elecstate/module_charge/symmetry_rho.h" -#include "module_elecstate/occupy.h" -#include "module_hamilt_lcao/module_tddft/ELEC_evolve.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#include "module_io/print_info.h" - -//-----HSolver ElecState Hamilt-------- -#include "module_elecstate/elecstate_lcao.h" -#include "module_elecstate/elecstate_lcao_tddft.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" -#include "module_hsolver/hsolver_lcao.h" -#include "module_psi/psi.h" - -//-----force& stress------------------- -#include "module_hamilt_lcao/hamilt_lcaodft/FORCE_STRESS.h" - -//--------------------------------------------------- - -namespace ModuleESolver -{ - -ESolver_KS_LCAO_TDDFT::ESolver_KS_LCAO_TDDFT() -{ - classname = "ESolver_KS_LCAO_TDDFT"; - basisname = "LCAO"; -} -ESolver_KS_LCAO_TDDFT::~ESolver_KS_LCAO_TDDFT() -{ - // this->orb_con.clear_after_ions(GlobalC::UOT, GlobalC::ORB, GlobalV::deepks_setorb, GlobalC::ucell.infoNL.nproj); - delete psi_laststep; - for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ - delete Hk_laststep[ik];} - delete Hk_laststep; -} - -void ESolver_KS_LCAO_TDDFT::Init(Input& inp, UnitCell& ucell) -{ - ESolver_KS::Init(inp, ucell); - - // Initialize the FFT. - // this function belongs to cell LOOP - - // output is GlobalC::ppcell.vloc 3D local pseudopotentials - // without structure factors - // this function belongs to cell LOOP - GlobalC::ppcell.init_vloc(GlobalC::ppcell.vloc, GlobalC::rhopw); - - if (this->pelec == nullptr) - { - this->pelec = new elecstate::ElecStateLCAO_TDDFT(&(chr), - &(GlobalC::kv), - GlobalC::kv.nks, - &(this->LOC), - &(this->UHM), - &(this->LOWF)); - } - - //------------------init Basis_lcao---------------------- - // Init Basis should be put outside of Ensolver. - // * reading the localized orbitals/projectors - // * construct the interpolation tables. - this->Init_Basis_lcao(this->orb_con, inp, ucell); - //------------------init Basis_lcao---------------------- - - //------------------init Hamilt_lcao---------------------- - // * allocate H and S matrices according to computational resources - // * set the 'trace' between local H/S and global H/S - this->LM.divide_HS_in_frag(GlobalV::GAMMA_ONLY_LOCAL, orb_con.ParaV); - //------------------init Hamilt_lcao---------------------- - - // pass Hamilt-pointer to Operator - this->UHM.genH.LM = this->UHM.LM = &this->LM; - // pass basis-pointer to EState and Psi - this->LOC.ParaV = this->LOWF.ParaV = this->LM.ParaV; - - // init Psi, HSolver, ElecState, Hamilt - if (this->phsol == nullptr) - { - this->phsol = new hsolver::HSolverLCAO(this->LOWF.ParaV); - this->phsol->method = GlobalV::KS_SOLVER; - } - - // Inititlize the charge density. - this->pelec->charge->allocate(GlobalV::NSPIN, GlobalC::rhopw->nrxx, GlobalC::rhopw->npw); - - // Initializee the potential. - this->pelec->pot = new elecstate::Potential(GlobalC::rhopw, - &GlobalC::ucell, - &(GlobalC::ppcell.vloc), - &(GlobalC::sf.strucFac), - &(GlobalC::en.etxc), - &(GlobalC::en.vtxc)); - this->pelec_td = dynamic_cast(this->pelec); -} - -void ESolver_KS_LCAO_TDDFT::eachiterinit(const int istep, const int iter) -{ - // mohan add 2010-07-16 - // used for pulay mixing. - if (iter == 1) - GlobalC::CHR_MIX.reset(); - - // mohan update 2012-06-05 - GlobalC::en.deband_harris = GlobalC::en.delta_e(this->pelec); - - // mohan move it outside 2011-01-13 - // first need to calculate the weight according to - // electrons number. - // mohan add iter > 1 on 2011-04-02 - // because the GlobalC::en.ekb has not value now. - // so the smearing can not be done. - // if (iter > 1 && istep <= 1 && GlobalV::ocp == 0) - // Occupy::calculate_weights(); - - if (GlobalC::wf.init_wfc == "file") - { - if (iter == 1) - { - std::cout << " WAVEFUN -> CHARGE " << std::endl; - - // The occupation should be read in together. - // Occupy::calculate_weights(); //mohan add 2012-02-15 - - // calculate the density matrix using read in wave functions - // and the ncalculate the charge density on grid. - if (this->psi != nullptr) - { - if (istep >= 2) - { - this->pelec_td->psiToRho_td(this->psi[0]); - } - else - { - this->pelec_td->psiToRho(this->psi[0]); - } - } - else - { - this->pelec_td->psiToRho(this->psid[0]); - } - - // calculate the local potential(rho) again. - // the grid integration will do in later grid integration. - - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - // a puzzle remains here. - // if I don't renew potential, - // The scf_thr is very small. - // OneElectron, Hartree and - // Exc energy are all correct - // except the band energy. - // - // solved by mohan 2010-09-10 - // there are there rho here: - // rho1: formed by read in orbitals. - // rho2: atomic rho, used to construct H - // rho3: generated by after diagonalize - // here converged because rho3 and rho1 - // are very close. - // so be careful here, make sure - // rho1 and rho2 are the same rho. - // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - this->pelec->pot->init_pot(istep, this->pelec->charge); - GlobalC::en.delta_escf(this->pelec); - } - } - - if (!GlobalV::GAMMA_ONLY_LOCAL) - { - this->UHM.GK.renew(); - } -} - -void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) -{ - - pelec->charge->save_rho_before_sum_band(); - - if (GlobalV::ESOLVER_TYPE == "tddft" && istep >= 2 && !GlobalV::GAMMA_ONLY_LOCAL) - { - ELEC_evolve::evolve_psi(istep, this->p_hamilt, this->LOWF, this->psi, this->psi_laststep, this->Hk_laststep, this->pelec_td->ekb); - this->pelec_td->psiToRho_td(this->psi[0]); - // this->pelec_td->psiToRho(this->psi[0]); - } - // using HSolverLCAO::solve() - else if (this->phsol != nullptr) - { - // reset energy - this->pelec_td->eband = 0.0; - this->pelec_td->demet = 0.0; - this->pelec_td->ef = 0.0; - GlobalC::en.ef_up = 0.0; - GlobalC::en.ef_dw = 0.0; - if (this->psi != nullptr) - { - this->phsol->solve(this->p_hamilt, this->psi[0], this->pelec_td, GlobalV::KS_SOLVER); - } - else if (this->psid != nullptr) - { - this->phsol->solve(this->p_hamilt, this->psid[0], this->pelec_td, GlobalV::KS_SOLVER); - } - } - else - { - ModuleBase::WARNING_QUIT("ESolver_KS_LCAO", "HSolver has not been initialed!"); - } - - if (iter == 1 && istep <= 2) - { - GlobalV::ofs_running - << "------------------------------------------------------------------------------------------------" - << endl; - GlobalV::ofs_running << "occupation : " << endl; - GlobalV::ofs_running << "ik iband occ " << endl; - GlobalV::ofs_running << std::setprecision(6); - GlobalV::ofs_running << std::setiosflags(ios::showpoint); - for (int ik = 0; ik < GlobalC::kv.nks; ik++) - { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) - { - std::setprecision(6); - GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " " << this->pelec_td->wg(ik, ib) << endl; - } - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running - << "------------------------------------------------------------------------------------------------" - << endl; - } - - // transform energy for print - GlobalC::en.eband = this->pelec_td->eband; - GlobalC::en.demet = this->pelec_td->demet; - GlobalC::en.ef = this->pelec_td->ef; - - // (3) sum bands to calculate charge density - // if (istep <= 1 ) Occupy::calculate_weights(); - - for (int ik = 0; ik < GlobalC::kv.nks; ++ik) - { - this->pelec_td->print_band(ik, GlobalC::en.printe, iter); - } - - // (4) mohan add 2010-06-24 - // using new charge density. - GlobalC::en.calculate_harris(); - - // (5) symmetrize the charge density - if (istep <= 1) - { - Symmetry_rho srho; - for (int is = 0; is < GlobalV::NSPIN; is++) - { - srho.begin(is, *(pelec->charge), GlobalC::rhopw, GlobalC::Pgrid, GlobalC::symm); - } - } - - // (6) compute magnetization, only for spin==2 - GlobalC::ucell.magnet.compute_magnetization(pelec->charge, pelec->nelec_spin.data()); - - // (7) calculate delta energy - GlobalC::en.deband = GlobalC::en.delta_e(this->pelec); -} - -void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) -{ - //print Hamiltonian and Overlap matrix - if (this->conv_elec) - { - if (!GlobalV::GAMMA_ONLY_LOCAL) - { - this->UHM.GK.renew(true); - } - for (int ik = 0; ik < GlobalC::kv.nks; ++ik) - { - if(hsolver::HSolverLCAO::out_mat_hs) - { - this->p_hamilt->updateHk(ik); - } - bool bit = false; // LiuXh, 2017-03-21 - // if set bit = true, there would be error in soc-multi-core calculation, noted by zhengdy-soc - if (this->psi != nullptr) - { - hamilt::MatrixBlock> h_mat, s_mat; - this->p_hamilt->matrix(h_mat, s_mat); - ModuleIO::saving_HS(h_mat.p, - s_mat.p, - bit, - hsolver::HSolverLCAO::out_mat_hs, - "data-" + std::to_string(ik), - this->LOWF.ParaV[0], - 1); // LiuXh, 2017-03-21 - } - else if (this->psid != nullptr) - { - hamilt::MatrixBlock h_mat, s_mat; - this->p_hamilt->matrix(h_mat, s_mat); - ModuleIO::saving_HS(h_mat.p, - s_mat.p, - bit, - hsolver::HSolverLCAO::out_mat_hs, - "data-" + std::to_string(ik), - this->LOWF.ParaV[0], - 1); // LiuXh, 2017-03-21 - } - } - } - - if (this->conv_elec) - { - if (elecstate::ElecStateLCAO::out_wfc_lcao) - { - elecstate::ElecStateLCAO::out_wfc_flag = 1; - } - for (int ik = 0; ik < GlobalC::kv.nks; ik++) - { - if (this->psi != nullptr) - { - this->psi[0].fix_k(ik); - this->pelec->print_psi(this->psi[0]); - } - else - { - this->psid[0].fix_k(ik); - this->pelec->print_psi(this->psid[0]); - } - } - elecstate::ElecStateLCAO::out_wfc_flag = 0; - } - - // (9) Calculate new potential according to new Charge Density. - - if (!this->conv_elec) - { - if(GlobalV::NSPIN==4) GlobalC::ucell.cal_ux(); - this->pelec->pot->update_from_charge(this->pelec->charge, &GlobalC::ucell); - GlobalC::en.delta_escf(this->pelec); - } - else - { - GlobalC::en.cal_converged(this->pelec); - } - - // store wfc and Hk laststep - if (istep >= 1 && this->conv_elec) - { - if (this->psi_laststep == nullptr) -#ifdef __MPI - this->psi_laststep = new psi::Psi>(GlobalC::kv.nks, - this->LOWF.ParaV->ncol_bands, - this->LOWF.ParaV->nrow, - nullptr); -#else - this->psi_laststep - = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); -#endif - if (this->Hk_laststep == nullptr){ - this->Hk_laststep = new std::complex*[GlobalC::kv.nks]; - for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ - this->Hk_laststep[ik] = new std::complex[this->LOC.ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Hk_laststep[ik], this->LOC.ParaV->nloc); - } - } - - for (int ik = 0; ik < GlobalC::kv.nks; ++ik) - { - this->psi->fix_k(ik); - this->psi_laststep->fix_k(ik); - int size0 = psi->get_nbands() * psi->get_nbasis(); - for (int index = 0; index < size0; ++index) - psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; - //use for new propagator - this->p_hamilt->updateHk(ik); - //store Hk laststep - hamilt::MatrixBlock> h_mat, s_mat; - this->p_hamilt->matrix(h_mat, s_mat); - BlasConnector::copy(this->LOC.ParaV->nloc, h_mat.p, 1, Hk_laststep[ik], 1); - } - - - if (istep > 1 && ELEC_evolve::td_edm == 0) - this->cal_edm_tddft(); - } - - if (this->conv_elec) - { - GlobalV::ofs_running - << "------------------------------------------------------------------------------------------------" - << endl; - GlobalV::ofs_running << "Eii : " << endl; - GlobalV::ofs_running << "ik iband Eii (eV)" << endl; - GlobalV::ofs_running << std::setprecision(6); - GlobalV::ofs_running << std::setiosflags(ios::showpoint); - for (int ik = 0; ik < GlobalC::kv.nks; ik++) - { - for (int ib = 0; ib < GlobalV::NBANDS; ib++) - { - GlobalV::ofs_running << ik + 1 << " " << ib + 1 << " " - << this->pelec_td->ekb(ik, ib) * ModuleBase::Ry_to_eV << endl; - } - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running - << "------------------------------------------------------------------------------------------------" - << endl; - } -} - -void ESolver_KS_LCAO_TDDFT::afterscf(const int istep) -{ - // if (this->conv_elec || iter == GlobalV::SCF_NMAX) - // { - //-------------------------------------- - // 1. output charge density for converged, - // 0 means don't need to consider iter, - //-------------------------------------- - - for (int is = 0; is < GlobalV::NSPIN; is++) - { - const int precision = 3; - std::stringstream ssc; - ssc << GlobalV::global_out_dir << "SPIN" << is + 1 << "_CHG.cube"; - double& ef_tmp = GlobalC::en.get_ef(is,GlobalV::TWO_EFERMI); - ModuleIO::write_rho( -#ifdef __MPI - GlobalC::bigpw->bz, - GlobalC::bigpw->nbz, - GlobalC::rhopw->nplane, - GlobalC::rhopw->startz_current, -#endif - pelec->charge->rho_save[is], - is, - GlobalV::NSPIN, - 0, - ssc.str(), - GlobalC::rhopw->nx, - GlobalC::rhopw->ny, - GlobalC::rhopw->nz, - ef_tmp, - &(GlobalC::ucell), - precision); - - if (ELEC_evolve::out_dipole == 1) - { - std::stringstream ss_dipole; - ss_dipole << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DIPOLE"; - ModuleIO::write_dipole(pelec->charge->rho_save[is], is, istep, ss_dipole.str()); - } - - std::stringstream ssd; - if (GlobalV::GAMMA_ONLY_LOCAL) - { - ssd << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DM"; - } - else - { - ssd << GlobalV::global_out_dir << "SPIN" << is + 1 << "_DM_R"; - } - - ModuleIO::write_dm( -#ifdef __MPI - GlobalC::GridT.trace_lo, -#endif - is, - 0, - ssd.str(), - precision, - this->LOC.out_dm, - this->LOC.DM, - ef_tmp, - &(GlobalC::ucell)); - - if (GlobalV::out_pot == 1) // LiuXh add 20200701 - { - std::stringstream ssp; - ssp << GlobalV::global_out_dir << "SPIN" << is + 1 << "_POT.cube"; - this->pelec->pot->write_potential(is, 0, ssp.str(), this->pelec->pot->get_effective_v(), precision); - } - } - - if (this->conv_elec) - { - GlobalV::ofs_running << "\n charge density convergence is achieved" << std::endl; - GlobalV::ofs_running << " final etot is " << GlobalC::en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; - } - - if (GlobalV::OUT_LEVEL != "m") - { - // this->pelec->print_eigenvalue(GlobalV::ofs_running); - } - - if (this->conv_elec) - { - // xiaohui add "OUT_LEVEL", 2015-09-16 - if (GlobalV::OUT_LEVEL != "m") - GlobalV::ofs_running << std::setprecision(16); - if (GlobalV::OUT_LEVEL != "m") - GlobalV::ofs_running << " EFERMI = " << GlobalC::en.ef * ModuleBase::Ry_to_eV << " eV" << std::endl; - if (GlobalV::OUT_LEVEL == "ie") - { - GlobalV::ofs_running << " " << GlobalV::global_out_dir << " final etot is " - << GlobalC::en.etot * ModuleBase::Ry_to_eV << " eV" << std::endl; - } - } - else - { - GlobalV::ofs_running << " !! convergence has not been achieved @_@" << std::endl; - if (GlobalV::OUT_LEVEL == "ie" || GlobalV::OUT_LEVEL == "m") // xiaohui add "m" option, 2015-09-16 - std::cout << " !! CONVERGENCE HAS NOT BEEN ACHIEVED !!" << std::endl; - } - - if( GlobalV::CALCULATION != "md" || (istep % hsolver::HSolverLCAO::out_hsR_interval == 0)) - { - if (hsolver::HSolverLCAO::out_mat_hsR) - { - ModuleIO::output_HS_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 - } - - if (hsolver::HSolverLCAO::out_mat_t) - { - ModuleIO::output_T_R(istep, this->UHM); // LiuXh add 2019-07-15 - } - - if (hsolver::HSolverLCAO::out_mat_dh) - { - ModuleIO::output_dH_R(istep, this->pelec->pot->get_effective_v(), this->UHM); // LiuXh add 2019-07-15 - } - - // add by jingan for out r_R matrix 2019.8.14 - if (INPUT.out_mat_r) - { - cal_r_overlap_R r_matrix; - r_matrix.init(*this->LOWF.ParaV); - - if (hsolver::HSolverLCAO::out_mat_hsR) - { - r_matrix.out_rR_other(istep, this->LM.output_R_coor); - } - else - { - r_matrix.out_rR(istep); - - } - } - } -} - -// use the original formula (Hamiltonian matrix) to calculate energy density matrix -void ESolver_KS_LCAO_TDDFT::cal_edm_tddft() -{ - this->LOC.edm_k_tddft.resize(GlobalC::kv.nks); - for (int ik = 0; ik < GlobalC::kv.nks; ++ik) - { -#ifdef __MPI - this->LOC.edm_k_tddft[ik].create(this->LOC.ParaV->ncol, this->LOC.ParaV->nrow); - complex* Htmp = new complex[this->LOC.ParaV->nloc]; - complex* Sinv = new complex[this->LOC.ParaV->nloc]; - complex* tmp1 = new complex[this->LOC.ParaV->nloc]; - complex* tmp2 = new complex[this->LOC.ParaV->nloc]; - complex* tmp3 = new complex[this->LOC.ParaV->nloc]; - complex* tmp4 = new complex[this->LOC.ParaV->nloc]; - complex* tmp5 = new complex[this->LOC.ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Htmp, this->LOC.ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(Sinv, this->LOC.ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp1, this->LOC.ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp2, this->LOC.ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp3, this->LOC.ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp4, this->LOC.ParaV->nloc); - ModuleBase::GlobalFunc::ZEROS(tmp5, this->LOC.ParaV->nloc); - const int inc = 1; - int nrow = this->LOC.ParaV->nrow; - int ncol = this->LOC.ParaV->ncol; - hamilt::MatrixBlock> h_mat, s_mat; - p_hamilt->matrix(h_mat, s_mat); - zcopy_(&this->LOC.ParaV->nloc, h_mat.p, &inc, Htmp, &inc); - zcopy_(&this->LOC.ParaV->nloc, s_mat.p, &inc, Sinv, &inc); - - int* ipiv = new int[this->LOC.ParaV->nloc]; - int info; - const int one_int = 1; - pzgetrf_(&GlobalV::NLOCAL, &GlobalV::NLOCAL, Sinv, &one_int, &one_int, this->LOC.ParaV->desc, ipiv, &info); - - int LWORK = -1, liWORK = -1; - std::vector> WORK(1, 0); - std::vector iWORK(1, 0); - - pzgetri_(&GlobalV::NLOCAL, - Sinv, - &one_int, - &one_int, - this->LOC.ParaV->desc, - ipiv, - WORK.data(), - &LWORK, - iWORK.data(), - &liWORK, - &info); - - LWORK = WORK[0].real(); - WORK.resize(LWORK, 0); - liWORK = iWORK[0]; - iWORK.resize(liWORK, 0); - - pzgetri_(&GlobalV::NLOCAL, - Sinv, - &one_int, - &one_int, - this->LOC.ParaV->desc, - ipiv, - WORK.data(), - &LWORK, - iWORK.data(), - &liWORK, - &info); - - const char N_char = 'N', T_char = 'T'; - const complex one_float = {1.0, 0.0}, zero_float = {0.0, 0.0}; - const complex half_float = {0.5, 0.0}; - pzgemm_(&T_char, - &T_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &one_float, - this->LOC.dm_k[ik].c, - &one_int, - &one_int, - this->LOC.ParaV->desc, - Htmp, - &one_int, - &one_int, - this->LOC.ParaV->desc, - &zero_float, - tmp1, - &one_int, - &one_int, - this->LOC.ParaV->desc); - - pzgemm_(&N_char, - &N_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &one_float, - tmp1, - &one_int, - &one_int, - this->LOC.ParaV->desc, - Sinv, - &one_int, - &one_int, - this->LOC.ParaV->desc, - &zero_float, - tmp2, - &one_int, - &one_int, - this->LOC.ParaV->desc); - - pzgemm_(&N_char, - &T_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &one_float, - Sinv, - &one_int, - &one_int, - this->LOC.ParaV->desc, - Htmp, - &one_int, - &one_int, - this->LOC.ParaV->desc, - &zero_float, - tmp3, - &one_int, - &one_int, - this->LOC.ParaV->desc); - - pzgemm_(&N_char, - &T_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &one_float, - tmp3, - &one_int, - &one_int, - this->LOC.ParaV->desc, - this->LOC.dm_k[ik].c, - &one_int, - &one_int, - this->LOC.ParaV->desc, - &zero_float, - tmp4, - &one_int, - &one_int, - this->LOC.ParaV->desc); - - pzgeadd_(&N_char, - &GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &half_float, - tmp2, - &one_int, - &one_int, - this->LOC.ParaV->desc, - &half_float, - tmp4, - &one_int, - &one_int, - this->LOC.ParaV->desc); - - pztranu_(&GlobalV::NLOCAL, - &GlobalV::NLOCAL, - &one_float, - tmp4, - &one_int, - &one_int, - this->LOC.ParaV->desc, - &zero_float, - tmp5, - &one_int, - &one_int, - this->LOC.ParaV->desc); - zcopy_(&this->LOC.ParaV->nloc, tmp5, &inc, this->LOC.edm_k_tddft[ik].c, &inc); - - delete[] Htmp; - delete[] Sinv; - delete[] tmp1; - delete[] tmp2; - delete[] tmp3; - delete[] tmp4; - delete[] tmp5; - delete[] ipiv; -#else - this->LOC.edm_k_tddft[ik].create(this->LOC.ParaV->ncol, this->LOC.ParaV->nrow); - ModuleBase::ComplexMatrix Sinv(GlobalV::NLOCAL, GlobalV::NLOCAL); - ModuleBase::ComplexMatrix Htmp(GlobalV::NLOCAL, GlobalV::NLOCAL); - hamilt::MatrixBlock> h_mat, s_mat; - p_hamilt->matrix(h_mat, s_mat); - // cout<<"hmat "<* WORK = new std::complex[LWORK]; - ModuleBase::GlobalFunc::ZEROS(WORK, LWORK); - int IPIV[GlobalV::NLOCAL]; - - LapackConnector::zgetrf(GlobalV::NLOCAL, GlobalV::NLOCAL, Sinv, GlobalV::NLOCAL, IPIV, &INFO); - LapackConnector::zgetri(GlobalV::NLOCAL, Sinv, GlobalV::NLOCAL, IPIV, WORK, LWORK, &INFO); - - this->LOC.edm_k_tddft[ik] = 0.5 * (Sinv * Htmp * this->LOC.dm_k[ik] + this->LOC.dm_k[ik] * Htmp * Sinv); - delete[] WORK; -#endif - } - return; -} -} // namespace ModuleESolver \ No newline at end of file diff --git a/module_esolver/esolver_ks_lcao_tddft.h b/module_esolver/esolver_ks_lcao_tddft.h deleted file mode 100644 index 6f9da4a185..0000000000 --- a/module_esolver/esolver_ks_lcao_tddft.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef ESOLVER_KS_LCAO_TDDFT_H -#define ESOLVER_KS_LCAO_TDDFT_H -#include "esolver_ks.h" -#include "esolver_ks_lcao.h" -#include "module_basis/module_ao/ORB_control.h" -#include "module_psi/psi.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" -#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" -#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" -#include "module_hamilt_lcao/hamilt_lcaodft/record_adj.h" -#include "module_elecstate/elecstate_lcao_tddft.h" - - -namespace ModuleESolver -{ - -class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO -{ - public: - ESolver_KS_LCAO_TDDFT(); - ~ESolver_KS_LCAO_TDDFT(); - void Init(Input& inp, UnitCell& cell) override; - - psi::Psi>* psi_laststep = nullptr; - std::complex** Hk_laststep = nullptr; - //same as pelec - elecstate::ElecStateLCAO_TDDFT* pelec_td = nullptr; - - protected: - virtual void hamilt2density(const int istep, const int iter, const double ethr) override; - virtual void eachiterinit(const int istep, const int iter) override; - virtual void updatepot(const int istep, const int iter) override; - virtual void afterscf(const int istep) override; - void cal_edm_tddft(); -}; - -} // namespace ModuleESolver -#endif From fcbfcfb3c413144cebb56426e5503b384869f118 Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Tue, 18 Apr 2023 21:02:50 +0800 Subject: [PATCH 6/8] Delete module_hamilt_general directory --- module_hamilt_general/hamilt.h | 43 ---------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 module_hamilt_general/hamilt.h diff --git a/module_hamilt_general/hamilt.h b/module_hamilt_general/hamilt.h deleted file mode 100644 index 65962311fa..0000000000 --- a/module_hamilt_general/hamilt.h +++ /dev/null @@ -1,43 +0,0 @@ -#ifndef MODULEHAMILT_H -#define MODULEHAMILT_H - -#include "matrixblock.h" -#include "module_psi/psi.h" -#include "operator.h" - -#include -#include - -namespace hamilt -{ - -template -class Hamilt -{ - public: - virtual ~Hamilt(){}; - - // for target K point, update consequence of hPsi() and matrix() - virtual void updateHk(const int ik){return;} - - // core function: for solving eigenvalues of Hamiltonian with iterative method - virtual void hPsi(const std::complex *psi_in, std::complex *hpsi, const size_t size) const{return;} - virtual void sPsi(const std::complex *psi_in, std::complex *spsi, const size_t size) const{return;} - - // core function: return H(k) and S(k) matrixs for direct solving eigenvalues. - virtual void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in){return;} - virtual void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in){return;} - - std::string classname = "none"; - - int non_first_scf=0; - - // first node operator, add operations from each operators - Operator, Device>* ops = nullptr; - Operator* opsd = nullptr; - -}; - -} // namespace hamilt - -#endif \ No newline at end of file From f5eaa11fbdb3b948f5cdd5049ed6a056604cdcc0 Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Tue, 18 Apr 2023 21:03:22 +0800 Subject: [PATCH 7/8] Delete module_hamilt_lcao directory --- .../hamilt_lcaodft/LCAO_matrix.cpp | 1002 ---------------- .../hamilt_lcaodft/LCAO_matrix.h | 221 ---- .../hamilt_lcaodft/hamilt_lcao.cpp | 352 ------ .../hamilt_lcaodft/hamilt_lcao.h | 58 - .../operator_lcao/operator_lcao.cpp | 189 --- .../operator_lcao/operator_lcao.h | 101 -- .../module_tddft/ELEC_evolve.cpp | 49 - module_hamilt_lcao/module_tddft/ELEC_evolve.h | 51 - .../module_tddft/LCAO_evolve.cpp | 1022 ----------------- module_hamilt_lcao/module_tddft/LCAO_evolve.h | 79 -- 10 files changed, 3124 deletions(-) delete mode 100644 module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp delete mode 100644 module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h delete mode 100644 module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp delete mode 100644 module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h delete mode 100644 module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp delete mode 100644 module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h delete mode 100644 module_hamilt_lcao/module_tddft/ELEC_evolve.cpp delete mode 100644 module_hamilt_lcao/module_tddft/ELEC_evolve.h delete mode 100644 module_hamilt_lcao/module_tddft/LCAO_evolve.cpp delete mode 100644 module_hamilt_lcao/module_tddft/LCAO_evolve.h diff --git a/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp b/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp deleted file mode 100644 index 1a4fb745da..0000000000 --- a/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp +++ /dev/null @@ -1,1002 +0,0 @@ -#include "LCAO_matrix.h" -#include "module_hamilt_lcao/hamilt_lcaodft/global_fp.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#include "module_base/tool_threading.h" -#ifdef __DEEPKS -#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h" -#endif - -LCAO_Matrix::LCAO_Matrix() -{ -} - -LCAO_Matrix::~LCAO_Matrix() -{ -} - - -void LCAO_Matrix::divide_HS_in_frag(const bool isGamma, Parallel_Orbitals &pv) -{ - ModuleBase::TITLE("LCAO_Matrix","divide_HS_in_frag"); - - //(1), (2): set up matrix division have been moved into ORB_control - //just pass `ParaV` as pointer is enough - this->ParaV = &pv; - // (3) allocate for S, H_fixed, H, and S_diag - if(isGamma) - { - allocate_HS_gamma(this->ParaV->nloc); - } - else - { - allocate_HS_k(this->ParaV->nloc); - } -#ifdef __DEEPKS - //wenfei 2021-12-19 - //preparation for DeePKS - - if (GlobalV::deepks_out_labels || GlobalV::deepks_scf) - { - //allocate relevant data structures for calculating descriptors - std::vector na; - na.resize(GlobalC::ucell.ntype); - for(int it=0;itSloc.resize(nloc); - this->Hloc_fixed.resize(nloc); - this->Hloc.resize(nloc); - - ModuleBase::GlobalFunc::ZEROS(Sloc.data(),nloc); - ModuleBase::GlobalFunc::ZEROS(Hloc_fixed.data(),nloc); - ModuleBase::GlobalFunc::ZEROS(Hloc.data(),nloc); - - return; -} - - -void LCAO_Matrix::allocate_HS_k(const long &nloc) -{ - ModuleBase::TITLE("LCAO_Matrix","allocate_HS_k"); - - ModuleBase::GlobalFunc::OUT(GlobalV::ofs_running,"nloc",nloc); - if(nloc==0) return; //mohan fix bug 2012-05-25 - - // because we initilize in the constructor function - // with dimension '1', so here we reconstruct these - // matrices - this->Sloc2.resize(nloc); - this->Hloc_fixed2.resize(nloc); - this->Hloc2.resize(nloc); - - ModuleBase::GlobalFunc::ZEROS(Sloc2.data(),nloc); - ModuleBase::GlobalFunc::ZEROS(Hloc_fixed2.data(),nloc); - ModuleBase::GlobalFunc::ZEROS(Hloc2.data(),nloc); - - return; -} - -void LCAO_Matrix::allocate_HS_R(const int &nnR) -{ - if(GlobalV::NSPIN!=4) - { - this->SlocR.resize(nnR); - if(GlobalV::CALCULATION!="get_S") this->Hloc_fixedR.resize(nnR); - - ModuleBase::GlobalFunc::ZEROS(SlocR.data(), nnR); - if(GlobalV::CALCULATION!="get_S") ModuleBase::GlobalFunc::ZEROS(Hloc_fixedR.data(), nnR); - } - else - { - this->SlocR_soc.resize(nnR); - if(GlobalV::CALCULATION!="get_S") this->Hloc_fixedR_soc.resize(nnR); - - ModuleBase::GlobalFunc::ZEROS(SlocR_soc.data(), nnR); - if(GlobalV::CALCULATION!="get_S") ModuleBase::GlobalFunc::ZEROS(Hloc_fixedR_soc.data(), nnR); - - } - - return; -} - -//------------------------------------------------------ -// DESCRIPTION: -// set 'dtype' matrix element (iw1_all, iw2_all) with -// an input value 'v' -//------------------------------------------------------ -void LCAO_Matrix::set_HSgamma( - const int &iw1_all, // index i for atomic orbital (row) - const int &iw2_all, // index j for atomic orbital (column) - const double &v, // value for matrix element (i,j) - const char &dtype, // type of the matrix - double* HSloc) //input pointer for store the matrix -{ - // use iw1_all and iw2_all to set Hloc - // becareful! The ir and ic may be < 0 !!! - const int ir = this->ParaV->trace_loc_row[ iw1_all ]; - const int ic = this->ParaV->trace_loc_col[ iw2_all ]; - - //const int index = ir * ParaO.ncol + ic; - long index=0; - - // save the matrix as column major format - if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()) - { - index=ic*this->ParaV->nrow+ir; - } - else - { - index=ir*this->ParaV->ncol+ic; - } - - if( index >= this->ParaV->nloc) - { - std::cout << " iw1_all = " << iw1_all << std::endl; - std::cout << " iw2_all = " << iw2_all << std::endl; - std::cout << " ir = " << ir << std::endl; - std::cout << " ic = " << ic << std::endl; - std::cout << " index = " << index << std::endl; - std::cout << " this->ParaV->nloc = " << this->ParaV->nloc << std::endl; - ModuleBase::WARNING_QUIT("LCAO_Matrix","set_HSgamma"); - } - - //using input pointer HSloc - HSloc[index] += v; - - return; -} - -void LCAO_Matrix::set_HSk(const int &iw1_all, const int &iw2_all, const std::complex &v, const char &dtype, const int spin) -{ - // use iw1_all and iw2_all to set Hloc - // becareful! The ir and ic may < 0!!!!!!!!!!!!!!!! - const int ir = this->ParaV->trace_loc_row[ iw1_all ]; - const int ic = this->ParaV->trace_loc_col[ iw2_all ]; - //const int index = ir * this->ParaV->ncol + ic; - long index; - if (ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER()) - { - index=ic*this->ParaV->nrow+ir; - } - else - { - index=ir*this->ParaV->ncol+ic; - } - assert(index < this->ParaV->nloc); - if (dtype=='S')//overlap Hamiltonian. - { - this->Sloc2[index] += v; - } - else if (dtype=='T' || dtype=='N')// kinetic and nonlocal Hamiltonian. - { - this->Hloc_fixed2[index] += v; // because kinetic and nonlocal Hamiltonian matrices are already block-cycle staraged after caculated in lcao_nnr.cpp - // this statement will not be used. - } - else if (dtype=='L') // Local potential Hamiltonian. - { - this->Hloc2[index] += v; - } - else - { - ModuleBase::WARNING_QUIT("LCAO_Matrix","set_HSk"); - } - - return; -} - -void LCAO_Matrix::set_force -( - const int &iw1_all, - const int &iw2_all, - const double& vx, - const double& vy, - const double& vz, - const char &dtype) -{ - // use iw1_all and iw2_all to set Hloc - // becareful! The ir and ic may < 0!!!!!!!!!!!!!!!! - const int ir = this->ParaV->trace_loc_row[ iw1_all ]; - const int ic = this->ParaV->trace_loc_col[ iw2_all ]; - const long index = ir * this->ParaV->ncol + ic; - - if( index >= this->ParaV->nloc) - { - std::cout << " iw1_all = " << iw1_all << std::endl; - std::cout << " iw2_all = " << iw2_all << std::endl; - std::cout << " ir = " << ir << std::endl; - std::cout << " ic = " << ic << std::endl; - std::cout << " index = " << index << std::endl; - std::cout << " this->ParaV->nloc = " << this->ParaV->nloc << std::endl; - ModuleBase::WARNING_QUIT("LCAO_Matrix","set_force"); - } - - if (dtype == 'S') - { - this->DSloc_x[index] += vx; - this->DSloc_y[index] += vy; - this->DSloc_z[index] += vz; - } - else if (dtype == 'T') - { - // notice, the sign is '-', minus. - this->DHloc_fixed_x[index] -= vx; - this->DHloc_fixed_y[index] -= vy; - this->DHloc_fixed_z[index] -= vz; - } - else if (dtype == 'N') - { - this->DHloc_fixed_x[index] += vx; - this->DHloc_fixed_y[index] += vy; - this->DHloc_fixed_z[index] += vz; - } - - return; -} - -void LCAO_Matrix::set_stress -( - const int &iw1_all, - const int &iw2_all, - const double& vx, - const double& vy, - const double& vz, - const char &dtype, - const ModuleBase::Vector3 &dtau) -{ - // use iw1_all and iw2_all to set Hloc - // becareful! The ir and ic may < 0!!!!!!!!!!!!!!!! - const int ir = this->ParaV->trace_loc_row[ iw1_all ]; - const int ic = this->ParaV->trace_loc_col[ iw2_all ]; - const long index = ir * this->ParaV->ncol + ic; - - if( index >= this->ParaV->nloc) - { - std::cout << " iw1_all = " << iw1_all << std::endl; - std::cout << " iw2_all = " << iw2_all << std::endl; - std::cout << " ir = " << ir << std::endl; - std::cout << " ic = " << ic << std::endl; - std::cout << " index = " << index << std::endl; - std::cout << " this->ParaV->nloc = " << this->ParaV->nloc << std::endl; - ModuleBase::WARNING_QUIT("LCAO_Matrix","set_stress"); - } - - if (dtype == 'S') - { - this->DSloc_11[index] += vx * dtau.x; - this->DSloc_12[index] += vx * dtau.y; - this->DSloc_13[index] += vx * dtau.z; - this->DSloc_22[index] += vy * dtau.y; - this->DSloc_23[index] += vy * dtau.z; - this->DSloc_33[index] += vz * dtau.z; - } - else if (dtype == 'T') - { - // notice, the sign is '-', minus. - this->DHloc_fixed_11[index] -= vx * dtau.x; - this->DHloc_fixed_12[index] -= vx * dtau.y; - this->DHloc_fixed_13[index] -= vx * dtau.z; - this->DHloc_fixed_22[index] -= vy * dtau.y; - this->DHloc_fixed_23[index] -= vy * dtau.z; - this->DHloc_fixed_33[index] -= vz * dtau.z; - } - else if (dtype == 'N') - { - this->DHloc_fixed_11[index] += vx * dtau.x; - this->DHloc_fixed_12[index] += vx * dtau.y; - this->DHloc_fixed_13[index] += vx * dtau.z; - this->DHloc_fixed_22[index] += vy * dtau.y; - this->DHloc_fixed_23[index] += vy * dtau.z; - this->DHloc_fixed_33[index] += vz * dtau.z; - } - - return; -} - -void LCAO_Matrix::zeros_HSgamma(const char &mtype) -{ - auto zeros_HSgamma_ker = [&](int num_threads, int thread_id) - { - long long beg, len; - if (mtype=='S') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Sloc.size(), (long long)512, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->Sloc.data() + beg, len); - } - else if (mtype=='T') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc_fixed.size(), (long long)512, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->Hloc_fixed.data() + beg, len); - } - else if (mtype=='H') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc.size(), (long long)512, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->Hloc.data() + beg, len); - } - }; - ModuleBase::OMP_PARALLEL(zeros_HSgamma_ker); - return; -} - -void LCAO_Matrix::zeros_HSk(const char &mtype) -{ - auto zeros_HSk_ker = [&](int num_threads, int thread_id) - { - long long beg, len; - if (mtype=='S') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Sloc2.size(), (long long)256, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->Sloc2.data() + beg, len); - } - else if (mtype=='T') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc_fixed2.size(), (long long)256, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->Hloc_fixed2.data() + beg, len); - } - else if (mtype=='H') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc2.size(), (long long)256, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->Hloc2.data() + beg, len); - } - }; - ModuleBase::OMP_PARALLEL(zeros_HSk_ker); - return; -} - -void LCAO_Matrix::zeros_HSR(const char &mtype) -{ - auto zeros_HSR_ker = [&](int num_threads, int thread_id) - { - long long beg, len; - if(GlobalV::NSPIN!=4) - { - if (mtype=='S') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->SlocR.size(), (long long)512, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->SlocR.data() + beg, len); - } - else if (mtype=='T') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc_fixedR.size(), (long long)512, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->Hloc_fixedR.data() + beg, len); - } - } - else - { - if (mtype=='S') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->SlocR_soc.size(), (long long)256, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->SlocR_soc.data() + beg, len); - } - else if (mtype=='T') - { - ModuleBase::BLOCK_TASK_DIST_1D(num_threads, thread_id, (long long)this->Hloc_fixedR_soc.size(), (long long)256, beg, len); - ModuleBase::GlobalFunc::ZEROS(this->Hloc_fixedR_soc.data() + beg, len); - } - } - }; - ModuleBase::OMP_PARALLEL(zeros_HSR_ker); - return; -} - -// Peize Lin add vtype='A' 2018-11-30 -void LCAO_Matrix::print_HSk(const char &mtype, const char &vtype, const double &accuracy, std::ostream &os) -{ - ModuleBase::TITLE("LCAO_Matrix","print_HSk"); - if(mtype=='S') os << "Sloc2 matrix" << std::endl; - else if(mtype=='T') os << "Hloc_fixed2 matrix" << std::endl; - else if(mtype=='H') os << "Hloc2 matrix" << std::endl; - else - { - ModuleBase::WARNING_QUIT("LCAO_Matrix::print_HSk","Check input parameter: mtype."); - } - - if(vtype=='C') os << " Output norm." << std::endl; - else if(vtype=='R') os << " Output real part." << std::endl; - else if(vtype=='I') os << " Output imag part." << std::endl; - else if(vtype=='A') os << " Output std::complex." << std::endl; - - - os << std::setprecision(8) << std::endl; - for(int i=0; iParaV->nrow; i++) - { - os << " " ; - for(int j=0; jParaV->ncol; j++) - { - const int index = i * this->ParaV->ncol + j; - if(vtype=='A') - { - std::complex v; - if(mtype=='S') v = Sloc2[index]; - else if(mtype=='T') v = Hloc_fixed2[index]; - else if(mtype=='H') v = Hloc2[index]; - auto threshold = [accuracy]( const double v ){ return abs(v)>accuracy ? v : 0.0; }; - os << '(' << threshold(v.real()) << ',' << threshold(v.imag()) << "\t"; - } - else - { - double v=-888.888;//wrong number - if(vtype=='R') - { - if(mtype=='S') v = Sloc2[index].real(); - else if(mtype=='T') v = Hloc_fixed2[index].real(); - else if(mtype=='H') v = Hloc2[index].real(); - } - else if(vtype=='C') - { - if(mtype=='S') v = sqrt( norm ( Sloc2[index] ) ); - else if(mtype=='T') v = sqrt( norm ( Hloc_fixed2[index] ) ); - else if(mtype=='H') v = sqrt( norm ( Hloc2[index] ) ); - } - else if(vtype=='I') - { - if(mtype=='S') v = Sloc2[index].imag(); - else if(mtype=='T') v = Hloc_fixed2[index].imag(); - else if(mtype=='H') v = Hloc2[index].imag(); - } - - if( abs(v) > accuracy ) - { - // os << std::setw(15) << v; - os << v << "\t"; - } - else - { - // os << std::setw(15) << "0"; - os << "0" << "\t"; - } - } - } - os << std::endl; - } - os << std::endl; - os << std::setprecision(6) << std::endl; - return; -} - - -void LCAO_Matrix::print_HSgamma(const char &mtype, std::ostream &os) -{ - ModuleBase::TITLE("LCAO_Matrix","print_HSgamma"); - - GlobalV::ofs_running << " " << mtype << " matrix" << std::endl; - GlobalV::ofs_running << " nrow=" << this->ParaV->nrow << std::endl; - GlobalV::ofs_running << " ncol=" << this->ParaV->ncol << std::endl; - GlobalV::ofs_running << " element number = " << this->ParaV->ncol << std::endl; - - if (mtype=='S') - { - os << std::setprecision(8); - os << " print Sloc" << std::endl; - for(int i=0; iParaV->ncol+j]; - if( abs(v) > 1.0e-8) - { - os << std::setw(15) << v; - } - else - { - os << std::setw(15) << "0"; - } - }//end j - os << std::endl; - }//end i - } - if (mtype=='T') - { - os << " print Hloc_fixed" << std::endl; - for(int i=0; iParaV->ncol+j]; - if( abs(v) > 1.0e-8) - { - os << std::setw(15) << v; - } - else - { - os << std::setw(15) << "0"; - } - }//end j - os << std::endl; - }//end i - } - if (mtype=='H') - { - os << " print Hloc" << std::endl; - for(int i=0; iParaV->ncol+j]; - if( abs(v) > 1.0e-8) - { - os << std::setw(15) << v; - } - else - { - os << std::setw(15) << "0"; - } - }//end j - os << std::endl; - }//end i - } - - return; -} - -// becareful! Update Hloc, we add new members to it. -void LCAO_Matrix::update_Hloc(void) -{ - ModuleBase::TITLE("LCAO_Matrix","update_Hloc"); -#ifdef _OPENMP -#pragma omp parallel for schedule(static, 1024) -#endif - for (long i=0; iParaV->nloc; i++) - { - Hloc[i] += Hloc_fixed[i]; - } - return; -} - -void LCAO_Matrix::update_Hloc2(const int &ik) -{ - ModuleBase::TITLE("LCAO_Matrix","update_Hloc2"); -#ifdef _OPENMP -#pragma omp parallel for schedule(static, 1024) -#endif - for (long i = 0; i < this->ParaV->nloc; i++) - { - Hloc2[i] += Hloc_fixed2[i]; -#ifdef __DEEPKS - if(GlobalV::deepks_scf) - { - Hloc2[i] += GlobalC::ld.H_V_delta_k[ik][i]; - } -#endif - } - - return; -} - - -void LCAO_Matrix::output_HSk(const char &mtype, std::string &fn) -{ - ModuleBase::TITLE("LCAO_Matrix","output_HSk"); - std::stringstream ss; - ss << GlobalV::global_out_dir << fn; - std::ofstream ofs(ss.str().c_str()); - ofs << GlobalV::NLOCAL << std::endl; - for(int i=0; iParaV->nloc]; - //HR_tr[ix][iy][iz] = new double[this->ParaV->nloc]; - //SlocR_tr[ix][iy][iz] = new double[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Hloc_fixedR_tr[ix][iy][iz], this->ParaV->nloc); - //ModuleBase::GlobalFunc::ZEROS(HR_tr[ix][iy][iz], this->ParaV->nloc); - //ModuleBase::GlobalFunc::ZEROS(SlocR_tr[ix][iy][iz], this->ParaV->nloc); - } - } - } - } - else - { - Hloc_fixedR_tr_soc = new std::complex***[R_x]; - //HR_tr = new double***[R_x]; - //SlocR_tr = new double***[R_x]; - for(int ix=0; ix**[R_y]; - //HR_tr[ix] = new double**[R_y]; - //SlocR_tr[ix] = new double**[R_y]; - for(int iy=0; iy*[R_z]; - //HR_tr[ix][iy] = new double*[R_z]; - //SlocR_tr[ix][iy] = new double*[R_z]; - for(int iz=0; iz[this->ParaV->nloc]; - //HR_tr[ix][iy][iz] = new double[this->ParaV->nloc]; - //SlocR_tr[ix][iy][iz] = new double[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Hloc_fixedR_tr_soc[ix][iy][iz], this->ParaV->nloc); - //ModuleBase::GlobalFunc::ZEROS(HR_tr[ix][iy][iz], this->ParaV->nloc); - //ModuleBase::GlobalFunc::ZEROS(SlocR_tr[ix][iy][iz], this->ParaV->nloc); - } - } - } - } -//std::cout<<"R_x: "<ParaV->nloc: "<ParaV->nloc<ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(HR_tr[ix][iy][iz], this->ParaV->nloc); - } - } - } - } - else - { - HR_tr_soc = new std::complex***[R_x]; - for(int ix=0; ix**[R_y]; - for(int iy=0; iy*[R_z]; - for(int iz=0; iz[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(HR_tr_soc[ix][iy][iz], this->ParaV->nloc); - } - } - } - } - - return; -} - -void LCAO_Matrix::allocate_SlocR_tr(void) -{ - ModuleBase::TITLE("LCAO_Matrix","allocate_SlocR_tr"); - - //int R_x = 10; - //int R_y = 10; - //int R_z = 10; - int R_x = GlobalC::GridD.getCellX(); - int R_y = GlobalC::GridD.getCellY(); - int R_z = GlobalC::GridD.getCellZ(); - - if(GlobalV::NSPIN!=4) - { - SlocR_tr = new double***[R_x]; - for(int ix=0; ixParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(SlocR_tr[ix][iy][iz], this->ParaV->nloc); - } - } - } - } - else - { - SlocR_tr_soc = new std::complex***[R_x]; - for(int ix=0; ix**[R_y]; - for(int iy=0; iy*[R_z]; - for(int iz=0; iz[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(SlocR_tr_soc[ix][iy][iz], this->ParaV->nloc); - } - } - } - } - - return; -} - -void LCAO_Matrix::destroy_Hloc_fixedR_tr(void) -{ - ModuleBase::TITLE("LCAO_Matrix","destroy_Hloc_fixed2_R"); - - //int R_x = 10; - //int R_y = 10; - //int R_z = 10; - int R_x = GlobalC::GridD.getCellX(); - int R_y = GlobalC::GridD.getCellY(); - int R_z = GlobalC::GridD.getCellZ(); - - if(GlobalV::NSPIN!=4) - { - for(int ix=0; ixParaV->trace_loc_row[ iw1_all ]; - const int ic = this->ParaV->trace_loc_col[ iw2_all ]; - -//std::cout<<"ir: "<ParaV->nrow+ir; -//std::cout<<"index: "<ParaV->ncol+ic; -//std::cout<<"index: "<ParaV->nloc: "<ParaV->nloc<ParaV->nloc); -//std::cout<<"Rx: "< &v) -{ - const int ir = this->ParaV->trace_loc_row[ iw1_all ]; - const int ic = this->ParaV->trace_loc_col[ iw2_all ]; - -//std::cout<<"ir: "<ParaV->nrow+ir; -//std::cout<<"index: "<ParaV->ncol+ic; -//std::cout<<"index: "<ParaV->nloc: "<ParaV->nloc<ParaV->nloc); -//std::cout<<"Rx: "<, std::map>> empty_HR_sparse_up; - std::map, std::map>> empty_HR_sparse_down; - std::map, std::map>> empty_SR_sparse; - HR_sparse[0].swap(empty_HR_sparse_up); - HR_sparse[1].swap(empty_HR_sparse_down); - SR_sparse.swap(empty_SR_sparse); - } - else - { - std::map, std::map>>> empty_HR_soc_sparse; - std::map, std::map>>> empty_SR_soc_sparse; - HR_soc_sparse.swap(empty_HR_soc_sparse); - SR_soc_sparse.swap(empty_SR_soc_sparse); - } - - // 'all_R_coor' has a small memory requirement and does not need to be deleted. - // std::set> empty_all_R_coor; - // all_R_coor.swap(empty_all_R_coor); - - return; -} - -void LCAO_Matrix::destroy_T_R_sparse(void) -{ - ModuleBase::TITLE("LCAO_Matrix","destroy_T_R_sparse"); - - if (GlobalV::NSPIN != 4) - { - std::map, std::map>> empty_TR_sparse; - TR_sparse.swap(empty_TR_sparse); - } - else - { - std::map, std::map>>> empty_TR_soc_sparse; - TR_soc_sparse.swap(empty_TR_soc_sparse); - } - return; -} - -void LCAO_Matrix::destroy_dH_R_sparse(void) -{ - ModuleBase::TITLE("LCAO_Matrix","destroy_dH_R_sparse"); - - if (GlobalV::NSPIN != 4) - { - std::map, std::map>> empty_dHRx_sparse_up; - std::map, std::map>> empty_dHRx_sparse_down; - std::map, std::map>> empty_dHRy_sparse_up; - std::map, std::map>> empty_dHRy_sparse_down; - std::map, std::map>> empty_dHRz_sparse_up; - std::map, std::map>> empty_dHRz_sparse_down; - - dHRx_sparse[0].swap(empty_dHRx_sparse_up); - dHRx_sparse[1].swap(empty_dHRx_sparse_down); - dHRy_sparse[0].swap(empty_dHRy_sparse_up); - dHRy_sparse[1].swap(empty_dHRy_sparse_down); - dHRz_sparse[0].swap(empty_dHRz_sparse_up); - dHRz_sparse[1].swap(empty_dHRz_sparse_down); - } - else - { - std::map, std::map>>> empty_dHRx_soc_sparse; - std::map, std::map>>> empty_dHRy_soc_sparse; - std::map, std::map>>> empty_dHRz_soc_sparse; - - dHRx_soc_sparse.swap(empty_dHRx_soc_sparse); - dHRy_soc_sparse.swap(empty_dHRy_soc_sparse); - dHRz_soc_sparse.swap(empty_dHRz_soc_sparse); - } - - return; -} \ No newline at end of file diff --git a/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h b/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h deleted file mode 100644 index dd33df593c..0000000000 --- a/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h +++ /dev/null @@ -1,221 +0,0 @@ -#ifndef LCAO_MATRIX_H -#define LCAO_MATRIX_H - -#include "module_base/global_function.h" -#include "module_base/global_variable.h" -#include "module_base/vector3.h" -#include "module_base/complexmatrix.h" -#include "module_basis/module_ao/parallel_orbitals.h" - -// add by jingan for map<> in 2021-12-2, will be deleted in the future -#include "module_base/abfs-vector3_order.h" - -class LCAO_Matrix -{ - friend class Mulliken_Charge; - - public: - - LCAO_Matrix(); - ~LCAO_Matrix(); - - void divide_HS_in_frag(const bool isGamma, Parallel_Orbitals& pv); - - // folding the fixed Hamiltonian (T+Vnl) if - // k-point algorithm is used. - void folding_fixedH(const int &ik, bool cal_syns = false); - - Parallel_Orbitals *ParaV; - - void allocate_HS_k(const long &nloc); - -private: - - void allocate_HS_gamma(const long &nloc); - - - public: - //------------------------------ - // H, S, Hfixed - // used in gamma only algorithm. - // thse matrix are used to - // diagonalize. - //------------------------------ - std::vector Hloc; - std::vector Sloc; - std::vector Hloc_fixed; - - //------------------------------ - // 1. Hamiltonian(vl), - // 2. overlap matrix Sloc2 - // 3. fixed (vna+T+Vnl) matrix. - // used in kpoint algorithm. - // these matrix are used to - // diagonalize. - //------------------------------ - std::vector> Hloc2; - std::vector> Sloc2; - std::vector> Hloc_fixed2; - //with soc, zhengdy-soc -/* ModuleBase::ComplexMatrix Hloc2_soc; - ModuleBase::ComplexMatrix Sloc2_soc; - ModuleBase::ComplexMatrix Hloc_fixed2_soc;*/ - - - //------------------------------ - // Store H(mu,nu') - // nu' : nu in near unitcell R. - // used in kpoint algorithm. - // these matrixed are used - // for 'folding_matrix' in lcao_nnr, - // HlocR -> Hloc2, - // SlocR -> Sloc2, - //------------------------------ - std::vector SlocR; - std::vector Hloc_fixedR; - - //with soc, zhengdy-soc - std::vector> SlocR_soc; - std::vector> Hloc_fixedR_soc; - - //LiuXh add 2019-07-15 - double ****Hloc_fixedR_tr; - double ****SlocR_tr; - double ****HR_tr; - - - std::complex ****Hloc_fixedR_tr_soc; - std::complex ****SlocR_tr_soc; - std::complex ****HR_tr_soc; - - // jingan add 2021-6-4, modify 2021-12-2 - // Sparse form of HR and SR, the format is [R_direct_coor][orbit_row][orbit_col] - - // For HR_sparse[2], when nspin=1, only 0 is valid, when nspin=2, 0 means spin up, 1 means spin down - std::map, std::map>> HR_sparse[2]; - std::map, std::map>> SR_sparse; - std::map, std::map>> TR_sparse; - - std::map, std::map>> dHRx_sparse[2]; - std::map, std::map>> dHRy_sparse[2]; - std::map, std::map>> dHRz_sparse[2]; - - // For nspin = 4 - std::map, std::map>>> HR_soc_sparse; - std::map, std::map>>> SR_soc_sparse; - std::map, std::map>>> TR_soc_sparse; - - std::map, std::map>>> dHRx_soc_sparse; - std::map, std::map>>> dHRy_soc_sparse; - std::map, std::map>>> dHRz_soc_sparse; - - // Record all R direct coordinate information, even if HR or SR is a zero matrix - std::set> all_R_coor; - - // Records the R direct coordinates of HR and SR output, This variable will be filled with data when HR and SR files are output. - std::set> output_R_coor; - - - //======================================== - // FORCE - //======================================== - - //----------------------------------------- - // force in LCAO - // used in gamma only algorithm. - //----------------------------------------- - double* DSloc_x; - double* DSloc_y; - double* DSloc_z; - - //----------------------------------------- - // force in LCAO - // used in k-points algorithm. - //----------------------------------------- - double* DSloc_Rx; - double* DSloc_Ry; - double* DSloc_Rz; - - //----------------------------------------- - // dT + part of dVNL - // used in gamma only algorithm. - //----------------------------------------- - double* DHloc_fixed_x; - double* DHloc_fixed_y; - double* DHloc_fixed_z; - - //----------------------------------------- - // dT + part of dVNL - // used in kpoint algorithm. - //----------------------------------------- - double* DHloc_fixedR_x; - double* DHloc_fixedR_y; - double* DHloc_fixedR_z; - - //---------------------------------------- - // r_mu - r_nu - //---------------------------------------- - - double* DH_r;//zhengdy added 2017-07 - - - double* stvnl11; - double* stvnl12; - double* stvnl13; - double* stvnl22; - double* stvnl23; - double* stvnl33; - - double* DSloc_11; - double* DSloc_12; - double* DSloc_13; - double* DSloc_22; - double* DSloc_23; - double* DSloc_33; - - double* DHloc_fixed_11; - double* DHloc_fixed_12; - double* DHloc_fixed_13; - double* DHloc_fixed_22; - double* DHloc_fixed_23; - double* DHloc_fixed_33; - - - void set_HSgamma(const int &iw1_all, const int &iw2_all, const double &v, const char &dtype, double* HSloc); - void set_HSk(const int &iw1_all, const int &iw2_all, const std::complex &v, const char &dtype, const int spin = 0); - - void set_force (const int& iw1_all, const int& iw2_all, const double& vx, const double& vy, - const double& vz, const char &dtype); - void set_stress (const int& iw1_all, const int& iw2_all, const double& vx, const double& vy, - const double& vz, const char &dtype, const ModuleBase::Vector3 &dtau); - - void set_HR_tr(const int &Rx, const int &Ry, const int &Rz, const int &iw1_all, const int &iw2_all, const double &v); - void set_HR_tr_soc(const int &Rx, const int &Ry, const int &Rz, - const int &iw1_all, const int &iw2_all, const std::complex &v); //LiuXh add 2019-07-16 - - void zeros_HSgamma(const char &mtype); - void zeros_HSk(const char &mtype); - void zeros_HSR(const char &mtype); - - void print_HSgamma(const char &mtype, std::ostream &os=std::cout); - void print_HSk(const char &mtype, const char &vtype = 'C', const double &accuracy = 1.0e-5, std::ostream &os=std::cout); - void update_Hloc(void); - void update_Hloc2(const int &ik); - - void allocate_HS_R(const int &nnr); - - void output_HSk(const char &mtype, std::string &fn); - //LiuXh add 2019-07-15 - void allocate_Hloc_fixedR_tr(void); - void allocate_HR_tr(void); - void allocate_SlocR_tr(void); - void destroy_Hloc_fixedR_tr(void); - - // jingan add 2021-6-4, modify 2021-12-2 - void destroy_HS_R_sparse(void); - void destroy_T_R_sparse(void); - void destroy_dH_R_sparse(void); - -}; - -#endif diff --git a/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp deleted file mode 100644 index 978e0dd61c..0000000000 --- a/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ /dev/null @@ -1,352 +0,0 @@ -#include "hamilt_lcao.h" - -#include "module_base/global_variable.h" -#include "module_base/timer.h" -#include "module_hamilt_lcao/module_dftu/dftu.h" -#include "module_hamilt_lcao/hamilt_lcaodft/global_fp.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#ifdef __DEEPKS -#include "module_hamilt_lcao/module_deepks/LCAO_deepks.h" -#include "operator_lcao/deepks_lcao.h" -#endif -#ifdef __ELPA -#include "module_hsolver/diago_elpa.h" -#endif -#include "operator_lcao/op_dftu_lcao.h" -#include "operator_lcao/ekinetic_lcao.h" -#include "operator_lcao/meta_lcao.h" -#include "operator_lcao/nonlocal_lcao.h" -#include "operator_lcao/op_exx_lcao.h" -#include "operator_lcao/overlap_lcao.h" -#include "operator_lcao/veff_lcao.h" -#include "module_hsolver/hsolver_lcao.h" -#include "module_hamilt_general/module_xc/xc_functional.h" - -namespace hamilt -{ - -template -HamiltLCAO::HamiltLCAO( - Gint_Gamma* GG_in, - LCAO_gen_fixedH* genH_in, - LCAO_Matrix* LM_in, - Local_Orbital_Charge* loc_in, - elecstate::Potential* pot_in) -{ - this->classname = "HamiltLCAO"; - //reset fixed Hamiltonian matrix in real space - LM_in->zeros_HSgamma('T'); - //reset Overlap matrix in real space - LM_in->zeros_HSgamma('S'); - - // initial operator for Gamma_only case - // overlap term () is indispensable - // in Gamma_only case, target SR is LCAO_Matrix::Sloc, which is same as SK - this->opsd = new Overlap>( - genH_in, - LM_in, - &(LM_in->Sloc), - &(LM_in->Sloc) - ); - - // kinetic term (), - // in Gamma_only case, target HR is LCAO_Matrix::Hloc_fixed, while target HK is LCAO_Matrix::Hloc - // LCAO_Matrix::Hloc_fixed2 is used for storing - if(GlobalV::T_IN_H) - { - Operator* ekinetic = new Ekinetic>( - genH_in, - LM_in, - &(LM_in->Hloc_fixed), - &(LM_in->Hloc) - ); - this->opsd->add(ekinetic); - } - - // nonlocal term (D) - // in general case, target HR is LCAO_Matrix::Hloc_fixedR, while target HK is LCAO_Matrix::Hloc - if(GlobalV::VNL_IN_H) - { - Operator* nonlocal = new Nonlocal>( - genH_in, - LM_in, - &(LM_in->Hloc_fixed), - &(LM_in->Hloc) - ); - this->opsd->add(nonlocal); - } - - // Effective potential term (\sum_r ) - // in general case, target HR is Gint::pvpR_grid, while target HK is LCAO_Matrix::Hloc - if(GlobalV::VL_IN_H) - { - std::vector pot_register_in; - if (GlobalV::VION_IN_H) - { - pot_register_in.push_back("local"); - } - if (GlobalV::VH_IN_H) - { - pot_register_in.push_back("hartree"); - } - pot_register_in.push_back("xc"); - if (GlobalV::imp_sol) - { - pot_register_in.push_back("surchem"); - } - if (GlobalV::EFIELD_FLAG) - { - pot_register_in.push_back("efield"); - } - if (GlobalV::GATE_FLAG) - { - pot_register_in.push_back("gatefield"); - } - pot_register_in.push_back("tddft"); - //only Potential is not empty, Veff and Meta are available - if(pot_register_in.size()>0) - { - //register Potential by gathered operator - pot_in->pot_register(pot_register_in); - //effective potential term - Operator* veff = new Veff>( - GG_in, - loc_in, - LM_in, - pot_in, - nullptr, // no explicit call yet - &(LM_in->Hloc) // no explicit call yet - ); - this->opsd->add(veff); - - // Meta term - Operator* meta = new Meta>( - GG_in, - loc_in, - LM_in, - nullptr, // no explicit call yet - &(LM_in->Hloc) // no explicit call yet - ); - this->opsd->add(meta); - } - } - -#ifdef __DEEPKS - if (GlobalV::deepks_scf) - { - Operator* deepks = new DeePKS>( - loc_in, - LM_in, - nullptr,// no explicit call yet - &(LM_in->Hloc) - ); - this->opsd->add(deepks); - } -#endif - - //end node should be OperatorDFTU - if (GlobalV::dft_plus_u) - { - Operator* dftu = new OperatorDFTU>( - LM_in, - nullptr,// no explicit call yet - &(LM_in->Hloc) - ); - this->opsd->add(dftu); - } - return; -} - -template -HamiltLCAO::HamiltLCAO( - Gint_k* GK_in, - LCAO_gen_fixedH* genH_in, - LCAO_Matrix* LM_in, - Local_Orbital_Charge* loc_in, - elecstate::Potential* pot_in) -{ - this->classname = "HamiltLCAO"; - - //reset fixed Hamiltonian matrix in real space - LM_in->zeros_HSR('T'); - //reset Overlap matrix in real space - LM_in->zeros_HSR('S'); - - // Effective potential term (\sum_r ) - // Meta potential term (\sum_r ) - // in general case, target HR is Gint::pvpR_reduced, while target HK is LCAO_Matrix::Hloc2 - if(GlobalV::VL_IN_H) - { - std::vector pot_register_in; - if (GlobalV::VION_IN_H) - { - pot_register_in.push_back("local"); - } - if (GlobalV::VH_IN_H) - { - pot_register_in.push_back("hartree"); - } - pot_register_in.push_back("xc"); - if (GlobalV::imp_sol) - { - pot_register_in.push_back("surchem"); - } - if (GlobalV::EFIELD_FLAG) - { - pot_register_in.push_back("efield"); - } - if (GlobalV::GATE_FLAG) - { - pot_register_in.push_back("gatefield"); - } - pot_register_in.push_back("tddft"); - //only Potential is not empty, Veff and Meta are available - if(pot_register_in.size()>0) - { - //register Potential by gathered operator - pot_in->pot_register(pot_register_in); - //Veff term - this->ops = new Veff>>( - GK_in, - loc_in, - LM_in, - pot_in, - nullptr, // no explicit call yet - &(LM_in->Hloc2) // no explicit call yet - ); - //reset spin index and real space Hamiltonian matrix - int start_spin = -1; - GK_in->reset_spin(start_spin); - GK_in->destroy_pvpR(); - GK_in->allocate_pvpR(); - - // Meta term - Operator>* meta = new Meta>>( - GK_in, - loc_in, - LM_in, - nullptr, // no explicit call yet - &(LM_in->Hloc2) // no explicit call yet - ); - this->ops->add(meta); - } - } - - // initial operator for multi-k case - // overlap term is indispensable - Operator>* overlap = new Overlap>>( - genH_in, - LM_in, - &(LM_in->SlocR), - &(LM_in->Sloc2) - ); - if(this->ops == nullptr) - { - this->ops = overlap; - } - else - { - this->ops->add(overlap); - } - - // kinetic term (), - // in general case, target HR is LCAO_Matrix::Hloc_fixedR, while target HK is LCAO_Matrix::Hloc2 - if(GlobalV::T_IN_H) - { - Operator>* ekinetic = new Ekinetic>>( - genH_in, - LM_in, - &(LM_in->Hloc_fixedR), - &(LM_in->Hloc2) - ); - this->ops->add(ekinetic); - } - - // nonlocal term (D) - // in general case, target HR is LCAO_Matrix::Hloc_fixedR, while target HK is LCAO_Matrix::Hloc2 - if(GlobalV::VNL_IN_H) - { - Operator>* nonlocal = new Nonlocal>>( - genH_in, - LM_in, - &(LM_in->Hloc_fixedR), - &(LM_in->Hloc2) - ); - this->ops->add(nonlocal); - } - -#ifdef __DEEPKS - if (GlobalV::deepks_scf) - { - Operator>* deepks = new DeePKS>>( - loc_in, - LM_in, - nullptr,// no explicit call yet - &(LM_in->Hloc2) - ); - this->ops->add(deepks); - } -#endif - //end node should be OperatorDFTU - if (GlobalV::dft_plus_u) - { - Operator>* dftu = new OperatorDFTU>>( - LM_in, - nullptr,// no explicit call yet - &(LM_in->Hloc2) - ); - this->ops->add(dftu); - } - -} - -// case for multi-k-points -template <> -void HamiltLCAO>::matrix(MatrixBlock> &hk_in, - MatrixBlock> &sk_in) -{ - auto op = dynamic_cast>*>(this->ops); - assert(op != NULL); - op->matrixHk(hk_in, sk_in); -} - -// case for nspin<4, gamma_only -template <> void HamiltLCAO::matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) -{ - auto op = dynamic_cast*>(this->opsd); - assert(op != NULL); - op->matrixHk(hk_in, sk_in); -} - -template <> void HamiltLCAO::updateHk(const int ik) -{ - ModuleBase::TITLE("HamiltLCAO", "updateHk"); - ModuleBase::timer::tick("HamiltLCAO", "updateHk"); - //update global spin index - if (GlobalV::NSPIN == 2) - { - GlobalV::CURRENT_SPIN = GlobalC::kv.isk[ik]; - } - this->opsd->init(ik); - ModuleBase::timer::tick("HamiltLCAO", "updateHk"); -} - -template <> void HamiltLCAO>::updateHk(const int ik) -{ - ModuleBase::TITLE("HamiltLCAO", "updateHk"); - ModuleBase::timer::tick("HamiltLCAO", "updateHk"); - //update global spin index - if (GlobalV::NSPIN == 2) - { - GlobalV::CURRENT_SPIN = GlobalC::kv.isk[ik]; - } - this->ops->init(ik); - ModuleBase::timer::tick("HamiltLCAO", "updateHk"); -} - -// case for nspin<4, gamma-only k-point -template class HamiltLCAO; -// case for nspin<4, multi-k-points -// case for nspin == 4, non-collinear spin case -template class HamiltLCAO>; -} // namespace hamilt diff --git a/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h b/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h deleted file mode 100644 index 77e353dcb2..0000000000 --- a/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef HAMILTLCAO_H -#define HAMILTLCAO_H - -#include "module_hamilt_general/hamilt.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_gen_fixedH.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" -#include "module_hamilt_lcao/module_gint/gint_gamma.h" -#include "module_hamilt_lcao/module_gint/gint_k.h" -#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_charge.h" -#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" -#include "module_elecstate/potentials/potential_new.h" - -namespace hamilt -{ - -// template first for type of k space H matrix elements -// template second for type of temporary matrix, gamma_only fix-gamma-matrix + S-gamma, multi-k fix-Real + S-Real -template class HamiltLCAO : public Hamilt -{ - public: - HamiltLCAO( - Gint_Gamma* GG_in, - LCAO_gen_fixedH* genH_in, - LCAO_Matrix* LM_in, - Local_Orbital_Charge* loc_in, - elecstate::Potential* pot_in); - - HamiltLCAO( - Gint_k* GK_in, - LCAO_gen_fixedH* genH_in, - LCAO_Matrix* LM_in, - Local_Orbital_Charge* loc_in, - elecstate::Potential* pot_in); - - ~HamiltLCAO(){ - if(this->ops!= nullptr) - { - delete this->ops; - } - if(this->opsd!= nullptr) - { - delete this->opsd; - } - }; - - // for target K point, update consequence of hPsi() and matrix() - virtual void updateHk(const int ik) override; - - // core function: return H(k) and S(k) matrixs for direct solving eigenvalues. - // not used in PW base - //void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in) override; - void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) override; -}; - -} // namespace hamilt - -#endif \ No newline at end of file diff --git a/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp b/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp deleted file mode 100644 index 5f8f668b17..0000000000 --- a/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp +++ /dev/null @@ -1,189 +0,0 @@ -#include "operator_lcao.h" -#include "module_base/timer.h" -#include "module_base/tool_title.h" -#include "module_hsolver/hsolver_lcao.h" - -#ifdef __ELPA -#include "module_hsolver/diago_elpa.h" -#endif - -namespace hamilt -{ - -template<> -void OperatorLCAO::get_hs_pointers() -{ - ModuleBase::timer::tick("OperatorLCAO", "get_hs_pointers"); - this->hmatrix_k = this->LM->Hloc.data(); - if ((this->new_e_iteration && ik == 0) || hsolver::HSolverLCAO::out_mat_hs) - { - if (this->smatrix_k == nullptr) - { - this->smatrix_k = new double[this->LM->Sloc.size()]; - this->allocated_smatrix = true; - } - const int inc = 1; - BlasConnector::copy(this->LM->Sloc.size(), this->LM->Sloc.data(), inc, this->smatrix_k, inc); -#ifdef __ELPA - hsolver::DiagoElpa::DecomposedState = 0; -#endif - this->new_e_iteration = false; - } -} - -template<> -void OperatorLCAO>::get_hs_pointers() -{ - ModuleBase::timer::tick("OperatorLCAO", "get_hs_pointers"); - this->hmatrix_k = this->LM->Hloc2.data(); - this->smatrix_k = this->LM->Sloc2.data(); -} - -template<> -void OperatorLCAO::refresh_h() -{ - // Set the matrix 'H' to zero. - this->LM->zeros_HSgamma('H'); -} - -template<> -void OperatorLCAO>::refresh_h() -{ - // Set the matrix 'H' to zero. - this->LM->zeros_HSk('H'); -} - -template<> -void OperatorLCAO::folding_fixed(const int ik) -{ - ModuleBase::TITLE("OperatorLCAO", "folding_fixed"); - ModuleBase::timer::tick("OperatorLCAO", "folding_fixed"); - //add T+VNL matrix. - this->LM->update_Hloc(); - ModuleBase::timer::tick("OperatorLCAO", "folding_fixed"); -} - -template<> -void OperatorLCAO>::folding_fixed(const int ik) -{ - ModuleBase::TITLE("OperatorLCAO", "folding_fixed"); - ModuleBase::timer::tick("OperatorLCAO", "folding_fixed"); - //----------------------------------------- - // folding matrix here: S(k) (SlocR->Sloc2) - // folding matrix here: T(k)+Vnl(k) - // (Hloc_fixed->Hloc_fixed2) - //----------------------------------------- - this->LM->zeros_HSk('S'); - this->LM->zeros_HSk('T'); - this->LM->folding_fixedH(ik); - - //------------------------------------------ - // Add T(k)+Vnl(k)+Vlocal(k) - // (Hloc2 += Hloc_fixed2), (std::complex matrix) - //------------------------------------------ - this->LM->update_Hloc2(ik); - ModuleBase::timer::tick("OperatorLCAO", "folding_fixed"); -} - -template -void OperatorLCAO::init(const int ik_in) -{ - ModuleBase::TITLE("OperatorLCAO", "init"); - ModuleBase::timer::tick("OperatorLCAO", "init"); - if(this->is_first_node) - { - this->refresh_h(); - } - switch(this->cal_type) - { - case lcao_fixed: - { - //cal_type=lcao_fixed refer to fixed matrix operators, which are only rely on stucture, and not changed during SCF - - //update HR first - //in cal_type=lcao_fixed, HR should be updated by each sub-chain nodes - OperatorLCAO* last = this; - while(last != nullptr) - { - last->contributeHR(); - last = dynamic_cast*>(last->next_sub_op); - } - - //update HK next - //in cal_type=lcao_fixed, HK only need to update together in folding_fixed() - - break; - } - case lcao_gint: - { - //cal_type=lcao_gint refer to grid integral operators, which are relied on stucture and potential based on real space grids - //and should be updated each SCF steps - - OperatorLCAO* last = this; - while(last != nullptr) - { - //update HR first - //in cal_type=lcao_gint, HR should be updated by every sub-node. - last->contributeHR(); - - //update HK next - //in cal_type=lcao_gint, HK should be updated by every sub-node. - last->contributeHk(ik_in); - - last = dynamic_cast*>(last->next_sub_op); - } - - break; - } - case lcao_deepks: - { - //update HR first - //in cal_type=lcao_deepks, HR should be updated - this->contributeHR(); - - //update HK next - //in cal_type=lcao_deepks, HK should be updated - this->contributeHk(ik_in); - - break; - - } - case lcao_dftu: - { - //only HK should be updated when cal_type=lcao_dftu - //in cal_type=lcao_dftu, HK only need to update from one node - //dftu is a special operator, it should be the last node of chain - //Overlap matrix for ik is used by it, do folding first and then return - this->folding_fixed(ik_in); - this->contributeHk(ik_in); - return; - - break; - } - case lcao_exx: - { - //update HR first - //in cal_type=lcao_exx, HR should be updated by most priority sub-chain nodes - this->contributeHR(); - - //update HK next - //in cal_type=lcao_exx, HK only need to update from one node - this->contributeHk(ik_in); - - break; - } - } - if(this->next_op != nullptr) - {//it is not the last node, loop next init() function - this->next_op->init(ik_in); - } - else - {//it is the last node, do folding process together - this->folding_fixed(ik_in); - } - - ModuleBase::timer::tick("OperatorLCAO", "init"); -} -template class OperatorLCAO; -template class OperatorLCAO>; -} // namespace hamilt diff --git a/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h b/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h deleted file mode 100644 index 81f9f900db..0000000000 --- a/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h +++ /dev/null @@ -1,101 +0,0 @@ -#ifndef OPERATORLCAO_H -#define OPERATORLCAO_H -#include"module_hamilt_general/operator.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" -#include "module_hamilt_general/matrixblock.h" - -namespace hamilt -{ - -template -class OperatorLCAO : public Operator -{ - public: - virtual ~OperatorLCAO() - { - if(this->allocated_smatrix) delete[] this->smatrix_k; - }; - - /* Function init(k) is used for update HR and HK , - data pointers of HR and HK are not passed by this function, but passed by constructors of every derived classes. - No need to override init() in base class, but must override in derived class */ - virtual void init(const int ik_in)override; - - void refresh_h(); - - /* Function getHR() is designed to update HR matrix only, it will loop all contributeHR() functions in chain table. - Detail of this function is still in developed, HR matrix has two form: HR_all_spin and HR_one_spin. - For NSPIN=2 case, HR_one_spin for spin-up and spin-down is not constructed at same time. - */ - //void getHR(T* hr_pointer); - - /* Function contributeHR() is defined in derived class, for constructing - */ - virtual void contributeHR() - { - return; - } - - /* Function matrixHk() is used for get information of HK matrix and SK matrix for diagolization. - Matrixes HK and SK come from LCAO_Matrix class. - Gamma_only case (T = double), SK would not changed during one SCF loop, a template triangle matrix SK_temp is used for accelerating. - General case (T = std::complex), only pointers of HK and SK saved in OperatorLCAO - */ - void matrixHk(MatrixBlock &hk_in, MatrixBlock &sk_in) - { - this->get_hs_pointers(); -#ifdef __MPI - hk_in = MatrixBlock{hmatrix_k, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - this->LM->ParaV->desc}; - sk_in = MatrixBlock{smatrix_k, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - this->LM->ParaV->desc}; -#else - hk_in = MatrixBlock{hmatrix_k, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - nullptr}; - sk_in = MatrixBlock{smatrix_k, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - nullptr}; -#endif - } - - /* Function contributeHk() is defined in derived class, for constructing (K) - */ - virtual void contributeHk(int ik) - { - return; - } - - //protected: - // Hamiltonian matrix which are stored in LCAO_Matrix and calculated in OperatorLCAO - LCAO_Matrix* LM = nullptr; - - protected: - bool new_e_iteration = true; - - 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 for multi-k-points case - T* hmatrix_k = nullptr; - T* smatrix_k = nullptr; - - //only used for Gamma_only case - bool allocated_smatrix = false; - - //fixed HR matrix folding to HK - void folding_fixed(const int ik); - - -}; - -}//end namespace hamilt - -#endif \ No newline at end of file diff --git a/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp deleted file mode 100644 index 3cfdd30b1d..0000000000 --- a/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "ELEC_evolve.h" - -#include "module_base/timer.h" -#include "module_base/parallel_reduce.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#include "module_elecstate/module_charge/symmetry_rho.h" -#include "LCAO_evolve.h" -#include "module_hamilt_lcao/module_dftu/dftu.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" - -ELEC_evolve::ELEC_evolve(){}; -ELEC_evolve::~ELEC_evolve(){}; - -double ELEC_evolve::td_force_dt; -bool ELEC_evolve::td_vext; -std::vector ELEC_evolve::td_vext_dire_case; -bool ELEC_evolve::out_dipole; -bool ELEC_evolve::out_efield; -double ELEC_evolve::td_print_eij; // the threshold to output Eij elements -int ELEC_evolve::td_edm; // 0: new edm method 1: old edm method - -// this routine only serves for TDDFT using LCAO basis set -void ELEC_evolve::evolve_psi(const int& istep, - hamilt::Hamilt* phm, - Local_Orbital_wfc& lowf, - psi::Psi>* psi, - psi::Psi>* psi_laststep, - std::complex** Hk_laststep, - ModuleBase::matrix& ekb) -{ - ModuleBase::TITLE("ELEC_evolve", "eveolve_psi"); - ModuleBase::timer::tick("ELEC_evolve", "evolve_psi"); - - // pool parallization in future -- mohan note 2021-02-09 - for (int ik = 0; ik < GlobalC::kv.nks; ik++) - { - phm->updateHk(ik); - - ModuleBase::timer::tick("Efficience", "evolve_k"); - Evolve_LCAO_Matrix ELM(lowf.ParaV); - psi->fix_k(ik); - psi_laststep->fix_k(ik); - ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, Hk_laststep[ik], &(ekb(ik, 0))); - ModuleBase::timer::tick("Efficience", "evolve_k"); - } // end k - - ModuleBase::timer::tick("ELEC_evolve", "evolve_psi"); - return; -} diff --git a/module_hamilt_lcao/module_tddft/ELEC_evolve.h b/module_hamilt_lcao/module_tddft/ELEC_evolve.h deleted file mode 100644 index eb647b83c3..0000000000 --- a/module_hamilt_lcao/module_tddft/ELEC_evolve.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef ELEC_EVOLVE_H -#define ELEC_EVOLVE_H - -#include "module_base/global_function.h" -#include "module_base/global_variable.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_hamilt.h" -#include "module_esolver/esolver_ks_lcao.h" -#include "module_esolver/esolver_ks_lcao_tddft.h" -#include "module_psi/psi.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" - -//----------------------------------------------------------- -// mohan add 2021-02-09 -// This class is used to evolve the electronic wave functions -// in TDDFT in terms of the multiple k points -// k is the index for the points in the first Brillouin zone -//----------------------------------------------------------- - -class ELEC_evolve -{ - - friend class ELEC_scf; - friend class ModuleESolver::ESolver_KS_LCAO; - friend class ModuleESolver::ESolver_KS_LCAO_TDDFT; - - public: - ELEC_evolve(); - ~ELEC_evolve(); - - // fuxiang add 2021-05-25 - - static double td_force_dt; - static bool td_vext; - static std::vector td_vext_dire_case; - static bool out_dipole; - static bool out_efield; - - static double td_print_eij; // the threshold to output Eij elements - static int td_edm; // 0: new edm method 1: old edm method - - private: - static void evolve_psi(const int& istep, - hamilt::Hamilt* phm, - Local_Orbital_wfc& lowf, - psi::Psi>* psi, - psi::Psi>* psi_laststep, - std::complex** Hk_laststep, - ModuleBase::matrix& ekb); -}; - -#endif diff --git a/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp b/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp deleted file mode 100644 index 49b190f6af..0000000000 --- a/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp +++ /dev/null @@ -1,1022 +0,0 @@ -#include "LCAO_evolve.h" - -#include "module_io/input.h" -#include "module_base/scalapack_connector.h" -#include "module_base/lapack_connector.h" -#include "module_io/write_HS.h" -#include "module_hamilt_pw/hamilt_pwdft/global.h" -#include "ELEC_evolve.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" - -#include -// fuxiang add 2016-10-28 - -Evolve_LCAO_Matrix::~Evolve_LCAO_Matrix() -{ -} - -inline int globalIndex(int localindex, int nblk, int nprocs, int myproc) -{ - int iblock, gIndex; - iblock = localindex / nblk; - gIndex = (iblock * nprocs + myproc) * nblk + localindex % nblk; - return gIndex; -} - -void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, - hamilt::Hamilt* p_hamilt, - psi::Psi>* psi_k, - psi::Psi>* psi_k_laststep, - std::complex* Hk_laststep, - double* ekb) const -{ - ModuleBase::TITLE("Evolve_LCAO_Matrix", "evolve_complex_matrix"); - time_t time_start = time(NULL); - GlobalV::ofs_running << " Start Time : " << ctime(&time_start); - - if (GlobalV::ESOLVER_TYPE == "tddft") - { -#ifdef __MPI - this->using_ScaLAPACK_complex(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), Hk_laststep, p_hamilt, psi_k[0].get_pointer(), ekb); -#else - this->using_LAPACK_complex(ik, p_hamilt, psi_k[0].get_pointer(), psi_k_laststep[0].get_pointer(), ekb); -#endif - } - else - { - ModuleBase::WARNING_QUIT("Evolve_LCAO_Matrix::evolve_complex_matrix", - "only esolver_type == tddft cando evolve"); - } - - time_t time_end = time(NULL); - ModuleBase::GlobalFunc::OUT_TIME("evolve(std::complex)", time_start, time_end); - - return; -} - -void Evolve_LCAO_Matrix::using_LAPACK_complex(const int& ik, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - std::complex* psi_k_laststep, - double* ekb) const -{ - ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_LAPACK_complex"); - - // Calculate the U operator - - ModuleBase::ComplexMatrix Htmp(GlobalV::NLOCAL, GlobalV::NLOCAL); - ModuleBase::ComplexMatrix Stmp(GlobalV::NLOCAL, GlobalV::NLOCAL); - hamilt::MatrixBlock> h_mat, s_mat; - p_hamilt->matrix(h_mat, s_mat); - for (int i = 0; i < GlobalV::NLOCAL; i++) - { - for (int j = 0; j < GlobalV::NLOCAL; j++) - { - Htmp(i, j) = h_mat.p[i * GlobalV::NLOCAL + j]; - // Htmp(i,j) = (this->LM->Hloc2[i*GlobalV::NLOCAL+j] +this->LM->Hloc2_laststep[i*GlobalV::NLOCAL+j])/2.0; - Stmp(i, j) = s_mat.p[i * GlobalV::NLOCAL + j]; - } - } - - ModuleBase::ComplexMatrix wfc_tmp(GlobalV::NBANDS, GlobalV::NLOCAL, true); - ModuleBase::ComplexMatrix wfc_laststep_tmp(GlobalV::NBANDS, GlobalV::NLOCAL, true); - // wfc_laststep_tmp.c = psi_k_laststep; - - for (int i = 0; i < GlobalV::NBANDS; i++) - { - for (int j = 0; j < GlobalV::NLOCAL; j++) - { - wfc_laststep_tmp.c[i * GlobalV::NLOCAL + j] = psi_k_laststep[i * GlobalV::NLOCAL + j]; - } - } - - /* - GlobalV::ofs_running << " Htmp: " < * work = new std::complex[lwork]; - ModuleBase::GlobalFunc::ZEROS(work, lwork); - int IPIV[GlobalV::NLOCAL]; - - LapackConnector::zgetrf( GlobalV::NLOCAL, GlobalV::NLOCAL, Stmp, GlobalV::NLOCAL, IPIV, &INFO); - LapackConnector::zgetri( GlobalV::NLOCAL, Stmp, GlobalV::NLOCAL, IPIV, work, lwork, &INFO); - */ - /* - std::cout << " S^-1: " <( -S_plus_H(i,j).imag(), S_plus_H(i,j).real() ); - } - } - - ModuleBase::ComplexMatrix Idmat(GlobalV::NLOCAL,GlobalV::NLOCAL); - for(int i=0; i(1.0, 0.0); - else Idmat(i,j) = std::complex(0.0, 0.0); - } - } - */ - ModuleBase::ComplexMatrix Numerator(GlobalV::NLOCAL, GlobalV::NLOCAL); - // Numerator = Idmat - 0.5*INPUT.mdp.md_dt*41.34*Denominator; - // Denominator = Idmat + 0.5*INPUT.mdp.md_dt*41.34*Denominator; - - complex para = {0.0, 1.0}; - para = para * 0.25 * INPUT.mdp.md_dt; - Numerator = Stmp - para * Htmp; - Denominator = Stmp + para * Htmp; - - int info; - int lwork = 3 * GlobalV::NLOCAL - 1; // tmp - std::complex* work = new std::complex[lwork]; - ModuleBase::GlobalFunc::ZEROS(work, lwork); - int* ipiv = new int[GlobalV::NLOCAL]; - - LapackConnector::zgetrf(GlobalV::NLOCAL, GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, &info); - LapackConnector::zgetri(GlobalV::NLOCAL, Denominator, GlobalV::NLOCAL, ipiv, work, lwork, &info); - - ModuleBase::ComplexMatrix U_operator(GlobalV::NLOCAL, GlobalV::NLOCAL); - /* - GlobalV::ofs_running << " Numerator: " <* psi_k_laststep, - const std::complex* Hk_laststep, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - double* ekb) const -{ - ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_ScaLAPACK_complex"); - - int print_matrix = 0; - hamilt::MatrixBlock> h_mat, s_mat; - p_hamilt->matrix(h_mat, s_mat); - - complex* Stmp = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Stmp, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, s_mat.p, 1, Stmp, 1); - - complex* Htmp = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); - - //print test - /*GlobalV::ofs_running << " H(t) matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Hk_laststep[i * this->ParaV->ncol + j].real() << "+" << Hk_laststep[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl;} - GlobalV::ofs_running << " H(t+dt) matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl;} - // -*/ - - complex mixing = {0.5, 0.0}; - ScalapackConnector::geadd( - 'N', - nlocal, - nlocal, - mixing, - Hk_laststep, - 1, - 1, - this->ParaV->desc, - mixing, - Htmp, - 1, - 1, - this->ParaV->desc - ); - /*GlobalV::ofs_running << " H(t+dt/2) matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl;}*/ - complex* U_operator = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); - -// (1)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief compute U_operator - /// @input Stmp, Htmp, print_matrix - /// @output U_operator - compute_U_operator(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); - -// (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief apply U_operator to the wave function of the previous step for new wave function - /// @input U_operator, psi_k_laststep - /// @output psi_k - U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k); - - - -// (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief normalize psi_k - /// @input Stmp, psi_not_norm, psi_k, print_matrix - /// @output psi_k - norm_wfc(nband, nlocal, Stmp, psi_k, print_matrix); - - -// (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief compute ekb - /// @input Htmp, psi_k - /// @output ekb - compute_ekb(nband, nlocal, Htmp, psi_k, ekb); - - delete[] Stmp; - delete[] Htmp; - delete[] U_operator; - return; -} - - -void Evolve_LCAO_Matrix::compute_U_operator( - const int nband, - const int nlocal, - const std::complex* Stmp, - const std::complex* Htmp, - std::complex* U_operator, - const int print_matrix) const -{ - // (1) copy Htmp to Numerator & Denominator - complex* Numerator = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Numerator, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, Htmp, 1, Numerator, 1); - - complex* Denominator = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Denominator, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, Htmp, 1, Denominator, 1); - - if (print_matrix) - { - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " S matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Stmp[i * this->ParaV->ncol + j].real() << "+" << Stmp[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " H matrix :" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" << Numerator[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } - -// ->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - // (2) compute Numerator & Denominator by GEADD - // Numerator = Stmp - i*para * Htmp; beta1 = - para = -0.25 * INPUT.mdp.md_dt - // Denominator = Stmp + i*para * Htmp; beta2 = para = 0.25 * INPUT.mdp.md_dt - complex alpha = {1.0, 0.0}; - complex beta1 = {0.0, -0.25 * INPUT.mdp.md_dt}; - complex beta2 = {0.0, 0.25 * INPUT.mdp.md_dt}; - - ScalapackConnector::geadd( - 'N', - nlocal, - nlocal, - alpha, - Stmp, - 1, - 1, - this->ParaV->desc, - beta1, - Numerator, - 1, - 1, - this->ParaV->desc - ); - ScalapackConnector::geadd( - 'N', - nlocal, - nlocal, - alpha, - Stmp, - 1, - 1, - this->ParaV->desc, - beta2, - Denominator, - 1, - 1, - this->ParaV->desc - ); - - if (print_matrix) - { - GlobalV::ofs_running << " fenmu:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" << Denominator[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - } - -//->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - // (3) Next, invert Denominator - int* ipiv = new int[this->ParaV->nloc]; - int info = 0; - // (3.1) compute ipiv - ScalapackConnector::getrf( - nlocal, - nlocal, - Denominator, - 1, - 1, - this->ParaV->desc, - ipiv, - &info - ); - int lwork = -1; - int liwotk = -1; - std::vector> work(1, 0); - std::vector iwork(1, 0); - // (3.2) compute work - ScalapackConnector::getri( - nlocal, - Denominator, - 1, - 1, - this->ParaV->desc, - ipiv, - work.data(), - &lwork, - iwork.data(), - &liwotk, - &info - ); - lwork = work[0].real(); - work.resize(lwork, 0); - liwotk = iwork[0]; - iwork.resize(liwotk, 0); - // (3.3) compute inverse matrix of matrix_A - ScalapackConnector::getri( - nlocal, - Denominator, - 1, - 1, - this->ParaV->desc, - ipiv, - work.data(), - &lwork, - iwork.data(), - &liwotk, - &info - ); - assert(0 == info); - -//->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - // (4) U_operator = Denominator * Numerator; - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nlocal, - nlocal, - 1.0, - Denominator, - 1, - 1, - this->ParaV->desc, - Numerator, - 1, - 1, - this->ParaV->desc, - 0.0, - U_operator, - 1, - 1, - this->ParaV->desc - ); - - if (print_matrix) - { - GlobalV::ofs_running << " fenmu^-1:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Denominator[i * this->ParaV->ncol + j].real() << "+" << Denominator[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " fenzi:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - GlobalV::ofs_running << Numerator[i * this->ParaV->ncol + j].real() << "+" << Numerator[i * this->ParaV->ncol + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " U operator:" << endl; - for (int i = 0; i < this->ParaV->nrow; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = U_operator[i * this->ParaV->ncol + j].real(); - bb = U_operator[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - } - -// cout << "U_operator Success!!!" <* U_operator, - const std::complex* psi_k_laststep, - std::complex* psi_k) const -{ - - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - U_operator, - 1, - 1, - this->ParaV->desc, - psi_k_laststep, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc - ); -} - - -void Evolve_LCAO_Matrix::norm_wfc( - const int nband, - const int nlocal, - const std::complex* Stmp, - std::complex* psi_k, - const int print_matrix) const -{ - complex* tmp1 = new complex[this->ParaV->nloc_wfc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); - - complex* Cij = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Cij, this->ParaV->nloc); - - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - Stmp, - 1, - 1, - this->ParaV->desc, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc - ); - - - ScalapackConnector::gemm( - 'C', - 'N', - nband, - nband, - nlocal, - 1.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - Cij, - 1, - 1, - this->ParaV->desc - ); - - int info; - int myid; - MPI_Comm_rank(this->ParaV->comm_2D, &myid); - int naroc[2]; // maximum number of row or column - - for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) - { - for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) - { - const int coord[2] = {iprow, ipcol}; - int src_rank; - info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); - if (myid == src_rank) - { - naroc[0] = this->ParaV->nrow; - naroc[1] = this->ParaV->ncol; - for (int j = 0; j < naroc[1]; ++j) - { - int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); - if (igcol >= nband) - continue; - for (int i = 0; i < naroc[0]; ++i) - { - int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); - if (igrow >= nband) - continue; - if (igcol == igrow) - { - Cij[j * naroc[0] + i] = {1.0 / sqrt(Cij[j * naroc[0] + i].real()), 0.0}; - } - else - { - Cij[j * naroc[0] + i] = {0.0, 0.0}; - } - } - } - } - } // loop ipcol - } // loop iprow - - // std::cout << "nlocal" << nlocal << std::endl; - // std::cout << "GlobalV::NLOCAL" << GlobalV::NLOCAL << std::endl; - BlasConnector::copy(this->ParaV->nloc_wfc, psi_k, 1, tmp1, 1); - - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nband, - nband, - 1.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - Cij, - 1, - 1, - this->ParaV->desc, - 0.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc - ); - - - if (print_matrix) - { - GlobalV::ofs_running << " Cij:" << endl; - for (int i = 0; i < this->ParaV->ncol; i++) - { - for (int j = 0; j < this->ParaV->nrow; j++) - { - GlobalV::ofs_running << Cij[i * this->ParaV->ncol + j].real() << "+" << Cij[i * this->ParaV->ncol_bands + j].imag() << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " psi_k:" << endl; - for (int i = 0; i < this->ParaV->ncol_bands; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = psi_k[i * this->ParaV->ncol + j].real(); - bb = psi_k[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << " psi_k nlocal*nlocal:" << endl; - for (int i = 0; i < this->ParaV->ncol; i++) - { - for (int j = 0; j < this->ParaV->ncol; j++) - { - double aa, bb; - aa = tmp1[i * this->ParaV->ncol + j].real(); - bb = tmp1[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < 1e-8) - aa = 0.0; - if (abs(bb) < 1e-8) - bb = 0.0; - GlobalV::ofs_running << aa << "+" << bb << "i "; - } - GlobalV::ofs_running << endl; - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running << endl; - } - - - delete[] tmp1; - delete[] Cij; - -} - - -void Evolve_LCAO_Matrix::compute_ekb( - const int nband, - const int nlocal, - const std::complex* Htmp, - const std::complex* psi_k, - double* ekb) const -{ - - complex* tmp1 = new complex[this->ParaV->nloc_wfc]; - ModuleBase::GlobalFunc::ZEROS(tmp1, this->ParaV->nloc_wfc); - - complex* Eij = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Eij, this->ParaV->nloc); - - ScalapackConnector::gemm( - 'N', - 'N', - nlocal, - nband, - nlocal, - 1.0, - Htmp, - 1, - 1, - this->ParaV->desc, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - tmp1, - 1, - 1, - this->ParaV->desc_wfc - ); - - ScalapackConnector::gemm( - 'C', - 'N', - nband, - nband, - nlocal, - 1.0, - psi_k, - 1, - 1, - this->ParaV->desc_wfc, - tmp1, - 1, - 1, - this->ParaV->desc_wfc, - 0.0, - Eij, - 1, - 1, - this->ParaV->desc - ); - - - if (ELEC_evolve::td_print_eij > 0.0) - { - GlobalV::ofs_running - << "------------------------------------------------------------------------------------------------" - << endl; - GlobalV::ofs_running << " Eij:" << endl; - for (int i = 0; i < this->ParaV->ncol; i++) - { - for (int j = 0; j < this->ParaV->nrow; j++) - { - double aa, bb; - aa = Eij[i * this->ParaV->ncol + j].real(); - bb = Eij[i * this->ParaV->ncol + j].imag(); - if (abs(aa) < ELEC_evolve::td_print_eij) - aa = 0.0; - if (abs(bb) < ELEC_evolve::td_print_eij) - bb = 0.0; - if (aa > 0.0 || bb > 0.0) - { - GlobalV::ofs_running << i << " " << j << " " << aa << "+" << bb << "i " << endl; - } - } - } - GlobalV::ofs_running << endl; - GlobalV::ofs_running - << "------------------------------------------------------------------------------------------------" - << endl; - } - - - int info; - int myid; - int naroc[2]; - MPI_Comm_rank(this->ParaV->comm_2D, &myid); - - double* Eii = new double[nband]; - ModuleBase::GlobalFunc::ZEROS(Eii, nband); - for (int iprow = 0; iprow < this->ParaV->dim0; ++iprow) - { - for (int ipcol = 0; ipcol < this->ParaV->dim1; ++ipcol) - { - const int coord[2] = {iprow, ipcol}; - int src_rank; - info = MPI_Cart_rank(this->ParaV->comm_2D, coord, &src_rank); - if (myid == src_rank) - { - naroc[0] = this->ParaV->nrow; - naroc[1] = this->ParaV->ncol; - for (int j = 0; j < naroc[1]; ++j) - { - int igcol = globalIndex(j, this->ParaV->nb, this->ParaV->dim1, ipcol); - if (igcol >= nband) - continue; - for (int i = 0; i < naroc[0]; ++i) - { - int igrow = globalIndex(i, this->ParaV->nb, this->ParaV->dim0, iprow); - if (igrow >= nband) - continue; - if (igcol == igrow) - { - Eii[igcol] = Eij[j * naroc[0] + i].real(); - } - } - } - } - } // loop ipcol - } // loop iprow - info = MPI_Allreduce(Eii, ekb, nband, MPI_DOUBLE, MPI_SUM, this->ParaV->comm_2D); - - delete[] tmp1; - delete[] Eij; - delete[] Eii; -} - - -#endif diff --git a/module_hamilt_lcao/module_tddft/LCAO_evolve.h b/module_hamilt_lcao/module_tddft/LCAO_evolve.h deleted file mode 100644 index 1f1f4e1fc0..0000000000 --- a/module_hamilt_lcao/module_tddft/LCAO_evolve.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef EVOLVE_LCAO_MATRIX_H -#define EVOLVE_LCAO_MATRIX_H - -#include "module_base/complexmatrix.h" -#include "module_base/global_function.h" -#include "module_base/global_variable.h" -#include "module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h" -#include "module_psi/psi.h" -#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h" -#include "module_hamilt_lcao/hamilt_lcaodft/local_orbital_wfc.h" - -class Evolve_LCAO_Matrix -{ - public: - Evolve_LCAO_Matrix(const Parallel_Orbitals* pv) - { - this->ParaV = pv; - } - ~Evolve_LCAO_Matrix(); - - void evolve_complex_matrix(const int& ik, - hamilt::Hamilt* p_hamilt, - psi::Psi>* psi_k, - psi::Psi>* psi_k_laststep, - std::complex* Hk_laststep, - double* ekb) const; - - private: - // LCAO_Matrix* LM; - const Parallel_Orbitals* ParaV; - - void using_LAPACK_complex(const int& ik, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - std::complex* psi_k_laststep, - double* ekb) const; -#ifdef __MPI - void using_ScaLAPACK_complex( - const int nband, - const int nlocal, - const std::complex* psi_k_laststep, - const std::complex* Hk_laststep, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - double* ekb) const; - - void compute_U_operator( - const int nband, - const int nlocal, - const std::complex* Stmp, - const std::complex* Htmp, - std::complex* U_operator, - const int print_matrix) const; - - void U_to_wfc( - const int nband, - const int nlocal, - const std::complex* U_operator, - const std::complex* psi_k_laststep, - std::complex* psi_k) const; - - void norm_wfc( - const int nband, - const int nlocal, - const std::complex* Stmp, - std::complex* psi_k, - const int print_matrix) const; - - - void compute_ekb( - const int nband, - const int nlocal, - const std::complex* Htmp, - const std::complex* psi_k, - double* ekb) const; - -#endif -}; -#endif From 4f7e0f6a5a09ca59d3d1b23b815270ec8e661060 Mon Sep 17 00:00:00 2001 From: HTZhao <104255052+ESROAMER@users.noreply.github.com> Date: Tue, 18 Apr 2023 21:04:50 +0800 Subject: [PATCH 8/8] Add files via upload --- .../module_esolver/esolver_ks_lcao_tddft.cpp | 25 +++- source/module_esolver/esolver_ks_lcao_tddft.h | 1 + source/module_hamilt_general/hamilt.h | 4 +- .../hamilt_lcaodft/LCAO_matrix.cpp | 13 -- .../hamilt_lcaodft/LCAO_matrix.h | 3 - .../hamilt_lcaodft/hamilt_lcao.cpp | 19 +-- .../hamilt_lcaodft/hamilt_lcao.h | 1 - .../operator_lcao/operator_lcao.cpp | 14 -- .../operator_lcao/operator_lcao.h | 30 +--- .../module_tddft/ELEC_evolve.cpp | 7 +- .../module_tddft/ELEC_evolve.h | 1 + .../module_tddft/LCAO_evolve.cpp | 130 +++++------------- .../module_tddft/LCAO_evolve.h | 14 +- 13 files changed, 61 insertions(+), 201 deletions(-) diff --git a/source/module_esolver/esolver_ks_lcao_tddft.cpp b/source/module_esolver/esolver_ks_lcao_tddft.cpp index f6feaf5bab..4276cb5fb3 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.cpp +++ b/source/module_esolver/esolver_ks_lcao_tddft.cpp @@ -41,6 +41,9 @@ ESolver_KS_LCAO_TDDFT::~ESolver_KS_LCAO_TDDFT() { // this->orb_con.clear_after_ions(GlobalC::UOT, GlobalC::ORB, GlobalV::deepks_setorb, GlobalC::ucell.infoNL.nproj); delete psi_laststep; + for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ + delete Hk_laststep[ik];} + delete Hk_laststep; } void ESolver_KS_LCAO_TDDFT::Init(Input& inp, UnitCell& ucell) @@ -188,7 +191,7 @@ void ESolver_KS_LCAO_TDDFT::hamilt2density(int istep, int iter, double ethr) if (GlobalV::ESOLVER_TYPE == "tddft" && istep >= 2 && !GlobalV::GAMMA_ONLY_LOCAL) { - ELEC_evolve::evolve_psi(istep, this->p_hamilt, this->LOWF, this->psi, this->psi_laststep, this->pelec_td->ekb); + ELEC_evolve::evolve_psi(istep, this->p_hamilt, this->LOWF, this->psi, this->psi_laststep, this->Hk_laststep, this->pelec_td->ekb); this->pelec_td->psiToRho_td(this->psi[0]); // this->pelec_td->psiToRho(this->psi[0]); } @@ -351,7 +354,7 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) GlobalC::en.cal_converged(this->pelec); } - // store wfc + // store wfc and Hk laststep if (istep >= 1 && this->conv_elec) { if (this->psi_laststep == nullptr) @@ -364,6 +367,13 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) this->psi_laststep = new psi::Psi>(GlobalC::kv.nks, GlobalV::NBANDS, GlobalV::NLOCAL, nullptr); #endif + if (this->Hk_laststep == nullptr){ + this->Hk_laststep = new std::complex*[GlobalC::kv.nks]; + for(int ik = 0; ik < GlobalC::kv.nks; ++ik){ + this->Hk_laststep[ik] = new std::complex[this->LOC.ParaV->nloc]; + ModuleBase::GlobalFunc::ZEROS(Hk_laststep[ik], this->LOC.ParaV->nloc); + } + } for (int ik = 0; ik < GlobalC::kv.nks; ++ik) { @@ -372,10 +382,15 @@ void ESolver_KS_LCAO_TDDFT::updatepot(const int istep, const int iter) int size0 = psi->get_nbands() * psi->get_nbasis(); for (int index = 0; index < size0; ++index) psi_laststep[0].get_pointer()[index] = psi[0].get_pointer()[index]; + //use for new propagator + this->p_hamilt->updateHk(ik); + //store Hk laststep + hamilt::MatrixBlock> h_mat, s_mat; + this->p_hamilt->matrix(h_mat, s_mat); + BlasConnector::copy(this->LOC.ParaV->nloc, h_mat.p, 1, Hk_laststep[ik], 1); } - for (int ik = 0; ik < GlobalC::kv.nks; ++ik){ - this->LM.update_Hl(ik); - } + + if (istep > 1 && ELEC_evolve::td_edm == 0) this->cal_edm_tddft(); } diff --git a/source/module_esolver/esolver_ks_lcao_tddft.h b/source/module_esolver/esolver_ks_lcao_tddft.h index a943cebe5a..6f9da4a185 100644 --- a/source/module_esolver/esolver_ks_lcao_tddft.h +++ b/source/module_esolver/esolver_ks_lcao_tddft.h @@ -22,6 +22,7 @@ class ESolver_KS_LCAO_TDDFT : public ESolver_KS_LCAO void Init(Input& inp, UnitCell& cell) override; psi::Psi>* psi_laststep = nullptr; + std::complex** Hk_laststep = nullptr; //same as pelec elecstate::ElecStateLCAO_TDDFT* pelec_td = nullptr; diff --git a/source/module_hamilt_general/hamilt.h b/source/module_hamilt_general/hamilt.h index 0e01c75ee8..65962311fa 100644 --- a/source/module_hamilt_general/hamilt.h +++ b/source/module_hamilt_general/hamilt.h @@ -27,9 +27,7 @@ class Hamilt // core function: return H(k) and S(k) matrixs for direct solving eigenvalues. virtual void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in){return;} virtual void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in){return;} - // used for tddft evolve - virtual void matrix_l(MatrixBlock> &hk_in, MatrixBlock> &hk_last_in, MatrixBlock> &sk_in){return;} - virtual void matrix_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in){return;} + std::string classname = "none"; int non_first_scf=0; diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp index 31ed633313..1a4fb745da 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.cpp @@ -101,12 +101,10 @@ void LCAO_Matrix::allocate_HS_k(const long &nloc) this->Sloc2.resize(nloc); this->Hloc_fixed2.resize(nloc); this->Hloc2.resize(nloc); - this->Hloc2_last.resize(nloc); ModuleBase::GlobalFunc::ZEROS(Sloc2.data(),nloc); ModuleBase::GlobalFunc::ZEROS(Hloc_fixed2.data(),nloc); ModuleBase::GlobalFunc::ZEROS(Hloc2.data(),nloc); - ModuleBase::GlobalFunc::ZEROS(Hloc2_last.data(),nloc); return; } @@ -596,18 +594,7 @@ void LCAO_Matrix::update_Hloc2(const int &ik) return; } -void LCAO_Matrix::update_Hl(const int &ik) -{ -#ifdef _OPENMP -#pragma omp parallel for schedule(static, 1024) -#endif - for (long i = 0; i < this->ParaV->nloc; i++) - { - Hloc2_last[i]=Hloc2[i]; - } - return; -} void LCAO_Matrix::output_HSk(const char &mtype, std::string &fn) { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h index 3a8731ede4..dd33df593c 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/LCAO_matrix.h @@ -54,7 +54,6 @@ class LCAO_Matrix // diagonalize. //------------------------------ std::vector> Hloc2; - std::vector> Hloc2_last; std::vector> Sloc2; std::vector> Hloc_fixed2; //with soc, zhengdy-soc @@ -203,8 +202,6 @@ class LCAO_Matrix void update_Hloc(void); void update_Hloc2(const int &ik); - void update_Hl(const int &ik); - void allocate_HS_R(const int &nnr); void output_HSk(const char &mtype, std::string &fn); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp index ff394cb625..978e0dd61c 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.cpp @@ -317,24 +317,7 @@ template <> void HamiltLCAO::matrix(MatrixBlock &hk_in, MatrixBl assert(op != NULL); op->matrixHk(hk_in, sk_in); } -template <> -void HamiltLCAO>::matrix_l(MatrixBlock> &hk_in, - MatrixBlock> &hk_last_in, - MatrixBlock> &sk_in) -{ - auto op = dynamic_cast>*>(this->ops); - assert(op != NULL); - op->matrixHk_l(hk_in, hk_last_in, sk_in); -} -template <> -void HamiltLCAO::matrix_l(MatrixBlock &hk_in, - MatrixBlock &hk_last_in, - MatrixBlock &sk_in) -{ - auto op = dynamic_cast*>(this->opsd); - assert(op != NULL); - op->matrixHk_l(hk_in, hk_last_in, sk_in); -} + template <> void HamiltLCAO::updateHk(const int ik) { ModuleBase::TITLE("HamiltLCAO", "updateHk"); diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h index 24ab48673c..77e353dcb2 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/hamilt_lcao.h @@ -51,7 +51,6 @@ template class HamiltLCAO : public Hamilt // not used in PW base //void matrix(MatrixBlock> &hk_in, MatrixBlock> &sk_in) override; void matrix(MatrixBlock &hk_in, MatrixBlock &sk_in) override; - void matrix_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in) override; }; } // namespace hamilt diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp index 4086b7b070..5f8f668b17 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.cpp @@ -39,20 +39,6 @@ void OperatorLCAO>::get_hs_pointers() this->smatrix_k = this->LM->Sloc2.data(); } -template<> -void OperatorLCAO::get_hls_pointers() -{ - return; -} -template<> -void OperatorLCAO>::get_hls_pointers() -{ - ModuleBase::timer::tick("OperatorLCAO", "get_hs_pointers"); - this->hmatrix_k = this->LM->Hloc2.data(); - this->hmatrix_k_last = this->LM->Hloc2_last.data(); - this->smatrix_k = this->LM->Sloc2.data(); -} - template<> void OperatorLCAO::refresh_h() { diff --git a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h index 55a8d4d755..81f9f900db 100644 --- a/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h +++ b/source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/operator_lcao.h @@ -64,33 +64,7 @@ class OperatorLCAO : public Operator nullptr}; #endif } - void matrixHk_l(MatrixBlock &hk_in, MatrixBlock &hk_last_in, MatrixBlock &sk_in) - { - this->get_hls_pointers(); -#ifdef __MPI - hk_in = MatrixBlock{hmatrix_k, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - this->LM->ParaV->desc}; - hk_last_in = MatrixBlock{hmatrix_k_last, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - this->LM->ParaV->desc}; - sk_in = MatrixBlock{smatrix_k, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - this->LM->ParaV->desc}; -#else - hk_in = MatrixBlock{hmatrix_k, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - nullptr}; - sk_in = MatrixBlock{smatrix_k, - (size_t)this->LM->ParaV->nrow, - (size_t)this->LM->ParaV->ncol, - nullptr}; -#endif - } + /* Function contributeHk() is defined in derived class, for constructing (K) */ virtual void contributeHk(int ik) @@ -107,12 +81,10 @@ class OperatorLCAO : public Operator private: void get_hs_pointers(); - void get_hls_pointers(); // there are H and S matrix for each k point in reciprocal space // type double for gamma_only case, type complex for multi-k-points case T* hmatrix_k = nullptr; - T* hmatrix_k_last = nullptr; T* smatrix_k = nullptr; //only used for Gamma_only case diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp index 2a196c1f77..3cfdd30b1d 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.cpp @@ -25,6 +25,7 @@ void ELEC_evolve::evolve_psi(const int& istep, Local_Orbital_wfc& lowf, psi::Psi>* psi, psi::Psi>* psi_laststep, + std::complex** Hk_laststep, ModuleBase::matrix& ekb) { ModuleBase::TITLE("ELEC_evolve", "eveolve_psi"); @@ -39,11 +40,7 @@ void ELEC_evolve::evolve_psi(const int& istep, Evolve_LCAO_Matrix ELM(lowf.ParaV); psi->fix_k(ik); psi_laststep->fix_k(ik); - if(istep<3){ - ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, &(ekb(ik, 0)));} - else{ - ELM.evolve_complex_matrix_1(ik, phm, psi, psi_laststep, &(ekb(ik, 0))); - } + ELM.evolve_complex_matrix(ik, phm, psi, psi_laststep, Hk_laststep[ik], &(ekb(ik, 0))); ModuleBase::timer::tick("Efficience", "evolve_k"); } // end k diff --git a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h index 6571e72033..eb647b83c3 100644 --- a/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/ELEC_evolve.h @@ -44,6 +44,7 @@ class ELEC_evolve Local_Orbital_wfc& lowf, psi::Psi>* psi, psi::Psi>* psi_laststep, + std::complex** Hk_laststep, ModuleBase::matrix& ekb); }; diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp index df572932bd..49b190f6af 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.cpp @@ -27,6 +27,7 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, hamilt::Hamilt* p_hamilt, psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, + std::complex* Hk_laststep, double* ekb) const { ModuleBase::TITLE("Evolve_LCAO_Matrix", "evolve_complex_matrix"); @@ -36,37 +37,7 @@ void Evolve_LCAO_Matrix::evolve_complex_matrix(const int& ik, if (GlobalV::ESOLVER_TYPE == "tddft") { #ifdef __MPI - this->using_ScaLAPACK_complex(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), p_hamilt, psi_k[0].get_pointer(), ekb); -#else - this->using_LAPACK_complex(ik, p_hamilt, psi_k[0].get_pointer(), psi_k_laststep[0].get_pointer(), ekb); -#endif - } - else - { - ModuleBase::WARNING_QUIT("Evolve_LCAO_Matrix::evolve_complex_matrix", - "only esolver_type == tddft cando evolve"); - } - - time_t time_end = time(NULL); - ModuleBase::GlobalFunc::OUT_TIME("evolve(std::complex)", time_start, time_end); - - return; -} -//usenew propagator -void Evolve_LCAO_Matrix::evolve_complex_matrix_1(const int& ik, - hamilt::Hamilt* p_hamilt, - psi::Psi>* psi_k, - psi::Psi>* psi_k_laststep, - double* ekb) const -{ - ModuleBase::TITLE("Evolve_LCAO_Matrix", "evolve_complex_matrix"); - time_t time_start = time(NULL); - GlobalV::ofs_running << " Start Time : " << ctime(&time_start); - - if (GlobalV::ESOLVER_TYPE == "tddft") - { -#ifdef __MPI - this->using_ScaLAPACK_complex_1(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), p_hamilt, psi_k[0].get_pointer(), ekb); + this->using_ScaLAPACK_complex(GlobalV::NBANDS, GlobalV::NLOCAL, psi_k_laststep[0].get_pointer(), Hk_laststep, p_hamilt, psi_k[0].get_pointer(), ekb); #else this->using_LAPACK_complex(ik, p_hamilt, psi_k[0].get_pointer(), psi_k_laststep[0].get_pointer(), ekb); #endif @@ -374,6 +345,7 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( const int nband, const int nlocal, const std::complex* psi_k_laststep, + const std::complex* Hk_laststep, hamilt::Hamilt* p_hamilt, std::complex* psi_k, double* ekb) const @@ -391,73 +363,26 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex( complex* Htmp = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); - - complex* U_operator = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); - -// (1)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief compute U_operator - /// @input Stmp, Htmp, print_matrix - /// @output U_operator - compute_U_operator(nband, nlocal, Stmp, Htmp, U_operator, print_matrix); -// (2)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief apply U_operator to the wave function of the previous step for new wave function - /// @input U_operator, psi_k_laststep - /// @output psi_k - U_to_wfc(nband, nlocal, U_operator, psi_k_laststep, psi_k); - - - -// (3)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief normalize psi_k - /// @input Stmp, psi_not_norm, psi_k, print_matrix - /// @output psi_k - norm_wfc(nband, nlocal, Stmp, psi_k, print_matrix); - - -// (4)->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> - - /// @brief compute ekb - /// @input Htmp, psi_k - /// @output ekb - compute_ekb(nband, nlocal, Htmp, psi_k, ekb); - - delete[] Stmp; - delete[] Htmp; - delete[] U_operator; - return; -} - - -void Evolve_LCAO_Matrix::using_ScaLAPACK_complex_1( - const int nband, - const int nlocal, - const std::complex* psi_k_laststep, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - double* ekb) const -{ - ModuleBase::TITLE("Evolve_LCAO_Matrix", "using_ScaLAPACK_complex"); - - int print_matrix = 0; - hamilt::MatrixBlock> h_mat, h_mat_last, s_mat; - p_hamilt->matrix_l(h_mat, h_mat_last, s_mat); - - complex* Stmp = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Stmp, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, s_mat.p, 1, Stmp, 1); - - complex* Htmp_last = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Htmp_last, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, h_mat_last.p, 1, Htmp_last, 1); - - complex* Htmp = new complex[this->ParaV->nloc]; - ModuleBase::GlobalFunc::ZEROS(Htmp, this->ParaV->nloc); - BlasConnector::copy(this->ParaV->nloc, h_mat.p, 1, Htmp, 1); + //print test + /*GlobalV::ofs_running << " H(t) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Hk_laststep[i * this->ParaV->ncol + j].real() << "+" << Hk_laststep[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;} + GlobalV::ofs_running << " H(t+dt) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;} + // +*/ complex mixing = {0.5, 0.0}; ScalapackConnector::geadd( @@ -465,7 +390,7 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex_1( nlocal, nlocal, mixing, - Htmp_last, + Hk_laststep, 1, 1, this->ParaV->desc, @@ -475,6 +400,14 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex_1( 1, this->ParaV->desc ); + /*GlobalV::ofs_running << " H(t+dt/2) matrix :" << endl; + for (int i = 0; i < this->ParaV->nrow; i++) + { + for (int j = 0; j < this->ParaV->ncol; j++) + { + GlobalV::ofs_running << Htmp[i * this->ParaV->ncol + j].real() << "+" << Htmp[i * this->ParaV->ncol + j].imag() << "i "; + } + GlobalV::ofs_running << endl;}*/ complex* U_operator = new complex[this->ParaV->nloc]; ModuleBase::GlobalFunc::ZEROS(U_operator, this->ParaV->nloc); @@ -515,6 +448,7 @@ void Evolve_LCAO_Matrix::using_ScaLAPACK_complex_1( return; } + void Evolve_LCAO_Matrix::compute_U_operator( const int nband, const int nlocal, diff --git a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h index 83bb1d40dd..1f1f4e1fc0 100644 --- a/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h +++ b/source/module_hamilt_lcao/module_tddft/LCAO_evolve.h @@ -22,11 +22,7 @@ class Evolve_LCAO_Matrix hamilt::Hamilt* p_hamilt, psi::Psi>* psi_k, psi::Psi>* psi_k_laststep, - double* ekb) const; - void evolve_complex_matrix_1(const int& ik, - hamilt::Hamilt* p_hamilt, - psi::Psi>* psi_k, - psi::Psi>* psi_k_laststep, + std::complex* Hk_laststep, double* ekb) const; private: @@ -43,13 +39,7 @@ class Evolve_LCAO_Matrix const int nband, const int nlocal, const std::complex* psi_k_laststep, - hamilt::Hamilt* p_hamilt, - std::complex* psi_k, - double* ekb) const; - void using_ScaLAPACK_complex_1( - const int nband, - const int nlocal, - const std::complex* psi_k_laststep, + const std::complex* Hk_laststep, hamilt::Hamilt* p_hamilt, std::complex* psi_k, double* ekb) const;