1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
25 Creates surface patches from surface subsets
27 \*---------------------------------------------------------------------------*/
30 #include "objectRegistry.H"
33 #include "demandDrivenData.H"
37 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
39 void makePatchFromSubset
42 const DynList<word>& subsetNames
45 //- create new list of patches
46 geometricSurfacePatchList newPatches
48 origSurf.patches().size() + subsetNames.size()
51 //- set names of the new patches
52 forAll(origSurf.patches(), patchI)
53 newPatches[patchI].name() = origSurf.patches()[patchI].name();
55 forAll(subsetNames, subsetI)
56 newPatches[origSurf.patches().size()+subsetI].name() =
59 //- create new triangles
60 LongList<labelledTri> newTriangles(origSurf.facets());
62 //- set patches for all triangles
63 forAll(subsetNames, subsetI)
65 const label subsetID = origSurf.facetSubsetIndex(subsetNames[subsetI]);
67 labelLongList subsetFaces;
68 origSurf.facetsInSubset(subsetID, subsetFaces);
70 const label regionI = origSurf.patches().size() + subsetI;
72 forAll(subsetFaces, fI)
74 newTriangles[subsetFaces[fI]].region() = regionI;
78 //- remove patches with no elements
79 labelList nTrianglesInPatch(newPatches.size(), 0);
80 forAll(newTriangles, triI)
81 ++nTrianglesInPatch[newTriangles[triI].region()];
83 Map<label> newPatchLabel;
85 forAll(nTrianglesInPatch, patchI)
87 if( nTrianglesInPatch[patchI] )
88 newPatchLabel.insert(patchI, counter++);
91 geometricSurfacePatchList copyPatches(counter);
93 forAll(newPatches, patchI)
95 if( newPatchLabel.found(patchI) )
97 copyPatches[newPatchLabel[patchI]].name() =
98 newPatches[patchI].name();
102 newPatches = copyPatches;
104 //- renumber the patches in the list of triangles
105 forAll(newTriangles, triI)
106 newTriangles[triI].region() =
107 newPatchLabel[newTriangles[triI].region()];
109 //- delete subsets converted to patches
110 forAll(subsetNames, subsetI)
112 const label subsetID = origSurf.facetSubsetIndex(subsetNames[subsetI]);
113 origSurf.removeFacetSubset(subsetID);
117 origSurf.updateFacetsSubsets(newPatchLabel);
121 int main(int argc, char *argv[])
123 argList::noParallel();
124 argList::validArgs.clear();
126 argList::validArgs.append("input surface file");
127 argList::validArgs.append("subset");
128 argList args(argc, argv);
130 fileName inFileName(args.args()[1]);
131 word subsetName(args.args()[2]);
133 triSurf* origSurfPtr = new triSurf(inFileName);
135 DynList<word> subsetNames;
136 const label subsetID = origSurfPtr->facetSubsetIndex(subsetName);
139 Warning << "Subset " << subsetName
140 << " checking subsets containing this string!" << endl;
142 DynList<label> existingSubsets;
143 origSurfPtr->facetSubsetIndices(existingSubsets);
145 forAll(existingSubsets, subsetI)
148 origSurfPtr->facetSubsetName(existingSubsets[subsetI]);
150 if( sName.substr(0, subsetName.size()) == subsetName )
152 subsetNames.append(sName);
156 Info << "Converting " << subsetNames.size() << " subsets" << endl;
160 subsetNames.append(subsetName);
163 makePatchFromSubset(*origSurfPtr, subsetNames);
164 origSurfPtr->writeSurface(inFileName);
165 deleteDemandDrivenData(origSurfPtr);
167 Info << "End\n" << endl;
171 // ************************************************************************* //