LoginSignup
2
2

More than 5 years have passed since last update.

OpenFOAMのDebugSwitches

Last updated at Posted at 2017-12-17

OpenFOAMのDebugSwitches

オープンCAE勉強会@関東(流体など)の忘年会2017年で発表したLT用のネタです.
OpenFOAM-v1612+用です.

OpenFOAMのDebugSwitchesとは

  • DebugSwitchesはdebug用フラグを設定する辞書.
  • 通常system/controlDict 内で設定する.
  • $FOAM_ETC/controlDict でシステムデフォルト値が定義されているので,system/controlDict にコピーして変更するのが楽.
$FOAM_ETC/controlDict
DebugSwitches
{
    Analytical          0;
    APIdiffCoefFunc     0;
    Ar                  0;
    BirdCarreau         0;
    C10H22              0;
:
    zoneToPoint         0;
}

DebugSwitchesの値

  • 0:デバック表示なし
  • 1:デバック表示あり
  • 2以上:さらに詳細なデバッグ表示
    • SolverPerformance (デフォルト1)
    • ccm
    • faceAreaWeightAMI
    • fileName
    • layerAdditionRemoval
    • lduMatrix (デフォルト1)
    • meshToMesh
    • turbulentDFSEMInlet
    • word
    • 等々
  • 1,2,4のビットの有無で細かくデバッグ表示を制御
    • cellCuts
    • edgeSurface

DebugSwitchesの挙動

ソースをキーワードdebugで検索します.

src
emacs
M-x grep
grep -rnH -e debug

emacs派以外の方は慣れている方法で検索を行ってください.
以下はdebug出力を行なっているソースの例です.

$FOAM_SRC/fvMotionSolver/fvMotionSolvers/fvMotionSolverCore/fvMotionSolverCoreTemplates.C
        if (debug)
        {
            Pout<< "Patch:" << fvMesh_.boundary()[patchi].patch().name()
                << " pointType:" << pmUbf.types()[patchi]
                << " cellType:" << cmUbf[patchi] << endl;
        }

あとは,デバッグ出力を行いたい項目に1以上の値を入れてプログラムを走らせ,ログの違いをdiffなどで調べます.

DebugSwitchesの例

SolverPerformance

  • デフォルトの1では,線形ソルバーの初期残差・最終残差・反復回数を出力.
  • 2以上で各反復での残差も表示する.線形ソルバー内のプロット用に有用.
SolverPerformance=1
DILUPBiCGStab:  Solving for h, Initial residual = 1, Final residual = 0.0670926, No Iterations 1
SolverPerformance=2
DILUPBiCGStab:  Iteration 0 residual = 1
DILUPBiCGStab:  Iteration 0 residual = 0.0670926
DILUPBiCGStab:  Solving for h, Initial residual = 1, Final residual = 0.0670926, No Iterations 1

GAMGAgglomeration

  • GAMGソルバでのAgglomeration(粗視化)のログを出力.
system/controlDict
DebugSwitches
{
  GAMGAgglomeration          2;
}
GAMGAgglomeration=2
GAMGAgglomeration : agglomerated level 0 from nCells:1460 nFaces:3858 to nCells:730 nFaces:1978
GAMGAgglomeration : agglomerated level 1 from nCells:730 nFaces:1978 to nCells:364 nFaces:1028
GAMGAgglomeration : agglomerated level 2 from nCells:364 nFaces:1028 to nCells:182 nFaces:511
GAMGAgglomeration : agglomerated level 3 from nCells:182 nFaces:511 to nCells:90 nFaces:283
GAMGAgglomeration : agglomerated level 4 from nCells:90 nFaces:283 to nCells:44 nFaces:151
GAMGAgglomeration : agglomerated level 5 from nCells:44 nFaces:151 to nCells:21 nFaces:65
GAMGAgglomeration : agglomerated level 6 from nCells:21 nFaces:65 to nCells:10 nFaces:25
GAMG:  Solving for p_rgh, Initial residual = 0.9816739, Final residual = 0.003765396, No Iterations 2

turbulentTemperatureRadCoupledMixed

  • 通過熱流量やパッチ面での最小・最大・平均温度を表示.
  • 熱収支の確認,プロットに大変有用.
  • なぜか$FOAM_ETC/controlDictに記載されていない.
system/controlDict
DebugSwitches
{
  compressible::turbulentTemperatureRadCoupledMixed 1;
}
turbulentTemperatureRadCoupledMixed=1
Solving for solid region heater

heater:heater_to_topAir:T <- topAir:topAir_to_heater:T : heat transfer rate:2.572062e-06 walltemperature  min:300 max:300 avg:300

heater:heater_to_bottomAir:T <- bottomAir:bottomAir_to_heater:T : heat transfer rate:0.0001776574 walltemperature  min:300 max:300 avg:300

他にも以下の熱流系の境界条件にdebugSwitchesがあり,各種熱量やパッチ温度の統計値出力が可能です.

  • externalWallHeatFluxTemperature
  • fixedIncidentRadiation
  • lumpedMassWallTemperature
  • thermalBaffle1D
  • turbulentTemperatureCoupledBaffleMixed
  • turbulentTemperatureRadCoupledMixed

dimensionSet

  • dimensionの一致検査を行う(デフォルト).
  • 0にすると僅かに高速化するかも?

DebugSwitches全部張り

張らしてもうらぜっ・・・!
限界を超えてっ・・・!

DebugSwitchesを全部オンにして,tutorials/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeaterRadiation の Allrun-parallel (4並列)を実行してみる.

system/controlDict
DebugSwitches
{
    compressible::turbulentTemperatureRadCoupledMixed 7;
    Analytical          7;
    APIdiffCoefFunc     7;
    Ar                  7;
    BirdCarreau         7;
:
    zoneToPoint         7;
}
  • 1,2,4のbit演算を行うタイプもあるので,1+2+4で全て7を張る

ざわ・・・!

run
cp -a $FOAM_TUTORIALS/heatTransfer/chtMultiRegionSimpleFoam/multiRegionHeaterRadiation .
cd multiRegionHeaterRadiation
emacs system/controlDict
./Allrun-parallel >& log.Allrun-parallel &

ざわ・・・!
ざわ・・・!

tail -f log.chtMultiRegionSimpleFoam

ログっ・・・!
圧倒的ログっ・・・!

これはOpenFOAMerにとって・・・

僥倖っ・・・!
なんという僥倖っ・・・!・・・

しかし,実行時間は15 s → 355 sと23倍!
ログサイズは3.9MB→2.3GBと60倍!

以下,時事ネタにつき自粛.

まとめ

OpenFOAMのDebugSwitchesについて簡単に紹介しました.
なんでもやりすぎは駄目よ!

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