我在网上见到的代码,你试试:
const cellList& cells = mesh.cells();
const vectorField& faceAreas = mesh.faceAreas();
List<bool> outsideFaces(faceAreas.size(), false);
forAll(mesh.cellZones(), zoneI)
{
const labelList& cellLabels = mesh_.cellZones()[zoneI];
outsideFaces = false;
// mark all faces that are NOT internal to the cellZone:
forAll(cellLabels, i)
{
const cell& c = cells[cellLabels[i]];
forAll(c, cFaceI)
{
const label faceI = c[cFaceI];
// xor operation
// internal faces get marked twice, outside faces get marked once
if (outsideFaces[faceI])
{
outsideFaces[faceI] = false;
}
else
{
outsideFaces[faceI] = true;
}
}
}
// now calculate the area
scalar zoneOutsideArea = 0;
label zoneOutsideNFaces = 0;
forAll(outsideFaces, faceI)
{
if (outsideFaces[faceI])
{
zoneSurfaceArea += mag(faceAreas[faceI]);
zoneOutsideNFaces++;
}
}
Info<<"zone:" << zoneI
<< " nFaces:" << zoneOutsideNFaces
<< " area:" << zoneOutsideArea << endl;
}
https://www.cfd-online.com/Forums/openfoam-programming-development/69661-how-compute-cellzone-volume.html