1#ifndef ABACUS_SOURCE_LCAO_MODULE_LR_UTILS_LR_UTIL_HCONTAINER_H
2#define ABACUS_SOURCE_LCAO_MODULE_LR_UTILS_LR_UTIL_HCONTAINER_H
21 std::cout << label <<
"\n";
25 const int ia = ap.get_atom_i();
26 const int ja = ap.get_atom_j();
27 for (
int iR = 0;iR < ap.get_R_size();++iR)
29 std::cout <<
"atom pair (" << ia <<
", " << ja <<
"), "
30 <<
"R=(" << ap.get_R_index(iR)[0] <<
", " << ap.get_R_index(iR)[1] <<
", " << ap.get_R_index(iR)[2] <<
"): \n";
31 auto& mat = ap.get_HR_values(iR);
32 std::cout <<
"rowsize=" << ap.get_row_size() <<
", colsize=" << ap.get_col_size() <<
"\n";
33 for (
int i = 0;i < ap.get_row_size();++i)
35 for (
int j = 0;j < ap.get_col_size();++j)
37 auto& v = mat.get_value(i, j);
38 std::cout << (std::abs(v) >
threshold ? v : 0) <<
" ";
46 template <
typename TK,
typename TR>
49 std::cout << label <<
"\n";
57 template<
typename TR_from,
typename TR_to>
79 for (
int i = 0; i < ap->
get_size(); ++i)
81 ptr_real[i] = (get_imag ? std::imag(ptr[i]) : std::real(ptr[i]));
90 const char& type =
'R')
92 assert(DMR.
get_dmr_vec().size() == DMR_real.get_dmr_vec().size());
93 const bool get_imag = (type ==
'I' || type ==
'i');
94 for (
size_t is = 0; is < DMR.
get_dmr_vec().size(); ++is)
98 assert(dr !=
nullptr);
99 assert(dr_real !=
nullptr);
110 const char& type =
'R')
112 assert(
static_cast<size_t>(is) < DMR.
get_dmr_vec().size());
113 assert(DMR_real.get_dmr_vec().size() == 1);
114 const bool get_imag = (type ==
'I' || type ==
'i');
116 auto dr_real = DMR_real.get_dmr_vec()[0];
117 assert(dr !=
nullptr);
118 assert(dr_real !=
nullptr);
126 bool get_imag = (type ==
'I' || type ==
'i');
127 for (
int iap = 0; iap < HR.size_atom_pairs(); ++iap)
133 assert(ap_real !=
nullptr);
138 std::complex<double>* ptr = ap->
get_HR_values(iR).get_pointer();
140 for (
int i = 0; i < ap->
get_size(); ++i)
142 get_imag ? ptr[i].imag(ptr_real[i]) : ptr[i].real(ptr_real[i]);
148 template <
typename T,
typename TR>
152 const std::vector<double>& orb_cutoff)
155 for (
int iat1 = 0; iat1 < ucell.
nat; iat1++)
161 gd.
Find_atom(ucell, tau1, T1, I1, &adjs);
162 for (
int ad = 0; ad < adjs.
adj_num + 1; ++ad)
164 const int T2 = adjs.
ntype[ad];
165 const int I2 = adjs.
natom[ad];
169 if (ucell.
cal_dtau(iat1, iat2, R_index).
norm() * ucell.
lat0 >= orb_cutoff[T1] + orb_cutoff[T2]) {
continue; }
176 if (std::is_same<T, double>::value) { hR.
fix_gamma(); }
178 template <
typename T,
typename TR>
183 const std::vector<double>& orb_cutoff)
191 template<
typename TR1,
typename TR2>
212 for (
int index = 0; index < size; ++index)
214 block_sum += values1[index] * values2[index];
227 template<
typename TK>
240 std::vector<TK> transposed(dk.size());
241 for (
int j = 0; j < n; ++j)
243 for (
int i = 0; i < n; ++i)
255 template<
typename TK>
258 throw std::runtime_error(
"transpose_DMR is not implemented for complex DMR, due to the lack of minus-sign FT.");
260 for (
auto& dk : dm.get_dmk_vec())
265 throw std::runtime_error(
"transpose_DMR requires MPI (PBLAS mattrans) for the 2D-block-cyclic dm(k) transpose.");
273 template<
typename TK,
typename TR>
280 const std::vector<double>& orb_cutoff,
281 const bool symmetrize =
false,
282 const bool cal_dmr =
true,
283 const bool transpose =
false)
289 for (
int ik = 0; ik < nk; ++ik)
296 for (
int ik = 0; ik < nk; ++ik)
311 template <
typename TK,
typename TR>
318 const std::vector<double>& orb_cutoff,
319 const bool symmetrize =
false,
320 const bool cal_dmr =
true)
322 const int nspin_dm =
static_cast<int>(dmk.size());
325 for (
int is = 0; is < nspin_dm; ++is)
327 const std::size_t kpoint_count = nk;
328 assert(dmk[is].size() >= kpoint_count);
331 for (
int ik = 0; ik < nk; ++ik)
340 for (
int ik = 0; ik < nk; ++ik)
342 dm.
set_dmk_ptr(is * nk + ik, dmk[is][ik].data<TK>());
354 template<
typename TR>
357 double sparse_thr, std::ostream& running_log);
359 template<
typename TK,
typename TR>
362 double sparse_thr, std::ostream& running_log);
367 template <
typename TK,
typename TR>
370 -> std::map<int, std::map<std::pair<int, std::array<int, 3>>,
RI::Tensor<TK>>>
372 const int& nk = dm.get_DMK_nks();
373 std::vector<const std::vector<TK>*> DMk_trans_pointer(nk);
374 for (
int ik = 0; ik < nk; ++ik)
376 DMk_trans_pointer[ik] = &dm.get_dmk_vec()[ik];
379 ucell, kv, DMk_trans_pointer, pmat.para_2d(), 1)[0];
383 template <
typename TK,
typename TR>
384 auto get_exx_Ds_gs(
const module_dm::DensityMatrix<TK, TR>& dm,
385 const UnitCell& ucell,
const K_Vectors& kv,
const Parallel_Orbitals& pmat)
386 -> std::vector<std::map<int, std::map<std::pair<int, std::array<int, 3>>, RI::Tensor<TK>>>>
388 const int& nspin = dm.get_dmr_vec().size();
389 const int nks = dm.get_DMK_nks();
390 std::vector<const std::vector<TK>*> DMk_trans_pointer(nks);
391 for (
int iks = 0;iks < dm.get_DMK_nks();++iks)
392 DMk_trans_pointer[iks] = &dm.get_dmk_vec()[iks];
394 ucell, kv, DMk_trans_pointer, pmat.para_2d(), nspin);
Struct of array for packing the Adjacent atom information.
Definition sltk_grid_driver.h:21
int adj_num
number of adjacent atoms
Definition sltk_grid_driver.h:30
std::vector< ModuleBase::Vector3< int > > box
box indices of adjacent atoms
Definition sltk_grid_driver.h:34
std::vector< int > ntype
types of adjacent atoms
Definition sltk_grid_driver.h:31
std::vector< int > natom
indices of adjacent atoms
Definition sltk_grid_driver.h:32
Grid_Driver class for neighbor search interface.
Definition sltk_grid_driver.h:63
void Find_atom(const UnitCell &ucell, const int ntype, const int nnumber, AdjacentAtomInfo *adjs=nullptr) const
Find adjacent atoms for a given atom.
Definition sltk_grid_driver.cpp:24
Class for k-points management.
Definition klist.h:20
3 elements vector
Definition vector3.h:21
T x
Definition vector3.h:23
T norm(void) const
Get the norm of a Vector3.
Definition vector3.h:213
T y
Definition vector3.h:24
T z
Definition vector3.h:25
int nrglb() const
Definition parallel_blkcyc.cpp:75
Definition parallel_orbitals.h:16
bool is_invalid_atom_pair(int iat1, int iat2) const
Definition parallel_orbitals.cpp:131
Parallel_Blkcyclic & para_2d()
Definition parallel_orbitals.h:24
Definition rpa_lri_coeff_v1.h:11
Provide the basic information about unitcell.
Definition unitcell.h:16
const ModuleBase::Vector3< double > & get_tau(const int &iat) const
Get tau for atom iat.
Definition unitcell.h:104
double & lat0
Definition unitcell.h:135
ModuleBase::IntArray itia2iat
(it, ia)==>iat, the index in nat (add 2009-3-2 by mohan)
Definition unitcell.h:160
int nat
total number of atoms of all species in unitcell
Definition unitcell.h:155
const ModuleBase::Vector3< double > cal_dtau(const int &iat1, const int &iat2, const ModuleBase::Vector3< int > &R) const
Calculate vector between two atoms with R cell.
Definition unitcell.h:110
bool iat2iait(const Tiat iat, Tiait *ia, Tiait *it) const
Indexing tools for ia and it.
Definition unitcell.h:79
Definition atom_pair.h:45
BaseMatrix< T > & get_HR_values(int rx_in, int ry_in, int rz_in)
get target BaseMatrix of target cell for const AtomPair, it will return a const BaseMatrix<T> object,...
Definition atom_pair.cpp:451
int get_size() const
get size = col_size * row_size
Definition atom_pair.h:167
ModuleBase::Vector3< int > get_R_index(const int &index) const
Definition atom_pair.cpp:908
size_t get_R_size() const
Definition atom_pair.h:391
int get_atom_j() const
Definition atom_pair.cpp:370
int get_atom_i() const
get atom_i and atom_j for this AtomPair
Definition atom_pair.cpp:363
Definition base_matrix.h:20
T * get_pointer() const
get pointer of value from a submatrix
Definition base_matrix.h:86
int get_col_size() const
get col_size for this matrix
Definition base_matrix.h:102
int get_row_size() const
get row_size for this matrix
Definition base_matrix.h:106
Definition hcontainer.h:147
void fix_gamma()
restrict R indexes of all atom-pair to 0, 0, 0 add BaseMatrix<T> with non-zero R index to this->atom_...
Definition hcontainer.cpp:715
void insert_pair(const AtomPair< T > &atom_ij)
a AtomPair object can be inserted into HContainer, two steps: 1, find AtomPair with atom index atom_i...
Definition hcontainer.cpp:880
size_t size_atom_pairs() const
calculate number of AtomPairs for current R index
Definition hcontainer.cpp:832
void allocate(T *data_array=nullptr, bool if_zero=false)
allocate memory for all <IJR> matrix if data_array is not nullptr, use memory after data_array for ea...
Definition hcontainer.cpp:324
AtomPair< T > & get_atom_pair(int i, int j) const
return a reference of AtomPair with index of atom I and J in atom_pairs
Definition hcontainer.cpp:528
const Parallel_Orbitals * get_paraV() const
get parallel orbital pointer to check parallel information
Definition hcontainer.h:210
AtomPair< T > * find_pair(int i, int j) const
find AtomPair with atom index atom_i and atom_j This interface can be used to find AtomPair,...
Definition hcontainer.cpp:378
DensityMatrix Class <TK,TR> = <double,double> for Gamma-only calculation <TK,TR> = <std::complex<doub...
Definition density_matrix.h:172
const std::vector< hamilt::HContainer< TR > * > & get_dmr_vec() const
get pointer vector of DMR
Definition density_matrix.h:301
void init_dmr(const Grid_Driver *GridD_in, const UnitCell *ucell)
initialize density matrix DMR from UnitCell
Definition dmr_init.cpp:19
void cal_dmr(const int ik_in)
calculate density matrix DMR from dm(k) using blas::axpy
const std::vector< std::vector< TK > > & get_dmk_vec() const
get pointer vector of DMK
Definition density_matrix.h:329
void set_dmk_ptr(const int ik, TK *DMK_in)
set dmk using a input TK* pointer please make sure the size of TK* is correct
Definition dm_setter.cpp:20
#define T
Definition exp.cpp:237
Definition exciton_plotter.cpp:368
void save_DMR(const module_dm::DensityMatrix< TK, TR > &dm, const std::string &filename, const Parallel_Orbitals &pv, const std::string &out_dir, const double sparse_thr, std::ostream &running_log)
Definition lr_sparse.cpp:26
module_dm::DensityMatrix< TK, TR > build_dm_from_dmk_spin(const std::vector< std::vector< ct::Tensor > > &dmk, const Parallel_Orbitals &pmat, const int &nk, const std::vector< ModuleBase::Vector3< double > > &kvec_d, const UnitCell &ucell, const Grid_Driver &gd, const std::vector< double > &orb_cutoff, const bool symmetrize=false, const bool cal_dmr=true)
Spin-resolved counterpart of build_dm_from_dmk: one dmk list per spin channel.
Definition lr_util_hcontainer.h:312
void save_HR(const hamilt::HContainer< TR > &hR, const std::string &filename, const Parallel_Orbitals &pv, const std::string &out_dir, const double sparse_thr, std::ostream &running_log)
Definition lr_sparse.cpp:9
void matsym(const T *in, const int n, T *out)
Definition lr_util.hpp:79
void set_HR_real_imag_part(const hamilt::HContainer< double > &HR_real, hamilt::HContainer< std::complex< double > > &HR, const char &type)
Definition lr_util_hcontainer.h:122
void get_DMR_real_imag_part(const module_dm::DensityMatrix< T, T > &DMR, module_dm::DensityMatrix< T, Real< T > > &DMR_real, const char &type='R')
Definition lr_util_hcontainer.h:88
double get_conj(const double &x)
Definition lr_util.hpp:70
typename GetTypeReal< T >::type Real
Definition lr_util_hcontainer.h:17
void print_HR(const hamilt::HContainer< TR > &HR, const std::string &label, const double &threshold=1e-10)
Definition lr_util_hcontainer.h:19
void copy_hcontainer_real_imag_part(const hamilt::HContainer< TR_from > &HR, hamilt::HContainer< TR_to > &HR_real, const bool get_imag)
Definition lr_util_hcontainer.h:58
void initialize_DMR(module_dm::DensityMatrix< T, TR > &dm, const Parallel_Orbitals &pmat, const UnitCell &ucell, const Grid_Driver &gd, const std::vector< double > &orb_cutoff)
Definition lr_util_hcontainer.h:179
void transpose_DMR(module_dm::DensityMatrix< TK, double > &dm, const Parallel_Orbitals &pv)
Definition lr_util_hcontainer.h:228
void print_DMR(const module_dm::DensityMatrix< TK, TR > &DMR, const std::string &label, const double &threshold=1e-10)
Definition lr_util_hcontainer.h:47
void initialize_HR(hamilt::HContainer< TR > &hR, const UnitCell &ucell, const Grid_Driver &gd, const std::vector< double > &orb_cutoff)
Definition lr_util_hcontainer.h:149
void mattrans(const T *in, const int n, const Parallel_Blkcyclic &pmat, T *out)
TR1 dot_R_matrix(const hamilt::HContainer< TR1 > &h1, const hamilt::HContainer< TR2 > &h2)
$\sum_{uvR} H1_{uv}(R) H2_{uv}(R)$
Definition lr_util_hcontainer.h:192
module_dm::DensityMatrix< TK, TR > build_dm_from_dmk(const std::vector< ct::Tensor > &dmk, const Parallel_Orbitals &pmat, const int &nk, const std::vector< ModuleBase::Vector3< double > > &kvec_d, const UnitCell &ucell, const Grid_Driver &gd, const std::vector< double > &orb_cutoff, const bool symmetrize=false, const bool cal_dmr=true, const bool transpose=false)
Definition lr_util_hcontainer.h:274
std::vector< std::map< TA, std::map< TAC, RI::Tensor< Tdata > > > > split_m2D_ktoR(const UnitCell &ucell, const K_Vectors &kv, const std::vector< const Tmatrix * > &mks_2D, const Parallel_Blkcyclic &pv, const int nspin, const bool spgsym=false)
const int nks
Definition dos_test_data.h:12
#define threshold
Definition sph_bessel_rec_test.cpp:4
T type
Definition macros.h:8