/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | foam-extend: Open Source CFD
\\ / O peration | Version: 3.2
\\ / A nd | Web: http://www.foam-extend.org
\\/ M anipulation | For copyright notice see file Copyright
-------------------------------------------------------------------------------
License
This file is part of foam-extend.
foam-extend 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.
foam-extend 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 foam-extend. If not, see .
\*---------------------------------------------------------------------------*/
#include "triangle.H"
#include "triSurface.H"
#include "triSurfaceTools.H"
#include "triSurfaceSearch.H"
#include "argList.H"
#include "OFstream.H"
#include "surfaceIntersection.H"
#include "SortableList.H"
#include "PatchTools.H"
using namespace Foam;
// Does face use valid vertices?
bool validTri(const bool verbose, const triSurface& surf, const label faceI)
{
// Simple check on indices ok.
const labelledTri& f = surf[faceI];
if
(
(f[0] < 0) || (f[0] >= surf.points().size())
|| (f[1] < 0) || (f[1] >= surf.points().size())
|| (f[2] < 0) || (f[2] >= surf.points().size())
)
{
WarningIn("validTri(const triSurface&, const label)")
<< "triangle " << faceI << " vertices " << f
<< " uses point indices outside point range 0.."
<< surf.points().size()-1 << endl;
return false;
}
if ((f[0] == f[1]) || (f[0] == f[2]) || (f[1] == f[2]))
{
WarningIn("validTri(const triSurface&, const label)")
<< "triangle " << faceI
<< " uses non-unique vertices " << f
<< " coords:" << f.points(surf.points())
<< endl;
return false;
}
// Duplicate triangle check
const labelList& fFaces = surf.faceFaces()[faceI];
// Check if faceNeighbours use same points as this face.
// Note: discards normal information - sides of baffle are merged.
forAll(fFaces, i)
{
label nbrFaceI = fFaces[i];
if (nbrFaceI <= faceI)
{
// lower numbered faces already checked
continue;
}
const labelledTri& nbrF = surf[nbrFaceI];
if
(
((f[0] == nbrF[0]) || (f[0] == nbrF[1]) || (f[0] == nbrF[2]))
&& ((f[1] == nbrF[0]) || (f[1] == nbrF[1]) || (f[1] == nbrF[2]))
&& ((f[2] == nbrF[0]) || (f[2] == nbrF[1]) || (f[2] == nbrF[2]))
)
{
WarningIn("validTri(const triSurface&, const label)")
<< "triangle " << faceI << " vertices " << f
<< " has the same vertices as triangle " << nbrFaceI
<< " vertices " << nbrF
<< " coords:" << f.points(surf.points())
<< endl;
return false;
}
}
return true;
}
labelList countBins
(
const scalar min,
const scalar max,
const label nBins,
const scalarField& vals
)
{
scalar dist = nBins/(max - min);
labelList binCount(nBins, 0);
forAll(vals, i)
{
scalar val = vals[i];
label index = -1;
if (Foam::mag(val - min) < SMALL)
{
index = 0;
}
else if (val >= max - SMALL)
{
index = nBins - 1;
}
else
{
index = label((val - min)*dist);
if ((index < 0) || (index >= nBins))
{
WarningIn
(
"countBins(const scalar, const scalar, const label"
", const scalarField&)"
) << "value " << val << " at index " << i
<< " outside range " << min << " .. " << max << endl;
if (index < 0)
{
index = 0;
}
else
{
index = nBins - 1;
}
}
}
binCount[index]++;
}
return binCount;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validArgs.clear();
argList::validArgs.append("surface file");
argList::validOptions.insert("checkSelfIntersection", "");
argList::validOptions.insert("verbose", "");
argList args(argc, argv);
bool checkSelfIntersection = args.optionFound("checkSelfIntersection");
bool verbose = args.optionFound("verbose");
fileName surfFileName(args.additionalArgs()[0]);
Pout<< "Reading surface from " << surfFileName << " ..." << nl << endl;
// Read
// ~~~~
triSurface surf(surfFileName);
const pointField& surfPoints = surf.points();
Pout<< "Statistics:" << endl;
surf.writeStats(Pout);
Pout<< endl;
// Region sizes
// ~~~~~~~~~~~~
{
labelList regionSize(surf.patches().size(), 0);
scalarField regionSumArea(surf.patches().size(), 0);
forAll(surf, faceI)
{
label region = surf[faceI].region();
if (region < 0 || region >= regionSize.size())
{
WarningIn(args.executable())
<< "Triangle " << faceI << " vertices " << surf[faceI]
<< " has region " << region
<< " which is outside the range"
<< " of regions 0.." << surf.patches().size() - 1
<< endl;
}
else
{
regionSize[region]++;
regionSumArea[region] += surf[faceI].mag(surfPoints);
}
}
Pout<< "Region\tSize\tArea" << nl
<< "------\t----\t----" << nl;
forAll(surf.patches(), patchI)
{
Pout<< surf.patches()[patchI].name() << tab
<< regionSize[patchI] << tab << regionSumArea[patchI] << nl;
}
Pout<< nl << endl;
}
// Check triangles
// ~~~~~~~~~~~~~~~
{
DynamicList