Test-FixedList.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  Test-FixedList
26 
27 Description
28  Simple tests and examples of use of FixedList
29 
30 See Also
31  Foam::FixedList
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #include "argList.H"
36 #include "IOstreams.H"
37 #include "FixedList.H"
38 #include "IFstream.H"
39 #include "OFstream.H"
40 #include "IPstream.H"
41 #include "OPstream.H"
42 
43 using namespace Foam;
44 
45 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
46 // Main program:
47 
48 int main(int argc, char *argv[])
49 {
50  argList args(argc, argv);
51 
53  list[0] = 1;
54  list[1] = 2;
55  list[2] = 3;
56  list[3] = 4;
57 
58  Info<< "list:" << list
59  << " hash:" << FixedList<label, 4>::Hash<>()(list) << endl;
60 
61  label a[4] = {0, 1, 2, 3};
62  FixedList<label, 4> list2(a);
63 
64  Info<< "list2:" << list2
65  << " hash:" << FixedList<label, 4>::Hash<>()(list2) << endl;
66 
67  Info<< "list: " << list << nl
68  << "list2: " << list2 << endl;
69  list.swap(list2);
70  Info<< "Swapped via the swap() method" << endl;
71  Info<< "list: " << list << nl
72  << "list2: " << list2 << endl;
73 
74  if (Pstream::parRun())
75  {
77  {
78  Serr<< "slave sending to master "
79  << Pstream::masterNo() << endl;
80 
82 
83  FixedList<label, 2> list3;
84  list3[0] = 0;
85  list3[1] = 1;
86  toMaster << list3;
87  }
88  else
89  {
90  for
91  (
92  int slave = Pstream::firstSlave();
93  slave <= Pstream::lastSlave();
94  slave++
95  )
96  {
97  Serr << "master receiving from slave " << slave << endl;
98  IPstream fromSlave(Pstream::blocking, slave);
99  FixedList<label, 2> list3(fromSlave);
100 
101  Serr<< list3 << endl;
102  }
103  }
104  }
105 
106  return 0;
107 }
108 
109 
110 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::OPstream
Output inter-processor communications stream.
Definition: OPstream.H:50
Foam::UPstream::parRun
static bool & parRun()
Is this a parallel run?
Definition: UPstream.H:377
OPstream.H
Foam::argList
Extract command arguments and options from the supplied argc and argv parameters.
Definition: argList.H:97
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
OFstream.H
Foam::UPstream::blocking
@ blocking
Definition: UPstream.H:66
IPstream.H
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::UPstream::lastSlave
static int lastSlave(const label communicator=0)
Process index of last slave.
Definition: UPstream.H:428
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::Serr
OSstream Serr(cerr, "Serr")
Definition: IOstreams.H:52
Foam::UPstream::masterNo
static int masterNo()
Process index of the master.
Definition: UPstream.H:393
IFstream.H
main
int main(int argc, char *argv[])
Definition: Test-FixedList.C:45
Foam::UPstream::firstSlave
static int firstSlave()
Process index of first slave.
Definition: UPstream.H:422
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::UPstream::myProcNo
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
Definition: UPstream.H:405
Foam::FixedList::swap
void swap(FixedList< T, Size > &)
Swap two FixedLists of the same type in constant time.
Definition: FixedList.C:32
Foam::FixedList< label, 4 >
Foam::IPstream
Input inter-processor communications stream.
Definition: IPstream.H:50
FixedList.H
args
Foam::argList args(argc, argv)