Test-Circulator.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-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-circulator
26 
27 Description
28 
29 \*---------------------------------------------------------------------------*/
30 
31 #include "List.H"
32 #include "ListOps.H"
33 #include "face.H"
34 #include "Circulator.H"
35 #include "ConstCirculator.H"
36 
37 
38 using namespace Foam;
39 
40 
41 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
42 // Main program:
43 
44 int main(int argc, char *argv[])
45 {
46  Info<< "Test the implementation of a circular iterator" << nl << endl;
47 
48  Info<< "Test const circulator. First go forwards, then backwards."
49  << nl << endl;
50 
51  face f(identity(4));
52 
53  ConstCirculator<face> cStart(f);
54 
55  if (cStart.size()) do
56  {
57  Info<< "Iterate forwards over face (prev/curr/next) : "
58  << cStart.prev() << " / " << cStart() << " / " << cStart.next()
59  << endl;
60 
61  } while (cStart.circulate(CirculatorBase::CLOCKWISE));
62 
63  if (cStart.size()) do
64  {
65  Info<< "Iterate backwards over face : " << cStart() << endl;
66 
67  } while (cStart.circulate(CirculatorBase::ANTICLOCKWISE));
68 
69 
70  Info<< nl << nl << "Test non-const circulator" << nl << endl;
71 
72  Circulator<face> cStart2(f);
73 
74  Info<< "Face before : " << f << endl;
75 
76  if (cStart2.size()) do
77  {
78  Info<< "Iterate forwards over face (prev/curr/next) : "
79  << cStart2.prev() << " / " << cStart2() << " / " << cStart2.next()
80  << endl;
81 
82  } while (cStart2.circulate(CirculatorBase::CLOCKWISE));
83 
84  if (cStart2.size()) do
85  {
86  Info<< "Iterate forwards over face, adding 1 to each element : "
87  << cStart2();
88 
89  cStart2() += 1;
90 
91  Info<< " -> " << cStart2() << endl;
92  } while (cStart2.circulate(CirculatorBase::CLOCKWISE));
93 
94  Info<< "Face after : " << f << endl;
95 
96 
97  Info<< nl << nl << "Compare two faces: " << endl;
98  face a(identity(5));
99  Info<< "Compare " << a << " and " << a << " Match = " << face::compare(a, a)
100  << endl;
101 
102  face b(reverseList(a));
103  Info<< "Compare " << a << " and " << b << " Match = " << face::compare(a, b)
104  << endl;
105 
106  face c(a);
107  c[4] = 3;
108  Info<< "Compare " << a << " and " << c << " Match = " << face::compare(a, c)
109  << endl;
110 
111  face d(rotateList(a, 2));
112  Info<< "Compare " << a << " and " << d << " Match = " << face::compare(a, d)
113  << endl;
114 
115  face g(labelList(5, 1));
116  face h(g);
117  Info<< "Compare " << g << " and " << h << " Match = " << face::compare(g, h)
118  << endl;
119 
120  g[0] = 2;
121  h[3] = 2;
122  Info<< "Compare " << g << " and " << h << " Match = " << face::compare(g, h)
123  << endl;
124 
125  g[4] = 3;
126  h[4] = 3;
127  Info<< "Compare " << g << " and " << h << " Match = " << face::compare(g, h)
128  << endl;
129 
130  face face1(identity(1));
131  Info<< "Compare " << face1 << " and " << face1
132  << " Match = " << face::compare(face1, face1) << endl;
133 
134  face face2(identity(1)+1);
135  Info<< "Compare " << face1 << " and " << face2
136  << " Match = " << face::compare(face1, face2) << endl;
137 
138  Info<< nl << nl << "Zero face" << nl << endl;
139 
140  face fZero;
141  Circulator<face> cZero(fZero);
142 
143  if (cZero.size()) do
144  {
145  Info<< "Iterate forwards over face : " << cZero() << endl;
146 
147  } while (cZero.circulate(CirculatorBase::CLOCKWISE));
148 
149  fZero = face(identity(5));
150 
151  // circulator was invalidated so reset
152  cZero = Circulator<face>(fZero);
153 
154  do
155  {
156  Info<< "Iterate forwards over face : " << cZero() << endl;
157 
158  } while (cZero.circulate(CirculatorBase::CLOCKWISE));
159 
160 
161  Info<< nl << nl << "Simultaneously go forwards/backwards over face " << f
162  << nl << endl;
163 
164  ConstCirculator<face> circForward(f);
165  ConstCirculator<face> circBackward(f);
166 
167  if (circForward.size() && circBackward.size()) do
168  {
169  Info<< "Iterate over face forwards : " << circForward()
170  << ", backwards : " << circBackward() << endl;
171  }
172  while
173  (
176  );
177 
178  Info<< "\nEnd\n" << endl;
179 
180  return 0;
181 }
182 
183 
184 // ************************************************************************* //
Foam::Circulator::circulate
bool circulate(const CirculatorBase::direction dir=NONE)
Circulate around the list in the given direction.
Definition: CirculatorI.H:98
Foam::reverseList
ListType reverseList(const ListType &list)
Reverse a list. First element becomes last element etc.
Definition: ListOpsTemplates.C:769
List.H
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
Foam::ConstCirculator
Walks over a container as if it were circular. The container must have the following members defined:
Definition: ConstCirculator.H:91
Foam::Circulator
Walks over a container as if it were circular. The container must have the following members defined:
Definition: Circulator.H:75
face.H
ConstCirculator.H
g
const dimensionedVector & g
Definition: setRegionFluidFields.H:33
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::Circulator::prev
reference prev() const
Dereference the previous iterator and return.
Definition: CirculatorI.H:152
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:28
Foam::constant::universal::h
const dimensionedScalar h
Planck constant.
Definition: createFields.H:6
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::Info
messageStream Info
Foam::ConstCirculator::size
size_type size() const
Return the range of the iterator.
Definition: ConstCirculatorI.H:93
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::Circulator::next
reference next() const
Dereference the next iterator and return.
Definition: CirculatorI.H:139
Foam::CirculatorBase::CLOCKWISE
@ CLOCKWISE
Definition: CirculatorBase.H:54
main
int main(int argc, char *argv[])
Definition: Test-Circulator.C:41
f
labelList f(nPoints)
Foam::Circulator::size
size_type size() const
Return the range of the iterator.
Definition: CirculatorI.H:90
Circulator.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::face::compare
static int compare(const face &, const face &)
Compare faces.
Definition: face.C:298
ListOps.H
Various functions to operate on Lists.
Foam::ConstCirculator::next
const_reference next() const
Dereference the next iterator and return.
Definition: ConstCirculatorI.H:142
Foam::CirculatorBase::ANTICLOCKWISE
@ ANTICLOCKWISE
Definition: CirculatorBase.H:55
Foam::ConstCirculator::circulate
bool circulate(const CirculatorBase::direction dir=NONE)
Circulate around the list in the given direction.
Definition: ConstCirculatorI.H:101
Foam::ConstCirculator::prev
const_reference prev() const
Dereference the previous iterator and return.
Definition: ConstCirculatorI.H:155