请教OpenFOAM获得某个区域面积的方法



  • 如下图所示,模型被划分成很多个区域(每个区域包含很多个网格),我想知道每个区域的面积或者(体积),除了手算外,OpenFOAM是否有什么办法得到每个区域的面积(或体积)?最好是functionObject或者utility的办法。期待大佬们的回复,多谢!(备注:这些区域我是通过toposet划分的)

    MSFR-xz - 副本.png



  • 我在网上见到的代码,你试试:

    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


Log in to reply
 

CFD中文网 2016 - 2020 | 京ICP备15017992号-2