9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OpenFOAM: 導入編 WSLへのOpenFOAM 6, OpenFOAM-dev, OpenFOAM-v1812のインストール

Last updated at Posted at 2019-01-17

Windows 10上のWSL(Windows Subsytem for Linux)へOpenFOAMのインストール方法をまとめます。
linuxの知識を多少有している人を前提としています。3月に予定しているOpenCAE初歩情報交換会@北東北のための準備資料になります。

OpenFOAM環境の構築方法

大きく分けると4通りくらい考えられます。OpenFOAMで本格的に計算したい人は1~3を、お手軽に練習したい人は4がお勧めです。ただし、WSLはI/O回りが遅いようで、本格的な計算をするのであれば少しでもI/O速度を上げるために、M2 SSDなどの高速な書き込みをできるハードウェア上が望ましいのかなと思います。

  1. 物理的にLinuxマシンを用意してインストールする
  2. dockerコンテナを利用する(mac, win, linux)
  3. VirtualBox、VMwareなどの仮想環境ソフトウェアを利用する(mac, win)
  4. Windows10 64bitのWSL上のlinuxにインストールする(windows 10 64bit)

WSLの有効化およびWSL上へのLinuxのインストールと設定

Windows10(64bit限定)ではバージョン1709(ビルド16299)以降で正式なOS機能の一つとしてWSLが導入されました。WSLを有効にした後に、Windowsアプリのストアで「Ubuntu」「openSUSE Leap」「SUSE Linux Enterprise Server」などの各Linuxディストリビューションがインストール可能になっています。

最新のビルドに更新(バージョン1709(ビルド16299)以降)した上で、以下の手続きを行いWSLを有効化します。

  1. スタートボタンを右クリックして、「アプリと機能」をクリック
  2. 右上にある関連機能の「プログラムと機能」をクリック
  3. 「Windowsの機能の有効化または無効化」をクリック (Cortanaで入力しても出てきます)
  4. 「Windows Subsystem for Linux」に☑をいれます。
    image.png
    5. 再起動します。

次に、Windowsストアから、Linuxディストリビューションを選択し、インストールします。OpenFOAMが公式に対応しているUbuntu 18.04LTSを導入(入手)します。同じようにUbuntuがありますが、中身は同じのようです。Ubuntu 16.04LTSがありますが、新規に導入する場合はより新しい18.04LTSを選ぶべきかと思います。

image.png

インストール作業が終わったら、スタートに追加されるUbuntuアイコンをクリックします。
初回にインストール作業が行われ、完了すると、内部で使用するユーザー名とパスワードの設定を求められますので、入力してください。なお、パスワードは入力しても表示されませんので、ご注意ください。

Foundation版OpenFOAM 6およびOpenFOAM-devのインストール

レポジトリを追加してdebパッケージをインストールします。必要なパッケージやParaviewもインストールされますので、ほんとに楽です。

(OpenFOAM 6)
sudo sh -c "wget -O - http://dl.openfoam.org/gpg.key | apt-key add -"
sudo add-apt-repository http://dl.openfoam.org/ubuntu
sudo apt update
sudo apt -y install openfoam6

(OpenFOAM-dev)
sudo add-apt-repository "http://dl.openfoam.org/ubuntu dev"
sudo sh -c "wget -O - http://dl.openfoam.org/gpg.key | apt-key add -"
sudo add-apt-repository http://dl.openfoam.org/ubuntu
sudo apt update
sudo apt -y install openfoam-dev

なお、定期的にパッケージが更新されますので(2週に1度程度?)、
sudo apt-get update
sudo apt-get upgrade
を実行してください。

※ OpenFOAM Foundation版の各パッケージは、/opt以下に導入されます。一般的に行われるソースインストールの場合の~/OpenFOAM以下と異なっていますので、ご注意下さい。

$ ls -la /opt
drwxr-xr-x 1 root root 512 Jan  7 17:32 .
drwxr-xr-x 1 root root 512 Jun  1  2018 ..
drwxr-xr-x 1 root root 512 Jan 16 13:49 openfoam-dev
drwxr-xr-x 1 root root 512 Jan 16 14:12 openfoam6
drwxr-xr-x 1 root root 512 Jan 16 13:25 paraviewopenfoam56

ESI版OpenFOAM v1812のビルド・インストール

~/OpenFOAM/{OpenFOAM-v1812/, ThirdParty-v1812/}にインストールされます(します)。
https://www.openfoam.com/download/install-source.php を参考に以下のように実施します。
ソースからのコンパイルが必要となりますが、かなり時間を要しますのでご注意ください。

cd ~
mkdir OpenFOAM
cd OpenFOAM

wget https://sourceforge.net/projects/openfoamplus/files/v1812/OpenFOAM-v1812.tgz
wget https://sourceforge.net/projects/openfoamplus/files/v1812/ThirdParty-v1812.tgz
tar -xzf OpenFOAM-v1812.tgz 
tar -xzf ThirdParty-v1812.tgz 

