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 "renameBoundaryPatches.H"
29 #include "demandDrivenData.H"
30 #include "IOdictionary.H"
34 // #define DEBUGSearch
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 void renameBoundaryPatches::calculateNewBoundary()
45 Info << "Renaming boundary patches" << endl;
47 const dictionary& dict = meshDict_.subDict("renameBoundary");
49 std::map<word, label> patchToLabel;
50 forAll(mesh_.boundaries(), patchI)
54 std::pair<word, label>
56 mesh_.boundaries()[patchI].patchName(),
62 labelList patchToNew(mesh_.boundaries().size(), -1);
64 wordList newPatchNames(patchToNew.size());
65 wordList newPatchTypes(patchToNew.size());
66 std::map<word, label> newNameToPos;
69 //- read new patch names and types
70 if( dict.found("newPatchNames") )
72 PtrList<entry> patchesToRename;
74 if( dict.isDict("newPatchNames") )
76 const dictionary& newPatchNames = dict.subDict("newPatchNames");
77 const wordList keys = newPatchNames.toc();
79 patchesToRename.setSize(keys.size());
85 newPatchNames.lookupEntry
95 PtrList<entry> copyPatchesToRename(dict.lookup("newPatchNames"));
96 patchesToRename.transfer(copyPatchesToRename);
99 forAll(patchesToRename, patchI)
101 const word patchName = patchesToRename[patchI].keyword();
103 const labelList matchedPatches = mesh_.findPatches(patchName);
105 if(matchedPatches.empty())
107 Warning << "No matches for " << patchName << " found!!" << endl;
111 if( !patchesToRename[patchI].isDict() )
113 Warning << "Cannot rename patch " << patchName << endl;
114 Warning << "This is due to incorrect settings! Exitting."
119 const dictionary pDict = patchesToRename[patchI].dict();
121 forAll(matchedPatches, matchI)
123 word newName(mesh_.getPatchName(matchedPatches[matchI]));
125 if( pDict.found("newName") )
126 newName = word(pDict.lookup("newName"));
128 if( newNameToPos.find(newName) != newNameToPos.end() )
130 //- patch with the same name already exists
131 patchToNew[matchedPatches[matchI]] = newNameToPos[newName];
136 newNameToPos.insert(std::pair<word, label>(newName, newPatchI));
137 newPatchNames[newPatchI] = newName;
138 if( pDict.found("type") )
140 const word newType(pDict.lookup("type"));
141 newPatchTypes[newPatchI] = newType;
145 newPatchTypes[newPatchI] = "wall";
148 patchToNew[matchedPatches[matchI]] = newPatchI;
154 word defaultName("walls");
155 if( dict.found("defaultName") )
156 defaultName = word(dict.lookup("defaultName"));
157 word defaultType("wall");
158 if( dict.found("defaultType") )
159 defaultType = word(dict.lookup("defaultType"));
161 if( dict.found("defaultName") && (newPatchI < patchToNew.size()) )
163 bool addPatch(false);
164 forAll(patchToNew, patchI)
165 if( patchToNew[patchI] == -1 )
173 newNameToPos.insert(std::pair<word, label>(defaultName, newPatchI));
174 newPatchNames[newPatchI] = defaultName;
175 newPatchTypes[newPatchI] = defaultType;
181 forAll(patchToNew, patchI)
183 if( patchToNew[patchI] != -1 )
186 patchToNew[patchI] = newPatchI;
187 newPatchNames[newPatchI] = mesh_.boundaries()[patchI].patchName();
188 newPatchTypes[newPatchI] = mesh_.boundaries()[patchI].patchType();
196 newPatchNames.setSize(newPatchI);
197 newPatchTypes.setSize(newPatchI);
199 //- start creating new boundary
200 VRWGraph newBoundaryFaces;
201 labelLongList newBoundaryOwners;
202 labelLongList newBoundaryPatches;
204 const PtrList<boundaryPatch>& boundaries = mesh_.boundaries();
205 const faceListPMG& faces = mesh_.faces();
206 const labelList& owner = mesh_.owner();
207 forAll(boundaries, patchI)
209 const boundaryPatch& wp = boundaries[patchI];
210 const label start = wp.patchStart();
211 const label end = start + wp.patchSize();
213 if( patchToNew[patchI] == -1 )
215 //- this patch is moved to the default patch
216 for(label faceI=start;faceI<end;++faceI)
218 newBoundaryFaces.appendList(faces[faceI]);
219 newBoundaryPatches.append(newPatchI-1);
220 newBoundaryOwners.append(owner[faceI]);
225 //- this patch is renamed
226 for(label faceI=start;faceI<end;++faceI)
228 newBoundaryFaces.appendList(faces[faceI]);
229 newBoundaryPatches.append(patchToNew[patchI]);
230 newBoundaryOwners.append(owner[faceI]);
235 //- execute the modifier
236 polyMeshGenModifier meshModifier(mesh_);
237 meshModifier.replaceBoundary
244 forAll(meshModifier.boundariesAccess(), patchI)
245 meshModifier.boundariesAccess()[patchI].patchType() =
246 newPatchTypes[patchI];
248 Info << "Finished renaming boundary patches" << endl;
251 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
253 renameBoundaryPatches::renameBoundaryPatches
256 const IOdictionary& meshDict
262 if( meshDict.found("renameBoundary") )
263 calculateNewBoundary();
266 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
268 renameBoundaryPatches::~renameBoundaryPatches()
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 } // End namespace Foam
275 // ************************************************************************* //