00001 /*---------------------------------------------------------------------------*\ 00002 ========= | 00003 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox 00004 \\ / O peration | 00005 \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd. 00006 \\/ M anipulation | 00007 ------------------------------------------------------------------------------- 00008 License 00009 This file is part of OpenFOAM. 00010 00011 OpenFOAM is free software: you can redistribute it and/or modify it 00012 under the terms of the GNU General Public License as published by 00013 the Free Software Foundation, either version 3 of the License, or 00014 (at your option) any later version. 00015 00016 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT 00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00018 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00019 for more details. 00020 00021 You should have received a copy of the GNU General Public License 00022 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. 00023 00024 Application 00025 surfaceSmooth 00026 00027 Description 00028 Example of simple laplacian smoother 00029 00030 Usage 00031 00032 - surfaceSmooth [OPTIONS] <Foam surface file> <underrelaxation factor (0..1)> <iterations> <Foam output surface file> 00033 00034 @param <Foam surface file> \n 00035 @todo Detailed description of argument. 00036 00037 @param <underrelaxation factor (0..1)> \n 00038 @todo Detailed description of argument. 00039 00040 @param <iterations> \n 00041 @todo Detailed description of argument. 00042 00043 @param <Foam output surface file> \n 00044 @todo Detailed description of argument. 00045 00046 @param -help \n 00047 Display help message. 00048 00049 @param -doc \n 00050 Display Doxygen API documentation page for this application. 00051 00052 @param -srcDoc \n 00053 Display Doxygen source documentation page for this application. 00054 00055 \*---------------------------------------------------------------------------*/ 00056 00057 #include <triSurface/triSurface.H> 00058 #include <OpenFOAM/argList.H> 00059 #include <OpenFOAM/OFstream.H> 00060 #include <OpenFOAM/boundBox.H> 00061 00062 using namespace Foam; 00063 00064 00065 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // 00066 // Main program: 00067 00068 int main(int argc, char *argv[]) 00069 { 00070 argList::noParallel(); 00071 argList::validOptions.clear(); 00072 argList::validArgs.clear(); 00073 argList::validArgs.append("surface file"); 00074 argList::validArgs.append("underrelax factor (0..1)"); 00075 argList::validArgs.append("iterations"); 00076 argList::validArgs.append("output file"); 00077 argList args(argc, argv); 00078 00079 fileName surfFileName(args.additionalArgs()[0]); 00080 scalar relax(readScalar(IStringStream(args.additionalArgs()[1])())); 00081 if ((relax <= 0) || (relax > 1)) 00082 { 00083 FatalErrorIn(args.executable()) << "Illegal relaxation factor " 00084 << relax << endl 00085 << "0: no change 1: move vertices to average of neighbours" 00086 << exit(FatalError); 00087 } 00088 label iters(readLabel(IStringStream(args.additionalArgs()[2])())); 00089 fileName outFileName(args.additionalArgs()[3]); 00090 00091 Info<< "Relax:" << relax << endl; 00092 Info<< "Iters:" << iters << endl; 00093 00094 00095 Info<< "Reading surface from " << surfFileName << " ..." << endl; 00096 00097 triSurface surf1(surfFileName); 00098 00099 Info<< "Triangles : " << surf1.size() << endl; 00100 Info<< "Vertices : " << surf1.nPoints() << endl; 00101 Info<< "Bounding Box : " << boundBox(surf1.localPoints()) << endl; 00102 00103 pointField newPoints(surf1.localPoints()); 00104 00105 const labelListList& pointEdges = surf1.pointEdges(); 00106 00107 00108 for(label iter = 0; iter < iters; iter++) 00109 { 00110 forAll(pointEdges, vertI) 00111 { 00112 vector avgPos(vector::zero); 00113 00114 const labelList& myEdges = pointEdges[vertI]; 00115 00116 forAll(myEdges, myEdgeI) 00117 { 00118 const edge& e = surf1.edges()[myEdges[myEdgeI]]; 00119 00120 label otherVertI = e.otherVertex(vertI); 00121 00122 avgPos += surf1.localPoints()[otherVertI]; 00123 } 00124 avgPos /= myEdges.size(); 00125 00126 newPoints[vertI] = (1-relax)*newPoints[vertI] + relax*avgPos; 00127 } 00128 } 00129 00130 triSurface surf2 00131 ( 00132 surf1.localFaces(), 00133 surf1.patches(), 00134 newPoints 00135 ); 00136 00137 Info<< "Writing surface to " << outFileName << " ..." << endl; 00138 00139 surf2.write(outFileName); 00140 00141 Info << "End\n" << endl; 00142 00143 return 0; 00144 } 00145 00146 00147 // ************************ vim: set sw=4 sts=4 et: ************************ //