cellShapeEqual.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011 OpenFOAM Foundation
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "cellShape.H"
29
30// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
31
32bool Foam::operator==(const cellShape& a, const cellShape& b)
33{
34 // Basic rule: we assume that the sequence of labels in each list
35 // will be circular in the same order (but not necessarily in the
36 // same direction). The limitation of this method is that with 3D
37 // topologies I cannot guarantee that a congruent but not
38 // identical cellShape (i.e. one sharing the same points but in a
39 // different order) will necessarily be matched.
40
41 const labelList& labsA = a;
42 const labelList& labsB = b;
43
44 // Trivial reject: faces are different size
45 label sizeA = labsA.size();
46 label sizeB = labsB.size();
47 if (sizeA != sizeB)
48 {
49 return false;
50 }
51
52
53 // First we look for the occurrence of the first label in A, in B
54
55 label Bptr = -1;
56 label firstA = labsA[0];
57 forAll(labsB, i)
58 {
59 if (labsB[i] == firstA)
60 {
61 Bptr = i; // Denotes 'found match' at element 'i'
62 break;
63 }
64 }
65
66 // If no match was found, exit false
67 if (Bptr < 0)
68 {
69 return false;
70 }
71
72 // Now we must look for the direction, if any
73 label secondA = labsA[1];
74 label dir = 0;
75
76 // Check whether at top of list
77 Bptr++;
78 if (Bptr == labsB.size())
79 {
80 Bptr = 0;
81 }
82
83 // Test whether upward label matches second A label
84 if (labsB[Bptr] == secondA)
85 {
86 // Yes - direction is 'up'
87 dir = 1;
88 }
89 else
90 {
91 // No - so look downwards, checking whether at bottom of list
92 Bptr -= 2;
93 if (Bptr < 0)
94 {
95 // Case (1) Bptr=-1
96 if (Bptr == -1)
97 {
98 Bptr = labsB.size() - 1;
99 }
100
101 // Case (2) Bptr = -2
102 else
103 {
104 Bptr = labsB.size() - 2;
105 }
106 }
107
108 // Test whether downward label matches second A label
109 if (labsB[Bptr] == secondA)
110 {
111 // Yes - direction is 'down'
112 dir = -1;
113 }
114 }
115
116 // Check whether a match was made at all, and exit false if not
117 if (dir == 0)
118 {
119 return false;
120 }
121
122 // Decrement size by 2 to account for first searches
123 sizeA -= 2;
124
125 // We now have both direction of search and next element
126 // to search, so we can continue search until no more points.
127 label Aptr = 1;
128 if (dir > 0)
129 {
130 while (sizeA--)
131 {
132 Aptr++;
133 if (Aptr >= labsA.size())
134 {
135 Aptr = 0;
136 }
137
138 Bptr++;
139 if (Bptr >= labsB.size())
140 {
141 Bptr = 0;
142 }
143 if (labsA[Aptr] != labsB[Bptr])
144 {
145 return false;
146 }
147 }
148 }
149 else
150 {
151 while (sizeA--)
152 {
153 Aptr++;
154 if (Aptr >= labsA.size())
155 {
156 Aptr = 0;
157 }
158
159 Bptr--;
160 if (Bptr < 0)
161 {
162 Bptr = labsB.size() - 1;
163 }
164 if (labsA[Aptr] != labsB[Bptr])
165 {
166 return false;
167 }
168 }
169 }
170
171 // They must be equal
172 return true;
173}
174
175
176// ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
An analytical geometric cellShape.
Definition: cellShape.H:72
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
volScalarField & b
Definition: createFields.H:27
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333