surfaceSplitByTopology.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Application
27  surfaceSplitByTopology
28 
29 Group
30  grpSurfaceUtilities
31 
32 Description
33  Strips any baffle parts of a surface.
34 
35  A baffle region is one which is reached by walking from an open edge, and
36  stopping when a multiply connected edge is reached.
37 
38 \*---------------------------------------------------------------------------*/
39 
40 #include "argList.H"
41 #include "triSurface.H"
42 
43 using namespace Foam;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 
47 int main(int argc, char *argv[])
48 {
50  (
51  "Strips any baffle parts of a surface.\n"
52  "A baffle region is one which is reached by walking from an open edge,"
53  " and stopping when a multiply connected edge is reached."
54  );
55 
57  argList::validOptions.clear();
58  argList::addArgument("input", "The input surface file");
59  argList::addArgument("output", "The output surface file");
60  argList args(argc, argv);
61 
62  fileName surfFileName(args[1]);
63  Info<< "Reading surface from " << surfFileName << endl;
64 
65  fileName outFileName(args[2]);
66  fileName outFileBaseName = outFileName.lessExt();
67  word outExtension = outFileName.ext();
68 
69  // Load surface
70  triSurface surf(surfFileName);
71 
72  bool anyZoneRemoved = false;
73 
74  label iterationNo = 0;
75  label iterationLimit = 10;
76 
77  Info<< "Splitting off baffle parts " << endl;
78 
79  do
80  {
81  anyZoneRemoved = false;
82 
84 
85  const labelListList& edFaces = surf.edgeFaces();
86  const labelListList& faceEds = surf.faceEdges();
87 
88  boolList multipleEdges(edFaces.size(), false);
89 
90  forAll(multipleEdges, i)
91  {
92  if (edFaces[i].size() > 2)
93  {
94  multipleEdges[i] = true;
95  }
96  }
97 
98  label nZones = surf.markZones(multipleEdges, faceZone);
99 
100  if (nZones < 2)
101  {
102  break;
103  }
104 
105  boolList nonBaffle(faceZone.size(), true);
106  boolList baffle(faceZone.size(), true);
107  labelList pointMap;
109 
110 
111  for (label z = 0; z < nZones; z++)
112  {
113  bool keepZone = true;
114 
115  forAll(faceZone, f)
116  {
117  if (faceZone[f] == z)
118  {
119  forAll(faceEds[f], fe)
120  {
121  if (edFaces[faceEds[f][fe]].size() < 2)
122  {
123  keepZone = false;
124 
125  anyZoneRemoved = true;
126 
127  break;
128  }
129  }
130  }
131 
132  if (!keepZone)
133  {
134  break;
135  }
136  }
137 
138  forAll(faceZone, f)
139  {
140  if (faceZone[f] == z)
141  {
142  nonBaffle[f] = keepZone;
143  baffle[f] = !keepZone;
144  }
145  }
146  }
147 
148  Info<< " Iteration " << iterationNo << endl;
149 
150  triSurface baffleSurf = surf.subsetMesh(baffle, pointMap, faceMap);
151 
152  if (baffleSurf.size())
153  {
154  fileName bafflePartFileName =
155  outFileBaseName
156  + "_bafflePart_"
157  + name(iterationNo)
158  + "." + outExtension;
159 
160  Info<< " Writing baffle part to " << bafflePartFileName << endl;
161 
162  baffleSurf.write(bafflePartFileName);
163  }
164 
165  surf = surf.subsetMesh(nonBaffle, pointMap, faceMap);
166 
167  if (iterationNo == iterationLimit)
168  {
170  << "Iteration limit of " << iterationLimit << "reached" << endl;
171  }
172 
173  iterationNo++;
174 
175  } while (anyZoneRemoved && iterationNo < iterationLimit);
176 
177  Info<< "Writing new surface to " << outFileName << endl;
178 
179  surf.write(outFileName);
180 
182 
183  const labelListList& edFaces = surf.edgeFaces();
184 
185  boolList multipleEdges(edFaces.size(), false);
186 
187  forAll(multipleEdges, i)
188  {
189  if (edFaces[i].size() > 2)
190  {
191  multipleEdges[i] = true;
192  }
193  }
194 
195  label nZones = surf.markZones(multipleEdges, faceZone);
196 
197  Info<< "Splitting remaining multiply connected parts" << endl;
198 
199  for (label z = 0; z < nZones; z++)
200  {
201  boolList include(faceZone.size(), false);
202 
203  forAll(faceZone, f)
204  {
205  if (faceZone[f] == z)
206  {
207  include[f] = true;
208  }
209  }
210 
211  triSurface zoneSurf = surf.subsetMesh(include);
212 
213  fileName remainingPartFileName =
214  outFileBaseName
215  + "_multiplePart_"
216  + name(z)
217  + "." + outExtension;
218 
219  Info<< " Writing multiple part "
220  << z << " to " << remainingPartFileName << endl;
221 
222  zoneSurf.write(remainingPartFileName);
223  }
224 
225  Info << "End\n" << endl;
226 
227  return 0;
228 }
229 
230 
231 // ************************************************************************* //
nZones
label nZones
Definition: interpolatedFaces.H:24
Foam::triSurface::subsetMesh
triSurface subsetMesh(const UList< bool > &include, labelList &pointMap, labelList &faceMap) const
Return a new surface subsetted on the selected faces.
Definition: triSurface.C:840
Foam::faceMap
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
Definition: blockMeshMergeTopological.C:94
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::argList::addNote
static void addNote(const string &note)
Add extra notes for the usage information.
Definition: argList.C:413
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:123
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::fileName::lessExt
fileName lessExt() const
Return file name without extension (part before last .)
Definition: fileNameI.H:240
Foam::word::ext
word ext() const
Return file name extension (part after last .)
Definition: word.C:126
triSurface.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::argList::addArgument
static void addArgument(const string &argName, const string &usage="")
Append a (mandatory) argument to validArgs.
Definition: argList.C:302
Foam::triSurface::write
void write(Ostream &os) const
Write to Ostream in simple OpenFOAM format.
Definition: triSurfaceIO.C:336
Foam::triSurface
Triangulated surface description with patch information.
Definition: triSurface.H:76
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
argList.H
Foam::argList::validOptions
static HashTable< string > validOptions
A list of valid options.
Definition: argList.H:210
Foam::Ostream::write
virtual bool write(const token &tok)=0
Write token to stream or otherwise handle it.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
f
labelList f(nPoints)
Foam::List< label >
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:491
args
Foam::argList args(argc, argv)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:298