mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
Merge branch 'feature-reorganise' into 'develop'
code style, bug fixes See merge request Development/openfoam!535
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,7 +33,7 @@ License
|
||||
#include "IOstreams.H"
|
||||
#include "StringStream.H"
|
||||
#include "ListOps.H"
|
||||
#include "StringListOps.H"
|
||||
#include "stringListOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -71,9 +71,18 @@ int main()
|
||||
<< "table1 [" << table1.size() << "] " << endl;
|
||||
forAllConstIters(table1, iter)
|
||||
{
|
||||
Info<< iter.key() << " => " << iter() << nl;
|
||||
Info<< iter.key() << " => " << iter.val() << nl;
|
||||
}
|
||||
|
||||
|
||||
Info<< "\ntable1 sorted() :" << endl;
|
||||
for (const auto& iter : table1.sorted())
|
||||
{
|
||||
Info<< " " << iter.key() << " => " << iter.val() << nl;
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
|
||||
table1.set("acr", 108);
|
||||
table1.set("adx", 109);
|
||||
table1.set("aec", 100);
|
||||
@ -82,6 +91,22 @@ int main()
|
||||
|
||||
Info<< "\noverwrote some values table1: " << table1 << endl;
|
||||
|
||||
|
||||
// Test writable sorted access
|
||||
for (auto& iter : table1.sorted())
|
||||
{
|
||||
// Should not compile: iter.key() = "illegal";
|
||||
iter.val() *= 2;
|
||||
}
|
||||
|
||||
Info<< "\nInplace modified - via sorted() access :" << endl;
|
||||
for (const auto& iter : table1.sorted())
|
||||
{
|
||||
Info<< " " << iter.key() << " => " << iter.val() << nl;
|
||||
}
|
||||
Info<< endl;
|
||||
|
||||
|
||||
Info<< "\ntest find:" << endl;
|
||||
Info<< table1.find("aaa")() << nl
|
||||
<< table1.find("aba")() << nl
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -34,6 +34,7 @@ Description
|
||||
|
||||
#include "argList.H"
|
||||
#include "IOField.H"
|
||||
#include "IOList.H"
|
||||
#include "primitiveFields.H"
|
||||
#include "polyMesh.H"
|
||||
#include "Time.H"
|
||||
@ -181,6 +182,7 @@ int main(int argc, char *argv[])
|
||||
argList::addBoolOption("bool", "Use bool for tests");
|
||||
argList::addBoolOption("scalar", "Use scalar for tests");
|
||||
argList::addBoolOption("label", "Use label for tests (default)");
|
||||
argList::addBoolOption("ref", "Test writing by ref");
|
||||
|
||||
#include "addTimeOptions.H"
|
||||
|
||||
@ -232,6 +234,36 @@ int main(int argc, char *argv[])
|
||||
doTests<label>(io, sz);
|
||||
}
|
||||
|
||||
if (args.found("ref"))
|
||||
{
|
||||
Info<< nl << "Testing writing referenced external data" << nl << endl;
|
||||
|
||||
IOobject ioOutput
|
||||
(
|
||||
args.executable(),
|
||||
"constant",
|
||||
runTime,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
);
|
||||
|
||||
labelList ints(identity(200));
|
||||
|
||||
ioOutput.rename(args.executable() + "-labels");
|
||||
Info<< "write " << ioOutput.objectRelPath() << endl;
|
||||
{
|
||||
IOListRef<label>(ioOutput, ints).write();
|
||||
}
|
||||
|
||||
ioOutput.rename(args.executable() + "-points");
|
||||
Info<< "write " << ioOutput.objectRelPath() << endl;
|
||||
{
|
||||
IOFieldRef<vector>(ioOutput, mesh.points()).write();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Pout<< "\nEnd\n" << endl;
|
||||
|
||||
|
||||
@ -34,7 +34,7 @@ Description
|
||||
#include "argList.H"
|
||||
#include "ITstream.H"
|
||||
#include "ListOps.H"
|
||||
#include "StringListOps.H"
|
||||
#include "stringListOps.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
|
||||
@ -151,6 +151,10 @@ int main(int argc, char *argv[])
|
||||
<< subsetList(test6, evenNonZero) << nl
|
||||
<< endl;
|
||||
|
||||
Info<< "Subset of non-zero, even values: "
|
||||
<< IndirectList<label>::subset_if(test6, evenNonZero) << nl
|
||||
<< endl;
|
||||
|
||||
test6.append(identity(13, 12));
|
||||
|
||||
Info<< "Randomized: " << flatOutput(test6) << endl;
|
||||
|
||||
@ -59,7 +59,7 @@ public:
|
||||
|
||||
~Scalar()
|
||||
{
|
||||
Info<<"delete Scalar: " << data_ << endl;
|
||||
Info<< "delete Scalar: " << data_ << endl;
|
||||
}
|
||||
|
||||
const scalar& value() const
|
||||
@ -324,7 +324,7 @@ int main(int argc, char *argv[])
|
||||
list1.set(i, new Scalar(1.3*i));
|
||||
}
|
||||
|
||||
Info<<"Emplace set " << list2.size() << " values" << nl;
|
||||
Info<< "Emplace set " << list2.size() << " values" << nl;
|
||||
forAll(list2, i)
|
||||
{
|
||||
list2.emplace(i, (10 + 1.3*i));
|
||||
@ -338,9 +338,9 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
Info<< nl
|
||||
<<"list1: " << list1 << nl
|
||||
<<"list2: " << list2 << nl
|
||||
<<"list-appended: " << listApp << endl;
|
||||
<< "list1: " << list1 << nl
|
||||
<< "list2: " << list2 << nl
|
||||
<< "list-appended: " << listApp << endl;
|
||||
|
||||
|
||||
// Release values
|
||||
@ -357,27 +357,27 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
Info<<"Released pointers from";
|
||||
Info<< "Released pointers from";
|
||||
print(Info, listApp) << nl;
|
||||
|
||||
Info<<"Into plain list of pointers";
|
||||
Info<< "Into plain list of pointers";
|
||||
print(Info, ptrs) << nl;
|
||||
|
||||
PtrDynList<Scalar> newlist1(ptrs);
|
||||
|
||||
Info<<"Constructed from plain list of pointers";
|
||||
Info<< "Constructed from plain list of pointers";
|
||||
print(Info, ptrs) << nl;
|
||||
print(Info, newlist1) << nl;
|
||||
}
|
||||
|
||||
|
||||
Info<<"indirectly delete some items via set(.., nullptr) :" << endl;
|
||||
Info<< "indirectly delete some items via set(.., nullptr) :" << endl;
|
||||
for (label i = 2; i < 5; i++)
|
||||
{
|
||||
list1.set(i, nullptr);
|
||||
}
|
||||
|
||||
Info<<"release some items:" << endl;
|
||||
Info<< "release some items:" << endl;
|
||||
|
||||
for (label i = -2; i < 5; i++)
|
||||
{
|
||||
@ -389,31 +389,31 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
|
||||
Info<<"list1: ";
|
||||
Info<< "list1: ";
|
||||
print(Info, list1) << nl;
|
||||
|
||||
list1.resize(list1.squeezeNull());
|
||||
Info<<"squeezed null: ";
|
||||
Info<< "squeezed null: ";
|
||||
print(Info, list1) << nl;
|
||||
|
||||
Info<<"transfer list2 -> list1:" << endl;
|
||||
Info<< "transfer list2 -> list1:" << endl;
|
||||
list1.transfer(list2);
|
||||
|
||||
Info<<"list1: " << list1 << nl
|
||||
<<"list2: " << list2 << endl;
|
||||
Info<< "list1: " << list1 << nl
|
||||
<< "list2: " << list2 << endl;
|
||||
|
||||
Info<<"indirectly delete some items via setSize :" << endl;
|
||||
Info<< "indirectly delete some items via setSize :" << endl;
|
||||
list1.setSize(4);
|
||||
|
||||
Info<<"list1: " << list1 << endl;
|
||||
Info<< "list1: " << list1 << endl;
|
||||
|
||||
{
|
||||
PtrList<Scalar> list1a(list1, false);
|
||||
|
||||
Info<<"Clone constructed" << endl;
|
||||
Info<<"in: " << list1 << nl
|
||||
<<"out: " << list1a << nl
|
||||
<<"addresses:" << nl;
|
||||
Info<< "Clone constructed" << endl;
|
||||
Info<< "in: " << list1 << nl
|
||||
<< "out: " << list1a << nl
|
||||
<< "addresses:" << nl;
|
||||
printAddr(Info, list1);
|
||||
printAddr(Info, list1a);
|
||||
Info<<"values:" << nl;
|
||||
@ -423,112 +423,112 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
auto* ptr = &(list1a.first());
|
||||
list1a.set(0, ptr);
|
||||
Info<<"values:" << nl;
|
||||
Info<< "values:" << nl;
|
||||
print(Info, list1a);
|
||||
}
|
||||
|
||||
|
||||
PtrList<Scalar> list1b(list1a, true);
|
||||
|
||||
Info<<"Reuse constructed" << endl;
|
||||
Info<<"in: " << list1a << nl
|
||||
<<"out: " << list1b << nl
|
||||
<<"addresses:" << nl;
|
||||
Info<< "Reuse constructed" << endl;
|
||||
Info<< "in: " << list1a << nl
|
||||
<< "out: " << list1b << nl
|
||||
<< "addresses:" << nl;
|
||||
printAddr(Info, list1a);
|
||||
printAddr(Info, list1b);
|
||||
|
||||
|
||||
PtrList<Scalar> list1c(list1b.clone());
|
||||
|
||||
Info<<"Explicit clone()" << endl;
|
||||
Info<<"in: " << list1b << nl
|
||||
<<"out: " << list1c << nl
|
||||
<<"addresses:" << nl;
|
||||
Info<< "Explicit clone()" << endl;
|
||||
Info<< "in: " << list1b << nl
|
||||
<< "out: " << list1c << nl
|
||||
<< "addresses:" << nl;
|
||||
printAddr(Info, list1b);
|
||||
printAddr(Info, list1c);
|
||||
}
|
||||
|
||||
PtrList<Scalar> list3(std::move(list1));
|
||||
Info<<"Move constructed" << endl;
|
||||
Info<< "Move constructed" << endl;
|
||||
|
||||
Info<<"list1: " << list1 << nl
|
||||
<<"list2: " << list2 << nl
|
||||
<<"list3: " << list3 << endl;
|
||||
Info<< "list1: " << list1 << nl
|
||||
<< "list2: " << list2 << nl
|
||||
<< "list3: " << list3 << endl;
|
||||
|
||||
|
||||
Info<<"Move construct:" << endl;
|
||||
Info<< "Move construct:" << endl;
|
||||
|
||||
PtrList<Scalar> list4(std::move(list3));
|
||||
|
||||
Info<<"list3: " << list3 << nl
|
||||
<<"list4: " << list4 << endl;
|
||||
Info<< "list3: " << list3 << nl
|
||||
<< "list4: " << list4 << endl;
|
||||
|
||||
Info<<"Move assign:" << endl;
|
||||
Info<< "Move assign:" << endl;
|
||||
list3 = std::move(list4);
|
||||
|
||||
Info<<"list3: " << list3 << nl
|
||||
<<"list4: " << list4 << endl;
|
||||
Info<< "list3: " << list3 << nl
|
||||
<< "list4: " << list4 << endl;
|
||||
|
||||
|
||||
Info<<"UPtrList from PtrList" << nl;
|
||||
Info<< "UPtrList from PtrList" << nl;
|
||||
|
||||
UPtrList<Scalar> ulist1(list3);
|
||||
|
||||
Info<<"ulist1: " << ulist1 << nl;
|
||||
Info<<"PtrList addresses:";
|
||||
Info<< "ulist1: " << ulist1 << nl;
|
||||
Info<< "PtrList addresses:";
|
||||
printAddr(Info, list3);
|
||||
Info<<"UPtrList addresses:";
|
||||
Info<< "UPtrList addresses:";
|
||||
printAddr(Info, ulist1);
|
||||
Info<< nl;
|
||||
|
||||
{
|
||||
Info<<"UPtrList(const UPtrList&)" << nl;
|
||||
Info<< "UPtrList(const UPtrList&)" << nl;
|
||||
|
||||
const UPtrList<Scalar>& cref = ulist1;
|
||||
|
||||
UPtrList<Scalar> ulist1cp(cref);
|
||||
|
||||
Info<<"src addresses:";
|
||||
Info<< "src addresses:";
|
||||
printAddr(Info, cref);
|
||||
Info<<"dst addresses:";
|
||||
Info<< "dst addresses:";
|
||||
printAddr(Info, ulist1cp);
|
||||
Info<< nl;
|
||||
}
|
||||
|
||||
|
||||
Info<<"Move construct:" << endl;
|
||||
Info<< "Move construct:" << endl;
|
||||
|
||||
UPtrList<Scalar> ulist2(std::move(ulist1));
|
||||
|
||||
Info<<"ulist1: " << ulist1 << nl
|
||||
<<"ulist2: " << ulist2 << nl;
|
||||
Info<< "ulist1: " << ulist1 << nl
|
||||
<< "ulist2: " << ulist2 << nl;
|
||||
|
||||
Info<<"Copy assign:" << endl;
|
||||
Info<< "Copy assign:" << endl;
|
||||
ulist1 = ulist2;
|
||||
|
||||
Info<<"ulist1: " << ulist1 << nl
|
||||
<<"ulist2: " << ulist2 << nl;
|
||||
Info<< "ulist1: " << ulist1 << nl
|
||||
<< "ulist2: " << ulist2 << nl;
|
||||
|
||||
Info<<"Move assign:" << endl;
|
||||
Info<< "Move assign:" << endl;
|
||||
ulist1 = std::move(ulist2);
|
||||
|
||||
Info<<"ulist1: " << ulist1 << nl
|
||||
<<"ulist2: " << ulist2 << nl;
|
||||
Info<< "ulist1: " << ulist1 << nl
|
||||
<< "ulist2: " << ulist2 << nl;
|
||||
|
||||
// Test iterator random access
|
||||
{
|
||||
auto iter1 = ulist1.begin();
|
||||
auto iter2 = iter1 + 3;
|
||||
|
||||
Info<<"begin:" << *iter1 << " (+3):" << *iter2 << nl;
|
||||
Info<< "begin:" << *iter1 << " (+3):" << *iter2 << nl;
|
||||
Info<< "diff= " << (iter1 - iter2) << nl;
|
||||
Info<< "iter[2]=" << iter1[2] << nl;
|
||||
Info<< "iter1 < iter2 : " << (iter1 < iter2) << nl;
|
||||
Info<< "iter1 >= iter2 : " << (iter1 >= iter2) << nl;
|
||||
|
||||
Info<<"->" << iter1->value() << nl;
|
||||
Info<<"*" << (*iter1).value() << nl;
|
||||
Info<<"()" << iter1().value() << nl;
|
||||
Info<< "->" << iter1->value() << nl;
|
||||
Info<< "*" << (*iter1).value() << nl;
|
||||
Info<< "()" << iter1().value() << nl;
|
||||
}
|
||||
|
||||
PtrList<plane> planes;
|
||||
@ -541,7 +541,7 @@ int main(int argc, char *argv[])
|
||||
Info<< " plane " << p << endl;
|
||||
}
|
||||
|
||||
Info<<"Testing PtrDynList" << nl;
|
||||
Info<< "Testing PtrDynList" << nl;
|
||||
|
||||
PtrDynList<plane> dynPlanes;
|
||||
|
||||
@ -566,10 +566,10 @@ int main(int argc, char *argv[])
|
||||
report(Info, dynPlanes, true);
|
||||
|
||||
dynPlanes.clear();
|
||||
Info<<"clear()" << nl;
|
||||
Info<< "clear()" << nl;
|
||||
report(Info, dynPlanes);
|
||||
|
||||
Info<<"now append again" << endl;
|
||||
Info<< "now append again" << endl;
|
||||
{
|
||||
dynPlanes.append(new plane(vector::one, vector::one));
|
||||
dynPlanes.append(new plane(vector(1,2,3), vector::one));
|
||||
@ -597,13 +597,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
stdPlanes.resize(stdPlanes.squeezeNull());
|
||||
|
||||
Info<<"After pruning nullptr entries" << endl;
|
||||
Info<< "After pruning nullptr entries" << endl;
|
||||
printAddr(Info, stdPlanes);
|
||||
}
|
||||
|
||||
dynPlanes.resize(dynPlanes.squeezeNull());
|
||||
|
||||
Info<<"After pruning nullptr entries" << endl;
|
||||
Info<< "After pruning nullptr entries" << endl;
|
||||
report(Info, dynPlanes, true);
|
||||
|
||||
|
||||
@ -621,25 +621,48 @@ int main(int argc, char *argv[])
|
||||
sortedOrder(dynPlanes2, order);
|
||||
Info<< "sorted order: " << flatOutput(order) << nl;
|
||||
|
||||
sortedOrder(dynPlanes2, order, PtrListOps::greater<plane>(dynPlanes2));
|
||||
sortedOrder(dynPlanes2, order, UPtrList<plane>::greater(dynPlanes2));
|
||||
Info<< "sorted order: " << flatOutput(order) << nl;
|
||||
|
||||
// Shuffle
|
||||
shuffle(dynPlanes2);
|
||||
Info<< "Shuffled" << endl;
|
||||
report(Info, dynPlanes2, false);
|
||||
|
||||
// Reverse sort
|
||||
sort
|
||||
(
|
||||
dynPlanes2,
|
||||
[](const plane& a, const plane& b) { return (b < a); }
|
||||
);
|
||||
Info<< "Reverse sorted" << endl;
|
||||
report(Info, dynPlanes2, false);
|
||||
|
||||
// Forward sort
|
||||
sort(dynPlanes2);
|
||||
Info<< "Sorted" << endl;
|
||||
report(Info, dynPlanes2, false);
|
||||
|
||||
// Reverse pointer list - not yet available or needed!
|
||||
/// reverse(dynPlanes2);
|
||||
/// Info<< "Reversed" << endl;
|
||||
/// report(Info, dynPlanes2, false);
|
||||
|
||||
// dynPlanes2.squeezeNull();
|
||||
|
||||
Info<<"Append" << endl;
|
||||
Info<< "Append" << endl;
|
||||
report(Info, dynPlanes2, false);
|
||||
|
||||
dynPlanes.append(std::move(dynPlanes2));
|
||||
|
||||
Info<<"Result" << endl;
|
||||
Info<< "Result" << endl;
|
||||
report(Info, dynPlanes, false);
|
||||
|
||||
Info<<"From" << endl;
|
||||
Info<< "From" << endl;
|
||||
report(Info, dynPlanes2, false);
|
||||
}
|
||||
|
||||
Info<<"free()" << endl;
|
||||
Info<< "free()" << endl;
|
||||
|
||||
dynPlanes.free();
|
||||
report(Info, dynPlanes, true);
|
||||
|
||||
@ -27,7 +27,7 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "UIndirectList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "DynamicList.H"
|
||||
#include "IOstreams.H"
|
||||
#include "ListOps.H"
|
||||
|
||||
@ -344,12 +344,35 @@ int main(int argc, char *argv[])
|
||||
|
||||
Info<< "\noperator|=\n";
|
||||
{
|
||||
bitSet a; a.set(labelRange(15, 8));
|
||||
bitSet b; b.set(labelRange(30, 8));
|
||||
|
||||
report(a, false);
|
||||
report(b, false);
|
||||
report((a |= b), true);
|
||||
}
|
||||
{
|
||||
Info<< " other test\n";
|
||||
|
||||
bitSet list3 = list1;
|
||||
report((list3 |= list2), true);
|
||||
}
|
||||
|
||||
Info<< "\noperator&=\n";
|
||||
{
|
||||
bitSet a; a.set(labelRange(30, 8));
|
||||
bitSet b; b.set(labelRange(0, 8));
|
||||
|
||||
report(a, false);
|
||||
report(b, false);
|
||||
Info<< " (a & b)\n";
|
||||
report((a & b), true);
|
||||
Info<< " (b & a)\n";
|
||||
report((b & a), true);
|
||||
}
|
||||
{
|
||||
Info<< " other test\n";
|
||||
|
||||
bitSet list3 = list1;
|
||||
report((list3 &= list2), true);
|
||||
}
|
||||
|
||||
@ -157,18 +157,34 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
boolList list2(5, true);
|
||||
list2.unset(2);
|
||||
list2.unset(3);
|
||||
|
||||
Info<< "Test wrapper idea" << nl;
|
||||
|
||||
bitSetOrBoolList wrapper(list2);
|
||||
|
||||
if (wrapper.test(1))
|
||||
// Use predicate, or test() method
|
||||
|
||||
if (list2(1))
|
||||
{
|
||||
Info<< "1 is on" << nl;
|
||||
Info<< "1 is on (original)" << nl;
|
||||
}
|
||||
if (!wrapper.test(2))
|
||||
if (!list2(2))
|
||||
{
|
||||
Info<< "2 is off" << nl;
|
||||
Info<< "2 is off (original)" << nl;
|
||||
}
|
||||
if (!list2(100))
|
||||
{
|
||||
Info<< "100 is off (original)" << nl;
|
||||
}
|
||||
|
||||
if (wrapper(1))
|
||||
{
|
||||
Info<< "1 is on (wrapped)" << nl;
|
||||
}
|
||||
if (!wrapper(2))
|
||||
{
|
||||
Info<< "2 is off (wrapped)" << nl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,8 +32,8 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef bitSetOrBoolList_H
|
||||
#define bitSetOrBoolList_H
|
||||
#ifndef Foam_bitSetOrBoolList_H
|
||||
#define Foam_bitSetOrBoolList_H
|
||||
|
||||
#include "bitSet.H"
|
||||
#include "boolList.H"
|
||||
@ -88,6 +88,13 @@ public:
|
||||
{
|
||||
return bits_.test(i) || bools_.test(i);
|
||||
}
|
||||
|
||||
//- Test predicate
|
||||
bool operator()(const label i) const
|
||||
{
|
||||
// Can also use test(i) etc...
|
||||
return bits_(i) || bools_(i);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -41,8 +41,8 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef disabledBoolList_H
|
||||
#define disabledBoolList_H
|
||||
#ifndef Foam_disabledBoolList_H
|
||||
#define Foam_disabledBoolList_H
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class disabledBoolList Declaration
|
||||
@ -60,6 +60,9 @@ struct disabledBoolList
|
||||
bool test(int) const { return true; }
|
||||
|
||||
void set(bool) {}
|
||||
|
||||
// Perhaps not?
|
||||
/// bool operator()(const label i) const { return true; }
|
||||
};
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -31,7 +31,7 @@ Description
|
||||
#include "string.H"
|
||||
#include "macros.H"
|
||||
#include "IOstreams.H"
|
||||
#include "UList.H"
|
||||
#include "List.H"
|
||||
#include "HashSet.H"
|
||||
|
||||
#include <typeinfo>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -190,6 +190,8 @@ int main(int argc, char *argv[])
|
||||
<< nl;
|
||||
|
||||
Info<< "Subset = " << subsetList(values1, limiter) << nl;
|
||||
Info<< "Subset = "
|
||||
<< IndirectList<scalar>::subset_if(values1, limiter) << nl;
|
||||
|
||||
Info<< nl << "test clip() with limiter: " << limiter << nl;
|
||||
for (const scalar& val : values1)
|
||||
|
||||
@ -32,7 +32,6 @@ Description
|
||||
#include "argList.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "primitiveFacePatch.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "IndirectList.H"
|
||||
#include "Fstream.H"
|
||||
|
||||
@ -44,7 +44,7 @@ int main(int argc, char *argv[])
|
||||
argList::noFunctionObjects();
|
||||
argList::addNote
|
||||
(
|
||||
"Create a metis graph file representation for an OpenFOAM mesh"
|
||||
"Create graph of OpenFOAM mesh connections"
|
||||
);
|
||||
|
||||
#include "setRootCase.H"
|
||||
@ -59,9 +59,9 @@ int main(int argc, char *argv[])
|
||||
#include "createTime.H"
|
||||
#include "createPolyMesh.H"
|
||||
|
||||
const globalMeshData& globData = mesh.globalData();
|
||||
|
||||
const labelListList& connectivity = globData;
|
||||
// Adjacency table
|
||||
const labelListList& connectivity =
|
||||
mesh.globalData().topology().procNeighbours();
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,7 +28,9 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "SortList.H"
|
||||
#include "SortableList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "ListOps.H"
|
||||
#include "HashSet.H"
|
||||
#include "stringOps.H"
|
||||
@ -49,6 +51,18 @@ void printInfo(const SortableList<T>& list)
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
{
|
||||
const labelList orig({7, 9, 7, 12, 9, 1, 12, 2, 4, 7, 4, 0});
|
||||
|
||||
Info<< "original list: " << flatOutput(orig) << endl;
|
||||
|
||||
auto unique = IndirectList<label>::uniq(orig);
|
||||
|
||||
Info<< "unique list: " << flatOutput(unique) << endl;
|
||||
Info<< "unique idx : " << flatOutput(unique.addressing()) << endl;
|
||||
}
|
||||
|
||||
|
||||
const labelList orig({7, 9, 1, 2, 4, 7, 4, 0});
|
||||
|
||||
labelList order;
|
||||
|
||||
@ -45,7 +45,7 @@ Original Authors
|
||||
#include "areaFields.H"
|
||||
#include "edgeFields.H"
|
||||
#include "processorFaPatch.H"
|
||||
#include "foamVtkUIndPatchWriter.H"
|
||||
#include "foamVtkIndPatchWriter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ Original Authors
|
||||
#include "faFieldDecomposer.H"
|
||||
#include "faMeshReconstructor.H"
|
||||
#include "PtrListOps.H"
|
||||
#include "foamVtkUIndPatchWriter.H"
|
||||
#include "foamVtkIndPatchWriter.H"
|
||||
#include "OBJstream.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -60,6 +60,7 @@ Description
|
||||
#include "wedgePolyPatch.H"
|
||||
#include "planeExtrusion.H"
|
||||
#include "emptyPolyPatch.H"
|
||||
#include "processorPolyPatch.H"
|
||||
#include "processorMeshes.H"
|
||||
#include "hexRef8Data.H"
|
||||
|
||||
|
||||
@ -163,9 +163,8 @@ void Foam::conformalVoronoiMesh::calcTetMesh
|
||||
|
||||
label nPatches = patchNames.size();
|
||||
|
||||
List<DynamicList<face>> patchFaces(nPatches, DynamicList<face>(0));
|
||||
|
||||
List<DynamicList<label>> patchOwners(nPatches, DynamicList<label>(0));
|
||||
List<DynamicList<face>> patchFaces(nPatches);
|
||||
List<DynamicList<label>> patchOwners(nPatches);
|
||||
|
||||
faces.setSize(number_of_finite_facets());
|
||||
|
||||
@ -1711,12 +1710,11 @@ void Foam::conformalVoronoiMesh::createFacesOwnerNeighbourAndPatches
|
||||
patchDicts[patchi].getOrDefault<label>("neighbProcNo", -1);
|
||||
}
|
||||
|
||||
List<DynamicList<face>> patchFaces(nPatches, DynamicList<face>(0));
|
||||
List<DynamicList<label>> patchOwners(nPatches, DynamicList<label>(0));
|
||||
List<DynamicList<face>> patchFaces(nPatches);
|
||||
List<DynamicList<label>> patchOwners(nPatches);
|
||||
// Per patch face the index of the slave node of the point pair
|
||||
List<DynamicList<label>> patchPPSlaves(nPatches, DynamicList<label>(0));
|
||||
|
||||
List<DynamicList<bool>> indirectPatchFace(nPatches, DynamicList<bool>(0));
|
||||
List<DynamicList<label>> patchPPSlaves(nPatches);
|
||||
List<DynamicList<bool>> indirectPatchFace(nPatches);
|
||||
|
||||
|
||||
faces.setSize(number_of_finite_edges());
|
||||
|
||||
@ -55,7 +55,7 @@ Description
|
||||
#include "faceSet.H"
|
||||
#include "motionSmoother.H"
|
||||
#include "polyTopoChange.H"
|
||||
#include "uindirectPrimitivePatch.H"
|
||||
#include "indirectPrimitivePatch.H"
|
||||
#include "surfZoneIdentifierList.H"
|
||||
#include "UnsortedMeshedSurface.H"
|
||||
#include "MeshedSurface.H"
|
||||
|
||||
@ -57,6 +57,7 @@ Description
|
||||
|
||||
#include "fvMeshTools.H"
|
||||
#include "topoSet.H"
|
||||
#include "processorPolyPatch.H"
|
||||
#include "processorMeshes.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -58,7 +58,7 @@ Description
|
||||
#include "attachDetach.H"
|
||||
#include "attachPolyTopoChanger.H"
|
||||
#include "regionSide.H"
|
||||
#include "primitiveFacePatch.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "processorMeshes.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -39,7 +39,7 @@ SourceFiles
|
||||
#define writeAreaFields_H
|
||||
|
||||
#include "readFields.H"
|
||||
#include "foamVtkUIndPatchGeoFieldsWriter.H"
|
||||
#include "foamVtkIndPatchGeoFieldsWriter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -38,7 +38,7 @@ SourceFiles
|
||||
#define writeSurfaceFields_H
|
||||
|
||||
#include "readFields.H"
|
||||
#include "primitiveFacePatch.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "foamVtkGenericPatchGeoFieldsWriter.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -57,7 +57,7 @@ Description
|
||||
#include "distributedTriSurfaceMesh.H"
|
||||
#include "meshTools.H"
|
||||
|
||||
#include "uindirectPrimitivePatch.H"
|
||||
#include "indirectPrimitivePatch.H"
|
||||
#include "DynamicField.H"
|
||||
#include "unitConversion.H"
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ Description
|
||||
#include "emptyPolyPatch.H"
|
||||
#include "processorPolyPatch.H"
|
||||
#include "ListListOps.H"
|
||||
#include "uindirectPrimitivePatch.H"
|
||||
#include "indirectPrimitivePatch.H"
|
||||
#include "globalMeshData.H"
|
||||
#include "globalIndex.H"
|
||||
#include "timeSelector.H"
|
||||
|
||||
@ -32,8 +32,8 @@ License
|
||||
#include "JobInfo.H"
|
||||
#include "OSspecific.H"
|
||||
#include "IOstreams.H"
|
||||
#include "List.H"
|
||||
#include "Switch.H"
|
||||
#include "UList.H"
|
||||
|
||||
#include <float.h> // For *fp functions
|
||||
#include <limits>
|
||||
|
||||
@ -31,8 +31,8 @@ License
|
||||
#include "JobInfo.H"
|
||||
#include "OSspecific.H"
|
||||
#include "IOstreams.H"
|
||||
#include "List.H"
|
||||
#include "Switch.H"
|
||||
#include "UList.H"
|
||||
|
||||
#include <limits>
|
||||
|
||||
|
||||
@ -317,7 +317,7 @@ $(IOdictionary)/localIOdictionary.C
|
||||
$(IOdictionary)/unwatchedIOdictionary.C
|
||||
$(IOdictionary)/IOdictionary.C
|
||||
|
||||
db/IOobjects/IOMap/IOMapName.C
|
||||
db/IOobjects/IOMap/IOMaps.C
|
||||
db/IOobjects/decomposedBlockData/decomposedBlockData.C
|
||||
db/IOobjects/decomposedBlockData/decomposedBlockDataHeader.C
|
||||
db/IOobjects/GlobalIOField/GlobalIOFields.C
|
||||
|
||||
@ -344,7 +344,7 @@ public:
|
||||
//- a minimum position, below which trimming will not occur.
|
||||
//
|
||||
// \return true if trimming changed the size.
|
||||
inline bool trim(label minpos=-1);
|
||||
inline bool trim(label minpos = -1);
|
||||
|
||||
//- Clear all bits but do not adjust the addressable size.
|
||||
// \note Method name compatibility with boost::dynamic_bitset
|
||||
|
||||
@ -43,7 +43,7 @@ Foam::bitSet& Foam::bitSet::minusEq(const bitSet& other)
|
||||
{
|
||||
if (&other == this)
|
||||
{
|
||||
// Self '-=' : results in clearing all bits
|
||||
// Self '-=' : clears all bits
|
||||
if (debug & 2)
|
||||
{
|
||||
InfoInFunction
|
||||
@ -53,12 +53,12 @@ Foam::bitSet& Foam::bitSet::minusEq(const bitSet& other)
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
else if (empty() || other.empty())
|
||||
else if (none() || other.none())
|
||||
{
|
||||
// no-op: nothing can change
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// The operation (on overlapping blocks)
|
||||
{
|
||||
const label nblocks = num_blocks(std::min(size(), other.size()));
|
||||
@ -88,21 +88,32 @@ Foam::bitSet& Foam::bitSet::andEq(const bitSet& other)
|
||||
|
||||
return *this;
|
||||
}
|
||||
else if (empty())
|
||||
else if (none())
|
||||
{
|
||||
// empty set : no-op (no overlap possible)
|
||||
// no-op: nothing is set - no intersection possible
|
||||
return *this;
|
||||
}
|
||||
else if (other.empty())
|
||||
else if (other.none())
|
||||
{
|
||||
reset(); // Other is empty - no overlap possible
|
||||
// no-op: other has nothing set - no intersection possible
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
const label origSize(size());
|
||||
const label otherSize(other.size());
|
||||
|
||||
if (origSize > otherSize)
|
||||
{
|
||||
// Clear bits (and blocks) that do not overlap at all
|
||||
resize(otherSize);
|
||||
resize(origSize);
|
||||
}
|
||||
|
||||
// The operation (on overlapping blocks)
|
||||
{
|
||||
const label nblocks = num_blocks(std::min(size(), other.size()));
|
||||
const label nblocks = num_blocks(std::min(origSize, otherSize));
|
||||
const auto& rhs = other.blocks_;
|
||||
|
||||
for (label blocki = 0; blocki < nblocks; ++blocki)
|
||||
@ -115,7 +126,7 @@ Foam::bitSet& Foam::bitSet::andEq(const bitSet& other)
|
||||
}
|
||||
|
||||
|
||||
Foam::bitSet& Foam::bitSet::orEq(const bitSet& other, const bool strict)
|
||||
Foam::bitSet& Foam::bitSet::orEq(const bitSet& other)
|
||||
{
|
||||
if (&other == this)
|
||||
{
|
||||
@ -129,52 +140,21 @@ Foam::bitSet& Foam::bitSet::orEq(const bitSet& other, const bool strict)
|
||||
|
||||
return *this;
|
||||
}
|
||||
else if (other.empty())
|
||||
else if (other.none())
|
||||
{
|
||||
if ((debug & 2) && !empty())
|
||||
{
|
||||
// OK if both are empty
|
||||
InfoInFunction
|
||||
<< "Perform |= using empty operand: ignore" << nl;
|
||||
}
|
||||
|
||||
// No (normal) overlap: no-op
|
||||
// no-op: nothing can change
|
||||
return *this;
|
||||
}
|
||||
else if (empty())
|
||||
|
||||
|
||||
// Largest new bit that could be introduced
|
||||
const label otherMax(other.find_last());
|
||||
|
||||
if (otherMax >= size())
|
||||
{
|
||||
if (debug & 2)
|
||||
{
|
||||
InfoInFunction
|
||||
<< "Perform |= on empty bitSet" << nl;
|
||||
}
|
||||
|
||||
if (strict)
|
||||
{
|
||||
// No (normal) overlap: no-op
|
||||
return *this;
|
||||
}
|
||||
// Extend to accommodate bits from 'other'
|
||||
resize(otherMax+1);
|
||||
}
|
||||
else if ((debug & 2) && (size() != other.size()))
|
||||
{
|
||||
InfoInFunction
|
||||
<< "Perform |= on dissimilar sized bitSets: "
|
||||
<< size() << " vs. " << other.size() << nl;
|
||||
}
|
||||
|
||||
label minpos = -1; // Min trim point
|
||||
|
||||
if ((size() < other.size()) && !strict)
|
||||
{
|
||||
// The size (B > A) and we are non-strict (greedy), which means we may
|
||||
// acquire additional bits from B. However, we would like to avoid
|
||||
// spurious changes in the size of A (ie, B is longer but the extra
|
||||
// bits are unset and thus don't affect the logical result).
|
||||
|
||||
minpos = size();
|
||||
resize(other.size()); // Blocks now overlap
|
||||
}
|
||||
|
||||
|
||||
// The operation (on overlapping blocks)
|
||||
{
|
||||
@ -187,26 +167,15 @@ Foam::bitSet& Foam::bitSet::orEq(const bitSet& other, const bool strict)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Cleanup - minpos >= 0 means we need to check/adjust the trim point
|
||||
if (minpos >= 0)
|
||||
{
|
||||
trim(minpos); // Adjust the trim point (size)
|
||||
}
|
||||
else
|
||||
{
|
||||
clear_trailing_bits();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Foam::bitSet& Foam::bitSet::xorEq(const bitSet& other, const bool strict)
|
||||
Foam::bitSet& Foam::bitSet::xorEq(const bitSet& other)
|
||||
{
|
||||
if (&other == this)
|
||||
{
|
||||
// Self '^=' : results in clearing all bits
|
||||
// Self '^=' : clears all bits
|
||||
|
||||
if (debug & 2)
|
||||
{
|
||||
@ -217,47 +186,21 @@ Foam::bitSet& Foam::bitSet::xorEq(const bitSet& other, const bool strict)
|
||||
reset();
|
||||
return *this;
|
||||
}
|
||||
else if (other.empty())
|
||||
else if (other.none())
|
||||
{
|
||||
if ((debug & 2) && !empty())
|
||||
{
|
||||
// OK if both are empty
|
||||
InfoInFunction
|
||||
<< "Perform ^= using empty operand: ignore" << nl;
|
||||
}
|
||||
|
||||
// No (normal) overlap: no-op
|
||||
// no-op: nothing can change
|
||||
return *this;
|
||||
}
|
||||
else if (empty())
|
||||
|
||||
|
||||
// Largest new bit that could be introduced
|
||||
const label otherMax(other.find_last());
|
||||
|
||||
if (otherMax >= size())
|
||||
{
|
||||
if (debug & 2)
|
||||
{
|
||||
InfoInFunction
|
||||
<< "Perform ^= on empty bitSet" << nl;
|
||||
}
|
||||
|
||||
if (strict)
|
||||
{
|
||||
// No (normal) overlap: no-op
|
||||
return *this;
|
||||
}
|
||||
// Extend to accommodate bits from 'other'
|
||||
resize(otherMax+1);
|
||||
}
|
||||
else if ((debug & 2) && (size() != other.size()))
|
||||
{
|
||||
InfoInFunction
|
||||
<< "Perform ^= on dissimilar sized bitSets: "
|
||||
<< size() << " vs. " << other.size() << nl;
|
||||
}
|
||||
|
||||
label minpos = -1; // Min trim point
|
||||
|
||||
if ((size() < other.size()) && !strict)
|
||||
{
|
||||
minpos = size(); // This logic is explained in the orEq() method
|
||||
resize(other.size()); // Blocks now overlap
|
||||
}
|
||||
|
||||
|
||||
// The operation (on overlapping blocks)
|
||||
{
|
||||
@ -270,17 +213,6 @@ Foam::bitSet& Foam::bitSet::xorEq(const bitSet& other, const bool strict)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Cleanup - minpos >= 0 means we need to check/adjust the trim point
|
||||
if (minpos >= 0)
|
||||
{
|
||||
trim(minpos); // Adjust the trim point (size)
|
||||
}
|
||||
else
|
||||
{
|
||||
clear_trailing_bits();
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
@ -83,7 +83,8 @@ protected:
|
||||
// A = (A & ~B)
|
||||
// \endcode
|
||||
// A and B can have different sizes.
|
||||
// Does not change the original set size.
|
||||
// Never changes the original set size.
|
||||
// Non-overlapping parts are considered \em off.
|
||||
bitSet& minusEq(const bitSet& other);
|
||||
|
||||
//- The set logical AND
|
||||
@ -91,8 +92,9 @@ protected:
|
||||
// A = (A & B)
|
||||
//
|
||||
// \endcode
|
||||
// A and B can have different sizes..
|
||||
// Does not change the original set size.
|
||||
// A and B can have different sizes.
|
||||
// Never changes the original set size.
|
||||
// Non-overlapping parts are considered \em off.
|
||||
bitSet& andEq(const bitSet& other);
|
||||
|
||||
//- The set logical OR
|
||||
@ -101,18 +103,17 @@ protected:
|
||||
// \endcode
|
||||
// A and B can have different sizes
|
||||
//
|
||||
// \note
|
||||
// The default (strict=true) ignores additional length from B,
|
||||
// whereas (strict=false) permits the set to automatically grow
|
||||
// to accommodate additional elements arising from B.
|
||||
bitSet& orEq(const bitSet& other, const bool strict=true);
|
||||
// The size grows to accommodate new \em on bits.
|
||||
bitSet& orEq(const bitSet& other);
|
||||
|
||||
//- The set logical XOR
|
||||
// \code
|
||||
// A = (A ^ B)
|
||||
// \endcode
|
||||
// A and B can have different sizes. Sizing behaviour as per orEq.
|
||||
bitSet& xorEq(const bitSet& other, const bool strict=true);
|
||||
// A and B can have different sizes.
|
||||
//
|
||||
// The size grows to accommodate new \em on bits.
|
||||
bitSet& xorEq(const bitSet& other);
|
||||
|
||||
|
||||
public:
|
||||
@ -123,6 +124,7 @@ public:
|
||||
class const_iterator;
|
||||
typedef unsigned int const_reference;
|
||||
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Return a null bitSet reference
|
||||
@ -363,10 +365,14 @@ public:
|
||||
//- Invert all bits in the addressable region
|
||||
inline void flip();
|
||||
|
||||
//- Invert bits at the specified position.
|
||||
//- Invert bit at the specified position.
|
||||
// A no-op if the position is out-of-range
|
||||
inline void flip(const label pos);
|
||||
|
||||
//- Resize to include the last \em on bit only.
|
||||
// Functionally identical to resize(find_last()+1)
|
||||
inline void resize_last();
|
||||
|
||||
//- Swap contents
|
||||
inline void swap(bitSet& bitset);
|
||||
|
||||
@ -573,23 +579,24 @@ public:
|
||||
inline bitSet& operator=(const bool val);
|
||||
|
||||
//- Bitwise-AND all the bits in other with the bits in this bitset.
|
||||
// The operands may have dissimilar sizes without affecting the size
|
||||
// of the set.
|
||||
// The operands may have dissimilar sizes,
|
||||
// never changes the original set size.
|
||||
// Non-overlapping elements are considered \em off.
|
||||
inline bitSet& operator&=(const bitSet& other);
|
||||
|
||||
//- Bitwise-OR operator - similar to the set() method.
|
||||
// The operands may have dissimilar sizes without affecting the size
|
||||
// of the set.
|
||||
// The operands may have dissimilar sizes,
|
||||
// the set grows to accommodate new \em on bits.
|
||||
inline bitSet& operator|=(const bitSet& other);
|
||||
|
||||
//- Bitwise-XOR operator - retains unique entries.
|
||||
// The operands may have dissimilar sizes without affecting the size
|
||||
// of the set.
|
||||
// The operands may have dissimilar sizes,
|
||||
// the set grows to accommodate new \em on bits.
|
||||
inline bitSet& operator^=(const bitSet& other);
|
||||
|
||||
//- Remove entries from this list - identical to the unset() method.
|
||||
// The operands may have dissimilar sizes without affecting the size
|
||||
// of the set.
|
||||
// The operands may have dissimilar sizes,
|
||||
// never changes the original set size.
|
||||
inline bitSet& operator-=(const bitSet& other);
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2018-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -316,6 +316,7 @@ inline Foam::label Foam::bitSet::find_first() const
|
||||
// Process block-wise, detecting any '1' bits
|
||||
|
||||
const label nblocks = num_blocks(size());
|
||||
|
||||
for (label blocki = 0; blocki < nblocks; ++blocki)
|
||||
{
|
||||
label pos = (blocki * elem_per_block);
|
||||
@ -535,6 +536,21 @@ inline Foam::labelList Foam::bitSet::sortedToc() const
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::bitSet::resize_last()
|
||||
{
|
||||
const label pos = find_last();
|
||||
|
||||
if (pos >= 0)
|
||||
{
|
||||
resize(pos+1);
|
||||
}
|
||||
else
|
||||
{
|
||||
clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void Foam::bitSet::swap(bitSet& bitset)
|
||||
{
|
||||
PackedList<1>::swap(bitset);
|
||||
@ -573,7 +589,7 @@ inline void Foam::bitSet::fill(const bool val)
|
||||
|
||||
inline void Foam::bitSet::set(const bitSet& bitset)
|
||||
{
|
||||
orEq(bitset, false); // Non-strict: Lets the set size grow.
|
||||
orEq(bitset);
|
||||
}
|
||||
|
||||
|
||||
@ -754,28 +770,40 @@ inline Foam::bitSet Foam::operator~(const bitSet& bitset)
|
||||
inline Foam::bitSet Foam::operator&(const bitSet& a, const bitSet& b)
|
||||
{
|
||||
bitSet result(a);
|
||||
return (result &= b);
|
||||
result &= b;
|
||||
|
||||
result.resize_last();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::bitSet Foam::operator|(const bitSet& a, const bitSet& b)
|
||||
{
|
||||
bitSet result(a);
|
||||
return (result |= b);
|
||||
result |= b;
|
||||
|
||||
result.resize_last();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::bitSet Foam::operator^(const bitSet& a, const bitSet& b)
|
||||
{
|
||||
bitSet result(a);
|
||||
return (result ^= b);
|
||||
result ^= b;
|
||||
|
||||
result.resize_last();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
inline Foam::bitSet Foam::operator-(const bitSet& a, const bitSet& b)
|
||||
{
|
||||
bitSet result(a);
|
||||
return (result -= b);
|
||||
result |= b;
|
||||
|
||||
result.resize_last();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,12 +26,13 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef HashTable_C
|
||||
#define HashTable_C
|
||||
#ifndef Foam_HashTable_C
|
||||
#define Foam_HashTable_C
|
||||
|
||||
#include "HashTable.H"
|
||||
#include "List.H"
|
||||
#include "FixedList.H"
|
||||
#include "UPtrList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
@ -156,6 +157,45 @@ Foam::List<Key> Foam::HashTable<T, Key, Hash>::sortedToc
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::UPtrList<const typename Foam::HashTable<T, Key, Hash>::node_type>
|
||||
Foam::HashTable<T, Key, Hash>::sorted() const
|
||||
{
|
||||
UPtrList<const node_type> list(size_);
|
||||
|
||||
label count = 0;
|
||||
|
||||
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
|
||||
{
|
||||
list.set(count++, iter.node());
|
||||
}
|
||||
|
||||
Foam::sort(list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
Foam::UPtrList<typename Foam::HashTable<T, Key, Hash>::node_type>
|
||||
Foam::HashTable<T, Key, Hash>::sorted()
|
||||
{
|
||||
UPtrList<node_type> list(size_);
|
||||
|
||||
label count = 0;
|
||||
|
||||
for (iterator iter = begin(); iter != end(); ++iter)
|
||||
{
|
||||
list.set(count++, iter.node());
|
||||
}
|
||||
|
||||
Foam::sort(list);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<class T, class Key, class Hash>
|
||||
template<class UnaryPredicate>
|
||||
Foam::List<Key> Foam::HashTable<T, Key, Hash>::tocKeys
|
||||
|
||||
@ -34,7 +34,8 @@ Description
|
||||
depends on the method used to generate the hash key index, the
|
||||
table capacity, insertion order etc. When the key order is
|
||||
important, use the sortedToc() method to obtain a list of sorted
|
||||
keys and use that for further access.
|
||||
keys and use that for further access, or the sorted() method
|
||||
to obtain a UPtrList of entries to traverse in sorted order.
|
||||
|
||||
Internally the table uses closed addressing into a flat storage space
|
||||
with collisions handled by linked-list chaining.
|
||||
@ -80,8 +81,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef HashTable_H
|
||||
#define HashTable_H
|
||||
#ifndef Foam_HashTable_H
|
||||
#define Foam_HashTable_H
|
||||
|
||||
#include "word.H"
|
||||
#include "zero.H"
|
||||
@ -102,6 +103,7 @@ namespace Foam
|
||||
|
||||
template<class T> class List;
|
||||
template<class T> class UList;
|
||||
template<class T> class UPtrList;
|
||||
template<class T, unsigned N> class FixedList;
|
||||
template<class T, class Key, class Hash> class HashTable;
|
||||
|
||||
@ -120,9 +122,15 @@ class HashTable
|
||||
:
|
||||
public HashTableCore
|
||||
{
|
||||
// Types
|
||||
public:
|
||||
|
||||
//- Table entry. A hashed node with a linked-list for collisions
|
||||
// Data Types
|
||||
|
||||
//- The template instance used for this HashTable
|
||||
typedef HashTable<T, Key, Hash> this_type;
|
||||
|
||||
//- A table entry (node) that encapsulates the key/val tuple
|
||||
//- with an additional linked-list entry for hash collisions
|
||||
typedef typename std::conditional
|
||||
<
|
||||
std::is_same<zero::null, typename std::remove_cv<T>::type>::value,
|
||||
@ -131,42 +139,6 @@ class HashTable
|
||||
>::type node_type;
|
||||
|
||||
|
||||
// Private Data
|
||||
|
||||
//- The number of nodes currently stored in table
|
||||
label size_;
|
||||
|
||||
//- Number of nodes allocated in table
|
||||
label capacity_;
|
||||
|
||||
//- The table of primary nodes
|
||||
node_type** table_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Return the hash index of the Key within the current table size.
|
||||
// No checks for zero-sized tables.
|
||||
inline label hashKeyIndex(const Key& key) const;
|
||||
|
||||
//- Assign a new hash-entry to a possibly already existing key.
|
||||
// \return True if the new entry was set.
|
||||
template<class... Args>
|
||||
bool setEntry(const bool overwrite, const Key& key, Args&&... args);
|
||||
|
||||
//- Read hash table
|
||||
Istream& readTable(Istream& is);
|
||||
|
||||
//- Write hash table
|
||||
Ostream& writeTable(Ostream& os) const;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- The template instance used for this HashTable
|
||||
typedef HashTable<T, Key, Hash> this_type;
|
||||
|
||||
|
||||
// STL type definitions
|
||||
|
||||
//- The second template parameter, type of keys used.
|
||||
@ -209,6 +181,39 @@ public:
|
||||
//- Forward iterator with const access
|
||||
class const_iterator;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private Data
|
||||
|
||||
//- The number of nodes currently stored in table
|
||||
label size_;
|
||||
|
||||
//- Number of nodes allocated in table
|
||||
label capacity_;
|
||||
|
||||
//- The table of primary nodes
|
||||
node_type** table_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Return the hash index of the Key within the current table size.
|
||||
// No checks for zero-sized tables.
|
||||
inline label hashKeyIndex(const Key& key) const;
|
||||
|
||||
//- Assign a new hash-entry to a possibly already existing key.
|
||||
// \return True if the new entry was set.
|
||||
template<class... Args>
|
||||
bool setEntry(const bool overwrite, const Key& key, Args&&... args);
|
||||
|
||||
//- Read hash table
|
||||
Istream& readTable(Istream& is);
|
||||
|
||||
//- Write hash table
|
||||
Ostream& writeTable(Ostream& os) const;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//- Internally used base for iterator and const_iterator
|
||||
@ -220,6 +225,7 @@ protected:
|
||||
//- An iterator with non-const access to HashTable internals.
|
||||
friend class Iterator<false>;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
@ -336,6 +342,17 @@ public:
|
||||
) const;
|
||||
|
||||
|
||||
// Sorted entries
|
||||
|
||||
//- Const access to the hash-table contents in sorted order
|
||||
//- (sorted by keys).
|
||||
UPtrList<const node_type> sorted() const;
|
||||
|
||||
//- Non-const access to the hash-table contents in sorted order
|
||||
//- (sorted by keys).
|
||||
UPtrList<node_type> sorted();
|
||||
|
||||
|
||||
// Counting
|
||||
|
||||
//- Count the number of keys that satisfy the unary predicate
|
||||
@ -701,6 +718,7 @@ public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using difference_type = this_type::difference_type;
|
||||
|
||||
using node_type = this_type::node_type;
|
||||
using key_type = this_type::key_type;
|
||||
using mapped_type = this_type::mapped_type;
|
||||
using value_type = this_type::value_type;
|
||||
@ -724,25 +742,37 @@ public:
|
||||
|
||||
// Member Functions/Operators
|
||||
|
||||
//- Const access to the entry (node)
|
||||
const node_type* node() const noexcept
|
||||
{
|
||||
return Iterator<false>::entry_;
|
||||
}
|
||||
|
||||
//- Non-const access to the entry (node)
|
||||
node_type* node() noexcept
|
||||
{
|
||||
return Iterator<false>::entry_;
|
||||
}
|
||||
|
||||
//- Const access to referenced object (value)
|
||||
inline const_reference val() const
|
||||
const_reference val() const
|
||||
{
|
||||
return Iterator<false>::entry_->cval();
|
||||
}
|
||||
|
||||
//- Non-const access to referenced object (value)
|
||||
inline reference val()
|
||||
reference val()
|
||||
{
|
||||
return Iterator<false>::entry_->val();
|
||||
}
|
||||
|
||||
//- Const access to referenced object (value)
|
||||
inline const_reference operator*() const { return this->val(); }
|
||||
inline const_reference operator()() const { return this->val(); }
|
||||
const_reference operator*() const { return this->val(); }
|
||||
const_reference operator()() const { return this->val(); }
|
||||
|
||||
//- Non-const access to referenced object (value)
|
||||
inline reference operator*() { return this->val(); }
|
||||
inline reference operator()() { return this->val(); }
|
||||
reference operator*() { return this->val(); }
|
||||
reference operator()() { return this->val(); }
|
||||
|
||||
inline iterator& operator++();
|
||||
inline iterator operator++(int);
|
||||
@ -762,6 +792,7 @@ public:
|
||||
using iterator_category = std::forward_iterator_tag;
|
||||
using difference_type = this_type::difference_type;
|
||||
|
||||
using node_type = this_type::node_type;
|
||||
using key_type = this_type::key_type;
|
||||
using mapped_type = const this_type::mapped_type;
|
||||
using value_type = const this_type::value_type;
|
||||
@ -799,15 +830,21 @@ public:
|
||||
|
||||
// Member Functions/Operators
|
||||
|
||||
//- Const access to the entry (node)
|
||||
const node_type* node() const noexcept
|
||||
{
|
||||
return Iterator<true>::entry_;
|
||||
}
|
||||
|
||||
//- Const access to referenced object (value)
|
||||
inline reference val() const
|
||||
reference val() const
|
||||
{
|
||||
return Iterator<true>::entry_->cval();
|
||||
}
|
||||
|
||||
//- Const access to referenced object (value)
|
||||
inline reference operator*() const { return this->val(); }
|
||||
inline reference operator()() const { return this->val(); }
|
||||
reference operator*() const { return this->val(); }
|
||||
reference operator()() const { return this->val(); }
|
||||
|
||||
inline const_iterator& operator++();
|
||||
inline const_iterator operator++(int);
|
||||
@ -853,8 +890,8 @@ public:
|
||||
{}
|
||||
|
||||
//- Return the key
|
||||
inline reference operator*() const { return this->key(); }
|
||||
inline reference operator()() const { return this->key(); }
|
||||
reference operator*() const { return this->key(); }
|
||||
reference operator()() const { return this->key(); }
|
||||
|
||||
inline key_iterator_base& operator++()
|
||||
{
|
||||
|
||||
@ -34,8 +34,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef HashTableDetail_H
|
||||
#define HashTableDetail_H
|
||||
#ifndef Foam_HashTableDetail_H
|
||||
#define Foam_HashTableDetail_H
|
||||
|
||||
#include "zero.H"
|
||||
#include <memory>
|
||||
@ -73,13 +73,13 @@ template<class T> struct isPointerLike<std::unique_ptr<T>> : std::true_type {};
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- Internal storage type for HashTable entries
|
||||
// Structure with a (K,V) tuple and a linked-list for collisions
|
||||
// Comprises a (K,V) tuple and a linked-list entry for hash collisions.
|
||||
// Could store key/val as std::pair, but no particular advantage
|
||||
// unless the iterator dereference type changes.
|
||||
template<class K, class V>
|
||||
struct HashTablePair
|
||||
{
|
||||
// Types
|
||||
// Data Types
|
||||
|
||||
//- Type of key
|
||||
typedef K key_type;
|
||||
@ -87,26 +87,26 @@ struct HashTablePair
|
||||
//- Type of content
|
||||
typedef V mapped_type;
|
||||
|
||||
//- This struct stores a value
|
||||
//- This class stores a value
|
||||
static constexpr bool stores_value() noexcept
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Member Data
|
||||
// Data
|
||||
|
||||
//- The lookup key
|
||||
key_type key_;
|
||||
const K key_;
|
||||
|
||||
//- The mapped data
|
||||
mapped_type val_;
|
||||
V val_;
|
||||
|
||||
//- Addressing (next in collision list)
|
||||
HashTablePair* next_;
|
||||
|
||||
|
||||
// Member Functions
|
||||
// Generated Methods
|
||||
|
||||
//- No copy construct
|
||||
HashTablePair(const HashTablePair&) = delete;
|
||||
@ -115,6 +115,8 @@ struct HashTablePair
|
||||
void operator=(const HashTablePair&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from next pointer, key, contents
|
||||
template<class... Args>
|
||||
HashTablePair
|
||||
@ -130,24 +132,39 @@ struct HashTablePair
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- The key
|
||||
const key_type& key() const
|
||||
const key_type& key() const noexcept
|
||||
{
|
||||
return key_;
|
||||
}
|
||||
|
||||
//- Const access to the mapped value
|
||||
const mapped_type& cval() const
|
||||
const mapped_type& cval() const noexcept
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
//- Const access to the mapped value
|
||||
const mapped_type& val() const noexcept
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
//- Non-const access to the mapped value
|
||||
mapped_type& val()
|
||||
mapped_type& val() noexcept
|
||||
{
|
||||
return val_;
|
||||
}
|
||||
|
||||
|
||||
//- Compare keys
|
||||
bool operator<(const HashTablePair& rhs) const
|
||||
{
|
||||
return key_ < rhs.key_;
|
||||
}
|
||||
|
||||
//- Write (key, val) pair - for pointer types
|
||||
template<class TypeT = V>
|
||||
typename std::enable_if
|
||||
@ -190,38 +207,38 @@ struct HashTablePair
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- Internal storage type for HashSet entries
|
||||
// Structure with a single (K) value and a linked-list for collisions
|
||||
// Comprises a single (K) value and a linked-list entry for hash collisions
|
||||
template<class K>
|
||||
struct HashTableSingle
|
||||
{
|
||||
// Types
|
||||
// Data Types
|
||||
|
||||
//- Type of key
|
||||
typedef K key_type;
|
||||
|
||||
//- Type of content
|
||||
//- Type of content (no content: placeholder)
|
||||
typedef Foam::zero::null mapped_type;
|
||||
|
||||
//- Content storage type to the entry
|
||||
typedef key_type value_type;
|
||||
|
||||
//- This struct does not store a value
|
||||
//- This class does not store any value
|
||||
static constexpr bool stores_value() noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Member Data
|
||||
// Data
|
||||
|
||||
//- The lookup key == content
|
||||
key_type key_;
|
||||
const K key_;
|
||||
|
||||
//- Addressing (next in collision list)
|
||||
HashTableSingle* next_;
|
||||
|
||||
|
||||
// Member Functions
|
||||
// Generated Methods
|
||||
|
||||
//- No copy construct
|
||||
HashTableSingle(const HashTableSingle&) = delete;
|
||||
@ -230,6 +247,8 @@ struct HashTableSingle
|
||||
void operator=(const HashTableSingle&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from next pointer, key, (unused) contents
|
||||
template<class... Args>
|
||||
HashTableSingle
|
||||
@ -244,25 +263,40 @@ struct HashTableSingle
|
||||
{}
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- The key
|
||||
const key_type& key() const
|
||||
const key_type& key() const noexcept
|
||||
{
|
||||
return key_;
|
||||
}
|
||||
|
||||
//- Const access to the (dummy) mapped value
|
||||
const mapped_type& cval() const
|
||||
const mapped_type& cval() const noexcept
|
||||
{
|
||||
return Foam::zero::null::dummy;
|
||||
}
|
||||
|
||||
//- Const access to the (dummy) mapped value
|
||||
const mapped_type& val() const noexcept
|
||||
{
|
||||
return Foam::zero::null::dummy;
|
||||
}
|
||||
|
||||
//- Non-const access to the (dummy) mapped value
|
||||
mapped_type& val()
|
||||
mapped_type& val() noexcept
|
||||
{
|
||||
return Foam::zero::null::dummy;
|
||||
}
|
||||
|
||||
//- Write the key. There is no value
|
||||
|
||||
//- Compare keys
|
||||
bool operator<(const HashTableSingle& rhs) const
|
||||
{
|
||||
return key_ < rhs.key_;
|
||||
}
|
||||
|
||||
//- Write the key. There is no value to write.
|
||||
void print(Ostream& os) const
|
||||
{
|
||||
os << key_;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,22 +33,82 @@ Description
|
||||
See also
|
||||
Foam::UIndirectList for a version without addressing allocation.
|
||||
|
||||
Class
|
||||
Foam::UIndirectList
|
||||
|
||||
Description
|
||||
A List with indirect addressing.
|
||||
Like IndirectList but does not store addressing
|
||||
|
||||
Note the const_cast of the list values. This is so we can use it both
|
||||
on const and non-const lists. Alternative would be to have a const_
|
||||
variant etc.
|
||||
|
||||
SourceFiles
|
||||
IndirectListI.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef IndirectList_H
|
||||
#define IndirectList_H
|
||||
#ifndef Foam_IndirectList_H
|
||||
#define Foam_IndirectList_H
|
||||
|
||||
#include "List.H"
|
||||
#include "IndirectListBase.H"
|
||||
#include "IndirectListAddressing.H"
|
||||
#include "UIndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
template<class T> class IndirectList;
|
||||
template<class T> class UIndirectList;
|
||||
|
||||
// Common list types
|
||||
typedef UIndirectList<bool> boolUIndList; //!< UIndirectList of bools
|
||||
typedef UIndirectList<label> labelUIndList; //!< UIndirectList of labels
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class UIndirectList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class T>
|
||||
class UIndirectList
|
||||
:
|
||||
public IndirectListBase<T, labelUList>
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Shallow copy values and addressing
|
||||
UIndirectList(const UList<T>& values, const labelUList& addr)
|
||||
:
|
||||
IndirectListBase<T, labelUList>(values, addr)
|
||||
{}
|
||||
|
||||
//- Copy construct (shallow copy values and addressing)
|
||||
UIndirectList(const UIndirectList<T>& list)
|
||||
:
|
||||
UIndirectList<T>(list.values(), list.addressing())
|
||||
{}
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Use standard assignment operations
|
||||
using IndirectListBase<T, labelUList>::operator=;
|
||||
|
||||
//- Deep copy values, Fatal if list sizes are not identical
|
||||
void operator=(const UIndirectList<T>& rhs)
|
||||
{
|
||||
this->copyList(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class IndirectList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
@ -82,6 +142,53 @@ public:
|
||||
inline explicit IndirectList(const UIndirectList<T>& list);
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Return an IndirectList comprising entries with \em positions
|
||||
//- that satisfy the condition predicate.
|
||||
//
|
||||
// The condition predicate can be considered a type of \em mask
|
||||
// for any given position.
|
||||
// A boolList, bitSet, labelRange or labelHashSet all satisfy
|
||||
// the requirements for use as position condition predicates.
|
||||
//
|
||||
// \param values The source list values
|
||||
// \param select Accept/reject predicate based on \em position.
|
||||
// \param invert Invert (negate) the selection logic
|
||||
template<class UnaryCondition>
|
||||
static IndirectList<T> subset
|
||||
(
|
||||
const UList<T>& values,
|
||||
const UnaryCondition& select,
|
||||
const bool invert = false
|
||||
);
|
||||
|
||||
//- Return an IndirectList comprising entries with \em values
|
||||
//- that satisfy the predicate.
|
||||
//
|
||||
// \param values The source list values
|
||||
// \param pred Predicate used to test the \em value
|
||||
// \param invert Invert (negate) the selection logic
|
||||
template<class UnaryPredicate>
|
||||
static IndirectList<T> subset_if
|
||||
(
|
||||
const UList<T>& values,
|
||||
const UnaryPredicate& pred,
|
||||
const bool invert = false
|
||||
);
|
||||
|
||||
//- Return an IndirectList with duplicate entries filtered out.
|
||||
// Preserves the original input order, unless sorted = true
|
||||
//
|
||||
// \param values The source list values
|
||||
// \param sorted Retain sorted order instead of original order
|
||||
static IndirectList<T> uniq
|
||||
(
|
||||
const UList<T>& values,
|
||||
const bool sorted = false
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- The list addressing
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -115,4 +115,111 @@ inline Foam::IndirectList<T>::IndirectList(const UIndirectList<T>& list)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
template<class UnaryCondition>
|
||||
Foam::IndirectList<T> Foam::IndirectList<T>::subset
|
||||
(
|
||||
const UList<T>& values,
|
||||
const UnaryCondition& select,
|
||||
const bool invert
|
||||
)
|
||||
{
|
||||
const label len = values.size();
|
||||
|
||||
IndirectList<T> result(values, Foam::zero{});
|
||||
labelList& addr = result.addressing();
|
||||
|
||||
addr.resize_nocopy(len);
|
||||
|
||||
label count = 0;
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
// Test on position
|
||||
if (select(i) ? !invert : invert)
|
||||
{
|
||||
addr[count] = i;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
addr.resize(count);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
template<class UnaryPredicate>
|
||||
Foam::IndirectList<T> Foam::IndirectList<T>::subset_if
|
||||
(
|
||||
const UList<T>& values,
|
||||
const UnaryPredicate& pred,
|
||||
const bool invert
|
||||
)
|
||||
{
|
||||
const label len = values.size();
|
||||
|
||||
IndirectList<T> result(values, Foam::zero{});
|
||||
labelList& addr = result.addressing();
|
||||
|
||||
addr.resize_nocopy(len);
|
||||
|
||||
label count = 0;
|
||||
for (label i=0; i < len; ++i)
|
||||
{
|
||||
// Test on value
|
||||
if (pred(values[i]) ? !invert : invert)
|
||||
{
|
||||
addr[count] = i;
|
||||
++count;
|
||||
}
|
||||
}
|
||||
addr.resize(count);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::IndirectList<T> Foam::IndirectList<T>::uniq
|
||||
(
|
||||
const UList<T>& values,
|
||||
const bool sorted
|
||||
)
|
||||
{
|
||||
const label len = values.size();
|
||||
|
||||
IndirectList<T> result(values, Foam::zero{});
|
||||
labelList& order = result.addressing();
|
||||
|
||||
// Start from sorted order
|
||||
Foam::sortedOrder(values, order);
|
||||
|
||||
if (len > 1)
|
||||
{
|
||||
label count = 0;
|
||||
for (label i = 1; i < len; ++i)
|
||||
{
|
||||
// Eliminate duplicates
|
||||
if (values[order[count]] != values[order[i]])
|
||||
{
|
||||
++count;
|
||||
order[count] = order[i];
|
||||
}
|
||||
}
|
||||
++count;
|
||||
order.resize(count);
|
||||
|
||||
// Recover the original input order
|
||||
if (!sorted)
|
||||
{
|
||||
Foam::sort(order);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Description
|
||||
Compatibility include
|
||||
|
||||
UIndirectList.H combined into IndirectList.H (MAY-2022)
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Foam_UIndirectList_H
|
||||
#define Foam_UIndirectList_H
|
||||
|
||||
#include "IndirectList.H"
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -33,8 +33,10 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef IndirectListAddressing_H
|
||||
#define IndirectListAddressing_H
|
||||
#ifndef Foam_IndirectListAddressing_H
|
||||
#define Foam_IndirectListAddressing_H
|
||||
|
||||
#include <utility> // std::move
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -25,7 +25,7 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ListOps.H"
|
||||
#include "ListOps.H" // For identity
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -1,108 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2019 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::UIndirectList
|
||||
|
||||
Description
|
||||
A List with indirect addressing.
|
||||
|
||||
Like IndirectList but does not store addressing.
|
||||
|
||||
Note the const_cast of the list values. This is so we can use it both
|
||||
on const and non-const lists. Alternative would be to have a const_
|
||||
variant etc.
|
||||
|
||||
SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef UIndirectList_H
|
||||
#define UIndirectList_H
|
||||
|
||||
#include "List.H"
|
||||
#include "IndirectListBase.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
template<class T> class UIndirectList;
|
||||
|
||||
// Common list types
|
||||
typedef UIndirectList<bool> boolUIndList; //!< UIndirectList of bools
|
||||
typedef UIndirectList<label> labelUIndList; //!< UIndirectList of labels
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class UIndirectList Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class T>
|
||||
class UIndirectList
|
||||
:
|
||||
public IndirectListBase<T, labelUList>
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Shallow copy values and addressing
|
||||
UIndirectList(const UList<T>& values, const labelUList& addr)
|
||||
:
|
||||
IndirectListBase<T, labelUList>(values, addr)
|
||||
{}
|
||||
|
||||
//- Copy construct (shallow copy values and addressing)
|
||||
UIndirectList(const UIndirectList<T>& list)
|
||||
:
|
||||
UIndirectList<T>(list.values(), list.addressing())
|
||||
{}
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Use standard assignment operations
|
||||
using IndirectListBase<T, labelUList>::operator=;
|
||||
|
||||
//- Deep copy values, Fatal if list sizes are not identical
|
||||
void operator=(const UIndirectList<T>& rhs)
|
||||
{
|
||||
this->copyList(rhs);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -636,4 +636,52 @@ void Foam::List<T>::operator=(SLList<T>&& list)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
Foam::labelList Foam::sortedOrder
|
||||
(
|
||||
const UList<T>& list
|
||||
)
|
||||
{
|
||||
labelList order;
|
||||
Foam::sortedOrder(list, order, typename UList<T>::less(list));
|
||||
return order;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::sortedOrder
|
||||
(
|
||||
const UList<T>& list,
|
||||
labelList& order
|
||||
)
|
||||
{
|
||||
Foam::sortedOrder(list, order, typename UList<T>::less(list));
|
||||
}
|
||||
|
||||
|
||||
template<class T, class ListComparePredicate>
|
||||
void Foam::sortedOrder
|
||||
(
|
||||
const UList<T>& list,
|
||||
labelList& order,
|
||||
const ListComparePredicate& comp
|
||||
)
|
||||
{
|
||||
// List lengths must be identical. Old content is overwritten
|
||||
order.resize_nocopy(list.size());
|
||||
|
||||
// Same as std::iota and ListOps::identity
|
||||
label value = 0;
|
||||
for (label& item : order)
|
||||
{
|
||||
item = value;
|
||||
++value;
|
||||
}
|
||||
|
||||
Foam::stableSort(order, comp);
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -373,10 +373,27 @@ Istream& operator>>(Istream& is, List<T>& list)
|
||||
|
||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||
|
||||
//- Create identity map of the given length with (map[i] == i)
|
||||
//- Return an identity map of the given length with (map[i] == i)
|
||||
// Optionally with an alternative start index, so that (map[i] == i+start)
|
||||
labelList identity(const label len, label start=0);
|
||||
|
||||
//- Return the (stable) sort order for the list
|
||||
template<class T>
|
||||
labelList sortedOrder(const UList<T>& input);
|
||||
|
||||
//- Generate the (stable) sort order for the list
|
||||
template<class T>
|
||||
void sortedOrder(const UList<T>& input, labelList& order);
|
||||
|
||||
//- Sort using specified list compare predicate
|
||||
template<class T, class ListComparePredicate>
|
||||
void sortedOrder
|
||||
(
|
||||
const UList<T>& input,
|
||||
labelList& order,
|
||||
const ListComparePredicate& comp
|
||||
);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -39,11 +39,10 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef SubList_H
|
||||
#define SubList_H
|
||||
#ifndef Foam_SubList_H
|
||||
#define Foam_SubList_H
|
||||
|
||||
#include "List.H"
|
||||
#include "FixedList.H"
|
||||
#include "labelRange.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
@ -52,6 +51,7 @@ namespace Foam
|
||||
{
|
||||
|
||||
// Forward Declarations
|
||||
template<class T, unsigned N> class FixedList;
|
||||
template<class T> class SubList;
|
||||
|
||||
// Common list types
|
||||
@ -26,6 +26,8 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "FixedList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -257,41 +257,6 @@ Foam::label Foam::UList<T>::rfind(const T& val, label pos) const
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::sort(UList<T>& a)
|
||||
{
|
||||
std::sort(a.begin(), a.end());
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Compare>
|
||||
void Foam::sort(UList<T>& a, const Compare& comp)
|
||||
{
|
||||
std::sort(a.begin(), a.end(), comp);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::stableSort(UList<T>& a)
|
||||
{
|
||||
std::stable_sort(a.begin(), a.end());
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Compare>
|
||||
void Foam::stableSort(UList<T>& a, const Compare& comp)
|
||||
{
|
||||
std::stable_sort(a.begin(), a.end(), comp);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::shuffle(UList<T>& a)
|
||||
{
|
||||
std::shuffle(a.begin(), a.end(), std::default_random_engine());
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -371,4 +336,41 @@ bool Foam::UList<T>::operator>=(const UList<T>& list) const
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
void Foam::sort(UList<T>& list)
|
||||
{
|
||||
std::sort(list.begin(), list.end());
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Compare>
|
||||
void Foam::sort(UList<T>& list, const Compare& comp)
|
||||
{
|
||||
std::sort(list.begin(), list.end(), comp);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::stableSort(UList<T>& list)
|
||||
{
|
||||
std::stable_sort(list.begin(), list.end());
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Compare>
|
||||
void Foam::stableSort(UList<T>& list, const Compare& comp)
|
||||
{
|
||||
std::stable_sort(list.begin(), list.end(), comp);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::shuffle(UList<T>& list)
|
||||
{
|
||||
std::shuffle(list.begin(), list.end(), std::default_random_engine());
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -74,6 +74,7 @@ class labelRange;
|
||||
template<class T> class List;
|
||||
template<class T> class SubList;
|
||||
template<class T> class UList;
|
||||
template<class T> class IndirectList;
|
||||
template<class T, class Addr> class IndirectListBase;
|
||||
|
||||
template<class T> Istream& operator>>(Istream&, UList<T>&);
|
||||
@ -510,9 +511,19 @@ public:
|
||||
|
||||
// Special Methods
|
||||
|
||||
//- A bitSet::test() method for a list of bool
|
||||
//
|
||||
// \return The element value, or false for out-of-range access
|
||||
//- Test \c bool value at specified position,
|
||||
//- always false for out-of-range access. Same as test().
|
||||
// \note Predicate definition as per bitSet, HashSet
|
||||
template<class TypeT = T>
|
||||
typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
|
||||
inline operator()(const label i) const
|
||||
{
|
||||
return (i >= 0 && i < size_ && v_[i]);
|
||||
}
|
||||
|
||||
//- Test \c bool value at specified position,
|
||||
//- always false for out-of-range access.
|
||||
// \note Method name compatibility with bitSet, HashSet
|
||||
template<class TypeT = T>
|
||||
typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
|
||||
inline test(const label i) const
|
||||
@ -520,9 +531,9 @@ public:
|
||||
return (i >= 0 && i < size_ && v_[i]);
|
||||
}
|
||||
|
||||
//- A bitSet::get() method for a list of bool
|
||||
//
|
||||
// \return The element value, or false for out-of-range access
|
||||
//- Return \c bool value at specified position,
|
||||
//- always false for out-of-range access.
|
||||
// \note Method name compatibility with bitSet
|
||||
template<class TypeT = T>
|
||||
typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
|
||||
inline get(const label i) const
|
||||
@ -530,9 +541,10 @@ public:
|
||||
return (i >= 0 && i < size_ && v_[i]);
|
||||
}
|
||||
|
||||
//- A bitSet::unset() method for a list of bool
|
||||
//
|
||||
//- Unset the \c bool entry at specified position,
|
||||
//- always false for out-of-range access.
|
||||
// \return True if value changed and was not out-of-range
|
||||
// \note Method name compatibility with bitSet
|
||||
template<class TypeT = T>
|
||||
typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
|
||||
inline unset(const label i)
|
||||
@ -624,26 +636,31 @@ Ostream& operator<<(Ostream& os, const std::vector<T>& list);
|
||||
|
||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||
|
||||
//- Sort the list
|
||||
template<class T>
|
||||
void sort(UList<T>& a);
|
||||
void sort(UList<T>& list);
|
||||
|
||||
//- Sort the list with the specified comparator
|
||||
template<class T, class Compare>
|
||||
void sort(UList<T>& a, const Compare& comp);
|
||||
void sort(UList<T>& list, const Compare& comp);
|
||||
|
||||
//- Stable sort the list
|
||||
template<class T>
|
||||
void stableSort(UList<T>& a);
|
||||
void stableSort(UList<T>& list);
|
||||
|
||||
//- Stable sort the list with the specified comparator
|
||||
template<class T, class Compare>
|
||||
void stableSort(UList<T>& a, const Compare& comp);
|
||||
void stableSort(UList<T>& list, const Compare& comp);
|
||||
|
||||
//- Randomise the list order
|
||||
template<class T>
|
||||
void shuffle(UList<T>& a);
|
||||
void shuffle(UList<T>& list);
|
||||
|
||||
// Reverse the first n elements of the list
|
||||
//- Reverse the first n elements of the list
|
||||
template<class T>
|
||||
inline void reverse(UList<T>& list, const label n);
|
||||
|
||||
// Reverse all the elements of the list
|
||||
//- Reverse all elements of the list
|
||||
template<class T>
|
||||
inline void reverse(UList<T>& list);
|
||||
|
||||
@ -448,7 +448,9 @@ inline void Foam::UList<T>::swap(UList<T>& list)
|
||||
template<class T>
|
||||
inline void Foam::reverse(UList<T>& list, const label n)
|
||||
{
|
||||
for (label i=0; i<n/2; ++i)
|
||||
const label nBy2 = n/2;
|
||||
|
||||
for (label i = 0; i < nBy2; ++i)
|
||||
{
|
||||
Foam::Swap(list[i], list[n-1-i]);
|
||||
}
|
||||
@ -458,7 +460,7 @@ inline void Foam::reverse(UList<T>& list, const label n)
|
||||
template<class T>
|
||||
inline void Foam::reverse(UList<T>& list)
|
||||
{
|
||||
reverse(list, list.size());
|
||||
Foam::reverse(list, list.size());
|
||||
}
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@ SourceFiles
|
||||
#include "FlatOutput.H"
|
||||
#include "labelPair.H"
|
||||
#include "labelList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "HashSet.H"
|
||||
#include "Map.H"
|
||||
#include "bitSet.H"
|
||||
@ -178,24 +179,6 @@ template<class Container>
|
||||
label inplaceMapValue(const Map<label>& mapper, Container& input);
|
||||
|
||||
|
||||
//- Return the (stable) sort order for the list
|
||||
template<class T>
|
||||
labelList sortedOrder(const UList<T>& input);
|
||||
|
||||
//- Generate the (stable) sort order for the list
|
||||
template<class T>
|
||||
void sortedOrder(const UList<T>& input, labelList& order);
|
||||
|
||||
//- Sort using specified list compare predicate
|
||||
template<class T, class ListComparePredicate>
|
||||
void sortedOrder
|
||||
(
|
||||
const UList<T>& input,
|
||||
labelList& order,
|
||||
const ListComparePredicate& comp
|
||||
);
|
||||
|
||||
|
||||
//- Return (sorted) indices corresponding to duplicate list values
|
||||
template<class T>
|
||||
labelList duplicateOrder(const UList<T>& input);
|
||||
@ -263,6 +246,7 @@ void inplaceUniqueSort
|
||||
// \endcode
|
||||
//
|
||||
// \return The subsetted list
|
||||
// \see IndirectList::subset
|
||||
template<class BoolListType, class T>
|
||||
List<T> subset
|
||||
(
|
||||
@ -278,6 +262,7 @@ List<T> subset
|
||||
// \param[in] invert set as true to invert the selection logic
|
||||
//
|
||||
// \return The subsetted list
|
||||
// \see IndirectList::subset
|
||||
template<class T>
|
||||
List<T> subset
|
||||
(
|
||||
@ -320,9 +305,12 @@ void inplaceSubset
|
||||
|
||||
//- Copy a subset of the input list when predicate is true.
|
||||
//
|
||||
// \param[in,out] input the list input values.
|
||||
// \param[in] input the list input values.
|
||||
// \param[in] pred the selection predicate
|
||||
// \param[in] invert set as true to invert the selection logic
|
||||
//
|
||||
// \return The subsetted list
|
||||
// \see IndirectList::subset_if
|
||||
template<class T, class UnaryPredicate>
|
||||
List<T> subsetList
|
||||
(
|
||||
|
||||
@ -321,46 +321,6 @@ Foam::label Foam::inplaceMapValue
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::labelList Foam::sortedOrder
|
||||
(
|
||||
const UList<T>& input
|
||||
)
|
||||
{
|
||||
labelList order;
|
||||
sortedOrder(input, order, typename UList<T>::less(input));
|
||||
return order;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::sortedOrder
|
||||
(
|
||||
const UList<T>& input,
|
||||
labelList& order
|
||||
)
|
||||
{
|
||||
sortedOrder(input, order, typename UList<T>::less(input));
|
||||
}
|
||||
|
||||
|
||||
template<class T, class ListComparePredicate>
|
||||
void Foam::sortedOrder
|
||||
(
|
||||
const UList<T>& input,
|
||||
labelList& order,
|
||||
const ListComparePredicate& comp
|
||||
)
|
||||
{
|
||||
// List lengths must be identical. Old content is overwritten
|
||||
order.resize_nocopy(input.size());
|
||||
|
||||
ListOps::identity(order);
|
||||
|
||||
Foam::stableSort(order, comp);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::labelList Foam::duplicateOrder
|
||||
(
|
||||
@ -398,7 +358,7 @@ void Foam::duplicateOrder
|
||||
return;
|
||||
}
|
||||
|
||||
sortedOrder(input, order, comp);
|
||||
Foam::sortedOrder(input, order, comp);
|
||||
|
||||
const label last = (order.size()-1);
|
||||
label count = 0;
|
||||
@ -445,7 +405,7 @@ void Foam::uniqueOrder
|
||||
const ListComparePredicate& comp
|
||||
)
|
||||
{
|
||||
sortedOrder(input, order, comp);
|
||||
Foam::sortedOrder(input, order, comp);
|
||||
|
||||
if (order.size() > 1)
|
||||
{
|
||||
|
||||
@ -26,7 +26,7 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ListOps.H"
|
||||
#include "ListOps.H" // For identity
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -50,6 +50,9 @@ Foam::label Foam::Detail::PtrListDetail<T>::count() const
|
||||
template<class T>
|
||||
Foam::label Foam::Detail::PtrListDetail<T>::findNull() const
|
||||
{
|
||||
// Same as List<T*>::find(nullptr);
|
||||
// except perhaps without pointer ambiguities...
|
||||
|
||||
label idx = 0;
|
||||
|
||||
for (const T* ptr : *this)
|
||||
|
||||
@ -42,8 +42,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef PtrListDetail_H
|
||||
#define PtrListDetail_H
|
||||
#ifndef Foam_PtrListDetail_H
|
||||
#define Foam_PtrListDetail_H
|
||||
|
||||
#include "List.H"
|
||||
|
||||
@ -92,9 +92,12 @@ public:
|
||||
//- Return the count of non-nullptr entries
|
||||
label count() const;
|
||||
|
||||
//- Locate the first null entry, -1 if there are not any
|
||||
//- Locate the first null entry, -1 if there are none (or empty list)
|
||||
label findNull() const;
|
||||
|
||||
//- FatalError if any null exists in the list
|
||||
inline void checkNonNull() const;
|
||||
|
||||
//- Assign all pointers to nullptr, without deleting.
|
||||
void setNull();
|
||||
|
||||
|
||||
@ -109,6 +109,20 @@ inline void Foam::Detail::PtrListDetail<T>::resize(const label newLen)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::Detail::PtrListDetail<T>::checkNonNull() const
|
||||
{
|
||||
const label idx = this->findNull();
|
||||
|
||||
if (idx >= 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Element " << idx << " is null" << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -40,8 +40,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef PtrListOps_H
|
||||
#define PtrListOps_H
|
||||
#ifndef Foam_PtrListOps_H
|
||||
#define Foam_PtrListOps_H
|
||||
|
||||
#include "predicates.H"
|
||||
#include "PtrList.H"
|
||||
@ -54,31 +54,23 @@ namespace Foam
|
||||
|
||||
//- Return (stable) sort order for the list
|
||||
template<class T>
|
||||
labelList sortedOrder(const UPtrList<T>& input);
|
||||
labelList sortedOrder(const UPtrList<T>& list);
|
||||
|
||||
//- Generate (stable) sort order for the list
|
||||
template<class T>
|
||||
void sortedOrder(const UPtrList<T>& input, labelList& order);
|
||||
void sortedOrder(const UPtrList<T>& list, labelList& order);
|
||||
|
||||
//- Generate (stable) sort order for the list,
|
||||
//- using the specified list compare predicate
|
||||
template<class T, class ListComparePredicate>
|
||||
void sortedOrder
|
||||
(
|
||||
const UPtrList<T>& input,
|
||||
const UPtrList<T>& list,
|
||||
labelList& order,
|
||||
const ListComparePredicate& comp
|
||||
);
|
||||
|
||||
|
||||
//- Inplace (stable) sorting of pointer list.
|
||||
template<class T>
|
||||
void sort(UPtrList<T>& list);
|
||||
|
||||
//- Inplace (stable) sorting of pointer list.
|
||||
template<class T, class Compare>
|
||||
void sort(UPtrList<T>& list, const Compare& comp);
|
||||
|
||||
//- Inplace shuffle of pointer list.
|
||||
template<class T>
|
||||
void shuffle(UPtrList<T>& list);
|
||||
@ -91,52 +83,6 @@ void shuffle(UPtrList<T>& list);
|
||||
namespace PtrListOps
|
||||
{
|
||||
|
||||
// Public Classes
|
||||
|
||||
//- A UPtrList compare binary predicate for normal sort.
|
||||
// Null entries sort to the end
|
||||
template<class T>
|
||||
struct less
|
||||
{
|
||||
const UPtrList<T>& values;
|
||||
|
||||
less(const UPtrList<T>& list)
|
||||
:
|
||||
values(list)
|
||||
{}
|
||||
|
||||
bool operator()(const label a, const label b) const
|
||||
{
|
||||
const T* const ptr1 = values(a);
|
||||
const T* const ptr2 = values(b);
|
||||
|
||||
return (ptr1 && ptr2) ? (*ptr1 < *ptr2) : !ptr2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- A UPtrList compare binary predicate for reverse sort.
|
||||
// Null entries sort to the end
|
||||
template<class T>
|
||||
struct greater
|
||||
{
|
||||
const UPtrList<T>& values;
|
||||
|
||||
greater(const UPtrList<T>& list)
|
||||
:
|
||||
values(list)
|
||||
{}
|
||||
|
||||
bool operator()(const label a, const label b) const
|
||||
{
|
||||
const T* const ptr1 = values(a);
|
||||
const T* const ptr2 = values(b);
|
||||
|
||||
return (ptr1 && ptr2) ? (*ptr2 < *ptr1) : !ptr2;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- List of values generated by applying the access operation
|
||||
//- to each list item.
|
||||
//
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -32,11 +32,11 @@ License
|
||||
template<class T>
|
||||
Foam::labelList Foam::sortedOrder
|
||||
(
|
||||
const UPtrList<T>& input
|
||||
const UPtrList<T>& list
|
||||
)
|
||||
{
|
||||
labelList order;
|
||||
sortedOrder(input, order, typename PtrListOps::less<T>(input));
|
||||
Foam::sortedOrder(list, order, typename UPtrList<T>::less(list));
|
||||
return order;
|
||||
}
|
||||
|
||||
@ -44,59 +44,49 @@ Foam::labelList Foam::sortedOrder
|
||||
template<class T>
|
||||
void Foam::sortedOrder
|
||||
(
|
||||
const UPtrList<T>& input,
|
||||
const UPtrList<T>& list,
|
||||
labelList& order
|
||||
)
|
||||
{
|
||||
sortedOrder(input, order, typename PtrListOps::less<T>(input));
|
||||
Foam::sortedOrder(list, order, typename UPtrList<T>::less(list));
|
||||
}
|
||||
|
||||
|
||||
template<class T, class ListComparePredicate>
|
||||
void Foam::sortedOrder
|
||||
(
|
||||
const UPtrList<T>& input,
|
||||
const UPtrList<T>& list,
|
||||
labelList& order,
|
||||
const ListComparePredicate& comp
|
||||
)
|
||||
{
|
||||
// List lengths must be identical. Old content is overwritten
|
||||
order.resize_nocopy(input.size());
|
||||
order.resize_nocopy(list.size());
|
||||
|
||||
ListOps::identity(order);
|
||||
// Same as std::iota and ListOps::identity
|
||||
label value = 0;
|
||||
for (label& item : order)
|
||||
{
|
||||
item = value;
|
||||
++value;
|
||||
}
|
||||
|
||||
Foam::stableSort(order, comp);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::sort(UPtrList<T>& list)
|
||||
{
|
||||
labelList order;
|
||||
sortedOrder(list, order);
|
||||
list.sortOrder(order, false); // false = allow nullptr
|
||||
}
|
||||
|
||||
|
||||
template<class T, class Compare>
|
||||
void Foam::sort(UPtrList<T>& list, const Compare& comp)
|
||||
{
|
||||
labelList order;
|
||||
sortedOrder(list, order, comp);
|
||||
list.sortOrder(order, false); // false = allow nullptr
|
||||
std::stable_sort(order.begin(), order.end(), comp);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::shuffle(UPtrList<T>& list)
|
||||
{
|
||||
// Cannot use std::shuffle directly since that would dereference
|
||||
// the list entries, which may contain null pointers.
|
||||
// The alternative would be to expose the pointer details (a bit ugly).
|
||||
labelList order(identity(list.size()));
|
||||
Foam::shuffle(order);
|
||||
list.sortOrder(order, false); // false = allow nullptr
|
||||
list.sortOrder(order, false); // false = no nullptr check
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Templated implementation for types(), names(), etc - file-scope
|
||||
template<class ReturnType, class T, class AccessOp>
|
||||
Foam::List<ReturnType> Foam::PtrListOps::get
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2015-2019 OpenCFD Ltd.
|
||||
Copyright (C) 2015-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -66,11 +66,7 @@ Foam::label Foam::UPtrList<T>::squeezeNull()
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::UPtrList<T>::reorder
|
||||
(
|
||||
const labelUList& oldToNew,
|
||||
const bool testNull
|
||||
)
|
||||
void Foam::UPtrList<T>::reorder(const labelUList& oldToNew, const bool check)
|
||||
{
|
||||
const label len = this->size();
|
||||
|
||||
@ -87,37 +83,31 @@ void Foam::UPtrList<T>::reorder
|
||||
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
const label idx = oldToNew[i];
|
||||
const label newIdx = oldToNew[i];
|
||||
|
||||
if (idx < 0 || idx >= len)
|
||||
if (newIdx < 0 || newIdx >= len)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Illegal index " << idx << nl
|
||||
<< "Illegal index " << newIdx << nl
|
||||
<< "Valid indices are [0," << len << ") for type "
|
||||
<< typeid(T).name() << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (newList[idx])
|
||||
if (newList[newIdx])
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "reorder map is not unique; element " << idx
|
||||
<< "reorder map is not unique; element " << newIdx
|
||||
<< " already used for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
newList[idx] = ptrs_[i];
|
||||
newList[newIdx] = ptrs_[i];
|
||||
}
|
||||
|
||||
// Verify that all pointers were indeed set
|
||||
if (testNull)
|
||||
// Verify all pointers were indeed set
|
||||
if (check)
|
||||
{
|
||||
const label idx = newList.findNull();
|
||||
if (idx >= 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Element " << idx << " not set after reordering." << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
newList.checkNonNull();
|
||||
}
|
||||
|
||||
ptrs_.transfer(newList);
|
||||
@ -125,11 +115,7 @@ void Foam::UPtrList<T>::reorder
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::UPtrList<T>::sortOrder
|
||||
(
|
||||
const labelUList& order,
|
||||
const bool testNull
|
||||
)
|
||||
void Foam::UPtrList<T>::sortOrder(const labelUList& order, const bool check)
|
||||
{
|
||||
const label len = this->size();
|
||||
|
||||
@ -147,39 +133,33 @@ void Foam::UPtrList<T>::sortOrder
|
||||
|
||||
for (label i=0; i<len; ++i)
|
||||
{
|
||||
const label idx = order[i];
|
||||
const label oldIdx = order[i];
|
||||
|
||||
if (idx < 0 || idx >= len)
|
||||
if (oldIdx < 0 || oldIdx >= len)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Illegal index " << idx << nl
|
||||
<< "Illegal index " << oldIdx << nl
|
||||
<< "Valid indices are [0," << len << ") for type "
|
||||
<< typeid(T).name() << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
if (guard[idx])
|
||||
if (guard[oldIdx])
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "order map is not unique; element " << idx
|
||||
<< "order map is not unique; element " << oldIdx
|
||||
<< " already used for type " << typeid(T).name()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
guard[idx] = ptrs_[idx];
|
||||
newList[i] = ptrs_[idx];
|
||||
guard[oldIdx] = ptrs_[oldIdx];
|
||||
newList[i] = ptrs_[oldIdx];
|
||||
}
|
||||
|
||||
// Verify that all pointers were indeed set
|
||||
if (testNull)
|
||||
if (check)
|
||||
{
|
||||
const label idx = newList.findNull();
|
||||
if (idx >= 0)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Element " << idx << " not set after reordering." << nl
|
||||
<< abort(FatalError);
|
||||
}
|
||||
newList.checkNonNull();
|
||||
}
|
||||
|
||||
ptrs_.transfer(newList);
|
||||
@ -195,4 +175,26 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const UPtrList<T>& list)
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T, class Compare>
|
||||
void Foam::sort(UPtrList<T>& list, const Compare& comp)
|
||||
{
|
||||
std::stable_sort
|
||||
(
|
||||
list.begin_ptr(),
|
||||
list.end_ptr(),
|
||||
typename UPtrList<T>::template value_compare<Compare>(comp)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
void Foam::sort(UPtrList<T>& list)
|
||||
{
|
||||
// ie, lessOp<T>() or std::less<T>()
|
||||
Foam::sort(list, [](const T& a, const T& b) { return (a < b); });
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -110,6 +110,72 @@ public:
|
||||
class const_iterator;
|
||||
|
||||
|
||||
// Public Classes
|
||||
|
||||
//- A wrapper for a binary comparison of values that interjects
|
||||
//- pointer dereferencing with null pointer guards.
|
||||
// It will also sort any null pointers to the end
|
||||
// (eg, rubbish that can be truncated)
|
||||
template<class Compare>
|
||||
struct value_compare
|
||||
{
|
||||
const Compare& comp;
|
||||
|
||||
value_compare(const Compare& cmp)
|
||||
:
|
||||
comp(cmp)
|
||||
{}
|
||||
|
||||
//- Compare dereferenced pointers
|
||||
bool operator()(const T* const a, const T* const b) const
|
||||
{
|
||||
return (a && b) ? comp(*a, *b) : bool(a);
|
||||
}
|
||||
};
|
||||
|
||||
//- A UPtrList compare binary predicate for normal sort order.
|
||||
//- Null entries (if any) sort to the end.
|
||||
struct less
|
||||
{
|
||||
const UPtrList<T>& values;
|
||||
|
||||
less(const UPtrList<T>& list)
|
||||
:
|
||||
values(list)
|
||||
{}
|
||||
|
||||
//- Compare dereferenced pointer locations for normal sort.
|
||||
bool operator()(const label ai, const label bi) const
|
||||
{
|
||||
const T* const a = values.get(ai);
|
||||
const T* const b = values.get(bi);
|
||||
|
||||
return (a && b) ? (*a < *b) : bool(a);
|
||||
}
|
||||
};
|
||||
|
||||
//- A UPtrList compare binary predicate for reverse sort order.
|
||||
// Null entries (if any) sort to the end.
|
||||
struct greater
|
||||
{
|
||||
const UPtrList<T>& values;
|
||||
|
||||
greater(const UPtrList<T>& list)
|
||||
:
|
||||
values(list)
|
||||
{}
|
||||
|
||||
//- Compare dereferenced pointer locations for reverse sort
|
||||
bool operator()(const label ai, const label bi) const
|
||||
{
|
||||
const T* const a = values.get(ai);
|
||||
const T* const b = values.get(bi);
|
||||
|
||||
return (a && b) ? (*b < *a) : bool(b);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Default construct
|
||||
@ -215,13 +281,19 @@ public:
|
||||
|
||||
//- Reorder elements.
|
||||
//- Reordering must be unique (ie, shuffle).
|
||||
// Optionally verify that all pointers have been set.
|
||||
void reorder(const labelUList& oldToNew, const bool testNull = true);
|
||||
// Optionally check that all pointers have been set.
|
||||
void reorder(const labelUList& oldToNew, const bool check = false);
|
||||
|
||||
//- Reorder elements according to new order mapping (newToOld).
|
||||
//- Reordering must be unique (ie, shuffle).
|
||||
// Optionally verify that all pointers have been set.
|
||||
void sortOrder(const labelUList& order, const bool testNull = true);
|
||||
// Optionally check that all pointers have been set.
|
||||
void sortOrder(const labelUList& order, const bool check = false);
|
||||
|
||||
|
||||
// Checks
|
||||
|
||||
//- Check and raise FatalError if any nullptr exists in the list
|
||||
inline void checkNonNull() const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
@ -362,22 +434,29 @@ public:
|
||||
};
|
||||
|
||||
|
||||
//- Return an iterator to begin traversing the UPtrList
|
||||
//- Iterator to begin of raw pointers traversal (use with caution)
|
||||
T** begin_ptr() noexcept { return ptrs_.begin(); }
|
||||
|
||||
//- Iterator beyond end of raw pointers traversal (use with caution)
|
||||
T** end_ptr() noexcept { return ptrs_.end(); }
|
||||
|
||||
|
||||
//- Return an iterator to begin of UPtrList traversal
|
||||
inline iterator begin() noexcept;
|
||||
|
||||
//- Return an iterator to end traversing the UPtrList
|
||||
//- Return iterator beyond end of UPtrList traversal
|
||||
inline iterator end() noexcept;
|
||||
|
||||
//- Return an const_iterator to begin traversing the UPtrList
|
||||
//- Return const_iterator to begin of UPtrList traversal
|
||||
inline const_iterator cbegin() const noexcept;
|
||||
|
||||
//- Return an const_iterator to end traversing the UPtrList
|
||||
//- Return const_iterator beyond end of UPtrList traversal
|
||||
inline const_iterator cend() const noexcept;
|
||||
|
||||
//- Return an const_iterator to begin traversing the UPtrList
|
||||
//- Return const_iterator to begin of UPtrList traversal
|
||||
inline const_iterator begin() const noexcept;
|
||||
|
||||
//- Return an const_iterator to end traversing the UPtrList
|
||||
//- Return const_iterator beyond end of UPtrList traversal
|
||||
inline const_iterator end() const noexcept;
|
||||
|
||||
|
||||
@ -392,6 +471,20 @@ public:
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||
|
||||
//- Inplace (stable) sorting of pointer list.
|
||||
template<class T>
|
||||
void sort(UPtrList<T>& list);
|
||||
|
||||
//- Inplace (stable) sorting of pointer list using given comparator,
|
||||
//- which compares objects, not pointers.
|
||||
// This sort function includes null pointer guards and will also sort
|
||||
// any null pointers to the end (eg, rubbish that can be truncated)
|
||||
template<class T, class Compare>
|
||||
void sort(UPtrList<T>& list, const Compare& comp);
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -215,6 +215,13 @@ inline T* Foam::UPtrList<T>::set(const label i, T* ptr)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline void Foam::UPtrList<T>::checkNonNull() const
|
||||
{
|
||||
ptrs_.checkNonNull();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
|
||||
@ -167,12 +167,33 @@ Foam::IOField<Type>::IOField(const IOobject& io, const tmp<Field<Type>>& tfld)
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
Foam::IOFieldRef<Type>::IOFieldRef
|
||||
(
|
||||
const IOobject& io,
|
||||
const Field<Type>& content
|
||||
)
|
||||
:
|
||||
regIOobject(io),
|
||||
contentRef_(content) // cref
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
bool Foam::IOField<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
return (os << static_cast<const Field<Type>&>(*this)).good();
|
||||
os << static_cast<const Field<Type>&>(*this);
|
||||
return os.good();
|
||||
}
|
||||
|
||||
|
||||
template<class Type>
|
||||
bool Foam::IOFieldRef<Type>::writeData(Ostream& os) const
|
||||
{
|
||||
os << contentRef_.cref();
|
||||
return os.good();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -38,8 +38,9 @@ SourceFiles
|
||||
#ifndef Foam_IOField_H
|
||||
#define Foam_IOField_H
|
||||
|
||||
#include "regIOobject.H"
|
||||
#include "Field.H"
|
||||
#include "regIOobject.H"
|
||||
#include "refPtr.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -100,7 +101,8 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
bool writeData(Ostream& os) const;
|
||||
//- The writeData method for regIOobject write operation
|
||||
virtual bool writeData(Ostream& os) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
@ -113,6 +115,72 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class IOFieldRef Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- A IOField wrapper for writing external data.
|
||||
template<class Type>
|
||||
class IOFieldRef
|
||||
:
|
||||
public regIOobject
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- Reference to the external content
|
||||
refPtr<Field<Type>> contentRef_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- The underlying content type
|
||||
typedef Field<Type> content_type;
|
||||
|
||||
|
||||
//- Type is identical to IOField
|
||||
virtual const word& type() const
|
||||
{
|
||||
return IOField<Type>::typeName;
|
||||
}
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No default construct
|
||||
IOFieldRef() = delete;
|
||||
|
||||
//- No copy construct
|
||||
IOFieldRef(const IOFieldRef&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const IOFieldRef&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from IOobject and const data reference
|
||||
IOFieldRef(const IOobject& io, const Field<Type>& content);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~IOFieldRef() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Allow cast to const content
|
||||
// Fatal if content is not set
|
||||
operator const Field<Type>&() const
|
||||
{
|
||||
return contentRef_.cref();
|
||||
}
|
||||
|
||||
//- The writeData method for regIOobject write operation
|
||||
// Fatal if content is not set
|
||||
virtual bool writeData(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -109,12 +109,33 @@ Foam::IOList<T>::IOList(const IOobject& io, List<T>&& content)
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
Foam::IOListRef<T>::IOListRef
|
||||
(
|
||||
const IOobject& io,
|
||||
const List<T>& content
|
||||
)
|
||||
:
|
||||
regIOobject(io),
|
||||
contentRef_(content)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
bool Foam::IOList<T>::writeData(Ostream& os) const
|
||||
{
|
||||
return (os << *this).good();
|
||||
os << static_cast<const List<T>&>(*this);
|
||||
return os.good();
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
bool Foam::IOListRef<T>::writeData(Ostream& os) const
|
||||
{
|
||||
os << contentRef_.cref();
|
||||
return os.good();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -40,6 +40,7 @@ SourceFiles
|
||||
|
||||
#include "List.H"
|
||||
#include "regIOobject.H"
|
||||
#include "refPtr.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -94,7 +95,8 @@ public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
bool writeData(Ostream& os) const;
|
||||
//- The writeData method for regIOobject write operation
|
||||
virtual bool writeData(Ostream& os) const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
@ -107,6 +109,72 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class IOListRef Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- A IOList wrapper for writing external data.
|
||||
template<class T>
|
||||
class IOListRef
|
||||
:
|
||||
public regIOobject
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- Reference to the external content
|
||||
refPtr<List<T>> contentRef_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//- The underlying content type
|
||||
typedef List<T> content_type;
|
||||
|
||||
|
||||
//- Type is identical to IOList
|
||||
virtual const word& type() const
|
||||
{
|
||||
return IOList<T>::typeName;
|
||||
}
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No default construct
|
||||
IOListRef() = delete;
|
||||
|
||||
//- No copy construct
|
||||
IOListRef(const IOListRef&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const IOListRef&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from IOobject and const data reference
|
||||
IOListRef(const IOobject& io, const List<T>& content);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~IOListRef() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Allow cast to const content
|
||||
// Fatal if content is not set
|
||||
operator const List<T>&() const
|
||||
{
|
||||
return contentRef_.cref();
|
||||
}
|
||||
|
||||
//- The writeData method for regIOobject write operation
|
||||
// Fatal if content is not set
|
||||
virtual bool writeData(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -106,7 +106,8 @@ Foam::IOMap<T>::IOMap(const IOobject& io, Map<T>&& content)
|
||||
template<class T>
|
||||
bool Foam::IOMap<T>::writeData(Ostream& os) const
|
||||
{
|
||||
return (os << *this).good();
|
||||
os << *this;
|
||||
return os.good();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -32,8 +32,8 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef lduSchedule_H
|
||||
#define lduSchedule_H
|
||||
#ifndef Foam_lduSchedule_H
|
||||
#define Foam_lduSchedule_H
|
||||
|
||||
#include "List.H"
|
||||
|
||||
@ -42,14 +42,17 @@ Description
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward Declarations
|
||||
|
||||
struct lduScheduleEntry;
|
||||
Ostream& operator<<(Ostream& os, const lduScheduleEntry& lb);
|
||||
|
||||
//- A List of lduSchedule entries.
|
||||
typedef List<lduScheduleEntry> lduSchedule;
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class lduSchedule Declaration
|
||||
Class lduScheduleEntry Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
struct lduScheduleEntry
|
||||
@ -57,11 +60,22 @@ struct lduScheduleEntry
|
||||
label patch;
|
||||
bool init;
|
||||
|
||||
friend bool operator!=
|
||||
(
|
||||
const lduScheduleEntry& lb1,
|
||||
const lduScheduleEntry& lb2
|
||||
)
|
||||
//- Define patch for initEvaluate()
|
||||
void setInitEvaluate(const label patchi) noexcept
|
||||
{
|
||||
patch = patchi;
|
||||
init = true;
|
||||
}
|
||||
|
||||
//- Define patch for evaluate()
|
||||
void setEvaluate(const label patchi) noexcept
|
||||
{
|
||||
patch = patchi;
|
||||
init = false;
|
||||
}
|
||||
|
||||
//- Always unequal: each entry is supposed to be unique!
|
||||
friend bool operator!=(const lduScheduleEntry&, const lduScheduleEntry&)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -74,9 +88,6 @@ struct lduScheduleEntry
|
||||
};
|
||||
|
||||
|
||||
typedef List<lduScheduleEntry> lduSchedule;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -1,273 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ProcessorTopology.H"
|
||||
#include "ListOps.H"
|
||||
#include "Pstream.H"
|
||||
#include "commSchedule.H"
|
||||
|
||||
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
|
||||
|
||||
template<class Container, class ProcPatch>
|
||||
Foam::labelList Foam::ProcessorTopology<Container, ProcPatch>::procNeighbours
|
||||
(
|
||||
const label nProcs,
|
||||
const Container& patches
|
||||
)
|
||||
{
|
||||
// Determine number of processor neighbours and max neighbour id.
|
||||
|
||||
label nNeighbours = 0;
|
||||
|
||||
label maxNb = 0;
|
||||
|
||||
boolList isNeighbourProc(nProcs, false);
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
const auto* cpp = isA<ProcPatch>(patches[patchi]);
|
||||
if (cpp)
|
||||
{
|
||||
const label nbrProci = cpp->neighbProcNo();
|
||||
|
||||
if (!isNeighbourProc[nbrProci])
|
||||
{
|
||||
isNeighbourProc[nbrProci] = true;
|
||||
maxNb = max(maxNb, nbrProci);
|
||||
++nNeighbours;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
labelList neighbours(nNeighbours, -1);
|
||||
|
||||
nNeighbours = 0;
|
||||
|
||||
forAll(isNeighbourProc, proci)
|
||||
{
|
||||
if (isNeighbourProc[proci])
|
||||
{
|
||||
neighbours[nNeighbours++] = proci;
|
||||
}
|
||||
}
|
||||
|
||||
procPatchMap_.setSize(maxNb + 1);
|
||||
procPatchMap_ = -1;
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
const auto* cpp = isA<ProcPatch>(patches[patchi]);
|
||||
if (cpp)
|
||||
{
|
||||
const label nbrProci = cpp->neighbProcNo();
|
||||
|
||||
// Reverse map
|
||||
procPatchMap_[nbrProci] = patchi;
|
||||
}
|
||||
}
|
||||
|
||||
return neighbours;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class Container, class ProcPatch>
|
||||
Foam::ProcessorTopology<Container, ProcPatch>::ProcessorTopology
|
||||
(
|
||||
const Container& patches,
|
||||
const label comm
|
||||
)
|
||||
:
|
||||
labelListList(Pstream::nProcs(comm)),
|
||||
patchSchedule_()
|
||||
{
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
// Fill my 'slot' with my neighbours
|
||||
operator[](Pstream::myProcNo(comm)) =
|
||||
procNeighbours(this->size(), patches);
|
||||
|
||||
// Distribute to all processors
|
||||
Pstream::allGatherList(*this, Pstream::msgType(), comm);
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
Pstream::parRun()
|
||||
&& Pstream::defaultCommsType == Pstream::commsTypes::scheduled
|
||||
)
|
||||
{
|
||||
patchSchedule_.resize(2*patches.size());
|
||||
|
||||
label patchEvali = 0;
|
||||
|
||||
// 1. All non-processor patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (!isA<ProcPatch>(patches[patchi]))
|
||||
{
|
||||
patchSchedule_[patchEvali].patch = patchi;
|
||||
patchSchedule_[patchEvali++].init = true;
|
||||
patchSchedule_[patchEvali].patch = patchi;
|
||||
patchSchedule_[patchEvali++].init = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. All processor patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
// Determine the schedule for all. Insert processor pair once
|
||||
// to determine the schedule. Each processor pair stands for both
|
||||
// send and receive.
|
||||
label nComms = 0;
|
||||
for (const labelList& neighbours : *this)
|
||||
{
|
||||
nComms += neighbours.size();
|
||||
}
|
||||
DynamicList<labelPair> comms(nComms);
|
||||
|
||||
forAll(*this, proci)
|
||||
{
|
||||
const labelList& neighbours = operator[](proci);
|
||||
|
||||
for (const label nbrProci : neighbours)
|
||||
{
|
||||
if (proci < nbrProci)
|
||||
{
|
||||
comms.append(labelPair(proci, nbrProci));
|
||||
}
|
||||
}
|
||||
}
|
||||
comms.shrink();
|
||||
|
||||
// Determine a schedule.
|
||||
labelList mySchedule
|
||||
(
|
||||
commSchedule
|
||||
(
|
||||
Pstream::nProcs(comm),
|
||||
comms
|
||||
).procSchedule()[Pstream::myProcNo(comm)]
|
||||
);
|
||||
|
||||
for (const label commI : mySchedule)
|
||||
{
|
||||
// Get the other processor
|
||||
label nb = comms[commI][0];
|
||||
if (nb == Pstream::myProcNo(comm))
|
||||
{
|
||||
nb = comms[commI][1];
|
||||
}
|
||||
label patchi = procPatchMap_[nb];
|
||||
|
||||
if (Pstream::myProcNo(comm) > nb)
|
||||
{
|
||||
patchSchedule_[patchEvali].patch = patchi;
|
||||
patchSchedule_[patchEvali++].init = true;
|
||||
patchSchedule_[patchEvali].patch = patchi;
|
||||
patchSchedule_[patchEvali++].init = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
patchSchedule_[patchEvali].patch = patchi;
|
||||
patchSchedule_[patchEvali++].init = false;
|
||||
patchSchedule_[patchEvali].patch = patchi;
|
||||
patchSchedule_[patchEvali++].init = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
patchSchedule_ = nonBlockingSchedule(patches);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Container, class ProcPatch>
|
||||
Foam::lduSchedule
|
||||
Foam::ProcessorTopology<Container, ProcPatch>::nonBlockingSchedule
|
||||
(
|
||||
const Container& patches
|
||||
)
|
||||
{
|
||||
lduSchedule patchSchedule(2*patches.size());
|
||||
|
||||
label patchEvali = 0;
|
||||
|
||||
// 1. All non-processor patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
// Have evaluate directly after initEvaluate. Could have them separated
|
||||
// as long as they're not intermingled with processor patches since
|
||||
// then e.g. any reduce parallel traffic would interfere with the
|
||||
// processor swaps.
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (!isA<ProcPatch>(patches[patchi]))
|
||||
{
|
||||
patchSchedule[patchEvali].patch = patchi;
|
||||
patchSchedule[patchEvali++].init = true;
|
||||
patchSchedule[patchEvali].patch = patchi;
|
||||
patchSchedule[patchEvali++].init = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. All processor patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
// 2a. initEvaluate
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (isA<ProcPatch>(patches[patchi]))
|
||||
{
|
||||
patchSchedule[patchEvali].patch = patchi;
|
||||
patchSchedule[patchEvali++].init = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 2b. evaluate
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (isA<ProcPatch>(patches[patchi]))
|
||||
{
|
||||
patchSchedule[patchEvali].patch = patchi;
|
||||
patchSchedule[patchEvali++].init = false;
|
||||
}
|
||||
}
|
||||
|
||||
return patchSchedule;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -1,126 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::ProcessorTopology
|
||||
|
||||
Description
|
||||
Determines processor-processor connection. After instantiation contains
|
||||
on all processors the processor-processor connection table.
|
||||
|
||||
*this[proci] gives the list of neighbouring processors.
|
||||
|
||||
TODO: This does not currently correctly support multiple processor
|
||||
patches connecting two processors.
|
||||
|
||||
SourceFiles
|
||||
ProcessorTopology.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Foam_ProcessorTopology_H
|
||||
#define Foam_ProcessorTopology_H
|
||||
|
||||
#include "labelList.H"
|
||||
#include "lduSchedule.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class ProcessorTopology Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
template<class Container, class ProcPatch>
|
||||
class ProcessorTopology
|
||||
:
|
||||
public labelListList
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- Local map from neighbour proc to patchi. Different per processor!
|
||||
// -1 or patchi for connection to procID
|
||||
labelList procPatchMap_;
|
||||
|
||||
//- Order in which the patches should be initialised/evaluated
|
||||
// corresponding to the schedule
|
||||
lduSchedule patchSchedule_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Return all neighbouring processors of this processor.
|
||||
// Sets procPatchMap_.
|
||||
labelList procNeighbours(const label nProcs, const Container&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from boundaryMesh
|
||||
ProcessorTopology(const Container& patches, const label comm);
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Calculate non-blocking (i.e. unscheduled) schedule
|
||||
static lduSchedule nonBlockingSchedule(const Container& patches);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- From neighbour processor to index in boundaryMesh.
|
||||
// Local information (so not same over all processors)
|
||||
const labelList& procPatchMap() const noexcept
|
||||
{
|
||||
return procPatchMap_;
|
||||
}
|
||||
|
||||
//- Order in which the patches should be initialised/evaluated
|
||||
//- corresponding to the schedule
|
||||
const lduSchedule& patchSchedule() const noexcept
|
||||
{
|
||||
return patchSchedule_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#ifdef NoRepository
|
||||
#include "ProcessorTopology.C"
|
||||
#endif
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -31,7 +31,6 @@ License
|
||||
#include "CircularBuffer.H"
|
||||
#include "CompactListList.H"
|
||||
#include "DynamicList.H"
|
||||
#include "ListOps.H" // sortedOrder
|
||||
#include "IOstreams.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2013 OpenFOAM Foundation
|
||||
Copyright (C) 2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -36,38 +37,37 @@ Foam::lduSchedule Foam::lduPrimitiveMesh::nonBlockingSchedule
|
||||
)
|
||||
{
|
||||
lduSchedule schedule(2*interfaces.size());
|
||||
label slotI = 0;
|
||||
|
||||
forAll(interfaces, i)
|
||||
// 1. All non-processor patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
label patchEvali = 0;
|
||||
|
||||
forAll(interfaces, patchi)
|
||||
{
|
||||
if (interfaces.set(i) && !isA<ProcPatch>(interfaces[i]))
|
||||
if (interfaces.set(patchi) && !isA<ProcPatch>(interfaces[patchi]))
|
||||
{
|
||||
schedule[slotI].patch = i;
|
||||
schedule[slotI].init = true;
|
||||
slotI++;
|
||||
schedule[slotI].patch = i;
|
||||
schedule[slotI].init = false;
|
||||
slotI++;
|
||||
schedule[patchEvali++].setInitEvaluate(patchi);
|
||||
schedule[patchEvali++].setEvaluate(patchi);
|
||||
}
|
||||
}
|
||||
|
||||
forAll(interfaces, i)
|
||||
// 2. All processor patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
forAll(interfaces, patchi)
|
||||
{
|
||||
if (interfaces.set(i) && isA<ProcPatch>(interfaces[i]))
|
||||
if (interfaces.set(patchi) && isA<ProcPatch>(interfaces[patchi]))
|
||||
{
|
||||
schedule[slotI].patch = i;
|
||||
schedule[slotI].init = true;
|
||||
slotI++;
|
||||
schedule[patchEvali++].setInitEvaluate(patchi);
|
||||
}
|
||||
}
|
||||
|
||||
forAll(interfaces, i)
|
||||
forAll(interfaces, patchi)
|
||||
{
|
||||
if (interfaces.set(i) && isA<ProcPatch>(interfaces[i]))
|
||||
if (interfaces.set(patchi) && isA<ProcPatch>(interfaces[patchi]))
|
||||
{
|
||||
schedule[slotI].patch = i;
|
||||
schedule[slotI].init = false;
|
||||
slotI++;
|
||||
schedule[patchEvali++].setEvaluate(patchi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -37,13 +37,12 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef cellIndList_H
|
||||
#define cellIndList_H
|
||||
#ifndef Foam_cellIndList_H
|
||||
#define Foam_cellIndList_H
|
||||
|
||||
// Include all normal list typedefs as well
|
||||
#include "cellList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "UIndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ License
|
||||
#include "Istream.H"
|
||||
#include "cell.H"
|
||||
#include "cellModel.H"
|
||||
#include "UIndirectList.H"
|
||||
#include "IndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -37,13 +37,12 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef edgeIndList_H
|
||||
#define edgeIndList_H
|
||||
#ifndef Foam_edgeIndList_H
|
||||
#define Foam_edgeIndList_H
|
||||
|
||||
// Include all normal list typedefs as well
|
||||
#include "edgeList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "UIndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -37,13 +37,12 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef faceIndList_H
|
||||
#define faceIndList_H
|
||||
#ifndef Foam_faceIndList_H
|
||||
#define Foam_faceIndList_H
|
||||
|
||||
// Include all normal list typedefs as well
|
||||
#include "faceList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "UIndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -30,7 +30,7 @@ License
|
||||
#include "addToRunTimeSelectionTable.H"
|
||||
#include "pointMesh.H"
|
||||
#include "faceList.H"
|
||||
#include "primitiveFacePatch.H"
|
||||
#include "primitivePatch.H"
|
||||
#include "emptyPolyPatch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -27,14 +27,15 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "globalMeshData.H"
|
||||
#include "Pstream.H"
|
||||
#include "processorPolyPatch.H"
|
||||
#include "globalPoints.H"
|
||||
#include "polyMesh.H"
|
||||
#include "mapDistribute.H"
|
||||
#include "labelIOList.H"
|
||||
#include "mergePoints.H"
|
||||
#include "processorPolyPatch.H"
|
||||
#include "processorTopologyNew.H"
|
||||
#include "globalIndexAndTransform.H"
|
||||
#include "Pstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
@ -61,15 +62,15 @@ public:
|
||||
|
||||
void Foam::globalMeshData::initProcAddr()
|
||||
{
|
||||
processorPatchIndices_.setSize(mesh_.boundaryMesh().size());
|
||||
processorPatchIndices_.resize_nocopy(mesh_.boundaryMesh().size());
|
||||
processorPatchIndices_ = -1;
|
||||
|
||||
processorPatchNeighbours_.setSize(mesh_.boundaryMesh().size());
|
||||
processorPatchNeighbours_.resize_nocopy(mesh_.boundaryMesh().size());
|
||||
processorPatchNeighbours_ = -1;
|
||||
|
||||
// Construct processor patch indexing. processorPatchNeighbours_ only
|
||||
// set if running in parallel!
|
||||
processorPatches_.setSize(mesh_.boundaryMesh().size());
|
||||
processorPatches_.resize_nocopy(mesh_.boundaryMesh().size());
|
||||
|
||||
label nNeighbours = 0;
|
||||
|
||||
@ -81,7 +82,7 @@ void Foam::globalMeshData::initProcAddr()
|
||||
processorPatchIndices_[patchi] = nNeighbours++;
|
||||
}
|
||||
}
|
||||
processorPatches_.setSize(nNeighbours);
|
||||
processorPatches_.resize(nNeighbours);
|
||||
|
||||
|
||||
if (Pstream::parRun())
|
||||
@ -1728,14 +1729,21 @@ void Foam::globalMeshData::calcGlobalCoPointSlaves() const
|
||||
|
||||
Foam::globalMeshData::globalMeshData(const polyMesh& mesh)
|
||||
:
|
||||
processorTopology(mesh.boundaryMesh(), UPstream::worldComm),
|
||||
mesh_(mesh),
|
||||
nTotalPoints_(-1),
|
||||
nTotalFaces_(-1),
|
||||
nTotalCells_(-1),
|
||||
processorPatches_(0),
|
||||
processorPatchIndices_(0),
|
||||
processorPatchNeighbours_(0),
|
||||
processorTopology_
|
||||
(
|
||||
processorTopology::New<processorPolyPatch>
|
||||
(
|
||||
mesh.boundaryMesh(),
|
||||
UPstream::worldComm
|
||||
)
|
||||
),
|
||||
processorPatches_(),
|
||||
processorPatchIndices_(),
|
||||
processorPatchNeighbours_(),
|
||||
nGlobalPoints_(-1),
|
||||
sharedPointLabelsPtr_(nullptr),
|
||||
sharedPointAddrPtr_(nullptr),
|
||||
@ -1750,10 +1758,9 @@ Foam::globalMeshData::globalMeshData(const polyMesh& mesh)
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
// A non-default destructor since we had incomplete types in the header
|
||||
Foam::globalMeshData::~globalMeshData()
|
||||
{
|
||||
clearOut();
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
void Foam::globalMeshData::clearOut()
|
||||
@ -1780,6 +1787,7 @@ void Foam::globalMeshData::clearOut()
|
||||
globalPointSlavesPtr_.clear();
|
||||
globalPointTransformedSlavesPtr_.clear();
|
||||
globalPointSlavesMapPtr_.clear();
|
||||
|
||||
// Edge
|
||||
globalEdgeNumberingPtr_.clear();
|
||||
globalEdgeSlavesPtr_.clear();
|
||||
@ -2728,7 +2736,7 @@ void Foam::globalMeshData::updateMesh()
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "globalMeshData : nTotalFaces_:" << nTotalFaces_ << endl;
|
||||
Pout<< "globalMeshData : nTotalFaces:" << nTotalFaces_ << endl;
|
||||
}
|
||||
|
||||
nTotalCells_ = returnReduce
|
||||
@ -2741,7 +2749,7 @@ void Foam::globalMeshData::updateMesh()
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "globalMeshData : nTotalCells_:" << nTotalCells_ << endl;
|
||||
Pout<< "globalMeshData : nTotalCells:" << nTotalCells_ << endl;
|
||||
}
|
||||
|
||||
nTotalPoints_ = returnReduce
|
||||
@ -2757,7 +2765,7 @@ void Foam::globalMeshData::updateMesh()
|
||||
|
||||
if (debug)
|
||||
{
|
||||
Pout<< "globalMeshData : nTotalPoints_:" << nTotalPoints_ << endl;
|
||||
Pout<< "globalMeshData : nTotalPoints:" << nTotalPoints_ << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2018-2021 OpenCFD Ltd.
|
||||
Copyright (C) 2018-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -81,8 +81,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef globalMeshData_H
|
||||
#define globalMeshData_H
|
||||
#ifndef Foam_globalMeshData_H
|
||||
#define Foam_globalMeshData_H
|
||||
|
||||
#include "processorTopology.H"
|
||||
#include "labelPair.H"
|
||||
@ -106,8 +106,6 @@ class bitSet;
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class globalMeshData
|
||||
:
|
||||
public processorTopology
|
||||
{
|
||||
// Private Data
|
||||
|
||||
@ -129,6 +127,9 @@ class globalMeshData
|
||||
|
||||
// Processor patch addressing (be careful if not running in parallel!)
|
||||
|
||||
//- The processor/processor topology
|
||||
processorTopology processorTopology_;
|
||||
|
||||
//- List of processor patch labels
|
||||
// (size of list = number of processor patches)
|
||||
labelList processorPatches_;
|
||||
@ -377,6 +378,19 @@ public:
|
||||
|
||||
// Processor patch addressing (be careful when not running in parallel)
|
||||
|
||||
//- The processor to processor topology.
|
||||
const processorTopology& topology() const noexcept
|
||||
{
|
||||
return processorTopology_;
|
||||
}
|
||||
|
||||
//- Order in which the patches should be initialised/evaluated
|
||||
//- corresponding to the schedule
|
||||
const lduSchedule& patchSchedule() const noexcept
|
||||
{
|
||||
return processorTopology_.patchSchedule();
|
||||
}
|
||||
|
||||
//- Return list of processor patch labels
|
||||
// (size of list = number of processor patches)
|
||||
const labelList& processorPatches() const noexcept
|
||||
@ -393,7 +407,7 @@ public:
|
||||
}
|
||||
|
||||
//- Return processorPatchIndices of the neighbours
|
||||
// processor patches. -1 if not running parallel.
|
||||
//- processor patches. -1 if not running parallel.
|
||||
const labelList& processorPatchNeighbours() const noexcept
|
||||
{
|
||||
return processorPatchNeighbours_;
|
||||
|
||||
@ -1,51 +0,0 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2013 OpenFOAM Foundation
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef processorTopology_H
|
||||
#define processorTopology_H
|
||||
|
||||
#include "ProcessorTopology.H"
|
||||
#include "processorPolyPatch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
typedef ProcessorTopology<polyPatchList, processorPolyPatch> processorTopology;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -106,17 +106,59 @@ Foam::IOmapDistributePolyMesh::IOmapDistributePolyMesh
|
||||
}
|
||||
|
||||
|
||||
Foam::IOmapDistributePolyMeshRef::IOmapDistributePolyMeshRef
|
||||
(
|
||||
const IOobject& io,
|
||||
const mapDistributePolyMesh& map
|
||||
)
|
||||
:
|
||||
regIOobject(io),
|
||||
contentRef_(map) // cref
|
||||
{}
|
||||
|
||||
|
||||
// Not sure if we need this yet...
|
||||
//
|
||||
/// Foam::IOmapDistributePolyMeshRef::IOmapDistributePolyMeshRef
|
||||
/// (
|
||||
/// const IOobject& io,
|
||||
/// mapDistributePolyMesh& map
|
||||
/// )
|
||||
/// :
|
||||
/// regIOobject(io),
|
||||
/// contentRef_()
|
||||
/// {
|
||||
/// contentRef_.ref(map); // writable reference
|
||||
/// }
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::IOmapDistributePolyMesh::readData(Istream& is)
|
||||
{
|
||||
return (is >> *this).good();
|
||||
is >> *this;
|
||||
return is.good();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::IOmapDistributePolyMesh::writeData(Ostream& os) const
|
||||
{
|
||||
return (os << *this).good();
|
||||
os << *this;
|
||||
return os.good();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::IOmapDistributePolyMeshRef::readData(Istream& is)
|
||||
{
|
||||
is >> contentRef_.ref();
|
||||
return is.good();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::IOmapDistributePolyMeshRef::writeData(Ostream& os) const
|
||||
{
|
||||
os << contentRef_.cref();
|
||||
return os.good();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -42,6 +42,7 @@ SourceFiles
|
||||
|
||||
#include "mapDistributePolyMesh.H"
|
||||
#include "regIOobject.H"
|
||||
#include "refPtr.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -102,6 +103,74 @@ public:
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class IOmapDistributePolyMeshRef Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- A IOmapDistributePolyMesh wrapper for using referenced external data.
|
||||
class IOmapDistributePolyMeshRef
|
||||
:
|
||||
public regIOobject
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- Reference to the external content
|
||||
refPtr<mapDistributePolyMesh> contentRef_;
|
||||
|
||||
public:
|
||||
|
||||
//- Type is identical to IOmapDistributePolyMesh
|
||||
virtual const word& type() const
|
||||
{
|
||||
return IOmapDistributePolyMesh::typeName;
|
||||
}
|
||||
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- No default construct
|
||||
IOmapDistributePolyMeshRef() = delete;
|
||||
|
||||
//- No copy construct
|
||||
IOmapDistributePolyMeshRef(const IOmapDistributePolyMeshRef&) = delete;
|
||||
|
||||
//- No copy assignment
|
||||
void operator=(const IOmapDistributePolyMeshRef&) = delete;
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from IOobject and const data reference
|
||||
IOmapDistributePolyMeshRef
|
||||
(
|
||||
const IOobject& io,
|
||||
const mapDistributePolyMesh& map
|
||||
);
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~IOmapDistributePolyMeshRef() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Allow cast to const content
|
||||
// Fatal if content is not set
|
||||
operator const mapDistributePolyMesh&() const
|
||||
{
|
||||
return contentRef_.cref();
|
||||
}
|
||||
|
||||
//- The readData method for regIOobject read operation
|
||||
// Fatal if content is constant (or not set)
|
||||
virtual bool readData(Istream& is);
|
||||
|
||||
//- The writeData method for regIOobject write operation
|
||||
// Fatal if content is not set
|
||||
virtual bool writeData(Ostream& os) const;
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
@ -40,12 +40,12 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef faceZone_H
|
||||
#define faceZone_H
|
||||
#ifndef Foam_faceZone_H
|
||||
#define Foam_faceZone_H
|
||||
|
||||
#include "zone.H"
|
||||
#include "faceZoneMeshFwd.H"
|
||||
#include "primitiveFacePatch.H"
|
||||
#include "primitivePatch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,13 +28,20 @@ Typedef
|
||||
Foam::indirectPrimitivePatch
|
||||
|
||||
Description
|
||||
A PrimitivePatch with an IndirectList for the faces, const reference
|
||||
for the point field.
|
||||
A PrimitivePatch with an IndirectList for the faces,
|
||||
const reference for the point field.
|
||||
|
||||
Typedef
|
||||
Foam::uindirectPrimitivePatch
|
||||
|
||||
Description
|
||||
A PrimitivePatch with UIndirectList for the faces,
|
||||
const reference for the point field.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef indirectPrimitivePatch_H
|
||||
#define indirectPrimitivePatch_H
|
||||
#ifndef Foam_indirectPrimitivePatch_H
|
||||
#define Foam_indirectPrimitivePatch_H
|
||||
|
||||
#include "PrimitivePatch.H"
|
||||
#include "face.H"
|
||||
@ -45,8 +52,15 @@ Description
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef PrimitivePatch<IndirectList<face>, const pointField&>
|
||||
indirectPrimitivePatch;
|
||||
|
||||
typedef
|
||||
PrimitivePatch<IndirectList<face>, const pointField&>
|
||||
indirectPrimitivePatch;
|
||||
|
||||
typedef
|
||||
PrimitivePatch<UIndirectList<face>, const pointField&>
|
||||
uindirectPrimitivePatch;
|
||||
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -1,57 +1,16 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Typedef
|
||||
Foam::primitiveFacePatch
|
||||
|
||||
Description
|
||||
A PrimitivePatch with List storage for the faces,
|
||||
const reference for the point field.
|
||||
Compatibility include
|
||||
|
||||
Can be used to store faces.
|
||||
primitiveFacePatch.H combined into primitivePatch.H
|
||||
(MAY-2022)
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef primitiveFacePatch_H
|
||||
#define primitiveFacePatch_H
|
||||
#ifndef Foam_primitiveFacePatch_H
|
||||
#define Foam_primitiveFacePatch_H
|
||||
|
||||
#include "PrimitivePatch.H"
|
||||
#include "face.H"
|
||||
#include "List.H"
|
||||
#include "pointField.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef PrimitivePatch<List<face>, const pointField&>
|
||||
primitiveFacePatch;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
#include "indirectPrimitivePatch.H"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,27 +28,43 @@ Typedef
|
||||
Foam::primitivePatch
|
||||
|
||||
Description
|
||||
A PrimitivePatch with a SubList addressing for the faces,
|
||||
A PrimitivePatch with a SubList \em addressing for the faces,
|
||||
const reference for the point field.
|
||||
|
||||
Can be used as addressing for a faceList slice.
|
||||
|
||||
Typedef
|
||||
Foam::primitiveFacePatch
|
||||
|
||||
Description
|
||||
A PrimitivePatch with List \em storage for the faces,
|
||||
const reference for the point field.
|
||||
|
||||
Can be used to store faces.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef primitivePatch_H
|
||||
#define primitivePatch_H
|
||||
#ifndef Foam_primitivePatch_H
|
||||
#define Foam_primitivePatch_H
|
||||
|
||||
#include "PrimitivePatch.H"
|
||||
#include "face.H"
|
||||
#include "SubList.H"
|
||||
#include "List.H"
|
||||
#include "pointField.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef PrimitivePatch<SubList<face>, const pointField&>
|
||||
primitivePatch;
|
||||
|
||||
typedef
|
||||
PrimitivePatch<SubList<face>, const pointField&>
|
||||
primitivePatch;
|
||||
|
||||
typedef
|
||||
PrimitivePatch<List<face>, const pointField&>
|
||||
primitiveFacePatch;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -1,55 +1,16 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011 OpenFOAM Foundation
|
||||
Copyright (C) 2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Typedef
|
||||
Foam::uindirectPrimitivePatch
|
||||
|
||||
Description
|
||||
A PrimitivePatch with UIndirectList for the faces, const reference
|
||||
for the point field.
|
||||
Compatibility include
|
||||
|
||||
uindirectPrimitivePatch.H combined into uindirectPrimitivePatch.H
|
||||
(MAY-2022)
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef uindirectPrimitivePatch_H
|
||||
#define uindirectPrimitivePatch_H
|
||||
#ifndef Foam_uindirectPrimitivePatch_H
|
||||
#define Foam_uindirectPrimitivePatch_H
|
||||
|
||||
#include "PrimitivePatch.H"
|
||||
#include "face.H"
|
||||
#include "UIndirectList.H"
|
||||
#include "pointField.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
typedef PrimitivePatch<UIndirectList<face>, const pointField&>
|
||||
uindirectPrimitivePatch;
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
#include "indirectPrimitivePatch.H"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -37,13 +37,12 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef pointIndList_H
|
||||
#define pointIndList_H
|
||||
#ifndef Foam_pointIndList_H
|
||||
#define Foam_pointIndList_H
|
||||
|
||||
// Include all normal list typedefs as well
|
||||
#include "pointList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "UIndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -90,7 +90,8 @@ Foam::commSchedule::commSchedule
|
||||
if (proc0 < 0 || proc0 >= nProcs || proc1 < 0 || proc1 >= nProcs)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Illegal processor " << comms[commI] << abort(FatalError);
|
||||
<< "Illegal processor(s): "
|
||||
<< comms[commI] << abort(FatalError);
|
||||
}
|
||||
|
||||
procToComms[proc0].append(commI);
|
||||
|
||||
@ -42,8 +42,8 @@ Description
|
||||
- procSchedule()[proci] gives per proci
|
||||
|
||||
Does not care whether 'talking' is first send, second receive or maybe
|
||||
full swap. This is all responsibility of caller. See ProcessorTopology
|
||||
class for use in scheduling processor boundary swaps.
|
||||
full swap. This is all responsibility of caller.
|
||||
See Foam::rocessorTopology for use in scheduling processor boundary swaps.
|
||||
|
||||
SourceFiles
|
||||
commSchedule.C
|
||||
@ -78,13 +78,17 @@ class commSchedule
|
||||
|
||||
public:
|
||||
|
||||
//- Runtime type information
|
||||
ClassName("commSchedule");
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from wanted communication. Wanted communication is between
|
||||
// two processors. Can be a one-way communication or
|
||||
// two-way communication, that is up to the caller. This class just
|
||||
//- two processors. Can be a one-way communication or
|
||||
//- two-way communication, that is up to the caller.
|
||||
//
|
||||
// This class just
|
||||
// determines an order for it such that any processor is only talking
|
||||
// to one other at a time. After construction:
|
||||
// - schedule is the order in which comms is done.
|
||||
|
||||
176
src/OpenFOAM/parallel/processorTopology/processorTopology.H
Normal file
176
src/OpenFOAM/parallel/processorTopology/processorTopology.H
Normal file
@ -0,0 +1,176 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Class
|
||||
Foam::processorTopology
|
||||
|
||||
Description
|
||||
Determines/represents processor-processor connection.
|
||||
After instantiation contains the processor-processor connection table
|
||||
(globally synchronized on all processors).
|
||||
|
||||
Note
|
||||
A processorTopology is usually generated by using the \c New
|
||||
factory method, which has been wrapped into a separate header to
|
||||
minimize dependencies.
|
||||
|
||||
Warning
|
||||
Does not currently correctly support multiple processor
|
||||
patches connecting two processors.
|
||||
|
||||
SourceFiles
|
||||
processorTopologyNew.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Foam_processorTopology_H
|
||||
#define Foam_processorTopology_H
|
||||
|
||||
#include "labelList.H"
|
||||
#include "lduSchedule.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class processorTopology Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class processorTopology
|
||||
{
|
||||
// Private Data
|
||||
|
||||
//- The processor to processor connection (adjacency) table
|
||||
labelListList procNeighbours_;
|
||||
|
||||
//- Order in which the patches should be initialised/evaluated
|
||||
//- corresponding to the schedule
|
||||
lduSchedule patchSchedule_;
|
||||
|
||||
//- Local map from neighbour proc to patchi. Different per processor!
|
||||
// -1 or patchi for connection to procID
|
||||
labelList procPatchMap_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- From neighbour processor to index in our local boundary.
|
||||
// Local information (so not same over all processors)
|
||||
///const labelList& procPatchMap() const noexcept
|
||||
///{
|
||||
/// return procPatchMap_;
|
||||
///}
|
||||
|
||||
//- Which \em local boundary is attached to specified processor
|
||||
// Local information (so not same over all processors)
|
||||
// \return -1 if not currently connected to specified processor.
|
||||
label procToLocalPatch(const label proci) const
|
||||
{
|
||||
return
|
||||
(
|
||||
proci >= 0 && proci < procPatchMap_.size()
|
||||
? procPatchMap_[proci]
|
||||
: static_cast<label>(-1)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// Generated Methods
|
||||
|
||||
//- Default construct (empty)
|
||||
processorTopology() = default;
|
||||
|
||||
//- Copy construct
|
||||
processorTopology(const processorTopology&) = default;
|
||||
|
||||
//- Move construct
|
||||
processorTopology(processorTopology&&) = default;
|
||||
|
||||
//- Copy assignment
|
||||
processorTopology& operator=(const processorTopology&) = default;
|
||||
|
||||
//- Move assignment
|
||||
processorTopology& operator=(processorTopology&&) = default;
|
||||
|
||||
|
||||
// Static Functions
|
||||
|
||||
//- Factory method to create topology, schedule and proc/patch maps.
|
||||
// Scans the list of patches for processor connections corresponding
|
||||
// to the ProcPatch type.
|
||||
template<class ProcPatch, class PatchListType>
|
||||
static processorTopology New
|
||||
(
|
||||
const PatchListType& patches,
|
||||
const label comm
|
||||
);
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- The number of processors used by the topology
|
||||
label nProcs() const noexcept
|
||||
{
|
||||
return procNeighbours_.size();
|
||||
}
|
||||
|
||||
//- The processor to processor connection topology
|
||||
//- (like an adjacency list). Globally synchronized information
|
||||
const labelListList& procNeighbours() const noexcept
|
||||
{
|
||||
return procNeighbours_;
|
||||
}
|
||||
|
||||
//- Order in which the patches should be initialised/evaluated
|
||||
//- corresponding to the schedule
|
||||
const lduSchedule& patchSchedule() const noexcept
|
||||
{
|
||||
return patchSchedule_;
|
||||
}
|
||||
|
||||
//- Which \em local boundary is attached to specified processor
|
||||
// Local information (so not same over all processors)
|
||||
// \return -1 if not currently connected to specified processor.
|
||||
label procPatchLookup(const label proci) const
|
||||
{
|
||||
return procToLocalPatch(proci);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
229
src/OpenFOAM/parallel/processorTopology/processorTopologyNew.H
Normal file
229
src/OpenFOAM/parallel/processorTopology/processorTopologyNew.H
Normal file
@ -0,0 +1,229 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2022 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
InClass
|
||||
Foam::processorTopology
|
||||
|
||||
Description
|
||||
Define the processor-processor connection table by walking a list of
|
||||
patches and detecting the processor ones.
|
||||
|
||||
This has been split off as a separate include from processorTopology
|
||||
to minimize dependencies.
|
||||
|
||||
Warning
|
||||
Does not currently correctly support multiple processor
|
||||
patches connecting two processors.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Foam_processorTopologyNew_H
|
||||
#define Foam_processorTopologyNew_H
|
||||
|
||||
#include "processorTopology.H"
|
||||
#include "bitSet.H"
|
||||
#include "commSchedule.H"
|
||||
#include "DynamicList.H"
|
||||
#include "Pstream.H"
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
|
||||
|
||||
template<class ProcPatch, class PatchListType>
|
||||
Foam::processorTopology Foam::processorTopology::New
|
||||
(
|
||||
const PatchListType& patches,
|
||||
const label comm
|
||||
)
|
||||
{
|
||||
const label myProci = Pstream::myProcNo(comm);
|
||||
const label nProcs = Pstream::nProcs(comm);
|
||||
|
||||
processorTopology procTopo;
|
||||
|
||||
auto& procToProcs = procTopo.procNeighbours_;
|
||||
auto& procToPatch = procTopo.procPatchMap_;
|
||||
auto& schedule = procTopo.patchSchedule_;
|
||||
|
||||
procToProcs.resize(nProcs);
|
||||
schedule.resize(2*patches.size());
|
||||
|
||||
|
||||
if (Pstream::parRun())
|
||||
{
|
||||
// Fill my 'slot' with my neighbours
|
||||
auto& procSlot = procToProcs[myProci];
|
||||
|
||||
bitSet isNeighbour(procToProcs.size());
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
const auto* cpp = isA<ProcPatch>(patches[patchi]);
|
||||
if (cpp)
|
||||
{
|
||||
const label nbrProci = cpp->neighbProcNo();
|
||||
|
||||
isNeighbour.set(nbrProci);
|
||||
}
|
||||
}
|
||||
|
||||
// The neighbouring procs in sorted (ascending) order
|
||||
procSlot = isNeighbour.sortedToc();
|
||||
|
||||
const label maxNbrProci = procSlot.empty() ? -1 : procSlot.last();
|
||||
|
||||
// Note could also use Map<label> if desired
|
||||
procToPatch.resize_nocopy(maxNbrProci + 1);
|
||||
procToPatch = -1;
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
const auto* cpp = isA<ProcPatch>(patches[patchi]);
|
||||
if (cpp)
|
||||
{
|
||||
const label nbrProci = cpp->neighbProcNo();
|
||||
|
||||
// Reverse map
|
||||
procToPatch[nbrProci] = patchi;
|
||||
}
|
||||
}
|
||||
|
||||
// Synchronize on all processors
|
||||
Pstream::allGatherList(procToProcs, UPstream::msgType(), comm);
|
||||
}
|
||||
|
||||
|
||||
// Define the schedule
|
||||
|
||||
label patchEvali = 0;
|
||||
|
||||
// 1. All non-processor patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (!isA<ProcPatch>(patches[patchi]))
|
||||
{
|
||||
schedule[patchEvali++].setInitEvaluate(patchi);
|
||||
schedule[patchEvali++].setEvaluate(patchi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 2. All processor patches
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
if
|
||||
(
|
||||
Pstream::parRun()
|
||||
&& Pstream::defaultCommsType == Pstream::commsTypes::scheduled
|
||||
)
|
||||
{
|
||||
// Determine the schedule for all processor patches.
|
||||
// Insert processor pair once to determine the schedule.
|
||||
// Each processor pair stands for both send and receive.
|
||||
|
||||
label nComms = 0;
|
||||
for (const labelList& nbrProcs : procToProcs)
|
||||
{
|
||||
nComms += nbrProcs.size();
|
||||
}
|
||||
DynamicList<labelPair> comms(nComms/2);
|
||||
|
||||
forAll(procToProcs, proci)
|
||||
{
|
||||
for (const label nbrProci : procToProcs[proci])
|
||||
{
|
||||
if (proci < nbrProci)
|
||||
{
|
||||
comms.append(labelPair(proci, nbrProci));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine a schedule.
|
||||
labelList mySchedule
|
||||
(
|
||||
commSchedule
|
||||
(
|
||||
nProcs,
|
||||
comms
|
||||
).procSchedule()[myProci]
|
||||
);
|
||||
|
||||
for (const label scheduleIndex : mySchedule)
|
||||
{
|
||||
// Get the other processor
|
||||
label nbrProci = comms[scheduleIndex][0];
|
||||
if (nbrProci == myProci)
|
||||
{
|
||||
nbrProci = comms[scheduleIndex][1];
|
||||
}
|
||||
const label patchi = procToPatch[nbrProci];
|
||||
|
||||
if (myProci > nbrProci)
|
||||
{
|
||||
schedule[patchEvali++].setInitEvaluate(patchi);
|
||||
schedule[patchEvali++].setEvaluate(patchi);
|
||||
}
|
||||
else
|
||||
{
|
||||
schedule[patchEvali++].setEvaluate(patchi);
|
||||
schedule[patchEvali++].setInitEvaluate(patchi);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Non-blocking schedule for processor patches
|
||||
|
||||
// initEvaluate
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (isA<ProcPatch>(patches[patchi]))
|
||||
{
|
||||
schedule[patchEvali++].setInitEvaluate(patchi);
|
||||
}
|
||||
}
|
||||
|
||||
// evaluate
|
||||
forAll(patches, patchi)
|
||||
{
|
||||
if (isA<ProcPatch>(patches[patchi]))
|
||||
{
|
||||
schedule[patchEvali++].setEvaluate(patchi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return procTopo;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -37,13 +37,12 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef scalarIndList_H
|
||||
#define scalarIndList_H
|
||||
#ifndef Foam_scalarIndList_H
|
||||
#define Foam_scalarIndList_H
|
||||
|
||||
// Include all normal list typedefs as well
|
||||
#include "scalarList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "UIndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -37,13 +37,12 @@ Description
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef vectorIndList_H
|
||||
#define vectorIndList_H
|
||||
#ifndef Foam_vectorIndList_H
|
||||
#define Foam_vectorIndList_H
|
||||
|
||||
// Include all normal list typedefs as well
|
||||
#include "vectorList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "UIndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -43,14 +43,13 @@ Description
|
||||
// Include all normal list typedefs as well
|
||||
#include "labelList.H"
|
||||
#include "IndirectList.H"
|
||||
#include "UIndirectList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
// NB: labelUIndList is defined in UIndirectList itself
|
||||
typedef IndirectList<label> labelIndList;
|
||||
// labelUIndList is defined in UIndirectList itself
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -70,6 +70,7 @@ namespace Foam
|
||||
// \endcode
|
||||
//
|
||||
// \return List indices for matching strings
|
||||
// \see IndirectList::subset_if
|
||||
template<class UnaryMatchPredicate, class StringType>
|
||||
labelList findMatchingStrings
|
||||
(
|
||||
@ -161,6 +162,7 @@ namespace Foam
|
||||
// \code
|
||||
// subsetMatchingStrings<regExp, stringList>(myRegExp, list);
|
||||
// \endcode
|
||||
// \see IndirectList::subset_if
|
||||
template<class UnaryMatchPredicate, class StringListType>
|
||||
StringListType subsetMatchingStrings
|
||||
(
|
||||
@ -326,8 +328,6 @@ namespace Foam
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Namespace stringListOps Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -34,7 +34,7 @@ License
|
||||
#include "IOdictionary.H"
|
||||
|
||||
#include "ccmBoundaryInfo.H"
|
||||
#include "uindirectPrimitivePatch.H"
|
||||
#include "indirectPrimitivePatch.H"
|
||||
#include "SortableList.H"
|
||||
#include "mergePoints.H"
|
||||
#include "bitSet.H"
|
||||
|
||||
@ -31,6 +31,14 @@ Description
|
||||
as a vtp file or a legacy vtk file
|
||||
with support for geometric fields.
|
||||
|
||||
Typedef
|
||||
Foam::vtk::uindirectPatchGeoFieldsWriter
|
||||
|
||||
Description
|
||||
Write uindirectPrimitivePatch faces/points
|
||||
as a vtp file or a legacy vtk file
|
||||
with support for geometric fields.
|
||||
|
||||
See Also
|
||||
Foam::vtk::GenericPatchWriter
|
||||
|
||||
@ -55,6 +63,10 @@ typedef
|
||||
GenericPatchGeoFieldsWriter<indirectPrimitivePatch>
|
||||
indirectPatchGeoFieldsWriter;
|
||||
|
||||
typedef
|
||||
GenericPatchGeoFieldsWriter<uindirectPrimitivePatch>
|
||||
uindirectPatchGeoFieldsWriter;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
@ -1,67 +1,17 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2021 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
|
||||
OpenFOAM is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
|
||||
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Typedef
|
||||
Foam::vtk::uindirectPatchGeoFieldsWriter
|
||||
|
||||
Description
|
||||
Write uindirectPrimitivePatch faces/points
|
||||
as a vtp file or a legacy vtk file
|
||||
with support for geometric fields.
|
||||
Compatibility include
|
||||
|
||||
See Also
|
||||
Foam::vtk::GenericPatchWriter
|
||||
foamVtkUIndPatchGeoFieldsWriter.H
|
||||
combined into foamVtkIndPatchGeoFieldsWriter.H
|
||||
(MAY-2022)
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef Foam_vtk_UIndPatchGeoFieldsWriter_H
|
||||
#define Foam_vtk_UIndPatchGeoFieldsWriter_H
|
||||
|
||||
#include "foamVtkGenericPatchGeoFieldsWriter.H"
|
||||
#include "uindirectPrimitivePatch.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
namespace vtk
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
typedef
|
||||
GenericPatchGeoFieldsWriter<uindirectPrimitivePatch>
|
||||
uindirectPatchGeoFieldsWriter;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace vtk
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
#include "foamVtkIndPatchGeoFieldsWriter.H"
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user