Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / solidModels / arbitraryCrack / cohesive / cohesivePolyPatch.C
blob0b957505527015414097e0af609eb719636f799a
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
29 #include "polyMesh.H"
30 #include "demandDrivenData.H"
31 #include "OFstream.H"
32 #include "patchZones.H"
33 #include "matchPoints.H"
34 #include "SortableList.H"
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
38 namespace Foam
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,
50     labelList& faceMap,
51     labelList& rotation
52 ) const
54     return false;
56     // Grab faceMap from polyTopoChanger
57     SortableList<label> topoFaceMap(faceMap);
59     faceMap.setSize(pp.size());
60     faceMap = -1;
62     rotation.setSize(pp.size());
63     rotation = 0;
65     if (pp.size() == 0)
66     {
67         // No faces, nothing to change.
68         return false;
69     }
71     label oldFacesStartIndex = -1;
72     for (label i = 0; i < topoFaceMap.size(); i += 2)
73     {
74         if (topoFaceMap[i + 1] - topoFaceMap[i] == 1)
75         {
76             oldFacesStartIndex = i;
77             break;
78         }
79     }
81     label oldFacesSize = 0;
82     if (oldFacesStartIndex != -1)
83     {
84         oldFacesSize = oldFacesSize + 2;
85         for (label i = oldFacesStartIndex + 2; i < topoFaceMap.size(); i += 2)
86         {
87             oldFacesSize += 2*(topoFaceMap[i + 1]-topoFaceMap[i]);
88         }
89     }
91     // Indices of faces on half0
92     labelList half0ToPatch(pp.size());
93     // Indices of faces on half1
94     labelList half1ToPatch(pp.size());
96     {
97         // Calculate normals
98         vectorField normals(pp.size());
100         forAll (pp, faceI)
101         {
102             normals[faceI] = pp[faceI].normal(pp.points());
103         }
105         normals /= mag(normals) + VSMALL;
107         label n0Faces = 0;
108         label n1Faces = 0;
110         label sizeByTwo = oldFacesSize/2;
112         if (oldFacesStartIndex != -1)
113         {
114             for
115             (
116                 label i = oldFacesStartIndex;
117                 i < oldFacesStartIndex+sizeByTwo;
118                 i++
119             )
120             {
121                 half0ToPatch[n0Faces++] = i;
122                 half1ToPatch[n1Faces++] = i + sizeByTwo;
123             }
125             for (label i = 0; i < oldFacesStartIndex; i += 2)
126             {
127                 half0ToPatch[n0Faces++] = i;
128                 half1ToPatch[n1Faces++] = i + 1;
129             }
131             for
132             (
133                 label i=oldFacesStartIndex+oldFacesSize;
134                 i<topoFaceMap.size();
135                 i = i + 2
136             )
137             {
138                 half0ToPatch[n0Faces++] = i;
139                 half1ToPatch[n1Faces++] = i + 1;
140             }
141         }
142         else
143         {
144             for
145             (
146                 label i = 0;
147                 i < topoFaceMap.size();
148                 i += 2
149             )
150             {
151                 half0ToPatch[n0Faces++] = i;
152                 half1ToPatch[n1Faces++] = i + 1;
153             }
154         }
156         half0ToPatch.setSize(n0Faces);
157         half1ToPatch.setSize(n1Faces);
159         Pout<< "cohesivePolyPatch::order : "
160             << "Number of faces per zone:("
161             << n0Faces << ' ' << n1Faces << ')' << endl;
162     }
164     if (half0ToPatch.size() != half1ToPatch.size())
165     {
166         SeriousErrorIn
167         (
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;
176         return false;
177     }
179     forAll (half0ToPatch, faceI)
180     {
181         // Label in original patch
182         label patchFaceI = topoFaceMap.indices()[half0ToPatch[faceI]];
184         faceMap[patchFaceI] = faceI;
185     }
187     forAll (half1ToPatch, faceI)
188     {
189         // Label in original patch
190         label patchFaceI = topoFaceMap.indices()[half1ToPatch[faceI]];
192         faceMap[patchFaceI] = half0ToPatch.size() + faceI;
193     }
195     forAll (faceMap, faceI)
196     {
197         if (faceMap[faceI] != faceI)
198         {
199             return true;
200         }
201     }
203     return false;
206 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
208 } // End namespace Foam
210 // ************************************************************************* //