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-2013 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 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeFast.C:90
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addNote
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:139
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::geometricSurfacePatch
The geometricSurfacePatch is like patchIdentifier but for surfaces. Holds type, name and index.
Definition: geometricSurfacePatch.H:53
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::fileName::lessExt
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:313
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
main
int main(int argc, char *argv[])
Definition: postCalc.C:54
Foam::fileName::ext
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:329
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
f
labelList f(nPoints)
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::labelledTri
Triangle with additional region number.
Definition: labelledTri.H:49
patches
patches[0]
Definition: createSingleCellMesh.H:36
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
args
Foam::argList args(argc, argv)
Foam::geometricSurfacePatch::name
const word & name() const
Return name.
Definition: geometricSurfacePatch.H:101
Foam::name
word name(const complex &)
Return a string representation of a complex.
Definition: complex.C:47