Skip to content

Commit 8a08196

Browse files
dyzhengdyzheng
andauthored
Feature: add out_mat_ds to print <phi|dphi> matrix (#6149)
* Feature: add out_mat_ds to print <phi|dphi> matrix * Fix: decrease the memory of reference files --------- Co-authored-by: dyzheng <[email protected]>
1 parent b7547a6 commit 8a08196

File tree

21 files changed

+231
-344
lines changed

21 files changed

+231
-344
lines changed

docs/advanced/input_files/input-main.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153
- [out\_mat\_hs2](#out_mat_hs2)
154154
- [out\_mat\_t](#out_mat_t)
155155
- [out\_mat\_dh](#out_mat_dh)
156+
- [out\_mat\_ds](#out_mat_ds)
156157
- [out\_mat\_xc](#out_mat_xc)
157158
- [out\_mat\_xc2](#out_mat_xc2)
158159
- [out\_mat\_l](#out_mat_l)
@@ -1801,6 +1802,13 @@ These variables are used to control the output of properties.
18011802
- **Description**: Whether to print files containing the derivatives of the Hamiltonian matrix (in Ry/Bohr). The format will be the same as the Hamiltonian matrix $H(R)$ and overlap matrix $S(R)$ as mentioned in [out_mat_hs2](#out_mat_hs2). The name of the files will be `data-dHRx-sparse_SPIN0.csr` and so on. Also controled by [out_interval](#out_interval) and [out_app_flag](#out_app_flag).
18021803
- **Default**: False
18031804

1805+
### out_mat_ds
1806+
1807+
- **Type**: Boolean
1808+
- **Availability**: Numerical atomic orbital basis (not gamma-only algorithm)
1809+
- **Description**: Whether to print files containing the derivatives of the Overlap matrix (in Ry/Bohr). The format will be the same as the Overlap matrix $dH(R)$ as mentioned in [out_mat_dh](#out_mat_dh). The name of the files will be `data-dSRx-sparse_SPIN0.csr` and so on. Also controled by [out_interval](#out_interval) and [out_app_flag](#out_app_flag). This feature can be used with `calculation get_S`.
1810+
- **Default**: False
1811+
18041812
### out_mat_xc
18051813

18061814
- **Type**: Boolean

source/module_esolver/esolver_gets.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,20 @@ void ESolver_GetS::runner(UnitCell& ucell, const int istep)
137137
r_matrix.out_rR(ucell, gd, istep);
138138
}
139139

140+
if (PARAM.inp.out_mat_ds)
141+
{
142+
LCAO_HS_Arrays HS_Arrays; // store sparse arrays
143+
//! Print out sparse matrix
144+
ModuleIO::output_dSR(istep,
145+
ucell,
146+
this->pv,
147+
HS_Arrays,
148+
gd, // mohan add 2024-04-06
149+
two_center_bundle_,
150+
orb_,
151+
kv);
152+
}
153+
140154
ModuleBase::timer::tick("ESolver_GetS", "runner");
141155
}
142156

source/module_esolver/lcao_after_scf.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ void ESolver_KS_LCAO<TK, TR>::after_scf(UnitCell& ucell, const int istep, const
305305
//! Print out sparse matrix
306306
ModuleIO::output_mat_sparse(PARAM.inp.out_mat_hs2,
307307
PARAM.inp.out_mat_dh,
308+
PARAM.inp.out_mat_ds,
308309
PARAM.inp.out_mat_t,
309310
PARAM.inp.out_mat_r,
310311
istep,

source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,52 @@
44
#include "module_hamilt_lcao/hamilt_lcaodft/LCAO_domain.h"
55
#include <vector>
66

7+
void sparse_format::cal_dS(const UnitCell& ucell,
8+
const Parallel_Orbitals& pv,
9+
LCAO_HS_Arrays& HS_Arrays,
10+
const Grid_Driver& grid,
11+
const TwoCenterBundle& two_center_bundle,
12+
const LCAO_Orbitals& orb,
13+
const double& sparse_thr)
14+
{
15+
ModuleBase::TITLE("sparse_format", "cal_dS");
16+
17+
sparse_format::set_R_range(HS_Arrays.all_R_coor, grid);
18+
const int nnr = pv.nnr;
19+
20+
ForceStressArrays fsr_dh;
21+
fsr_dh.DHloc_fixedR_x = new double[nnr];
22+
fsr_dh.DHloc_fixedR_y = new double[nnr];
23+
fsr_dh.DHloc_fixedR_z = new double[nnr];
24+
ModuleBase::GlobalFunc::ZEROS(fsr_dh.DHloc_fixedR_x, nnr);
25+
ModuleBase::GlobalFunc::ZEROS(fsr_dh.DHloc_fixedR_y, nnr);
26+
ModuleBase::GlobalFunc::ZEROS(fsr_dh.DHloc_fixedR_z, nnr);
27+
// the pointers of dS is different from dH, use the dh pointers to reuse the print functions
28+
fsr_dh.DSloc_Rx = fsr_dh.DHloc_fixedR_x;
29+
fsr_dh.DSloc_Ry = fsr_dh.DHloc_fixedR_y;
30+
fsr_dh.DSloc_Rz = fsr_dh.DHloc_fixedR_z;
31+
// cal dS=<phi|dphi> in LCAO
32+
const bool cal_deri = true;
33+
const bool cal_stress = false;
34+
LCAO_domain::build_ST_new(fsr_dh,
35+
'S',
36+
cal_deri,
37+
cal_stress,
38+
ucell,
39+
orb,
40+
pv,
41+
two_center_bundle,
42+
&grid,
43+
nullptr,
44+
false); // delete unused parameter lm.Hloc_fixedR
45+
46+
sparse_format::cal_dSTN_R(ucell,pv, HS_Arrays, fsr_dh, grid, orb.cutoffs(), 0, sparse_thr);
47+
delete[] fsr_dh.DHloc_fixedR_x;
48+
delete[] fsr_dh.DHloc_fixedR_y;
49+
delete[] fsr_dh.DHloc_fixedR_z;
50+
return;
51+
}
52+
753
void sparse_format::cal_dH(const UnitCell& ucell,
854
const Parallel_Orbitals& pv,
955
LCAO_HS_Arrays& HS_Arrays,

source/module_hamilt_lcao/hamilt_lcaodft/spar_dh.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ void cal_dH(const UnitCell& ucell,
2121
const double& sparse_thr,
2222
Gint_k& gint_k);
2323

24+
// calculated the derivative of the overlap matrix: <phi|dphi>
25+
void cal_dS(const UnitCell& ucell,
26+
const Parallel_Orbitals& pv,
27+
LCAO_HS_Arrays& HS_Arrays,
28+
const Grid_Driver& grid,
29+
const TwoCenterBundle& two_center_bundle,
30+
const LCAO_Orbitals& orb,
31+
const double& sparse_thr);
32+
2433
// be called by 'cal_dH_sparse'
2534
void set_R_range(std::set<Abfs::Vector3_Order<int>>& all_R_coor, const Grid_Driver& grid);
2635

source/module_io/output_mat_sparse.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace ModuleIO
99
template <>
1010
void output_mat_sparse(const bool& out_mat_hsR,
1111
const bool& out_mat_dh,
12+
const bool& out_mat_ds,
1213
const bool& out_mat_t,
1314
const bool& out_mat_r,
1415
const int& istep,
@@ -27,6 +28,7 @@ void output_mat_sparse(const bool& out_mat_hsR,
2728
template <>
2829
void output_mat_sparse(const bool& out_mat_hsR,
2930
const bool& out_mat_dh,
31+
const bool& out_mat_ds,
3032
const bool& out_mat_t,
3133
const bool& out_mat_r,
3234
const int& istep,
@@ -68,6 +70,18 @@ void output_mat_sparse(const bool& out_mat_hsR,
6870
orb,
6971
kv); // LiuXh add 2019-07-15
7072
}
73+
//! generate a file containing the derivatives of the overlap matrix (in Ry/Bohr)
74+
if (out_mat_ds)
75+
{
76+
output_dSR(istep,
77+
ucell,
78+
pv,
79+
HS_Arrays,
80+
grid, // mohan add 2024-04-06
81+
two_center_bundle,
82+
orb,
83+
kv);
84+
}
7185

7286
// add by jingan for out r_R matrix 2019.8.14
7387
if (out_mat_r)

source/module_io/output_mat_sparse.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace ModuleIO
1313
template <typename T>
1414
void output_mat_sparse(const bool& out_mat_hsR,
1515
const bool& out_mat_dh,
16+
const bool& out_mat_ds,
1617
const bool& out_mat_t,
1718
const bool& out_mat_r,
1819
const int& istep,

source/module_io/read_input.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void ReadInput::create_directory(const Parameter& param)
182182
//----------------------------------------------------------
183183
bool out_dir = false;
184184
if (!param.input.out_app_flag
185-
&& (param.input.out_mat_hs2 || param.input.out_mat_r || param.input.out_mat_t || param.input.out_mat_dh))
185+
&& (param.input.out_mat_hs2 || param.input.out_mat_r || param.input.out_mat_t || param.input.out_mat_dh || param.input.out_mat_ds))
186186
{
187187
out_dir = true;
188188
}

source/module_io/read_input_item_output.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,18 @@ void ReadInput::item_output()
322322
};
323323
this->add_item(item);
324324
}
325+
{
326+
Input_Item item("out_mat_ds");
327+
item.annotation = "output of derivative of S(R) matrix";
328+
read_sync_bool(input.out_mat_ds);
329+
item.check_value = [](const Input_Item& item, const Parameter& para) {
330+
if (para.input.out_mat_ds && para.input.nspin == 4)
331+
{
332+
ModuleBase::WARNING_QUIT("ReadInput", "out_mat_ds is not available for nspin = 4");
333+
}
334+
};
335+
this->add_item(item);
336+
}
325337
{
326338
Input_Item item("out_mat_xc");
327339
item.annotation = "output exchange-correlation matrix in KS-orbital representation";

source/module_io/write_HS_R.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,37 @@ void ModuleIO::output_HSR(const UnitCell& ucell,
8383
return;
8484
}
8585

86+
void ModuleIO::output_dSR(const int& istep,
87+
const UnitCell& ucell,
88+
const Parallel_Orbitals& pv,
89+
LCAO_HS_Arrays& HS_Arrays,
90+
const Grid_Driver& grid, // mohan add 2024-04-06
91+
const TwoCenterBundle& two_center_bundle,
92+
const LCAO_Orbitals& orb,
93+
const K_Vectors& kv,
94+
const bool& binary,
95+
const double& sparse_thr)
96+
{
97+
ModuleBase::TITLE("ModuleIO", "output_dSR");
98+
ModuleBase::timer::tick("ModuleIO", "output_dSR");
99+
100+
101+
sparse_format::cal_dS(ucell,
102+
pv,
103+
HS_Arrays,
104+
grid,
105+
two_center_bundle,
106+
orb,
107+
sparse_thr);
108+
// mohan update 2024-04-01
109+
ModuleIO::save_dH_sparse(istep, pv, HS_Arrays, sparse_thr, binary, "S");
110+
111+
sparse_format::destroy_dH_R_sparse(HS_Arrays);
112+
113+
ModuleBase::timer::tick("ModuleIO", "output_dSR");
114+
return;
115+
}
116+
86117
void ModuleIO::output_dHR(const int& istep,
87118
const ModuleBase::matrix& v_eff,
88119
Gint_k& gint_k, // mohan add 2024-04-01

0 commit comments

Comments
 (0)