Commit 0d78d97e authored by Mark Olesen's avatar Mark Olesen

ENH: code cleanup and improvement of ensight parts

- improved the selection mechanism to include using a bitSet
  cell selection (more efficient and convenient).

  Use templated implementation internally to remove the previous
  reliance on a NullObject.
parent e53e7111
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -348,29 +348,21 @@ void Foam::ensightFile::writeList ...@@ -348,29 +348,21 @@ void Foam::ensightFile::writeList
void Foam::ensightFile::writeList void Foam::ensightFile::writeList
( (
const UList<scalar>& field, const UList<scalar>& field,
const labelUList& idList const labelUList& addr
) )
{ {
if (notNull(idList)) for (const label id : addr)
{ {
for (const label idx : idList) if (idx >= field.size() || std::isnan(field[id]))
{ {
if (idx >= field.size() || std::isnan(field[idx])) writeUndef();
{
writeUndef();
}
else
{
write(field[idx]);
}
newline();
} }
} else
else {
{ write(field[id]);
// No idList => perNode }
writeList(field);
newline();
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016-2018 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -195,11 +195,7 @@ public: ...@@ -195,11 +195,7 @@ public:
//- Write an indirect list of scalars as "%12.5e" or as binary //- Write an indirect list of scalars as "%12.5e" or as binary
// With carriage return after each value (ascii stream) // With carriage return after each value (ascii stream)
void writeList void writeList(const UList<scalar>& field, const labelUList& addr);
(
const UList<scalar>& field,
const labelUList& idList
);
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -25,6 +25,7 @@ License ...@@ -25,6 +25,7 @@ License
#include "ensightCells.H" #include "ensightCells.H"
#include "error.H" #include "error.H"
#include "bitSet.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "cellModel.H" #include "cellModel.H"
...@@ -90,7 +91,7 @@ Foam::ensightCells::ensightCells(const ensightCells& obj) ...@@ -90,7 +91,7 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
// Need local sizes for the resize operation // Need local sizes for the resize operation
this->sizes_ = obj.sizes(); this->sizes_ = obj.sizes();
resizeAll(); // adjust allocation/sizing resizeAll(); // Adjust allocation/sizing
// Restore total (reduced) sizes // Restore total (reduced) sizes
this->sizes_ = totSizes; this->sizes_ = totSizes;
...@@ -153,10 +154,11 @@ void Foam::ensightCells::sort() ...@@ -153,10 +154,11 @@ void Foam::ensightCells::sort()
} }
void Foam::ensightCells::classify template<class Addressing>
void Foam::ensightCells::classifyImpl
( (
const polyMesh& mesh, const polyMesh& mesh,
const labelUList& addressing const Addressing& cellIds
) )
{ {
// References to cell shape models // References to cell shape models
...@@ -167,16 +169,11 @@ void Foam::ensightCells::classify ...@@ -167,16 +169,11 @@ void Foam::ensightCells::classify
const cellShapeList& shapes = mesh.cellShapes(); const cellShapeList& shapes = mesh.cellShapes();
const bool indirect = notNull(addressing); // Pass 1: Count the shapes
const label sz = indirect ? addressing.size() : mesh.nCells();
// Count the shapes
// Can avoid double looping, but only at the expense of allocation
sizes_ = Zero; // reset sizes sizes_ = Zero; // reset sizes
for (label listi = 0; listi < sz; ++listi) for (const label id : cellIds)
{ {
const label id = indirect ? addressing[listi] : listi;
const cellModel& model = shapes[id].model(); const cellModel& model = shapes[id].model();
enum elemType what = NFACED; enum elemType what = NFACED;
...@@ -203,10 +200,10 @@ void Foam::ensightCells::classify ...@@ -203,10 +200,10 @@ void Foam::ensightCells::classify
resizeAll(); // adjust allocation resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes - use for local indexing here sizes_ = Zero; // reset sizes - use for local indexing here
// Assign cell-id per shape type // Pass 2: Assign cell-id per shape type
for (label listi = 0; listi < sz; ++listi)
for (const label id : cellIds)
{ {
const label id = indirect ? addressing[listi] : listi;
const cellModel& model = shapes[id].model(); const cellModel& model = shapes[id].model();
enum elemType what = NFACED; enum elemType what = NFACED;
...@@ -236,4 +233,31 @@ void Foam::ensightCells::classify ...@@ -236,4 +233,31 @@ void Foam::ensightCells::classify
} }
void Foam::ensightCells::classify(const polyMesh& mesh)
{
// All mesh cells
classifyImpl(mesh, labelRange::identity(mesh.nCells()));
}
void Foam::ensightCells::classify
(
const polyMesh& mesh,
const labelUList& cellIds
)
{
classifyImpl(mesh, cellIds);
}
void Foam::ensightCells::classify
(
const polyMesh& mesh,
const bitSet& selection
)
{
classifyImpl(mesh, selection);
}
// ************************************************************************* // // ************************************************************************* //
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
...@@ -42,6 +42,7 @@ namespace Foam ...@@ -42,6 +42,7 @@ namespace Foam
{ {
// Forward declarations // Forward declarations
class bitSet;
class polyMesh; class polyMesh;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
...@@ -79,7 +80,7 @@ public: ...@@ -79,7 +80,7 @@ public:
private: private:
// Private data // Private Data
//- Location within a list. //- Location within a list.
// The ensight part number is typically this value +1. // The ensight part number is typically this value +1.
...@@ -101,6 +102,10 @@ private: ...@@ -101,6 +102,10 @@ private:
//- Use temporarily stored sizes to redimension the element lists //- Use temporarily stored sizes to redimension the element lists
void resizeAll(); void resizeAll();
//- Classify cell types, set element lists for selection (implemention)
template<class Addressing>
void classifyImpl(const polyMesh& mesh, const Addressing& cellIds);
//- No copy assignment //- No copy assignment
void operator=(const ensightCells&) = delete; void operator=(const ensightCells&) = delete;
...@@ -167,14 +172,15 @@ public: ...@@ -167,14 +172,15 @@ public:
// Edit // Edit
//- Classify cell types and set the element lists. //- Classify cell types and set the element lists.
// The optional indirect addressing can be used when classifying void classify(const polyMesh& mesh);
// groups of cells (eg, from a cellZone etc).
void classify //- Classify cell types and set element lists,
( //- using a subgroup of cells (eg, from a cellZone etc).
const polyMesh& mesh, void classify(const polyMesh& mesh, const labelUList& cellIds);
const labelUList& addressing = labelUList::null()
);
//- Classify cell types and set element lists,
//- using a subgroup of cells
void classify(const polyMesh& mesh, const bitSet& selection);
//- Set addressable sizes to zero, free up addressing memory. //- Set addressable sizes to zero, free up addressing memory.
void clear(); void clear();
......
...@@ -26,7 +26,6 @@ License ...@@ -26,7 +26,6 @@ License
#include "ensightFaces.H" #include "ensightFaces.H"
#include "error.H" #include "error.H"
#include "polyMesh.H" #include "polyMesh.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
...@@ -34,11 +33,13 @@ const char* Foam::ensightFaces::elemNames[3] = ...@@ -34,11 +33,13 @@ const char* Foam::ensightFaces::elemNames[3] =
{ "tria3", "quad4", "nsided" }; { "tria3", "quad4", "nsided" };
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace
{
// only used in this file-scope // Simple shape classifier
inline Foam::ensightFaces::elemType static inline Foam::ensightFaces::elemType whatType(const Foam::face& f)
Foam::ensightFaces::whatType(const face& f)
{ {
return return
( (
...@@ -50,8 +51,12 @@ Foam::ensightFaces::whatType(const face& f) ...@@ -50,8 +51,12 @@ Foam::ensightFaces::whatType(const face& f)
); );
} }
} // End anonymous namespace
// only used in this file-scope
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Only used in this file-scope
inline void Foam::ensightFaces::add inline void Foam::ensightFaces::add
( (
const face& f, const face& f,
...@@ -223,8 +228,7 @@ void Foam::ensightFaces::classify(const faceList& faces) ...@@ -223,8 +228,7 @@ void Foam::ensightFaces::classify(const faceList& faces)
{ {
const label sz = faces.size(); const label sz = faces.size();
// Count the shapes // Pass 1: Count the shapes
// Can avoid double looping, but only at the expense of allocation
sizes_ = Zero; // reset sizes sizes_ = Zero; // reset sizes
for (label listi = 0; listi < sz; ++listi) for (label listi = 0; listi < sz; ++listi)
...@@ -236,7 +240,8 @@ void Foam::ensightFaces::classify(const faceList& faces) ...@@ -236,7 +240,8 @@ void Foam::ensightFaces::classify(const faceList& faces)
resizeAll(); // adjust allocation resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes - use for local indexing here sizes_ = Zero; // reset sizes - use for local indexing here
// Assign face-id per shape type // Pass 2: 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);
...@@ -252,14 +257,10 @@ void Foam::ensightFaces::classify ...@@ -252,14 +257,10 @@ void Foam::ensightFaces::classify
const bitSet& exclude const bitSet& exclude
) )
{ {
// Note: Since PackedList::operator[] returns zero (false) for out-of-range
// indices, can skip our own bounds checking here.
const label sz = addressing.size(); const label sz = addressing.size();
const bool useFlip = (addressing.size() == flipMap.size()); const bool useFlip = (addressing.size() == flipMap.size());
// Count the shapes // Pass 1: Count the shapes
// Can avoid double looping, but only at the expense of allocation
sizes_ = Zero; // reset sizes sizes_ = Zero; // reset sizes
for (label listi = 0; listi < sz; ++listi) for (label listi = 0; listi < sz; ++listi)
...@@ -282,7 +283,8 @@ void Foam::ensightFaces::classify ...@@ -282,7 +283,8 @@ void Foam::ensightFaces::classify
flipMap_ = false; flipMap_ = false;
} }
// Assign face-id per shape type // Pass 2: 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 label faceId = addressing[listi];
......
...@@ -51,7 +51,7 @@ class ensightFaces ...@@ -51,7 +51,7 @@ class ensightFaces
{ {
public: public:
// Public data // Public Data
//- Addressable ensight element types //- Addressable ensight element types
enum elemType enum elemType
...@@ -98,9 +98,6 @@ private: ...@@ -98,9 +98,6 @@ private:
// Private Member Functions // Private Member Functions
//- Simple classifier
inline static elemType whatType(const face& f);
//- Low-level internal addition routine //- Low-level internal addition routine
inline void add(const face& f, const label id, const bool flip = false); inline void add(const face& f, const label id, const bool flip = false);
......
...@@ -65,12 +65,6 @@ Foam::ensightPart::ensightPart(const string& description) ...@@ -65,12 +65,6 @@ Foam::ensightPart::ensightPart(const string& description)
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPart::~ensightPart()
{}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * // // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::ensightGeoFile& Foam::operator<< Foam::ensightGeoFile& Foam::operator<<
......
...@@ -47,9 +47,9 @@ SourceFiles ...@@ -47,9 +47,9 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of friend functions and operators // Forward declarations
class ensightPart; class ensightPart;
ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&); ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&);
...@@ -79,9 +79,8 @@ protected: ...@@ -79,9 +79,8 @@ protected:
// Protected Classes // Protected Classes
//- Track the points used by the part and map global to local indices //- Track the points used by the part and map global to local indices
class localPoints struct localPoints
{ {
public:
//- Number of points used //- Number of points used
label nPoints; label nPoints;
...@@ -92,7 +91,7 @@ protected: ...@@ -92,7 +91,7 @@ protected:
localPoints() localPoints()
: :
nPoints(0), nPoints(0),
list(0) list()
{} {}
//- Construct for mesh points //- Construct for mesh points
...@@ -116,7 +115,7 @@ public: ...@@ -116,7 +115,7 @@ public:
//- Destructor //- Destructor
virtual ~ensightPart(); virtual ~ensightPart() = default;
// Access // Access
...@@ -130,16 +129,16 @@ public: ...@@ -130,16 +129,16 @@ public:
return 0; return 0;
} }
//- Part name or description //- Return the part name or description
const string& name() const const string& name() const
{ {
return name_; return name_;
} }
//- non-const access to part name or description //- Change the part name or description
void name(const string& value) void name(string value)
{ {
name_ = value; name_ = std::move(value);
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.
...@@ -41,12 +41,11 @@ Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const ...@@ -41,12 +41,11 @@ Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
labelList& usedPoints = ptList.list; labelList& usedPoints = ptList.list;
label nPoints = 0; label nPoints = 0;
// add all points from cells // Add all points from cells
const labelUList& idList = this->cellIds(); const labelUList& idList = this->cellIds();
forAll(idList, i) for (const label id : idList)
{ {
const label id = idList[i];
const labelUList& cFaces = mesh_.cells()[id]; const labelUList& cFaces = mesh_.cells()[id];
forAll(cFaces, cFacei) forAll(cFaces, cFacei)
...@@ -98,14 +97,14 @@ Foam::ensightPartCells::ensightPartCells ...@@ -98,14 +97,14 @@ Foam::ensightPartCells::ensightPartCells
( (
label partIndex, label partIndex,
const polyMesh& mesh, const polyMesh& mesh,
const labelUList& idList const labelUList& cellIds
) )
: :
ensightCells(partIndex), ensightCells(partIndex),
ensightPart("cells"), ensightPart("cells"),
mesh_(mesh)