This repository has been archived on 2023-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
foam-extend4.1-coherent-io/applications/utilities/surface/surfaceSmooth/surfaceSmooth.C

120 lines
3.6 KiB
C
Raw Normal View History

/*---------------------------------------------------------------------------*\
========= |
2013-12-11 16:09:41 +00:00
\\ / 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
2013-12-11 16:09:41 +00:00
This file is part of foam-extend.
2013-12-11 16:09:41 +00:00
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
2013-12-11 16:09:41 +00:00
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
2013-12-11 16:09:41 +00:00
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
2013-12-11 16:09:41 +00:00
along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
Description
Example of simple laplacian smoother
\*---------------------------------------------------------------------------*/
#include "triSurface.H"
#include "argList.H"
#include "OFstream.H"
#include "boundBox.H"
using namespace Foam;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Main program:
int main(int argc, char *argv[])
{
argList::noParallel();
argList::validOptions.clear();
argList::validArgs.clear();
argList::validArgs.append("surface file");
argList::validArgs.append("underrelax factor (0..1)");
argList::validArgs.append("iterations");
argList::validArgs.append("output file");
argList args(argc, argv);
fileName surfFileName(args.additionalArgs()[0]);
scalar relax(readScalar(IStringStream(args.additionalArgs()[1])()));
if ((relax <= 0) || (relax > 1))
{
FatalErrorIn(args.executable()) << "Illegal relaxation factor "
<< relax << endl
<< "0: no change 1: move vertices to average of neighbours"
<< exit(FatalError);
}
label iters(readLabel(IStringStream(args.additionalArgs()[2])()));
fileName outFileName(args.additionalArgs()[3]);
Info<< "Relax:" << relax << endl;
Info<< "Iters:" << iters << endl;
Info<< "Reading surface from " << surfFileName << " ..." << endl;
triSurface surf1(surfFileName);
Info<< "Triangles : " << surf1.size() << endl;
Info<< "Vertices : " << surf1.nPoints() << endl;
Info<< "Bounding Box : " << boundBox(surf1.localPoints()) << endl;
pointField newPoints(surf1.localPoints());
const labelListList& pointEdges = surf1.pointEdges();
2013-04-15 11:57:08 +00:00
for (label iter = 0; iter < iters; iter++)
{
forAll(pointEdges, vertI)
{
vector avgPos(vector::zero);
const labelList& myEdges = pointEdges[vertI];
forAll(myEdges, myEdgeI)
{
const edge& e = surf1.edges()[myEdges[myEdgeI]];
label otherVertI = e.otherVertex(vertI);
avgPos += surf1.localPoints()[otherVertI];
}
avgPos /= myEdges.size();
newPoints[vertI] = (1-relax)*newPoints[vertI] + relax*avgPos;
}
}
triSurface surf2
(
surf1.localFaces(),
surf1.patches(),
newPoints
);
Info<< "Writing surface to " << outFileName << " ..." << endl;
surf2.write(outFileName);
Info << "End\n" << endl;
return 0;
}
// ************************************************************************* //