Commit b2ee629a authored by Mark Olesen's avatar Mark Olesen
Browse files

BUG: removed oddness in pointer allocations (ensight parts).

- manifest in some parallel operations.

STYLE: update foamToEnsight, foamToEnsightParts to use C++ initializer_list

- avoid warning message when removing a non-existent directory (ensight output).
parent 39159421
......@@ -189,9 +189,8 @@ int main(int argc, char *argv[])
"(tet pyr prism hex poly)."
);
// the volume field types that we handle
const label nVolFieldTypes = 10;
const word volFieldTypes[] =
// The volume field types that we handle
const wordList volFieldTypes
{
volScalarField::typeName,
volVectorField::typeName,
......@@ -363,7 +362,7 @@ int main(int argc, char *argv[])
// ~~~~~~~~~~~~~~~~~~~~~~
Info<< "Write volume field (";
for (label typei=0; typei < nVolFieldTypes; ++typei)
forAll(volFieldTypes, typei)
{
const word& fieldType = volFieldTypes[typei];
wordList fieldNames = objects.names(fieldType);
......
......@@ -139,18 +139,22 @@ int main(int argc, char *argv[])
);
// The volume field types that we handle
wordHashSet volFieldTypes;
volFieldTypes.insert(volScalarField::typeName);
volFieldTypes.insert(volVectorField::typeName);
volFieldTypes.insert(volSphericalTensorField::typeName);
volFieldTypes.insert(volSymmTensorField::typeName);
volFieldTypes.insert(volTensorField::typeName);
const wordHashSet volFieldTypes
{
volScalarField::typeName,
volVectorField::typeName,
volSphericalTensorField::typeName,
volSymmTensorField::typeName,
volTensorField::typeName
};
// The lagrangian field types that we handle
wordHashSet cloudFieldTypes;
cloudFieldTypes.insert(scalarIOField::typeName);
cloudFieldTypes.insert(vectorIOField::typeName);
cloudFieldTypes.insert(tensorIOField::typeName);
const wordHashSet cloudFieldTypes
{
scalarIOField::typeName,
vectorIOField::typeName,
tensorIOField::typeName
};
#include "setRootCase.H"
......
......@@ -58,14 +58,17 @@ void Foam::ensightCase::initialize()
// eg, convert new results or a particular time interva
// OR remove everything
if (options_->overwrite())
if (isDir(ensightDir_))
{
rmDir(ensightDir_);
}
else if (isDir(ensightDir_))
{
Info<<"Warning: re-using existing directory" << nl
<< " " << ensightDir_ << endl;
if (options_->overwrite())
{
Foam::rmDir(ensightDir_);
}
else
{
Info<<"Warning: re-using existing directory" << nl
<< " " << ensightDir_ << endl;
}
}
// Create ensight and data directories
......
......@@ -65,7 +65,7 @@ inline Foam::label Foam::ensightCells::offset
}
void Foam::ensightCells::allocate()
void Foam::ensightCells::resize()
{
// overall required size
label n = 0;
......@@ -97,13 +97,39 @@ Foam::ensightCells::ensightCells(const label partIndex)
sizes_(0),
lists_()
{
// ensure sub-lists are properly initialized to nullptr
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typeI)
{
lists_[typeI] = nullptr;
}
clear();
resize(); // adjust allocation
}
Foam::ensightCells::ensightCells(const ensightCells& obj)
:
index_(obj.index_),
address_(obj.address_),
sizes_(0),
lists_()
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typeI)
{
lists_[typeI] = nullptr;
}
// Total (reduced) sizes
FixedList<label, 5> totSizes = obj.sizes_;
// Local sizes
this->sizes_ = obj.sizes();
resize(); // adjust allocation
// Restore total (reduced) sizes
this->sizes_ = totSizes;
}
......@@ -111,7 +137,12 @@ Foam::ensightCells::ensightCells(const label partIndex)
Foam::ensightCells::~ensightCells()
{
clear();
sizes_ = 0;
forAll(lists_, typeI)
{
deleteDemandDrivenData(lists_[typeI]);
}
address_.clear();
}
......@@ -143,12 +174,7 @@ Foam::label Foam::ensightCells::total() const
void Foam::ensightCells::clear()
{
sizes_ = 0;
forAll(lists_, typeI)
{
deleteDemandDrivenData(lists_[typeI]);
}
address_.clear();
resize();
}
......@@ -156,7 +182,7 @@ void Foam::ensightCells::reduce()
{
forAll(sizes_, typeI)
{
sizes_[typeI] = lists_[typeI] ? lists_[typeI]->size() : 0;
sizes_[typeI] = lists_[typeI]->size();
Foam::reduce(sizes_[typeI], sumOp<label>());
}
}
......@@ -221,8 +247,8 @@ void Foam::ensightCells::classify
sizes_[what]++;
}
allocate();
sizes_ = 0; // reset sizes
resize(); // adjust allocation
sizes_ = 0; // reset sizes
// Assign cell-id per shape type
for (label listI = 0; listI < sz; ++listI)
......
......@@ -82,7 +82,8 @@ private:
// Private data
//- Location within a list
//- Location within a list.
// The ensight part number is typically this value +1.
label index_;
//- Linear list of ids, sub-sectioned per element type via SubLists
......@@ -92,6 +93,7 @@ private:
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_;
......@@ -101,12 +103,11 @@ private:
inline label offset(const enum elemType what, const label i) const;
//- Use current sizes to redimension the element lists
void allocate();
void resize();
//- Disallow default bitwise assignment
void operator=(const ensightCells&) = delete;
// Retain default copy constructor (needed for lists etc).
public:
......@@ -115,6 +116,9 @@ public:
//- Construct null, optionally with index
ensightCells(label partIndex = 0);
//- Copy constructor. Needed for lists etc.
ensightCells(const ensightCells&);
//- Destructor
~ensightCells();
......@@ -171,7 +175,7 @@ public:
);
//- Set sizes to zero, free up memory
//- Set addressable sizes to zero, free up addressing memory.
void clear();
//- Sum element counts across all processes.
......
......@@ -23,6 +23,8 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline const char* Foam::ensightCells::key(const enum elemType what)
......@@ -66,6 +68,14 @@ 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]);
}
......
......@@ -101,7 +101,7 @@ inline Foam::label Foam::ensightFaces::offset
}
void Foam::ensightFaces::allocate()
void Foam::ensightFaces::resize()
{
// overall required size
label n = 0;
......@@ -137,13 +137,40 @@ Foam::ensightFaces::ensightFaces(label partIndex)
sizes_(0),
lists_()
{
// ensure sub-lists are properly initialized to nullptr
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typeI)
{
lists_[typeI] = nullptr;
}
clear();
resize(); // adjust allocation
}
Foam::ensightFaces::ensightFaces(const ensightFaces& obj)
:
index_(obj.index_),
address_(obj.address_),
flipMap_(obj.flipMap_),
sizes_(0),
lists_()
{
// Ensure sub-lists are properly initialized to nullptr
forAll(lists_, typeI)
{
lists_[typeI] = nullptr;
}
// Total (reduced) sizes
FixedList<label, 3> totSizes = obj.sizes_;
// Local sizes
this->sizes_ = obj.sizes();
resize(); // adjust allocation
// Restore total (reduced) sizes
this->sizes_ = totSizes;
}
......@@ -151,7 +178,13 @@ Foam::ensightFaces::ensightFaces(label partIndex)
Foam::ensightFaces::~ensightFaces()
{
clear();
sizes_ = 0;
forAll(lists_, typeI)
{
deleteDemandDrivenData(lists_[typeI]);
}
address_.clear();
flipMap_.clear();
}
......@@ -162,7 +195,7 @@ Foam::FixedList<Foam::label, 3> Foam::ensightFaces::sizes() const
FixedList<label, 3> count;
forAll(lists_, typeI)
{
count[typeI] = lists_[typeI] ? lists_[typeI]->size() : 0;
count[typeI] = lists_[typeI]->size();
}
return count;
......@@ -183,13 +216,7 @@ Foam::label Foam::ensightFaces::total() const
void Foam::ensightFaces::clear()
{
sizes_ = 0;
forAll(lists_, typeI)
{
deleteDemandDrivenData(lists_[typeI]);
}
address_.clear();
flipMap_.clear();
resize();
}
......@@ -197,7 +224,7 @@ void Foam::ensightFaces::reduce()
{
forAll(sizes_, typeI)
{
sizes_[typeI] = lists_[typeI] ? lists_[typeI]->size() : 0;
sizes_[typeI] = lists_[typeI]->size();
Foam::reduce(sizes_[typeI], sumOp<label>());
}
}
......@@ -265,7 +292,7 @@ void Foam::ensightFaces::classify(const faceList& faces)
sizes_[what]++;
}
allocate(); // adjust allocation
resize(); // adjust allocation
sizes_ = 0; // reset sizes
// Assign face-id per shape type
......@@ -305,7 +332,7 @@ void Foam::ensightFaces::classify
}
}
allocate(); // adjust allocation
resize(); // adjust allocation
sizes_ = 0; // reset sizes
if (useFlip)
......
......@@ -74,11 +74,13 @@ public:
//- Return the ensight element name for the specified type
static inline const char* key(const enum elemType);
private:
// Private data
//- Location in list
//- Location within a list.
// The ensight part number is typically this value +1.
label index_;
//- Linear list of ids, sub-sectioned per element type via SubLists
......@@ -90,7 +92,8 @@ private:
//- List of global sizes for each element type
FixedList<label, 3> sizes_;
//- SubLists of ids for each element type
//- SubLists of ids for each element type.
// Managed via pointers, since a SubList cannot be relocated/resized.
FixedList<SubList<label>*, 3> lists_;
......@@ -106,12 +109,11 @@ private:
inline label offset(const enum elemType what, const label i) const;
//- Use current sizes to redimension the element lists
void allocate();
void resize();
//- Disallow default bitwise assignment
void operator=(const ensightFaces&) = delete;
// Retain default copy constructor. Needed for lists etc.
public:
......@@ -120,6 +122,9 @@ public:
//- Construct null, optionally with index
ensightFaces(label partIndex = 0);
//- Copy constructor. Needed for lists etc.
ensightFaces(const ensightFaces&);
//- Destructor
~ensightFaces();
......@@ -189,7 +194,7 @@ public:
);
//- Set sizes to zero, free up memory
//- Set addressable sizes to zero, free up addressing memory.
void clear();
//- Sum element counts across all processes.
......
......@@ -23,6 +23,8 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline const char* Foam::ensightFaces::key(const enum elemType what)
......@@ -66,6 +68,14 @@ inline const Foam::labelUList& Foam::ensightFaces::faceIds
const enum elemType what
) const
{
if (!lists_[what])
{
FatalErrorInFunction
<< "Accessing unallocated sublist for elem-type: "
<< elemEnum[what]
<< exit(FatalError);
}
return *(lists_[what]);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment