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 -------------------------------------------------------------------------------
10 License
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 Description
27  Equality operator for cellShape class
28 
29 \*---------------------------------------------------------------------------*/
30 
31 #include "cellShape.H"
32 
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
34 
35 bool Foam::operator==(const cellShape& a, const cellShape& b)
36 {
37  // Basic rule: we assume that the sequence of labels in each list
38  // will be circular in the same order (but not necessarily in the
39  // same direction). The limitation of this method is that with 3D
40  // topologies I cannot guarantee that a congruent but not
41  // identical cellShape (i.e. one sharing the same points but in a
42  // different order) will necessarily be matched.
43 
44  const labelList& labsA = a;
45  const labelList& labsB = b;
46 
47  // Trivial reject: faces are different size
48  label sizeA = labsA.size();
49  label sizeB = labsB.size();
50  if (sizeA != sizeB)
51  {
52  return false;
53  }
54 
55 
56  // First we look for the occurrence of the first label in A, in B
57 
58  label Bptr = -1;
59  label firstA = labsA[0];
60  forAll(labsB, i)
61  {
62  if (labsB[i] == firstA)
63  {
64  Bptr = i; // Denotes 'found match' at element 'i'
65  break;
66  }
67  }
68 
69  // If no match was found, exit false
70  if (Bptr < 0)
71  {
72  return false;
73  }
74 
75  // Now we must look for the direction, if any
76  label secondA = labsA[1];
77  label dir = 0;
78 
79  // Check whether at top of list
80  Bptr++;
81  if (Bptr == labsB.size())
82  {
83  Bptr = 0;
84  }
85 
86  // Test whether upward label matches second A label
87  if (labsB[Bptr] == secondA)
88  {
89  // Yes - direction is 'up'
90  dir = 1;
91  }
92  else
93  {
94  // No - so look downwards, checking whether at bottom of list
95  Bptr -= 2;
96  if (Bptr < 0)
97  {
98  // Case (1) Bptr=-1
99  if (Bptr == -1)
100  {
101  Bptr = labsB.size() - 1;
102  }
103 
104  // Case (2) Bptr = -2
105  else
106  {
107  Bptr = labsB.size() - 2;
108  }
109  }
110 
111  // Test whether downward label matches second A label
112  if (labsB[Bptr] == secondA)
113  {
114  // Yes - direction is 'down'
115  dir = -1;
116  }
117  }
118 
119  // Check whether a match was made at all, and exit false if not
120  if (dir == 0)
121  {
122  return false;
123  }
124 
125  // Decrement size by 2 to account for first searches
126  sizeA -= 2;
127 
128  // We now have both direction of search and next element
129  // to search, so we can continue search until no more points.
130  label Aptr = 1;
131  if (dir > 0)
132  {
133  while (sizeA--)
134  {
135  Aptr++;
136  if (Aptr >= labsA.size())
137  {
138  Aptr = 0;
139  }
140 
141  Bptr++;
142  if (Bptr >= labsB.size())
143  {
144  Bptr = 0;
145  }
146  if (labsA[Aptr] != labsB[Bptr])
147  {
148  return false;
149  }
150  }
151  }
152  else
153  {
154  while (sizeA--)
155  {
156  Aptr++;
157  if (Aptr >= labsA.size())
158  {
159  Aptr = 0;
160  }
161 
162  Bptr--;
163  if (Bptr < 0)
164  {
165  Bptr = labsB.size() - 1;
166  }
167  if (labsA[Aptr] != labsB[Bptr])
168  {
169  return false;
170  }
171  }
172  }
173 
174  // They must be equal
175  return true;
176 }
177 
178 
179 // ************************************************************************* //
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
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:62
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::operator==
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Foam::cellShape
An analytical geometric cellShape.
Definition: cellShape.H:71
Foam::List< label >
cellShape.H