Skip to content

Update write_dipole.cpp#7349

Merged
mohanchen merged 11 commits into
deepmodeling:developfrom
mohanchen:20260516
May 17, 2026
Merged

Update write_dipole.cpp#7349
mohanchen merged 11 commits into
deepmodeling:developfrom
mohanchen:20260516

Conversation

@mohanchen
Copy link
Copy Markdown
Collaborator

Update write_dipole.cpp

abacus_fixer added 3 commits May 16, 2026 16:52
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)
   - 优化变量作用域
   - 改进错误处理
@mohanchen mohanchen requested a review from AsTonyshment May 16, 2026 09:49
@mohanchen mohanchen added Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes labels May 16, 2026
Comment thread source/source_io/module_dipole/write_dipole.cpp Outdated
Copy link
Copy Markdown
Collaborator

@AsTonyshment AsTonyshment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, LGTM.

abacus_fixer added 8 commits May 16, 2026 21:12
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
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
@mohanchen mohanchen merged commit 6095b84 into deepmodeling:develop May 17, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Input&Output Suitable for coders without knowing too many DFT details Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants