2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

コマンドラインからOpenFOAMテキストファイルを編集する方法

Posted at

コマンドラインからOpenFOAMテキストファイルを編集する方法

はじめに

OpenFOAMの設定ファイルの入力形式は「辞書」です。
具体的には、

	  Dict{
		  keyword value;
	  }

みたいな形です。
このように構造化済みであり、foamDictionaryコマンドで編集できます。
つまり、エディタを立ち上げずにコマンドラインまたはシェルスクリプトから値の変更ができます。
foamDictionaryコマンドの使い方と具体例を示します。

動作環境

  • WSL2 + Ubuntu 22.04
  • OpenFOAM 10

下記のコマンド実行に用いたサンプルモデルの場所

念のため、コマンド実行に用いたサンプルモデルの場所です。

  /opt/openfoam10/tutorials/multiphase/interFoam/RAS/weirOverflow

コマンドの説明

  • foamDictionary
    • 説明:辞書ファイルの中身の確認や変更を行う。

コマンド具体例

使用例:非定常流れ解析の最終時刻の変更

  • 個人的に一番便利だと思って使っている場面
  foamDictionary -entry endTime -set 300  system/controlDict

使用例:コマンドラインから設定ファイルを閲覧

  • 「-value」オプションでentryのvalueを表示
  foamDictionary -value 0/include/initialConditions
# 実行結果
inletFlowRate   75;

pressure        0;

turbulentKE     0.00414;

turbulentEpsilon 4.39e-05;
  • ちなみにcatコマンドで表示させた場合
    • foamDictionary -valueはentryのみ表示される。
/*--------------------------------*- C++ -*----------------------------------*\
  =========                 |
  \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
   \\    /   O peration     | Website:  https://openfoam.org
    \\  /    A nd           | Version:  10
     \\/     M anipulation  |
\*---------------------------------------------------------------------------*/

inletFlowRate        75;
pressure             0;
turbulentKE          4.14e-03;
turbulentEpsilon     4.39e-05;

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

辞書の一部分を表示させたい場合

  • 「entry」オプションを使う。
foamDictionary -entry boundaryField 0/U
# 実行結果のサンプル
boundaryField
{
    inlet
    {
        type            variableHeightFlowRateInletVelocity;
        flowRate        $inletFlowRate;
        alpha           alpha.water;
        value           uniform ( 0 0 0 );
    }
    outlet
    {
        type            inletOutlet;
        inletValue      uniform ( 0 0 0 );
    }
    lowerWall
    {
        type            noSlip;
    }
    atmosphere
    {
        type            pressureInletOutletVelocity;
        value           uniform ( 0 0 0 );
    }
    defaultFaces
    {
        type            empty;
    }
}

さらに深いDictを表示させたい場合

  • 「entry」オプションに与える引数をスラッシュで区切り、Dictの中のSubDictを表示させる。
  foamDictionary -entry boundaryField/inlet 0/U
# 実行結果
inlet
{
    type            variableHeightFlowRateInletVelocity;
    flowRate        $inletFlowRate;
    alpha           alpha.water;
    value           uniform ( 0 0 0 );
}

Dictの中のkeywordを抽出するには

  foamDictionary -entry boundaryField/inlet/value 0/U
# 実行結果
  value           uniform ( 0 0 0 );

値を変更する場合

  • 「set」オプションで値を変更する。今回の場合はダブルクォートで括って値を変更します。
foamDictionary -entry boundaryField/inlet/value  -set "uniform ( 1 0 0 );" 0/U
# 実行結果
  New entry value           uniform ( 1 0 0 );

さいごに

  • foamDictionaryコマンドの使い方を示しましたが、いかがでしたか。
  • 個人的にfoamDictionaryってタイプ数長いやんって思います。
  • 基本的にBashのAutocompleteが効くので問題ないですが。。。
  • Aliasを書くのもアリかもしれない。
  • たとえば、こんなの(でもこれって嬉しいのか?もっと短いほうが使いやすい?)
	alias foamDict='foamDictionary'
2
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?