surfaceSplitByPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 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 {
41  #include "removeCaseOptions.H"
42 
44  (
45  "write surface mesh regions to separate files"
46  );
47 
48  argList::validArgs.append("surface file");
49  argList args(argc, argv);
50 
51  const fileName surfName = args[1];
52 
53  Info<< "Reading surf from " << surfName << " ..." << nl << endl;
54 
55  fileName surfBase = surfName.lessExt();
56 
57  word extension = surfName.ext();
58 
59  triSurface surf(surfName);
60 
61  Info<< "Writing regions to separate files ..."
62  << nl << endl;
63 
64 
65  const geometricSurfacePatchList& patches = surf.patches();
66 
68  {
70 
71  word patchName = pp.name();
72 
73  if (patchName.empty())
74  {
75  patchName = "patch" + Foam::name(patchi);
76  }
77 
78  fileName outFile(surfBase + '_' + patchName + '.' + extension);
79 
80  Info<< " Writing patch " << patchName << " to file " << outFile
81  << endl;
82 
83 
84  // Collect faces of region
85  boolList includeMap(surf.size(), false);
86 
87  forAll(surf, facei)
88  {
89  const labelledTri& f = surf[facei];
90 
91  if (f.region() == patchi)
92  {
93  includeMap[facei] = true;
94  }
95  }
96 
97  // Subset triSurface
98  labelList pointMap;
100 
101  triSurface subSurf
102  (
103  surf.subsetMesh
104  (
105  includeMap,
106  pointMap,
107  faceMap
108  )
109  );
110 
111  subSurf.write(outFile);
112  }
113 
114  Info<< "End\n" << endl;
115 
116  return 0;
117 }
118 
119 
120 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
static void addNote(const string &)
Add extra notes for the usage information.
Definition: argList.C:159
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
A class for handling file names.
Definition: fileName.H:82
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileName.C:284
word ext() const
Return file name extension (part after last .)
Definition: fileName.C:299
The geometricSurfacePatch is like patchIdentifier but for surfaces. Holds type, name and index.
const word & name() const
Return name.
Triangle with additional region number.
Definition: labelledTri.H:60
Triangulated surface description with patch information.
Definition: triSurface.H:69
A class for handling words, derived from string.
Definition: word.H:62
int main(int argc, char *argv[])
Definition: financialFoam.C:44
label patchi
const fvPatchList & patches
Namespace for OpenFOAM.
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
word name(const bool)
Return a word representation of a bool.
Definition: boolIO.C:39
messageStream Info
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
static const char nl
Definition: Ostream.H:260
labelList f(nPoints)
Foam::argList args(argc, argv)