surfaceSplitByTopology.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 Description
25 
26  Strips any baffle parts of a surface. A baffle region is one which is
27  reached by walking from an open edge, and stopping when a multiply connected
28  edge is reached.
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 
43  argList::validOptions.clear();
44  argList::validArgs.append("surface file");
45  argList::validArgs.append("output surface file");
46  argList args(argc, argv);
47 
48  fileName surfFileName(args[1]);
49  Info<< "Reading surface from " << surfFileName << endl;
50 
51  fileName outFileName(args[2]);
52  fileName outFileBaseName = outFileName.lessExt();
53  word outExtension = outFileName.ext();
54 
55  // Load surface
56  triSurface surf(surfFileName);
57 
58  bool anyZoneRemoved = false;
59 
60  label iterationNo = 0;
61  label iterationLimit = 10;
62 
63  Info<< "Splitting off baffle parts " << endl;
64 
65  do
66  {
67  anyZoneRemoved = false;
68 
70 
71  const labelListList& edFaces = surf.edgeFaces();
72  const labelListList& faceEds = surf.faceEdges();
73 
74  boolList multipleEdges(edFaces.size(), false);
75 
76  forAll(multipleEdges, i)
77  {
78  if (edFaces[i].size() > 2)
79  {
80  multipleEdges[i] = true;
81  }
82  }
83 
84  label nZones = surf.markZones(multipleEdges, faceZone);
85 
86  if (nZones < 2)
87  {
88  break;
89  }
90 
91  boolList nonBaffle(faceZone.size(), true);
92  boolList baffle(faceZone.size(), true);
93  labelList pointMap;
95 
96 
97  for (label z = 0; z < nZones; z++)
98  {
99  bool keepZone = true;
100 
101  forAll(faceZone, f)
102  {
103  if (faceZone[f] == z)
104  {
105  forAll(faceEds[f], fe)
106  {
107  if (edFaces[faceEds[f][fe]].size() < 2)
108  {
109  keepZone = false;
110 
111  anyZoneRemoved = true;
112 
113  break;
114  }
115  }
116  }
117 
118  if (!keepZone)
119  {
120  break;
121  }
122  }
123 
124  forAll(faceZone, f)
125  {
126  if (faceZone[f] == z)
127  {
128  nonBaffle[f] = keepZone;
129  baffle[f] = !keepZone;
130  }
131  }
132  }
133 
134  Info<< " Iteration " << iterationNo << endl;
135 
136  triSurface baffleSurf = surf.subsetMesh(baffle, pointMap, faceMap);
137 
138  if (baffleSurf.size())
139  {
140  fileName bafflePartFileName =
141  outFileBaseName
142  + "_bafflePart_"
143  + name(iterationNo)
144  + "." + outExtension;
145 
146  Info<< " Writing baffle part to " << bafflePartFileName << endl;
147 
148  baffleSurf.write(bafflePartFileName);
149  }
150 
151  surf = surf.subsetMesh(nonBaffle, pointMap, faceMap);
152 
153  if (iterationNo == iterationLimit)
154  {
156  << "Iteration limit of " << iterationLimit << "reached" << endl;
157  }
158 
159  iterationNo++;
160 
161  } while (anyZoneRemoved && iterationNo < iterationLimit);
162 
163  Info<< "Writing new surface to " << outFileName << endl;
164 
165  surf.write(outFileName);
166 
168 
169  const labelListList& edFaces = surf.edgeFaces();
170 
171  boolList multipleEdges(edFaces.size(), false);
172 
173  forAll(multipleEdges, i)
174  {
175  if (edFaces[i].size() > 2)
176  {
177  multipleEdges[i] = true;
178  }
179  }
180 
181  label nZones = surf.markZones(multipleEdges, faceZone);
182 
183  Info<< "Splitting remaining multiply connected parts" << endl;
184 
185  for (label z = 0; z < nZones; z++)
186  {
187 
188  boolList include(faceZone.size(), false);
189  labelList pointMap;
191 
192  forAll(faceZone, f)
193  {
194  if (faceZone[f] == z)
195  {
196  include[f] = true;
197  }
198  }
199 
200  triSurface zoneSurf = surf.subsetMesh(include, pointMap, faceMap);
201 
202 
203  fileName remainingPartFileName =
204  outFileBaseName
205  + "_multiplePart_"
206  + name(z)
207  + "." + outExtension;
208 
209  Info<< " Writing multiple part "
210  << z << " to " << remainingPartFileName << endl;
211 
212  zoneSurf.write(remainingPartFileName);
213  }
214 
215  Info << "End\n" << endl;
216 
217  return 0;
218 }
219 
220 
221 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
virtual Ostream & write(const char)=0
Write character.
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:103
static HashTable< string > validOptions
A list of valid options.
Definition: argList.H:156
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:153
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:68
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
Triangulated surface description with patch information.
Definition: triSurface.H:69
triSurface subsetMesh(const boolList &include, labelList &pointMap, labelList &faceMap) const
Return new surface. Returns pointMap, faceMap from.
Definition: triSurface.C:1089
A class for handling words, derived from string.
Definition: word.H:62
int main(int argc, char *argv[])
Definition: financialFoam.C:44
#define WarningInFunction
Report a warning using Foam::Warning.
Namespace for OpenFOAM.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
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)
labelList f(nPoints)
Foam::argList args(argc, argv)