customHeat
{
type coded;
libs ("libutilityFunctionObjects.so");
name customHeat;
region bottomSolid;
writeControl timeStep;
writeInterval 1;
codeExecute
#{
const Time& myTime = mesh().time();
const scalar myDeltaT = myTime.deltaT().value(); //時間step⊿tを取得
volScalarField& h = const_cast<volScalarField&>(mesh().lookupObject<volScalarField>("h"));
const vectorField& C = mesh().C();
//const scalarField& V = mesh().V();
const scalar p0 = 1000; //レーザ出力
const scalar absoptionRate = 0.4; //吸収率
const scalar x0 = 0.0; //光軸中心座標
const scalar y0 = 0.0;
const scalar radius = 0.01; //ビーム半径
const scalar endTime = 0.05; //レーザ照射を終了する時刻
const scalar pi = 3.1415; //円周率
scalar p = 0;
scalar r = 0;
scalar x = 0;
scalar y = 0;
OFstream logFile("output.txt",
IOstream::ASCII,
IOstream::UNCOMPRESSED,
IOstreamOption::APPEND); //IOstreamOption::APPEND IOstreamOption::NO_APPEND
word patchName = "bottomSolid_to_topAir";
logFile << "\nTime: " << myTime.value() << endl;
if (myTime.value() < endTime)
{
label patchI = mesh().boundaryMesh().findPatchID(patchName); //境界"bottomSolid_to_topAir"に属するパッチid
// パッチの開始face番号とサイズ
const polyPatch& pp = mesh().boundaryMesh()[patchI];
label startFace = pp.start();
label nFaces = pp.size();
DynamicList<label> cellsOnPatch;
label cellI;
DynamicList<scalar> areaOnPatch;
scalar area;
for (label faceI = startFace; faceI < startFace + nFaces; ++faceI)
{
cellI = mesh().faceOwner()[faceI]; // 該当するパッチを保有するセル
cellsOnPatch.append(cellI); //セルのリスト
area = mag(mesh().Sf()[faceI]); //該当するパッチの面積
areaOnPatch.append(area); //パッチの面積のリスト
}
logFile << "=======================cellsOnPatch======================" << endl;
logFile << cellsOnPatch << endl;
logFile << "=======================q_location======================" << endl;
forAll(cellsOnPatch, celli)
{
x = C[cellsOnPatch[celli]].x(); //該当するセルの中心のx座標
y = C[cellsOnPatch[celli]].y();
r = sqrt(pow(x-x0, 2) + pow(y-y0, 2)); //光軸中心からの半径
if (r < 1.5*radius)
{
logFile << C[cellsOnPatch[celli]].x() << " " << C[cellsOnPatch[celli]].y() << " " << C[cellsOnPatch[celli]].z() << endl;
p = 2 * absoptionRate * p0 * exp(-2 * pow(r / radius, 2)) / (pi * pow(radius, 2)); //該当する位置のパワー密度(ガウス分布)
h[cellsOnPatch[celli]] += p * areaOnPatch[celli] * myDeltaT; // パワー密度 x 面積 x 時間step で熱量を算出し加える
}
}
}
#};
}