/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2013-2026 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "meshStructure.H" #include "FaceCellWave.H" #include "topoDistanceData.H" #include "pointTopoDistanceData.H" #include "PointEdgeWave.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(meshStructure, 0); } // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // bool Foam::meshStructure::isStructuredCell ( const polyMesh& mesh, const label layerI, const label celli ) const { const cell& cFaces = mesh.cells()[celli]; // Count number of side faces label nSide = 0; forAll(cFaces, i) { if (faceToPatchEdgeAddressing_[cFaces[i]] != -1) { nSide++; } } if (nSide != cFaces.size()-2) { return false; } // Check that side faces have correct point layers forAll(cFaces, i) { if (faceToPatchEdgeAddressing_[cFaces[i]] != -1) { const face& f = mesh.faces()[cFaces[i]]; label nLayer = 0; label nLayerPlus1 = 0; forAll(f, fp) { label pointi = f[fp]; if (pointLayer_[pointi] == layerI) { nLayer++; } else if (pointLayer_[pointi] == layerI+1) { nLayerPlus1++; } } if (f.size() != 4 || (nLayer+nLayerPlus1 != 4)) { return false; } } } return true; } void Foam::meshStructure::correct ( const polyMesh& mesh, const uindirectPrimitivePatch& pp ) { // Field on cells and faces. List cellData(mesh.nCells()); List faceData(mesh.nFaces()); { if (debug) { Info<< typeName << " : seeding " << returnReduce(pp.size(), sumOp()) << " patch faces" << nl << endl; } // Start of changes labelList patchFaces(pp.size()); List patchData(pp.size()); forAll(pp, patchFacei) { patchFaces[patchFacei] = pp.addressing()[patchFacei]; patchData[patchFacei] = topoDistanceData(patchFacei, 0); } // Propagate information inwards FaceCellWave distanceCalc ( mesh, patchFaces, patchData, faceData, cellData, mesh.globalData().nTotalCells()+1 ); // Determine cells from face-cell-walk // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ cellToPatchFaceAddressing_.setSize(mesh.nCells()); cellLayer_.setSize(mesh.nCells()); forAll(cellToPatchFaceAddressing_, celli) { cellToPatchFaceAddressing_[celli] = cellData[celli].data(); cellLayer_[celli] = cellData[celli].distance(); } // Determine faces from face-cell-walk // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ faceToPatchFaceAddressing_.setSize(mesh.nFaces()); faceToPatchEdgeAddressing_.setSize(mesh.nFaces()); faceToPatchEdgeAddressing_ = labelMin; faceLayer_.setSize(mesh.nFaces()); forAll(faceToPatchFaceAddressing_, facei) { label own = mesh.faceOwner()[facei]; label patchFacei = faceData[facei].data(); label patchDist = faceData[facei].distance(); if (mesh.isInternalFace(facei)) { label nei = mesh.faceNeighbour()[facei]; if (cellData[own].distance() == cellData[nei].distance()) { // side face faceToPatchFaceAddressing_[facei] = 0; faceLayer_[facei] = cellData[own].distance(); } else if (cellData[own].distance() < cellData[nei].distance()) { // unturned face faceToPatchFaceAddressing_[facei] = patchFacei+1; faceToPatchEdgeAddressing_[facei] = -1; faceLayer_[facei] = patchDist; } else { // turned face faceToPatchFaceAddressing_[facei] = -(patchFacei+1); faceToPatchEdgeAddressing_[facei] = -1; faceLayer_[facei] = patchDist; } } else if (patchDist == cellData[own].distance()) { // starting face faceToPatchFaceAddressing_[facei] = -(patchFacei+1); faceToPatchEdgeAddressing_[facei] = -1; faceLayer_[facei] = patchDist; } else { // unturned face or side face. Cannot be determined until // we determine the point layers. Problem is that both are // the same number of steps away from the initial seed face. } } } // Determine points from separate walk on point-edge // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { pointToPatchPointAddressing_.setSize(mesh.nPoints()); pointLayer_.setSize(mesh.nPoints()); if (debug) { Info<< typeName << " : seeding " << returnReduce(pp.nPoints(), sumOp()) << " patch points" << nl << endl; } // Field on edges and points. List edgeData(mesh.nEdges()); List pointData(mesh.nPoints()); // Start of changes labelList patchPoints(pp.nPoints()); List patchData(pp.nPoints()); forAll(pp.meshPoints(), patchPointi) { patchPoints[patchPointi] = pp.meshPoints()[patchPointi]; patchData[patchPointi] = pointTopoDistanceData(patchPointi, 0); } // Walk PointEdgeWave distanceCalc ( mesh, patchPoints, patchData, pointData, edgeData, mesh.globalData().nTotalPoints() // max iterations ); forAll(pointData, pointi) { pointToPatchPointAddressing_[pointi] = pointData[pointi].data(); pointLayer_[pointi] = pointData[pointi].distance(); } // Derive from originating patch points what the patch edges were. EdgeMap