OpenFOAM中计算某一个边界的面积,代码为:
// 找到inlet这个patch的ID
label patchID = mesh.boundaryMesh().findPatchID("inlet");
// 创建inlet的polyPatch类型的引用
const polyPatch& cPatch = mesh.boundaryMesh()[patchID];
// 创建面标量场magSf,代表的是网格单元某一个面的面积
const surfaceScalarField& magSf = mesh.magSf();
// 定义标量,并初始化为0.0
scalar patchArea = 0.0;
// 遍历inlet上的所有单元面,然后将单元面的面积加起来
forAll(cPatch,faceI)
{
patchArea += magSf.boundaryField()[patchID][faceI];
}
// 输出inlet这个边界面的面积
Info << "Patch Area " << patchArea << endl;
或者:
label patchID = mesh.boundaryMesh().findPatchID("inlet");
const polyPatch& cPatch = mesh.boundaryMesh()[patchID];
const surfaceScalarField& magSf = mesh.magSf();
// 直接使用gSum函数来求inlet的面积
scalar AREA = gSum(magSf.boundaryField()[patchID]);
Info << "AREA = " << nl << AREA << endl;
参考资料:
https://www.cfd-online.com/Forums/openfoam-solving/59251-how-access-faces-patch.html