1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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.
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
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/>.
25 Divides external faces into patches based on (user supplied) feature
28 \*---------------------------------------------------------------------------*/
33 #include "boundaryMesh.H"
34 #include "repatchPolyTopoChanger.H"
35 #include "unitConversion.H"
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 // Get all feature edges.
44 void collectFeatureEdges(const boundaryMesh& bMesh, labelList& markedEdges)
46 markedEdges.setSize(bMesh.mesh().nEdges());
50 forAll(bMesh.featureSegments(), i)
52 const labelList& segment = bMesh.featureSegments()[i];
56 label featEdgeI = segment[j];
58 label meshEdgeI = bMesh.featureToEdge()[featEdgeI];
60 markedEdges[markedI++] = meshEdgeI;
63 markedEdges.setSize(markedI);
69 int main(int argc, char *argv[])
71 # include "addOverwriteOption.H"
72 argList::noParallel();
73 argList::validArgs.append("feature angle[0-180]");
75 # include "setRootCase.H"
76 # include "createTime.H"
77 runTime.functionObjects().off();
78 # include "createPolyMesh.H"
79 const word oldInstance = mesh.pointsInstance();
81 Info<< "Mesh read in = "
82 << runTime.cpuTimeIncrement()
83 << " s\n" << endl << endl;
86 const scalar featureAngle = args.argRead<scalar>(1);
87 const bool overwrite = args.optionFound("overwrite");
89 const scalar minCos = Foam::cos(degToRad(featureAngle));
91 Info<< "Feature:" << featureAngle << endl
92 << "minCos :" << minCos << endl
96 // Use boundaryMesh to reuse all the featureEdge stuff in there.
102 // Set feature angle (calculate feature edges)
103 bMesh.setFeatureEdges(minCos);
105 // Collect all feature edges as edge labels
106 labelList markedEdges;
108 collectFeatureEdges(bMesh, markedEdges);
112 // (new) patch ID for every face in mesh.
113 labelList patchIDs(bMesh.mesh().size(), -1);
116 // Fill patchIDs with values for every face by floodfilling without
117 // crossing feature edge.
120 // Current patch number.
121 label newPatchI = bMesh.patches().size();
127 // Find first unset face.
128 label unsetFaceI = findIndex(patchIDs, -1);
130 if (unsetFaceI == -1)
132 // All faces have patchID set. Exit.
136 // Found unset face. Create patch for it.
140 patchName = "auto" + name(suffix++);
142 while (bMesh.findPatchID(patchName) != -1);
144 bMesh.addPatch(patchName);
146 bMesh.changePatchType(patchName, "patch");
149 // Fill visited with all faces reachable from unsetFaceI.
150 boolList visited(bMesh.mesh().size());
152 bMesh.markFaces(markedEdges, unsetFaceI, visited);
155 // Assign all visited faces to current patch
158 forAll(visited, faceI)
164 patchIDs[faceI] = newPatchI;
168 Info<< "Assigned " << nVisited << " faces to patch " << patchName
176 const PtrList<boundaryPatch>& patches = bMesh.patches();
178 // Create new list of patches with old ones first
179 List<polyPatch*> newPatchPtrList(patches.size());
184 forAll(mesh.boundaryMesh(), patchI)
186 const polyPatch& patch = mesh.boundaryMesh()[patchI];
188 newPatchPtrList[newPatchI] =
200 // Add new ones with empty size.
201 for (label patchI = newPatchI; patchI < patches.size(); patchI++)
203 const boundaryPatch& bp = patches[patchI];
205 newPatchPtrList[newPatchI] = polyPatch::New
225 repatchPolyTopoChanger polyMeshRepatcher(mesh);
226 polyMeshRepatcher.changePatches(newPatchPtrList);
229 // Change face ordering
231 // Since bMesh read from mesh there is one to one mapping so we don't
232 // have to do the geometric stuff.
233 const labelList& meshFace = bMesh.meshFace();
235 forAll(patchIDs, faceI)
237 label meshFaceI = meshFace[faceI];
239 polyMeshRepatcher.changePatchID(meshFaceI, patchIDs[faceI]);
242 polyMeshRepatcher.repatch();
244 // Write resulting mesh
247 mesh.setInstance(oldInstance);
252 Info<< "End\n" << endl;
258 // ************************************************************************* //