Test-ListOps.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) 2012-2013 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-ListOps
26 
27 Description
28 
29 \*---------------------------------------------------------------------------*/
30 
31 #include "argList.H"
32 #include "List.H"
33 #include "SubList.H"
34 #include "ListOps.H"
35 #include "face.H"
36 
37 using namespace Foam;
38 
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
40 // Main program:
41 
42 int main(int argc, char *argv[])
43 {
44  Info<< "Test Rotations:" << nl << endl;
45 
46  List<label> forwardRotate(identity(5));
47  face testFace(identity(4));
48 
49  for (label i = 0; i < 8; ++i)
50  {
51  Info<< "Rotate forward by " << i << " : "
52  << rotateList(forwardRotate, i) << endl;
53  }
54 
55  for (label i = 0; i < 8; ++i)
56  {
57  Info<< "Rotate backward by " << i << " : "
58  << rotateList(forwardRotate, -i) << endl;
59  }
60 
61  Info<< nl << "Face : " << testFace << endl;
62  Info<< "Rotate by 2 : " << rotateList(testFace, 2) << endl;
63  inplaceRotateList<List, label>(testFace, -6);
64  Info<< "Rotate inplace by -6 : " << testFace << nl << endl;
65 
66  Info<< "Test inplace rotate : " << forwardRotate << endl;
67  inplaceRotateList(forwardRotate, 2);
68  Info<< "Rotate to the right by 2 : " << forwardRotate << endl;
69  inplaceRotateList(forwardRotate, -2);
70  Info<< "Rotate to the left by 2 : " << forwardRotate << endl;
71 
72  List<label> subRotate(identity(10));
73  SubList<label> subL(subRotate, 5, 3);
74 
75  Info<< "Test inplace rotate on sublist : " << subRotate << endl;
76  inplaceRotateList(subL, 3);
77  Info<< "Rotate to the right by 3 : " << subRotate << endl;
78  inplaceRotateList(subL, -8);
79  Info<< "Rotate to the left by 3 : " << subRotate << endl;
80 
81  Info<< nl << nl << "Test Reversing:" << nl << endl;
82 
83  Info<< "List : " << identity(5) << endl;
84  Info<< "Reverse : " << reverseList(identity(5)) << endl;
85  Info<< "List : " << identity(6) << endl;
86  Info<< "Reverse : " << reverseList(identity(6)) << nl << endl;
87 
88  List<label> test1(identity(5));
89  Info<< "List : " << test1 << endl;
90  inplaceReverseList(test1);
91  Info<< "Inplace Reverse : " << test1 << nl << endl;
92 
93  List<label> test2(identity(6));
94  Info<< "List : " << test2 << endl;
95  inplaceReverseList(test2);
96  Info<< "Inplace Reverse : " << test2 << nl << endl;
97 
98  face test3(identity(6));
99  Info<< "Face : " << test3 << endl;
100  inplaceReverseList(test3);
101  Info<< "Inplace Reverse : " << test3 << nl << endl;
102 
103  FixedList<label, 6> test4(identity(6));
104  Info<< "FixedList : " << test4 << endl;
105  inplaceReverseList(test4);
106  Info<< "Inplace Reverse : " << test4 << nl << endl;
107 
108  List<label> test5(identity(9));
109  SubList<label> test5SubList(test5, 4, 3);
110  Info<< "List : " << test5 << endl;
111  inplaceReverseList(test5SubList);
112  Info<< "Reverse Sublist between 3 and 6 : " << test5 << endl;
113 
114  Info<< "\nEnd\n" << endl;
115 
116  return 0;
117 }
118 
119 
120 // ************************************************************************* //
SubList.H
Foam::reverseList
ListType reverseList(const ListType &list)
Reverse a list. First element becomes last element etc.
Definition: ListOpsTemplates.C:769
List.H
Foam::SubList
A List obtained as a section of another List.
Definition: SubList.H:53
Foam::inplaceRotateList
void inplaceRotateList(ListType< DataType > &list, label n)
Inplace reversal of a list using the Reversal Block Swapping algorithm.
Definition: ListOpsTemplates.C:826
face.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
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::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
argList.H
Foam::identity
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
Definition: ListOps.C:104
Foam::rotateList
ListType rotateList(const ListType &list, const label n)
Rotate a list by n places. If n is positive rotate clockwise/right/down.
Definition: ListOpsTemplates.C:803
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::List< label >
Foam::FixedList< label, 6 >
Foam::inplaceReverseList
void inplaceReverseList(ListType &list)
Inplace reversal of a list using Swap.
Definition: ListOpsTemplates.C:786
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
ListOps.H
Various functions to operate on Lists.
main
int main(int argc, char *argv[])
Definition: Test-ListOps.C:39