LoginSignup
4
4

More than 1 year has passed since last update.

【OpenFOAM】並列計算をする方法

Last updated at Posted at 2020-07-04

#はじめに
OpenFOAMで並列計算する方法を解説します.並列計算は複数のcpuに処理を並列して実行させる計算方法で,計算の高速化が期待できます.

作業ディレクトリをcaseDirとします.

#手順
計算前にdecomposeParというユーティリティを使って領域を並列数で分割しておく必要があります.decomposeparの設定は,caseDir/systemディレクトリ内にdecomposeParDictというファイルを用意して行います.以下記述例です.

decomposeParDict
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  7
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/
FoamFile
{
    version     2.0;
    format      ascii;
    class       dictionary;
    note        "mesh decomposition control dictionary";
    object      decomposeParDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

numberOfSubdomains  2;

method          scotch;
// method          hierarchical;
// method          simple;
// method          metis;
// method          manual;
// method          multiLevel;
// method          structured;  // does 2D decomposition of structured mesh


// ************************************************************************* //

numberOfSubdomainsが領域の分割数(=並列数)で,分割方法をmethodで指定します.scotchとしておけば他に何も設定しなくても分割してくれます.他にも分割方法は用意されてますが,使用の際はdecomposeParDict内に別途記述が必要です.

設定後,以下のコマンドを実行.

caseDir$ decomposePar

processor0,processor1,...といった感じで並列化後の領域の情報が格納されたディレクトリが生成されます.

これで領域分割完了.OpenFOAMではOpen MPIというMPIのライブラリを使って並列処理を行う仕様になっています.例えばsimpleFoamを2並列で計算させたい場合,次のようにコマンドを実行すると計算が開始します.

caseDir$ mpirun -np 2 simpleFoam -parallel > log &

計算結果はprocessso0,...に格納されていきます.可視化のためには結果の結合が必要で,次のようにコマンド実行します.

caseDir$ reconstructPar -latestTime     // -latestTime指定で最後の結果だけ結合

caseDirに結合結果が出力されます.

4
4
2

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
4
4