initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / utilities / mesh / conversion / starToFoam / createPolyCells.C
blobfc2e65a0b984503a3ce8a30ec13e48d70c1a61f5
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
26     Create intermediate mesh files from PROSTAR files
28 \*---------------------------------------------------------------------------*/
30 #include "starMesh.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 void starMesh::createPolyCells()
36     // loop through all cell faces and create connectivity. This will produce
37     // a global face list and will describe all cells as lists of face labels
39     // count the maximum number of faces and set the size of the cellPolys_
40     cellPolys_.setSize(cellShapes_.size());
42     label maxFaces = 0;
44     forAll (cellPolys_, cellI)
45     {
46         cell& curCell = cellPolys_[cellI];
48         curCell.setSize(cellFaces_[cellI].size());
50         forAll (curCell, fI)
51         {
52             curCell[fI] = -1;
53         }
55         maxFaces += cellFaces_[cellI].size();
56     }
58     Info << "Maximum possible number of faces in mesh: " << maxFaces << endl;
60     meshFaces_.setSize(maxFaces);
62     // set reference to point-cell addressing
63     const labelListList& PointCells = pointCells();
65     bool found = false;
67     nInternalFaces_ = 0;
69     forAll(cellFaces_, cellI)
70     {
71         // Note:
72         // Insertion cannot be done in one go as the faces need to be
73         // added into the list in the increasing order of neighbour
74         // cells.  Therefore, all neighbours will be detected first
75         // and then added in the correct order.  
77         const faceList& curFaces = cellFaces_[cellI];
79         // Record the neighbour cell
80         labelList neiCells(curFaces.size(), -1);
82         // Record the face of neighbour cell
83         labelList faceOfNeiCell(curFaces.size(), -1);
85         label nNeighbours = 0;
87         // For all faces ...
88         forAll(curFaces, faceI)
89         {
90             // Skip faces that have already been matched
91             if (cellPolys_[cellI][faceI] >= 0) continue;
93             found = false;
95             const face& curFace = curFaces[faceI];
97             // get the list of labels
98             const labelList& curPoints = curFace;
100             // For all points
101             forAll(curPoints, pointI)
102             {
103                 // get the list of cells sharing this point
104                 const labelList& curNeighbours = PointCells[curPoints[pointI]];
106                 // For all neighbours
107                 forAll(curNeighbours, neiI)
108                 {
109                     label curNei = curNeighbours[neiI];
111                     // reject neighbours with the lower label. This should
112                     // also reject current cell. 
113                     if (curNei > cellI)
114                     {
115                         // get the list of search faces
116                         const faceList& searchFaces = cellFaces_[curNei];
118                         forAll(searchFaces, neiFaceI)
119                         {
120                             if (searchFaces[neiFaceI] == curFace)
121                             {
122                                 // match!!
123                                 found = true;
125                                 // Record the neighbour cell and face
126                                 neiCells[faceI] = curNei;
127                                 faceOfNeiCell[faceI] = neiFaceI;
128                                 nNeighbours++;
130                                 break;
131                             }
132                         }
133                         if (found) break;
134                     }
135                     if (found) break;
136                 }
137                 if (found) break;
138             } // End of current points
139         } // End of current faces
141         // Add the faces in the increasing order of neighbours
142         for (label neiSearch = 0; neiSearch < nNeighbours; neiSearch++)
143         {
144             // Find the lowest neighbour which is still valid
145             label nextNei = -1;
146             label minNei = cellPolys_.size();
148             forAll (neiCells, ncI)
149             {
150                 if (neiCells[ncI] > -1 && neiCells[ncI] < minNei)
151                 {
152                     nextNei = ncI;
153                     minNei = neiCells[ncI];
154                 }
155             }
157             if (nextNei > -1)
158             {
159                 // Add the face to the list of faces
160                 meshFaces_[nInternalFaces_] = curFaces[nextNei];
162                 // Mark for owner
163                 cellPolys_[cellI][nextNei] = nInternalFaces_;
165                 // Mark for neighbour
166                 cellPolys_[neiCells[nextNei]][faceOfNeiCell[nextNei]] =
167                     nInternalFaces_;
169                 // Stop the neighbour from being used again
170                 neiCells[nextNei] = -1;
172                 // Increment number of faces counter
173                 nInternalFaces_++;
174             }
175             else
176             {
177               FatalErrorIn("void starMesh::createPolyCells()")
178                   << "Error in internal face insertion"
179                   << abort(FatalError);
180             }
181         }
182     }
184     // I won't reset the size of internal faces, because more faces will be
185     // added in createPolyBoundary()
189 // ************************************************************************* //