Loading...
Searching...
No Matches
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 Copyright (C) 2025 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
27\*---------------------------------------------------------------------------*/
28
29#include "cellShape.H"
30
31// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
32
34{
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.
41
42 const labelUList& labsA = a;
43 const labelUList& labsB = b;
44
45 const label sizeA = labsA.size();
46 const label sizeB = labsB.size();
47
48 if (sizeA != sizeB)
49 {
50 // Trivial reject: different sizes
51 return 0;
52 }
53 else if (sizeA == 0)
54 {
55 // Both have zero vertices. Always identical
56 return 1;
57 }
58 else if (sizeA == 1)
59 {
60 // Both have a single vertex? Simple check
61 return (labsA[0] == labsB[0] ? 1 : 0);
62 }
63
64
65 // Search B for the starting point of A
66 label Bptr = labsB.find(labsA[0]);
67
68 if (Bptr < 0)
69 {
70 // No match found
71 return 0;
72 }
73
74 // Now check B for the next label of A,
75 // it could be in either direction
76 label Aptr = 1;
77 int dir = 0;
78
79 ++Bptr;
80 if (Bptr == labsB.size())
81 {
82 Bptr = 0;
83 }
84
85 if (labsA[Aptr] == labsB[Bptr])
86 {
87 // Yes - direction is 'up'
88 dir = 1;
89 }
90 else
91 {
92 // No - so look downwards
93 Bptr -= 2;
94 if (Bptr < 0)
95 {
96 Bptr += labsB.size();
97 }
98
99 // Test whether downward label matches the second label in A
100 if (labsA[Aptr] == labsB[Bptr])
101 {
102 // Yes - direction is 'down'
103 dir = -1;
104 }
105 }
106
107 // Check whether a match was made at all, and exit false if not
108 if (dir == 0)
109 {
110 return 0;
111 }
112
113 // We now have both direction of search and next element
114 // to search, so we can continue search until no more points.
115 // Decrement size by 2 to account for first searches
116
117 label remaining = (sizeA - 2);
118
119 if (dir > 0)
120 {
121 while (remaining--)
122 {
123 ++Aptr;
124 if (Aptr >= labsA.size())
125 {
126 Aptr = 0;
127 }
128
129 ++Bptr;
130 if (Bptr >= labsB.size())
131 {
132 Bptr = 0;
133 }
134
135 if (labsA[Aptr] != labsB[Bptr])
136 {
137 return 0;
138 }
139 }
140 }
141 else
142 {
143 while (remaining--)
144 {
145 ++Aptr;
146 if (Aptr >= labsA.size())
147 {
148 Aptr = 0;
149 }
150
151 --Bptr;
152 if (Bptr < 0)
153 {
154 Bptr = labsB.size() - 1;
155 }
156
157 if (labsA[Aptr] != labsB[Bptr])
158 {
159 return 0;
160 }
161 }
162 }
163
164 // Equal values but perhaps different order
165 return dir;
166}
167
168
169// * * * * * * * * * * * * * * Global Operators * * * * * * * * * * * * * * //
170
171bool Foam::operator==(const cellShape& a, const cellShape& b)
172{
173 return cellShape::compare(a, b) != 0;
174}
175
176// bool Foam::operator!=(const cellShape& a, const cellShape& b)
177// {
178// return cellShape::compare(a, b) == 0;
179// }
180
181
182// ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
label find(const T &val) const
Find index of the first occurrence of the value.
Definition UList.C:160
An analytical geometric cellShape.
Definition cellShape.H:71
static int compare(const cellShape &a, const cellShape &b)
Compare cellShape vertices.
constexpr cellShape() noexcept
Default construct. Empty shape, no cell model.
Definition cellShapeI.H:29
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
UList< label > labelUList
A UList of labels.
Definition UList.H:75
volScalarField & b