MRG: merged develop line back into integration branch

This commit is contained in:
Andrew Heather
2017-05-18 11:11:12 +01:00
514 changed files with 12134 additions and 16093 deletions

View File

@ -215,6 +215,7 @@ triSurface/triSurfaceSearch/triSurfaceSearch.C
triSurface/triSurfaceSearch/triSurfaceRegionSearch.C
triSurface/triangleFuncs/triangleFuncs.C
triSurface/surfaceFeatures/surfaceFeatures.C
triSurface/triSurfaceLoader/triSurfaceLoader.C
triSurface/triSurfaceTools/triSurfaceTools.C
triSurface/triSurfaceTools/geompack/geompack.C
triSurface/triSurfaceTools/pointToPointPlanarInterpolation.C

View File

@ -30,30 +30,31 @@ License
Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
(
const dictionary& dict, const objectRegistry& obr
const dictionary& dict,
const objectRegistry& obr
)
{
if (debug)
{
Pout<< "coordinateRotation::New(const dictionary&) : "
Pout<< "coordinateRotation::New"
"(const dictionary&, const objectRegistry&) : "
<< "constructing coordinateRotation"
<< endl;
}
word rotType = dict.lookup("type");
const word rotType = dict.lookup("type");
objectRegistryConstructorTable::iterator cstrIter =
objectRegistryConstructorTablePtr_->find(rotType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
if (!cstrIter.found())
{
FatalIOErrorInFunction
(
dict
) << "Unknown coordinateRotation type "
FatalIOErrorInFunction(dict)
<< "Unknown coordinateRotation type "
<< rotType << nl << nl
<< "Valid coordinateRotation types are :" << nl
<< dictionaryConstructorTablePtr_->sortedToc()
<< "[default: axes ]"
<< objectRegistryConstructorTablePtr_->sortedToc()
<< exit(FatalIOError);
}
@ -73,17 +74,15 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
<< endl;
}
word rotType = dict.lookup("type");
const word rotType = dict.lookup("type");
dictionaryConstructorTable::iterator cstrIter =
dictionaryConstructorTablePtr_->find(rotType);
if (cstrIter == dictionaryConstructorTablePtr_->end())
if (!cstrIter.found())
{
FatalIOErrorInFunction
(
dict
) << "Unknown coordinateRotation type "
FatalIOErrorInFunction(dict)
<< "Unknown coordinateRotation type "
<< rotType << nl << nl
<< "Valid coordinateRotation types are :" << nl
<< dictionaryConstructorTablePtr_->sortedToc()
@ -93,4 +92,5 @@ Foam::autoPtr<Foam::coordinateRotation> Foam::coordinateRotation::New
return autoPtr<coordinateRotation>(cstrIter()(dict));
}
// ************************************************************************* //

View File

@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -29,6 +29,7 @@ License
#include "addToMemberFunctionSelectionTable.H"
#include "ListOps.H"
#include "EdgeMap.H"
#include "PackedBoolList.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -286,16 +287,12 @@ void Foam::edgeMesh::scalePoints(const scalar scaleFactor)
}
void Foam::edgeMesh::mergePoints
(
const scalar mergeDist,
labelList& reversePointMap
)
void Foam::edgeMesh::mergePoints(const scalar mergeDist)
{
pointField newPoints;
labelList pointMap;
bool hasMerged = Foam::mergePoints
const bool hasMerged = Foam::mergePoints
(
points_,
mergeDist,
@ -307,92 +304,107 @@ void Foam::edgeMesh::mergePoints
if (hasMerged)
{
pointEdgesPtr_.clear();
pointEdgesPtr_.clear(); // connectivity change
points_.transfer(newPoints);
// connectivity changed
pointEdgesPtr_.clear();
// Renumber and make sure e[0] < e[1] (not really necessary)
forAll(edges_, edgeI)
{
edge& e = edges_[edgeI];
label p0 = pointMap[e[0]];
label p1 = pointMap[e[1]];
if (p0 < p1)
{
e[0] = p0;
e[1] = p1;
}
else
{
e[0] = p1;
e[1] = p0;
}
}
// Compact using a hashtable and commutative hash of edge.
EdgeMap<label> edgeToLabel(2*edges_.size());
label newEdgeI = 0;
forAll(edges_, edgeI)
{
const edge& e = edges_[edgeI];
if (e[0] != e[1])
{
if (edgeToLabel.insert(e, newEdgeI))
{
newEdgeI++;
}
}
}
edges_.setSize(newEdgeI);
forAllConstIter(EdgeMap<label>, edgeToLabel, iter)
{
edges_[iter()] = iter.key();
e[0] = pointMap[e[0]];
e[1] = pointMap[e[1]];
}
}
this->mergeEdges();
}
void Foam::edgeMesh::mergeEdges()
{
EdgeMap<label> existingEdges(2*edges_.size());
HashSet<edge, Hash<edge>> uniqEdges(2*edges_.size());
PackedBoolList pointIsUsed(points_.size());
label curEdgeI = 0;
label nUniqEdges = 0;
label nUniqPoints = 0;
forAll(edges_, edgeI)
{
const edge& e = edges_[edgeI];
if (existingEdges.insert(e, curEdgeI))
// Remove degenerate and repeated edges
// - reordering (e[0] < e[1]) is not really necessary
if (e[0] != e[1] && uniqEdges.insert(e))
{
curEdgeI++;
if (nUniqEdges != edgeI)
{
edges_[nUniqEdges] = e;
}
edges_[nUniqEdges].sort();
++nUniqEdges;
if (pointIsUsed.set(e[0], 1))
{
++nUniqPoints;
}
if (pointIsUsed.set(e[1], 1))
{
++nUniqPoints;
}
}
}
if (debug)
{
Info<< "Merging duplicate edges: "
<< edges_.size() - existingEdges.size()
<< " edges will be deleted." << endl;
<< (edges_.size() - nUniqEdges)
<< " edges will be deleted, "
<< (points_.size() - nUniqPoints)
<< " unused points will be removed." << endl;
}
edges_.setSize(existingEdges.size());
forAllConstIter(EdgeMap<label>, existingEdges, iter)
if (nUniqEdges < edges_.size())
{
edges_[iter()] = iter.key();
pointEdgesPtr_.clear(); // connectivity change
edges_.setSize(nUniqEdges); // truncate
}
if (nUniqPoints < points_.size())
{
pointEdgesPtr_.clear(); // connectivity change
// build a oldToNew point-map and rewrite the points.
// We can do this simultaneously since the point order is unchanged
// and we are only effectively eliminating some entries.
labelList pointMap(points_.size(), -1);
label newId = 0;
forAll(pointMap, pointi)
{
if (pointIsUsed[pointi])
{
pointMap[pointi] = newId;
if (newId < pointi)
{
// copy down
points_[newId] = points_[pointi];
}
++newId;
}
}
points_.setSize(newId);
// Renumber edges - already sorted (above)
forAll(edges_, edgeI)
{
edge& e = edges_[edgeI];
e[0] = pointMap[e[0]];
e[1] = pointMap[e[1]];
}
}
// connectivity changed
pointEdgesPtr_.clear();
}

View File

@ -2,8 +2,8 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
\\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -59,8 +59,8 @@ class Ostream;
// Forward declaration of friend functions and operators
class edgeMesh;
Istream& operator>>(Istream&, edgeMesh&);
Ostream& operator<<(Ostream&, const edgeMesh&);
Istream& operator>>(Istream& is, edgeMesh& em);
Ostream& operator<<(Ostream& os, const edgeMesh& em);
/*---------------------------------------------------------------------------*\
@ -109,7 +109,7 @@ public:
// Static
//- Can we read this file format?
static bool canRead(const fileName&, const bool verbose=false);
static bool canRead(const fileName& name, const bool verbose=false);
//- Can we read this file format?
static bool canReadType(const word& ext, const bool verbose=false);
@ -127,26 +127,23 @@ public:
edgeMesh();
//- Construct from components
edgeMesh(const pointField&, const edgeList&);
edgeMesh(const pointField& points, const edgeList& edges);
//- Construct by transferring components (points, edges).
edgeMesh
(
const Xfer<pointField>&,
const Xfer<edgeList>&
const Xfer<pointField>& pointLst,
const Xfer<edgeList>& edgeLst
);
//- Construct as copy
edgeMesh(const edgeMesh&);
edgeMesh(const edgeMesh& em);
//- Construct from file name (uses extension to determine type)
edgeMesh(const fileName&);
edgeMesh(const fileName& name);
//- Construct from file name (uses extension to determine type)
edgeMesh(const fileName&, const word& ext);
//- Construct from Istream
edgeMesh(Istream&);
edgeMesh(const fileName& name, const word& ext);
// Declare run-time constructor selection table
@ -168,12 +165,12 @@ public:
//- Select constructed from filename (explicit extension)
static autoPtr<edgeMesh> New
(
const fileName&,
const fileName& name,
const word& ext
);
//- Select constructed from filename (implicit extension)
static autoPtr<edgeMesh> New(const fileName&);
static autoPtr<edgeMesh> New(const fileName& name);
//- Destructor
@ -196,7 +193,7 @@ public:
);
//- Write to file
static void write(const fileName&, const edgeMesh&);
static void write(const fileName& name, const edgeMesh& mesh);
// Member Functions
@ -205,15 +202,15 @@ public:
void transfer(edgeMesh&);
//- Transfer contents to the Xfer container
Xfer<edgeMesh > xfer();
Xfer<edgeMesh> xfer();
// Read
//- Read from file. Chooses reader based on explicit extension
bool read(const fileName&, const word& ext);
bool read(const fileName& name, const word& ext);
//- Read from file. Chooses reader based on detected extension
virtual bool read(const fileName&);
virtual bool read(const fileName& name);
// Access
@ -246,13 +243,13 @@ public:
);
//- Scale points. A non-positive factor is ignored
virtual void scalePoints(const scalar);
virtual void scalePoints(const scalar scaleFactor);
//- Merge common points (points within mergeDist). Return map from
// old to new points.
virtual void mergePoints(const scalar mergeDist, labelList&);
//- Geometric merge points (points within mergeDist) prior to
// automatically calling mergeEdges().
virtual void mergePoints(const scalar mergeDist);
//- Merge duplicate edges
//- Merge duplicate edges and eliminate unused points.
virtual void mergeEdges();
@ -269,12 +266,12 @@ public:
// Member Operators
inline void operator=(const edgeMesh&);
inline void operator=(const edgeMesh& rhs);
// Ostream Operator
friend Ostream& operator<<(Ostream&, const edgeMesh&);
friend Istream& operator>>(Istream&, edgeMesh&);
friend Ostream& operator<<(Ostream& os, const edgeMesh& em);
friend Istream& operator>>(Istream& is, edgeMesh& em);
};

View File

@ -454,6 +454,34 @@ Foam::extendedEdgeMesh::extendedEdgeMesh(Istream& is)
}
Foam::extendedEdgeMesh::extendedEdgeMesh
(
const pointField& points,
const edgeList& edges
)
:
edgeMesh(points, edges),
concaveStart_(0),
mixedStart_(0),
nonFeatureStart_(0),
internalStart_(0),
flatStart_(0),
openStart_(0),
multipleStart_(0),
normals_(0),
normalVolumeTypes_(0),
edgeDirections_(0),
normalDirections_(0),
edgeNormals_(0),
featurePointNormals_(0),
featurePointEdges_(0),
regionEdges_(0),
pointTree_(),
edgeTree_(),
edgeTreesByType_()
{}
Foam::extendedEdgeMesh::extendedEdgeMesh
(
const Xfer<pointField>& pointLst,
@ -1260,20 +1288,36 @@ void Foam::extendedEdgeMesh::add(const extendedEdgeMesh& fem)
// ~~~~~~~
// Combine normals
DynamicField<point> newNormals(normals().size()+fem.normals().size());
DynamicField<point> newNormals
(
normals().size()
+ fem.normals().size()
);
newNormals.append(normals());
newNormals.append(fem.normals());
// Combine and re-index into newNormals
labelListList newEdgeNormals(edgeNormals().size()+fem.edgeNormals().size());
UIndirectList<labelList>(newEdgeNormals, reverseEdgeMap) =
edgeNormals();
UIndirectList<labelList>(newEdgeNormals, reverseFemEdgeMap) =
fem.edgeNormals();
forAll(reverseFemEdgeMap, i)
labelListList newEdgeNormals
(
edgeNormals().size()
+ fem.edgeNormals().size()
);
UIndirectList<labelList>
(
newEdgeNormals,
SubList<label>(reverseEdgeMap, edgeNormals().size())
) = edgeNormals();
UIndirectList<labelList>
(
newEdgeNormals,
SubList<label>(reverseFemEdgeMap, fem.edgeNormals().size())
) = fem.edgeNormals();
forAll(fem.edgeNormals(), i)
{
label mapI = reverseFemEdgeMap[i];
const label mapI = reverseFemEdgeMap[i];
labelList& en = newEdgeNormals[mapI];
forAll(en, j)
{
@ -1300,9 +1344,10 @@ void Foam::extendedEdgeMesh::add(const extendedEdgeMesh& fem)
newFeaturePointNormals,
SubList<label>(reverseFemPointMap, fem.featurePointNormals().size())
) = fem.featurePointNormals();
forAll(fem.featurePointNormals(), i)
{
label mapI = reverseFemPointMap[i];
const label mapI = reverseFemPointMap[i];
labelList& fn = newFeaturePointNormals[mapI];
forAll(fn, j)
{

View File

@ -250,7 +250,7 @@ public:
static label nEdgeTypes;
//- Can we read this file format?
static bool canRead(const fileName&, const bool verbose=false);
static bool canRead(const fileName& name, const bool verbose=false);
//- Can we read this file format?
static bool canReadType(const word& ext, const bool verbose=false);
@ -268,7 +268,7 @@ public:
extendedEdgeMesh();
//- Construct as copy
explicit extendedEdgeMesh(const extendedEdgeMesh&);
explicit extendedEdgeMesh(const extendedEdgeMesh& fem);
//- Construct from file name (uses extension to determine type)
extendedEdgeMesh(const fileName&);
@ -277,13 +277,16 @@ public:
extendedEdgeMesh(const fileName&, const word& ext);
//- Construct from Istream
extendedEdgeMesh(Istream&);
extendedEdgeMesh(Istream& is);
//- Construct from components
extendedEdgeMesh(const pointField& points, const edgeList& edges);
//- Construct by transferring components (points, edges)
extendedEdgeMesh
(
const Xfer<pointField>&,
const Xfer<edgeList>&
const Xfer<pointField>& pointLst,
const Xfer<edgeList>& edgeLst
);
//- Construct given a surface with selected edges,points
@ -346,12 +349,12 @@ public:
//- Select constructed from filename (explicit extension)
static autoPtr<extendedEdgeMesh> New
(
const fileName&,
const fileName& name,
const word& ext
);
//- Select constructed from filename (implicit extension)
static autoPtr<extendedEdgeMesh> New(const fileName&);
static autoPtr<extendedEdgeMesh> New(const fileName& name);
//- Destructor
@ -509,16 +512,16 @@ public:
// Edit
//- Transfer the contents of the argument and annul the argument
void transfer(extendedEdgeMesh&);
void transfer(extendedEdgeMesh& mesh);
//- Transfer contents to the Xfer container
Xfer<extendedEdgeMesh > xfer();
Xfer<extendedEdgeMesh> xfer();
//- Clear all storage
virtual void clear();
//- Add extendedEdgeMesh. No filtering of duplicates.
void add(const extendedEdgeMesh&);
void add(const extendedEdgeMesh& fem);
//- Flip normals. All concave become convex, all internal external
// etc.
@ -527,8 +530,8 @@ public:
//- Update with derived geometry
void autoMap
(
const pointField&,
const edgeList&,
const pointField& subPoints,
const edgeList& subEdges,
const labelList& pointMap,
const labelList& edgeMap
);
@ -565,10 +568,10 @@ public:
// Read
//- Read from file. Chooses reader based on explicit extension
bool read(const fileName&, const word& ext);
bool read(const fileName& name, const word& ext);
//- Read from file. Chooses reader based on detected extension
virtual bool read(const fileName&);
virtual bool read(const fileName& name);
// Write

View File

@ -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) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -26,6 +26,7 @@ License
#include "meshTools.H"
#include "polyMesh.H"
#include "hexMatcher.H"
#include "treeBoundBox.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
@ -209,16 +210,31 @@ void Foam::meshTools::writeOBJ
}
void Foam::meshTools::writeOBJ
(
Ostream& os,
const UList<point>& pts
)
{
forAll(pts, i)
{
const point& pt = pts[i];
os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
}
void Foam::meshTools::writeOBJ
(
Ostream& os,
const triad& t,
const point& pt
const point& origin
)
{
forAll(t, dirI)
{
writeOBJ(os, pt, pt + t[dirI]);
writeOBJ(os, origin, origin + t[dirI]);
}
}
@ -231,10 +247,9 @@ void Foam::meshTools::writeOBJ
label& count
)
{
os << "v" << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << endl;
os << "v" << ' ' << p2.x() << ' ' << p2.y() << ' ' << p2.z() << endl;
os << "l" << " " << (count + 1) << " " << (count + 2) << endl;
os << "v " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl;
os << "v " << p2.x() << ' ' << p2.y() << ' ' << p2.z() << nl;
os << "l " << (count + 1) << " " << (count + 2) << endl;
count += 2;
}
@ -247,12 +262,28 @@ void Foam::meshTools::writeOBJ
const point& p2
)
{
os << "v" << ' ' << p1.x() << ' ' << p1.y() << ' ' << p1.z() << endl;
os << "v " << p1.x() << ' ' << p1.y() << ' ' << p1.z() << nl;
os << "vn "
<< (p2.x() - p1.x()) << ' '
<< (p2.y() - p1.y()) << ' '
<< (p2.z() - p1.z()) << endl;
}
os << "vn"
<< ' ' << p2.x() - p1.x()
<< ' ' << p2.y() - p1.y()
<< ' ' << p2.z() - p1.z() << endl;
void Foam::meshTools::writeOBJ
(
Ostream& os,
const treeBoundBox& bb
)
{
writeOBJ(os, bb.points());
forAll(treeBoundBox::edges, edgei)
{
const edge& e = treeBoundBox::edges[edgei];
os << "l " << (e[0] + 1) << ' ' << (e[1] + 1) << nl;
}
}
@ -261,7 +292,7 @@ void Foam::meshTools::writeOBJ
Ostream& os,
const cellList& cells,
const faceList& faces,
const pointField& points,
const UList<point>& points,
const labelList& cellLabels
)
{
@ -342,7 +373,7 @@ Foam::label Foam::meshTools::findEdge
{
forAll(candidates, i)
{
label edgeI = candidates[i];
const label edgeI = candidates[i];
const edge& e = edges[edgeI];

View File

@ -49,8 +49,9 @@ SourceFiles
namespace Foam
{
class primitiveMesh;
class polyMesh;
class primitiveMesh;
class treeBoundBox;
/*---------------------------------------------------------------------------*\
Namespace meshTools Declaration
@ -101,23 +102,30 @@ namespace meshTools
// OBJ writing
//- Write obj representation of point
//- Write obj representation of a point
void writeOBJ
(
Ostream& os,
const point& pt
);
//- Write obj representation of a triad. Requires the location of the
//- Write obj representation of points
void writeOBJ
(
Ostream& os,
const UList<point>& pts
);
//- Write obj representation of a triad. Requires the origin of the
// triad to be supplied
void writeOBJ
(
Ostream& os,
const triad& t,
const point& pt
const point& origin
);
//- Write obj representation of a line connecting two points
//- Write obj representation of a line connecting two points.
// Need to keep track of points that have been added. count starts at 0
void writeOBJ
(
@ -135,13 +143,20 @@ namespace meshTools
const point& p2
);
//- Write obj representation of tree-bounding box as a series of lines
void writeOBJ
(
Ostream& os,
const treeBoundBox& bb
);
//- Write obj representation of faces subset
template<class FaceType>
void writeOBJ
(
Ostream& os,
const UList<FaceType>&,
const pointField&,
const UList<FaceType>& faces,
const UList<point>& points,
const labelList& faceLabels
);
@ -150,17 +165,17 @@ namespace meshTools
void writeOBJ
(
Ostream& os,
const UList<FaceType>&,
const pointField&
const UList<FaceType>& faces,
const UList<point>& points
);
//- Write obj representation of cell subset
void writeOBJ
(
Ostream& os,
const cellList&,
const faceList&,
const pointField&,
const cellList& cells,
const faceList& faces,
const UList<point>& points,
const labelList& cellLabels
);
@ -170,7 +185,7 @@ namespace meshTools
//- Is edge used by cell
bool edgeOnCell
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label edgeI
);
@ -178,7 +193,7 @@ namespace meshTools
//- Is edge used by face
bool edgeOnFace
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label facei,
const label edgeI
);
@ -186,7 +201,7 @@ namespace meshTools
//- Is face used by cell
bool faceOnCell
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label facei
);
@ -203,7 +218,7 @@ namespace meshTools
//- Return edge between two mesh vertices. Returns -1 if no edge.
label findEdge
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label v0,
const label v1
);
@ -211,7 +226,7 @@ namespace meshTools
//- Return edge shared by two faces. Throws error if no edge found.
label getSharedEdge
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label f0,
const label f1
);
@ -219,7 +234,7 @@ namespace meshTools
//- Return face shared by two cells. Throws error if none found.
label getSharedFace
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label cell0,
const label cell1
);
@ -227,7 +242,7 @@ namespace meshTools
//- Get faces on cell using edgeI. Throws error if no two found.
void getEdgeFaces
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label edgeI,
label& face0,
@ -238,17 +253,17 @@ namespace meshTools
// connected to vertex but not edgeI. Throws error if none found.
label otherEdge
(
const primitiveMesh&,
const primitiveMesh& mesh,
const labelList& edgeLabels,
const label edgeI,
const label vertI
const label thisEdgeI,
const label thisVertI
);
//- Return face on cell using edgeI but not facei. Throws error
// if none found.
label otherFace
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label facei,
const label edgeI
@ -258,7 +273,7 @@ namespace meshTools
// if face not internal.
label otherCell
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label facei
);
@ -267,7 +282,7 @@ namespace meshTools
// of startVertI)
label walkFace
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label facei,
const label startEdgeI,
const label startVertI,
@ -309,19 +324,19 @@ namespace meshTools
//- Given edge on hex find other 'parallel', non-connected edges.
void getParallelEdges
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label e0,
label&,
label&,
label&
label& e1,
label& e2,
label& e3
);
//- Given edge on hex find all 'parallel' (i.e. non-connected)
// edges and average direction of them
vector edgeToCutDir
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const label edgeI
);
@ -330,7 +345,7 @@ namespace meshTools
// return one of them.
label cutDirToEdge
(
const primitiveMesh&,
const primitiveMesh& mesh,
const label celli,
const vector& cutDir
);

View File

@ -28,7 +28,7 @@ void Foam::meshTools::writeOBJ
(
Ostream& os,
const UList<FaceType>& faces,
const pointField& points,
const UList<point>& points,
const labelList& faceLabels
)
{
@ -64,7 +64,7 @@ void Foam::meshTools::writeOBJ
(
Ostream& os,
const UList<FaceType>& faces,
const pointField& points
const UList<point>& points
)
{
labelList allFaces(faces.size());

View File

@ -1,146 +1,146 @@
1. OVERVIEW
This code accompanies the paper:
This code accompanies the paper:
Brian Mirtich, "Fast and Accurate Computation of
Polyhedral Mass Properties," journal of graphics
tools, volume 1, number 2, 1996.
Brian Mirtich, "Fast and Accurate Computation of
Polyhedral Mass Properties," journal of graphics
tools, volume 1, number 2, 1996.
It computes the ten volume integrals needed for
determining the center of mass, moments of
inertia, and products of inertia for a uniform
density polyhedron. From this information, a
body frame can be computed.
It computes the ten volume integrals needed for
determining the center of mass, moments of
inertia, and products of inertia for a uniform
density polyhedron. From this information, a
body frame can be computed.
To compile the program, use an ANSI compiler, and
type something like
% cc volInt.c -O2 -lm -o volInt
To compile the program, use an ANSI compiler, and
type something like
% cc volInt.c -O2 -lm -o volInt
Revision history
Revision history
26 Jan 1996 Program creation.
26 Jan 1996 Program creation.
3 Aug 1996 Corrected bug arising when polyhedron density
is not 1.0. Changes confined to function main().
Thanks to Zoran Popovic for catching this one.
3 Aug 1996 Corrected bug arising when polyhedron density
is not 1.0. Changes confined to function main().
Thanks to Zoran Popovic for catching this one.
2. POLYHEDRON GEOMETRY FILES
The program reads a data file specified on the
command line. This data file describes the
geometry of a polyhedron, and has the following
format:
The program reads a data file specified on the
command line. This data file describes the
geometry of a polyhedron, and has the following
format:
N
N
x_0 y_0 z_0
x_1 y_1 z_1
.
.
.
x_{N-1} y_{N-1} z_{N-1}
x_0 y_0 z_0
x_1 y_1 z_1
.
.
.
x_{N-1} y_{N-1} z_{N-1}
M
M
k1 v_{1,1} v_{1,2} ... v_{1,k1}
k2 v_{2,1} v_{2,2} ... v_{2,k2}
.
.
.
kM v_{M,1} v_{M,2} ... v_{M,kM}
k1 v_{1,1} v_{1,2} ... v_{1,k1}
k2 v_{2,1} v_{2,2} ... v_{2,k2}
.
.
.
kM v_{M,1} v_{M,2} ... v_{M,kM}
where:
N number of vertices on polyhedron
x_i y_i z_i x, y, and z coordinates of ith vertex
M number of faces on polyhedron
ki number of vertices on ith face
v_{i,j} jth vertex on ith face
where:
N number of vertices on polyhedron
x_i y_i z_i x, y, and z coordinates of ith vertex
M number of faces on polyhedron
ki number of vertices on ith face
v_{i,j} jth vertex on ith face
In English:
In English:
First the number of vertices are specified. Next
the vertices are defined by listing the 3
coordinates of each one. Next the number of faces
are specified. Finally, the faces themselves are
specified. A face is specified by first giving
the number of vertices around the polygonal face,
followed by the (integer) indices of these
vertices. When specifying indices, note that
they must be given in counter-clockwise order
(when looking at the face from outside the
polyhedron), and the vertices are indexed from 0
to N-1 for a polyhedron with N faces.
First the number of vertices are specified. Next
the vertices are defined by listing the 3
coordinates of each one. Next the number of faces
are specified. Finally, the faces themselves are
specified. A face is specified by first giving
the number of vertices around the polygonal face,
followed by the (integer) indices of these
vertices. When specifying indices, note that
they must be given in counter-clockwise order
(when looking at the face from outside the
polyhedron), and the vertices are indexed from 0
to N-1 for a polyhedron with N faces.
White space can be inserted (or not) as desired.
Three example polyhedron geometry files are included:
White space can be inserted (or not) as desired.
Three example polyhedron geometry files are included:
cube A cube, 20 units on a side, centered at
the origin and aligned with the coordinate axes.
cube A cube, 20 units on a side, centered at
the origin and aligned with the coordinate axes.
tetra A tetrahedron formed by taking the convex
hull of the origin, and the points (5,0,0),
(0,4,0), and (0,0,3).
tetra A tetrahedron formed by taking the convex
hull of the origin, and the points (5,0,0),
(0,4,0), and (0,0,3).
icosa An icosahedron with vertices lying on the unit
sphere, centered at the origin.
icosa An icosahedron with vertices lying on the unit
sphere, centered at the origin.
3. RUNNING THE PROGRAM
Simply type,
% volInt <polyhedron geometry filename>
Simply type,
The program will read in the geometry of the
polyhedron, and the print out the ten volume
integrals.
% volInt <polyhedron geometry filename>
The program also computes some of the mass
properties which may be inferred from the volume
integrals. A density of 1.0 is assumed, although
this may be changed in function main(). The
center of mass is computed as well as the inertia
tensor relative to a frame with origin at the
center of mass. Note, however, that this matrix
may not be diagonal. If not, a diagonalization
routine must be performed, to determine the
orientation of the true body frame relative to
the original model frame. The Jacobi method
works quite well (see Numerical Recipes in C by
Press, et. al.).
The program will read in the geometry of the
polyhedron, and the print out the ten volume
integrals.
The program also computes some of the mass
properties which may be inferred from the volume
integrals. A density of 1.0 is assumed, although
this may be changed in function main(). The
center of mass is computed as well as the inertia
tensor relative to a frame with origin at the
center of mass. Note, however, that this matrix
may not be diagonal. If not, a diagonalization
routine must be performed, to determine the
orientation of the true body frame relative to
the original model frame. The Jacobi method
works quite well (see Numerical Recipes in C by
Press, et. al.).
4. DISCLAIMERS
1. The volume integration code has been written
to match the development and algorithms presented
in the paper, and not with maximum optimization
in mind. While inherently very efficient, a few
more cycles can be squeezed out of the algorithm.
This is left as an exercise. :)
1. The volume integration code has been written
to match the development and algorithms presented
in the paper, and not with maximum optimization
in mind. While inherently very efficient, a few
more cycles can be squeezed out of the algorithm.
This is left as an exercise. :)
2. Don't like global variables? The three
procedures which evaluate the volume integrals
can be combined into a single procedure with two
nested loops. In addition to providing some
speedup, all of the global variables can then be
made local.
2. Don't like global variables? The three
procedures which evaluate the volume integrals
can be combined into a single procedure with two
nested loops. In addition to providing some
speedup, all of the global variables can then be
made local.
3. The polyhedron data structure used by the
program is admittedly lame; much better schemes
are possible. The idea here is just to give the
basic integral evaluation code, which will have
to be adjusted for other polyhedron data
structures.
3. The polyhedron data structure used by the
program is admittedly lame; much better schemes
are possible. The idea here is just to give the
basic integral evaluation code, which will have
to be adjusted for other polyhedron data
structures.
4. There is no error checking for the input
files. Be careful. Note the hard limits
#defined for the number of vertices, number of
faces, and number of vertices per faces.
4. There is no error checking for the input
files. Be careful. Note the hard limits
#defined for the number of vertices, number of
faces, and number of vertices per faces.

View File

@ -63,9 +63,6 @@ class searchableSurfaces
//- Region names per surface
List<wordList> regionNames_;
////- From global region name to surface and region on surface
//HashTable<labelPair> regionNames_;
//- Indices of all surfaces. Precalculated and stored.
labelList allSurfaces_;

View File

@ -30,29 +30,26 @@ License
#include "addToRunTimeSelectionTable.H"
#include "mapDistributePolyMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(cellSet, 0);
addToRunTimeSelectionTable(topoSet, cellSet, word);
addToRunTimeSelectionTable(topoSet, cellSet, size);
addToRunTimeSelectionTable(topoSet, cellSet, set);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
cellSet::cellSet(const IOobject& obj)
Foam::cellSet::cellSet(const IOobject& obj)
:
topoSet(obj, typeName)
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const polyMesh& mesh,
const word& name,
@ -67,7 +64,7 @@ cellSet::cellSet
}
cellSet::cellSet
Foam::cellSet::cellSet
(
const polyMesh& mesh,
const word& name,
@ -79,7 +76,7 @@ cellSet::cellSet
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const polyMesh& mesh,
const word& name,
@ -91,7 +88,7 @@ cellSet::cellSet
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const polyMesh& mesh,
const word& name,
@ -103,8 +100,20 @@ cellSet::cellSet
{}
Foam::cellSet::cellSet
(
const polyMesh& mesh,
const word& name,
const UList<label>& set,
writeOption w
)
:
topoSet(mesh, name, set, w)
{}
// Database constructors (for when no mesh available)
cellSet::cellSet
Foam::cellSet::cellSet
(
const Time& runTime,
const word& name,
@ -114,32 +123,13 @@ cellSet::cellSet
:
topoSet
(
IOobject
(
name,
runTime.findInstance
(
polyMesh::meshSubDir/"sets", //polyMesh::meshSubDir,
word::null, //"faces"
IOobject::MUST_READ,
runTime.findInstance
(
polyMesh::meshSubDir,
"faces",
IOobject::READ_IF_PRESENT
)
),
polyMesh::meshSubDir/"sets",
runTime,
r,
w
),
findIOobject(runTime, name, r, w),
typeName
)
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const Time& runTime,
const word& name,
@ -149,32 +139,13 @@ cellSet::cellSet
:
topoSet
(
IOobject
(
name,
runTime.findInstance
(
polyMesh::meshSubDir/"sets", //polyMesh::meshSubDir,
word::null, //"faces"
IOobject::NO_READ,
runTime.findInstance
(
polyMesh::meshSubDir,
"faces",
IOobject::READ_IF_PRESENT
)
),
polyMesh::meshSubDir/"sets",
runTime,
IOobject::NO_READ,
w
),
findIOobject(runTime, name, IOobject::NO_READ, w),
size
)
{}
cellSet::cellSet
Foam::cellSet::cellSet
(
const Time& runTime,
const word& name,
@ -184,26 +155,7 @@ cellSet::cellSet
:
topoSet
(
IOobject
(
name,
runTime.findInstance
(
polyMesh::meshSubDir/"sets", //polyMesh::meshSubDir,
word::null, //"faces"
IOobject::NO_READ,
runTime.findInstance
(
polyMesh::meshSubDir,
"faces",
IOobject::READ_IF_PRESENT
)
),
polyMesh::meshSubDir/"sets",
runTime,
IOobject::NO_READ,
w
),
findIOobject(runTime, name, IOobject::NO_READ, w),
set
)
{}
@ -211,25 +163,25 @@ cellSet::cellSet
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
cellSet::~cellSet()
Foam::cellSet::~cellSet()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
label cellSet::maxSize(const polyMesh& mesh) const
Foam::label Foam::cellSet::maxSize(const polyMesh& mesh) const
{
return mesh.nCells();
}
void cellSet::updateMesh(const mapPolyMesh& morphMap)
void Foam::cellSet::updateMesh(const mapPolyMesh& morphMap)
{
updateLabels(morphMap.reverseCellMap());
}
void cellSet::distribute(const mapDistributePolyMesh& map)
void Foam::cellSet::distribute(const mapDistributePolyMesh& map)
{
boolList inSet(map.nOldCells());
forAllConstIter(cellSet, *this, iter)
@ -271,8 +223,4 @@ void Foam::cellSet::writeDebug
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -53,7 +53,7 @@ class cellSet
// Private Member Functions
//- Disallow default bitwise copy construct
cellSet(const cellSet&);
cellSet(const cellSet&) = delete;
public:
@ -81,7 +81,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const label sizes,
const label size,
writeOption w=NO_WRITE
);
@ -90,7 +90,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const topoSet&,
const topoSet& set,
writeOption w=NO_WRITE
);
@ -99,7 +99,16 @@ public:
(
const polyMesh& mesh,
const word& name,
const labelHashSet&,
const labelHashSet& set,
writeOption w=NO_WRITE
);
//- Construct from additional list of labels for the labelHashSet
cellSet
(
const polyMesh& mesh,
const word& name,
const UList<label>& set,
writeOption w=NO_WRITE
);

View File

@ -31,29 +31,26 @@ License
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(faceSet, 0);
addToRunTimeSelectionTable(topoSet, faceSet, word);
addToRunTimeSelectionTable(topoSet, faceSet, size);
addToRunTimeSelectionTable(topoSet, faceSet, set);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
faceSet::faceSet(const IOobject& obj)
Foam::faceSet::faceSet(const IOobject& obj)
:
topoSet(obj, typeName)
{}
faceSet::faceSet
Foam::faceSet::faceSet
(
const polyMesh& mesh,
const word& name,
@ -67,7 +64,7 @@ faceSet::faceSet
}
faceSet::faceSet
Foam::faceSet::faceSet
(
const polyMesh& mesh,
const word& name,
@ -79,7 +76,7 @@ faceSet::faceSet
{}
faceSet::faceSet
Foam::faceSet::faceSet
(
const polyMesh& mesh,
const word& name,
@ -91,7 +88,7 @@ faceSet::faceSet
{}
faceSet::faceSet
Foam::faceSet::faceSet
(
const polyMesh& mesh,
const word& name,
@ -103,15 +100,27 @@ faceSet::faceSet
{}
Foam::faceSet::faceSet
(
const polyMesh& mesh,
const word& name,
const UList<label>& set,
writeOption w
)
:
topoSet(mesh, name, set, w)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
faceSet::~faceSet()
Foam::faceSet::~faceSet()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void faceSet::sync(const polyMesh& mesh)
void Foam::faceSet::sync(const polyMesh& mesh)
{
boolList set(mesh.nFaces(), false);
@ -150,19 +159,19 @@ void faceSet::sync(const polyMesh& mesh)
}
label faceSet::maxSize(const polyMesh& mesh) const
Foam::label Foam::faceSet::maxSize(const polyMesh& mesh) const
{
return mesh.nFaces();
}
void faceSet::updateMesh(const mapPolyMesh& morphMap)
void Foam::faceSet::updateMesh(const mapPolyMesh& morphMap)
{
updateLabels(morphMap.reverseFaceMap());
}
void faceSet::distribute(const mapDistributePolyMesh& map)
void Foam::faceSet::distribute(const mapDistributePolyMesh& map)
{
boolList inSet(map.nOldFaces());
forAllConstIter(faceSet, *this, iter)
@ -193,7 +202,7 @@ void faceSet::distribute(const mapDistributePolyMesh& map)
}
void faceSet::writeDebug
void Foam::faceSet::writeDebug
(
Ostream& os,
const primitiveMesh& mesh,
@ -204,8 +213,4 @@ void faceSet::writeDebug
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -51,7 +51,6 @@ class faceSet
public topoSet
{
public:
//- Runtime type information
@ -78,7 +77,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const label,
const label size,
writeOption w=NO_WRITE
);
@ -87,7 +86,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const topoSet&,
const topoSet& set,
writeOption w=NO_WRITE
);
@ -96,7 +95,16 @@ public:
(
const polyMesh& mesh,
const word& name,
const labelHashSet&,
const labelHashSet& set,
writeOption w=NO_WRITE
);
//- Construct from additional list of labels for the labelHashSet
faceSet
(
const polyMesh& mesh,
const word& name,
const UList<label>& set,
writeOption w=NO_WRITE
);

View File

@ -28,32 +28,28 @@ License
#include "polyMesh.H"
#include "syncTools.H"
#include "mapDistributePolyMesh.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(pointSet, 0);
addToRunTimeSelectionTable(topoSet, pointSet, word);
addToRunTimeSelectionTable(topoSet, pointSet, size);
addToRunTimeSelectionTable(topoSet, pointSet, set);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
pointSet::pointSet(const IOobject& obj)
Foam::pointSet::pointSet(const IOobject& obj)
:
topoSet(obj, typeName)
{}
pointSet::pointSet
Foam::pointSet::pointSet
(
const polyMesh& mesh,
const word& name,
@ -67,7 +63,7 @@ pointSet::pointSet
}
pointSet::pointSet
Foam::pointSet::pointSet
(
const polyMesh& mesh,
const word& name,
@ -79,7 +75,7 @@ pointSet::pointSet
{}
pointSet::pointSet
Foam::pointSet::pointSet
(
const polyMesh& mesh,
const word& name,
@ -91,7 +87,7 @@ pointSet::pointSet
{}
pointSet::pointSet
Foam::pointSet::pointSet
(
const polyMesh& mesh,
const word& name,
@ -103,15 +99,27 @@ pointSet::pointSet
{}
Foam::pointSet::pointSet
(
const polyMesh& mesh,
const word& name,
const UList<label>& set,
writeOption w
)
:
topoSet(mesh, name, set, w)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
pointSet::~pointSet()
Foam::pointSet::~pointSet()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void pointSet::sync(const polyMesh& mesh)
void Foam::pointSet::sync(const polyMesh& mesh)
{
// Convert to boolList
@ -145,19 +153,19 @@ void pointSet::sync(const polyMesh& mesh)
}
label pointSet::maxSize(const polyMesh& mesh) const
Foam::label Foam::pointSet::maxSize(const polyMesh& mesh) const
{
return mesh.nPoints();
}
void pointSet::updateMesh(const mapPolyMesh& morphMap)
void Foam::pointSet::updateMesh(const mapPolyMesh& morphMap)
{
updateLabels(morphMap.reversePointMap());
}
void pointSet::distribute(const mapDistributePolyMesh& map)
void Foam::pointSet::distribute(const mapDistributePolyMesh& map)
{
boolList inSet(map.nOldPoints());
forAllConstIter(pointSet, *this, iter)
@ -188,7 +196,7 @@ void pointSet::distribute(const mapDistributePolyMesh& map)
}
void pointSet::writeDebug
void Foam::pointSet::writeDebug
(
Ostream& os,
const primitiveMesh& mesh,
@ -198,8 +206,4 @@ void pointSet::writeDebug
topoSet::writeDebug(os, mesh.points(), maxLen);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View File

@ -78,7 +78,16 @@ public:
(
const polyMesh& mesh,
const word& name,
const label,
const label size,
writeOption w=NO_WRITE
);
//- Construct from existing set
pointSet
(
const polyMesh& mesh,
const word& name,
const topoSet& set,
writeOption w=NO_WRITE
);
@ -87,16 +96,16 @@ public:
(
const polyMesh& mesh,
const word& name,
const topoSet&,
const labelHashSet& set,
writeOption w=NO_WRITE
);
//- Construct from additional labelHashSet
//- Construct from additional list of labels for the labelHashSet
pointSet
(
const polyMesh& mesh,
const word& name,
const labelHashSet&,
const UList<label>& set,
writeOption w=NO_WRITE
);

View File

@ -289,6 +289,63 @@ void Foam::topoSet::writeDebug
}
Foam::IOobject Foam::topoSet::findIOobject
(
const polyMesh& mesh,
const word& name,
readOption r,
writeOption w
)
{
return IOobject
(
name,
mesh.time().findInstance
(
mesh.dbDir()/polyMesh::meshSubDir/"sets",
word::null,
r,
mesh.facesInstance()
),
polyMesh::meshSubDir/"sets",
mesh,
r,
w
);
}
Foam::IOobject Foam::topoSet::findIOobject
(
const Time& runTime,
const word& name,
readOption r,
writeOption w
)
{
return IOobject
(
name,
runTime.findInstance
(
polyMesh::meshSubDir/"sets",
word::null,
IOobject::MUST_READ,
runTime.findInstance
(
polyMesh::meshSubDir,
"faces",
IOobject::READ_IF_PRESENT
)
),
polyMesh::meshSubDir/"sets",
runTime,
r,
w
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::topoSet::topoSet(const IOobject& obj, const word& wantedType)
@ -324,24 +381,7 @@ Foam::topoSet::topoSet
writeOption w
)
:
regIOobject
(
IOobject
(
name,
mesh.time().findInstance
(
mesh.dbDir()/polyMesh::meshSubDir/"sets",
word::null,
r, //IOobject::MUST_READ,
mesh.facesInstance()
),
polyMesh::meshSubDir/"sets",
mesh,
r,
w
)
)
regIOobject(findIOobject(mesh, name, r, w))
{
if
(
@ -371,24 +411,7 @@ Foam::topoSet::topoSet
writeOption w
)
:
regIOobject
(
IOobject
(
name,
mesh.time().findInstance
(
mesh.dbDir()/polyMesh::meshSubDir/"sets",
word::null,
IOobject::NO_READ,
mesh.facesInstance()
),
polyMesh::meshSubDir/"sets",
mesh,
IOobject::NO_READ,
w
)
),
regIOobject(findIOobject(mesh, name, IOobject::NO_READ, w)),
labelHashSet(size)
{}
@ -401,24 +424,20 @@ Foam::topoSet::topoSet
writeOption w
)
:
regIOobject
(
IOobject
(
name,
mesh.time().findInstance
(
mesh.dbDir()/polyMesh::meshSubDir/"sets",
word::null,
IOobject::NO_READ,
mesh.facesInstance()
),
polyMesh::meshSubDir/"sets",
mesh,
IOobject::NO_READ,
w
)
),
regIOobject(findIOobject(mesh, name, IOobject::NO_READ, w)),
labelHashSet(set)
{}
Foam::topoSet::topoSet
(
const polyMesh& mesh,
const word& name,
const UList<label>& set,
writeOption w
)
:
regIOobject(findIOobject(mesh, name, IOobject::NO_READ, w)),
labelHashSet(set)
{}

View File

@ -108,7 +108,29 @@ protected:
//- Disallow default bitwise copy construct
topoSet(const topoSet&);
topoSet(const topoSet&) = delete;
protected:
//- Helper for constructor - return IOobject in the polyMesh/sets
static IOobject findIOobject
(
const polyMesh& mesh,
const word& name,
readOption r,
writeOption w
);
//- Helper for constructor - return IOobject in the polyMesh/sets
static IOobject findIOobject
(
const Time& runTime,
const word& name,
readOption r,
writeOption w
);
public:
@ -175,7 +197,7 @@ public:
//- Construct from IOobject as explicitly passed type.
// Can't use typeName info here since subclasses not yet instantiated
topoSet(const IOobject&, const word& wantedType);
topoSet(const IOobject& obj, const word& wantedType);
//- Construct from polyMesh and name. Searches for a polyMesh/sets
// directory but not beyond mesh.facesInstance.
@ -195,7 +217,7 @@ public:
(
const polyMesh& mesh,
const word& name,
const label,
const label size,
writeOption w=NO_WRITE
);
@ -206,7 +228,18 @@ public:
(
const polyMesh& mesh,
const word& name,
const labelHashSet&,
const labelHashSet& set,
writeOption w=NO_WRITE
);
//- Construct empty from additional labelHashSet
// Searches for a polyMesh/sets
// directory but not beyond mesh.facesInstance.
topoSet
(
const polyMesh& mesh,
const word& name,
const UList<label>&,
writeOption w=NO_WRITE
);

View File

@ -25,9 +25,7 @@ License
#include "edgeIntersections.H"
#include "triSurfaceSearch.H"
#include "labelPairLookup.H"
#include "OFstream.H"
#include "HashSet.H"
#include "triSurface.H"
#include "pointIndexHit.H"
#include "treeDataTriSurface.H"
@ -260,7 +258,7 @@ bool Foam::edgeIntersections::inlinePerturb
if (perturbStart)
{
// Perturb with something (hopefully) larger than tolerance.
scalar t = 4.0*(rndGen.scalar01() - 0.5);
scalar t = 4.0*(rndGen.sample01<scalar>() - 0.5);
points1[v0] += t*surf1PointTol[e[0]]*n;
const labelList& pEdges = surf1.pointEdges()[e[0]];
@ -273,7 +271,7 @@ bool Foam::edgeIntersections::inlinePerturb
if (perturbEnd)
{
// Perturb with something larger than tolerance.
scalar t = 4.0*(rndGen.scalar01() - 0.5);
scalar t = 4.0*(rndGen.sample01<scalar>() - 0.5);
points1[v1] += t*surf1PointTol[e[1]]*n;
const labelList& pEdges = surf1.pointEdges()[e[1]];
@ -320,7 +318,7 @@ bool Foam::edgeIntersections::rotatePerturb
//label pointi = e[0];
// Generate random vector slightly larger than tolerance.
vector rndVec = rndGen.vector01() - vector(0.5, 0.5, 0.5);
vector rndVec = rndGen.sample01<vector>() - vector(0.5, 0.5, 0.5);
// Make sure rndVec only perp to edge
vector n(points1[meshPoints[e[1]]] - points1[meshPoints[e[0]]]);
@ -405,7 +403,8 @@ bool Foam::edgeIntersections::offsetPerturb
if (nearType == triPointRef::POINT || nearType == triPointRef::EDGE)
{
// Shift edge towards tri centre
vector offset = 0.01*rndGen.scalar01()*(ctr - pHit.hitPoint());
vector offset =
0.01*rndGen.sample01<scalar>()*(ctr - pHit.hitPoint());
// shift e[0]
points1[meshPoints[e[0]]] += offset;

View File

@ -25,9 +25,8 @@ License
#include "surfaceIntersection.H"
#include "triSurfaceSearch.H"
#include "labelPairLookup.H"
#include "OFstream.H"
#include "HashSet.H"
#include "labelPairHashes.H"
#include "triSurface.H"
#include "pointIndexHit.H"
#include "mergePoints.H"

View File

@ -59,7 +59,7 @@ SourceFiles
#include "DynamicList.H"
#include "point.H"
#include "edge.H"
#include "labelPairLookup.H"
#include "labelPairHashes.H"
#include "typeInfo.H"
#include "edgeList.H"
#include "pointIndexHit.H"

View File

@ -25,7 +25,7 @@ License
#include "surfaceIntersection.H"
#include "triSurfaceSearch.H"
#include "labelPairLookup.H"
#include "labelPairHashes.H"
#include "OFstream.H"
#include "HashSet.H"
#include "triSurface.H"

View File

@ -1,59 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
Typedef
Foam::labelPairLookup
Description
A HashTable for two labels to another label.
Used for e.g. for face1, face2 to shared edge.
Note
The hash table is based on a FixedList and not edge, since an edge
hashes commutatively!
\*---------------------------------------------------------------------------*/
#ifndef labelPairLookup_H
#define labelPairLookup_H
#include "FixedList.H"
#include "HashTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
typedef HashTable
<
label,
FixedList<label, 2>,
FixedList<label, 2>::Hash<>
> labelPairLookup;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,262 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
\*---------------------------------------------------------------------------*/
#include "triSurfaceLoader.H"
#include "fileNameList.H"
#include "Time.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::triSurfaceLoader::triSurfaceLoader(const fileName& directory)
:
directory_(directory),
available_(),
selected_()
{
readDir();
}
Foam::triSurfaceLoader::triSurfaceLoader(const Time& runTime)
:
directory_(runTime.constantPath()/"triSurface"),
available_(),
selected_()
{
readDir();
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::triSurfaceLoader::~triSurfaceLoader()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::label Foam::triSurfaceLoader::readDir()
{
fileNameList files = Foam::readDir(directory_, fileName::FILE);
// Will be using triSurface
//
// - filter according to what is supported
//
// Transform from fileName to word and eliminate duplicates
// (eg, files with/without .gz)
wordHashSet names(2*files.size());
forAll(files, filei)
{
const fileName& f = files[filei];
if (triSurface::canRead(f))
{
names.insert(f.name());
}
}
available_ = names.sortedToc(); // Also hashes the names
return available_.size();
}
Foam::label Foam::triSurfaceLoader::selectAll()
{
selected_ = available_;
return selected_.size();
}
Foam::label Foam::triSurfaceLoader::select(const word& name)
{
if (available_.found(name))
{
selected_ = wordList{name}; // hashedWordList::operator[] is hidden!
}
else
{
selected_.clear();
}
return selected_.size();
}
Foam::label Foam::triSurfaceLoader::select(const wordRe& mat)
{
DynamicList<label> foundIds(available_.size());
if (mat.isPattern())
{
foundIds = findMatchingStrings(mat, available_);
sort(foundIds);
}
else
{
const word& plain = static_cast<const word&>(mat);
if (available_.found(plain))
{
foundIds.append(available_[plain]);
}
else
{
FatalErrorInFunction
<< "Specified the surfaces " << mat << nl
<< " - but could not find it"
<< exit(FatalError);
}
}
selected_ = wordList(available_, foundIds);
return selected_.size();
}
Foam::label Foam::triSurfaceLoader::select(const wordReList& matcher)
{
// Need to be more careful when select.
// - preserve same order as the input matcher itself
// - avoid duplicate selections
// - flag explicitly named files as missing.
// (Eg, foo.stl must exist, but "foo.*\.stl" is optional)
// Track which files have already been selected
DynamicList<label> foundIds(available_.size());
labelHashSet hashedFound(2*available_.size());
DynamicList<word> missing(matcher.size());
wordHashSet hashedMissing(2*matcher.size());
// Exact matches must exist
forAll(matcher, i)
{
const wordRe& mat = matcher[i];
if (mat.isPattern())
{
labelList indices = findMatchingStrings(mat, available_);
sort(indices);
forAll(indices, j)
{
const label idx = indices[j];
if (hashedFound.insert(idx))
{
foundIds.append(idx);
}
}
}
else
{
const word& plain = static_cast<const word&>(mat);
if (available_.found(plain))
{
const label idx = available_[plain];
if (hashedFound.insert(idx))
{
foundIds.append(idx);
}
}
else if (hashedMissing.insert(plain))
{
missing.append(plain);
}
}
}
if (missing.size())
{
FatalErrorInFunction
<< "Specified the surfaces " << flatOutput(matcher) << nl
<< " - but could not find " << flatOutput(missing)
<< exit(FatalError);
}
selected_ = wordList(available_, foundIds);
return selected_.size();
}
Foam::autoPtr<Foam::triSurface> Foam::triSurfaceLoader::load() const
{
if (selected_.empty())
{
return autoPtr<triSurface>();
}
else if (selected_.size() == 1)
{
return autoPtr<triSurface>(new triSurface(directory_/selected_[0]));
}
List<labelledTri> faces;
pointField points;
label regoff = 0; // region offset
// collect all patches, preserving names.
// This will be horrible for output, but is good if we are relying on
// the names for defining baffles.
DynamicList<geometricSurfacePatch> patches(16*selected_.size());
forAll(selected_, surfi)
{
triSurface addsurf(directory_/selected_[surfi]);
List<labelledTri> addfaces(addsurf.xferFaces());
List<point> addpoints(addsurf.xferPoints());
patches.append(addsurf.patches());
if (surfi)
{
const label ptoff = points.size(); // point offset
forAll(addfaces, facei)
{
labelledTri& f = addfaces[facei];
forAll(f, fi)
{
f[fi] += ptoff;
}
f.region() += regoff;
}
faces.append(addfaces);
points.append(addpoints);
}
else
{
faces.transfer(addfaces);
points.transfer(addpoints);
}
regoff += addsurf.patches().size();
}
return autoPtr<triSurface>(new triSurface(faces, patches, points, true));
}
// ************************************************************************* //

View File

@ -0,0 +1,152 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
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::triSurfaceLoader
Description
Convenience class for loading single or multiple surface files
from the constant/triSurface (or other) directory.
Surfaces selection based on word, wordRe, wordReList.
If multiple surfaces are selected, they are concatenated into a
single surface with offset faces,points,regions.
SourceFiles
triSurfaceLoader.C
\*---------------------------------------------------------------------------*/
#ifndef triSurfaceLoader_H
#define triSurfaceLoader_H
#include "triSurface.H"
#include "wordReList.H"
#include "hashedWordList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class triSurfaceLoader;
class Time;
/*---------------------------------------------------------------------------*\
Class triSurfaceLoader Declaration
\*---------------------------------------------------------------------------*/
class triSurfaceLoader
{
// Private data
//- The directory to load from (eg, case/constant/triSurface)
fileName directory_;
//- All available files
hashedWordList available_;
//- Selected files
hashedWordList selected_;
// Private Member Functions
//- Disallow default bitwise copy construct
triSurfaceLoader(const triSurfaceLoader&) = delete;
//- Disallow default bitwise assignment
void operator=(const triSurfaceLoader&) = delete;
public:
// Constructors
//- Construct with directory name
triSurfaceLoader(const fileName& directory);
//- Construct with time. Selects "constant/triSurface" directory.
triSurfaceLoader(const Time& runTime);
//- Destructor
~triSurfaceLoader();
// Member Functions
// Access
//- The directory being used
inline const fileName& directory() const
{
return directory_;
}
//- The list of available files
inline const hashedWordList& available() const
{
return available_;
}
//- The list of selected files
inline const hashedWordList& selected() const
{
return selected_;
}
// Edit
//- Read directory and populate the 'available' files.
// Automatically called on construction.
label readDir();
//- Populates 'selected' with all available files.
label selectAll();
//- Populates 'selected' with a subset of the available files.
label select(const word& name);
//- Populates 'selected' with a subset of the available files.
label select(const wordRe& mat);
//- Populates 'selected' with a subset of the available files.
label select(const wordReList& matcher);
//- Load a single file, or load and combine multiple selected files
autoPtr<triSurface> load() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -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) 2015 OpenCFD Ltd.
\\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
@ -175,7 +175,12 @@ Foam::triSurfaceSearch::triSurfaceSearch
tolerance_(tolerance),
maxTreeDepth_(maxTreeDepth),
treePtr_(nullptr)
{}
{
if (tolerance_ < 0)
{
tolerance_ = indexedOctree<treeDataTriSurface>::perturbTol();
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
@ -227,7 +232,7 @@ Foam::triSurfaceSearch::tree() const
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
}
scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
const scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
indexedOctree<treeDataTriSurface>::perturbTol() = tolerance_;
treePtr_.reset
@ -285,7 +290,7 @@ void Foam::triSurfaceSearch::findNearest
List<pointIndexHit>& info
) const
{
scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
const scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
indexedOctree<treeDataTriSurface>::perturbTol() = tolerance();
const indexedOctree<treeDataTriSurface>& octree = tree();
@ -332,7 +337,7 @@ void Foam::triSurfaceSearch::findLine
info.setSize(start.size());
scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
const scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
indexedOctree<treeDataTriSurface>::perturbTol() = tolerance();
forAll(start, i)
@ -355,7 +360,7 @@ void Foam::triSurfaceSearch::findLineAny
info.setSize(start.size());
scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
const scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
indexedOctree<treeDataTriSurface>::perturbTol() = tolerance();
forAll(start, i)
@ -378,7 +383,7 @@ void Foam::triSurfaceSearch::findLineAll
info.setSize(start.size());
scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
const scalar oldTol = indexedOctree<treeDataTriSurface>::perturbTol();
indexedOctree<treeDataTriSurface>::perturbTol() = tolerance();
// Work array

View File

@ -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.
@ -85,10 +85,10 @@ class triSurfaceSearch
) const;
//- Disallow default bitwise copy construct
triSurfaceSearch(const triSurfaceSearch&);
triSurfaceSearch(const triSurfaceSearch&) = delete;
//- Disallow default bitwise assignment
void operator=(const triSurfaceSearch&);
void operator=(const triSurfaceSearch&) = delete;
public:
@ -96,17 +96,18 @@ public:
// Constructors
//- Construct from surface. Holds reference to surface!
explicit triSurfaceSearch(const triSurface&);
explicit triSurfaceSearch(const triSurface& surface);
//- Construct from surface and dictionary.
triSurfaceSearch(const triSurface&, const dictionary& dict);
triSurfaceSearch(const triSurface& surface, const dictionary& dict);
//- Construct from components
//- Construct from components.
// A invalid (negative) tolerance uses the default tolerance.
triSurfaceSearch
(
const triSurface& surface,
const scalar tolerance,
const label maxTreeDepth
const label maxTreeDepth = 10
);
@ -155,7 +156,7 @@ public:
// - hit() : whether nearest point found within bounding box
// - hitPoint() : coordinate of nearest point
// - index() : surface triangle label
pointIndexHit nearest(const point&, const vector& span) const;
pointIndexHit nearest(const point& pt, const vector& span) const;
void findLine
(