subGraphI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | cfMesh: A library for mesh generation
4  \\ / O peration |
5  \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6  \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
8 License
9  This file is part of cfMesh.
10 
11  cfMesh is free software; you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by the
13  Free Software Foundation; either version 3 of the License, or (at your
14  option) any later version.
15 
16  cfMesh 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 cfMesh. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 namespace Foam
27 {
28 
29 template<class graphType>
30 inline void Foam::subGraph<graphType>::checkIndex(const label i) const
31 {
32  if( (i < 0) || (i >= size_) )
33  {
35  (
36  "void Foam::subGraph<graphType>::"
37  "checkIndex(const label i) const"
38  ) << "Row index " << i
39  << " is not in range " << Foam::label(0)
40  << " and " << size_ << abort(FatalError);
41  }
42 }
43 
44 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
45 
46 template<class graphType>
48 (
49  graphType& g,
50  const label start,
51  const label size
52 )
53 :
54  data_(g),
55  start_(start),
56  size_(size)
57 {
58 }
59 
60 template<class graphType>
62 (
63  const subGraph<graphType>& ol
64 )
65 :
66  data_(ol.data_),
67  start_(ol.start_),
68  size_(ol.size_)
69 {
70 }
71 
72 template<class graphType>
74 {
75 }
76 
77 
78 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
79 
80 template<class graphType>
82 {
83  return size_;
84 }
85 
86 template<class graphType>
88 {
89  return data_.sizeOfRow(start_+rowI);
90 }
91 
92 template<class graphType>
93 inline void Foam::subGraph<graphType>::append(const label rowI, const label el)
94 {
95  data_.append(start_+rowI, el);
96 }
97 
98 template<class graphType>
100 (
101  const label rowI,
102  const label el
103 )
104 {
105  data_.appendIfNotIn(start_+rowI, el);
106 }
107 
108 template<class graphType>
110 (
111  const label rowI,
112  const label e
113 ) const
114 {
115  return data_.contains(start_+rowI, e);
116 }
117 
118 template<class graphType>
120 (
121  const label rowI,
122  const label e
123 ) const
124 {
125  return data_.containsAtPosition(start_+rowI, e);
126 }
127 
128 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
129 
130 template<class graphType>
132 (
133  const label i,
134  const label j
135 ) const
136 {
137  # ifdef FULLDEBUG
138  checkIndex(i);
139  # endif
140 
141  return data_(start_+i, j);
142 }
143 
144 template<class graphType>
146 (
147  const label i,
148  const label j
149 )
150 {
151  return data_(start_+i, j);
152 }
153 
154 
155 template<class graphType>
158 (
159  const label i
160 ) const
161 {
162  return data_[start_+i];
163 }
164 
165 template<class graphType>
168 {
169  return data_[start_+i];
170 }
171 
172 template<class graphType>
173 inline Foam::Ostream& operator<<
174 (
175  Foam::Ostream& os,
176  const Foam::subGraph<graphType>& sg
177 )
178 {
179  os << sg.size() << "\n" << "(";
180  for(Foam::label i=0;i<sg.size();++i)
181  {
182  os << "\n" << sg.sizeOfRow(i) << "(";
183  for(Foam::label j=0;j<sg.sizeOfRow(i);++j)
184  {
185  if( j > 0 ) os << " ";
186 
187  os << sg(i, j);
188  }
189 
190  os << ")";
191  }
192 
193  os << "\n" << ")";
194 
195  return os;
196 }
197 
198 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199 
200 } // End namespace Foam
201 
202 // ************************************************************************* //
Foam::subGraph::data_
graphType & data_
reference to the graph
Definition: subGraph.H:60
Foam::subGraph::contains
bool contains(const label rowI, const label e) const
check if the element is in the given row (takes linear time)
Definition: subGraphI.H:110
Foam::subGraph::start_
const label start_
starts at row
Definition: subGraph.H:63
Foam::subGraph::containsAtPosition
label containsAtPosition(const label rowI, const label e) const
Definition: subGraphI.H:120
Foam::subGraph::subGraph
subGraph(graphType &, const label, const label)
Construct from graph and start row and size.
Definition: subGraphI.H:48
g
const dimensionedVector & g
Definition: setRegionFluidFields.H:33
Foam::subGraph::append
void append(const label rowI, const label)
Append an element to the given row.
Definition: subGraphI.H:93
Foam::label
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
Foam::subGraph::size_
const label size_
number of rows in the subGraph
Definition: subGraph.H:66
Foam::subGraph::appendIfNotIn
void appendIfNotIn(const label rowI, const label)
Append an element to the given row if it does not exist there.
Definition: subGraphI.H:100
Foam::subGraph
Definition: subGraph.H:47
Foam::FatalError
error FatalError
Foam::subGraph::size
label size() const
Returns the number of rows.
Definition: subGraphI.H:81
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::graphRow
Definition: graphRow.H:48
Foam::subGraph::operator[]
const graphRow< const graphType > operator[](const label) const
Definition: subGraphI.H:158
Foam::subGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the size of a given row.
Definition: subGraphI.H:87
Foam::subGraph::checkIndex
void checkIndex(const label i) const
check index
Definition: subGraphI.H:30
Foam::subGraph::operator
friend Ostream & operator(Ostream &, const subGraph< graphType > &)
FatalErrorIn
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:313
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::subGraph::~subGraph
~subGraph()
Definition: subGraphI.H:73