Skip to content

Commit 3f72f84

Browse files
committed
fix: preserve HR data when wrapping HContainer with external data_array
The HContainer copy constructor was unconditionally zeroing out the data_array when wrapping existing memory. This caused getHR_vector() to erase both spin channels' HR data for nspin=2, resulting in all-zero HR output when out_mat_hs2 is enabled. Fix: only zero memory when data_array is nullptr (fresh allocation); preserve existing data when wrapping external memory. Also add integration test scf_out_hsr_spin2 (nspin=2 + out_mat_hs2) and update catch_properties.sh to compare hrs2_nao.csr for nspin=2.
1 parent ee6ec4c commit 3f72f84

10 files changed

Lines changed: 735 additions & 1 deletion

File tree

source/source_lcao/module_hcontainer/hcontainer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ HContainer<T>::HContainer(const HContainer<T>& HR_in, T* data_array)
3838
this->allocated_size = 0;
3939
this->atom_pairs = HR_in.atom_pairs;
4040
// data of HR_in will not be copied, please call add() after this constructor to copy data.
41-
this->allocate(this->wrapper_pointer, true);
41+
// Only zero memory when allocating fresh data (data_array==nullptr);
42+
// when wrapping existing data (data_array!=nullptr), preserve the original content.
43+
this->allocate(this->wrapper_pointer, data_array == nullptr);
4244
// tmp terms not copied
4345
}
4446

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
INPUT_PARAMETERS
2+
#Parameters (1.General)
3+
suffix autotest
4+
calculation scf
5+
6+
nbands 6
7+
symmetry 0
8+
pseudo_dir ../../PP_ORB
9+
orbital_dir ../../PP_ORB
10+
gamma_only 0
11+
12+
nspin 2
13+
14+
#Parameters (2.Iteration)
15+
ecutwfc 20
16+
scf_thr 1e-8
17+
scf_nmax 1
18+
19+
#Parameters (3.Basis)
20+
basis_type lcao
21+
22+
#Parameters (4.Smearing)
23+
smearing_method gauss
24+
smearing_sigma 0.002
25+
26+
#Parameters (5.Mixing)
27+
mixing_type broyden
28+
mixing_beta 0.7
29+
mixing_gg0 0.0
30+
31+
out_mat_hs2 1 5
32+
ks_solver scalapack_gvx
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
K_POINTS
2+
0
3+
Gamma
4+
2 1 1 0 0 0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test the output of H(R)/S(R) matrix with nspin=2; Note: delete OUT folder before testing!
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ATOMIC_SPECIES
2+
Si 14 Si_dojo_nsoc.upf upf201
3+
4+
NUMERICAL_ORBITAL
5+
Si_dojo_6au_sz.orb
6+
7+
LATTICE_CONSTANT
8+
15.3 // add lattice constant
9+
10+
LATTICE_VECTORS
11+
0.0 0.5 0.5
12+
0.5 0.0 0.5
13+
0.5 0.5 0.0
14+
15+
ATOMIC_POSITIONS
16+
Direct
17+
18+
Si // Element type
19+
0.0 // magnetism
20+
2
21+
0.00 0.00 0.00 1 1 1 mag 1.0
22+
0.25 0.25 0.25 1 1 1 mag -1.0
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
--- Ionic Step 1 ---
2+
# print H matrix in real space H(R)
3+
2 # number of spin directions
4+
1 # spin index
5+
8 # number of localized basis
6+
13 # number of Bravais lattice vector R
7+
8+
user_defined_lattice
9+
8.09641
10+
0 0.5 0.5
11+
0.5 0 0.5
12+
0.5 0.5 0
13+
Si
14+
2
15+
Direct
16+
0 0 0
17+
0.25 0.25 0.25
18+
19+
#----------------------------------------------------------------------#
20+
# CSR Format #
21+
# The outer loop corresponds to the number of Bravais lattice vectors. #
22+
# The first line contains the index of the Bravais lattice vector #
23+
# (Rx, Ry, Rz), followed by the number of non-zero elements. #
24+
# The subsequent lines consist of three blocks of data, which are #
25+
# values, column indices, row pointers. #
26+
#----------------------------------------------------------------------#
27+
28+
-1 0 0 48
29+
# CSR values
30+
-1.11792e-04 7.16241e-04 -3.82452e-06 -7.16241e-04 -3.37629e-02 8.00872e-03
31+
8.00872e-03 -8.00872e-03 -7.16241e-04 2.12235e-03 -2.46427e-05 -2.57041e-03
32+
-5.50669e-03 -1.91945e-03 -1.96652e-02 1.96652e-02 -3.82452e-06 2.46427e-05
33+
-4.45692e-04 -2.46427e-05 -5.50669e-03 -1.96652e-02 -1.91945e-03 1.96652e-02
34+
7.16241e-04 -2.57041e-03 2.46427e-05 2.12235e-03 5.50669e-03 1.96652e-02
35+
1.96652e-02 -1.91945e-03 -1.12382e-04 7.21513e-04 3.79778e-06 -7.21513e-04
36+
-7.21513e-04 2.16956e-03 2.43147e-05 -2.61966e-03 3.79778e-06 -2.43147e-05
37+
-4.48512e-04 2.43147e-05 7.21513e-04 -2.61966e-03 -2.43147e-05 2.16956e-03
38+
# CSR column indices
39+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
40+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
41+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
42+
# CSR row pointers
43+
0 8 16 24 32 36 40 44 48
44+
45+
-1 0 1 32
46+
# CSR values
47+
-1.11792e-04 7.16241e-04 7.16241e-04 3.82452e-06 -7.16241e-04 2.12235e-03
48+
2.57041e-03 2.46427e-05 -7.16241e-04 2.57041e-03 2.12235e-03 2.46427e-05
49+
3.82452e-06 -2.46427e-05 -2.46427e-05 -4.45692e-04 -1.12382e-04 7.21513e-04
50+
7.21513e-04 -3.79778e-06 -7.21513e-04 2.16956e-03 2.61966e-03 -2.43147e-05
51+
-7.21513e-04 2.61966e-03 2.16956e-03 -2.43147e-05 -3.79778e-06 2.43147e-05
52+
2.43147e-05 -4.48512e-04
53+
# CSR column indices
54+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
55+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
56+
# CSR row pointers
57+
0 4 8 12 16 20 24 28 32
58+
59+
-1 1 0 32
60+
# CSR values
61+
-1.11792e-04 -3.82452e-06 7.16241e-04 -7.16241e-04 -3.82452e-06 -4.45692e-04
62+
2.46427e-05 -2.46427e-05 -7.16241e-04 -2.46427e-05 2.12235e-03 -2.57041e-03
63+
7.16241e-04 2.46427e-05 -2.57041e-03 2.12235e-03 -1.12382e-04 3.79778e-06
64+
7.21513e-04 -7.21513e-04 3.79778e-06 -4.48512e-04 -2.43147e-05 2.43147e-05
65+
-7.21513e-04 2.43147e-05 2.16956e-03 -2.61966e-03 7.21513e-04 -2.43147e-05
66+
-2.61966e-03 2.16956e-03
67+
# CSR column indices
68+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
69+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
70+
# CSR row pointers
71+
0 4 8 12 16 20 24 28 32
72+
73+
0 -1 0 48
74+
# CSR values
75+
-1.11792e-04 7.16241e-04 -7.16241e-04 -3.82452e-06 -3.37629e-02 8.00872e-03
76+
-8.00872e-03 8.00872e-03 -7.16241e-04 2.12235e-03 -2.57041e-03 -2.46427e-05
77+
-5.50669e-03 -1.91945e-03 1.96652e-02 -1.96652e-02 7.16241e-04 -2.57041e-03
78+
2.12235e-03 2.46427e-05 5.50669e-03 1.96652e-02 -1.91945e-03 1.96652e-02
79+
-3.82452e-06 2.46427e-05 -2.46427e-05 -4.45692e-04 -5.50669e-03 -1.96652e-02
80+
1.96652e-02 -1.91945e-03 -1.12382e-04 7.21513e-04 -7.21513e-04 3.79778e-06
81+
-7.21513e-04 2.16956e-03 -2.61966e-03 2.43147e-05 7.21513e-04 -2.61966e-03
82+
2.16956e-03 -2.43147e-05 3.79778e-06 -2.43147e-05 2.43147e-05 -4.48512e-04
83+
# CSR column indices
84+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
85+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
86+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
87+
# CSR row pointers
88+
0 8 16 24 32 36 40 44 48
89+
90+
0 -1 1 32
91+
# CSR values
92+
-1.11792e-04 7.16241e-04 3.82452e-06 7.16241e-04 -7.16241e-04 2.12235e-03
93+
2.46427e-05 2.57041e-03 3.82452e-06 -2.46427e-05 -4.45692e-04 -2.46427e-05
94+
-7.16241e-04 2.57041e-03 2.46427e-05 2.12235e-03 -1.12382e-04 7.21513e-04
95+
-3.79778e-06 7.21513e-04 -7.21513e-04 2.16956e-03 -2.43147e-05 2.61966e-03
96+
-3.79778e-06 2.43147e-05 -4.48512e-04 2.43147e-05 -7.21513e-04 2.61966e-03
97+
-2.43147e-05 2.16956e-03
98+
# CSR column indices
99+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
100+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
101+
# CSR row pointers
102+
0 4 8 12 16 20 24 28 32
103+
104+
0 0 -1 48
105+
# CSR values
106+
-1.11792e-04 3.82452e-06 -7.16241e-04 -7.16241e-04 -3.37629e-02 -8.00872e-03
107+
-8.00872e-03 -8.00872e-03 3.82452e-06 -4.45692e-04 2.46427e-05 2.46427e-05
108+
5.50669e-03 -1.91945e-03 -1.96652e-02 -1.96652e-02 7.16241e-04 -2.46427e-05
109+
2.12235e-03 2.57041e-03 5.50669e-03 -1.96652e-02 -1.91945e-03 -1.96652e-02
110+
7.16241e-04 -2.46427e-05 2.57041e-03 2.12235e-03 5.50669e-03 -1.96652e-02
111+
-1.96652e-02 -1.91945e-03 -1.12382e-04 -3.79778e-06 -7.21513e-04 -7.21513e-04
112+
-3.79778e-06 -4.48512e-04 -2.43147e-05 -2.43147e-05 7.21513e-04 2.43147e-05
113+
2.16956e-03 2.61966e-03 7.21513e-04 2.43147e-05 2.61966e-03 2.16956e-03
114+
# CSR column indices
115+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
116+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
117+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
118+
# CSR row pointers
119+
0 8 16 24 32 36 40 44 48
120+
121+
0 0 0 40
122+
# CSR values
123+
-5.43126e-01 -3.37629e-02 -8.00872e-03 8.00872e-03 8.00872e-03 8.04017e-01
124+
5.50669e-03 -1.91945e-03 1.96652e-02 1.96652e-02 8.04017e-01 -5.50669e-03
125+
1.96652e-02 -1.91945e-03 -1.96652e-02 8.04017e-01 -5.50669e-03 1.96652e-02
126+
-1.96652e-02 -1.91945e-03 -3.37629e-02 5.50669e-03 -5.50669e-03 -5.50669e-03
127+
-4.69258e-01 -8.00872e-03 -1.91945e-03 1.96652e-02 1.96652e-02 8.75227e-01
128+
8.00872e-03 1.96652e-02 -1.91945e-03 -1.96652e-02 8.75227e-01 8.00872e-03
129+
1.96652e-02 -1.96652e-02 -1.91945e-03 8.75227e-01
130+
# CSR column indices
131+
0 4 5 6 7 1 4 5 6 7 2 4 5 6 7 3
132+
4 5 6 7 0 1 2 3 4 0 1 2 3 5 0 1
133+
2 3 6 0 1 2 3 7
134+
# CSR row pointers
135+
0 5 10 15 20 25 30 35 40
136+
137+
0 0 1 48
138+
# CSR values
139+
-1.11792e-04 3.82452e-06 7.16241e-04 7.16241e-04 3.82452e-06 -4.45692e-04
140+
-2.46427e-05 -2.46427e-05 -7.16241e-04 2.46427e-05 2.12235e-03 2.57041e-03
141+
-7.16241e-04 2.46427e-05 2.57041e-03 2.12235e-03 -3.37629e-02 5.50669e-03
142+
5.50669e-03 5.50669e-03 -1.12382e-04 -3.79778e-06 7.21513e-04 7.21513e-04
143+
-8.00872e-03 -1.91945e-03 -1.96652e-02 -1.96652e-02 -3.79778e-06 -4.48512e-04
144+
2.43147e-05 2.43147e-05 -8.00872e-03 -1.96652e-02 -1.91945e-03 -1.96652e-02
145+
-7.21513e-04 -2.43147e-05 2.16956e-03 2.61966e-03 -8.00872e-03 -1.96652e-02
146+
-1.96652e-02 -1.91945e-03 -7.21513e-04 -2.43147e-05 2.61966e-03 2.16956e-03
147+
# CSR column indices
148+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
149+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
150+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
151+
# CSR row pointers
152+
0 4 8 12 16 24 32 40 48
153+
154+
0 1 -1 32
155+
# CSR values
156+
-1.11792e-04 -7.16241e-04 3.82452e-06 -7.16241e-04 7.16241e-04 2.12235e-03
157+
-2.46427e-05 2.57041e-03 3.82452e-06 2.46427e-05 -4.45692e-04 2.46427e-05
158+
7.16241e-04 2.57041e-03 -2.46427e-05 2.12235e-03 -1.12382e-04 -7.21513e-04
159+
-3.79778e-06 -7.21513e-04 7.21513e-04 2.16956e-03 2.43147e-05 2.61966e-03
160+
-3.79778e-06 -2.43147e-05 -4.48512e-04 -2.43147e-05 7.21513e-04 2.61966e-03
161+
2.43147e-05 2.16956e-03
162+
# CSR column indices
163+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
164+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
165+
# CSR row pointers
166+
0 4 8 12 16 20 24 28 32
167+
168+
0 1 0 48
169+
# CSR values
170+
-1.11792e-04 -7.16241e-04 7.16241e-04 -3.82452e-06 7.16241e-04 2.12235e-03
171+
-2.57041e-03 2.46427e-05 -7.16241e-04 -2.57041e-03 2.12235e-03 -2.46427e-05
172+
-3.82452e-06 -2.46427e-05 2.46427e-05 -4.45692e-04 -3.37629e-02 -5.50669e-03
173+
5.50669e-03 -5.50669e-03 -1.12382e-04 -7.21513e-04 7.21513e-04 3.79778e-06
174+
8.00872e-03 -1.91945e-03 1.96652e-02 -1.96652e-02 7.21513e-04 2.16956e-03
175+
-2.61966e-03 -2.43147e-05 -8.00872e-03 1.96652e-02 -1.91945e-03 1.96652e-02
176+
-7.21513e-04 -2.61966e-03 2.16956e-03 2.43147e-05 8.00872e-03 -1.96652e-02
177+
1.96652e-02 -1.91945e-03 3.79778e-06 2.43147e-05 -2.43147e-05 -4.48512e-04
178+
# CSR column indices
179+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
180+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
181+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
182+
# CSR row pointers
183+
0 4 8 12 16 24 32 40 48
184+
185+
1 -1 0 32
186+
# CSR values
187+
-1.11792e-04 -3.82452e-06 -7.16241e-04 7.16241e-04 -3.82452e-06 -4.45692e-04
188+
-2.46427e-05 2.46427e-05 7.16241e-04 2.46427e-05 2.12235e-03 -2.57041e-03
189+
-7.16241e-04 -2.46427e-05 -2.57041e-03 2.12235e-03 -1.12382e-04 3.79778e-06
190+
-7.21513e-04 7.21513e-04 3.79778e-06 -4.48512e-04 2.43147e-05 -2.43147e-05
191+
7.21513e-04 -2.43147e-05 2.16956e-03 -2.61966e-03 -7.21513e-04 2.43147e-05
192+
-2.61966e-03 2.16956e-03
193+
# CSR column indices
194+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
195+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
196+
# CSR row pointers
197+
0 4 8 12 16 20 24 28 32
198+
199+
1 0 -1 32
200+
# CSR values
201+
-1.11792e-04 -7.16241e-04 -7.16241e-04 3.82452e-06 7.16241e-04 2.12235e-03
202+
2.57041e-03 -2.46427e-05 7.16241e-04 2.57041e-03 2.12235e-03 -2.46427e-05
203+
3.82452e-06 2.46427e-05 2.46427e-05 -4.45692e-04 -1.12382e-04 -7.21513e-04
204+
-7.21513e-04 -3.79778e-06 7.21513e-04 2.16956e-03 2.61966e-03 2.43147e-05
205+
7.21513e-04 2.61966e-03 2.16956e-03 2.43147e-05 -3.79778e-06 -2.43147e-05
206+
-2.43147e-05 -4.48512e-04
207+
# CSR column indices
208+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
209+
4 5 6 7 4 5 6 7 4 5 6 7 4 5 6 7
210+
# CSR row pointers
211+
0 4 8 12 16 20 24 28 32
212+
213+
1 0 0 48
214+
# CSR values
215+
-1.11792e-04 -7.16241e-04 -3.82452e-06 7.16241e-04 7.16241e-04 2.12235e-03
216+
2.46427e-05 -2.57041e-03 -3.82452e-06 -2.46427e-05 -4.45692e-04 2.46427e-05
217+
-7.16241e-04 -2.57041e-03 -2.46427e-05 2.12235e-03 -3.37629e-02 -5.50669e-03
218+
-5.50669e-03 5.50669e-03 -1.12382e-04 -7.21513e-04 3.79778e-06 7.21513e-04
219+
8.00872e-03 -1.91945e-03 -1.96652e-02 1.96652e-02 7.21513e-04 2.16956e-03
220+
-2.43147e-05 -2.61966e-03 8.00872e-03 -1.96652e-02 -1.91945e-03 1.96652e-02
221+
3.79778e-06 2.43147e-05 -4.48512e-04 -2.43147e-05 -8.00872e-03 1.96652e-02
222+
1.96652e-02 -1.91945e-03 -7.21513e-04 -2.61966e-03 2.43147e-05 2.16956e-03
223+
# CSR column indices
224+
0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
225+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
226+
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
227+
# CSR row pointers
228+
0 4 8 12 16 24 32 40 48
229+

0 commit comments

Comments
 (0)