FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 <OpenFOAM/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 // ************************ vim: set sw=4 sts=4 et: ************************ //