1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2004-2010 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
13 the Free Software Foundation, either version 3 of the License, or
14 (at your 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, see <http://www.gnu.org/licenses/>.
25 Equality operator for cellShape class
27 \*---------------------------------------------------------------------------*/
29 #include "cellShape.H"
31 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
33 bool Foam::operator==(const cellShape& a, const cellShape& b)
35 // Basic rule: we assume that the sequence of labels in each list
36 // will be circular in the same order (but not necessarily in the
37 // same direction). The limitation of this method is that with 3D
38 // topologies I cannot guarantee that a congruent but not
39 // identical cellShape (i.e. one sharing the same points but in a
40 // different order) will necessarily be matched.
42 const labelList& labsA = a;
43 const labelList& labsB = b;
45 // Trivial reject: faces are different size
46 label sizeA = labsA.size();
47 label sizeB = labsB.size();
54 // First we look for the occurrence of the first label in A, in B
57 label firstA = labsA[0];
60 if (labsB[i] == firstA)
62 Bptr = i; // Denotes 'found match' at element 'i'
67 // If no match was found, exit false
73 // Now we must look for the direction, if any
74 label secondA = labsA[1];
77 // Check whether at top of list
79 if (Bptr == labsB.size())
84 // Test whether upward label matches second A label
85 if (labsB[Bptr] == secondA)
87 // Yes - direction is 'up'
92 // No - so look downwards, checking whether at bottom of list
99 Bptr = labsB.size() - 1;
102 // Case (2) Bptr = -2
105 Bptr = labsB.size() - 2;
109 // Test whether downward label matches second A label
110 if (labsB[Bptr] == secondA)
112 // Yes - direction is 'down'
117 // Check whether a match was made at all, and exit false if not
123 // Decrement size by 2 to account for first searches
126 // We now have both direction of search and next element
127 // to search, so we can continue search until no more points.
134 if (Aptr >= labsA.size())
140 if (Bptr >= labsB.size())
144 if (labsA[Aptr] != labsB[Bptr])
155 if (Aptr >= labsA.size())
163 Bptr = labsB.size() - 1;
165 if (labsA[Aptr] != labsB[Bptr])
172 // They must be equal
177 // ************************************************************************* //