1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 Example of simple laplacian smoother
33 - surfaceSmooth [OPTIONS] \<Foam surface file\> \<underrelaxation factor (0..1)\> \<iterations\> \<Foam output surface file\>
35 @param \<Foam surface file\> \n
36 @todo Detailed description of argument.
38 @param \<underrelaxation factor (0..1)\> \n
39 @todo Detailed description of argument.
41 @param \<iterations\> \n
42 @todo Detailed description of argument.
44 @param \<Foam output surface file\> \n
45 @todo Detailed description of argument.
51 Display Doxygen API documentation page for this application.
54 Display Doxygen source documentation page for this application.
56 \*---------------------------------------------------------------------------*/
58 #include <triSurface/triSurface.H>
59 #include <OpenFOAM/argList.H>
60 #include <OpenFOAM/OFstream.H>
61 #include <OpenFOAM/boundBox.H>
66 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
69 int main(int argc, char *argv[])
71 argList::noParallel();
72 argList::validOptions.clear();
73 argList::validArgs.clear();
74 argList::validArgs.append("surface file");
75 argList::validArgs.append("underrelax factor (0..1)");
76 argList::validArgs.append("iterations");
77 argList::validArgs.append("output file");
78 argList args(argc, argv);
80 fileName surfFileName(args.additionalArgs()[0]);
81 scalar relax(readScalar(IStringStream(args.additionalArgs()[1])()));
82 if ((relax <= 0) || (relax > 1))
84 FatalErrorIn(args.executable()) << "Illegal relaxation factor "
86 << "0: no change 1: move vertices to average of neighbours"
89 label iters(readLabel(IStringStream(args.additionalArgs()[2])()));
90 fileName outFileName(args.additionalArgs()[3]);
92 Info<< "Relax:" << relax << endl;
93 Info<< "Iters:" << iters << endl;
96 Info<< "Reading surface from " << surfFileName << " ..." << endl;
98 triSurface surf1(surfFileName);
100 Info<< "Triangles : " << surf1.size() << endl;
101 Info<< "Vertices : " << surf1.nPoints() << endl;
102 Info<< "Bounding Box : " << boundBox(surf1.localPoints()) << endl;
104 pointField newPoints(surf1.localPoints());
106 const labelListList& pointEdges = surf1.pointEdges();
109 for(label iter = 0; iter < iters; iter++)
111 forAll(pointEdges, vertI)
113 vector avgPos(vector::zero);
115 const labelList& myEdges = pointEdges[vertI];
117 forAll(myEdges, myEdgeI)
119 const edge& e = surf1.edges()[myEdges[myEdgeI]];
121 label otherVertI = e.otherVertex(vertI);
123 avgPos += surf1.localPoints()[otherVertI];
125 avgPos /= myEdges.size();
127 newPoints[vertI] = (1-relax)*newPoints[vertI] + relax*avgPos;
138 Info<< "Writing surface to " << outFileName << " ..." << endl;
140 surf2.write(outFileName);
142 Info << "End\n" << endl;
148 // ************************ vim: set sw=4 sts=4 et: ************************ //