1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 Example of a simple laplacian smoother
27 \*---------------------------------------------------------------------------*/
33 #include "MeshedSurfaces.H"
38 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 int main(int argc, char *argv[])
43 argList::noParallel();
44 argList::validOptions.clear();
45 argList::validArgs.append("surfaceFile");
46 argList::validArgs.append("underrelax factor (0..1)");
47 argList::validArgs.append("iterations");
48 argList::validArgs.append("output surfaceFile");
49 argList args(argc, argv);
51 const fileName surfFileName = args[1];
52 const scalar relax = args.argRead<scalar>(2);
53 const label iters = args.argRead<label>(3);
54 const fileName outFileName = args[4];
56 if (relax <= 0 || relax > 1)
58 FatalErrorIn(args.executable()) << "Illegal relaxation factor "
60 << "0: no change 1: move vertices to average of neighbours"
64 Info<< "Relax:" << relax << nl
65 << "Iters:" << iters << nl
66 << "Reading surface from " << surfFileName << " ..." << endl;
68 meshedSurface surf1(surfFileName);
70 Info<< "Faces : " << surf1.size() << nl
71 << "Vertices : " << surf1.nPoints() << nl
72 << "Bounding Box : " << boundBox(surf1.localPoints()) << endl;
74 pointField newPoints(surf1.localPoints());
76 const labelListList& pointEdges = surf1.pointEdges();
78 for (label iter = 0; iter < iters; iter++)
80 forAll(pointEdges, vertI)
82 vector avgPos(vector::zero);
84 const labelList& myEdges = pointEdges[vertI];
86 forAll(myEdges, myEdgeI)
88 const edge& e = surf1.edges()[myEdges[myEdgeI]];
90 label otherVertI = e.otherVertex(vertI);
92 avgPos += surf1.localPoints()[otherVertI];
94 avgPos /= myEdges.size();
96 newPoints[vertI] = (1-relax)*newPoints[vertI] + relax*avgPos;
100 Info<< "Writing surface to " << outFileName << " ..." << endl;
105 xferCopy(surf1.localFaces()),
106 xferCopy(surf1.surfZones())
107 ).write(outFileName);
109 Info<< "End\n" << endl;
115 // ************************************************************************* //