14#include <unordered_map>
22using NlmTot = std::vector<std::vector<std::unordered_map<int, std::vector<double>>>>;
39 const int current_spin,
40 std::vector<double>& occ)
44 dftu.occmat().get_flat(iat0, target_L, occ);
48 for (
int i = 0; i < static_cast<int>(occ.size()); i++)
50 occ[i] =
dftu.occmat().get(iat0, target_L, current_spin,
51 i / (2 * target_L + 1), i % (2 * target_L + 1));
77 const std::unordered_map<
int, std::vector<double>>& nlm1_all,
78 const std::unordered_map<
int, std::vector<double>>& nlm2_all,
79 const std::vector<TR>& pot_onsite,
85 assert(data_pointer !=
nullptr);
88 const int m_size = int(sqrt(pot_onsite.size()) / npol);
90 std::vector<int> step_trace(npol * npol, 0);
91 for (
int is = 0; is < npol; is++)
93 for (
int is2 = 0; is2 < npol; is2++)
95 step_trace[is * npol + is2] = pv.
get_ncol_atom(iat2) * is + is2;
99 for (
int iw1l = 0; iw1l < int(row_indexes.size()); iw1l += npol)
101 const std::vector<double>& nlm1 = nlm1_all.find(row_indexes[iw1l])->second;
102 for (
int iw2l = 0; iw2l < int(col_indexes.size()); iw2l += npol)
104 const std::vector<double>& nlm2 = nlm2_all.find(col_indexes[iw2l])->second;
106 assert(nlm1.size() == nlm2.size());
108 for (
int is = 0; is < npol * npol; ++is)
110 int start = is * m_size * m_size;
112 for (
int m1 = 0; m1 < m_size; m1++)
114 for (
int m2 = 0; m2 < m_size; m2++)
116 nlm_tmp += nlm1[m1] * nlm2[m2] * pot_onsite[m1 * m_size + m2 +
start];
119 data_pointer[step_trace[is]] += nlm_tmp;
121 data_pointer += npol;
123 data_pointer += (npol - 1) * col_indexes.size();
146 const std::unordered_map<
int, std::vector<double>>& nlm1_all,
147 const std::unordered_map<
int, std::vector<double>>& nlm2_all,
148 const double* dm_pointer,
149 std::vector<double>& occ)
154 assert(dm_pointer !=
nullptr);
157 const int m_size = int(sqrt(occ.size()) / npol);
158 const int m_size2 = m_size * m_size;
160 assert(m_size2 * npol * npol ==
int(occ.size()));
163 std::vector<int> step_trace(npol * npol, 0);
164 for (
int is = 0; is < npol; is++)
166 for (
int is2 = 0; is2 < npol; is2++)
168 step_trace[is * npol + is2] = pv.
get_ncol_atom(iat2) * is + is2;
171 for (
int iw1l = 0; iw1l < int(row_indexes.size()); iw1l += npol)
173 const std::vector<double>& nlm1 = nlm1_all.find(row_indexes[iw1l])->second;
174 for (
int iw2l = 0; iw2l < int(col_indexes.size()); iw2l += npol)
176 const std::vector<double>& nlm2 = nlm2_all.find(col_indexes[iw2l])->second;
178 assert(nlm1.size() == nlm2.size());
180 for (
int is1 = 0; is1 < npol; ++is1)
182 for (
int is2 = 0; is2 < npol; ++is2)
184 for (
int m1 = 0; m1 < m_size; ++m1)
186 for (
int m2 = 0; m2 < m_size; ++m2)
188 occ[m1 * m_size + m2 + (is1 * npol + is2) * m_size2]
189 += nlm1[m1] * nlm2[m2] * dm_pointer[step_trace[is1 * npol + is2]];
196 dm_pointer += (npol - 1) * col_indexes.size();
220template <
typename Body>
227 for (
int ad1 = 0; ad1 < adjs.
adj_num + 1; ++ad1)
229 const int T1 = adjs.
ntype[ad1];
230 const int I1 = adjs.
natom[ad1];
231 const int iat1 = ucell.
itia2iat(T1, I1);
233 const std::unordered_map<int, std::vector<double>>& nlm1 = nlm_tot[iat0][ad1];
234 for (
int ad2 = 0; ad2 < adjs.
adj_num + 1; ++ad2)
236 const int T2 = adjs.
ntype[ad2];
237 const int I2 = adjs.
natom[ad2];
238 const int iat2 = ucell.
itia2iat(T2, I2);
239 const std::unordered_map<int, std::vector<double>>& nlm2 = nlm_tot[iat0][ad2];
242 R_index2[1] - R_index1[1],
243 R_index2[2] - R_index1[2]);
244 body(iat1, iat2, R_vector, nlm1, nlm2);
265template <
typename TR>
272 const std::vector<TR>& pot_onsite)
275 [&](
int iat1,
int iat2,
277 const std::unordered_map<
int, std::vector<double>>& nlm1,
278 const std::unordered_map<
int, std::vector<double>>& nlm2)
284#pragma omp critical(dftu_hr_update)
316 const int current_spin,
322 std::vector<double>& occ)
325 [&](
int iat1,
int iat2,
327 const std::unordered_map<
int, std::vector<double>>& nlm1,
328 const std::unordered_map<
int, std::vector<double>>& nlm2)
331 = dmR_current.
find_matrix(iat1, iat2, R_vector[0], R_vector[1], R_vector[2]);
341 for (
double& v : occ) { v *= 0.5; }
343 dftu.occmat().set_flat(iat0, target_L, current_spin, occ);
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
3 elements vector
Definition vector3.h:21
Definition parallel_orbitals.h:16
std::vector< int > get_indexes_col() const
Definition parallel_orbitals.cpp:151
int get_ncol_atom(int iat) const
dimension getters for 2D-block-cyclic division of Hamiltonian matrix ncloc() : total number of column...
Definition parallel_orbitals.cpp:87
std::vector< int > get_indexes_row() const
gather global indexes of orbitals in this processor get_indexes_row() : global indexes (~NLOCAL) of r...
Definition parallel_orbitals.cpp:137
Definition dftu_base.h:21
Provide the basic information about unitcell.
Definition unitcell.h:16
const int & get_npol() const
Get npol.
Definition unitcell.h:66
ModuleBase::IntArray itia2iat
(it, ia)==>iat, the index in nat (add 2009-3-2 by mohan)
Definition unitcell.h:160
Definition base_matrix.h:20
T * get_pointer() const
get pointer of value from a submatrix
Definition base_matrix.h:86
Definition hcontainer.h:147
BaseMatrix< T > * find_matrix(int i, int j, int rx, int ry, int rz)
find BaseMatrix with atom index atom_i and atom_j and R index (rx, ry, rz) This interface can be used...
Definition hcontainer.cpp:426
Definition dftu_nao_adj.cpp:14
void accumulate_hr_for_iat0(const UnitCell &ucell, hamilt::HContainer< TR > *hR, const NlmTot &nlm_tot, const int iat0, const AdjacentAtomInfo &adjs, const Parallel_Orbitals &pv, const std::vector< TR > &pot_onsite)
accumulate the real-space HR contributions of one Hubbard atom (iat0) from the precomputed pot_onsite...
Definition dftu_nao_ijr.h:266
void cal_occ_ijr(const int iat1, const int iat2, const int npol, const Parallel_Orbitals &pv, const std::unordered_map< int, std::vector< double > > &nlm1_all, const std::unordered_map< int, std::vector< double > > &nlm2_all, const double *dm_pointer, std::vector< double > &occ)
accumulate one atom-pair contribution to the DFT+U occupation matrix: occ_mm' += sum_R DMR(I,...
Definition dftu_nao_ijr.h:142
std::vector< std::vector< std::unordered_map< int, std::vector< double > > > > NlmTot
Definition dftu_nao_ijr.h:22
void load_occ_from_file(const Plus_U_Base &dftu, const int iat0, const int target_L, const int nspin, const int current_spin, std::vector< double > &occ)
load the flattened occupation matrix of one Hubbard atom from pre-read occ_mat data.
Definition dftu_nao_ijr.h:35
void compute_occ_from_dmr(const UnitCell &ucell, Plus_U_Base &dftu, const int iat0, const int target_L, const int current_spin, const int nspin, const AdjacentAtomInfo &adjs, const Parallel_Orbitals &pv, const NlmTot &nlm_tot, const hamilt::HContainer< double > &dmR_current, std::vector< double > &occ)
compute the occupation matrix of one Hubbard atom (iat0) from the real-space density matrix: occ(m,...
Definition dftu_nao_ijr.h:312
void cal_hr_ijr(const int iat1, const int iat2, const int npol, const Parallel_Orbitals &pv, const std::unordered_map< int, std::vector< double > > &nlm1_all, const std::unordered_map< int, std::vector< double > > &nlm2_all, const std::vector< TR > &pot_onsite, TR *data_pointer)
accumulate one real-space HR atom-pair block for DFT+U: HR += <psi_I|beta_m> * pot_onsite(m,...
Definition dftu_nao_ijr.h:73
void for_adj_pair(const UnitCell &ucell, const int iat0, const AdjacentAtomInfo &adjs, const NlmTot &nlm_tot, Body &&body)
walk all (ad1, ad2) adjacent-atom pairs of one Hubbard atom iat0 and invoke body for each pair that h...
Definition dftu_nao_ijr.h:221
void reduce_all(T &object)
reduce in all process
Definition depend_mock.cpp:14
Grid_Driver class for neighbor search interface.
Plus_U_Base dftu
Definition test_dftu_nao_op.cpp:11
iclock::time_point start
Definition test_partition.cpp:22