Skip to content

Commit ca9a37b

Browse files
committed
Fix: calculate net force after symmetrization
1 parent fac9330 commit ca9a37b

1 file changed

Lines changed: 24 additions & 12 deletions

File tree

source/source_lcao/force_stress_lcao.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -536,8 +536,6 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
536536
ModuleBase::Vector3<double> net_force = {0.0, 0.0, 0.0};
537537
for (int i = 0; i < 3; i++)
538538
{
539-
double sum = 0.0;
540-
541539
for (int iat = 0; iat < nat; iat++)
542540
{
543541
fcs(iat, i) += foverlap(iat, i) + ftvnl_dphi(iat, i) + fvnl_dbeta(iat, i) + fvl_dphi(iat, i)
@@ -595,16 +593,6 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
595593
fcs(iat, i) += fvnl_dalpha(iat, i);
596594
}
597595
#endif
598-
// sum total force for correction
599-
sum += fcs(iat, i);
600-
}
601-
net_force[i]=sum;
602-
if (!(PARAM.inp.gate_flag || PARAM.inp.efield_flag))
603-
{
604-
for (int iat = 0; iat < nat; ++iat)
605-
{
606-
fcs(iat, i) -= sum / nat;
607-
}
608596
}
609597
}
610598

@@ -619,6 +607,30 @@ void Force_Stress_LCAO<T>::getForceStress(UnitCell& ucell,
619607
this->forceSymmetry(ucell, fcs, symm);
620608
}
621609

610+
// The net force should be evaluated AFTER the symmetrization.
611+
// With symmetry switched on, the forces assembled above are built from IBZ-reduced
612+
// quantities and only become physical after the symmetrization, forceSymmetry().
613+
// Force symmetrization is linear, so it commutes with the removal of a
614+
// uniform shift: the resulting fcs is identical to the previous ordering.
615+
for (int i = 0; i < 3; i++)
616+
{
617+
double sum = 0.0;
618+
619+
for (int iat = 0; iat < nat; iat++)
620+
{
621+
// sum total force for correction
622+
sum += fcs(iat, i);
623+
}
624+
net_force[i]=sum;
625+
if (!(PARAM.inp.gate_flag || PARAM.inp.efield_flag))
626+
{
627+
for (int iat = 0; iat < nat; ++iat)
628+
{
629+
fcs(iat, i) -= sum / nat;
630+
}
631+
}
632+
}
633+
622634
// compute forces using the DeePKS model
623635
deepks.write_forces(fcs, fvnl_dalpha, PARAM.inp);
624636

0 commit comments

Comments
 (0)