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

Merge branch 'feature-consistency-face-access' into 'develop'

Feature consistency face access

See merge request !109
parents 46a1fed9 708c1b5c
......@@ -112,6 +112,7 @@ Foam::UList<T> Foam::UList<T>::operator[](const labelRange& range)
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
}
template<class T>
const Foam::UList<T> Foam::UList<T>::operator[](const labelRange& range) const
{
......@@ -132,6 +133,7 @@ Foam::UList<T> Foam::UList<T>::operator[]
return UList<T>(&(this->v_[slice.start()]), slice.size()); // SubList
}
template<class T>
const Foam::UList<T> Foam::UList<T>::operator[]
(
......
......@@ -149,7 +149,11 @@ public:
//- Return true if point label is found in edge.
// Always false for a negative label.
inline bool found(const label index) const;
inline bool found(const label pointLabel) const;
//- Return local index (0,1) of point label in edge -1 on failure
// Always return -1 for a negative label.
inline label which(const label pointLabel) const;
//- Do the edges share a common vertex index?
// Negative point labels never connect.
......
......@@ -206,10 +206,28 @@ inline Foam::label Foam::edge::maxVertex() const
}
inline bool Foam::edge::found(const label index) const
inline bool Foam::edge::found(const label pointLabel) const
{
// -1: always false
return (index >= 0 && (index == start() || index == end()));
return (pointLabel >= 0 && (pointLabel == start() || pointLabel == end()));
}
inline Foam::label Foam::edge::which(const label pointLabel) const
{
// -1: always false
if (pointLabel >= 0)
{
if (pointLabel == start())
{
return 0;
}
if (pointLabel == end())
{
return 1;
}
}
return -1;
}
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -202,7 +202,10 @@ public:
//- Navigation through face vertices
//- Which vertex on face (face index given a global index)
//- Return true if the global point label is found in face.
inline bool found(const label globalIndex) const;
//- Which local vertex on face given a global index.
// returns -1 if not found
label which(const label globalIndex) const;
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -116,20 +116,24 @@ inline Foam::edge Foam::face::faceEdge(const label n) const
}
// Next vertex on face
inline bool Foam::face::found(const label globalIndex) const
{
return which(globalIndex) != -1;
}
inline Foam::label Foam::face::nextLabel(const label i) const
{
return operator[](fcIndex(i));
}
// Previous vertex on face
inline Foam::label Foam::face::prevLabel(const label i) const
{
return operator[](rcIndex(i));
}
// Number of triangles directly known from number of vertices
inline Foam::label Foam::face::nTriangles() const
{
return size() - 2;
......
......@@ -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) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -21,83 +21,53 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Class
Foam::faceTraits
Description
Traits class for faces
\*---------------------------------------------------------------------------*/
#ifndef faceTraits_H
#define faceTraits_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// A triFace surface only handles triangulated faces
template<>
inline bool MeshedSurface<triFace>::isTri()
{
return true;
}
// Forward declarations
class triFace;
class labelledTri;
/*---------------------------------------------------------------------------*\
Class faceTraits Declaration
\*---------------------------------------------------------------------------*/
// A labelledTri surface only handles triangulated faces
template<>
inline bool MeshedSurface<labelledTri>::isTri()
template<class FaceType>
class faceTraits
{
return true;
}
public:
//- Face-type only handles triangles. Not true in general.
inline static bool isTri() { return false; }
};
// Number of triangles for a triFace surface
template<>
inline label MeshedSurface<triFace>::nTriangles() const
{
return ParentType::size();
}
// Number of triangles for a labelledTri surface
template<>
inline label MeshedSurface<labelledTri>::nTriangles() const
{
return ParentType::size();
}
inline bool faceTraits<triFace>::isTri() { return true; }
// Inplace triangulation of triFace surface = no-op
template<>
inline label MeshedSurface<triFace>::triangulate()
{
return 0;
}
inline bool faceTraits<labelledTri>::isTri() { return true; }
// Inplace triangulation of labelledTri surface = no-op
template<>
inline label MeshedSurface<labelledTri>::triangulate()
{
return 0;
}
// Inplace triangulation of triFace surface (with face map) = no-op
template<>
inline label MeshedSurface<triFace>::triangulate(List<label>& faceMap)
{
if (notNull(faceMap))
{
faceMap.clear();
}
return 0;
}
// Inplace triangulation of labelledTri surface (with face map) = no-op
template<>
inline label MeshedSurface<labelledTri>::triangulate(List<label>& faceMap)
{
if (notNull(faceMap))
{
faceMap.clear();
}
return 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
#endif
// ************************************************************************* //
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -137,6 +137,13 @@ public:
// The starting points of the original and reverse face are identical.
inline triFace reverseFace() const;
//- Return true if the global point label is found in face.
bool found(const label globalIndex) const;
//- Which local index (0,1,2) on face given a global index.
// returns -1 if not found
label which(const label globalIndex) const;
//- Return swept-volume from old-points to new-points
inline scalar sweptVol
(
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -209,6 +209,21 @@ inline Foam::triFace Foam::triFace::reverseFace() const
}
inline bool Foam::triFace::found(const label globalIndex) const
{
return which(globalIndex) != -1;
}
inline Foam::label Foam::triFace::which(const label globalIndex) const
{
if (operator[](0) == globalIndex) return 0;
if (operator[](1) == globalIndex) return 1;
if (operator[](2) == globalIndex) return 2;
return -1;
}
inline Foam::scalar Foam::triFace::sweptVol
(
const UList<point>& opts,
......
......@@ -98,10 +98,10 @@ public:
// Access
//- Return first vertex
//- Return first point
inline PointRef start() const;
//- Return second vertex
//- Return second point
inline PointRef end() const;
......@@ -113,9 +113,12 @@ public:
//- Return scalar magnitude
inline scalar mag() const;
//- Return start-end vector
//- Return start-to-end vector
inline Point vec() const;
//- Return the unit vector (start-to-end)
inline Point unitVec() const;
//- Return nearest distance to line from a given point
// If the nearest point is on the line, return a hit
PointHit<Point> nearestDist(const Point& p) const;
......
......@@ -90,6 +90,16 @@ inline Point Foam::line<Point, PointRef>::vec() const
}
template<class Point, class PointRef>
inline Point Foam::line<Point, PointRef>::unitVec() const
{
Point v = b_ - a_;
v /= ::Foam::mag(v) + VSMALL;
return v;
}
template<class Point, class PointRef>
Foam::PointHit<Point> Foam::line<Point, PointRef>::nearestDist
(
......
......@@ -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;