BUG: incorrect addressing in ensight faces/cells (issue #334)

- was erroneously using global sizing for offsets instead the processor
  local sizing.

--

STYLE: adjust variable naming, indentation for consistency
This commit is contained in:
Mark Olesen
2016-12-12 17:52:02 +01:00
parent f3d8be7abe
commit 9041c9083e
4 changed files with 165 additions and 194 deletions

View File

@ -49,41 +49,25 @@ const Foam::NamedEnum<Foam::ensightCells::elemType, 5>
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline Foam::label Foam::ensightCells::offset
(
const enum elemType what,
const label i
) const
{
label n = i;
for (label typeI = 0; typeI < label(what); ++typeI)
{
n += sizes_[typeI];
}
return n;
}
void Foam::ensightCells::resize()
void Foam::ensightCells::resizeAll()
{
// overall required size
label n = 0;
forAll(sizes_, typeI)
forAll(sizes_, typei)
{
n += sizes_[typeI];
n += sizes_[typei];
}
address_.setSize(n, Zero);
// assign corresponding sub-lists
n = 0;
forAll(sizes_, typeI)
forAll(sizes_, typei)
{
deleteDemandDrivenData(lists_[typeI]);
deleteDemandDrivenData(lists_[typei]);
lists_[typeI] = new SubList<label>(address_, sizes_[typeI], n);
lists_[typei] = new SubList<label>(address_, sizes_[typei], n);
n += sizes_[typeI];
n += sizes_[typei];
}
}
@ -98,12 +82,12 @@ Foam::ensightCells::ensightCells(const label partIndex)
lists_()
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typeI)
forAll(lists_, typei)
{
lists_[typeI] = nullptr;
lists_[typei] = nullptr;
}
resize(); // adjust allocation
resizeAll(); // adjust allocation
}
@ -115,9 +99,9 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
lists_()
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typeI)
forAll(lists_, typei)
{
lists_[typeI] = nullptr;
lists_[typei] = nullptr;
}
// Total (reduced) sizes
@ -126,7 +110,7 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
// Local sizes
this->sizes_ = obj.sizes();
resize(); // adjust allocation
resizeAll(); // adjust allocation
// Restore total (reduced) sizes
this->sizes_ = totSizes;
@ -137,9 +121,9 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
Foam::ensightCells::~ensightCells()
{
forAll(lists_, typeI)
forAll(lists_, typei)
{
deleteDemandDrivenData(lists_[typeI]);
deleteDemandDrivenData(lists_[typei]);
}
address_.clear();
}
@ -150,21 +134,33 @@ Foam::ensightCells::~ensightCells()
Foam::FixedList<Foam::label, 5> Foam::ensightCells::sizes() const
{
FixedList<label, 5> count;
forAll(lists_, typeI)
forAll(lists_, typei)
{
count[typeI] = lists_[typeI]->size();
count[typei] = lists_[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;
forAll(sizes_, typeI)
forAll(sizes_, typei)
{
n += sizes_[typeI];
n += sizes_[typei];
}
return n;
}
@ -173,25 +169,25 @@ Foam::label Foam::ensightCells::total() const
void Foam::ensightCells::clear()
{
sizes_ = Zero; // reset sizes
resize();
resizeAll();
}
void Foam::ensightCells::reduce()
{
forAll(sizes_, typeI)
forAll(sizes_, typei)
{
sizes_[typeI] = lists_[typeI]->size();
Foam::reduce(sizes_[typeI], sumOp<label>());
sizes_[typei] = lists_[typei]->size();
Foam::reduce(sizes_[typei], sumOp<label>());
}
}
void Foam::ensightCells::sort()
{
forAll(lists_, typeI)
forAll(lists_, typei)
{
Foam::sort(*(lists_[typeI]));
Foam::sort(*(lists_[typei]));
}
}
@ -217,9 +213,9 @@ void Foam::ensightCells::classify
// Can avoid double looping, but only at the expense of allocation
sizes_ = Zero; // reset sizes
for (label listI = 0; listI < sz; ++listI)
for (label listi = 0; listi < sz; ++listi)
{
const label id = indirect ? addressing[listI] : listI;
const label id = indirect ? addressing[listi] : listi;
const cellModel& model = shapes[id].model();
enum elemType what = NFACED;
@ -243,13 +239,13 @@ void Foam::ensightCells::classify
sizes_[what]++;
}
resize(); // adjust allocation
resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes
// Assign cell-id per shape type
for (label listI = 0; listI < sz; ++listI)
for (label listi = 0; listi < sz; ++listi)
{
const label id = indirect ? addressing[listI] : listI;
const label id = indirect ? addressing[listi] : listi;
const cellModel& model = shapes[id].model();
enum elemType what = NFACED;
@ -276,10 +272,4 @@ void Foam::ensightCells::classify
}
Foam::label Foam::ensightCells::offset(const enum elemType what) const
{
return offset(what, 0);
}
// ************************************************************************* //

View File

@ -89,21 +89,19 @@ private:
//- Linear list of ids, sub-sectioned per element type via SubLists
labelList address_;
//- List of sizes for each element type
//- 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
//- 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
//- Low-level offset routine
inline label offset(const enum elemType what, const label i) const;
//- Use current sizes to redimension the element lists
void resize();
//- Use temporarily stored sizes to redimension the element lists
void resizeAll();
//- Disallow default bitwise assignment
void operator=(const ensightCells&) = delete;
@ -126,7 +124,7 @@ public:
// Member Functions
// Access
// Access
//- The index in a list.
inline label index() const;
@ -145,13 +143,15 @@ public:
// This value is only meaningful after a reduce operation.
label total() const;
//- The processor local sizes per element type.
FixedList<label, 5> sizes() const;
//- The global numbers per element type.
// This value is only meaningful after a reduce operation.
inline const FixedList<label, 5>& totals() const;
//- The processor local sizes per element type.
FixedList<label, 5> sizes() const;
//- Processor local starting offset of element type.
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;
@ -159,9 +159,6 @@ public:
//- Return the cell ids of all elements
inline const labelUList& cellIds() const;
//- Starting offset of element type.
label offset(const enum elemType what) const;
// Edit

View File

@ -74,52 +74,36 @@ inline void Foam::ensightFaces::add
{
const enum elemType what = whatType(f);
label n = sizes_[what]++;
lists_[what]->operator[](n) = id;
// linear addressing:
const label index = offset(what) + sizes_[what]++;
address_[index] = id;
if (flipMap_.size())
{
flipMap_[offset(what, n)] = flip;
flipMap_[index] = flip;
}
}
// only used in this file-scope
inline Foam::label Foam::ensightFaces::offset
(
const enum elemType what,
const label i
) const
{
label n = i;
for (label typeI = 0; typeI < label(what); ++typeI)
{
n += sizes_[typeI];
}
return n;
}
void Foam::ensightFaces::resize()
void Foam::ensightFaces::resizeAll()
{
// overall required size
label n = 0;
forAll(sizes_, typeI)
forAll(sizes_, typei)
{
n += sizes_[typeI];
n += sizes_[typei];
}
address_.setSize(n, Zero);
// assign corresponding sub-lists
n = 0;
forAll(sizes_, typeI)
forAll(sizes_, typei)
{
deleteDemandDrivenData(lists_[typeI]);
deleteDemandDrivenData(lists_[typei]);
lists_[typeI] = new SubList<label>(address_, sizes_[typeI], n);
lists_[typei] = new SubList<label>(address_, sizes_[typei], n);
n += sizes_[typeI];
n += sizes_[typei];
}
// normally assume no flipMap
@ -138,12 +122,12 @@ Foam::ensightFaces::ensightFaces(label partIndex)
lists_()
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typeI)
forAll(lists_, typei)
{
lists_[typeI] = nullptr;
lists_[typei] = nullptr;
}
resize(); // adjust allocation
resizeAll(); // adjust allocation
}
@ -156,9 +140,9 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj)
lists_()
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typeI)
forAll(lists_, typei)
{
lists_[typeI] = nullptr;
lists_[typei] = nullptr;
}
// Total (reduced) sizes
@ -167,7 +151,7 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj)
// Local sizes
this->sizes_ = obj.sizes();
resize(); // adjust allocation
resizeAll(); // adjust allocation
// Restore total (reduced) sizes
this->sizes_ = totSizes;
@ -178,9 +162,9 @@ Foam::ensightFaces::ensightFaces(const ensightFaces& obj)
Foam::ensightFaces::~ensightFaces()
{
forAll(lists_, typeI)
forAll(lists_, typei)
{
deleteDemandDrivenData(lists_[typeI]);
deleteDemandDrivenData(lists_[typei]);
}
address_.clear();
flipMap_.clear();
@ -192,21 +176,33 @@ Foam::ensightFaces::~ensightFaces()
Foam::FixedList<Foam::label, 3> Foam::ensightFaces::sizes() const
{
FixedList<label, 3> count;
forAll(lists_, typeI)
forAll(lists_, typei)
{
count[typeI] = lists_[typeI]->size();
count[typei] = lists_[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;
forAll(sizes_, typeI)
forAll(sizes_, typei)
{
n += sizes_[typeI];
n += sizes_[typei];
}
return n;
}
@ -215,16 +211,16 @@ Foam::label Foam::ensightFaces::total() const
void Foam::ensightFaces::clear()
{
sizes_ = Zero; // reset sizes
resize();
resizeAll();
}
void Foam::ensightFaces::reduce()
{
forAll(sizes_, typeI)
forAll(sizes_, typei)
{
sizes_[typeI] = lists_[typeI]->size();
Foam::reduce(sizes_[typeI], sumOp<label>());
sizes_[typei] = lists_[typei]->size();
Foam::reduce(sizes_[typei], sumOp<label>());
}
}
@ -238,9 +234,9 @@ void Foam::ensightFaces::sort()
labelList order;
label start = 0;
forAll(lists_, typeI)
forAll(lists_, typei)
{
SubList<label>& idLst = *(lists_[typeI]);
SubList<label>& idLst = *(lists_[typei]);
const label sz = idLst.size();
if (sz)
@ -258,9 +254,9 @@ void Foam::ensightFaces::sort()
else
{
// no flip-maps, simpler to sort
forAll(lists_, typeI)
forAll(lists_, typei)
{
Foam::sort(*(lists_[typeI]));
Foam::sort(*(lists_[typei]));
}
flipMap_.clear(); // for safety
}
@ -275,19 +271,19 @@ void Foam::ensightFaces::classify(const faceList& faces)
// Can avoid double looping, but only at the expense of allocation
sizes_ = Zero; // reset sizes
for (label listI = 0; listI < sz; ++listI)
for (label listi = 0; listi < sz; ++listi)
{
const enum elemType what = whatType(faces[listI]);
const enum elemType what = whatType(faces[listi]);
sizes_[what]++;
}
resize(); // adjust allocation
resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes
// Assign face-id per shape type
for (label listI = 0; listI < sz; ++listI)
for (label listi = 0; listi < sz; ++listi)
{
add(faces[listI], listI);
add(faces[listi], listi);
}
}
@ -310,9 +306,9 @@ void Foam::ensightFaces::classify
// Can avoid double looping, but only at the expense of allocation
sizes_ = Zero; // reset sizes
for (label listI = 0; listI < sz; ++listI)
for (label listi = 0; listi < sz; ++listi)
{
const label faceId = addressing[listI];
const label faceId = addressing[listi];
if (!exclude[faceId])
{
@ -321,7 +317,7 @@ void Foam::ensightFaces::classify
}
}
resize(); // adjust allocation
resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes
if (useFlip)
@ -331,10 +327,10 @@ void Foam::ensightFaces::classify
}
// Assign face-id per shape type
for (label listI = 0; listI < sz; ++listI)
for (label listi = 0; listi < sz; ++listi)
{
const label faceId = addressing[listI];
const bool flip = useFlip && flipMap[listI];
const label faceId = addressing[listi];
const bool flip = useFlip && flipMap[listi];
if (!exclude[faceId])
{
@ -343,11 +339,4 @@ void Foam::ensightFaces::classify
}
}
Foam::label Foam::ensightFaces::offset(const enum elemType what) const
{
return offset(what, 0);
}
// ************************************************************************* //

View File

@ -89,7 +89,8 @@ private:
//- Linear list of face-flips
boolList flipMap_;
//- List of global sizes for each element type
//- 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.
@ -102,14 +103,11 @@ private:
//- Simple classifier
inline static elemType whatType(const face&);
//- Low-level addition routine
//- Low-level internal addition routine
inline void add(const face&, const label id, const bool flip = false);
//- Low-level offset routine
inline label offset(const enum elemType what, const label i) const;
//- Use current sizes to redimension the element lists
void resize();
//- Use temporarily stored sizes to redimension the element lists
void resizeAll();
//- Disallow default bitwise assignment
void operator=(const ensightFaces&) = delete;
@ -132,76 +130,73 @@ public:
// Member Functions
// Access
// Access
//- The index in a list.
inline label index() const;
//- The index in a list.
inline label index() const;
//- The index in a list, non-const access.
inline label& index();
//- The index in a list, non-const access.
inline label& index();
//- The processor local size of all elements.
inline label size() const;
//- The processor local size of all elements.
inline label size() 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;
//- The global number of the specified element type.
// This value is only meaningful after a reduce operation.
inline label total(const enum elemType) const;
//- The global number of all element types.
// This value is only meaningful after a reduce operation.
label total() const;
//- The global number of all element types.
// This value is only meaningful after a reduce operation.
label total() const;
//- The global numbers per element type.
// This value is only meaningful after a reduce operation.
inline const FixedList<label, 3>& totals() const;
//- The processor local sizes per element type.
FixedList<label, 3> sizes() const;
//- Processor local starting offset of element type.
label offset(const enum elemType what) const;
//- Return the (local) face ids of the specified element type
inline const labelUList& faceIds(const enum elemType) const;
//- Return the processor local face ids of all elements
inline const labelUList& faceIds() const;
//- Return the processor local flip-map of all elements
inline const boolList& flipMap() const;
//- The processor local sizes per element type.
FixedList<label, 3> sizes() const;
// Edit
//- The global numbers per element type.
// This value is only meaningful after a reduce operation.
const FixedList<label, 3>& totals() const;
//- Classify the face types, set element list.
void classify(const faceList& faces);
//- Return the (local) face ids of the specified element type
inline const labelUList& faceIds(const enum elemType) const;
//- Return the face ids of all elements
inline const labelUList& faceIds() const;
//- Return the flip-map of all elements
inline const boolList& flipMap() const;
//- Classify the face types, set element list.
// The indirect addressing can be used when classifying groups of
// face (eg, from a faceZone etc) with an optional flipMap.
// The optional exclude marker can be used to skip faces on particular
// boundary types or regions.
void classify
(
const faceList& faces,
const labelUList& addressing,
const boolList& flipMap = boolList(),
const PackedBoolList& exclude = PackedBoolList()
);
//- Starting offset of element type.
label offset(const enum elemType what) const;
//- Set addressable sizes to zero, free up addressing memory.
void clear();
//- Sum element counts across all processes.
void reduce();
// Edit
//- Classify the face types, set element list.
void classify(const faceList& faces);
//- Classify the face types, set element list.
// The indirect addressing can be used when classifying groups of
// face (eg, from a faceZone etc) with an optional flipMap.
// The optional exclude marker can be used to skip faces on particular
// boundary types or regions.
void classify
(
const faceList& faces,
const labelUList& addressing,
const boolList& flipMap = boolList(),
const PackedBoolList& exclude = PackedBoolList()
);
//- Set addressable sizes to zero, free up addressing memory.
void clear();
//- Sum element counts across all processes.
void reduce();
//- Sort element lists numerically.
void sort();
//- Sort element lists numerically.
void sort();
// Member operators