/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | www.openfoam.com \\/ M anipulation | ------------------------------------------------------------------------------- Copyright (C) 2011-2019 OpenFOAM Foundation Copyright (C) 2019-2023 OpenCFD Ltd. ------------------------------------------------------------------------------- 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 "isoSurfaceTopo.H" #include "polyMesh.H" #include "volFields.H" #include "edgeHashes.H" #include "tetCell.H" #include "DynamicField.H" #include "syncTools.H" #include "indirectPrimitivePatch.H" #include "polyMeshTetDecomposition.H" #include "foamVtkInternalMeshWriter.H" #include "foamVtkLineWriter.H" #include "foamVtkSurfaceWriter.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // #include "isoSurfaceBaseMethods.H" defineIsoSurfaceInterpolateMethods(Foam::isoSurfaceTopo); // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // namespace Foam { defineTypeNameAndDebug(isoSurfaceTopo, 0); } // Get/set snapIndex (0, 1 or 2) at given position // 0 = no snap // 1 = snap to first edge end // 2 = snap to second edge end // NB: 4 lower bits left free for regular tet-cut information #undef SNAP_END_VALUE #undef SNAP_END_ENCODE #define SNAP_END_ENCODE(pos, val) (((val) << (4 + 2 * pos))) #define SNAP_END_VALUE(pos, val) (((val) >> (4 + 2 * pos)) & 0x3) // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // namespace Foam { // Check for tet values above/below given (iso) value // Result encoded as an integer, with possible snapping information too inline static int getTetCutIndex ( scalar p0, scalar p1, scalar p2, scalar p3, const scalar val, const bool doSnap ) noexcept { int cutIndex ( (p0 < val ? 1 : 0) // point 0 | (p1 < val ? 2 : 0) // point 1 | (p2 < val ? 4 : 0) // point 2 | (p3 < val ? 8 : 0) // point 3 ); if (doSnap && cutIndex && cutIndex != 0xF) { // Not all below or all // Calculate distances (for snapping) p0 -= val; if (cutIndex & 1) p0 *= -1; p1 -= val; if (cutIndex & 2) p1 *= -1; p2 -= val; if (cutIndex & 4) p2 *= -1; p3 -= val; if (cutIndex & 8) p3 *= -1; // Add snap index into regular edge cut index // Snap to end if less than approx 1% of the distance. // - only valid if there is also a corresponding sign change #undef ADD_SNAP_INDEX #define ADD_SNAP_INDEX(pos, d1, d2, idx1, idx2) \ switch (cutIndex & (idx1 | idx2)) \ { \ case idx1 : /* first below, second above */ \ case idx2 : /* first above, second below */ \ cutIndex |= SNAP_END_ENCODE \ ( \ pos, \ ((d1 * 100 < d2) ? 1 : (d2 * 100 < d1) ? 2 : 0) \ ); \ break; \ } ADD_SNAP_INDEX(0, p0, p1, 1, 2); // Edge 0: 0 -> 1 ADD_SNAP_INDEX(1, p0, p2, 1, 4); // Edge 1: 0 -> 2 ADD_SNAP_INDEX(2, p0, p3, 1, 8); // Edge 2: 0 -> 3 ADD_SNAP_INDEX(3, p3, p1, 8, 2); // Edge 3: 3 -> 1 ADD_SNAP_INDEX(4, p1, p2, 2, 4); // Edge 4: 1 -> 2 ADD_SNAP_INDEX(5, p3, p2, 8, 4); // Edge 5: 3 -> 2 #undef ADD_SNAP_INDEX } return cutIndex; } // Append three labels to list. // Filter out degenerate (eg, snapped) tris. Flip face as requested inline static void appendTriLabels ( DynamicList