From 1bab6ffac6ae8f8653ba7aeb16893887753084d7 Mon Sep 17 00:00:00 2001 From: wenfei-li Date: Fri, 10 Nov 2023 15:01:01 +0800 Subject: [PATCH 1/5] Feature : enable cg diagonalization with PAW --- .../hamilt_pwdft/hamilt_pw.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp b/source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp index 88063016afe..1bd03f2cd5d 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/hamilt_pw.cpp @@ -10,6 +10,10 @@ #include "operator_pw/meta_pw.h" #include "operator_pw/nonlocal_pw.h" +#ifdef USE_PAW +#include "module_cell/module_paw/paw_cell.h" +#endif + namespace hamilt { @@ -207,6 +211,21 @@ void HamiltPW::sPsi(const T* psi_in, // psi const T one{1, 0}; const T zero{0, 0}; + if(GlobalV::use_paw) + { +#ifdef USE_PAW +#ifdef __DEBUG + assert(psi.get_k_first()); +#endif + for(int m = 0; m < nbands; m ++) + { + GlobalC::paw_cell.paw_nl_psi(1, reinterpret_cast*> (&psi_in[m * npw]), + reinterpret_cast*>(&spsi[m * nrow])); + } +#endif + return; + } + syncmem_op()(this->ctx, this->ctx, spsi, psi_in, static_cast(nbands * nrow)); if (GlobalV::use_uspp) { From 2c13670cecb8771346934c012cc7268116b6c6f1 Mon Sep 17 00:00:00 2001 From: wenfei-li Date: Fri, 10 Nov 2023 15:02:03 +0800 Subject: [PATCH 2/5] Feature : added mixing of dij (not used yet) --- source/module_cell/module_paw/paw_cell.cpp | 23 ++++++++++++++ source/module_cell/module_paw/paw_cell.h | 9 ++++++ .../module_paw/paw_cell_libpaw.cpp | 31 +++++++++++++++++-- .../module_charge/charge_mixing.cpp | 1 + 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/source/module_cell/module_paw/paw_cell.cpp b/source/module_cell/module_paw/paw_cell.cpp index 7c53bdc48fa..f683686d886 100644 --- a/source/module_cell/module_paw/paw_cell.cpp +++ b/source/module_cell/module_paw/paw_cell.cpp @@ -76,6 +76,29 @@ void Paw_Cell::init_paw_cell( } this -> init_rhoij(); + this -> init_mix_dij(); +} + +void Paw_Cell::init_mix_dij() +{ + first_iter = true; + count = 0; + + if(GlobalV::RANK_IN_POOL == 0) + { + dij_save.resize(natom); + for(int iat = 0; iat < natom; iat ++) + { + const int it = atom_type[iat]; + const int nproj = paw_element_list[it].get_mstates(); + const int size_dij = nproj * (nproj+1) / 2; + dij_save[iat].resize(size_dij * nspden); + for(int i = 0; i < size_dij * nspden; i ++) + { + dij_save[iat][i] = 0.0; + } + } + } } void Paw_Cell::init_rhoij() diff --git a/source/module_cell/module_paw/paw_cell.h b/source/module_cell/module_paw/paw_cell.h index a12de8d59cf..749e8ecb086 100644 --- a/source/module_cell/module_paw/paw_cell.h +++ b/source/module_cell/module_paw/paw_cell.h @@ -236,6 +236,15 @@ class Paw_Cell double calculate_ecore(); private: + + bool first_iter; + int count; + + void init_mix_dij(); + void mix_dij(const int iat, double*dij_libpaw); + + std::vector> dij_save; + // Info to be passed to libpaw_interface: // 1. ecut, ecutpaw : kinetic energy cutoff of the planewave basis set // there will be one coarse grid for density/potential, and a fine grid for PAW diff --git a/source/module_cell/module_paw/paw_cell_libpaw.cpp b/source/module_cell/module_paw/paw_cell_libpaw.cpp index 413f93cb6f0..5c2317664b6 100644 --- a/source/module_cell/module_paw/paw_cell_libpaw.cpp +++ b/source/module_cell/module_paw/paw_cell_libpaw.cpp @@ -192,6 +192,28 @@ void Paw_Cell::set_libpaw_atom(const int natom_in, const int ntypat_in, const in } } +void Paw_Cell::mix_dij(const int iat, double*dij_paw) +{ + double mixing_beta = 0.1; + + std::cout << "mixing_beta : " << mixing_beta << std::endl; + + const int it = atom_type[iat]; + const int nproj = paw_element_list[it].get_mstates(); + const int size_dij = nproj * (nproj+1) / 2; + for(int i = 0; i < size_dij * nspden; i ++) + { + if(!first_iter) dij_paw[i] = dij_save[iat][i] * (1.0 - mixing_beta) + dij_paw[i] * mixing_beta; + + if(count > 30) dij_paw[i] = dij_save[iat][i]; + + dij_save[iat][i] = dij_paw[i]; + } + + first_iter = false; + count ++; +} + // Sets filename_list // I'm going to read directly from STRU file void Paw_Cell::set_libpaw_files() @@ -609,13 +631,16 @@ void Paw_Cell::set_dij() dij[is] = new double[nproj * nproj]; } - - #ifdef __MPI - if(GlobalV::RANK_IN_POOL == 0) extract_dij(iat,size_dij,dij_libpaw); + if(GlobalV::RANK_IN_POOL == 0) + { + extract_dij(iat,size_dij,dij_libpaw); + //mix_dij(iat,dij_libpaw); + } Parallel_Common::bcast_double(dij_libpaw,size_dij*nspden); #else extract_dij(iat,size_dij,dij_libpaw); + //mix_dij(iat,dij_libpaw); #endif for(int is = 0; is < nspden; is ++) diff --git a/source/module_elecstate/module_charge/charge_mixing.cpp b/source/module_elecstate/module_charge/charge_mixing.cpp index 8a0912d5808..f4efb193366 100755 --- a/source/module_elecstate/module_charge/charge_mixing.cpp +++ b/source/module_elecstate/module_charge/charge_mixing.cpp @@ -99,6 +99,7 @@ void Charge_Mixing::auto_set(const double& bandgap_in, const UnitCell& ucell_) { this->mixing->mixing_beta = this->mixing_beta = 0.7; } + GlobalV::MIXING_BETA = mixing_beta; GlobalV::ofs_running << " Autoset mixing_beta to " << this->mixing_beta << std::endl; bool has_trans_metal = false; From 88fa929553a0a84f64817fd049ccd3c9450ae3ab Mon Sep 17 00:00:00 2001 From: wenfei-li Date: Mon, 13 Nov 2023 13:41:11 +0800 Subject: [PATCH 3/5] not mixing dij yet --- source/module_cell/module_paw/paw_cell.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/module_cell/module_paw/paw_cell.cpp b/source/module_cell/module_paw/paw_cell.cpp index f683686d886..ed269cc9988 100644 --- a/source/module_cell/module_paw/paw_cell.cpp +++ b/source/module_cell/module_paw/paw_cell.cpp @@ -76,7 +76,7 @@ void Paw_Cell::init_paw_cell( } this -> init_rhoij(); - this -> init_mix_dij(); + //this -> init_mix_dij(); } void Paw_Cell::init_mix_dij() From 2bf15978d0bf5d2db37052c37831a86e7e64d2eb Mon Sep 17 00:00:00 2001 From: wenfei-li Date: Tue, 14 Nov 2023 18:09:40 +0800 Subject: [PATCH 4/5] update libpaw_interface --- deps/libpaw_interface | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/libpaw_interface b/deps/libpaw_interface index 9928c3fbdec..60c445a0f99 160000 --- a/deps/libpaw_interface +++ b/deps/libpaw_interface @@ -1 +1 @@ -Subproject commit 9928c3fbdec87adfd52ff73ac26df1481e176227 +Subproject commit 60c445a0f994151ecdea14d942690943340125be From 2c6c3a43b9a77ff78e46072be4388a93e7cf520f Mon Sep 17 00:00:00 2001 From: wenfei-li Date: Wed, 15 Nov 2023 14:46:13 +0800 Subject: [PATCH 5/5] update reading of STRU file --- source/module_io/input.cpp | 2 +- source/module_io/parameter_pool.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/module_io/input.cpp b/source/module_io/input.cpp index 23054fdaaf2..656c3afe46d 100644 --- a/source/module_io/input.cpp +++ b/source/module_io/input.cpp @@ -4026,7 +4026,7 @@ int Input::count_ntype(const std::string &fn) while (true) { ModuleBase::GlobalFunc::READ_VALUE(ifa, temp); - if (temp == "LATTICE_CONSTANT" || temp == "NUMERICAL_ORBITAL" || temp == "NUMERICAL_DESCRIPTOR" + if (temp == "LATTICE_CONSTANT" || temp == "NUMERICAL_ORBITAL" || temp == "NUMERICAL_DESCRIPTOR" || temp == "PAW_FILES" || ifa.eof()) { break; diff --git a/source/module_io/parameter_pool.cpp b/source/module_io/parameter_pool.cpp index 4ea615d87e0..8b9cc08132f 100644 --- a/source/module_io/parameter_pool.cpp +++ b/source/module_io/parameter_pool.cpp @@ -46,7 +46,7 @@ int count_ntype(const std::string& fn) while (true) { ModuleBase::GlobalFunc::READ_VALUE(ifa, temp); - if (temp == "LATTICE_CONSTANT" || temp == "NUMERICAL_ORBITAL" || temp == "NUMERICAL_DESCRIPTOR" + if (temp == "LATTICE_CONSTANT" || temp == "NUMERICAL_ORBITAL" || temp == "NUMERICAL_DESCRIPTOR" || temp == "PAW_FILES" || ifa.eof()) { break;