FreeFOAM The Cross-Platform CFD Toolkit
polyMeshInitMesh.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) 1991-2010 OpenCFD Ltd.
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 \*---------------------------------------------------------------------------*/
25 
26 #include "polyMesh.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 void Foam::polyMesh::initMesh()
31 {
32  if (debug)
33  {
34  Info<< "void polyMesh::initMesh() : "
35  << "initialising primitiveMesh" << endl;
36  }
37 
38  // For backward compatibility check if the neighbour array is the same
39  // length as the owner and shrink to remove the -1s padding
40  if (neighbour_.size() == owner_.size())
41  {
42  label nInternalFaces = 0;
43 
44  forAll(neighbour_, faceI)
45  {
46  if (neighbour_[faceI] == -1)
47  {
48  break;
49  }
50  else
51  {
52  nInternalFaces++;
53  }
54  }
55 
56  neighbour_.setSize(nInternalFaces);
57  }
58 
59  label nCells = -1;
60 
61  forAll(owner_, facei)
62  {
63  nCells = max(nCells, owner_[facei]);
64  }
65 
66  // The neighbour array may or may not be the same length as the owner
67  forAll(neighbour_, facei)
68  {
69  nCells = max(nCells, neighbour_[facei]);
70  }
71 
72  nCells++;
73 
74  // Reset the primitiveMesh with the sizes of the primitive arrays
76  (
77  points_.size(),
78  neighbour_.size(),
79  owner_.size(),
80  nCells
81  );
82 
83  string meshInfo =
84  "nPoints:" + Foam::name(nPoints())
85  + " nCells:" + Foam::name(this->nCells())
86  + " nFaces:" + Foam::name(nFaces())
87  + " nInternalFaces:" + Foam::name(nInternalFaces());
88 
89  owner_.note() = meshInfo;
90  neighbour_.note() = meshInfo;
91 }
92 
93 
94 void Foam::polyMesh::initMesh(cellList& c)
95 {
96  if (debug)
97  {
98  Info<< "void polyMesh::initMesh(cellList& c) : "
99  << "calculating owner-neighbour arrays" << endl;
100  }
101 
102  owner_.setSize(faces_.size(), -1);
103  neighbour_.setSize(faces_.size(), -1);
104 
105  boolList markedFaces(faces_.size(), false);
106 
107  label nInternalFaces = 0;
108 
109  forAll(c, cellI)
110  {
111  // get reference to face labels for current cell
112  const labelList& cellfaces = c[cellI];
113 
114  forAll (cellfaces, faceI)
115  {
116  if (!markedFaces[cellfaces[faceI]])
117  {
118  // First visit: owner
119  owner_[cellfaces[faceI]] = cellI;
120  markedFaces[cellfaces[faceI]] = true;
121  }
122  else
123  {
124  // Second visit: neighbour
125  neighbour_[cellfaces[faceI]] = cellI;
126  nInternalFaces++;
127  }
128  }
129  }
130 
131  // The neighbour array is initialised with the same length as the owner
132  // padded with -1s and here it is truncated to the correct size of the
133  // number of internal faces.
134  neighbour_.setSize(nInternalFaces);
135 
136  // Reset the primitiveMesh
138  (
139  points_.size(),
140  neighbour_.size(),
141  owner_.size(),
142  c.size(),
143  c
144  );
145 
146  string meshInfo =
147  "nPoints: " + Foam::name(nPoints())
148  + " nCells: " + Foam::name(nCells())
149  + " nFaces: " + Foam::name(nFaces())
150  + " nInternalFaces: " + Foam::name(this->nInternalFaces());
151 
152  owner_.note() = meshInfo;
153  neighbour_.note() = meshInfo;
154 }
155 
156 // ************************ vim: set sw=4 sts=4 et: ************************ //