Commit e9fb8b85 authored by Will Bainbridge's avatar Will Bainbridge Committed by Andrew Heather
Browse files

tetIndices: Removed duplicate logic

The logic for generating tetrahedra from a face base point and an offset
was duplicated in a few places. It is now confined to the tetIndices
class.
parent a28f84c3
......@@ -1389,16 +1389,7 @@ bool Foam::polyMesh::pointInCell
for (label tetPti = 1; tetPti < f.size() - 1; tetPti++)
{
// Get tetIndices of face triangle
tetIndices faceTetIs
(
polyMeshTetDecomposition::triangleTetIndices
(
*this,
facei,
celli,
tetPti
)
);
tetIndices faceTetIs(celli, facei, tetPti);
triPointRef faceTri = faceTetIs.faceTri(*this);
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -530,11 +530,7 @@ Foam::List<Foam::tetIndices> Foam::polyMeshTetDecomposition::faceTetIndices
label cI
)
{
static label nWarnings = 0;
static const label maxWarnings = 100;
const faceList& pFaces = mesh.faces();
const labelList& pOwner = mesh.faceOwner();
const face& f = pFaces[fI];
......@@ -542,123 +538,15 @@ Foam::List<Foam::tetIndices> Foam::polyMeshTetDecomposition::faceTetIndices
List<tetIndices> faceTets(nTets);
bool own = (pOwner[fI] == cI);
label tetBasePtI = mesh.tetBasePtIs()[fI];
if (tetBasePtI == -1)
for (label tetPtI = 1; tetPtI < f.size() - 1; tetPtI ++)
{
if (nWarnings < maxWarnings)
{
WarningInFunction
<< "No base point for face " << fI << ", " << f
<< ", vertices " << UIndirectList<point>(mesh.points(), f)
<< ", produces a valid tet decomposition."
<< endl;
nWarnings++;
}
if (nWarnings == maxWarnings)
{
Warning<< "Suppressing any further warnings." << endl;
nWarnings++;
}
tetBasePtI = 0;
}
for (label tetPtI = 1; tetPtI < f.size() - 1; tetPtI++)
{
tetIndices& faceTetIs = faceTets[tetPtI - 1];
label facePtI = (tetPtI + tetBasePtI) % f.size();
label otherFacePtI = f.fcIndex(facePtI);
faceTetIs.cell() = cI;
faceTetIs.face() = fI;
faceTetIs.faceBasePt() = tetBasePtI;
if (own)
{
faceTetIs.facePtA() = facePtI;
faceTetIs.facePtB() = otherFacePtI;
}
else
{
faceTetIs.facePtA() = otherFacePtI;
faceTetIs.facePtB() = facePtI;
}
faceTetIs.tetPt() = tetPtI;
faceTets[tetPtI - 1] = tetIndices(cI, fI, tetPtI);
}
return faceTets;
}
Foam::tetIndices Foam::polyMeshTetDecomposition::triangleTetIndices
(
const polyMesh& mesh,
const label fI,
const label cI,
const label tetPtI
)
{
static label nWarnings = 0;
static const label maxWarnings = 100;
const face& f = mesh.faces()[fI];
bool own = (mesh.faceOwner()[fI] == cI);
label tetBasePtI = mesh.tetBasePtIs()[fI];
if (tetBasePtI == -1)
{
if (nWarnings < maxWarnings)
{
WarningInFunction
<< "No base point for face " << fI << ", " << f
<< ", vertices " << UIndirectList<point>(mesh.points(), f)
<< ", produces a valid tet decomposition."
<< endl;
nWarnings++;
}
if (nWarnings == maxWarnings)
{
Warning<< "Suppressing any further warnings." << endl;
nWarnings++;
}
tetBasePtI = 0;
}
tetIndices faceTetIs;
label facePtI = (tetPtI + tetBasePtI) % f.size();
label otherFacePtI = f.fcIndex(facePtI);
faceTetIs.cell() = cI;
faceTetIs.face() = fI;
faceTetIs.faceBasePt() = tetBasePtI;
if (own)
{
faceTetIs.facePtA() = facePtI;
faceTetIs.facePtB() = otherFacePtI;
}
else
{
faceTetIs.facePtA() = otherFacePtI;
faceTetIs.facePtB() = facePtI;
}
faceTetIs.tetPt() = tetPtI;
return faceTetIs;
}
Foam::List<Foam::tetIndices> Foam::polyMeshTetDecomposition::cellTetIndices
(
const polyMesh& mesh,
......@@ -713,16 +601,7 @@ Foam::tetIndices Foam::polyMeshTetDecomposition::findTet
for (label tetPtI = 1; tetPtI < f.size() - 1; tetPtI++)
{
// Get tetIndices of face triangle
tetIndices faceTetIs
(
triangleTetIndices
(
mesh,
fI,
cI,
tetPtI
)
);
tetIndices faceTetIs(cI, fI, tetPtI);
// Check if inside
if (faceTetIs.tet(mesh).inside(pt))
......
......@@ -130,15 +130,6 @@ public:
label cI
);
//- Return the tet decomposition of the given triangle of the given face
static tetIndices triangleTetIndices
(
const polyMesh& mesh,
label fI,
label cI,
const label tetPtI // offset in face
);
//- Return the tet decomposition of the given cell, see
// findFacePt for the meaning of the indices
static List<tetIndices> cellTetIndices
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,15 +25,19 @@ License
#include "tetIndices.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const Foam::label Foam::tetIndices::maxNWarnings = 100;
Foam::label Foam::tetIndices::nWarnings = 0;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::tetIndices::tetIndices()
:
celli_(-1),
facei_(-1),
faceBasePtI_(-1),
facePtAI_(-1),
facePtBI_(-1),
tetPti_(-1)
{}
......@@ -42,61 +46,15 @@ Foam::tetIndices::tetIndices
(
label celli,
label facei,
label faceBasePtI,
label facePtAI,
label facePtBI,
label tetPtI
)
:
celli_(celli),
facei_(facei),
faceBasePtI_(faceBasePtI),
facePtAI_(facePtAI),
facePtBI_(facePtBI),
tetPti_(tetPtI)
{}
Foam::tetIndices::tetIndices
(
label celli,
label facei,
label tetPtI,
const polyMesh& mesh
)
:
celli_(celli),
facei_(facei),
faceBasePtI_(-1),
facePtAI_(-1),
facePtBI_(-1),
tetPti_(tetPtI)
{
const faceList& pFaces = mesh.faces();
const labelList& pOwner = mesh.faceOwner();
const Foam::face& f = pFaces[facei_];
bool own = (pOwner[facei_] == celli_);
faceBasePtI_ = mesh.tetBasePtIs()[facei_];
label facePtI = (tetPti_ + faceBasePtI_) % f.size();
label otherFacePtI = f.fcIndex(facePtI);
if (own)
{
facePtAI_ = facePtI;
facePtBI_ = otherFacePtI;
}
else
{
facePtAI_ = otherFacePtI;
facePtBI_ = facePtI;
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::tetIndices::~tetIndices()
......@@ -107,12 +65,7 @@ Foam::tetIndices::~tetIndices()
Foam::Istream& Foam::operator>>(Istream& is, tetIndices& tI)
{
is >> tI.cell()
>> tI.face()
>> tI.faceBasePt()
>> tI.facePtA()
>> tI.facePtB()
>> tI.tetPt();
is >> tI.cell() >> tI.face() >> tI.tetPt();
is.check(FUNCTION_NAME);
return is;
......@@ -123,9 +76,6 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const tetIndices& tI)
{
os << tI.cell() << token::SPACE
<< tI.face() << token::SPACE
<< tI.faceBasePt() << token::SPACE
<< tI.facePtA() << token::SPACE
<< tI.facePtB() << token::SPACE
<< tI.tetPt() << token::SPACE
<< endl;
......
......@@ -83,28 +83,25 @@ class tetIndices
{
// Private data
//- Cell that this is a decomposed tet of
label celli_;
//- Cell that this is a decomposed tet of
label celli_;
//- Face that holds this decomposed tet
label facei_;
//- Face that holds this decomposed tet
label facei_;
//- Base point on the face
label faceBasePtI_;
//- Point on the face, *relative to the base point*, which
// characterises this tet on the face.
label tetPti_;
//- Point on the face such that the right-hand circulation
// {faceBasePtI_, facePtAI_, facePtBI_}
// forms a triangle that points out of the tet
label facePtAI_;
//- Point on the face such that the right-hand circulation
// {faceBasePtI_, facePtAI_, facePtBI_}
// forms a triangle that points out of the tet
label facePtBI_;
// Private static data
//- Point on the face, *relative to the base point*, which
// characterises this tet on the face.
label tetPti_;
//- Maximum number of bad tet warnings
static const label maxNWarnings;
//- Current number of bad tet warnings. Warnings stop when this reaches
// the maximum number.
static label nWarnings;
public:
......@@ -115,24 +112,7 @@ public:
tetIndices();
//- Construct from components
tetIndices
(
label celli,
label facei,
label faceBasePtI,
label facePtAI,
label facePtBI,
label tetPtI
);
//- Construct from cell, face, pt description of tet
tetIndices
(
label celli,
label facei,
label tetPtI,
const polyMesh& mesh
);
tetIndices(label celli, label facei, label tetPtI);
//- Destructor
......@@ -146,64 +126,35 @@ public:
//- Return the cell
inline label cell() const;
//- Return non-const access to the cell
inline label& cell();
//- Return the face
inline label face() const;
//- Return the face base point
inline label faceBasePt() const;
//- Return face point A
inline label facePtA() const;
//- Return face point B
inline label facePtB() const;
//- Return non-const access to the face
inline label& face();
//- Return the characterising tetPtI
inline label tetPt() const;
//- Return the geometry corresponding to this tet from the
// supplied mesh
inline tetPointRef tet(const polyMesh& mesh) const;
//- Return the geometry corresponding to this tet from the
// supplied mesh using the old positions
inline tetPointRef oldTet(const polyMesh& mesh) const;
//- Return the geometry corresponding to the tri on the
// mesh face for this tet from the supplied mesh. Normal of
// the tri points out of the cell.
inline triPointRef faceTri(const polyMesh& mesh) const;
//- Return non-const access to the characterising tetPtI
inline label& tetPt();
//- Return the point indices corresponding to the tri on the mesh
// face for this tet from the supplied mesh. Normal of
// the tri points out of the cell.
//- Return the indices corresponding to the tri on the face for
// this tet. The normal of the tri points out of the cell.
inline triFace faceTriIs(const polyMesh& mesh) const;
//- Return the geometry corresponding to the tri on the
// mesh face for this tet from the supplied mesh using
// the old position
inline triPointRef oldFaceTri(const polyMesh& mesh) const;
// Edit
//- Return non-const access to the cell
inline label& cell();
//- Return non-const access to the face
inline label& face();
//- Return non-const access to the face base point
inline label& faceBasePt();
//- Return non-const access to face point A
inline label& facePtA();
//- Return the geometry corresponding to this tet
inline tetPointRef tet(const polyMesh& mesh) const;
//- Return non-const access to face point B
inline label& facePtB();
//- Return the geometry corresponding to the tri on the face for
// this tet. The normal of the tri points out of the cell.
inline triPointRef faceTri(const polyMesh& mesh) const;
//- Return non-const access to the characterising tetPtI
inline label& tetPt();
//- Return the geometry corresponding to the tri on the face for
// this tet using the old positions.
inline triPointRef oldFaceTri(const polyMesh& mesh) const;
// Member Operators
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,181 +25,132 @@ License
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::tetIndices::cell() const
inline Foam::label Foam::tetIndices::cell() const
{
return celli_;
}
Foam::label Foam::tetIndices::face() const
inline Foam::label& Foam::tetIndices::cell()
{
return facei_;
return celli_;
}
Foam::label Foam::tetIndices::faceBasePt() const
inline Foam::label Foam::tetIndices::face() const
{
return faceBasePtI_;
return facei_;
}
Foam::label Foam::tetIndices::facePtA() const
inline Foam::label& Foam::tetIndices::face()
{
return facePtAI_;
return facei_;
}
Foam::label Foam::tetIndices::facePtB() const
inline Foam::label Foam::tetIndices::tetPt() const
{
return facePtBI_;
return tetPti_;
}
Foam::label Foam::tetIndices::tetPt() const
inline Foam::label& Foam::tetIndices::tetPt()
{
return tetPti_;
}
Foam::tetPointRef Foam::tetIndices::tet(const polyMesh& mesh) const
inline Foam::triFace Foam::tetIndices::faceTriIs(const polyMesh& mesh) const
{
const pointField& pPts = mesh.points();
const faceList& pFaces = mesh.faces();
const vectorField& pC = mesh.cellCentres();
const Foam::face& f = pFaces[facei_];
return tetPointRef
(
pC[celli_],
pPts[f[faceBasePtI_]],
pPts[f[facePtAI_]],
pPts[f[facePtBI_]]
);
}
const Foam::face& f = mesh.faces()[face()];
label faceBasePtI = mesh.tetBasePtIs()[face()];
Foam::tetPointRef Foam::tetIndices::oldTet(const polyMesh& mesh) const
{
const pointField& oldPPts = mesh.oldPoints();
const faceList& pFaces = mesh.faces();
if (faceBasePtI < 0)
{
faceBasePtI = 0;
if (nWarnings < maxNWarnings)
{
WarningInFunction
<< "No base point for face " << face() << ", " << f
<< ", produces a valid tet decomposition." << endl;
++ nWarnings;
}
if (nWarnings == maxNWarnings)
{
Warning
<< "Suppressing any further warnings." << endl;
++ nWarnings;
}
}
// We need to reconstruct the old Cc from oldPoints (it isn't
// stored)
point oldC = mesh.cells()[celli_].centre
(
oldPPts,
pFaces
);
label facePtI = (tetPt() + faceBasePtI) % f.size();
label faceOtherPtI = f.fcIndex(facePtI);
const Foam::face& f = pFaces[facei_];
if (mesh.faceOwner()[face()] != cell())
{
Swap(facePtI, faceOtherPtI);
}
return tetPointRef
(
oldC,
oldPPts[f[faceBasePtI_]],
oldPPts[f[facePtAI_]],
oldPPts[f[facePtBI_]]
);
return triFace(f[faceBasePtI], f[facePtI], f[faceOtherPtI]);