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 -------------------------------------------------------------------------------
10 License
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 
32 void 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 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::edgeList
List< edge > edgeList
A List of edges.
Definition: edgeList.H:63
Foam::DynamicList< label >
primitiveMesh.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::DynamicList::capacity
label capacity() const noexcept
Size of the underlying storage.
Definition: DynamicListI.H:287
Foam::primitiveMesh::edges
const edgeList & edges() const
Return mesh edges. Uses calcEdges.
Definition: primitiveMeshEdges.C:505
Foam::Pout
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
Foam::primitiveMesh::pointEdges
const labelListList & pointEdges() const
Definition: primitiveMeshEdges.C:516
Foam::DynamicList::clear
void clear() noexcept
Clear the addressed list, i.e. set the size to zero.
Definition: DynamicListI.H:391
Foam::DynamicList::setCapacity
void setCapacity(const label len)
Alter the size of the underlying storage.
Definition: DynamicListI.H:303
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::DynamicList::append
DynamicList< T, SizeMin > & append(const T &val)
Append an element to the end of this list.
Definition: DynamicListI.H:511
Foam::FatalError
error FatalError
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::labelListList
List< labelList > labelListList
A List of labelList.
Definition: labelList.H:56
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::List< labelList >
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
Foam::primitiveMesh::pointPoints
const labelListList & pointPoints() const
Definition: primitiveMeshPointPoints.C:93