Test-UIndirectList.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 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 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "UIndirectList.H"
29 #include "DynamicList.H"
30 #include "IOstreams.H"
31 #include "ListOps.H"
32 #include "OFstream.H"
33 
34 using namespace Foam;
35 
36 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
37 // Main program:
38 
39 int main(int argc, char *argv[])
40 {
41  List<double> completeList(10);
42 
43  forAll(completeList, i)
44  {
45  completeList[i] = 0.1*i;
46  }
47 
48  List<label> addresses(5);
49  addresses[0] = 1;
50  addresses[1] = 0;
51  addresses[2] = 7;
52  addresses[3] = 8;
53  addresses[4] = 5;
54 
55  UIndirectList<double> idl(completeList, addresses);
56 
57  Info<< idl << "\n";
58 
59  idl[1] = -666;
60 
61  Info<< "idl[1] changed: " << idl << endl;
62 
63  idl = -999;
64 
65  Info<< "idl changed: " << idl << endl;
66 
67  UIndirectList<double> idl2(idl);
68 
69  Info<< "idl2: " << idl2 << endl;
70 
71 
72  {
73  List<double> ident(idl.size());
74 
75  forAll(ident, i)
76  {
77  ident[i] = ident.size() - i;
78  }
79  idl = ident;
80  }
81 
82  Info<< "idl assigned from UList: " << idl << endl;
83 
84  // test List operations
85 
86  List<double> flatList(UIndirectList<double>(completeList, addresses));
87  Info<< "List constructed from UIndirectList: " << flatList << endl;
88 
89  flatList = UIndirectList<double>(completeList, addresses);
90  Info<< "List assigned from UIndirectList: " << flatList << endl;
91 
92  flatList.append(UIndirectList<double>(completeList, addresses));
93  Info<< "List::append(UIndirectList): " << flatList << endl;
94 
95 
96  DynamicList<double> dynList(UIndirectList<double>(completeList, addresses));
97  Info<< "DynamicList constructed from UIndirectList: " << dynList << endl;
98 
99  dynList.append(UIndirectList<double>(completeList, addresses));
100  Info<< "DynamicList::append(UIndirectList): " << dynList << endl;
101 
102  Info<< "\nEnd\n" << endl;
103 
104  return 0;
105 }
106 
107 
108 // ************************************************************************* //
IOstreams.H
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
UIndirectList.H
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::DynamicList
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:56
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
OFstream.H
Foam::List::append
void append(const T &)
Append an element at the end of the list.
Foam::Info
messageStream Info
main
int main(int argc, char *argv[])
Definition: Test-UIndirectList.C:39
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::DynamicList::append
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::UIndirectList
A List with indirect addressing.
Definition: fvMatrix.H:106
DynamicList.H
ListOps.H
Various functions to operate on Lists.
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.