BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / applications / test / CompactIOList / Test-CompactIOList.C
blobf224bb307c2340e9ca5c1b9bd10053db80d75b68
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.
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.
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.
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/>.
24 Application
25     testCompactIOList
27 Description
28     Simple demonstration and test application for the CompactIOList container
30 \*---------------------------------------------------------------------------*/
32 #include "IOstreams.H"
33 #include "argList.H"
34 #include "Time.H"
35 #include "polyMesh.H"
37 using namespace Foam;
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 //  Main program:
44 int main(int argc, char *argv[])
46 #   include "setRootCase.H"
47 #   include "createTime.H"
49     IOstream::streamFormat format=IOstream::BINARY;
50     // IOstream::streamFormat format=IOstream::ASCII;
52     const label size = 20000000;
54     // Old format
55     // ~~~~~~~~~~
57     {
58         // Construct big faceList in old format
59         faceIOList faces2
60         (
61             IOobject
62             (
63                 "faces2",
64                 runTime.constant(),
65                 polyMesh::meshSubDir,
66                 runTime,
67                 IOobject::NO_READ,
68                 IOobject::NO_WRITE,
69                 false
70             ),
71             size
72         );
74         const face f(identity(4));
76         forAll(faces2, i)
77         {
78             faces2[i] = f;
79         }
81         Info<< "Constructed faceList in = "
82             << runTime.cpuTimeIncrement() << " s" << nl << endl;
85         // Write binary
86         faces2.writeObject
87         (
88             format,
89             IOstream::currentVersion,
90             IOstream::UNCOMPRESSED
91         );
93         Info<< "Written old format faceList in = "
94             << runTime.cpuTimeIncrement() << " s" << nl << endl;
96         // Read
97         faceIOList faces3
98         (
99             IOobject
100             (
101                 "faces2",
102                 runTime.constant(),
103                 polyMesh::meshSubDir,
104                 runTime,
105                 IOobject::MUST_READ,
106                 IOobject::NO_WRITE,
107                 false
108             )
109         );
111         Info<< "Read old format " << faces3.size() << " faceList in = "
112             << runTime.cpuTimeIncrement() << " s" << nl << endl;
113     }
116     // New format
117     // ~~~~~~~~~~
119     {
120         // Construct big faceList in new format
121         faceCompactIOList faces2
122         (
123             IOobject
124             (
125                 "faces2",
126                 runTime.constant(),
127                 polyMesh::meshSubDir,
128                 runTime,
129                 IOobject::NO_READ,
130                 IOobject::NO_WRITE,
131                 false
132             ),
133             size
134         );
136         const face f(identity(4));
138         forAll(faces2, i)
139         {
140             faces2[i] = f;
141         }
143         Info<< "Constructed new format faceList in = "
144             << runTime.cpuTimeIncrement() << " s" << nl << endl;
147         // Write binary
148         faces2.writeObject
149         (
150             format,
151             IOstream::currentVersion,
152             IOstream::UNCOMPRESSED
153         );
155         Info<< "Written new format faceList in = "
156             << runTime.cpuTimeIncrement() << " s" << nl << endl;
158         // Read
159         faceCompactIOList faces3
160         (
161             IOobject
162             (
163                 "faces2",
164                 runTime.constant(),
165                 polyMesh::meshSubDir,
166                 runTime,
167                 IOobject::MUST_READ,
168                 IOobject::NO_WRITE,
169                 false
170             )
171         );
173         Info<< "Read new format " << faces3.size() << " faceList in = "
174             << runTime.cpuTimeIncrement() << " s" << nl << endl;
175     }
177     return 0;
181 // ************************************************************************* //