primitiveMeshCellCells.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-2018 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 "primitiveMesh.H"
27 
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 void Foam::primitiveMesh::calcCellCells() const
32 {
33  // Loop through faceCells and mark up neighbours
34 
35  if (debug)
36  {
37  Pout<< "primitiveMesh::calcCellCells() : calculating cellCells"
38  << endl;
39 
40  if (debug == -1)
41  {
42  // For checking calls:abort so we can quickly hunt down
43  // origin of call
45  << abort(FatalError);
46  }
47  }
48 
49  // It is an error to attempt to recalculate cellCells
50  // if the pointer is already set
51  if (ccPtr_)
52  {
54  << "cellCells already calculated"
55  << abort(FatalError);
56  }
57  else
58  {
59  // 1. Count number of internal faces per cell
60 
61  labelList ncc(nCells(), 0);
62 
63  const labelList& own = faceOwner();
64  const labelList& nei = faceNeighbour();
65 
66  forAll(nei, facei)
67  {
68  ncc[own[facei]]++;
69  ncc[nei[facei]]++;
70  }
71 
72  // Create the storage
73  ccPtr_ = new labelListList(ncc.size());
74  labelListList& cellCellAddr = *ccPtr_;
75 
76 
77 
78  // 2. Size and fill cellFaceAddr
79 
80  forAll(cellCellAddr, celli)
81  {
82  cellCellAddr[celli].setSize(ncc[celli]);
83  }
84  ncc = 0;
85 
86  forAll(nei, facei)
87  {
88  label ownCelli = own[facei];
89  label neiCelli = nei[facei];
90 
91  cellCellAddr[ownCelli][ncc[ownCelli]++] = neiCelli;
92  cellCellAddr[neiCelli][ncc[neiCelli]++] = ownCelli;
93  }
94  }
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
99 
101 {
102  if (!ccPtr_)
103  {
104  calcCellCells();
105  }
106 
107  return *ccPtr_;
108 }
109 
110 
112 (
113  const label celli,
114  DynamicList<label>& storage
115 ) const
116 {
117  if (hasCellCells())
118  {
119  return cellCells()[celli];
120  }
121  else
122  {
123  const labelList& own = faceOwner();
124  const labelList& nei = faceNeighbour();
125  const cell& cFaces = cells()[celli];
126 
127  storage.clear();
128 
129  forAll(cFaces, i)
130  {
131  label facei = cFaces[i];
132 
133  if (facei < nInternalFaces())
134  {
135  if (own[facei] == celli)
136  {
137  storage.append(nei[facei]);
138  }
139  else
140  {
141  storage.append(own[facei]);
142  }
143  }
144  }
145 
146  return storage;
147  }
148 }
149 
150 
152 {
153  return cellCells(celli, labels_);
154 }
155 
156 
157 // ************************************************************************* //
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
label nInternalFaces() const
bool hasCellCells() const
label nCells() const
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
const cellList & cells() const
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:292
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
A cell is defined as a list of faces with extra functionality.
Definition: cell.H:56
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:224
const labelListList & cellCells() const