1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | cfMesh: A library for mesh generation
5 \\ / A nd | Author: Franjo Juretic (franjo.juretic@c-fields.com)
6 \\/ M anipulation | Copyright (C) Creative Fields, Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of cfMesh.
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.
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
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/>.
28 This class is an implementation of a graph with variable column width.
29 The imoplementation is memory efficient.
35 \*---------------------------------------------------------------------------*/
40 #include "labelLongList.H"
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51 class VRWGraphModifier;
56 //- starting element of the row
59 //- number of elements in the row
70 inline rowElement(const label i, const label j)
79 inline label start() const
88 inline label size() const
98 /*---------------------------------------------------------------------------*\
99 Class VRWGraph Declaration
100 \*---------------------------------------------------------------------------*/
105 //- list containing data
109 LongList<rowElement> rows_;
111 // Private member functions
113 inline void checkIndex(const label i, const label j) const;
128 friend class VRWGraphSMPModifier;
135 //- Construct given number of rows
136 explicit inline VRWGraph(const label size);
138 //- Construct given number of rows and row size
139 explicit inline VRWGraph
142 const label nColumnsInRow
145 //- Construct to given number of rows, row size and initialize
146 explicit inline VRWGraph
149 const label nColumnsInRow,
154 inline VRWGraph(const VRWGraph&);
164 //- Returns the number of rows
165 inline label size() const;
167 //- Returns the number of elements in the given row
168 inline label sizeOfRow(const label rowI) const;
172 //- Reset the number of rows
173 inline void setSize(const label);
175 //- Reset the number of rows. The second argument specifies
176 //- the reserved column width
177 inline void setSizeAndColumnWidth
179 const label newNumRows,
183 //- Set the number of rows and the size of each row
184 template<class ListType>
185 inline void setSizeAndRowSize(const ListType&);
187 //- Reset the size of the given row
188 inline void setRowSize(const label rowI, const label newSize);
195 //- Append a list as a row at the end of the graph
196 template<class ListType>
197 inline void appendList(const ListType& l);
199 //- Append an element to the given row
200 inline void append(const label rowI, const label);
202 //- Append an element to the given row if it does not exist there
203 inline void appendIfNotIn(const label rowI, const label);
205 //- Set row with the list
206 template<class ListType>
207 inline void setRow(const label rowI, const ListType& l);
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);
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
220 const GraphType& origGraph
223 template<class GraphType>
224 inline void reverseAddressing(const GraphType& origGraph);
226 inline void reverseAddressing
229 const VRWGraph& origGraph
232 inline void reverseAddressing(const VRWGraph& origGraph);
234 //- optimize memory usage
235 // this should be used once the graph will not be resized any more
236 void optimizeMemoryUsage();
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;
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);
246 inline constRow operator[](const label i) const;
247 inline row operator[](const label i);
249 //- Assignment operator
250 inline void operator=(const VRWGraph&);
253 // IOstream operators
255 // Write VRWGraph to Ostream.
256 friend Ostream& operator<<(Ostream&, const VRWGraph&);
258 //- Read from Istream, discarding contents of existing VRWGraph.
259 /* friend Istream& operator>> <T, width>
268 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
270 } // End namespace Foam
272 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
274 #include "VRWGraphI.H"
276 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
278 #define forAllRow(graph, rowI, index) \
279 for(Foam::label index=0;index<(graph).sizeOfRow(rowI);++index)
281 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
285 // ************************************************************************* //