Skip to content

Update ABACUS from deepmodeling#353

Closed
mohanchen wants to merge 316 commits intoabacusmodeling:developfrom
deepmodeling:develop
Closed

Update ABACUS from deepmodeling#353
mohanchen wants to merge 316 commits intoabacusmodeling:developfrom
deepmodeling:develop

Conversation

@mohanchen
Copy link
Collaborator

Update ABACUS from deepmodeling

19hello and others added 30 commits October 4, 2025 12:13
…6517)

* change BFGS name and make lattice_change_cg and ions_move_cg shorter

* change input parameters

* change BFGS name and make lattice_change_cg and ions_move_cg shorter

* change input parameters

* change input parameters

* change input parameters

* change input parameters

* change input parameters

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

---------

Co-authored-by: Fei Yang <2501213217@stu.pku.edu.cn>
* feat pexsi

* fix : diag not completed

* feat

* feat: pexsi hsolver

* CMake building implemented

* Works

* adapt to the new container

* Turn off USE_PEXSI

* Update LibRI to 553c91c

* modify include files

* namespace-ize

* new inputs added

* Configure Makefile Compiling, fix typos

* Fix Makefile Intel toolchains compile errors

* Fix even more PEXSI related Makefile compiling issues

* Modify inputs and update to latest version (#2)

* run INPUT.Default() in every process in InputParaTest (#3490)

Co-authored-by: kirk0830 <67682086+kirk0830@users.noreply.github.com>

* add blas support for FindLAPACK.cmake (#3497)

* more unittest of QO: towards orbital selection (#3499)

* Fix: fix bug in mulliken charge calculation (#3503)

* fix phase

* fix case test

* Refactor: namespace Conv_Coulomb_Pot_K (#3446)

* Refactor: namespace Conv_Coulomb_Pot_K

* Refactor: namespace Conv_Coulomb_Pot_K

---------

Co-authored-by: wqzhou <33364058+WHUweiqingzhou@users.noreply.github.com>

* enable the computation of all zeros in one function call (#3449)

Co-authored-by: wqzhou <33364058+WHUweiqingzhou@users.noreply.github.com>

* replace ios.eof() by ios.good() to avoid meeting badbit and failbit in reading STRU (#3506)

* Build: add ccache to accelerate the testing process (#3509)

* Build: add ccache to accelerate the testing process

* Update test.yml

* Update test.yml

* Update test.yml

* Docs: to avoid the misunderstanding in docs (#3518)

* to avoid the misunderstanding in docs

* Update docs/quick_start/hands_on.md

Co-authored-by: Chun Cai <amoycaic@gmail.com>

---------

Co-authored-by: Chun Cai <amoycaic@gmail.com>

* Docs: fix a missing depencency in conda build env (#3508)

* Feature: Add ENABLE_RAPIDJSON option to control the output of abacus.json (#3519)

Add ENABLE_RAPIDJSON option to control the output of abacus.json

* Feature: add python wrapper for math sphbes (#3475)

* recommit for review

* add python wrapper

* remove timer since performace tests add

* Feature: support segment split in kline mode in KPT file and `out_band` band output precision control, `8` as default (#3493)

* add precision control

* correct serial version of nscf_band function

* fix issue 3482

* update unit and integrated test

* update document

* correct unittest and make compatible with false and true

* fix: bug in Autotest.sh when result.ref has no totaltimeref (#3523)

* Fix : unit test of module_xc (#3524)

* Fix: omit small magnetic moments to avoid numerical instability (#3530)

* update deltalambda

* avoid numerical error in orbMulP

* add constrain on Mi

* change case reference value

* Fix: fix multiple compiler warnings (#3515)

* Fix: add noreturn attribute to warning_quit

* Add type conversion

* fix string literal

* fix small number trunctuation

* Fix system call returned value not checked

* fix missing braket

* Refactor parameter_pool.cpp and parameter_pool.h

* remove duplicated return statements

* Change WARNING_QUIT occurances in tests

* Add warning message to help debug UT

* output the default precision flag (#3496)

Co-authored-by: kirk0830 <67682086+kirk0830@users.noreply.github.com>

* Build: Improving CMake performance for finding LibXC and ELPA (#3478)

* Fix for finding LibXC and ELPA

* For compatibility to previous routines

* syntax fix for FindELPA.cmake

* Update cmake/FindELPA.cmake

Co-authored-by: Chun Cai <amoycaic@gmail.com>

* Using CMake interface as default for finding LibXC

* update docs

* fix for FindLibxc: changing imcompatible if statement

* fix for FindLibxc: changing imcompatible if statement

* fix for FindLibxc: changing imcompatible if statement

* update docs for installing pkg-config

* Update FindLibxc.cmake

* Update FindLibxc.cmake

* remove previous LibXC routine in CMakeLists.txt

Co-authored-by: Chun Cai <amoycaic@gmail.com>

* Update easy_install.md with Makefile-built LibXC supported

* Update easy_install.md to include different behavior in different version on finding ELPA

---------

Co-authored-by: Chun Cai <amoycaic@gmail.com>

* Docs: correct some docs about mp2 smearing method (#3533)

* correct some docs about mp2 smearing method

* add docs about mv method

* Feature : printing band density (#3501)

Co-authored-by: wenfei-li <liwenfei@gmail.com>
Co-authored-by: wqzhou <33364058+WHUweiqingzhou@users.noreply.github.com>

* add some docs for PR#3501 (#3537)

* Feature: enable restart charge density mixing during SCF (#3542)

* add a new parameter mixing_restart

* do not update rho if iter==mixing_restart

* do not update rho if iter==mixing_restart-1

* reset mix and rho_mdata if iter==mixing_restart

* fix SCF exit directly since drho=0 if iter=GlobalV::MIXING_RESTART

* re-set_mixing in eachiterinit for PW and LCAO

* enable SCF restarts in esolver_ks::RUN

* add some UnitTests

* add some Docs

* new inputs added

* Update input-main.md (#3551)

Solve the format problem mentioned in issue 3543

* Build: fix compatibility issue against toolchain install (#3540)

* Fix for finding LibXC and ELPA

* For compatibility to previous routines

* syntax fix for FindELPA.cmake

* Update cmake/FindELPA.cmake

Co-authored-by: Chun Cai <amoycaic@gmail.com>

* Using CMake interface as default for finding LibXC

* update docs

* fix for FindLibxc: changing imcompatible if statement

* fix for FindLibxc: changing imcompatible if statement

* fix for FindLibxc: changing imcompatible if statement

* update docs for installing pkg-config

* Update FindLibxc.cmake

* Update FindLibxc.cmake

* remove previous LibXC routine in CMakeLists.txt

Co-authored-by: Chun Cai <amoycaic@gmail.com>

* Update easy_install.md with Makefile-built LibXC supported

* Update easy_install.md to include different behavior in different version on finding ELPA

* fix compatibility issue against toolchain

* Change default ELPA install routine to old one

---------

Co-authored-by: Chun Cai <amoycaic@gmail.com>

* Test: Configure performance tests for math libraries (#3511)

* add performace test of sphbes functions.

* fix benchmark cmake errors

* add dependencies for docker

* update docs

* add performance tests for sphbes

* add google benchmark

* rewrite benchmark tests in fixtures

* disable internal testing in benchmark

* merge benchmark into integration test

---------

Co-authored-by: StarGrys <771582678@qq.com>

* Configure Makefile Compiling, fix typos

* Fix Makefile Intel toolchains compile errors

* Fix even more PEXSI related Makefile compiling issues

* Update hsolver_pw.cpp (#3556)

when use_uspp==false, overlap matrix should be E.

* Fix: cuda build target (#3276)

* Fix: cuda buid target

* Update CMakeLists.txt

---------

Co-authored-by: Denghui Lu <denghuilu@pku.edu.cn>

---------

Co-authored-by: wqzhou <33364058+WHUweiqingzhou@users.noreply.github.com>
Co-authored-by: kirk0830 <67682086+kirk0830@users.noreply.github.com>
Co-authored-by: Haozhi Han <haozhi.han@outlook.com>
Co-authored-by: Zhao Tianqi <hongriTianqi@users.noreply.github.com>
Co-authored-by: PeizeLin <78645006+PeizeLin@users.noreply.github.com>
Co-authored-by: jinzx10 <jzx016@hotmail.com>
Co-authored-by: Chun Cai <amoycaic@gmail.com>
Co-authored-by: Peng Xingliang <91927439+pxlxingliang@users.noreply.github.com>
Co-authored-by: Jie Li <76780849+jieli-matrix@users.noreply.github.com>
Co-authored-by: Wenfei Li <38569667+wenfei-li@users.noreply.github.com>
Co-authored-by: Denghui Lu <denghuilu@pku.edu.cn>
Co-authored-by: YI Zeping <18586016708@163.com>
Co-authored-by: wenfei-li <liwenfei@gmail.com>
Co-authored-by: jingan-181 <78459531+jingan-181@users.noreply.github.com>
Co-authored-by: StarGrys <771582678@qq.com>
Co-authored-by: Haozhi Han <haozhi.han@stu.pku.edu.cn>

* Revert "Modify inputs and update to latest version"

* Update FindPEXSI.cmake to fix Comments

* Fix CI errors

* Fix CI Errors and Merge with Upstream

* Resolve Pull Request Reviews

* Fix parallel communication related issue

* Fix vars in Makefile.vars, add input tests and comments for pexsi vars

* Fix nspin > 1 cases

* Improvement: take calculated mu as new initial guess, may slightly improve performance

* Fix mistakes in the last commit

* Fix: params and features
- set default pexsi_temp
- fix md in pexsi

* fix empty lines

* Fix: move params to pexsi_solver, rename USE_PEXSI to ENABLE_PEXSI

* Docs: added docs for pexsi inputs

* Fix unit test issues in input_conv

* Change default pexsi_npole from 80 to 40

* Place pexsi_EDM in DensityMatrix, set size of pexsi_dm = 1 when GlobalV::NSPIN==4, and add comments for dmToRho

* An unit test added for DiagoPexsi

* modify for changed gint interface

* correct nspin related behaviors

* add efermi passthrough

* Revert "add efermi passthrough"

This reverts commit d7b402d.

* commits to resolve conversations related to codes

* DM and EDM pointers in pexsi now handled by diagopexsi, and copying h s matrices no longer needed

* add pexsi examples

* fix pexsi unit test (original version shouldn't run)

* add building docs for pexsi

* set cxx standard to c++14, which is required in make_unique

* Fix: Fix typo related to pexsi

* update to PPEXSIDFTDriver2

* default npoints to 1, so single core pexsi will work

* Fix Compile errors

* refactor to abandon `pdiagh`

* Fix mu_buffer and nspin

* Updates with latest

* Refactor: in ESolver_KS_PW, calculate deband in iter_finish, not in hamilt2density

* Fix: make files in consistent with upstream

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor: fix unit test

* Refactor: fix unit test

* Refactor: fix unit test

* Refactor: fix unit test

* Refactor: Remove set kvec funcs in `K_Vectors`

* Refactor: Remove final_scf

* Refactor: Fix kvecc2d/d2c

* Fix: Tests

* Fix: Tests

* Fix: Tests

* Fix: Tests

* Refactor: Final?

* Fix

* Fix

* Fix

* Fix

* Fix: Compile Error on CUDA > 12.9

* Fix: Compile Error on CUDA > 12.9

* Feature: Support linear combination of coulomb_param for EXX PW

* Fix: Fix compile issue

* Uploading hybrid gauge tddft (#6369)

* hybrid gague

* update tests

* update

* update

* update

* update

* update unit test

* fix tests

* update tests

* fix read_wfc

* fix catch_properties.sh

* fix restart

* update gpu test

* update tests

* fix

* fix input_conv

* Improve md calculation stress output in running log (#6366)

* Improve md calculation stress output in running log

* Module_IO Unittest modify

* ModuleMD Unittests modify

* modify code comment in fire_test.cpp

* maintain setprecision(8) for md stress output

* Refactor: Remove redundant Input_para from ESolver Class (#6370)

* Refactor: Replace PARAM.inp with inp in ESolver classes for consistency

* Refactor: Replace local input parameters with PARAM.inp in ESolver classes for consistency

* Refactor: Use PARAM.inp.scf_ene_thr in ESolver_KS_LCAO iter_finish method

* Revert "Refactor: Use PARAM.inp.scf_ene_thr in ESolver_KS_LCAO iter_finish method"

This reverts commit b1bd0fd.

* Revert "Refactor: Replace local input parameters with PARAM.inp in ESolver classes for consistency"

This reverts commit f4f81e3.

* Fix: Fix memory leak introduced by new gint module (#6375)

* fix memory leak

* delete copy assignment

* refactor Exx_Opt_Orb (#6378)

Co-authored-by: linpz <linpz@mail.ustc.edu.cn>

* Add use sw and fix Floating point exception  (#6372)

* remove float error in sunway

* fix ig=0

* add the sw

* change the make_dir

* unify the gg use

* fix compile bug

* add init

* temporarily remove the sunway define

* add the pesduo

* fix compile bug

* fix bug in the betar

* modify the test

* Update the output formats of rt-TDDFT (#6381)

* update the output formats of rt-TDDFT

* update the output formats of rt-TDDFT

* fix a bug

* update initialized velocities

* found some output information is still lacking in MD module

* [Refactor] Rename grid to module_grid and genelpa to module_genelpa (#6386)

* Rename grid to module_grid

* Rename genelpa to module_genelpa

* Fix cmake

* Update the outputs of geometry relaxation (#6387)

* update the output formats of rt-TDDFT

* update the output formats of rt-TDDFT

* fix a bug

* update initialized velocities

* found some output information is still lacking in MD module

* update output information

* remove some global variables in relax_driver

* update outputs

* update relaxation outputs

* update relaxation output messages

* update tests of print info

* fix a test

* fix cg outputs

* udpate cg test

* update relax tests

* update LCAO output stress format

* change update_cell.cpp algorithm, when the ion move is larger than the cell length, it is fine to proceed the relaxation calculations

* fix tests for unitcells

* update cell

* Feature: support the output of matrix representation of symm_ops (#6390)

* Feature: support output the matrix representation of symmetry operation

* Feature: support the output of matrix representation of symm_ops

* update the document

* Feature: Output real space wavefunction and partial charge density when `device=gpu` (#6391)

* Fix GPU output of out_pchg and out_wfc_norm, out_wfc_re_im

* GPU integrate test is functional again

* Optimize RT-TDDFT dipole output (#6393)

* Perf: support GPU version of cal_force_cc with LCAO basis (#6392)

* support GPU version of cal_force_cc with LCAO basis

* fix a bug

* [Refactor] Move module_lr to source_lcao and add a new folder module_external in source_base (#6388)

* Move module_lr to source_lcao

* Fix test build

* Move blas_connector to module_external

* Fix header use

* Fix internal header use

* A fierce battle with Makefile😡

* Move blacs_connector.h to module_external

* Move lapack_connector.h and lapack_wrapper.h to module_external

* Fix header usage

* Move scalapack_connector.h to module_external

* Fix a bug for the output information after relaxation (#6395)

* update the output formats of rt-TDDFT

* update the output formats of rt-TDDFT

* fix a bug

* update initialized velocities

* found some output information is still lacking in MD module

* update output information

* remove some global variables in relax_driver

* update outputs

* update relaxation outputs

* update relaxation output messages

* update tests of print info

* fix a test

* fix cg outputs

* udpate cg test

* update relax tests

* update LCAO output stress format

* change update_cell.cpp algorithm, when the ion move is larger than the cell length, it is fine to proceed the relaxation calculations

* fix tests for unitcells

* update cell

* update some function names, update output A to Angstrom

* change eV/A to eV/Angstrom

* bump version to 3.9.0.10 (#6397)

Co-authored-by: Liang Sun <50293369+sunliang98@users.noreply.github.com>

* Fix: fix exx_gamma_extrapolation error in MPI

* Fix: fix exx_gamma_extrapolation error in MPI

* Update lapack.cu

* Fix: Integrate test

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Fix: conv

* Fix: conv hard code thr for now

* Fix: conv hard code thr for now

* Fix: conv hard code thr for now

* Fix: conv hard code thr for now

* Refactor

* Refactor

* Refactor

* Refactor

* Refactor

* Mod

* Begin EXX KPAR

* Begin EXX KPAR

* Begin EXX KPAR

* Begin EXX KPAR

* Fix GPU, but so ugly...

* Fix GPU, but so ugly...

---------

Co-authored-by: zhangzhihao <1900017707@pku.edu.cn>
Co-authored-by: zhangzh-pku <64026312+zhangzh-pku@users.noreply.github.com>
Co-authored-by: wqzhou <33364058+WHUweiqingzhou@users.noreply.github.com>
Co-authored-by: kirk0830 <67682086+kirk0830@users.noreply.github.com>
Co-authored-by: Haozhi Han <haozhi.han@outlook.com>
Co-authored-by: Zhao Tianqi <hongriTianqi@users.noreply.github.com>
Co-authored-by: PeizeLin <78645006+PeizeLin@users.noreply.github.com>
Co-authored-by: jinzx10 <jzx016@hotmail.com>
Co-authored-by: Chun Cai <amoycaic@gmail.com>
Co-authored-by: Peng Xingliang <91927439+pxlxingliang@users.noreply.github.com>
Co-authored-by: Jie Li <76780849+jieli-matrix@users.noreply.github.com>
Co-authored-by: Wenfei Li <38569667+wenfei-li@users.noreply.github.com>
Co-authored-by: Denghui Lu <denghuilu@pku.edu.cn>
Co-authored-by: YI Zeping <18586016708@163.com>
Co-authored-by: wenfei-li <liwenfei@gmail.com>
Co-authored-by: jingan-181 <78459531+jingan-181@users.noreply.github.com>
Co-authored-by: StarGrys <771582678@qq.com>
Co-authored-by: Haozhi Han <haozhi.han@stu.pku.edu.cn>
Co-authored-by: Mohan Chen <mohan.chen.chen.mohan@gmail.com>
Co-authored-by: HTZhao <104255052+ESROAMER@users.noreply.github.com>
Co-authored-by: lanshuyue <140165754+lanshuyue@users.noreply.github.com>
Co-authored-by: Liang Sun <50293369+sunliang98@users.noreply.github.com>
Co-authored-by: dzzz2001 <153698752+dzzz2001@users.noreply.github.com>
Co-authored-by: linpeize <linpeize2024@163.com>
Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
Co-authored-by: liiutao <74701833+A-006@users.noreply.github.com>
Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
Co-authored-by: Critsium <tsfxwbbzxy@163.com>
Co-authored-by: Taoni Bao <baotaoni@pku.edu.cn>
Co-authored-by: Chen Nuo <49788094+Cstandardlib@users.noreply.github.com>
* update small places in charge_mixing_residual.cpp

* update charge_mixing_preconditioner

* add timers and remove some PARAM.inp.nspin

* fix problems

* add timers

* small fix

* fix a potential memory leak

* fix bug

* add ctrl_output_pw files but cannot run now

* add some interfaces in ctrl_output_pw

* keep fixing bugs

* successfully compile the codes

* finally I understand Devicegit add ../source/source_base/module_device/device.h ../source/source_io/ctrl_output_pw.cpp ../source/source_io/ctrl_output_pw.h!

* update function variables

* one step further

* move on

* update codes, done!

* fix bug

* add setup_pot

* fix bugs

* update esolver_ks_pw, add setup_pot

* update format of esolver_ks_pw.cpp

* update setup_pot for GPU version

* update esolver_ks_pw.cpp

* add setup_estate_pw in source_estate

* fix some bugs

* small update

* move teardown to deconstructor of ESolver

* fix error in passing pointers

* move teardown function to the correct place

* fix bugs

* update

* add two functions in module_pwdft

* add setup_pwrho file, and update esolver_fp

* update esolver_fp

* add teardown function in setup_pwrho

* update esolver

* move the after_all_runners() function of the base class to the end

* add TITLE for after_all_runners

* update esolver_fp, move teardown to desconstructor

* Revert "update esolver_fp, move teardown to desconstructor"

This reverts commit 8516477.

* Revert "add TITLE for after_all_runners"

This reverts commit 16ba5d2.

* Revert "move the after_all_runners() function of the base class to the end"

This reverts commit d672bca.
…_Orb` (#6561)

* Feature: add ABFS_ORBITAL and ABFS_JLES_ORBITAL in Exx_Opt_Orb

* Fix: delete exx_opt_orb_lmax=-1 unittest

---------

Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
* update small places in charge_mixing_residual.cpp

* update charge_mixing_preconditioner

* add timers and remove some PARAM.inp.nspin

* fix problems

* add timers

* small fix

* fix a potential memory leak

* fix bug

* add ctrl_output_pw files but cannot run now

* add some interfaces in ctrl_output_pw

* keep fixing bugs

* successfully compile the codes

* finally I understand Devicegit add ../source/source_base/module_device/device.h ../source/source_io/ctrl_output_pw.cpp ../source/source_io/ctrl_output_pw.h!

* update function variables

* one step further

* move on

* update codes, done!

* fix bug

* add setup_pot

* fix bugs

* update esolver_ks_pw, add setup_pot

* update format of esolver_ks_pw.cpp

* update setup_pot for GPU version

* update esolver_ks_pw.cpp

* add setup_estate_pw in source_estate

* fix some bugs

* small update

* move teardown to deconstructor of ESolver

* fix error in passing pointers

* move teardown function to the correct place

* fix bugs

* update

* add two functions in module_pwdft

* add setup_pwrho file, and update esolver_fp

* update esolver_fp

* add teardown function in setup_pwrho

* update esolver

* move the after_all_runners() function of the base class to the end

* add TITLE for after_all_runners

* update esolver_fp, move teardown to desconstructor

* Revert "update esolver_fp, move teardown to desconstructor"

This reverts commit 8516477.

* Revert "add TITLE for after_all_runners"

This reverts commit 16ba5d2.

* Revert "move the after_all_runners() function of the base class to the end"

This reverts commit d672bca.

* update esolver, move chargemixing to module_charge

* update dm pointer in esolver_ks_lcao

* reduce the charge mixing code in esolver_ks_lcao

* reduce the lines of esolver_ks_lcao

* update dm vector

* change ctrl_output_lcao to ctrl_scf_lcao

* add ctrl_runner_lcao, but cannot run

* add ctrl_runner_lcao successfully

* add ctrl_iter_lcao files

* restore esolver_ks_lcao iter_finish

* fix bugs

* update ctrl_iter_lcao

* upate, compile successfully

* fix bug

* fix bug, add GlobalC using global.h

* fix deepks compile

* update estate
* add setup_dm in module_dm

* update before_all_runners in esolver

* change setup_dm back

* add setup_exx

* fix bug

* add setup_exx in normal LCAO codes

* fix bug about p_hamilt and fix setup_exx

* fix bug

* fix bug

* eliminate exd and exc from ctrl_iter_lcao input parameters

* add setup_deepks

* update the input variables of ctrl_scf_lcao

* reconstruct the constructor of p_hamilt

* update ld

* fix a few bugs

* DeePKS has been used in operator, fix it
…6573)

* (Fix) Fixed the uninitialized error during DFT-1/2 calculations.

* During DFT-1/2 calculations, the self-energy potential vsep_cell
required for DFT-1/2 was not initialized before computing potential_new.

* The generation of the self-energy potential vsep_cell has been moved
forward to before the computation of potential_new.

* (Test) Add integration testing for DFT-1/2

* Add integration testing 01_PW/209_PW_DFTHALF for DFT-1/2
…error on DSP hardware. (#6577)

* Initial Commit

* Optimize Compilation experience on DSP
* update DFT-1/2 INPUT file

* update deepks using Setup_DeePKS class

* add write_stress in setup_deepks.h

* reduce one more #ifdefine MLALGO in ctrl_iter_lcao

* add build_overlap in setup_deepks.h

* update build_overlap in Setup_DeePKS class

* update arrays of force and stress

* remove some MLALGO

* update pulay_fs files
* Add hegvx routine

* Update hegvd_op.h/cpp to use the uniform lapackConnector

* Update docs for LAPACK connector API files

* Update docs for LAPACK connector API files
* change BFGS name and make lattice_change_cg and ions_move_cg shorter

* change input parameters

* change BFGS name and make lattice_change_cg and ions_move_cg shorter

* change input parameters

* change input parameters

* change input parameters

* change input parameters

* change input parameters

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* fix INPUT problem

* code optimazation

* fix INPUT problem

* code optimazation

* modify bfgstest code

* fixcode

---------

Co-authored-by: Fei Yang <2501213217@stu.pku.edu.cn>
* add esolver_of_tddft

* esolver_of_tddft cmakelist

* move memeber function of esolver_of_tddft to module_ofdft

* fix bug (confuse evolve_psi with evolve_phi)

* change evolve_phi with evolve_ofdft; change to vector

* details

* code optimization

* add situation of reading charge file for tdofdft

* add CD Potential

* add INPUT parameters for tdofdft

* add integrate test for TDOFDFT

* update doc file for tdofdft

* solve conflict

* type transformation

* type transformation

* move integration test for TDOFDFT to 07_OFDFT

* add judgement for nspin in TDOFDFT

* add judgement for nspin in TDOFDFT

* TDOFDFT integration test

* change type of warning

---------

Co-authored-by: Liang Sun <50293369+sunliang98@users.noreply.github.com>
* Fix: Resolve the output of Eband

* Refactor: Remove the input parameter `out_bandgap`

* Refactor: Replace PARAM.inp.nbands with this->ekb.nc in bandgap calculations
* add psi interface for pw

* update setup_psi

* update pis

* keep updating psi

* fix things

* update psi fix bugs

* update psi

* update psi

* update, now can be compiled successfully

* fix bug

* update cmake in module_psi

* update esolver_ks

* fix error introduced by esolver_ks's psi, which should be esolver_ks_pw's new psi (stp.psi)

* change function name
* Fix: Fix cal_bandgap for parallelism of k-points and band.

* Fix: Update cal_bandgap to use VBM and CBM terminology for clarity
* Add a value check for deepks_bandgap>0.

* Fix the test script for deepks_bandgap>1.
* update NEP_CPU

* update toolchain and document

* update cmake file

* update cmake file

* update test

* update toolchain script

* remove nep_cpu; update test case and toolchain script

* update unit test

* update test.yml

* update related doc.

---------

Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
Co-authored-by: Fei Yang <2501213217@stu.pku.edu.cn>
* add update_pot in source_estate

* split update_pot in rt-TDDFT into two functions, one is the original update_pot, which is replaced by update_pot function in estate, the other is save2 function used in after_iter

* fix bugs

* update
…ge (#6616)

* add update_pot in source_estate

* split update_pot in rt-TDDFT into two functions, one is the original update_pot, which is replaced by update_pot function in estate, the other is save2 function used in after_iter

* fix bugs

* update

* update esolver_ks

* small updates

* small bug fixed
* fix relax_method parameter bug

* remove vector<vector> in bfgs and remove const number

* remove vector<vector> in bfgs and remove const number

---------

Co-authored-by: Fei Yang <2501213217@stu.pku.edu.cn>
Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
… has been deleted, E_bandgap has been changed to E_gap(k), struct efermi has been changed to Efermi (#6617)

* add update_pot in source_estate

* split update_pot in rt-TDDFT into two functions, one is the original update_pot, which is replaced by update_pot function in estate, the other is save2 function used in after_iter

* fix bugs

* update

* update esolver_ks

* small updates

* small bug fixed

* update E_bandgap to E_gap(k)

* delete rho_restart file

* change setup_parameters to print_parameters

* move setup_pw.cpp to setup_pwwfc.cpp in module_pwdft

* update esolver, small things

* delete some old_gint codes in esolver

* fix bugs, update outputs

* fix bug in tests

* change efermi to Efermi in fp_energy.h

* fix bugs

* fix exd and exc in ctrl_runner_lcao

* fix cmake

* fix bug
* build: 更新 OpenMPI 和 MPICH 版本及其校验值

更新 OpenMPI 从 5.0.7 到 5.0.8 和 MPICH 从 4.3.0 到 4.3.1,并更新对应的 SHA256 校验值
同时更新 README.md 中的任务状态标记

* build(toolchain): 更新依赖库版本和配置

- 更新OpenBLAS到v0.3.30版本
- 更新ELPA到2025.06.001版本
- 将libcomm、cereal、rapidjson、libri指向master分支

* docs(toolchain): 添加ABACUS工具链开发者指南和重构方案文档

添加详细的开发者指南文档,介绍工具链的架构设计、核心功能和实现细节
包含完整的重构方案文档,提出用户友好度改进、代码去冗余、硬编码解决和错误处理统一化的解决方案

* docs(toolchain): 添加项目规则文档以明确代码质量标准和哲学

* docs(project_rules): 更新项目规则文档,添加维护指南

- 补充各stage目录的具体用途说明
- 新增代码维护时的注意事项
- 保持文档与当前项目实践一致

* refactor(toolchain): 简化数学库默认设置逻辑

移除对MKL和AOCL的自动检测,始终默认使用openblas作为数学库

* docs(toolchain): 更新GPU架构选项的说明文档

将GPU架构选项从具体的硬件型号更新为CUDA架构编号,以提供更灵活的兼容性

* feat(toolchain): 更新工具链脚本和依赖版本

refactor(toolchain): 重构工具链安装脚本,增加模块化和错误处理
docs(toolchain): 更新脚本注释和帮助信息
fix(toolchain): 修复OpenBLAS架构检测逻辑
style(toolchain): 统一代码格式和缩进

* docs(toolchain): 更新离线安装推荐说明中的日期和下载步骤

更新推荐离线安装的注释日期至2025年,并调整下载步骤顺序和描述

* fix(openblas): 仅在未找到openblas_dir时解压openblas包

* refactor(toolchain): remove test building scripts

* docs(toolchain): 添加ABACUS工具链重构验证报告和进度报告

* feat(工具链): 添加GCC离线安装支持并优化依赖下载逻辑

添加对GCC离线安装的支持,引入repack_filename变量用于打包包含依赖的GCC源码
优化依赖下载逻辑,优先尝试官方源,失败后回退到镜像源
当检测到无网络连接时跳过依赖下载以支持纯离线模式

* docs(toolchain): 添加废弃警告提示并引导迁移到新版本脚本

* feat(工具链): 优化工具链配置管理和安装脚本

- 添加版本配置导出功能以支持阶段脚本
- 优化OpenBLAS架构检测逻辑,提前解压包
- 修复版本验证中的包名大小写问题
- 为ELPA和LibXC添加包变量提前定义
- 改进配置验证器,支持MKL作为ScaLAPACK替代
- 统一多个安装脚本的包变量定义位置
- 重构包版本导出逻辑,动态构建版本字符串
- 更新工具链模板脚本,添加版本控制和执行模式
- 完善文档,记录GCC脚本优化和网络处理改进
- 重构配置管理器,支持更灵活的数学库和MPI设置

* refactor(工具链): 优化脚本架构并修复ELPA与MKL集成问题

重构工具链脚本实现模块化架构,修复ELPA在使用MKL时的BLACS检测问题。主要变更包括:
1. 移除过时注释和冗余代码
2. 为所有安装脚本添加pack-run模式支持
3. 优化MKL环境变量设置,适配不同MPI实现
4. 修复ELPA安装时的SCALAPACK配置传递
5. 更新Intel编译器默认使用ifx
6. 改进配置管理器的静默模式处理

重构后工具链更易维护且完全兼容现有功能,为后续扩展奠定基础

* feat(toolchain): 更新工具链版本至2025.3并重构构建脚本

更新VERSION文件至2025.3版本
统一各工具链脚本中的作者和日期信息
重构构建脚本以支持MLALGO功能并优化GPU支持
添加ABACUS构建脚本自动生成功能开发文档

* docs(toolchain): 更新文档和作者信息

refactor(ui): 改进终端用户界面和输出信息
- 添加彩色输出和更美观的进度显示
- 优化安装完成后的使用说明格式
- 增强MPI检测时的信息显示

chore: 移除过时的离线安装说明

* docs(toolchain): 在构建脚本中注释CUDA编译器路径选项

* feat(工具链): 新增智能证书验证策略和并行编译控制功能

新增DOWNLOAD_CERT_POLICY环境变量支持strict|smart|skip三种证书验证模式
移除-j参数并改用NPROCS_OVERWRITE环境变量控制并行编译核数
更新README文档详细说明新功能和使用方法

* refactor(toolchain): 统一MPI实现参数名并更新文档

将各工具链脚本中的MPI实现参数从`MPI_IMPLEMENTATION`统一改为`MPI_MODE`以保持一致性
更新README文档,添加新功能说明并删除过时的Details.md文件

* [Feature] Add NEP as esolver (#6603)

* update NEP_CPU

* update toolchain and document

* update cmake file

* update cmake file

* update test

* update toolchain script

* remove nep_cpu; update test case and toolchain script

* update unit test

* update test.yml

* update related doc.

---------

Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>

* feat(ui): 优化用户界面兼容性和错误提示

增加Unicode图标的三级fallback策略,确保在不同终端环境下的显示兼容性
增强GCC版本检查的错误提示,提供详细的问题分析和解决方案
添加glibc版本检测和系统信息摘要功能
改进版本号显示功能,支持智能查找VERSION文件
更新帮助文档和进度报告,反映最新优化内容

* refactor(toolchain): 将NEP选项加入注释

* style(toolchain): 统一调整可选特性的变量顺序

* feat(toolchain): 添加NEP包支持并更新相关文档

在工具链中添加NEP(Neural Evolution Potential)包支持,包括:
1. 在package_versions.sh中添加版本管理
2. 更新config_manager.sh中的配置项
3. 修改install_nep.sh使用集中版本管理
4. 更新用户界面显示
5. 添加NEP集成案例文档
6. 更新README中的包列表和文档

此变更使工具链支持NEP包的安装和配置,为ABACUS提供机器学习势能支持

* feat(toolchain): 增强package-version参数支持多键值对

修复--package-version参数仅支持单个键值对的问题,现支持两种写法:
1. 多个独立参数:--package-version PKG1:VER1 --package-version PKG2:VER2
2. 单个参数多键值对:--package-version PKG1:VER1 PKG2:VER2

同时更新相关文档说明和README,添加环境变量使用注意事项

* add system option for libcomm, libri and libnpy

* refactor(toolchain): 对stage4的头文件添加system和path选项支持

* fix(toolchain): 移除合并冲突标记并改进配置验证

重构配置验证逻辑以更精确检查cmake依赖
当使用系统cmake时增加额外检查

* feat(validator): 优化系统检测与错误计数机制

- 新增错误组概念,区分逻辑错误与描述行,提供准确错误计数
- 实现智能cmake检查,根据用户配置进行条件验证和版本检测
- 增强GCC工具链验证,包括版本一致性检查和最小版本要求
- 提供更详细的错误信息和解决方案指导

* refactor(toolchain): 统一安装脚本中环境变量设置的格式和顺序

确保在system选项下,环境变量不会被额外写入setup中

* move a doc

* chore: remove Trae Files

* fix(install_nep.sh):
unify --pack-run exit way

* refactor(toolchain):  clean the redundant and out-dated comments

* Update paths in install_cereal.sh for include directory

Modify the wrong paths.

* Fix path setup for cereal installation script

* Fix CEREAL include path in build script

The Include  Dir should be "include/", not "include/cereal/".

---------

Co-authored-by: m0sey <61280022+MoseyQAQ@users.noreply.github.com>
Co-authored-by: Mohan Chen <mohanchen@pku.edu.cn>
Co-authored-by: Levi Zhou <31941107+ZhouXY-PKU@users.noreply.github.com>
* refactor(scripts): Rename uncorrect FAST_MATH_* env to MATH_*

* docs(toolchain): correct NEP description

* fix(scripts): correct all FAST_MATH to MATH

* fix: 下载失败时删除临时文件

* docs(toolchain): 更新LibTorch版本注释并统一MLALGO支持描述

* chore: update .gitignore to ignore .trae

* feat(用户界面): 在系统摘要中添加CPU型号信息

添加CPU型号检测逻辑,通过lscpu或/proc/cpuinfo获取处理器信息并显示在系统摘要中,方便用户查看完整的硬件信息

* docs(toolchain): 更新支持的编译器及特性说明

更新README中关于GNU、Intel和AMD工具链的编译器要求及特性描述,使其更准确

* refactor(toolchain): refine the comments of the main scripts and mark removal of origin scripts in the future.

* docs(toolchain): modify and add comments for libtorch
ZhouXY-PKU and others added 28 commits February 27, 2026 16:25
Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v4...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [crazy-max/ghaction-github-pages](https://github.com/crazy-max/ghaction-github-pages) from 4 to 5.
- [Release notes](https://github.com/crazy-max/ghaction-github-pages/releases)
- [Commits](crazy-max/ghaction-github-pages@v4...v5)

---
updated-dependencies:
- dependency-name: crazy-max/ghaction-github-pages
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 6 to 7.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](actions/upload-artifact@v6...v7)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…e GPU calculations (#6995)

* Optimize memory management of RT-TDDFT to enable larger scale calculation

* Fixed a bug where calculation results were incorrect due to not allocating H matrix on device
* Refactor cg interface from Tensor to T *

* Remove redundant code

* Remove redundant code
* fix some small places in source_base

* refactor(cell_index): replace std::out_of_range with WARNING_QUIT

Replace standard exception handling with project-specific error handling
in cell_index.cpp to comply with ABACUS code style guidelines.

Changes:
- Replace 3 instances of 'throw std::out_of_range' with ModuleBase::WARNING_QUIT
  in functions: iw2l(), iw2z(), iw2m()
- Remove unnecessary #include <stdexcept>
- Fix incorrect error message strings in iw2z() and iw2m() (was 'iw2l')

This change follows the cpp-code-style skill rule that requires using
ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions for
error handling in the ABACUS project.

* refactor(cell_index): add const qualifier to member functions

Add const qualifier to all getter and helper member functions in
CellIndex class to improve const-correctness according to cpp-code-style
skill guidelines.

Changes in cell_index.h:
- Add const to all public getter functions: get_nat(), get_ntype(),
  get_nw(), get_iwt(), get_maxL(), get_nchi(), get_atom_label()
- Add const to write_orb_info() and change parameter to const reference
- Add const to private helper functions: iat2it(), iat2ia(), iw2l(),
  iw2z(), iw2m()

Changes in cell_index.cpp:
- Update all function definitions to match header declarations
- Change write_orb_info parameter from std::string to const std::string&

This follows the ABACUS code style rule that getter functions and
functions that do not modify member state should be marked const.

* fix(density_matrix): 使用WARNING_QUIT替代throw语句

- 在density_matrix.cpp中添加了tool_quit.h头文件
- 将第616行的throw std::string替换为ModuleBase::WARNING_QUIT
- 统一了项目的错误处理方式,符合ABACUS代码规范

修改文件:
- source/source_estate/module_dm/density_matrix.cpp

影响范围:错误处理流程

* fix(symmetry_rotation): 修复C++14泛型lambda语法,改为C++11兼容写法

- 将泛型lambda [](auto x) 改为 [](double x)
- 符合ABACUS项目只支持C++11标准的要求
- Matrix3的元素类型为double,无需泛型

修改文件:
- source/source_lcao/module_ri/module_exx_symmetry/symmetry_rotation_output.cpp

* refactor(restart): replace std::runtime_error with WARNING_QUIT

Replace standard exception handling with project-specific error handling
in restart.cpp to comply with cpp-code-style skill guidelines.

Changes:
- Replace 4 instances of 'throw std::runtime_error' with ModuleBase::WARNING_QUIT
  in functions: write_file2() and read_file2()
- Remove unnecessary #include <stdexcept>
- Add #include "source_base/tool_quit.h"

This follows the ABACUS code style rule that requires using
ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions.

* refactor(write_libxc_r): replace std::exception with WARNING_QUIT

Replace standard exception handling with project-specific error handling
in write_libxc_r.cpp to comply with cpp-code-style skill guidelines.

Changes:
- Replace 9 instances of throw with ModuleBase::WARNING_QUIT
  - throw std::domain_error -> WARNING_QUIT
  - throw std::invalid_argument -> WARNING_QUIT
- Remove #include <stdexcept>
- Add #include "source_base/tool_quit.h"

This follows the ABACUS code style rule that requires using
ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions.

* style: unify code indentation to 4-space in source_md files

- Replace tabs with 4 spaces in md_func.cpp (lines 198-209)
- Replace tabs with 4 spaces in md_base.cpp (line 65)
- Replace tabs with 4 spaces in run_md.cpp (lines 59-61)

* refactor(source_io): replace std::exception with WARNING_QUIT

Replace standard exception handling with project-specific error handling
in source_io directory to comply with cpp-code-style skill guidelines.

Changes:
- Replace all instances of throw with ModuleBase::WARNING_QUIT
  - throw std::runtime_error -> WARNING_QUIT
  - throw std::logic_error -> WARNING_QUIT
  - throw std::invalid_argument -> WARNING_QUIT
  - throw std::domain_error -> WARNING_QUIT
- Remove unnecessary #include <stdexcept>
- Add #include "source_base/tool_quit.h" where needed

Files modified:
- module_restart/restart.cpp (4 instances)
- module_chgpot/write_libxc_r.cpp (9 instances)
- module_wannier/to_wannier90_lcao.h (1 instance)
- module_wannier/to_wannier90_lcao_in_pw.h (1 instance)
- module_wannier/to_wannier90_pw.h (1 instance)
- module_wannier/to_wannier90.cpp (1 instance)
- module_unk/berryphase.h (1 instance)
- module_parameter/read_input_tool.h (1 instance)
- module_parameter/input_conv.cpp (1 instance)

This follows the ABACUS code style rule that requires using
ModuleBase::WARNING/WARNING_QUIT instead of standard exceptions.

* revert(vector3): 撤销operator==的eps精度比较修改

- 恢复Vector3的operator==为直接比较
- 移除之前添加的eps精度比较逻辑

修改文件:
- source/source_base/vector3.h

* Revert "refactor(source_io): replace std::exception with WARNING_QUIT"

This reverts commit 39811c4.

* Revert "refactor(write_libxc_r): replace std::exception with WARNING_QUIT"

This reverts commit f0558c5.

* Revert "refactor(restart): replace std::runtime_error with WARNING_QUIT"

This reverts commit 5682e00.

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
Bumps [docker/setup-buildx-action](https://github.com/docker/setup-buildx-action) from 3 to 4.
- [Release notes](https://github.com/docker/setup-buildx-action/releases)
- [Commits](docker/setup-buildx-action@v3...v4)

---
updated-dependencies:
- dependency-name: docker/setup-buildx-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [docker/login-action](https://github.com/docker/login-action) from 3 to 4.
- [Release notes](https://github.com/docker/login-action/releases)
- [Commits](docker/login-action@v3...v4)

---
updated-dependencies:
- dependency-name: docker/login-action
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [docker/metadata-action](https://github.com/docker/metadata-action) from 5 to 6.
- [Release notes](https://github.com/docker/metadata-action/releases)
- [Commits](docker/metadata-action@v5...v6)

---
updated-dependencies:
- dependency-name: docker/metadata-action
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [docker/build-push-action](https://github.com/docker/build-push-action) from 6 to 7.
- [Release notes](https://github.com/docker/build-push-action/releases)
- [Commits](docker/build-push-action@v6...v7)

---
updated-dependencies:
- dependency-name: docker/build-push-action
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Update default value for ks_solver

* Update default value for ks_solver

* Update default value for ks_solver

* Update default value for ks_solver
* refactor(esolver): extract update_cell_pw function from esolver_ks_pw

- Create new files update_cell_pw.h and update_cell_pw.cpp in source_pw/module_pwdft
- Extract cell parameter update logic from ESolver_KS_PW::before_scf()
- The new function handles:
  1. Rescaling non-local pseudopotential (ppcell.rescale_vnl)
  2. Reinitializing plane wave basis grids (pw_wfc->initgrids/initparameters/collect_local_pw)
- Keep psi initialization (p_psi_init->prepare_init) in esolver to avoid template dependency
- Update CMakeLists.txt and Makefile.Objects for new source files

This refactoring improves code organization by moving PW-specific cell update
logic out of the esolver, making the esolver code cleaner and more focused
on high-level workflow control.

* refactor(esolver): extract EXX initialization into Exx_Helper::init

- Add init() function to Exx_Helper class for EXX initialization
- The init function handles:
  1. Check if calculation type is scf/relax/cell-relax/md
  2. Check if cal_exx is enabled
  3. Set XC first loop if separate_loop is true
  4. Set wg pointer for EXX calculation
- Simplify ESolver_KS_PW::before_all_runners() by calling exx_helper.init()
- Move EXX-specific logic out of esolver, improving code organization

This refactoring makes the esolver code cleaner and more focused
on high-level workflow control.

* refactor(esolver): extract DFT+U initialization into pw::iter_init_dftu_pw

- Create new files dftu_pw.h and dftu_pw.cpp in source_pw/module_pwdft
- Extract DFT+U occupation update logic from ESolver_KS_PW::iter_init()
- The new function handles:
  1. Check if DFT+U is enabled
  2. Check iteration and step conditions
  3. Call cal_occ_pw for occupation calculation
  4. Output DFT+U results
- Use void* for psi parameter to avoid template dependency
- Update CMakeLists.txt and Makefile.Objects for new source files

This refactoring improves code organization by moving DFT+U specific
logic out of the esolver, making the esolver code cleaner and more
focused on high-level workflow control.

* refactor(esolver): extract DeltaSpin lambda loop into pw::run_deltaspin_lambda_loop

- Create new files deltaspin_pw.h and deltaspin_pw.cpp in source_pw/module_pwdft
- Extract DeltaSpin lambda loop logic from ESolver_KS_PW::hamilt2rho_single()
- The new function handles:
  1. Check if DeltaSpin (sc_mag_switch) is enabled
  2. Get SpinConstrain singleton instance
  3. Run lambda loop to constrain atomic magnetic moments
  4. Return skip_solve flag to control solver execution
- Add Doxygen-style comments in English
- Update CMakeLists.txt and Makefile.Objects for new source files

This refactoring improves code organization by moving DeltaSpin-specific
logic out of the esolver, making the esolver code cleaner and more
focused on high-level workflow control.

* refactor(esolver): extract DeltaSpin oscillation check into pw::check_deltaspin_oscillation

- Add check_deltaspin_oscillation() function to deltaspin_pw.h/cpp
- Extract DeltaSpin SCF oscillation check logic from ESolver_KS_PW::iter_finish()
- The new function handles:
  1. Check if DeltaSpin (sc_mag_switch) is enabled
  2. Get SpinConstrain singleton instance
  3. Detect SCF oscillation using if_scf_oscillate()
  4. Set mixing_restart_step if oscillation detected
- Add Doxygen-style comments in English

This refactoring consolidates all DeltaSpin-related functions in one place,
making the code more modular and easier to maintain.

* refactor(esolver): extract EXX before_scf setup into Exx_Helper::before_scf

- Add before_scf() function to Exx_Helper class
- Extract EXX setup logic from ESolver_KS_PW::before_scf()
- The new function handles:
  1. Check if calculation type is valid (scf/relax/cell-relax/md)
  2. Check if EXX is enabled and basis type is PW
  3. Set EXX helper to Hamiltonian
  4. Set psi for EXX calculation
- Use void* for p_hamilt parameter to avoid circular dependency
- Add Doxygen-style comments in English

This refactoring consolidates EXX-related setup logic in the Exx_Helper class,
making the code more modular and easier to maintain.

* refactor(esolver): extract EXX iter_finish logic into Exx_Helper::iter_finish

- Add iter_finish() function to Exx_Helper class
- Extract EXX convergence handling logic from ESolver_KS_PW::iter_finish()
- The new function handles:
  1. Check if EXX is enabled
  2. Handle separate_loop mode for EXX convergence
  3. Calculate EXX energy difference for energy threshold
  4. Update potential if SCF not converged
  5. Increment EXX iteration counter
- Use Charge* and void* parameters to avoid circular dependency
- Add Doxygen-style comments in English

This refactoring consolidates all EXX-related functions in the Exx_Helper class,
making the code more modular and easier to maintain.

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
* Allow compile LCAO version on DSP

* Nooo, I shouldn't have modified the INPUT file
* small format changes

* refactor(esolver): extract charge density symmetrization to Symmetry_rho::symmetrize_rho

- Add static method symmetrize_rho() in Symmetry_rho class
- Replace 7 duplicate code blocks with single function call
- Simplify code from 35 lines to 7 lines (80% reduction)
- Improve code readability and maintainability

Modified files:
- source_estate/module_charge/symmetry_rho.h: add static method declaration
- source_estate/module_charge/symmetry_rho.cpp: implement static method
- source_esolver/esolver_ks_lcao.cpp: 2 calls updated
- source_esolver/esolver_ks_pw.cpp: 1 call updated
- source_esolver/esolver_ks_lcao_tddft.cpp: 1 call updated
- source_esolver/esolver_ks_lcaopw.cpp: 1 call updated
- source_esolver/esolver_of.cpp: 1 call updated
- source_esolver/esolver_sdft_pw.cpp: 1 call updated

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DeltaSpin lambda loop to deltaspin_lcao module

- Create new files deltaspin_lcao.h/cpp in module_deltaspin
- Extract DeltaSpin lambda loop logic from ESolver_KS_LCAO
- Simplify code from 18 lines to 1 line in hamilt2rho_single
- Separate LCAO and PW implementations for DeltaSpin

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace inline code with function call
- source_lcao/module_deltaspin/CMakeLists.txt: add new source file

New files:
- source_lcao/module_deltaspin/deltaspin_lcao.h: function declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: function implementation

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): complete DeltaSpin refactoring in LCAO

- Add init_deltaspin_lcao() function for DeltaSpin initialization
- Add cal_mi_lcao_wrapper() function for magnetic moment calculation
- Refactor all DeltaSpin-related code in esolver_ks_lcao.cpp
- Simplify code from 29 lines to 3 lines (90% reduction)

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 3 code blocks with function calls
- source_lcao/module_deltaspin/deltaspin_lcao.h: add 2 new function declarations
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: implement 2 new functions

This completes the DeltaSpin refactoring for LCAO method:
1. init_deltaspin_lcao() - initialize DeltaSpin calculation
2. cal_mi_lcao_wrapper() - calculate magnetic moments
3. run_deltaspin_lambda_loop_lcao() - run lambda loop optimization

All functions follow the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DFT+U code to dftu_lcao module

- Create new files dftu_lcao.h/cpp in source_lcao directory
- Add init_dftu_lcao() function for DFT+U initialization
- Add finish_dftu_lcao() function for DFT+U finalization
- Simplify code from 32 lines to 2 lines in esolver_ks_lcao.cpp
- Remove conditional checks from ESolver, move them to functions

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 2 code blocks with function calls
- source_lcao/CMakeLists.txt: add new source file

New files:
- source_lcao/dftu_lcao.h: function declarations
- source_lcao/dftu_lcao.cpp: function implementations

This refactoring prepares for unifying old and new DFT+U implementations:
- Old DFT+U: source_lcao/module_dftu/
- New DFT+U: source_lcao/module_operator_lcao/op_dftu_lcao.cpp

All functions follow ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract diagonalization parameters setup to hsolver module

- Create new files diago_params.h/cpp in source_hsolver directory
- Add setup_diago_params_pw() function for PW diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_ks_pw.cpp
- Encapsulate diagonalization parameter setup logic

Modified files:
- source_esolver/esolver_ks_pw.cpp: replace inline code with function call
- source_hsolver/CMakeLists.txt: add new source file

New files:
- source_hsolver/diago_params.h: function declaration
- source_hsolver/diago_params.cpp: function implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* fix(deltaspin): add sc_mag_switch check in cal_mi_lcao_wrapper

- Add Input_para parameter to cal_mi_lcao_wrapper function
- Add sc_mag_switch check to avoid calling cal_mi_lcao when DeltaSpin is disabled
- Fix 'atomCounts is not set' error in non-DeltaSpin calculations
- Update function call in esolver_ks_lcao.cpp

This fix resolves the CI/CD failure caused by commit 2a520e3.
The root cause was that cal_mi_lcao_wrapper was called without checking
sc_mag_switch, leading to uninitialized atomCounts error.

Modified files:
- source_esolver/esolver_ks_lcao.cpp: update function call
- source_lcao/module_deltaspin/deltaspin_lcao.h: add parameter
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add check

This follows the refactoring principle: preserve original condition checks
when extracting code to wrapper functions.

* fix(deltaspin): add #ifdef __LCAO for conditional compilation

- Add #ifdef __LCAO conditional compilation in init_deltaspin_lcao and cal_mi_lcao_wrapper
- Fix parameter order in init_sc call for LCAO and non-LCAO builds
- Fix undefined reference to cal_mi_lcao in non-LCAO build

This fix resolves CI/CD compilation errors in both build_5pt (with __LCAO) and build_1p (without __LCAO) environments.

The The root cause was 1. init_sc has different parameter order in LCAO vs non-LCAO builds
   - LCAO: psi, dm, pelec
   - non-LCAO: psi, pelec
  2. cal_mi_lcao is only defined in LCAO build

Modified files:
- source_hsolver/diago_params.h: add setup_diago_params_sdft declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add conditional compilation

This follows the refactoring principle: handle conditional compilation properly
when code has different implementations for different build configurations.

* refactor(esolver): extract SDFT diagonalization parameters setup

- Add setup_diago_params_sdft() function for SDFT diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_sdft_pw.cpp
- Encapsulate diagonalization parameter setup logic for SDFT

Modified files:
- source_esolver/esolver_sdft_pw.cpp: replace inline code with function call
- source_hsolver/diago_params.cpp: add setup_diago_params_sdft implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

Note: SDFT has different parameter setup logic compared to PW:
- Different need_subspace condition
- No SCF_ITER setting
- Always set PW_DIAG_NMAX (no nscf check)

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
* small format changes

* refactor(esolver): extract charge density symmetrization to Symmetry_rho::symmetrize_rho

- Add static method symmetrize_rho() in Symmetry_rho class
- Replace 7 duplicate code blocks with single function call
- Simplify code from 35 lines to 7 lines (80% reduction)
- Improve code readability and maintainability

Modified files:
- source_estate/module_charge/symmetry_rho.h: add static method declaration
- source_estate/module_charge/symmetry_rho.cpp: implement static method
- source_esolver/esolver_ks_lcao.cpp: 2 calls updated
- source_esolver/esolver_ks_pw.cpp: 1 call updated
- source_esolver/esolver_ks_lcao_tddft.cpp: 1 call updated
- source_esolver/esolver_ks_lcaopw.cpp: 1 call updated
- source_esolver/esolver_of.cpp: 1 call updated
- source_esolver/esolver_sdft_pw.cpp: 1 call updated

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DeltaSpin lambda loop to deltaspin_lcao module

- Create new files deltaspin_lcao.h/cpp in module_deltaspin
- Extract DeltaSpin lambda loop logic from ESolver_KS_LCAO
- Simplify code from 18 lines to 1 line in hamilt2rho_single
- Separate LCAO and PW implementations for DeltaSpin

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace inline code with function call
- source_lcao/module_deltaspin/CMakeLists.txt: add new source file

New files:
- source_lcao/module_deltaspin/deltaspin_lcao.h: function declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: function implementation

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): complete DeltaSpin refactoring in LCAO

- Add init_deltaspin_lcao() function for DeltaSpin initialization
- Add cal_mi_lcao_wrapper() function for magnetic moment calculation
- Refactor all DeltaSpin-related code in esolver_ks_lcao.cpp
- Simplify code from 29 lines to 3 lines (90% reduction)

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 3 code blocks with function calls
- source_lcao/module_deltaspin/deltaspin_lcao.h: add 2 new function declarations
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: implement 2 new functions

This completes the DeltaSpin refactoring for LCAO method:
1. init_deltaspin_lcao() - initialize DeltaSpin calculation
2. cal_mi_lcao_wrapper() - calculate magnetic moments
3. run_deltaspin_lambda_loop_lcao() - run lambda loop optimization

All functions follow the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DFT+U code to dftu_lcao module

- Create new files dftu_lcao.h/cpp in source_lcao directory
- Add init_dftu_lcao() function for DFT+U initialization
- Add finish_dftu_lcao() function for DFT+U finalization
- Simplify code from 32 lines to 2 lines in esolver_ks_lcao.cpp
- Remove conditional checks from ESolver, move them to functions

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 2 code blocks with function calls
- source_lcao/CMakeLists.txt: add new source file

New files:
- source_lcao/dftu_lcao.h: function declarations
- source_lcao/dftu_lcao.cpp: function implementations

This refactoring prepares for unifying old and new DFT+U implementations:
- Old DFT+U: source_lcao/module_dftu/
- New DFT+U: source_lcao/module_operator_lcao/op_dftu_lcao.cpp

All functions follow ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract diagonalization parameters setup to hsolver module

- Create new files diago_params.h/cpp in source_hsolver directory
- Add setup_diago_params_pw() function for PW diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_ks_pw.cpp
- Encapsulate diagonalization parameter setup logic

Modified files:
- source_esolver/esolver_ks_pw.cpp: replace inline code with function call
- source_hsolver/CMakeLists.txt: add new source file

New files:
- source_hsolver/diago_params.h: function declaration
- source_hsolver/diago_params.cpp: function implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* fix(deltaspin): add sc_mag_switch check in cal_mi_lcao_wrapper

- Add Input_para parameter to cal_mi_lcao_wrapper function
- Add sc_mag_switch check to avoid calling cal_mi_lcao when DeltaSpin is disabled
- Fix 'atomCounts is not set' error in non-DeltaSpin calculations
- Update function call in esolver_ks_lcao.cpp

This fix resolves the CI/CD failure caused by commit 2a520e3.
The root cause was that cal_mi_lcao_wrapper was called without checking
sc_mag_switch, leading to uninitialized atomCounts error.

Modified files:
- source_esolver/esolver_ks_lcao.cpp: update function call
- source_lcao/module_deltaspin/deltaspin_lcao.h: add parameter
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add check

This follows the refactoring principle: preserve original condition checks
when extracting code to wrapper functions.

* fix(deltaspin): add #ifdef __LCAO for conditional compilation

- Add #ifdef __LCAO conditional compilation in init_deltaspin_lcao and cal_mi_lcao_wrapper
- Fix parameter order in init_sc call for LCAO and non-LCAO builds
- Fix undefined reference to cal_mi_lcao in non-LCAO build

This fix resolves CI/CD compilation errors in both build_5pt (with __LCAO) and build_1p (without __LCAO) environments.

The The root cause was 1. init_sc has different parameter order in LCAO vs non-LCAO builds
   - LCAO: psi, dm, pelec
   - non-LCAO: psi, pelec
  2. cal_mi_lcao is only defined in LCAO build

Modified files:
- source_hsolver/diago_params.h: add setup_diago_params_sdft declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add conditional compilation

This follows the refactoring principle: handle conditional compilation properly
when code has different implementations for different build configurations.

* refactor(esolver): extract SDFT diagonalization parameters setup

- Add setup_diago_params_sdft() function for SDFT diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_sdft_pw.cpp
- Encapsulate diagonalization parameter setup logic for SDFT

Modified files:
- source_esolver/esolver_sdft_pw.cpp: replace inline code with function call
- source_hsolver/diago_params.cpp: add setup_diago_params_sdft implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

Note: SDFT has different parameter setup logic compared to PW:
- Different need_subspace condition
- No SCF_ITER setting
- Always set PW_DIAG_NMAX (no nscf check)

* refactor(hamilt): introduce HamiltBase non-template base class

- Create HamiltBase as a non-template base class for Hamilt<T, Device>
- Modify Hamilt<T, Device> to inherit from HamiltBase
- Change ESolver_KS::p_hamilt type from Hamilt<T, Device>* to HamiltBase*
- Add static_cast where needed when passing p_hamilt to functions expecting Hamilt<T, Device>*

This is the first step towards removing template parameters from ESolver.

Modified files:
- source/source_esolver/esolver_ks.h
- source/source_esolver/esolver_ks_lcaopw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_sdft_pw.cpp
- source/source_hamilt/hamilt.h

New files:
- source/source_hamilt/hamilt_base.h

* refactor(esolver): add static_cast for p_hamilt in esolver files

- Add static_cast<hamilt::Hamilt<T>*> when passing p_hamilt to functions
  expecting Hamilt<T, Device>* type
- Split long cast statements into multiple lines for better readability
- Files modified:
  - esolver_ks_pw.cpp: setup_pot, stp.init calls
  - esolver_ks_lcao.cpp: init_chg_hr, hsolver_lcao_obj.solve calls
  - esolver_ks_lcao_tddft.cpp: solve_psi, cal_edm_tddft, matrix calls
  - esolver_gets.cpp: ops access, output_SR call

This follows the HamiltBase refactoring strategy where p_hamilt is stored
as HamiltBase* and cast to Hamilt<T, Device>* when needed.

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
* small format changes

* refactor(esolver): extract charge density symmetrization to Symmetry_rho::symmetrize_rho

- Add static method symmetrize_rho() in Symmetry_rho class
- Replace 7 duplicate code blocks with single function call
- Simplify code from 35 lines to 7 lines (80% reduction)
- Improve code readability and maintainability

Modified files:
- source_estate/module_charge/symmetry_rho.h: add static method declaration
- source_estate/module_charge/symmetry_rho.cpp: implement static method
- source_esolver/esolver_ks_lcao.cpp: 2 calls updated
- source_esolver/esolver_ks_pw.cpp: 1 call updated
- source_esolver/esolver_ks_lcao_tddft.cpp: 1 call updated
- source_esolver/esolver_ks_lcaopw.cpp: 1 call updated
- source_esolver/esolver_of.cpp: 1 call updated
- source_esolver/esolver_sdft_pw.cpp: 1 call updated

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DeltaSpin lambda loop to deltaspin_lcao module

- Create new files deltaspin_lcao.h/cpp in module_deltaspin
- Extract DeltaSpin lambda loop logic from ESolver_KS_LCAO
- Simplify code from 18 lines to 1 line in hamilt2rho_single
- Separate LCAO and PW implementations for DeltaSpin

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace inline code with function call
- source_lcao/module_deltaspin/CMakeLists.txt: add new source file

New files:
- source_lcao/module_deltaspin/deltaspin_lcao.h: function declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: function implementation

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): complete DeltaSpin refactoring in LCAO

- Add init_deltaspin_lcao() function for DeltaSpin initialization
- Add cal_mi_lcao_wrapper() function for magnetic moment calculation
- Refactor all DeltaSpin-related code in esolver_ks_lcao.cpp
- Simplify code from 29 lines to 3 lines (90% reduction)

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 3 code blocks with function calls
- source_lcao/module_deltaspin/deltaspin_lcao.h: add 2 new function declarations
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: implement 2 new functions

This completes the DeltaSpin refactoring for LCAO method:
1. init_deltaspin_lcao() - initialize DeltaSpin calculation
2. cal_mi_lcao_wrapper() - calculate magnetic moments
3. run_deltaspin_lambda_loop_lcao() - run lambda loop optimization

All functions follow the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DFT+U code to dftu_lcao module

- Create new files dftu_lcao.h/cpp in source_lcao directory
- Add init_dftu_lcao() function for DFT+U initialization
- Add finish_dftu_lcao() function for DFT+U finalization
- Simplify code from 32 lines to 2 lines in esolver_ks_lcao.cpp
- Remove conditional checks from ESolver, move them to functions

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 2 code blocks with function calls
- source_lcao/CMakeLists.txt: add new source file

New files:
- source_lcao/dftu_lcao.h: function declarations
- source_lcao/dftu_lcao.cpp: function implementations

This refactoring prepares for unifying old and new DFT+U implementations:
- Old DFT+U: source_lcao/module_dftu/
- New DFT+U: source_lcao/module_operator_lcao/op_dftu_lcao.cpp

All functions follow ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract diagonalization parameters setup to hsolver module

- Create new files diago_params.h/cpp in source_hsolver directory
- Add setup_diago_params_pw() function for PW diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_ks_pw.cpp
- Encapsulate diagonalization parameter setup logic

Modified files:
- source_esolver/esolver_ks_pw.cpp: replace inline code with function call
- source_hsolver/CMakeLists.txt: add new source file

New files:
- source_hsolver/diago_params.h: function declaration
- source_hsolver/diago_params.cpp: function implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* fix(deltaspin): add sc_mag_switch check in cal_mi_lcao_wrapper

- Add Input_para parameter to cal_mi_lcao_wrapper function
- Add sc_mag_switch check to avoid calling cal_mi_lcao when DeltaSpin is disabled
- Fix 'atomCounts is not set' error in non-DeltaSpin calculations
- Update function call in esolver_ks_lcao.cpp

This fix resolves the CI/CD failure caused by commit 2a520e3.
The root cause was that cal_mi_lcao_wrapper was called without checking
sc_mag_switch, leading to uninitialized atomCounts error.

Modified files:
- source_esolver/esolver_ks_lcao.cpp: update function call
- source_lcao/module_deltaspin/deltaspin_lcao.h: add parameter
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add check

This follows the refactoring principle: preserve original condition checks
when extracting code to wrapper functions.

* fix(deltaspin): add #ifdef __LCAO for conditional compilation

- Add #ifdef __LCAO conditional compilation in init_deltaspin_lcao and cal_mi_lcao_wrapper
- Fix parameter order in init_sc call for LCAO and non-LCAO builds
- Fix undefined reference to cal_mi_lcao in non-LCAO build

This fix resolves CI/CD compilation errors in both build_5pt (with __LCAO) and build_1p (without __LCAO) environments.

The The root cause was 1. init_sc has different parameter order in LCAO vs non-LCAO builds
   - LCAO: psi, dm, pelec
   - non-LCAO: psi, pelec
  2. cal_mi_lcao is only defined in LCAO build

Modified files:
- source_hsolver/diago_params.h: add setup_diago_params_sdft declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add conditional compilation

This follows the refactoring principle: handle conditional compilation properly
when code has different implementations for different build configurations.

* refactor(esolver): extract SDFT diagonalization parameters setup

- Add setup_diago_params_sdft() function for SDFT diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_sdft_pw.cpp
- Encapsulate diagonalization parameter setup logic for SDFT

Modified files:
- source_esolver/esolver_sdft_pw.cpp: replace inline code with function call
- source_hsolver/diago_params.cpp: add setup_diago_params_sdft implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

Note: SDFT has different parameter setup logic compared to PW:
- Different need_subspace condition
- No SCF_ITER setting
- Always set PW_DIAG_NMAX (no nscf check)

* refactor(hamilt): introduce HamiltBase non-template base class

- Create HamiltBase as a non-template base class for Hamilt<T, Device>
- Modify Hamilt<T, Device> to inherit from HamiltBase
- Change ESolver_KS::p_hamilt type from Hamilt<T, Device>* to HamiltBase*
- Add static_cast where needed when passing p_hamilt to functions expecting Hamilt<T, Device>*

This is the first step towards removing template parameters from ESolver.

Modified files:
- source/source_esolver/esolver_ks.h
- source/source_esolver/esolver_ks_lcaopw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_sdft_pw.cpp
- source/source_hamilt/hamilt.h

New files:
- source/source_hamilt/hamilt_base.h

* refactor(esolver): add static_cast for p_hamilt in esolver files

- Add static_cast<hamilt::Hamilt<T>*> when passing p_hamilt to functions
  expecting Hamilt<T, Device>* type
- Split long cast statements into multiple lines for better readability
- Files modified:
  - esolver_ks_pw.cpp: setup_pot, stp.init calls
  - esolver_ks_lcao.cpp: init_chg_hr, hsolver_lcao_obj.solve calls
  - esolver_ks_lcao_tddft.cpp: solve_psi, cal_edm_tddft, matrix calls
  - esolver_gets.cpp: ops access, output_SR call

This follows the HamiltBase refactoring strategy where p_hamilt is stored
as HamiltBase* and cast to Hamilt<T, Device>* when needed.

* refactor(esolver): remove psi member from ESolver_KS base class

Move psi::Psi<T>* psi from ESolver_KS base class to derived classes
to eliminate template parameter dependency and improve code organization.

Changes:
1. ESolver_KS base class:
   - Remove psi::Psi<T>* psi member variable
   - Remove Setup_Psi<T>::deallocate_psi() call in destructor
   - Remove unnecessary includes: psi.h and setup_psi.h

2. ESolver_KS_LCAO:
   - Add psi::Psi<TK>* psi member variable
   - Add Setup_Psi<TK>::deallocate_psi() in destructor
   - Add include: setup_psi.h

3. ESolver_KS_LCAO_TDDFT:
   - Improve psi_laststep deallocation with nullptr check
   - psi member inherited from ESolver_KS_LCAO

4. ESolver_KS_PW:
   - Use stp.psi_cpu directly instead of base class psi
   - Remove unnecessary memory allocation in after_scf()

5. pw_others.cpp (BUG FIX):
   - Fix gen_bessel: use *(this->stp.psi_cpu) instead of this->psi[0]
   - Previous code accessed uninitialized base class psi (nullptr)
   - This was a latent bug that could cause crashes

Benefits:
- Eliminates template parameter T dependency in ESolver_KS base class
- Clearer memory management: each derived class manages its own psi
- Reduces compilation dependencies
- Fixes potential memory access bug in pw_others.cpp

Tested: Compiled successfully in build_5pt and build_1p

* refactor(esolver): remove template parameters from ESolver_KS base class

This is a major milestone in ESolver refactoring!

ESolver_KS no longer needs template parameters because:
- All member variables are non-template types
- All member functions do not use T or Device parameters
- Template parameters were only needed for derived classes

Changes:
1. ESolver_KS base class:
   - Remove template <typename T, typename Device> declaration
   - Remove all template declarations from member functions
   - Remove template instantiation code at end of file
   - Fix Tab indentation to spaces for better readability

2. Derived classes:
   - ESolver_KS_PW: public ESolver_KS (was ESolver_KS<T, Device>)
   - ESolver_KS_LCAO: public ESolver_KS (was ESolver_KS<TK>)
   - ESolver_GetS: public ESolver_KS (was ESolver_KS<std::complex<double>>)
   - Update base class calls: ESolver_KS:: (was ESolver_KS<T, Device>::)

Code reduction:
- esolver_ks.h: 78 -> 77 lines (-1 line)
- esolver_ks.cpp: 346 -> 317 lines (-29 lines)
- Total ESolver code: 424 -> 394 lines (-30 lines)
- Overall: 8 files changed, 50 insertions(+), 80 deletions(-), net -30 lines

Benefits:
- Simpler base class without template complexity
- Faster compilation (no template instantiation needed)
- Clearer inheritance hierarchy
- Easier to extract common code in future refactoring
- Sets foundation for further ESolver template removal

Tested: Compiled successfully in build_5pt

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
* small format changes

* refactor(esolver): extract charge density symmetrization to Symmetry_rho::symmetrize_rho

- Add static method symmetrize_rho() in Symmetry_rho class
- Replace 7 duplicate code blocks with single function call
- Simplify code from 35 lines to 7 lines (80% reduction)
- Improve code readability and maintainability

Modified files:
- source_estate/module_charge/symmetry_rho.h: add static method declaration
- source_estate/module_charge/symmetry_rho.cpp: implement static method
- source_esolver/esolver_ks_lcao.cpp: 2 calls updated
- source_esolver/esolver_ks_pw.cpp: 1 call updated
- source_esolver/esolver_ks_lcao_tddft.cpp: 1 call updated
- source_esolver/esolver_ks_lcaopw.cpp: 1 call updated
- source_esolver/esolver_of.cpp: 1 call updated
- source_esolver/esolver_sdft_pw.cpp: 1 call updated

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DeltaSpin lambda loop to deltaspin_lcao module

- Create new files deltaspin_lcao.h/cpp in module_deltaspin
- Extract DeltaSpin lambda loop logic from ESolver_KS_LCAO
- Simplify code from 18 lines to 1 line in hamilt2rho_single
- Separate LCAO and PW implementations for DeltaSpin

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace inline code with function call
- source_lcao/module_deltaspin/CMakeLists.txt: add new source file

New files:
- source_lcao/module_deltaspin/deltaspin_lcao.h: function declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: function implementation

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): complete DeltaSpin refactoring in LCAO

- Add init_deltaspin_lcao() function for DeltaSpin initialization
- Add cal_mi_lcao_wrapper() function for magnetic moment calculation
- Refactor all DeltaSpin-related code in esolver_ks_lcao.cpp
- Simplify code from 29 lines to 3 lines (90% reduction)

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 3 code blocks with function calls
- source_lcao/module_deltaspin/deltaspin_lcao.h: add 2 new function declarations
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: implement 2 new functions

This completes the DeltaSpin refactoring for LCAO method:
1. init_deltaspin_lcao() - initialize DeltaSpin calculation
2. cal_mi_lcao_wrapper() - calculate magnetic moments
3. run_deltaspin_lambda_loop_lcao() - run lambda loop optimization

All functions follow the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DFT+U code to dftu_lcao module

- Create new files dftu_lcao.h/cpp in source_lcao directory
- Add init_dftu_lcao() function for DFT+U initialization
- Add finish_dftu_lcao() function for DFT+U finalization
- Simplify code from 32 lines to 2 lines in esolver_ks_lcao.cpp
- Remove conditional checks from ESolver, move them to functions

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 2 code blocks with function calls
- source_lcao/CMakeLists.txt: add new source file

New files:
- source_lcao/dftu_lcao.h: function declarations
- source_lcao/dftu_lcao.cpp: function implementations

This refactoring prepares for unifying old and new DFT+U implementations:
- Old DFT+U: source_lcao/module_dftu/
- New DFT+U: source_lcao/module_operator_lcao/op_dftu_lcao.cpp

All functions follow ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract diagonalization parameters setup to hsolver module

- Create new files diago_params.h/cpp in source_hsolver directory
- Add setup_diago_params_pw() function for PW diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_ks_pw.cpp
- Encapsulate diagonalization parameter setup logic

Modified files:
- source_esolver/esolver_ks_pw.cpp: replace inline code with function call
- source_hsolver/CMakeLists.txt: add new source file

New files:
- source_hsolver/diago_params.h: function declaration
- source_hsolver/diago_params.cpp: function implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* fix(deltaspin): add sc_mag_switch check in cal_mi_lcao_wrapper

- Add Input_para parameter to cal_mi_lcao_wrapper function
- Add sc_mag_switch check to avoid calling cal_mi_lcao when DeltaSpin is disabled
- Fix 'atomCounts is not set' error in non-DeltaSpin calculations
- Update function call in esolver_ks_lcao.cpp

This fix resolves the CI/CD failure caused by commit 2a520e3.
The root cause was that cal_mi_lcao_wrapper was called without checking
sc_mag_switch, leading to uninitialized atomCounts error.

Modified files:
- source_esolver/esolver_ks_lcao.cpp: update function call
- source_lcao/module_deltaspin/deltaspin_lcao.h: add parameter
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add check

This follows the refactoring principle: preserve original condition checks
when extracting code to wrapper functions.

* fix(deltaspin): add #ifdef __LCAO for conditional compilation

- Add #ifdef __LCAO conditional compilation in init_deltaspin_lcao and cal_mi_lcao_wrapper
- Fix parameter order in init_sc call for LCAO and non-LCAO builds
- Fix undefined reference to cal_mi_lcao in non-LCAO build

This fix resolves CI/CD compilation errors in both build_5pt (with __LCAO) and build_1p (without __LCAO) environments.

The The root cause was 1. init_sc has different parameter order in LCAO vs non-LCAO builds
   - LCAO: psi, dm, pelec
   - non-LCAO: psi, pelec
  2. cal_mi_lcao is only defined in LCAO build

Modified files:
- source_hsolver/diago_params.h: add setup_diago_params_sdft declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add conditional compilation

This follows the refactoring principle: handle conditional compilation properly
when code has different implementations for different build configurations.

* refactor(esolver): extract SDFT diagonalization parameters setup

- Add setup_diago_params_sdft() function for SDFT diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_sdft_pw.cpp
- Encapsulate diagonalization parameter setup logic for SDFT

Modified files:
- source_esolver/esolver_sdft_pw.cpp: replace inline code with function call
- source_hsolver/diago_params.cpp: add setup_diago_params_sdft implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

Note: SDFT has different parameter setup logic compared to PW:
- Different need_subspace condition
- No SCF_ITER setting
- Always set PW_DIAG_NMAX (no nscf check)

* refactor(hamilt): introduce HamiltBase non-template base class

- Create HamiltBase as a non-template base class for Hamilt<T, Device>
- Modify Hamilt<T, Device> to inherit from HamiltBase
- Change ESolver_KS::p_hamilt type from Hamilt<T, Device>* to HamiltBase*
- Add static_cast where needed when passing p_hamilt to functions expecting Hamilt<T, Device>*

This is the first step towards removing template parameters from ESolver.

Modified files:
- source/source_esolver/esolver_ks.h
- source/source_esolver/esolver_ks_lcaopw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_sdft_pw.cpp
- source/source_hamilt/hamilt.h

New files:
- source/source_hamilt/hamilt_base.h

* refactor(esolver): add static_cast for p_hamilt in esolver files

- Add static_cast<hamilt::Hamilt<T>*> when passing p_hamilt to functions
  expecting Hamilt<T, Device>* type
- Split long cast statements into multiple lines for better readability
- Files modified:
  - esolver_ks_pw.cpp: setup_pot, stp.init calls
  - esolver_ks_lcao.cpp: init_chg_hr, hsolver_lcao_obj.solve calls
  - esolver_ks_lcao_tddft.cpp: solve_psi, cal_edm_tddft, matrix calls
  - esolver_gets.cpp: ops access, output_SR call

This follows the HamiltBase refactoring strategy where p_hamilt is stored
as HamiltBase* and cast to Hamilt<T, Device>* when needed.

* refactor(esolver): remove psi member from ESolver_KS base class

Move psi::Psi<T>* psi from ESolver_KS base class to derived classes
to eliminate template parameter dependency and improve code organization.

Changes:
1. ESolver_KS base class:
   - Remove psi::Psi<T>* psi member variable
   - Remove Setup_Psi<T>::deallocate_psi() call in destructor
   - Remove unnecessary includes: psi.h and setup_psi.h

2. ESolver_KS_LCAO:
   - Add psi::Psi<TK>* psi member variable
   - Add Setup_Psi<TK>::deallocate_psi() in destructor
   - Add include: setup_psi.h

3. ESolver_KS_LCAO_TDDFT:
   - Improve psi_laststep deallocation with nullptr check
   - psi member inherited from ESolver_KS_LCAO

4. ESolver_KS_PW:
   - Use stp.psi_cpu directly instead of base class psi
   - Remove unnecessary memory allocation in after_scf()

5. pw_others.cpp (BUG FIX):
   - Fix gen_bessel: use *(this->stp.psi_cpu) instead of this->psi[0]
   - Previous code accessed uninitialized base class psi (nullptr)
   - This was a latent bug that could cause crashes

Benefits:
- Eliminates template parameter T dependency in ESolver_KS base class
- Clearer memory management: each derived class manages its own psi
- Reduces compilation dependencies
- Fixes potential memory access bug in pw_others.cpp

Tested: Compiled successfully in build_5pt and build_1p

* refactor(esolver): remove template parameters from ESolver_KS base class

This is a major milestone in ESolver refactoring!

ESolver_KS no longer needs template parameters because:
- All member variables are non-template types
- All member functions do not use T or Device parameters
- Template parameters were only needed for derived classes

Changes:
1. ESolver_KS base class:
   - Remove template <typename T, typename Device> declaration
   - Remove all template declarations from member functions
   - Remove template instantiation code at end of file
   - Fix Tab indentation to spaces for better readability

2. Derived classes:
   - ESolver_KS_PW: public ESolver_KS (was ESolver_KS<T, Device>)
   - ESolver_KS_LCAO: public ESolver_KS (was ESolver_KS<TK>)
   - ESolver_GetS: public ESolver_KS (was ESolver_KS<std::complex<double>>)
   - Update base class calls: ESolver_KS:: (was ESolver_KS<T, Device>::)

Code reduction:
- esolver_ks.h: 78 -> 77 lines (-1 line)
- esolver_ks.cpp: 346 -> 317 lines (-29 lines)
- Total ESolver code: 424 -> 394 lines (-30 lines)
- Overall: 8 files changed, 50 insertions(+), 80 deletions(-), net -30 lines

Benefits:
- Simpler base class without template complexity
- Faster compilation (no template instantiation needed)
- Clearer inheritance hierarchy
- Easier to extract common code in future refactoring
- Sets foundation for further ESolver template removal

Tested: Compiled successfully in build_5pt

* refactor(device): remove explicit template parameter from get_device_type calls

- Move get_device_type implementation to header file using std::is_same
- Add DEVICE_DSP support
- Remove template specialization declarations and definitions
- Update all call sites to use automatic template parameter deduction
- The compiler now deduces Device type from the ctx parameter

* refactor(esolver): remove device member variable from ESolver_KS_PW

- Modify copy_d2h to accept ctx parameter and call get_device_type internally
- Remove device parameter from ctrl_scf_pw function
- Remove device member variable from ESolver_KS_PW class
- Simplify function interfaces by using automatic template deduction

* style(esolver): explicitly initialize ctx to nullptr in constructor

* feat(device): add runtime device type support to DeviceContext

- Add device_type_ member variable to DeviceContext class
- Add set_device_type() and get_device_type() methods
- Add is_cpu(), is_gpu(), is_dsp() convenience methods
- Add get_device_type(const DeviceContext*) overload for runtime device type query
- Maintain backward compatibility with existing template-based get_device_type

* feat(device): add runtime device context overloads for gradual migration

- Add copy_d2h(const DeviceContext*) overload to Setup_Psi_pw
- Add ctrl_scf_pw(..., const DeviceContext*, ...) overload
- Add ctrl_runner_pw(..., const DeviceContext*, ...) overload
- Keep original functions for backward compatibility
- Replace tabs with spaces in modified files

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
* Refactor: add nullptr for uninitialized pointer

* remove nullptr in MatrixBlock

---------

Co-authored-by: linpz <linpz@mail.ustc.edu.cn>
* small format changes

* refactor(esolver): extract charge density symmetrization to Symmetry_rho::symmetrize_rho

- Add static method symmetrize_rho() in Symmetry_rho class
- Replace 7 duplicate code blocks with single function call
- Simplify code from 35 lines to 7 lines (80% reduction)
- Improve code readability and maintainability

Modified files:
- source_estate/module_charge/symmetry_rho.h: add static method declaration
- source_estate/module_charge/symmetry_rho.cpp: implement static method
- source_esolver/esolver_ks_lcao.cpp: 2 calls updated
- source_esolver/esolver_ks_pw.cpp: 1 call updated
- source_esolver/esolver_ks_lcao_tddft.cpp: 1 call updated
- source_esolver/esolver_ks_lcaopw.cpp: 1 call updated
- source_esolver/esolver_of.cpp: 1 call updated
- source_esolver/esolver_sdft_pw.cpp: 1 call updated

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DeltaSpin lambda loop to deltaspin_lcao module

- Create new files deltaspin_lcao.h/cpp in module_deltaspin
- Extract DeltaSpin lambda loop logic from ESolver_KS_LCAO
- Simplify code from 18 lines to 1 line in hamilt2rho_single
- Separate LCAO and PW implementations for DeltaSpin

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace inline code with function call
- source_lcao/module_deltaspin/CMakeLists.txt: add new source file

New files:
- source_lcao/module_deltaspin/deltaspin_lcao.h: function declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: function implementation

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): complete DeltaSpin refactoring in LCAO

- Add init_deltaspin_lcao() function for DeltaSpin initialization
- Add cal_mi_lcao_wrapper() function for magnetic moment calculation
- Refactor all DeltaSpin-related code in esolver_ks_lcao.cpp
- Simplify code from 29 lines to 3 lines (90% reduction)

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 3 code blocks with function calls
- source_lcao/module_deltaspin/deltaspin_lcao.h: add 2 new function declarations
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: implement 2 new functions

This completes the DeltaSpin refactoring for LCAO method:
1. init_deltaspin_lcao() - initialize DeltaSpin calculation
2. cal_mi_lcao_wrapper() - calculate magnetic moments
3. run_deltaspin_lambda_loop_lcao() - run lambda loop optimization

All functions follow the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DFT+U code to dftu_lcao module

- Create new files dftu_lcao.h/cpp in source_lcao directory
- Add init_dftu_lcao() function for DFT+U initialization
- Add finish_dftu_lcao() function for DFT+U finalization
- Simplify code from 32 lines to 2 lines in esolver_ks_lcao.cpp
- Remove conditional checks from ESolver, move them to functions

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 2 code blocks with function calls
- source_lcao/CMakeLists.txt: add new source file

New files:
- source_lcao/dftu_lcao.h: function declarations
- source_lcao/dftu_lcao.cpp: function implementations

This refactoring prepares for unifying old and new DFT+U implementations:
- Old DFT+U: source_lcao/module_dftu/
- New DFT+U: source_lcao/module_operator_lcao/op_dftu_lcao.cpp

All functions follow ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract diagonalization parameters setup to hsolver module

- Create new files diago_params.h/cpp in source_hsolver directory
- Add setup_diago_params_pw() function for PW diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_ks_pw.cpp
- Encapsulate diagonalization parameter setup logic

Modified files:
- source_esolver/esolver_ks_pw.cpp: replace inline code with function call
- source_hsolver/CMakeLists.txt: add new source file

New files:
- source_hsolver/diago_params.h: function declaration
- source_hsolver/diago_params.cpp: function implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* fix(deltaspin): add sc_mag_switch check in cal_mi_lcao_wrapper

- Add Input_para parameter to cal_mi_lcao_wrapper function
- Add sc_mag_switch check to avoid calling cal_mi_lcao when DeltaSpin is disabled
- Fix 'atomCounts is not set' error in non-DeltaSpin calculations
- Update function call in esolver_ks_lcao.cpp

This fix resolves the CI/CD failure caused by commit 2a520e3.
The root cause was that cal_mi_lcao_wrapper was called without checking
sc_mag_switch, leading to uninitialized atomCounts error.

Modified files:
- source_esolver/esolver_ks_lcao.cpp: update function call
- source_lcao/module_deltaspin/deltaspin_lcao.h: add parameter
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add check

This follows the refactoring principle: preserve original condition checks
when extracting code to wrapper functions.

* fix(deltaspin): add #ifdef __LCAO for conditional compilation

- Add #ifdef __LCAO conditional compilation in init_deltaspin_lcao and cal_mi_lcao_wrapper
- Fix parameter order in init_sc call for LCAO and non-LCAO builds
- Fix undefined reference to cal_mi_lcao in non-LCAO build

This fix resolves CI/CD compilation errors in both build_5pt (with __LCAO) and build_1p (without __LCAO) environments.

The The root cause was 1. init_sc has different parameter order in LCAO vs non-LCAO builds
   - LCAO: psi, dm, pelec
   - non-LCAO: psi, pelec
  2. cal_mi_lcao is only defined in LCAO build

Modified files:
- source_hsolver/diago_params.h: add setup_diago_params_sdft declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add conditional compilation

This follows the refactoring principle: handle conditional compilation properly
when code has different implementations for different build configurations.

* refactor(esolver): extract SDFT diagonalization parameters setup

- Add setup_diago_params_sdft() function for SDFT diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_sdft_pw.cpp
- Encapsulate diagonalization parameter setup logic for SDFT

Modified files:
- source_esolver/esolver_sdft_pw.cpp: replace inline code with function call
- source_hsolver/diago_params.cpp: add setup_diago_params_sdft implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

Note: SDFT has different parameter setup logic compared to PW:
- Different need_subspace condition
- No SCF_ITER setting
- Always set PW_DIAG_NMAX (no nscf check)

* refactor(hamilt): introduce HamiltBase non-template base class

- Create HamiltBase as a non-template base class for Hamilt<T, Device>
- Modify Hamilt<T, Device> to inherit from HamiltBase
- Change ESolver_KS::p_hamilt type from Hamilt<T, Device>* to HamiltBase*
- Add static_cast where needed when passing p_hamilt to functions expecting Hamilt<T, Device>*

This is the first step towards removing template parameters from ESolver.

Modified files:
- source/source_esolver/esolver_ks.h
- source/source_esolver/esolver_ks_lcaopw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_sdft_pw.cpp
- source/source_hamilt/hamilt.h

New files:
- source/source_hamilt/hamilt_base.h

* refactor(esolver): add static_cast for p_hamilt in esolver files

- Add static_cast<hamilt::Hamilt<T>*> when passing p_hamilt to functions
  expecting Hamilt<T, Device>* type
- Split long cast statements into multiple lines for better readability
- Files modified:
  - esolver_ks_pw.cpp: setup_pot, stp.init calls
  - esolver_ks_lcao.cpp: init_chg_hr, hsolver_lcao_obj.solve calls
  - esolver_ks_lcao_tddft.cpp: solve_psi, cal_edm_tddft, matrix calls
  - esolver_gets.cpp: ops access, output_SR call

This follows the HamiltBase refactoring strategy where p_hamilt is stored
as HamiltBase* and cast to Hamilt<T, Device>* when needed.

* refactor(esolver): remove psi member from ESolver_KS base class

Move psi::Psi<T>* psi from ESolver_KS base class to derived classes
to eliminate template parameter dependency and improve code organization.

Changes:
1. ESolver_KS base class:
   - Remove psi::Psi<T>* psi member variable
   - Remove Setup_Psi<T>::deallocate_psi() call in destructor
   - Remove unnecessary includes: psi.h and setup_psi.h

2. ESolver_KS_LCAO:
   - Add psi::Psi<TK>* psi member variable
   - Add Setup_Psi<TK>::deallocate_psi() in destructor
   - Add include: setup_psi.h

3. ESolver_KS_LCAO_TDDFT:
   - Improve psi_laststep deallocation with nullptr check
   - psi member inherited from ESolver_KS_LCAO

4. ESolver_KS_PW:
   - Use stp.psi_cpu directly instead of base class psi
   - Remove unnecessary memory allocation in after_scf()

5. pw_others.cpp (BUG FIX):
   - Fix gen_bessel: use *(this->stp.psi_cpu) instead of this->psi[0]
   - Previous code accessed uninitialized base class psi (nullptr)
   - This was a latent bug that could cause crashes

Benefits:
- Eliminates template parameter T dependency in ESolver_KS base class
- Clearer memory management: each derived class manages its own psi
- Reduces compilation dependencies
- Fixes potential memory access bug in pw_others.cpp

Tested: Compiled successfully in build_5pt and build_1p

* refactor(esolver): remove template parameters from ESolver_KS base class

This is a major milestone in ESolver refactoring!

ESolver_KS no longer needs template parameters because:
- All member variables are non-template types
- All member functions do not use T or Device parameters
- Template parameters were only needed for derived classes

Changes:
1. ESolver_KS base class:
   - Remove template <typename T, typename Device> declaration
   - Remove all template declarations from member functions
   - Remove template instantiation code at end of file
   - Fix Tab indentation to spaces for better readability

2. Derived classes:
   - ESolver_KS_PW: public ESolver_KS (was ESolver_KS<T, Device>)
   - ESolver_KS_LCAO: public ESolver_KS (was ESolver_KS<TK>)
   - ESolver_GetS: public ESolver_KS (was ESolver_KS<std::complex<double>>)
   - Update base class calls: ESolver_KS:: (was ESolver_KS<T, Device>::)

Code reduction:
- esolver_ks.h: 78 -> 77 lines (-1 line)
- esolver_ks.cpp: 346 -> 317 lines (-29 lines)
- Total ESolver code: 424 -> 394 lines (-30 lines)
- Overall: 8 files changed, 50 insertions(+), 80 deletions(-), net -30 lines

Benefits:
- Simpler base class without template complexity
- Faster compilation (no template instantiation needed)
- Clearer inheritance hierarchy
- Easier to extract common code in future refactoring
- Sets foundation for further ESolver template removal

Tested: Compiled successfully in build_5pt

* refactor(device): remove explicit template parameter from get_device_type calls

- Move get_device_type implementation to header file using std::is_same
- Add DEVICE_DSP support
- Remove template specialization declarations and definitions
- Update all call sites to use automatic template parameter deduction
- The compiler now deduces Device type from the ctx parameter

* refactor(esolver): remove device member variable from ESolver_KS_PW

- Modify copy_d2h to accept ctx parameter and call get_device_type internally
- Remove device parameter from ctrl_scf_pw function
- Remove device member variable from ESolver_KS_PW class
- Simplify function interfaces by using automatic template deduction

* style(esolver): explicitly initialize ctx to nullptr in constructor

* feat(device): add runtime device type support to DeviceContext

- Add device_type_ member variable to DeviceContext class
- Add set_device_type() and get_device_type() methods
- Add is_cpu(), is_gpu(), is_dsp() convenience methods
- Add get_device_type(const DeviceContext*) overload for runtime device type query
- Maintain backward compatibility with existing template-based get_device_type

* feat(device): add runtime device context overloads for gradual migration

- Add copy_d2h(const DeviceContext*) overload to Setup_Psi_pw
- Add ctrl_scf_pw(..., const DeviceContext*, ...) overload
- Add ctrl_runner_pw(..., const DeviceContext*, ...) overload
- Keep original functions for backward compatibility
- Replace tabs with spaces in modified files

* refactor(esolver): remove ctx member variable from ESolver_KS_PW

- Remove Device* ctx member variable from ESolver_KS_PW class
- Remove ctx parameter from ctrl_scf_pw and ctrl_runner_pw functions
- Add local ctx variable inside ctrl_scf_pw and ctrl_runner_pw functions
- Update all template instantiations to match new function signatures

This refactoring simplifies the code by moving the ctx variable from
a class member to a local variable within the functions that need it.
The ctx variable is only used for template parameter deduction in
copy_d2h and get_pchg_pw/get_wf_pw functions, so it doesn't need to
be stored as a member variable.

* refactor(psi): add runtime type information to Setup_Psi_pw

- Add runtime type information (device_type_ and precision_type_) to Setup_Psi_pw
- Add accessor functions for basic information (get_nbands, get_nk, get_nbasis, size)
- Add accessor functions for runtime type information
- Add get_psi_t() function for backward compatibility

This is the first step of a gradual refactoring to remove template parameters
from Setup_Psi_pw in the future. The current changes are backward compatible
and do not affect existing functionality.

* refactor(esolver): use get_psi_t() accessor instead of direct psi_t access

- Replace all direct access to stp.psi_t with stp.get_psi_t()
- Replace stp.psi_t->get_nbands() with stp.get_nbands()
- This is the second step of gradual refactoring to prepare for removing template parameters

Modified files:
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_sdft_pw.cpp
- source/source_esolver/esolver_ks_lcaopw.cpp
- source/source_io/module_ctrl/ctrl_output_pw.cpp

* refactor(psi): change psi_t from template pointer to void*

- Change psi_t from psi::Psi<T, Device>* to void*
- Add static_cast in get_psi_t() function for type conversion
- Update all functions that use psi_t to use get_psi_t() or static_cast
- This is the third step of gradual refactoring to remove template parameters

Modified functions:
- before_runner: use if-else instead of ternary operator for void* assignment
- update_psi_d: use get_psi_t() to access psi_t
- init: use get_psi_t() to access psi_t
- copy_d2h: use get_psi_t() to access psi_t
- clean: use get_psi_t() to delete psi_t

* style: replace Chinese comments with English in setup_psi_pw.h

- Replace '原来的模板版本' with 'Original template version'
- Replace '使用 void* 存储指针,运行时类型信息记录实际类型' with 'Use void* to store pointer, runtime type information records actual type'
- Follow ABACUS code style guidelines for English-only comments

* refactor(psi): change psi_d from template pointer to void*

- Change psi_d from psi::Psi<std::complex<double>, Device>* to void*
- Add get_psi_d() accessor function for type conversion
- Update all functions that use psi_d to use get_psi_d()
- This is part of step 1 in phase 4 of gradual refactoring

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_io/module_ctrl/ctrl_output_pw.cpp

* refactor(psi): introduce PSIPrepareBase base class for template removal

This is the first step towards removing template parameters from Setup_Psi_pw.

Changes:
1. Create PSIPrepareBase base class
   - Non-template base class for PSIPrepare<T, Device>
   - Similar approach to HamiltBase for Hamilt<T, Device>

2. Modify PSIPrepare to inherit from PSIPrepareBase
   - Add #include "source_psi/psi_prepare_base.h"
   - Change class declaration to inherit from PSIPrepareBase

3. Update Setup_Psi_pw to use PSIPrepareBase*
   - Change p_psi_init from PSIPrepare<T, Device>* to PSIPrepareBase*
   - Add static_cast when calling PSIPrepare methods

4. Update all PSIPrepare usage in ESolver files
   - esolver_ks_pw.cpp: add static_cast before prepare_init call
   - esolver_ks_lcaopw.cpp: add static_cast before method calls

Modified files:
- source/source_psi/psi_prepare_base.h (new)
- source/source_psi/psi_prepare.h
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_ks_lcaopw.cpp

Benefits:
- Eliminates p_psi_init template dependency from Setup_Psi_pw
- Paves the way for removing template parameters from Setup_Psi_pw
- Maintains type safety through static_cast
- Follows the same pattern as HamiltBase refactoring

Tested: Compiled successfully in build_5pt and build_1p

* refactor(psi): change init() parameter from template to HamiltBase*

This is the second step towards removing template parameters from Setup_Psi_pw.

Changes:
1. Modify init() function signature
   - Change parameter from hamilt::Hamilt<T, Device>* to hamilt::HamiltBase*
   - Eliminates template dependency in function signature

2. Update init() implementation
   - Add static_cast<hamilt::Hamilt<T, Device>*> inside function
   - Maintain type safety through explicit cast

3. Update call site in esolver_ks_pw.cpp
   - Remove static_cast from call site
   - Directly pass p_hamilt (which is already HamiltBase*)

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_esolver/esolver_ks_pw.cpp

Benefits:
- init() function no longer depends on template parameters in signature
- Simplifies call sites (no cast needed)
- Follows the same pattern as p_hamilt storage in ESolver_KS
- One step closer to removing template parameters from Setup_Psi_pw

Tested: Compiled successfully in build_5pt and build_1p

* refactor(psi): remove template version of copy_d2h function

This is the third step towards removing template parameters from Setup_Psi_pw.

Changes:
1. Remove template version copy_d2h(const Device* ctx)
   - Delete the template version from setup_psi_pw.h
   - Delete the implementation from setup_psi_pw.cpp
   - Keep only the runtime version copy_d2h(const base_device::DeviceContext* ctx)

2. Update call site in ctrl_output_pw.cpp
   - Create Device* ctx = nullptr for template parameter deduction
   - Use DeviceContext::instance() for runtime device context
   - Call copy_d2h with DeviceContext* pointer

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_io/module_ctrl/ctrl_output_pw.cpp

Benefits:
- Eliminates copy_d2h function's template dependency
- All member functions now use runtime device context
- One step closer to removing template parameters from Setup_Psi_pw
- Maintains backward compatibility with existing code

Technical details:
- get_pchg_pw and get_wf_pw still need Device* ctx for template deduction
- DeviceContext is used for actual device type information
- This follows the gradual migration pattern used in ESolver refactoring

Tested: Compiled successfully in build_5pt and build_1p

* refactor(psi): remove castmem_2d_d2h_op template type alias dependency

This is the fourth step towards removing template parameters from Setup_Psi_pw.

Changes:
1. Remove castmem_2d_d2h_op type alias from setup_psi_pw.h
   - The type alias depended on template parameters T and Device
   - Replaced with overloaded member functions

2. Add castmem_d2h_impl() overloaded functions
   - One overload for std::complex<double> source
   - One overload for std::complex<float> source
   - Each uses the appropriate cast_memory_op internally

3. Update copy_d2h() to use the new overloaded functions
   - Calls castmem_d2h_impl() instead of castmem_2d_d2h_op()
   - Compiler selects the correct overload based on T type

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp

Benefits:
- All member variables now independent of template parameters
- castmem_d2h_impl encapsulates the type-dependent logic
- One step closer to removing template parameters from Setup_Psi_pw

Tested: Compiled successfully in build_5pt and build_1p

* delete useless files

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
…igh ecutwfc (#7025)

* Initial plan

* fix: dynamically compute mxr in H_Ewald_pw to prevent buffer overflow for small unit cells

Co-authored-by: Cstandardlib <49788094+Cstandardlib@users.noreply.github.com>

* test: add unit tests for H_Ewald_pw::rgen including large-rmax buffer-overflow regression

Co-authored-by: Cstandardlib <49788094+Cstandardlib@users.noreply.github.com>

* test: clarify misleading comment in SimpleCubicNonZeroDtau test

Co-authored-by: Cstandardlib <49788094+Cstandardlib@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Cstandardlib <49788094+Cstandardlib@users.noreply.github.com>
* small format changes

* refactor(esolver): extract charge density symmetrization to Symmetry_rho::symmetrize_rho

- Add static method symmetrize_rho() in Symmetry_rho class
- Replace 7 duplicate code blocks with single function call
- Simplify code from 35 lines to 7 lines (80% reduction)
- Improve code readability and maintainability

Modified files:
- source_estate/module_charge/symmetry_rho.h: add static method declaration
- source_estate/module_charge/symmetry_rho.cpp: implement static method
- source_esolver/esolver_ks_lcao.cpp: 2 calls updated
- source_esolver/esolver_ks_pw.cpp: 1 call updated
- source_esolver/esolver_ks_lcao_tddft.cpp: 1 call updated
- source_esolver/esolver_ks_lcaopw.cpp: 1 call updated
- source_esolver/esolver_of.cpp: 1 call updated
- source_esolver/esolver_sdft_pw.cpp: 1 call updated

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DeltaSpin lambda loop to deltaspin_lcao module

- Create new files deltaspin_lcao.h/cpp in module_deltaspin
- Extract DeltaSpin lambda loop logic from ESolver_KS_LCAO
- Simplify code from 18 lines to 1 line in hamilt2rho_single
- Separate LCAO and PW implementations for DeltaSpin

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace inline code with function call
- source_lcao/module_deltaspin/CMakeLists.txt: add new source file

New files:
- source_lcao/module_deltaspin/deltaspin_lcao.h: function declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: function implementation

This refactoring follows the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): complete DeltaSpin refactoring in LCAO

- Add init_deltaspin_lcao() function for DeltaSpin initialization
- Add cal_mi_lcao_wrapper() function for magnetic moment calculation
- Refactor all DeltaSpin-related code in esolver_ks_lcao.cpp
- Simplify code from 29 lines to 3 lines (90% reduction)

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 3 code blocks with function calls
- source_lcao/module_deltaspin/deltaspin_lcao.h: add 2 new function declarations
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: implement 2 new functions

This completes the DeltaSpin refactoring for LCAO method:
1. init_deltaspin_lcao() - initialize DeltaSpin calculation
2. cal_mi_lcao_wrapper() - calculate magnetic moments
3. run_deltaspin_lambda_loop_lcao() - run lambda loop optimization

All functions follow the ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract DFT+U code to dftu_lcao module

- Create new files dftu_lcao.h/cpp in source_lcao directory
- Add init_dftu_lcao() function for DFT+U initialization
- Add finish_dftu_lcao() function for DFT+U finalization
- Simplify code from 32 lines to 2 lines in esolver_ks_lcao.cpp
- Remove conditional checks from ESolver, move them to functions

Modified files:
- source_esolver/esolver_ks_lcao.cpp: replace 2 code blocks with function calls
- source_lcao/CMakeLists.txt: add new source file

New files:
- source_lcao/dftu_lcao.h: function declarations
- source_lcao/dftu_lcao.cpp: function implementations

This refactoring prepares for unifying old and new DFT+U implementations:
- Old DFT+U: source_lcao/module_dftu/
- New DFT+U: source_lcao/module_operator_lcao/op_dftu_lcao.cpp

All functions follow ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* refactor(esolver): extract diagonalization parameters setup to hsolver module

- Create new files diago_params.h/cpp in source_hsolver directory
- Add setup_diago_params_pw() function for PW diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_ks_pw.cpp
- Encapsulate diagonalization parameter setup logic

Modified files:
- source_esolver/esolver_ks_pw.cpp: replace inline code with function call
- source_hsolver/CMakeLists.txt: add new source file

New files:
- source_hsolver/diago_params.h: function declaration
- source_hsolver/diago_params.cpp: function implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

* fix(deltaspin): add sc_mag_switch check in cal_mi_lcao_wrapper

- Add Input_para parameter to cal_mi_lcao_wrapper function
- Add sc_mag_switch check to avoid calling cal_mi_lcao when DeltaSpin is disabled
- Fix 'atomCounts is not set' error in non-DeltaSpin calculations
- Update function call in esolver_ks_lcao.cpp

This fix resolves the CI/CD failure caused by commit 2a520e3.
The root cause was that cal_mi_lcao_wrapper was called without checking
sc_mag_switch, leading to uninitialized atomCounts error.

Modified files:
- source_esolver/esolver_ks_lcao.cpp: update function call
- source_lcao/module_deltaspin/deltaspin_lcao.h: add parameter
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add check

This follows the refactoring principle: preserve original condition checks
when extracting code to wrapper functions.

* fix(deltaspin): add #ifdef __LCAO for conditional compilation

- Add #ifdef __LCAO conditional compilation in init_deltaspin_lcao and cal_mi_lcao_wrapper
- Fix parameter order in init_sc call for LCAO and non-LCAO builds
- Fix undefined reference to cal_mi_lcao in non-LCAO build

This fix resolves CI/CD compilation errors in both build_5pt (with __LCAO) and build_1p (without __LCAO) environments.

The The root cause was 1. init_sc has different parameter order in LCAO vs non-LCAO builds
   - LCAO: psi, dm, pelec
   - non-LCAO: psi, pelec
  2. cal_mi_lcao is only defined in LCAO build

Modified files:
- source_hsolver/diago_params.h: add setup_diago_params_sdft declaration
- source_lcao/module_deltaspin/deltaspin_lcao.cpp: add conditional compilation

This follows the refactoring principle: handle conditional compilation properly
when code has different implementations for different build configurations.

* refactor(esolver): extract SDFT diagonalization parameters setup

- Add setup_diago_params_sdft() function for SDFT diagonalization parameters
- Simplify code from 11 lines to 1 line in esolver_sdft_pw.cpp
- Encapsulate diagonalization parameter setup logic for SDFT

Modified files:
- source_esolver/esolver_sdft_pw.cpp: replace inline code with function call
- source_hsolver/diago_params.cpp: add setup_diago_params_sdft implementation

This refactoring follows ESolver cleanup principle:
keep ESolver focused on high-level workflow control.

Note: SDFT has different parameter setup logic compared to PW:
- Different need_subspace condition
- No SCF_ITER setting
- Always set PW_DIAG_NMAX (no nscf check)

* refactor(hamilt): introduce HamiltBase non-template base class

- Create HamiltBase as a non-template base class for Hamilt<T, Device>
- Modify Hamilt<T, Device> to inherit from HamiltBase
- Change ESolver_KS::p_hamilt type from Hamilt<T, Device>* to HamiltBase*
- Add static_cast where needed when passing p_hamilt to functions expecting Hamilt<T, Device>*

This is the first step towards removing template parameters from ESolver.

Modified files:
- source/source_esolver/esolver_ks.h
- source/source_esolver/esolver_ks_lcaopw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_sdft_pw.cpp
- source/source_hamilt/hamilt.h

New files:
- source/source_hamilt/hamilt_base.h

* refactor(esolver): add static_cast for p_hamilt in esolver files

- Add static_cast<hamilt::Hamilt<T>*> when passing p_hamilt to functions
  expecting Hamilt<T, Device>* type
- Split long cast statements into multiple lines for better readability
- Files modified:
  - esolver_ks_pw.cpp: setup_pot, stp.init calls
  - esolver_ks_lcao.cpp: init_chg_hr, hsolver_lcao_obj.solve calls
  - esolver_ks_lcao_tddft.cpp: solve_psi, cal_edm_tddft, matrix calls
  - esolver_gets.cpp: ops access, output_SR call

This follows the HamiltBase refactoring strategy where p_hamilt is stored
as HamiltBase* and cast to Hamilt<T, Device>* when needed.

* refactor(esolver): remove psi member from ESolver_KS base class

Move psi::Psi<T>* psi from ESolver_KS base class to derived classes
to eliminate template parameter dependency and improve code organization.

Changes:
1. ESolver_KS base class:
   - Remove psi::Psi<T>* psi member variable
   - Remove Setup_Psi<T>::deallocate_psi() call in destructor
   - Remove unnecessary includes: psi.h and setup_psi.h

2. ESolver_KS_LCAO:
   - Add psi::Psi<TK>* psi member variable
   - Add Setup_Psi<TK>::deallocate_psi() in destructor
   - Add include: setup_psi.h

3. ESolver_KS_LCAO_TDDFT:
   - Improve psi_laststep deallocation with nullptr check
   - psi member inherited from ESolver_KS_LCAO

4. ESolver_KS_PW:
   - Use stp.psi_cpu directly instead of base class psi
   - Remove unnecessary memory allocation in after_scf()

5. pw_others.cpp (BUG FIX):
   - Fix gen_bessel: use *(this->stp.psi_cpu) instead of this->psi[0]
   - Previous code accessed uninitialized base class psi (nullptr)
   - This was a latent bug that could cause crashes

Benefits:
- Eliminates template parameter T dependency in ESolver_KS base class
- Clearer memory management: each derived class manages its own psi
- Reduces compilation dependencies
- Fixes potential memory access bug in pw_others.cpp

Tested: Compiled successfully in build_5pt and build_1p

* refactor(esolver): remove template parameters from ESolver_KS base class

This is a major milestone in ESolver refactoring!

ESolver_KS no longer needs template parameters because:
- All member variables are non-template types
- All member functions do not use T or Device parameters
- Template parameters were only needed for derived classes

Changes:
1. ESolver_KS base class:
   - Remove template <typename T, typename Device> declaration
   - Remove all template declarations from member functions
   - Remove template instantiation code at end of file
   - Fix Tab indentation to spaces for better readability

2. Derived classes:
   - ESolver_KS_PW: public ESolver_KS (was ESolver_KS<T, Device>)
   - ESolver_KS_LCAO: public ESolver_KS (was ESolver_KS<TK>)
   - ESolver_GetS: public ESolver_KS (was ESolver_KS<std::complex<double>>)
   - Update base class calls: ESolver_KS:: (was ESolver_KS<T, Device>::)

Code reduction:
- esolver_ks.h: 78 -> 77 lines (-1 line)
- esolver_ks.cpp: 346 -> 317 lines (-29 lines)
- Total ESolver code: 424 -> 394 lines (-30 lines)
- Overall: 8 files changed, 50 insertions(+), 80 deletions(-), net -30 lines

Benefits:
- Simpler base class without template complexity
- Faster compilation (no template instantiation needed)
- Clearer inheritance hierarchy
- Easier to extract common code in future refactoring
- Sets foundation for further ESolver template removal

Tested: Compiled successfully in build_5pt

* refactor(device): remove explicit template parameter from get_device_type calls

- Move get_device_type implementation to header file using std::is_same
- Add DEVICE_DSP support
- Remove template specialization declarations and definitions
- Update all call sites to use automatic template parameter deduction
- The compiler now deduces Device type from the ctx parameter

* refactor(esolver): remove device member variable from ESolver_KS_PW

- Modify copy_d2h to accept ctx parameter and call get_device_type internally
- Remove device parameter from ctrl_scf_pw function
- Remove device member variable from ESolver_KS_PW class
- Simplify function interfaces by using automatic template deduction

* style(esolver): explicitly initialize ctx to nullptr in constructor

* feat(device): add runtime device type support to DeviceContext

- Add device_type_ member variable to DeviceContext class
- Add set_device_type() and get_device_type() methods
- Add is_cpu(), is_gpu(), is_dsp() convenience methods
- Add get_device_type(const DeviceContext*) overload for runtime device type query
- Maintain backward compatibility with existing template-based get_device_type

* feat(device): add runtime device context overloads for gradual migration

- Add copy_d2h(const DeviceContext*) overload to Setup_Psi_pw
- Add ctrl_scf_pw(..., const DeviceContext*, ...) overload
- Add ctrl_runner_pw(..., const DeviceContext*, ...) overload
- Keep original functions for backward compatibility
- Replace tabs with spaces in modified files

* refactor(esolver): remove ctx member variable from ESolver_KS_PW

- Remove Device* ctx member variable from ESolver_KS_PW class
- Remove ctx parameter from ctrl_scf_pw and ctrl_runner_pw functions
- Add local ctx variable inside ctrl_scf_pw and ctrl_runner_pw functions
- Update all template instantiations to match new function signatures

This refactoring simplifies the code by moving the ctx variable from
a class member to a local variable within the functions that need it.
The ctx variable is only used for template parameter deduction in
copy_d2h and get_pchg_pw/get_wf_pw functions, so it doesn't need to
be stored as a member variable.

* refactor(psi): add runtime type information to Setup_Psi_pw

- Add runtime type information (device_type_ and precision_type_) to Setup_Psi_pw
- Add accessor functions for basic information (get_nbands, get_nk, get_nbasis, size)
- Add accessor functions for runtime type information
- Add get_psi_t() function for backward compatibility

This is the first step of a gradual refactoring to remove template parameters
from Setup_Psi_pw in the future. The current changes are backward compatible
and do not affect existing functionality.

* refactor(esolver): use get_psi_t() accessor instead of direct psi_t access

- Replace all direct access to stp.psi_t with stp.get_psi_t()
- Replace stp.psi_t->get_nbands() with stp.get_nbands()
- This is the second step of gradual refactoring to prepare for removing template parameters

Modified files:
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_sdft_pw.cpp
- source/source_esolver/esolver_ks_lcaopw.cpp
- source/source_io/module_ctrl/ctrl_output_pw.cpp

* refactor(psi): change psi_t from template pointer to void*

- Change psi_t from psi::Psi<T, Device>* to void*
- Add static_cast in get_psi_t() function for type conversion
- Update all functions that use psi_t to use get_psi_t() or static_cast
- This is the third step of gradual refactoring to remove template parameters

Modified functions:
- before_runner: use if-else instead of ternary operator for void* assignment
- update_psi_d: use get_psi_t() to access psi_t
- init: use get_psi_t() to access psi_t
- copy_d2h: use get_psi_t() to access psi_t
- clean: use get_psi_t() to delete psi_t

* style: replace Chinese comments with English in setup_psi_pw.h

- Replace '原来的模板版本' with 'Original template version'
- Replace '使用 void* 存储指针,运行时类型信息记录实际类型' with 'Use void* to store pointer, runtime type information records actual type'
- Follow ABACUS code style guidelines for English-only comments

* refactor(psi): change psi_d from template pointer to void*

- Change psi_d from psi::Psi<std::complex<double>, Device>* to void*
- Add get_psi_d() accessor function for type conversion
- Update all functions that use psi_d to use get_psi_d()
- This is part of step 1 in phase 4 of gradual refactoring

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_io/module_ctrl/ctrl_output_pw.cpp

* refactor(psi): introduce PSIPrepareBase base class for template removal

This is the first step towards removing template parameters from Setup_Psi_pw.

Changes:
1. Create PSIPrepareBase base class
   - Non-template base class for PSIPrepare<T, Device>
   - Similar approach to HamiltBase for Hamilt<T, Device>

2. Modify PSIPrepare to inherit from PSIPrepareBase
   - Add #include "source_psi/psi_prepare_base.h"
   - Change class declaration to inherit from PSIPrepareBase

3. Update Setup_Psi_pw to use PSIPrepareBase*
   - Change p_psi_init from PSIPrepare<T, Device>* to PSIPrepareBase*
   - Add static_cast when calling PSIPrepare methods

4. Update all PSIPrepare usage in ESolver files
   - esolver_ks_pw.cpp: add static_cast before prepare_init call
   - esolver_ks_lcaopw.cpp: add static_cast before method calls

Modified files:
- source/source_psi/psi_prepare_base.h (new)
- source/source_psi/psi_prepare.h
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_ks_lcaopw.cpp

Benefits:
- Eliminates p_psi_init template dependency from Setup_Psi_pw
- Paves the way for removing template parameters from Setup_Psi_pw
- Maintains type safety through static_cast
- Follows the same pattern as HamiltBase refactoring

Tested: Compiled successfully in build_5pt and build_1p

* refactor(psi): change init() parameter from template to HamiltBase*

This is the second step towards removing template parameters from Setup_Psi_pw.

Changes:
1. Modify init() function signature
   - Change parameter from hamilt::Hamilt<T, Device>* to hamilt::HamiltBase*
   - Eliminates template dependency in function signature

2. Update init() implementation
   - Add static_cast<hamilt::Hamilt<T, Device>*> inside function
   - Maintain type safety through explicit cast

3. Update call site in esolver_ks_pw.cpp
   - Remove static_cast from call site
   - Directly pass p_hamilt (which is already HamiltBase*)

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_esolver/esolver_ks_pw.cpp

Benefits:
- init() function no longer depends on template parameters in signature
- Simplifies call sites (no cast needed)
- Follows the same pattern as p_hamilt storage in ESolver_KS
- One step closer to removing template parameters from Setup_Psi_pw

Tested: Compiled successfully in build_5pt and build_1p

* refactor(psi): remove template version of copy_d2h function

This is the third step towards removing template parameters from Setup_Psi_pw.

Changes:
1. Remove template version copy_d2h(const Device* ctx)
   - Delete the template version from setup_psi_pw.h
   - Delete the implementation from setup_psi_pw.cpp
   - Keep only the runtime version copy_d2h(const base_device::DeviceContext* ctx)

2. Update call site in ctrl_output_pw.cpp
   - Create Device* ctx = nullptr for template parameter deduction
   - Use DeviceContext::instance() for runtime device context
   - Call copy_d2h with DeviceContext* pointer

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_io/module_ctrl/ctrl_output_pw.cpp

Benefits:
- Eliminates copy_d2h function's template dependency
- All member functions now use runtime device context
- One step closer to removing template parameters from Setup_Psi_pw
- Maintains backward compatibility with existing code

Technical details:
- get_pchg_pw and get_wf_pw still need Device* ctx for template deduction
- DeviceContext is used for actual device type information
- This follows the gradual migration pattern used in ESolver refactoring

Tested: Compiled successfully in build_5pt and build_1p

* refactor(psi): remove castmem_2d_d2h_op template type alias dependency

This is the fourth step towards removing template parameters from Setup_Psi_pw.

Changes:
1. Remove castmem_2d_d2h_op type alias from setup_psi_pw.h
   - The type alias depended on template parameters T and Device
   - Replaced with overloaded member functions

2. Add castmem_d2h_impl() overloaded functions
   - One overload for std::complex<double> source
   - One overload for std::complex<float> source
   - Each uses the appropriate cast_memory_op internally

3. Update copy_d2h() to use the new overloaded functions
   - Calls castmem_d2h_impl() instead of castmem_2d_d2h_op()
   - Compiler selects the correct overload based on T type

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp

Benefits:
- All member variables now independent of template parameters
- castmem_d2h_impl encapsulates the type-dependent logic
- One step closer to removing template parameters from Setup_Psi_pw

Tested: Compiled successfully in build_5pt and build_1p

* delete useless files

* refactor(psi): remove template parameters from Setup_Psi_pw class

- Remove template parameters <T, Device> from Setup_Psi_pw class
- Convert member functions to template functions
- Update all call sites to explicitly specify template parameters
- This is a major refactoring step to enable runtime polymorphism

Modified files:
- source/source_psi/setup_psi_pw.h
- source/source_psi/setup_psi_pw.cpp
- source/source_esolver/esolver_ks_pw.h
- source/source_esolver/esolver_ks_pw.cpp
- source/source_esolver/esolver_sdft_pw.cpp
- source/source_esolver/esolver_ks_lcaopw.cpp
- source/source_io/module_ctrl/ctrl_output_pw.h
- source/source_io/module_ctrl/ctrl_output_pw.cpp

Key changes:
1. Setup_Psi_pw class no longer has template parameters
2. Member functions like get_psi_t(), get_psi_d(), before_runner(), init(), update_psi_d(), clean() are now template functions
3. All call sites now use stp.template get_psi_t<T, Device>() instead of stp.get_psi_t()
4. Removed template instantiation statements

* fix(psi): add explicit template instantiation for Setup_Psi_pw class

Fix undefined reference linker errors for template member functions:
- update_psi_d<T, Device>()
- copy_d2h<T, Device>()
- clean<T, Device>()
- before_runner<T, Device>()
- init<T, Device>()
- castmem_d2h_impl<T, Device>()

Changes:
1. Add explicit template instantiation for CPU version:
   - std::complex<float>, DEVICE_CPU
   - std::complex<double>, DEVICE_CPU

2. Add explicit template instantiation for GPU version (conditional):
   - std::complex<float>, DEVICE_GPU
   - std::complex<double>, DEVICE_GPU
   - Wrapped with #if ((defined __CUDA) || (defined __ROCM))

3. Fix template argument deduction error:
   - Add explicit template parameters <T, Device> when calling castmem_d2h_impl()
   - The template parameter T is not used in function parameters, so it cannot be deduced

Root cause:
Template functions defined in .cpp files require explicit instantiation
for each type combination used by other compilation units.

Modified files:
- source/source_psi/setup_psi_pw.cpp (+91 lines)

* refactor(psi): convert before_runner to non-template function

Convert Setup_Psi_pw::before_runner from template function to
non-template function with runtime type dispatch.

Changes:
1. setup_psi_pw.h:
   - Remove template parameters from before_runner declaration
   - Add private template function before_runner_impl for internal use

2. setup_psi_pw.cpp:
   - Rename original before_runner to before_runner_impl (template)
   - Add new non-template before_runner that dispatches based on:
     - inp.device (gpu or cpu)
     - inp.precision (single or double)
   - Update template instantiation from before_runner to before_runner_impl

3. esolver_ks_pw.cpp:
   - Update call from stp.before_runner<T, Device>(...)
     to stp.before_runner(...)

Benefits:
- Caller no longer needs to specify template parameters
- Type is determined at runtime from input parameters
- Simpler API for ESolver

* refactor(psi): convert init to non-template function

Convert Setup_Psi_pw::init from template function to non-template
function with runtime type dispatch based on device_type_ and
precision_type_ member variables.

Changes:
1. setup_psi_pw.h:
   - Change init parameter from Hamilt<T,Device>* to HamiltBase*
   - Add private template function init_impl for internal use

2. setup_psi_pw.cpp:
   - Rename original init to init_impl (template)
   - Add new non-template init that dispatches based on:
     - device_type_ (GpuDevice or CpuDevice)
     - precision_type_ (ComplexFloat or ComplexDouble)
   - Update template instantiation from init to init_impl

3. esolver_ks_pw.cpp:
   - Update call from stp.init<T, Device>(...) to stp.init(...)

Design principle:
before_runner sets device_type_ and precision_type_, subsequent
functions use these member variables for runtime dispatch.

* refactor(psi): move private member variables to private section

Move the following member variables from public to private:
- psi_t: accessible via get_psi_t<T, Device>()
- psi_d: accessible via get_psi_d<T, Device>()
- already_initpsi: internal use only
- device_type_: accessible via get_device_type()
- precision_type_: accessible via get_precision_type()

Keep the following in public:
- psi_cpu: directly accessed by 14 external locations
- p_psi_init: directly accessed by 3 external locations
- PrecisionType enum: used as return type of get_precision_type()

This improves encapsulation while maintaining backward compatibility
through accessor functions.

* refactor(psi): convert clean to non-template function

Convert Setup_Psi_pw::clean from template function to non-template
function with runtime type dispatch based on device_type_ and
precision_type_ member variables.

Changes:
1. setup_psi_pw.h:
   - Remove template parameters from clean declaration
   - Add private template function clean_impl for internal use

2. setup_psi_pw.cpp:
   - Rename original clean to clean_impl (template)
   - Add new non-template clean that dispatches based on:
     - device_type_ (GpuDevice or CpuDevice)
     - precision_type_ (ComplexFloat or ComplexDouble)
   - Replace PARAM.inp.device/precision checks with member variables
   - Update template instantiation from clean to clean_impl

3. esolver_ks_pw.cpp:
   - Update call from stp.clean<T, Device>() to stp.clean()

* refactor(psi): convert copy_d2h to non-template function

Convert Setup_Psi_pw::copy_d2h from template function to non-template
function with runtime type dispatch based on device_type_ and
precision_type_ member variables.

Changes:
1. setup_psi_pw.h:
   - Remove template parameters and DeviceContext parameter from copy_d2h
   - Add private template function copy_d2h_impl for internal use

2. setup_psi_pw.cpp:
   - Rename original copy_d2h to copy_d2h_impl (template)
   - Add new non-template copy_d2h that:
     - Returns early if device_type_ is not GpuDevice
     - Dispatches based on precision_type_ (ComplexFloat or ComplexDouble)
   - Update template instantiation from copy_d2h to copy_d2h_impl

3. ctrl_output_pw.cpp:
   - Simplify call from stp.template copy_d2h<T, Device>(device_ctx)
     to stp.copy_d2h()
   - Remove DeviceContext setup code for copy_d2h

* refactor(psi): convert update_psi_d to non-template function

Convert Setup_Psi_pw::update_psi_d from template function to non-template
function with runtime type dispatch based on device_type_ and
precision_type_ member variables.

Changes:
1. setup_psi_pw.h:
   - Remove template parameters from update_psi_d declaration
   - Add private template function update_psi_d_impl for internal use

2. setup_psi_pw.cpp:
   - Rename original update_psi_d to update_psi_d_impl (template)
   - Add new non-template update_psi_d that dispatches based on:
     - device_type_ (GpuDevice or CpuDevice)
     - precision_type_ (ComplexFloat or ComplexDouble)
   - Replace PARAM.inp.precision checks with precision_type_ member variable
   - Update template instantiation from update_psi_d to update_psi_d_impl

3. esolver_ks_pw.cpp:
   - Update calls from stp.update_psi_d<T, Device>() to stp.update_psi_d()

4. ctrl_output_pw.cpp:
   - Update calls from stp.template update_psi_d<T, Device>() to stp.update_psi_d()

This completes the refactoring of all Setup_Psi_pw member functions to
use runtime type dispatch instead of template parameters.

* refactor(exx): convert Exx_Helper to runtime polymorphism

Convert Exx_Helper from template member to runtime polymorphic pointer
using a base class pattern similar to Setup_Psi_pw.

Changes:
1. exx_helper_base.h (new):
   - Create pure virtual base class Exx_HelperBase
   - Use void* for template-dependent parameters

2. exx_helper.h:
   - Exx_Helper now inherits from Exx_HelperBase
   - All public methods marked as override

3. exx_helper.cpp:
   - Update function signatures to use void* parameters
   - Add static_cast for type conversion

4. esolver_ks_pw.h:
   - Change Exx_Helper<T, Device> exx_helper to Exx_HelperBase* exx_helper

5. esolver_ks_pw.cpp:
   - Create concrete Exx_Helper instance based on inp.device and inp.precision
   - Delete exx_helper in destructor

Benefits:
- ESolver_KS_PW no longer requires Exx_Helper template parameters
- Type determined at runtime from input parameters
- Consistent with Setup_Psi_pw refactoring pattern

* style: use static_cast instead of reinterpret_cast in deallocate_hamilt

Replace reinterpret_cast with static_cast when deleting HamiltPW pointer.
Since HamiltPW inherits from HamiltBase, static_cast is safer and more
appropriate for downcasting in inheritance hierarchies.

* refactor(estate): convert setup_estate_pw to non-template function

Convert setup_estate_pw and teardown_estate_pw from template functions to
non-template functions with runtime type dispatch based on inp.device and
inp.precision.

Changes:
1. setup_estate_pw.h:
   - Remove template parameters from setup_estate_pw and teardown_estate_pw
   - Add template implementation functions setup_estate_pw_impl and
     teardown_estate_pw_impl

2. setup_estate_pw.cpp:
   - Add non-template setup_estate_pw that dispatches based on:
     - inp.device (gpu or cpu)
     - inp.precision (single or double)
   - Rename original implementations to *_impl
   - Update template instantiation

3. esolver_ks_pw.cpp:
   - Update calls from setup_estate_pw<T, Device>(...) to setup_estate_pw(...)
   - Update calls from teardown_estate_pw<T, Device>(...) to teardown_estate_pw(...)

This simplifies the calling code in ESolver_KS_PW by removing template
parameters while maintaining the same functionality through runtime dispatch.

---------

Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
@mohanchen mohanchen requested a review from ZhouXY-PKU March 15, 2026 09:49
@mohanchen mohanchen closed this Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.