システムコール

2013年4月28日

はじめに

計算中にあるタイミングでシェルコマンドを実行させるシステムコールという仕組みがある。外部プログラムによって計算中に処理を行わせることができる。

使用バージョン

OpenFOAM 2.2.0

準備

~/.OpenFOAM/$WM_PROJECT_VERSION/controlDict を編集してつぎのようにする。

allowSystemOperations 1

ファイルがなければ用意する。

$ mkdir ~/.OpenFOAM/$WM_PROJECT_VERSION
$ cp $WM_PROJECT_DIR/etc/controlDict ~/.OpenFOAM/$WM_PROJECT_VERSION

テスト用に icoFoam の cavity ケースをコピーを用意。

$ cp -r $FOAM_TUTORIALS/incompressible/icoFoam/cavity .
$ cd cavity
$ blockMesh

システムコールの設定

system/controlDict につぎのように設定する。

functions
{
    sysCall
    {
        type systemCall;
        functionObjectLibs ( "libsystemCall.so" );
        executeCalls ( "echo sysCall: execute" );
        endCalls ( "echo sysCall: end" );
        writeCalls ( "echo sysCall: write" );
        outputControl outputTime;
        outputInterval 1;
    }
}

executeCalls, endCalls, writeCalls で指定したシェルのコマンドがそれぞれのタイミングで実行される。

上の設定の場合、icoFoam の出力は以下のようになる。

$ icoFoam

...

Time = 0.005

Courant Number mean: 0 max: 0
DILUPBiCG:  Solving for Ux, Initial residual = 1, Final residual = 2.96338e-06, No Iterations 8
DILUPBiCG:  Solving for Uy, Initial residual = 0, Final residual = 0, No Iterations 0
DICPCG:  Solving for p, Initial residual = 1, Final residual = 7.55402e-07, No Iterations 35
time step continuity errors : sum local = 5.03809e-09, global = 4.40722e-19, cumulative = 4.40722e-19
DICPCG:  Solving for p, Initial residual = 0.523591, Final residual = 9.72352e-07, No Iterations 34
time step continuity errors : sum local = 1.07766e-08, global = 2.93897e-19, cumulative = 7.34619e-19
ExecutionTime = 0.01 s  ClockTime = 0 s

sysCall: execute
Time = 0.01

Courant Number mean: 0.0976805 max: 0.585722
DILUPBiCG:  Solving for Ux, Initial residual = 0.148584, Final residual = 7.15711e-06, No Iterations 6
DILUPBiCG:  Solving for Uy, Initial residual = 0.256618, Final residual = 8.94127e-06, No Iterations 6
DICPCG:  Solving for p, Initial residual = 0.379232, Final residual = 3.38648e-07, No Iterations 34
time step continuity errors : sum local = 3.15698e-09, global = 1.94222e-19, cumulative = 9.28841e-19
DICPCG:  Solving for p, Initial residual = 0.286937, Final residual = 5.99637e-07, No Iterations 33
time step continuity errors : sum local = 6.08774e-09, global = 5.80474e-19, cumulative = 1.50932e-18
ExecutionTime = 0.02 s  ClockTime = 0 s

sysCall: execute

..

Time = 0.1

Courant Number mean: 0.22118 max: 0.851703
DILUPBiCG:  Solving for Ux, Initial residual = 0.000275818, Final residual = 5.94812e-06, No Iterations 2
DILUPBiCG:  Solving for Uy, Initial residual = 0.000604438, Final residual = 2.79374e-06, No Iterations 3
DICPCG:  Solving for p, Initial residual = 0.000612763, Final residual = 9.20763e-07, No Iterations 22
time step continuity errors : sum local = 7.56001e-09, global = -1.22431e-18, cumulative = 4.48456e-19
DICPCG:  Solving for p, Initial residual = 0.000470309, Final residual = 6.99743e-07, No Iterations 22
time step continuity errors : sum local = 5.74556e-09, global = -3.64538e-19, cumulative = 8.39175e-20
ExecutionTime = 0.11 s  ClockTime = 1 s

sysCall: execute
sysCall: write

...

Time = 0.2

Courant Number mean: 0.222142 max: 0.852128
DILUPBiCG:  Solving for Ux, Initial residual = 6.01714e-06, Final residual = 6.01714e-06, No Iterations 0
DILUPBiCG:  Solving for Uy, Initial residual = 9.4338e-06, Final residual = 9.4338e-06, No Iterations 0
DICPCG:  Solving for p, Initial residual = 1.82152e-06, Final residual = 6.38065e-07, No Iterations 4
time step continuity errors : sum local = 6.06219e-09, global = 1.95132e-19, cumulative = 5.53802e-18
DICPCG:  Solving for p, Initial residual = 9.63857e-07, Final residual = 9.63857e-07, No Iterations 0
time step continuity errors : sum local = 8.81931e-09, global = -4.97136e-19, cumulative = 5.04088e-18
ExecutionTime = 0.19 s  ClockTime = 1 s

sysCall: execute
sysCall: write

...

Time = 0.5

Courant Number mean: 0.222158 max: 0.852134
DILUPBiCG:  Solving for Ux, Initial residual = 1.89493e-07, Final residual = 1.89493e-07, No Iterations 0
DILUPBiCG:  Solving for Uy, Initial residual = 4.14522e-07, Final residual = 4.14522e-07, No Iterations 0
DICPCG:  Solving for p, Initial residual = 1.06665e-06, Final residual = 3.39604e-07, No Iterations 1
time step continuity errors : sum local = 5.25344e-09, global = -9.50761e-19, cumulative = 8.05678e-18
DICPCG:  Solving for p, Initial residual = 5.36118e-07, Final residual = 5.36118e-07, No Iterations 0
time step continuity errors : sum local = 6.86432e-09, global = 4.62063e-19, cumulative = 8.51884e-18
ExecutionTime = 0.38 s  ClockTime = 1 s

sysCall: end
sysCall: write
End
  • executeCalls : 最後以外の各ステップの計算後に実行
  • endCalls : 最後のステップの計算後に実行
  • writeCalls : 書き出しステップの最後に実行