Skip to content

Commit fac9330

Browse files
mohanchenabacus_fixer
andauthored
Remove GlobalC::exx_info entirely, refactor ESolver, add esolver_refactor.cpp, remove most PARAM in ESolver (deepmodeling#7805)
* refactor: shorten long filenames in source (phase 1) Rename 7 files (32-29 chars → 12-22 chars): - charge_mixing_preconditioner.cpp → mix_precond.cpp - spherical_bessel_transformer.{cpp,h} → sph_bessel_tf.{cpp,h} - read_input_item_postprocess.cpp → read_inp_postproc.cpp - gint_vl_metagga_nspin4_gpu.{cpp,h} → gint_vl_mgga_n4_gpu.{cpp,h} - snap_projector_half_tddft.{cpp,h} → snap_proj_half_tddft.{cpp,h} Update all #include references, CMakeLists.txt, Makefile.Objects, header guards, and code comments. Function names (e.g. snap_projector_half_tddft) are preserved unchanged. * refactor: shorten long filenames in source (phase 2) Rename 15 files (29-25 chars → 12-21 chars): - read_input_item_elec_stru.cpp → read_inp_estruc.cpp - gint_precision_controller.{cpp,h} → gint_prec_ctrl.{cpp,h} - global_function-func_each_2.h → glob_fn_each2.h - snap_phialpha_half_tddft.{cpp,h} → snap_pha_half_tddft.{cpp,h} - snap_psibeta_half_tddft.{cpp,h} → snap_psb_half_tddft.{cpp,h} - symmetry_rotation_output.cpp → symm_rot_out.cpp - read_input_item_exx_dftu.cpp → read_inp_exx_dftu.cpp - write_mlkedf_descriptors.{cpp,h} → write_mlkedf_desc.{cpp,h} - global_function_ddotreal.cpp → glob_fn_ddotreal.cpp - exx_abfs-construct_orbs.{cpp,h} → exx_abfs_ctor_orbs.{cpp,h} Update all #include references, CMakeLists.txt, Makefile.Objects, and header guards. Function and variable names preserved unchanged. * refactor: shorten long filenames in source (phase 3) Rename 8 files (27-25 chars → 12-21 chars): - to_wannier90_lcao_in_pw.{cpp,h} → to_w90_lcao_pw.{cpp,h} - dist_matrix_transformer.{cpp,h} → dist_mat_tf.{cpp,h} - element_basis_index-ORB.{cpp,h} → elem_basis_idx_orb.{cpp,h} - sph_bessel_recursive-d1.cpp → sph_bessel_rec_d1.cpp - sph_bessel_recursive-d2.cpp → sph_bessel_rec_d2.cpp Update all #include references, CMakeLists.txt, Makefile.Objects, and header guards. Function and class names preserved unchanged. * refactor: shorten long filenames in source (phase 4) Rename 20 files (26 chars → 12-20 chars), including 6 .cpp/.h pairs: - lattice_change_methods.{cpp,h} → lat_change_method.{cpp,h} - vec_mul_vec_complex_op.{cpp,h} → vec_mul_cx_op.{cpp,h} - psi_init_atomic_random.{cpp,h} → psi_init_atom_rand.{cpp,h} - cal_mlkedf_descriptors.{cpp,h} → cal_mlkedf_desc.{cpp,h} - gint_vl_metagga_nspin4.{cpp,h} → gint_vl_mgga_n4.{cpp,h} - symmetry_rotation_spin.{cpp,h} → symm_rot_spin.{cpp,h} - irreducible_sector_bvk.cpp → irred_sec_bvk.cpp - read_input_item_{system,output,deepks}.cpp → read_inp_{sys,out,deepks}.cpp - charge_mixing_residual.cpp → mix_resid.cpp - elecstate_energy_terms.cpp → estate_e_terms.cpp - pw_distributeg_method{1,2}.cpp → pw_distg_method{1,2}.cpp Update all #include references, CMakeLists.txt, Makefile.Objects, Makefile, header guards, and WARNING string literals. Function, class, and struct names preserved unchanged. * refactor: shorten long filenames in source (phase 4) Rename 20 files (26 chars → 12-20 chars), including 6 .cpp/.h pairs: - lattice_change_methods.{cpp,h} → lat_change_method.{cpp,h} - vec_mul_vec_complex_op.{cpp,h} → vec_mul_cx_op.{cpp,h} - psi_init_atomic_random.{cpp,h} → psi_init_atom_rand.{cpp,h} - cal_mlkedf_descriptors.{cpp,h} → cal_mlkedf_desc.{cpp,h} - gint_vl_metagga_nspin4.{cpp,h} → gint_vl_mgga_n4.{cpp,h} - symmetry_rotation_spin.{cpp,h} → symm_rot_spin.{cpp,h} - irreducible_sector_bvk.cpp → irred_sec_bvk.cpp - read_input_item_{system,output,deepks}.cpp → read_inp_{sys,out,deepks}.cpp - charge_mixing_residual.cpp → mix_resid.cpp - elecstate_energy_terms.cpp → estate_e_terms.cpp - pw_distributeg_method{1,2}.cpp → pw_distg_method{1,2}.cpp Update all #include references, CMakeLists.txt, Makefile.Objects, Makefile, header guards, and WARNING string literals. Function, class, and struct names preserved unchanged. * refactor: shorten long filenames in source (phase 5, revised) Rename 11 files (25 chars → 14-20 chars), including 3 .cpp/.h pairs: - LCAO_deepks_interface.{cpp,h} → lcao_deepks_iface.{cpp,h} - para_linear_transform.{cpp,h} → para_lin_tf.{cpp,h} - read_input_item_{tddft,relax,other,ofdft,model}.cpp → read_inp_{...}.cpp - vdwd3_autoset_xcparam.cpp → vdwd3_auto_xcpar.cpp - element_covalent_radius.h → elem_cov_rad.h Update all #include references, CMakeLists.txt, Makefile.Objects, header guards, and python pyabacus references. Function, class, and variable names preserved unchanged. Note: esolver_ks_lcao_tddft, two_center_integrator, and blas_connector files are intentionally kept unchanged per user request. * refactor: normalize LCAO_ prefix filenames to lowercase (phase A) Rename 16 files from LCAO_* to lcao_* (remove uppercase letters): - LCAO_allocate.cpp → lcao_allocate.cpp - LCAO_domain.h → lcao_domain.h - LCAO_HS_arrays.hpp → lcao_hs_arrays.hpp - LCAO_init_basis.cpp → lcao_init_basis.cpp - LCAO_nl_mu.cpp → lcao_nl_mu.cpp - LCAO_nonlocal_info.h → lcao_nonlocal_info.h - LCAO_set.{cpp,h} → lcao_set.{cpp,h} - LCAO_set_{fs,mat2d,st,zero}.cpp → lcao_set_{...}.cpp - LCAO_deepks.{cpp,h} → lcao_deepks.{cpp,h} - LCAO_deepks_io.{cpp,h} → lcao_deepks_io.{cpp,h} Update all #include references, CMakeLists.txt, Makefile.Objects, and code comments. Namespace names (LCAO_domain::), class names, and header guards preserved unchanged. * refactor: normalize ORB_ prefix filenames to lowercase (phase B) Rename 18 files from ORB_* to orb_* (remove uppercase letters): - ORB_atomic.{cpp,h} → orb_atomic.{cpp,h} - ORB_atomic_lm.{cpp,h} → orb_atomic_lm.{cpp,h} - ORB_gaunt_table.{cpp,h} → orb_gaunt_table.{cpp,h} - ORB_nonlocal.{cpp,h} → orb_nonlocal.{cpp,h} - ORB_nonlocal_lm.{cpp,h} → orb_nonlocal_lm.{cpp,h} - ORB_read.{cpp,h} → orb_read.{cpp,h} - ORB_{atomic_lm,nonlocal_lm,nonlocal,read}_test.cpp → orb_{...}_test.cpp - ORB_unittest.{cpp,h} → orb_unittest.{cpp,h} Update all #include references, CMakeLists.txt, Makefile.Objects, and README. Class names, header guards, and CMake target identifiers preserved unchanged. * refactor: normalize ORB_ prefix filenames to lowercase (phase B) Rename 18 files from ORB_* to orb_* (remove uppercase letters): - ORB_atomic.{cpp,h} → orb_atomic.{cpp,h} - ORB_atomic_lm.{cpp,h} → orb_atomic_lm.{cpp,h} - ORB_gaunt_table.{cpp,h} → orb_gaunt_table.{cpp,h} - ORB_nonlocal.{cpp,h} → orb_nonlocal.{cpp,h} - ORB_nonlocal_lm.{cpp,h} → orb_nonlocal_lm.{cpp,h} - ORB_read.{cpp,h} → orb_read.{cpp,h} - ORB_{atomic_lm,nonlocal_lm,nonlocal,read}_test.cpp → orb_{...}_test.cpp - ORB_unittest.{cpp,h} → orb_unittest.{cpp,h} Update all #include references, CMakeLists.txt, Makefile.Objects, and README. Class names, header guards, and CMake target identifiers preserved unchanged. * refactor: normalize H_/FORCE_/forces_ filenames (phase C) Rename 21 files, add module suffixes for force files, and update header guards: Correction abbreviation: - H_correction_pw.cpp → h_corr_pw.cpp Hamiltonian uppercase prefixes (H_* → h_*): - H_Ewald_pw.{cpp,h} → h_ewald_pw.{cpp,h} - H_Hartree_pw.{cpp,h} → h_hartree_pw.{cpp,h} - H_TDDFT_pw.{cpp,h} → h_tddft_pw.{cpp,h} LCAO force files (FORCE_* → force_lcao_*, FORCE_STRESS → force_stress_lcao): - FORCE.h → force_lcao.h - FORCE_gamma.cpp → force_lcao_gamma.cpp - FORCE_k.cpp → force_lcao_k.cpp - FORCE_STRESS.{cpp,h} → force_stress_lcao.{cpp,h} PW force files (forces_* → force_pw_*, distinguish from LCAO): - forces.{cpp,h} → force_pw.{cpp,h} - forces_nl.cpp → force_pw_nl.cpp - forces_onsite.cpp → force_pw_onsite.cpp - forces_scc.cpp → force_pw_scc.cpp - forces_us.cpp → force_pw_us.cpp - forces_cc.cpp → force_pw_cc.cpp Test files: - opt_CG_test.cpp → opt_cg_test.cpp - opt_TN_test.cpp → opt_tn_test.cpp Header guards updated: HHARTREEPW_H → H_HARTREE_PW_H, FORCES_H → FORCE_PW_H. Update all #include references, CMakeLists.txt, and Makefile.Objects. Class/variable names preserved. * refactor: normalize Matrix_/Mix_/RI_/RPA_/LRI_ filenames (phase D) Rename 24 files to lowercase in source_lcao/module_ri/: - Matrix_Orbs{11,21,22}.{cpp,h,hpp} → matrix_orbs{11,21,22}.{cpp,h,hpp} - Mix_DMk_2D.{cpp,h} → mix_dmk_2d.{cpp,h} - RI_2D_Comm.{cpp,h,hpp} → ri_2d_comm.{cpp,h,hpp} - RI_Util.{h,hpp} → ri_util.{h,hpp} - RPA_LRI.{h,hpp} → rpa_lri.{h,hpp} - LRI_CV.{h,hpp} → lri_cv.{h,hpp} - LRI_CV_Tools.{h,hpp} → lri_cv_tools.{h,hpp} - make_gaunt_table-unittest.h → make_gaunt_table_unittest.h Update all #include references, CMakeLists.txt, and Makefile.Objects. Class names, namespace names, and header guards preserved unchanged. * refactor: replace dashes with underscores in filenames (phase E) Rename 22 files, replacing '-' with '_' and normalizing case: - ABFs_Construct-PCA.{cpp,h} → abfs_construct_pca.{cpp,h} - abfs-vector3_order.{h} → abfs_vector3_order.{h} - abfs-vector3_order_test.cpp → abfs_vector3_order_test.cpp - center2_orb-orb{11,21,22}.{cpp,h} → center2_orb_orb{11,21,22}.{cpp,h} - exx_abfs-io.{cpp,h} → exx_abfs_io.{cpp,h} - exx_abfs-jle.{cpp,h} → exx_abfs_jle.{cpp,h} - exx_opt_orb-print.cpp → exx_opt_orb_print.cpp - exx_abfs-construct_orbs-test.h → exx_abfs_construct_orbs_test.h - gram_schmidt_orth-inl.h → gram_schmidt_orth_inl.h - matrix-inl.h → matrix_inl.h - scalapack-test.cpp → scalapack_test.cpp - element_basis_index-{test.h,unittest.cpp} → element_basis_index_{test.h,unittest.cpp} - Inverse_Matrix-test.h → invmat_ri_test.h Update all #include references, CMakeLists.txt, Makefile.Objects, and code comments. Class names and header guards preserved unchanged. * refactor: normalize remaining uppercase filenames to lowercase (phase F) Rename 44 files, converting uppercase letters to lowercase: - Cblacs.h → cblacs.h - cal_pLpR.{cpp,h} → cal_plpr.{cpp,h} - cal_r_overlap_R.{cpp,h} → cal_r_overlap_r.{cpp,h} - ewald_Vq.{h,hpp} → ewald_vq.{h,hpp} - ExxLriDetail.{cpp,h} → exx_lri_detail.{cpp,h} - Exx_LRI.{h,hpp} → exx_lri.{h,hpp} - Exx_LRI_interface.{h,hpp} → exx_lri_interface.{h,hpp} - fR_overlap.{cpp,h} → fr_overlap.{cpp,h} - Inverse_Matrix.{h,hpp} → invmat_ri.{h,hpp} - opt_TN.hpp → opt_tn.hpp - single_R_io.{cpp,h} → single_r_io.{cpp,h} - symmetry_rotation_R{,_hcontainer}.hpp → symmetry_rotation_r{,_hcontainer}.hpp - write_dH{,_terms}.{cpp,h} → write_dh{,_terms}.{cpp,h} - write_HS{,_R,_sparse}.{cpp,h} → write_hs{,_r,_sparse}.{cpp,h} - write_H_terms.{cpp,h} → write_h_terms.{cpp,h} - pw_basis_{C2C,C2R}.cpp → pw_basis_{c2c,c2r}.cpp - pw_basis_k_C2C.cpp → pw_basis_k_c2c.cpp - test_T_NL_cd.cpp → test_t_nl_cd.cpp - test-{big,other}.cpp → test_{big,other}.cpp - test_hcontainer_readCSR.cpp → test_hcontainer_read_csr.cpp - test_{cal_dm_R,dm_R_init}.cpp → test_{cal_dm_r,dm_r_init}.cpp Update all #include references, CMakeLists.txt, Makefile.Objects, CMake target names, and code comments. Class names, function names, namespace names, and header guards preserved unchanged. * Rename test files to follow source file renames Rename 6 test files to match their already-renamed source files: - spherical_bessel_transformer_test → sph_bessel_tf_test - gint_precision_controller_test → gint_prec_ctrl_test - snap_psibeta_half_tddft_test → snap_psb_half_tddft_test - lattice_change_methods_test → lat_change_method_test - symmetry_rotation_spin_test → symm_rot_spin_test - symmetry_rho_soc_test → symm_rho_soc_test Update CMakeLists.txt entries and log file references accordingly. * update * Simplify test file names using standard abbreviations (Phase G2) Apply KISS abbreviation rules to 15 test files: - construct→ctor, radial→rad, interpolation→interp - integrator→integ, initializer→init, recursive→rec - clebsch_gordan→cg (math standard), element→elem, index→idx - vector3→vec3, algorithms→algo, helper→hlp - system→sys, variable→var, chebyshev→cheby - operator→op Update CMakeLists.txt entries, #include paths, and header guards accordingly. * Replace dashes with underscores in test file names (Phase G3) Rename 42 numbered test files in source_basis/module_pw/test/: - test1-1-1.cpp → test1_1_1.cpp - test1-2.cpp → test1_2.cpp - ... (all test*-*.cpp files) Update CMakeLists.txt references accordingly. Follows project naming convention: filenames must use underscores, not dashes. * Rename: normalize source file naming across modules - source_base: lowercase opt_CG/opt_DCsrch → opt_cg/opt_dcsrch (4 files) - symmetry modules: unify symmetry_ → symm_ prefix (16 renamed, 61 total files updated across source_cell/symmetry, source_estate, source_lcao/module_ri/module_exx_symmetry, and all call sites; module entry points symmetry.h / symmetry.cpp unchanged, class names Symmetry_Basic / Symmetry_rho / Symmetry_rotation preserved) - source_cell: unify read_pseudo → read_pp_ucell to match read_pp series (2 renamed, 18 total files updated across CMake targets, Makefile.Objects, and callers; function names untouched) - test files: unify _unittest suffix → _test (4 files: orb_test, element_basis_index_test, make_gaunt_table_test; include paths and header guards synced) - source_lcao: disambiguate duplicate dftu_lcao name — rename dftu_lcao.{cpp,h} → setup_dftu_lcao.{cpp,h} (init/finish helpers); module_operator_lcao/dftu_lcao (DFTU operator implementation) retains original name * update makefile in module_pw * solve conflict * Fix psi_init_atom_rand to match updated base class interface - Update initialize() signature to match psi_init_atomic's new interface - Use this->npol_ instead of PARAM.globalv.npol - Remove unnecessary includes (vnl_pw.h, parameter.h) * Add missing pw_basis_k.h include to psi_init_atom_rand.cpp The init_psig() method accesses pw_wfc_->npwk_max which requires the complete type of ModulePW::PW_Basis_K, not just the forward declaration. * refactor(exx): bridge GlobalC::exx_info through ESolver_KS member pointer Add Exx_Info* exx_info_ member to ESolver_KS base class, initialized to &GlobalC::exx_info in the constructor. Replace all direct GlobalC::exx_info accesses in ESolver subclasses (LCAO, LCAOPW, PW, LCAO_TDDFT) with exx_info_-> member access. This is the first step toward removing the GlobalC::exx_info global. The global still exists; this commit only introduces the indirection layer so subsequent commits can redirect the pointer to an owned Exx_Info instance. * refactor(exx): pass Exx_Info through LCAO module parameters Replace GlobalC::exx_info accesses in the LCAO module with explicit parameter passing: - setup_exx: add Exx_Info& param to init/before_runner/before_scf - HamiltLCAO: add const Exx_Info& param to constructor, forward to OperatorEXX - OperatorEXX: add const Exx_Info*/const Exx_Info& params to both constructors, store as exx_info_ptr member - Force_Stress_LCAO::getForceStress: add const Exx_Info& param - LCAO_domain::set_pot: add Exx_Info& param, forward to exx_nao - RDMFT: add const Exx_Info& param to init, store as exx_info_ member - Update all call sites in esolver_ks_lcao, esolver_ks_lcao_tddft, esolver_double_xc, lcao_others, write_vxc to pass exx_info The source_io module (write_vxc.hpp) still uses GlobalC::exx_info directly and will be addressed in a subsequent commit. * refactor(exx): pass Exx_Info through PW module parameters Replace GlobalC::exx_info accesses in the PW module with explicit parameter passing: - HamiltPW: add const Exx_Info* param to constructor, use it for EXX operator initialization - Exx_HelperBase/Exx_Helper: add const Exx_Info& param to init() and before_scf() virtual methods - Stress_PW::cal_stress: add const Exx_Info& param for EXX stress - HSolverLIP::solve: add const Exx_Info& param for LCAO-in-PW EXX - Update all call sites in esolver_ks_pw, esolver_ks_lcaopw - Update HamiltLIP and HamiltSdftPW derived constructors to pass nullptr to HamiltPW base - Update all test mock implementations and call sites The source_io module still uses GlobalC::exx_info directly and will be addressed in a subsequent commit. * refactor(exx): ESolver_KS owns Exx_Info value object Change ESolver_KS from holding a pointer to GlobalC::exx_info to owning its own Exx_Info value member (exx_info_obj_). The constructor copies the content from GlobalC::exx_info (initialized by Input_Conv::Convert) into the owned object, so ESolver internals now operate on their own copy. The exx_info_ pointer still points to exx_info_obj_ for uniform access, preserving the parameter-passing pattern established in the previous commits. This breaks the runtime dependency on GlobalC::exx_info from ESolver internals and prepares for removing the global entirely in the next commit. GlobalC::exx_info is kept for now as other modules still reference it during the transition. * refactor(exx): remove GlobalC::exx_info global variable Remove the GlobalC::exx_info global instance entirely. The Exx_Info data is now owned by ESolver_KS (exx_info_obj_ member) and passed through function parameters to all consumers. Key changes: - Extract Exx_Info initialization logic from Input_Conv::Convert() into a standalone init_exx_info(Exx_Info&, const Input_para&) function in exx_info.cpp. ESolver_KS constructor calls this to initialize its owned Exx_Info object directly from input parameters. - Remove GlobalC::exx_info extern declaration and definition. - Add const Exx_Info& parameter to all functions that previously accessed GlobalC::exx_info: ctrl_runner_lcao, ctrl_scf_lcao, ctrl_iter_lcao, ctrl_output_td, write_dH_components, write_dH_sum, write_dH_exx, write_h_exx, write_Vxc, write_eband_terms, sum_HR, write_current, and their helper functions. - Update all call sites in ESolver to pass *exx_info_ (the owned Exx_Info object). - ESolver_LR (LR-TDDFT) now owns its Exx_Info as a value member initialized via init_exx_info instead of referencing the global. - Update stale include comments referencing GlobalC::exx_info. * move function from constructor to before_all_runners * clean exx_info_ * fix bug * refactor(exx): extract CoulombParam types into coulomb_config.h Extract Coulomb_Type, Ccp_Type, Coulomb_Method enums and CoulombParam alias from conv_coulomb_pot_k.h into a new header coulomb_config.h under module_xc. This separates the basis-type-independent Coulomb configuration types from the LCAO-specific algorithm declarations, allowing PW modules to depend only on the lightweight config header. Step 1 of 5: Extract Coulomb config types from module_ri to module_xc. * refactor(exx): extract General_Exx_Info and init_general_exx_info Create General_Exx_Info struct in general_exx_info.h containing the basis-type-independent EXX fields (cal_exx, hybrid_alpha, coulomb_param, ccp_type, hse_omega, separate_loop, hybrid_step, mixing_beta_for_loop1). Exx_Info_Global now inherits from General_Exx_Info for backward compat. Extract init_general_exx_info() from init_exx_info(): the general function fills only General_Exx_Info fields, while init_exx_info() delegates to it then fills LCAO-specific sub-structures (info_ri, info_opt_abfs, info_lip) and calls sync_from_global(). Step 2 of 5: Introduce General_Exx_Info and split init logic. * refactor(exx): switch PW interfaces from Exx_Info to General_Exx_Info Replace Exx_Info with General_Exx_Info in all PW-facing interfaces: - HamiltPW constructor: const Exx_Info* -> const General_Exx_Info* - Stress_PW::cal_stress: const Exx_Info& -> const General_Exx_Info& - Exx_HelperBase/Exx_Helper::init/before_scf: same change - HSolverLIP::solve: same change In ESolver_KS_PW and ESolver_KS_LIP, pass exx_info_.info_global (which inherits from General_Exx_Info) to the new PW interfaces. Update test mocks (diago_mock.h, test_hamilt_sto.cpp, test_sto_tool.cpp) and test_hsolver_pw.cpp to use General_Exx_Info. PW modules no longer depend on exx_info.h; they include only the lightweight general_exx_info.h and coulomb_config.h. Step 3 of 5: Switch PW interfaces to General_Exx_Info. * refactor(exx): move Exx_Info from ESolver_KS to ESolver_KS_LCAO Replace Exx_Info exx_info_ in ESolver_KS base class with the lightweight General_Exx_Info general_exx_info_. The full Exx_Info (with info_ri, info_opt_abfs, info_lip) is now owned by ESolver_KS_LCAO, which calls init_exx_info() in its before_all_runners(). ESolver_KS_LIP (LCAO_in_PW) inherits general_exx_info_ from ESolver_KS_PW and owns a new Exx_Info_Lip info_lip_ member, initialized from general_exx_info_ (ccp_type, hse_omega) and inp.exx_fock_lambda (lambda). PW branch (ESolver_KS_PW) now uses general_exx_info_ directly instead of exx_info_.info_global. Step 4 of 5: Move Exx_Info member to LCAO subclass. * refactor(exx): update exx_info_lip.h to use coulomb_config.h Replace heavy conv_coulomb_pot_k.h include with lightweight coulomb_config.h in exx_info_lip.h, since only Ccp_Type is needed. Step 5 of 5: Final cleanup and verification. All 5 steps complete: 1. Extract CoulombParam types into coulomb_config.h 2. Introduce General_Exx_Info and init_general_exx_info 3. Switch PW interfaces to General_Exx_Info 4. Move Exx_Info member from ESolver_KS to ESolver_KS_LCAO 5. Final cleanup and verification Key results: - PW modules no longer depend on exx_info.h or module_ri - ESolver_KS base class uses lightweight General_Exx_Info - ESolver_KS_LCAO owns full Exx_Info (info_ri, info_opt_abfs, info_lip) - ESolver_KS_LIP owns Exx_Info_Lip info_lip_ separately - All tests pass (MODULE_PW_Sto, MODULE_HSOLVER_pw, MODULE_HAMILT_XCTest_HSE) * refactor(esolver): extract init_esolver factory from base class file The factory functions init_esolver() and determine_type() were previously hosted in esolver.cpp, which is nominally the implementation file of the abstract base class ESolver. To instantiate the concrete derived classes (ESolver_KS_PW, ESolver_KS_LCAO, ESolver_OF, etc.), esolver.cpp had to #include 13 derived-class headers, making the base-class file reverse- depend on all its derivatives. This violates ABACUS coding rule 3 ("Keep header dependencies minimal") and the dependency-inversion principle. Fix by moving the factory code into a dedicated esolver_factory module so that esolver.h/cpp only carries the ESolver interface and knows nothing about derived classes. The factory is the single place allowed to see both the interface and all concrete implementations, which is its essential responsibility. Changes: - Add source/source_esolver/esolver_factory.h with declarations of determine_type() and init_esolver(); forward-declares Input_para and ESolver to keep includes minimal. - Add source/source_esolver/esolver_factory.cpp containing the full bodies of determine_type() and init_esolver() moved verbatim from esolver.cpp, plus the 13 derived-class includes that now live here. - Remove source/source_esolver/esolver.cpp (its entire content was the factory code; the ESolver base class has no out-of-line members). - Trim source/source_esolver/esolver.h: drop determine_type() and init_esolver() declarations and their doxygen blocks. The Input_para forward declaration is retained because before_all_runners() takes it as a parameter. - Update source/source_esolver/CMakeLists.txt and source/Makefile.Objects to compile esolver_factory.cpp instead of esolver.cpp. - Add explicit #include "source_esolver/esolver_factory.h" in source/source_main/driver_run.cpp, the sole caller of init_esolver(); previously the declaration was pulled in transitively via relax_driver.h. No runtime behavior change. After this refactor, touching a derived esolver header no longer forces recompilation of the base-class file. Verified: incremental build of `esolver` and `abacus_std_para` targets in build_std_para (ENABLE_LCAO=ON) passes. * remove PARAM.inp in esolver * Refactor ESolver_LR: remove redundant input member, use base class inp_ Problem: ESolver_LR maintained a redundant 'const Input_para& input;' member bound in the constructor, while the base class ESolver already provides 'const Input_para* inp_' bound during before_all_runners(). This duplication existed as a workaround for a bug: in the 'ks-lr' branch of before_all_runners, inp_ was never assigned (only the temporary ks_solver.inp_ was set), so ESolver_LR could not rely on inp_ and instead used its own reference member. Changes: 1. esolver_lr_lcao_tddft.cpp: - Add 'this->inp_ = &inp;' at the beginning of before_all_runners() to ensure inp_ is bound in both 'ks-lr' and 'lr' branches. - Remove 'input(inp)' from the constructor initializer list. - Replace all 'input.xxx' and 'this->input.xxx' with 'this->inp_->xxx'. - Remove GlobalC::exx_info from constructor initializer list (already removed upstream; init_exx_info handles full initialization from inp). - Fix uninitialized 'inp' variable in setup_2center_table() (was 'inp.' but the function has no 'inp' parameter; changed to 'input.' and then to 'this->inp_->'). 2. esolver_lr_lcao_tddft.h: - Remove the redundant 'const Input_para& input;' member declaration. 3. esolver_lr_lcao_bse.cpp: - Replace all 'this->input.xxx' with 'this->inp_->xxx'. - Replace 'GlobalC::exx_info.info_ri' with 'this->exx_info.info_ri' (use inherited member instead of removed global). Verification: - Built successfully with 'make -j 20' in build_max_para_test/. - Not committed until now per user request. * fix bug * move codes in ESolver_KS_LCAO_TDDFT constructor to before_all_runners * delete useless constructor in sto_che * support C++11 only * update esolvers * Fix EXX dH null-deref: require Exx_Info in OperatorEXX, thread through write_dH_exx path Remove the = nullptr default on the one-shot OperatorEXX constructor so Exx_Info is a required dependency, and thread const Exx_Info& through write_dH_exx_impl / fill_dH_exx. Otherwise cal_dH dereferences a null exx_info_ptr->info_global.hybrid_alpha when EXX dH is written. * remove PARAM * fix bug in lr-tddft --------- Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>
1 parent 815c370 commit fac9330

100 files changed

Lines changed: 1504 additions & 1248 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

source/Makefile.Objects

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ OBJS_ELECSTAT_LCAO=elecstate_lcao.o\
272272
cal_dm_psi.o\
273273
cal_edm_tddft.o\
274274

275-
OBJS_ESOLVER=esolver.o\
275+
OBJS_ESOLVER=esolver_factory.o\
276276
esolver_ks.o\
277277
esolver_fp.o\
278278
esolver_ks_pw.o\

source/source_esolver/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
list(APPEND objects
2-
esolver.cpp
2+
esolver_factory.cpp
33
esolver_ks.cpp
44
esolver_fp.cpp
55
esolver_ks_pw.cpp

source/source_esolver/esolver.h

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,26 +49,11 @@ class ESolver
4949
bool conv_esolver = true; // whether esolver is converged
5050

5151
std::string classname;
52-
};
5352

54-
/**
55-
* @brief A subrutine called in init_esolver()
56-
* This function returns type of ESolver
57-
* Based on PARAM.inp.basis_type and PARAM.inp.esolver_type
58-
* @return [out] std::string The type of ESolver
59-
*/
60-
std::string determine_type();
61-
62-
/**
63-
* @brief Determine and initialize an ESolver based on input information.
64-
*
65-
* This function determines the type of ESolver to create based on input information and initializes
66-
* the corresponding ESolver child class. It supports various ESolver types including ksdft_pw,
67-
* ksdft_lcao, ksdft_lcao_tddft, sdft_pw, ofdft, lj_pot, and dp_pot.
68-
*
69-
* @return [out] A pointer to an ESolver object that will be initialized.
70-
*/
71-
ESolver* init_esolver(const Input_para& inp);
53+
protected:
54+
/// Bound in before_all_runners; members use inp_->xxx instead of PARAM.inp.xxx
55+
const Input_para* inp_ = nullptr;
56+
};
7257

