From c0120d989dd909bae74832194031bca196927f5a Mon Sep 17 00:00:00 2001 From: Qianruipku Date: Fri, 10 Jan 2025 22:34:53 +0800 Subject: [PATCH 1/6] fix wrong band results when kpar>1 --- source/module_cell/klist.cpp | 46 +- source/module_cell/klist.h | 498 +++++++++--------- source/module_elecstate/elecstate_print.cpp | 100 ++-- .../module_dm/test/test_cal_dm_R.cpp | 7 - .../module_dm/test/test_dm_R_init.cpp | 7 - .../module_dm/test/test_dm_constructor.cpp | 6 - .../module_dm/test/test_dm_io.cpp | 9 - .../test/elecstate_base_test.cpp | 6 - .../test/elecstate_energy_test.cpp | 6 - .../test/elecstate_print_test.cpp | 6 - .../test/elecstate_pw_test.cpp | 6 - source/module_esolver/esolver_ks_pw.cpp | 2 +- .../test/lambda_loop_helper_test.cpp | 6 - .../test/spin_constrain_test.cpp | 2 - .../test/template_helpers_test.cpp | 6 - .../module_hamilt_pw/hamilt_pwdft/elecond.cpp | 2 +- .../module_hamilt_pw/hamilt_stodft/sto_wf.cpp | 2 +- .../hamilt_stodft/test/test_hamilt_sto.cpp | 2 - .../test/hsolver_supplementary_mock.h | 6 - .../module_io/test/read_wfc_to_rho_test.cpp | 29 +- .../module_io/test_serial/nscf_band_test.cpp | 7 - source/module_io/write_wfc_pw.cpp | 6 +- source/module_psi/psi_init.cpp | 4 +- source/module_psi/psi_init.h | 4 +- source/module_psi/psi_initializer.cpp | 17 + source/module_psi/psi_initializer.h | 7 +- source/module_psi/psi_initializer_atomic.cpp | 9 +- source/module_psi/psi_initializer_atomic.h | 8 +- .../psi_initializer_atomic_random.cpp | 6 +- .../psi_initializer_atomic_random.h | 8 +- source/module_psi/psi_initializer_file.cpp | 13 +- source/module_psi/psi_initializer_file.h | 12 +- source/module_psi/psi_initializer_nao.cpp | 9 +- source/module_psi/psi_initializer_nao.h | 8 +- .../module_psi/psi_initializer_nao_random.cpp | 4 +- .../module_psi/psi_initializer_nao_random.h | 8 +- source/module_psi/psi_initializer_random.cpp | 8 +- source/module_psi/psi_initializer_random.h | 6 +- .../test/psi_initializer_unit_test.cpp | 35 +- 39 files changed, 415 insertions(+), 518 deletions(-) diff --git a/source/module_cell/klist.cpp b/source/module_cell/klist.cpp index 4bae46f38f..73dbad9b69 100644 --- a/source/module_cell/klist.cpp +++ b/source/module_cell/klist.cpp @@ -13,34 +13,33 @@ #include "module_cell/module_paw/paw_cell.h" #endif -K_Vectors::K_Vectors() +int K_Vectors::cal_ik_global() { - - nspin = 0; // default spin. - kc_done = false; - kd_done = false; - nkstot_full = 0; - nks = 0; - nkstot = 0; - k_nkstot = 0; // LiuXh add 20180619 -} - -K_Vectors::~K_Vectors() -{ -} - -int K_Vectors::get_ik_global(const int& ik, const int& nkstot) -{ - int nkp = nkstot / PARAM.inp.kpar; - int rem = nkstot % PARAM.inp.kpar; - if (GlobalV::MY_POOL < rem) + const int my_pool = this->para_k.my_pool; + this->ik2iktot.resize(this->nks); +#ifdef __MPI + if(this->nspin == 2) { - return GlobalV::MY_POOL * nkp + GlobalV::MY_POOL + ik; + for (int ik = 0; ik < this->nks / 2; ++ik) + { + this->ik2iktot[ik] = this->para_k.startk_pool[my_pool] + ik; + this->ik2iktot[ik + this->nks / 2] = this->nsktot / 2 + this->para_k.startk_pool[my_pool] + ik; + } } else { - return GlobalV::MY_POOL * nkp + rem + ik; + for (int ik = 0; ik < this->nks; ++ik) + { + this->ik2iktot[ik] = this->para_k.startk_pool[my_pool] + ik; + } } +#else + for (int ik = 0; ik < this->nks; ++ik) + { + this->ik2iktot[ik] = ik; + } +#endif + } void K_Vectors::set(const UnitCell& ucell, @@ -162,6 +161,9 @@ void K_Vectors::set(const UnitCell& ucell, // set the k vectors for the up and down spin this->set_kup_and_kdw(); + // get ik2iktot + this->cal_ik_global(); + this->print_klists(ofs); // std::cout << " NUMBER OF K-POINTS : " << nkstot << std::endl; diff --git a/source/module_cell/klist.h b/source/module_cell/klist.h index cc08e336f1..c0c14a905c 100644 --- a/source/module_cell/klist.h +++ b/source/module_cell/klist.h @@ -26,8 +26,8 @@ class K_Vectors /// dim: [iks_ibz][(isym, kvec_d)] std::vector>> kstars; - K_Vectors(); - ~K_Vectors(); + K_Vectors(){}; + ~K_Vectors(){}; K_Vectors& operator=(const K_Vectors&) = default; K_Vectors& operator=(K_Vectors&& rhs) = default; @@ -106,23 +106,6 @@ class K_Vectors */ void set_after_vc(const int& nspin, const ModuleBase::Matrix3& reciprocal_vec, const ModuleBase::Matrix3& latvec); - /** - * @brief Gets the global index of a k-point. - * - * This function gets the global index of a k-point based on its local index and the process pool ID. - * The global index is used when the k-points are distributed among multiple process pools. - * - * @param nkstot The total number of k-points. - * @param ik The local index of the k-point. - * - * @return int Returns the global index of the k-point. - * - * @note The function calculates the global index by dividing the total number of k-points (nkstot) by the number of - * process pools (KPAR), and adding the remainder if the process pool ID (MY_POOL) is less than the remainder. - * @note The function is declared as inline for efficiency. - */ - static int get_ik_global(const int& ik, const int& nkstot); - int get_nks() const { return this->nks; @@ -159,240 +142,247 @@ class K_Vectors } private: - int nks; // number of symmetry-reduced k points in this pool(processor, up+dw) - int nkstot; /// number of symmetry-reduced k points in full k mesh - int nkstot_full; /// number of k points before symmetry reduction in full k mesh - - int nspin; - bool kc_done; - bool kd_done; - double koffset[3]={0.0}; // used only in automatic k-points. - std::string k_kword; // LiuXh add 20180619 - int k_nkstot; // LiuXh add 20180619 - bool is_mp = false; // Monkhorst-Pack - - /** - * @brief Resize the k-point related vectors according to the new k-point number. - * - * This function resizes the vectors that store the k-point information, - * including the Cartesian and Direct coordinates of k-points, - * the weights of k-points, the index of k-points, and the number of plane waves for each k-point. - * - * @param kpoint_number The new number of k-points. - * - * @return void - * - * @note The memory recording lines are commented out. If you want to track the memory usage, - * you can uncomment these lines. - */ - void renew(const int& kpoint_number); - - // step 1 : generate kpoints - - /** - * @brief Reads the k-points from a file. - * - * This function reads the k-points from a file specified by the filename. - * It supports both Cartesian and Direct coordinates, and can handle different types of k-points, - * including Gamma, Monkhorst-Pack, and Line mode. It also supports automatic generation of k-points - * file if the file does not exist. - * - * @param fn The name of the file containing the k-points. - * - * @return bool Returns true if the k-points are successfully read from the file, - * false otherwise. - * - * @note It will generate a k-points file automatically - * according to the global variables GAMMA_ONLY_LOCAL and KSPACING. - * @note If the k-points type is neither Gamma nor Monkhorst-Pack, it will quit with a warning. - * @note If the k-points type is Line mode and the symmetry flag is 1, it will quit with a warning. - * @note If the number of k-points is greater than 100000, it will quit with a warning. - */ - bool read_kpoints(const UnitCell& ucell, - const std::string& fn); // return 0: something wrong. - - /** - * @brief Adds k-points linearly between special points. - * - * This function adds k-points linearly between special points in the Brillouin zone. - * The special points and the number of k-points between them are read from an input file. - * - * @param ifk The input file stream from which the special points and the number of k-points between them are read. - * @param kvec A vector to store the generated k-points. - * - * @return void - * - * @note The function first reads the number of special points (nks_special) and the number of k-points between them - * (nkl) from the input file. - * @note The function then recalculates the total number of k-points (nkstot) based on the number of k-points - * between the special points. - * @note The function generates the k-points by linearly interpolating between the special points. - * @note The function also assigns a segment ID to each k-point to distinguish different k-line segments. - * @note The function checks that the total number of generated k-points matches the calculated total number of - * k-points. - * @note The function checks that the size of the segment ID vector matches the total number of k-points. - */ - void interpolate_k_between(std::ifstream& ifk, std::vector>& kvec); - - /** - * @brief Generates k-points using the Monkhorst-Pack scheme. - * - * This function generates k-points in the reciprocal space using the Monkhorst-Pack scheme. - * - * @param nmp_in the number of k-points in each dimension. - * @param koffset_in the offset for the k-points in each dimension. - * @param k_type The type of k-point. 1 means without Gamma point, 0 means with Gamma. - * - * @return void - * - * @note The function assumes that the k-points are evenly distributed in the reciprocal space. - * @note The function sets the weight of each k-point to be equal, so that the total weight of all k-points is 1. - * @note The function sets the flag kd_done to true to indicate that the k-points have been generated. - */ - void Monkhorst_Pack(const int* nmp_in, const double* koffset_in, const int tipo); - - /** - * @brief Calculates the coordinate of a k-point using the Monkhorst-Pack scheme. - * - * This function calculates the coordinate of a k-point in the reciprocal space using the Monkhorst-Pack scheme. - * The Monkhorst-Pack scheme is a method for generating k-points in the Brillouin zone. - * - * @param k_type The type of k-point. 1 means without Gamma point, 0 means with Gamma. - * @param offset The offset for the k-point. - * @param n The index of the k-point in the current dimension. - * @param dim The total number of k-points in the current dimension. - * - * @return double Returns the coordinate of the k-point. - * - * @note The function assumes that the k-points are evenly distributed in the reciprocal space. - */ - double Monkhorst_Pack_formula(const int& k_type, const double& offset, const int& n, const int& dim); - - // step 2 : set both kvec and kved; normalize weight - - /** - * @brief Updates the k-points to use the irreducible Brillouin zone (IBZ). - * - * This function updates the k-points to use the irreducible Brillouin zone (IBZ) instead of the full Brillouin - * zone. - * - * @return void - * - * @note This function should only be called by the master process (MY_RANK == 0). - * @note This function assumes that the number of k-points in the IBZ (nkstot_ibz) is greater than 0. - * @note This function updates the total number of k-points (nkstot) to be the number of k-points in the IBZ. - * @note This function resizes the vector of k-points (kvec_d) and updates its values to be the k-points in the IBZ. - * @note This function also updates the weights of the k-points (wk) to be the weights in the IBZ. - * @note After this function is called, the flag kd_done is set to true to indicate that the k-points have been - * updated, and the flag kc_done is set to false to indicate that the Cartesian coordinates of the k-points need to - * be recalculated. - */ - void update_use_ibz(const int& nkstot_ibz, - const std::vector>& kvec_d_ibz, - const std::vector& wk_ibz); - - /** - * @brief Sets both the direct and Cartesian k-vectors. - * - * This function sets both the direct and Cartesian k-vectors based on the input parameters. - * It also checks the k-point type and sets the corresponding flags. - * - * @param G The reciprocal lattice matrix. - * @param R The real space lattice matrix. - * @param skpt A string to store the k-point table. - * - * @return void - * - * @note If the k-point type is neither "Cartesian" nor "Direct", an error message will be printed. - * @note The function sets the flags kd_done and kc_done to indicate whether the direct and Cartesian k-vectors have - * been set, respectively. - * @note The function also prints a table of the direct k-vectors and their weights. - * @note If the function is called by the master process (MY_RANK == 0), the k-point table is also stored in the - * string skpt. - */ - void set_both_kvec(const ModuleBase::Matrix3& G, const ModuleBase::Matrix3& R, std::string& skpt); - - /** - * @brief Normalizes the weights of the k-points. - * - * This function normalizes the weights of the k-points so that their sum is equal to the degeneracy of spin - * (degspin). - * - * @param degspin The degeneracy of spin. This is 1 for non-spin-polarized calculations and 2 for spin-polarized - * calculations. - * - * @return void - * - * @note This function should only be called by the master process (MY_RANK == 0). - * @note The function assumes that the sum of the weights of the k-points is greater than 0. - * @note The function first normalizes the weights so that their sum is 1, and then scales them by the degeneracy of - * spin. - */ - void normalize_wk(const int& degspin); - - // step 3 : mpi kpoints information. - - /** - * @brief Distributes k-points among MPI processes. - * - * This function distributes the k-points among the MPI processes. Each process gets a subset of the k-points to - * work on. The function also broadcasts various variables related to the k-points to all processes. - * - * @return void - * - * @note This function is only compiled and used if MPI is enabled. - * @note The function assumes that the number of k-points (nkstot) is greater than 0. - * @note The function broadcasts the flags kc_done and kd_done, the number of spins (nspin), the total number of - * k-points (nkstot), the full number of k-points (nkstot_full), the Monkhorst-Pack grid (nmp), the k-point offsets - * (koffset), and the segment IDs of the k-points (kl_segids). - * @note The function also broadcasts the indices of the k-points (isk), their weights (wk), and their Cartesian and - * direct coordinates (kvec_c and kvec_d). - * @note If a process has no k-points to work on, the function will quit with an error message. - */ - void mpi_k(); - - // step 4 : *2 kpoints. - - /** - * @brief Sets up the k-points for spin-up and spin-down calculations. - * - * This function sets up the k-points for spin-up and spin-down calculations. - * If the calculation is spin-polarized (nspin = 2), the number of k-points is doubled. - * The first half of the k-points correspond to spin-up, and the second half correspond to spin-down. - * 2 for LSDA - * 4 for non-collinear - * - * @return void - * - * @note For non-spin-polarized calculations (nspin = 1 or 4), the function simply sets the spin index of all - * k-points to 0. - * @note For spin-polarized calculations (nspin = 2), the function duplicates the k-points and their weights, - * sets the spin index of the first half of the k-points to 0 (spin-up), and the spin index of the second half - * to 1 (spin-down). - * @note The function also doubles the total number of k-points (nks and nkstot) for spin-polarized calculations. - * @note The function prints the total number of k-points for spin-polarized calculations. - */ - void set_kup_and_kdw(); - - // step 5 - // print k lists. - - /** - * @brief Prints the k-points in both Cartesian and direct coordinates. - * - * This function prints the k-points in both Cartesian and direct coordinates to the output file stream. - * The output includes the index, x, y, and z coordinates, and the weight of each k-point. - * - * @param ofs The output file stream to which the k-points are printed. - * - * @return void - * - * @note The function first checks if the total number of k-points (nkstot) is less than the number of k-points for - * the current spin (nks). If so, it prints an error message and quits. - * @note The function prints the k-points in a table format, with separate tables for Cartesian and direct - * coordinates. - * @note The function uses the FmtCore::format function to format the output. - */ - void print_klists(std::ofstream& fn); + int nks = 0; ///< number of symmetry-reduced k points in this pool(processor, up+dw) + int nkstot = 0; ///< number of symmetry-reduced k points in full k mesh + int nkstot_full = 0; ///< number of k points before symmetry reduction in full k mesh + std::vector ik2iktot; ///<[nks] map ik to the global index of k points + + int nspin = 0; + bool kc_done = false; + bool kd_done = false; + double koffset[3] = {0.0}; // used only in automatic k-points. + std::string k_kword; // LiuXh add 20180619 + int k_nkstot = 0; // LiuXh add 20180619 + bool is_mp = false; // Monkhorst-Pack + + /** + * @brief Resize the k-point related vectors according to the new k-point number. + * + * This function resizes the vectors that store the k-point information, + * including the Cartesian and Direct coordinates of k-points, + * the weights of k-points, the index of k-points, and the number of plane waves for each k-point. + * + * @param kpoint_number The new number of k-points. + * + * @return void + * + * @note The memory recording lines are commented out. If you want to track the memory usage, + * you can uncomment these lines. + */ + void renew(const int& kpoint_number); + + // step 1 : generate kpoints + + /** + * @brief Reads the k-points from a file. + * + * This function reads the k-points from a file specified by the filename. + * It supports both Cartesian and Direct coordinates, and can handle different types of k-points, + * including Gamma, Monkhorst-Pack, and Line mode. It also supports automatic generation of k-points + * file if the file does not exist. + * + * @param fn The name of the file containing the k-points. + * + * @return bool Returns true if the k-points are successfully read from the file, + * false otherwise. + * + * @note It will generate a k-points file automatically + * according to the global variables GAMMA_ONLY_LOCAL and KSPACING. + * @note If the k-points type is neither Gamma nor Monkhorst-Pack, it will quit with a warning. + * @note If the k-points type is Line mode and the symmetry flag is 1, it will quit with a warning. + * @note If the number of k-points is greater than 100000, it will quit with a warning. + */ + bool read_kpoints(const UnitCell& ucell, + const std::string& fn); // return 0: something wrong. + + /** + * @brief Adds k-points linearly between special points. + * + * This function adds k-points linearly between special points in the Brillouin zone. + * The special points and the number of k-points between them are read from an input file. + * + * @param ifk The input file stream from which the special points and the number of k-points between them are read. + * @param kvec A vector to store the generated k-points. + * + * @return void + * + * @note The function first reads the number of special points (nks_special) and the number of k-points between them + * (nkl) from the input file. + * @note The function then recalculates the total number of k-points (nkstot) based on the number of k-points + * between the special points. + * @note The function generates the k-points by linearly interpolating between the special points. + * @note The function also assigns a segment ID to each k-point to distinguish different k-line segments. + * @note The function checks that the total number of generated k-points matches the calculated total number of + * k-points. + * @note The function checks that the size of the segment ID vector matches the total number of k-points. + */ + void interpolate_k_between(std::ifstream& ifk, std::vector>& kvec); + + /** + * @brief Generates k-points using the Monkhorst-Pack scheme. + * + * This function generates k-points in the reciprocal space using the Monkhorst-Pack scheme. + * + * @param nmp_in the number of k-points in each dimension. + * @param koffset_in the offset for the k-points in each dimension. + * @param k_type The type of k-point. 1 means without Gamma point, 0 means with Gamma. + * + * @return void + * + * @note The function assumes that the k-points are evenly distributed in the reciprocal space. + * @note The function sets the weight of each k-point to be equal, so that the total weight of all k-points is 1. + * @note The function sets the flag kd_done to true to indicate that the k-points have been generated. + */ + void Monkhorst_Pack(const int* nmp_in, const double* koffset_in, const int tipo); + + /** + * @brief Calculates the coordinate of a k-point using the Monkhorst-Pack scheme. + * + * This function calculates the coordinate of a k-point in the reciprocal space using the Monkhorst-Pack scheme. + * The Monkhorst-Pack scheme is a method for generating k-points in the Brillouin zone. + * + * @param k_type The type of k-point. 1 means without Gamma point, 0 means with Gamma. + * @param offset The offset for the k-point. + * @param n The index of the k-point in the current dimension. + * @param dim The total number of k-points in the current dimension. + * + * @return double Returns the coordinate of the k-point. + * + * @note The function assumes that the k-points are evenly distributed in the reciprocal space. + */ + double Monkhorst_Pack_formula(const int& k_type, const double& offset, const int& n, const int& dim); + + // step 2 : set both kvec and kved; normalize weight + + /** + * @brief Updates the k-points to use the irreducible Brillouin zone (IBZ). + * + * This function updates the k-points to use the irreducible Brillouin zone (IBZ) instead of the full Brillouin + * zone. + * + * @return void + * + * @note This function should only be called by the master process (MY_RANK == 0). + * @note This function assumes that the number of k-points in the IBZ (nkstot_ibz) is greater than 0. + * @note This function updates the total number of k-points (nkstot) to be the number of k-points in the IBZ. + * @note This function resizes the vector of k-points (kvec_d) and updates its values to be the k-points in the IBZ. + * @note This function also updates the weights of the k-points (wk) to be the weights in the IBZ. + * @note After this function is called, the flag kd_done is set to true to indicate that the k-points have been + * updated, and the flag kc_done is set to false to indicate that the Cartesian coordinates of the k-points need to + * be recalculated. + */ + void update_use_ibz(const int& nkstot_ibz, + const std::vector>& kvec_d_ibz, + const std::vector& wk_ibz); + + /** + * @brief Sets both the direct and Cartesian k-vectors. + * + * This function sets both the direct and Cartesian k-vectors based on the input parameters. + * It also checks the k-point type and sets the corresponding flags. + * + * @param G The reciprocal lattice matrix. + * @param R The real space lattice matrix. + * @param skpt A string to store the k-point table. + * + * @return void + * + * @note If the k-point type is neither "Cartesian" nor "Direct", an error message will be printed. + * @note The function sets the flags kd_done and kc_done to indicate whether the direct and Cartesian k-vectors have + * been set, respectively. + * @note The function also prints a table of the direct k-vectors and their weights. + * @note If the function is called by the master process (MY_RANK == 0), the k-point table is also stored in the + * string skpt. + */ + void set_both_kvec(const ModuleBase::Matrix3& G, const ModuleBase::Matrix3& R, std::string& skpt); + + /** + * @brief Normalizes the weights of the k-points. + * + * This function normalizes the weights of the k-points so that their sum is equal to the degeneracy of spin + * (degspin). + * + * @param degspin The degeneracy of spin. This is 1 for non-spin-polarized calculations and 2 for spin-polarized + * calculations. + * + * @return void + * + * @note This function should only be called by the master process (MY_RANK == 0). + * @note The function assumes that the sum of the weights of the k-points is greater than 0. + * @note The function first normalizes the weights so that their sum is 1, and then scales them by the degeneracy of + * spin. + */ + void normalize_wk(const int& degspin); + + // step 3 : mpi kpoints information. + + /** + * @brief Distributes k-points among MPI processes. + * + * This function distributes the k-points among the MPI processes. Each process gets a subset of the k-points to + * work on. The function also broadcasts various variables related to the k-points to all processes. + * + * @return void + * + * @note This function is only compiled and used if MPI is enabled. + * @note The function assumes that the number of k-points (nkstot) is greater than 0. + * @note The function broadcasts the flags kc_done and kd_done, the number of spins (nspin), the total number of + * k-points (nkstot), the full number of k-points (nkstot_full), the Monkhorst-Pack grid (nmp), the k-point offsets + * (koffset), and the segment IDs of the k-points (kl_segids). + * @note The function also broadcasts the indices of the k-points (isk), their weights (wk), and their Cartesian and + * direct coordinates (kvec_c and kvec_d). + * @note If a process has no k-points to work on, the function will quit with an error message. + */ + void mpi_k(); + + // step 4 : *2 kpoints. + + /** + * @brief Sets up the k-points for spin-up and spin-down calculations. + * + * This function sets up the k-points for spin-up and spin-down calculations. + * If the calculation is spin-polarized (nspin = 2), the number of k-points is doubled. + * The first half of the k-points correspond to spin-up, and the second half correspond to spin-down. + * 2 for LSDA + * 4 for non-collinear + * + * @return void + * + * @note For non-spin-polarized calculations (nspin = 1 or 4), the function simply sets the spin index of all + * k-points to 0. + * @note For spin-polarized calculations (nspin = 2), the function duplicates the k-points and their weights, + * sets the spin index of the first half of the k-points to 0 (spin-up), and the spin index of the second half + * to 1 (spin-down). + * @note The function also doubles the total number of k-points (nks and nkstot) for spin-polarized calculations. + * @note The function prints the total number of k-points for spin-polarized calculations. + */ + void set_kup_and_kdw(); + + // step 5 + // print k lists. + + /** + * @brief Prints the k-points in both Cartesian and direct coordinates. + * + * This function prints the k-points in both Cartesian and direct coordinates to the output file stream. + * The output includes the index, x, y, and z coordinates, and the weight of each k-point. + * + * @param ofs The output file stream to which the k-points are printed. + * + * @return void + * + * @note The function first checks if the total number of k-points (nkstot) is less than the number of k-points for + * the current spin (nks). If so, it prints an error message and quits. + * @note The function prints the k-points in a table format, with separate tables for Cartesian and direct + * coordinates. + * @note The function uses the FmtCore::format function to format the output. + */ + void print_klists(std::ofstream& fn); + + /** + * @brief Gets the global index of a k-point. + * @return this->ik2iktot[ik] + */ + void cal_ik_global(); }; #endif // KVECT_H \ No newline at end of file diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index bbdebb7476..f515e76027 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -152,7 +152,9 @@ void print_scf_iterinfo(const std::string& ks_solver, void ElecState::print_eigenvalue(std::ofstream& ofs) { bool wrong = false; - for (int ik = 0; ik < this->klist->get_nks(); ++ik) + const int nks = this->klist->get_nks(); + const int nkstot = this->klist->get_nkstot(); + for (int ik = 0; ik < nks; ++ik) { for (int ib = 0; ib < this->ekb.nc; ++ib) { @@ -164,76 +166,72 @@ void ElecState::print_eigenvalue(std::ofstream& ofs) } } } +#ifdef __MPI + MPI_Allreduce(MPI_IN_PLACE, &wrong, 1, MPI_C_BOOL, MPI_LOR, MPI_COMM_WORLD); +#endif if (wrong) { ModuleBase::WARNING_QUIT("print_eigenvalue", "Eigenvalues are too large!"); } - if (GlobalV::MY_RANK != 0) - { - return; - } + std::string filename = ofs.rdbuf()->get_filename(); + std::vector ngk_tot = this->klist->ngk; + +#ifdef __MPI + Parallel_Common::bcast_string(filename); + MPI_Allreduce(MPI_IN_PLACE, ngk_tot.data(), nks, MPI_INT, MPI_SUM, POOL_WORLD); +#endif ModuleBase::TITLE("ESolver_KS_PW", "print_eigenvalue"); ofs << "\n STATE ENERGY(eV) AND OCCUPATIONS "; - for (int ik = 0; ik < this->klist->get_nks(); ik++) + const int nk_fac = PARAM.inp.nspin == 2 ? 2 : 1; + const int nks_np = nks / nk_fac; + const int nkstot_np + 1 = nkstot / nk_fac; + ofs << " NSPIN == " << PARAM.inp.nspin << std::endl; + for (int is = 0; is < nk_fac; ++is) { - ofs << std::setprecision(5); - ofs << std::setiosflags(std::ios::showpoint); - if (ik == 0) + if (is == 0 && nk_fac == 2) { - ofs << " NSPIN == " << PARAM.inp.nspin << std::endl; - if (PARAM.inp.nspin == 2) - { - ofs << "SPIN UP : " << std::endl; - } + ofs << "SPIN UP : " << std::endl; } - else if (ik == this->klist->get_nks() / 2) + else if (is == 1 && nk_fac == 2) { - if (PARAM.inp.nspin == 2) - { - ofs << "SPIN DOWN : " << std::endl; - } + ofs << "SPIN DOWN : " << std::endl; } - if (PARAM.inp.nspin == 2) + for (int ip = 0; ip < GlobalV::KPAR; ++ip) { - if (this->klist->isk[ik] == 0) - { - ofs << " " << ik + 1 << "/" << this->klist->get_nks() / 2 - << " kpoint (Cartesian) = " << this->klist->kvec_c[ik].x << " " << this->klist->kvec_c[ik].y << " " - << this->klist->kvec_c[ik].z << " (" << this->klist->ngk[ik] << " pws)" << std::endl; - - ofs << std::setprecision(6); - } - if (this->klist->isk[ik] == 1) +#ifdef __MPI + MPI_Barrier(MPI_COMM_WORLD); +#endif + if (GlobalV::MY_POOL == ip && GlobalV::RANK_IN_POOL == 0 && GlobalV::MY_STOGROUP == 0) { - ofs << " " << ik + 1 - this->klist->get_nks() / 2 << "/" << this->klist->get_nks() / 2 - << " kpoint (Cartesian) = " << this->klist->kvec_c[ik].x << " " << this->klist->kvec_c[ik].y << " " - << this->klist->kvec_c[ik].z << " (" << this->klist->ngk[ik] << " pws)" << std::endl; + const int start_ik = nks_np * is; + const int end_ik = nks_np * (is + 1); + for (int ik = start_ik; ik < end_ik; ++ik) + { + std::ofstream ofs_eig(filename.c_str(), std::ios::app); + ofs_eig << std::setprecision(5); + ofs_eig << std::setiosflags(std::ios::showpoint); + ofs_eig << " " << this->klist->ik2iktot[ik] + 1 - is * nkstot_np << "/" << nks_np + << " kpoint (Cartesian) = " << this->klist->kvec_c[ik].x << " " << this->klist->kvec_c[ik].y + << " " << this->klist->kvec_c[ik].z << " (" << ngk_tot[ik] << " pws)" << std::endl; - ofs << std::setprecision(6); + ofs_eig << std::setprecision(6); + ofs_eig << std::setiosflags(std::ios::showpoint); + for (int ib = 0; ib < this->ekb.nc; ib++) + { + ofs_eig << std::setw(8) << ib + 1 << std::setw(15) << this->ekb(ik, ib) * ModuleBase::Ry_to_eV + << std::setw(15) << this->wg(ik, ib) << std::endl; + } + ofs_eig << std::endl; + ofs_eig.close(); + } } - } // Pengfei Li added 14-9-9 - else - { - ofs << " " << ik + 1 << "/" << this->klist->get_nks() - << " kpoint (Cartesian) = " << this->klist->kvec_c[ik].x << " " << this->klist->kvec_c[ik].y << " " - << this->klist->kvec_c[ik].z << " (" << this->klist->ngk[ik] << " pws)" << std::endl; - - ofs << std::setprecision(6); } - - ofs << std::setprecision(6); - ofs << std::setiosflags(std::ios::showpoint); - for (int ib = 0; ib < this->ekb.nc; ib++) - { - ofs << std::setw(8) << ib + 1 << std::setw(15) << this->ekb(ik, ib) * ModuleBase::Ry_to_eV << std::setw(15) - << this->wg(ik, ib) << std::endl; - } - ofs << std::endl; - } // end ik + ofs.seekp(0, std::ios::end); + } return; } diff --git a/source/module_elecstate/module_dm/test/test_cal_dm_R.cpp b/source/module_elecstate/module_dm/test/test_cal_dm_R.cpp index 1557b5dde8..7acd2aa6fb 100644 --- a/source/module_elecstate/module_dm/test/test_cal_dm_R.cpp +++ b/source/module_elecstate/module_dm/test/test_cal_dm_R.cpp @@ -6,13 +6,6 @@ #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} - -K_Vectors::~K_Vectors() -{ -} /************************************************ * unit test of DensityMatrix constructor ***********************************************/ diff --git a/source/module_elecstate/module_dm/test/test_dm_R_init.cpp b/source/module_elecstate/module_dm/test/test_dm_R_init.cpp index 181f20266d..bdbce1fa2b 100644 --- a/source/module_elecstate/module_dm/test/test_dm_R_init.cpp +++ b/source/module_elecstate/module_dm/test/test_dm_R_init.cpp @@ -7,13 +7,6 @@ #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_cell/klist.h" #undef private -K_Vectors::K_Vectors() -{ -} - -K_Vectors::~K_Vectors() -{ -} /************************************************ * unit test of DensityMatrix constructor ***********************************************/ diff --git a/source/module_elecstate/module_dm/test/test_dm_constructor.cpp b/source/module_elecstate/module_dm/test/test_dm_constructor.cpp index e31483bf84..04d96728bf 100644 --- a/source/module_elecstate/module_dm/test/test_dm_constructor.cpp +++ b/source/module_elecstate/module_dm/test/test_dm_constructor.cpp @@ -5,12 +5,6 @@ #include "module_elecstate/module_dm/density_matrix.h" #include "module_hamilt_lcao/module_hcontainer/hcontainer.h" #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} /************************************************ * unit test of DensityMatrix constructor ***********************************************/ diff --git a/source/module_elecstate/module_dm/test/test_dm_io.cpp b/source/module_elecstate/module_dm/test/test_dm_io.cpp index 56f47e36fe..1d1a5ff199 100644 --- a/source/module_elecstate/module_dm/test/test_dm_io.cpp +++ b/source/module_elecstate/module_dm/test/test_dm_io.cpp @@ -33,15 +33,6 @@ Magnetism::~Magnetism() } #include "module_cell/klist.h" - -K_Vectors::K_Vectors() -{ -} - -K_Vectors::~K_Vectors() -{ -} - #include "module_cell/module_neighbor/sltk_grid_driver.h" // mock find_atom() function void Grid_Driver::Find_atom(const UnitCell& ucell, diff --git a/source/module_elecstate/test/elecstate_base_test.cpp b/source/module_elecstate/test/elecstate_base_test.cpp index 02905c64ed..9e393f7323 100644 --- a/source/module_elecstate/test/elecstate_base_test.cpp +++ b/source/module_elecstate/test/elecstate_base_test.cpp @@ -41,12 +41,6 @@ Magnetism::~Magnetism(){} InfoNonlocal::InfoNonlocal(){} InfoNonlocal::~InfoNonlocal(){} #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} ModulePW::PW_Basis::PW_Basis() { diff --git a/source/module_elecstate/test/elecstate_energy_test.cpp b/source/module_elecstate/test/elecstate_energy_test.cpp index b8078c1962..bc2f5eb4be 100644 --- a/source/module_elecstate/test/elecstate_energy_test.cpp +++ b/source/module_elecstate/test/elecstate_energy_test.cpp @@ -54,12 +54,6 @@ double ElecState::get_local_pp_energy() } // namespace elecstate #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} /*************************************************************** diff --git a/source/module_elecstate/test/elecstate_print_test.cpp b/source/module_elecstate/test/elecstate_print_test.cpp index 0fb0248e64..644f037cc5 100644 --- a/source/module_elecstate/test/elecstate_print_test.cpp +++ b/source/module_elecstate/test/elecstate_print_test.cpp @@ -11,12 +11,6 @@ #include "module_elecstate/potentials/gatefield.h" #include "module_elecstate/module_charge/charge.h" #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} /*************************************************************** * mock functions diff --git a/source/module_elecstate/test/elecstate_pw_test.cpp b/source/module_elecstate/test/elecstate_pw_test.cpp index 1ab7273721..a2a3533ade 100644 --- a/source/module_elecstate/test/elecstate_pw_test.cpp +++ b/source/module_elecstate/test/elecstate_pw_test.cpp @@ -127,12 +127,6 @@ Fcoef::~Fcoef() { } #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} void Charge::set_rho_core(const UnitCell& ucell, ModuleBase::ComplexMatrix const&, const bool*) { diff --git a/source/module_esolver/esolver_ks_pw.cpp b/source/module_esolver/esolver_ks_pw.cpp index 6ab0cccba1..84bf0fe8a4 100644 --- a/source/module_esolver/esolver_ks_pw.cpp +++ b/source/module_esolver/esolver_ks_pw.cpp @@ -209,7 +209,7 @@ void ESolver_KS_PW::before_all_runners(UnitCell& ucell, const Input_p GlobalV::MY_RANK, ucell, this->sf, - this->kv.para_k, + this->kv, this->ppcell, *this->pw_wfc); allocate_psi(this->psi, this->kv.get_nks(), this->kv.ngk.data(), PARAM.inp.nbands, this->pw_wfc->npwk_max); diff --git a/source/module_hamilt_lcao/module_deltaspin/test/lambda_loop_helper_test.cpp b/source/module_hamilt_lcao/module_deltaspin/test/lambda_loop_helper_test.cpp index b10e4ea08f..040a20fabd 100644 --- a/source/module_hamilt_lcao/module_deltaspin/test/lambda_loop_helper_test.cpp +++ b/source/module_hamilt_lcao/module_deltaspin/test/lambda_loop_helper_test.cpp @@ -3,12 +3,6 @@ #include "gtest/gtest.h" #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} /************************************************ * unit test of the functions in lambda_loop_helper.cpp ***********************************************/ diff --git a/source/module_hamilt_lcao/module_deltaspin/test/spin_constrain_test.cpp b/source/module_hamilt_lcao/module_deltaspin/test/spin_constrain_test.cpp index 1fd36524e3..e654f0e1ff 100644 --- a/source/module_hamilt_lcao/module_deltaspin/test/spin_constrain_test.cpp +++ b/source/module_hamilt_lcao/module_deltaspin/test/spin_constrain_test.cpp @@ -36,8 +36,6 @@ * get the index of orbital with spin component from (itype, iat, orbital_index) */ #include "module_cell/klist.h" -K_Vectors::K_Vectors(){} -K_Vectors::~K_Vectors(){} template class SpinConstrainTest : public testing::Test diff --git a/source/module_hamilt_lcao/module_deltaspin/test/template_helpers_test.cpp b/source/module_hamilt_lcao/module_deltaspin/test/template_helpers_test.cpp index 374dc380f7..ea0731ae84 100644 --- a/source/module_hamilt_lcao/module_deltaspin/test/template_helpers_test.cpp +++ b/source/module_hamilt_lcao/module_deltaspin/test/template_helpers_test.cpp @@ -16,12 +16,6 @@ * So, we just test if they can be called without error. */ #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} class SpinConstrainTest : public testing::Test { diff --git a/source/module_hamilt_pw/hamilt_pwdft/elecond.cpp b/source/module_hamilt_pw/hamilt_pwdft/elecond.cpp index f7ac5000d4..5f59858132 100644 --- a/source/module_hamilt_pw/hamilt_pwdft/elecond.cpp +++ b/source/module_hamilt_pw/hamilt_pwdft/elecond.cpp @@ -137,7 +137,7 @@ void EleCond::jjresponse_ks(const int ik, const int nt, const double dt, const d if (GlobalV::RANK_IN_POOL == 0) { int nkstot = this->p_kv->get_nkstot(); - int ikglobal = K_Vectors::get_ik_global(ik, nkstot); + int ikglobal = p_kv->ik2iktot[ik]; std::stringstream ss; ss << PARAM.globalv.global_out_dir << "vmatrix" << ikglobal + 1 << ".dat"; Binstream binpij(ss.str(), "w"); diff --git a/source/module_hamilt_pw/hamilt_stodft/sto_wf.cpp b/source/module_hamilt_pw/hamilt_stodft/sto_wf.cpp index 6d5accd3b0..8a76daa9e9 100644 --- a/source/module_hamilt_pw/hamilt_stodft/sto_wf.cpp +++ b/source/module_hamilt_pw/hamilt_stodft/sto_wf.cpp @@ -325,7 +325,7 @@ void Stochastic_WF::init_sto_orbitals_Ecut(const int seed_in, for (int ik = 0; ik < nks; ++ik) { - const int iktot = K_Vectors::get_ik_global(ik, nkstot); + const int iktot = kv.ik2iktot[ik]; const int npw = wfcpw.npwk[ik]; int* ig2ixyz = new int[npw]; diff --git a/source/module_hamilt_pw/hamilt_stodft/test/test_hamilt_sto.cpp b/source/module_hamilt_pw/hamilt_stodft/test/test_hamilt_sto.cpp index 305cc548f9..6da83c4ced 100644 --- a/source/module_hamilt_pw/hamilt_stodft/test/test_hamilt_sto.cpp +++ b/source/module_hamilt_pw/hamilt_stodft/test/test_hamilt_sto.cpp @@ -4,8 +4,6 @@ #include "gtest/gtest.h" #include -K_Vectors::K_Vectors(){} -K_Vectors::~K_Vectors(){} elecstate::Potential::~Potential(){} void elecstate::Potential::cal_v_eff(Charge const*, UnitCell const*, ModuleBase::matrix&){} void elecstate::Potential::cal_fixed_v(double*){} diff --git a/source/module_hsolver/test/hsolver_supplementary_mock.h b/source/module_hsolver/test/hsolver_supplementary_mock.h index e670adfe15..808aa8ed5c 100644 --- a/source/module_hsolver/test/hsolver_supplementary_mock.h +++ b/source/module_hsolver/test/hsolver_supplementary_mock.h @@ -146,9 +146,3 @@ void Stochastic_WF::init(K_Vectors* p_kv, const int npwx_in) } #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} diff --git a/source/module_io/test/read_wfc_to_rho_test.cpp b/source/module_io/test/read_wfc_to_rho_test.cpp index cbf0ba0586..74be35a20c 100644 --- a/source/module_io/test/read_wfc_to_rho_test.cpp +++ b/source/module_io/test/read_wfc_to_rho_test.cpp @@ -55,12 +55,6 @@ int XC_Functional::get_func_type() { return 0; } -K_Vectors::K_Vectors() -{ -} -K_Vectors::~K_Vectors() -{ -} Symmetry_rho::Symmetry_rho() { } @@ -75,17 +69,20 @@ void Symmetry_rho::begin(const int& spin_now, return; } -int K_Vectors::get_ik_global(const int& ik, const int& nkstot) +void cal_ik2iktot(std::vector&ik2iktot, const int& nks, const int& nkstot) { - int nkp = nkstot / PARAM.inp.kpar; - int rem = nkstot % PARAM.inp.kpar; - if (GlobalV::MY_POOL < rem) - { - return GlobalV::MY_POOL * nkp + GlobalV::MY_POOL + ik; - } - else + for(int ik = 0; ik < nks; ++ik) { - return GlobalV::MY_POOL * nkp + rem + ik; + int nkp = nkstot / PARAM.inp.kpar; + int rem = nkstot % PARAM.inp.kpar; + if (GlobalV::MY_POOL < rem) + { + ik2iktot[ik] = GlobalV::MY_POOL * nkp + GlobalV::MY_POOL + ik; + } + else + { + ik2iktot[ik] = GlobalV::MY_POOL * nkp + rem + ik; + } } } @@ -140,6 +137,8 @@ TEST_F(ReadWfcRhoTest, ReadWfcRho) const double shift = my_pool * 0.1; kv->kvec_d = {ModuleBase::Vector3(shift, shift, shift), ModuleBase::Vector3(0.5 + shift, 0.5 + shift, 0.5 + shift)}; + kv->ik2iktot.resize(nks); + cal_ik2iktot(kv->ik2iktot, nks, nkstot); // Init the pw basis #ifdef __MPI diff --git a/source/module_io/test_serial/nscf_band_test.cpp b/source/module_io/test_serial/nscf_band_test.cpp index 078226a94e..be3a359f92 100644 --- a/source/module_io/test_serial/nscf_band_test.cpp +++ b/source/module_io/test_serial/nscf_band_test.cpp @@ -3,13 +3,6 @@ #include "module_io/nscf_band.h" #include "module_cell/parallel_kpoints.h" #include "module_cell/klist.h" -K_Vectors::K_Vectors() -{ -} - -K_Vectors::~K_Vectors() -{ -} /************************************************ diff --git a/source/module_io/write_wfc_pw.cpp b/source/module_io/write_wfc_pw.cpp index 640608e078..d00ca6a41f 100644 --- a/source/module_io/write_wfc_pw.cpp +++ b/source/module_io/write_wfc_pw.cpp @@ -66,13 +66,11 @@ void ModuleIO::write_wfc_pw(const std::string& fn, int ikstot = 0; // ikstot : the index within all k-points const int ng = kv.ngk[ik]; const int ng_max = wfcpw->npwk_max; + ikstot = kv.ik2iktot[ik]; #ifdef __MPI MPI_Allreduce(&kv.ngk[ik], &ikngtot, 1, MPI_INT, MPI_SUM, POOL_WORLD); - - ikstot = K_Vectors::get_ik_global(ik, nkstot); #else - ikngtot = kv.ngk[ik]; - ikstot = ik; + ikngtot = kv.ngk[ik]; #endif const int ikngtot_npol = ikngtot * PARAM.globalv.npol; #ifdef __MPI diff --git a/source/module_psi/psi_init.cpp b/source/module_psi/psi_init.cpp index 24708c9665..a98ec0c89b 100644 --- a/source/module_psi/psi_init.cpp +++ b/source/module_psi/psi_init.cpp @@ -22,10 +22,10 @@ PSIInit::PSIInit(const std::string& init_wfc_in, const int& rank_in, const UnitCell& ucell_in, const Structure_Factor& sf_in, - const Parallel_Kpoints& parakpts_in, + const K_Vectors& kv_in, const pseudopot_cell_vnl& nlpp_in, const ModulePW::PW_Basis_K& pw_wfc_in) - : ucell(ucell_in), sf(sf_in), nlpp(nlpp_in), parakpts(parakpts_in), pw_wfc(pw_wfc_in), rank(rank_in) + : ucell(ucell_in), sf(sf_in), nlpp(nlpp_in), kv(kv_in), pw_wfc(pw_wfc_in), rank(rank_in) { this->init_wfc = init_wfc_in; this->ks_solver = ks_solver_in; diff --git a/source/module_psi/psi_init.h b/source/module_psi/psi_init.h index 712952e634..e112a71a6e 100644 --- a/source/module_psi/psi_init.h +++ b/source/module_psi/psi_init.h @@ -17,7 +17,7 @@ class PSIInit const int& rank, const UnitCell& ucell, const Structure_Factor& sf, - const Parallel_Kpoints& parakpts, + const K_Vectors& kv_in, const pseudopot_cell_vnl& nlpp, const ModulePW::PW_Basis_K& pw_wfc); ~PSIInit(){}; @@ -65,7 +65,7 @@ class PSIInit const ModulePW::PW_Basis_K& pw_wfc; // parallel kpoints - const Parallel_Kpoints& parakpts; + const K_Vectors& kv; // unit cell const UnitCell& ucell; diff --git a/source/module_psi/psi_initializer.cpp b/source/module_psi/psi_initializer.cpp index 36c7624bda..27eea4e00c 100644 --- a/source/module_psi/psi_initializer.cpp +++ b/source/module_psi/psi_initializer.cpp @@ -12,6 +12,23 @@ #include "module_base/parallel_reduce.h" #endif +template +void psi_initializer::initialize(const Structure_Factor* sf, + const ModulePW::PW_Basis_K* pw_wfc, + const UnitCell* p_ucell, + const K_Vectors* p_kv_in, + const int& random_seed, + const pseudopot_cell_vnl* p_pspot_nl, + const int& rank) +{ + this->sf_ = sf; + this->pw_wfc_ = pw_wfc; + this->p_ucell_ = p_ucell; + this->p_kv = p_kv_in; + this->random_seed_ = random_seed; + this->p_pspot_nl_ = p_pspot_nl; +} + template void psi_initializer::random_t(T* psi, const int iw_start, const int iw_end, const int ik, const int mode) { diff --git a/source/module_psi/psi_initializer.h b/source/module_psi/psi_initializer.h index 876be12bda..06ec7b326b 100644 --- a/source/module_psi/psi_initializer.h +++ b/source/module_psi/psi_initializer.h @@ -61,11 +61,10 @@ class psi_initializer virtual void initialize(const Structure_Factor*, //< structure factor const ModulePW::PW_Basis_K*, //< planewave basis const UnitCell*, //< unit cell - const Parallel_Kpoints* = nullptr, //< parallel kpoints + const K_Vectors* = nullptr, //< parallel kpoints const int& = 1, //< random seed const pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential - const int& = 0) - = 0; //< MPI rank + const int& = 0); //< rank /// @brief CENTRAL FUNCTION: calculate the interpolate table if needed virtual void tabulate() @@ -129,7 +128,7 @@ class psi_initializer const Structure_Factor* sf_ = nullptr; ///< Structure_Factor const ModulePW::PW_Basis_K* pw_wfc_ = nullptr; ///< use |k+G>, |G>, getgpluskcar and so on in PW_Basis_K const UnitCell* p_ucell_ = nullptr; ///< UnitCell - const Parallel_Kpoints* p_parakpts_ = nullptr; ///< Parallel_Kpoints + const K_Vectors* p_kv = nullptr; ///< Parallel_Kpoints const pseudopot_cell_vnl* p_pspot_nl_ = nullptr; ///< pseudopot_cell_vnl int random_seed_ = 1; ///< random seed, shared by random, atomic+random, nao+random std::vector ixy2is_; ///< used by stick_to_pool function diff --git a/source/module_psi/psi_initializer_atomic.cpp b/source/module_psi/psi_initializer_atomic.cpp index 6c86910bdb..d5ea4583b0 100644 --- a/source/module_psi/psi_initializer_atomic.cpp +++ b/source/module_psi/psi_initializer_atomic.cpp @@ -50,7 +50,7 @@ template void psi_initializer_atomic::initialize(const Structure_Factor* sf, //< structure factor const ModulePW::PW_Basis_K* pw_wfc, //< planewave basis const UnitCell* p_ucell, //< unit cell - const Parallel_Kpoints* p_parakpts, //< parallel kpoints + const K_Vectors* p_kv_in, const int& random_seed, //< random seed const pseudopot_cell_vnl* p_pspot_nl, const int& rank) @@ -62,12 +62,7 @@ void psi_initializer_atomic::initialize(const Structure_Factor* sf, / "pseudopot_cell_vnl object cannot be nullptr for atomic, quit."); } // import - this->sf_ = sf; - this->pw_wfc_ = pw_wfc; - this->p_ucell_ = p_ucell; - this->p_parakpts_ = p_parakpts; - this->p_pspot_nl_ = p_pspot_nl; - this->random_seed_ = random_seed; + psi_initializer::initialize(sf, pw_wfc, p_ucell, p_kv_in, random_seed, p_pspot_nl, rank); this->nbands_start_ = std::max(this->p_ucell_->natomwfc, PARAM.inp.nbands); this->nbands_complem_ = this->nbands_start_ - this->p_ucell_->natomwfc; // allocate diff --git a/source/module_psi/psi_initializer_atomic.h b/source/module_psi/psi_initializer_atomic.h index ef475dc7e2..402e63af59 100644 --- a/source/module_psi/psi_initializer_atomic.h +++ b/source/module_psi/psi_initializer_atomic.h @@ -23,12 +23,12 @@ class psi_initializer_atomic : public psi_initializer virtual void initialize(const Structure_Factor*, //< structure factor const ModulePW::PW_Basis_K*, //< planewave basis const UnitCell*, //< unit cell - const Parallel_Kpoints*, //< parallel kpoints - const int& = 1, //< random seed + const K_Vectors*, //< kpoints + const int& = 1, //< random seed const pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential - const int& = 0) override; //< MPI rank + const int& = 0) override; //< MPI rank virtual void tabulate() override; - virtual void init_psig(T* psig, const int& ik) override; + virtual void init_psig(T* psig, const int& ik) override; protected: // allocate memory for overlap table diff --git a/source/module_psi/psi_initializer_atomic_random.cpp b/source/module_psi/psi_initializer_atomic_random.cpp index b97e6fe5d9..f7b735f5ed 100644 --- a/source/module_psi/psi_initializer_atomic_random.cpp +++ b/source/module_psi/psi_initializer_atomic_random.cpp @@ -6,12 +6,12 @@ template void psi_initializer_atomic_random::initialize(const Structure_Factor* sf, //< structure factor const ModulePW::PW_Basis_K* pw_wfc, //< planewave basis const UnitCell* p_ucell, //< unit cell - const Parallel_Kpoints* p_parakpts, //< parallel kpoints - const int& random_seed, //< random seed + const K_Vectors* p_kv_in, + const int& random_seed, //< random seed const pseudopot_cell_vnl* p_pspot_nl, const int& rank) { - psi_initializer_atomic::initialize(sf, pw_wfc, p_ucell, p_parakpts, random_seed, p_pspot_nl, rank); + psi_initializer_atomic::initialize(sf, pw_wfc, p_ucell, p_kv_in, random_seed, p_pspot_nl, rank); } template diff --git a/source/module_psi/psi_initializer_atomic_random.h b/source/module_psi/psi_initializer_atomic_random.h index 1ee2353310..4055819fcc 100644 --- a/source/module_psi/psi_initializer_atomic_random.h +++ b/source/module_psi/psi_initializer_atomic_random.h @@ -25,12 +25,12 @@ class psi_initializer_atomic_random : public psi_initializer_atomic virtual void initialize(const Structure_Factor*, //< structure factor const ModulePW::PW_Basis_K*, //< planewave basis const UnitCell*, //< unit cell - const Parallel_Kpoints*, //< parallel kpoints - const int& = 1, //< random seed + const K_Vectors*, //< kpoints + const int& = 1, //< random seed const pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential - const int& = 0) override; //< MPI rank + const int& = 0) override; //< MPI rank - virtual void init_psig(T* psig, const int& ik) override; + virtual void init_psig(T* psig, const int& ik) override; private: }; diff --git a/source/module_psi/psi_initializer_file.cpp b/source/module_psi/psi_initializer_file.cpp index a1871672f9..5630d116de 100644 --- a/source/module_psi/psi_initializer_file.cpp +++ b/source/module_psi/psi_initializer_file.cpp @@ -8,16 +8,12 @@ template void psi_initializer_file::initialize(const Structure_Factor* sf, const ModulePW::PW_Basis_K* pw_wfc, const UnitCell* p_ucell, - const Parallel_Kpoints* p_parakpts, + const K_Vectors* p_kv_in, const int& random_seed, const pseudopot_cell_vnl* p_pspot_nl, const int& rank) { - this->pw_wfc_ = pw_wfc; - this->p_ucell_ = p_ucell; - this->p_parakpts_ = p_parakpts; - this->random_seed_ = random_seed; - this->p_pspot_nl_ = p_pspot_nl; + psi_initializer::initialize(sf, pw_wfc, p_ucell, p_kv_in, random_seed, p_pspot_nl, rank); this->nbands_start_ = PARAM.inp.nbands; this->nbands_complem_ = 0; } @@ -28,11 +24,10 @@ void psi_initializer_file::init_psig(T* psig, const int& ik) ModuleBase::timer::tick("psi_initializer_file", "init_psig"); const int npol = PARAM.globalv.npol; const int nbasis = this->pw_wfc_->npwk_max * npol; - const int pre_nk = PARAM.inp.nspin == 2 ? 2 : 1; - const int nkstot = this->p_parakpts_->nkstot_np * pre_nk; + const int nkstot = this->p_kv->nkstot; ModuleBase::ComplexMatrix wfcatom(this->nbands_start_, nbasis); std::stringstream filename; - int ik_tot = K_Vectors::get_ik_global(ik, nkstot); + int ik_tot = this->p_kv->ik2iktot[ik]; filename << PARAM.globalv.global_readin_dir << "WAVEFUNC" << ik_tot + 1 << ".dat"; ModuleIO::read_wfc_pw(filename.str(), this->pw_wfc_, ik, nkstot, wfcatom); diff --git a/source/module_psi/psi_initializer_file.h b/source/module_psi/psi_initializer_file.h index e4e527b4f7..115f0425c3 100644 --- a/source/module_psi/psi_initializer_file.h +++ b/source/module_psi/psi_initializer_file.h @@ -18,19 +18,19 @@ class psi_initializer_file : public psi_initializer this->method_ = "file"; }; ~psi_initializer_file(){}; - + /// @brief initialize the psi_initializer with external data and methods virtual void initialize(const Structure_Factor*, //< structure factor const ModulePW::PW_Basis_K*, //< planewave basis const UnitCell*, //< unit cell - const Parallel_Kpoints*, //< parallel kpoints - const int& = 1, //< random seed + const K_Vectors*, //< kpoints + const int& = 1, //< random seed const pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential - const int& = 0) override; //< MPI rank - + const int& = 0) override; //< MPI rank + /// @brief calculate and output planewave wavefunction /// @param ik kpoint index /// @return initialized planewave wavefunction (psi::Psi>*) - virtual void init_psig(T* psig, const int& ik) override; + virtual void init_psig(T* psig, const int& ik) override; }; #endif \ No newline at end of file diff --git a/source/module_psi/psi_initializer_nao.cpp b/source/module_psi/psi_initializer_nao.cpp index de71457c73..c2bb249501 100644 --- a/source/module_psi/psi_initializer_nao.cpp +++ b/source/module_psi/psi_initializer_nao.cpp @@ -150,7 +150,7 @@ template void psi_initializer_nao::initialize(const Structure_Factor* sf, const ModulePW::PW_Basis_K* pw_wfc, const UnitCell* p_ucell, - const Parallel_Kpoints* p_parakpts, + const K_Vectors* p_kv_in, const int& random_seed, const pseudopot_cell_vnl* p_pspot_nl, const int& rank) @@ -158,12 +158,7 @@ void psi_initializer_nao::initialize(const Structure_Factor* sf, ModuleBase::timer::tick("psi_initializer_nao", "initialize_mpi"); // import - this->sf_ = sf; - this->pw_wfc_ = pw_wfc; - this->p_ucell_ = p_ucell; - this->p_parakpts_ = p_parakpts; - this->p_pspot_nl_ = p_pspot_nl; - this->random_seed_ = random_seed; + psi_initializer::initialize(sf, pw_wfc, p_ucell, p_kv_in, random_seed, p_pspot_nl, rank); // allocate this->allocate_ao_table(); diff --git a/source/module_psi/psi_initializer_nao.h b/source/module_psi/psi_initializer_nao.h index 324e201df1..c9ba087ed6 100644 --- a/source/module_psi/psi_initializer_nao.h +++ b/source/module_psi/psi_initializer_nao.h @@ -21,16 +21,16 @@ class psi_initializer_nao : public psi_initializer }; ~psi_initializer_nao(){}; - virtual void init_psig(T* psig, const int& ik) override; + virtual void init_psig(T* psig, const int& ik) override; /// @brief initialize the psi_initializer with external data and methods virtual void initialize(const Structure_Factor*, //< structure factor const ModulePW::PW_Basis_K*, //< planewave basis const UnitCell*, //< unit cell - const Parallel_Kpoints*, //< parallel kpoints - const int& = 1, //< random seed + const K_Vectors*, //< kpoints + const int& = 1, //< random seed const pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential - const int& = 0) override; //< MPI rank + const int& = 0) override; //< MPI rank void read_external_orbs(const std::string* orbital_files, const int& rank); virtual void tabulate() override; diff --git a/source/module_psi/psi_initializer_nao_random.cpp b/source/module_psi/psi_initializer_nao_random.cpp index ef0811fd9d..4f8b8d940f 100644 --- a/source/module_psi/psi_initializer_nao_random.cpp +++ b/source/module_psi/psi_initializer_nao_random.cpp @@ -6,12 +6,12 @@ template void psi_initializer_nao_random::initialize(const Structure_Factor* sf, const ModulePW::PW_Basis_K* pw_wfc, const UnitCell* p_ucell, - const Parallel_Kpoints* p_parakpts, + const K_Vectors* p_kv_in, const int& random_seed, const pseudopot_cell_vnl* p_pspot_nl, const int& rank) { - psi_initializer_nao::initialize(sf, pw_wfc, p_ucell, p_parakpts, random_seed, p_pspot_nl, rank); + psi_initializer_nao::initialize(sf, pw_wfc, p_ucell, p_kv_in, random_seed, p_pspot_nl, rank); } template diff --git a/source/module_psi/psi_initializer_nao_random.h b/source/module_psi/psi_initializer_nao_random.h index acbdb76945..b4d533cea6 100644 --- a/source/module_psi/psi_initializer_nao_random.h +++ b/source/module_psi/psi_initializer_nao_random.h @@ -25,11 +25,11 @@ class psi_initializer_nao_random : public psi_initializer_nao virtual void initialize(const Structure_Factor*, //< structure factor const ModulePW::PW_Basis_K*, //< planewave basis const UnitCell*, //< unit cell - const Parallel_Kpoints*, //< parallel kpoints - const int& = 1, //< random seed + const K_Vectors*, //< kpoints + const int& = 1, //< random seed const pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential - const int& = 0) override; //< MPI rank + const int& = 0) override; //< MPI rank - virtual void init_psig(T* psig, const int& ik) override; + virtual void init_psig(T* psig, const int& ik) override; }; #endif \ No newline at end of file diff --git a/source/module_psi/psi_initializer_random.cpp b/source/module_psi/psi_initializer_random.cpp index 56497d5c7b..6375df4d24 100644 --- a/source/module_psi/psi_initializer_random.cpp +++ b/source/module_psi/psi_initializer_random.cpp @@ -11,16 +11,12 @@ template void psi_initializer_random::initialize(const Structure_Factor* sf, const ModulePW::PW_Basis_K* pw_wfc, const UnitCell* p_ucell, - const Parallel_Kpoints* p_parakpts, + const K_Vectors* p_kv_in const int& random_seed, const pseudopot_cell_vnl* p_pspot_nl, const int& rank) { - this->pw_wfc_ = pw_wfc; - this->p_ucell_ = p_ucell; - this->p_parakpts_ = p_parakpts; - this->random_seed_ = random_seed; - this->p_pspot_nl_ = p_pspot_nl; + psi_initializer::initialize(sf, pw_wfc, p_ucell, p_kv_in, random_seed, p_pspot_nl, rank); this->ixy2is_.clear(); this->ixy2is_.resize(this->pw_wfc_->fftnxy); this->pw_wfc_->getfftixy2is(this->ixy2is_.data()); diff --git a/source/module_psi/psi_initializer_random.h b/source/module_psi/psi_initializer_random.h index 9285bd9bcf..c2f66d6020 100644 --- a/source/module_psi/psi_initializer_random.h +++ b/source/module_psi/psi_initializer_random.h @@ -27,9 +27,9 @@ class psi_initializer_random : public psi_initializer virtual void initialize(const Structure_Factor*, //< structure factor const ModulePW::PW_Basis_K*, //< planewave basis const UnitCell*, //< unit cell - const Parallel_Kpoints*, //< parallel kpoints - const int& = 1, //< random seed + const K_Vectors*, //< kpoints + const int& = 1, //< random seed const pseudopot_cell_vnl* = nullptr, //< nonlocal pseudopotential - const int& = 0) override; //< MPI rank + const int& = 0) override; //< MPI rank }; #endif \ No newline at end of file diff --git a/source/module_psi/test/psi_initializer_unit_test.cpp b/source/module_psi/test/psi_initializer_unit_test.cpp index d4e30234c9..fd9dcd497c 100644 --- a/source/module_psi/test/psi_initializer_unit_test.cpp +++ b/source/module_psi/test/psi_initializer_unit_test.cpp @@ -90,18 +90,13 @@ std::complex* Structure_Factor::get_sk(int ik, int it, int ia, ModulePW: return sk; } -int K_Vectors::get_ik_global(const int& ik, const int& nkstot) -{ - return ik; -} - class PsiIntializerUnitTest : public ::testing::Test { public: Structure_Factor* p_sf = nullptr; ModulePW::PW_Basis_K* p_pw_wfc = nullptr; UnitCell* p_ucell = nullptr; pseudopot_cell_vnl* p_pspot_vnl = nullptr; - Parallel_Kpoints* p_parakpts = nullptr; + K_Vectors* p_kv = nullptr; int random_seed = 1; psi_initializer>* psi_init; @@ -115,7 +110,7 @@ class PsiIntializerUnitTest : public ::testing::Test { this->p_pw_wfc = new ModulePW::PW_Basis_K(); this->p_ucell = new UnitCell(); this->p_pspot_vnl = new pseudopot_cell_vnl(); - this->p_parakpts = new Parallel_Kpoints(); + this->p_kv = new K_Vectors(); // mock PARAM.input.nbands = 1; PARAM.input.nspin = 1; @@ -261,8 +256,8 @@ class PsiIntializerUnitTest : public ::testing::Test { this->p_pspot_vnl->lmaxkb = 1; - this->p_parakpts->startk_pool.resize(1); - this->p_parakpts->startk_pool[0] = 0; + this->p_kv->ik2iktot.resize(1); + this->p_kv->ik2iktot[0] = 0; } void TearDown() override @@ -272,7 +267,7 @@ class PsiIntializerUnitTest : public ::testing::Test { delete this->p_pw_wfc; delete this->p_ucell; delete this->p_pspot_vnl; - delete this->p_parakpts; + delete this->p_kv; } }; @@ -319,7 +314,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigRandom) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -338,7 +333,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomic) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -361,7 +356,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSoc) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -388,7 +383,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicSocHasSo) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -411,7 +406,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigAtomicRandom) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -430,7 +425,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNao) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -449,7 +444,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoRandom) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -473,7 +468,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSoc) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -497,7 +492,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSo) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); @@ -521,7 +516,7 @@ TEST_F(PsiIntializerUnitTest, CalPsigNaoSocHasSoDOMAG) { this->psi_init->initialize(this->p_sf, this->p_pw_wfc, this->p_ucell, - this->p_parakpts, + this->p_kv, this->random_seed, this->p_pspot_vnl, GlobalV::MY_RANK); From bb765cc053a48ddca48cc307787487200572564b Mon Sep 17 00:00:00 2001 From: Qianruipku Date: Sat, 11 Jan 2025 09:44:14 +0800 Subject: [PATCH 2/6] fix compile --- source/module_cell/klist.cpp | 4 +- source/module_cell/klist.h | 486 +++++++++---------- source/module_cell/parallel_kpoints.h | 5 +- source/module_elecstate/elecstate_print.cpp | 15 +- source/module_io/to_wannier90_lcao_in_pw.cpp | 2 +- source/module_psi/psi_init.cpp | 2 +- source/module_psi/psi_initializer.cpp | 2 +- source/module_psi/psi_initializer.h | 2 +- source/module_psi/psi_initializer_file.cpp | 2 +- source/module_psi/psi_initializer_random.cpp | 2 +- 10 files changed, 265 insertions(+), 257 deletions(-) diff --git a/source/module_cell/klist.cpp b/source/module_cell/klist.cpp index 73dbad9b69..7648ee3f5f 100644 --- a/source/module_cell/klist.cpp +++ b/source/module_cell/klist.cpp @@ -13,7 +13,7 @@ #include "module_cell/module_paw/paw_cell.h" #endif -int K_Vectors::cal_ik_global() +void K_Vectors::cal_ik_global() { const int my_pool = this->para_k.my_pool; this->ik2iktot.resize(this->nks); @@ -23,7 +23,7 @@ int K_Vectors::cal_ik_global() for (int ik = 0; ik < this->nks / 2; ++ik) { this->ik2iktot[ik] = this->para_k.startk_pool[my_pool] + ik; - this->ik2iktot[ik + this->nks / 2] = this->nsktot / 2 + this->para_k.startk_pool[my_pool] + ik; + this->ik2iktot[ik + this->nks / 2] = this->nkstot / 2 + this->para_k.startk_pool[my_pool] + ik; } } else diff --git a/source/module_cell/klist.h b/source/module_cell/klist.h index c0c14a905c..c8dc7dfd84 100644 --- a/source/module_cell/klist.h +++ b/source/module_cell/klist.h @@ -140,249 +140,249 @@ class K_Vectors { this->nkstot_full = value; } + std::vector ik2iktot; ///<[nks] map ik to the global index of k points -private: - int nks = 0; ///< number of symmetry-reduced k points in this pool(processor, up+dw) - int nkstot = 0; ///< number of symmetry-reduced k points in full k mesh - int nkstot_full = 0; ///< number of k points before symmetry reduction in full k mesh - std::vector ik2iktot; ///<[nks] map ik to the global index of k points - - int nspin = 0; - bool kc_done = false; - bool kd_done = false; - double koffset[3] = {0.0}; // used only in automatic k-points. - std::string k_kword; // LiuXh add 20180619 - int k_nkstot = 0; // LiuXh add 20180619 - bool is_mp = false; // Monkhorst-Pack - - /** - * @brief Resize the k-point related vectors according to the new k-point number. - * - * This function resizes the vectors that store the k-point information, - * including the Cartesian and Direct coordinates of k-points, - * the weights of k-points, the index of k-points, and the number of plane waves for each k-point. - * - * @param kpoint_number The new number of k-points. - * - * @return void - * - * @note The memory recording lines are commented out. If you want to track the memory usage, - * you can uncomment these lines. - */ - void renew(const int& kpoint_number); - - // step 1 : generate kpoints - - /** - * @brief Reads the k-points from a file. - * - * This function reads the k-points from a file specified by the filename. - * It supports both Cartesian and Direct coordinates, and can handle different types of k-points, - * including Gamma, Monkhorst-Pack, and Line mode. It also supports automatic generation of k-points - * file if the file does not exist. - * - * @param fn The name of the file containing the k-points. - * - * @return bool Returns true if the k-points are successfully read from the file, - * false otherwise. - * - * @note It will generate a k-points file automatically - * according to the global variables GAMMA_ONLY_LOCAL and KSPACING. - * @note If the k-points type is neither Gamma nor Monkhorst-Pack, it will quit with a warning. - * @note If the k-points type is Line mode and the symmetry flag is 1, it will quit with a warning. - * @note If the number of k-points is greater than 100000, it will quit with a warning. - */ - bool read_kpoints(const UnitCell& ucell, - const std::string& fn); // return 0: something wrong. - - /** - * @brief Adds k-points linearly between special points. - * - * This function adds k-points linearly between special points in the Brillouin zone. - * The special points and the number of k-points between them are read from an input file. - * - * @param ifk The input file stream from which the special points and the number of k-points between them are read. - * @param kvec A vector to store the generated k-points. - * - * @return void - * - * @note The function first reads the number of special points (nks_special) and the number of k-points between them - * (nkl) from the input file. - * @note The function then recalculates the total number of k-points (nkstot) based on the number of k-points - * between the special points. - * @note The function generates the k-points by linearly interpolating between the special points. - * @note The function also assigns a segment ID to each k-point to distinguish different k-line segments. - * @note The function checks that the total number of generated k-points matches the calculated total number of - * k-points. - * @note The function checks that the size of the segment ID vector matches the total number of k-points. - */ - void interpolate_k_between(std::ifstream& ifk, std::vector>& kvec); - - /** - * @brief Generates k-points using the Monkhorst-Pack scheme. - * - * This function generates k-points in the reciprocal space using the Monkhorst-Pack scheme. - * - * @param nmp_in the number of k-points in each dimension. - * @param koffset_in the offset for the k-points in each dimension. - * @param k_type The type of k-point. 1 means without Gamma point, 0 means with Gamma. - * - * @return void - * - * @note The function assumes that the k-points are evenly distributed in the reciprocal space. - * @note The function sets the weight of each k-point to be equal, so that the total weight of all k-points is 1. - * @note The function sets the flag kd_done to true to indicate that the k-points have been generated. - */ - void Monkhorst_Pack(const int* nmp_in, const double* koffset_in, const int tipo); - - /** - * @brief Calculates the coordinate of a k-point using the Monkhorst-Pack scheme. - * - * This function calculates the coordinate of a k-point in the reciprocal space using the Monkhorst-Pack scheme. - * The Monkhorst-Pack scheme is a method for generating k-points in the Brillouin zone. - * - * @param k_type The type of k-point. 1 means without Gamma point, 0 means with Gamma. - * @param offset The offset for the k-point. - * @param n The index of the k-point in the current dimension. - * @param dim The total number of k-points in the current dimension. - * - * @return double Returns the coordinate of the k-point. - * - * @note The function assumes that the k-points are evenly distributed in the reciprocal space. - */ - double Monkhorst_Pack_formula(const int& k_type, const double& offset, const int& n, const int& dim); - - // step 2 : set both kvec and kved; normalize weight - - /** - * @brief Updates the k-points to use the irreducible Brillouin zone (IBZ). - * - * This function updates the k-points to use the irreducible Brillouin zone (IBZ) instead of the full Brillouin - * zone. - * - * @return void - * - * @note This function should only be called by the master process (MY_RANK == 0). - * @note This function assumes that the number of k-points in the IBZ (nkstot_ibz) is greater than 0. - * @note This function updates the total number of k-points (nkstot) to be the number of k-points in the IBZ. - * @note This function resizes the vector of k-points (kvec_d) and updates its values to be the k-points in the IBZ. - * @note This function also updates the weights of the k-points (wk) to be the weights in the IBZ. - * @note After this function is called, the flag kd_done is set to true to indicate that the k-points have been - * updated, and the flag kc_done is set to false to indicate that the Cartesian coordinates of the k-points need to - * be recalculated. - */ - void update_use_ibz(const int& nkstot_ibz, - const std::vector>& kvec_d_ibz, - const std::vector& wk_ibz); - - /** - * @brief Sets both the direct and Cartesian k-vectors. - * - * This function sets both the direct and Cartesian k-vectors based on the input parameters. - * It also checks the k-point type and sets the corresponding flags. - * - * @param G The reciprocal lattice matrix. - * @param R The real space lattice matrix. - * @param skpt A string to store the k-point table. - * - * @return void - * - * @note If the k-point type is neither "Cartesian" nor "Direct", an error message will be printed. - * @note The function sets the flags kd_done and kc_done to indicate whether the direct and Cartesian k-vectors have - * been set, respectively. - * @note The function also prints a table of the direct k-vectors and their weights. - * @note If the function is called by the master process (MY_RANK == 0), the k-point table is also stored in the - * string skpt. - */ - void set_both_kvec(const ModuleBase::Matrix3& G, const ModuleBase::Matrix3& R, std::string& skpt); - - /** - * @brief Normalizes the weights of the k-points. - * - * This function normalizes the weights of the k-points so that their sum is equal to the degeneracy of spin - * (degspin). - * - * @param degspin The degeneracy of spin. This is 1 for non-spin-polarized calculations and 2 for spin-polarized - * calculations. - * - * @return void - * - * @note This function should only be called by the master process (MY_RANK == 0). - * @note The function assumes that the sum of the weights of the k-points is greater than 0. - * @note The function first normalizes the weights so that their sum is 1, and then scales them by the degeneracy of - * spin. - */ - void normalize_wk(const int& degspin); - - // step 3 : mpi kpoints information. - - /** - * @brief Distributes k-points among MPI processes. - * - * This function distributes the k-points among the MPI processes. Each process gets a subset of the k-points to - * work on. The function also broadcasts various variables related to the k-points to all processes. - * - * @return void - * - * @note This function is only compiled and used if MPI is enabled. - * @note The function assumes that the number of k-points (nkstot) is greater than 0. - * @note The function broadcasts the flags kc_done and kd_done, the number of spins (nspin), the total number of - * k-points (nkstot), the full number of k-points (nkstot_full), the Monkhorst-Pack grid (nmp), the k-point offsets - * (koffset), and the segment IDs of the k-points (kl_segids). - * @note The function also broadcasts the indices of the k-points (isk), their weights (wk), and their Cartesian and - * direct coordinates (kvec_c and kvec_d). - * @note If a process has no k-points to work on, the function will quit with an error message. - */ - void mpi_k(); - - // step 4 : *2 kpoints. - - /** - * @brief Sets up the k-points for spin-up and spin-down calculations. - * - * This function sets up the k-points for spin-up and spin-down calculations. - * If the calculation is spin-polarized (nspin = 2), the number of k-points is doubled. - * The first half of the k-points correspond to spin-up, and the second half correspond to spin-down. - * 2 for LSDA - * 4 for non-collinear - * - * @return void - * - * @note For non-spin-polarized calculations (nspin = 1 or 4), the function simply sets the spin index of all - * k-points to 0. - * @note For spin-polarized calculations (nspin = 2), the function duplicates the k-points and their weights, - * sets the spin index of the first half of the k-points to 0 (spin-up), and the spin index of the second half - * to 1 (spin-down). - * @note The function also doubles the total number of k-points (nks and nkstot) for spin-polarized calculations. - * @note The function prints the total number of k-points for spin-polarized calculations. - */ - void set_kup_and_kdw(); - - // step 5 - // print k lists. - - /** - * @brief Prints the k-points in both Cartesian and direct coordinates. - * - * This function prints the k-points in both Cartesian and direct coordinates to the output file stream. - * The output includes the index, x, y, and z coordinates, and the weight of each k-point. - * - * @param ofs The output file stream to which the k-points are printed. - * - * @return void - * - * @note The function first checks if the total number of k-points (nkstot) is less than the number of k-points for - * the current spin (nks). If so, it prints an error message and quits. - * @note The function prints the k-points in a table format, with separate tables for Cartesian and direct - * coordinates. - * @note The function uses the FmtCore::format function to format the output. - */ - void print_klists(std::ofstream& fn); - - /** - * @brief Gets the global index of a k-point. - * @return this->ik2iktot[ik] - */ - void cal_ik_global(); + private: + int nks = 0; ///< number of symmetry-reduced k points in this pool(processor, up+dw) + int nkstot = 0; ///< number of symmetry-reduced k points in full k mesh + int nkstot_full = 0; ///< number of k points before symmetry reduction in full k mesh + + int nspin = 0; + bool kc_done = false; + bool kd_done = false; + double koffset[3] = {0.0}; // used only in automatic k-points. + std::string k_kword; // LiuXh add 20180619 + int k_nkstot = 0; // LiuXh add 20180619 + bool is_mp = false; // Monkhorst-Pack + + /** + * @brief Resize the k-point related vectors according to the new k-point number. + * + * This function resizes the vectors that store the k-point information, + * including the Cartesian and Direct coordinates of k-points, + * the weights of k-points, the index of k-points, and the number of plane waves for each k-point. + * + * @param kpoint_number The new number of k-points. + * + * @return void + * + * @note The memory recording lines are commented out. If you want to track the memory usage, + * you can uncomment these lines. + */ + void renew(const int& kpoint_number); + + // step 1 : generate kpoints + + /** + * @brief Reads the k-points from a file. + * + * This function reads the k-points from a file specified by the filename. + * It supports both Cartesian and Direct coordinates, and can handle different types of k-points, + * including Gamma, Monkhorst-Pack, and Line mode. It also supports automatic generation of k-points + * file if the file does not exist. + * + * @param fn The name of the file containing the k-points. + * + * @return bool Returns true if the k-points are successfully read from the file, + * false otherwise. + * + * @note It will generate a k-points file automatically + * according to the global variables GAMMA_ONLY_LOCAL and KSPACING. + * @note If the k-points type is neither Gamma nor Monkhorst-Pack, it will quit with a warning. + * @note If the k-points type is Line mode and the symmetry flag is 1, it will quit with a warning. + * @note If the number of k-points is greater than 100000, it will quit with a warning. + */ + bool read_kpoints(const UnitCell& ucell, + const std::string& fn); // return 0: something wrong. + + /** + * @brief Adds k-points linearly between special points. + * + * This function adds k-points linearly between special points in the Brillouin zone. + * The special points and the number of k-points between them are read from an input file. + * + * @param ifk The input file stream from which the special points and the number of k-points between them are read. + * @param kvec A vector to store the generated k-points. + * + * @return void + * + * @note The function first reads the number of special points (nks_special) and the number of k-points between them + * (nkl) from the input file. + * @note The function then recalculates the total number of k-points (nkstot) based on the number of k-points + * between the special points. + * @note The function generates the k-points by linearly interpolating between the special points. + * @note The function also assigns a segment ID to each k-point to distinguish different k-line segments. + * @note The function checks that the total number of generated k-points matches the calculated total number of + * k-points. + * @note The function checks that the size of the segment ID vector matches the total number of k-points. + */ + void interpolate_k_between(std::ifstream& ifk, std::vector>& kvec); + + /** + * @brief Generates k-points using the Monkhorst-Pack scheme. + * + * This function generates k-points in the reciprocal space using the Monkhorst-Pack scheme. + * + * @param nmp_in the number of k-points in each dimension. + * @param koffset_in the offset for the k-points in each dimension. + * @param k_type The type of k-point. 1 means without Gamma point, 0 means with Gamma. + * + * @return void + * + * @note The function assumes that the k-points are evenly distributed in the reciprocal space. + * @note The function sets the weight of each k-point to be equal, so that the total weight of all k-points is 1. + * @note The function sets the flag kd_done to true to indicate that the k-points have been generated. + */ + void Monkhorst_Pack(const int* nmp_in, const double* koffset_in, const int tipo); + + /** + * @brief Calculates the coordinate of a k-point using the Monkhorst-Pack scheme. + * + * This function calculates the coordinate of a k-point in the reciprocal space using the Monkhorst-Pack scheme. + * The Monkhorst-Pack scheme is a method for generating k-points in the Brillouin zone. + * + * @param k_type The type of k-point. 1 means without Gamma point, 0 means with Gamma. + * @param offset The offset for the k-point. + * @param n The index of the k-point in the current dimension. + * @param dim The total number of k-points in the current dimension. + * + * @return double Returns the coordinate of the k-point. + * + * @note The function assumes that the k-points are evenly distributed in the reciprocal space. + */ + double Monkhorst_Pack_formula(const int& k_type, const double& offset, const int& n, const int& dim); + + // step 2 : set both kvec and kved; normalize weight + + /** + * @brief Updates the k-points to use the irreducible Brillouin zone (IBZ). + * + * This function updates the k-points to use the irreducible Brillouin zone (IBZ) instead of the full Brillouin + * zone. + * + * @return void + * + * @note This function should only be called by the master process (MY_RANK == 0). + * @note This function assumes that the number of k-points in the IBZ (nkstot_ibz) is greater than 0. + * @note This function updates the total number of k-points (nkstot) to be the number of k-points in the IBZ. + * @note This function resizes the vector of k-points (kvec_d) and updates its values to be the k-points in the IBZ. + * @note This function also updates the weights of the k-points (wk) to be the weights in the IBZ. + * @note After this function is called, the flag kd_done is set to true to indicate that the k-points have been + * updated, and the flag kc_done is set to false to indicate that the Cartesian coordinates of the k-points need to + * be recalculated. + */ + void update_use_ibz(const int& nkstot_ibz, + const std::vector>& kvec_d_ibz, + const std::vector& wk_ibz); + + /** + * @brief Sets both the direct and Cartesian k-vectors. + * + * This function sets both the direct and Cartesian k-vectors based on the input parameters. + * It also checks the k-point type and sets the corresponding flags. + * + * @param G The reciprocal lattice matrix. + * @param R The real space lattice matrix. + * @param skpt A string to store the k-point table. + * + * @return void + * + * @note If the k-point type is neither "Cartesian" nor "Direct", an error message will be printed. + * @note The function sets the flags kd_done and kc_done to indicate whether the direct and Cartesian k-vectors have + * been set, respectively. + * @note The function also prints a table of the direct k-vectors and their weights. + * @note If the function is called by the master process (MY_RANK == 0), the k-point table is also stored in the + * string skpt. + */ + void set_both_kvec(const ModuleBase::Matrix3& G, const ModuleBase::Matrix3& R, std::string& skpt); + + /** + * @brief Normalizes the weights of the k-points. + * + * This function normalizes the weights of the k-points so that their sum is equal to the degeneracy of spin + * (degspin). + * + * @param degspin The degeneracy of spin. This is 1 for non-spin-polarized calculations and 2 for spin-polarized + * calculations. + * + * @return void + * + * @note This function should only be called by the master process (MY_RANK == 0). + * @note The function assumes that the sum of the weights of the k-points is greater than 0. + * @note The function first normalizes the weights so that their sum is 1, and then scales them by the degeneracy of + * spin. + */ + void normalize_wk(const int& degspin); + + // step 3 : mpi kpoints information. + + /** + * @brief Distributes k-points among MPI processes. + * + * This function distributes the k-points among the MPI processes. Each process gets a subset of the k-points to + * work on. The function also broadcasts various variables related to the k-points to all processes. + * + * @return void + * + * @note This function is only compiled and used if MPI is enabled. + * @note The function assumes that the number of k-points (nkstot) is greater than 0. + * @note The function broadcasts the flags kc_done and kd_done, the number of spins (nspin), the total number of + * k-points (nkstot), the full number of k-points (nkstot_full), the Monkhorst-Pack grid (nmp), the k-point offsets + * (koffset), and the segment IDs of the k-points (kl_segids). + * @note The function also broadcasts the indices of the k-points (isk), their weights (wk), and their Cartesian and + * direct coordinates (kvec_c and kvec_d). + * @note If a process has no k-points to work on, the function will quit with an error message. + */ + void mpi_k(); + + // step 4 : *2 kpoints. + + /** + * @brief Sets up the k-points for spin-up and spin-down calculations. + * + * This function sets up the k-points for spin-up and spin-down calculations. + * If the calculation is spin-polarized (nspin = 2), the number of k-points is doubled. + * The first half of the k-points correspond to spin-up, and the second half correspond to spin-down. + * 2 for LSDA + * 4 for non-collinear + * + * @return void + * + * @note For non-spin-polarized calculations (nspin = 1 or 4), the function simply sets the spin index of all + * k-points to 0. + * @note For spin-polarized calculations (nspin = 2), the function duplicates the k-points and their weights, + * sets the spin index of the first half of the k-points to 0 (spin-up), and the spin index of the second half + * to 1 (spin-down). + * @note The function also doubles the total number of k-points (nks and nkstot) for spin-polarized calculations. + * @note The function prints the total number of k-points for spin-polarized calculations. + */ + void set_kup_and_kdw(); + + // step 5 + // print k lists. + + /** + * @brief Prints the k-points in both Cartesian and direct coordinates. + * + * This function prints the k-points in both Cartesian and direct coordinates to the output file stream. + * The output includes the index, x, y, and z coordinates, and the weight of each k-point. + * + * @param ofs The output file stream to which the k-points are printed. + * + * @return void + * + * @note The function first checks if the total number of k-points (nkstot) is less than the number of k-points for + * the current spin (nks). If so, it prints an error message and quits. + * @note The function prints the k-points in a table format, with separate tables for Cartesian and direct + * coordinates. + * @note The function uses the FmtCore::format function to format the output. + */ + void print_klists(std::ofstream& fn); + + /** + * @brief Gets the global index of a k-point. + * @return this->ik2iktot[ik] + */ + void cal_ik_global(); }; #endif // KVECT_H \ No newline at end of file diff --git a/source/module_cell/parallel_kpoints.h b/source/module_cell/parallel_kpoints.h index 751a44163a..971a2849f2 100644 --- a/source/module_cell/parallel_kpoints.h +++ b/source/module_cell/parallel_kpoints.h @@ -68,14 +68,13 @@ class Parallel_Kpoints return *std::max_element(nks_pool.begin(), nks_pool.end()); } - private: - + public: int kpar = 0; // number of pools int my_pool = 0; // the pool index of the present processor int rank_in_pool = 0; // the rank in the present pool int nproc = 1; // number of processors int nspin = 1; // number of spins - + private: std::vector startpro_pool; // the first processor in each pool #ifdef __MPI void get_nks_pool(const int& nkstot); diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index f515e76027..1519fbd9f9 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -2,6 +2,7 @@ #include "elecstate_getters.h" #include "module_base/formatter.h" #include "module_base/global_variable.h" +#include "module_base/parallel_common.h" #include "module_elecstate/potentials/H_Hartree_pw.h" #include "module_elecstate/potentials/efield.h" #include "module_elecstate/potentials/gatefield.h" @@ -173,8 +174,16 @@ void ElecState::print_eigenvalue(std::ofstream& ofs) { ModuleBase::WARNING_QUIT("print_eigenvalue", "Eigenvalues are too large!"); } - - std::string filename = ofs.rdbuf()->get_filename(); + std::stringstream ss; + if(PARAM.inp.out_alllog) + { + ss << PARAM.globalv.global_out_dir << "running_" << PARAM.inp.calculation << ".log"; + } + else + { + ss << PARAM.globalv.global_out_dir << "running_" << PARAM.inp.calculation << "_" << GlobalV::MY_RANK + 1 << ".log"; + } + std::string filename = ss.str(); std::vector ngk_tot = this->klist->ngk; #ifdef __MPI @@ -187,7 +196,7 @@ void ElecState::print_eigenvalue(std::ofstream& ofs) ofs << "\n STATE ENERGY(eV) AND OCCUPATIONS "; const int nk_fac = PARAM.inp.nspin == 2 ? 2 : 1; const int nks_np = nks / nk_fac; - const int nkstot_np + 1 = nkstot / nk_fac; + const int nkstot_np = nkstot / nk_fac; ofs << " NSPIN == " << PARAM.inp.nspin << std::endl; for (int is = 0; is < nk_fac; ++is) { diff --git a/source/module_io/to_wannier90_lcao_in_pw.cpp b/source/module_io/to_wannier90_lcao_in_pw.cpp index 24b7cec15c..78f04a8a97 100644 --- a/source/module_io/to_wannier90_lcao_in_pw.cpp +++ b/source/module_io/to_wannier90_lcao_in_pw.cpp @@ -46,7 +46,7 @@ void toWannier90_LCAO_IN_PW::calculate( ModulePW::PW_Basis_K* wfcpw_ptr = const_cast(wfcpw); delete this->psi_initer_; this->psi_initer_ = new psi_initializer_nao>(); - this->psi_initer_->initialize(sf_ptr, wfcpw_ptr, &ucell, &kv.para_k, 1, nullptr, GlobalV::MY_RANK); + this->psi_initer_->initialize(sf_ptr, wfcpw_ptr, &ucell, &kv, 1, nullptr, GlobalV::MY_RANK); this->psi_initer_->tabulate(); delete this->psi; const int nks_psi = (PARAM.inp.calculation == "nscf" && PARAM.inp.mem_saver == 1)? 1 : wfcpw->nks; diff --git a/source/module_psi/psi_init.cpp b/source/module_psi/psi_init.cpp index a98ec0c89b..2cdce4a5a8 100644 --- a/source/module_psi/psi_init.cpp +++ b/source/module_psi/psi_init.cpp @@ -74,7 +74,7 @@ void PSIInit::prepare_init(const int& random_seed) ModuleBase::WARNING_QUIT("PSIInit::prepare_init", "for new psi initializer, init_wfc type not supported"); } - this->psi_initer->initialize(&sf, &pw_wfc, &ucell, ¶kpts, random_seed, &nlpp, rank); + this->psi_initer->initialize(&sf, &pw_wfc, &ucell, &kv, random_seed, &nlpp, rank); this->psi_initer->tabulate(); ModuleBase::timer::tick("PSIInit", "prepare_init"); diff --git a/source/module_psi/psi_initializer.cpp b/source/module_psi/psi_initializer.cpp index 27eea4e00c..982ef2fdce 100644 --- a/source/module_psi/psi_initializer.cpp +++ b/source/module_psi/psi_initializer.cpp @@ -44,7 +44,7 @@ void psi_initializer::random_t(T* psi, const int iw_start, const int iw_end, if (this->random_seed_ > 0) // qianrui add 2021-8-13 { #ifdef __MPI - srand(unsigned(this->random_seed_ + this->p_parakpts_->startk_pool[GlobalV::MY_POOL] + ik)); + srand(unsigned(this->random_seed_ + this->p_kv->ik2iktot[ik])); #else srand(unsigned(this->random_seed_ + ik)); #endif diff --git a/source/module_psi/psi_initializer.h b/source/module_psi/psi_initializer.h index 06ec7b326b..e54ff9d3ff 100644 --- a/source/module_psi/psi_initializer.h +++ b/source/module_psi/psi_initializer.h @@ -14,7 +14,7 @@ #endif #include "module_base/macros.h" #include "module_base/parallel_global.h" -#include "module_cell/parallel_kpoints.h" +#include "module_cell/klist.h" #include /* diff --git a/source/module_psi/psi_initializer_file.cpp b/source/module_psi/psi_initializer_file.cpp index 5630d116de..ff65196f82 100644 --- a/source/module_psi/psi_initializer_file.cpp +++ b/source/module_psi/psi_initializer_file.cpp @@ -24,7 +24,7 @@ void psi_initializer_file::init_psig(T* psig, const int& ik) ModuleBase::timer::tick("psi_initializer_file", "init_psig"); const int npol = PARAM.globalv.npol; const int nbasis = this->pw_wfc_->npwk_max * npol; - const int nkstot = this->p_kv->nkstot; + const int nkstot = this->p_kv->get_nkstot(); ModuleBase::ComplexMatrix wfcatom(this->nbands_start_, nbasis); std::stringstream filename; int ik_tot = this->p_kv->ik2iktot[ik]; diff --git a/source/module_psi/psi_initializer_random.cpp b/source/module_psi/psi_initializer_random.cpp index 6375df4d24..84905513e3 100644 --- a/source/module_psi/psi_initializer_random.cpp +++ b/source/module_psi/psi_initializer_random.cpp @@ -11,7 +11,7 @@ template void psi_initializer_random::initialize(const Structure_Factor* sf, const ModulePW::PW_Basis_K* pw_wfc, const UnitCell* p_ucell, - const K_Vectors* p_kv_in + const K_Vectors* p_kv_in, const int& random_seed, const pseudopot_cell_vnl* p_pspot_nl, const int& rank) From 47beb63691aea43f20eb8867506b5c77c415b4d5 Mon Sep 17 00:00:00 2001 From: Qianruipku Date: Sat, 11 Jan 2025 11:22:15 +0800 Subject: [PATCH 3/6] fix: bug for init_wfc file when nspin = 2 --- source/module_elecstate/elecstate_print.cpp | 17 ++++--- .../module_charge/charge_init.cpp | 2 +- source/module_io/read_wfc_pw.cpp | 18 ++------ source/module_io/read_wfc_pw.h | 2 + source/module_io/read_wfc_to_rho.cpp | 45 ++++++++++--------- source/module_io/read_wfc_to_rho.h | 1 + source/module_io/test/read_wfc_pw_test.cpp | 16 +++---- .../module_io/test/read_wfc_to_rho_test.cpp | 2 +- source/module_psi/psi_initializer_file.cpp | 2 +- 9 files changed, 54 insertions(+), 51 deletions(-) diff --git a/source/module_elecstate/elecstate_print.cpp b/source/module_elecstate/elecstate_print.cpp index 1519fbd9f9..fc08baea4e 100644 --- a/source/module_elecstate/elecstate_print.cpp +++ b/source/module_elecstate/elecstate_print.cpp @@ -177,17 +177,20 @@ void ElecState::print_eigenvalue(std::ofstream& ofs) std::stringstream ss; if(PARAM.inp.out_alllog) { - ss << PARAM.globalv.global_out_dir << "running_" << PARAM.inp.calculation << ".log"; + ss << PARAM.globalv.global_out_dir << "running_" << PARAM.inp.calculation << "_" << GlobalV::MY_RANK + 1 << ".log"; } else { - ss << PARAM.globalv.global_out_dir << "running_" << PARAM.inp.calculation << "_" << GlobalV::MY_RANK + 1 << ".log"; + ss << PARAM.globalv.global_out_dir << "running_" << PARAM.inp.calculation << ".log"; } std::string filename = ss.str(); std::vector ngk_tot = this->klist->ngk; #ifdef __MPI - Parallel_Common::bcast_string(filename); + if(!PARAM.inp.out_alllog) + { + Parallel_Common::bcast_string(filename); + } MPI_Allreduce(MPI_IN_PLACE, ngk_tot.data(), nks, MPI_INT, MPI_SUM, POOL_WORLD); #endif @@ -214,7 +217,8 @@ void ElecState::print_eigenvalue(std::ofstream& ofs) #ifdef __MPI MPI_Barrier(MPI_COMM_WORLD); #endif - if (GlobalV::MY_POOL == ip && GlobalV::RANK_IN_POOL == 0 && GlobalV::MY_STOGROUP == 0) + bool ip_flag = PARAM.inp.out_alllog || (GlobalV::RANK_IN_POOL == 0 && GlobalV::MY_STOGROUP == 0); + if (GlobalV::MY_POOL == ip && ip_flag) { const int start_ik = nks_np * is; const int end_ik = nks_np * (is + 1); @@ -223,7 +227,7 @@ void ElecState::print_eigenvalue(std::ofstream& ofs) std::ofstream ofs_eig(filename.c_str(), std::ios::app); ofs_eig << std::setprecision(5); ofs_eig << std::setiosflags(std::ios::showpoint); - ofs_eig << " " << this->klist->ik2iktot[ik] + 1 - is * nkstot_np << "/" << nks_np + ofs_eig << " " << this->klist->ik2iktot[ik] + 1 - is * nkstot_np << "/" << nkstot_np << " kpoint (Cartesian) = " << this->klist->kvec_c[ik].x << " " << this->klist->kvec_c[ik].y << " " << this->klist->kvec_c[ik].z << " (" << ngk_tot[ik] << " pws)" << std::endl; @@ -239,6 +243,9 @@ void ElecState::print_eigenvalue(std::ofstream& ofs) } } } +#ifdef __MPI + MPI_Barrier(MPI_COMM_WORLD); +#endif ofs.seekp(0, std::ios::end); } return; diff --git a/source/module_elecstate/module_charge/charge_init.cpp b/source/module_elecstate/module_charge/charge_init.cpp index 9d104312b7..f6a0b400d4 100644 --- a/source/module_elecstate/module_charge/charge_init.cpp +++ b/source/module_elecstate/module_charge/charge_init.cpp @@ -248,7 +248,7 @@ void Charge::init_rho(elecstate::efermi& eferm_iout, const K_Vectors* kv = reinterpret_cast(klist); const int nkstot = kv->get_nkstot(); const std::vector& isk = kv->isk; - ModuleIO::read_wfc_to_rho(pw_wfc, symm, nkstot, isk, *this); + ModuleIO::read_wfc_to_rho(pw_wfc, symm, kv->ik2iktot.data(), nkstot, isk, *this); } } diff --git a/source/module_io/read_wfc_pw.cpp b/source/module_io/read_wfc_pw.cpp index 43977d0a3d..331d18138e 100644 --- a/source/module_io/read_wfc_pw.cpp +++ b/source/module_io/read_wfc_pw.cpp @@ -12,6 +12,7 @@ void ModuleIO::read_wfc_pw(const std::string& filename, const ModulePW::PW_Basis_K* pw_wfc, const int& ik, + const int& ikstot, const int& nkstot, ModuleBase::ComplexMatrix& wfc) { @@ -60,28 +61,17 @@ void ModuleIO::read_wfc_pw(const std::string& filename, const int nz = pw_wfc->nz; const int npwk_max = pw_wfc->npwk_max; - int npwtot, ikstot, max_dim; + int npwtot = 0; + int max_dim = 0; - // get npwtot and ikstot + // get npwtot #ifdef __MPI MPI_Allreduce(&pw_wfc->npwk[ik], &npwtot, 1, MPI_INT, MPI_SUM, POOL_WORLD); MPI_Allreduce(&npwk_max, &max_dim, 1, MPI_INT, MPI_MAX, POOL_WORLD); - int nkp = nkstot / GlobalV::KPAR; - int rem = nkstot % GlobalV::KPAR; - if (GlobalV::MY_POOL < rem) - { - ikstot = GlobalV::MY_POOL * nkp + GlobalV::MY_POOL + ik; - } - else - { - ikstot = GlobalV::MY_POOL * nkp + rem + ik; - } #else max_dim = npwk_max; npwtot = pw_wfc->npwk[ik]; - ikstot = ik; #endif - int npwtot_npol = npwtot * PARAM.globalv.npol; diff --git a/source/module_io/read_wfc_pw.h b/source/module_io/read_wfc_pw.h index e1630277bf..4952e307b2 100644 --- a/source/module_io/read_wfc_pw.h +++ b/source/module_io/read_wfc_pw.h @@ -15,12 +15,14 @@ namespace ModuleIO * @param filename filename containing wave functions * @param pw_wfc wave function FFT grids * @param ik k index + * @param ikstot total index of k points * @param nkstot total number of k points * @param wfc wave functions */ void read_wfc_pw(const std::string& filedir, const ModulePW::PW_Basis_K* pw_wfc, const int& ik, + const int& ikstot, const int& nkstot, ModuleBase::ComplexMatrix& wfc); } // namespace ModuleIO diff --git a/source/module_io/read_wfc_to_rho.cpp b/source/module_io/read_wfc_to_rho.cpp index 1a9d6c1237..6fee1bf9a7 100644 --- a/source/module_io/read_wfc_to_rho.cpp +++ b/source/module_io/read_wfc_to_rho.cpp @@ -9,6 +9,7 @@ void ModuleIO::read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc, ModuleSymmetry::Symmetry& symm, + const int* ik2iktot, const int nkstot, const std::vector& isk, Charge& chg) @@ -39,13 +40,29 @@ void ModuleIO::read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc, std::string filename = PARAM.globalv.global_readin_dir + "istate.info"; std::ifstream ifs(filename); std::string useless; - for (int ik_tot = 0; ik_tot < nkstot; ++ik_tot) + if (PARAM.inp.nspin == 2) { - ifs >> useless; - getline(ifs, useless); - for(int ib = 0; ib < nbands; ++ib) + const int nkstot_np = nkstot / 2; + for (int iktot_np = 0; iktot_np < nkstot_np; ++iktot_np) { - ifs >> useless >> useless >> wg_tmp(ik_tot, ib); + ifs >> useless; + getline(ifs, useless); + for (int ib = 0; ib < nbands; ++ib) + { + ifs >> useless >> useless >> wg_tmp(iktot_np, ib) >> useless >> wg_tmp(iktot_np + nkstot_np, ib); + } + } + } + else + { + for (int ik_tot = 0; ik_tot < nkstot; ++ik_tot) + { + ifs >> useless; + getline(ifs, useless); + for (int ib = 0; ib < nbands; ++ib) + { + ifs >> useless >> useless >> wg_tmp(ik_tot, ib); + } } } } @@ -54,20 +71,6 @@ void ModuleIO::read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc, MPI_Bcast(wg_tmp.c, nkstot * nbands, MPI_DOUBLE, 0, MPI_COMM_WORLD); #endif - auto get_ikstot = [&](int ik) { - int nkp = nkstot / kpar; - int rem = nkstot % kpar; - int ikstot; - if (my_pool < rem) - { - ikstot = my_pool * nkp + my_pool + ik; - } - else - { - ikstot = my_pool * nkp + rem + ik; - } - return ikstot; - }; for (int ik = 0; ik < pw_wfc->nks; ++ik) { int is = 0; @@ -75,10 +78,10 @@ void ModuleIO::read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc, { is = isk[ik]; } - const int ikstot = get_ikstot(ik); std::stringstream filename; + const int ikstot = ik2iktot[ik]; filename << PARAM.globalv.global_readin_dir << "WAVEFUNC" << ikstot + 1 << ".dat"; - ModuleIO::read_wfc_pw(filename.str(), pw_wfc, ik, nkstot, wfc_tmp); + ModuleIO::read_wfc_pw(filename.str(), pw_wfc, ik, ikstot, nkstot, wfc_tmp); if (PARAM.inp.nspin == 4) { std::vector> rho_tmp2(nrxx); diff --git a/source/module_io/read_wfc_to_rho.h b/source/module_io/read_wfc_to_rho.h index 3e8492d679..01ec266f36 100644 --- a/source/module_io/read_wfc_to_rho.h +++ b/source/module_io/read_wfc_to_rho.h @@ -19,6 +19,7 @@ namespace ModuleIO */ void read_wfc_to_rho(const ModulePW::PW_Basis_K* pw_wfc, ModuleSymmetry::Symmetry& symm, + const int* ik2iktot, const int nkstot, const std::vector& isk, Charge& chg); diff --git a/source/module_io/test/read_wfc_pw_test.cpp b/source/module_io/test/read_wfc_pw_test.cpp index 1a4830345d..ac13e8a020 100644 --- a/source/module_io/test/read_wfc_pw_test.cpp +++ b/source/module_io/test/read_wfc_pw_test.cpp @@ -55,7 +55,7 @@ TEST_F(ReadWfcPwTest, ReadWfcPw) PARAM.input.nbands = 8; const int nbasis = wfcpw->npwk[0]; ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); - ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom); + ModuleIO::read_wfc_pw(filename, wfcpw, 0, 0, nkstot, wfcatom); if (GlobalV::NPROC_IN_POOL == 1) { @@ -126,7 +126,7 @@ TEST_F(ReadWfcPwTest, NotFoundFile) // dat file std::string filename = "notfound.dat"; testing::internal::CaptureStdout(); - EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); std::string output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output,testing::HasSubstr("Can't open file notfound.dat")); @@ -134,14 +134,14 @@ TEST_F(ReadWfcPwTest, NotFoundFile) // txt file filename = "notfound.txt"; testing::internal::CaptureStdout(); - EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output,testing::HasSubstr("Can't open file notfound.txt")); // other file filename = "notfound"; testing::internal::CaptureStdout(); - EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output,testing::HasSubstr("Unknown file type und")); } @@ -166,7 +166,7 @@ TEST_F(ReadWfcPwTest, InconsistentBands) const int nbasis = wfcpw->npwk[0]; ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); testing::internal::CaptureStdout(); - EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); std::string output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("nbands_in = 8")); EXPECT_THAT(output, testing::HasSubstr("nbands = 4")); @@ -198,7 +198,7 @@ TEST_F(ReadWfcPwTest, InconsistentKvec) const int nbasis = wfcpw->npwk[0]; ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); testing::internal::CaptureStdout(); - EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); std::string output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("kvec_in[0] = 0 0 0")); EXPECT_THAT(output, testing::HasSubstr("kvec[0] = -1 1 -1")); @@ -226,7 +226,7 @@ TEST_F(ReadWfcPwTest, InconsistentLat0) const int nbasis = wfcpw->npwk[0]; ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); testing::internal::CaptureStdout(); - EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); std::string output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("lat0_in = 5.3233")); EXPECT_THAT(output, testing::HasSubstr("lat0 = 5")); @@ -254,7 +254,7 @@ TEST_F(ReadWfcPwTest, InconsistentG) const int nbasis = wfcpw->npwk[0]; ModuleBase::ComplexMatrix wfcatom(PARAM.input.nbands, nbasis); testing::internal::CaptureStdout(); - EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); + EXPECT_EXIT(ModuleIO::read_wfc_pw(filename, wfcpw, 0, 0, nkstot, wfcatom), ::testing::ExitedWithCode(1), ""); std::string output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("G_in[0] = -1 -1 1\nG_in[1] = 1 1 1\nG_in[2] = -1 1 -1\n")); EXPECT_THAT( diff --git a/source/module_io/test/read_wfc_to_rho_test.cpp b/source/module_io/test/read_wfc_to_rho_test.cpp index 74be35a20c..e4f93ad9be 100644 --- a/source/module_io/test/read_wfc_to_rho_test.cpp +++ b/source/module_io/test/read_wfc_to_rho_test.cpp @@ -229,7 +229,7 @@ TEST_F(ReadWfcRhoTest, ReadWfcRho) ModuleIO::write_wfc_pw("WAVEFUNC", *psi, *kv, wfcpw); // Read the wave functions to charge density - ModuleIO::read_wfc_to_rho(wfcpw, symm, nkstot, kv->isk, chg); + ModuleIO::read_wfc_to_rho(wfcpw, symm, kv->ik2iktot.data(), nkstot, kv->isk, chg); // compare the charge density for (int ir = 0; ir < rhopw->nrxx; ++ir) diff --git a/source/module_psi/psi_initializer_file.cpp b/source/module_psi/psi_initializer_file.cpp index ff65196f82..169772aa49 100644 --- a/source/module_psi/psi_initializer_file.cpp +++ b/source/module_psi/psi_initializer_file.cpp @@ -29,7 +29,7 @@ void psi_initializer_file::init_psig(T* psig, const int& ik) std::stringstream filename; int ik_tot = this->p_kv->ik2iktot[ik]; filename << PARAM.globalv.global_readin_dir << "WAVEFUNC" << ik_tot + 1 << ".dat"; - ModuleIO::read_wfc_pw(filename.str(), this->pw_wfc_, ik, nkstot, wfcatom); + ModuleIO::read_wfc_pw(filename.str(), this->pw_wfc_, ik, ik_tot, nkstot, wfcatom); assert(this->nbands_start_ <= wfcatom.nr); for (int ib = 0; ib < this->nbands_start_; ib++) From e591a7d1a48ad908bf7f7d88e6f3e9d39989da75 Mon Sep 17 00:00:00 2001 From: Qianruipku Date: Sun, 12 Jan 2025 20:12:15 +0800 Subject: [PATCH 4/6] add new integral test --- .../test/elecstate_print_test.cpp | 32 +++++++++++------- .../101_PW_upf201_uspp_Fe/result.ref | 8 ++--- tests/integrate/127_PW_15_PK_AF_wfcinit/INPUT | 28 +++++++++++++++ tests/integrate/127_PW_15_PK_AF_wfcinit/KPT | 4 +++ .../OUT.autotest/WAVEFUNC1.dat | Bin 0 -> 5236 bytes .../OUT.autotest/WAVEFUNC2.dat | Bin 0 -> 4032 bytes .../OUT.autotest/WAVEFUNC3.dat | Bin 0 -> 5236 bytes .../OUT.autotest/WAVEFUNC4.dat | Bin 0 -> 4032 bytes .../OUT.autotest/istate.info | 26 ++++++++++++++ .../integrate/127_PW_15_PK_AF_wfcinit/README | 7 ++++ tests/integrate/127_PW_15_PK_AF_wfcinit/STRU | 19 +++++++++++ .../127_PW_15_PK_AF_wfcinit/result.ref | 3 ++ tests/integrate/CASES_CPU.txt | 1 + 13 files changed, 111 insertions(+), 17 deletions(-) create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/INPUT create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/KPT create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC1.dat create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC2.dat create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC3.dat create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC4.dat create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/istate.info create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/README create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/STRU create mode 100644 tests/integrate/127_PW_15_PK_AF_wfcinit/result.ref diff --git a/source/module_elecstate/test/elecstate_print_test.cpp b/source/module_elecstate/test/elecstate_print_test.cpp index 644f037cc5..e05759f6ca 100644 --- a/source/module_elecstate/test/elecstate_print_test.cpp +++ b/source/module_elecstate/test/elecstate_print_test.cpp @@ -69,11 +69,15 @@ class ElecStatePrintTest : public ::testing::Test { p_klist = new K_Vectors; p_klist->set_nks(2); + p_klist->set_nkstot(2); p_klist->isk = {0, 1}; p_klist->ngk = {100, 101}; p_klist->kvec_c.resize(2); p_klist->kvec_c[0].set(0.1, 0.11, 0.111); p_klist->kvec_c[1].set(0.2, 0.22, 0.222); + p_klist->ik2iktot.resize(2); + p_klist->ik2iktot[0] = 0; + p_klist->ik2iktot[1] = 1; // initialize klist of elecstate elecstate.klist = p_klist; // initialize ekb of elecstate @@ -116,11 +120,11 @@ TEST_F(ElecStatePrintTest, PrintFormat) TEST_F(ElecStatePrintTest, PrintEigenvalueS2) { PARAM.input.nspin = 2; - GlobalV::ofs_running.open("test.dat", std::ios::out); + GlobalV::ofs_running.open("running_scf.log", std::ios::out); // print eigenvalue elecstate.print_eigenvalue(GlobalV::ofs_running); GlobalV::ofs_running.close(); - ifs.open("test.dat", std::ios::in); + ifs.open("running_scf.log", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_THAT(str, testing::HasSubstr("STATE ENERGY(eV) AND OCCUPATIONS")); EXPECT_THAT(str, testing::HasSubstr("NSPIN == 2")); @@ -133,17 +137,17 @@ TEST_F(ElecStatePrintTest, PrintEigenvalueS2) EXPECT_THAT(str, testing::HasSubstr("1 40.8171 0.300000")); EXPECT_THAT(str, testing::HasSubstr("2 54.4228 0.400000")); ifs.close(); - std::remove("test.dat"); + std::remove("running_scf.log"); } TEST_F(ElecStatePrintTest, PrintEigenvalueS4) { PARAM.input.nspin = 4; - GlobalV::ofs_running.open("test.dat", std::ios::out); + GlobalV::ofs_running.open("running_scf.log", std::ios::out); // print eigenvalue elecstate.print_eigenvalue(GlobalV::ofs_running); GlobalV::ofs_running.close(); - ifs.open("test.dat", std::ios::in); + ifs.open("running_scf.log", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_THAT(str, testing::HasSubstr("STATE ENERGY(eV) AND OCCUPATIONS")); EXPECT_THAT(str, testing::HasSubstr("NSPIN == 4")); @@ -154,7 +158,7 @@ TEST_F(ElecStatePrintTest, PrintEigenvalueS4) EXPECT_THAT(str, testing::HasSubstr("1 40.8171 0.300000")); EXPECT_THAT(str, testing::HasSubstr("2 54.4228 0.400000")); ifs.close(); - std::remove("test.dat"); + std::remove("running_scf.log"); } TEST_F(ElecStatePrintTest, PrintBand) @@ -162,43 +166,43 @@ TEST_F(ElecStatePrintTest, PrintBand) PARAM.input.nspin = 1; PARAM.input.nbands = 2; GlobalV::MY_RANK = 0; - GlobalV::ofs_running.open("test.dat", std::ios::out); + GlobalV::ofs_running.open("running_scf.log", std::ios::out); // print eigenvalue elecstate.print_band(0, 1, 0); GlobalV::ofs_running.close(); - ifs.open("test.dat", std::ios::in); + ifs.open("running_scf.log", std::ios::in); std::string str((std::istreambuf_iterator(ifs)), std::istreambuf_iterator()); EXPECT_THAT(str, testing::HasSubstr("Energy (eV) & Occupations for spin=1 K-point=1")); EXPECT_THAT(str, testing::HasSubstr("1 13.6057 0.100000")); EXPECT_THAT(str, testing::HasSubstr("2 27.2114 0.200000")); ifs.close(); - std::remove("test.dat"); + std::remove("running_scf.log"); } TEST_F(ElecStatePrintTest, PrintEigenvalueWarning) { elecstate.ekb(0, 0) = 1.0e11; PARAM.input.nspin = 4; - GlobalV::ofs_running.open("test.dat", std::ios::out); + GlobalV::ofs_running.open("running_scf.log", std::ios::out); testing::internal::CaptureStdout(); EXPECT_EXIT(elecstate.print_eigenvalue(GlobalV::ofs_running), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("Eigenvalues are too large!")); GlobalV::ofs_running.close(); - std::remove("test.dat"); + std::remove("running_scf.log"); } TEST_F(ElecStatePrintTest, PrintBandWarning) { elecstate.ekb(0, 0) = 1.0e11; PARAM.input.nspin = 4; - GlobalV::ofs_running.open("test.dat", std::ios::out); + GlobalV::ofs_running.open("running_scf.log", std::ios::out); testing::internal::CaptureStdout(); EXPECT_EXIT(elecstate.print_band(0, 1, 0), ::testing::ExitedWithCode(1), ""); output = testing::internal::GetCapturedStdout(); EXPECT_THAT(output, testing::HasSubstr("Eigenvalues are too large!")); GlobalV::ofs_running.close(); - std::remove("test.dat"); + std::remove("running_scf.log"); } TEST_F(ElecStatePrintTest, PrintEtot) @@ -342,6 +346,7 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS2) PARAM.input.nspin = 2; GlobalV::MY_RANK = 0; elecstate.print_etot(ucell.magnet,converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print); + delete elecstate.charge; } TEST_F(ElecStatePrintTest, PrintEtotColorS4) @@ -367,4 +372,5 @@ TEST_F(ElecStatePrintTest, PrintEtotColorS4) PARAM.input.noncolin = true; GlobalV::MY_RANK = 0; elecstate.print_etot(ucell.magnet,converged, iter, scf_thr, scf_thr_kin, duration, printe, pw_diag_thr, avg_iter, print); + delete elecstate.charge; } \ No newline at end of file diff --git a/tests/integrate/101_PW_upf201_uspp_Fe/result.ref b/tests/integrate/101_PW_upf201_uspp_Fe/result.ref index 0f6659ed9c..293616c602 100644 --- a/tests/integrate/101_PW_upf201_uspp_Fe/result.ref +++ b/tests/integrate/101_PW_upf201_uspp_Fe/result.ref @@ -1,5 +1,5 @@ -etotref -673.8349337888099626 -etotperatomref -673.8349337888 +etotref -673.8349306935572258 +etotperatomref -673.8349306936 totalforceref 0.000000 -totalstressref 66620.402512 -totaltimeref 0.75 +totalstressref 66620.323844 +totaltimeref 1.34 diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/INPUT b/tests/integrate/127_PW_15_PK_AF_wfcinit/INPUT new file mode 100644 index 0000000000..9da4604f8d --- /dev/null +++ b/tests/integrate/127_PW_15_PK_AF_wfcinit/INPUT @@ -0,0 +1,28 @@ +INPUT_PARAMETERS +suffix autotest + +nbands 10 + +calculation scf +ecutwfc 8 +scf_thr 1.0e-10 +scf_nmax 1 + +smearing_method gaussian +smearing_sigma 0.02 + +mixing_type broyden +mixing_beta 0.4 + +ks_solver cg +basis_type pw +symmetry 0 +nspin 2 +pseudo_dir ../../PP_ORB + +pw_seed 1 + +kpar 2 +# out_wfc_pw 2 +init_wfc file +init_chg wfc diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/KPT b/tests/integrate/127_PW_15_PK_AF_wfcinit/KPT new file mode 100644 index 0000000000..e769af7638 --- /dev/null +++ b/tests/integrate/127_PW_15_PK_AF_wfcinit/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +2 1 1 0 0 0 diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC1.dat b/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC1.dat new file mode 100644 index 0000000000000000000000000000000000000000..c9131db655c790bc876bfe781808d104fcad2972 GIT binary patch literal 5236 zcmai02{hGR*GE!Pi4=t>WN07>MQsTw^O#4-P$@$LqR~7LNrp&fZr3F)*F5cOcF8=4 z3ek*066wwNyjstC*0;WIuk~BMz4zJs{LeXioqhhQbaZs|zrpw$|F^sb-roW1{si$W z{H<~*yqyE$A(GP% z4F&aXYfg~RaG@w;kF_Vp9<$t4ERlgOcVcI9w|QX{O|DvBCKES=j|zU0_Cn(5wLnKw zK87XoyPTF~AYGxKabC1q^)&BhB&*pvkI ze$V$M)F<$8s~;LXZ&Nl->BBqLA}tqKb8-FcUR5SWBARnaUsTKRK0A z>TQh|772sms4WRw1mbfA+I>)O`l4PzK|U4~@BSouCJ0qt2McAH!jz7 z85kU5RQfI$G+bjojK0f&0Oc0j@aIHSx3@3rzmf~yXJZ;>9LunsY#6V2As)Oqj{l%* zDZ^B%%bQ(S6F|V4JGZl(fKP$aWs)O5TBH3x$}4!@JZah=$>X2s`d>8m8?7B zNkO^rez&SXXMQ$1Kcu5ZMrOmCkNyRMlQ}p-&(2J4Dg{f)gbJz1bbRKmZFkh|6?Pk(b4RsAPNTU-bb8>i$JDNuXoReCtzyBG5wjaJaBQ5aDR5X6zF(wTr+7V1B2>$ z364Z6Mle4fuR4=~!HjFIetO@4?_b{R=k;`gtvj^5e+W?FsPm#?;+G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R9|kugZ)wRZqGK|?kABj2)T0g5vyKz)k7k1ov-4BUzI!loHT9&|NFbimre0J} zj>qANOBz9JH(bj)+Ce*3i$NbrwP&J;xF<)bHQ`(b#9EYPoPJdVE$nK+AgfsTIi^SL z68D4&ojsj;f$?auJZ!bCS{MqxDpYf9?Ld)xha}Xd@6845`bwvvIA}B0A5WoqLvurq zr_W6e1U>1~%FN9Mxzuk-Un6Rff9(2m>)j-*%{Lz-sMVnRl3fEo%Zd!fJah?DHFO+V>+J XRy8!eQj?0qtczAtEDh^_&hvi&yVFjj literal 0 HcmV?d00001 diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC3.dat b/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC3.dat new file mode 100644 index 0000000000000000000000000000000000000000..42fd8b9b7038837935c7355f5a899db6ad42145e GIT binary patch literal 5236 zcmai12{@J8*HR+{2a^JL!6<*a>>=mrYKlN4npMC!w^Kbj#@vCF3@V{jxw-xzk%xWI1Z7c1o z`U1VZROm_oaZdBAVewQ@rnnsqkS0Jy zZ$AIL8U>E&aLzbn=*I>Z4KTTYLgJKM+z=IB$WBah9x;V(xruj*R+*5)UfZ5AX9b5o>u>Lh z%z#4|Nm+#<<`7)(>+|GP1_-|W-s8>t05WG(#@w9x!F|x~V7ajqNbSGH?MtA*{*qGt z(0%sseo_3WffyAG2+1PJUs8en+)(K$r!n9o7b|Yx=>p#O?|b+yP{Gh($0wNuI~cV; zd5|8G2hZ7^M0kq{@c7M+yJAsP*lqqtYK*Bptofwo^WZ!c-tFOG7K^usV8iLP-*!{L z&a`?gH`x~6R_t<;P|pKfxs*IlzDMvqQ&8E=r5}DPtqijM(-C^7I}Vw%WP;jgKmRz7 zE$DpllJw5WfLqqN-^yy7pl81#Sg~b65qZK>==C))eMd8pn<;?x*0c1%&P(7eFj3*A zl?5v`T|onTY_Ua>C8Wn+CwZSpht>xZsrn&q;Bi3kuJd>S%=$6aHEni+ym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m}!P&Dl5or1>>bXn@k7sKut%Y}oSnJ`pQ%d5Cp0Kr2F z0xCA`3!xoq8^$uh- z=oW8j?8o8Cw<^TQ!#G-gI*^Uz`m3(0qH_ydjL8_1CpEmwhYtJ#p|w%MRP?=`ed8gq zA7tC3Sq20%LDLk(nfE-yD{Mb=<(Pt?>f0@CrMhY?mbSC|^oR_X@=M&lRuVw>WQOvg zfk@cUMd_UFNyk$SYh$)PzKX=JG+I6BDLzVQzoKxD0{%?Q5ejeXQS&H=;k}v!d>M7- zBg;|`+N!F0UaH9lCZoq`?XSrgQ5tD2B9n=Hy>n}%ey;_N@|0B7Q43@tGd``=Ylj`= zv*GG<%%)uav`3Ov{{GHb(S1Lud_I=iN#fJtz={6bmGy zn4#C+Kb9InukCB+>B(>)rg;VswG#18k!M7!Wig74!w|>wLbTd%J=H>}z|fiQKkNw2 zpcLy;aYV)w7E6DAom74fT2vd>3E2o3tMbzwWADKmwfSK@#rL2nmOilVMlEirH0{j0 zOoJA2qooT$?6Ybq^%Me}%LW>q>cZ5$K61R%lj@${vmyLZw5wAkuSdI~#X_K*O_dIBYl>i7+xtq?ejK_|JRz Fe*iP#W^(`l literal 0 HcmV?d00001 diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC4.dat b/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/WAVEFUNC4.dat new file mode 100644 index 0000000000000000000000000000000000000000..109ba171efb3e65ad6bca2380318ecd3d197cb9b GIT binary patch literal 4032 zcmai1c{EjP8#hlWB5A;_WJtJOV@aM!Zn=?)%rd7)iPX)US>}08=s0vZ$2AKNDl*kM zD1T{ckw7Qdq^0HV;3Tj{lqgfB))Q9E?9^|Cjzr zR^wGL{R^wQR`ss(TD+S7xQ8FS7O#|l)>qeA8~1Ns9kbT{J#VeH%4?d|`qy;*n^!fi z=4-qbujZU9SkwEzcumjhoYl7Kh2;w7ec~T6Q?u|(^em&dMIqVDyXYF1U)n^Y{oUbi!CPs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rBSHv70@*~JvB5D8l{2vi$DFOfh literal 0 HcmV?d00001 diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/istate.info b/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/istate.info new file mode 100644 index 0000000000..c81d6811cf --- /dev/null +++ b/tests/integrate/127_PW_15_PK_AF_wfcinit/OUT.autotest/istate.info @@ -0,0 +1,26 @@ +BAND Spin up Energy(ev) Occupation Spin down Energy(ev) Occupation Kpoint = 1 (0 0 0) + 1 -34.6013 0.5 -33.7761 0.5 + 2 -2.58855 0.5 -2.08974 0.5 + 3 1.86986 0.5 2.7984 0.5 + 4 1.91195 0.5 2.79982 0.5 + 5 23.9461 0.5 24.2851 0.5 + 6 42.8714 0.5 43.4213 0.5 + 7 42.892 0.5 43.4713 0.5 + 8 47.1737 0.5 47.5816 0.5 + 9 55.927 0 56.4901 0 + 10 57.1475 0 59.2227 0 + + +BAND Spin up Energy(ev) Occupation Spin down Energy(ev) Occupation Kpoint = 2 (0.5 0 0) + 1 -13.2966 0.5 -12.4566 0.5 + 2 -4.22422 0.5 -3.61022 0.5 + 3 5.20853 0.5 5.15653 0.5 + 4 4.99881 0.5 6.43699 0.5 + 5 29.4915 0.5 29.8951 0.5 + 6 34.7709 0.5 35.236 0.5 + 7 38.1075 0.5 38.4163 0.5 + 8 47.7803 0.5 48.3026 0.5 + 9 51.2238 6.10623e-15 51.6084 0 + 10 53.4218 0 53.7871 0 + + diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/README b/tests/integrate/127_PW_15_PK_AF_wfcinit/README new file mode 100644 index 0000000000..21b02c2e09 --- /dev/null +++ b/tests/integrate/127_PW_15_PK_AF_wfcinit/README @@ -0,0 +1,7 @@ +Fe Antiferromagnetic +NSPIN 2 +pw +init magnet: up + down +SG15 +init_wfc file +init_chg wfc diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/STRU b/tests/integrate/127_PW_15_PK_AF_wfcinit/STRU new file mode 100644 index 0000000000..f7e6647962 --- /dev/null +++ b/tests/integrate/127_PW_15_PK_AF_wfcinit/STRU @@ -0,0 +1,19 @@ +ATOMIC_SPECIES +Fe 1.000 Fe_ONCV_PBE-1.0.upf + +LATTICE_CONSTANT +5 + +LATTICE_VECTORS + 1.00 0.50 0.50 + 0.50 1.00 0.50 + 0.50 0.50 1.00 +ATOMIC_POSITIONS +Direct + +Fe +1.0 +1 +0.00 0.00 0.00 1 1 1 + + diff --git a/tests/integrate/127_PW_15_PK_AF_wfcinit/result.ref b/tests/integrate/127_PW_15_PK_AF_wfcinit/result.ref new file mode 100644 index 0000000000..16d4ecfa7d --- /dev/null +++ b/tests/integrate/127_PW_15_PK_AF_wfcinit/result.ref @@ -0,0 +1,3 @@ +etotref -2511.209813664946 +etotperatomref -2511.2098136649 +totaltimeref 0.07 diff --git a/tests/integrate/CASES_CPU.txt b/tests/integrate/CASES_CPU.txt index 9dbfc1a6b1..db834ee8e0 100644 --- a/tests/integrate/CASES_CPU.txt +++ b/tests/integrate/CASES_CPU.txt @@ -100,6 +100,7 @@ 121_PW_KPAR 121_PW_kspacing 127_PW_15_PK_AF +127_PW_15_PK_AF_wfcinit 123_PW_zero_atom 128_PW_zero_ntype 133_PW_DJ_PK From 580eaab45e6e8fa4e62a86930b45f5085a732a77 Mon Sep 17 00:00:00 2001 From: Qianruipku Date: Mon, 13 Jan 2025 15:25:15 +0800 Subject: [PATCH 5/6] format read_wfc_to_rho_test --- source/module_io/test/read_wfc_to_rho_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100644 => 100755 source/module_io/test/read_wfc_to_rho_test.cpp diff --git a/source/module_io/test/read_wfc_to_rho_test.cpp b/source/module_io/test/read_wfc_to_rho_test.cpp old mode 100644 new mode 100755 index e4f93ad9be..f964fb95d2 --- a/source/module_io/test/read_wfc_to_rho_test.cpp +++ b/source/module_io/test/read_wfc_to_rho_test.cpp @@ -69,9 +69,9 @@ void Symmetry_rho::begin(const int& spin_now, return; } -void cal_ik2iktot(std::vector&ik2iktot, const int& nks, const int& nkstot) +void cal_ik2iktot(std::vector& ik2iktot, const int& nks, const int& nkstot) { - for(int ik = 0; ik < nks; ++ik) + for (int ik = 0; ik < nks; ++ik) { int nkp = nkstot / PARAM.inp.kpar; int rem = nkstot % PARAM.inp.kpar; From fe33a2d59fd6907418783ea02ae1e0caf27c28f2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci-lite[bot]" <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Date: Mon, 13 Jan 2025 09:47:39 +0000 Subject: [PATCH 6/6] [pre-commit.ci lite] apply automatic fixes --- source/module_io/test/read_wfc_to_rho_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 source/module_io/test/read_wfc_to_rho_test.cpp diff --git a/source/module_io/test/read_wfc_to_rho_test.cpp b/source/module_io/test/read_wfc_to_rho_test.cpp old mode 100755 new mode 100644 index f964fb95d2..6d64b90dd4 --- a/source/module_io/test/read_wfc_to_rho_test.cpp +++ b/source/module_io/test/read_wfc_to_rho_test.cpp @@ -238,9 +238,9 @@ TEST_F(ReadWfcRhoTest, ReadWfcRho) } // std::cout.precision(16); // std::cout< ref = {8207.849135313403, 35.34776105132742, 8207.849135313403, 35.34776105132742}; EXPECT_NEAR(chg.rho[0][0], ref[GlobalV::MY_RANK], 1e-8);