Commit 430d8e1c authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: UList<point> instead of pointField for meshShapes methods

- improves flexibility.

STYLE: make longestEdge a face method and deprecate the global function
parent f2304f7c
......@@ -101,10 +101,10 @@ Foam::labelList Foam::cell::labels(const faceUList& f) const
Foam::pointField Foam::cell::points
(
const faceUList& f,
const pointField& meshPoints
const UList<point>& meshPoints
) const
{
labelList pointLabels = labels(f);
const labelList pointLabels = labels(f);
pointField p(pointLabels.size());
......@@ -171,7 +171,7 @@ Foam::edgeList Foam::cell::edges(const faceUList& f) const
Foam::point Foam::cell::centre
(
const pointField& p,
const UList<point>& p,
const faceUList& f
) const
{
......@@ -237,7 +237,7 @@ Foam::point Foam::cell::centre
Foam::scalar Foam::cell::mag
(
const pointField& p,
const UList<point>& p,
const faceUList& f
) const
{
......@@ -290,7 +290,7 @@ bool Foam::operator==(const cell& a, const cell& b)
forAll(b, bI)
{
label curLabel = b[bI];
const label curLabel = b[bI];
bool found = false;
......@@ -310,15 +310,16 @@ bool Foam::operator==(const cell& a, const cell& b)
}
}
// check if all faces on a were marked
bool result = true;
// Any faces missed?
forAll(fnd, aI)
{
result = (result && fnd[aI]);
if (!fnd[aI])
{
return false;
}
}
return result;
return true;
}
......
......@@ -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.
......@@ -29,6 +29,8 @@ Description
SourceFiles
cellI.H
cell.C
oppositeCellFace.C
\*---------------------------------------------------------------------------*/
......@@ -46,8 +48,8 @@ namespace Foam
// Forward declaration of friend functions and operators
class cell;
bool operator==(const cell&, const cell&);
inline bool operator!=(const cell&, const cell&);
bool operator==(const cell& a, const cell& b);
inline bool operator!=(const cell& a, const cell& b);
/*---------------------------------------------------------------------------*\
......@@ -72,16 +74,16 @@ public:
inline cell();
//- Construct given size
explicit inline cell(label);
explicit inline cell(const label sz);
//- Construct from list of labels
explicit inline cell(const labelUList&);
explicit inline cell(const labelUList& lst);
//- Construct by transferring the parameter contents
explicit inline cell(const Xfer<labelList>&);
//- Construct by transferring list of labels
explicit inline cell(const Xfer<labelList>& lst);
//- Construct from Istream
inline cell(Istream&);
inline cell(Istream& is);
// Member Functions
......@@ -89,14 +91,18 @@ public:
//- Return number of faces
inline label nFaces() const;
//- Return labels of cell vertices
labelList labels(const faceUList&) const;
//- Return unordered list of cell vertices given the list of faces
labelList labels(const faceUList& f) const;
//- Return the cell vertices
pointField points(const faceUList&, const pointField&) const;
//- Return the cell vertices given the list of faces and mesh points
pointField points
(
const faceUList& f,
const UList<point>& meshPoints
) const;
//- Return cell edges
edgeList edges(const faceUList&) const;
edgeList edges(const faceUList& f) const;
//- Return index of opposite face
label opposingFaceLabel
......@@ -122,16 +128,16 @@ public:
// future.
//- Returns cell centre
point centre(const pointField&, const faceUList&) const;
point centre(const UList<point>& p, const faceUList& f) const;
//- Returns cell volume
scalar mag(const pointField&, const faceUList&) const;
scalar mag(const UList<point>& p, const faceUList& f) const;
// Friend Operators
friend bool operator==(const cell&, const cell&);
friend bool operator!=(const cell&, const cell&);
friend bool operator==(const cell& a, const cell& b);
friend bool operator!=(const cell& a, const cell& b);
};
......
......@@ -21,25 +21,20 @@ License
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Description
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct null
inline Foam::cell::cell()
{}
// Construct given size
inline Foam::cell::cell(label s)
inline Foam::cell::cell(const label sz)
:
labelList(s, -1)
labelList(sz, -1)
{}
// Construct from components
inline Foam::cell::cell(const labelUList& lst)
:
labelList(lst)
......@@ -52,7 +47,6 @@ inline Foam::cell::cell(const Xfer<labelList>& lst)
{}
// Construct from Istream
inline Foam::cell::cell(Istream& is)
:
labelList(is)
......@@ -61,7 +55,6 @@ inline Foam::cell::cell(Istream& is)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Number of faces
inline Foam::label Foam::cell::nFaces() const
{
return size();
......@@ -73,4 +66,5 @@ inline bool Foam::operator!=(const cell& a, const cell& b)
return (!(a == b));
}
// ************************************************************************* //
......@@ -31,7 +31,7 @@ License
Foam::vector Foam::cellModel::centre
(
const labelList& pointLabels,
const pointField& points
const UList<point>& points
) const
{
// Estimate centre of cell
......@@ -88,7 +88,7 @@ Foam::vector Foam::cellModel::centre
Foam::scalar Foam::cellModel::mag
(
const labelList& pointLabels,
const pointField& points
const UList<point>& points
) const
{
// Estimate centre of cell
......
......@@ -53,9 +53,9 @@ namespace Foam
// Forward declaration of friend functions and operators
class cellModel;
inline bool operator==(const cellModel&, const cellModel&);
inline bool operator!=(const cellModel&, const cellModel&);
Ostream& operator<<(Ostream&, const cellModel&);
inline bool operator==(const cellModel& m1, const cellModel& m2);
inline bool operator!=(const cellModel& m1, const cellModel& m2);
Ostream& operator<<(Ostream& os, const cellModel& c);
/*---------------------------------------------------------------------------*\
......@@ -87,7 +87,7 @@ public:
// Constructors
//- Construct from Istream
cellModel(Istream&);
cellModel(Istream& is);
//- Return a new cellModel on free-store created from Istream
static autoPtr<cellModel> New(Istream& is)
......@@ -135,14 +135,14 @@ public:
vector centre
(
const labelList& pointLabels,
const pointField& points
const UList<point>& points
) const;
//- Cell volume
scalar mag
(
const labelList& pointLabels,
const pointField& points
const UList<point>& points
) const;
//- Return info proxy.
......@@ -163,15 +163,15 @@ public:
// Friend operators
//- Equality operator: true => ptr to models are equal !
friend bool operator==(const cellModel&, const cellModel&);
friend bool operator==(const cellModel& m1, const cellModel& m2);
//- Inequality operator: true => ptr to models are not equal !
friend bool operator!=(const cellModel&, const cellModel&);
friend bool operator!=(const cellModel& m1, const cellModel& m2);
// Ostream operator
friend Ostream& operator<<(Ostream&, const cellModel&);
friend Ostream& operator<<(Ostream& os, const cellModel& c);
};
......
......@@ -86,12 +86,12 @@ inline edgeList cellModel::edges(const labelList& pointLabels) const
}
// Return a raw list of model faces
inline const faceList& cellModel::modelFaces() const
{
return faces_;
}
// Return the faces of a cellModel by untangling the geometry
// supplied in terms of the face labels
inline faceList cellModel::faces(const labelList& pointLabels) const
......
......@@ -58,9 +58,9 @@ class cell;
// Forward declaration of friend functions and operators
class cellShape;
bool operator==(const cellShape&, const cellShape&);
Istream& operator>>(Istream&, cellShape&);
Ostream& operator<<(Ostream&, const cellShape&);
bool operator==(const cellShape& a, const cellShape& b);
Istream& operator>>(Istream& is, cellShape& s);
Ostream& operator<<(Ostream& os, const cellShape& s);
/*---------------------------------------------------------------------------*\
......@@ -110,19 +110,23 @@ public:
// Member Functions
//- Return the points corresponding to this cellShape
inline pointField points(const pointField& meshPoints) const;
inline pointField points(const UList<point>& meshPoints) const;
//- Model reference
inline const cellModel& model() const;
//- Mesh face labels of this cell (in order of model)
inline labelList meshFaces(const faceList& allFaces, const cell&) const;
inline labelList meshFaces
(
const faceList& allFaces,
const cell& cFaces
) const;
//- Mesh edge labels of this cell (in order of model)
inline labelList meshEdges
(
const edgeList& allEdges,
const labelList&
const labelList& cEdges
) const;
//- Faces of this cell
......@@ -144,7 +148,7 @@ public:
inline label nPoints() const;
//- Centroid of the cell
inline point centre(const pointField&) const;
inline point centre(const UList<point>& points) const;
//- Return info proxy.
// Used to print token information to a stream
......@@ -154,7 +158,7 @@ public:
}
//- Scalar magnitude
inline scalar mag(const pointField&) const;
inline scalar mag(const UList<point>& points) const;
//- Collapse shape to correct one after removing duplicate vertices
void collapse();
......@@ -162,13 +166,13 @@ public:
// Friend Operators
friend bool operator==(const cellShape&, const cellShape&);
friend bool operator==(const cellShape& a, const cellShape& b);
// IOstream operators
friend Istream& operator>>(Istream&, cellShape&);
friend Ostream& operator<<(Ostream&, const cellShape&);
friend Istream& operator>>(Istream& is, cellShape& s);
friend Ostream& operator<<(Ostream& os, const cellShape& s);
};
......
......@@ -85,7 +85,7 @@ inline Foam::autoPtr<Foam::cellShape> Foam::cellShape::clone() const
inline Foam::pointField Foam::cellShape::points
(
const pointField& meshPoints
const UList<point>& meshPoints
) const
{
// There are as many points as there labels for them
......@@ -256,13 +256,13 @@ inline Foam::label Foam::cellShape::nPoints() const
}
inline Foam::point Foam::cellShape::centre(const pointField& points) const
inline Foam::point Foam::cellShape::centre(const UList<point>& points) const
{
return m->centre(*this, points);
}
inline Foam::scalar Foam::cellShape::mag(const pointField& points) const
inline Foam::scalar Foam::cellShape::mag(const UList<point>& points) const
{
return m->mag(*this, points);
}
......
......@@ -92,7 +92,7 @@ Foam::Istream& Foam::operator>>(Istream& is, cellShape& s)
}
Foam::Ostream& Foam::operator<<(Ostream& os, const cellShape & s)
Foam::Ostream& Foam::operator<<(Ostream& os, const cellShape& s)
{
// Write beginning of record
os << token::BEGIN_LIST;
......
......@@ -38,7 +38,7 @@ const char* const Foam::face::typeName = "face";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::tmp<Foam::vectorField>
Foam::face::calcEdges(const pointField& points) const
Foam::face::calcEdges(const UList<point>& points) const
{
tmp<vectorField> tedges(new vectorField(size()));
vectorField& edges = tedges.ref();
......@@ -76,7 +76,7 @@ Foam::scalar Foam::face::edgeCos
Foam::label Foam::face::mostConcaveAngle
(
const pointField& points,
const UList<point>& points,
const vectorField& edges,
scalar& maxAngle
) const
......@@ -124,7 +124,7 @@ Foam::label Foam::face::mostConcaveAngle
Foam::label Foam::face::split
(
const face::splitMode mode,
const pointField& points,
const UList<point>& points,
label& triI,
label& quadI,
faceList& triFaces,
......@@ -399,8 +399,8 @@ int Foam::face::compare(const face& a, const face& b)
bool Foam::face::sameVertices(const face& a, const face& b)
{
label sizeA = a.size();
label sizeB = b.size();
const label sizeA = a.size();
const label sizeB = b.size();
// Trivial reject: faces are different size
if (sizeA != sizeB)
......@@ -410,14 +410,7 @@ bool Foam::face::sameVertices(const face& a, const face& b)
// Check faces with a single vertex
else if (sizeA == 1)
{
if (a[0] == b[0])
{
return true;
}
else
{
return false;
}
return (a[0] == b[0]);
}
forAll(a, i)
......@@ -461,7 +454,7 @@ Foam::label Foam::face::collapse()
if (operator[](ci) != operator[](0))
{
ci++;
++ci;
}
setSize(ci);
......@@ -485,7 +478,7 @@ void Foam::face::flip()
}
Foam::point Foam::face::centre(const pointField& points) const
Foam::point Foam::face::centre(const UList<point>& points) const
{
// Calculate the centre by breaking the face into triangles and
// area-weighted averaging their centres
......@@ -549,7 +542,7 @@ Foam::point Foam::face::centre(const pointField& points) const
}
Foam::vector Foam::face::normal(const pointField& p) const
Foam::vector Foam::face::normal(const UList<point>& p) const
{
const label nPoints = size();
......@@ -645,8 +638,8 @@ Foam::label Foam::face::which(const label globalIndex) const
Foam::scalar Foam::face::sweptVol
(
const pointField& oldPoints,
const pointField& newPoints
const UList<point>& oldPoints,
const UList<point>& newPoints
) const
{
// This Optimization causes a small discrepancy between the swept-volume of
......@@ -724,7 +717,7 @@ Foam::scalar Foam::face::sweptVol
Foam::tensor Foam::face::inertia
(
const pointField& p,
const UList<point>& p,
const point& refPt,
scalar density
) const
......@@ -819,7 +812,7 @@ int Foam::face::edgeDirection(const edge& e) const
}
Foam::label Foam::face::nTriangles(const pointField&) const
Foam::label Foam::face::nTriangles(const UList<point>&) const
{
return nTriangles();
}
......@@ -827,7 +820,7 @@ Foam::label Foam::face::nTriangles(const pointField&) const
Foam::label Foam::face::triangles
(
const pointField& points,
const UList<point>& points,
label& triI,
faceList& triFaces
) const
......@@ -841,7 +834,7 @@ Foam::label Foam::face::triangles
Foam::label Foam::face::nTrianglesQuads
(
const pointField& points,
const UList<point>& points,
label& triI,
label& quadI
) const
......@@ -855,7 +848,7 @@ Foam::label Foam::face::nTrianglesQuads
Foam::label Foam::face::trianglesQuads
(
const pointField& points,
const UList<point>& points,
label& triI,
label& quadI,
faceList& triFaces,
......@@ -866,9 +859,9 @@ Foam::label Foam::face::trianglesQuads
}
Foam::label Foam::longestEdge(const face& f, const pointField& pts)
Foam::label Foam::face::longestEdge(const UList<point>& pts) const
{
const edgeList& eds = f.edges();
const edgeList& eds = this->edges();
label longestEdgeI = -1;
scalar longestEdgeLength = -SMALL;
......@@ -888,4 +881,10 @@ Foam::label Foam::longestEdge(const face& f, const pointField& pts)
}
Foam::label Foam::longestEdge(const face& f, const UList<point>& pts)
{
return f.longestEdge(pts);
}
// ************************************************************************* //
......@@ -67,7 +67,7 @@ class DynamicList;
inline bool operator==(const face& a, const face& b);
inline bool operator!=(const face& a, const face& b);
inline Istream& operator>>(Istream&, face&);
inline Istream& operator>>(Istream& is, face& f);
/*---------------------------------------------------------------------------*\
Class face Declaration
......@@ -88,7 +88,7 @@ class face
//- Construct list of edge vectors for face
tmp<vectorField> calcEdges
(
const pointField& points
const UList<point>& points
) const;
//- Cos between neighbouring edges
......@@ -101,7 +101,7 @@ class face
//- Find index of largest internal angle on face
label mostConcaveAngle
(
const pointField& points,
const UList<point>& points,
const vectorField& edges,
scalar& edgeCos
) const;
......@@ -121,7 +121,7 @@ class face
label split
(
const splitMode mode,
const pointField& points,
const UList<point>& points,
label& triI,
label& quadI,
faceList& triFaces,
......@@ -149,23 +149,23 @@ public:
//- Construct null
inline face();
//- Construct given size
explicit inline face(label);
//- Construct given size, with invalid point labels (-1)
explicit inline face(const label sz);
//- Construct from list of labels
explicit inline face(const labelUList&);
explicit inline face(const labelUList& lst);