Mesh connectivities
Cells
const labelListList& cellPoints = mesh.cellPoints(); // Cell to node const labelListList& cellEdges = mesh.cellEdges(); // Cell to edge const cellList& cells = mesh.cells(); // Cell to face const labelListList& cellCells = mesh.cellCells(); // Cell to cell
Faces
const faceList& faces = mesh.faces(); // Face to node const labelListList& faceEdges = mesh.faceEdges(); // Face to edge const labelList& faceOwner = mesh.faceOwner(); // Face to owner cell const labelList& faceNeighbour = mesh.faceNeighbour(); // Face to neighbour cell
Nodes
const labelListList& pointPoints = mesh.pointPoints(); // Node to node const labelListList& pointEdges = mesh.pointEdges(); // Point to edge const labelListList& pointFaces = mesh.pointFaces(); // Point to face const labelListList& pointCells = mesh.pointCells(); // Point to cell
Edges
const edgeList& edges = mesh.edges(); // Edge to node const labelListList& edgeFaces = mesh.edgeFaces(); // Edge to face const labelListList& edgeCells = mesh.edgeCells(); // Edge to cell
Mesh coordinates
Cell center, face center and node
const volVectorField& C = mesh.C(); // Cell center coordinates const surfaceVectorField& Cf = mesh.Cf(); // Face center coordinates const pointField& points = mesh.points(); // Node coordinates
Edge center
Since OpenFOAM is based on the conventional cell-centred Finite Volume Method, edge coordinates are not computed by the fvMesh
class. However, if necessary they can be obtained very easily by averaging the 2 node coordinates associated to each edge.
// Include vectorList definition to store edge coordinates #include "vectorList.H" // Create edge list which contains edge to node connectivity const edgeList& edges = mesh.edges(); // Create a vectorList to store edge centre coordinates // This list has size of edgeList 'edges' and is initialized to zero vectorList Ce(edges.size(), vector::zero); // Loop over all edges forAll(edges, edge) { const label& own = edges[edge][0]; // Index of edge owner node const label& nei = edges[edge][1]; // Index of edge neighbour node // Calculate edge center coordinates by averaging node coordinates Ce[edge] = 0.5*(points[own] + points[nei]); }
Boundary mesh data
// Store boundary mesh information const polyBoundaryMesh& boundaryMesh = mesh.boundaryMesh();
Distinguish between internal and boundary faces
// Loop over all faces (internal and boundary) forAll(faces, face) { if (mesh.isInternalFace(face)) // Internal face is found { // Do your calculations for internal faces i.e. // U[face] = vector::zero; } else // Boundary face is found { const label& patch = boundaryMesh.whichPatch(face); // Boundary patch index const label& facei = boundaryMesh[patch].whichFace(face); // Local boundary face index // Do your calculations for boundary faces i.e. // U.boundaryField()[patch][facei] = vector::zero; } }
Boundary patches
// Loop over boundary patches forAll(mesh.boundary(), patch) { const word& patchName = mesh.boundary()[patch].name(); // Boundary patch name // Loop over all faces of boundary patch forAll(mesh.boundary()[patch], facei) { const label& bCell = boundaryMesh[patch].faceCells()[facei]; // Boundary cell index const label& face = boundaryMesh[patch].start() + facei; // Face index // Do your calculations e.g. // U.boundaryField()[patch][facei] = vector::zero; } // Loop over all nodes of boundary patch forAll(boundaryMesh[patch].meshPoints(), pointi) { const label& point = boundaryMesh[patch].meshPoints()[pointi]; // Node index // Do your calculations e.g. // U[point] = vector::one; } }
Other useful mesh parameters
// Cell volumes const scalarField& V = mesh.V(); // Face area normal vectors const surfaceVectorField& Sf = mesh.Sf(); // Face areas const surfaceScalarField& magSf = mesh.magSf(); // Face normals const surfaceVectorField& N = Sf/magSf; // Total number of cells const label& nCells = mesh.nCells(); // Total number of nodes const label& nPoints = mesh.nPoints(); // Total number of internal faces const label& nInternalFaces = mesh.nInternalFaces(); // Total number of internal nodes const label& nInternalPoints = mesh.nInternalPoints();