initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / generation / blockMesh / createPatches.C
blob1a670c6578dd27d597b061a1956cc6176feda4db
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM; if not, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Description
28 \*---------------------------------------------------------------------------*/
30 #include "blockMesh.H"
32 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
34 Foam::faceList Foam::blockMesh::createPatchFaces
36     const polyPatch& patchTopologyFaces
39     blockMesh& blocks = *this;
41     labelList blockLabels = patchTopologyFaces.polyPatch::faceCells();
43     label nFaces=0;
45     forAll(patchTopologyFaces, patchTopologyFaceLabel)
46     {
47         label blockLabel = blockLabels[patchTopologyFaceLabel];
49         faceList blockFaces
50         (
51             blocks[blockLabel].blockDef().blockShape().faces()
52         );
54         forAll(blockFaces, blockFaceLabel)
55         {
56             if
57             (
58                 blockFaces[blockFaceLabel]
59              == patchTopologyFaces[patchTopologyFaceLabel]
60             )
61             {
62                 nFaces +=
63                     blocks[blockLabel].boundaryPatches()[blockFaceLabel].size();
64             }
65         }
66     }
69     faceList patchFaces(nFaces);
70     face quadFace(4);
71     label faceLabel = 0;
73     forAll(patchTopologyFaces, patchTopologyFaceLabel)
74     {
75         label blockLabel = blockLabels[patchTopologyFaceLabel];
77         faceList blockFaces
78         (
79             blocks[blockLabel].blockDef().blockShape().faces()
80         );
82         forAll(blockFaces, blockFaceLabel)
83         {
84             if
85             (
86                 blockFaces[blockFaceLabel]
87                 == patchTopologyFaces[patchTopologyFaceLabel]
88             )
89             {
90                 const labelListList& blockPatchFaces =
91                     blocks[blockLabel].boundaryPatches()[blockFaceLabel];
93                 forAll(blockPatchFaces, blockFaceLabel)
94                 {
95                     // Lookup the face points
96                     // and collapse duplicate point labels
98                     quadFace[0] =
99                         mergeList_
100                         [
101                             blockPatchFaces[blockFaceLabel][0]
102                           + blockOffsets_[blockLabel]
103                         ];
105                     label nUnique = 1;
107                     for
108                     (
109                         label facePointLabel = 1;
110                         facePointLabel < 4;
111                         facePointLabel++
112                     )
113                     {
114                         quadFace[nUnique] =
115                             mergeList_
116                             [
117                                 blockPatchFaces[blockFaceLabel][facePointLabel]
118                               + blockOffsets_[blockLabel]
119                             ];
121                         if (quadFace[nUnique] != quadFace[nUnique-1])
122                         {
123                             nUnique++;
124                         }
125                     }
127                     if (quadFace[nUnique-1] == quadFace[0])
128                     {
129                         nUnique--;
130                     }
132                     if (nUnique == 4)
133                     {
134                         patchFaces[faceLabel++] = quadFace;
135                     }
136                     else if (nUnique == 3)
137                     {
138                         patchFaces[faceLabel++] = face
139                         (
140                             labelList::subList(quadFace, 3)
141                         );
142                     }
143                     // else the face has collapsed to an edge or point
144                 }
145             }
146         }
147     }
149     patchFaces.setSize(faceLabel);
151     return patchFaces;
155 Foam::faceListList Foam::blockMesh::createPatches()
157     Info<< "\nCreating patches\n";
159     const polyPatchList& patchTopologies = topology().boundaryMesh();
160     faceListList patches(patchTopologies.size());
162     forAll(patchTopologies, patchLabel)
163     {
164         patches[patchLabel] =
165             createPatchFaces(patchTopologies[patchLabel]);
166     }
168     return patches;
171 // ************************************************************************* //