owned this note
owned this note
Published
Linked with GitHub
HPC app - OpenFOAM
==
### 1.Openfoam hardware
### 2.Openfoam real case
### 3.Openfoam GPU-accelerated issue
<br>
<br>
<br>
<br>
<br>
## Openfoam hardware
#### [Hardware for CFD, 2021, May <br> Lubos Pirkl Enabler, Storyteller at CFDSUPPORT, Indiana Jones in the Jungle of CAE](https://www.linkedin.com/pulse/hardware-cfd-lubos-pirkl/)
* 每一個simulation所需要的size,可以看做是core*hours。
A simulation need 1 core 100 hours = 2 cores 50 hours.
* 在CFD中影響simulation size關鍵因素為:
1.**Mesh size** 2.Time method 3.Physical model complexity
* Hardware 元件最重要的是:**CPU 處理器**。
**主機板**檢查相容性即可,**記憶體**有一個黃金法則:「每一百萬網格需要2GB RAM」。
**螢幕**適當大小即可,**顯示卡**可以讓放大、縮小、旋轉、渲染的過程更加滑順。
* 作者以OpenFOAM motorBike為例子的實驗數據

若是碩博士生需要5 core * hours來完成論文實驗;
若是設計師或工程師需要500 core * hours來完成工程;
若是專業CFD使用者需要超過500 core * hours並建立模擬集群。
<br>
<br>
#### [Hardware Recommendation for CFD <br> SimFlow ](https://sim-flow.com/hardware-recommendation-for-cfd/)
* 對於CFD simulation挑選**CPU**的幾個要點
1. **記憶體頻寬 Memory Bandwidth (memory channels)**, CFD不會進行複雜的計算,而是會面對大量的資料處理,記憶體頻寬和允許平行資料傳輸的記憶體通道直接相關。
2. **快取大小 CPU cache size**, 大的cache可以減少檢所資料的時間,加速CFD計算。
3. **核心數量 Number of cores**, 核心和記憶體通道要保持一致避免無法充分利用,通常建議的準則是每個記憶體通道2~4個CPU cores。超執行緒對CFD計算沒有好處。
4. **時脈速度 High clock speed**, 影響較小,通常CFD計算瓶頸在於 information flow : 訊息的傳遞、收集、檢索、儲存等等。
* 推薦的CPU處理器範例(長時間運算CFD計算推薦AMD EPYC系列)
> **AMD EPYC 4th Generation**
>
>
> 12 Memory Channels and up to 460 GB/s Memory Bandwidth
>
> In this generation, we recommend:
>
> AMD EPYC™ 9354 (32 cores and 256 MB L3 Cache) ~ 3500$
>
> AMD EPYC™ 9384X (32 cores and 768 MB L3 Cache) ~ 5000$
>
> **AMD EPYC 3rd Generation**
>
> 8 Memory Channels and up to 204 GB/s Memory Bandwidth
>
> In this generation, we recommend:
>
> AMD EPYC™ 7373X (16 cores) or AMD EPYC™ 7473X (24 cores) ~4000$
>
> AMD EPYC™ 74F3 ~3000$
>
> The AMD EPYC 3rd generation has a worse performance but is compatible with older and more affordable components, such as AM4 motherboards and DDR4 memory.
* RAM記憶體
**低於** 10M 網格的模擬計算32gb RAM就足夠。
**小於** 10M 網格的simulation = 32GB RAM
**等於** 10M 網格的simulation且在一台PC上執行多項分析 = 64GB RAM
**大於** 10M 網格的simulation = 每1M節點使用2GB RAM
不論RAM總量為何,建議每個記憶體通道配置一個RAM module
ex.4 記憶體通道 需要 64gb RAM
<br>
<br>
#### [Hardware for CFD simulations <br> CFDSUPPORT ](https://www.cfdsupport.com/hardware-for-cfd.html)
* Laptop, PC, Cluster - Server, Storage - Server
<br>
<br>
#### [AMD EPYC 7002 SERIES PROCESSORS AND OPENFOAM FOR COMPUTATIONAL FLUID DYNAMICS, 2020, Feb](https://www.amd.com/content/dam/amd/en/documents/epyc-business-docs/solution-briefs/AMD-EPYC-7002-OpenFOAM.pdf)
* OpenFOAM motorBike為例子,測試160,000網格和351,520網格


