abacus-develop icon indicating copy to clipboard operation
abacus-develop copied to clipboard

Refactor: Unify the interfaces of Pulay terms of force and stress

Open maki49 opened this issue 1 year ago • 4 comments

Why need this change

To implement the analytical gradient of LR-TDDFT, we need to calculate: image

where $(T+D^{Z})$ is a density matrix different from the ground-state (GS) one, and $\Lambda$ is a complicated energy density matrix different from the GS one.

However in the current code, the GS energy density matrix is hard-coded in cal_fedm, blocking me from implementing the feature.

Additionally, I notice that if the energy density matrix is treated equally as the density matrix as the input argument, the Pulay terms of force can be abstracted to $\text{Tr}[D\frac{dH}{dr_x}]$, and similarly $\frac{1}{\Omega}\text{Tr}[D\frac{dH}{dr_x}r_y]$ for stress, which can avoid a lot of duplicate code (cal_fedm, cal_ftvnl_dphi and cal_fvnl_dphi).

What's changed

Unify cal_fedm, cal_ftvnl_dphi and cal_fvnl_dphi (both gamma-only and multi-k) into a new function cal_pulay_fs , where 3 overloads are provided:

  • calculated by 2-center integration, provided dH(x, y, z) and dH*r(11, 12, 13, 21, 22, 23)
  • calculated by 2-center integration, provided dH(x, y, z) and dr(x,y,z)
  • calculated by grid integration

All of them above treat the (energy) density matrix as an input parameter, and the Hamiltonian term (any operator) is passed in the way according to the algorithm.

maki49 avatar Sep 18 '24 09:09 maki49

The refactor of force or stress code should avoid the memory cost of $$\frac{dH}{d\tau_i}$$ for force or $$\frac{dH}{d\tau_\alpha}\tau_\beta$$ for stress, otherwise it will be refactored again in the future.

dyzheng avatar Sep 18 '24 13:09 dyzheng

The refactor of force or stress code should avoid the memory cost of d H d τ i for force or d H d τ α τ β for stress, otherwise it will be refactored again in the future.

You can delete those arrays in fsr later. It does not conflict with my demands.

maki49 avatar Sep 18 '24 17:09 maki49

You can delete those arrays in fsr later

In PRs, try to fix the issues proposed by others, don‘t let others do anything to meet your demands. Nobody has the obligation to do something to meet your personal demands. You need to consider more for others.

mohanchen avatar Sep 19 '24 02:09 mohanchen

In PRs, try to fix the issues proposed by others, don‘t let others do anything to meet your demands. Nobody has the obligation to do something to meet your personal demands. You need to consider more for others.

I didn't let others do anything to meet my demands. I'm meeting my demands by myself. Deleting fsr (already existing, not my addition) is another plan of @dyzheng. We've talked about it. The two things do not conflict.

maki49 avatar Sep 19 '24 03:09 maki49