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

surfaceSplitByPatch.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 Description
00026     Writes regions of triSurface to separate files.
00027 
00028 \*---------------------------------------------------------------------------*/
00029 
00030 #include "argList.H"
00031 #include "triSurface.H"
00032 
00033 using namespace Foam;
00034 
00035 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00036 // Main program:
00037 
00038 int main(int argc, char *argv[])
00039 {
00040     argList::noParallel();
00041     argList::validArgs.clear();
00042     argList::validArgs.append("input file");
00043     argList::argList args(argc, argv);
00044 
00045     fileName surfName(args.additionalArgs()[0]);
00046 
00047     Info<< "Reading surf from " << surfName << " ..." << nl << endl;
00048 
00049     fileName surfBase = surfName.lessExt();
00050 
00051     word extension = surfName.ext();
00052 
00053     triSurface surf(surfName);
00054 
00055     Info<< "Writing regions to separate files ..."
00056         << nl << endl;
00057 
00058 
00059     const geometricSurfacePatchList& patches = surf.patches();
00060 
00061     forAll(patches, patchI)
00062     {
00063         const geometricSurfacePatch& pp = patches[patchI];
00064 
00065         word patchName = pp.name();
00066 
00067         if (patchName.empty())
00068         {
00069             patchName = "patch" + Foam::name(patchI);
00070         }
00071 
00072         fileName outFile(surfBase + '_' + patchName + '.' + extension);
00073 
00074         Info<< "   Writing patch " << patchName << " to file " << outFile
00075             << endl;
00076 
00077 
00078         // Collect faces of region
00079         boolList includeMap(surf.size(), false);
00080 
00081         forAll(surf, faceI)
00082         {
00083             const labelledTri& f = surf[faceI];
00084 
00085             if (f.region() == patchI)
00086             {
00087                 includeMap[faceI] = true;
00088             }
00089         }
00090 
00091         // Subset triSurface
00092         labelList pointMap;
00093         labelList faceMap;
00094 
00095         triSurface subSurf
00096         (
00097             surf.subsetMesh
00098             (
00099                 includeMap,
00100                 pointMap,
00101                 faceMap
00102             )
00103         );
00104 
00105         subSurf.write(outFile);
00106     }
00107 
00108 
00109     Info << "End\n" << endl;
00110 
00111     return 0;
00112 }
00113 
00114 
00115 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd