forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 153
Fix energy jumps occur in rt-TDDFT calculations #6779
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| #include "boundary_fix.h" | ||
| #include "source_base/libm/libm.h" | ||
| #include "source_base/constants.h" | ||
| #include "source_base/vector3.h" | ||
|
|
||
| namespace module_rt{ | ||
|
|
||
| void reset_matrix_boundary(const UnitCell& ucell, | ||
| const K_Vectors& kv, | ||
| const Parallel_Orbitals* pv, | ||
| ct::Tensor& hk_last, | ||
| ct::Tensor& sk_last, | ||
| psi::Psi<std::complex<double>>* psi_last, | ||
| const size_t len_hs) | ||
| { | ||
mohanchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ModuleBase::TITLE("module_rt", "reset_matrix_boundary"); | ||
| ModuleBase::timer::tick("module_rt", "reset_matrix_boundary"); | ||
| const ModuleBase::Vector3<int> zero = {0, 0, 0}; | ||
| for(size_t iat = 0; iat < ucell.nat; iat++) | ||
| { | ||
| const size_t it = ucell.iat2it[iat]; | ||
| const size_t ia = ucell.iat2ia[iat]; | ||
| if(ucell.atoms[it].boundary_shift[ia]!=zero) | ||
| { | ||
| const auto& rshift = ucell.atoms[it].boundary_shift[ia]; | ||
| #ifdef _OPENMP | ||
| #pragma omp parallel for schedule(dynamic) | ||
| #endif | ||
| for(int ik = 0; ik < kv.get_nks(); ik++) | ||
| { | ||
| const ModuleBase::Vector3<double> tmp_rshift(rshift.x, rshift.y, rshift.z); | ||
| const double arg = -kv.kvec_d[ik] * tmp_rshift * ModuleBase::TWO_PI; | ||
| //skip unrelevent ik | ||
| if(arg==0)continue; | ||
| //calculate correction phase | ||
| double sinp, cosp; | ||
| ModuleBase::libm::sincos(arg, &sinp, &cosp); | ||
| const std::complex<double> phase = std::complex<double>(cosp, sinp); | ||
| //phase correction for Hamiltionian, overlap matrix and c vec. | ||
| module_rt::boundary_shift_mat(phase, hk_last.template data<std::complex<double>>() + ik * len_hs, pv, iat); | ||
| module_rt::boundary_shift_mat(phase, sk_last.template data<std::complex<double>>() + ik * len_hs, pv, iat); | ||
| psi_last->fix_k(ik); | ||
| module_rt::boundary_shift_c(phase, psi_last[0].get_pointer(), pv, iat); | ||
| } | ||
| } | ||
| } | ||
| ModuleBase::timer::tick("module_rt", "reset_matrix_boundary"); | ||
| return; | ||
| } | ||
|
|
||
| void boundary_shift_mat(const std::complex<double>& phase, | ||
| std::complex<double>* matk, | ||
| const Parallel_Orbitals* pv, | ||
| const size_t iat) | ||
| { | ||
| const std::complex<double> phase_conj = std::conj(phase); | ||
| size_t row0 = pv->atom_begin_row[iat]; | ||
| size_t col0 = pv->atom_begin_col[iat]; | ||
| std::complex<double>* p_matkc = matk + col0 * pv->get_row_size(); | ||
| for(size_t nu = 0; nu < pv->get_col_size(iat); ++nu) | ||
| { | ||
|
|
||
| BlasConnector::scal(pv->get_row_size(), | ||
| phase, | ||
| p_matkc, | ||
| 1); | ||
| p_matkc += pv->get_row_size(); | ||
| } | ||
| std::complex<double>* p_matkr = matk + row0; | ||
| for(size_t mu = 0; mu < pv->get_row_size(iat); ++mu) | ||
| { | ||
| BlasConnector::scal(pv->get_col_size(), | ||
| phase_conj, | ||
| p_matkr, | ||
| pv->get_row_size()); | ||
| p_matkr += 1; | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| void boundary_shift_c(const std::complex<double>& phase, | ||
| std::complex<double>* psi_k_last, | ||
| const Parallel_Orbitals* pv, | ||
| const size_t iat) | ||
| { | ||
| const std::complex<double> phase_conj = std::conj(phase); | ||
| size_t row0 = pv->atom_begin_row[iat]; | ||
| std::complex<double>* p_ck = psi_k_last + row0; | ||
| for(size_t nu = 0; nu < pv->get_row_size(iat); ++nu) | ||
| { | ||
| BlasConnector::scal(pv->ncol_bands, | ||
| phase_conj, | ||
| p_ck, | ||
| pv->get_row_size()); | ||
| p_ck+=1; | ||
| } | ||
| return; | ||
| } | ||
| } //namespace module_rt | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * @file boundary_fix.h | ||
| * @brief Correct the discontinuity that occurs when crossing periodic boundary conditions | ||
| */ | ||
| #ifndef BOUNDARY_FIX_H | ||
| #define BOUNDARY_FIX_H | ||
|
|
||
| #include "source_cell/unitcell.h" | ||
| #include "source_cell/klist.h" | ||
| #include "source_basis/module_ao/parallel_orbitals.h" | ||
| #include "source_psi/psi.h" | ||
| #include "source_base/module_container/ATen/core/tensor.h" | ||
| namespace module_rt{ | ||
|
|
||
| /** | ||
| * @brief Add phases to the matrix and coefficient from the previous step to correct the boundary discontinuity. | ||
| * | ||
| * @param[in] ucell Unitcell information | ||
| * @param[in] kv K-point vectors | ||
| * @param[in] pv information of parallel | ||
| * @param[in] hk_last Hamiltonian matrix from last step | ||
| * @param[in] sk_last Overlap matrix from last step | ||
| * @param[in] psi_last Wavefunctions from last step | ||
| * @param[in] len_hs size of matrix element in this processor | ||
| * @param[out] hk_last the fixed hk matrix | ||
| * @param[out] sk_last the fixed sk matrix | ||
| * @param[out] sk_last the fixed wavefunctions | ||
| */ | ||
| void reset_matrix_boundary(const UnitCell& ucell, | ||
| const K_Vectors& kv, | ||
| const Parallel_Orbitals* pv, | ||
| ct::Tensor& hk_last, | ||
| ct::Tensor& sk_last, | ||
| psi::Psi<std::complex<double>>* psi_last, | ||
| const size_t len_hs); | ||
|
|
||
| /** | ||
| * @brief Add extra phase to the matrix element belong to iat | ||
| * | ||
| * @param[in] phase extra phase | ||
| * @param[in] matk the matrix need to be fixed | ||
| * @param[in] pv information of parallel | ||
| * @param[in] iat atom index | ||
| * @param[out] matk the fixed matrix | ||
| */ | ||
| void boundary_shift_mat(const std::complex<double>& phase, | ||
| std::complex<double>* matk, | ||
| const Parallel_Orbitals* pv, | ||
| const size_t iat); | ||
| /** | ||
| * @brief Add extra phase to the wfc coefficient belong to iat | ||
| * | ||
| * @param[in] phase extra phase | ||
| * @param[in] psi_k_last psi of last step | ||
| * @param[in] pv information of parallel | ||
| * @param[in] iat atom index | ||
| * @param[out] psi_k_last fixed psi of last step | ||
| */ | ||
| void boundary_shift_c(const std::complex<double>& phase, | ||
| std::complex<double>* psi_k_last, | ||
| const Parallel_Orbitals* pv, | ||
| const size_t iat); | ||
| }// namespace module_rt | ||
| #endif // BOUNDARY_FIX_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.