primitiveMeshPointPoints.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 // * * * * * * * * * * * * * 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
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  {
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  {
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 // ************************************************************************* //
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:57
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
const labelListList & pointEdges() const
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
Definition: DynamicList.H:56
List< edge > edgeList
Definition: edgeList.H:38
void setCapacity(const label)
Alter the size of the underlying storage.
Definition: DynamicListI.H:130
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Definition: DynamicListI.H:296
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
bool hasPointPoints() const
const labelListList & pointPoints() const
label capacity() const
Size of the underlying storage.
Definition: DynamicListI.H:121
void clear()
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:236