在OpenFOAM中获取网格详细信息

转载自: https://jibranhaider.weebly.com/blog/mesh-information-in-openfoam。

Updated: 29/04/2019
When developing your own code in OpenFOAM, it is almost certain that access to mesh information will be required in order to evaluate various parameters. In this post, I have provided a short description on how to access some of this information which could come in handy while programming. These have been characterized into mesh connectivities, mesh coordinates and some other useful mesh data.

Connectivities

// CELLS
const labelListList& cellPoints = mesh.cellPoints();        // Cell to point connectivity
const labelListList& cellEdges =  mesh.cellEdges();         // Cell to edge connectivity
const cellList& cells = mesh.cells();                       // Cell to face connectivity
const labelListList& cellCells =  mesh.cellCells();         // Cell to cell connectivity
// FACES
const faceList& faces = mesh.faces();                       // Face to node connectivity
const labelListList& faceEdges = mesh.faceEdges();          // Face to edge connectivity
const labelList& faceOwner = mesh.faceOwner();              // Face to owner cell
const labelList& faceNeighbour = mesh.faceNeighbour();      // Face to neighbour cell
// POINTS
const labelListList& pointPoints = mesh.pointPoints();      // Point to point connectivity
const labelListList& pointEdges = mesh.pointEdges();        // Point to edge connectivity
const labelListList& pointFaces = mesh.pointFaces();        // Point to face connectivity
const labelListList& pointCells = mesh.pointCells();        // Point to cell connectivity
// EDGES
const edgeList& edges = mesh.edges();                       // Edge to point connectivity
const labelListList& edgeFaces = mesh.edgeFaces();          // Edge to face connectivity
const labelListList& edgeCells = mesh.edgeCells();          // Edge to cell connectivity

Coordinates

const volVectorField& C = mesh.C();                         // Cell center coordinates
const surfaceVectorField& Cf = mesh.Cf();                   // Face center coordinates
const pointField& points = mesh.points();                   // Point coordinates

// EXAMPLE: COMPUTE EDGE CENTRE COORDINATES
#include "vectorList.H"
vectorList Ce(edges.size(), vector::zero);                  // Edge centre coordinates
forAll(edges, edge)
{
    const label& own = edges[edge][0];                      // Label of owner point
    const label& nei = edges[edge][1];                      // Label of neighbour point
    Ce[edge] = 0.5*(points[own] + points[nei]);             // Compute edge centre coordinates
}

Boundaries

const polyBoundaryMesh& boundaryMesh = mesh.boundaryMesh();           // Boundary mesh

// EXAMPLE: LOOP OVER ALL FACES
forAll(faces, face)
{
   if (mesh.isInternalFace(face))                                     // Check for an internal face
   {
       // Do your calculations
   }
   else                                                               // Boundary face
   {
       const label& patch = boundaryMesh.whichPatch(face);            // Boundary patchID
       const label& facei = boundaryMesh[patch].whichFace(face);      // Local boundary faceID
       // Do your calculations
   }
}

// EXAMPLE: LOOP OVER FACES OF BOUNDARY PATCHES
forAll(mesh.boundary(), patch)
{
   const word& patchName = mesh.boundary()[patch].name();             // Boundary patch name
   forAll(mesh.boundary()[patch], facei)
   {
       const label& bCell = boundaryMesh[patch].faceCells()[facei];   // Boundary cellID
       const label& face = boundaryMesh[patch].start() + facei;       // FaceID
       // Do your calculations
       // U.boundaryField()[patch][facei] = vector::zero;
   }
}

// EXAMPLE: LOOP OVER POINTS OF BOUNDARY PATCHES
forAll(mesh.boundary(), patch)
{
        forAll(boundaryMesh[patch].meshPoints(), pointi)
    {
        const label& point = boundaryMesh[patch].meshPoints()[pointi];  // PointID
        // Do your calculations
    }
}

Other useful parameters

const scalarField& V = mesh.V();                            // Cell volumes
const surfaceVectorField& Sf = mesh.Sf();                   // Face area normal vectors
const surfaceScalarField& magSf = mesh.magSf();             // Face areas
const surfaceVectorField& N = Sf/magSf;                     // Face normal vectors
const label& nCells = mesh.nCells();                        // Total number of cells in the mesh
const label& nPoints = mesh.nPoints();                      // Total number of points in the mesh
const label& nInternalFaces = mesh.nInternalFaces();        // Number of internal faces in the mesh
const label& nInternalPoints = mesh.nInternalPoints();      // Number of internal points in 

你可能感兴趣的:(OpenFOAM,#,OpenFOAM技术总结,OpenFOAM)