Commit 6095b84
Update write_dipole.cpp (#7349)
* change the output of step of electron evolve, starts from 1
* update dipole outputs
* 改进 dipole_io 模块:优化性能和代码结构
1. 增强 write_dipole 函数:
- 添加 ofs_running 参数,支持自定义输出流
- 移除未使用的头文件引用(charge.h, evolve_elec.h)
- 统一电子偶极矩计算算法,移除 ifdef MPI 分支
- 预计算倒网格维度倒数,优化性能
- 添加除零保护检查
- 添加 OpenMP 并行化,使用 reduction 累加
- 提取公共打印函数 printDipoleMoment
2. 改进 prepare 函数:
- 使用 switch 语句替代 if-else 链
- 移除中间变量,直接返回结果
3. 更新 dipole_io.h:
- 添加 UnitCell 头文件引用
- 调整参数顺序,添加 ofs_running 在前
4. 添加详细注释:
- 函数文档注释
- 物理公式说明
- 代码实现细节
5. 优化代码风格:
- 使用小写常量名(small_value)
- 优化变量作用域
- 改进错误处理
* delete uselss #ifdef __LCAO
* Refactor: migrate write_dipole from ctrl_output_td to ctrl_output_fp
This refactoring extends the dipole output functionality to all DFT solvers
by moving it from the TDDFT-specific module to the common output module.
Changes:
1. source/source_io/module_ctrl/ctrl_output_fp.cpp
- Add include for dipole_io.h
- Add dipole output functionality after out_xc_r section
- Now supports out_dipole parameter for all FP-based solvers
2. source/source_io/module_ctrl/ctrl_output_td.cpp
- Remove duplicate dipole output code (migrated to ctrl_output_fp)
- Remove unnecessary dipole_io.h include
- Renumber comments (1) for current, (3) for restart
3. source/source_io/module_dipole/write_dipole.cpp
- Rename printDipoleMoment to print_dipole_moment (snake_case convention)
Benefits:
- OFDFT, KSDFT (PW/LCAO), SDFT, and TDDFT all gain dipole output capability
- Single implementation point reduces maintenance burden
- Consistent behavior across all solver types
- Better code organization following the base class aggregation pattern
* Cleanup: remove unused 'is' parameter from write_dipole
The 'is' (spin channel index) parameter was not used in the write_dipole function:
- Electron dipole moment uses rho_save (already selected by spin)
- Ionic dipole moment uses ucell (spin-independent)
- File naming is handled by the caller through 'fn' parameter
Changes:
1. dipole_io.h - Remove 'is' parameter from function declaration
2. write_dipole.cpp - Remove 'is' parameter from function definition
3. ctrl_output_fp.cpp - Update function call to remove 'is' argument
* update index.rst
* add back #ifdef __LCAO
* add output_dipole.md
* add INPUT
* fix
---------
Co-authored-by: abacus_fixer <mohanchen@pku.eud.cn>1 parent 8ff0a05 commit 6095b84
9 files changed
Lines changed: 280 additions & 112 deletions
File tree
- docs/advanced/output_files
- examples
- 18_md/01_lcao_gamma_Si8
- 22_rt-tddft/01_H2_length_gauge
- source
- source_esolver
- source_io
- module_ctrl
- module_dipole
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
249 | 249 | | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
253 | 253 | | |
254 | 254 | | |
255 | 255 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
198 | 199 | | |
199 | 200 | | |
200 | 201 | | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
201 | 213 | | |
202 | 214 | | |
203 | 215 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | 4 | | |
6 | 5 | | |
7 | 6 | | |
| |||
30 | 29 | | |
31 | 30 | | |
32 | 31 | | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
| 32 | + | |
45 | 33 | | |
46 | 34 | | |
47 | 35 | | |
| |||
65 | 53 | | |
66 | 54 | | |
67 | 55 | | |
68 | | - | |
69 | 56 | | |
70 | 57 | | |
71 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | | - | |
14 | 15 | | |
15 | 16 | | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| |||
0 commit comments