subsetToPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  Creates surface patches from surface subsets
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "argList.H"
30 #include "triSurf.H"
31 #include "demandDrivenData.H"
32 
33 using namespace Foam;
34 
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
36 
38 (
39  triSurf& origSurf,
40  const DynList<word>& subsetNames
41 )
42 {
43  //- create new list of patches
44  geometricSurfacePatchList newPatches
45  (
46  origSurf.patches().size() + subsetNames.size()
47  );
48 
49  //- set names of the new patches
50  forAll(origSurf.patches(), patchI)
51  newPatches[patchI].name() = origSurf.patches()[patchI].name();
52 
53  forAll(subsetNames, subsetI)
54  newPatches[origSurf.patches().size()+subsetI].name() =
55  subsetNames[subsetI];
56 
57  //- create new triangles
58  LongList<labelledTri> newTriangles(origSurf.facets());
59 
60  //- set patches for all triangles
61  forAll(subsetNames, subsetI)
62  {
63  const label subsetID = origSurf.facetSubsetIndex(subsetNames[subsetI]);
64 
65  labelLongList subsetFaces;
66  origSurf.facetsInSubset(subsetID, subsetFaces);
67 
68  const label regionI = origSurf.patches().size() + subsetI;
69 
70  forAll(subsetFaces, fI)
71  {
72  newTriangles[subsetFaces[fI]].region() = regionI;
73  }
74  }
75 
76  //- remove patches with no elements
77  labelList nTrianglesInPatch(newPatches.size(), 0);
78  forAll(newTriangles, triI)
79  ++nTrianglesInPatch[newTriangles[triI].region()];
80 
81  Map<label> newPatchLabel;
82  label counter(0);
83  forAll(nTrianglesInPatch, patchI)
84  {
85  if( nTrianglesInPatch[patchI] )
86  newPatchLabel.insert(patchI, counter++);
87  }
88 
89  geometricSurfacePatchList copyPatches(counter);
90  counter = 0;
91  forAll(newPatches, patchI)
92  {
93  if( newPatchLabel.found(patchI) )
94  {
95  copyPatches[newPatchLabel[patchI]].name() =
96  newPatches[patchI].name();
97  }
98  }
99 
100  newPatches = copyPatches;
101 
102  //- renumber the patches in the list of triangles
103  forAll(newTriangles, triI)
104  newTriangles[triI].region() =
105  newPatchLabel[newTriangles[triI].region()];
106 
107  //- delete subsets converted to patches
108  forAll(subsetNames, subsetI)
109  {
110  const label subsetID = origSurf.facetSubsetIndex(subsetNames[subsetI]);
111  origSurf.removeFacetSubset(subsetID);
112  }
113 
114  //- update subsets
115  origSurf.updateFacetsSubsets(newPatchLabel);
116 }
117 
118 
119 int main(int argc, char *argv[])
120 {
122  argList::validArgs.clear();
123 
124  argList::validArgs.append("input surface file");
125  argList::validArgs.append("subset");
126  argList args(argc, argv);
127 
128  fileName inFileName(args.args()[1]);
129  word subsetName(args.args()[2]);
130 
131  triSurf* origSurfPtr = new triSurf(inFileName);
132 
133  DynList<word> subsetNames;
134  const label subsetID = origSurfPtr->facetSubsetIndex(subsetName);
135  if( subsetID >= 0 )
136  {
137  Warning << "Subset " << subsetName
138  << " checking subsets containing this string!" << endl;
139 
140  DynList<label> existingSubsets;
141  origSurfPtr->facetSubsetIndices(existingSubsets);
142 
143  forAll(existingSubsets, subsetI)
144  {
145  const word sName =
146  origSurfPtr->facetSubsetName(existingSubsets[subsetI]);
147 
148  if( sName.substr(0, subsetName.size()) == subsetName )
149  {
150  subsetNames.append(sName);
151  }
152  }
153 
154  Info << "Converting " << subsetNames.size() << " subsets" << endl;
155  }
156  else
157  {
158  subsetNames.append(subsetName);
159  }
160 
161  makePatchFromSubset(*origSurfPtr, subsetNames);
162  origSurfPtr->writeSurface(inFileName);
163  deleteDemandDrivenData(origSurfPtr);
164 
165  Info << "End\n" << endl;
166  return 0;
167 }
168 
169 // ************************************************************************* //
Foam::argList::validArgs
static SLList< string > validArgs
A list of valid (mandatory) arguments.
Definition: argList.H:143
triSurf.H
Foam::word
A class for handling words, derived from string.
Definition: word.H:59
Foam::argList::args
const stringList & args() const
Return arguments.
Definition: argListI.H:66
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::Warning
messageStream Warning
Foam::Map< label >
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
labelLongList
This is a typedef for LongList<label>
Foam::LongList
Definition: LongList.H:55
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::triSurfFacets::removeFacetSubset
void removeFacetSubset(const label)
Definition: triSurfFacets.C:127
Foam::label
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
Foam::Info
messageStream Info
argList.H
Foam::triSurfFacets::patches
const geometricSurfacePatchList & patches() const
access to patches
Definition: triSurfFacetsI.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynList
Definition: DynList.H:53
Foam::triSurfFacets::facetSubsetIndices
void facetSubsetIndices(DynList< label > &) const
Definition: triSurfFacetsI.H:105
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::triSurf::writeSurface
void writeSurface(const fileName &) const
Definition: triSurf.C:430
Foam::triSurfFacets::updateFacetsSubsets
void updateFacetsSubsets(const ListType &)
Definition: triSurfFacetsI.H:135
Foam::triSurfFacets::facets
const LongList< labelledTri > & facets() const
access to facets
Definition: triSurfFacetsI.H:44
Foam::triSurfFacets::facetSubsetName
word facetSubsetName(const label) const
Definition: triSurfFacets.C:135
Foam::DynList::size
label size() const
Definition: DynListI.H:235
Foam::triSurfFacets::facetSubsetIndex
label facetSubsetIndex(const word &) const
Definition: triSurfFacets.C:147
Foam::triSurfFacets::facetsInSubset
void facetsInSubset(const label, ListType &) const
Definition: triSurfFacetsI.H:120
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::argList::noParallel
static void noParallel()
Remove the parallel options.
Definition: argList.C:161
main
int main(int argc, char *argv[])
Definition: subsetToPatch.C:119
args
Foam::argList args(argc, argv)
Foam::triSurf
Definition: triSurf.H:59
makePatchFromSubset
void makePatchFromSubset(triSurf &origSurf, const DynList< word > &subsetNames)
Definition: subsetToPatch.C:38
Foam::DynList::append
void append(const T &e)
Append an element at the end of the list.
Definition: DynListI.H:304