LoginSignup
1
2

More than 5 years have passed since last update.

[OpenFOAM]WSL UbuntuへのOpenFOAM v6のインストール

Last updated at Posted at 2019-03-27

OpenFOAM v6をWSLへインストール

OpenFOAMは主にESI社とThe OpenFOAM Foundationによって開発されているバージョンに分けられる。
前者をESI版、後者をFoundation版と区別して呼ばれる事が多い。
詳しい違いについては分からないがソルバ、機能や実装方法が異なるらしい。
今回はFoundation版のv6をWSL機能を使ってWindows10にインストールする。

確認環境

OS : Windows10 Home
WSL : Ubuntu "18.04.1 LTS (Bionic Beaver)"

インストール

インターネットに接続しておいてください

公式サイトの確認

以下のサイトから自分のOSを選択する
https://openfoam.org/download/

Ubuntuは以下
https://openfoam.org/download/6-ubuntu/

対象のUbuntuのバージョンは以下のようです
14.04 LTS, codename trusty
16.04 LTS, codename xenial
18.04 LTS, codename bionic
18.10, codename cosmic (from 30th November 2018)

Ubuntuの起動

事前にWSLを使ってUbuntuをインストールします
以下の記事が参考になります
https://qiita.com/UedaShigenori/items/b1d1dafa920a99873f26

WindowsのプログラムからUbuntuを起動します

リポジトリの追加

以下をターミナルで実行
sudo sh -c "wget -O - http://dl.openfoam.org/gpg.key | apt-key add -"

OKが出ることを確認

[sudo] password for (username):
--2019-03-27 11:17:21--  http://dl.openfoam.org/gpg.key
Resolving dl.openfoam.org (dl.openfoam.org)... 52.208.208.42
Connecting to dl.openfoam.org (dl.openfoam.org)|52.208.208.42|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1710 (1.7K) [application/pgp-keys]
Saving to: ‘STDOUT’

-                             100%[=================================================>]   1.67K  --.-KB/s    in 0s

2019-03-27 11:17:26 (61.8 MB/s) - written to stdout [1710/1710]

OK

sudo add-apt-repository http://dl.openfoam.org/ubuntu
以下のメッセージを確認

~中略~
Reading package lists... Done

アップデート

sudo apt-get update
以下のメッセージを確認

~中略~
Reading package lists... Done

インストール実行

以下のコマンドでParaView5.4.0もインストールされます
sudo apt-get -y install openfoam6

「OpenFOAMを使うときは自分のbashrcにコマンドを追加してね」という優しさメッセージが表示されます
大体15分くらいかかりました

~中略~
** To use OpenFOAM please add
**
**    . /opt/openfoam6/etc/bashrc
**
** To your ~/.bashrc
~中略~

User Configuration

OpenFOAM v6を使用するためにはパスを通す必要があります

公式サイトではgeditでbashrcを編集することが指示されていますがWSLにはgeditが入っていません。
最初から入っているviで編集します。

vi ~/.bashrc

一番下に移動して、iキーを押すと挿入モードになります。

以下を記入
source /opt/openfoam6/etc/bashrc

昔は挿入モードで矢印キーを動かすと変な挙動になりましたが、仕様が変わったのか普通にカーソルが移動します。

ESCキーで挿入モードから離脱できるので以下を入力して上書き保存して終了
:wq

慣れないと使いづらいですが、Linuxの標準エディターなのでgeditのようにインストールする必要がないのが大きなメリットです。

インストールの確認

いったんUbuntuを閉じて、再度立ち上げてください。
以下を実行してください

simpleFoam -help

以下が表示され、OpenFOAM-6が使われていることを確認してください

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)
Build: 6-e29811f5dff8

計算の実行確認

計算実行の確認にはステップ流れ(pitzDaily)の計算を使用します。

適当なフォルダーを作成し、以下をコピーします。
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .

cd pitzDaily

メッシュ作成
blockMesh

以下確認

~中略~
----------------
Patches
----------------
  patch 0 (start: 24170 size: 30) name: inlet
  patch 1 (start: 24200 size: 57) name: outlet
  patch 2 (start: 24257 size: 223) name: upperWall
  patch 3 (start: 24480 size: 250) name: lowerWall
  patch 4 (start: 24730 size: 24450) name: frontAndBack

End

計算実行
simpleFoam

以下確認

SIMPLE solution converged in 288 iterations

streamLine streamlines write:
    seeded 10 particles
    Tracks:20
    Total samples:12040
    Writing data to "/(実行ディレクトリ)/pitzDaily/postProcessing/sets/streamlines/288"
End

結果の可視化は「Xming」や「XLunch」などを使用します。
上記のどちらかなどを起動し以下を実行
ParaFoam

速度場が発生していることを確認してください。

image.png

1
2
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
1
2