関数による初期化2015年10月9日 | |
はじめに関数による初期化について。 使用バージョンOpenFOAM 2.4.0 関数による初期値の設定関数により初期値を設定するには、codeStream を用いる。例として interFoam のチュートリアルケース damBreak における水の液相率 alpha.water の設定を考える。ここでは原点を中心とした半径 0.2 の円の内部に初期の液相率を与えるものとする。alpha.water の internalField で以下のように設定する。 0/alpha.water
internalField #codeStream
{
codeInclude
#{
#include "fvCFD.H"
#};
codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
#};
code
#{
const IOdictionary& d = static_cast<const IOdictionary&>(dict);
const fvMesh& mesh = refCast<const fvMesh>(d.db());
scalarField alpha(mesh.nCells(), 0.);
forAll(alpha, i)
{
const scalar x = mesh.C()[i][0];
const scalar y = mesh.C()[i][1];
const scalar r = sqrt(x*x + y*y);
if (r < 0.2)
{
alpha[i] = 1.;
}
}
alpha.writeEntry("", os);
#};
};
controlDict でライブラリを指定 (ParaView 用)。
libs
(
"libfiniteVolume.so"
);
つぎのような初期液相率分布が得られる。 ![]() 関数による境界条件の設定codeStream により、分布を持たせた境界条件を設定することもできる。simpleFoam のチュートリアルケース pitzDaily で流入速度に分布を持たせた例を示す。 0/U
inlet
{
type fixedValue;
value #codeStream
{
codeInclude
#{
#include "fvCFD.H"
#};
codeOptions
#{
-I$(LIB_SRC)/finiteVolume/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
#};
code
#{
const IOdictionary& d = static_cast<const IOdictionary&>(
dict.parent().parent()
);
const fvMesh& mesh = refCast<const fvMesh>(d.db());
const label id = mesh.boundary().findPatchID("inlet");
const fvPatch& patch = mesh.boundary()[id];
vectorField U(mesh.boundary()[id].size(), vector(0, 0, 0));
const scalar pi = constant::mathematical::pi;
const scalar ux = 10.;
const scalar ymax = 0.0245;
forAll(U, i)
{
const scalar y = patch.Cf()[i][1];
U[i] = vector(ux*sin(pi*y/ymax), 0., 0.);
}
U.writeEntry("", os);
#};
};
}
![]() コードの中で境界名 ("inlet") が指定されていることに注意。これは codeStream の一例を示しているだけで、もし同様のことを行うなら境界タイプ codedFixedValue を使うのが素直である (その場合、少しだけコードが短くなる)。 | |
| PENGUINITIS | |