関数による境界条件の設定2015年10月9日 | |
はじめに関数による境界条件の設定について。 使用バージョンOpenFOAM 2.4.0 実行時コードコンパイルによる設定OpenFOAM 2.0.0 で実装された実行時コードコンパイル (Run-Time Code Compilation) により、ソルバー同様のコードを用いて境界条件を設定することができる。 コードを使える境界条件タイプは codedFixedValue と codedMixed である。 codedFixedValue による設定simpleFoam のチュートリアルケース pitzDaily で、入口流速に分布をつける例を以下に示す。
inlet
{
type codedFixedValue;
value uniform (0 0 0);
redirectType sineVelocity;
code
#{
fvPatchField<vector> f
(
patch().lookupPatchField<volVectorField, vector>("U")
);
const scalar pi = constant::mathematical::pi;
const scalar ux = 10.;
const scalar ymax = 0.0245;
forAll(f, i)
{
const scalar y = patch().Cf()[i][1];
f[i] = vector(ux*sin(pi*y/ymax), 0., 0.);
}
operator==(f);
#};
}
![]() フィールド f として U の値を取っているが、その必要がなければ以下のようにしてもよい。
vectorField f(patch().size(), vector(0., 0., 0.));
非定常境界条件
inlet
{
type codedFixedValue;
value uniform (0 0 0);
redirectType sinVelocity;
code
#{
fvPatchField<vector> f
(
patch().lookupPatchField<volVectorField, vector>("U")
);
const scalar t = this->db().time().timeOutputValue();
const scalar pi = constant::mathematical::pi;
const scalar ux = 10.*sin(2.*pi*t/0.1);
const scalar ymax = 0.0245;
forAll(patch().Cf(), i)
{
const scalar y = patch().Cf()[i][1];
f[i] = vector(ux*sin(pi*y/ymax), 0., 0.);
}
operator==(f);
#};
}
t として時刻を取得し、流速を時間の関数として与えている。 codedMixedcodedMixed で同様の設定を行う例を以下に示す。
inlet
{
type codedMixed;
refValue uniform (0 0 0);
refGradient uniform (0 0 0);
valueFraction uniform 1;
value uniform (0 0 0);
redirectType sineVelocity;
code
#{
fvPatchField<vector> f
(
patch().lookupPatchField<volVectorField, vector>("U")
);
const scalar pi = constant::mathematical::pi;
const scalar ux = 10.;
const scalar ymax = 0.0245;
forAll(patch().Cf(), i)
{
const scalar y = patch().Cf()[i][1];
f[i] = vector(ux*sin(pi*y/ymax), 0., 0.);
}
refValue() = f;
valueFraction() = 1;
#};
}
mixed では値指定と勾配指定を混合できる。refValue() で値指定、refGrad() で勾配指定を行う。valueFraction() は混合具合の指定で、0 から 1 の範囲の値を取り、0 でノイマン条件 (勾配指定)、1 でディリクレ条件 (値指定) になる。 インクルードファイル・オプションの指定以下のようなセクションにより、インクルードファイルやオプションを指定することができる。
codeInclude
#{
#include "basicThermo.H"
#include "turbulenceModel.H"
#include "wallFvPatch.H"
#};
codeOptions
#{
-I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \
-I$(LIB_SRC)/turbulenceModels/compressible/turbulenceModel/lnInclude
#};
オプションでは、ソルバーのコードの Make/options のようにインクルードパスの指定を行える。 外部辞書によるコードの指定code セクションを指定しなければ、system/codeDict が参照される。 system/codeDict
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object codeDict;
}
sineVelocity
{
code
#{
fvPatchField<vector> f
(
patch().lookupPatchField<volVectorField, vector>("U")
);
const scalar pi = constant::mathematical::pi;
const scalar ux = 10.;
const scalar ymax = 0.0245;
forAll(patch().Cf(), i)
{
f[i] = vector(ux*sin(pi*patch().Cf()[i][1]/ymax),0,0);
}
refValue() = f;
valueFraction() = 1;
#};
}
| |
| PENGUINITIS | |