source ~/OpenFOAM/OpenFOAM-v1812/etc/bashrc
初回は、以下のようなメッセージが出ますがビルドが終われば大丈夫です。
No completion added for /home/user/OpenFOAM/OpenFOAM-v1812/platforms/linux64GccDPInt32Opt/bin
... incorrect platform, or not yet compiled?

(ubuntu側の必要パッケージのinstall)
sudo apt-get install build-essential flex bison cmake zlib1g-dev libboost-system-dev libboost-thread-dev libopenmpi-dev openmpi-bin gnuplot libreadline-dev libncurses-dev libxt-dev 
sudo apt install qt5-default libqt5x11extras5-dev libqt5help5 qtdeclarative5-dev qttools5-dev libqtwebkit-dev freeglut3-dev libqt5opengl5-dev texinfo 
sudo apt-get install libscotch-dev libcgal-dev 

(paraview 5.6.0のビルド)
cd $WM_THIRD_PARTY_DIR 
./makeParaView 

(OpenFOAM v1812のビルド)
foamSystemCheck 
foam
./Allwmake -j 2 (-j 2は2コアで並列コンパイルするという意味です。CPUコアがある場合は-j 4などとしてもOKです。)

環境変数の設定および.bashrcへのaliasコマンドの登録

OpenFOAMを実行するには、立ち上げた端末で環境変数を設定する必要があります。一度設定すればその端末を使う限り、毎回実行はしなくてもOKです。

(OF 6)
source /opt/openfoam6/etc/bashrc
(OF-dev)
source /opt/openfoam-dev/etc/bashrc
(OF v1812)
source ~/OpenFOAM/OpenFOAM-v1812/etc/bashrc

いちいちsourceコマンドが面倒だという人は、以下のmobaXtermを導入後に、mobaXtermを起動し、
適当なテキストエディタ(geditなど: sudo apt install geditでインストールできます)でユーザー用bash設定ファイルである~/.bashrcを開き、以下の行を1番最後に追記してください。

Ubuntuを再起動、あるいはsource ~/.bashrcとbash設定ファイルを再読み込みしてあげると、
それぞれのaliasコマンド(of6, ofd, ofv)を打つことでOpenFOAMの各PATHにある環境変数が設定されるようになります。
(echoコマンドを使って.bashrcに追記することも可能ですが、初心者がやると多重追記になったりするので、こここではあえて書いていません)

alias of6="source /opt/openfoam6/etc/bashrc"
alias ofd="source /opt/openfoam-dev/etc/bashrc"
alias ofv="source ~/OpenFOAM/OpenFOAM-v1812/etc/bashrc"

例えばOpenFOAM6を使用する場合、端末上で動作確認をするために以下のようなコマンドを打ち込んでみます。

$ of6 (OpenFOAM6の環境変数設定の設定、各端末ごとに1回実行すればOK)
$ simpleFoam -help
Usage: simpleFoam [OPTIONS]
options:
  -case <dir>       specify alternate case directory, default is the cwd
  -fileHandler <handler>
                    override the fileHandler
  -hostRoots <(((host1 dir1) .. (hostN dirN))>
                    slave root directories (per host) for distributed running
  -listFunctionObjects
                    List functionObjects
  -listFvOptions    List fvOptions
  -listRegisteredSwitches
                    List switches registered for run-time modification
  -listScalarBCs    List scalar field boundary conditions (fvPatchField<scalar>)
  -listSwitches     List switches declared in libraries but not set in
                    etc/controlDict
  -listTurbulenceModels
                    List turbulenceModels
  -listUnsetSwitches
                    List switches declared in libraries but not set in
                    etc/controlDict
  -listVectorBCs    List vector field boundary conditions (fvPatchField<vector>)
  -noFunctionObjects
                    do not execute functionObjects
  -parallel         run in parallel
  -postProcess      Execute functionObjects only
  -roots <(dir1 .. dirN)>
                    slave root directories for distributed running
  -srcDoc           display source code in browser
  -doc              display application documentation in browser
  -help             print the usage

Using: OpenFOAM-6 (see www.OpenFOAM.org) <-- OpenFOAMのバージョンが表示されます。
Build: 6-6257b17a4cf8

WindowsへのmobaXtermのインストール

mobaXtermは、terminalソフトですが、OpenGL対応のX-serverで、SSH clientなどの機能も包含する便利な端末ソフトです。WSL上のUbuntuでParaviewなどを起動する場合は、mobaXterm上からログインすると便利です。

  1. FreeのHome Ed.をダウンロード・インストールします。
    https://mobaxterm.mobatek.net/download-home-edition.html

2.mobaXtermを起動します。一番左のSessionアイコンをクリックし、出てきたSession settingsのなかから「WSL」を選びます。「Linux distribution」から「Ubuntu」を選び、OKボタンを押します(初回のみ)。
image.png

3.左側のSessionsメニューに登録されますので、ダブルクリックすると、端末が起動します。
コマンドラインからpraviewなどを起動して見て下さい。
image.png

9
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?