/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | Website: https://openfoam.org \\ / A nd | Copyright (C) 2011-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 "polyMeshTetDecomposition.H" // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // Note: the use of this tolerance is ad-hoc, there may be extreme // cases where the resulting tetrahedra still have particle tracking // problems, or tets with lower quality may track OK. const Foam::scalar Foam::polyMeshTetDecomposition::minTetQuality = sqr(small); // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // Foam::scalar Foam::polyMeshTetDecomposition::minQuality ( const polyMesh& mesh, const point& cC, const label fI, const bool isOwner, const label faceBasePtI ) { // Does fan decomposition of face (starting at faceBasePti) and determines // min quality over all resulting tets. const pointField& pPts = mesh.points(); const face& f = mesh.faces()[fI]; const point& tetBasePt = pPts[f[faceBasePtI]]; scalar thisBaseMinTetQuality = vGreat; for (label tetPtI = 1; tetPtI < f.size() - 1; tetPtI++) { label facePtI = (tetPtI + faceBasePtI) % f.size(); label otherFacePtI = f.fcIndex(facePtI); label ptAI = -1; label ptBI = -1; if (isOwner) { ptAI = f[facePtI]; ptBI = f[otherFacePtI]; } else { ptAI = f[otherFacePtI]; ptBI = f[facePtI]; } const point& pA = pPts[ptAI]; const point& pB = pPts[ptBI]; tetPointRef tet(cC, tetBasePt, pA, pB); scalar tetQuality = tet.quality(); if (tetQuality < thisBaseMinTetQuality) { thisBaseMinTetQuality = tetQuality; } } return thisBaseMinTetQuality; } Foam::label Foam::polyMeshTetDecomposition::findSharedBasePoint ( const polyMesh& mesh, label fI, const point& nCc, scalar tol, bool report ) { const faceList& pFaces = mesh.faces(); const vectorField& pC = mesh.cellCentres(); const labelList& pOwner = mesh.faceOwner(); const face& f = pFaces[fI]; label oCI = pOwner[fI]; const point& oCc = pC[oCI]; forAll(f, faceBasePtI) { scalar minQ = minQuality(mesh, oCc, fI, true, faceBasePtI); minQ = min(minQ, minQuality(mesh, nCc, fI, false, faceBasePtI)); if (minQ > tol) { return faceBasePtI; } } // If a base point hasn't triggered a return by now, then there is // none that can produce a good decomposition return -1; } Foam::label Foam::polyMeshTetDecomposition::findSharedBasePoint ( const polyMesh& mesh, label fI, scalar tol, bool report ) { return findSharedBasePoint ( mesh, fI, mesh.cellCentres()[mesh.faceNeighbour()[fI]], tol, report ); } Foam::label Foam::polyMeshTetDecomposition::findBasePoint ( const polyMesh& mesh, label fI, scalar tol, bool report ) { const faceList& pFaces = mesh.faces(); const vectorField& pC = mesh.cellCentres(); const labelList& pOwner = mesh.faceOwner(); const face& f = pFaces[fI]; label cI = pOwner[fI]; bool own = (pOwner[fI] == cI); const point& cC = pC[cI]; forAll(f, faceBasePtI) { scalar quality = minQuality(mesh, cC, fI, own, faceBasePtI); if (quality > tol) { return faceBasePtI; } } // If a base point hasn't triggered a return by now, then there is // none that can produce a good decomposition return -1; } Foam::labelList Foam::polyMeshTetDecomposition::findFaceBasePts ( const polyMesh& mesh, scalar tol, bool report ) { const labelList& pOwner = mesh.faceOwner(); const vectorField& pC = mesh.cellCentres(); // Find a suitable base point for each face, considering both // cells for interface faces or those on coupled patches labelList tetBasePtIs(mesh.nFaces(), -1); label nInternalFaces = mesh.nInternalFaces(); for (label fI = 0; fI < nInternalFaces; fI++) { tetBasePtIs[fI] = findSharedBasePoint(mesh, fI, tol, report); } pointField neighbourCellCentres(mesh.nFaces() - nInternalFaces); for(label facei = nInternalFaces; facei < mesh.nFaces(); facei++) { neighbourCellCentres[facei - nInternalFaces] = pC[pOwner[facei]]; } syncTools::swapBoundaryFacePositions(mesh, neighbourCellCentres); const polyBoundaryMesh& patches = mesh.boundary(); SubList