Update write_dipole.cpp#7349
Merged
Merged
Conversation
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) - 优化变量作用域 - 改进错误处理
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Update write_dipole.cpp