From 3758eb379b78ccd1a4e7f6e12d7f281c7c985689 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 25 Aug 2026 07:49:23 +0800 Subject: [PATCH 1/6] refactor(dftu): rename member locale/locale_save -> occ_mat/occ_mat_save (Step 1/5) - Rename Plus_U_Base data members: locale -> occ_mat, locale_save -> occ_mat_save - Update all direct member access sites in: * dftu_base.h inline get_locale/set_locale bodies and doc examples * dftu_base.cpp (init allocation, copy/zero/mix/set internal, flat conv, read_occup_m, local_occup_bcast MPI, Memory::record tag) * dftu_pw.cpp (cal_occ_pw: becp accumulation, k-pool reduce, VU & energy) * dftu.cpp (cal_energy_correction trace & double-counting terms) * dftu_occup.cpp (LCAO cal_occup_m_k/_gamma S*DM accumulation, MPI Allreduce, symmetrization via transpose) * dftu_tools.cpp (get_onebody_eff_pot new/saved branches) * test_dftu.cpp (setup resize/create, EXPECT assertions on values) - Public API names (get_locale, set_locale, copy_locale, zero_locale, mix_locale, set_locale_flat, is_locale_initialized, etc.) are kept unchanged in this step to keep the change surface minimal. 7 files changed, 133 insertions(+), 133 deletions(-). --- source/source_lcao/module_dftu/dftu.cpp | 16 +-- source/source_lcao/module_dftu/dftu_occup.cpp | 42 ++++---- source/source_lcao/module_dftu/dftu_tools.cpp | 16 +-- .../module_operator_lcao/test/test_dftu.cpp | 18 ++-- source/source_pw/module_pwdft/dftu_base.cpp | 98 +++++++++---------- source/source_pw/module_pwdft/dftu_base.h | 18 ++-- source/source_pw/module_pwdft/dftu_pw.cpp | 58 +++++------ 7 files changed, 133 insertions(+), 133 deletions(-) diff --git a/source/source_lcao/module_dftu/dftu.cpp b/source/source_lcao/module_dftu/dftu.cpp index ca77a04c611..10ac681f9b0 100644 --- a/source/source_lcao/module_dftu/dftu.cpp +++ b/source/source_lcao/module_dftu/dftu.cpp @@ -158,11 +158,11 @@ void Plus_U::cal_energy_correction(const UnitCell& ucell, for (int m0 = 0; m0 < 2 * l + 1; m0++) { - nm_trace += this->locale[iat][l][n][spin](m0, m0); + nm_trace += this->occ_mat[iat][l][n][spin](m0, m0); for (int m1 = 0; m1 < 2 * l + 1; m1++) { - nm2_trace += this->locale[iat][l][n][spin](m0, m1) - * this->locale[iat][l][n][spin](m1, m0); + nm2_trace += this->occ_mat[iat][l][n][spin](m0, m1) + * this->occ_mat[iat][l][n][spin](m1, m0); } } if (Yukawa) @@ -186,7 +186,7 @@ void Plus_U::cal_energy_correction(const UnitCell& ucell, for (int ipol0 = 0; ipol0 < this->npol; ipol0++) { const int m0_all = m0 + (2 * l + 1) * ipol0; - nm_trace += this->locale[iat][l][n][0](m0_all, m0_all); + nm_trace += this->occ_mat[iat][l][n][0](m0_all, m0_all); for (int m1 = 0; m1 < 2 * l + 1; m1++) { @@ -194,8 +194,8 @@ void Plus_U::cal_energy_correction(const UnitCell& ucell, { int m1_all = m1 + (2 * l + 1) * ipol1; - nm2_trace += this->locale[iat][l][n][0](m0_all, m1_all) - * this->locale[iat][l][n][0](m1_all, m0_all); + nm2_trace += this->occ_mat[iat][l][n][0](m0_all, m1_all) + * this->occ_mat[iat][l][n][0](m1_all, m0_all); } } } @@ -228,14 +228,14 @@ void Plus_U::cal_energy_correction(const UnitCell& ucell, { double VU = 0.0; VU = get_onebody_eff_pot(T, iat, l, n, is, m1_all, m2_all, false); - energy_dc += VU * this->locale[iat][l][n][is](m1_all, m2_all); + energy_dc += VU * this->occ_mat[iat][l][n][is](m1_all, m2_all); } } else if (Plus_U::nspin == 4) { double VU = 0.0; VU = get_onebody_eff_pot(T, iat, l, n, 0, m1_all, m2_all, false); - energy_dc += VU * this->locale[iat][l][n][0](m1_all, m2_all); + energy_dc += VU * this->occ_mat[iat][l][n][0](m1_all, m2_all); } } } diff --git a/source/source_lcao/module_dftu/dftu_occup.cpp b/source/source_lcao/module_dftu/dftu_occup.cpp index e0ccfd9e0df..de15b12a215 100644 --- a/source/source_lcao/module_dftu/dftu_occup.cpp +++ b/source/source_lcao/module_dftu/dftu_occup.cpp @@ -129,12 +129,12 @@ void Plus_U::cal_occup_m_k(const int iter, if ((nu >= 0) && (mu >= 0)) { - locale[iat][l][n][spin](m0_all, m1_all) += (srho[irc]).real() / 4.0; + occ_mat[iat][l][n][spin](m0_all, m1_all) += (srho[irc]).real() / 4.0; } if ((nu_prime >= 0) && (mu_prime >= 0)) { - locale[iat][l][n][spin](m0_all, m1_all) + occ_mat[iat][l][n][spin](m0_all, m1_all) += (std::conj(srho[irc_prime])).real() / 4.0; } } // ipol1 @@ -182,9 +182,9 @@ void Plus_U::cal_occup_m_k(const int iter, #ifdef __MPI if (Plus_U::nspin == 1 || Plus_U::nspin == 4) { - ModuleBase::matrix temp(locale[iat][l][n][0]); + ModuleBase::matrix temp(occ_mat[iat][l][n][0]); MPI_Allreduce(&temp(0, 0), - &locale[iat][l][n][0](0, 0), + &occ_mat[iat][l][n][0](0, 0), (2 * l + 1) * this->npol * (2 * l + 1) * this->npol, MPI_DOUBLE, MPI_SUM, @@ -192,17 +192,17 @@ void Plus_U::cal_occup_m_k(const int iter, } else if (Plus_U::nspin == 2) { - ModuleBase::matrix temp0(locale[iat][l][n][0]); + ModuleBase::matrix temp0(occ_mat[iat][l][n][0]); MPI_Allreduce(&temp0(0, 0), - &locale[iat][l][n][0](0, 0), + &occ_mat[iat][l][n][0](0, 0), (2 * l + 1) * (2 * l + 1), MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD); - ModuleBase::matrix temp1(locale[iat][l][n][1]); + ModuleBase::matrix temp1(occ_mat[iat][l][n][1]); MPI_Allreduce(&temp1(0, 0), - &locale[iat][l][n][1](0, 0), + &occ_mat[iat][l][n][1](0, 0), (2 * l + 1) * (2 * l + 1), MPI_DOUBLE, MPI_SUM, @@ -213,18 +213,18 @@ void Plus_U::cal_occup_m_k(const int iter, switch (Plus_U::nspin) { case 1: - locale[iat][l][n][0] += transpose(locale[iat][l][n][0]); - locale[iat][l][n][0] *= 0.5; - locale[iat][l][n][1] += locale[iat][l][n][0]; + occ_mat[iat][l][n][0] += transpose(occ_mat[iat][l][n][0]); + occ_mat[iat][l][n][0] *= 0.5; + occ_mat[iat][l][n][1] += occ_mat[iat][l][n][0]; break; case 2: for (int is = 0; is < Plus_U::nspin; is++) - locale[iat][l][n][is] += transpose(locale[iat][l][n][is]); + occ_mat[iat][l][n][is] += transpose(occ_mat[iat][l][n][is]); break; case 4: - locale[iat][l][n][0] += transpose(locale[iat][l][n][0]); + occ_mat[iat][l][n][0] += transpose(occ_mat[iat][l][n][0]); break; default: @@ -343,7 +343,7 @@ void Plus_U::cal_occup_m_gamma(const int iter, int m0_all = m0 + (2 * l + 1) * ipol0; int m1_all = m0 + (2 * l + 1) * ipol1; - locale[iat][l][n][is](m0, m1) += srho[irc] / 4.0; + occ_mat[iat][l][n][is](m0, m1) += srho[irc] / 4.0; } if ((nu_prime >= 0) && (mu_prime >= 0)) @@ -351,18 +351,18 @@ void Plus_U::cal_occup_m_gamma(const int iter, int m0_all = m0 + (2 * l + 1) * ipol0; int m1_all = m0 + (2 * l + 1) * ipol1; - locale[iat][l][n][is](m0, m1) += srho[irc_prime] / 4.0; + occ_mat[iat][l][n][is](m0, m1) += srho[irc_prime] / 4.0; } } } } } - ModuleBase::matrix temp(locale[iat][l][n][is]); + ModuleBase::matrix temp(occ_mat[iat][l][n][is]); #ifdef __MPI MPI_Allreduce(&temp(0, 0), - &locale[iat][l][n][is](0, 0), + &occ_mat[iat][l][n][is](0, 0), (2 * l + 1) * this->npol * (2 * l + 1) * this->npol, MPI_DOUBLE, MPI_SUM, @@ -373,13 +373,13 @@ void Plus_U::cal_occup_m_gamma(const int iter, switch (Plus_U::nspin) { case 1: - locale[iat][l][n][0] += transpose(locale[iat][l][n][0]); - locale[iat][l][n][0] *= 0.5; - locale[iat][l][n][1] += locale[iat][l][n][0]; + occ_mat[iat][l][n][0] += transpose(occ_mat[iat][l][n][0]); + occ_mat[iat][l][n][0] *= 0.5; + occ_mat[iat][l][n][1] += occ_mat[iat][l][n][0]; break; case 2: - locale[iat][l][n][is] += transpose(locale[iat][l][n][is]); + occ_mat[iat][l][n][is] += transpose(occ_mat[iat][l][n][is]); break; default: diff --git a/source/source_lcao/module_dftu/dftu_tools.cpp b/source/source_lcao/module_dftu/dftu_tools.cpp index d66a4b2d9a5..6c43581d661 100644 --- a/source/source_lcao/module_dftu/dftu_tools.cpp +++ b/source/source_lcao/module_dftu/dftu_tools.cpp @@ -163,17 +163,17 @@ double Plus_U::get_onebody_eff_pot(const int T, if (m0 == m1) { VU = (this->U_Yukawa[T][L][N] - this->J_Yukawa[T][L][N]) - * (0.5 - this->locale[iat][L][N][spin](m0, m1)); + * (0.5 - this->occ_mat[iat][L][N][spin](m0, m1)); } else { - VU = -(this->U_Yukawa[T][L][N] - this->J_Yukawa[T][L][N]) * this->locale[iat][L][N][spin](m0, m1); + VU = -(this->U_Yukawa[T][L][N] - this->J_Yukawa[T][L][N]) * this->occ_mat[iat][L][N][spin](m0, m1); } } else { if (m0 == m1) { - VU = (this->U[T]) * (0.5 - this->locale[iat][L][N][spin](m0, m1)); + VU = (this->U[T]) * (0.5 - this->occ_mat[iat][L][N][spin](m0, m1)); } else { - VU = -(this->U[T]) * this->locale[iat][L][N][spin](m0, m1); + VU = -(this->U[T]) * this->occ_mat[iat][L][N][spin](m0, m1); } } } @@ -183,18 +183,18 @@ double Plus_U::get_onebody_eff_pot(const int T, { if (m0 == m1) { VU = (this->U_Yukawa[T][L][N] - this->J_Yukawa[T][L][N]) - * (0.5 - this->locale_save[iat][L][N][spin](m0, m1)); + * (0.5 - this->occ_mat_save[iat][L][N][spin](m0, m1)); } else { VU = -(this->U_Yukawa[T][L][N] - this->J_Yukawa[T][L][N]) - * this->locale_save[iat][L][N][spin](m0, m1); + * this->occ_mat_save[iat][L][N][spin](m0, m1); } } else { if (m0 == m1) { - VU = (this->U[T]) * (0.5 - this->locale_save[iat][L][N][spin](m0, m1)); + VU = (this->U[T]) * (0.5 - this->occ_mat_save[iat][L][N][spin](m0, m1)); } else { - VU = -(this->U[T]) * this->locale_save[iat][L][N][spin](m0, m1); + VU = -(this->U[T]) * this->occ_mat_save[iat][L][N][spin](m0, m1); } } } diff --git a/source/source_lcao/module_operator_lcao/test/test_dftu.cpp b/source/source_lcao/module_operator_lcao/test/test_dftu.cpp index 0e371b084ea..090a3998243 100644 --- a/source/source_lcao/module_operator_lcao/test/test_dftu.cpp +++ b/source/source_lcao/module_operator_lcao/test/test_dftu.cpp @@ -85,16 +85,16 @@ class DFTUTest : public ::testing::Test tmp_DMR = DMR; // setting of DFTU - dftu.locale.resize(test_size); + dftu.occ_mat.resize(test_size); for (int iat = 0; iat < test_size; iat++) { - dftu.locale[iat].resize(3); + dftu.occ_mat[iat].resize(3); for (int l = 0; l < 3; l++) { - dftu.locale[iat][l].resize(1); - dftu.locale[iat][l][0].resize(2); - dftu.locale[iat][l][0][0].create(2 * l + 1, 2 * l + 1); - dftu.locale[iat][l][0][1].create(2 * l + 1, 2 * l + 1); + dftu.occ_mat[iat][l].resize(1); + dftu.occ_mat[iat][l][0].resize(2); + dftu.occ_mat[iat][l][0][0].create(2 * l + 1, 2 * l + 1); + dftu.occ_mat[iat][l][0][1].create(2 * l + 1, 2 * l + 1); } } Plus_U::U = {U_test}; @@ -172,7 +172,7 @@ TEST_F(DFTUTest, constructHRd2d) { for (int icc = 0; icc < 25; icc++) { - EXPECT_NEAR(dftu.locale[iat][2][0][0].c[icc], 0.5, 1e-10); + EXPECT_NEAR(dftu.occ_mat[iat][2][0][0].c[icc], 0.5, 1e-10); } } // check the value of HR @@ -230,7 +230,7 @@ TEST_F(DFTUTest, constructHRd2cd) { for (int icc = 0; icc < 25; icc++) { - EXPECT_NEAR(dftu.locale[iat][2][0][0].c[icc], 0.5, 1e-10); + EXPECT_NEAR(dftu.occ_mat[iat][2][0][0].c[icc], 0.5, 1e-10); } } // check the value of HR @@ -263,7 +263,7 @@ TEST_F(DFTUTest, constructHRd2cd) { for (int icc = 0; icc < 25; icc++) { - EXPECT_NEAR(dftu.locale[iat][2][0][1].c[icc], 0.5, 1e-10); + EXPECT_NEAR(dftu.occ_mat[iat][2][0][1].c[icc], 0.5, 1e-10); } } } diff --git a/source/source_pw/module_pwdft/dftu_base.cpp b/source/source_pw/module_pwdft/dftu_base.cpp index 15cb2f7e683..5cefdceb1f9 100644 --- a/source/source_pw/module_pwdft/dftu_base.cpp +++ b/source/source_pw/module_pwdft/dftu_base.cpp @@ -91,8 +91,8 @@ void Plus_U_Base::init_base(UnitCell& cell, Plus_U_Base::energy_u = 0.0; - this->locale.resize(cell.nat); - this->locale_save.resize(cell.nat); + this->occ_mat.resize(cell.nat); + this->occ_mat_save.resize(cell.nat); this->eff_pot_pw_index.resize(cell.nat); int pot_index = 0; @@ -105,8 +105,8 @@ void Plus_U_Base::init_base(UnitCell& cell, { const int iat = cell.itia2iat(it, ia); - locale[iat].resize(cell.atoms[it].nwl + 1); - locale_save[iat].resize(cell.atoms[it].nwl + 1); + occ_mat[iat].resize(cell.atoms[it].nwl + 1); + occ_mat_save[iat].resize(cell.atoms[it].nwl + 1); this->iatlnmipol2iwt[iat].resize(cell.atoms[it].nwl + 1); @@ -133,30 +133,30 @@ void Plus_U_Base::init_base(UnitCell& cell, { const int N = cell.atoms[it].l_nchi[l]; - locale[iat][l].resize(N); - locale_save[iat][l].resize(N); + occ_mat[iat][l].resize(N); + occ_mat_save[iat][l].resize(N); for (int n = 0; n < N; n++) { if (nspin == 1 || nspin == 2) { - locale[iat][l][n].resize(2); - locale_save[iat][l][n].resize(2); + occ_mat[iat][l][n].resize(2); + occ_mat_save[iat][l][n].resize(2); - locale[iat][l][n][0].create(2 * l + 1, 2 * l + 1); - locale[iat][l][n][1].create(2 * l + 1, 2 * l + 1); + occ_mat[iat][l][n][0].create(2 * l + 1, 2 * l + 1); + occ_mat[iat][l][n][1].create(2 * l + 1, 2 * l + 1); - locale_save[iat][l][n][0].create(2 * l + 1, 2 * l + 1); - locale_save[iat][l][n][1].create(2 * l + 1, 2 * l + 1); + occ_mat_save[iat][l][n][0].create(2 * l + 1, 2 * l + 1); + occ_mat_save[iat][l][n][1].create(2 * l + 1, 2 * l + 1); num_locale += (2 * l + 1) * (2 * l + 1) * 2; } else if (nspin == 4) { - locale[iat][l][n].resize(1); - locale_save[iat][l][n].resize(1); + occ_mat[iat][l][n].resize(1); + occ_mat_save[iat][l][n].resize(1); - locale[iat][l][n][0].create((2 * l + 1) * npol, (2 * l + 1) * npol); - locale_save[iat][l][n][0].create((2 * l + 1) * npol, (2 * l + 1) * npol); + occ_mat[iat][l][n][0].create((2 * l + 1) * npol, (2 * l + 1) * npol); + occ_mat_save[iat][l][n][0].create((2 * l + 1) * npol, (2 * l + 1) * npol); num_locale += (2 * l + 1) * (2 * l + 1) * npol * npol; } } @@ -259,7 +259,7 @@ void Plus_U_Base::init_base(UnitCell& cell, } } - ModuleBase::Memory::record("Plus_U_Base::locale", sizeof(double) * num_locale); + ModuleBase::Memory::record("Plus_U_Base::occ_mat", sizeof(double) * num_locale); return; } @@ -306,7 +306,7 @@ bool Plus_U_Base::u_converged() } -// copy_locale — save current locale to locale_save and uom_save +// copy_locale — save current occ_mat to occ_mat_save and uom_save void Plus_U_Base::copy_locale(const UnitCell& ucell) { ModuleBase::TITLE("Plus_U_Base", "copy_locale"); @@ -324,28 +324,28 @@ void Plus_U_Base::copy_locale(const UnitCell& ucell) if (Plus_U_Base::nspin == 4) { - locale_save[iat][target_l][0][0] = locale[iat][target_l][0][0]; + occ_mat_save[iat][target_l][0][0] = occ_mat[iat][target_l][0][0]; if(this->uom_save.size() != 0) { - const int size = locale[iat][target_l][0][0].nr * locale[iat][target_l][0][0].nc; + const int size = occ_mat[iat][target_l][0][0].nr * occ_mat[iat][target_l][0][0].nc; for(int mm=0; mmuom_save[eff_pot_pw_index[iat]+mm] = locale[iat][target_l][0][0].c[mm]; + this->uom_save[eff_pot_pw_index[iat]+mm] = occ_mat[iat][target_l][0][0].c[mm]; } } } else if (Plus_U_Base::nspin == 1 || Plus_U_Base::nspin == 2) { - locale_save[iat][target_l][0][0] = locale[iat][target_l][0][0]; - locale_save[iat][target_l][0][1] = locale[iat][target_l][0][1]; + occ_mat_save[iat][target_l][0][0] = occ_mat[iat][target_l][0][0]; + occ_mat_save[iat][target_l][0][1] = occ_mat[iat][target_l][0][1]; if(this->uom_save.size() != 0) { - const int size = locale[iat][target_l][0][0].nr * locale[iat][target_l][0][0].nc; + const int size = occ_mat[iat][target_l][0][0].nr * occ_mat[iat][target_l][0][0].nc; const int half_size = this->uom_save.size() / 2; for(int mm=0; mmuom_save[eff_pot_pw_index[iat]+mm] = locale[iat][target_l][0][0].c[mm]; - this->uom_save[half_size + eff_pot_pw_index[iat]+mm] = locale[iat][target_l][0][1].c[mm]; + this->uom_save[eff_pot_pw_index[iat]+mm] = occ_mat[iat][target_l][0][0].c[mm]; + this->uom_save[half_size + eff_pot_pw_index[iat]+mm] = occ_mat[iat][target_l][0][1].c[mm]; } } } @@ -379,12 +379,12 @@ void Plus_U_Base::zero_locale(const UnitCell& ucell) { if (Plus_U_Base::nspin == 4) { - locale[iat][l][n][0].zero_out(); + occ_mat[iat][l][n][0].zero_out(); } else if (Plus_U_Base::nspin == 1 || Plus_U_Base::nspin == 2) { - locale[iat][l][n][0].zero_out(); - locale[iat][l][n][1].zero_out(); + occ_mat[iat][l][n][0].zero_out(); + occ_mat[iat][l][n][1].zero_out(); } } } @@ -414,34 +414,34 @@ void Plus_U_Base::mix_locale(const UnitCell& ucell, if (Plus_U_Base::nspin == 4) { - const int size = locale[iat][target_l][0][0].nr * locale[iat][target_l][0][0].nc; + const int size = occ_mat[iat][target_l][0][0].nr * occ_mat[iat][target_l][0][0].nc; for (int mm = 0; mm < size; mm++) { - locale[iat][target_l][0][0].c[mm] = locale[iat][target_l][0][0].c[mm] * beta + locale_save[iat][target_l][0][0].c[mm] * (1.0 - beta); + occ_mat[iat][target_l][0][0].c[mm] = occ_mat[iat][target_l][0][0].c[mm] * beta + occ_mat_save[iat][target_l][0][0].c[mm] * (1.0 - beta); } if (this->uom_save.size() != 0) { for (int mm = 0; mm < size; mm++) { - this->uom_save[eff_pot_pw_index[iat] + mm] = locale[iat][target_l][0][0].c[mm]; + this->uom_save[eff_pot_pw_index[iat] + mm] = occ_mat[iat][target_l][0][0].c[mm]; } } } else if (Plus_U_Base::nspin == 1 || Plus_U_Base::nspin == 2) { - const int size = locale[iat][target_l][0][0].nr * locale[iat][target_l][0][0].nc; + const int size = occ_mat[iat][target_l][0][0].nr * occ_mat[iat][target_l][0][0].nc; const int half_size = this->uom_save.size() / 2; for (int mm = 0; mm < size; mm++) { - locale[iat][target_l][0][0].c[mm] = locale[iat][target_l][0][0].c[mm] * beta + locale_save[iat][target_l][0][0].c[mm] * (1.0 - beta); - locale[iat][target_l][0][1].c[mm] = locale[iat][target_l][0][1].c[mm] * beta + locale_save[iat][target_l][0][1].c[mm] * (1.0 - beta); + occ_mat[iat][target_l][0][0].c[mm] = occ_mat[iat][target_l][0][0].c[mm] * beta + occ_mat_save[iat][target_l][0][0].c[mm] * (1.0 - beta); + occ_mat[iat][target_l][0][1].c[mm] = occ_mat[iat][target_l][0][1].c[mm] * beta + occ_mat_save[iat][target_l][0][1].c[mm] * (1.0 - beta); } if (this->uom_save.size() != 0) { for (int mm = 0; mm < size; mm++) { - this->uom_save[eff_pot_pw_index[iat] + mm] = locale[iat][target_l][0][0].c[mm]; - this->uom_save[half_size + eff_pot_pw_index[iat] + mm] = locale[iat][target_l][0][1].c[mm]; + this->uom_save[eff_pot_pw_index[iat] + mm] = occ_mat[iat][target_l][0][0].c[mm]; + this->uom_save[half_size + eff_pot_pw_index[iat] + mm] = occ_mat[iat][target_l][0][1].c[mm]; } } } @@ -465,18 +465,18 @@ void Plus_U_Base::set_locale(const UnitCell& ucell) const int iat = ucell.itia2iat(T, I); if (Plus_U_Base::nspin == 4) { - for(int mm = 0; mm < locale[iat][l][0][0].nr * locale[iat][l][0][0].nc; mm++) - locale[iat][l][0][0].c[mm] = this->uom_array[eff_pot_pw_index[iat] + mm]; + for(int mm = 0; mm < occ_mat[iat][l][0][0].nr * occ_mat[iat][l][0][0].nc; mm++) + occ_mat[iat][l][0][0].c[mm] = this->uom_array[eff_pot_pw_index[iat] + mm]; } else if (Plus_U_Base::nspin == 1 || Plus_U_Base::nspin == 2) { const int half_size = this->uom_array.size() / 2; - for(int mm = 0; mm < locale[iat][l][0][0].nr * locale[iat][l][0][0].nc; mm++) + for(int mm = 0; mm < occ_mat[iat][l][0][0].nr * occ_mat[iat][l][0][0].nc; mm++) { - locale[iat][l][0][0].c[mm] = this->uom_array[eff_pot_pw_index[iat] + mm]; + occ_mat[iat][l][0][0].c[mm] = this->uom_array[eff_pot_pw_index[iat] + mm]; if (Plus_U_Base::nspin == 2) { - locale[iat][l][0][1].c[mm] = this->uom_array[half_size + eff_pot_pw_index[iat] + mm]; + occ_mat[iat][l][0][1].c[mm] = this->uom_array[half_size + eff_pot_pw_index[iat] + mm]; } } } @@ -497,7 +497,7 @@ void Plus_U_Base::get_locale_flat(const int iat, const int l, std::vector(occ.size()); i++) { - occ[i] = locale[iat][l][0][0].c[i]; + occ[i] = occ_mat[iat][l][0][0].c[i]; } } } @@ -516,7 +516,7 @@ void Plus_U_Base::set_locale_flat(const int iat, const int l, const int spin, { for (int i = 0; i < static_cast(occ.size()); i++) { - locale[iat][l][0][spin].c[i] = occ[i]; + occ_mat[iat][l][0][spin].c[i] = occ[i]; } } @@ -621,7 +621,7 @@ void Plus_U_Base::read_occup_m(const UnitCell& ucell, for (int m1 = 0; m1 < 2 * L + 1; m1++) { ifdftu >> value; - locale[iat][L][zeta][spin](m0, m1) = value; + occ_mat[iat][L][zeta][spin](m0, m1) = value; } ifdftu.ignore(150, '\n'); } @@ -647,7 +647,7 @@ void Plus_U_Base::read_occup_m(const UnitCell& ucell, { int m1_all = m1 + (2 * L + 1) * ipol1; ifdftu >> value; - locale[iat][L][zeta][0](m0_all, m1_all) = value; + occ_mat[iat][L][zeta][0](m0_all, m1_all) = value; } } ifdftu.ignore(150, '\n'); @@ -714,7 +714,7 @@ void Plus_U_Base::local_occup_bcast(const UnitCell& ucell, for (int m1 = 0; m1 < 2 * l + 1; m1++) { #ifdef __MPI - MPI_Bcast(&locale[iat][l][n][spin](m0, m1), 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); + MPI_Bcast(&occ_mat[iat][l][n][spin](m0, m1), 1, MPI_DOUBLE, 0, MPI_COMM_WORLD); #endif } } @@ -734,7 +734,7 @@ void Plus_U_Base::local_occup_bcast(const UnitCell& ucell, { int m1_all = m1 + (2 * L + 1) * ipol1; #ifdef __MPI - MPI_Bcast(&locale[iat][l][n][0](m0_all, m1_all), + MPI_Bcast(&occ_mat[iat][l][n][0](m0_all, m1_all), 1, MPI_DOUBLE, 0, diff --git a/source/source_pw/module_pwdft/dftu_base.h b/source/source_pw/module_pwdft/dftu_base.h index 06818778127..9d5a9ba60cb 100644 --- a/source/source_pw/module_pwdft/dftu_base.h +++ b/source/source_pw/module_pwdft/dftu_base.h @@ -162,24 +162,24 @@ class Plus_U_Base std::vector>> J_Yukawa; public: - /// get occupation matrix element locale[iat][l][n][spin](m1,m2) + /// get occupation matrix element occ_mat[iat][l][n][spin](m1,m2) double get_locale(const int iat, const int l, const int n, const int spin, const int m1, const int m2) const { - return locale[iat][l][n][spin](m1, m2); + return occ_mat[iat][l][n][spin](m1, m2); } - /// set occupation matrix element locale[iat][l][n][spin](m1,m2) + /// set occupation matrix element occ_mat[iat][l][n][spin](m1,m2) void set_locale(const int iat, const int l, const int n, const int spin, const int m1, const int m2, const double val) { - locale[iat][l][n][spin](m1, m2) = val; + occ_mat[iat][l][n][spin](m1, m2) = val; } /// get flat occupation matrix for an atom's correlated orbital. - /// nspin=1: fills occ with locale[iat][l][0][0] data - /// nspin=2: fills occ with interleaved locale[iat][l][0][0] and [1] data - /// nspin=4: fills occ with locale[iat][l][0][0] data (all 4 Pauli blocks) + /// nspin=1: fills occ with occ_mat[iat][l][0][0] data + /// nspin=2: fills occ with interleaved occ_mat[iat][l][0][0] and [1] data + /// nspin=4: fills occ with occ_mat[iat][l][0][0] data (all 4 Pauli blocks) void get_locale_flat(const int iat, const int l, std::vector& occ) const; /// set flat occupation matrix for an atom's correlated orbital (write-back) @@ -187,8 +187,8 @@ class Plus_U_Base const std::vector& occ); // local occupancy matrix of the correlated subspace - std::vector>>> locale; - std::vector>>> locale_save; + std::vector>>> occ_mat; + std::vector>>> occ_mat_save; //============================================================= // output() and write_occup_m() have been extracted to free functions diff --git a/source/source_pw/module_pwdft/dftu_pw.cpp b/source/source_pw/module_pwdft/dftu_pw.cpp index ba44a210abe..4816a478caa 100644 --- a/source/source_pw/module_pwdft/dftu_pw.cpp +++ b/source/source_pw/module_pwdft/dftu_pw.cpp @@ -7,11 +7,11 @@ /// calculate occupation matrix for DFT+U (PW basis) /// -/// nspin=1 (npol=1): single spin channel; locale[iat][l][n][0] only; +/// nspin=1 (npol=1): single spin channel; occ_mat[iat][l][n][0] only; /// eff_pot_pw has one block of tlp1^2 per atom. /// /// nspin=2 (npol=1): two spin channels stored separately: -/// locale[iat][l][n][0] = spin-up, locale[iat][l][n][1] = spin-down; +/// occ_mat[iat][l][n][0] = spin-up, occ_mat[iat][l][n][1] = spin-down; /// becp indices: ib*nkb + begin_ih + m (same formula for both spins); /// spin channel selected by `isk[ik]` (not ik >= nk/2, which fails for kpar>1); /// @@ -76,10 +76,10 @@ void Plus_U_Base::cal_occ_pw(const int iter, occ[1] = weight * conj(becp[index_m1]) * becp[index_m2 + nkb]; occ[2] = weight * conj(becp[index_m1 + nkb]) * becp[index_m2]; occ[3] = weight * conj(becp[index_m1 + nkb]) * becp[index_m2 + nkb]; - this->locale[iat][target_l][0][0].c[ind_m1m2] += (occ[0] + occ[3]).real(); - this->locale[iat][target_l][0][0].c[ind_m1m2 + tlp1_2] += (occ[1] + occ[2]).real(); - this->locale[iat][target_l][0][0].c[ind_m1m2 + 2 * tlp1_2] += (occ[1] - occ[2]).imag(); - this->locale[iat][target_l][0][0].c[ind_m1m2 + 3 * tlp1_2] += (occ[0] - occ[3]).real(); + this->occ_mat[iat][target_l][0][0].c[ind_m1m2] += (occ[0] + occ[3]).real(); + this->occ_mat[iat][target_l][0][0].c[ind_m1m2 + tlp1_2] += (occ[1] + occ[2]).real(); + this->occ_mat[iat][target_l][0][0].c[ind_m1m2 + 2 * tlp1_2] += (occ[1] - occ[2]).imag(); + this->occ_mat[iat][target_l][0][0].c[ind_m1m2 + 3 * tlp1_2] += (occ[0] - occ[3]).real(); ind_m1m2++; } } @@ -97,7 +97,7 @@ void Plus_U_Base::cal_occ_pw(const int iter, for(int m2 = 0; m2 < tlp1; m2++) { const int index_m2 = ib*nkb + begin_ih + m_begin + m2; - this->locale[iat][target_l][0][is].c[ind_m1m2] += weight * (conj(becp[index_m1]) * becp[index_m2]).real(); + this->occ_mat[iat][target_l][0][is].c[ind_m1m2] += weight * (conj(becp[index_m1]) * becp[index_m2]).real(); ind_m1m2++; } } @@ -155,10 +155,10 @@ void Plus_U_Base::cal_occ_pw(const int iter, occ[1] = weight * conj(becp[index_m1]) * becp[index_m2 + nkb]; occ[2] = weight * conj(becp[index_m1 + nkb]) * becp[index_m2]; occ[3] = weight * conj(becp[index_m1 + nkb]) * becp[index_m2 + nkb]; - this->locale[iat][target_l][0][0].c[ind_m1m2] += (occ[0] + occ[3]).real(); - this->locale[iat][target_l][0][0].c[ind_m1m2 + tlp1_2] += (occ[1] + occ[2]).real(); - this->locale[iat][target_l][0][0].c[ind_m1m2 + 2 * tlp1_2] += (occ[1] - occ[2]).imag(); - this->locale[iat][target_l][0][0].c[ind_m1m2 + 3 * tlp1_2] += (occ[0] - occ[3]).real(); + this->occ_mat[iat][target_l][0][0].c[ind_m1m2] += (occ[0] + occ[3]).real(); + this->occ_mat[iat][target_l][0][0].c[ind_m1m2 + tlp1_2] += (occ[1] + occ[2]).real(); + this->occ_mat[iat][target_l][0][0].c[ind_m1m2 + 2 * tlp1_2] += (occ[1] - occ[2]).imag(); + this->occ_mat[iat][target_l][0][0].c[ind_m1m2 + 3 * tlp1_2] += (occ[0] - occ[3]).real(); ind_m1m2++; } } @@ -176,7 +176,7 @@ void Plus_U_Base::cal_occ_pw(const int iter, for(int m2 = 0; m2 < tlp1; m2++) { const int index_m2 = ib*nkb + begin_ih + m_begin + m2; - this->locale[iat][target_l][0][is].c[ind_m1m2] += weight * (conj(becp[index_m1]) * becp[index_m2]).real(); + this->occ_mat[iat][target_l][0][is].c[ind_m1m2] += weight * (conj(becp[index_m1]) * becp[index_m2]).real(); ind_m1m2++; } } @@ -203,13 +203,13 @@ void Plus_U_Base::cal_occ_pw(const int iter, { Parallel_Reduce::reduce_double_allpool(this->kpar, GlobalV::NPROC_IN_POOL, - this->locale[iat][target_l][0][0].c, + this->occ_mat[iat][target_l][0][0].c, size); if(Plus_U_Base::nspin == 2) { Parallel_Reduce::reduce_double_allpool(this->kpar, GlobalV::NPROC_IN_POOL, - this->locale[iat][target_l][0][1].c, + this->occ_mat[iat][target_l][0][1].c, size); } } @@ -217,7 +217,7 @@ void Plus_U_Base::cal_occ_pw(const int iter, { Parallel_Reduce::reduce_double_allpool(this->kpar, GlobalV::NPROC_IN_POOL, - this->locale[iat][target_l][0][0].c, + this->occ_mat[iat][target_l][0][0].c, size * 4); } @@ -226,14 +226,14 @@ void Plus_U_Base::cal_occ_pw(const int iter, { for(int mm=0;mmuom_array[eff_pot_pw_index[iat]+mm] = this->locale[iat][target_l][0][0].c[mm]; + this->uom_array[eff_pot_pw_index[iat]+mm] = this->occ_mat[iat][target_l][0][0].c[mm]; } if(Plus_U_Base::nspin == 2) { const int half_size = this->uom_array.size() / 2; for(int mm=0;mmuom_array[half_size + eff_pot_pw_index[iat]+mm] = this->locale[iat][target_l][0][1].c[mm]; + this->uom_array[half_size + eff_pot_pw_index[iat]+mm] = this->occ_mat[iat][target_l][0][1].c[mm]; } } } @@ -272,9 +272,9 @@ void Plus_U_Base::cal_occ_pw(const int iter, for (int m2 = 0; m2 < m_size; m2++) { vu_iat[m1 * m_size + m2] = u_value * - (diag_coeff * (m1 == m2) - this->locale[iat][target_l][0][0].c[m2 * m_size + m1]); - Plus_U_Base::energy_u += u_value * weight_eu * this->locale[iat][target_l][0][0].c[m2 * m_size + m1] - * this->locale[iat][target_l][0][0].c[m1 * m_size + m2]; + (diag_coeff * (m1 == m2) - this->occ_mat[iat][target_l][0][0].c[m2 * m_size + m1]); + Plus_U_Base::energy_u += u_value * weight_eu * this->occ_mat[iat][target_l][0][0].c[m2 * m_size + m1] + * this->occ_mat[iat][target_l][0][0].c[m1 * m_size + m2]; } } for (int is = 1; is < 4; ++is) @@ -285,10 +285,10 @@ void Plus_U_Base::cal_occ_pw(const int iter, for (int m2 = 0; m2 < m_size; m2++) { vu_iat[start + m1 * m_size + m2] = u_value * - (0 - this->locale[iat][target_l][0][0].c[start + m2 * m_size + m1]); + (0 - this->occ_mat[iat][target_l][0][0].c[start + m2 * m_size + m1]); Plus_U_Base::energy_u += u_value * weight_eu - * this->locale[iat][target_l][0][0].c[start + m2 * m_size + m1] - * this->locale[iat][target_l][0][0].c[start + m1 * m_size + m2]; + * this->occ_mat[iat][target_l][0][0].c[start + m2 * m_size + m1] + * this->occ_mat[iat][target_l][0][0].c[start + m1 * m_size + m2]; } } } @@ -322,9 +322,9 @@ void Plus_U_Base::cal_occ_pw(const int iter, for (int m2 = 0; m2 < m_size; m2++) { vu_iat[m1 * m_size + m2] = u_value * - (diag_coeff * (m1 == m2) - this->locale[iat][target_l][0][0].c[m2 * m_size + m1]); - Plus_U_Base::energy_u += u_value * weight_eu * this->locale[iat][target_l][0][0].c[m2 * m_size + m1] - * this->locale[iat][target_l][0][0].c[m1 * m_size + m2]; + (diag_coeff * (m1 == m2) - this->occ_mat[iat][target_l][0][0].c[m2 * m_size + m1]); + Plus_U_Base::energy_u += u_value * weight_eu * this->occ_mat[iat][target_l][0][0].c[m2 * m_size + m1] + * this->occ_mat[iat][target_l][0][0].c[m1 * m_size + m2]; } } // spin-down channel for nspin=2 @@ -336,9 +336,9 @@ void Plus_U_Base::cal_occ_pw(const int iter, for (int m2 = 0; m2 < m_size; m2++) { vu_iat1[m1 * m_size + m2] = u_value * - (diag_coeff * (m1 == m2) - this->locale[iat][target_l][0][1].c[m2 * m_size + m1]); - Plus_U_Base::energy_u += u_value * weight_eu * this->locale[iat][target_l][0][1].c[m2 * m_size + m1] - * this->locale[iat][target_l][0][1].c[m1 * m_size + m2]; + (diag_coeff * (m1 == m2) - this->occ_mat[iat][target_l][0][1].c[m2 * m_size + m1]); + Plus_U_Base::energy_u += u_value * weight_eu * this->occ_mat[iat][target_l][0][1].c[m2 * m_size + m1] + * this->occ_mat[iat][target_l][0][1].c[m1 * m_size + m2]; } } } From 66b2fcd60d7a7145bfa8f95cfffc569fdcd07b9e Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 25 Aug 2026 07:53:03 +0800 Subject: [PATCH 2/6] refactor(dftu): rename get_locale/set_locale -> get_occ_mat/set_occ_mat (Step 2/5) Rename the public single-element accessors of Plus_U_Base: get_locale(iat,l,n,spin,m1,m2) -> get_occ_mat(...) set_locale(iat,l,n,spin,m1,m2,val) -> set_occ_mat(...) Update all 5 direct call sites: * dftu_output.cpp (4 calls in dftu_io::write_occup_m for output) * dftu_lcao.cpp (1 call in DFTU cal_occ fallback branch) The protected batch overload set_locale(const UnitCell&) and the other state/flat helpers (copy_locale, zero_locale, mix_locale, get_locale_flat, set_locale_flat, is_locale_initialized, mark_*) are intentionally kept unchanged and will be renamed in the following steps. 3 files changed, 7 insertions(+), 7 deletions(-). --- source/source_lcao/module_operator_lcao/dftu_lcao.cpp | 2 +- source/source_pw/module_pwdft/dftu_base.h | 4 ++-- source/source_pw/module_pwdft/dftu_output.cpp | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/source_lcao/module_operator_lcao/dftu_lcao.cpp b/source/source_lcao/module_operator_lcao/dftu_lcao.cpp index 590d6596dde..d663553aef9 100644 --- a/source/source_lcao/module_operator_lcao/dftu_lcao.cpp +++ b/source/source_lcao/module_operator_lcao/dftu_lcao.cpp @@ -358,7 +358,7 @@ void hamilt::DFTU>::contributeHR() // TODO: UNSAFE - current_spin must be correct for nspin=2. // If current_spin is not toggled properly, wrong spin channel's locale is read. // This can happen if contributeHR() is called out of expected order. - occ[i] = this->dftu->get_locale(iat0, target_L, 0, this->current_spin, + occ[i] = this->dftu->get_occ_mat(iat0, target_L, 0, this->current_spin, i / (2 * target_L + 1), i % (2 * target_L + 1)); } } diff --git a/source/source_pw/module_pwdft/dftu_base.h b/source/source_pw/module_pwdft/dftu_base.h index 9d5a9ba60cb..3ee8c4dfe69 100644 --- a/source/source_pw/module_pwdft/dftu_base.h +++ b/source/source_pw/module_pwdft/dftu_base.h @@ -163,14 +163,14 @@ class Plus_U_Base public: /// get occupation matrix element occ_mat[iat][l][n][spin](m1,m2) - double get_locale(const int iat, const int l, const int n, const int spin, + double get_occ_mat(const int iat, const int l, const int n, const int spin, const int m1, const int m2) const { return occ_mat[iat][l][n][spin](m1, m2); } /// set occupation matrix element occ_mat[iat][l][n][spin](m1,m2) - void set_locale(const int iat, const int l, const int n, const int spin, + void set_occ_mat(const int iat, const int l, const int n, const int spin, const int m1, const int m2, const double val) { occ_mat[iat][l][n][spin](m1, m2) = val; diff --git a/source/source_pw/module_pwdft/dftu_output.cpp b/source/source_pw/module_pwdft/dftu_output.cpp index 722f12382e3..13502a9c473 100644 --- a/source/source_pw/module_pwdft/dftu_output.cpp +++ b/source/source_pw/module_pwdft/dftu_output.cpp @@ -220,7 +220,7 @@ void write_occup_m(const Plus_U_Base& dftu, { for (int m1 = 0; m1 < 2 * l + 1; m1++) { - A[m0][m1] = dftu.get_locale(iat, l, n, is, m0, m1); + A[m0][m1] = dftu.get_occ_mat(iat, l, n, is, m0, m1); } } std::vector eigenvalues = CalculateEigenvalues(A, 2 * l + 1); @@ -242,7 +242,7 @@ void write_occup_m(const Plus_U_Base& dftu, for (int m1 = 0; m1 < 2 * l + 1; m1++) { ofs << std::setw(12) - << dftu.get_locale(iat, l, n, is, m0, m1); + << dftu.get_occ_mat(iat, l, n, is, m0, m1); } ofs << std::endl; } @@ -267,7 +267,7 @@ void write_occup_m(const Plus_U_Base& dftu, { for (int m1 = 0; m1 < 2 * l + 1; m1++) { - A[m0][m1] = dftu.get_locale(iat, l, n, 0, m0, m1); + A[m0][m1] = dftu.get_occ_mat(iat, l, n, 0, m0, m1); index++; } } @@ -301,7 +301,7 @@ void write_occup_m(const Plus_U_Base& dftu, { int m1_all = m1 + (2 * l + 1) * ipol1; ofs << std::setw(12) << std::setprecision(8) << std::fixed - << dftu.get_locale(iat, l, n, 0, m0_all, m1_all); + << dftu.get_occ_mat(iat, l, n, 0, m0_all, m1_all); } } ofs << std::endl; From 4afb72a7f7b230a272edb803236ee695b450feb2 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 25 Aug 2026 07:57:46 +0800 Subject: [PATCH 3/6] refactor(dftu): rename flat/state funcs + fix initialed_locale spelling (Step 3/5) Rename Plus_U_Base flat-conversion and state-management APIs: get_locale_flat -> get_occ_mat_flat set_locale_flat -> set_occ_mat_flat is_locale_initialized -> is_occ_mat_initialized mark_locale_initialized-> mark_occ_mat_initialized mark_locale_dirty -> mark_occ_mat_dirty Also fix a long-standing spelling bug: the member variable bool initialed_locale was renamed to bool occ_mat_initialized (initialed -> initialized + naming aligned with occ_mat_* convention). Header declarations updated in dftu_base.h, plus definitions and all call sites updated across: * dftu_base.cpp (defs + mark_locale_initialized calls in init_base) * dftu_lcao.cpp (~16 call sites + doc comments) * dftu_fs.cpp (1 get_occ_mat_flat call) * dftu_hamilt.cpp (2 is_occ_mat_initialized calls) * setup_dftu_lcao.cpp (1 mark_occ_mat_initialized call) * dftu_occup.cpp (is/mark calls in cal_occup_m_*) * dftu.cpp (1 is_occ_mat_initialized call in cal_energy_correction) 8 files changed, 36 insertions(+), 36 deletions(-). --- source/source_lcao/module_dftu/dftu.cpp | 2 +- .../source_lcao/module_dftu/dftu_hamilt.cpp | 4 +-- source/source_lcao/module_dftu/dftu_occup.cpp | 8 ++--- .../module_operator_lcao/dftu_fs.cpp | 2 +- .../module_operator_lcao/dftu_lcao.cpp | 32 +++++++++---------- source/source_lcao/setup_dftu_lcao.cpp | 2 +- source/source_pw/module_pwdft/dftu_base.cpp | 8 ++--- source/source_pw/module_pwdft/dftu_base.h | 14 ++++---- 8 files changed, 36 insertions(+), 36 deletions(-) diff --git a/source/source_lcao/module_dftu/dftu.cpp b/source/source_lcao/module_dftu/dftu.cpp index 10ac681f9b0..f387f09409c 100644 --- a/source/source_lcao/module_dftu/dftu.cpp +++ b/source/source_lcao/module_dftu/dftu.cpp @@ -105,7 +105,7 @@ void Plus_U::cal_energy_correction(const UnitCell& ucell, { ModuleBase::TITLE("Plus_U", "cal_energy_correction"); ModuleBase::timer::start("Plus_U", "cal_energy_correction"); - if (!is_locale_initialized()) + if (!is_occ_mat_initialized()) { ModuleBase::timer::end("Plus_U", "cal_energy_correction"); return; diff --git a/source/source_lcao/module_dftu/dftu_hamilt.cpp b/source/source_lcao/module_dftu/dftu_hamilt.cpp index 19c20a1c095..fc1afdbc8e5 100644 --- a/source/source_lcao/module_dftu/dftu_hamilt.cpp +++ b/source/source_lcao/module_dftu/dftu_hamilt.cpp @@ -12,7 +12,7 @@ void Plus_U::cal_eff_pot_mat_complex(const int ik, const int npol) { ModuleBase::TITLE("Plus_U", "cal_eff_pot_c"); - if (!is_locale_initialized()) + if (!is_occ_mat_initialized()) { return; } @@ -65,7 +65,7 @@ void Plus_U::cal_eff_pot_mat_complex(const int ik, void Plus_U::cal_eff_pot_mat_real(const int ik, double* eff_pot, const std::vector& isk, const double* sk, const int npol) { ModuleBase::TITLE("Plus_U", "cal_eff_pot_r"); - if (!is_locale_initialized()) + if (!is_occ_mat_initialized()) { return; } diff --git a/source/source_lcao/module_dftu/dftu_occup.cpp b/source/source_lcao/module_dftu/dftu_occup.cpp index de15b12a215..5cca6c10af9 100644 --- a/source/source_lcao/module_dftu/dftu_occup.cpp +++ b/source/source_lcao/module_dftu/dftu_occup.cpp @@ -236,12 +236,12 @@ void Plus_U::cal_occup_m_k(const int iter, } // end ia } // end it - if(is_mixing_enabled() && is_locale_initialized()) + if(is_mixing_enabled() && is_occ_mat_initialized()) { this->mix_locale(ucell,mixing_beta); } - mark_locale_initialized(); + mark_occ_mat_initialized(); ModuleBase::timer::end("Plus_U", "cal_occup_m_k"); return; } @@ -393,12 +393,12 @@ void Plus_U::cal_occup_m_gamma(const int iter, } // it } // is - if(is_mixing_enabled() && is_locale_initialized()) + if(is_mixing_enabled() && is_occ_mat_initialized()) { this->mix_locale(ucell,mixing_beta); } - mark_locale_initialized(); + mark_occ_mat_initialized(); ModuleBase::timer::end("Plus_U", "cal_occup_m_gamma"); return; } diff --git a/source/source_lcao/module_operator_lcao/dftu_fs.cpp b/source/source_lcao/module_operator_lcao/dftu_fs.cpp index 54014250bc1..7db4896ed06 100644 --- a/source/source_lcao/module_operator_lcao/dftu_fs.cpp +++ b/source/source_lcao/module_operator_lcao/dftu_fs.cpp @@ -138,7 +138,7 @@ void DFTU>::cal_force_stress(const bool cal_force, } // first iteration to calculate occupation matrix std::vector occ(tlp1 * tlp1 * this->nspin, 0); - this->dftu->get_locale_flat(iat0, target_L, occ); + this->dftu->get_occ_mat_flat(iat0, target_L, occ); // calculate VU const double u_value = this->dftu->U[T0]; diff --git a/source/source_lcao/module_operator_lcao/dftu_lcao.cpp b/source/source_lcao/module_operator_lcao/dftu_lcao.cpp index d663553aef9..85d428676ec 100644 --- a/source/source_lcao/module_operator_lcao/dftu_lcao.cpp +++ b/source/source_lcao/module_operator_lcao/dftu_lcao.cpp @@ -177,25 +177,25 @@ void hamilt::DFTU>::cal_nlm_all(const Parallel_Orbi * @brief Contribute DFT+U Hamiltonian to real-space HR matrix * * @details This function handles different scenarios based on: - * 1. Whether locale (occupation matrix) is read from file (is_locale_initialized) + * 1. Whether locale (occupation matrix) is read from file (is_occ_mat_initialized) * 2. Spin configuration (nspin=1, 2, or 4) * 3. SCF iteration stage (first vs subsequent iterations) * - * Case 1: Locale NOT initialized (!is_locale_initialized) + * Case 1: Locale NOT initialized (!is_occ_mat_initialized) * - First electronic iteration: calculates occupation matrix from density matrix (DMR) * * Uses get_dmr(current_spin) to get real-space density matrix * * Accumulates contributions from all atom pairs via cal_occ() * * Performs MPI reduction to sum occ across processes - * * Stores result via set_locale_flat() for use in VU calculation + * * Stores result via set_occ_mat_flat() for use in VU calculation * * For nspin=1: occ is scaled by 0.5 (since only one spin channel computed) * - Subsequent iterations: locale is computed fresh each iteration from updated DMR * - * Case 2: Locale IS initialized (is_locale_initialized, i.e., read from dm_onsite.txt file) + * Case 2: Locale IS initialized (is_occ_mat_initialized, i.e., read from dm_onsite.txt file) * - First electronic iteration: uses pre-read locale directly without DMR calculation * * Skips DMR-based occ calculation entirely * * Reads locale from stored data via get_locale() * * Different indexing for nspin=4 vs nspin=1/2 (see below) - * - After first iteration: mark_locale_dirty() is called to force recomputation + * - After first iteration: mark_occ_mat_dirty() is called to force recomputation * * Spin configurations: * nspin=1 (non-spin-polarized): @@ -206,14 +206,14 @@ void hamilt::DFTU>::cal_nlm_all(const Parallel_Orbi * nspin=2 (collinear spin-polarized): * - Two separate spin channels (spin-up: 0, spin-down: 1) * - current_spin toggles between 0 and 1 across iterations - * - mark_locale_dirty() called when current_spin == 1 (last spin) + * - mark_occ_mat_dirty() called when current_spin == 1 (last spin) * - HR accumulated separately for each spin * * nspin=4 (non-collinear/SOC): * - Single 4x4 Pauli matrix representation per atom * - occ has 4*(2l+1)^2 elements (spin_fold=4) * - get_locale uses spin=0, ipol indices for Pauli blocks - * - mark_locale_dirty() always called (current_spin check always true) + * - mark_occ_mat_dirty() always called (current_spin check always true) * - No current_spin toggling (all spins handled simultaneously) * * @warning THREAD SAFETY: cal_HR_IJR() updates shared HR matrix entries. @@ -228,10 +228,10 @@ void hamilt::DFTU>::contributeHR() ModuleBase::TITLE("DFTU", "contributeHR"); // Early exit conditions: // - get_dmr(0) == nullptr: DMR not available (typical in first iteration without file input) - // - !is_locale_initialized(): locale not read from file AND not yet computed from DMR + // - !is_occ_mat_initialized(): locale not read from file AND not yet computed from DMR // When both true, skip DFT+U contribution entirely (first iteration, no file input) const bool dmr_null = (this->dftu->get_dmr(0) == nullptr); - const bool locale_not_init = !this->dftu->is_locale_initialized(); + const bool locale_not_init = !this->dftu->is_occ_mat_initialized(); if (dmr_null && locale_not_init) { @@ -280,10 +280,10 @@ void hamilt::DFTU>::contributeHR() // BRANCH 1: Locale NOT initialized (compute from DMR) // ============================================================ // This branch is taken when: - // - is_locale_initialized() == false (no file read or omc != 0) + // - is_occ_mat_initialized() == false (no file read or omc != 0) // - DMR is available (get_dmr() != nullptr) // Typical scenario: normal SCF iterations after first step - if (!this->dftu->is_locale_initialized()) + if (!this->dftu->is_occ_mat_initialized()) { // TODO: UNSAFE - get_dmr(current_spin) assumes DMR has correct spin indexing. // For nspin=2, current_spin must be correctly toggled (0 then 1). @@ -328,13 +328,13 @@ void hamilt::DFTU>::contributeHR() { for (auto& v : occ) { v *= 0.5; } } - this->dftu->set_locale_flat(iat0, target_L, this->current_spin, occ); + this->dftu->set_occ_mat_flat(iat0, target_L, this->current_spin, occ); } // ============================================================ // BRANCH 2: Locale IS initialized (use pre-read data) // ============================================================ // This branch is taken when: - // - is_locale_initialized() == true (locale read from dm_onsite.txt file) + // - is_occ_mat_initialized() == true (locale read from dm_onsite.txt file) // - OR omc != 0 (occupation matrix control with dm_onsite_ini.txt) // Typical scenario: first SCF iteration with file input, or restart calculation else @@ -346,8 +346,8 @@ void hamilt::DFTU>::contributeHR() { // For nspin=4, locale is stored as 4 stacked tlp1^2 blocks // at offsets 0, tlp1^2, 2*tlp1^2, 3*tlp1^2 for the 4 Pauli channels. - // Use get_locale_flat to read the stacked blocks directly - this->dftu->get_locale_flat(iat0, target_L, occ); + // Use get_occ_mat_flat to read the stacked blocks directly + this->dftu->get_occ_mat_flat(iat0, target_L, occ); } // nspin=1 or nspin=2: Collinear spin case // Locale stored separately for each spin channel @@ -447,7 +447,7 @@ void hamilt::DFTU>::contributeHR() // TODO: This logic is confusing. Consider explicit variable like `is_last_spin_channel`. if (this->current_spin == this->nspin - 1 || this->nspin == 4) { - this->dftu->mark_locale_dirty(); + this->dftu->mark_occ_mat_dirty(); } // 8. Spin channel toggling for nspin=2 diff --git a/source/source_lcao/setup_dftu_lcao.cpp b/source/source_lcao/setup_dftu_lcao.cpp index 11ee697c096..a56449015a5 100644 --- a/source/source_lcao/setup_dftu_lcao.cpp +++ b/source/source_lcao/setup_dftu_lcao.cpp @@ -73,7 +73,7 @@ void finish_dftu_lcao(const int iter, /// use the converged occupation matrix for next MD/Relax SCF calculation if (conv_esolver) { - dftu_ptr->mark_locale_initialized(); + dftu_ptr->mark_occ_mat_initialized(); } } diff --git a/source/source_pw/module_pwdft/dftu_base.cpp b/source/source_pw/module_pwdft/dftu_base.cpp index 5cefdceb1f9..8c5f08c1931 100644 --- a/source/source_pw/module_pwdft/dftu_base.cpp +++ b/source/source_pw/module_pwdft/dftu_base.cpp @@ -238,7 +238,7 @@ void Plus_U_Base::init_base(UnitCell& cell, this->local_occup_bcast(cell, nspin, npol); #endif - mark_locale_initialized(); + mark_occ_mat_initialized(); this->copy_locale(cell); } else @@ -251,7 +251,7 @@ void Plus_U_Base::init_base(UnitCell& cell, #ifdef __MPI this->local_occup_bcast(cell, nspin, npol); #endif - mark_locale_initialized(); + mark_occ_mat_initialized(); } else { @@ -487,7 +487,7 @@ void Plus_U_Base::set_locale(const UnitCell& ucell) } -void Plus_U_Base::get_locale_flat(const int iat, const int l, std::vector& occ) const +void Plus_U_Base::get_occ_mat_flat(const int iat, const int l, std::vector& occ) const { const int tlp1 = 2 * l + 1; const int size = tlp1 * tlp1; @@ -511,7 +511,7 @@ void Plus_U_Base::get_locale_flat(const int iat, const int l, std::vector& occ) { for (int i = 0; i < static_cast(occ.size()); i++) diff --git a/source/source_pw/module_pwdft/dftu_base.h b/source/source_pw/module_pwdft/dftu_base.h index 3ee8c4dfe69..eeeb859d8c8 100644 --- a/source/source_pw/module_pwdft/dftu_base.h +++ b/source/source_pw/module_pwdft/dftu_base.h @@ -134,12 +134,12 @@ class Plus_U_Base return eff_pot_pw.size(); } - // dftu can be calculated only after locale has been initialed - bool initialed_locale = false; + // dftu can be calculated only after occ_mat has been initialized + bool occ_mat_initialized = false; - bool is_locale_initialized() const { return initialed_locale; } - void mark_locale_initialized() { initialed_locale = true; } - void mark_locale_dirty() { initialed_locale = false; } + bool is_occ_mat_initialized() const { return occ_mat_initialized; } + void mark_occ_mat_initialized() { occ_mat_initialized = true; } + void mark_occ_mat_dirty() { occ_mat_initialized = false; } static bool is_mixing_enabled() { return mixing_dftu != 0; } static void enable_mixing() { mixing_dftu = 1; } @@ -180,10 +180,10 @@ class Plus_U_Base /// nspin=1: fills occ with occ_mat[iat][l][0][0] data /// nspin=2: fills occ with interleaved occ_mat[iat][l][0][0] and [1] data /// nspin=4: fills occ with occ_mat[iat][l][0][0] data (all 4 Pauli blocks) - void get_locale_flat(const int iat, const int l, std::vector& occ) const; + void get_occ_mat_flat(const int iat, const int l, std::vector& occ) const; /// set flat occupation matrix for an atom's correlated orbital (write-back) - void set_locale_flat(const int iat, const int l, const int spin, + void set_occ_mat_flat(const int iat, const int l, const int spin, const std::vector& occ); // local occupancy matrix of the correlated subspace From e805788d613c07f61fe874a4762bc3997a05d620 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 25 Aug 2026 08:02:12 +0800 Subject: [PATCH 4/6] refactor(dftu): rename protected copy/zero/mix/set_locale -> *_occ_mat (Step 4/5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename the four protected internal helpers of Plus_U_Base and their ModuleBase::TITLE / timer tag strings for consistency: copy_locale(ucell) -> copy_occ_mat(ucell) zero_locale(ucell) -> zero_occ_mat(ucell) mix_locale(ucell, mixing_beta) -> mix_occ_mat(ucell, mixing_beta) set_locale(ucell) -> set_occ_mat(ucell) The single-argument batch setter set_occ_mat(const UnitCell&) now overloads the public element-wise setter set_occ_mat(iat,l,n,spin,m1,m2,val) with a different signature — no ambiguity, no change to callers. Declarations (dftu_base.h), definitions + internal call sites in dftu_base.cpp (init_base flow, also all TITLE/timer labels), and call sites in cal_occ_pw (dftu_pw.cpp) and cal_occup_m_{k,gamma} (dftu_occup.cpp) are all updated together. 4 files changed, 32 insertions(+), 32 deletions(-). --- source/source_lcao/module_dftu/dftu_occup.cpp | 14 ++++---- source/source_pw/module_pwdft/dftu_base.cpp | 36 +++++++++---------- source/source_pw/module_pwdft/dftu_base.h | 8 ++--- source/source_pw/module_pwdft/dftu_pw.cpp | 6 ++-- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/source/source_lcao/module_dftu/dftu_occup.cpp b/source/source_lcao/module_dftu/dftu_occup.cpp index 5cca6c10af9..715bd26a318 100644 --- a/source/source_lcao/module_dftu/dftu_occup.cpp +++ b/source/source_lcao/module_dftu/dftu_occup.cpp @@ -6,7 +6,7 @@ #endif #include "source_base/module_external/scalapack_connector.h" -// copy_locale(), zero_locale(), mix_locale(), set_locale(ucell), +// copy_occ_mat(), zero_occ_mat(), mix_occ_mat(), set_locale(ucell), // get_locale_flat(), set_locale_flat() // are now implemented in dftu_base.cpp as Plus_U_Base methods (inherited by Plus_U). @@ -22,8 +22,8 @@ void Plus_U::cal_occup_m_k(const int iter, ModuleBase::TITLE("Plus_U", "cal_occup_m_k"); ModuleBase::timer::start("Plus_U", "cal_occup_m_k"); - this->copy_locale(ucell); - this->zero_locale(ucell); + this->copy_occ_mat(ucell); + this->zero_occ_mat(ucell); //=================Part 1====================== // call SCALAPACK routine to calculate the product of the S and density matrix @@ -238,7 +238,7 @@ void Plus_U::cal_occup_m_k(const int iter, if(is_mixing_enabled() && is_occ_mat_initialized()) { - this->mix_locale(ucell,mixing_beta); + this->mix_occ_mat(ucell,mixing_beta); } mark_occ_mat_initialized(); @@ -254,8 +254,8 @@ void Plus_U::cal_occup_m_gamma(const int iter, { ModuleBase::TITLE("Plus_U", "cal_occup_m_gamma"); ModuleBase::timer::start("Plus_U", "cal_occup_m_gamma"); - this->copy_locale(ucell); - this->zero_locale(ucell); + this->copy_occ_mat(ucell); + this->zero_occ_mat(ucell); //=================Part 1====================== // call PBLAS routine to calculate the product of the S and density matrix @@ -395,7 +395,7 @@ void Plus_U::cal_occup_m_gamma(const int iter, if(is_mixing_enabled() && is_occ_mat_initialized()) { - this->mix_locale(ucell,mixing_beta); + this->mix_occ_mat(ucell,mixing_beta); } mark_occ_mat_initialized(); diff --git a/source/source_pw/module_pwdft/dftu_base.cpp b/source/source_pw/module_pwdft/dftu_base.cpp index 8c5f08c1931..a0c99e7b439 100644 --- a/source/source_pw/module_pwdft/dftu_base.cpp +++ b/source/source_pw/module_pwdft/dftu_base.cpp @@ -239,7 +239,7 @@ void Plus_U_Base::init_base(UnitCell& cell, #endif mark_occ_mat_initialized(); - this->copy_locale(cell); + this->copy_occ_mat(cell); } else { @@ -255,7 +255,7 @@ void Plus_U_Base::init_base(UnitCell& cell, } else { - this->zero_locale(cell); + this->zero_occ_mat(cell); } } @@ -307,10 +307,10 @@ bool Plus_U_Base::u_converged() // copy_locale — save current occ_mat to occ_mat_save and uom_save -void Plus_U_Base::copy_locale(const UnitCell& ucell) +void Plus_U_Base::copy_occ_mat(const UnitCell& ucell) { - ModuleBase::TITLE("Plus_U_Base", "copy_locale"); - ModuleBase::timer::start("Plus_U_Base", "copy_locale"); + ModuleBase::TITLE("Plus_U_Base", "copy_occ_mat"); + ModuleBase::timer::start("Plus_U_Base", "copy_occ_mat"); for (int T = 0; T < ucell.ntype; T++) { @@ -351,14 +351,14 @@ void Plus_U_Base::copy_locale(const UnitCell& ucell) } } } - ModuleBase::timer::end("Plus_U_Base", "copy_locale"); + ModuleBase::timer::end("Plus_U_Base", "copy_occ_mat"); } -void Plus_U_Base::zero_locale(const UnitCell& ucell) +void Plus_U_Base::zero_occ_mat(const UnitCell& ucell) { - ModuleBase::TITLE("Plus_U_Base", "zero_locale"); - ModuleBase::timer::start("Plus_U_Base", "zero_locale"); + ModuleBase::TITLE("Plus_U_Base", "zero_occ_mat"); + ModuleBase::timer::start("Plus_U_Base", "zero_occ_mat"); for (int T = 0; T < ucell.ntype; T++) { @@ -390,15 +390,15 @@ void Plus_U_Base::zero_locale(const UnitCell& ucell) } } } - ModuleBase::timer::end("Plus_U_Base", "zero_locale"); + ModuleBase::timer::end("Plus_U_Base", "zero_occ_mat"); } -void Plus_U_Base::mix_locale(const UnitCell& ucell, +void Plus_U_Base::mix_occ_mat(const UnitCell& ucell, const double& mixing_beta) { - ModuleBase::TITLE("Plus_U_Base", "mix_locale"); - ModuleBase::timer::start("Plus_U_Base", "mix_locale"); + ModuleBase::TITLE("Plus_U_Base", "mix_occ_mat"); + ModuleBase::timer::start("Plus_U_Base", "mix_occ_mat"); double beta = mixing_beta; @@ -447,14 +447,14 @@ void Plus_U_Base::mix_locale(const UnitCell& ucell, } } } - ModuleBase::timer::end("Plus_U_Base", "mix_locale"); + ModuleBase::timer::end("Plus_U_Base", "mix_occ_mat"); } -void Plus_U_Base::set_locale(const UnitCell& ucell) +void Plus_U_Base::set_occ_mat(const UnitCell& ucell) { - ModuleBase::TITLE("Plus_U_Base", "set_locale"); - ModuleBase::timer::start("Plus_U_Base", "set_locale"); + ModuleBase::TITLE("Plus_U_Base", "set_occ_mat"); + ModuleBase::timer::start("Plus_U_Base", "set_occ_mat"); for (int T = 0; T < ucell.ntype; T++) { @@ -483,7 +483,7 @@ void Plus_U_Base::set_locale(const UnitCell& ucell) } } - ModuleBase::timer::end("Plus_U_Base", "set_locale"); + ModuleBase::timer::end("Plus_U_Base", "set_occ_mat"); } diff --git a/source/source_pw/module_pwdft/dftu_base.h b/source/source_pw/module_pwdft/dftu_base.h index eeeb859d8c8..278ec0ee2fb 100644 --- a/source/source_pw/module_pwdft/dftu_base.h +++ b/source/source_pw/module_pwdft/dftu_base.h @@ -145,10 +145,10 @@ class Plus_U_Base static void enable_mixing() { mixing_dftu = 1; } protected: - void copy_locale(const UnitCell& ucell); - void zero_locale(const UnitCell& ucell); - void mix_locale(const UnitCell& ucell, const double& mixing_beta); - void set_locale(const UnitCell& ucell); + void copy_occ_mat(const UnitCell& ucell); + void zero_occ_mat(const UnitCell& ucell); + void mix_occ_mat(const UnitCell& ucell, const double& mixing_beta); + void set_occ_mat(const UnitCell& ucell); std::vector> eff_pot_pw; std::vector eff_pot_pw_index; diff --git a/source/source_pw/module_pwdft/dftu_pw.cpp b/source/source_pw/module_pwdft/dftu_pw.cpp index 4816a478caa..033b942b801 100644 --- a/source/source_pw/module_pwdft/dftu_pw.cpp +++ b/source/source_pw/module_pwdft/dftu_pw.cpp @@ -26,8 +26,8 @@ void Plus_U_Base::cal_occ_pw(const int iter, const int* isk) { ModuleBase::timer::start("Plus_U_Base", "cal_occ_pw"); - this->copy_locale(cell); - this->zero_locale(cell); + this->copy_occ_mat(cell); + this->zero_occ_mat(cell); if(this->device == "cpu") { @@ -243,7 +243,7 @@ void Plus_U_Base::cal_occ_pw(const int iter, if(is_mixing_enabled() && p_chgmix != nullptr) { p_chgmix->mix_uom(this->uom_array, this->uom_save); - this->set_locale(cell); + this->set_occ_mat(cell); } Plus_U_Base::energy_u = 0.0; From 22659fc941f5ae4a66cafc0ca3f4b02bce338614 Mon Sep 17 00:00:00 2001 From: abacus_fixer Date: Tue, 25 Aug 2026 08:07:41 +0800 Subject: [PATCH 5/6] refactor(dftu): cleanup comments, tests, parameter names (Step 5/5) Final cleanup pass to align naming after the locale -> occ_mat rename: * dftu_lcao.cpp (~40 lines): - Replace identifier-style 'locale' / 'Locale' references in the contributeHR() doc block and inline comments with 'occ_mat' / 'Occ_mat', including stale 'via get_locale()' / 'get_locale uses' mentions that no longer match the API. - Rename local bool flag locale_not_init -> occ_mat_not_init. * dftu_pw.cpp (4 lines): Fix the 4 remaining comments that still referred to 'locale matrix' / 'reduce locale' / 'locale reduced' in the cal_occ_pw implementation notes. * dftu_occup.cpp (2 lines): Update the top-of-file function inventory comment: set_locale(ucell) -> set_occ_mat(ucell); get/set_locale_flat -> get/set_occ_mat_flat. * dftu_tools.cpp (12 lines): Rename bool parameter 'newlocale' -> 'new_occ_mat' and its 3 internal uses in cal_VU_pot_mat_{complex,real} and get_onebody_eff_pot signatures/bodies, so the parameter name matches the occ_mat naming convention. * dftu_core_test.cpp (28 lines): - copy_locale_to_flat -> copy_occ_mat_to_flat (def + 3 call sites) - set_locale_from_flat -> set_occ_mat_from_flat (def + 3 call sites) - LocaleRoundtripTest -> OccMatRoundtripTest (test fixture + 2 TEST_F) - Related header comments: 'copy_locale <-> set_locale roundtrip', 'nested locale matrix' updated accordingly. * dftu_pw_test.cpp (6 lines): - 'Locale accumulation from becp' -> 'Occupation matrix accumulation from becp' in the test description; - 'set_locale is tested via integration tests.' -> 'set_occ_mat is tested via integration tests.' Not touched: pure semantic/mathematical local variable names inside the test helpers (locale_up, locale_dn, locale_c, compute_vu(locale_val), compute_energy(locale_flat), etc.) - these are local symbolic placeholders independent of the Plus_U_Base member naming. 6 files changed, 49 insertions(+), 49 deletions(-). --- source/source_lcao/module_dftu/dftu_occup.cpp | 4 +- source/source_lcao/module_dftu/dftu_tools.cpp | 12 +++--- .../module_dftu/test/dftu_core_test.cpp | 28 ++++++------- .../module_dftu/test/dftu_pw_test.cpp | 6 +-- .../module_operator_lcao/dftu_lcao.cpp | 40 +++++++++---------- source/source_pw/module_pwdft/dftu_pw.cpp | 8 ++-- 6 files changed, 49 insertions(+), 49 deletions(-) diff --git a/source/source_lcao/module_dftu/dftu_occup.cpp b/source/source_lcao/module_dftu/dftu_occup.cpp index 715bd26a318..782b6b1cb14 100644 --- a/source/source_lcao/module_dftu/dftu_occup.cpp +++ b/source/source_lcao/module_dftu/dftu_occup.cpp @@ -6,8 +6,8 @@ #endif #include "source_base/module_external/scalapack_connector.h" -// copy_occ_mat(), zero_occ_mat(), mix_occ_mat(), set_locale(ucell), -// get_locale_flat(), set_locale_flat() +// copy_occ_mat(), zero_occ_mat(), mix_occ_mat(), set_occ_mat(ucell), +// get_occ_mat_flat(), set_occ_mat_flat() // are now implemented in dftu_base.cpp as Plus_U_Base methods (inherited by Plus_U). #ifdef __LCAO diff --git a/source/source_lcao/module_dftu/dftu_tools.cpp b/source/source_lcao/module_dftu/dftu_tools.cpp index 6c43581d661..ab03942e64d 100644 --- a/source/source_lcao/module_dftu/dftu_tools.cpp +++ b/source/source_lcao/module_dftu/dftu_tools.cpp @@ -3,7 +3,7 @@ #include "source_io/module_parameter/parameter.h" #ifdef __LCAO -void Plus_U::cal_VU_pot_mat_complex(const int spin, const bool newlocale, std::complex* VU, const int npol) +void Plus_U::cal_VU_pot_mat_complex(const int spin, const bool new_occ_mat, std::complex* VU, const int npol) { ModuleBase::TITLE("Plus_U", "cal_VU_pot_mat_complex"); ModuleBase::GlobalFunc::ZEROS(VU, this->paraV->nloc); @@ -53,7 +53,7 @@ void Plus_U::cal_VU_pot_mat_complex(const int spin, const bool newlocale, std::c } int m1_all = m1 + (2 * L + 1) * ipol1; int m2_all = m2 + (2 * L + 1) * ipol2; - double val = get_onebody_eff_pot(it, iat, L, n, spin, m1_all, m2_all, newlocale); + double val = get_onebody_eff_pot(it, iat, L, n, spin, m1_all, m2_all, new_occ_mat); VU[nu * this->paraV->nrow + mu] = std::complex(val, 0.0); } // ipol2 } // m2 @@ -67,7 +67,7 @@ void Plus_U::cal_VU_pot_mat_complex(const int spin, const bool newlocale, std::c return; } -void Plus_U::cal_VU_pot_mat_real(const int spin, const bool newlocale, double* VU, const int npol) +void Plus_U::cal_VU_pot_mat_real(const int spin, const bool new_occ_mat, double* VU, const int npol) { ModuleBase::TITLE("Plus_U", "cal_VU_pot_mat_real"); ModuleBase::GlobalFunc::ZEROS(VU, this->paraV->nloc); @@ -118,7 +118,7 @@ void Plus_U::cal_VU_pot_mat_real(const int spin, const bool newlocale, double* V int m2_all = m2 + (2 * L + 1) * ipol2; VU[nu * this->paraV->nrow + mu] - = this->get_onebody_eff_pot(it, iat, L, n, spin, m1_all, m2_all, newlocale); + = this->get_onebody_eff_pot(it, iat, L, n, spin, m1_all, m2_all, new_occ_mat); } // ipol2 } // m2 @@ -139,7 +139,7 @@ double Plus_U::get_onebody_eff_pot(const int T, const int spin, const int m0, const int m1, - const bool newlocale) + const bool new_occ_mat) { ModuleBase::TITLE("Plus_U", "get_onebody_eff_pot"); @@ -156,7 +156,7 @@ double Plus_U::get_onebody_eff_pot(const int T, break; case 3: // simplified formalism and FLL double counting - if (newlocale) + if (new_occ_mat) { if (Yukawa) { diff --git a/source/source_lcao/module_dftu/test/dftu_core_test.cpp b/source/source_lcao/module_dftu/test/dftu_core_test.cpp index 3ccd8c056b6..ab40aded66e 100644 --- a/source/source_lcao/module_dftu/test/dftu_core_test.cpp +++ b/source/source_lcao/module_dftu/test/dftu_core_test.cpp @@ -10,7 +10,7 @@ * * These tests target the most complex and bug-prone logic: * 1. eff_pot_pw_index calculation for mixed atom types and nspin modes - * 2. copy_locale <-> set_locale roundtrip (3 data layouts) + * 2. copy_occ_mat <-> set_occ_mat roundtrip (3 data layouts) * 3. VU effective potential formula (cal_type=3, FLL) * 4. Energy correction and double-counting terms ***********************************************************************/ @@ -88,9 +88,9 @@ TEST_F(EffPotIndexTest, Nspin2and4_SplitAndPauli) } // ===================================================================== -// 2. copy_locale <-> set_locale roundtrip +// 2. copy_occ_mat <-> set_occ_mat roundtrip // -// Tests the bidirectional conversion between nested locale matrix +// Tests the bidirectional conversion between nested occ_mat matrix // and flat uom_array/uom_save arrays for all 3 nspin modes. // ===================================================================== @@ -103,7 +103,7 @@ struct Matrix2D { const double& operator()(int i, int j) const { return data[i * nc + j]; } }; -static void copy_locale_to_flat( +static void copy_occ_mat_to_flat( const std::vector& locale_up, const std::vector& locale_dn, std::vector& uom_save, @@ -143,7 +143,7 @@ static void copy_locale_to_flat( } } -static void set_locale_from_flat( +static void set_occ_mat_from_flat( const std::vector& uom_array, std::vector& locale_up, std::vector& locale_dn, @@ -183,13 +183,13 @@ static void set_locale_from_flat( } } -class LocaleRoundtripTest : public ::testing::Test +class OccMatRoundtripTest : public ::testing::Test { protected: void SetUp() override {} }; -TEST_F(LocaleRoundtripTest, Nspin1and2_SingleAndSplitLayout) +TEST_F(OccMatRoundtripTest, Nspin1and2_SingleAndSplitLayout) { // nspin=1: single atom d-orbital roundtrip const int l = 2; @@ -202,8 +202,8 @@ TEST_F(LocaleRoundtripTest, Nspin1and2_SingleAndSplitLayout) std::vector eff_pot_pw_index = {0}; std::vector uom_save(size, 0.0); - copy_locale_to_flat(locale_up, locale_dn, uom_save, eff_pot_pw_index, 1); - set_locale_from_flat(uom_save, locale_up, locale_dn, eff_pot_pw_index, 1); + copy_occ_mat_to_flat(locale_up, locale_dn, uom_save, eff_pot_pw_index, 1); + set_occ_mat_from_flat(uom_save, locale_up, locale_dn, eff_pot_pw_index, 1); for (int i = 0; i < size; i++) EXPECT_DOUBLE_EQ(locale_up[0].data[i], static_cast(i + 1)); @@ -215,14 +215,14 @@ TEST_F(LocaleRoundtripTest, Nspin1and2_SingleAndSplitLayout) locale_dn[0].data[i] = static_cast(i + 100); } uom_save.assign(total, 0.0); - copy_locale_to_flat(locale_up, locale_dn, uom_save, eff_pot_pw_index, 2); + copy_occ_mat_to_flat(locale_up, locale_dn, uom_save, eff_pot_pw_index, 2); // Verify split layout for (int i = 0; i < size; i++) { EXPECT_DOUBLE_EQ(uom_save[i], static_cast(i + 1)); EXPECT_DOUBLE_EQ(uom_save[size + i], static_cast(i + 100)); } - set_locale_from_flat(uom_save, locale_up, locale_dn, eff_pot_pw_index, 2); + set_occ_mat_from_flat(uom_save, locale_up, locale_dn, eff_pot_pw_index, 2); for (int i = 0; i < size; i++) { EXPECT_DOUBLE_EQ(locale_up[0].data[i], static_cast(i + 1)); @@ -230,7 +230,7 @@ TEST_F(LocaleRoundtripTest, Nspin1and2_SingleAndSplitLayout) } } -TEST_F(LocaleRoundtripTest, Nspin4_PauliBlocks) +TEST_F(OccMatRoundtripTest, Nspin4_PauliBlocks) { // 2 atoms: d(l=2), p(l=1) struct AtomSpec { int l; }; @@ -265,8 +265,8 @@ TEST_F(LocaleRoundtripTest, Nspin4_PauliBlocks) std::vector uom_array(total, 0.0); std::vector locale_dn(specs.size()); // unused for nspin=4 - copy_locale_to_flat(locale, locale_dn, uom_array, eff_pot_pw_index, 4); - set_locale_from_flat(uom_array, locale, locale_dn, eff_pot_pw_index, 4); + copy_occ_mat_to_flat(locale, locale_dn, uom_array, eff_pot_pw_index, 4); + set_occ_mat_from_flat(uom_array, locale, locale_dn, eff_pot_pw_index, 4); for (size_t i = 0; i < specs.size(); i++) for (int j = 0; j < sizes[i]; j++) diff --git a/source/source_lcao/module_dftu/test/dftu_pw_test.cpp b/source/source_lcao/module_dftu/test/dftu_pw_test.cpp index 0a7f4f2c976..5dc811b6874 100644 --- a/source/source_lcao/module_dftu/test/dftu_pw_test.cpp +++ b/source/source_lcao/module_dftu/test/dftu_pw_test.cpp @@ -12,13 +12,13 @@ * 2. Becp index logic: different index formulas for nspin=1/2 vs nspin=4 * 3. VU effective potential: cal_occ_pw VU calculation for all nspin modes * 4. Energy calculation: E_U accumulation with correct weights - * 5. Locale accumulation from becp: the core loop of cal_occ_pw + * 5. Occupation matrix accumulation from becp: the core loop of cal_occ_pw * 6. Multi-atom split layout: [all_up | all_dn] layout for nspin=2 * 7. OnsitePsOp kernel: vu application to ps for npol=1 * * Strategy: test energy weights and becp index logic as pure * arithmetic — no need to link against full ABACUS libraries. - * set_locale is tested via integration tests. + * set_occ_mat is tested via integration tests. ***********************************************************************/ class DftuPwTest : public ::testing::Test @@ -215,7 +215,7 @@ TEST_F(DftuPwTest, EnergyNspin4_WithOffDiagonal) } // ===================================================================== -// Locale accumulation from becp (cal_occ_pw core loop) +// Occupation matrix accumulation from becp (cal_occ_pw core loop) // ===================================================================== TEST_F(DftuPwTest, LocaleAccumNspin12) diff --git a/source/source_lcao/module_operator_lcao/dftu_lcao.cpp b/source/source_lcao/module_operator_lcao/dftu_lcao.cpp index 85d428676ec..3d02c7b3e5e 100644 --- a/source/source_lcao/module_operator_lcao/dftu_lcao.cpp +++ b/source/source_lcao/module_operator_lcao/dftu_lcao.cpp @@ -177,23 +177,23 @@ void hamilt::DFTU>::cal_nlm_all(const Parallel_Orbi * @brief Contribute DFT+U Hamiltonian to real-space HR matrix * * @details This function handles different scenarios based on: - * 1. Whether locale (occupation matrix) is read from file (is_occ_mat_initialized) + * 1. Whether occ_mat (occupation matrix) is read from file (is_occ_mat_initialized) * 2. Spin configuration (nspin=1, 2, or 4) * 3. SCF iteration stage (first vs subsequent iterations) * - * Case 1: Locale NOT initialized (!is_occ_mat_initialized) + * Case 1: Occ_mat NOT initialized (!is_occ_mat_initialized) * - First electronic iteration: calculates occupation matrix from density matrix (DMR) * * Uses get_dmr(current_spin) to get real-space density matrix * * Accumulates contributions from all atom pairs via cal_occ() * * Performs MPI reduction to sum occ across processes * * Stores result via set_occ_mat_flat() for use in VU calculation * * For nspin=1: occ is scaled by 0.5 (since only one spin channel computed) - * - Subsequent iterations: locale is computed fresh each iteration from updated DMR + * - Subsequent iterations: occ_mat is computed fresh each iteration from updated DMR * - * Case 2: Locale IS initialized (is_occ_mat_initialized, i.e., read from dm_onsite.txt file) - * - First electronic iteration: uses pre-read locale directly without DMR calculation + * Case 2: Occ_mat IS initialized (is_occ_mat_initialized, i.e., read from dm_onsite.txt file) + * - First electronic iteration: uses pre-read occ_mat directly without DMR calculation * * Skips DMR-based occ calculation entirely - * * Reads locale from stored data via get_locale() + * * Reads locale from stored data via get_occ_mat() * * Different indexing for nspin=4 vs nspin=1/2 (see below) * - After first iteration: mark_occ_mat_dirty() is called to force recomputation * @@ -212,7 +212,7 @@ void hamilt::DFTU>::cal_nlm_all(const Parallel_Orbi * nspin=4 (non-collinear/SOC): * - Single 4x4 Pauli matrix representation per atom * - occ has 4*(2l+1)^2 elements (spin_fold=4) - * - get_locale uses spin=0, ipol indices for Pauli blocks + * - get_occ_mat uses spin=0, ipol indices for Pauli blocks * - mark_occ_mat_dirty() always called (current_spin check always true) * - No current_spin toggling (all spins handled simultaneously) * @@ -228,12 +228,12 @@ void hamilt::DFTU>::contributeHR() ModuleBase::TITLE("DFTU", "contributeHR"); // Early exit conditions: // - get_dmr(0) == nullptr: DMR not available (typical in first iteration without file input) - // - !is_occ_mat_initialized(): locale not read from file AND not yet computed from DMR + // - !is_occ_mat_initialized(): occ_mat not read from file AND not yet computed from DMR // When both true, skip DFT+U contribution entirely (first iteration, no file input) const bool dmr_null = (this->dftu->get_dmr(0) == nullptr); - const bool locale_not_init = !this->dftu->is_occ_mat_initialized(); + const bool occ_mat_not_init = !this->dftu->is_occ_mat_initialized(); - if (dmr_null && locale_not_init) + if (dmr_null && occ_mat_not_init) { return; } @@ -277,7 +277,7 @@ void hamilt::DFTU>::contributeHR() std::vector occ(tlp1 * tlp1 * spin_fold, 0.0); // ============================================================ - // BRANCH 1: Locale NOT initialized (compute from DMR) + // BRANCH 1: Occ_mat NOT initialized (compute from DMR) // ============================================================ // This branch is taken when: // - is_occ_mat_initialized() == false (no file read or omc != 0) @@ -331,32 +331,32 @@ void hamilt::DFTU>::contributeHR() this->dftu->set_occ_mat_flat(iat0, target_L, this->current_spin, occ); } // ============================================================ - // BRANCH 2: Locale IS initialized (use pre-read data) + // BRANCH 2: Occ_mat IS initialized (use pre-read data) // ============================================================ // This branch is taken when: - // - is_occ_mat_initialized() == true (locale read from dm_onsite.txt file) + // - is_occ_mat_initialized() == true (occ_mat read from dm_onsite.txt file) // - OR omc != 0 (occupation matrix control with dm_onsite_ini.txt) // Typical scenario: first SCF iteration with file input, or restart calculation else { // nspin=4: Non-collinear case with Pauli matrix representation - // Locale stored as single 4x4 block per atom, with spin indices embedded + // Occ_mat stored as single 4x4 block per atom, with spin indices embedded // in the matrix indices (ipol0, ipol1 for Pauli block indices) if (this->nspin == 4) { - // For nspin=4, locale is stored as 4 stacked tlp1^2 blocks + // For nspin=4, occ_mat is stored as 4 stacked tlp1^2 blocks // at offsets 0, tlp1^2, 2*tlp1^2, 3*tlp1^2 for the 4 Pauli channels. // Use get_occ_mat_flat to read the stacked blocks directly this->dftu->get_occ_mat_flat(iat0, target_L, occ); } // nspin=1 or nspin=2: Collinear spin case - // Locale stored separately for each spin channel + // Occ_mat stored separately for each spin channel else { for (int i = 0; i < static_cast(occ.size()); i++) { // TODO: UNSAFE - current_spin must be correct for nspin=2. - // If current_spin is not toggled properly, wrong spin channel's locale is read. + // If current_spin is not toggled properly, wrong spin channel's occ_mat is read. // This can happen if contributeHR() is called out of expected order. occ[i] = this->dftu->get_occ_mat(iat0, target_L, 0, this->current_spin, i / (2 * target_L + 1), i % (2 * target_L + 1)); @@ -428,7 +428,7 @@ void hamilt::DFTU>::contributeHR() ModuleBase::timer::end("DFTU", "cal_vu"); } - // 6. Post-processing: Energy correction and locale state management + // 6. Post-processing: Energy correction and occ_mat state management // For nspin=1: DFT+U energy computed for single spin channel, but should count both spins // set_double_energy() doubles the energy to account for degenerate spin-up/down if (this->nspin == 1) @@ -436,13 +436,13 @@ void hamilt::DFTU>::contributeHR() this->dftu->set_double_energy(); } - // 7. Mark locale as dirty to force recomputation in next iteration + // 7. Mark occ_mat as dirty to force recomputation in next iteration // This is called when: // - nspin=4: Always (all spins handled simultaneously, current_spin==0==nspin-1) // - nspin=2: When current_spin==1 (after spin-down calculation, last spin channel) // - nspin=1: When current_spin==0==nspin-1 (always called) // - // Purpose: Ensure locale is recomputed from updated DMR in next SCF iteration, + // Purpose: Ensure occ_mat is recomputed from updated DMR in next SCF iteration, // rather than using stale pre-read data from file. // TODO: This logic is confusing. Consider explicit variable like `is_last_spin_channel`. if (this->current_spin == this->nspin - 1 || this->nspin == 4) diff --git a/source/source_pw/module_pwdft/dftu_pw.cpp b/source/source_pw/module_pwdft/dftu_pw.cpp index 033b942b801..08a8aafd24c 100644 --- a/source/source_pw/module_pwdft/dftu_pw.cpp +++ b/source/source_pw/module_pwdft/dftu_pw.cpp @@ -16,7 +16,7 @@ /// spin channel selected by `isk[ik]` (not ik >= nk/2, which fails for kpar>1); /// /// nspin=4 (npol=2): spinor calculation; -/// locale has a single matrix of size (2*tlp1) x (2*tlp1) per atom +/// occ_mat has a single matrix of size (2*tlp1) x (2*tlp1) per atom /// storing all 4 Pauli blocks contiguously. void Plus_U_Base::cal_occ_pw(const int iter, const void* psi_in, @@ -188,7 +188,7 @@ void Plus_U_Base::cal_occ_pw(const int iter, } #endif - // reduce locale from all k-pools + // reduce occ_mat from all k-pools for(int iat = 0; iat < cell.nat; iat++) { const int it = cell.iat2it[iat]; @@ -221,7 +221,7 @@ void Plus_U_Base::cal_occ_pw(const int iter, size * 4); } - // save locale matrix for this iat to uom_array + // save occ_mat matrix for this iat to uom_array if(this->uom_array.size() != 0) { for(int mm=0;mm Date: Tue, 25 Aug 2026 08:40:22 +0800 Subject: [PATCH 6/6] refactor(dftu): move DFT+U operator from module_operator_lcao to module_dftu Move DFTU/OperatorDFTU operator implementation files (dftu.hpp, dftu_lcao.h/cpp, dftu_fs.cpp, op_dftu_lcao.h/cpp) and the related unit test (test_dftu.cpp -> dftu_lcao_test.cpp) from module_operator_lcao to module_dftu. This is a step toward removing module_operator_lcao and grouping DFT+U code by physical domain. CMake changes: - module_dftu CMakeLists adds the 3 cpp files guarded by ENABLE_LCAO, since module_dftu is unconditionally added by source_lcao while these files depend on operator_lcao.h - module_operator_lcao CMakeLists drops the 3 cpp files - source_lcao CMakeLists drops the 3 cpp entries from the hamilt_lcao OBJECT library (now provided by the dftu OBJECT library) - New dftu_lcao_test target guarded by ENABLE_LCAO AND ENABLE_MPI matches the original MODULE_LCAO_operator_dftu_test build condition Include path updates in 5 external call sites plus op_dftu_lcao.h internal operator_lcao.h path (changed from same-directory relative to full path since the file is no longer co-located). Verified: cmake configure, make abacus_max_para + dftu_lcao_test, and ctest dftu_pw_test/dftu_core_test/dftu_operator_test/dftu_lcao_test all pass; agent_governance_check reports only include-path change warnings with no errors. --- source/source_io/module_hs/write_vxc.hpp | 2 +- source/source_io/module_hs/write_vxc_r.hpp | 2 +- source/source_lcao/CMakeLists.txt | 3 --- source/source_lcao/force_stress_lcao.cpp | 2 +- source/source_lcao/hamilt_lcao.cpp | 4 ++-- source/source_lcao/module_dftu/CMakeLists.txt | 8 ++++++++ .../dftu.hpp | 0 .../dftu_fs.cpp | 0 .../dftu_lcao.cpp | 0 .../dftu_lcao.h | 0 .../op_dftu_lcao.cpp | 0 .../op_dftu_lcao.h | 2 +- .../source_lcao/module_dftu/test/CMakeLists.txt | 17 +++++++++++++++++ .../test/dftu_lcao_test.cpp} | 0 .../module_operator_lcao/CMakeLists.txt | 3 --- .../module_operator_lcao/test/CMakeLists.txt | 10 ---------- 16 files changed, 31 insertions(+), 22 deletions(-) rename source/source_lcao/{module_operator_lcao => module_dftu}/dftu.hpp (100%) rename source/source_lcao/{module_operator_lcao => module_dftu}/dftu_fs.cpp (100%) rename source/source_lcao/{module_operator_lcao => module_dftu}/dftu_lcao.cpp (100%) rename source/source_lcao/{module_operator_lcao => module_dftu}/dftu_lcao.h (100%) rename source/source_lcao/{module_operator_lcao => module_dftu}/op_dftu_lcao.cpp (100%) rename source/source_lcao/{module_operator_lcao => module_dftu}/op_dftu_lcao.h (94%) rename source/source_lcao/{module_operator_lcao/test/test_dftu.cpp => module_dftu/test/dftu_lcao_test.cpp} (100%) diff --git a/source/source_io/module_hs/write_vxc.hpp b/source/source_io/module_hs/write_vxc.hpp index 9f8665534b3..b8368903f09 100644 --- a/source/source_io/module_hs/write_vxc.hpp +++ b/source/source_io/module_hs/write_vxc.hpp @@ -4,7 +4,7 @@ #include "source_base/parallel_reduce.h" #include "source_base/module_container/base/third_party/blas.h" #include "source_base/module_external/scalapack_connector.h" -#include "source_lcao/module_operator_lcao/op_dftu_lcao.h" +#include "source_lcao/module_dftu/op_dftu_lcao.h" #include "source_lcao/module_operator_lcao/veff_lcao.h" #include "source_hamilt/module_xc/exx_info.h" #ifdef __EXX diff --git a/source/source_io/module_hs/write_vxc_r.hpp b/source/source_io/module_hs/write_vxc_r.hpp index 1a759c14e2d..b2e91a7437b 100644 --- a/source/source_io/module_hs/write_vxc_r.hpp +++ b/source/source_io/module_hs/write_vxc_r.hpp @@ -2,7 +2,7 @@ #define __WRITE_VXC_R_H_ #include "source_io/module_parameter/parameter.h" #include "source_io/module_hs/write_hs_sparse.h" -#include "source_lcao/module_operator_lcao/op_dftu_lcao.h" +#include "source_lcao/module_dftu/op_dftu_lcao.h" #include "source_lcao/module_operator_lcao/veff_lcao.h" #include "source_lcao/spar_hsr.h" #ifdef __EXX diff --git a/source/source_lcao/CMakeLists.txt b/source/source_lcao/CMakeLists.txt index c83afa4af8b..485dd07b455 100644 --- a/source/source_lcao/CMakeLists.txt +++ b/source/source_lcao/CMakeLists.txt @@ -15,7 +15,6 @@ if(ENABLE_LCAO) module_operator_lcao/veff_lcao.cpp module_operator_lcao/veff_dh.cpp module_operator_lcao/meta_lcao.cpp - module_operator_lcao/op_dftu_lcao.cpp module_operator_lcao/deepks_lcao.cpp module_operator_lcao/op_exx_lcao.cpp module_operator_lcao/overlap.cpp @@ -32,8 +31,6 @@ if(ENABLE_LCAO) module_operator_lcao/td_pot_hybrid_fs.cpp module_operator_lcao/dspin_lcao.cpp module_operator_lcao/dspin_fs.cpp - module_operator_lcao/dftu_lcao.cpp - module_operator_lcao/dftu_fs.cpp module_operator_lcao/operator_fs_utils.cpp setup_dftu_lcao.cpp pulay_fs_center2.cpp diff --git a/source/source_lcao/force_stress_lcao.cpp b/source/source_lcao/force_stress_lcao.cpp index 64c4a963f6d..f2b4a04435b 100644 --- a/source/source_lcao/force_stress_lcao.cpp +++ b/source/source_lcao/force_stress_lcao.cpp @@ -20,7 +20,7 @@ #include "source_lcao/module_deepks/lcao_deepks_io.h" // mohan add 2024-07-22 #include "source_lcao/module_deepks/deepks_force.h" #endif -#include "source_lcao/module_operator_lcao/dftu_lcao.h" +#include "source_lcao/module_dftu/dftu_lcao.h" #include "source_lcao/module_operator_lcao/dspin_lcao.h" #include "source_lcao/module_operator_lcao/nonlocal.h" #include "source_lcao/module_operator_lcao/ekinetic.h" diff --git a/source/source_lcao/hamilt_lcao.cpp b/source/source_lcao/hamilt_lcao.cpp index 4b1e465f278..8d9fcbbb62c 100644 --- a/source/source_lcao/hamilt_lcao.cpp +++ b/source/source_lcao/hamilt_lcao.cpp @@ -31,12 +31,12 @@ #include "source_lcao/module_deltaspin/spin_constrain.h" #include "source_hamilt/module_hcontainer/hcontainer_funcs.h" #include "source_hsolver/hsolver_lcao.h" -#include "module_operator_lcao/dftu_lcao.h" +#include "module_dftu/dftu_lcao.h" #include "module_operator_lcao/dspin_lcao.h" #include "module_operator_lcao/ekinetic.h" #include "module_operator_lcao/meta_lcao.h" #include "module_operator_lcao/nonlocal.h" -#include "module_operator_lcao/op_dftu_lcao.h" +#include "module_dftu/op_dftu_lcao.h" #include "module_operator_lcao/op_exx_lcao.h" #include "module_operator_lcao/overlap.h" #include "module_operator_lcao/td_ekinetic_lcao.h" diff --git a/source/source_lcao/module_dftu/CMakeLists.txt b/source/source_lcao/module_dftu/CMakeLists.txt index 4079b358d8f..bc5af4c68e8 100644 --- a/source/source_lcao/module_dftu/CMakeLists.txt +++ b/source/source_lcao/module_dftu/CMakeLists.txt @@ -8,6 +8,14 @@ list(APPEND objects dftu_hamilt.cpp ) +if(ENABLE_LCAO) + list(APPEND objects + dftu_lcao.cpp + dftu_fs.cpp + op_dftu_lcao.cpp + ) +endif() + add_library( dftu OBJECT diff --git a/source/source_lcao/module_operator_lcao/dftu.hpp b/source/source_lcao/module_dftu/dftu.hpp similarity index 100% rename from source/source_lcao/module_operator_lcao/dftu.hpp rename to source/source_lcao/module_dftu/dftu.hpp diff --git a/source/source_lcao/module_operator_lcao/dftu_fs.cpp b/source/source_lcao/module_dftu/dftu_fs.cpp similarity index 100% rename from source/source_lcao/module_operator_lcao/dftu_fs.cpp rename to source/source_lcao/module_dftu/dftu_fs.cpp diff --git a/source/source_lcao/module_operator_lcao/dftu_lcao.cpp b/source/source_lcao/module_dftu/dftu_lcao.cpp similarity index 100% rename from source/source_lcao/module_operator_lcao/dftu_lcao.cpp rename to source/source_lcao/module_dftu/dftu_lcao.cpp diff --git a/source/source_lcao/module_operator_lcao/dftu_lcao.h b/source/source_lcao/module_dftu/dftu_lcao.h similarity index 100% rename from source/source_lcao/module_operator_lcao/dftu_lcao.h rename to source/source_lcao/module_dftu/dftu_lcao.h diff --git a/source/source_lcao/module_operator_lcao/op_dftu_lcao.cpp b/source/source_lcao/module_dftu/op_dftu_lcao.cpp similarity index 100% rename from source/source_lcao/module_operator_lcao/op_dftu_lcao.cpp rename to source/source_lcao/module_dftu/op_dftu_lcao.cpp diff --git a/source/source_lcao/module_operator_lcao/op_dftu_lcao.h b/source/source_lcao/module_dftu/op_dftu_lcao.h similarity index 94% rename from source/source_lcao/module_operator_lcao/op_dftu_lcao.h rename to source/source_lcao/module_dftu/op_dftu_lcao.h index d2ef6c9e795..99f4fae8b6d 100644 --- a/source/source_lcao/module_operator_lcao/op_dftu_lcao.h +++ b/source/source_lcao/module_dftu/op_dftu_lcao.h @@ -2,7 +2,7 @@ #define OPDFTULCAO_H #include "source_base/timer.h" -#include "operator_lcao.h" +#include "source_lcao/module_operator_lcao/operator_lcao.h" #include "source_lcao/module_dftu/dftu.h" // mohan add 20251107 namespace hamilt diff --git a/source/source_lcao/module_dftu/test/CMakeLists.txt b/source/source_lcao/module_dftu/test/CMakeLists.txt index de94b196903..e18eebb6982 100644 --- a/source/source_lcao/module_dftu/test/CMakeLists.txt +++ b/source/source_lcao/module_dftu/test/CMakeLists.txt @@ -17,3 +17,20 @@ AddTest( LIBS base device SOURCES dftu_operator_test.cpp ) + +if(ENABLE_LCAO AND ENABLE_MPI) +AddTest( + TARGET dftu_lcao_test + LIBS parameter psi base device container + SOURCES dftu_lcao_test.cpp ../dftu_lcao.cpp ../dftu_fs.cpp + ../../../source_pw/module_pwdft/dftu_base.cpp + ../../../source_hamilt/module_hcontainer/func_folding.cpp + ../../../source_hamilt/module_hcontainer/base_matrix.cpp + ../../../source_hamilt/module_hcontainer/hcontainer.cpp + ../../../source_hamilt/module_hcontainer/atom_pair.cpp + ../../../source_basis/module_ao/parallel_orbitals.cpp + ../../../source_basis/module_ao/orb_atomic_lm.cpp + ../../module_operator_lcao/test/tmp_mocks.cpp + ../../../source_hamilt/operator.cpp +) +endif() diff --git a/source/source_lcao/module_operator_lcao/test/test_dftu.cpp b/source/source_lcao/module_dftu/test/dftu_lcao_test.cpp similarity index 100% rename from source/source_lcao/module_operator_lcao/test/test_dftu.cpp rename to source/source_lcao/module_dftu/test/dftu_lcao_test.cpp diff --git a/source/source_lcao/module_operator_lcao/CMakeLists.txt b/source/source_lcao/module_operator_lcao/CMakeLists.txt index 7e09e099a03..8a6ddaeeb50 100644 --- a/source/source_lcao/module_operator_lcao/CMakeLists.txt +++ b/source/source_lcao/module_operator_lcao/CMakeLists.txt @@ -2,7 +2,6 @@ add_library( operator_ks_lcao OBJECT op_exx_lcao.cpp - op_dftu_lcao.cpp meta_lcao.cpp veff_lcao.cpp veff_dh.cpp @@ -21,8 +20,6 @@ add_library( td_pot_hybrid_fs.cpp dspin_lcao.cpp dspin_fs.cpp - dftu_lcao.cpp - dftu_fs.cpp operator_fs_utils.cpp ) diff --git a/source/source_lcao/module_operator_lcao/test/CMakeLists.txt b/source/source_lcao/module_operator_lcao/test/CMakeLists.txt index c0dc14f086f..b93390dfed8 100644 --- a/source/source_lcao/module_operator_lcao/test/CMakeLists.txt +++ b/source/source_lcao/module_operator_lcao/test/CMakeLists.txt @@ -80,16 +80,6 @@ AddTest( tmp_mocks.cpp ../../../source_hamilt/operator.cpp ) -AddTest( - TARGET MODULE_LCAO_operator_dftu_test - LIBS parameter psi base device container - SOURCES test_dftu.cpp ../dftu_lcao.cpp ../dftu_fs.cpp ../../../source_pw/module_pwdft/dftu_base.cpp ../../../source_hamilt/module_hcontainer/func_folding.cpp - ../../../source_hamilt/module_hcontainer/base_matrix.cpp ../../../source_hamilt/module_hcontainer/hcontainer.cpp ../../../source_hamilt/module_hcontainer/atom_pair.cpp - ../../../source_basis/module_ao/parallel_orbitals.cpp - ../../../source_basis/module_ao/orb_atomic_lm.cpp - tmp_mocks.cpp ../../../source_hamilt/operator.cpp -) - install(FILES parallel_operator_tests.sh DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) find_program(BASH bash) add_test(NAME MODULE_LCAO_operators_para_test