7358
} // namespace ModuleESolver
7459

source/source_esolver/esolver_dfpt_pw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void ESolver_DFPT_PW::init_dfpt(UnitCell& ucell)
8686

8787
dfpt_ = new ModuleDFPT::DFPT_PW();
8888

89-
// dfpt_->init(ucell, *this->stp.psi, this->pelec->nelec, PARAM.inp.ecutwfc);
89+
// dfpt_->init(ucell, *this->stp.psi, this->pelec->nelec, this->inp_->ecutwfc);
9090

9191
dfpt_->set_parameters("dfpt.in");
9292

source/source_esolver/esolver_dm2rho.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,17 +58,17 @@ void ESolver_DM2rho<TK, TR>::runner(BaseCell& basecell, const int istep)
5858
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(this->dmat.dm->get_DMR_pointer(1)));
5959

6060
// if nspin=2, need extra reading
61-
if (PARAM.inp.nspin == 2)
61+
if (this->inp_->nspin == 2)
6262
{
6363
zipname = "output_DM1.npz";
6464
ModuleIO::read_mat_npz(&(this->pv), ucell, zipname, *(this->dmat.dm->get_DMR_pointer(2)));
6565
}
6666

6767
// it's dangerous to design psiToRho function like this, mohan note 20251024
6868
// this->pelec->psiToRho(*this->psi);
69-
LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), PARAM.inp.nspin, &this->chr);
69+
LCAO_domain::dm2rho(this->dmat.dm->get_DMR_vector(), this->inp_->nspin, &this->chr);
7070

