createPolyCells.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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.
20 
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/>.
23 
24 Description
25  Create intermediate mesh files from PROSTAR files
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "starMesh.H"
30 
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 
33 void Foam::starMesh::createPolyCells()
34 {
35  // loop through all cell faces and create connectivity. This will produce
36  // a global face list and will describe all cells as lists of face labels
37 
38  // count the maximum number of faces and set the size of the cellPolys_
39  cellPolys_.setSize(cellShapes_.size());
40 
41  label maxFaces = 0;
42 
43  forAll(cellPolys_, celli)
44  {
45  cell& curCell = cellPolys_[celli];
46 
47  curCell.setSize(cellFaces_[celli].size());
48 
49  forAll(curCell, fI)
50  {
51  curCell[fI] = -1;
52  }
53 
54  maxFaces += cellFaces_[celli].size();
55  }
56 
57  Info<< "Maximum possible number of faces in mesh: " << maxFaces << endl;
58 
59  meshFaces_.setSize(maxFaces);
60 
61  // set reference to point-cell addressing
62  const labelListList& PointCells = pointCells();
63 
64  bool found = false;
65 
66  nInternalFaces_ = 0;
67 
68  forAll(cellFaces_, celli)
69  {
70  // Note:
71  // Insertion cannot be done in one go as the faces need to be
72  // added into the list in the increasing order of neighbour
73  // cells. Therefore, all neighbours will be detected first
74  // and then added in the correct order.
75 
76  const faceList& curFaces = cellFaces_[celli];
77 
78  // Record the neighbour cell
79  labelList neiCells(curFaces.size(), -1);
80 
81  // Record the face of neighbour cell
82  labelList faceOfNeiCell(curFaces.size(), -1);
83 
84  label nNeighbours = 0;
85 
86  // For all faces ...
87  forAll(curFaces, facei)
88  {
89  // Skip faces that have already been matched
90  if (cellPolys_[celli][facei] >= 0) continue;
91 
92  found = false;
93 
94  const face& curFace = curFaces[facei];
95 
96  // get the list of labels
97  const labelList& curPoints = curFace;
98 
99  // For all points
100  forAll(curPoints, pointi)
101  {
102  // get the list of cells sharing this point
103  const labelList& curNeighbours = PointCells[curPoints[pointi]];
104 
105  // For all neighbours
106  forAll(curNeighbours, neiI)
107  {
108  label curNei = curNeighbours[neiI];
109 
110  // reject neighbours with the lower label. This should
111  // also reject current cell.
112  if (curNei > celli)
113  {
114  // get the list of search faces
115  const faceList& searchFaces = cellFaces_[curNei];
116 
117  forAll(searchFaces, neiFacei)
118  {
119  if (searchFaces[neiFacei] == curFace)
120  {
121  // match!!
122  found = true;
123 
124  // Record the neighbour cell and face
125  neiCells[facei] = curNei;
126  faceOfNeiCell[facei] = neiFacei;
127  nNeighbours++;
128 
129  break;
130  }
131  }
132  if (found) break;
133  }
134  if (found) break;
135  }
136  if (found) break;
137  } // End of current points
138  } // End of current faces
139 
140  // Add the faces in the increasing order of neighbours
141  for (label neiSearch = 0; neiSearch < nNeighbours; neiSearch++)
142  {
143  // Find the lowest neighbour which is still valid
144  label nextNei = -1;
145  label minNei = cellPolys_.size();
146 
147  forAll(neiCells, ncI)
148  {
149  if (neiCells[ncI] > -1 && neiCells[ncI] < minNei)
150  {
151  nextNei = ncI;
152  minNei = neiCells[ncI];
153  }
154  }
155 
156  if (nextNei > -1)
157  {
158  // Add the face to the list of faces
159  meshFaces_[nInternalFaces_] = curFaces[nextNei];
160 
161  // Mark for owner
162  cellPolys_[celli][nextNei] = nInternalFaces_;
163 
164  // Mark for neighbour
165  cellPolys_[neiCells[nextNei]][faceOfNeiCell[nextNei]] =
166  nInternalFaces_;
167 
168  // Stop the neighbour from being used again
169  neiCells[nextNei] = -1;
170 
171  // Increment number of faces counter
172  nInternalFaces_++;
173  }
174  else
175  {
177  << "Error in internal face insertion"
178  << abort(FatalError);
179  }
180  }
181  }
182 
183  // I won't reset the size of internal faces, because more faces will be
184  // added in createPolyBoundary()
185 }
186 
187 
188 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void setSize(const label)
Reset size of List.
Definition: List.C:295
messageStream Info