Commit 708c1b5c authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: simplify ensightCells/ensightFaces with labelRange

- can avoid allocating/reallocating SubList

STYLE: don't need NamedEnum for ensightCells, ensightFaces lookup
parent b4f6484d
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -27,24 +27,13 @@ License
#include "error.H"
#include "polyMesh.H"
#include "cellModeller.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::label Foam::ensightCells::nTypes = 5;
namespace Foam
{
template<>
const char* Foam::NamedEnum
<
Foam::ensightCells::elemType,
5
>::names[] = { "tetra4", "pyramid5", "penta6", "hexa8", "nfaced" };
}
const Foam::NamedEnum<Foam::ensightCells::elemType, 5>
Foam::ensightCells::elemEnum;
const char* Foam::ensightCells::elemNames[5] =
{ "tetra4", "pyramid5", "penta6", "hexa8", "nfaced" };
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -63,9 +52,8 @@ void Foam::ensightCells::resizeAll()
n = 0;
forAll(sizes_, typei)
{
deleteDemandDrivenData(lists_[typei]);
lists_[typei] = new SubList<label>(address_, sizes_[typei], n);
slices_[typei].setStart(n);
slices_[typei].setSize(sizes_[typei]);
n += sizes_[typei];
}
......@@ -78,16 +66,10 @@ Foam::ensightCells::ensightCells(const label partIndex)
:
index_(partIndex),
address_(),
sizes_(Zero),
lists_()
slices_(),
sizes_(Zero)
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typei)
{
lists_[typei] = nullptr;
}
resizeAll(); // adjust allocation
resizeAll(); // adjust allocation/sizing
}
......@@ -95,22 +77,16 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
:
index_(obj.index_),
address_(obj.address_),
sizes_(),
lists_()
slices_(),
sizes_()
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typei)
{
lists_[typei] = nullptr;
}
// Total (reduced) sizes
// Save the total (reduced) sizes
FixedList<label, 5> totSizes = obj.sizes_;
// Local sizes
// Need local sizes for the resize operation
this->sizes_ = obj.sizes();
resizeAll(); // adjust allocation
resizeAll(); // adjust allocation/sizing
// Restore total (reduced) sizes
this->sizes_ = totSizes;
......@@ -120,13 +96,7 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightCells::~ensightCells()
{
forAll(lists_, typei)
{
deleteDemandDrivenData(lists_[typei]);
}
address_.clear();
}
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -134,27 +104,15 @@ Foam::ensightCells::~ensightCells()
Foam::FixedList<Foam::label, 5> Foam::ensightCells::sizes() const
{
FixedList<label, 5> count;
forAll(lists_, typei)
forAll(slices_, typei)
{
count[typei] = lists_[typei]->size();
count[typei] = slices_[typei].size();
}
return count;
}
Foam::label Foam::ensightCells::offset(const enum elemType what) const
{
label n = 0;
for (label typei = 0; typei < label(what); ++typei)
{
n += lists_[typei]->size();
}
return n;
}
Foam::label Foam::ensightCells::total() const
{
label n = 0;
......@@ -175,9 +133,10 @@ void Foam::ensightCells::clear()
void Foam::ensightCells::reduce()
{
// No listCombineGather, listCombineScatter for FixedList
forAll(sizes_, typei)
{
sizes_[typei] = lists_[typei]->size();
sizes_[typei] = slices_[typei].size();
Foam::reduce(sizes_[typei], sumOp<label>());
}
}
......@@ -185,9 +144,13 @@ void Foam::ensightCells::reduce()
void Foam::ensightCells::sort()
{
forAll(lists_, typei)
forAll(slices_, typei)
{
Foam::sort(*(lists_[typei]));
if (slices_[typei].size())
{
SubList<label> idLst(address_, slices_[typei]);
Foam::sort(idLst);
}
}
}
......@@ -240,7 +203,7 @@ void Foam::ensightCells::classify
}
resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes
sizes_ = Zero; // reset sizes - use for local indexing here
// Assign cell-id per shape type
for (label listi = 0; listi < sz; ++listi)
......@@ -267,7 +230,10 @@ void Foam::ensightCells::classify
}
// eg, the processor local cellId
lists_[what]->operator[](sizes_[what]++) = id;
UList<label> slice = address_[slices_[what]];
slice[sizes_[what]] = id;
sizes_[what]++;
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -35,8 +35,6 @@ Description
#include "labelList.H"
#include "FixedList.H"
#include "SubList.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -58,18 +56,18 @@ public:
//- Addressable ensight element types
enum elemType
{
TETRA4,
PYRAMID5,
PENTA6,
HEXA8,
NFACED
TETRA4, //!< "tetra4"
PYRAMID5, //!< "pyramid5"
PENTA6, //!< "penta6"
HEXA8, //!< "hexa8"
NFACED //!< "nfaced"
};
//- Number of element types (5)
static const label nTypes;
//- The Ensight names for each element type
static const NamedEnum<elemType, 5> elemEnum;
//- The ensight element type names
static const char* elemNames[5];
// Static Member Functions
......@@ -86,17 +84,16 @@ private:
// The ensight part number is typically this value +1.
label index_;
//- Linear list of ids, sub-sectioned per element type via SubLists
//- Linear list of ids, sub-sectioned per element type by sub-lists
labelList address_;
//- Slices (sub-lists) of the address ids for each element type.
FixedList<labelRange, 5> slices_;
//- List of global sizes for each element type.
// Used temporarily for local sizes when building the element lists.
FixedList<label, 5> sizes_;
//- List of ids for each element type.
// Managed via pointers, since a SubList cannot be relocated/resized.
FixedList<SubList<label>*, 5> lists_;
// Private Member Functions
......@@ -115,7 +112,7 @@ public:
ensightCells(label partIndex = 0);
//- Copy constructor. Needed for lists etc.
ensightCells(const ensightCells&);
ensightCells(const ensightCells& obj);
//- Destructor
......@@ -135,6 +132,9 @@ public:
//- The processor local size of all elements.
inline label size() const;
//- The processor local size of the specified element type.
inline label size(const enum elemType) const;
//- The global number of the specified element type.
// This value is only meaningful after a reduce operation.
inline label total(const enum elemType) const;
......@@ -151,23 +151,23 @@ public:
FixedList<label, 5> sizes() const;
//- Processor local starting offset of element type.
label offset(const enum elemType what) const;
inline label offset(const enum elemType what) const;
//- Return the (local) cell ids of the specified element type
inline const labelUList& cellIds(const enum elemType) const;
inline const labelUList cellIds(const enum elemType) const;
//- Return the cell ids of all elements
inline const labelUList& cellIds() const;
// Edit
// Edit
//- Classify cell types and set the element lists.
// The optional indirect addressing can be used when classifying
// groups of cells (eg, from a cellZone etc).
void classify
(
const polyMesh&,
const polyMesh& mesh,
const labelUList& addressing = labelUList::null()
);
......
......@@ -29,7 +29,7 @@ License
inline const char* Foam::ensightCells::key(const enum elemType what)
{
return elemEnum[what];
return elemNames[what];
}
......@@ -63,20 +63,24 @@ inline Foam::label Foam::ensightCells::total(const enum elemType what) const
}
inline const Foam::labelUList& Foam::ensightCells::cellIds
inline Foam::label Foam::ensightCells::size(const enum elemType what) const
{
return slices_[what].size();
}
inline Foam::label Foam::ensightCells::offset(const enum elemType what) const
{
return slices_[what].start();
}
inline const Foam::labelUList Foam::ensightCells::cellIds
(
const enum elemType what
) const
{
if (!lists_[what])
{
FatalErrorInFunction
<< "Accessing unallocated sublist for elem-type: "
<< elemEnum[what]
<< exit(FatalError);
}
return *(lists_[what]);
return address_[slices_[what]];
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -27,24 +27,13 @@ License
#include "error.H"
#include "polyMesh.H"
#include "ListOps.H"
#include "demandDrivenData.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::label Foam::ensightFaces::nTypes = 3;
namespace Foam
{
template<>
const char* Foam::NamedEnum
<
Foam::ensightFaces::elemType,
3
>::names[] = { "tria3", "quad4", "nsided" };
}
const Foam::NamedEnum<Foam::ensightFaces::elemType, 3>
Foam::ensightFaces::elemEnum;
const char* Foam::ensightFaces::elemNames[3] =
{ "tria3", "quad4", "nsided" };
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
......@@ -99,9 +88,8 @@ void Foam::ensightFaces::resizeAll()
n = 0;
forAll(sizes_, typei)
{
deleteDemandDrivenData(lists_[typei]);
lists_[typei] = new SubList<label>(address_, sizes_[typei], n);
slices_[typei].setStart(n);
slices_[typei].setSize(sizes_[typei]);
n += sizes_[typei];
}
......@@ -118,16 +106,10 @@ Foam::ensightFaces::ensightFaces(label partIndex)
index_(partIndex),
address_(),
flipMap_(),
sizes_(Zero),
lists_()
slices_(),
sizes_(Zero)
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typei)
{
lists_[typei] = nullptr;
}
resizeAll(); // adjust allocation
resizeAll(); // adjust allocation/sizing
}
......@@ -136,22 +118,16 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj)
index_(obj.index_),
address_(obj.address_),
flipMap_(obj.flipMap_),
sizes_(),
lists_()
slices_(),
sizes_()
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typei)
{
lists_[typei] = nullptr;
}
// Total (reduced) sizes
// Save the total (reduced) sizes
FixedList<label, 3> totSizes = obj.sizes_;
// Local sizes
// Need local sizes for the resize operation
this->sizes_ = obj.sizes();
resizeAll(); // adjust allocation
resizeAll(); // adjust allocation/sizing
// Restore total (reduced) sizes
this->sizes_ = totSizes;
......@@ -161,14 +137,7 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightFaces::~ensightFaces()
{
forAll(lists_, typei)
{
deleteDemandDrivenData(lists_[typei]);
}
address_.clear();
flipMap_.clear();
}
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......@@ -176,27 +145,15 @@ Foam::ensightFaces::~ensightFaces()
Foam::FixedList<Foam::label, 3> Foam::ensightFaces::sizes() const
{
FixedList<label, 3> count;
forAll(lists_, typei)
forAll(slices_, typei)
{
count[typei] = lists_[typei]->size();
count[typei] = slices_[typei].size();
}
return count;
}
Foam::label Foam::ensightFaces::offset(const enum elemType what) const
{
label n = 0;
for (label typei = 0; typei < label(what); ++typei)
{
n += lists_[typei]->size();
}
return n;
}
Foam::label Foam::ensightFaces::total() const
{
label n = 0;
......@@ -217,9 +174,10 @@ void Foam::ensightFaces::clear()
void Foam::ensightFaces::reduce()
{
// No listCombineGather, listCombineScatter for FixedList
forAll(sizes_, typei)
{
sizes_[typei] = lists_[typei]->size();
sizes_[typei] = slices_[typei].size();
Foam::reduce(sizes_[typei], sumOp<label>());
}
}
......@@ -229,20 +187,15 @@ void Foam::ensightFaces::sort()
{
if (flipMap_.size() == address_.size())
{
// sort flip map too
// Must sort flip map as well
labelList order;
label start = 0;
forAll(lists_, typei)
forAll(slices_, typei)
{
SubList<label>& idLst = *(lists_[typei]);
const label sz = idLst.size();
if (sz)
if (slices_[typei].size())
{
SubList<bool> flip(flipMap_, sz, start);
start += sz; // for next sub-list
SubList<label> idLst(address_, slices_[typei]);
SubList<bool> flip(flipMap_, slices_[typei]);
Foam::sortedOrder(idLst, order);
......@@ -254,11 +207,16 @@ void Foam::ensightFaces::sort()
else
{
// no flip-maps, simpler to sort
forAll(lists_, typei)
forAll(slices_, typei)
{
Foam::sort(*(lists_[typei]));
if (slices_[typei].size())
{
SubList<label> idLst(address_, slices_[typei]);
Foam::sort(idLst);
}
}
flipMap_.clear(); // for safety
flipMap_.clear(); // for extra safety
}
}
......@@ -278,7 +236,7 @@ void Foam::ensightFaces::classify(const faceList& faces)
}
resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes
sizes_ = Zero; // reset sizes - use for local indexing here
// Assign face-id per shape type
for (label listi = 0; listi < sz; ++listi)
......@@ -318,7 +276,7 @@ void Foam::ensightFaces::classify
}
resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes
sizes_ = Zero; // reset sizes - use for local indexing here
if (useFlip)
{
......@@ -330,11 +288,11 @@ void Foam::ensightFaces::classify
for (label listi = 0; listi < sz; ++listi)
{
const label faceId = addressing[listi];
const bool flip = useFlip && flipMap[listi];
const bool doFlip = useFlip && flipMap[listi];
if (!exclude[faceId])
{
add(faces[faceId], faceId, flip);
add(faces[faceId], faceId, doFlip);
}
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -37,7 +37,6 @@ Description
#include "faceList.H"
#include "FixedList.H"
#include "PackedBoolList.H"
#include "NamedEnum.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -57,16 +56,16 @@ public:
//- Addressable ensight element types
enum elemType
{
TRIA3,
QUAD4,
NSIDED
TRIA3, //!< "tria3"
QUAD4, //!< "quad4"
NSIDED //!< "nsided"
};
//- Number of element types (3)
static const label nTypes;
//- The Ensight names for each element type
static const NamedEnum<elemType, 3> elemEnum;
//- The ensight element type names
static const char* elemNames[3];
// Static Member Functions
......@@ -83,28 +82,27 @@ private:
// The ensight part number is typically this value +1.
label index_;
//- Linear list of ids, sub-sectioned per element type via SubLists
//- Linear list of ids, sub-sectioned per element type by sub-lists
labelList address_;
//- Linear list of face-flips
boolList flipMap_;
//- Slices (sub-lists) of the address and flips for each element type.
FixedList<labelRange, 3> slices_;
//- List of global sizes for each element type.
// Used temporarily for local sizes when building the element lists.
FixedList<label, 3> sizes_;
//- SubLists of ids for each element type.
// Managed via pointers, since a SubList cannot be relocated/resized.
FixedList<SubList<label>*, 3> lists_;