Skip to content

Commit c8ab236

Browse files
committed
correct 1-electron terms: T, Vl, Vnl
1 parent 3790620 commit c8ab236

21 files changed

Lines changed: 734 additions & 604 deletions

File tree

source/source_estate/module_pot/potential_new.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ class Potential : public PotBase
175175
{
176176
return this->rho_basis_;
177177
}
178+
// get the local pseudopotential vloc(it, G) table; used by the dH module (out_mat_dh_vl)
179+
const ModuleBase::matrix* get_vloc() const
180+
{
181+
return this->vloc_;
182+
}
178183
// What about adding a function to get the wfc?
179184
// This is useful for the calculation of the exx energy
180185

source/source_io/CMakeLists.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,7 @@ if(ENABLE_LCAO)
8383
module_ml/io_npz.cpp
8484
module_hs/cal_pLpR.cpp
8585
module_dhs/write_dH.cpp
86-
module_dhs/write_dH_t.cpp
87-
module_dhs/write_dH_vnl.cpp
88-
module_dhs/write_dH_vl.cpp
89-
module_dhs/write_dH_vh.cpp
90-
module_dhs/write_dH_vxc.cpp
86+
module_dhs/write_dH_terms.cpp
9187
)
9288
list(APPEND objects_advanced
9389
module_unk/unk_overlap_lcao.cpp

source/source_io/module_ctrl/ctrl_scf_lcao.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ void ModuleIO::ctrl_scf_lcao(UnitCell& ucell,
262262
dh_params.orb = &orb;
263263
dh_params.kv = &kv;
264264
dh_params.v_eff = &pelec->pot->get_eff_v();
265+
dh_params.pot = pelec->pot;
265266
dh_params.iat2iwt = ucell.get_iat2iwt();
266267
dh_params.nat = ucell.nat;
267268
dh_params.nspin = inp.nspin;

source/source_io/module_dhs/write_dH.cpp

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,104 @@
11
#include "write_dH.h"
22

33
#include "source_base/timer.h"
4+
#include "source_io/module_hs/write_HS.h"
45
#include "source_io/module_hs/write_HS_R.h"
56
#include "source_io/module_output/ucell_io.h"
67
#include "source_io/module_parameter/parameter.h"
78
#include "source_lcao/module_hcontainer/hcontainer_funcs.h"
89
#include "source_lcao/module_hcontainer/output_hcontainer.h"
910

11+
#include <complex>
1012
#include <fstream>
1113
#include <iomanip>
14+
#include <string>
1215

1316
namespace ModuleIO
1417
{
1518

19+
void write_dh_perI(WriteDHParams& params,
20+
int ispin,
21+
const std::string& rprefix,
22+
const std::string& kprefix,
23+
const std::string& label,
24+
std::vector<hamilt::HContainer<double>*>& gx,
25+
std::vector<hamilt::HContainer<double>*>& gy,
26+
std::vector<hamilt::HContainer<double>*>& gz)
27+
{
28+
const UnitCell& ucell = *params.ucell;
29+
const Parallel_Orbitals& pv = *params.pv;
30+
const int nat = params.nat;
31+
const int nspin = params.nspin;
32+
const int nbasis = gx[0]->get_nbasis();
33+
34+
const char dirc[3] = {'x', 'y', 'z'};
35+
std::vector<hamilt::HContainer<double>*>* g[3] = {&gx, &gy, &gz};
36+
37+
// k-space (dense, folded like H(k)) parameters
38+
const int nspin_k = (nspin == 2 ? 2 : 1);
39+
const int nks = params.kv->get_nks() / nspin_k;
40+
const int nlocal = PARAM.globalv.nlocal;
41+
const std::string global_out_dir = PARAM.globalv.global_out_dir;
42+
const bool out_app_flag = PARAM.inp.out_app_flag;
43+
const std::string r_dir
44+
= (PARAM.inp.calculation == "md" && !out_app_flag) ? PARAM.globalv.global_matrix_dir : global_out_dir;
45+
46+
#ifdef __MPI
47+
Parallel_Orbitals serialV;
48+
serialV.init(nbasis, nbasis, nbasis, pv.comm());
49+
serialV.set_serial(nbasis, nbasis);
50+
serialV.set_atomic_trace(params.iat2iwt, nat, nbasis);
51+
#endif
52+
53+
for (int iat = 0; iat < nat; ++iat)
54+
{
55+
for (int d = 0; d < 3; ++d)
56+
{
57+
hamilt::HContainer<double>* hR = (*g[d])[iat];
58+
const std::string tag = std::string(1, dirc[d]) + "_iat" + std::to_string(iat + 1);
59+
60+
// ---- real space dH(R), CSR ----
61+
#ifdef __MPI
62+
hamilt::HContainer<double> hR_s(&serialV);
63+
hamilt::gatherParallels(*hR, &hR_s, 0);
64+
if (GlobalV::MY_RANK == 0)
65+
#endif
66+
{
67+
std::string fr = r_dir + ModuleIO::dhr_gen_fname(rprefix + tag, ispin, params.append, params.istep);
68+
#ifdef __MPI
69+
ModuleIO::write_hcontainer_csr(fr, &ucell, 8, &hR_s, params.istep, ispin, nspin, label);
70+
#else
71+
ModuleIO::write_hcontainer_csr(fr, &ucell, 8, hR, params.istep, ispin, nspin, label);
72+
#endif
73+
}
74+
75+
// ---- k space dH(k), dense (folded like H(k), comparable to *_nao.txt) ----
76+
// build the filename directly (filename_output only accepts a fixed property set)
77+
for (int ik = 0; ik < nks; ++ik)
78+
{
79+
std::vector<std::complex<double>> hk(static_cast<size_t>(nlocal) * nlocal, 0);
80+
hamilt::folding_HR(*hR, hk.data(), params.kv->kvec_d[ik], nlocal, 0);
81+
std::string fk = global_out_dir + kprefix + tag;
82+
if (nks > 1)
83+
{
84+
fk += "_ik" + std::to_string(params.kv->ik2iktot[ik]);
85+
}
86+
fk += "_nao.txt";
87+
ModuleIO::save_mat(params.istep,
88+
hk.data(),
89+
nlocal,
90+
false,
91+
8,
92+
false,
93+
out_app_flag,
94+
fk,
95+
pv,
96+
GlobalV::DRANK);
97+
}
98+
}
99+
}
100+
}
101+
16102
bool any_dh_term_enabled()
17103
{
18104
return PARAM.inp.out_mat_dh_t[0] || PARAM.inp.out_mat_dh_vl[0] || PARAM.inp.out_mat_dh_vnl[0]
@@ -88,6 +174,11 @@ bool write_dH_sum(WriteDHParams& params)
88174
dH_sum_y.set_zero();
89175
dH_sum_z.set_zero();
90176

177+
if (dH_sum_x.size_atom_pairs() == 0)
178+
{
179+
continue;
180+
}
181+
91182
const int nbasis = dH_sum_x.get_nbasis();
92183

93184
#ifdef __MPI

source/source_io/module_dhs/write_dH.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "source_basis/module_nao/two_center_bundle.h"
55
#include "source_cell/klist.h"
66
#include "source_cell/module_neighbor/sltk_grid_driver.h"
7+
#include "source_estate/module_pot/potential_new.h"
78
#include "source_lcao/LCAO_domain.h"
89
#include "source_lcao/module_hcontainer/hcontainer.h"
910

@@ -22,6 +23,7 @@ struct WriteDHParams
2223
const K_Vectors* kv = nullptr;
2324
const ModuleBase::matrix* v_eff = nullptr;
2425
const int* iat2iwt = nullptr;
26+
elecstate::Potential* pot = nullptr;
2527
int nat = 0;
2628
int nspin = 1;
2729
int istep = 0;
@@ -32,6 +34,20 @@ struct WriteDHParams
3234

3335
bool any_dh_term_enabled();
3436

37+
// Shared writer for the per-atom-I dH terms. For every differentiated atom I it writes:
38+
// - dH(R) in CSR real-space format ({rprefix}{x,y,z}_iat{I}...)
39+
// - dH(k) dense matrices ({kprefix}{x,y,z}_iat{I}...) folded like H(k),
40+
// so they can be compared directly with the H(k) term matrices (*_nao.txt).
41+
// gx/gy/gz are nat per-I HContainers (already filled by an operator's cal_dH).
42+
void write_dh_perI(WriteDHParams& params,
43+
int ispin,
44+
const std::string& rprefix,
45+
const std::string& kprefix,
46+
const std::string& label,
47+
std::vector<hamilt::HContainer<double>*>& gx,
48+
std::vector<hamilt::HContainer<double>*>& gy,
49+
std::vector<hamilt::HContainer<double>*>& gz);
50+
3551
void write_dH_components(WriteDHParams& params);
3652

3753
bool write_dH_t(WriteDHParams& params);

source/source_io/module_dhs/write_dH_t.cpp

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

0 commit comments

Comments
 (0)