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) 2011-2016 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
31 
32 #include "argList.H"
33 #include "triSurface.H"
34 
35 using namespace Foam;
36 
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 
39 int main(int argc, char *argv[])
40 {
42  (
43  "write surface mesh regions to separate files"
44  );
45 
47  argList::validArgs.append("input surfaceFile");
48  argList args(argc, argv);
49 
50  const fileName surfName = args[1];
51 
52  Info<< "Reading surf from " << surfName << " ..." << nl << endl;
53 
54  fileName surfBase = surfName.lessExt();
55 
56  word extension = surfName.ext();
57 
58  triSurface surf(surfName);
59 
60  Info<< "Writing regions to separate files ..."
61  << nl << endl;
62 
63 
64  const geometricSurfacePatchList& patches = surf.patches();
65 
66  forAll(patches, patchi)
67  {
68  const geometricSurfacePatch& pp = patches[patchi];
69 
70  word patchName = pp.name();
71 
72  if (patchName.empty())
73  {
74  patchName = "patch" + Foam::name(patchi);
75  }
76 
77  fileName outFile(surfBase + '_' + patchName + '.' + extension);
78 
79  Info<< " Writing patch " << patchName << " to file " << outFile
80  << endl;
81 
82 
83  // Collect faces of region
84  boolList includeMap(surf.size(), false);
85 
86  forAll(surf, facei)
87  {
88  const labelledTri& f = surf[facei];
89 
90  if (f.region() == patchi)
91  {
92  includeMap[facei] = true;
93  }
94  }
95 
96  // Subset triSurface
97  labelList pointMap;
99 
100  triSurface subSurf
101  (
102  surf.subsetMesh
103  (
104  includeMap,
105  pointMap,
106  faceMap
107  )
108  );
109 
110  subSurf.write(outFile);
111  }
112 
113  Info<< "End\n" << endl;
114 
115  return 0;
116 }
117 
118 
119 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
A class for handling file names.
Definition: fileName.H:69
label region() const
Return region label.
Definition: labelledTriI.H:68
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
static void noParallel()
Remove the parallel options.
Definition: argList.C:146
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:154
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
A class for handling words, derived from string.
Definition: word.H:59
Extract command arguments and options from the supplied argc and argv parameters. ...
Definition: argList.H:102
Triangle with additional region number.
Definition: labelledTri.H:57
const word & name() const
Return name.
static const char nl
Definition: Ostream.H:262
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:268
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47
label patchi
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:283
The geometricSurfacePatch is like patchIdentifier but for surfaces. Holds type, name and index...
messageStream Info
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:124
Triangulated surface description with patch information.
Definition: triSurface.H:65
Foam::argList args(argc, argv)
Namespace for OpenFOAM.