File size: 987 Bytes
ed552fd | 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 | #!/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')
|