Marten Lienen,DavidLüdke,Jan Hansen-Palmus,StephanGünnemann

該存儲庫包含用於在我們的論文中產生結果的代碼:OpenReview,Arxiv。
除模型,數據加載和培訓代碼外,該存儲庫還包含用於配置和運行OpenFOAM併後進程輸出的代碼。對於該領域的其他研究人員來說,這些工具可能是非常有用的起點。特別是
# Clone the repository
git clone https://github.com/martenlienen/generative-turbulence.git
# Change into the repository
cd generative-turbulence
# Install package editably with dependencies
pip install -e .
# If you need a specific pytorch version, e.g. CPU-only or an older CUDA version, check
#
# https://pytorch.org/get-started/locally/
#
# and run, for example,
#
# pip install torch --extra-index-url https://download.pytorch.org/whl/cu117
#
# before installing this package. 形狀數據集託管在Tum大學圖書館。要下載它,請按照其頁面上的說明進行操作或執行以下步驟。首先,下載文件。
# Download all archives to data/shapes/download
scripts/download-dataset.sh請注意,這可能需要很長時間,因為處理後的數據大約為2TB。該腳本使用rsync ,因此您可以恢復部分下載。如果您還想下載RAW OpenFOAM案例數據,請改用
scripts/download-dataset.sh --with-raw下載Invidual檔案後,您需要提取文件。以下腳本為您服務
scripts/extract-dataset.sh之後,您可以按照以下所述開始訓練模型。
以下片段從data.h5集中的任何數據中加載數據。H5文件供您探索和實驗。
import numpy as np
import h5py as h5
def load_data ( path , idx , features = [ "u" , "p" ]):
"""Load data from a data.h5 file into an easily digestible matrix format.
Arguments
---------
path
Path to a data.h5 file in the `shapes` dataset
idx
Index or indices of sample to load. Can be a number, list, boolean mask or a slice.
features
Features to load. By default loads only velocity and pressure but you can also
access the LES specific k and nut variables.
Returns
-------
t: np.ndarray of shape T
Time steps of the loaded data frames
data_3d: np.ndarray of shape T x W x H x D x F
3D data with all features concatenated in the order that they are requested, i.e.
in the default case the first 3 features will be the velocity vector and the fourth
will be the pressure
inside_mask: np.ndarray of shape W x H x D
Boolean mask that marks the inside cells of the domain, i.e. cells that are not part
of walls, inlets or outlets
boundary_masks: dict of str to nd.ndarray of shape W x H x D
Masks that mark cells belonging to each type of boundary
boundary_values: dict[str, dict[str, np.ndarray]]
Prescribed values for variables and boundaries with Dirichlet boundary conditions
"""
with h5 . File ( path , mode = "r" ) as f :
t = np . array ( f [ "data/times" ])
cell_data = np . concatenate ([ np . atleast_3d ( f [ "data" ][ name ][ idx ]) for name in features ], axis = - 1 )
padded_cell_counts = np . array ( f [ "grid/cell_counts" ])
cell_idx = np . array ( f [ "grid/cell_idx" ])
n_steps , n_features = cell_data . shape [ 0 ], cell_data . shape [ - 1 ]
data_3d = np . zeros (( n_steps , * padded_cell_counts , n_features ))
data_3d . reshape (( n_steps , - 1 , n_features ))[:, cell_idx ] = cell_data
inside_mask = np . zeros ( padded_cell_counts , dtype = bool )
inside_mask . reshape ( - 1 )[ cell_idx ] = 1
boundary_masks = { name : np . zeros ( padded_cell_counts , dtype = bool ) for name in f [ "grid/boundaries" ]. keys ()}
for name , mask in boundary_masks . items ():
mask . reshape ( - 1 )[ np . array ( f [ "grid/boundaries" ][ name ])] = 1
boundary_values = {
ft : {
name : np . atleast_1d ( desc [ "value" ])
for name , desc in f [ "boundary-conditions" ][ ft ]. items ()
if desc . attrs [ "type" ] == "fixed-value"
}
for ft in features
}
return t , data_3d , inside_mask , boundary_masks , boundary_values你可以像
from matplotlib . pyplot import matshow
path = "data/shapes/data/2x2-large/data.h5"
t , data_3d , inside_mask , boundary_masks , boundary_values = load_data ( path , [ 50 , 300 ])
matshow ( np . linalg . norm ( data_3d [ - 1 , :, :, 20 , : 3 ], axis = - 1 ). T )
data.h5文件包含的信息比此摘要負載更多。要探索其他可用的東西,請在我們的數據加載程序中戳一下。
要為新的OpenFOAM模擬生成數據,請首先確保您已經安裝了額外的依賴項並just可用:
pip install -e " .[data] "如果您不想just使用,也可以閱讀justfile並自己運行命令。
首先創建一個安裝了OpenFOAM的Docker容器:
just of-docker現在生成一堆新案例。例如,以下設置我們數據集中的所有OpenFOAM案例(仿真):
./scripts/generate-shapes.py data/shapes當然,您可以調整腳本以創建其他形狀或全新的數據集。
現在,您可以在本地使用OpenFOAM解決案例(運行模擬)
just of-solve path/to/case或將其中一堆提交您自己的漿液群:
./scripts/solve-slurm.py data/shapes/data/ * /case之後,將後處理(例如HDF5轉換)應用於每個模擬,例如
just postprocess data/shapes/data/2x2最後,計算特徵歸一化的訓練集統計數據:
./scripts/dataset-stats.py data/shapes要開始培訓,請與您的設置聯繫train.py ,
./train.py data.batch_size=128培訓腳本使用Hydra進行配置,因此請查看config目錄中的文件,以了解所有可用的設置。
要重新運行紙的實驗,請執行
./train.py -cn shapes_experiment -m它開始使用config/shapes_experiment.yaml中的設置進行培訓。如果您沒有可用的Slurm群集,請刪除與launcher相關的設置。
如果您以這項工作為基礎,請如下引用我們的論文。
@inproceedings{lienen2024zero,
title = {From {{Zero}} to {{Turbulence}}: {{Generative Modeling}} for {{3D Flow Simulation}}},
author = {Lienen, Marten and L{"u}dke, David and {Hansen-Palmus}, Jan and G{"u}nnemann, Stephan},
booktitle = {International {{Conference}} on {{Learning Representations}}},
year = {2024},
}