1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
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
26 Example of simple laplacian smoother
28 \*---------------------------------------------------------------------------*/
30 #include "triSurface.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 int main(int argc, char *argv[])
43 argList::noParallel();
44 argList::validOptions.clear();
45 argList::validArgs.clear();
46 argList::validArgs.append("surface file");
47 argList::validArgs.append("underrelax factor (0..1)");
48 argList::validArgs.append("iterations");
49 argList::validArgs.append("output file");
50 argList args(argc, argv);
52 fileName surfFileName(args.additionalArgs()[0]);
53 scalar relax(readScalar(IStringStream(args.additionalArgs()[1])()));
54 if ((relax <= 0) || (relax > 1))
56 FatalErrorIn(args.executable()) << "Illegal relaxation factor "
58 << "0: no change 1: move vertices to average of neighbours"
61 label iters(readLabel(IStringStream(args.additionalArgs()[2])()));
62 fileName outFileName(args.additionalArgs()[3]);
64 Info<< "Relax:" << relax << endl;
65 Info<< "Iters:" << iters << endl;
68 Info<< "Reading surface from " << surfFileName << " ..." << endl;
70 triSurface surf1(surfFileName);
72 Info<< "Triangles : " << surf1.size() << endl;
73 Info<< "Vertices : " << surf1.nPoints() << endl;
74 Info<< "Bounding Box : " << boundBox(surf1.localPoints()) << endl;
76 pointField newPoints(surf1.localPoints());
78 const labelListList& pointEdges = surf1.pointEdges();
81 for (label iter = 0; iter < iters; iter++)
83 forAll(pointEdges, vertI)
85 vector avgPos(vector::zero);
87 const labelList& myEdges = pointEdges[vertI];
89 forAll(myEdges, myEdgeI)
91 const edge& e = surf1.edges()[myEdges[myEdgeI]];
93 label otherVertI = e.otherVertex(vertI);
95 avgPos += surf1.localPoints()[otherVertI];
97 avgPos /= myEdges.size();
99 newPoints[vertI] = (1-relax)*newPoints[vertI] + relax*avgPos;
110 Info<< "Writing surface to " << outFileName << " ..." << endl;
112 surf2.write(outFileName);
114 Info << "End\n" << endl;
120 // ************************************************************************* //