| #!/usr/bin/env python3 | |
| """批量更新 raw/ 下所有 case 的 controlDict writeInterval""" | |
| import os, re | |
| raw = '/mnt/f/agent-workspace/paper2/Exp/data/raw' | |
| # endTime/25 for each case type | |
| wi_map = { | |
| 'dam_break': 0.08, | |
| 'rising_bubble': 0.12, | |
| 'droplet_impact': 0.008, | |
| 'stokes_wave': 0.8, | |
| } | |
| updated = 0 | |
| for ct, wi in wi_map.items(): | |
| ct_dir = os.path.join(raw, ct) | |
| if not os.path.isdir(ct_dir): | |
| continue | |
| for case in sorted(os.listdir(ct_dir)): | |
| cd_path = os.path.join(ct_dir, case, 'system', 'controlDict') | |
| if not os.path.isfile(cd_path): | |
| continue | |
| with open(cd_path) as f: | |
| content = f.read() | |
| new_content = re.sub( | |
| r'(writeInterval\s+)\S+', | |
| f'\\g<1>{wi};', | |
| content | |
| ) | |
| if new_content != content: | |
| with open(cd_path, 'w') as f: | |
| f.write(new_content) | |
| updated += 1 | |
| print(f'Updated {updated} controlDict files') | |