mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: face: Use circulator in compare()
This commit is contained in:
@ -28,6 +28,7 @@ License
|
|||||||
#include "triPointRef.H"
|
#include "triPointRef.H"
|
||||||
#include "mathematicalConstants.H"
|
#include "mathematicalConstants.H"
|
||||||
#include "Swap.H"
|
#include "Swap.H"
|
||||||
|
#include "const_circulator.H"
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||||
|
|
||||||
@ -299,7 +300,6 @@ Foam::face::face(const triFace& f)
|
|||||||
|
|
||||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
// return
|
// return
|
||||||
// 0: no match
|
// 0: no match
|
||||||
// +1: identical
|
// +1: identical
|
||||||
@ -314,144 +314,89 @@ int Foam::face::compare(const face& a, const face& b)
|
|||||||
label sizeA = a.size();
|
label sizeA = a.size();
|
||||||
label sizeB = b.size();
|
label sizeB = b.size();
|
||||||
|
|
||||||
if (sizeA != sizeB)
|
if (sizeA != sizeB || sizeA == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const_circulator<face> aCirc(a);
|
||||||
|
const_circulator<face> bCirc(b);
|
||||||
|
|
||||||
// Full list comparison
|
// Rotate face b until its element matches the starting element of face a.
|
||||||
const label firstA = a[0];
|
do
|
||||||
label Bptr = -1;
|
|
||||||
|
|
||||||
forAll(b, i)
|
|
||||||
{
|
{
|
||||||
if (b[i] == firstA)
|
if (aCirc() == bCirc())
|
||||||
|
{
|
||||||
|
// Set bCirc fulcrum to its iterator and increment the iterators
|
||||||
|
bCirc.setFulcrumToIterator();
|
||||||
|
++aCirc;
|
||||||
|
++bCirc;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (bCirc.circulate(CirculatorBase::CLOCKWISE));
|
||||||
|
|
||||||
|
// If the circulator has stopped then faces a and b do not share a matching
|
||||||
|
// point
|
||||||
|
if (!bCirc.circulate())
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look forwards around the faces for a match
|
||||||
|
do
|
||||||
|
{
|
||||||
|
if (aCirc() != bCirc())
|
||||||
{
|
{
|
||||||
Bptr = i; // 'found match' at element 'i'
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
while
|
||||||
|
(
|
||||||
|
aCirc.circulate(CirculatorBase::CLOCKWISE),
|
||||||
|
bCirc.circulate(CirculatorBase::CLOCKWISE)
|
||||||
|
);
|
||||||
|
|
||||||
// If no match was found, return 0
|
// If the circulator has stopped then faces a and b matched.
|
||||||
if (Bptr < 0)
|
if (!aCirc.circulate())
|
||||||
{
|
{
|
||||||
return 0;
|
return 1;
|
||||||
}
|
|
||||||
|
|
||||||
// Now we must look for the direction, if any
|
|
||||||
label secondA = a[1];
|
|
||||||
|
|
||||||
if (sizeA > 1 && (secondA == firstA || firstA == a[sizeA - 1]))
|
|
||||||
{
|
|
||||||
face ca = a;
|
|
||||||
ca.collapse();
|
|
||||||
|
|
||||||
face cb = b;
|
|
||||||
cb.collapse();
|
|
||||||
|
|
||||||
return face::compare(ca, cb);
|
|
||||||
}
|
|
||||||
|
|
||||||
int dir = 0;
|
|
||||||
|
|
||||||
// Check whether at top of list
|
|
||||||
Bptr++;
|
|
||||||
if (Bptr == b.size())
|
|
||||||
{
|
|
||||||
Bptr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test whether upward label matches second A label
|
|
||||||
if (b[Bptr] == secondA)
|
|
||||||
{
|
|
||||||
// Yes - direction is 'up'
|
|
||||||
dir = 1;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// No - so look downwards, checking whether at bottom of list
|
// Reset the circulators back to their fulcrum
|
||||||
Bptr -= 2;
|
aCirc.setIteratorToFulcrum();
|
||||||
|
bCirc.setIteratorToFulcrum();
|
||||||
if (Bptr < 0)
|
++aCirc;
|
||||||
{
|
--bCirc;
|
||||||
// wraparound
|
|
||||||
Bptr += b.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test whether downward label matches second A label
|
|
||||||
if (b[Bptr] == secondA)
|
|
||||||
{
|
|
||||||
// Yes - direction is 'down'
|
|
||||||
dir = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check whether a match was made at all, and exit 0 if not
|
// Look backwards around the faces for a match
|
||||||
if (dir == 0)
|
do
|
||||||
{
|
{
|
||||||
return 0;
|
if (aCirc() != bCirc())
|
||||||
}
|
|
||||||
|
|
||||||
// Decrement size by 2 to account for first searches
|
|
||||||
sizeA -= 2;
|
|
||||||
|
|
||||||
// We now have both direction of search and next element
|
|
||||||
// to search, so we can continue search until no more points.
|
|
||||||
label Aptr = 1;
|
|
||||||
if (dir > 0)
|
|
||||||
{
|
|
||||||
while (sizeA--)
|
|
||||||
{
|
{
|
||||||
Aptr++;
|
break;
|
||||||
if (Aptr >= a.size())
|
|
||||||
{
|
|
||||||
Aptr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bptr++;
|
|
||||||
if (Bptr >= b.size())
|
|
||||||
{
|
|
||||||
Bptr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a[Aptr] != b[Bptr])
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
while
|
||||||
|
(
|
||||||
|
aCirc.circulate(CirculatorBase::CLOCKWISE),
|
||||||
|
bCirc.circulate(CirculatorBase::ANTICLOCKWISE)
|
||||||
|
);
|
||||||
|
|
||||||
|
// If the circulator has stopped then faces a and b matched.
|
||||||
|
if (!aCirc.circulate())
|
||||||
{
|
{
|
||||||
while (sizeA--)
|
return -1;
|
||||||
{
|
|
||||||
Aptr++;
|
|
||||||
if (Aptr >= a.size())
|
|
||||||
{
|
|
||||||
Aptr = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Bptr--;
|
|
||||||
if (Bptr < 0)
|
|
||||||
{
|
|
||||||
Bptr = b.size() - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a[Aptr] != b[Bptr])
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// They must be equal - return direction
|
return 0;
|
||||||
return dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||||
|
|
||||||
|
|
||||||
Foam::label Foam::face::collapse()
|
Foam::label Foam::face::collapse()
|
||||||
{
|
{
|
||||||
if (size() > 1)
|
if (size() > 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user