Skip to content

Commit bbc0a91

Browse files
dyzhengdyzheng
and
dyzheng
authored
Fix: DFT+U force&stress with of some elements are -1 (#6049)
Co-authored-by: dyzheng <[email protected]>
1 parent 0ec187d commit bbc0a91

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

source/module_hamilt_lcao/hamilt_lcaodft/operator_lcao/dftu_force_stress.hpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,21 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
4141
{
4242
force.zero_out();
4343
}
44+
// calculate atom_index for adjs_all, induced by omp parallel
45+
int atom_index = 0;
46+
std::vector<int> atom_index_all(this->ucell->nat, -1);
47+
for (int iat0 = 0; iat0 < this->ucell->nat; iat0++)
48+
{
49+
int T0=0;
50+
int I0=0;
51+
ucell->iat2iait(iat0, &I0, &T0);
52+
if(this->dftu->orbital_corr[T0] == -1)
53+
{
54+
continue;
55+
}
56+
atom_index_all[iat0] = atom_index;
57+
atom_index++;
58+
}
4459

4560
// 1. calculate <psi|beta> for each pair of atoms
4661
// loop over all on-site atoms
@@ -62,7 +77,7 @@ void DFTU<OperatorLCAO<TK, TR>>::cal_force_stress(const bool cal_force,
6277
continue;
6378
}
6479
const int tlp1 = 2 * target_L + 1;
65-
AdjacentAtomInfo& adjs = this->adjs_all[iat0];
80+
AdjacentAtomInfo& adjs = this->adjs_all[atom_index_all[iat0]];
6681

6782
std::vector<std::unordered_map<int, std::vector<double>>> nlm_tot;
6883
nlm_tot.resize(adjs.adj_num + 1);

0 commit comments

Comments
 (0)