FreeFOAM The Cross-Platform CFD Toolkit
surfaceSplitByPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Application
25  surfaceSplitByPatch
26 
27 Description
28  Writes regions of triSurface to separate files.
29 
30 Usage
31 
32  - surfaceSplitByPatch [OPTIONS] <input file>
33 
34  @param <input file> \n
35  @todo Detailed description of argument.
36 
37  @param -case <dir>\n
38  Case directory.
39 
40  @param -help \n
41  Display help message.
42 
43  @param -doc \n
44  Display Doxygen API documentation page for this application.
45 
46  @param -srcDoc \n
47  Display Doxygen source documentation page for this application.
48 
49 \*---------------------------------------------------------------------------*/
50 
51 #include <OpenFOAM/argList.H>
52 #include <triSurface/triSurface.H>
53 
54 using namespace Foam;
55 
56 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
57 // Main program:
58 
59 int main(int argc, char *argv[])
60 {
63  argList::validArgs.append("input file");
64  argList args(argc, argv);
65 
66  fileName surfName(args.additionalArgs()[0]);
67 
68  Info<< "Reading surf from " << surfName << " ..." << nl << endl;
69 
70  fileName surfBase = surfName.lessExt();
71 
72  word extension = surfName.ext();
73 
74  triSurface surf(surfName);
75 
76  Info<< "Writing regions to separate files ..."
77  << nl << endl;
78 
79 
80  const geometricSurfacePatchList& patches = surf.patches();
81 
82  forAll(patches, patchI)
83  {
84  const geometricSurfacePatch& pp = patches[patchI];
85 
86  word patchName = pp.name();
87 
88  if (patchName.empty())
89  {
90  patchName = "patch" + Foam::name(patchI);
91  }
92 
93  fileName outFile(surfBase + '_' + patchName + '.' + extension);
94 
95  Info<< " Writing patch " << patchName << " to file " << outFile
96  << endl;
97 
98 
99  // Collect faces of region
100  boolList includeMap(surf.size(), false);
101 
102  forAll(surf, faceI)
103  {
104  const labelledTri& f = surf[faceI];
105 
106  if (f.region() == patchI)
107  {
108  includeMap[faceI] = true;
109  }
110  }
111 
112  // Subset triSurface
113  labelList pointMap;
114  labelList faceMap;
115 
116  triSurface subSurf
117  (
118  surf.subsetMesh
119  (
120  includeMap,
121  pointMap,
122  faceMap
123  )
124  );
125 
126  subSurf.write(outFile);
127  }
128 
129 
130  Info << "End\n" << endl;
131 
132  return 0;
133 }
134 
135 
136 // ************************ vim: set sw=4 sts=4 et: ************************ //