ENH: promote ListOps::identity to Foam::identity
- becoming more frequently used and there is no ambiguity in calling parameters either - identity(label) vs identity(labelUList&). Provide both int32 and int64 versions.
This commit is contained in:
parent
ef92d31493
commit
d9f0587416
@ -133,7 +133,7 @@ int main(int argc, char *argv[])
|
||||
DynamicList<label, 64> list1;
|
||||
|
||||
list1.resize(4);
|
||||
ListOps::identity(list1);
|
||||
Foam::identity(list1);
|
||||
|
||||
list1.resize(3);
|
||||
printInfo("", list1);
|
||||
@ -152,7 +152,7 @@ int main(int argc, char *argv[])
|
||||
DynamicList<label, 64> list2;
|
||||
|
||||
list2.resize(5);
|
||||
ListOps::identity(list2);
|
||||
Foam::identity(list2);
|
||||
|
||||
Info<< "initial list" << nl;
|
||||
printInfo("", list2);
|
||||
|
@ -147,7 +147,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
{
|
||||
List<label> ident(15);
|
||||
std::iota(ident.begin(), ident.end(), 0);
|
||||
Foam::identity(ident, 0);
|
||||
|
||||
Info<<"Ident:";
|
||||
forAllConstIters(ident, iter)
|
||||
@ -546,10 +546,10 @@ int main(int argc, char *argv[])
|
||||
Info<< "scalars: " << flatOutput(scalars) << endl;
|
||||
}
|
||||
|
||||
#if WM_LABEL_SIZE == 32
|
||||
// #if WM_LABEL_SIZE == 32
|
||||
{
|
||||
List<int64_t> input(10);
|
||||
std::iota(input.begin(), input.end(), 50);
|
||||
Foam::identity(input, 50);
|
||||
|
||||
auto output = ListOps::create<label>
|
||||
(
|
||||
@ -558,10 +558,10 @@ int main(int argc, char *argv[])
|
||||
);
|
||||
Info<< "label (from int64): " << flatOutput(output) << endl;
|
||||
}
|
||||
#elif WM_LABEL_SIZE == 64
|
||||
// #elif WM_LABEL_SIZE == 64
|
||||
{
|
||||
List<int32_t> input(10);
|
||||
std::iota(input.begin(), input.end(), 50);
|
||||
Foam::identity(input, 50);
|
||||
|
||||
auto output = ListOps::create<label>
|
||||
(
|
||||
@ -570,7 +570,7 @@ int main(int argc, char *argv[])
|
||||
);
|
||||
Info<< "label (from int32): " << flatOutput(output) << endl;
|
||||
}
|
||||
#endif
|
||||
// #endif
|
||||
|
||||
|
||||
labelHashSet locations{ -15, 5, 10, 15, 25, 35 };
|
||||
|
@ -59,7 +59,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
{
|
||||
List<label> ident(25);
|
||||
std::iota(ident.begin(), ident.end(), 0);
|
||||
Foam::identity(ident, 0);
|
||||
|
||||
print(ident);
|
||||
|
||||
@ -108,7 +108,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// This is also possible since we hold a concrete pointer/size
|
||||
// and not an intermediate
|
||||
ListOps::identity(sub.reset(ident, 8, 8));
|
||||
Foam::identity(sub.reset(ident, 8, 8));
|
||||
print(sub);
|
||||
print(ident);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -523,8 +523,8 @@ int main(int argc, char *argv[])
|
||||
labelList faceIds;
|
||||
|
||||
// Markup master face ids
|
||||
faceIds.setSize(masterPatch.size());
|
||||
std::iota(faceIds.begin(), faceIds.end(), masterPatch.start());
|
||||
faceIds.resize_nocopy(masterPatch.size());
|
||||
Foam::identity(faceIds, masterPatch.start());
|
||||
|
||||
stitcher.clear();
|
||||
stitcher.setSize(1);
|
||||
@ -569,8 +569,8 @@ int main(int argc, char *argv[])
|
||||
).resetAddressing(std::move(faceIds), false);
|
||||
|
||||
// Markup slave face ids
|
||||
faceIds.setSize(slavePatch.size());
|
||||
std::iota(faceIds.begin(), faceIds.end(), slavePatch.start());
|
||||
faceIds.resize_nocopy(slavePatch.size());
|
||||
Foam::identity(faceIds, slavePatch.start());
|
||||
|
||||
mesh.faceZones()
|
||||
(
|
||||
|
@ -62,7 +62,7 @@ $(ints)/int32/int32IO.C
|
||||
$(ints)/int64/int64.C
|
||||
$(ints)/int64/int64IO.C
|
||||
$(ints)/label/label.C
|
||||
$(ints)/lists/labelList.C
|
||||
$(ints)/lists/labelLists.C
|
||||
$(ints)/lists/labelIOList.C
|
||||
$(ints)/lists/labelListIOList.C
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -25,8 +25,6 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ListOps.H" // For identity
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -77,7 +75,7 @@ inline void Foam::SortList<T>::reset()
|
||||
auto& addr = this->indices();
|
||||
|
||||
addr.resize_nocopy(this->values().size());
|
||||
ListOps::identity(addr);
|
||||
Foam::identity(addr, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -89,7 +87,7 @@ inline void Foam::SortList<T>::sort(const Compare& comp)
|
||||
auto& addr = this->indices();
|
||||
|
||||
addr.resize_nocopy(vals.size());
|
||||
ListOps::identity(addr);
|
||||
Foam::identity(addr, 0);
|
||||
|
||||
std::stable_sort
|
||||
(
|
||||
|
@ -481,14 +481,7 @@ void Foam::sortedOrder
|
||||
// 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::identity(order, 0);
|
||||
Foam::stableSort(order, comp);
|
||||
}
|
||||
|
||||
|
@ -431,7 +431,8 @@ Istream& operator>>(Istream& is, List<T>& list)
|
||||
|
||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||
|
||||
//- Return an identity map of the given length with (map[i] == i)
|
||||
//- Return an identity map of the given length with (map[i] == i),
|
||||
//- works like std::iota() but returning a list of label values.
|
||||
// Optionally with an alternative start index, so that (map[i] == i+start)
|
||||
labelList identity(const label len, label start=0);
|
||||
|
||||
|
@ -201,7 +201,7 @@ public:
|
||||
|
||||
bool operator()(const label a, const label b) const
|
||||
{
|
||||
return values[a] < values[b];
|
||||
return (values[a] < values[b]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -217,7 +217,7 @@ public:
|
||||
|
||||
bool operator()(const label a, const label b) const
|
||||
{
|
||||
return values[b] < values[a];
|
||||
return (values[b] < values[a]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -677,6 +677,14 @@ Ostream& operator<<(Ostream& os, const std::vector<T>& list);
|
||||
|
||||
// * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
|
||||
|
||||
//- Fill an identity map with (map[i] == i), works like std::iota().
|
||||
// Optionally with an alternative start index, so that (map[i] == i+start)
|
||||
void identity(UList<int32_t>& map, int32_t start = 0);
|
||||
|
||||
//- Fill an identity map with (map[i] == i), works like std::iota().
|
||||
// Optionally with an alternative start index, so that (map[i] == i+start)
|
||||
void identity(UList<int64_t>& map, int64_t start = 0);
|
||||
|
||||
//- Sort the list
|
||||
template<class T>
|
||||
void sort(UList<T>& list);
|
||||
|
@ -200,12 +200,6 @@ void Foam::inplaceReorder
|
||||
}
|
||||
|
||||
|
||||
void Foam::ListOps::identity(labelUList& map, label start)
|
||||
{
|
||||
std::iota(map.begin(), map.end(), start);
|
||||
}
|
||||
|
||||
|
||||
void Foam::ListOps::unionEqOp::operator()
|
||||
(
|
||||
labelList& x,
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2017 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -593,7 +593,7 @@ struct less
|
||||
|
||||
bool operator()(const label a, const label b) const
|
||||
{
|
||||
return values[a] < values[b];
|
||||
return (values[a] < values[b]);
|
||||
}
|
||||
};
|
||||
|
||||
@ -611,14 +611,19 @@ struct greater
|
||||
|
||||
bool operator()(const label a, const label b) const
|
||||
{
|
||||
return values[b] < values[a];
|
||||
return (values[b] < values[a]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//- Set identity map with (map[i] == i)
|
||||
//- Fill an identity map with (map[i] == i)
|
||||
// Optionally with an alternative start index, so that (map[i] == i+start)
|
||||
void identity(labelUList& map, label start=0);
|
||||
FOAM_DEPRECATED_STRICT(2023-10, "Foam::identity(...)")
|
||||
inline void identity(labelUList& map, label start = 0)
|
||||
{
|
||||
Foam::identity(map, start);
|
||||
}
|
||||
|
||||
|
||||
//- Count the number of matching entries.
|
||||
// When start is specified, any occurrences before start are ignored.
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,8 +26,6 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ListOps.H" // For identity
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<class T>
|
||||
@ -136,7 +134,7 @@ template<class T>
|
||||
void Foam::SortableList<T>::partialSort(label n, label start)
|
||||
{
|
||||
indices_.resize_nocopy(this->size());
|
||||
ListOps::identity(indices_);
|
||||
Foam::identity(indices_, 0);
|
||||
|
||||
// Forward partial sort of indices
|
||||
std::partial_sort
|
||||
@ -156,7 +154,7 @@ template<class T>
|
||||
void Foam::SortableList<T>::partialReverseSort(label n, label start)
|
||||
{
|
||||
indices_.resize_nocopy(this->size());
|
||||
ListOps::identity(indices_);
|
||||
Foam::identity(indices_, 0);
|
||||
|
||||
// Reverse partial sort of indices
|
||||
std::partial_sort
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -63,13 +63,7 @@ void Foam::sortedOrder
|
||||
// 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::identity(order, 0);
|
||||
|
||||
std::stable_sort(order.begin(), order.end(), comp);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2013-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2020 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -28,19 +28,17 @@ License
|
||||
|
||||
#include "SquareMatrix.H"
|
||||
#include "RectangularMatrix.H"
|
||||
#include "labelList.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
template<class Type>
|
||||
template<class CompOp>
|
||||
Foam::List<Foam::label> Foam::SquareMatrix<Type>::sortPermutation
|
||||
Foam::labelList Foam::SquareMatrix<Type>::sortPermutation
|
||||
(
|
||||
CompOp& compare
|
||||
) const
|
||||
{
|
||||
List<label> p(this->m());
|
||||
std::iota(p.begin(), p.end(), 0);
|
||||
labelList p = Foam::identity(this->m());
|
||||
std::sort
|
||||
(
|
||||
p.begin(),
|
||||
@ -53,7 +51,7 @@ Foam::List<Foam::label> Foam::SquareMatrix<Type>::sortPermutation
|
||||
|
||||
|
||||
template<class Type>
|
||||
void Foam::SquareMatrix<Type>::applyPermutation(const List<label>& p)
|
||||
void Foam::SquareMatrix<Type>::applyPermutation(const labelUList& p)
|
||||
{
|
||||
#ifdef FULLDEBUG
|
||||
if (this->m() != p.size())
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2019-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -40,8 +40,8 @@ SourceFiles
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef SquareMatrix_H
|
||||
#define SquareMatrix_H
|
||||
#ifndef Foam_SquareMatrix_H
|
||||
#define Foam_SquareMatrix_H
|
||||
|
||||
#include "Matrix.H"
|
||||
#include "Identity.H"
|
||||
@ -65,7 +65,6 @@ class SquareMatrix
|
||||
:
|
||||
public Matrix<SquareMatrix<Type>, Type>
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
// Generated Methods
|
||||
@ -172,14 +171,13 @@ public:
|
||||
|
||||
// Sort
|
||||
|
||||
//- Return a sort permutation labelList according to
|
||||
//- a given comparison on the diagonal entries
|
||||
//- Return a sort permutation using the given comparison operator
|
||||
//- on the diagonal entries
|
||||
template<class CompOp>
|
||||
List<label> sortPermutation(CompOp& compare) const;
|
||||
labelList sortPermutation(CompOp& compare) const;
|
||||
|
||||
//- Column-reorder this Matrix according to
|
||||
//- a given permutation labelList
|
||||
void applyPermutation(const List<label>& p);
|
||||
//- Column-reorder this Matrix according to the given permutation
|
||||
void applyPermutation(const labelUList& p);
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -26,7 +26,7 @@ License
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "ListOps.H" // sortedOrder, ListOps::identity
|
||||
#include "ListOps.H" // sortedOrder
|
||||
|
||||
// * * * * * * * * * * * * * * * Implementation * * * * * * * * * * * * * * //
|
||||
|
||||
@ -230,7 +230,7 @@ Foam::label Foam::Detail::mergePoints
|
||||
// Setup initial identity +1 mapping for pointToUnique
|
||||
// The +1 allows negatives to mark duplicates
|
||||
|
||||
ListOps::identity(pointToUnique, 1);
|
||||
Foam::identity(pointToUnique, 1);
|
||||
|
||||
// The newPointCounts is an offsets table that we use to walk
|
||||
// across the adjacency list (lookupMerged), picking the original
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2019 OpenCFD Ltd.
|
||||
Copyright (C) 2019-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -30,11 +30,24 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * Global Data Members * * * * * * * * * * * * * //
|
||||
|
||||
// This was deprecated (2019-02) in favour of labelList::null()
|
||||
const Foam::labelList Foam::emptyLabelList;
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::identity(Foam::UList<int32_t>& map, int32_t start)
|
||||
{
|
||||
std::iota(map.begin(), map.end(), start);
|
||||
}
|
||||
|
||||
|
||||
void Foam::identity(Foam::UList<int64_t>& map, int64_t start)
|
||||
{
|
||||
std::iota(map.begin(), map.end(), start);
|
||||
}
|
||||
|
||||
|
||||
Foam::labelList Foam::identity(const label len, label start)
|
||||
{
|
||||
labelList map(len);
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -161,16 +161,16 @@ Foam::label Foam::ensightCells::meshPointMapppings
|
||||
// Non-parallel
|
||||
|
||||
nPoints = mesh.nPoints();
|
||||
pointToGlobal.resize(nPoints);
|
||||
pointToGlobal.resize_nocopy(nPoints);
|
||||
|
||||
if (allCells)
|
||||
{
|
||||
// All cells used, and thus all points
|
||||
|
||||
uniqueMeshPointLabels.resize(nPoints);
|
||||
uniqueMeshPointLabels.resize_nocopy(nPoints);
|
||||
|
||||
ListOps::identity(pointToGlobal);
|
||||
ListOps::identity(uniqueMeshPointLabels);
|
||||
Foam::identity(pointToGlobal);
|
||||
Foam::identity(uniqueMeshPointLabels);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2020-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2020-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -88,8 +88,8 @@ void Foam::ensightFaces::write
|
||||
nPoints = pp.meshPoints().size();
|
||||
uniqueMeshPointLabels = pp.meshPoints();
|
||||
|
||||
pointToGlobal.resize(nPoints);
|
||||
ListOps::identity(pointToGlobal);
|
||||
pointToGlobal.resize_nocopy(nPoints);
|
||||
Foam::identity(pointToGlobal);
|
||||
}
|
||||
|
||||
ensightOutput::Detail::writeCoordinates
|
||||
|
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2022 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2023 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -858,7 +858,7 @@ void Foam::vtk::vtuSizing::populateArrays
|
||||
|
||||
// May have been done by caller,
|
||||
// but for additional safety set an identity mapping
|
||||
ListOps::identity(cellMap);
|
||||
Foam::identity(cellMap);
|
||||
|
||||
// ===========================================
|
||||
// Adjust vertOffset for all cells
|
||||
|
Loading…
Reference in New Issue
Block a user