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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2019-2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "polyMesh.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::polyMesh::initMesh()
34 {
35  DebugInFunction << "initialising primitiveMesh" << endl;
36 
37  // For backward compatibility check if the neighbour array is the same
38  // length as the owner and shrink to remove the -1s padding
39  if (neighbour_.size() == owner_.size())
40  {
41  label nInternalFaces = 0;
42 
43  forAll(neighbour_, facei)
44  {
45  if (neighbour_[facei] == -1)
46  {
47  break;
48  }
49  else
50  {
52  }
53  }
54 
55  neighbour_.setSize(nInternalFaces);
56  }
57 
58  label nCells = -1;
59 
60  forAll(owner_, facei)
61  {
62  if (owner_[facei] < 0)
63  {
65  << "Illegal cell label " << owner_[facei]
66  << " in owner addressing for face " << facei
67  << exit(FatalError);
68  }
69  nCells = max(nCells, owner_[facei]);
70  }
71 
72  // The neighbour array may or may not be the same length as the owner
73  forAll(neighbour_, facei)
74  {
75  if (neighbour_[facei] < 0)
76  {
78  << "Illegal cell label " << neighbour_[facei]
79  << " in neighbour addressing for face " << facei
80  << exit(FatalError);
81  }
82  nCells = max(nCells, neighbour_[facei]);
83  }
84 
85  nCells++;
86 
87  // Reset the primitiveMesh with the sizes of the primitive arrays
89  (
90  points_.size(),
91  neighbour_.size(),
92  owner_.size(),
93  nCells
94  );
95 
96  const string meshInfo
97  (
98  "nPoints:" + Foam::name(nPoints())
99  + " nCells:" + Foam::name(this->nCells())
100  + " nFaces:" + Foam::name(nFaces())
101  + " nInternalFaces:" + Foam::name(nInternalFaces())
102  );
103 
104  owner_.note() = meshInfo;
105  neighbour_.note() = meshInfo;
106 }
107 
108 
109 void Foam::polyMesh::initMesh(cellList& c)
110 {
111  DebugInFunction << "Calculating owner-neighbour arrays" << endl;
112 
113  owner_.setSize(faces_.size(), -1);
114  neighbour_.setSize(faces_.size(), -1);
115 
116  boolList markedFaces(faces_.size(), false);
117 
118  label nInternalFaces = 0;
119 
120  forAll(c, celli)
121  {
122  // get reference to face labels for current cell
123  const labelList& cellfaces = c[celli];
124 
125  forAll(cellfaces, facei)
126  {
127  if (cellfaces[facei] < 0)
128  {
130  << "Illegal face label " << cellfaces[facei]
131  << " in cell " << celli
132  << exit(FatalError);
133  }
134 
135  if (!markedFaces[cellfaces[facei]])
136  {
137  // First visit: owner
138  owner_[cellfaces[facei]] = celli;
139  markedFaces[cellfaces[facei]] = true;
140  }
141  else
142  {
143  // Second visit: neighbour
144  neighbour_[cellfaces[facei]] = celli;
145  nInternalFaces++;
146  }
147  }
148  }
149 
150  // The neighbour array is initialised with the same length as the owner
151  // padded with -1s and here it is truncated to the correct size of the
152  // number of internal faces.
153  neighbour_.setSize(nInternalFaces);
154 
155  // Reset the primitiveMesh
157  (
158  points_.size(),
159  neighbour_.size(),
160  owner_.size(),
161  c.size(),
162  c
163  );
164 
165  const string meshInfo
166  (
167  "nPoints:" + Foam::name(nPoints())
168  + " nCells:" + Foam::name(nCells())
169  + " nFaces:" + Foam::name(nFaces())
170  + " nInternalFaces:" + Foam::name(this->nInternalFaces())
171  );
172 
173  owner_.note() = meshInfo;
174  neighbour_.note() = meshInfo;
175 }
176 
177 
178 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::boolList
List< bool > boolList
A List of bools.
Definition: List.H:65
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
polyMesh.H
Foam::primitiveMesh::nPoints
label nPoints() const noexcept
Number of mesh points.
Definition: primitiveMeshI.H:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
nPoints
label nPoints
Definition: gmvOutputHeader.H:2
Foam::primitiveMesh::nCells
label nCells() const noexcept
Number of mesh cells.
Definition: primitiveMeshI.H:96
DebugInFunction
#define DebugInFunction
Report an information message using Foam::Info.
Definition: messageStream.H:388
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::cellList
List< cell > cellList
A List of cells.
Definition: cellListFwd.H:47
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
Foam::FatalError
error FatalError
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::IOobject::note
const string & note() const noexcept
Return the optional note.
Definition: IOobjectI.H:95
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::primitiveMesh::nInternalFaces
label nInternalFaces() const noexcept
Number of internal faces.
Definition: primitiveMeshI.H:78
Foam::primitiveMesh::reset
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
Definition: primitiveMesh.C:207
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::name
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
Foam::primitiveMesh::nFaces
label nFaces() const noexcept
Number of mesh faces.
Definition: primitiveMeshI.H:90