initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / applications / test / FixedList / FixedListTest.C
blobe46e910d3a266ad2359c272ab6d7ce250a13e7e5
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 Application
26     FixedListTest
28 Description
30 \*---------------------------------------------------------------------------*/
32 #include "argList.H"
33 #include "IOstreams.H"
34 #include "FixedList.H"
35 #include "IFstream.H"
36 #include "OFstream.H"
37 #include "IPstream.H"
38 #include "OPstream.H"
40 using namespace Foam;
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 //  Main program:
45 int main(int argc, char *argv[])
47     argList::validArgs.clear();
48     argList args(argc, argv);
50     FixedList<label, 4> list;
51     list[0] = 1;
52     list[1] = 2;
53     list[2] = 3;
54     list[3] = 4;
56     Info<< "list:" << list
57         << " hash:" << FixedList<label, 4>::Hash<>()(list) << endl;
59     Info<< "FixedList<label, ..> is contiguous, "
60         "thus hashing function is irrelevant: with string::hash" << endl;
62     Info<< "list:" << list
63         << " hash:" << FixedList<label, 4>::Hash<string::hash>()(list) << endl;
65     label a[4] = {0, 1, 2, 3};
66     FixedList<label, 4> list2(a);
68     Info<< "list:" << list2
69         << " hash:" << FixedList<label, 4>::Hash<>()(list2) << endl;
71     // FixedList<label, 3> hmm(Sin);
72     // Info<< hmm << endl;
74     if (Pstream::parRun())
75     {
76         if (Pstream::myProcNo() != Pstream::masterNo())
77         {
78             Serr<< "slave sending to master "
79                 << Pstream::masterNo() << endl;
81             OPstream toMaster
82             (
83                 Pstream::blocking, Pstream::masterNo(), IOstream::ASCII
84             );
86             FixedList<label, 2> list3;
87             list3[0] = 0;
88             list3[1] = 1;
89             toMaster << list3;
90         }
91         else
92         {
93             for
94             (
95                 int slave = Pstream::firstSlave();
96                 slave <= Pstream::lastSlave();
97                 slave++
98             )
99             {
100                 Serr << "master receiving from slave " << slave << endl;
101                 IPstream fromSlave
102                 (
103                     Pstream::blocking, slave, IOstream::ASCII
104                 );
105                 FixedList<label, 2> list3(fromSlave);
107                 Serr<< list3 << endl;
108             }
109         }
110     }
112     return 0;
116 // ************************************************************************* //