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 \*---------------------------------------------------------------------------*/
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 void Foam::polyMesh::initMesh()
34 Info<< "void polyMesh::initMesh() : "
35 << "initialising primitiveMesh" << endl;
38 // For backward compatibility check if the owner array is the same
39 // length as the number of allFaces and shrink to remove the -1s padding
42 label nActiveFaces = 0;
46 if (owner_[faceI] == -1)
56 InfoIn("void polyMesh::initMesh()")
57 << "Truncating owner list at " << nActiveFaces
58 << " for backward compatibility" << endl;
60 owner_.setSize(nActiveFaces);
63 // For backward compatibility check if the neighbour array is the same
64 // length as the owner and shrink to remove the -1s padding
65 if (min(neighbour_) < 0)
69 forAll(neighbour_, faceI)
71 if (neighbour_[faceI] == -1)
81 InfoIn("void polyMesh::initMesh()")
82 << "Truncating neighbour list at " << nIntFaces
83 << " for backward compatibility" << endl;
85 neighbour_.setSize(nIntFaces);
92 nCells = max(nCells, owner_[facei]);
95 // The neighbour array may or may not be the same length as the owner
96 forAll(neighbour_, facei)
98 nCells = max(nCells, neighbour_[facei]);
103 label nUsedFaces = 0;
105 // Use patch info if provided, use all faces otherwise
106 if (boundary_.size())
109 boundary_[boundary_.size() - 1].start()
110 + boundary_[boundary_.size() - 1].size();
114 // No patch info. Assume all faces are used.
115 nUsedFaces = owner_.size();
119 label nUsedPoints = allPoints_.size();
121 // If not all faces are being used, check that all unused
122 // faces are at the back of the list and check the number of
124 if (nUsedFaces < allFaces_.size())
128 Info<< "void polyMesh::initMesh() : "
129 << "unused faces detected. "
130 << "Number of used faces: " << nUsedFaces
131 << ". Total number of faces: " << allFaces_.size() << endl;
134 // Mark the points used by live faces.
135 boolList usedPoints(allPoints_.size(), false);
137 for (label faceI = 0; faceI < nUsedFaces; faceI++)
139 const face& curFace = allFaces_[faceI];
141 forAll (curFace, pointI)
143 usedPoints[curFace[pointI]] = true;
147 forAll (usedPoints, pointI)
149 if (!usedPoints[pointI])
151 nUsedPoints = pointI;
156 if (nUsedPoints < allPoints_.size())
160 Info<< "void polyMesh::initMesh() : unused points "
161 << "detected. Number of used points: "
162 << nUsedPoints << ". Total number of points: "
163 << allPoints_.size() << endl;
166 for (label i = nUsedPoints; i < allPoints_.size(); i++)
170 FatalErrorIn("void polyMesh::initMesh()")
171 << "Error in point ordering: mixed used and unused "
172 << "points at the end of point list." << nl
173 << "Last used point: " << nUsedPoints
174 << " " << allPoints_[nUsedPoints] << nl
175 << "First unused point: " << nUsedPoints + 1
176 << " " << allPoints_[nUsedPoints + 1] << nl
177 << "and point " << i << " " << allPoints_[i]
178 << " is used by a live face." << endl;
180 // Find out which face uses this point
182 for (label faceI = 0; faceI < nUsedFaces; faceI++)
184 const face& curFace = allFaces_[faceI];
186 forAll (curFace, pointI)
188 if (curFace[pointI] == i)
191 << "Face " << faceI << " " << curFace
193 << curFace.points(allPoints_)
205 FatalError << "Done. " << abort(FatalError);
212 points_.reset(allPoints_, nUsedPoints);
213 faces_.reset(allFaces_, owner_.size());
215 // Reset the primitiveMesh with the sizes of the primitive arrays
225 "nPoints: " + Foam::name(nPoints())
226 + " nAllPoints: " + Foam::name(allPoints().size())
227 + " nInternalFaces: " + Foam::name(nInternalFaces())
228 + " nFaces: " + Foam::name(nFaces())
229 + " nAllFaces: " + Foam::name(allFaces().size())
230 + " nCells: " + Foam::name(this->nCells());
232 owner_.note() = meshInfo;
233 neighbour_.note() = meshInfo;
237 void Foam::polyMesh::initMesh(cellList& c)
241 Info<< "void polyMesh::initMesh(cellList& c) : "
242 << "calculating owner-neighbour arrays" << endl;
245 owner_.setSize(allFaces_.size(), -1);
246 neighbour_.setSize(allFaces_.size(), -1);
248 boolList markedFaces(allFaces_.size(), false);
250 label nInternalFaces = 0;
254 // get reference to face labels for current cell
255 const labelList& cellfaces = c[cellI];
257 forAll (cellfaces, faceI)
259 if (!markedFaces[cellfaces[faceI]])
261 // First visit: owner
262 owner_[cellfaces[faceI]] = cellI;
263 markedFaces[cellfaces[faceI]] = true;
267 // Second visit: neighbour
268 neighbour_[cellfaces[faceI]] = cellI;
274 // The neighbour array is initialised with the same length as the owner
275 // padded with -1s and here it is truncated to the correct size of the
276 // number of internal faces.
277 neighbour_.setSize(nInternalFaces);
279 label nUsedPoints = allPoints_.size();
280 label nUsedFaces = allFaces_.size();
282 forAll (owner_, faceI)
284 if (owner_[faceI] < 0)
291 // If not all faces are being used, check that all unused
292 // faces are at the back of the list and check the number of
294 if (nUsedFaces < owner_.size())
298 Info<< "void polyMesh::initMesh(cellList& c) : "
299 << "unused faces detected. "
300 << "Number of used faces: " << nUsedFaces
301 << ". Total number of faces: " << owner_.size() << endl;
304 for (label i = nUsedFaces; i < owner_.size(); i++)
308 FatalErrorIn("void polyMesh::initMesh(cellList& c)")
309 << "Error in face ordering: mixed used and unused "
310 << "faces at the end of face list." << nl
311 << "Number of used faces: " << nUsedFaces
312 << " and face " << i << " is owned by cell " << owner_[i]
313 << abort(FatalError);
317 // Reset the size of owner array to the number of live faces
318 owner_.setSize(nUsedFaces);
320 // Mark the points used by live faces.
321 boolList usedPoints(allPoints_.size(), false);
323 for (label faceI = 0; faceI < nUsedFaces; faceI++)
325 const face& curFace = allFaces_[faceI];
327 forAll (curFace, pointI)
329 usedPoints[curFace[pointI]] = true;
333 forAll (usedPoints, pointI)
335 if (!usedPoints[pointI])
337 nUsedPoints = pointI;
342 if (nUsedPoints < allPoints_.size())
346 Info<< "void polyMesh::initMesh(cellList& c) : unused points "
347 << "detected. Number of used points: "
348 << nUsedPoints << ". Total number of points: "
349 << allPoints_.size() << endl;
352 for (label i = nUsedPoints; i < allPoints_.size(); i++)
356 FatalErrorIn("void polyMesh::initMesh(cellList& c)")
357 << "Error in point ordering: mixed used and unused "
358 << "points at the end of point list." << nl
359 << "Number of used points: " << nUsedPoints
360 << " and point " << i
361 << " is used by a live face." << endl;
363 // Find out which face uses this point
365 for (label faceI = 0; faceI < nUsedFaces; faceI++)
367 const face& curFace = allFaces_[faceI];
369 forAll (curFace, pointI)
371 if (curFace[pointI] == i)
374 << "Face " << faceI << " " << curFace
381 FatalError << "Done. " << abort(FatalError);
388 // Reset the primitiveMesh
399 "nPoints: " + Foam::name(nPoints())
400 + " nCells: " + Foam::name(nCells())
401 + " nFaces: " + Foam::name(nFaces())
402 + " nInternalFaces: " + Foam::name(this->nInternalFaces());
404 owner_.note() = meshInfo;
405 neighbour_.note() = meshInfo;
409 // ************************************************************************* //