ENH: patchCloud: return pTraits<Type>::max for unfound points
[OpenFOAM-1.7.x.git] / applications / test / PackedList / PackedListTest.C
blob97f6060ee05c8ed1f86c7d8c5e5940d769117b94
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
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
26 Description
28 \*---------------------------------------------------------------------------*/
30 #include "argList.H"
31 #include "uLabel.H"
32 #include "IOobject.H"
33 #include "IOstreams.H"
34 #include "IFstream.H"
35 #include "PackedBoolList.H"
36 #include <climits>
39 using namespace Foam;
41 template<unsigned nBits>
42 inline void reportInfo()
44     unsigned offset = PackedList<nBits>::packing();
46     unsigned useSHL = ((1u << (nBits * offset)) - 1);
47     unsigned useSHR = (~0u >> (sizeof(unsigned)*CHAR_BIT - nBits * offset));
49     Info<< nl
50         << "PackedList<" << nBits << ">" << nl
51         << " max_value: " << PackedList<nBits>::max_value() << nl
52         << " packing: " << PackedList<nBits>::packing() << nl
53         << " utilization: " << (nBits * offset) << nl;
55     Info<< " Masking:" << nl
56         << "  shift << " << unsigned(nBits * offset) << nl
57         << "  shift >> " << unsigned((sizeof(unsigned)*CHAR_BIT) - nBits * offset)
58         << nl;
60     hex(Info);
61     Info<< "   maskLower: " << PackedList<nBits>::maskLower(PackedList<nBits>::packing())
62         << nl
63         << "      useSHL: " << useSHL << nl
64         << "      useSHR: " << useSHR << nl;
66     if (useSHL != useSHR)
67     {
68         Info<< "WARNING:  different results for SHL and SHR" << nl;
69     }
71     Info<< nl;
72     dec(Info);
76 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
77 //  Main program:
79 int main(int argc, char *argv[])
81     argList::noParallel();
82     argList::validArgs.insert("file .. fileN");
84     argList::validOptions.insert("mask", "");
85     argList::validOptions.insert("count", "");
86     argList::validOptions.insert("info", "");
88     argList args(argc, argv, false, true);
91     if (args.optionFound("mask"))
92     {
93         Info<< "bit width: " << unsigned(sizeof(unsigned)*CHAR_BIT) << endl;
94         reportInfo<1>();
95         reportInfo<2>();
96         reportInfo<3>();
97         reportInfo<4>();
98         reportInfo<5>();
99         reportInfo<6>();
100         reportInfo<7>();
101         reportInfo<8>();
102         reportInfo<9>();
103         reportInfo<10>();
104         reportInfo<11>();
105         reportInfo<12>();
106         reportInfo<13>();
107         reportInfo<14>();
108         reportInfo<15>();
109         reportInfo<16>();
110         reportInfo<17>();
111         reportInfo<18>();
112         reportInfo<19>();
113         reportInfo<20>();
114         reportInfo<21>();
115         reportInfo<22>();
116         reportInfo<23>();
117         reportInfo<24>();
118         reportInfo<25>();
119         reportInfo<26>();
120         reportInfo<27>();
121         reportInfo<28>();
122         reportInfo<29>();
123         reportInfo<30>();
124         reportInfo<31>();
126         return 0;
127     }
128     else if (args.additionalArgs().empty())
129     {
130         args.printUsage();
131     }
134     forAll(args.additionalArgs(), argI)
135     {
136         const string& srcFile = args.additionalArgs()[argI];
137         Info<< nl << "reading " << srcFile << nl;
139         IFstream ifs(srcFile);
140         List<label> rawLst(ifs);
142         PackedBoolList packLst(rawLst);
144         Info<< "size: " << packLst.size() << nl;
146         if (args.optionFound("count"))
147         {
148             unsigned int rawCount = 0;
149             forAll(rawLst, elemI)
150             {
151                 if (rawLst[elemI])
152                 {
153                     rawCount++;
154                 }
155             }
156             Info<< "raw count: " << rawCount << nl
157                 << "packed count: " << packLst.count() << nl;
158         }
160         if (args.optionFound("info"))
161         {
162             packLst.print(Info);
163         }
165         Info<< nl;
166         IOobject::writeDivider(Info);
167     }
169     return 0;
172 // ************************************************************************* //