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 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / 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
This file is part of OpenFOAM.
......@@ -348,29 +348,21 @@ void Foam::ensightFile::writeList
void Foam::ensightFile::writeList
(
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();
}
else
{
write(field[idx]);
}
newline();
writeUndef();
}
}
else
{
// No idList => perNode
writeList(field);
else
{
write(field[id]);
}
newline();
}
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / 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
This file is part of OpenFOAM.
......@@ -195,11 +195,7 @@ public:
//- Write an indirect list of scalars as "%12.5e" or as binary
// With carriage return after each value (ascii stream)
void writeList
(
const UList<scalar>& field,
const labelUList& idList
);
void writeList(const UList<scalar>& field, const labelUList& addr);
};
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,6 +25,7 @@ License
#include "ensightCells.H"
#include "error.H"
#include "bitSet.H"
#include "polyMesh.H"
#include "cellModel.H"
......@@ -90,7 +91,7 @@ Foam::ensightCells::ensightCells(const ensightCells& obj)
// Need local sizes for the resize operation
this->sizes_ = obj.sizes();
resizeAll(); // adjust allocation/sizing
resizeAll(); // Adjust allocation/sizing
// Restore total (reduced) sizes
this->sizes_ = totSizes;
......@@ -153,10 +154,11 @@ void Foam::ensightCells::sort()
}
void Foam::ensightCells::classify
template<class Addressing>
void Foam::ensightCells::classifyImpl
(
const polyMesh& mesh,
const labelUList& addressing
const Addressing& cellIds
)
{
// References to cell shape models
......@@ -167,16 +169,11 @@ void Foam::ensightCells::classify
const cellShapeList& shapes = mesh.cellShapes();
const bool indirect = notNull(addressing);
const label sz = indirect ? addressing.size() : mesh.nCells();
// Count the shapes
// Can avoid double looping, but only at the expense of allocation
// Pass 1: Count the shapes
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();
enum elemType what = NFACED;
......@@ -203,10 +200,10 @@ void Foam::ensightCells::classify
resizeAll(); // adjust allocation
sizes_ = Zero; // reset sizes - use for local indexing here
// Assign cell-id per shape type
for (label listi = 0; listi < sz; ++listi)
// Pass 2: Assign cell-id per shape type
for (const label id : cellIds)
{
const label id = indirect ? addressing[listi] : listi;
const cellModel& model = shapes[id].model();
enum elemType what = NFACED;
......@@ -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 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -42,6 +42,7 @@ namespace Foam
{
// Forward declarations
class bitSet;
class polyMesh;
/*---------------------------------------------------------------------------*\
......@@ -79,7 +80,7 @@ public:
private:
// Private data
// Private Data
//- Location within a list.
// The ensight part number is typically this value +1.
......@@ -101,6 +102,10 @@ private:
//- Use temporarily stored sizes to redimension the element lists
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
void operator=(const ensightCells&) = delete;
......@@ -167,14 +172,15 @@ public:
// 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& mesh,
const labelUList& addressing = labelUList::null()
);
void classify(const polyMesh& mesh);
//- Classify cell types and set element lists,
//- using a subgroup of cells (eg, from a cellZone etc).
void classify(const polyMesh& mesh, const labelUList& cellIds);
//- 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.
void clear();
......
......@@ -26,7 +26,6 @@ License
#include "ensightFaces.H"
#include "error.H"
#include "polyMesh.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
......@@ -34,11 +33,13 @@ const char* Foam::ensightFaces::elemNames[3] =
{ "tria3", "quad4", "nsided" };
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
namespace
{
// only used in this file-scope
inline Foam::ensightFaces::elemType
Foam::ensightFaces::whatType(const face& f)
// Simple shape classifier
static inline Foam::ensightFaces::elemType whatType(const Foam::face& f)
{
return
(
......@@ -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
(
const face& f,
......@@ -223,8 +228,7 @@ void Foam::ensightFaces::classify(const faceList& faces)
{
const label sz = faces.size();
// Count the shapes
// Can avoid double looping, but only at the expense of allocation
// Pass 1: Count the shapes
sizes_ = Zero; // reset sizes
for (label listi = 0; listi < sz; ++listi)
......@@ -236,7 +240,8 @@ void Foam::ensightFaces::classify(const faceList& faces)
resizeAll(); // adjust allocation
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)
{
add(faces[listi], listi);
......@@ -252,14 +257,10 @@ void Foam::ensightFaces::classify
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 bool useFlip = (addressing.size() == flipMap.size());
// Count the shapes
// Can avoid double looping, but only at the expense of allocation
// Pass 1: Count the shapes
sizes_ = Zero; // reset sizes
for (label listi = 0; listi < sz; ++listi)
......@@ -282,7 +283,8 @@ void Foam::ensightFaces::classify
flipMap_ = false;
}
// Assign face-id per shape type
// Pass 2: Assign face-id per shape type
for (label listi = 0; listi < sz; ++listi)
{
const label faceId = addressing[listi];
......
......@@ -51,7 +51,7 @@ class ensightFaces
{
public:
// Public data
// Public Data
//- Addressable ensight element types
enum elemType
......@@ -98,9 +98,6 @@ private:
// Private Member Functions
//- Simple classifier
inline static elemType whatType(const face& f);
//- Low-level internal addition routine
inline void add(const face& f, const label id, const bool flip = false);
......
......@@ -65,12 +65,6 @@ Foam::ensightPart::ensightPart(const string& description)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPart::~ensightPart()
{}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::ensightGeoFile& Foam::operator<<
......
......@@ -47,9 +47,9 @@ SourceFiles
namespace Foam
{
// Forward declaration of friend functions and operators
// Forward declarations
class ensightPart;
ensightGeoFile& operator<<(ensightGeoFile&, const ensightPart&);
......@@ -79,9 +79,8 @@ protected:
// Protected Classes
//- Track the points used by the part and map global to local indices
class localPoints
struct localPoints
{
public:
//- Number of points used
label nPoints;
......@@ -92,7 +91,7 @@ protected:
localPoints()
:
nPoints(0),
list(0)
list()
{}
//- Construct for mesh points
......@@ -116,7 +115,7 @@ public:
//- Destructor
virtual ~ensightPart();
virtual ~ensightPart() = default;
// Access
......@@ -130,16 +129,16 @@ public:
return 0;
}
//- Part name or description
//- Return the part name or description
const string& name() const
{
return name_;
}
//- non-const access to part name or description
void name(const string& value)
//- Change the part name or description
void name(string value)
{
name_ = value;
name_ = std::move(value);
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -41,12 +41,11 @@ Foam::ensightPart::localPoints Foam::ensightPartCells::calcLocalPoints() const
labelList& usedPoints = ptList.list;
label nPoints = 0;
// add all points from cells
// Add all points from cells
const labelUList& idList = this->cellIds();
forAll(idList, i)
for (const label id : idList)
{
const label id = idList[i];
const labelUList& cFaces = mesh_.cells()[id];
forAll(cFaces, cFacei)
......@@ -98,14 +97,14 @@ Foam::ensightPartCells::ensightPartCells
(
label partIndex,
const polyMesh& mesh,
const labelUList& idList
const labelUList& cellIds
)
:
ensightCells(partIndex),
ensightPart("cells"),
mesh_(mesh)
{
classify(mesh, idList);
classify(mesh, cellIds);
}
......@@ -113,21 +112,29 @@ Foam::ensightPartCells::ensightPartCells
(
label partIndex,
const polyMesh& mesh,
const cellZone& cZone
const cellZone& zn
)
:
ensightCells(partIndex),
ensightPart(cZone.name()),
mesh_(mesh)
ensightPartCells(partIndex, mesh, static_cast<const labelList&>(zn))
{
classify(mesh, cZone);
// Rename according to the zone name
name(zn.name());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPartCells::~ensightPartCells()
{}
Foam::ensightPartCells::ensightPartCells
(
label partIndex,
const polyMesh& mesh,
const bitSet& selection
)
:
ensightCells(partIndex),
ensightPart("cells"),
mesh_(mesh)
{
classify(mesh, selection);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2016-2019 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -53,7 +53,7 @@ class ensightPartCells
public ensightCells,
public ensightPart
{
// Private data
// Private Data
//- Mesh referenced
const polyMesh& mesh_;
......@@ -92,28 +92,36 @@ public:
ensightPartCells
(
label partIndex,
const polyMesh&
const polyMesh& mesh
);
//- Construct from polyMesh and list of (non-zoned) cells
//- Construct a "cells" part from polyMesh and list of cells
ensightPartCells
(
label partIndex,
const polyMesh&,
const labelUList&
const polyMesh& mesh,
const labelUList& cellIds
);
//- Construct from polyMesh and cellZone
//- Construct from polyMesh and cellZone with name of the zone.
ensightPartCells
(
label partIndex,
const polyMesh&,
const cellZone&
const polyMesh& mesh,
const cellZone& zn
);
//- Construct a "cells" part from polyMesh and selection of cells
ensightPartCells
(
label partIndex,
const polyMesh& mesh,
const bitSet& selection
);
//- Destructor
virtual ~ensightPartCells();
virtual ~ensightPartCells() = default;
// Member Functions
......@@ -136,17 +144,17 @@ public:
// Output
//- Write geometry
virtual void write(ensightGeoFile&) const;
virtual void write(ensightGeoFile& os) const;
//- Helper: write geometry given the pointField
virtual void write(ensightGeoFile&, const pointField&) const;
virtual void write(ensightGeoFile& os, const pointField& points) const;
//- Write summary information about the object
virtual void writeSummary(Ostream&) const;
virtual void writeSummary(Ostream& os) const;
//- Print various types of debugging information
virtual void dumpInfo(Ostream&) const;
virtual void dumpInfo(Ostream& os) const;
};
......
......@@ -126,12 +126,6 @@ Foam::ensightPartFaces::ensightPartFaces
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::ensightPartFaces::~ensightPartFaces()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::ensightPartFaces::writeConnectivity
......
......@@ -118,8 +118,8 @@ public:
(
label partIndex,
const string& description,
const pointField&,
const faceList&,
const pointField& points,
const faceList& faces,
const bool contiguousPoints = false
);
......@@ -127,54 +127,54 @@ public:
ensightPartFaces
(
label partIndex,
const polyMesh&,
const polyPatch&
const polyMesh& mesh,
const polyPatch& patch
);
//- Destructor
virtual ~ensightPartFaces();
virtual ~ensightPartFaces() = default;
// Member Functions
// Access
// Access
//- Part index (0-based)
virtual label index() const
{
return ensightFaces::index();
}
//- Part index (0-based)
virtual label index() const
{
return ensightFaces::index();
}
//- Number of elements in this part
virtual label size() const
{
return ensightFaces::size();
}
//- Number of elements in this part
virtual label size() const
{
return ensightFaces::size();
}
//- Return the patch index, -1 when not in use.
inline label patchIndex() const
{
return patchIndex_;
}
//- Return the patch index, -1 when not in use.
inline label patchIndex() const
{