polyMeshInitMesh.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2025 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 \*---------------------------------------------------------------------------*/
25 
26 #include "polyMesh.H"
27 
28 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 void Foam::polyMesh::initMesh()
31 {
32  DebugInFunction << "Initialising primitiveMesh" << endl;
33 
34  // For backward compatibility check if the neighbour array is the same
35  // length as the owner and shrink to remove the -1s padding
36  if (neighbour_.size() == owner_.size())
37  {
39 
40  forAll(neighbour_, facei)
41  {
42  if (neighbour_[facei] == -1)
43  {
44  break;
45  }
46  else
47  {
49  }
50  }
51 
52  neighbour_.setSize(nInternalFaces);
53  }
54 
55  label nCells = -1;
56 
57  forAll(owner_, facei)
58  {
59  if (owner_[facei] < 0)
60  {
62  << "Illegal cell label " << owner_[facei]
63  << " in neighbour addressing for face " << facei
64  << exit(FatalError);
65  }
66  nCells = max(nCells, owner_[facei]);
67  }
68 
69  // The neighbour array may or may not be the same length as the owner
70  forAll(neighbour_, facei)
71  {
72  if (neighbour_[facei] < 0)
73  {
75  << "Illegal cell label " << neighbour_[facei]
76  << " in neighbour addressing for face " << facei
77  << exit(FatalError);
78  }
79  nCells = max(nCells, neighbour_[facei]);
80  }
81 
82  nCells++;
83 
84  // Reset the primitiveMesh with the sizes of the primitive arrays
86  (
87  points_.size(),
88  neighbour_.size(),
89  owner_.size(),
90  nCells
91  );
92 
93  string meshInfo =
94  "nPoints:" + Foam::name(nPoints())
95  + " nCells:" + Foam::name(this->nCells())
96  + " nFaces:" + Foam::name(nFaces())
97  + " nInternalFaces:" + Foam::name(nInternalFaces());
98 
99  owner_.note() = meshInfo;
100  neighbour_.note() = meshInfo;
101 }
102 
103 
104 void Foam::polyMesh::initMesh(cellList& c)
105 {
106  DebugInFunction << "Calculating owner-neighbour arrays" << endl;
107 
108  owner_.setSize(faces_.size(), -1);
109  neighbour_.setSize(faces_.size(), -1);
110 
111  boolList markedFaces(faces_.size(), false);
112 
113  label nInternalFaces = 0;
114 
115  forAll(c, celli)
116  {
117  // get reference to face labels for current cell
118  const labelList& cellfaces = c[celli];
119 
120  forAll(cellfaces, facei)
121  {
122  if (cellfaces[facei] < 0)
123  {
125  << "Illegal face label " << cellfaces[facei]
126  << " in cell " << celli
127  << exit(FatalError);
128  }
129 
130  if (!markedFaces[cellfaces[facei]])
131  {
132  // First visit: owner
133  owner_[cellfaces[facei]] = celli;
134  markedFaces[cellfaces[facei]] = true;
135  }
136  else
137  {
138  // Second visit: neighbour
139  neighbour_[cellfaces[facei]] = celli;
140  nInternalFaces++;
141  }
142  }
143  }
144 
145  // The neighbour array is initialised with the same length as the owner
146  // padded with -1s and here it is truncated to the correct size of the
147  // number of internal faces.
148  neighbour_.setSize(nInternalFaces);
149 
150  // Reset the primitiveMesh
152  (
153  points_.size(),
154  neighbour_.size(),
155  owner_.size(),
156  c.size(),
157  c
158  );
159 
160  string meshInfo =
161  "nPoints: " + Foam::name(nPoints())
162  + " nCells: " + Foam::name(nCells())
163  + " nFaces: " + Foam::name(nFaces())
164  + " nInternalFaces: " + Foam::name(this->nInternalFaces());
165 
166  owner_.note() = meshInfo;
167  neighbour_.note() = meshInfo;
168 }
169 
170 
171 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
string & note()
Return non-constant access to the optional note.
Definition: IOobject.H:325
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
label nInternalFaces() const
label nCells() const
void reset(const label nPoints, const label nInternalFaces, const label nFaces, const label nCells)
Reset this primitiveMesh given the primitive array sizes.
label nPoints() const
label nFaces() const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label nPoints
#define DebugInFunction
Report an information message using Foam::Info.
const dimensionedScalar c
Speed of light in a vacuum.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
List< label > labelList
A List of labels.
Definition: labelList.H:56
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
List< cell > cellList
list of cells
Definition: cellList.H:42
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
List< bool > boolList
Bool container classes.
Definition: boolList.H:50
word name(const LagrangianState state)
Return a string representation of a Lagrangian state enumeration.
error FatalError
dimensioned< Type > max(const DimensionedField< Type, GeoMesh, PrimitiveField > &df)