OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

surfaceAutoPatch.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 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 the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     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, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Application
00026     surfaceAutoPatch
00027 
00028 Description
00029     Patches surface according to feature angle. Like autoPatch.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "triangle.H"
00034 #include "triSurface.H"
00035 #include "argList.H"
00036 #include "surfaceFeatures.H"
00037 #include "treeBoundBox.H"
00038 #include "meshTools.H"
00039 #include "OFstream.H"
00040 
00041 using namespace Foam;
00042 
00043 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00044 
00045 // Main program:
00046 
00047 int main(int argc, char *argv[])
00048 {
00049     argList::noParallel();
00050     argList::validArgs.clear();
00051     argList::validArgs.append("input surface file");
00052     argList::validArgs.append("output surface file");
00053     argList::validArgs.append("included angle [0..180]");
00054     argList args(argc, argv);
00055 
00056     fileName inFileName(args.additionalArgs()[0]);
00057     fileName outFileName(args.additionalArgs()[1]);
00058     scalar includedAngle(readScalar(IStringStream(args.additionalArgs()[2])()));
00059 
00060     Pout<< "Surface        : " << inFileName << nl
00061         << endl;
00062 
00063 
00064     // Read
00065     // ~~~~
00066 
00067     Info << "Reading : " << inFileName << endl;
00068     triSurface surf(inFileName);
00069 
00070     Info<< "Read surface:" << endl;
00071     surf.writeStats(Info);
00072     Info<< endl;
00073     
00074 
00075 
00076     // Construct features from surface&featureangle
00077     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00078 
00079     Info<< "Constructing feature set from included angle " << includedAngle
00080         << endl;
00081 
00082     surfaceFeatures set(surf, includedAngle);
00083 
00084     Pout<< nl
00085         << "Feature set:" << nl
00086         << "    feature points : " << set.featurePoints().size() << nl
00087         << "    feature edges  : " << set.featureEdges().size() << nl
00088         << "    of which" << nl
00089         << "        region edges   : " << set.nRegionEdges() << nl
00090         << "        external edges : " << set.nExternalEdges() << nl
00091         << "        internal edges : " << set.nInternalEdges() << nl
00092         << endl;
00093 
00094     // Get per-edge status.
00095     boolList borderEdge(surf.nEdges(), false);
00096     forAll(set.featureEdges(), i)
00097     {
00098         borderEdge[set.featureEdges()[i]] = true;
00099     }
00100 
00101     labelList faceRegion(surf.size());
00102     label nRegions = surf.markZones(borderEdge, faceRegion);
00103 
00104     // Reregion triangles.
00105     forAll(surf, i)
00106     {
00107         surf[i].region() = faceRegion[i];
00108     }
00109 
00110     // Create some patches
00111     surf.patches().setSize(nRegions);
00112 
00113     forAll(surf.patches(), patchI)
00114     {
00115         surf.patches()[patchI].name() = "patch" + Foam::name(patchI);
00116         surf.patches()[patchI].geometricType() = "empty";
00117     }
00118 
00119 
00120     Info << "Writing : " << outFileName << endl;
00121     surf.write(outFileName, true);
00122 
00123     Info<< "End\n" << endl;
00124 
00125     return 0;
00126 }
00127 
00128 
00129 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd