# OpenFOAM Download 目前實驗室使用的版本有 `OpenFOAM_v10` 與 `OpenFOAM_v2206`,建議是先安裝 `OpenFOAM_v10` 熟悉環境 ## 基本流程 主要安裝方法會是使用 `wsl2` 建立 `Linux` 環境再安裝 `OpenFoam`,下面會在 `wsl2` 以安裝完成的情況下繼續安裝 `OpenFOAM` ### 確認 WSL2 環境正常 打開終端輸入,確保正在使用 `wsl2` 且 `distro` 是 `Ubuntu` `wsl --list --verbose` ### 更新套件與安裝基本工具 ```ba! sudo apt update && sudo apt upgrade -y sudo apt install -y build-essential cmake git wget curl gnupg lsb-release software-properties-common ``` :::warning 這裡通常會遇到錯誤訊息,這表示這邊加入了錯誤的來源,且該網址不存在或是不被支援,這個問題會導致後續的 `sudo apt update` 出現問題 ``` . . Ign:3 https://dl.openfoam.com/repos/deb sid InRelease Err:7 https://dl.openfoam.com/repos/deb sid Release 404 Not Found [IP: 172.67.128.143 443] . . E: The repository 'http://dl.openfoam.com/repos/deb sid Release' does not have a Release file. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. . . ``` ::: :::success 這邊的解決方法是編輯 `source.list` 內容 1. 使用 `nano` 編輯 `repository` 設定 `sudo nano /etc/apt/sources.list.d/openfoam.list` 將檔案內容中的 `deb https://dl.openfoam.com/repos/deb sid main` 替換為 `deb https://dl.openfoam.com/repos/deb jammy main` 完成後 `ctrl+o` + `enter` 儲存、`ctrl+x` 離開 `nano` 編輯器 2. 確認並刪除錯誤檔案 先列出內容 `ls /etc/apt/sources.list.d/` 通常會列出類似下面的內容 ``` openfoam.list openfoam-sid.list ``` 刪除帶有 `sid` 的內容 `sudo rm /etc/apt/sources.list.d/openfoam-sid.list` ::: ### 更新套件清單並安裝 先更新套件來源清單 `sudo apt update` 基本上成功的話不會有錯誤訊息或是提示訊息輸出,更新完成後安裝 `OpenFOAM` `sudo apt install -y openfoam2206` :::success `sudo apt update` 成功的輸出結果 ```bash! Hit:1 http://security.ubuntu.com/ubuntu jammy-security InRelease Hit:3 http://archive.ubuntu.com/ubuntu jammy InRelease Hit:4 http://archive.ubuntu.com/ubuntu jammy-updates InRelease Hit:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease Hit:6 https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64 InRelease Hit:2 https://sourceforge.net/projects/openfoam/files/repos/deb jammy InRelease Reading package lists... Done Building dependency tree... Done Reading state information... Done All packages are up to date. ``` ::: ### 設定載入設定 這邊需要確認 `bashrc` 文件中的設置,基本上會在該文件的最後一行中加上 `source /openfoam_path/etc/bashrc`,並在完成後更新該文件 `source ~/.bashrc` ```ba! echo "source /opt/openfoam2206/etc/bashrc" >> ~/.bashrc source ~/.bashrc ``` 這邊完成後基本上 `OpenFOAM` 就已經安裝成功了 :::info 這邊的 `openfoam_path` 會是 `OpenFOAM` 的安裝位置,可能會是 `/opt/openfoam10/etc/bashrc` 或是 `usr/lib/openfoam/openfoam_2206/etc/bashrc` 根據自己的安裝位置來調整 ::: ## 測試是否可用 可以輸入 `blockMesh -help` 如果安裝成功會輸出關於 `blockMesh` 的相關介紹與安裝的 `OpenFOAM` 版本