<br>
<br>
<br>
<br>
## Openfoam real case
<br>
| case | institution | abstract | cell | link |
| -------- | -------- | -------- | -------- | -------- |
| motorBike | CFDSUPPORT | 摩托車幾何形狀的外部空氣動力學。 | 1,280 | [link](https://www.cfdsupport.com/OpenFOAM-Training-by-CFD-Support/node133.html) |
| cavity | CFDSUPPORT | 在二維正方形腔體中模擬簡單流動,包括層流和湍流。 | 400 | [link](https://www.cfdsupport.com/OpenFOAM-Training-by-CFD-Support/node39.html) |
| Backward-Facing-Step | CFDSUPPORT | 測試湍流模型的準確性,通過模擬流體在台階處的分離和重新附著來評估模型。 | 400 | [link](https://www.cfdsupport.com/OpenFOAM-Training-by-CFD-Support/node39.html) |
| External Aerodynamics of a Car | CFDSUPPORT | 汽車外部空氣動力學,包括不同幾何形狀的車身流動和發動機艙內的熱交換效應。 | 13,500 | [link](https://www.cfdsupport.com/OpenFOAM-Training-by-CFD-Support/node256.html) |
| roomWithRadiator | CFDSUPPORT | 散熱器內的熱水通過傳導和輻射加熱房間,並通過自然對流傳播熱空氣。 | | [link](https://www.cfdsupport.com/OpenFOAM-Training-by-CFD-Support/node246.html) |
| Wind Turbine | CFDSUPPORT | 風力渦輪建構高級網格,評估其扭矩和功率 | | [link](https://www.cfdsupport.com/OpenFOAM-Training-by-CFD-Support/node276.html) |
| Verification and Validation of aerospike designs in supersonic flow (2023) | CFD FOSSEE | 利用 OpenFOAM 模擬高速飛行器上的減阻裝置,旨在通過降低空氣阻力來提高飛行效率,並確保設計的可靠性和準確性 | approximately 790k cells | [link](https://cfd.fossee.in/case-study-project/case-study-run/236) |
| 3D modelling of Porcupine River Training Works (2021) | CFD FOSSEE | 通過 OpenFOAM 模擬分析砥礪結構在減緩河流流速和防止河岸侵蝕方面的效果,並將模擬結果與實驗數據進行比較。 | approximately 560k cells | [link](https://cfd.fossee.in/case-study-project/case-study-run/195) |
| Wind analysis around tall buildings (2019) | CFD FOSSEE | 使用 OpenFOAM 研究高層建築在風力作用下的影響,以指導安全施工和提高建築耐久性。 | approximately 125k cells | [link](https://cfd.fossee.in/case-study-project/case-study-run/209) |
| Pollutant Dispersion Modelling using CFD: A walkthrough of solver development in OpenFOAM (2022) | CFD FOSSEE | 使用 OpenFOAM 對城市污染物擴散進行建模,通過開發湍流穩態求解器並與實驗對比來優化預測。 | 182,249 | [link](https://cfd.fossee.in/case-study-project/case-study-run/209) |
| Thermal Simulation of Electric Vehicle Battery (2021) | CFD FOSSEE | 通過熱模擬分析電動車鋰離子電池的溫度變化,並使用強制對流冷卻技術來驗證電池的實時性能。 | 15,300 | [link](https://cfd.fossee.in/case-study-project/case-study-run/168) |
| Multiphase simulation using OpenFOAM for calculating ship hull resistance (2022) | CFD FOSSEE | 使用 OpenFOAM 對船體在水中航行時的阻力進行多相模擬,並通過不同求解器和方案進行比較驗證。 | 570,000~2,000,000 (570k~2M) | [link](https://cfd.fossee.in/case-study-project/case-study-run/225) |
<br>
<br>
---
### motorBike case :
主要目標:觀察摩托車幾何形狀的外部空氣動力學結果

```
##Copy *motorBike* tutorial:##
cd $FOAM_RUN
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/motorBike ./ # solver = simpleFoam
cd motorBike
```
<br>
### step1.調整範例
**1.1 根據需求從初始化文件中調整物理參數。**
相關物理參數:
- 入口速度 Inlet velocity: U = 20 m/s
- 摩托車長度約 Motorbike length: L = 2 m
- 雷諾平均納維-斯托克斯 (RANS) 湍流建模 Reynolds Averaged Navier-Stokes (RANS) turbulence modeling
- 湍流參數 Turbulence parameters
- 不可壓縮流體流動 Incompressible fluid flow
- 穩態解 Steady-state solution
<br>
<br>
<br>
### step2.網格生成
**2.1 一般而言,針對湍流 RANS 流動的網格設計和選擇** https://www.cfdsupport.com/OpenFOAM-Training-by-CFD-Support/node136.html
<br>
<br>
**2.2 分析在流體與固體接觸壁面處的網格限制情況** https://www.cfdsupport.com/OpenFOAM-Training-by-CFD-Support/node137.html
<br>
<br>
**2.3 準備OBJ模型**
**motorBike.obj.gz** 是一個壓縮的 OBJ 文件,它包含了一個摩托車模型的三維表面幾何訊息。
*(OBJ 是一種標準的 3D 模型文件格式,可以被許多 3D 建模軟體和渲染引擎識別。)*
```
## resources/geometry/motorBike.obj.gz ##
gzip -d motorBike.obj.gz ⇒ motorBike.obj
```
解壓縮後的.obj檔案:
- 可以透過**3D建模軟體**(ex. **Blender**)或**可視化工具**(ex. **ParaView**)查看或編輯。
```
paraview - -data=motorBike.obj
```

- 可以做為流體流動模擬的幾何邊界進行計算。
<br>
<br>
**2.4 網格生成 Meshing**
透過編輯 *blockMeshDict* 檔案,設置適當的 域邊界 以及 背景網格。


透過指令”blockMesh”生成背景網格。
```
blockMesh
```
<br>
<br>
**2.5 執行 snappyHexMesh**
```
snappyHexMesh -overwrite #(overwrite可以保證覆蓋過去舊的網格)
```
使用上述blockMesh生成的背景網格,根據幾何模型細化網格,生成出更複雜的網格。

<br>
<br>
<br>
### step3.開始模擬計算
**3.1複製存放初始參數資料夾**
```
cp -r 0.orig/* 0
```
<br>
<br>
**3.2.1 run : 單核運行**
```
simpleFoam > log.simpleFoam &
```
<br>
<br>
**3.2.2 run : 平行運行**
> ##修改system/decomposeParDict的”numberOfSubdomains”數量##
numberOfSubdomains 1 ; ⇒ numberOfSubdomains 2
分割網格
```
decomposePar
```
開始平行運算
```
mpiexec -np 2 simpleFoam -parallel > log.simpleFoam &
```
使用*reconstructPar*重建網格並且使用paraview功能來查看
```
reconstructPar
paraFoam
```

<br>
<br>
### **面對任何openfoam case running大致流程:**
**挑選模擬案例 =>
設置初始條件 =>
準備幾何模型 =>
網格生成 (背景網格設置 + 細化網格生成) =>
單核或平行運行計算 =>
後處理分析。**
<br>
<br>
<br>
<br>
## Openfoam GPU-accelerated issue
<br>
官方openfoam並不支援GPU。
<br>
SimFlow團隊 開源套件 **[RapidCFD](https://github.com/SimFlowCFD/RapidCFD-dev)**
https://sim-flow.com/rapid-cfd-gpu/
https://github.com/SimFlowCFD/RapidCFD-dev
<br>
<br>
NTNU 使用 RapidCFD
https://www.hpc.ntnu.no/vilje/software/a-benchmark-test-for-openfoam-using-gpu-cards-flow-past-a-centrifugal-pump/
<br>
<br>
GPU Acceleration of CFD Simulations in OpenFOAM 2023 Sep
https://www.mdpi.com/2226-4310/10/9/792
<br>
<br>
GPU-accelerated OpenFOAM simulations using PETSc4FOAM 2020 Oct
https://www.esi-group.com/sites/default/files/resource/other/1806/8th_OpenFOAM_Conference_Cineca_Spisso_2_0.pdf
<br>
<br>
QA. GPU Parallelization in OpenFoam
https://www.cfd-online.com/Forums/openfoam-programming-development/214050-gpu-parallelization-openfoam.html