1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
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 the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
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
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 Equality operator for cellShape class
28 \*---------------------------------------------------------------------------*/
30 #include "cellShape.H"
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 bool Foam::operator==(const cellShape& a, const cellShape& b)
36 // Basic rule: we assume that the sequence of labels in each list
37 // will be circular in the same order (but not necessarily in the
38 // same direction). The limitation of this method is that with 3D
39 // topologies I cannot guarantee that a congruent but not
40 // identical cellShape (i.e. one sharing the same points but in a
41 // different order) will necessarily be matched.
43 const labelList& labsA = a;
44 const labelList& labsB = b;
46 // Trivial reject: faces are different size
47 label sizeA = labsA.size();
48 label sizeB = labsB.size();
55 // First we look for the occurrence of the first label in A, in B
58 label firstA = labsA[0];
61 if (labsB[i] == firstA)
63 Bptr = i; // Denotes 'found match' at element 'i'
68 // If no match was found, exit false
74 // Now we must look for the direction, if any
75 label secondA = labsA[1];
78 // Check whether at top of list
80 if (Bptr == labsB.size())
85 // Test whether upward label matches second A label
86 if (labsB[Bptr] == secondA)
88 // Yes - direction is 'up'
93 // No - so look downwards, checking whether at bottom of list
100 Bptr = labsB.size() - 1;
103 // Case (2) Bptr = -2
106 Bptr = labsB.size() - 2;
110 // Test whether downward label matches second A label
111 if (labsB[Bptr] == secondA)
113 // Yes - direction is 'down'
118 // Check whether a match was made at all, and exit false if not
124 // Decrement size by 2 to account for first searches
127 // We now have both direction of search and next element
128 // to search, so we can continue search until no more points.
135 if (Aptr >= labsA.size())
141 if (Bptr >= labsB.size())
145 if (labsA[Aptr] != labsB[Bptr])
156 if (Aptr >= labsA.size())
164 Bptr = labsB.size() - 1;
166 if (labsA[Aptr] != labsB[Bptr])
173 // They must be equal
178 // ************************************************************************* //