ENH: additional Map/HashTable constructors and ListOp functions

- construct Map/HashTable from key/value lists.

- invertToMap() : like invert() but returns a Map<label>,
  which is useful for sparse numbering

- inplaceRenumber() : taking a Map<label> for the mapper

ENH: construct/reset CStringList for list of C-strings
This commit is contained in:
Mark Olesen
2024-02-21 09:34:58 +01:00
parent f7cdd3ef63
commit 4f43f0302d
37 changed files with 363 additions and 298 deletions

View File

@ -124,11 +124,11 @@ int main(int argc, char *argv[])
<< "toc: " << flatOutput(table0.toc()) << nl; << "toc: " << flatOutput(table0.toc()) << nl;
HashTable<label, label, Hash<label>> table2 HashTable<label, label, Hash<label>> table2
({ (
{3, 10}, // From key/value pairs
{5, 12}, labelList({3, 5, 7}),
{7, 16} labelList({10, 12, 16})
}); );
Info<< "table2: " << table2 << nl Info<< "table2: " << table2 << nl
<< "toc: " << flatOutput(table2.toc()) << nl; << "toc: " << flatOutput(table2.toc()) << nl;

View File

@ -1,3 +1,3 @@
Test-cstring.C Test-cstring.cxx
EXE = $(FOAM_USER_APPBIN)/Test-cstring EXE = $(FOAM_USER_APPBIN)/Test-cstring

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -81,8 +81,7 @@ int print(char *argv[])
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
DynamicList<string> dynlst; DynamicList<string> dynlst(16);
dynlst.reserve(16);
dynlst.push_back("string1 with content"); dynlst.push_back("string1 with content");
dynlst.push_back("string2 other content"); dynlst.push_back("string2 other content");
@ -104,6 +103,18 @@ int main(int argc, char *argv[])
Info<< nl; Info<< nl;
} }
{
CStringList inC({ "string1", "string2", "string3", "end" });
Info<< "null-terminated string list from " << nl;
print(inC.strings());
Info<< "sublist: starting at " << inC.size()/2 << nl;
print(inC.strings(inC.size()/2));
Info<< nl;
}
{ {
string testInput string testInput
( (
@ -124,7 +135,7 @@ int main(int argc, char *argv[])
Info<< nl; Info<< nl;
} }
Info<<"command-line with " << CStringList::count(argv) << " items"<< endl; Info<< "command-line with " << CStringList::count(argv) << " items" << nl;
print(argc, argv); print(argc, argv);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020-2023 OpenCFD Ltd. Copyright (C) 2020-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -98,19 +98,6 @@ bool skipSection(IFstream& inFile)
} }
void renumber
(
const Map<label>& mshToFoam,
labelList& labels
)
{
forAll(labels, labelI)
{
labels[labelI] = mshToFoam[labels[labelI]];
}
}
// Find face in pp which uses all vertices in meshF (in mesh point labels) // Find face in pp which uses all vertices in meshF (in mesh point labels)
label findFace(const primitivePatch& pp, const labelList& meshF) label findFace(const primitivePatch& pp, const labelList& meshF)
{ {
@ -587,7 +574,7 @@ void readCellsLegacy
{ {
lineStr >> triPoints[0] >> triPoints[1] >> triPoints[2]; lineStr >> triPoints[0] >> triPoints[1] >> triPoints[2];
renumber(mshToFoam, triPoints); inplaceRenumber(mshToFoam, triPoints);
const auto regFnd = physToPatch.cfind(regPhys); const auto regFnd = physToPatch.cfind(regPhys);
@ -620,7 +607,7 @@ void readCellsLegacy
>> quadPoints[0] >> quadPoints[1] >> quadPoints[2] >> quadPoints[0] >> quadPoints[1] >> quadPoints[2]
>> quadPoints[3]; >> quadPoints[3];
renumber(mshToFoam, quadPoints); inplaceRenumber(mshToFoam, quadPoints);
const auto regFnd = physToPatch.cfind(regPhys); const auto regFnd = physToPatch.cfind(regPhys);
@ -662,7 +649,7 @@ void readCellsLegacy
>> tetPoints[0] >> tetPoints[1] >> tetPoints[2] >> tetPoints[0] >> tetPoints[1] >> tetPoints[2]
>> tetPoints[3]; >> tetPoints[3];
renumber(mshToFoam, tetPoints); inplaceRenumber(mshToFoam, tetPoints);
cells[celli++].reset(tet, tetPoints); cells[celli++].reset(tet, tetPoints);
@ -683,7 +670,7 @@ void readCellsLegacy
>> pyrPoints[0] >> pyrPoints[1] >> pyrPoints[2] >> pyrPoints[0] >> pyrPoints[1] >> pyrPoints[2]
>> pyrPoints[3] >> pyrPoints[4]; >> pyrPoints[3] >> pyrPoints[4];
renumber(mshToFoam, pyrPoints); inplaceRenumber(mshToFoam, pyrPoints);
cells[celli++].reset(pyr, pyrPoints); cells[celli++].reset(pyr, pyrPoints);
@ -704,7 +691,7 @@ void readCellsLegacy
>> prismPoints[0] >> prismPoints[1] >> prismPoints[2] >> prismPoints[0] >> prismPoints[1] >> prismPoints[2]
>> prismPoints[3] >> prismPoints[4] >> prismPoints[5]; >> prismPoints[3] >> prismPoints[4] >> prismPoints[5];
renumber(mshToFoam, prismPoints); inplaceRenumber(mshToFoam, prismPoints);
cells[celli].reset(prism, prismPoints); cells[celli].reset(prism, prismPoints);
@ -745,7 +732,7 @@ void readCellsLegacy
>> hexPoints[4] >> hexPoints[5] >> hexPoints[4] >> hexPoints[5]
>> hexPoints[6] >> hexPoints[7]; >> hexPoints[6] >> hexPoints[7];
renumber(mshToFoam, hexPoints); inplaceRenumber(mshToFoam, hexPoints);
cells[celli].reset(hex, hexPoints); cells[celli].reset(hex, hexPoints);
@ -929,7 +916,7 @@ void readCells
IStringStream lineStr(line); IStringStream lineStr(line);
lineStr >> elemID >> triPoints[0] >> triPoints[1] >> triPoints[2]; lineStr >> elemID >> triPoints[0] >> triPoints[1] >> triPoints[2];
renumber(mshToFoam, triPoints); inplaceRenumber(mshToFoam, triPoints);
const auto regFnd = physToPatch.cfind(regPhys); const auto regFnd = physToPatch.cfind(regPhys);
@ -967,7 +954,7 @@ void readCells
>> quadPoints[0] >> quadPoints[1] >> quadPoints[2] >> quadPoints[0] >> quadPoints[1] >> quadPoints[2]
>> quadPoints[3]; >> quadPoints[3];
renumber(mshToFoam, quadPoints); inplaceRenumber(mshToFoam, quadPoints);
const auto regFnd = physToPatch.cfind(regPhys); const auto regFnd = physToPatch.cfind(regPhys);
@ -1017,7 +1004,7 @@ void readCells
>> tetPoints[0] >> tetPoints[1] >> tetPoints[2] >> tetPoints[0] >> tetPoints[1] >> tetPoints[2]
>> tetPoints[3]; >> tetPoints[3];
renumber(mshToFoam, tetPoints); inplaceRenumber(mshToFoam, tetPoints);
cells[celli++].reset(tet, tetPoints); cells[celli++].reset(tet, tetPoints);
} }
@ -1044,7 +1031,7 @@ void readCells
>> pyrPoints[0] >> pyrPoints[1] >> pyrPoints[2] >> pyrPoints[0] >> pyrPoints[1] >> pyrPoints[2]
>> pyrPoints[3] >> pyrPoints[4]; >> pyrPoints[3] >> pyrPoints[4];
renumber(mshToFoam, pyrPoints); inplaceRenumber(mshToFoam, pyrPoints);
cells[celli++].reset(pyr, pyrPoints); cells[celli++].reset(pyr, pyrPoints);
} }
@ -1071,7 +1058,7 @@ void readCells
>> prismPoints[0] >> prismPoints[1] >> prismPoints[2] >> prismPoints[0] >> prismPoints[1] >> prismPoints[2]
>> prismPoints[3] >> prismPoints[4] >> prismPoints[5]; >> prismPoints[3] >> prismPoints[4] >> prismPoints[5];
renumber(mshToFoam, prismPoints); inplaceRenumber(mshToFoam, prismPoints);
cells[celli].reset(prism, prismPoints); cells[celli].reset(prism, prismPoints);
@ -1118,7 +1105,7 @@ void readCells
>> hexPoints[4] >> hexPoints[5] >> hexPoints[4] >> hexPoints[5]
>> hexPoints[6] >> hexPoints[7]; >> hexPoints[6] >> hexPoints[7];
renumber(mshToFoam, hexPoints); inplaceRenumber(mshToFoam, hexPoints);
cells[celli].reset(hex, hexPoints); cells[celli].reset(hex, hexPoints);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2021 OpenCFD Ltd. Copyright (C) 2021-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -219,14 +219,14 @@ void readPoints
<< endl; << endl;
} }
point pt;
is.getLine(line); is.getLine(line);
pt[0] = readUnvScalar(line.substr(0, 25));
pt[1] = readUnvScalar(line.substr(25, 25));
pt[2] = readUnvScalar(line.substr(50, 25));
unvPointID.append(pointi); unvPointID.push_back(pointi);
points.append(pt); point& p = points.emplace_back();
p.x() = readUnvScalar(line.substr(0, 25));
p.y() = readUnvScalar(line.substr(25, 25));
p.z() = readUnvScalar(line.substr(50, 25));
} }
points.shrink(); points.shrink();
@ -847,7 +847,7 @@ int main(int argc, char *argv[])
labelList own(boundaryFaces.size(), -1); labelList own(boundaryFaces.size(), -1);
labelList nei(boundaryFaces.size(), -1); labelList nei(boundaryFaces.size(), -1);
Map<label> faceToCell[2]; Pair<Map<label>> faceToCell;
{ {
// Can use face::symmHasher or use sorted indices instead // Can use face::symmHasher or use sorted indices instead
@ -996,12 +996,7 @@ int main(int argc, char *argv[])
labelHashSet alreadyOnBoundary; labelHashSet alreadyOnBoundary;
// Construct map from boundaryFaceIndices // Construct map from boundaryFaceIndices
Map<label> boundaryFaceToIndex(boundaryFaceIndices.size()); Map<label> boundaryFaceToIndex(invertToMap(boundaryFaceIndices));
forAll(boundaryFaceIndices, i)
{
boundaryFaceToIndex.insert(boundaryFaceIndices[i], i);
}
forAll(patchFaceVerts, patchi) forAll(patchFaceVerts, patchi)
{ {
@ -1216,20 +1211,13 @@ int main(int argc, char *argv[])
{ {
const label old = oldIndizes[i]; const label old = oldIndizes[i];
label noveau = -1; label noveau = -1;
label c1 = -1, c2 = -1;
if (faceToCell[0].found(old)) label c1 = faceToCell[0].lookup(old, -1);
{ label c2 = faceToCell[1].lookup(old, -1);
c1 = faceToCell[0][old];
}
if (faceToCell[1].found(old))
{
c2 = faceToCell[1][old];
}
if (c1 < c2) if (c1 < c2)
{ {
label tmp = c1; std::swap(c1, c2);
c1 = c2;
c2 = tmp;
} }
if (c2 == -1) if (c2 == -1)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2021 OpenCFD Ltd. Copyright (C) 2015-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -197,7 +197,7 @@ int main(int argc, char *argv[])
// //
pointField points(nNodes); pointField points(nNodes);
Map<label> nodeToPoint(nNodes); Map<label> nodeToPoint(2*nNodes);
{ {
labelList pointIndex(nNodes); labelList pointIndex(nNodes);
@ -439,23 +439,16 @@ int main(int argc, char *argv[])
// Get Foam patchID and update region->patch table. // Get Foam patchID and update region->patch table.
label patchi = 0; label patchi = regionToPatch.lookup(region, -1);
const auto patchFind = regionToPatch.cfind(region); if (patchi < 0)
if (patchFind.good())
{
patchi = *patchFind;
}
else
{ {
patchi = nPatches; patchi = nPatches;
regionToPatch.insert(region, nPatches++);
Info<< "Mapping tetgen region " << region Info<< "Mapping tetgen region " << region
<< " to patch " << " to patch "
<< patchi << endl; << patchi << endl;
regionToPatch.insert(region, nPatches++);
} }
boundaryPatch[facei] = patchi; boundaryPatch[facei] = patchi;

View File

@ -295,9 +295,7 @@ void addToInterface
else else
{ {
// Create new interface of size 1. // Create new interface of size 1.
Map<label> zoneToSize; regionsToSize(interface).insert(zoneID, 1);
zoneToSize.insert(zoneID, 1);
regionsToSize.insert(interface, zoneToSize);
} }
} }
@ -484,18 +482,10 @@ void getInterfaceSizes
zoneName + "_" + name1 + "_to_" + name0 zoneName + "_" + name1 + "_to_" + name0
); );
} }
interfaceSizes[nInterfaces] = infoIter();
if (regionsToInterface.found(e)) interfaceSizes[nInterfaces] = infoIter();
{ regionsToInterface(e).insert(zoneID, nInterfaces);
regionsToInterface[e].insert(zoneID, nInterfaces);
}
else
{
Map<label> zoneAndInterface;
zoneAndInterface.insert(zoneID, nInterfaces);
regionsToInterface.insert(e, zoneAndInterface);
}
nInterfaces++; nInterfaces++;
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -98,14 +98,38 @@ Foam::HashTable<T, Key, Hash>::HashTable(HashTable<T, Key, Hash>&& rhs) noexcept
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
Foam::HashTable<T, Key, Hash>::HashTable Foam::HashTable<T, Key, Hash>::HashTable
( (
std::initializer_list<std::pair<Key, T>> list std::initializer_list<std::pair<Key, T>> list,
const bool overwrite
) )
: :
HashTable<T, Key, Hash>(2*list.size()) HashTable<T, Key, Hash>()
{ {
reserve(list.size());
for (const auto& keyval : list) for (const auto& keyval : list)
{ {
set(keyval.first, keyval.second); this->setEntry(overwrite, keyval.first, keyval.second);
}
}
template<class T, class Key, class Hash>
Foam::HashTable<T, Key, Hash>::HashTable
(
const UList<Key>& keys,
const UList<T>& values,
const bool overwrite
)
:
HashTable<T, Key, Hash>()
{
const label len = std::min(keys.size(), values.size());
reserve(len);
for (label i = 0; i < len; ++i)
{
this->setEntry(overwrite, keys[i], values[i]);
} }
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -252,9 +252,22 @@ public:
//- Move construct //- Move construct
HashTable(this_type&& rhs) noexcept; HashTable(this_type&& rhs) noexcept;
//- Construct from an initializer list //- Construct from key/value pairs in initializer list
// Duplicate entries are handled by overwriting // By default, uses insert not overwrite semantics for duplicates.
HashTable(std::initializer_list<std::pair<Key, T>> list); HashTable
(
std::initializer_list<std::pair<Key, T>> list,
const bool overwrite = false
);
//- Construct from key/value pairs
// By default, uses insert not overwrite semantics for duplicates.
HashTable
(
const UList<Key>& keys,
const UList<T>& values,
const bool overwrite = false
);
//- Destructor //- Destructor

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -106,10 +106,27 @@ public:
parent_type(std::move(map)) parent_type(std::move(map))
{} {}
//- Construct from pairs of values //- Construct from key/value pairs in initializer list
Map(std::initializer_list<std::pair<label, T>> map) // By default, uses insert not overwrite semantics for duplicates.
Map
(
std::initializer_list<std::pair<label, T>> map,
const bool overwrite = false
)
: :
parent_type(map) parent_type(map, overwrite)
{}
//- Construct from key/value pairs
// By default, uses insert not overwrite semantics for duplicates.
Map
(
const UList<label>& keys,
const UList<T>& values,
const bool overwrite = false
)
:
parent_type(keys, values, overwrite)
{} {}

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2018-2020 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -110,6 +110,24 @@ Foam::labelList Foam::invert(const bitSet& map)
} }
Foam::Map<Foam::label> Foam::invertToMap(const labelUList& values)
{
const label len = values.size();
Map<label> inverse(2*len);
for (label i = 0 ; i < len; ++i)
{
// For correct behaviour with duplicates, do NOT use
// inverse.insert(values[i], inverse.size());
inverse.insert(values[i], i);
}
return inverse;
}
Foam::labelListList Foam::invertOneToMany Foam::labelListList Foam::invertOneToMany
( (
const label len, const label len,
@ -122,16 +140,26 @@ Foam::labelListList Foam::invertOneToMany
{ {
if (newIdx >= 0) if (newIdx >= 0)
{ {
#ifdef FULLDEBUG
if (newIdx >= len)
{
FatalErrorInFunction
<< "Inverse location " << newIdx
<< " is out of range. List has size " << len
<< abort(FatalError);
}
#endif
++sizes[newIdx]; ++sizes[newIdx];
} }
} }
labelListList inverse(len); labelListList inverse(len);
for (label i=0; i < len; ++i) for (label i = 0; i < len; ++i)
{ {
inverse[i].resize(sizes[i]); inverse[i].resize(sizes[i]);
sizes[i] = 0; // reset size counter sizes[i] = 0; // reset size counter
} }
label i = 0; label i = 0;
@ -196,7 +224,7 @@ void Foam::inplaceReorder
const bool prune const bool prune
) )
{ {
input = reorder(oldToNew, input, prune); input = Foam::reorder(oldToNew, input, prune);
} }

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -59,16 +59,21 @@ SourceFiles
namespace Foam namespace Foam
{ {
//- Renumber the values (not the indices) of a list. //- Renumber the values within a list.
// Negative IntListType elements are left untouched. // Negative input values are left untouched.
template<class IntListType> template<class IntListType>
IntListType renumber(const labelUList& oldToNew, const IntListType& input); IntListType renumber(const labelUList& oldToNew, const IntListType& input);
//- Inplace renumber the values (not the indices) of a list. //- Inplace renumber the values within a list.
// Negative IntListType elements are left untouched. // Negative input values are left untouched.
template<class IntListType> template<class IntListType>
void inplaceRenumber(const labelUList& oldToNew, IntListType& input); void inplaceRenumber(const labelUList& oldToNew, IntListType& input);
//- Inplace renumber the values of a list.
// Values that are not mapped by oldToNew are left untouched.
template<class IntListType>
void inplaceRenumber(const Map<label>& oldToNew, IntListType& input);
//- Reorder the elements of a list. //- Reorder the elements of a list.
// Locations with negative oldToNew values are left as is (copy-through). // Locations with negative oldToNew values are left as is (copy-through).
@ -362,6 +367,14 @@ labelList invert(const label len, const bitSet& map);
// \return the inverse mapping with -1 for unmapped elements. // \return the inverse mapping with -1 for unmapped elements.
labelList invert(const bitSet& map); labelList invert(const bitSet& map);
//- Create inverse mapping, which is a lookup table into the given list
// \param values the values (likely unique).
//
// Negative values are allowed, duplicates are "first wins"
//
// \return the inverse lookup
Map<label> invertToMap(const labelUList& values);
//- Invert one-to-many map. Unmapped elements will be size 0. //- Invert one-to-many map. Unmapped elements will be size 0.
labelListList invertOneToMany(const label len, const labelUList& map); labelListList invertOneToMany(const label len, const labelUList& map);

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2023 OpenCFD Ltd. Copyright (C) 2015-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -71,6 +71,27 @@ void Foam::inplaceRenumber
} }
template<class IntListType>
void Foam::inplaceRenumber
(
const Map<label>& oldToNew,
IntListType& input
)
{
const label len = input.size();
for (label i = 0; i < len; ++i)
{
const auto fnd = oldToNew.cfind(input[i]);
if (fnd.good())
{
input[i] = fnd.val();
}
}
}
template<class ListType> template<class ListType>
ListType Foam::reorder ListType Foam::reorder
( (
@ -224,7 +245,7 @@ void Foam::inplaceReorder
const bool prune const bool prune
) )
{ {
input = reorder(oldToNew, input, prune); input = Foam::reorder(oldToNew, input, prune);
// Verify address (for movable refs) // Verify address (for movable refs)
// Info<< "now have " << name(input.cdata()) << nl; // Info<< "now have " << name(input.cdata()) << nl;

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2023 OpenCFD Ltd. Copyright (C) 2015-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,6 +35,7 @@ License
#include "processorPolyPatch.H" #include "processorPolyPatch.H"
#include "processorTopologyNew.H" #include "processorTopologyNew.H"
#include "globalIndexAndTransform.H" #include "globalIndexAndTransform.H"
#include "ListOps.H"
#include "Pstream.H" #include "Pstream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -314,11 +315,8 @@ void Foam::globalMeshData::calcSharedEdges() const
// Since don't want to construct pointEdges for whole mesh create // Since don't want to construct pointEdges for whole mesh create
// Map for all shared points. // Map for all shared points.
Map<label> meshToShared(2*sharedPtLabels.size()); Map<label> meshToShared(invertToMap(sharedPtLabels));
forAll(sharedPtLabels, i)
{
meshToShared.insert(sharedPtLabels[i], i);
}
// Find edges using shared points. Store correspondence to local edge // Find edges using shared points. Store correspondence to local edge
// numbering. Note that multiple local edges can have the same shared // numbering. Note that multiple local edges can have the same shared

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2023 OpenCFD Ltd. Copyright (C) 2015-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -359,11 +359,7 @@ void Foam::syncTools::syncPointMap
// pointValues (keyed on mesh points). // pointValues (keyed on mesh points).
// Map from global shared index to meshpoint // Map from global shared index to meshpoint
Map<label> sharedToMeshPoint(2*sharedPtAddr.size()); Map<label> sharedToMeshPoint(sharedPtAddr, sharedPtLabels);
forAll(sharedPtAddr, i)
{
sharedToMeshPoint.insert(sharedPtAddr[i], sharedPtLabels[i]);
}
forAllConstIters(sharedToMeshPoint, iter) forAllConstIters(sharedToMeshPoint, iter)
{ {
@ -622,11 +618,7 @@ void Foam::syncTools::syncEdgeMap
const labelList& sharedPtLabels = pd.sharedPointLabels(); const labelList& sharedPtLabels = pd.sharedPointLabels();
// 1. Create map from meshPoint to globalShared index. // 1. Create map from meshPoint to globalShared index.
Map<label> meshToShared(2*sharedPtLabels.size()); Map<label> meshToShared(sharedPtLabels, sharedPtAddr);
forAll(sharedPtLabels, i)
{
meshToShared.insert(sharedPtLabels[i], sharedPtAddr[i]);
}
// Values on shared points. From two sharedPtAddr indices to a value. // Values on shared points. From two sharedPtAddr indices to a value.
EdgeMap<T> sharedEdgeValues(meshToShared.size()); EdgeMap<T> sharedEdgeValues(meshToShared.size());

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2016 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -129,15 +129,9 @@ Foam::PrimitivePatch<FaceList, PointField>::calcMeshPointMap() const
<< abort(FatalError); << abort(FatalError);
} }
const labelList& mp = meshPoints(); const labelList& meshPts = meshPoints();
meshPointMapPtr_.reset(new Map<label>(2*mp.size())); meshPointMapPtr_.reset(new Map<label>(invertToMap(meshPts)));
auto& mpMap = *meshPointMapPtr_;
forAll(mp, i)
{
mpMap.insert(mp[i], i);
}
DebugInfo << "Calculated mesh point map" << endl; DebugInfo << "Calculated mesh point map" << endl;
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2017-2022 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -28,20 +28,67 @@ License
#include "CStringList.H" #include "CStringList.H"
#include "Ostream.H" #include "Ostream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
int Foam::CStringList::reset
(
std::initializer_list<const char* const> input
)
{
clear();
if (!input.size())
{
// Special handling of an empty list
argv_ = new char*[1];
argv_[0] = nullptr; // Final nullptr terminator
return 0;
}
// Count overall required string length, including each trailing nul char
for (const char* const s : input)
{
// nbytes_ += Foam::string::length(s) + 1
nbytes_ += (s ? strlen(s) : 0) + 1;
}
--nbytes_; // Do not include final nul char in overall count
argv_ = new char*[input.size()+1]; // Extra +1 for terminating nullptr
data_ = new char[nbytes_+1]; // Extra +1 for terminating nul char
argv_[0] = data_; // Starts here
for (const char* const s : input)
{
char *next = stringCopy(argv_[argc_], s);
argv_[++argc_] = next; // The start of next string
}
argv_[argc_] = nullptr; // Final nullptr terminator
return argc_;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const CStringList& list) Foam::Ostream& Foam::operator<<(Ostream& os, const CStringList& list)
{ {
const int n = list.size(); const int n = list.size();
for (int i = 0, space = 0; i < n; ++i) bool separator = false;
for (int i = 0; i < n; ++i)
{ {
const char* p = list.get(i); const char* p = list.get(i);
if (p && *p) if (p && *p)
{ {
if (space++) os << ' '; if (separator) os << ' ';
os << p; os << p;
separator = true;
} }
} }

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -55,6 +55,9 @@ Description
#include "stringList.H" #include "stringList.H"
#include "wordList.H" #include "wordList.H"
#include <algorithm> // std::copy
#include <utility> // std::initializer_list
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
@ -87,6 +90,11 @@ class CStringList
// Private Member Functions // Private Member Functions
//- Copy characters into dest as NUL-terminated string.
//
// \return location one-past end of dest (ie, the next destination)
static inline char* stringCopy(char* dest, const char* src);
//- Copy string characters into dest as NUL-terminated string. //- Copy string characters into dest as NUL-terminated string.
// Forces conversion of std::sub_match to string form // Forces conversion of std::sub_match to string form
// //
@ -99,6 +107,10 @@ class CStringList
int resetContent(const ListType& input); int resetContent(const ListType& input);
public:
// Generated Methods
//- No copy construct //- No copy construct
CStringList(const CStringList&) = delete; CStringList(const CStringList&) = delete;
@ -106,13 +118,18 @@ class CStringList
void operator=(const CStringList&) = delete; void operator=(const CStringList&) = delete;
public:
// Constructors // Constructors
//- Default construct, adding content later (via reset). //- Default construct, adding content later (via reset).
inline constexpr CStringList() noexcept; inline constexpr CStringList() noexcept;
//- Copy construct from a list of C-strings
// Copies the input characters.
inline explicit CStringList
(
std::initializer_list<const char* const> input
);
//- Copy construct from a list of strings //- Copy construct from a list of strings
// Copies the input characters. // Copies the input characters.
template<class StringType> template<class StringType>
@ -174,6 +191,10 @@ public:
//- Clear contents and free memory //- Clear contents and free memory
inline void clear(); inline void clear();
//- Copy the input list of C-strings
// \return number of arguments (argc)
int reset(std::initializer_list<const char* const> input);
//- Copy the input list of strings. //- Copy the input list of strings.
// \return number of arguments (argc) // \return number of arguments (argc)
template<class StringType> template<class StringType>

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -27,17 +27,18 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline char* Foam::CStringList::stringCopy(char* dest, const char* src)
{
dest = std::copy_n(src, (src ? strlen(src) : 0), dest);
*(dest++) = '\0';
return dest;
}
inline char* Foam::CStringList::stringCopy(char *dest, const std::string& src) inline char* Foam::CStringList::stringCopy(char *dest, const std::string& src)
{ {
// Like string::copy() but without extra checks dest = std::copy_n(src.data(), src.size(), dest);
const size_t len = src.length();
for (size_t i = 0; i < len; ++i)
{
*dest = src[i];
++dest;
}
*(dest++) = '\0'; *(dest++) = '\0';
return dest; return dest;
} }
@ -69,6 +70,17 @@ inline constexpr Foam::CStringList::CStringList() noexcept
{} {}
inline Foam::CStringList::CStringList
(
std::initializer_list<const char* const> input
)
:
CStringList()
{
reset(input);
}
template<class StringType> template<class StringType>
inline Foam::CStringList::CStringList(const UList<StringType>& input) inline Foam::CStringList::CStringList(const UList<StringType>& input)
: :

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -34,7 +34,7 @@ int Foam::CStringList::resetContent(const ListType& input)
{ {
clear(); clear();
if (input.empty()) if (!input.size())
{ {
// Special handling of an empty list // Special handling of an empty list
argv_ = new char*[1]; argv_ = new char*[1];
@ -43,9 +43,9 @@ int Foam::CStringList::resetContent(const ListType& input)
} }
// Count overall required string length, including each trailing nul char // Count overall required string length, including each trailing nul char
for (const auto& str : input) for (const auto& s : input)
{ {
nbytes_ += str.length() + 1; nbytes_ += s.length() + 1;
} }
--nbytes_; // Do not include final nul char in overall count --nbytes_; // Do not include final nul char in overall count
@ -54,10 +54,10 @@ int Foam::CStringList::resetContent(const ListType& input)
argv_[0] = data_; // Starts here argv_[0] = data_; // Starts here
for (const auto& str : input) for (const auto& s : input)
{ {
char *next = stringCopy(argv_[argc_], str); char *next = stringCopy(argv_[argc_], s);
argv_[++argc_] = next; // The start of next string argv_[++argc_] = next; // The start of next string
} }
argv_[argc_] = nullptr; // Final nullptr terminator argv_[argc_] = nullptr; // Final nullptr terminator
@ -76,7 +76,7 @@ Foam::CStringList::asList(int argc, const char * const argv[])
for (int i=0; i < argc; ++i) for (int i=0; i < argc; ++i)
{ {
list[i] = argv[i]; if (argv[i]) list[i] = argv[i];
} }
return list; return list;

View File

@ -366,16 +366,8 @@ void Foam::attachDetach::detachInterface
} }
// Create the master layer point map // Create the master layer point map
Map<label> masterLayerPointMap(2*mp.size()); Map<label> masterLayerPointMap(mp, addedPoints);
forAll(mp, pointi)
{
masterLayerPointMap.insert
(
mp[pointi],
addedPoints[pointi]
);
}
// Grab the list of faces of the master layer // Grab the list of faces of the master layer
const labelList masterCellFaces = masterCellFaceMap.toc(); const labelList masterCellFaces = masterCellFaceMap.toc();

View File

@ -562,16 +562,8 @@ void Foam::layerAdditionRemoval::addCellLayer
} }
// Create the master layer point map // Create the master layer point map
Map<label> masterLayerPointMap(2*mp.size()); Map<label> masterLayerPointMap(mp, addedPoints);
forAll(mp, pointi)
{
masterLayerPointMap.insert
(
mp[pointi],
addedPoints[pointi]
);
}
// Grab the list of faces of the master layer // Grab the list of faces of the master layer
const labelList masterCellFaces = masterCellFaceMap.toc(); const labelList masterCellFaces = masterCellFaceMap.toc();

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -155,9 +155,9 @@ void Foam::layerAdditionRemoval::removeCellLayer
} }
// Remove all points that will be collapsed // Remove all points that will be collapsed
forAll(ptc, pointi) for (const label pointi : ptc)
{ {
ref.setAction(polyRemovePoint(ptc[pointi])); ref.setAction(polyRemovePoint(pointi));
} }
// Grab all faces coming off points to be deleted. If the face // Grab all faces coming off points to be deleted. If the face
@ -167,15 +167,10 @@ void Foam::layerAdditionRemoval::removeCellLayer
// Make a map of all point to be removed, giving the master point label // Make a map of all point to be removed, giving the master point label
// for each of them // for each of them
Map<label> removedPointMap(2*ptc.size());
const labelList& meshPoints = const labelList& meshPoints =
mesh.faceZones()[faceZoneID_.index()]().meshPoints(); mesh.faceZones()[faceZoneID_.index()].patch().meshPoints();
forAll(ptc, pointi) Map<label> removedPointMap(ptc, meshPoints);
{
removedPointMap.insert(ptc[pointi], meshPoints[pointi]);
}
const labelListList& pf = mesh.pointFaces(); const labelListList& pf = mesh.pointFaces();

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2015-2022 OpenCFD Ltd. Copyright (C) 2015-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -277,16 +277,14 @@ void Foam::multiDirRefinement::refineHex8
{ {
// Create count 1 for original cells // Create count 1 for original cells
Map<label> hexCellSet(2*hexCells.size()); Map<label> hexCellSet(2*hexCells.size());
forAll(hexCells, i) for (const label celli : hexCells)
{ {
hexCellSet.insert(hexCells[i], 1); hexCellSet.insert(celli, 1);
} }
// Increment count // Increment count
forAll(consistentCells, i) for (const label celli : consistentCells)
{ {
const label celli = consistentCells[i];
auto iter = hexCellSet.find(celli); auto iter = hexCellSet.find(celli);
if (iter.good()) if (iter.good())

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2017-2020 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -29,6 +29,7 @@ License
#include "enrichedPatch.H" #include "enrichedPatch.H"
#include "OFstream.H" #include "OFstream.H"
#include "meshTools.H" #include "meshTools.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -65,12 +66,8 @@ void Foam::enrichedPatch::calcLocalFaces() const
// Invert mesh points and renumber faces using it // Invert mesh points and renumber faces using it
const labelList& mp = meshPoints(); const labelList& mp = meshPoints();
Map<label> mpLookup(2*mp.size()); Map<label> mpLookup(invertToMap(mp));
forAll(mp, mpi)
{
mpLookup.insert(mp[mpi], mpi);
}
// Create local faces. // Create local faces.
// Copy original faces and overwrite vertices after // Copy original faces and overwrite vertices after
@ -82,10 +79,7 @@ void Foam::enrichedPatch::calcLocalFaces() const
for (face& f : locFaces) for (face& f : locFaces)
{ {
for (label& pointi : f) inplaceRenumber(mpLookup, f);
{
pointi = *(mpLookup.cfind(pointi));
}
} }
} }

View File

@ -528,8 +528,9 @@ Foam::faPatchList Foam::faMesh::createPatchList
} }
// Create processor-processor definitions // Create processor-processor definitions
Map<label> procToDefLookup(2*procConnections.size()); Map<label> procToDefLookup;
{ {
procToDefLookup.reserve(procConnections.size());
faPatchDefs.reserve(faPatchDefs.size() + procConnections.size()); faPatchDefs.reserve(faPatchDefs.size() + procConnections.size());
for (const label otherProci : procConnections.sortedToc()) for (const label otherProci : procConnections.sortedToc())

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2019-2020 OpenCFD Ltd. Copyright (C) 2019-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -493,11 +493,8 @@ Foam::fvMeshSubset::interpolate
const labelList& meshPoints = basePatch.meshPoints(); const labelList& meshPoints = basePatch.meshPoints();
// Make addressing from mesh to patch point // Make addressing from mesh to patch point
Map<label> meshPointMap(2*meshPoints.size()); Map<label> meshPointMap(invertToMap(meshPoints));
forAll(meshPoints, localI)
{
meshPointMap.insert(meshPoints[localI], localI);
}
// Find which subpatch points originate from which patch point // Find which subpatch points originate from which patch point
const pointPatch& subPatch = sMesh.boundary()[patchi]; const pointPatch& subPatch = sMesh.boundary()[patchi];
@ -515,7 +512,7 @@ Foam::fvMeshSubset::interpolate
if (iter.good()) if (iter.good())
{ {
directAddressing[localI] = *iter; directAddressing[localI] = iter.val();
} }
} }

View File

@ -254,11 +254,7 @@ Foam::pointMVCWeight::pointMVCWeight
{ {
// Addressing - face vertices to local points and vice versa // Addressing - face vertices to local points and vice versa
const labelList& toGlobal = mesh.cellPoints()[cellIndex_]; const labelList& toGlobal = mesh.cellPoints()[cellIndex_];
Map<label> toLocal(2*toGlobal.size()); Map<label> toLocal(invertToMap(toGlobal));
forAll(toGlobal, i)
{
toLocal.insert(toGlobal[i], i);
}
// Initialise weights // Initialise weights

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2015-2023 OpenCFD Ltd. Copyright (C) 2015-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -1364,11 +1364,7 @@ Foam::label Foam::meshRefinement::splitFacesUndo
} }
{ {
Map<label> splitFaceToIndex(2*splitFaces.size()); Map<label> splitFaceToIndex(invertToMap(splitFaces));
forAll(splitFaces, i)
{
splitFaceToIndex.insert(splitFaces[i], i);
}
forAll(map.faceMap(), facei) forAll(map.faceMap(), facei)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2017 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -165,15 +165,8 @@ bool Foam::fileFormats::NASedgeFormat::read
// transfer to normal lists // transfer to normal lists
storedPoints().transfer(dynPoints); storedPoints().transfer(dynPoints);
pointId.shrink();
dynEdges.shrink();
// Build inverse mapping (NASTRAN pointId -> index) // Build inverse mapping (NASTRAN pointId -> index)
Map<label> mapPointId(2*pointId.size()); Map<label> mapPointId(invertToMap(pointId));
forAll(pointId, i)
{
mapPointId.insert(pointId[i], i);
}
// note which points were really used and which can be culled // note which points were really used and which can be culled
bitSet usedPoints(points().size()); bitSet usedPoints(points().size());

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -128,11 +128,7 @@ bool Foam::fileFormats::STARCDedgeFormat::read
); );
// Build inverse mapping (STARCD pointId -> index) // Build inverse mapping (STARCD pointId -> index)
Map<label> mapPointId(2*pointId.size()); Map<label> mapPointId(invertToMap(pointId));
forAll(pointId, i)
{
mapPointId.insert(pointId[i], i);
}
pointId.clear(); pointId.clear();
// Note which points were really used and which can be culled // Note which points were really used and which can be culled

View File

@ -130,12 +130,15 @@ Foam::regionSplit2D::regionSplit2D
} }
// In-place renumber the local regionI to global (compact) regionI // In-place renumber the local regionI to global (compact) regionI
globalIndex giCompact(compactRegionI);
forAllIters(regionToCompactAddr, iter)
{ {
*iter = giCompact.toGlobal(*iter); const label myProcOffset = globalIndex::calcOffset(compactRegionI);
forAllIters(regionToCompactAddr, iter)
{
iter.val() += myProcOffset;
}
} }
// Ensure regionToCompactAddr consistent across all processors // Ensure regionToCompactAddr consistent across all processors
// - not concerned about the op (keys are unique) // - not concerned about the op (keys are unique)
// - map size will be the number of regions in the set of faces // - map size will be the number of regions in the set of faces

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2017 OpenFOAM Foundation Copyright (C) 2011-2017 OpenFOAM Foundation
Copyright (C) 2018-2022,2024 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -32,6 +32,7 @@ License
#include "setToFaceZone.H" #include "setToFaceZone.H"
#include "setsToFaceZone.H" #include "setsToFaceZone.H"
#include "syncTools.H" #include "syncTools.H"
#include "ListOps.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
@ -177,11 +178,7 @@ void Foam::faceZoneSet::subset(const topoSet& set)
DynamicList<label> newAddressing(addressing_.size()); DynamicList<label> newAddressing(addressing_.size());
DynamicList<bool> newFlipMap(flipMap_.size()); DynamicList<bool> newFlipMap(flipMap_.size());
Map<label> faceToIndex(addressing_.size()); Map<label> faceToIndex(invertToMap(addressing_));
forAll(addressing_, i)
{
faceToIndex.insert(addressing_[i], i);
}
const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set);
@ -225,11 +222,7 @@ void Foam::faceZoneSet::addSet(const topoSet& set)
DynamicList<label> newAddressing(addressing_); DynamicList<label> newAddressing(addressing_);
DynamicList<bool> newFlipMap(flipMap_); DynamicList<bool> newFlipMap(flipMap_);
Map<label> faceToIndex(addressing_.size()); Map<label> faceToIndex(invertToMap(addressing_));
forAll(addressing_, i)
{
faceToIndex.insert(addressing_[i], i);
}
const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set);
@ -277,11 +270,7 @@ void Foam::faceZoneSet::subtractSet(const topoSet& set)
const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set); const faceZoneSet& zoneSet = refCast<const faceZoneSet>(set);
Map<label> faceToIndex(zoneSet.addressing().size()); Map<label> faceToIndex(invertToMap(zoneSet.addressing()));
forAll(zoneSet.addressing(), i)
{
faceToIndex.insert(zoneSet.addressing()[i], i);
}
forAll(addressing_, i) forAll(addressing_, i)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2016-2017 Wikki Ltd Copyright (C) 2016-2017 Wikki Ltd
Copyright (C) 2018-2022 OpenCFD Ltd. Copyright (C) 2018-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -35,6 +35,7 @@ License
#include "OSspecific.H" #include "OSspecific.H"
#include "Map.H" #include "Map.H"
#include "SLList.H" #include "SLList.H"
#include "ListOps.H"
#include "globalMeshData.H" #include "globalMeshData.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -275,17 +276,9 @@ void Foam::faMeshDecomposition::decomposeMesh()
ioAddr.rename("faceProcAddressing"); ioAddr.rename("faceProcAddressing");
labelIOList fvFaceProcAddressing(ioAddr); labelIOList fvFaceProcAddressing(ioAddr);
fvFaceProcAddressingHash.reserve(fvFaceProcAddressing.size()); fvFaceProcAddressingHash = invertToMap(fvFaceProcAddressing);
}
forAll(fvFaceProcAddressing, facei)
{
fvFaceProcAddressingHash.insert
(
fvFaceProcAddressing[facei],
facei
);
}
};
const labelList& curProcFaceAddressing = procFaceAddressing_[procI]; const labelList& curProcFaceAddressing = procFaceAddressing_[procI];
@ -1116,12 +1109,8 @@ bool Foam::faMeshDecomposition::writeDecomposition()
Info<< "\nConstructing processor FA meshes" << endl; Info<< "\nConstructing processor FA meshes" << endl;
// Make a lookup map for globally shared points // Make a lookup map for globally shared points
Map<label> sharedPointLookup(2*globallySharedPoints_.size()); Map<label> sharedPointLookup(invertToMap(globallySharedPoints_));
forAll(globallySharedPoints_, pointi)
{
sharedPointLookup.insert(globallySharedPoints_[pointi], pointi);
}
label maxProcFaces = 0; label maxProcFaces = 0;
label totProcFaces = 0; label totProcFaces = 0;

