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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "primitiveMesh.H"
29
30// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
31
32void Foam::primitiveMesh::calcPointPoints() const
33{
34 if (debug)
35 {
36 Pout<< "primitiveMesh::calcPointPoints() : "
37 << "calculating pointPoints"
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 pointPoints
50 // if the pointer is already set
51 if (ppPtr_)
52 {
54 << "pointPoints already calculated"
55 << abort(FatalError);
56 }
57 else
58 {
59 const edgeList& e = edges();
60 const labelListList& pe = pointEdges();
61
62 ppPtr_ = new labelListList(pe.size());
63 labelListList& pp = *ppPtr_;
64
65 forAll(pe, pointi)
66 {
67 pp[pointi].setSize(pe[pointi].size());
68
69 forAll(pe[pointi], ppi)
70 {
71 if (e[pe[pointi][ppi]].start() == pointi)
72 {
73 pp[pointi][ppi] = e[pe[pointi][ppi]].end();
74 }
75 else if (e[pe[pointi][ppi]].end() == pointi)
76 {
77 pp[pointi][ppi] = e[pe[pointi][ppi]].start();
78 }
79 else
80 {
82 << "something wrong with edges"
83 << abort(FatalError);
84 }
85 }
86 }
87 }
88}
89
90
91// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
92
94{
95 if (!ppPtr_)
96 {
97 calcPointPoints();
98 }
99
100 return *ppPtr_;
101}
102
103
105(
106 const label pointi,
107 DynamicList<label>& storage
108) const
109{
110 if (hasPointPoints())
111 {
112 return pointPoints()[pointi];
113 }
114 else
115 {
116 const edgeList& edges = this->edges();
117 const labelList& pEdges = pointEdges()[pointi];
118
119 storage.clear();
120
121 if (pEdges.size() > storage.capacity())
122 {
123 storage.setCapacity(pEdges.size());
124 }
125
126 forAll(pEdges, i)
127 {
128 storage.append(edges[pEdges[i]].otherVertex(pointi));
129 }
130
131 return storage;
132 }
133}
134
135
137(
138 const label pointi
139) const
140{
141 return pointPoints(pointi, labels_);
142}
143
144
145// ************************************************************************* //
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:72
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
void append(const T &val)
Copy append an element to the end of this list.
Definition: DynamicListI.H:503
label capacity() const noexcept
Size of the underlying storage.
Definition: DynamicListI.H:287
void setCapacity(const label len)
Alter the size of the underlying storage.
Definition: DynamicListI.H:303
iterator end() noexcept
Return an iterator to end traversing the UList.
Definition: UListI.H:350
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
const labelListList & pointEdges() const
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
const labelListList & pointPoints() const
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
List< edge > edgeList
A List of edges.
Definition: edgeList.H:63
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:158
volScalarField & e
Definition: createFields.H:11
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333