ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
evolve_elec.h
Go to the documentation of this file.
1#ifndef W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_MODULE_TDDFT_EVOLVE_ELEC_H
2#define W_ABACUS_DEVELOP_ABACUS_DEVELOP_SOURCE_MODULE_HAMILT_LCAO_MODULE_TDDFT_EVOLVE_ELEC_H
3
8#include "source_base/module_device/device.h" // base_device
9#include "source_base/module_device/memory_op.h" // memory operations
14#include "source_lcao/module_rt/gather_mat.h" // MPI gathering and distributing functions
15#include "source_psi/psi.h"
16
17//-----------------------------------------------------------
18// mohan add 2021-02-09
19// This class is used to evolve the electronic wave functions
20// in TDDFT in terms of the multiple k points
21// k is the index for the points in the first Brillouin zone
22//-----------------------------------------------------------
23
24//------------------------ Debugging utility function ------------------------//
25
26// Print the shape of a Tensor
27inline void print_tensor_shape(const ct::Tensor& tensor, const std::string& name)
28{
29 std::cout << "Shape of " << name << ": [";
30 for (int i = 0; i < tensor.shape().ndim(); ++i)
31 {
32 std::cout << tensor.shape().dim_size(i);
33 if (i < tensor.shape().ndim() - 1)
34 {
35 std::cout << ", ";
36 }
37 }
38 std::cout << "]" << std::endl;
39}
40
41// Recursive print function
42template <typename T>
43inline void print_tensor_data_recursive(const T* data,
44 const std::vector<int64_t>& shape,
45 const std::vector<int64_t>& strides,
46 int dim,
47 std::vector<int64_t>& indices,
48 const std::string& name)
49{
50 if (dim == shape.size())
51 {
52 // Recursion base case: print data when reaching the innermost dimension
53 std::cout << name;
54 for (size_t i = 0; i < indices.size(); ++i)
55 {
56 std::cout << "[" << indices[i] << "]";
57 }
58 std::cout << " = " << *data << std::endl;
59 return;
60 }
61 // Recursively process the current dimension
62 for (int64_t i = 0; i < shape[dim]; ++i)
63 {
64 indices[dim] = i;
65 print_tensor_data_recursive(data + i * strides[dim], shape, strides, dim + 1, indices, name);
66 }
67}
68
69// Generic print function
70template <typename T>
71inline void print_tensor_data(const ct::Tensor& tensor, const std::string& name)
72{
73 const std::vector<int64_t>& shape = tensor.shape().dims();
74 const std::vector<int64_t>& strides = tensor.shape().strides();
75 const T* data = tensor.data<T>();
76 std::vector<int64_t> indices(shape.size(), 0);
77 print_tensor_data_recursive(data, shape, strides, 0, indices, name);
78}
79
80// Specialization for std::complex<double>
81template <>
82inline void print_tensor_data<std::complex<double>>(const ct::Tensor& tensor, const std::string& name)
83{
84 const std::vector<int64_t>& shape = tensor.shape().dims();
85 const std::vector<int64_t>& strides = tensor.shape().strides();
86 const std::complex<double>* data = tensor.data<std::complex<double>>();
87 std::vector<int64_t> indices(shape.size(), 0);
88 print_tensor_data_recursive(data, shape, strides, 0, indices, name);
89}
90
91//------------------------ Debugging utility function ------------------------//
92
93namespace module_rt
94{
95template <typename Device = base_device::DEVICE_CPU>
97{
98 friend class ModuleESolver::ESolver_KS_LCAO<std::complex<double>, double>;
99
100 // Template parameter is needed for the friend class declaration
101 friend class ModuleESolver::ESolver_KS_LCAO_TDDFT<double, Device>;
102 friend class ModuleESolver::ESolver_KS_LCAO_TDDFT<std::complex<double>, Device>;
103
104 public:
105 Evolve_elec();
106 ~Evolve_elec();
107
108 private:
109 static void solve_psi(const int& istep,
110 const int nband,
111 const int nlocal,
112 const int& nks,
113 hamilt::Hamilt<std::complex<double>>* phm,
114 Parallel_Orbitals& para_orb,
115 psi::Psi<std::complex<double>>* psi,
116 psi::Psi<std::complex<double>>* psi_laststep,
117 ct::Tensor& Hk_laststep,
118 ct::Tensor& Sk_laststep,
119 ModuleBase::matrix& ekb,
120 std::ofstream& ofs_running,
121 const int propagator,
122 const bool use_tensor,
123 const bool use_lapack);
124
125 // ct_device_type = ct::DeviceType::CpuDevice or ct::DeviceType::GpuDevice
127 // ct_Device = ct::DEVICE_CPU or ct::DEVICE_GPU
128 using ct_Device = typename ct::PsiToContainer<Device>::type;
129
130 // Memory operations
131 using syncmem_double_h2d_op = base_device::memory::synchronize_memory_op<double, Device, base_device::DEVICE_CPU>;
132 using syncmem_double_d2h_op = base_device::memory::synchronize_memory_op<double, base_device::DEVICE_CPU, Device>;
134 = base_device::memory::synchronize_memory_op<std::complex<double>, Device, base_device::DEVICE_CPU>;
136 = base_device::memory::synchronize_memory_op<std::complex<double>, base_device::DEVICE_CPU, Device>;
137};
138} // namespace module_rt
139#endif
Definition esolver_ks_lcao_tddft.h:15
Definition esolver_ks_lcao.h:32
int64_t dim_size(int dim) const
Get the size of a dimension in the tensor.
Definition tensor_shape.cpp:31
const std::vector< int64_t > & dims() const
Get all dimension sizes in the tensor.
Definition tensor_shape.cpp:36
unsigned int ndim() const
Get the ndim of the tensor.
Definition tensor_shape.cpp:46
const std::vector< int64_t > & strides() const
Definition tensor_shape.cpp:41
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
void * data() const
Get a pointer to the data buffer of the tensor.
Definition tensor.cpp:73
const TensorShape & shape() const
Get the shape of the tensor.
Definition tensor.cpp:67
Definition evolve_elec.h:97
static ct::DeviceType ct_device_type
Definition evolve_elec.h:126
typename ct::PsiToContainer< Device >::type ct_Device
Definition evolve_elec.h:128
static void solve_psi(const int &istep, const int nband, const int nlocal, const int &nks, hamilt::Hamilt< std::complex< double > > *phm, Parallel_Orbitals &para_orb, psi::Psi< std::complex< double > > *psi, psi::Psi< std::complex< double > > *psi_laststep, ct::Tensor &Hk_laststep, ct::Tensor &Sk_laststep, ModuleBase::matrix &ekb, std::ofstream &ofs_running, const int propagator, const bool use_tensor, const bool use_lapack)
Definition evolve_elec.cpp:23
std::complex< double > complex
Definition diago_cusolver.cpp:13
void print_tensor_data_recursive(const T *data, const std::vector< int64_t > &shape, const std::vector< int64_t > &strides, int dim, std::vector< int64_t > &indices, const std::string &name)
Definition evolve_elec.h:43
void print_tensor_shape(const ct::Tensor &tensor, const std::string &name)
Definition evolve_elec.h:27
void print_tensor_data(const ct::Tensor &tensor, const std::string &name)
Definition evolve_elec.h:71
#define T
Definition exp.cpp:237
DeviceType
The type of memory used by an allocator.
Definition tensor_types.h:73
Definition band_energy.cpp:11
Definition tensor_types.h:113