Datasets:

Modalities:
Text
License:
T0NGXU commited on
Commit
45d7d4e
·
verified ·
1 Parent(s): 94b0482

Add files using upload-large-folder tool

Browse files
Doublecone/case1.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:767646c5f6c81370d42228e1450c627ccb073fbdf9f74d93159f6258204a0a0d
3
+ size 709168420
Doublecone/case10-1.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb3330c88de70a3d89a10a5f9225b7df3d602984190f420fa1d65e6c1fa7e8c2
3
+ size 724263268
Doublecone/case10.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef4274bbf98b2cd31630dd291ccf8bfe323bfc17bf3e0a2622d47e18b6099427
3
+ size 715126705
Doublecone/case11.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:56225b79717b7584d9f6fc524836e71b8b6fb4ed387ef3ae1e55d9f02bc832ce
3
+ size 710377741
Doublecone/case12.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2626d9a29997bdb539a3e53db873360dc7081d41c88d3d27595d3079132b51e2
3
+ size 702566974
Doublecone/case13.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d40f9f4299671ddf7351f74fafd0f77a7645513f0fb1fb1dc1ce7346dc51a967
3
+ size 708989595
Doublecone/case14.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:fd95f244695fde7fcd3d9e3fd7067ba8df2e3d72da6f1c193b0e0e5b75e8c77a
3
+ size 711069271
Doublecone/case15.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1b6f248674bd865eb507a6e4703b435d91e7f228576985c8aa5b3761fdaef738
3
+ size 718121027
Doublecone/case16.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f725188f300c97566b81a3ca1c8c93efbbca70ad91b47112baf789a0167d8689
3
+ size 713587173
Doublecone/case17.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c9d6a775f90c81f84e7f001d2d76aefa9b4d24e9dca6a34b72bf59d9bd8b823d
3
+ size 723785386
Doublecone/case18.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:75dc196d26b8e95900151bcdda023fcc84fd6d69a14eca6baf72a78dbc70f8fb
3
+ size 710764013
Doublecone/case19.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:742945bba5834b357722ee0d89e3fe32a494ae17183d70e3e2591dedae16412b
3
+ size 713052270
Doublecone/case2.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ebddae4508d1f7db318c005ccfa50bde2343162717ab7980559debd39e1b8a7
3
+ size 708244113
Doublecone/case20.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a8dd1a6310202c18585c63cc61e861fa8f37430b504e109ec8db2deed753bbfd
3
+ size 713439124
Doublecone/case21.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:df72a006c922601182b2bf467208063b3b1248416b217d2fa64a0e62b2a01b3d
3
+ size 709785874
Doublecone/case22.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:95833ae70c359732f6e3caadfc7d15d1677d3246657db45e02f80f74127df1c1
3
+ size 708263582
Doublecone/case23.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:96635a8641cb911463698bb27e72edec87827c47471842d5c19e66417147f125
3
+ size 710496318
Doublecone/case24.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:468f94dcd7ceae3990f837e077f55642f03d7a80a297a38cfe731c6b153c3768
3
+ size 710809778
Doublecone/case25.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c366f0449f746965cfd4ad3b00ec478d42e9692efdaf56dd7674573492b4c531
3
+ size 713163469
Doublecone/case26.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5b8307a0fb8c06091a17549eb7d75fbf3ddb96da127daedcb79584ada2b78e3f
3
+ size 714056505
Doublecone/case27.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cf1fc5342a7ad4107948337d266f2681a8a683a3cf7d63868eb3c9a7b70ae12d
3
+ size 716552659
Doublecone/case28.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:17b2c68573d030c33b88a947d9401b8ec8119e59c6c0fee28f66d1a92f0b838f
3
+ size 722604392
Doublecone/case29.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:541e61638f2049e9910721430b65144c703f5f71e7bf58c0d60516abe438b954
3
+ size 707036841
Doublecone/case3.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:241ddb324a82fe9246af1066a6715bc4c7c8f006c02dedfb1da37a1de415f852
3
+ size 707431427
Doublecone/case30.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c3aa1cf077bf9ccf1af97588b80874e8a62fcf346ec40595a55f3a23d1804e34
3
+ size 707871217
Doublecone/case31.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:94a4ef9fed6d8c1d871c95337686ceed6121f56859283f458514afbfd3817c30
3
+ size 709866882
Doublecone/case32.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:72bc914ffb478edce944f97264921ac72ff030ccf08e53f518146bc57ac54edc
3
+ size 714358447
Doublecone/case33.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:55b3aade6f5b8d2fda799e135a7df8a8f1998c265cb5fc827e437ddf6f51fc64
3
+ size 711655995
Doublecone/case34.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c1f7d6d9fc5ccd344a5f87648ccfe9ccd0f9f40ace668beef0f490c851c1ea43
3
+ size 712066985
Doublecone/case35.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2b71242265d09aa34b84b74d7a498509332344ac297cf9a4cb75d28ccf375f8
3
+ size 705687009
Doublecone/case36.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06c8b9bc9470062631377b3f5db3161b6071125a7d6c0668c1347b714bffcb0a
3
+ size 708325958
Doublecone/case37.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:becf83ac911f5fbb8b875d487debee11af3116fcce28f20737c244b5fe727a01
3
+ size 709084068
Doublecone/case38.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b502f56b7bee4098d74048dc85e73353c3125ddfb8b247612951fd45ef94c3e4
3
+ size 710817356
Doublecone/case39.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:99521cc87c131ba35affe3b29b793ef5df3b9acffa0ed0ef0d30c0e87bd794ea
3
+ size 712577779
Doublecone/case4.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1dc958434a3830c6b9c9bb6c4dc1f914130ce2f6a2a8e836bde08e28f6671295
3
+ size 707157847
Doublecone/case40.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7fc4128872e28dace9ba834bbf7be98a7ac00ef08c8a6b14827fe9e6fb6eeb1e
3
+ size 713184040
Doublecone/case41.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6dca5e8d3185b379500806f1a7ea8be50f097caa24af78627a6b3c64818cfc96
3
+ size 706902315
Doublecone/case42.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:47406257105cecdd09aace85c4d714cfe4a59cf4c3e3547475d331efc8400f97
3
+ size 709389771
Doublecone/case43.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5999cab069e17a328e3bfad04d53eba53568f771f08706b79e812e9452466bfd
3
+ size 710932719
Doublecone/case44.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:20051cf44b7f607d1c2b7e41f633d109f5503fe777aef2d8c707476b44f1bc80
3
+ size 712854988
Doublecone/case45.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e527e4764540097fc9764a974a443381f1b594e6e04a04d6af3740c0cee0f6c7
3
+ size 712633044
Doublecone/case46.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e573674a42aea3a1ea5040d41f135d3ff7eebaa2fdf127f342c07096920976a4
3
+ size 713125265
Doublecone/case47.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a33884ec5b7a6abc92ecb551ae601febb81c5692e5920df3639665410ac1744b
3
+ size 720571295
Doublecone/case48.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44008676327b0ccc97873890afeb7725811f0936355d2bdfb7a1b8482d4dcb9b
3
+ size 722423730
Doublecone/case49.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:43b40f0e30a0e1dd6a4bed4e6cac6cf38676c4642e5f4f9b9760660ffee146ee
3
+ size 722086875
Doublecone/case5.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3be59fcc1e8c727f0a51aeda4b43cdf157dd46b0e7dae44549fb6b97fa818b00
3
+ size 711222593
Doublecone/case50.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:46f99321b304f6afc3e81b47360fcab1dd6523b04ace9c69d4804283790eb8a8
3
+ size 712344531
Doublecone/case7.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aa23172ec1626ad9d003936015759c4524a53d5183c7e4437648862fe22e4402
3
+ size 714790277
Doublecone/extract_artist_logs.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Wed Jan 14 11:04:01 2026
4
+
5
+ @author: T0NGXU
6
+ """
7
+
8
+ import os
9
+ import re
10
+ import pandas as pd
11
+ from pathlib import Path
12
+
13
+ def extract_artist_log_data(root_folder):
14
+ """
15
+ 从rawdata文件夹下的所有snapshot_*文件夹中提取artist.log文件的数据
16
+ 提取第11到19行的关键参数信息
17
+ """
18
+ # 存储所有提取的数据
19
+ all_data = []
20
+
21
+ # 查找所有的snapshot_*文件夹
22
+ snapshot_folders = sorted([f for f in Path(root_folder).iterdir()
23
+ if f.is_dir() and f.name.startswith('snapshot_')])
24
+
25
+ print(f"找到 {len(snapshot_folders)} 个snapshot文件夹")
26
+
27
+ for folder in snapshot_folders:
28
+ log_file = folder / "artist.log"
29
+
30
+ if not log_file.exists():
31
+ print(f"警告: {log_file} 不存在")
32
+ continue
33
+
34
+ try:
35
+ # 提取文件夹名中的数字(snapshot编号)
36
+ snapshot_num = int(folder.name.split('_')[1])
37
+
38
+ with open(log_file, 'r', encoding='utf-8') as f:
39
+ lines = f.readlines()
40
+
41
+ # 提取第11到19行(索引10到18)
42
+ if len(lines) >= 19:
43
+ data_lines = lines[10:19]
44
+
45
+ # 解析关键参数
46
+ params = {'snapshot': snapshot_num}
47
+
48
+ for line in data_lines:
49
+ line = line.strip()
50
+ if '=' in line:
51
+ # 分割键值对
52
+ parts = line.split('=')
53
+ if len(parts) == 2:
54
+ key = parts[0].strip()
55
+ value = parts[1].strip()
56
+
57
+ # 清理键名,移除特殊字符
58
+ key = re.sub(r'[^a-zA-Z0-9]', '', key)
59
+
60
+ # 尝试转换为数值
61
+ try:
62
+ # 处理科学计数法
63
+ if 'E' in value or 'e' in value:
64
+ value = float(value)
65
+ else:
66
+ # 尝试整数,失败则尝试浮点数
67
+ try:
68
+ value = int(value)
69
+ except ValueError:
70
+ value = float(value)
71
+ except ValueError:
72
+ # 如果转换失败,保持字符串
73
+ pass
74
+
75
+ params[key] = value
76
+
77
+ all_data.append(params)
78
+ print(f"成功提取 snapshot_{snapshot_num} 的数据")
79
+ else:
80
+ print(f"警告: {log_file} 行数不足")
81
+
82
+ except Exception as e:
83
+ print(f"处理 {log_file} 时出错: {e}")
84
+
85
+ # 创建DataFrame
86
+ if all_data:
87
+ df = pd.DataFrame(all_data)
88
+ # 按snapshot编号排序
89
+ df = df.sort_values('snapshot').reset_index(drop=True)
90
+
91
+ # 保存到CSV文件
92
+ output_file = Path(root_folder) / "extracted_artist_log_data.csv"
93
+ df.to_csv(output_file, index=False, encoding='utf-8')
94
+ print(f"\n数据已保存到: {output_file}")
95
+
96
+ # 显示数据概览
97
+ print(f"\n提取的数据概览:")
98
+ print(f"总共提取了 {len(df)} 个snapshot的数据")
99
+ print(f"包含的字段: {list(df.columns)}")
100
+ print(f"\n前5行数据:")
101
+ print(df.head())
102
+
103
+ return df
104
+ else:
105
+ print("未提取到任何数据")
106
+ return None
107
+
108
+ # 使用示例
109
+ if __name__ == "__main__":
110
+ # 设置rawdata文件夹的路径
111
+ rawdata_folder = "raw_data" # 请根据实际情况修改路径
112
+
113
+ if Path(rawdata_folder).exists():
114
+ df = extract_artist_log_data(rawdata_folder)
115
+ else:
116
+ print(f"错误: 文件夹 {rawdata_folder} 不存在")
Doublecone/preprocess.py ADDED
@@ -0,0 +1,208 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import re
3
+ import glob
4
+ import numpy as np
5
+ import torch
6
+ from scipy.interpolate import griddata
7
+ from tqdm import tqdm
8
+
9
+ # ================= 配置区域 =================
10
+ DATA_ROOT = r'D:\生成肖新算例\raw_data'
11
+ OUTPUT_FILE = r'D:\生成肖新算例\raw_data\double_cone_dataset_final.pt'
12
+
13
+ N_NODES_EXPECTED = 1120638
14
+ N_VARS_TOTAL = 68
15
+ TARGET_H = 17 # 我们想要的法向层数
16
+ TARGET_W = 384 # 我们想要的流向点数
17
+
18
+ # 变量索引 (x=0, y=1, rho=66, u=60, v=61, p=63)
19
+ VAR_INDICES = [0, 1, 66, 60, 61, 63]
20
+ # ============================================
21
+
22
+ def read_raw_points(filepath):
23
+ """
24
+ 只读取点云,不关心形状
25
+ """
26
+ try:
27
+ with open(filepath, 'r', encoding='utf-8', errors='ignore') as f:
28
+ content = f.read()
29
+
30
+ # 提取数字
31
+ pattern = re.compile(r'[-+]?\d*\.?\d+(?:[eEdD][-+]?\d+)?')
32
+ # 寻找数据区
33
+ if "ZONETYPE" in content:
34
+ content = content.split("ZONETYPE")[-1]
35
+ elif "POINT" in content:
36
+ content = content.split("POINT")[-1]
37
+
38
+ all_tokens = pattern.findall(content)
39
+
40
+ limit = N_NODES_EXPECTED * N_VARS_TOTAL
41
+ if len(all_tokens) < limit:
42
+ # 容错
43
+ actual_nodes = len(all_tokens) // N_VARS_TOTAL
44
+ limit = actual_nodes * N_VARS_TOTAL
45
+
46
+ # 转为 numpy 矩阵 [N, 68]
47
+ data_flat = np.array(all_tokens[:limit], dtype=np.float32)
48
+ actual_nodes = len(data_flat) // N_VARS_TOTAL
49
+ data_matrix = data_flat.reshape(actual_nodes, N_VARS_TOTAL)
50
+
51
+ # 提取 [N, 6] (x, y, rho, u, v, p)
52
+ return data_matrix[:, VAR_INDICES]
53
+
54
+ except Exception as e:
55
+ print(f"Read error: {e}")
56
+ return None
57
+
58
+ def generate_target_grid(points_data):
59
+ """
60
+ 根据点云的几何边界,生成一个完美的 17x384 结构化网格
61
+ """
62
+ x = points_data[:, 0]
63
+ y = points_data[:, 1]
64
+
65
+ # 1. 找到流向范围 (X轴)
66
+ x_min, x_max = x.min(), x.max()
67
+
68
+ # 我们需要在 X 方向生成 384 个切片
69
+ # 注意:双锥激波通常在 X > 0 的区域,我们需要覆盖整个区域
70
+ target_x_line = np.linspace(x_min, x_max, TARGET_W)
71
+
72
+ # 2. 构建上下边界
73
+ # 我们将空间划分为 TARGET_W 个竖条,在每个竖条里找 Y_min (壁面) 和 Y_max (远场)
74
+ # 为了加速,我们先对原始数据按 X 排序
75
+ # 但 griddata 不需要排序,我们直接定义目标网格的坐标
76
+
77
+ # 更好的策略:
78
+ # 原始网格是贴体的,意味着 Y 坐标随 X 变化。
79
+ # 我们利用几何特征:壁面通常是 Y=0 (或接近0),远场是 Y=Max
80
+
81
+ # 为了保持贴体特性(这一点对激波很重要),我们不能用矩形网格。
82
+ # 我们需要“扇形”网格。
83
+
84
+ # 简单策略:利用极坐标思想或比例思想
85
+ # 在每个 X 位置,Y 从 0 到 Y_max_at_that_x 分布
86
+
87
+ # 这里我们使用 griddata 的 'nearest' 或 'linear' 直接映射到一个规则的 Logical Grid
88
+ # 既然源数据很密,我们可以直接定义一个物理空间的网格吗?不行,因为远场边界是斜的。
89
+
90
+ # === 核心算法:边界重建 ===
91
+ # 1. 把所有点按 X 坐标分桶
92
+ num_bins = TARGET_W
93
+ x_bins = np.linspace(x_min, x_max, num_bins)
94
+
95
+ grid_x = np.zeros((TARGET_H, TARGET_W))
96
+ grid_y = np.zeros((TARGET_H, TARGET_W))
97
+
98
+ # 对每一列(流向位置)
99
+ for j in range(TARGET_W):
100
+ current_x = x_bins[j]
101
+ # 找到原始数据中 X 坐标接近 current_x 的点 (取一个薄切片)
102
+ # 宽度容差
103
+ dx = (x_max - x_min) / TARGET_W
104
+ mask = (x >= current_x - dx/1.5) & (x <= current_x + dx/1.5)
105
+
106
+ slice_y = y[mask]
107
+
108
+ if len(slice_y) == 0:
109
+ # 如果切片没数据(可能是坏点),沿用上一列
110
+ if j > 0:
111
+ grid_x[:, j] = grid_x[:, j-1]
112
+ grid_y[:, j] = grid_y[:, j-1]
113
+ continue
114
+
115
+ # 在这个切片里,找到 Y_min (壁面) 和 Y_max (远场)
116
+ y_bot = slice_y.min()
117
+ y_top = slice_y.max()
118
+
119
+ # 在 Y_bot 和 Y_top 之间均匀生成 17 个点
120
+ new_y_col = np.linspace(y_bot, y_top, TARGET_H)
121
+
122
+ grid_x[:, j] = current_x
123
+ grid_y[:, j] = new_y_col
124
+
125
+ return grid_x, grid_y
126
+
127
+ def process_regrid(filepath):
128
+ # 1. 读取原始散乱点
129
+ raw_data = read_raw_points(filepath)
130
+ if raw_data is None: return None
131
+
132
+ # 2. 生成目标网格坐标 (物理空间)
133
+ # [17, 384]
134
+ grid_x, grid_y = generate_target_grid(raw_data)
135
+
136
+ # 3. 插值 (核心步骤)
137
+ # 将原始数据 (x, y, rho...) 插值到新的 (grid_x, grid_y) 上
138
+ # raw_data[:, 0:2] 是源坐标 (N, 2)
139
+ # raw_data[:, 2:] 是源值 (N, 4)
140
+ # (grid_x, grid_y) 是目标坐标
141
+
142
+ points = raw_data[:, 0:2]
143
+ values = raw_data[:, 2:] # rho, u, v, p
144
+
145
+ # method='linear' 保证平滑,但比 nearest 慢。
146
+ # 鉴于数据量大,我们可以先尝试 'linear'。如果太慢,用 'nearest'。
147
+ # 这里为了质量,一定要用 linear
148
+ try:
149
+ grid_values = griddata(points, values, (grid_x, grid_y), method='linear', fill_value=0)
150
+ except Exception as e:
151
+ print(f"Interpolation failed: {e}")
152
+ return None
153
+
154
+ # 4. 组合结果
155
+ # grid_x: [17, 384]
156
+ # grid_values: [17, 384, 4]
157
+
158
+ # 转换为 [6, 17, 384] -> (x, y, rho, u, v, p)
159
+ # 先把 x, y 扩充维度
160
+ grid_x_exp = grid_x[:, :, np.newaxis]
161
+ grid_y_exp = grid_y[:, :, np.newaxis]
162
+
163
+ full_grid = np.concatenate([grid_x_exp, grid_y_exp, grid_values], axis=2)
164
+
165
+ # Transpose to [C, H, W]
166
+ final_tensor = np.transpose(full_grid, (2, 0, 1))
167
+
168
+ return final_tensor
169
+
170
+ def main():
171
+ print(f"Regridding Mode: {DATA_ROOT}")
172
+ file_list = sorted(glob.glob(os.path.join(DATA_ROOT, 'snapshot_*', 'flowPoint.plt')))
173
+
174
+ processed_list = []
175
+ for fname in tqdm(file_list, desc="Regridding"):
176
+ tensor = process_regrid(fname)
177
+ if tensor is not None:
178
+ processed_list.append(tensor)
179
+
180
+ if not processed_list:
181
+ print("Failed.")
182
+ return
183
+
184
+ full_tensor = np.stack(processed_list, axis=0)
185
+ full_tensor = torch.from_numpy(full_tensor).float()
186
+
187
+ # 处理 NaN (插值可能产生空洞)
188
+ if torch.isnan(full_tensor).any():
189
+ print("Warning: 插值包含 NaN,正在填充...")
190
+ full_tensor = torch.nan_to_num(full_tensor, 0.0)
191
+
192
+ print(f"\n✅ Done! Shape: {full_tensor.shape}")
193
+
194
+ # Save
195
+ input_data = full_tensor[:, 0:2]
196
+ target_data = full_tensor[:, 2:]
197
+
198
+ stats = {
199
+ 'x_mean': input_data[:,0].mean(), 'x_std': input_data[:,0].std(),
200
+ 'rho_mean': target_data[:,0].mean(), 'rho_std': target_data[:,0].std(),
201
+ }
202
+
203
+ torch.save({'x': input_data, 'y': target_data, 'stats': stats}, OUTPUT_FILE)
204
+ print(f"Saved to {OUTPUT_FILE}")
205
+ print("现在去运行 check_data.py,你会看到完美光滑的图像。")
206
+
207
+ if __name__ == "__main__":
208
+ main()