OpenFOAM【scalarCodedSource】

注意しよう!

結構苦戦しました。ネットのソースコードを参考にしていましたが、バージョン違い?などでうまくいかなかったので、結局自分がインストールしたソースコード内をあさりました。

テンプレートを探す

grep -r "scalarCodedSource" *

で探すと

  • etc/codeTemplates/dynamicCode/codedFvOptionTemplate.H
  • src/fvOptions/sources/general/codedSource/CodedSource.H

が引っ掛かりました。このうちsrc/fvOptions/sources/general/codedSource/CodedSource.Hの方がうまくいきました。もう片方はうまくいかなかった。

fvOptionsの中に、以下を張り付けました。

energySource
{
    type            scalarCodedSource;

    active          yes;

    name    sourceTime;

    scalarCodedSourceCoeffs
    {
        selectionMode   all;

        fields          (T);

        codeInclude
        #{

        #};

        codeCorrect
        #{
            Pout<< "**codeCorrect**" << endl;
        #};

        codeAddSup
        #{
            const Time& time = mesh().time();
            const scalarField& V = mesh_.V();
            scalarField& heSource = eqn.source();
            heSource -= 0.1*sqr(time.value())*V;
        #};

        codeSetValue
        #{
            Pout<< "**codeSetValue**" << endl;
        #};
    }

    sourceTimeCoeffs
    {
        $scalarCodedSourceCoeffs;
    }
}

実行したところ、なんか動いたのでok。実行後に/dynamicCodeが作成されていました。

参考にしました

PENGUINITIS - fvOptions

OpenFOAM: User Guide: Coded source

http://www.akionux.net/doc/OpenFOAM-2.3.x_Doxygen/html/a00293.html

https://www.cfd-online.com/Forums/openfoam-solving/123670-howto-use-scalarcodedsource-fvoptions.html