primitiveMeshCellCells.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) 2023 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 "primitiveMesh.H"
30 
31 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
32 
33 void Foam::primitiveMesh::calcCellCells() const
34 {
35  // Loop through faceCells and mark up neighbours
36 
37  if (debug)
38  {
39  Pout<< "primitiveMesh::calcCellCells() : calculating cellCells"
40  << endl;
41 
42  if (debug == -1)
43  {
44  // For checking calls:abort so we can quickly hunt down
45  // origin of call
47  << abort(FatalError);
48  }
49  }
50 
51  // It is an error to attempt to recalculate cellCells
52  // if the pointer is already set
53  if (ccPtr_)
54  {
56  << "cellCells already calculated"
57  << abort(FatalError);
58  }
59  else
60  {
61  // 1. Count number of internal faces per cell
62 
63  labelList ncc(nCells(), Zero);
64 
65  const labelList& own = faceOwner();
66  const labelList& nei = faceNeighbour();
67 
68  forAll(nei, facei)
69  {
70  ncc[own[facei]]++;
71  ncc[nei[facei]]++;
72  }
73 
74  // Create the storage
75  ccPtr_ = new labelListList(ncc.size());
76  labelListList& cellCellAddr = *ccPtr_;
77 
78 
79 
80  // 2. Size and fill cellFaceAddr
81 
82  forAll(cellCellAddr, celli)
83  {
84  cellCellAddr[celli].setSize(ncc[celli]);
85  }
86  ncc = 0;
87 
88  forAll(nei, facei)
89  {
90  label ownCelli = own[facei];
91  label neiCelli = nei[facei];
92 
93  cellCellAddr[ownCelli][ncc[ownCelli]++] = neiCelli;
94  cellCellAddr[neiCelli][ncc[neiCelli]++] = ownCelli;
95  }
96  }
97 }
98 
99 
100 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
101 
103 {
104  if (!ccPtr_)
105  {
106  calcCellCells();
107  }
108 
109  return *ccPtr_;
110 }
111 
112 
114 (
115  const label celli,
116  DynamicList<label>& storage
117 ) const
118 {
119  if (hasCellCells())
120  {
121  return cellCells()[celli];
122  }
123  else
124  {
125  const labelList& own = faceOwner();
126  const labelList& nei = faceNeighbour();
127  const cell& cFaces = cells()[celli];
128 
129  storage.clear();
130 
131  for (const label facei : cFaces)
132  {
133  if (facei < nInternalFaces())
134  {
135  if (own[facei] == celli)
136  {
137  storage.push_back(nei[facei]);
138  }
139  else
140  {
141  storage.push_back(own[facei]);
142  }
143  }
144  }
145 
146  return storage;
147  }
148 }
149 
150 
151 const Foam::labelList& Foam::primitiveMesh::cellCells(const label celli) const
152 {
153  return cellCells(celli, labels_);
154 }
155 
156 
157 // ************************************************************************* //
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
List< labelList > labelListList
List of labelList.
Definition: labelList.H:38
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
virtual const labelList & faceNeighbour() const =0
Face face-neighbour addressing.
const cellShapeList & cells
void clear()
Clear the list, i.e. set size to zero.
Definition: ListI.H:137
errorManip< error > abort(error &err)
Definition: errorManip.H:139
int debug
Static debugging option.
label nCells() const noexcept
Number of mesh cells.
virtual const labelList & faceOwner() const =0
Face face-owner addressing.
List< label > labelList
A List of labels.
Definition: List.H:62
const labelListList & cellCells() const
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127