/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2022-2025 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 "cutPolyValue.H"
#include "OBJstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template
Type min(const UIndirectList& l)
{
Type result = pTraits::max;
forAll(l, i)
{
result = min(result, l[i]);
}
return result;
}
template
Type max(const UIndirectList& l)
{
Type result = pTraits::min;
forAll(l, i)
{
result = max(result, l[i]);
}
return result;
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Foam::List Foam::cutPoly::faceCuts
(
const face& f,
const scalarField& pAlphas,
const scalar isoAlpha
)
{
UIndirectList fAlphas(pAlphas, f);
// Quick reject if all alpha values are above or below the iso value
if (min(fAlphas) > isoAlpha || isoAlpha > max(fAlphas))
{
return List();
}
// Find the starting point
label fpi0 = 0;
while ((fAlphas[fpi0] < isoAlpha) == separatedBelow)
{
++ fpi0;
}
// Create cuts on every edge for which there is a sign change
DynamicList cuts(1);
label cuti = 0;
forAll(f, i)
{
const label fpi1 = f.fcIndex(fpi0);
if ((fAlphas[fpi0] < isoAlpha) != (fAlphas[fpi1] < isoAlpha))
{
if (cuti == 0)
{
cuts.append({fpi0, -1});
}
else
{
cuts.last()[1] = fpi0;
}
cuti = !cuti;
}
fpi0 = fpi1;
}
// There should have been an even number of cuts
if (cuti != 0)
{
FatalErrorInFunction
<< "Cutting values " << fAlphas << " with iso-value " << isoAlpha
<< " resulted in an odd number of cuts"
<< exit(FatalError);
}
cuts.shrink();
return cuts;
}
Foam::labelListList Foam::cutPoly::cellCuts
(
const cell& c,
const cellEdgeAddressing& cAddr,
const faceUList& fs,
const List>& fCuts,
const scalarField& pAlphas,
const scalar isoAlpha
)
{
// Quick return if not cut
label nCellFaceCuts = 0;
forAll(c, cfi)
{
nCellFaceCuts += fCuts[c[cfi]].size();
}
if (nCellFaceCuts == 0)
{
return labelListList();
}
// Get local cell-face-edge addressing
const CompactListList