1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
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.
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
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/>.
26 \*---------------------------------------------------------------------------*/
28 #include "triSurfacePatchManipulator.H"
29 #include "helperFunctions.H"
30 #include "demandDrivenData.H"
31 #include "checkMeshDict.H"
35 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 triSurfacePatchManipulator::triSurfacePatchManipulator(const triSurf& surface)
45 featureEdges_(surf_.edges().size(), direction(0)),
51 allocateFeatureEdges();
56 triSurfacePatchManipulator::~triSurfacePatchManipulator()
59 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
61 void triSurfacePatchManipulator::detectedSurfaceRegions
66 graph.setSize(nPatches_);
68 labelLongList nFacetsInPatch(nPatches_, 0);
70 forAll(facetInPatch_, triI)
71 ++nFacetsInPatch[facetInPatch_[triI]];
73 graph.setSizeAndRowSize(nFacetsInPatch);
76 forAll(facetInPatch_, triI)
78 const label patchI = facetInPatch_[triI];
80 graph(patchI, nFacetsInPatch[patchI]) = triI;
81 ++nFacetsInPatch[patchI];
85 const triSurf* triSurfacePatchManipulator::surfaceWithPatches
87 IOdictionary* meshDictPtr,
89 const bool forceOverwrite
92 //- collect patch information
93 VRWGraph facetsInPatch;
94 detectedSurfaceRegions(facetsInPatch);
96 //- create new list of boundary patches
97 LongList<labelledTri> newTriangles(facetInPatch_.size());
99 geometricSurfacePatchList newPatches(nPatches_);
103 forAll(newPatches, patchI)
105 newPatches[patchI].name() = prefix+help::scalarToText(patchI);
106 newPatches[patchI].geometricType() = "patch";
107 newPatches[patchI].index() = patchI;
112 forAll(facetsInPatch, patchI)
114 forAllRow(facetsInPatch, patchI, fpI)
116 const label origPatchI =
117 surf_[facetsInPatch(patchI, fpI)].region();
118 newPatches[patchI].name() =
119 surf_.patches()[origPatchI].name() + '_' +
120 help::scalarToText(patchI);
121 newPatches[patchI].geometricType() =
122 surf_.patches()[origPatchI].geometricType();
123 newPatches[patchI].index() = patchI;
128 //- create triangles for the new surface
129 labelLongList newFacetLabel(newTriangles.size(), -1);
131 forAll(facetsInPatch, patchI)
132 forAllRow(facetsInPatch, patchI, tI)
134 newFacetLabel[facetsInPatch(patchI, tI)] = counter;
135 labelledTri tria = surf_[facetsInPatch(patchI, tI)];
136 tria.region() = patchI;
137 newTriangles[counter++] = tria;
140 //- create and return a new surface mesh
141 triSurf* newSurfPtr =
150 //- transfer facet subsets
151 DynList<label> subsetIDs;
152 surf_.facetSubsetIndices(subsetIDs);
153 forAll(subsetIDs, subsetI)
155 const word sName = surf_.facetSubsetName(subsetIDs[subsetI]);
157 const label newID = newSurfPtr->addFacetSubset(sName);
159 labelLongList facetsInSubset;
160 surf_.facetsInSubset(subsetIDs[subsetI], facetsInSubset);
162 forAll(facetsInSubset, i)
164 const label fI = newFacetLabel[facetsInSubset[i]];
166 newSurfPtr->addFacetToSubset(newID, fI);
170 //- transfer point subsets
171 surf_.pointSubsetIndices(subsetIDs);
172 forAll(subsetIDs, subsetI)
174 const word sName = surf_.pointSubsetName(subsetIDs[subsetI]);
176 const label newID = newSurfPtr->addPointSubset(sName);
178 labelLongList pointsInSubset;
179 surf_.pointsInSubset(subsetIDs[subsetI], pointsInSubset);
181 forAll(pointsInSubset, i)
182 newSurfPtr->addPointToSubset(newID, pointsInSubset[i]);
187 //- create mapping between the patches on the original surface
188 //- and the renamed patches
189 std::map<word, wordList> patchesForPatch;
190 std::map<word, word> patchTypes;
192 const geometricSurfacePatchList& origPatches = surf_.patches();
193 forAll(origPatches, patchI)
194 patchTypes[origPatches[patchI].name()] =
195 origPatches[patchI].geometricType();
197 //- find the mapping of patch ids
198 List<labelHashSet> patchToNewPatches(origPatches.size());
199 forAll(facetsInPatch, patchI)
201 forAllRow(facetsInPatch, patchI, fI)
203 const label opatchI = surf_[facetsInPatch(patchI, fI)].region();
205 patchToNewPatches[opatchI].insert(patchI);
209 forAll(patchToNewPatches, patchI)
211 const word& pName = origPatches[patchI].name();
212 patchesForPatch[pName].setSize
214 patchToNewPatches[patchI].size()
219 forAllConstIter(labelHashSet, patchToNewPatches[patchI], it)
220 patchesForPatch[pName][counter++] = newPatches[it.key()].name();
223 //- update the values in meshDict based on the created patches
224 checkMeshDict(*meshDictPtr).updateDictionaries
234 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
236 } // End namespace Foam
238 // ************************************************************************* //