Skip to content

Commit f4a2670

Browse files
committed
Fix initialization order for delta spin calculations in OnsiteProj
- Modified op_pw_proj.cpp to move delta spin initialization logic into init() method ensuring proper setup before calculations - Updated .gitignore with comprehensive file exclusion patterns including compressed archives and environment files - Ensures ip_iat array is properly initialized before being used in delta spin operations during PW onsite projections
1 parent 78e16d9 commit f4a2670

2 files changed

Lines changed: 82 additions & 46 deletions

File tree

.gitignore

Lines changed: 62 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,64 @@
1-
/build*
2-
build_info.h
3-
bin
4-
obj
1+
```
2+
# Compiled and build artifacts
53
*.o
6-
OUT.*
7-
log.txt
8-
result.out
9-
*.dat
10-
.DS_Store
11-
.cache
12-
.vscode
13-
html
4+
*.obj
5+
*.exe
6+
*.dll
7+
*.so
8+
*.a
9+
*.out
10+
11+
# Dependencies
12+
node_modules/
13+
venv/
14+
.venv/
15+
__pycache__/
16+
.mypy_cache/
17+
.pytest_cache/
18+
target/
19+
.gradle/
20+
21+
# Logs and temp files
1422
*.log
15-
STRU_READIN_ADJUST.cif
16-
*.egg
17-
*.egg-info
18-
build
19-
dist
20-
.idea
21-
time.json
22-
*.pyc
23-
__pycache__
24-
abacus.json
25-
*.npy
26-
toolchain/install/
27-
toolchain/abacus_env.sh
28-
.trae
29-
compile_commands.json
23+
*.tmp
24+
*.swp
25+
*.swo
26+
27+
# Environment
28+
.env
29+
.env.local
30+
*.env.*
31+
32+
# Editors
33+
.vscode/
34+
.idea/
35+
36+
# System files
37+
.DS_Store
38+
Thumbs.db
39+
40+
# Coverage
41+
coverage/
42+
htmlcov/
43+
.coverage
44+
45+
# Compressed files
46+
*.zip
47+
*.gz
48+
*.tar
49+
*.tgz
50+
*.bz2
51+
*.xz
52+
*.7z
53+
*.rar
54+
*.zst
55+
*.lz4
56+
*.lzh
57+
*.cab
58+
*.arj
59+
*.rpm
60+
*.deb
61+
*.Z
62+
*.lz
63+
*.lzo
64+
```

source/source_pw/module_pwdft/op_pw_proj.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,24 @@ void OnsiteProj<OperatorPW<T, Device>>::init(const int ik_in)
5858
onsite_p->tabulate_atomic(ik_in);
5959
this->tnp = onsite_p->get_tot_nproj();
6060

61+
if(this->has_delta_spin && !this->init_delta_spin)
62+
{
63+
this->init_delta_spin = true;
64+
//prepare ip_iat and lambda_coeff
65+
resmem_int_op()(this->ip_iat, onsite_p->get_tot_nproj());
66+
resmem_complex_op()(this->lambda_coeff, this->ucell->nat * 4);
67+
std::vector<int> ip_iat0(onsite_p->get_tot_nproj());
68+
int ip0 = 0;
69+
for(int iat=0;iat<this->ucell->nat;iat++)
70+
{
71+
for(int ip=0;ip<onsite_p->get_nh(iat);ip++)
72+
{
73+
ip_iat0[ip0++] = iat;
74+
}
75+
}
76+
syncmem_int_h2d_op()(this->ip_iat, ip_iat0.data(), onsite_p->get_tot_nproj());
77+
}
78+
6179
if(this->next_op != nullptr)
6280
{
6381
this->next_op->init(ik_in);
@@ -130,25 +148,9 @@ void OnsiteProj<OperatorPW<T, Device>>::cal_ps_delta_spin(const int npol, const
130148
}
131149
setmem_complex_op()(this->ps, 0, tnp * m);
132150

133-
if(!this->init_delta_spin)
134-
{
135-
this->init_delta_spin = true;
136-
//prepare ip_iat and lambda_coeff
137-
resmem_int_op()(this->ip_iat, onsite_p->get_tot_nproj());
138-
resmem_complex_op()(this->lambda_coeff, this->ucell->nat * 4);
139-
std::vector<int> ip_iat0(onsite_p->get_tot_nproj());
140-
int ip0 = 0;
141-
for(int iat=0;iat<this->ucell->nat;iat++)
142-
{
143-
for(int ip=0;ip<onsite_p->get_nh(iat);ip++)
144-
{
145-
ip_iat0[ip0++] = iat;
146-
}
147-
}
148-
syncmem_int_h2d_op()(this->ip_iat, ip_iat0.data(), onsite_p->get_tot_nproj());
149-
}
150-
151151
// prepare array of nh_iat and lambda_array to pass to the onsite_ps_op operator
152+
spinconstrain::SpinConstrain<std::complex<double>>& sc = spinconstrain::SpinConstrain<std::complex<double>>::getScInstance();
153+
auto& lambda = sc.get_sc_lambda();
152154
std::vector<std::complex<double>> tmp_lambda_coeff(this->ucell->nat * 4);
153155
for(int iat=0;iat<this->ucell->nat;iat++)
154156
{
@@ -158,7 +160,6 @@ void OnsiteProj<OperatorPW<T, Device>>::cal_ps_delta_spin(const int npol, const
158160
tmp_lambda_coeff[iat * 4 + 3] = std::complex<double>(-1 * lambda[iat][2], 0.0);
159161
}
160162
syncmem_complex_h2d_op()(this->lambda_coeff, tmp_lambda_coeff.data(), this->ucell->nat * 4);
161-
// TODO: code block above should be moved to the init function
162163

163164
hamilt::onsite_ps_op<Real, Device>()(
164165
this->ctx, // device context

0 commit comments

Comments
 (0)