Test-CompactIOList.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-2015 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  testCompactIOList
26 
27 Description
28  Simple demonstration and test application for the CompactIOList container
29 
30 \*---------------------------------------------------------------------------*/
31 
32 #include "IOstreams.H"
33 #include "argList.H"
34 #include "Time.H"
35 #include "polyMesh.H"
36 
37 using namespace Foam;
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 
41 
42 // Main program:
43 
44 int main(int argc, char *argv[])
45 {
46  #include "setRootCase.H"
47  #include "createTime.H"
48 
50  // IOstream::streamFormat format=IOstream::ASCII;
51 
52  const label size = 20000000;
53 
54  // Old format
55  // ~~~~~~~~~~
56 
57  {
58  // Construct big faceList in old format
59  faceIOList faces2
60  (
61  IOobject
62  (
63  "faces2",
64  runTime.constant(),
66  runTime,
69  false
70  ),
71  size
72  );
73 
74  const face f(identity(4));
75 
76  forAll(faces2, i)
77  {
78  faces2[i] = f;
79  }
80 
81  Info<< "Constructed faceList in = "
82  << runTime.cpuTimeIncrement() << " s" << nl << endl;
83 
84 
85  // Write binary
86  faces2.writeObject
87  (
88  format,
91  );
92 
93  Info<< "Written old format faceList in = "
94  << runTime.cpuTimeIncrement() << " s" << nl << endl;
95 
96  // Read
97  faceIOList faces3
98  (
99  IOobject
100  (
101  "faces2",
102  runTime.constant(),
104  runTime,
107  false
108  )
109  );
110 
111  Info<< "Read old format " << faces3.size() << " faceList in = "
112  << runTime.cpuTimeIncrement() << " s" << nl << endl;
113  }
114 
115 
116  // New format
117  // ~~~~~~~~~~
118 
119  {
120  // Construct big faceList in new format
121  faceCompactIOList faces2
122  (
123  IOobject
124  (
125  "faces2",
126  runTime.constant(),
128  runTime,
131  false
132  ),
133  size
134  );
135 
136  const face f(identity(4));
137 
138  forAll(faces2, i)
139  {
140  faces2[i] = f;
141  }
142 
143  Info<< "Constructed new format faceList in = "
144  << runTime.cpuTimeIncrement() << " s" << nl << endl;
145 
146 
147  // Write binary
148  faces2.writeObject
149  (
150  format,
153  );
154 
155  Info<< "Written new format faceList in = "
156  << runTime.cpuTimeIncrement() << " s" << nl << endl;
157 
158  // Read
159  faceCompactIOList faces3
160  (
161  IOobject
162  (
163  "faces2",
164  runTime.constant(),
166  runTime,
169  false
170  )
171  );
172 
173  Info<< "Read new format " << faces3.size() << " faceList in = "
174  << runTime.cpuTimeIncrement() << " s" << nl << endl;
175  }
176 
177  return 0;
178 }
179 
180 
181 // ************************************************************************* //
Foam::IOobject
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:91
format
word format(conversionProperties.lookup("format"))
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::regIOobject::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Write using given format, version and compression.
Definition: regIOobjectWrite.C:37
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
main
int main(int argc, char *argv[])
Definition: Test-CompactIOList.C:41
Foam::CompactIOList::writeObject
virtual bool writeObject(IOstream::streamFormat, IOstream::versionNumber, IOstream::compressionType) const
Definition: CompactIOList.C:175
Foam::polyMesh::meshSubDir
static word meshSubDir
Return the mesh sub-directory name (usually "polyMesh")
Definition: polyMesh.H:309
Foam::IOobject::MUST_READ
@ MUST_READ
Definition: IOobject.H:108
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::IOstream::currentVersion
static const versionNumber currentVersion
Current version number.
Definition: IOstream.H:206
polyMesh.H
Foam::IOobject::NO_WRITE
@ NO_WRITE
Definition: IOobject.H:118
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::IOobject::NO_READ
@ NO_READ
Definition: IOobject.H:111
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::CompactIOList
A List of objects of type <T> with automated input and output using a compact storage....
Definition: CompactIOList.H:53
Foam::identity
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
Foam::IOstream::BINARY
@ BINARY
Definition: IOstream.H:89
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
setRootCase.H
f
labelList f(nPoints)
Foam::IOList
A List of objects of type <T> with automated input and output.
Definition: IOList.H:50
createTime.H
Foam::IOstream::UNCOMPRESSED
@ UNCOMPRESSED
Definition: IOstream.H:195
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::IOstream::streamFormat
streamFormat
Enumeration for the format of data in the stream.
Definition: IOstream.H:86