Test-CompactListList.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) 2011 OpenFOAM Foundation
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 Application
25  CompactListListTest
26 
27 Description
28  Simple demonstration and test application for the CompactListList class.
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "CompactListList.H"
33 #include "IOstreams.H"
34 #include "OStringStream.H"
35 #include "IStringStream.H"
36 #include "faceList.H"
37 
38 using namespace Foam;
39 
40 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 // Main program:
42 
43 int main(int argc, char *argv[])
44 {
45  {
46  // null construct
48  Info<< "cll1:" << cll1 << endl;
49 
50  // Resize and assign row by row
51  labelList row0(2, 0);
52  labelList row1(3, 1);
53 
54  labelList rowSizes(2);
55  rowSizes[0] = row0.size();
56  rowSizes[1] = row1.size();
57  cll1.resize(rowSizes);
58 
59  cll1[0].assign(row0); //note: operator= will not work since UList
60  cll1[1].assign(row1);
61  Info<< "cll1:" << cll1 << endl;
62 
63  forAll(cll1.m(), i)
64  {
65  Info<< "i:" << i << " whichRow:" << cll1.whichRow(i) << endl;
66  }
67  }
68 
69  List<List<label> > lll(5);
70  lll[0].setSize(3, 0);
71  lll[1].setSize(2, 1);
72  lll[2].setSize(6, 2);
73  lll[3].setSize(0, 3);
74  lll[4].setSize(1, 4);
75 
76  CompactListList<label> cll2(lll);
77 
78  Info<< "cll2 = " << cll2 << endl;
79 
80  forAll(cll2, i)
81  {
82  Info<< cll2[i] << endl;
83  }
84 
85  Info<< endl;
86 
87  Info<< "cll2(2, 3) = " << cll2(2, 3) << nl << endl;
88  cll2(2, 3) = 999;
89  Info<< "cll2(2, 3) = " << cll2(2, 3) << nl << endl;
90 
91  Info<< "cll2 as List<List<label > > " << cll2()
92  << endl;
93 
94  cll2.setSize(3);
95 
96  Info<< "cll2 = " << cll2 << endl;
97 
98  cll2.setSize(0);
99 
100  Info<< "cll2 = " << cll2 << endl;
101 
102 
103  List<label> rowSizes(5);
104  rowSizes[0] = 2;
105  rowSizes[1] = 0;
106  rowSizes[2] = 1;
107  rowSizes[3] = 3;
108  rowSizes[4] = 2;
109 
110  CompactListList<label> cll3(rowSizes, 1);
111 
112  Info<< "cll3 = " << cll3 << endl;
113 
115 
116  cll4.transfer(cll3);
117 
118  Info<< "cll3 = " << cll3 << endl;
119  Info<< "cll4 = " << cll4 << endl;
120 
121 
122  {
123  // IO
124  OStringStream ostr;
125  ostr << cll4;
126 
127  IStringStream istr(ostr.str());
128  CompactListList<label> cll5(istr);
129  Info<< "cll5 = " << cll5 << endl;
130  }
131  {
132  // IO
133  cll4.clear();
134  OStringStream ostr;
135  ostr << cll4;
136 
137  IStringStream istr(ostr.str());
138  CompactListList<label> cll5(istr);
139  Info<< "cll5 = " << cll5 << endl;
140  }
141 
142  {
143  faceList fcs(2);
144  fcs[0] = face(labelList(1, 111));
145  fcs[1] = face(labelList(2, 222));
146 
147  CompactListList<label, face> compactFcs(fcs);
148  Info<< "comactFcs:" << compactFcs << endl;
149 
150  faceList fcs2 = compactFcs();
151  Info<< "fcs2:" << fcs2 << endl;
152  }
153 
154  return 0;
155 }
156 
157 
158 // ************************************************************************* //
Foam::CompactListList::m
const List< T > & m() const
Return the packed matrix of data.
Definition: CompactListListI.H:116
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::CompactListList::whichRow
label whichRow(const label index) const
Get row for index into m.
Definition: CompactListListI.H:142
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: polyTopoChange.H:91
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
main
int main(int argc, char *argv[])
Definition: Test-CompactListList.C:40
faceList.H
IStringStream.H
Foam::OStringStream::str
string str() const
Return the string.
Definition: OStringStream.H:107
Foam::CompactListList::resize
void resize(const label nRows)
Reset size of CompactListList.
Definition: CompactListListI.H:176
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
OStringStream.H
Foam::CompactListList::clear
void clear()
Clear the CompactListList, i.e. set sizes to zero.
Definition: CompactListList.C:213
Foam::IStringStream
Input from memory buffer stream.
Definition: IStringStream.H:49
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::CompactListList::transfer
void transfer(CompactListList< T, Container > &)
Transfer the contents of the argument CompactListList.
Definition: CompactListList.C:223
Foam::CompactListList::setSize
void setSize(const label nRows)
Reset size of CompactListList.
Definition: CompactListList.C:128
Foam::List::setSize
void setSize(const label)
Reset size of List.
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::OStringStream
Output to memory buffer stream.
Definition: OStringStream.H:49
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
CompactListList.H
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.