From 892df1e0a77f829aa5df82248378d41cc3b4e9b2 Mon Sep 17 00:00:00 2001 From: Xiaoyang Zhang Date: Wed, 18 Nov 2026 17:09:42 +0800 Subject: [PATCH 1/3] refactor(psi): move PW initialization orchestration into PW --- source/source_esolver/esolver_ks_lcaopw.cpp | 2 ++ source/source_esolver/esolver_ks_pw.h | 2 +- source/source_io/module_ctrl/ctrl_output_pw.h | 2 +- source/source_psi/CMakeLists.txt | 3 +-- source/source_psi/setup_psi.h | 2 +- source/source_pw/module_pwdft/CMakeLists.txt | 2 ++ .../module_pwdft}/psi_prepare.cpp | 0 .../module_pwdft}/psi_prepare.h | 9 +++++-- .../module_pwdft}/psi_prepare_base.h | 0 .../module_pwdft}/setup_psi_pw.cpp | 5 +++- .../module_pwdft}/setup_psi_pw.h | 24 +++++++++++++------ 11 files changed, 36 insertions(+), 15 deletions(-) rename source/{source_psi => source_pw/module_pwdft}/psi_prepare.cpp (100%) rename source/{source_psi => source_pw/module_pwdft}/psi_prepare.h (95%) rename source/{source_psi => source_pw/module_pwdft}/psi_prepare_base.h (100%) rename source/{source_psi => source_pw/module_pwdft}/setup_psi_pw.cpp (99%) rename source/{source_psi => source_pw/module_pwdft}/setup_psi_pw.h (94%) diff --git a/source/source_esolver/esolver_ks_lcaopw.cpp b/source/source_esolver/esolver_ks_lcaopw.cpp index 90fe4ab537d..c58709a38f3 100644 --- a/source/source_esolver/esolver_ks_lcaopw.cpp +++ b/source/source_esolver/esolver_ks_lcaopw.cpp @@ -1,4 +1,6 @@ #include "esolver_ks_lcaopw.h" + +#include "source_pw/module_pwdft/psi_prepare.h" #include "source_pw/module_pwdft/elecond.h" #include "source_io/module_parameter/input_conv.h" #include diff --git a/source/source_esolver/esolver_ks_pw.h b/source/source_esolver/esolver_ks_pw.h index a03e73c943e..415eae14232 100644 --- a/source/source_esolver/esolver_ks_pw.h +++ b/source/source_esolver/esolver_ks_pw.h @@ -1,7 +1,7 @@ #ifndef ESOLVER_KS_PW_H #define ESOLVER_KS_PW_H #include "./esolver_ks.h" -#include "source_psi/setup_psi_pw.h" // mohan add 20251012 +#include "source_pw/module_pwdft/setup_psi_pw.h" // mohan add 20251012 #include "source_pw/module_pwdft/exx_helper_base.h" #include "source_pw/module_pwdft/vsep_pw.h" diff --git a/source/source_io/module_ctrl/ctrl_output_pw.h b/source/source_io/module_ctrl/ctrl_output_pw.h index a3c05b0d4b3..901aa098921 100644 --- a/source/source_io/module_ctrl/ctrl_output_pw.h +++ b/source/source_io/module_ctrl/ctrl_output_pw.h @@ -4,7 +4,7 @@ #include "source_base/module_device/device.h" // use Device #include "source_estate/elecstate_lcao.h" // use pelec #include "source_psi/psi.h" // define psi -#include "source_psi/setup_psi_pw.h" // use Setup_Psi class +#include "source_pw/module_pwdft/setup_psi_pw.h" // use Setup_Psi class #include diff --git a/source/source_psi/CMakeLists.txt b/source/source_psi/CMakeLists.txt index 67de255887f..4d0bc5d4085 100644 --- a/source/source_psi/CMakeLists.txt +++ b/source/source_psi/CMakeLists.txt @@ -1,7 +1,6 @@ add_library(psi OBJECT psi.cpp) -add_library(psi_overall_init OBJECT setup_psi_pw.cpp setup_psi.cpp - psi_prepare.cpp) +add_library(psi_overall_init OBJECT setup_psi.cpp) add_library( psi_init OBJECT diff --git a/source/source_psi/setup_psi.h b/source/source_psi/setup_psi.h index 10628e7d3b5..f2723ee2e11 100644 --- a/source/source_psi/setup_psi.h +++ b/source/source_psi/setup_psi.h @@ -4,7 +4,7 @@ #include "source_basis/module_ao/parallel_orbitals.h" // use para_orb #include "source_cell/klist.h" #include "source_io/module_parameter/input_parameter.h" -#include "source_psi/psi_prepare.h" +#include "source_psi/psi.h" template class Setup_Psi diff --git a/source/source_pw/module_pwdft/CMakeLists.txt b/source/source_pw/module_pwdft/CMakeLists.txt index 73bbb73f0aa..4accb05d7ca 100644 --- a/source/source_pw/module_pwdft/CMakeLists.txt +++ b/source/source_pw/module_pwdft/CMakeLists.txt @@ -38,6 +38,8 @@ list( setup_pot.cpp setup_pwrho.cpp setup_pwwfc.cpp + setup_psi_pw.cpp + psi_prepare.cpp uspp_support.cpp update_cell_pw.cpp setup_dftu_pw.cpp diff --git a/source/source_psi/psi_prepare.cpp b/source/source_pw/module_pwdft/psi_prepare.cpp similarity index 100% rename from source/source_psi/psi_prepare.cpp rename to source/source_pw/module_pwdft/psi_prepare.cpp diff --git a/source/source_psi/psi_prepare.h b/source/source_pw/module_pwdft/psi_prepare.h similarity index 95% rename from source/source_psi/psi_prepare.h rename to source/source_pw/module_pwdft/psi_prepare.h index e60d2b7a8c6..7a5f6619ba7 100644 --- a/source/source_psi/psi_prepare.h +++ b/source/source_pw/module_pwdft/psi_prepare.h @@ -1,8 +1,13 @@ #ifndef PSI_PREPARE_H #define PSI_PREPARE_H -#include "source_hamilt/hamilt.h" #include "source_psi/psi_base.h" -#include "source_psi/psi_prepare_base.h" +#include "source_pw/module_pwdft/psi_prepare_base.h" + +namespace hamilt +{ +template +class Hamilt; +} namespace psi { diff --git a/source/source_psi/psi_prepare_base.h b/source/source_pw/module_pwdft/psi_prepare_base.h similarity index 100% rename from source/source_psi/psi_prepare_base.h rename to source/source_pw/module_pwdft/psi_prepare_base.h diff --git a/source/source_psi/setup_psi_pw.cpp b/source/source_pw/module_pwdft/setup_psi_pw.cpp similarity index 99% rename from source/source_psi/setup_psi_pw.cpp rename to source/source_pw/module_pwdft/setup_psi_pw.cpp index 237f0350dd2..d62983162a2 100644 --- a/source/source_psi/setup_psi_pw.cpp +++ b/source/source_pw/module_pwdft/setup_psi_pw.cpp @@ -1,4 +1,7 @@ -#include "source_psi/setup_psi_pw.h" +#include "setup_psi_pw.h" + +#include "psi_prepare.h" +#include "source_hamilt/hamilt.h" #include "source_basis/module_pw/pw_basis_k.h" #include "source_cell/klist.h" diff --git a/source/source_psi/setup_psi_pw.h b/source/source_pw/module_pwdft/setup_psi_pw.h similarity index 94% rename from source/source_psi/setup_psi_pw.h rename to source/source_pw/module_pwdft/setup_psi_pw.h index 251480785f6..c5d8c227318 100644 --- a/source/source_psi/setup_psi_pw.h +++ b/source/source_pw/module_pwdft/setup_psi_pw.h @@ -2,13 +2,23 @@ #define SETUP_PSI_PW_H #include "source_base/module_device/device.h" -#include "source_basis/module_pw/pw_basis_k.h" -#include "source_cell/klist.h" -#include "source_cell/stru_fac.h" -#include "source_cell/unitcell.h" -#include "source_hamilt/hamilt.h" -#include "source_io/module_parameter/input_parameter.h" -#include "source_psi/psi_prepare.h" +#include "source_psi/psi.h" +#include "psi_prepare_base.h" + +class UnitCell; +class K_Vectors; +class Structure_Factor; +class Input_para; +namespace ModulePW +{ +class PW_Basis_K; +} +namespace hamilt +{ +class HamiltBase; +template +class Hamilt; +} class Setup_Psi_pw { From c4faf2646d9d6b3c618776fcd3bc2936a2319e33 Mon Sep 17 00:00:00 2001 From: Xiaoyang Zhang Date: Wed, 18 Nov 2026 17:12:07 +0800 Subject: [PATCH 2/3] test(psi): cover mixed atomic initialization with CG --- source/source_pw/module_pwdft/setup_psi_pw.h | 2 +- tests/01_PW/CASES_CPU.txt | 1 + tests/01_PW/scf_psi_atomic_random/INPUT | 31 ++++++++++++++++++++ tests/01_PW/scf_psi_atomic_random/KPT | 4 +++ tests/01_PW/scf_psi_atomic_random/README | 8 +++++ tests/01_PW/scf_psi_atomic_random/STRU | 19 ++++++++++++ tests/01_PW/scf_psi_atomic_random/result.ref | 6 ++++ 7 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 tests/01_PW/scf_psi_atomic_random/INPUT create mode 100644 tests/01_PW/scf_psi_atomic_random/KPT create mode 100644 tests/01_PW/scf_psi_atomic_random/README create mode 100644 tests/01_PW/scf_psi_atomic_random/STRU create mode 100644 tests/01_PW/scf_psi_atomic_random/result.ref diff --git a/source/source_pw/module_pwdft/setup_psi_pw.h b/source/source_pw/module_pwdft/setup_psi_pw.h index c5d8c227318..f479df10710 100644 --- a/source/source_pw/module_pwdft/setup_psi_pw.h +++ b/source/source_pw/module_pwdft/setup_psi_pw.h @@ -8,7 +8,7 @@ class UnitCell; class K_Vectors; class Structure_Factor; -class Input_para; +struct Input_para; namespace ModulePW { class PW_Basis_K; diff --git a/tests/01_PW/CASES_CPU.txt b/tests/01_PW/CASES_CPU.txt index c135aaa9fca..12ad55a7869 100644 --- a/tests/01_PW/CASES_CPU.txt +++ b/tests/01_PW/CASES_CPU.txt @@ -23,6 +23,7 @@ scf_out_chg_tau 019_PW_Coulomb 020_PW_kspace 022_PW_CG +scf_psi_atomic_random 023_PW_DA 024_PW_DS 025_PW_DS_sca diff --git a/tests/01_PW/scf_psi_atomic_random/INPUT b/tests/01_PW/scf_psi_atomic_random/INPUT new file mode 100644 index 00000000000..3a0e8508216 --- /dev/null +++ b/tests/01_PW/scf_psi_atomic_random/INPUT @@ -0,0 +1,31 @@ +INPUT_PARAMETERS +#Parameters (1.General) +suffix autotest +calculation scf + +nbands 6 +symmetry 1 +pseudo_dir ../../PP_ORB + +#Parameters (2.Iteration) +ecutwfc 20 +scf_thr 1e-8 +scf_nmax 100 + + +#Parameters (3.Basis) +basis_type pw + +#Parameters (4.Smearing) +smearing_method gauss +smearing_sigma 0.002 + +#Parameters (5.Mixing) +mixing_type plain +mixing_beta 0.5 + +ks_solver cg +device cpu + +init_wfc atomic+random +pw_seed 1 diff --git a/tests/01_PW/scf_psi_atomic_random/KPT b/tests/01_PW/scf_psi_atomic_random/KPT new file mode 100644 index 00000000000..c289c0158aa --- /dev/null +++ b/tests/01_PW/scf_psi_atomic_random/KPT @@ -0,0 +1,4 @@ +K_POINTS +0 +Gamma +1 1 1 0 0 0 diff --git a/tests/01_PW/scf_psi_atomic_random/README b/tests/01_PW/scf_psi_atomic_random/README new file mode 100644 index 00000000000..34ccd933ddf --- /dev/null +++ b/tests/01_PW/scf_psi_atomic_random/README @@ -0,0 +1,8 @@ +PW initialization regression: atomic+random followed by CG subspace rotation. + +Uses the Si cell, six requested bands, and physical reference from 022_PW_CG. +The pseudopotential supplies eight atomic orbitals for this two-atom cell, so +atomic+random generates the mixed initial subspace and CG rotates it into the +six requested bands. A fixed pw_seed makes the initial guess reproducible. +Only the initial wavefunctions differ from 022_PW_CG; the converged energy +and symmetry reference and the default Autotest tolerances are unchanged. diff --git a/tests/01_PW/scf_psi_atomic_random/STRU b/tests/01_PW/scf_psi_atomic_random/STRU new file mode 100644 index 00000000000..5ab73f2c9d7 --- /dev/null +++ b/tests/01_PW/scf_psi_atomic_random/STRU @@ -0,0 +1,19 @@ +ATOMIC_SPECIES +Si 14 Si.pz-vbc.UPF + +LATTICE_CONSTANT +10.2 // add lattice constant + +LATTICE_VECTORS +0.0 0.5 0.5 +0.5 0.0 0.5 +0.5 0.5 0.0 + +ATOMIC_POSITIONS +Direct + +Si // Element type +0.0 // magnetism +2 +0.00 0.00 0.00 1 1 1 +0.25 0.25 0.25 1 1 1 diff --git a/tests/01_PW/scf_psi_atomic_random/result.ref b/tests/01_PW/scf_psi_atomic_random/result.ref new file mode 100644 index 00000000000..e73971f14e5 --- /dev/null +++ b/tests/01_PW/scf_psi_atomic_random/result.ref @@ -0,0 +1,6 @@ +etotref -198.2238296207179 +etotperatomref -99.1119148104 +pointgroupref T_d +spacegroupref O_h +nksibzref 1 +totaltimeref From ec4c1a7c9ade474d9207d5abffdf0d0442280915 Mon Sep 17 00:00:00 2001 From: Xiaoyang Zhang Date: Wed, 18 Nov 2026 17:43:29 +0800 Subject: [PATCH 3/3] test(psi): remove redundant initialization regression case --- tests/01_PW/CASES_CPU.txt | 1 - tests/01_PW/scf_psi_atomic_random/INPUT | 31 -------------------- tests/01_PW/scf_psi_atomic_random/KPT | 4 --- tests/01_PW/scf_psi_atomic_random/README | 8 ----- tests/01_PW/scf_psi_atomic_random/STRU | 19 ------------ tests/01_PW/scf_psi_atomic_random/result.ref | 6 ---- 6 files changed, 69 deletions(-) delete mode 100644 tests/01_PW/scf_psi_atomic_random/INPUT delete mode 100644 tests/01_PW/scf_psi_atomic_random/KPT delete mode 100644 tests/01_PW/scf_psi_atomic_random/README delete mode 100644 tests/01_PW/scf_psi_atomic_random/STRU delete mode 100644 tests/01_PW/scf_psi_atomic_random/result.ref diff --git a/tests/01_PW/CASES_CPU.txt b/tests/01_PW/CASES_CPU.txt index 12ad55a7869..c135aaa9fca 100644 --- a/tests/01_PW/CASES_CPU.txt +++ b/tests/01_PW/CASES_CPU.txt @@ -23,7 +23,6 @@ scf_out_chg_tau 019_PW_Coulomb 020_PW_kspace 022_PW_CG -scf_psi_atomic_random 023_PW_DA 024_PW_DS 025_PW_DS_sca diff --git a/tests/01_PW/scf_psi_atomic_random/INPUT b/tests/01_PW/scf_psi_atomic_random/INPUT deleted file mode 100644 index 3a0e8508216..00000000000 --- a/tests/01_PW/scf_psi_atomic_random/INPUT +++ /dev/null @@ -1,31 +0,0 @@ -INPUT_PARAMETERS -#Parameters (1.General) -suffix autotest -calculation scf - -nbands 6 -symmetry 1 -pseudo_dir ../../PP_ORB - -#Parameters (2.Iteration) -ecutwfc 20 -scf_thr 1e-8 -scf_nmax 100 - - -#Parameters (3.Basis) -basis_type pw - -#Parameters (4.Smearing) -smearing_method gauss -smearing_sigma 0.002 - -#Parameters (5.Mixing) -mixing_type plain -mixing_beta 0.5 - -ks_solver cg -device cpu - -init_wfc atomic+random -pw_seed 1 diff --git a/tests/01_PW/scf_psi_atomic_random/KPT b/tests/01_PW/scf_psi_atomic_random/KPT deleted file mode 100644 index c289c0158aa..00000000000 --- a/tests/01_PW/scf_psi_atomic_random/KPT +++ /dev/null @@ -1,4 +0,0 @@ -K_POINTS -0 -Gamma -1 1 1 0 0 0 diff --git a/tests/01_PW/scf_psi_atomic_random/README b/tests/01_PW/scf_psi_atomic_random/README deleted file mode 100644 index 34ccd933ddf..00000000000 --- a/tests/01_PW/scf_psi_atomic_random/README +++ /dev/null @@ -1,8 +0,0 @@ -PW initialization regression: atomic+random followed by CG subspace rotation. - -Uses the Si cell, six requested bands, and physical reference from 022_PW_CG. -The pseudopotential supplies eight atomic orbitals for this two-atom cell, so -atomic+random generates the mixed initial subspace and CG rotates it into the -six requested bands. A fixed pw_seed makes the initial guess reproducible. -Only the initial wavefunctions differ from 022_PW_CG; the converged energy -and symmetry reference and the default Autotest tolerances are unchanged. diff --git a/tests/01_PW/scf_psi_atomic_random/STRU b/tests/01_PW/scf_psi_atomic_random/STRU deleted file mode 100644 index 5ab73f2c9d7..00000000000 --- a/tests/01_PW/scf_psi_atomic_random/STRU +++ /dev/null @@ -1,19 +0,0 @@ -ATOMIC_SPECIES -Si 14 Si.pz-vbc.UPF - -LATTICE_CONSTANT -10.2 // add lattice constant - -LATTICE_VECTORS -0.0 0.5 0.5 -0.5 0.0 0.5 -0.5 0.5 0.0 - -ATOMIC_POSITIONS -Direct - -Si // Element type -0.0 // magnetism -2 -0.00 0.00 0.00 1 1 1 -0.25 0.25 0.25 1 1 1 diff --git a/tests/01_PW/scf_psi_atomic_random/result.ref b/tests/01_PW/scf_psi_atomic_random/result.ref deleted file mode 100644 index e73971f14e5..00000000000 --- a/tests/01_PW/scf_psi_atomic_random/result.ref +++ /dev/null @@ -1,6 +0,0 @@ -etotref -198.2238296207179 -etotperatomref -99.1119148104 -pointgroupref T_d -spacegroupref O_h -nksibzref 1 -totaltimeref