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/>.
24 \*---------------------------------------------------------------------------*/
26 #include "cohesivePolyPatch.H"
27 #include "addToRunTimeSelectionTable.H"
28 #include "polyBoundaryMesh.H"
30 #include "demandDrivenData.H"
32 #include "patchZones.H"
33 #include "matchPoints.H"
34 #include "SortableList.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
43 // Return new ordering. Ordering is -faceMap: for every face index
44 // the new face -rotation:for every new face the clockwise shift
45 // of the original face. Return false if nothing changes (faceMap
46 // is identity, rotation is 0)
47 bool cohesivePolyPatch::order
49 const primitivePatch& pp,
56 // Grab faceMap from polyTopoChanger
57 SortableList<label> topoFaceMap(faceMap);
59 faceMap.setSize(pp.size());
62 rotation.setSize(pp.size());
67 // No faces, nothing to change.
71 label oldFacesStartIndex = -1;
72 for (label i = 0; i < topoFaceMap.size(); i += 2)
74 if (topoFaceMap[i + 1] - topoFaceMap[i] == 1)
76 oldFacesStartIndex = i;
81 label oldFacesSize = 0;
82 if (oldFacesStartIndex != -1)
84 oldFacesSize = oldFacesSize + 2;
85 for (label i = oldFacesStartIndex + 2; i < topoFaceMap.size(); i += 2)
87 oldFacesSize += 2*(topoFaceMap[i + 1]-topoFaceMap[i]);
91 // Indices of faces on half0
92 labelList half0ToPatch(pp.size());
93 // Indices of faces on half1
94 labelList half1ToPatch(pp.size());
98 vectorField normals(pp.size());
102 normals[faceI] = pp[faceI].normal(pp.points());
105 normals /= mag(normals) + VSMALL;
110 label sizeByTwo = oldFacesSize/2;
112 if (oldFacesStartIndex != -1)
116 label i = oldFacesStartIndex;
117 i < oldFacesStartIndex+sizeByTwo;
121 half0ToPatch[n0Faces++] = i;
122 half1ToPatch[n1Faces++] = i + sizeByTwo;
125 for (label i = 0; i < oldFacesStartIndex; i += 2)
127 half0ToPatch[n0Faces++] = i;
128 half1ToPatch[n1Faces++] = i + 1;
133 label i=oldFacesStartIndex+oldFacesSize;
134 i<topoFaceMap.size();
138 half0ToPatch[n0Faces++] = i;
139 half1ToPatch[n1Faces++] = i + 1;
147 i < topoFaceMap.size();
151 half0ToPatch[n0Faces++] = i;
152 half1ToPatch[n1Faces++] = i + 1;
156 half0ToPatch.setSize(n0Faces);
157 half1ToPatch.setSize(n1Faces);
159 Pout<< "cohesivePolyPatch::order : "
160 << "Number of faces per zone:("
161 << n0Faces << ' ' << n1Faces << ')' << endl;
164 if (half0ToPatch.size() != half1ToPatch.size())
168 "cohesivePolyPatch::order"
169 "(const primitivePatch&, labelList&, labelList&) const"
170 ) << " patch:" << name() << " : "
171 << "Patch " << name() << " gets decomposed in two zones of"
172 << "inequal size: " << half0ToPatch.size()
173 << " and " << half1ToPatch.size() << endl
174 << "Continuing with incorrect face ordering from now on!" << endl;
179 forAll (half0ToPatch, faceI)
181 // Label in original patch
182 label patchFaceI = topoFaceMap.indices()[half0ToPatch[faceI]];
184 faceMap[patchFaceI] = faceI;
187 forAll (half1ToPatch, faceI)
189 // Label in original patch
190 label patchFaceI = topoFaceMap.indices()[half1ToPatch[faceI]];
192 faceMap[patchFaceI] = half0ToPatch.size() + faceI;
195 forAll (faceMap, faceI)
197 if (faceMap[faceI] != faceI)
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 } // End namespace Foam
210 // ************************************************************************* //