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-2024 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(), Foam::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_ = std::make_unique<labelListList>(ncc.size());
76  auto& cellCellAddr = *ccPtr_;
77 
78 
79  // 2. Size and fill cellFaceAddr
80 
81  forAll(cellCellAddr, celli)
82  {
83  cellCellAddr[celli].resize(ncc[celli]);
84  ncc[celli] = 0; // reset size counter
85  }
86 
87  forAll(nei, facei)
88  {
89  label ownCelli = own[facei];
90  label neiCelli = nei[facei];
91 
92  cellCellAddr[ownCelli][ncc[ownCelli]++] = neiCelli;
93  cellCellAddr[neiCelli][ncc[neiCelli]++] = ownCelli;
94  }
95  }
96 }
97 
98 
99 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
100 
102 {
103  if (!ccPtr_)
104  {
105  calcCellCells();
106  }
107 
108  return *ccPtr_;
109 }
110 
111 
113 (
114  const label celli,
115  DynamicList<label>& storage
116 ) const
117 {
118  if (hasCellCells())
119  {
120  return cellCells()[celli];
121  }
122  else
123  {
124  const labelList& own = faceOwner();
125  const labelList& nei = faceNeighbour();
126  const cell& cFaces = cells()[celli];
127 
128  storage.clear();
129 
130  for (const label facei : cFaces)
131  {
132  if (facei < nInternalFaces())
133  {
134  if (own[facei] == celli)
135  {
136  storage.push_back(nei[facei]);
137  }
138  else
139  {
140  storage.push_back(own[facei]);
141  }
142  }
143  }
144 
145  return storage;
146  }
147 }
148 
149 
150 const Foam::labelList& Foam::primitiveMesh::cellCells(const label celli) const
151 {
152  return cellCells(celli, labels_);
153 }
154 
155 
156 // ************************************************************************* //
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:600
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:529
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:286
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:130
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.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
List< label > labelList
A List of labels.
Definition: List.H:61
const labelListList & cellCells() const
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.