diff --git a/source/source_base/module_container/ATen/core/tensor_accessor.h b/source/source_base/module_container/ATen/core/tensor_accessor.h index 9fbea6f0b81..80e85881953 100644 --- a/source/source_base/module_container/ATen/core/tensor_accessor.h +++ b/source/source_base/module_container/ATen/core/tensor_accessor.h @@ -1,10 +1,9 @@ #ifndef ATEN_CORE_TENSOR_ACCESSOR_H_ #define ATEN_CORE_TENSOR_ACCESSOR_H_ -#include // Include the header file to define size_t +#include #include #include -#include namespace container { @@ -33,12 +32,17 @@ class TensorAccessorBase { const index_t* strides) : data_(data), sizes_(sizes), strides_(strides) {} - AT_HOST int_array_ref sizes() const { - return {sizes_, N}; + // NOTE: Previously returned int_array_ref (from ), + // which supported .size(), iteration, etc. Now returns raw const pointer. + // If you need array_ref functionality, include directly + // and wrap the result: int_array_ref(accessor.sizes(), N). + // mohan add 20260605 + AT_HOST_DEVICE const index_t* sizes() const { + return sizes_; } - AT_HOST int_array_ref strides() const { - return {strides_, N}; + AT_HOST_DEVICE const index_t* strides() const { + return strides_; } AT_HOST_DEVICE index_t stride(index_t idx) const { diff --git a/source/source_base/module_container/ATen/core/tensor_enums.h b/source/source_base/module_container/ATen/core/tensor_enums.h new file mode 100644 index 00000000000..4e3df3cb154 --- /dev/null +++ b/source/source_base/module_container/ATen/core/tensor_enums.h @@ -0,0 +1,96 @@ +// Extracted from tensor_types.h to break the circular dependency: +// macros.h -> tensor_types.h -> cuda.h/rocm.h -> macros.h +// This file provides only enums and template specializations needed by macros.h, +// without any GPU library dependencies. +// mohan add 20260605 +#ifndef ATEN_CORE_TENSOR_ENUMS_H_ +#define ATEN_CORE_TENSOR_ENUMS_H_ + +#include + +#include "source_base/module_device/types.h" + +namespace container { + +enum class DataType { + DT_INVALID = 0, + DT_FLOAT = 1, + DT_DOUBLE = 2, + DT_INT = 3, + DT_INT64 = 4, + DT_COMPLEX = 5, + DT_COMPLEX_DOUBLE = 6, +}; + +struct DEVICE_CPU {}; +struct DEVICE_GPU {}; + +enum class DeviceType { + UnKnown = 0, + CpuDevice = 1, + GpuDevice = 2, +}; + +template +struct DeviceTypeToEnum { + static constexpr DeviceType value = {}; +}; + +template <> +struct DeviceTypeToEnum { + static constexpr DeviceType value = DeviceType::CpuDevice; +}; + +template <> +struct DeviceTypeToEnum { + static constexpr DeviceType value = DeviceType::GpuDevice; +}; + +template <> +struct DeviceTypeToEnum { + static constexpr DeviceType value = DeviceType::CpuDevice; +}; + +template <> +struct DeviceTypeToEnum { + static constexpr DeviceType value = DeviceType::GpuDevice; +}; + +template +struct DataTypeToEnum { + static constexpr DataType value = {}; +}; + +template <> +struct DataTypeToEnum { + static constexpr DataType value = DataType::DT_INT; +}; + +template <> +struct DataTypeToEnum { + static constexpr DataType value = DataType::DT_FLOAT; +}; + +template <> +struct DataTypeToEnum { + static constexpr DataType value = DataType::DT_DOUBLE; +}; + +template <> +struct DataTypeToEnum { + static constexpr DataType value = DataType::DT_INT64; +}; + +template <> +struct DataTypeToEnum> { + static constexpr DataType value = DataType::DT_COMPLEX; +}; + +template <> +struct DataTypeToEnum> { + static constexpr DataType value = DataType::DT_COMPLEX_DOUBLE; +}; + +} // namespace container + +#endif // ATEN_CORE_TENSOR_ENUMS_H_ diff --git a/source/source_base/module_container/ATen/core/tensor_types.h b/source/source_base/module_container/ATen/core/tensor_types.h index b87907825ac..5dbdcc1e3e3 100644 --- a/source/source_base/module_container/ATen/core/tensor_types.h +++ b/source/source_base/module_container/ATen/core/tensor_types.h @@ -5,26 +5,23 @@ #ifndef ATEN_CORE_TENSOR_TYPES_H_ #define ATEN_CORE_TENSOR_TYPES_H_ -#include #include -#include -#include #include -#include -#include #include #include -#include -#include -#include #include "source_base/module_device/types.h" - -#if defined(__CUDACC__) -#include -#elif defined(__HIPCC__) -#include -#endif // defined(__CUDACC__) || defined(__HIPCC__) +#include "ATen/core/tensor_enums.h" + +// NOTE: Previously this file included or , +// which transitively provided GetTypeThrust, GetTypeCuda, GetTypeRocm, etc. +// Now replaced with which only provides thrust::complex type. +// If you need GetTypeThrust/GetTypeCuda/GetTypeRocm, include +// or directly in your .cpp file. +// mohan add 20260605 +#if defined(__CUDACC__) || defined(__HIPCC__) +#include +#endif namespace container { @@ -41,41 +38,6 @@ static inline bool element_compare(T& a, T& b) { } } -/** -@brief Enumeration of data types for tensors. -The DataType enum lists the supported data types for tensors. Each data type -is identified by a unique value. The DT_INVALID value is reserved for invalid -data types. -*/ -enum class DataType { - DT_INVALID = 0, ///< Invalid data type */ - DT_FLOAT = 1, ///< Single-precision floating point */ - DT_DOUBLE = 2, ///< Double-precision floating point */ - DT_INT = 3, ///< 32-bit integer */ - DT_INT64 = 4, ///< 64-bit integer */ - DT_COMPLEX = 5, ///< 32-bit complex */ - DT_COMPLEX_DOUBLE = 6, /**< 64-bit complex */ -// ... other data types -}; - -/** - *@struct DEVICE_CPU, DEVICE_GPU - *@brief A tag type for identifying CPU and GPU devices. -*/ -struct DEVICE_CPU; -struct DEVICE_GPU; - -struct DEVICE_CPU {}; -struct DEVICE_GPU {}; -/** - * @brief The type of memory used by an allocator. - */ -enum class DeviceType { - UnKnown = 0, ///< Memory type is unknown. - CpuDevice = 1, ///< Memory type is CPU. - GpuDevice = 2, ///< Memory type is GPU(CUDA or ROCm). -}; - /** * @brief Template struct to determine the return type based on the input type. * @@ -141,85 +103,6 @@ struct ContainerToPsi { using type = base_device::DEVICE_GPU; /**< The return type specialization for std::complex. */ }; - -/** - * @brief Template struct for mapping a Device Type to its corresponding enum value. - * - * @param T The DataType to map to its enum value. - * - * @return The enumeration value corresponding to the data type. - * This method uses template specialization to map each supported data type to its - * corresponding enumeration value. If the template argument T is not a supported - * data type, this method will cause a compile-time error. - * Example usage: - * DataTypeToEnum::value; // Returns DataType::DT_FLOAT - */ -template -struct DeviceTypeToEnum { - static constexpr DeviceType value = {}; -}; -// Specializations of DeviceTypeToEnum for supported devices. -template <> -struct DeviceTypeToEnum { - static constexpr DeviceType value = DeviceType::CpuDevice; -}; -template <> -struct DeviceTypeToEnum { - static constexpr DeviceType value = DeviceType::GpuDevice; -}; -template <> -struct DeviceTypeToEnum -{ - static constexpr DeviceType value = DeviceType::CpuDevice; -}; -template <> -struct DeviceTypeToEnum -{ - static constexpr DeviceType value = DeviceType::GpuDevice; -}; - -/** - * @brief Template struct for mapping a DataType to its corresponding enum value. - * - * @param T The DataType to map to its enum value. - * - * @return The enumeration value corresponding to the data type. - * This method uses template specialization to map each supported data type to its - * corresponding enumeration value. If the template argument T is not a supported - * data type, this method will cause a compile-time error. - * Example usage: - * DataTypeToEnum::value; // Returns DataType::DT_FLOAT - */ -template -struct DataTypeToEnum { - static constexpr DataType value = {}; -}; -// Specializations of DataTypeToEnum for supported types. -template <> -struct DataTypeToEnum { - static constexpr DataType value = DataType::DT_INT; -}; -template <> -struct DataTypeToEnum { - static constexpr DataType value = DataType::DT_FLOAT; -}; -template <> -struct DataTypeToEnum { - static constexpr DataType value = DataType::DT_DOUBLE; -}; -template <> -struct DataTypeToEnum { - static constexpr DataType value = DataType::DT_INT64; -}; -template <> -struct DataTypeToEnum> { - static constexpr DataType value = DataType::DT_COMPLEX; -}; -template <> -struct DataTypeToEnum> { - static constexpr DataType value = DataType::DT_COMPLEX_DOUBLE; -}; - #if defined(__CUDACC__) || defined(__HIPCC__) template <> struct DataTypeToEnum> { diff --git a/source/source_base/module_container/ATen/core/tensor_utils.h b/source/source_base/module_container/ATen/core/tensor_utils.h index 115ddfedb73..20f567d2843 100644 --- a/source/source_base/module_container/ATen/core/tensor_utils.h +++ b/source/source_base/module_container/ATen/core/tensor_utils.h @@ -1,6 +1,8 @@ #ifndef ATEN_CORE_TENSOR_UTILS_H_ #define ATEN_CORE_TENSOR_UTILS_H_ +#include + #include #include diff --git a/source/source_base/module_container/ATen/ops/einsum_op.cpp b/source/source_base/module_container/ATen/ops/einsum_op.cpp index 40440db9407..eeb60aea2c2 100644 --- a/source/source_base/module_container/ATen/ops/einsum_op.cpp +++ b/source/source_base/module_container/ATen/ops/einsum_op.cpp @@ -2,6 +2,9 @@ #include #include +#include +#include +#include #include #include diff --git a/source/source_base/module_container/ATen/ops/einsum_op.h b/source/source_base/module_container/ATen/ops/einsum_op.h index 6850f0445cb..feabf08d58b 100644 --- a/source/source_base/module_container/ATen/ops/einsum_op.h +++ b/source/source_base/module_container/ATen/ops/einsum_op.h @@ -1,6 +1,8 @@ #ifndef ATEN_KERNELS_EINSUM_OP_H_ #define ATEN_KERNELS_EINSUM_OP_H_ +#include + #include #include diff --git a/source/source_base/module_container/base/macros/macros.h b/source/source_base/module_container/base/macros/macros.h index 645c6aee896..fbcae6fe8a2 100644 --- a/source/source_base/module_container/base/macros/macros.h +++ b/source/source_base/module_container/base/macros/macros.h @@ -10,7 +10,14 @@ #include #endif -#include +// NOTE: Previously included which pulled in +// or transitively. +// Now only includes which provides DataType, +// DeviceType, DataTypeToEnum, DeviceTypeToEnum without GPU dependencies. +// If you need GetTypeReal, PsiToContainer, ContainerToPsi, etc., +// include directly. +// mohan add 20260605 +#include #define DISALLOW_COPY_AND_ASSIGN(TypeName) \ TypeName(const TypeName&) = delete; \ diff --git a/source/source_base/module_device/output_device.cpp b/source/source_base/module_device/output_device.cpp index 3d4587d4a99..db41786b969 100644 --- a/source/source_base/module_device/output_device.cpp +++ b/source/source_base/module_device/output_device.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #ifdef __MPI #include "mpi.h" diff --git a/source/source_esolver/esolver_ks_lcao.cpp b/source/source_esolver/esolver_ks_lcao.cpp index 08499df2bdf..5b864866041 100644 --- a/source/source_esolver/esolver_ks_lcao.cpp +++ b/source/source_esolver/esolver_ks_lcao.cpp @@ -9,6 +9,7 @@ #include "source_estate/module_charge/symmetry_rho.h" #include "source_lcao/LCAO_domain.h" // need DeePKS_init #include "source_lcao/FORCE_STRESS.h" +#include "source_lcao/module_gint/gint.h" #include "source_estate/elecstate_lcao.h" #include "source_lcao/hamilt_lcao.h" #include "source_hsolver/hsolver_lcao.h" diff --git a/source/source_esolver/esolver_ks_lcao.h b/source/source_esolver/esolver_ks_lcao.h index bfd80e50fe3..03ef22c5658 100644 --- a/source/source_esolver/esolver_ks_lcao.h +++ b/source/source_esolver/esolver_ks_lcao.h @@ -4,7 +4,6 @@ #include "esolver_ks.h" #include "source_lcao/record_adj.h" // adjacent atoms #include "source_basis/module_nao/two_center_bundle.h" // nao basis -#include "source_lcao/module_gint/gint.h" // gint #include "source_lcao/module_gint/gint_info.h" #include "source_estate/module_charge/gint_precision_controller.h" #include "source_lcao/setup_deepks.h" // for deepks, mohan add 20251008 diff --git a/source/source_esolver/lcao_others.cpp b/source/source_esolver/lcao_others.cpp index 57174c47ceb..1c08e815f7a 100644 --- a/source/source_esolver/lcao_others.cpp +++ b/source/source_esolver/lcao_others.cpp @@ -3,6 +3,7 @@ #include "source_estate/module_charge/symmetry_rho.h" #include "source_lcao/hamilt_lcao.h" #include "source_lcao/module_dftu/dftu.h" +#include "source_lcao/module_gint/gint.h" #include "source_base/formatter.h" #include "source_base/timer.h" #include "source_cell/module_neighbor/sltk_atom_arrange.h" diff --git a/source/source_estate/module_pot/H_TDDFT_pw.cpp b/source/source_estate/module_pot/H_TDDFT_pw.cpp index babece4d784..422045eab1c 100644 --- a/source/source_estate/module_pot/H_TDDFT_pw.cpp +++ b/source/source_estate/module_pot/H_TDDFT_pw.cpp @@ -3,9 +3,7 @@ #include "source_base/constants.h" #include "source_base/math_integral.h" #include "source_base/timer.h" -#include "source_io/module_parameter/input_conv.h" #include "source_io/module_parameter/parameter.h" -#include "source_lcao/module_rt/evolve_elec.h" namespace elecstate { diff --git a/source/source_hsolver/diago_bpcg.h b/source/source_hsolver/diago_bpcg.h index 27f528024ba..9eb64585df3 100644 --- a/source/source_hsolver/diago_bpcg.h +++ b/source/source_hsolver/diago_bpcg.h @@ -1,6 +1,8 @@ #ifndef DIAGO_BPCG_H_ #define DIAGO_BPCG_H_ +#include + #include "source_base/kernels/math_kernel_op.h" #include "source_base/module_device/memory_op.h" #include "source_base/module_device/types.h" diff --git a/source/source_io/module_ctrl/ctrl_scf_lcao.cpp b/source/source_io/module_ctrl/ctrl_scf_lcao.cpp index 7318a3f2b7b..30a220ef37d 100644 --- a/source/source_io/module_ctrl/ctrl_scf_lcao.cpp +++ b/source/source_io/module_ctrl/ctrl_scf_lcao.cpp @@ -12,7 +12,7 @@ #include "../module_hs/cal_pLpR.h" // use AngularMomentumCalculator() #include "source_io/module_hs/output_mat_sparse.h" // use ModuleIO::output_mat_sparse() #include "../module_hs/write_HS_R.h" // use ModuleIO::write_hsr() -#include "../module_mulliken/output_mulliken.h" // use cal_mag() +#include "../module_mulliken/cal_mag.h" // use cal_mag() #include "../module_wannier/to_wannier90_lcao.h" // use toWannier90_LCAO #include "../module_wannier/to_wannier90_lcao_in_pw.h" // use toWannier90_LCAO_IN_PW #include "../module_hs/write_HS.h" // use ModuleIO::write_hsk() diff --git a/source/source_io/module_current/td_current_io_comm.cpp b/source/source_io/module_current/td_current_io_comm.cpp index 66392a80394..a6e28ebaea9 100644 --- a/source/source_io/module_current/td_current_io_comm.cpp +++ b/source/source_io/module_current/td_current_io_comm.cpp @@ -7,10 +7,8 @@ #include "source_base/timer.h" #include "source_base/tool_threading.h" #include "source_base/vector3.h" -#include "source_estate/module_dm/cal_dm_psi.h" #include "source_estate/module_pot/H_TDDFT_pw.h" #include "source_io/module_parameter/parameter.h" -#include "source_lcao/LCAO_domain.h" #include "source_lcao/module_hcontainer/hcontainer_funcs.h" #include "source_lcao/module_rt/td_folding.h" #include "source_lcao/module_rt/td_info.h" diff --git a/source/source_io/module_mulliken/cal_mag.h b/source/source_io/module_mulliken/cal_mag.h new file mode 100644 index 00000000000..b0ec41974a6 --- /dev/null +++ b/source/source_io/module_mulliken/cal_mag.h @@ -0,0 +1,115 @@ +#ifndef CAL_MAG_H +#define CAL_MAG_H + +#include "source_basis/module_ao/parallel_orbitals.h" +#include "source_basis/module_ao/ORB_read.h" +#include "source_basis/module_nao/two_center_bundle.h" +#include "source_cell/cell_index.h" +#include "source_cell/klist.h" +#include "source_cell/module_neighbor/sltk_grid_driver.h" +#include "source_cell/unitcell.h" +#include "source_estate/module_dm/density_matrix.h" +#include "source_hamilt/hamilt.h" +#include "source_io/module_mulliken/output_dmk.h" +#include "source_io/module_mulliken/output_mulliken.h" +#include "source_io/module_mulliken/output_sk.h" +#include "source_io/module_parameter/parameter.h" +#include "source_lcao/module_operator_lcao/dspin_lcao.h" + +#include + +namespace ModuleIO +{ + +template +void cal_mag(Parallel_Orbitals* pv, + hamilt::Hamilt* p_ham, + K_Vectors& kv, + elecstate::DensityMatrix* dm, + const TwoCenterBundle& two_center_bundle, + const LCAO_Orbitals& orb, + UnitCell& ucell, + const Grid_Driver& gd, + const int istep, + const bool print) +{ + if (PARAM.inp.out_mul) + { + auto cell_index + = CellIndex(ucell.get_atomLabels(), + ucell.get_atomCounts(), ucell.get_lnchiCounts(), PARAM.inp.nspin); + auto out_s_k = ModuleIO::Output_Sk(p_ham, pv, PARAM.inp.nspin, kv.get_nks()); + auto out_dm_k = ModuleIO::Output_DMK(dm, pv, PARAM.inp.nspin, kv.get_nks()); + + auto mulp = ModuleIO::Output_Mulliken(&(out_s_k), + &(out_dm_k), pv, &cell_index, kv.isk, PARAM.inp.nspin); + auto atom_chg = mulp.get_atom_chg(); + ucell.atom_mulliken = mulp.get_atom_mulliken(atom_chg); + if (print && GlobalV::MY_RANK == 0) + { + cell_index.write_orb_info(PARAM.globalv.global_out_dir); + mulp.write(istep, PARAM.globalv.global_out_dir); + mulp.print_atom_mag(atom_chg, GlobalV::ofs_running); + } + } + if (PARAM.inp.onsite_radius > 0) + { + std::vector> atom_mag(ucell.nat, std::vector(PARAM.inp.nspin, 0.0)); + std::vector> constrain(ucell.nat, ModuleBase::Vector3(1, 1, 1)); + const hamilt::HContainer* dmr = dm->get_DMR_pointer(1); + std::vector moments; + std::vector mag_x(ucell.nat, 0.0); + std::vector mag_y(ucell.nat, 0.0); + std::vector mag_z(ucell.nat, 0.0); + auto atomLabels = ucell.get_atomLabels(); + + if(PARAM.inp.nspin == 2) + { + auto sc_lambda = new hamilt::DeltaSpin>(nullptr, + kv.kvec_d, + dynamic_cast*>(p_ham)->getHR(), + ucell, + &gd, + two_center_bundle.overlap_orb_onsite.get(), + orb.cutoffs()); + + dm->switch_dmr(2); + moments = sc_lambda->cal_moment(dmr, constrain); + dm->switch_dmr(0); + + delete sc_lambda; + + for(int iat=0;iat, std::complex>>( + nullptr, + kv.kvec_d, + dynamic_cast, std::complex>*>(p_ham)->getHR(), + ucell, + &gd, + two_center_bundle.overlap_orb_onsite.get(), + orb.cutoffs()); + moments = sc_lambda->cal_moment(dmr, constrain); + delete sc_lambda; + + for(int iat=0;iat #include @@ -16,6 +11,12 @@ namespace ModuleIO { +template +class Output_Sk; + +template +class Output_DMK; + /// @brief the output interface to write the Mulliken population charges template class Output_Mulliken @@ -85,101 +86,6 @@ class Output_Mulliken ModuleBase::matrix orbMulP_; }; -template -void cal_mag(Parallel_Orbitals* pv, - hamilt::Hamilt* p_ham, - K_Vectors& kv, - elecstate::DensityMatrix* dm, // mohan add 2025-11-04 - const TwoCenterBundle& two_center_bundle, - const LCAO_Orbitals& orb, - UnitCell& ucell, - const Grid_Driver& gd, - const int istep, - const bool print) -{ - // 1) calculate and output Mulliken population charges and magnetic moments - if (PARAM.inp.out_mul) - { - auto cell_index - = CellIndex(ucell.get_atomLabels(), - ucell.get_atomCounts(), ucell.get_lnchiCounts(), PARAM.inp.nspin); - auto out_s_k = ModuleIO::Output_Sk(p_ham, pv, PARAM.inp.nspin, kv.get_nks()); - auto out_dm_k = ModuleIO::Output_DMK(dm, pv, PARAM.inp.nspin, kv.get_nks()); - - auto mulp = ModuleIO::Output_Mulliken(&(out_s_k), - &(out_dm_k), pv, &cell_index, kv.isk, PARAM.inp.nspin); - auto atom_chg = mulp.get_atom_chg(); - /// used in updating mag info in STRU file - ucell.atom_mulliken = mulp.get_atom_mulliken(atom_chg); - if (print && GlobalV::MY_RANK == 0) - { - /// write the Orbital file - cell_index.write_orb_info(PARAM.globalv.global_out_dir); - /// write mulliken.txt - mulp.write(istep, PARAM.globalv.global_out_dir); - /// write atomic mag info in running log file - mulp.print_atom_mag(atom_chg, GlobalV::ofs_running); - } - } - // 2) calculate and output the magnetizations of each atom with projection method - if (PARAM.inp.onsite_radius > 0) - { - std::vector> atom_mag(ucell.nat, std::vector(PARAM.inp.nspin, 0.0)); - std::vector> constrain(ucell.nat, ModuleBase::Vector3(1, 1, 1)); - const hamilt::HContainer* dmr = dm->get_DMR_pointer(1); - std::vector moments; - std::vector mag_x(ucell.nat, 0.0); - std::vector mag_y(ucell.nat, 0.0); - std::vector mag_z(ucell.nat, 0.0); - auto atomLabels = ucell.get_atomLabels(); - - if(PARAM.inp.nspin == 2) - { - auto sc_lambda = new hamilt::DeltaSpin>(nullptr, - kv.kvec_d, - dynamic_cast*>(p_ham)->getHR(), - ucell, - &gd, - two_center_bundle.overlap_orb_onsite.get(), - orb.cutoffs()); - - dm->switch_dmr(2); - moments = sc_lambda->cal_moment(dmr, constrain); - dm->switch_dmr(0); - - delete sc_lambda; - - for(int iat=0;iat, std::complex>>( - nullptr, - kv.kvec_d, - dynamic_cast, std::complex>*>(p_ham)->getHR(), - ucell, - &gd, - two_center_bundle.overlap_orb_onsite.get(), - orb.cutoffs()); - moments = sc_lambda->cal_moment(dmr, constrain); - delete sc_lambda; - - for(int iat=0;iat diff --git a/source/source_lcao/hamilt_lcao.h b/source/source_lcao/hamilt_lcao.h index 70f73dfaad6..c286da764d7 100644 --- a/source/source_lcao/hamilt_lcao.h +++ b/source/source_lcao/hamilt_lcao.h @@ -3,8 +3,7 @@ #include "source_basis/module_nao/two_center_bundle.h" #include "source_cell/klist.h" -#include "source_estate/module_dm/density_matrix.h" -#include "source_estate/module_pot/potential_new.h" +#include "source_cell/module_neighbor/sltk_grid_driver.h" #include "source_hamilt/hamilt.h" #include "source_lcao/hs_matrix_k.hpp" #include "source_lcao/module_hcontainer/hcontainer.h" @@ -12,14 +11,24 @@ #include #include -#include "source_lcao/setup_deepks.h" // mohan add 20251008 +// elecstate::Potential forward declaration, full definition in potential_new.h (moved to .cpp) +// mohan add 20260605 +namespace elecstate { class Potential; } -#ifdef __EXX -#include "source_lcao/module_ri/Exx_LRI.h" -#endif +// elecstate::DensityMatrix forward declaration, full definition in density_matrix.h (moved to .cpp) +// mohan add 20260605 +namespace elecstate { template class DensityMatrix; } + +// Setup_DeePKS forward declaration, full definition in setup_deepks.h (moved to .cpp) +// mohan add 20260605 +template class Setup_DeePKS; +// Plus_U forward declaration, full definition in module_dftu/dftu.h (moved to .cpp) +// mohan add 20260605 +class Plus_U; -#include "source_lcao/setup_exx.h" // for exx, mohan add 20251022 -#include "source_lcao/module_dftu/dftu.h" // mohan add 2025-11-05 +// Exx_NAO forward declaration, full definition in setup_exx.h (moved to .cpp) +// mohan add 20260605 +template class Exx_NAO; namespace hamilt { @@ -43,16 +52,16 @@ class HamiltLCAO : public Hamilt */ HamiltLCAO(const UnitCell& ucell, const Grid_Driver& grid_d, - const Parallel_Orbitals* paraV, - elecstate::Potential* pot_in, - const K_Vectors& kv_in, - const TwoCenterBundle& two_center_bundle, + const Parallel_Orbitals* paraV, + elecstate::Potential* pot_in, + const K_Vectors& kv_in, + const TwoCenterBundle& two_center_bundle, const LCAO_Orbitals& orb, - elecstate::DensityMatrix* DM_in, - Plus_U* p_dftu, // mohan add 2025-11-05 - Setup_DeePKS &deepks, - const int istep, - Exx_NAO &exx_nao); + elecstate::DensityMatrix* DM_in, + Plus_U* p_dftu, // mohan add 2025-11-05 + Setup_DeePKS &deepks, + const int istep, + Exx_NAO &exx_nao); /** * @brief Constructor of vacuum Operators, only HR and SR will be initialed as empty HContainer @@ -145,7 +154,7 @@ class HamiltLCAO : public Hamilt * @param hk_type 0: SK is row-major, 1: SK is collumn-major * @return void */ - void updateSk(const int ik, const int hk_type = 0); + void updateSk(const int ik, const int hk_type = 0); // core function: return H(k) and S(k) matrixs for direct solving eigenvalues. // not used in PW base diff --git a/source/source_lcao/module_deepks/LCAO_deepks_interface.cpp b/source/source_lcao/module_deepks/LCAO_deepks_interface.cpp index 928617f4cdb..aaaa469477f 100644 --- a/source/source_lcao/module_deepks/LCAO_deepks_interface.cpp +++ b/source/source_lcao/module_deepks/LCAO_deepks_interface.cpp @@ -5,6 +5,7 @@ #include "source_base/global_variable.h" #include "source_base/tool_title.h" #include "source_estate/cal_dm.h" +#include "source_estate/module_dm/density_matrix.h" #include "source_io/module_parameter/parameter.h" #include "source_lcao/module_deepks/deepks_check.h" #include "source_lcao/module_deepks/deepks_descriptor.h" diff --git a/source/source_lcao/module_gint/gint_interface.cpp b/source/source_lcao/module_gint/gint_interface.cpp index f8b896fe255..d701fbef6e9 100644 --- a/source/source_lcao/module_gint/gint_interface.cpp +++ b/source/source_lcao/module_gint/gint_interface.cpp @@ -9,6 +9,7 @@ #include "gint_fvl_meta.h" #include "gint_rho.h" #include "gint_tau.h" +#include "gint_dvlocal.h" #ifdef __CUDA #include "gint_vl_gpu.h" diff --git a/source/source_lcao/module_gint/gint_interface.h b/source/source_lcao/module_gint/gint_interface.h index cb9112cf4f4..8710fc65131 100644 --- a/source/source_lcao/module_gint/gint_interface.h +++ b/source/source_lcao/module_gint/gint_interface.h @@ -2,7 +2,11 @@ #include #include "source_lcao/module_hcontainer/hcontainer.h" #include "gint_type.h" -#include "gint_dvlocal.h" + +class Parallel_Orbitals; +class UnitCell; +class Grid_Driver; +class LCAO_HS_Arrays; namespace ModuleGint { diff --git a/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp b/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp index 71b9b961202..92c36d52ae3 100644 --- a/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp +++ b/source/source_lcao/module_lr/esolver_lrtd_lcao.cpp @@ -5,6 +5,7 @@ #include "source_lcao/module_lr/potentials/pot_hxc_lrtd.h" #include "source_lcao/module_lr/hsolver_lrtd.hpp" #include "source_lcao/module_lr/lr_spectrum.h" +#include "source_lcao/module_gint/gint.h" #include #include "source_lcao/hamilt_lcao.h" #include "source_io/module_wf/read_wfc_nao.h" diff --git a/source/source_lcao/module_rdmft/rdmft.cpp b/source/source_lcao/module_rdmft/rdmft.cpp index c8c36cf9119..d62a3ee3716 100644 --- a/source/source_lcao/module_rdmft/rdmft.cpp +++ b/source/source_lcao/module_rdmft/rdmft.cpp @@ -9,6 +9,10 @@ #include "source_base/parallel_reduce.h" #include "source_cell/module_symmetry/symmetry.h" +#ifdef __EXX +#include "source_lcao/module_ri/Exx_LRI.h" +#endif + #include #include #include diff --git a/source/source_lcao/module_rdmft/rdmft.h b/source/source_lcao/module_rdmft/rdmft.h index c11b504ebd6..e67ea66181a 100644 --- a/source/source_lcao/module_rdmft/rdmft.h +++ b/source/source_lcao/module_rdmft/rdmft.h @@ -19,9 +19,10 @@ #include "source_lcao/hs_matrix_k.hpp" #ifdef __EXX -#include "source_lcao/module_ri/Exx_LRI.h" +// Exx_LRI forward declaration, full definition in Exx_LRI.h (moved to .cpp) +// mohan add 20260605 +template class Exx_LRI; #include "source_lcao/module_ri/module_exx_symmetry/symmetry_rotation.h" -// there are some operator reload to print data in different formats #endif #include "source_estate/elecstate.h" diff --git a/source/source_lcao/module_rt/band_energy.cpp b/source/source_lcao/module_rt/band_energy.cpp index 601840b2857..2a03a5f7dcc 100644 --- a/source/source_lcao/module_rt/band_energy.cpp +++ b/source/source_lcao/module_rt/band_energy.cpp @@ -3,6 +3,7 @@ #include "evolve_elec.h" #include "source_base/module_container/ATen/kernels/blas.h" #include "source_base/module_external/scalapack_connector.h" +#include "source_io/module_parameter/parameter.h" #ifdef __CUBLASMP #include "kernels/cuda/band_energy_kernel.cuh" diff --git a/source/source_lcao/module_rt/evolve_elec.cpp b/source/source_lcao/module_rt/evolve_elec.cpp index 491f5c63e0f..14aa91ca3a0 100644 --- a/source/source_lcao/module_rt/evolve_elec.cpp +++ b/source/source_lcao/module_rt/evolve_elec.cpp @@ -3,9 +3,6 @@ #include "evolve_psi.h" #include "source_base/parallel_reduce.h" #include "source_base/timer.h" -#include "source_estate/module_charge/symmetry_rho.h" -#include "source_lcao/hamilt_lcao.h" -#include "source_lcao/module_dftu/dftu.h" namespace module_rt { diff --git a/source/source_lcao/module_rt/evolve_elec.h b/source/source_lcao/module_rt/evolve_elec.h index bd6420f5ca2..f571027a6ee 100644 --- a/source/source_lcao/module_rt/evolve_elec.h +++ b/source/source_lcao/module_rt/evolve_elec.h @@ -6,14 +6,20 @@ #include "source_base/module_container/ATen/core/tensor.h" // ct::Tensor #include "source_base/module_device/device.h" // base_device #include "source_base/module_device/memory_op.h" // memory operations -#include "source_esolver/esolver_ks_lcao.h" -#include "source_esolver/esolver_ks_lcao_tddft.h" -#include "source_lcao/hamilt_lcao.h" +#include "source_hamilt/hamilt.h" #include "source_lcao/module_rt/gather_mat.h" // MPI gathering and distributing functions #include "source_lcao/module_rt/kernels/cublasmp_context.h" #include "source_lcao/module_rt/td_moving_gauge.h" #include "source_psi/psi.h" +namespace ModuleESolver +{ +template +class ESolver_KS_LCAO; +template +class ESolver_KS_LCAO_TDDFT; +} // namespace ModuleESolver + //----------------------------------------------------------- // mohan add 2021-02-09 // This class is used to evolve the electronic wave functions diff --git a/source/source_lcao/module_rt/evolve_psi.cpp b/source/source_lcao/module_rt/evolve_psi.cpp index 162f64e4574..d40fd4305e5 100644 --- a/source/source_lcao/module_rt/evolve_psi.cpp +++ b/source/source_lcao/module_rt/evolve_psi.cpp @@ -5,11 +5,14 @@ #include "norm_psi.h" #include "propagator.h" #include "solve_propagation.h" +#include "source_base/module_external/blas_connector.h" +#include "source_base/global_function.h" #include "source_base/module_container/ATen/kernels/blas.h" // cuBLAS handle #include "source_base/module_container/ATen/kernels/lapack.h" // cuSOLVER handle -#include "source_esolver/esolver_ks_lcao_tddft.h" // use gatherMatrix +#include "source_base/timer.h" +#include "source_base/tool_title.h" #include "source_io/module_parameter/parameter.h" -#include "source_lcao/hamilt_lcao.h" +#include "gather_mat.h" #include "upsi.h" #include diff --git a/source/source_lcao/module_rt/evolve_psi.h b/source/source_lcao/module_rt/evolve_psi.h index c723b6fba75..ad76e74b33d 100644 --- a/source/source_lcao/module_rt/evolve_psi.h +++ b/source/source_lcao/module_rt/evolve_psi.h @@ -8,8 +8,7 @@ #include "source_base/module_container/ATen/core/tensor.h" // ct::Tensor #include "source_basis/module_ao/parallel_orbitals.h" -#include "source_lcao/hamilt_lcao.h" -#include "source_lcao/module_rt/evolve_elec.h" +#include "source_hamilt/hamilt.h" #include "source_lcao/module_rt/kernels/cublasmp_context.h" namespace module_rt diff --git a/source/source_lcao/module_rt/gather_mat.h b/source/source_lcao/module_rt/gather_mat.h index 00df8620ad5..151ee066695 100644 --- a/source/source_lcao/module_rt/gather_mat.h +++ b/source/source_lcao/module_rt/gather_mat.h @@ -2,6 +2,7 @@ #define GATHER_MAT_H #include "source_base/module_external/scalapack_connector.h" // Cpxgemr2d +#include "source_basis/module_ao/parallel_orbitals.h" #include "source_hamilt/matrixblock.h" namespace module_rt diff --git a/source/source_lcao/module_rt/test/band_energy_test.cpp b/source/source_lcao/module_rt/test/band_energy_test.cpp index d35f25ebefe..800e2555c0a 100644 --- a/source/source_lcao/module_rt/test/band_energy_test.cpp +++ b/source/source_lcao/module_rt/test/band_energy_test.cpp @@ -5,7 +5,6 @@ #include #include "source_basis/module_ao/parallel_orbitals.h" -#include "source_lcao/module_rt/evolve_elec.h" #include "tddft_test.h" /************************************************ diff --git a/source/source_lcao/setup_exx.cpp b/source/source_lcao/setup_exx.cpp index f552ed06dff..841d3579707 100644 --- a/source/source_lcao/setup_exx.cpp +++ b/source/source_lcao/setup_exx.cpp @@ -1,5 +1,9 @@ #include "source_lcao/setup_exx.h" +#ifdef __EXX +#include "source_lcao/module_ri/Exx_LRI_interface.h" +#endif + template Exx_NAO::Exx_NAO(){} diff --git a/source/source_lcao/setup_exx.h b/source/source_lcao/setup_exx.h index badf9d14c7c..faf232e3de9 100644 --- a/source/source_lcao/setup_exx.h +++ b/source/source_lcao/setup_exx.h @@ -10,7 +10,9 @@ // for EXX #ifdef __EXX -#include "source_lcao/module_ri/Exx_LRI_interface.h" +// Exx_LRI_Interface forward declaration, full definition in Exx_LRI_interface.h (moved to .cpp) +// mohan add 20260605 +template class Exx_LRI_Interface; #endif template