VRWGraph.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 Class
25  VRWGraph
26 
27 Description
28  This class is an implementation of a graph with variable column width.
29  The imoplementation is memory efficient.
30 
31 SourceFiles
32  VRWGraphI.H
33  VRWGraph.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef VRWGraph_H
38 #define VRWGraph_H
39 
40 #include "labelLongList.H"
41 #include "graphRow.H"
42 #include "DynList.H"
43 #include "bool.H"
44 #include "error.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 namespace Foam
49 {
50 
51 class VRWGraphModifier;
52 
53 class rowElement
54 {
55  // Private data
56  //- starting element of the row
57  label start_;
58 
59  //- number of elements in the row
60  label size_;
61 
62  public:
63 
64  inline rowElement()
65  :
66  start_(),
67  size_()
68  {}
69 
70  inline rowElement(const label i, const label j)
71  :
72  start_(i),
73  size_(j)
74  {}
75 
76  inline ~rowElement()
77  {}
78 
79  inline label start() const
80  {
81  return start_;
82  }
83  inline label& start()
84  {
85  return start_;
86  }
87 
88  inline label size() const
89  {
90  return size_;
91  }
92  inline label& size()
93  {
94  return size_;
95  }
96 };
97 
98 /*---------------------------------------------------------------------------*\
99  Class VRWGraph Declaration
100 \*---------------------------------------------------------------------------*/
101 
102 class VRWGraph
103 {
104  // Private data
105  //- list containing data
107 
108  //- number of rows
110 
111  // Private member functions
112  //- check index
113  inline void checkIndex(const label i, const label j) const;
114 
115  // Enumerators
116  enum typeOfEntries
117  {
118  NONE = 0,
121  FREESTART=-12
122  };
123 
124 public:
125 
126  // Friend classes
127 
128  friend class VRWGraphSMPModifier;
129 
130  // Constructors
131 
132  //- Construct null
133  inline VRWGraph();
134 
135  //- Construct given number of rows
136  explicit inline VRWGraph(const label size);
137 
138  //- Construct given number of rows and row size
139  explicit inline VRWGraph
140  (
141  const label nRows,
142  const label nColumnsInRow
143  );
144 
145  //- Construct to given number of rows, row size and initialize
146  explicit inline VRWGraph
147  (
148  const label nRows,
149  const label nColumnsInRow,
150  const label t
151  );
152 
153  //- Copy contructor
154  inline VRWGraph(const VRWGraph&);
155 
156  // Destructor
157 
158  inline ~VRWGraph();
159 
160  // Member Functions
161 
162  // Access
163 
164  //- Returns the number of rows
165  inline label size() const;
166 
167  //- Returns the number of elements in the given row
168  inline label sizeOfRow(const label rowI) const;
169 
170  // Edit
171 
172  //- Reset the number of rows
173  inline void setSize(const label);
174 
175  //- Reset the number of rows. The second argument specifies
176  //- the reserved column width
177  inline void setSizeAndColumnWidth
178  (
179  const label newNumRows,
180  const label rcWidth
181  );
182 
183  //- Set the number of rows and the size of each row
184  template<class ListType>
185  inline void setSizeAndRowSize(const ListType&);
186 
187  //- Reset the size of the given row
188  inline void setRowSize(const label rowI, const label newSize);
189 
190  //- Clear the graph
191  inline void clear();
192 
193  // Member Operators
194 
195  //- Append a list as a row at the end of the graph
196  template<class ListType>
197  inline void appendList(const ListType& l);
198 
199  //- Append an element to the given row
200  inline void append(const label rowI, const label);
201 
202  //- Append an element to the given row if it does not exist there
203  inline void appendIfNotIn(const label rowI, const label);
204 
205  //- Set row with the list
206  template<class ListType>
207  inline void setRow(const label rowI, const ListType& l);
208 
209  //- merge graphs with the identical number of rows
210  //- into a single one. Use for SMP parallelisation
211  inline void mergeGraphs(const List<VRWGraph>& graphParts);
212 
213  //- set the graph to the reverse of the original graph.
214  //- the rows of such graph store the rows which contain the elements
215  //- of the original graph
216  template<class GraphType>
217  inline void reverseAddressing
218  (
219  const label nRows,
220  const GraphType& origGraph
221  );
222 
223  template<class GraphType>
224  inline void reverseAddressing(const GraphType& origGraph);
225 
226  inline void reverseAddressing
227  (
228  const label nRows,
229  const VRWGraph& origGraph
230  );
231 
232  inline void reverseAddressing(const VRWGraph& origGraph);
233 
234  //- optimize memory usage
235  // this should be used once the graph will not be resized any more
236  void optimizeMemoryUsage();
237 
238  //- check if the element is in the given row (takes linear time)
239  inline bool contains(const label rowI, const label e) const;
240  inline label containsAtPosition(const label rowI, const label e) const;
241 
242  //- get and set operators
243  inline label operator()(const label i, const label j) const;
244  inline label& operator()(const label i, const label j);
245 
246  inline constRow operator[](const label i) const;
247  inline row operator[](const label i);
248 
249  //- Assignment operator
250  inline void operator=(const VRWGraph&);
251 
252 
253  // IOstream operators
254 
255  // Write VRWGraph to Ostream.
256  friend Ostream& operator<<(Ostream&, const VRWGraph&);
257 
258  //- Read from Istream, discarding contents of existing VRWGraph.
259 /* friend Istream& operator>> <T, width>
260  (
261  Istream&,
262  VRWGraph<T, width>&
263  );
264 */
265 };
266 
267 
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
269 
270 } // End namespace Foam
271 
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
273 
274 #include "VRWGraphI.H"
275 
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
277 
278 #define forAllRow(graph, rowI, index) \
279  for(Foam::label index=0;index<(graph).sizeOfRow(rowI);++index)
280 
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
282 
283 #endif
284 
285 // ************************************************************************* //
Foam::VRWGraph::~VRWGraph
~VRWGraph()
Definition: VRWGraphI.H:116
Foam::VRWGraph::checkIndex
void checkIndex(const label i, const label j) const
check index
Definition: VRWGraphI.H:26
graphRow.H
Foam::VRWGraph::setRow
void setRow(const label rowI, const ListType &l)
Set row with the list.
Definition: VRWGraphI.H:354
Foam::VRWGraph::mergeGraphs
void mergeGraphs(const List< VRWGraph > &graphParts)
Definition: VRWGraphI.H:366
Foam::VRWGraph::NONE
@ NONE
Definition: VRWGraph.H:117
Foam::rowElement
Definition: VRWGraph.H:52
Foam::VRWGraph::FREESTART
@ FREESTART
Definition: VRWGraph.H:120
Foam::rowElement::rowElement
rowElement(const label i, const label j)
Definition: VRWGraph.H:69
Foam::VRWGraph::typeOfEntries
typeOfEntries
Definition: VRWGraph.H:115
Foam::VRWGraph::INVALIDROW
@ INVALIDROW
Definition: VRWGraph.H:118
Foam::VRWGraph::appendIfNotIn
void appendIfNotIn(const label rowI, const label)
Append an element to the given row if it does not exist there.
Definition: VRWGraphI.H:346
Foam::VRWGraph::contains
bool contains(const label rowI, const label e) const
check if the element is in the given row (takes linear time)
Definition: VRWGraphI.H:511
Foam::rowElement::size_
label size_
number of elements in the row
Definition: VRWGraph.H:59
Foam::LongList< label >
Foam::VRWGraph::operator=
void operator=(const VRWGraph &)
Assignment operator.
Definition: VRWGraphI.H:586
Foam::constRow
const typedef graphRow< const VRWGraph > constRow
Definition: graphRow.H:134
Foam::VRWGraph::FREEENTRY
@ FREEENTRY
Definition: VRWGraph.H:119
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
error.H
Foam::VRWGraph::optimizeMemoryUsage
void optimizeMemoryUsage()
optimize memory usage
Definition: VRWGraph.C:86
Foam::VRWGraph::data_
labelLongList data_
list containing data
Definition: VRWGraph.H:105
Foam::VRWGraph::operator<<
friend Ostream & operator<<(Ostream &, const VRWGraph &)
Foam::VRWGraph::size
label size() const
Returns the number of rows.
Definition: VRWGraphI.H:122
Foam::rowElement::rowElement
rowElement()
Definition: VRWGraph.H:63
Foam::VRWGraph::setSize
void setSize(const label)
Reset the number of rows.
Definition: VRWGraphI.H:132
Foam::rowElement::start
label start() const
Definition: VRWGraph.H:78
bool.H
System bool.
Foam::VRWGraph::setSizeAndColumnWidth
void setSizeAndColumnWidth(const label newNumRows, const label rcWidth)
Definition: VRWGraphI.H:148
Foam::VRWGraph::sizeOfRow
label sizeOfRow(const label rowI) const
Returns the number of elements in the given row.
Definition: VRWGraphI.H:127
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
VRWGraphI.H
Foam::e
const double e
Elementary charge.
Definition: doubleFloat.H:94
Foam::graphRow
Definition: graphRow.H:48
Foam::rowElement::start
label & start()
Definition: VRWGraph.H:82
Foam::rowElement::size
label size() const
Definition: VRWGraph.H:87
Foam::VRWGraph::rows_
LongList< rowElement > rows_
number of rows
Definition: VRWGraph.H:108
VRWGraphModifier
This class is a modifier for VRWGraph which allows for multi-threaded execution of most time-consuimg...
Foam::VRWGraph::operator[]
constRow operator[](const label i) const
Definition: VRWGraphI.H:575
Foam::VRWGraph::containsAtPosition
label containsAtPosition(const label rowI, const label e) const
Definition: VRWGraphI.H:529
Foam::VRWGraph::VRWGraph
VRWGraph()
Construct null.
Definition: VRWGraphI.H:52
Foam::VRWGraph::reverseAddressing
void reverseAddressing(const label nRows, const GraphType &origGraph)
Definition: VRWGraphI.H:406
Foam::VRWGraph::operator()
label operator()(const label i, const label j) const
get and set operators
Definition: VRWGraphI.H:550
Foam::VRWGraph::appendList
void appendList(const ListType &l)
Append a list as a row at the end of the graph.
Definition: VRWGraphI.H:286
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::rowElement::~rowElement
~rowElement()
Definition: VRWGraph.H:75
labelLongList.H
Foam::VRWGraph::clear
void clear()
Clear the graph.
Definition: VRWGraphI.H:278
Foam::VRWGraph::append
void append(const label rowI, const label)
Append an element to the given row.
Definition: VRWGraphI.H:303
Foam::rowElement::start_
label start_
starting element of the row
Definition: VRWGraph.H:56
Foam::rowElement::size
label & size()
Definition: VRWGraph.H:91
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:53
Foam::VRWGraphSMPModifier
Definition: VRWGraphSMPModifier.H:50
Foam::VRWGraph
Definition: VRWGraph.H:101
Foam::VRWGraph::setRowSize
void setRowSize(const label rowI, const label newSize)
Reset the size of the given row.
Definition: VRWGraphI.H:204
Foam::VRWGraph::setSizeAndRowSize
void setSizeAndRowSize(const ListType &)
Set the number of rows and the size of each row.
Definition: VRWGraphI.H:178
DynList.H