View File

@ -5,7 +5,7 @@
\\ / A nd | www.openfoam.com \\ / A nd | www.openfoam.com
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2020-2022 OpenCFD Ltd. Copyright (C) 2020-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -177,18 +177,13 @@ bool Foam::fileFormats::ABAQUSsurfaceFormat<Face>::read
// Extra safety // Extra safety
if (newToOldZone.empty()) if (newToOldZone.empty())
{ {
newToOldZone.resize(1, Zero); newToOldZone.push_back(0);
}
Map<label> oldToNewZone(2*newToOldZone.size());
forAll(newToOldZone, zonei)
{
oldToNewZone.set(newToOldZone[zonei], zonei);
} }
wordList zoneNames(newToOldZone.size()); wordList zoneNames(newToOldZone.size());
labelList zoneSizes(newToOldZone.size(), Zero); labelList zoneSizes(newToOldZone.size(), Foam::zero{});
Map<label> oldToNewZone(invertToMap(newToOldZone));
forAllConstIters(reader.elsetMap_, iter) forAllConstIters(reader.elsetMap_, iter)
{ {

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2015 OpenFOAM Foundation Copyright (C) 2011-2015 OpenFOAM Foundation
Copyright (C) 2017-2023 OpenCFD Ltd. Copyright (C) 2017-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -493,16 +493,11 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
// Transfer to normal lists // Transfer to normal lists
this->storedPoints().transfer(dynPoints); this->storedPoints().transfer(dynPoints);
pointId.shrink();
dynFaces.shrink(); dynFaces.shrink();
// Build inverse mapping (NASTRAN pointId -> index) // Build inverse mapping (NASTRAN pointId -> index)
Map<label> mapPointId; Map<label> mapPointId(invertToMap(pointId));
mapPointId.reserve(pointId.size()); pointId.clearStorage();
for (const label pointi : pointId)
{
mapPointId.insert(pointi, mapPointId.size());
}
// Relabel faces // Relabel faces
// ~~~~~~~~~~~~~ // ~~~~~~~~~~~~~
@ -513,7 +508,6 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
vert = mapPointId[vert]; vert = mapPointId[vert];
} }
} }
pointId.clearStorage();
mapPointId.clear(); mapPointId.clear();
DebugInfo DebugInfo

View File

@ -6,7 +6,7 @@
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2016-2022 OpenCFD Ltd. Copyright (C) 2016-2024 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
@ -107,11 +107,7 @@ bool Foam::fileFormats::STARCDsurfaceFormat<Face>::read
); );
// Build inverse mapping (STARCD pointId -> index) // Build inverse mapping (STARCD pointId -> index)
Map<label> mapPointId(2*pointId.size()); Map<label> mapPointId(invertToMap(pointId));
forAll(pointId, i)
{
mapPointId.insert(pointId[i], i);
}
pointId.clear(); pointId.clear();