71-
int nspin0 = PARAM.inp.nspin == 2 ? 2 : 1;
71+
int nspin0 = this->inp_->nspin == 2 ? 2 : 1;
7272

7373
for (int is = 0; is < nspin0; is++)
7474
{
@@ -78,7 +78,7 @@ void ESolver_DM2rho<TK, TR>::runner(BaseCell& basecell, const int istep)
7878
ModuleIO::write_vdata_palgrid(this->Pgrid,
7979
this->chr.rho[is],
8080
is,
81-
PARAM.inp.nspin,
81+
this->inp_->nspin,
8282
istep,
8383
fn,
8484
this->pelec->eferm.get_efval(is),

source/source_esolver/esolver_double_xc.cpp

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(BaseCell& basecell, const Inpu
6464
int ncol = 0;
6565
if (PARAM.globalv.gamma_only_local)
6666
{
67-
nsk = PARAM.inp.nspin;
67+
nsk = this->inp_->nspin;
6868
ncol = this->pv.ncol_bands;
69-
if (PARAM.inp.ks_solver == "genelpa" || PARAM.inp.ks_solver == "elpa" || PARAM.inp.ks_solver == "lapack"
70-
|| PARAM.inp.ks_solver == "pexsi" || PARAM.inp.ks_solver == "cusolver"
71-
|| PARAM.inp.ks_solver == "cusolvermp")
69+
if (this->inp_->ks_solver == "genelpa" || this->inp_->ks_solver == "elpa" || this->inp_->ks_solver == "lapack"
70+
|| this->inp_->ks_solver == "pexsi" || this->inp_->ks_solver == "cusolver"
71+
|| this->inp_->ks_solver == "cusolvermp")
7272
{
7373
ncol = this->pv.ncol;
7474
}
@@ -79,19 +79,19 @@ void ESolver_DoubleXC<TK, TR>::before_all_runners(BaseCell& basecell, const Inpu
7979
#ifdef __MPI
8080
ncol = this->pv.ncol_bands;
8181
#else
82-
ncol = PARAM.inp.nbands;
82+
ncol = this->inp_->nbands;
8383
#endif
8484
}
8585
this->psi_base = new psi::Psi<TK>(nsk, ncol, this->pv.nrow, this->kv.ngk, true);
8686
}
8787

8888
// 6) initialize the density matrix
89-
this->dmat_base.allocate_dm(&this->kv, &this->pv, PARAM.inp.nspin);
89+
this->dmat_base.allocate_dm(&this->kv, &this->pv, this->inp_->nspin);
9090

9191
// 10) inititlize the charge density
9292
this->chr_base.set_rhopw(this->pw_rhod); // mohan add 20251130
9393
const bool kin_den = this->chr_base.kin_density(); // mohan add 20251202
94-
this->chr_base.allocate(PARAM.inp.nspin, kin_den);
94+
this->chr_base.allocate(this->inp_->nspin, kin_den);
9595
this->chr_base.init_rho(ucell, this->Pgrid, this->sf.strucFac, ucell.symm, &this->kv);
9696
this->chr_base.check_rho();
9797

@@ -127,7 +127,7 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
127127
//----------------------------------------------------------
128128
//! calculate ewald energy
129129
//----------------------------------------------------------
130-
if (!PARAM.inp.test_skip_ewald)
130+
if (!this->inp_->test_skip_ewald)
131131
{
132132
// this->pelec_base->f_en.ewald_energy = H_Ewald_pw::compute_ewald(ucell, this->pw_rhod, this->sf.strucFac);
133133
this->pelec_base->f_en.ewald_energy = this->pelec->f_en.ewald_energy;
@@ -151,17 +151,18 @@ void ESolver_DoubleXC<TK, TR>::before_scf(UnitCell& ucell, const int istep)
151151
&this->dftu,
152152
this->deepks,
153153
istep,
154-
this->exx_nao);
154+
this->exx_nao,
155+
this->exx_info_);
155156
}
156157

157-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
158+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
158159
elecstate::init_scf(ucell,
159160
this->Pgrid,
160161
this->sf.strucFac,
161162
this->locpp.numeric,
162163
istep,
163164
PARAM.globalv.global_out_dir,
164-
PARAM.inp,
165+
*this->inp_,
165166
this->pelec_base);
166167
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
167168

@@ -183,13 +184,13 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
183184
ModuleBase::TITLE("ESolver_DoubleXC", "iter_finish");
184185
ModuleBase::timer::start("ESolver_DoubleXC", "iter_finish");
185186

186-
bool output_iter = PARAM.inp.deepks_out_labels > 0 && PARAM.inp.deepks_out_freq_elec
187-
&& (iter % PARAM.inp.deepks_out_freq_elec == 0);
187+
bool output_iter = this->inp_->deepks_out_labels > 0 && this->inp_->deepks_out_freq_elec
188+
&& (iter % this->inp_->deepks_out_freq_elec == 0);
188189

189190
if (output_iter)
190191
{
191192
// save output charge density (density after diagnonalization)
192-
for (int is = 0; is < PARAM.inp.nspin; is++)
193+
for (int is = 0; is < this->inp_->nspin; is++)
193194
{
194195
ModuleBase::GlobalFunc::DCOPY(this->chr.rho[is], this->chr_base.rho[is], this->chr.rhopw->nrxx);
195196
if (XC_Functional::get_ked_flag())
@@ -220,7 +221,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
220221
// This will change the result of out_hsk
221222
// The original result of out_hsk is H of input density, but this change H to that of output density
222223
// When converged, these two should be close
223-
if (PARAM.inp.deepks_v_delta > 0 && PARAM.inp.vl_in_h)
224+
if (this->inp_->deepks_v_delta > 0 && this->inp_->vl_in_h)
224225
{
225226
// update real space Hamiltonian
226227
this->p_hamilt->refresh();
@@ -255,7 +256,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
255256

256257
// ---------- prepare for base ----------
257258
// set as base functional Temporarily
258-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
259+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
259260

260261
// update pot of pelec_base according to chr_base
261262
if (!conv_esolver)
@@ -281,14 +282,14 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
281282
// std::endl;
282283

283284
#ifdef __MLALGO
284-
const std::string file_ebase = deepks_interface.get_filename("ebase", PARAM.inp.deepks_out_labels, iter);
285+
const std::string file_ebase = deepks_interface.get_filename("ebase", this->inp_->deepks_out_labels, iter);
285286
LCAO_deepks_io::save_npy_e(pelec_base->f_en.etot, file_ebase, GlobalV::MY_RANK);
286287
#endif
287288

288289
// ---------- h_base ----------
289-
if (PARAM.inp.deepks_v_delta > 0)
290+
if (this->inp_->deepks_v_delta > 0)
290291
{
291-
if (PARAM.inp.vl_in_h)
292+
if (this->inp_->vl_in_h)
292293
{
293294
// update real space Hamiltonian
294295
this->p_hamilt_base->refresh();
@@ -307,13 +308,13 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
307308
std::vector<TH> h_tot(nks);
308309
DeePKS_domain::get_h_tot<TK, TH, TR>(this->pv, p_ham_deepks_base, h_tot, PARAM.globalv.nlocal, nks, 'H');
309310

310-
const std::string file_htot = deepks_interface.get_filename("hbase", PARAM.inp.deepks_out_labels, iter);
311+
const std::string file_htot = deepks_interface.get_filename("hbase", this->inp_->deepks_out_labels, iter);
311312
LCAO_deepks_io::save_npy_h<TK, TH>(h_tot, file_htot, PARAM.globalv.nlocal, nks, GlobalV::MY_RANK);
312313
#endif
313314
}
314315

315316
// ---------- o_base ----------
316-
if (PARAM.inp.deepks_bandgap > 0)
317+
if (this->inp_->deepks_bandgap > 0)
317318
{
318319
// obase isn't implemented yet
319320
// don't need to solve p_hamilt_base
@@ -324,17 +325,17 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
324325
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
325326
}
326327
// ---------- prepare for f_base ----------
327-
else if (PARAM.inp.cal_force && conv_esolver)
328+
else if (this->inp_->cal_force && conv_esolver)
328329
{
329330
// vnew must be updated for force_scc() even if not output_iter
330331
// set as base functional Temporarily
331-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
332+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
332333
this->pelec_base->cal_converged();
333334
// restore to original xc
334335
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);
335336
}
336337

337-
if (PARAM.inp.cal_force)
338+
if (this->inp_->cal_force)
338339
{
339340
if (!conv_esolver)
340341
{
@@ -344,7 +345,7 @@ void ESolver_DoubleXC<TK, TR>::iter_finish(UnitCell& ucell, const int istep, int
344345
else
345346
{
346347
// copy charge
347-
for (int is = 0; is < PARAM.inp.nspin; is++)
348+
for (int is = 0; is < this->inp_->nspin; is++)
348349
{
349350
ModuleBase::GlobalFunc::DCOPY(this->chr.rho[is], this->chr_base.rho[is], this->chr.rhopw->nrxx);
350351
if (XC_Functional::get_ked_flag())
@@ -388,16 +389,16 @@ void ESolver_DoubleXC<TK, TR>::cal_force(BaseCell& basecell, ModuleBase::matrix&
388389
Force_Stress_LCAO<TK> fsl(this->RA, ucell.nat);
389390

390391
// set as base functional Temporarily
391-
XC_Functional::set_xc_type(PARAM.inp.deepks_out_base);
392+
XC_Functional::set_xc_type(this->inp_->deepks_out_base);
392393

393394
this->deepks.dpks_out_type = "base"; // for deepks method
394395

395396
fsl.getForceStress(ucell,
396397
this->get_vdw_result(),
397-
PARAM.inp.cal_force,
398-
PARAM.inp.cal_stress,
399-
PARAM.inp.test_force,
400-
PARAM.inp.test_stress,
398+
this->inp_->cal_force,
399+
this->inp_->cal_stress,
400+
this->inp_->test_force,
401+
this->inp_->test_stress,
401402
this->gd,
402403
this->pv,
403404
this->pelec_base,
@@ -415,7 +416,8 @@ void ESolver_DoubleXC<TK, TR>::cal_force(BaseCell& basecell, ModuleBase::matrix&
415416
this->dftu,
416417
this->deepks,
417418
this->exx_nao,
418-
&ucell.symm);
419+
&ucell.symm,
420+
this->exx_info_);
419421

420422
// restore to original xc
421423
XC_Functional::set_xc_type(ucell.atoms[0].ncpp.xc_func);

source/source_esolver/esolver_dp.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ void ESolver_DP::before_all_runners(BaseCell& basecell, const Input_para& inp)
3434
basecell.require_kind(BaseCell::Kind::unit_cell, __FUNCTION__);
3535
UnitCell& ucell = static_cast<UnitCell&>(basecell);
3636

37+
this->inp_ = &inp;
38+
3739
dp_potential = 0;
3840
dp_force.create(ucell.nat, 3);
3941
dp_virial.create(3, 3);
@@ -163,7 +165,7 @@ void ESolver_DP::cal_stress(BaseCell& basecell, ModuleBase::matrix& stress)
163165

164166
// external stress
165167
double unit_transform = ModuleBase::RYDBERG_SI / pow(ModuleBase::BOHR_RADIUS_SI, 3) * 1.0e-8;
166-
double external_stress[3] = {PARAM.inp.press1, PARAM.inp.press2, PARAM.inp.press3};
168+
double external_stress[3] = {this->inp_->press1, this->inp_->press2, this->inp_->press3};
167169
for (int i = 0; i < 3; i++)
168170
{
169171
stress(i, i) -= external_stress[i] / unit_transform;

0 commit comments

Comments
 (0)