primitiveMeshPointPoints.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 | Copyright (C) 2011 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 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
29 
30 void Foam::primitiveMesh::calcPointPoints() const
31 {
32  if (debug)
33  {
34  Pout<< "primitiveMesh::calcPointPoints() : "
35  << "calculating pointPoints"
36  << endl;
37 
38  if (debug == -1)
39  {
40  // For checking calls:abort so we can quickly hunt down
41  // origin of call
42  FatalErrorIn("primitiveMesh::calcPointPoints()")
43  << abort(FatalError);
44  }
45  }
46 
47  // It is an error to attempt to recalculate pointPoints
48  // if the pointer is already set
49  if (ppPtr_)
50  {
51  FatalErrorIn("primitiveMesh::calcPointPoints() const")
52  << "pointPoints already calculated"
53  << abort(FatalError);
54  }
55  else
56  {
57  const edgeList& e = edges();
58  const labelListList& pe = pointEdges();
59 
60  ppPtr_ = new labelListList(pe.size());
61  labelListList& pp = *ppPtr_;
62 
63  forAll(pe, pointI)
64  {
65  pp[pointI].setSize(pe[pointI].size());
66 
67  forAll(pe[pointI], ppi)
68  {
69  if (e[pe[pointI][ppi]].start() == pointI)
70  {
71  pp[pointI][ppi] = e[pe[pointI][ppi]].end();
72  }
73  else if (e[pe[pointI][ppi]].end() == pointI)
74  {
75  pp[pointI][ppi] = e[pe[pointI][ppi]].start();
76  }
77  else
78  {
79  FatalErrorIn("primitiveMesh::calcPointPoints() const")
80  << "something wrong with edges"
81  << abort(FatalError);
82  }
83  }
84  }
85  }
86 }
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
92 {
93  if (!ppPtr_)
94  {
95  calcPointPoints();
96  }
97 
98  return *ppPtr_;
99 }
100 
101 
103 (
104  const label pointI,
105  DynamicList<label>& storage
106 ) const
107 {
108  if (hasPointPoints())
109  {
110  return pointPoints()[pointI];
111  }
112  else
113  {
114  const edgeList& edges = this->edges();
115  const labelList& pEdges = pointEdges()[pointI];
116 
117  storage.clear();
118 
119  if (pEdges.size() > storage.capacity())
120  {
121  storage.setCapacity(pEdges.size());
122  }
123 
124  forAll(pEdges, i)
125  {
126  storage.append(edges[pEdges[i]].otherVertex(pointI));
127  }
128 
129  return storage;
130  }
131 }
132 
133 
135 (
136  const label pointI
137 ) const
138 {
139  return pointPoints(pointI, labels_);
140 }
141 
142 
143 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144 
145 // ************************************************************************* //
void setCapacity(const label)
Alter the size of the underlying storage.
Definition: DynamicListI.H:109
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
const labelListList & pointEdges() const
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:242
label capacity() const
Size of the underlying storage.
Definition: DynamicListI.H:100
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
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:76
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:310
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
#define forAll(list, i)
Definition: UList.H:421
errorManip< error > abort(error &err)
Definition: errorManip.H:131
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
List< edge > edgeList
Definition: edgeList.H:38
error FatalError
const labelListList & pointPoints() const
bool hasPointPoints() const
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
prefixOSstream Pout(cout,"Pout")
Definition: IOstreams.H:53