Skip to content

Commit 75939c8

Browse files
committed
center2 terms
1 parent 86e0291 commit 75939c8

File tree

11 files changed

+337
-164
lines changed

11 files changed

+337
-164
lines changed

source/Makefile.Objects

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ OBJS_LCAO=evolve_elec.o\
561561
FORCE_k.o\
562562
stress_tools.o\
563563
edm.o\
564+
pulay_force_stress_center2.o\
564565
fedm_gamma.o\
565566
fedm_k.o\
566567
ftvnl_dphi_gamma.o\

source/module_hamilt_lcao/hamilt_lcaodft/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if(ENABLE_LCAO)
1515
operator_lcao/td_nonlocal_lcao.cpp
1616
operator_lcao/sc_lambda_lcao.cpp
1717
operator_lcao/dftu_lcao.cpp
18+
pulay_force_stress/pulay_force_stress_center2.cpp
1819
FORCE_STRESS.cpp
1920
FORCE_gamma.cpp
2021
FORCE_k.cpp

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_gamma.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,20 @@ void Force_LCAO<double>::ftable(const bool isforce,
214214
// allocate DHloc_fixed_x, DHloc_fixed_y, DHloc_fixed_z
215215
this->allocate(pv, fsr, two_center_bundle, orb);
216216

217+
const double* dSx[3] = { fsr.DSloc_x, fsr.DSloc_y, fsr.DSloc_z };
218+
const double* dSxy[6] = { fsr.DSloc_11, fsr.DSloc_12, fsr.DSloc_13, fsr.DSloc_22, fsr.DSloc_23, fsr.DSloc_33 };
217219
// calculate the force related to 'energy density matrix'.
218-
this->cal_fedm(isforce, isstress, fsr, ucell,
220+
// this->cal_fedm(isforce, isstress, fsr, ucell,
221+
// this->cal_edm(pelec, *psi, *dm, *kv, pv, GlobalV::NSPIN, GlobalV::NBANDS, ucell, *ra),
222+
// psi, pv, pelec, foverlap, soverlap);
223+
PulayForceStress::cal_pulay_fs(foverlap, soverlap,
219224
this->cal_edm(pelec, *psi, *dm, *kv, pv, GlobalV::NSPIN, GlobalV::NBANDS, ucell, *ra),
220-
psi, pv, pelec, foverlap, soverlap);
225+
ucell, pv, dSx, dSxy, isforce, isstress);
221226

222-
this->cal_ftvnl_dphi(dm, pv, ucell, fsr, isforce, isstress, ftvnl_dphi, stvnl_dphi);
227+
const double* dHx[3] = { fsr.DHloc_fixed_x, fsr.DHloc_fixed_y, fsr.DHloc_fixed_z };
228+
const double* dHxy[6] = { fsr.DHloc_fixed_11, fsr.DHloc_fixed_12, fsr.DHloc_fixed_13, fsr.DHloc_fixed_22, fsr.DHloc_fixed_23, fsr.DHloc_fixed_33 };
229+
// this->cal_ftvnl_dphi(dm, pv, ucell, fsr, isforce, isstress, ftvnl_dphi, stvnl_dphi);
230+
PulayForceStress::cal_pulay_fs(ftvnl_dphi, stvnl_dphi, *dm, ucell, pv, dHx, dHxy, isforce, isstress);
223231

224232
this->cal_fvnl_dbeta(dm,
225233
pv,

source/module_hamilt_lcao/hamilt_lcaodft/FORCE_k.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,20 @@ void Force_LCAO<std::complex<double>>::ftable(const bool isforce,
310310
kv->get_nks(),
311311
kv->kvec_d);
312312

313+
const double* dSx[3] = { fsr.DSloc_Rx, fsr.DSloc_Ry, fsr.DSloc_Rz };
313314
// calculate the energy density matrix
314315
// and the force related to overlap matrix and energy density matrix.
315-
this->cal_fedm(isforce, isstress, fsr, ucell,
316+
// this->cal_fedm(isforce, isstress, fsr, ucell,
317+
// this->cal_edm(pelec, *psi, *dm, *kv, pv, GlobalV::NSPIN, GlobalV::NBANDS, ucell, *ra),
318+
// psi, pv, pelec, foverlap, soverlap, kv, ra);
319+
PulayForceStress::cal_pulay_fs(foverlap, soverlap,
316320
this->cal_edm(pelec, *psi, *dm, *kv, pv, GlobalV::NSPIN, GlobalV::NBANDS, ucell, *ra),
317-
psi, pv, pelec, foverlap, soverlap, kv, ra);
321+
ucell, pv, dSx, fsr.DH_r, isforce, isstress, ra, -1.0, 1.0);
318322

319-
this->cal_ftvnl_dphi(dm, pv, ucell, fsr, isforce, isstress, ftvnl_dphi, stvnl_dphi, ra);
323+
const double* dHx[3] = { fsr.DHloc_fixedR_x, fsr.DHloc_fixedR_y, fsr.DHloc_fixedR_z }; // T+Vnl
324+
const double* dHxy[6] = { fsr.stvnl11, fsr.stvnl12, fsr.stvnl13, fsr.stvnl22, fsr.stvnl23, fsr.stvnl33 }; //T
325+
// this->cal_ftvnl_dphi(dm, pv, ucell, fsr, isforce, isstress, ftvnl_dphi, stvnl_dphi, ra);
326+
PulayForceStress::cal_pulay_fs(ftvnl_dphi, stvnl_dphi, *dm, ucell, pv, dHx, dHxy, isforce, isstress, ra, 1.0, -1.0);
320327

321328
// doing on the real space grid.
322329
// this->cal_fvl_dphi(isforce, isstress, pelec->pot, gint, fvl_dphi, svl_dphi);

source/module_hamilt_lcao/hamilt_lcaodft/edm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@ elecstate::DensityMatrix<std::complex<double>, double> Force_LCAO<std::complex<d
9797
// cal_dm_2d
9898
edm.init_DMR(ra, &ucell);
9999
edm.cal_DMR();
100-
edm.sum_DMR_spin();
100+
// edm.sum_DMR_spin();
101101
return edm;
102102
}

source/module_hamilt_lcao/hamilt_lcaodft/force_stress_arrays.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ class ForceStressArrays
6060
double* DSloc_23;
6161
double* DSloc_33;
6262

63+
//缺少DSlocR_11, DSlocR_12, DSlocR_13, DSlocR_22, DSlocR_23, DSlocR_33
64+
//DH_r更省内存
65+
// 数组接口需要重构
66+
6367
double* DHloc_fixed_11;
6468
double* DHloc_fixed_12;
6569
double* DHloc_fixed_13;

source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress/pulay_force_stress.h

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,45 @@ template <> struct TGint<double> { using type = Gint_Gamma; };
1414
template <> struct TGint<std::complex<double>> { using type = Gint_k; };
1515
#endif
1616

17-
/// calculate $Tr[D*dH/dx]$ and $1/V Tr[D*(dH/dx_a*x_b)]
18-
/// where D can be either density matrix or energy density matrix
17+
/// calculate the abstract formulas:
18+
/// $Tr[D*dH/dx]$ (force) and $1/V Tr[D*(dH/dx_a*x_b)]$ (stress)
19+
/// where D can be any (energy) density matrix
20+
/// and H can be any operator
1921
namespace PulayForceStress
2022
{
21-
/// for 2-center terms
22-
// template<typename TK, typename TR>
23-
// void cal_pulay_fs(
24-
// ModuleBase::matrix& f, ///< [out] force
25-
// ModuleBase::matrix& s, ///< [out] stress
26-
// const elecstate::DensityMatrix<TK, TR>& dm, ///< [in] density matrix or energy density matrix
27-
// const UnitCell& ucell, ///< [in] unit cell
28-
// const ForceStressArrays& fsr,
29-
// const bool& isstress
30-
// );
31-
/// for grid terms
23+
/// for 2-center-integration terms, provided force and stress derivatives
24+
template<typename TK, typename TR>
25+
void cal_pulay_fs(
26+
ModuleBase::matrix& f, ///< [out] force
27+
ModuleBase::matrix& s, ///< [out] stress
28+
const elecstate::DensityMatrix<TK, TR>& dm, ///< [in] density matrix or energy density matrix
29+
const UnitCell& ucell, ///< [in] unit cell
30+
const Parallel_Orbitals& pv, ///< [in] parallel orbitals
31+
const double* (&dHSx)[3], ///< [in] dHSx x, y, z, for force
32+
const double* (&dHSxy)[6], ///< [in] dHSxy 11, 12, 13, 22, 23, 33, for stress
33+
const bool& isforce,
34+
const bool& isstress,
35+
Record_adj* ra = nullptr,
36+
const double& factor_force = 1.0,
37+
const double& factor_stress = 1.0);
38+
39+
/// for 2-center-integration terms, provided force derivatives and coordinate difference
40+
template<typename TK, typename TR>
41+
void cal_pulay_fs(
42+
ModuleBase::matrix& f, ///< [out] force
43+
ModuleBase::matrix& s, ///< [out] stress
44+
const elecstate::DensityMatrix<TK, TR>& dm, ///< [in] density matrix or energy density matrix
45+
const UnitCell& ucell, ///< [in] unit cell
46+
const Parallel_Orbitals& pv, ///< [in] parallel orbitals
47+
const double* (&dHSx)[3], ///< [in] dHSx x, y, z, for force and stress
48+
const double* dtau, ///< [in] dr x, y, z, for stress
49+
const bool& isforce,
50+
const bool& isstress,
51+
Record_adj* ra = nullptr,
52+
const double& factor_force = 1.0,
53+
const double& factor_stress = 1.0);
54+
55+
/// for grid-integration terms
3256
template<typename TK, typename TR>
3357
void cal_pulay_fs(
3458
ModuleBase::matrix& f, ///< [out] force
@@ -39,8 +63,7 @@ namespace PulayForceStress
3963
typename TGint<TK>::type& gint, ///< [in] Gint object
4064
const bool& isforce,
4165
const bool& isstress,
42-
const bool& set_dmr_gint = true
43-
);
66+
const bool& set_dmr_gint = true);
4467
}
45-
46-
#include "pulay_force_stress.hpp"
68+
#include "pulay_force_stress_center2_template.hpp"
69+
#include "pulay_force_stress_gint.hpp"

source/module_hamilt_lcao/hamilt_lcaodft/pulay_force_stress/pulay_force_stress.hpp

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)