Integrated Foundation code to commit 104aac5

This commit is contained in:
Andrew Heather
2017-05-17 16:35:18 +01:00
590 changed files with 5963 additions and 3699 deletions

View File

@ -1,3 +1,44 @@
em = edgeMesh
$(em)/edgeMesh.C
$(em)/edgeMeshIO.C
$(em)/edgeMeshNew.C
edgeMeshFormats = $(em)/edgeMeshFormats
$(edgeMeshFormats)/edgeMeshFormatsCore.C
$(edgeMeshFormats)/edgeMesh/edgeMeshFormat.C
$(edgeMeshFormats)/edgeMesh/edgeMeshFormatRunTime.C
$(edgeMeshFormats)/extendedFeatureEdgeMesh/extendedFeatureEdgeMeshFormat.C
$(edgeMeshFormats)/extendedFeatureEdgeMesh/extendedFeatureEdgeMeshFormatRunTime.C
$(edgeMeshFormats)/nas/NASedgeFormat.C
$(edgeMeshFormats)/nas/NASedgeFormatRunTime.C
$(edgeMeshFormats)/obj/OBJedgeFormat.C
$(edgeMeshFormats)/obj/OBJedgeFormatRunTime.C
$(edgeMeshFormats)/starcd/STARCDedgeFormat.C
$(edgeMeshFormats)/starcd/STARCDedgeFormatRunTime.C
$(edgeMeshFormats)/vtk/VTKedgeFormat.C
$(edgeMeshFormats)/vtk/VTKedgeFormatRunTime.C
$(em)/featureEdgeMesh/featureEdgeMesh.C
eem = $(em)/extendedEdgeMesh
$(eem)/extendedEdgeMesh.C
$(eem)/extendedEdgeMeshNew.C
$(eem)/extendedEdgeMeshFormats/extendedEdgeMeshFormat/extendedEdgeMeshFormat.C
$(eem)/extendedEdgeMeshFormats/extendedEdgeMeshFormat/extendedEdgeMeshFormatRunTime.C
efm = $(eem)/extendedFeatureEdgeMesh
$(efm)/extendedFeatureEdgeMesh.C
cellClassification/cellClassification.C
cellClassification/cellInfo.C
@ -63,23 +104,24 @@ indexedOctree/treeDataPoint.C
indexedOctree/treeDataPrimitivePatchName.C
indexedOctree/treeDataTriSurface.C
searchableSurface = searchableSurface
$(searchableSurface)/searchableBox.C
$(searchableSurface)/searchableRotatedBox.C
$(searchableSurface)/searchableCylinder.C
$(searchableSurface)/searchableCone.C
$(searchableSurface)/searchableDisk.C
$(searchableSurface)/searchablePlane.C
$(searchableSurface)/searchablePlate.C
$(searchableSurface)/searchableSphere.C
$(searchableSurface)/searchableSurface.C
$(searchableSurface)/searchableSurfaceCollection.C
$(searchableSurface)/searchableSurfaces.C
$(searchableSurface)/searchableSurfacesQueries.C
$(searchableSurface)/searchableSurfaceWithGaps.C
$(searchableSurface)/triSurfaceMesh.C
$(searchableSurface)/closedTriSurfaceMesh.C
$(searchableSurface)/subTriSurfaceMesh.C
searchableSurfaces/closedTriSurfaceMesh/closedTriSurfaceMesh.C
searchableSurfaces/searchableBox/searchableBox.C
searchableSurfaces/searchableCone/searchableCone.C
searchableSurfaces/searchableCylinder/searchableCylinder.C
searchableSurfaces/searchableDisk/searchableDisk.C
searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C
searchableSurfaces/searchablePlane/searchablePlane.C
searchableSurfaces/searchablePlate/searchablePlate.C
searchableSurfaces/searchableRotatedBox/searchableRotatedBox.C
searchableSurfaces/searchableSphere/searchableSphere.C
searchableSurfaces/searchableSurface/searchableSurface.C
searchableSurfaces/searchableSurfaceCollection/searchableSurfaceCollection.C
searchableSurfaces/searchableSurfaces/searchableSurfaces.C
searchableSurfaces/searchableSurfacesQueries/searchableSurfacesQueries.C
searchableSurfaces/searchableSurfaceWithGaps/searchableSurfaceWithGaps.C
searchableSurfaces/subTriSurfaceMesh/subTriSurfaceMesh.C
searchableSurfaces/triSurfaceMesh/triSurfaceMesh.C
topoSets = sets/topoSets
$(topoSets)/cellSet.C

View File

@ -0,0 +1,47 @@
em = .
$(em)/edgeMesh.C
$(em)/edgeMeshIO.C
$(em)/edgeMeshNew.C
edgeMeshFormats = $(em)/edgeMeshFormats
$(edgeMeshFormats)/edgeMeshFormatsCore.C
$(edgeMeshFormats)/edgeMesh/edgeMeshFormat.C
$(edgeMeshFormats)/edgeMesh/edgeMeshFormatRunTime.C
$(edgeMeshFormats)/extendedFeatureEdgeMesh/extendedFeatureEdgeMeshFormat.C
$(edgeMeshFormats)/extendedFeatureEdgeMesh/extendedFeatureEdgeMeshFormatRunTime.C
$(edgeMeshFormats)/nas/NASedgeFormat.C
$(edgeMeshFormats)/nas/NASedgeFormatRunTime.C
$(edgeMeshFormats)/obj/OBJedgeFormat.C
$(edgeMeshFormats)/obj/OBJedgeFormatRunTime.C
$(edgeMeshFormats)/starcd/STARCDedgeFormat.C
$(edgeMeshFormats)/starcd/STARCDedgeFormatRunTime.C
$(edgeMeshFormats)/vtk/VTKedgeFormat.C
$(edgeMeshFormats)/vtk/VTKedgeFormatRunTime.C
$(em)/featureEdgeMesh/featureEdgeMesh.C
eem = $(em)/extendedEdgeMesh
$(eem)/extendedEdgeMesh.C
$(eem)/extendedEdgeMeshNew.C
$(eem)/extendedEdgeMeshFormats/extendedEdgeMeshFormat/extendedEdgeMeshFormat.C
$(eem)/extendedEdgeMeshFormats/extendedEdgeMeshFormat/extendedEdgeMeshFormatRunTime.C
efm = $(eem)/extendedFeatureEdgeMesh
$(efm)/extendedFeatureEdgeMesh.C
searchableSurfaces/searchableExtrudedCircle/searchableExtrudedCircle.C
LIB = $(FOAM_LIBBIN)/libedgeMesh

View File

@ -0,0 +1,10 @@
EXE_INC = \
-I$(LIB_SRC)/fileFormats/lnInclude \
-I$(LIB_SRC)/surfMesh/lnInclude \
-I$(LIB_SRC)/triSurface/lnInclude \
-I$(LIB_SRC)/meshTools/lnInclude
LIB_LIBS = \
-ltriSurface \
-lmeshTools \
-lsurfMesh

View File

@ -0,0 +1,399 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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.
-------------------------------------------------------------------------------
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 "edgeMesh.H"
#include "mergePoints.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
#include "ListOps.H"
#include "EdgeMap.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(edgeMesh, 0);
defineRunTimeSelectionTable(edgeMesh, fileExtension);
defineMemberFunctionSelectionTable(edgeMesh,write,fileExtension);
}
Foam::wordHashSet Foam::edgeMesh::readTypes()
{
return wordHashSet(*fileExtensionConstructorTablePtr_);
}
Foam::wordHashSet Foam::edgeMesh::writeTypes()
{
return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
bool Foam::edgeMesh::canReadType
(
const word& ext,
const bool verbose
)
{
return checkSupport
(
readTypes(),
ext,
verbose,
"reading"
);
}
bool Foam::edgeMesh::canWriteType
(
const word& ext,
const bool verbose
)
{
return checkSupport
(
writeTypes(),
ext,
verbose,
"writing"
);
}
bool Foam::edgeMesh::canRead
(
const fileName& name,
const bool verbose
)
{
word ext = name.ext();
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return canReadType(ext, verbose);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::edgeMesh::calcPointEdges() const
{
if (pointEdgesPtr_.valid())
{
FatalErrorInFunction
<< "pointEdges already calculated." << abort(FatalError);
}
pointEdgesPtr_.reset(new labelListList(points_.size()));
labelListList& pointEdges = pointEdgesPtr_();
invertManyToMany(pointEdges.size(), edges_, pointEdges);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::edgeMesh::edgeMesh()
:
fileFormats::edgeMeshFormatsCore(),
points_(0),
edges_(0),
pointEdgesPtr_(nullptr)
{}
Foam::edgeMesh::edgeMesh
(
const pointField& points,
const edgeList& edges
)
:
fileFormats::edgeMeshFormatsCore(),
points_(points),
edges_(edges),
pointEdgesPtr_(nullptr)
{}
Foam::edgeMesh::edgeMesh
(
const Xfer<pointField>& pointLst,
const Xfer<edgeList>& edgeLst
)
:
fileFormats::edgeMeshFormatsCore(),
points_(0),
edges_(0),
pointEdgesPtr_(nullptr)
{
points_.transfer(pointLst());
edges_.transfer(edgeLst());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::edgeMesh::~edgeMesh()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::edgeMesh::clear()
{
points_.clear();
edges_.clear();
pointEdgesPtr_.clear();
}
void Foam::edgeMesh::reset
(
const Xfer<pointField>& pointLst,
const Xfer<edgeList>& edgeLst
)
{
// Take over new primitive data.
// Optimized to avoid overwriting data at all
if (notNull(pointLst))
{
points_.transfer(pointLst());
}
if (notNull(edgeLst))
{
edges_.transfer(edgeLst());
// connectivity likely changed
pointEdgesPtr_.clear();
}
}
void Foam::edgeMesh::transfer(edgeMesh& mesh)
{
points_.transfer(mesh.points_);
edges_.transfer(mesh.edges_);
pointEdgesPtr_ = mesh.pointEdgesPtr_;
}
Foam::Xfer<Foam::edgeMesh> Foam::edgeMesh::xfer()
{
return xferMove(*this);
}
Foam::label Foam::edgeMesh::regions(labelList& edgeRegion) const
{
edgeRegion.setSize(edges_.size());
edgeRegion = -1;
label startEdgeI = 0;
label currentRegion = 0;
while (true)
{
while (startEdgeI < edges_.size() && edgeRegion[startEdgeI] != -1)
{
startEdgeI++;
}
if (startEdgeI == edges_.size())
{
break;
}
// Found edge that has not yet been assigned a region.
// Mark connected region with currentRegion starting at startEdgeI.
edgeRegion[startEdgeI] = currentRegion;
labelList edgesToVisit(1, startEdgeI);
while (edgesToVisit.size())
{
// neighbours of current edgesToVisit
DynamicList<label> newEdgesToVisit(edgesToVisit.size());
// Mark all point connected edges with current region.
forAll(edgesToVisit, i)
{
label edgeI = edgesToVisit[i];
// Mark connected edges
const edge& e = edges_[edgeI];
forAll(e, fp)
{
const labelList& pEdges = pointEdges()[e[fp]];
forAll(pEdges, pEdgeI)
{
label nbrEdgeI = pEdges[pEdgeI];
if (edgeRegion[nbrEdgeI] == -1)
{
edgeRegion[nbrEdgeI] = currentRegion;
newEdgesToVisit.append(nbrEdgeI);
}
}
}
}
edgesToVisit.transfer(newEdgesToVisit);
}
currentRegion++;
}
return currentRegion;
}
void Foam::edgeMesh::scalePoints(const scalar scaleFactor)
{
// avoid bad scaling
if (scaleFactor > 0 && scaleFactor != 1.0)
{
points_ *= scaleFactor;
}
}
void Foam::edgeMesh::mergePoints
(
const scalar mergeDist,
labelList& reversePointMap
)
{
pointField newPoints;
labelList pointMap;
bool hasMerged = Foam::mergePoints
(
points_,
mergeDist,
false,
pointMap,
newPoints,
vector::zero
);
if (hasMerged)
{
pointEdgesPtr_.clear();
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();
}
}
}
void Foam::edgeMesh::mergeEdges()
{
EdgeMap<label> existingEdges(2*edges_.size());
label curEdgeI = 0;
forAll(edges_, edgeI)
{
const edge& e = edges_[edgeI];
if (existingEdges.insert(e, curEdgeI))
{
curEdgeI++;
}
}
if (debug)
{
Info<< "Merging duplicate edges: "
<< edges_.size() - existingEdges.size()
<< " edges will be deleted." << endl;
}
edges_.setSize(existingEdges.size());
forAllConstIter(EdgeMap<label>, existingEdges, iter)
{
edges_[iter()] = iter.key();
}
// connectivity changed
pointEdgesPtr_.clear();
}
// ************************************************************************* //

View File

@ -0,0 +1,294 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
Class
Foam::edgeMesh
Description
Points connected by edges.
Can be read from fileName based on extension. Uses ::New factory method
to select the reader and transfer the result.
SourceFiles
edgeMeshI.H
edgeMesh.C
edgeMeshIO.C
edgeMeshNew.C
\*---------------------------------------------------------------------------*/
#ifndef edgeMesh_H
#define edgeMesh_H
#include "pointField.H"
#include "edgeList.H"
#include "edgeMeshFormatsCore.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class Istream;
class Ostream;
// Forward declaration of friend functions and operators
class edgeMesh;
Istream& operator>>(Istream&, edgeMesh&);
Ostream& operator<<(Ostream&, const edgeMesh&);
/*---------------------------------------------------------------------------*\
Class edgeMesh Declaration
\*---------------------------------------------------------------------------*/
class edgeMesh
:
public fileFormats::edgeMeshFormatsCore
{
// Private data
//- Vertices of the edges
pointField points_;
//- The edges defining the boundary
edgeList edges_;
//- From point to edges
mutable autoPtr<labelListList> pointEdgesPtr_;
// Private Member Functions
//- Calculate point-edge addressing (inverse of edges)
void calcPointEdges() const;
protected:
// Protected Member Functions
//- Non-const access to global points
inline pointField& storedPoints();
//- Non-const access to the edges
inline edgeList& storedEdges();
public:
//- Runtime type information
TypeName("edgeMesh");
// Static
//- Can we read this file format?
static bool canRead(const fileName&, const bool verbose=false);
//- Can we read this file format?
static bool canReadType(const word& ext, const bool verbose=false);
//- Can we write this file format type?
static bool canWriteType(const word& ext, const bool verbose=false);
static wordHashSet readTypes();
static wordHashSet writeTypes();
// Constructors
//- Construct null
edgeMesh();
//- Construct from components
edgeMesh(const pointField&, const edgeList&);
//- Construct by transferring components (points, edges).
edgeMesh
(
const Xfer<pointField>&,
const Xfer<edgeList>&
);
//- Construct as copy
edgeMesh(const edgeMesh&);
//- Construct from file name (uses extension to determine type)
edgeMesh(const fileName&);
//- Construct from file name (uses extension to determine type)
edgeMesh(const fileName&, const word& ext);
//- Construct from Istream
edgeMesh(Istream&);
// Declare run-time constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
edgeMesh,
fileExtension,
(
const fileName& name
),
(name)
);
// Selectors
//- Select constructed from filename (explicit extension)
static autoPtr<edgeMesh> New
(
const fileName&,
const word& ext
);
//- Select constructed from filename (implicit extension)
static autoPtr<edgeMesh> New(const fileName&);
//- Destructor
virtual ~edgeMesh();
// Member Function Selectors
declareMemberFunctionSelectionTable
(
void,
edgeMesh,
write,
fileExtension,
(
const fileName& name,
const edgeMesh& mesh
),
(name, mesh)
);
//- Write to file
static void write(const fileName&, const edgeMesh&);
// Member Functions
//- Transfer the contents of the argument and annul the argument
void transfer(edgeMesh&);
//- Transfer contents to the Xfer container
Xfer<edgeMesh > xfer();
// Read
//- Read from file. Chooses reader based on explicit extension
bool read(const fileName&, const word& ext);
//- Read from file. Chooses reader based on detected extension
virtual bool read(const fileName&);
// Access
//- Return points
inline const pointField& points() const;
//- Return edges
inline const edgeList& edges() const;
//- Return edges
inline const labelListList& pointEdges() const;
//- Find connected regions. Set region number per edge.
// Returns number of regions.
label regions(labelList& edgeRegion) const;
// Edit
//- Clear all storage
virtual void clear();
//- Reset primitive data (points, edges)
// Note, optimized to avoid overwriting data (with Xfer::null)
virtual void reset
(
const Xfer<pointField>& points,
const Xfer<edgeList>& edges
);
//- Scale points. A non-positive factor is ignored
virtual void scalePoints(const scalar);
//- Merge common points (points within mergeDist). Return map from
// old to new points.
virtual void mergePoints(const scalar mergeDist, labelList&);
//- Merge duplicate edges
virtual void mergeEdges();
// Write
virtual void writeStats(Ostream&) const;
//- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& name) const
{
write(name, *this);
}
// Member Operators
inline void operator=(const edgeMesh&);
// Ostream Operator
friend Ostream& operator<<(Ostream&, const edgeMesh&);
friend Istream& operator>>(Istream&, edgeMesh&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "edgeMeshI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,216 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "edgeMeshFormat.H"
#include "IOobject.H"
#include "IFstream.H"
#include "clock.H"
#include "Time.H"
#include "featureEdgeMesh.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::edgeMeshFormat::edgeMeshFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::edgeMeshFormat::read
(
const fileName& filename
)
{
clear();
fileName dir = filename.path();
fileName caseName = dir.name();
fileName rootPath = dir.path();
// Construct dummy time to use as an objectRegistry
Time dummyTime
(
".", //rootPath,
".", //caseName,
"system", //systemName,
"constant", //constantName,
false //enableFunctionObjects
);
// Construct IOobject to re-use the headerOk & readHeader
// (so we can read ascii and binary)
IOobject io
(
filename,
dummyTime,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
);
if (!io.typeHeaderOk<featureEdgeMesh>(false))
{
FatalErrorInFunction
<< "Cannot read file " << filename
<< exit(FatalError);
}
const fileName fName(typeFilePath<featureEdgeMesh>(io));
autoPtr<IFstream> isPtr(new IFstream(fName));
bool ok = false;
if (isPtr().good())
{
Istream& is = isPtr();
ok = io.readHeader(is);
if (ok)
{
ok = read(is, this->storedPoints(), this->storedEdges());
}
}
return ok;
}
bool Foam::fileFormats::edgeMeshFormat::read
(
Istream& is,
pointField& pointLst,
edgeList& edgeLst
)
{
if (!is.good())
{
FatalErrorInFunction
<< "read error "
<< exit(FatalError);
}
// read points:
is >> pointLst;
// read edges:
is >> edgeLst;
return true;
}
Foam::Ostream& Foam::fileFormats::edgeMeshFormat::write
(
Ostream& os,
const pointField& pointLst,
const edgeList& edgeLst
)
{
if (!os.good())
{
FatalErrorInFunction
<< "bad output stream " << os.name()
<< exit(FatalError);
}
os << "\n// points:" << nl << pointLst << nl
<< "\n// edges:" << nl << edgeLst << nl;
IOobject::writeDivider(os);
// Check state of Ostream
os.check
(
"edgeMeshFormat::write"
"(Ostream&, const pointField&, const edgeList&)"
);
return os;
}
void Foam::fileFormats::edgeMeshFormat::write
(
const fileName& filename,
const edgeMesh& mesh
)
{
// Construct dummy time to use as an objectRegistry
Time dummyTime
(
".", //rootPath,
".", //caseName,
"system", //systemName,
"constant", //constantName,
false //enableFunctionObjects
);
// Construct IOobject to re-use the writeHeader
IOobject io
(
filename,
dummyTime,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
);
io.note() = "written " + clock::dateTime();
// Note: always write ascii
autoPtr<OFstream> osPtr(new OFstream(filename));
if (!osPtr().good())
{
FatalIOErrorInFunction
(
osPtr()
) << "Cannot open file for writing " << filename
<< exit(FatalIOError);
}
OFstream& os = osPtr();
bool ok = io.writeHeader(os, featureEdgeMesh::typeName);
if (!ok)
{
FatalIOErrorInFunction
(
os
) << "Cannot write header"
<< exit(FatalIOError);
}
write(os, mesh.points(), mesh.edges());
// Check state of Ostream
os.check("edgeMeshFormat::write(Ostream&)");
}
// ************************************************************************* //

View File

@ -0,0 +1,148 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
Class
Foam::fileFormats::edgeMeshFormat
Description
Provide a means of reading/writing the single-file OpenFOAM edge format.
Note
This class provides more methods than the regular edge format interface.
SourceFiles
edgeMeshFormat.C
\*---------------------------------------------------------------------------*/
#ifndef edgeMeshFormat_H
#define edgeMeshFormat_H
#include "edgeMesh.H"
#include "Ostream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class edgeMeshFormat Declaration
\*---------------------------------------------------------------------------*/
class edgeMeshFormat
:
public edgeMesh
{
// Private Member Functions
//- Disallow default bitwise copy construct
edgeMeshFormat(const edgeMeshFormat&);
//- Disallow default bitwise assignment
void operator=(const edgeMeshFormat&);
protected:
// Protected Member Functions
//- Write header information
static void writeHeader
(
Ostream&,
const pointField&,
const edgeList&
);
public:
// Constructors
//- Construct from file name
edgeMeshFormat(const fileName&);
// Selectors
//- Read file and return edgeMesh
static autoPtr<edgeMesh> New(const fileName& name)
{
return autoPtr<edgeMesh>
(
new edgeMeshFormat(name)
);
}
//- Destructor
virtual ~edgeMeshFormat()
{}
// Member Functions
//- Read edgeMesh components from stream
static bool read
(
Istream&,
pointField&,
edgeList&
);
//- Write edgeMesh components to stream
static Ostream& write
(
Ostream&,
const pointField&,
const edgeList&
);
//- Write edgeMesh with a mimicked IOobject header
static void write(const fileName&, const edgeMesh&);
//- Read from file
virtual bool read(const fileName&);
//- Write object
virtual void write(const fileName& name) const
{
write(name, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "edgeMeshFormat.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// read edgeMesh
addNamedToRunTimeSelectionTable
(
edgeMesh,
edgeMeshFormat,
fileExtension,
eMesh
);
// write edgeMesh
addNamedToMemberFunctionSelectionTable
(
edgeMesh,
edgeMeshFormat,
write,
fileExtension,
eMesh
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,199 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "edgeMeshFormatsCore.H"
#include "Time.H"
#include "IFstream.H"
#include "OFstream.H"
#include "edgeMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Foam::word Foam::fileFormats::edgeMeshFormatsCore::nativeExt("eMesh");
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::string Foam::fileFormats::edgeMeshFormatsCore::getLineNoComment
(
IFstream& is
)
{
string line;
do
{
is.getLine(line);
}
while ((line.empty() || line[0] == '#') && is.good());
return line;
}
#if 0
Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::localMeshFileName
(
const word& meshName
)
{
const word name(meshName.size() ? meshName : surfaceRegistry::defaultName);
return fileName
(
surfaceRegistry::prefix/name/surfMesh::meshSubDir
/ name + "." + nativeExt
);
}
Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::findMeshInstance
(
const Time& t,
const word& meshName
)
{
fileName localName = localMeshFileName(meshName);
// Search back through the time directories list to find the time
// closest to and lower than current time
instantList ts = t.times();
label instanceI;
for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
{
if (ts[instanceI].value() <= t.timeOutputValue())
{
break;
}
}
// Noting that the current directory has already been searched
// for mesh data, start searching from the previously stored time directory
if (instanceI >= 0)
{
for (label i = instanceI; i >= 0; --i)
{
if (isFile(t.path()/ts[i].name()/localName))
{
return ts[i].name();
}
}
}
return t.constant();
}
Foam::fileName Foam::fileFormats::edgeMeshFormatsCore::findMeshFile
(
const Time& t,
const word& meshName
)
{
fileName localName = localMeshFileName(meshName);
// Search back through the time directories list to find the time
// closest to and lower than current time
instantList ts = t.times();
label instanceI;
for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
{
if (ts[instanceI].value() <= t.timeOutputValue())
{
break;
}
}
// Noting that the current directory has already been searched
// for mesh data, start searching from the previously stored time directory
if (instanceI >= 0)
{
for (label i = instanceI; i >= 0; --i)
{
fileName testName(t.path()/ts[i].name()/localName);
if (isFile(testName))
{
return testName;
}
}
}
// fallback to "constant"
return t.path()/t.constant()/localName;
}
#endif
bool Foam::fileFormats::edgeMeshFormatsCore::checkSupport
(
const wordHashSet& available,
const word& ext,
const bool verbose,
const word& functionName
)
{
if (available.found(ext))
{
return true;
}
else if (verbose)
{
wordList known = available.sortedToc();
Info<<"Unknown file extension for " << functionName
<< " : " << ext << nl
<<"Valid types: (";
// compact output:
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::edgeMeshFormatsCore::edgeMeshFormatsCore()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::fileFormats::edgeMeshFormatsCore::~edgeMeshFormatsCore()
{}
// ************************************************************************* //

View File

@ -0,0 +1,124 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
Class
Foam::fileFormats::edgeMeshFormatsCore
Description
A collection of helper functions for reading/writing edge formats.
SourceFiles
edgeMeshFormatsCore.C
\*---------------------------------------------------------------------------*/
#ifndef edgeMeshFormatsCore_H
#define edgeMeshFormatsCore_H
#include "Map.H"
#include "HashSet.H"
#include "labelList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class IFstream;
class Time;
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class edgeMeshFormatsCore Declaration
\*---------------------------------------------------------------------------*/
class edgeMeshFormatsCore
{
protected:
// Protected Member Functions
//- Read non-comment line
static string getLineNoComment(IFstream&);
public:
// Static Data
//- The file extension corresponding to 'native' edge format
// Normally "eMesh" (edge-mesh)
static word nativeExt;
// Static Member Functions
static bool checkSupport
(
const wordHashSet& available,
const word& ext,
const bool verbose,
const word& functionName
);
// //- Return the local file name (within time directory)
// // NEEDS FIXING
// static fileName localMeshFileName(const word& edgeName="");
// //- Find instance with edgeName
// // NEEDS FIXING
// static fileName findMeshInstance
// (
// const Time&,
// const word& edgeName=""
// );
// //- Find mesh file with edgeName
// // NEEDS FIXING
// static fileName findMeshFile(const Time&, const word& edgeName="");
// Constructors
//- Construct null
edgeMeshFormatsCore();
//- Destructor
virtual ~edgeMeshFormatsCore();
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,67 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "extendedFeatureEdgeMeshFormat.H"
#include "edgeMeshFormat.H"
#include "IFstream.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::extendedFeatureEdgeMeshFormat::extendedFeatureEdgeMeshFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::extendedFeatureEdgeMeshFormat::read
(
const fileName& filename
)
{
clear();
IFstream is(filename);
if (!is.good())
{
FatalErrorInFunction
<< "Cannot read file " << filename
<< exit(FatalError);
}
return fileFormats::edgeMeshFormat::read
(
is,
this->storedPoints(),
this->storedEdges()
);
}
// ************************************************************************* //

View File

@ -0,0 +1,106 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 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/>.
Class
Foam::fileFormats::extendedFeatureEdgeMeshFormat
Description
Provide a means of reading extendedFeatureEdgeMesh as featureEdgeMesh
SourceFiles
extendedFeatureEdgeMeshFormat.C
\*---------------------------------------------------------------------------*/
#ifndef extendedFeatureEdgeMeshFormat_H
#define extendedFeatureEdgeMeshFormat_H
#include "edgeMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class extendedFeatureEdgeMeshFormat Declaration
\*---------------------------------------------------------------------------*/
class extendedFeatureEdgeMeshFormat
:
public edgeMesh
{
// Private Member Functions
//- Disallow default bitwise copy construct
extendedFeatureEdgeMeshFormat(const extendedFeatureEdgeMeshFormat&);
//- Disallow default bitwise assignment
void operator=(const extendedFeatureEdgeMeshFormat&);
public:
// Constructors
//- Construct from file name
extendedFeatureEdgeMeshFormat(const fileName&);
// Selectors
//- Read file and return surface
static autoPtr<edgeMesh> New(const fileName& name)
{
return autoPtr<edgeMesh>
(
new extendedFeatureEdgeMeshFormat(name)
);
}
//- Destructor
virtual ~extendedFeatureEdgeMeshFormat()
{}
// Member Functions
//- Read from file
virtual bool read(const fileName&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,50 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "extendedFeatureEdgeMeshFormat.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// read extendedEdgeMesh
addNamedToRunTimeSelectionTable
(
edgeMesh,
extendedFeatureEdgeMeshFormat,
fileExtension,
featureEdgeMesh
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,236 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "NASedgeFormat.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "PackedBoolList.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::NASedgeFormat::NASedgeFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::NASedgeFormat::read
(
const fileName& filename
)
{
clear();
IFstream is(filename);
if (!is.good())
{
FatalErrorInFunction
<< "Cannot read file " << filename
<< exit(FatalError);
}
DynamicList<point> dynPoints;
DynamicList<edge> dynEdges;
DynamicList<label> pointId; // Nastran index of points
while (is.good())
{
string line;
is.getLine(line);
// Skip empty or comment
if (line.empty() || line[0] == '$')
{
continue;
}
// Check if character 72 is continuation
if (line.size() > 72 && line[72] == '+')
{
line = line.substr(0, 72);
while (true)
{
string buf;
is.getLine(buf);
if (buf.size() > 72 && buf[72] == '+')
{
line += buf.substr(8, 64);
}
else
{
line += buf.substr(8, buf.size()-8);
break;
}
}
}
// Read first word
IStringStream lineStream(line);
word cmd;
lineStream >> cmd;
if (cmd == "CBEAM" || cmd == "CROD")
{
edge e;
// label groupId = readLabel(IStringStream(line.substr(16,8))());
e[0] = readLabel(IStringStream(line.substr(24,8))());
e[1] = readLabel(IStringStream(line.substr(32,8))());
// discard groupID
dynEdges.append(e);
}
else if (cmd == "PLOTEL")
{
edge e;
// label groupId = readLabel(IStringStream(line.substr(16,8))());
e[0] = readLabel(IStringStream(line.substr(16,8))());
e[1] = readLabel(IStringStream(line.substr(24,8))());
// discard groupID
dynEdges.append(e);
}
else if (cmd == "GRID")
{
label index = readLabel(IStringStream(line.substr(8,8))());
scalar x = parseNASCoord(line.substr(24, 8));
scalar y = parseNASCoord(line.substr(32, 8));
scalar z = parseNASCoord(line.substr(40, 8));
pointId.append(index);
dynPoints.append(point(x, y, z));
}
else if (cmd == "GRID*")
{
// Long format is on two lines with '*' continuation symbol
// on start of second line.
// Typical line (spaces compacted)
// GRID* 126 0 -5.55999875E+02 -5.68730474E+02
// * 2.14897901E+02
label index = readLabel(IStringStream(line.substr(8,16))());
scalar x = parseNASCoord(line.substr(40, 16));
scalar y = parseNASCoord(line.substr(56, 16));
is.getLine(line);
if (line[0] != '*')
{
FatalErrorInFunction
<< "Expected continuation symbol '*' when reading GRID*"
<< " (double precision coordinate) format" << nl
<< "Read:" << line << nl
<< "File:" << is.name() << " line:" << is.lineNumber()
<< exit(FatalError);
}
scalar z = parseNASCoord(line.substr(8, 16));
pointId.append(index);
dynPoints.append(point(x, y, z));
}
}
// transfer to normal lists
storedPoints().transfer(dynPoints);
pointId.shrink();
dynEdges.shrink();
// Build inverse mapping (NASTRAN pointId -> index)
Map<label> mapPointId(2*pointId.size());
forAll(pointId, i)
{
mapPointId.insert(pointId[i], i);
}
// note which points were really used and which can be culled
PackedBoolList usedPoints(points().size());
// Pass1: relabel edges
// ~~~~~~~~~~~~~~~~~~~~
forAll(dynEdges, i)
{
edge& e = dynEdges[i];
e[0] = mapPointId[e[0]];
e[1] = mapPointId[e[1]];
usedPoints.set(e[0]);
usedPoints.set(e[1]);
}
pointId.clearStorage();
mapPointId.clear();
// not all the points were used, cull them accordingly
if (unsigned(points().size()) != usedPoints.count())
{
label nUsed = 0;
pointField& pts = storedPoints();
forAll(pts, pointi)
{
if (usedPoints.get(pointi))
{
if (nUsed != pointi)
{
pts[nUsed] = pts[pointi];
}
// map prev -> new id
mapPointId[pointi] = nUsed;
++nUsed;
}
}
pts.setSize(nUsed);
// renumber edge vertices
forAll(dynEdges, edgeI)
{
edge& e = dynEdges[edgeI];
e[0] = mapPointId[e[0]];
e[1] = mapPointId[e[1]];
}
}
// transfer to normal lists
storedEdges().transfer(dynEdges);
return true;
}
// ************************************************************************* //

View File

@ -0,0 +1,106 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
Class
Foam::fileFormats::NASedgeFormat
Description
Nastran edge reader.
SourceFiles
NASedgeFormat.C
\*---------------------------------------------------------------------------*/
#ifndef NASedgeFormat_H
#define NASedgeFormat_H
#include "edgeMesh.H"
#include "NASCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class NASedgeFormat Declaration
\*---------------------------------------------------------------------------*/
class NASedgeFormat
:
public edgeMesh,
public NASCore
{
// Private Member Functions
//- Disallow default bitwise copy construct
NASedgeFormat(const NASedgeFormat&);
//- Disallow default bitwise assignment
void operator=(const NASedgeFormat&);
public:
// Constructors
//- Construct from file name
NASedgeFormat(const fileName&);
// Selectors
//- Read file and return edge mesh
static autoPtr<edgeMesh> New(const fileName& name)
{
return autoPtr<edgeMesh>
(
new NASedgeFormat(name)
);
}
//- Destructor
virtual ~NASedgeFormat()
{}
// Member Functions
//- Read from a file
virtual bool read(const fileName&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,59 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "NASedgeFormat.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// read edgeMesh - .bdf (Bulk Data Format)
addNamedToRunTimeSelectionTable
(
edgeMesh,
NASedgeFormat,
fileExtension,
bdf
);
// read edgeMesh - .nas (Nastran Data Format)
addNamedToRunTimeSelectionTable
(
edgeMesh,
NASedgeFormat,
fileExtension,
nas
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,279 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "OBJedgeFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "Ostream.H"
#include "OFstream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::OBJedgeFormat::OBJedgeFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::OBJedgeFormat::readVertices
(
const string& line,
string::size_type& endNum,
DynamicList<label>& dynVertices
)
{
dynVertices.clear();
while (true)
{
string::size_type startNum =
line.find_first_not_of(' ', endNum);
if (startNum == string::npos)
{
break;
}
endNum = line.find(' ', startNum);
string vertexSpec;
if (endNum != string::npos)
{
vertexSpec = line.substr(startNum, endNum-startNum);
}
else
{
vertexSpec = line.substr(startNum, line.size() - startNum);
}
string::size_type slashPos = vertexSpec.find('/');
label vertI = 0;
if (slashPos != string::npos)
{
IStringStream intStream(vertexSpec.substr(0, slashPos));
intStream >> vertI;
}
else
{
IStringStream intStream(vertexSpec);
intStream >> vertI;
}
dynVertices.append(vertI - 1);
}
}
bool Foam::fileFormats::OBJedgeFormat::read(const fileName& filename)
{
clear();
IFstream is(filename);
if (!is.good())
{
FatalErrorInFunction
<< "Cannot read file " << filename
<< exit(FatalError);
}
DynamicList<point> dynPoints;
DynamicList<edge> dynEdges;
DynamicList<label> dynUsedPoints;
DynamicList<label> dynVertices;
while (is.good())
{
string line = this->getLineNoComment(is);
// handle continuations
if (line[line.size()-1] == '\\')
{
line.substr(0, line.size()-1);
line += this->getLineNoComment(is);
}
// Read first word
IStringStream lineStream(line);
word cmd;
lineStream >> cmd;
if (cmd == "v")
{
scalar x, y, z;
lineStream >> x >> y >> z;
dynPoints.append(point(x, y, z));
dynUsedPoints.append(-1);
}
else if (cmd == "l")
{
// Assume 'l' is followed by space.
string::size_type endNum = 1;
readVertices
(
line,
endNum,
dynVertices
);
for (label i = 1; i < dynVertices.size(); i++)
{
edge edgeRead(dynVertices[i-1], dynVertices[i]);
dynUsedPoints[edgeRead[0]] = edgeRead[0];
dynUsedPoints[edgeRead[1]] = edgeRead[1];
dynEdges.append(edgeRead);
}
}
else if (cmd == "f")
{
// Support for faces with 2 vertices
// Assume 'f' is followed by space.
string::size_type endNum = 1;
readVertices
(
line,
endNum,
dynVertices
);
if (dynVertices.size() == 2)
{
for (label i = 1; i < dynVertices.size(); i++)
{
edge edgeRead(dynVertices[i-1], dynVertices[i]);
dynUsedPoints[edgeRead[0]] = edgeRead[0];
dynUsedPoints[edgeRead[1]] = edgeRead[1];
dynEdges.append(edgeRead);
}
}
}
}
// cull unused points
label nUsed = 0;
forAll(dynPoints, pointi)
{
if (dynUsedPoints[pointi] >= 0)
{
if (nUsed != pointi)
{
dynPoints[nUsed] = dynPoints[pointi];
dynUsedPoints[pointi] = nUsed; // new position
}
++nUsed;
}
}
dynPoints.setSize(nUsed);
// transfer to normal lists
storedPoints().transfer(dynPoints);
// renumber edge vertices
if (nUsed != dynUsedPoints.size())
{
forAll(dynEdges, edgeI)
{
edge& e = dynEdges[edgeI];
e[0] = dynUsedPoints[e[0]];
e[1] = dynUsedPoints[e[1]];
}
}
storedEdges().transfer(dynEdges);
return true;
}
void Foam::fileFormats::OBJedgeFormat::write
(
const fileName& filename,
const edgeMesh& mesh
)
{
const pointField& pointLst = mesh.points();
const edgeList& edgeLst = mesh.edges();
OFstream os(filename);
if (!os.good())
{
FatalErrorInFunction
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
<< "o " << os.name().nameLessExt() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# lines : " << edgeLst.size() << nl;
os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << nl;
// Write vertex coords
forAll(pointLst, ptI)
{
const point& p = pointLst[ptI];
os << "v " << p.x() << ' ' << p.y() << ' ' << p.z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <edges count=\"" << edgeLst.size() << "\">" << endl;
// Write line connectivity
forAll(edgeLst, edgeI)
{
const edge& e = edgeLst[edgeI];
os << "l " << (e[0] + 1) << " " << (e[1] + 1) << nl;
}
os << "# </edges>" << endl;
}
// ************************************************************************* //

View File

@ -0,0 +1,126 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
Class
Foam::fileFormats::OBJedgeFormat
Description
Provide a means of reading/writing Alias/Wavefront OBJ format.
Does not handle negative vertex indices.
SourceFiles
OBJedgeFormat.C
\*---------------------------------------------------------------------------*/
#ifndef OBJedgeFormat_H
#define OBJedgeFormat_H
#include "edgeMesh.H"
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class OBJedgeFormat Declaration
\*---------------------------------------------------------------------------*/
class OBJedgeFormat
:
public edgeMesh
{
// Private Member Functions
void readVertices
(
const string& line,
string::size_type& endNum,
DynamicList<label>& dynVertices
);
//- Disallow default bitwise copy construct
OBJedgeFormat(const OBJedgeFormat&);
//- Disallow default bitwise assignment
void operator=(const OBJedgeFormat&);
public:
// Constructors
//- Construct from file name
OBJedgeFormat(const fileName&);
// Selectors
//- Read file and return surface
static autoPtr<edgeMesh> New(const fileName& name)
{
return autoPtr<edgeMesh>
(
new OBJedgeFormat(name)
);
}
//- Destructor
virtual ~OBJedgeFormat()
{}
// Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const edgeMesh&);
//- Read from file
virtual bool read(const fileName&);
//- Write object file
virtual void write(const fileName& name) const
{
write(name, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "OBJedgeFormat.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// read edgeMesh
addNamedToRunTimeSelectionTable
(
edgeMesh,
OBJedgeFormat,
fileExtension,
obj
);
// write edgeMesh
addNamedToMemberFunctionSelectionTable
(
edgeMesh,
OBJedgeFormat,
write,
fileExtension,
obj
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,263 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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 "STARCDedgeFormat.H"
#include "ListOps.H"
#include "clock.H"
#include "PackedBoolList.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
inline void Foam::fileFormats::STARCDedgeFormat::writeLines
(
Ostream& os,
const edgeList& edges
)
{
writeHeader(os, STARCDCore::HEADER_CEL);
forAll(edges, edgeI)
{
const edge& e = edges[edgeI];
const label cellId = edgeI + 1;
os << cellId // includes 1 offset
<< ' ' << starcdLine // 2(line) shape
<< ' ' << e.size()
<< ' ' << 401 // arbitrary value
<< ' ' << starcdLineType; // 5(line)
os << nl << " " << cellId << " "
<< (e[0]+1) << " " << (e[1]+1) << nl;
}
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fileFormats::STARCDedgeFormat::writeCase
(
Ostream& os,
const pointField& pointLst,
const label nEdges
)
{
const word caseName = os.name().nameLessExt();
os << "! STAR-CD file written " << clock::dateTime().c_str() << nl
<< "! " << pointLst.size() << " points, " << nEdges << " lines" << nl
<< "! case " << caseName << nl
<< "! ------------------------------" << nl;
// forAll(zoneLst, zoneI)
// {
// os << "ctable " << zoneI + 1 << " line" << nl
// << "ctname " << zoneI + 1 << " "
// << zoneLst[zoneI].name() << nl;
// }
os << "! ------------------------------" << nl
<< "*set icvo mxv - 1" << nl
<< "vread " << caseName << ".vrt icvo,,,coded" << nl
<< "cread " << caseName << ".cel icvo,,,add,coded" << nl
<< "*set icvo" << nl
<< "! end" << nl;
os.flush();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::STARCDedgeFormat::STARCDedgeFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::STARCDedgeFormat::read
(
const fileName& filename
)
{
clear();
fileName baseName = filename.lessExt();
// STAR-CD index of points
List<label> pointId;
// read points from .vrt file
readPoints
(
IFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
storedPoints(),
pointId
);
// Build inverse mapping (STAR-CD pointId -> index)
Map<label> mapPointId(2*pointId.size());
forAll(pointId, i)
{
mapPointId.insert(pointId[i], i);
}
pointId.clear();
// note which points were really used and which can be culled
PackedBoolList usedPoints(points().size());
//
// read .cel file
// ~~~~~~~~~~~~~~
IFstream is(starFileName(baseName, STARCDCore::CEL_FILE));
if (!is.good())
{
FatalErrorInFunction
<< "Cannot read file " << is.name()
<< exit(FatalError);
}
readHeader(is, STARCDCore::HEADER_CEL);
DynamicList<edge> dynEdges;
label lineLabel, shapeId, nLabels, cellTableId, typeId;
DynamicList<label> vertexLabels(64);
while ((is >> lineLabel).good())
{
is >> shapeId >> nLabels >> cellTableId >> typeId;
vertexLabels.clear();
vertexLabels.reserve(nLabels);
// read indices - max 8 per line
for (label i = 0; i < nLabels; ++i)
{
label vrtId;
if ((i % 8) == 0)
{
is >> lineLabel;
}
is >> vrtId;
// convert original vertex id to point label
vertexLabels.append(mapPointId[vrtId]);
}
if (typeId == starcdLineType)
{
if (vertexLabels.size() >= 2)
{
dynEdges.append(edge(vertexLabels[0], vertexLabels[1]));
usedPoints.set(vertexLabels[0]);
usedPoints.set(vertexLabels[1]);
}
}
}
mapPointId.clear();
// not all the points were used, cull them accordingly
if (unsigned(points().size()) != usedPoints.count())
{
label nUsed = 0;
pointField& pts = storedPoints();
forAll(pts, pointi)
{
if (usedPoints.get(pointi))
{
if (nUsed != pointi)
{
pts[nUsed] = pts[pointi];
}
// map prev -> new id
mapPointId.set(pointi, nUsed);
++nUsed;
}
}
pts.setSize(nUsed);
// renumber edge vertices
forAll(dynEdges, edgeI)
{
edge& e = dynEdges[edgeI];
e[0] = mapPointId[e[0]];
e[1] = mapPointId[e[1]];
}
}
storedEdges().transfer(dynEdges);
return true;
}
void Foam::fileFormats::STARCDedgeFormat::write
(
const fileName& filename,
const edgeMesh& mesh
)
{
const pointField& pointLst = mesh.points();
const edgeList& edgeLst = mesh.edges();
fileName baseName = filename.lessExt();
writePoints
(
OFstream(starFileName(baseName, STARCDCore::VRT_FILE))(),
pointLst
);
writeLines
(
OFstream(starFileName(baseName, STARCDCore::CEL_FILE))(),
edgeLst
);
// write a simple .inp file
writeCase
(
OFstream(starFileName(baseName, STARCDCore::INP_FILE))(),
pointLst,
edgeLst.size()
);
}
// ************************************************************************* //

View File

@ -0,0 +1,142 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation | Copyright (C) 2016 OpenCFD Ltd.
-------------------------------------------------------------------------------
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::fileFormats::STARCDedgeFormat
Description
Read/write the lines from pro-STAR vrt/cel files.
Note
Uses the extension \a .inp (input) to denote the format.
See also
Foam::meshReaders::STARCD
SourceFiles
STARCDedgeFormat.C
\*---------------------------------------------------------------------------*/
#ifndef STARCDedgeFormat_H
#define STARCDedgeFormat_H
#include "edgeMesh.H"
#include "STARCDCore.H"
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class STARCDedgeFormat Declaration
\*---------------------------------------------------------------------------*/
class STARCDedgeFormat
:
public edgeMesh,
protected STARCDCore
{
// Private Member Functions
static inline void writeLines(Ostream&, const edgeList&);
//- Disallow default bitwise copy construct
STARCDedgeFormat(const STARCDedgeFormat&) = delete;
//- Disallow default bitwise assignment
void operator=(const STARCDedgeFormat&) = delete;
protected:
// Protected Member Functions
static void writeCase
(
Ostream&,
const pointField&,
const label nEdges
);
public:
// Constructors
//- Construct from file name
STARCDedgeFormat(const fileName&);
// Selectors
//- Read file and return edgeMesh
static autoPtr<edgeMesh> New(const fileName& name)
{
return autoPtr<edgeMesh>
(
new STARCDedgeFormat(name)
);
}
//- Destructor
virtual ~STARCDedgeFormat()
{}
// Member Functions
//- Write edge mesh
static void write(const fileName&, const edgeMesh&);
//- Read from file
virtual bool read(const fileName&);
//- Write object
virtual void write(const fileName& name) const
{
write(name, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "STARCDedgeFormat.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// read edgeMesh
addNamedToRunTimeSelectionTable
(
edgeMesh,
STARCDedgeFormat,
fileExtension,
inp
);
// write edgeMesh
addNamedToMemberFunctionSelectionTable
(
edgeMesh,
STARCDedgeFormat,
write,
fileExtension,
inp
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,173 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "VTKedgeFormat.H"
#include "OFstream.H"
#include "clock.H"
#include "IFstream.H"
#include "vtkUnstructuredReader.H"
#include "Time.H"
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::fileFormats::VTKedgeFormat::writeHeader
(
Ostream& os,
const pointField& pointLst
)
{
// Write header
os << "# vtk DataFile Version 2.0" << nl
<< "featureEdgeMesh written " << clock::dateTime().c_str() << nl
<< "ASCII" << nl
<< nl
<< "DATASET POLYDATA" << nl;
// Write vertex coords
os << "POINTS " << pointLst.size() << " float" << nl;
forAll(pointLst, ptI)
{
const point& pt = pointLst[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
}
void Foam::fileFormats::VTKedgeFormat::writeEdges
(
Ostream& os,
const UList<edge>& edgeLst
)
{
os << "LINES " << edgeLst.size() << ' ' << 3*edgeLst.size() << nl;
forAll(edgeLst, edgeI)
{
const edge& e = edgeLst[edgeI];
os << "2 " << e[0] << ' ' << e[1] << nl;
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::VTKedgeFormat::VTKedgeFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::VTKedgeFormat::read
(
const fileName& filename
)
{
IFstream is(filename);
if (!is.good())
{
FatalErrorInFunction
<< "Cannot read file " << filename
<< exit(FatalError);
}
// Construct dummy time so we have something to create an objectRegistry
// from
Time dummyTime
(
"dummyRoot",
"dummyCase",
"system",
"constant",
false // enableFunctionObjects
);
// Make dummy object registry
objectRegistry obr
(
IOobject
(
"dummy",
dummyTime,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
)
);
// Construct reader to read file
vtkUnstructuredReader reader(obr, is);
// Extract lines
storedPoints().transfer(reader.points());
label nEdges = 0;
forAll(reader.lines(), lineI)
{
nEdges += reader.lines()[lineI].size()-1;
}
storedEdges().setSize(nEdges);
nEdges = 0;
forAll(reader.lines(), lineI)
{
const labelList& verts = reader.lines()[lineI];
for (label i = 1; i < verts.size(); i++)
{
storedEdges()[nEdges++] = edge(verts[i-1], verts[i]);
}
}
return true;
}
void Foam::fileFormats::VTKedgeFormat::write
(
const fileName& filename,
const edgeMesh& eMesh
)
{
OFstream os(filename);
if (!os.good())
{
FatalErrorInFunction
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
writeHeader(os, eMesh.points());
writeEdges(os, eMesh.edges());
}
// ************************************************************************* //

View File

@ -0,0 +1,130 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
Class
Foam::fileFormats::VTKedgeFormat
Description
Provide a means of writing VTK legacy format.
SourceFiles
VTKedgeFormat.C
\*---------------------------------------------------------------------------*/
#ifndef VTKedgeFormat_H
#define VTKedgeFormat_H
#include "edgeMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class VTKedgeFormat Declaration
\*---------------------------------------------------------------------------*/
class VTKedgeFormat
:
public edgeMesh
{
// Private Member Functions
//- Disallow default bitwise copy construct
VTKedgeFormat(const VTKedgeFormat&);
//- Disallow default bitwise assignment
void operator=(const VTKedgeFormat&);
protected:
// Protected Member Functions
//- Write header information with points
static void writeHeader
(
Ostream&,
const pointField&
);
//- Write edges
static void writeEdges(Ostream&, const UList<edge>&);
public:
// Constructors
//- Construct from file name
VTKedgeFormat(const fileName&);
// Selectors
//- Read file and return surface
static autoPtr<edgeMesh> New(const fileName& name)
{
return autoPtr<edgeMesh>
(
new VTKedgeFormat(name)
);
}
//- Destructor
virtual ~VTKedgeFormat()
{}
// Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const edgeMesh&);
//- Read from file
virtual bool read(const fileName&);
//- Write object file
virtual void write(const fileName& name) const
{
write(name, *this);
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,60 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "VTKedgeFormat.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// read edgeMesh
addNamedToRunTimeSelectionTable
(
edgeMesh,
VTKedgeFormat,
fileExtension,
vtk
);
// write edgeMesh
addNamedToMemberFunctionSelectionTable
(
edgeMesh,
VTKedgeFormat,
write,
fileExtension,
vtk
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,85 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
inline Foam::pointField& Foam::edgeMesh::storedPoints()
{
return points_;
}
inline Foam::edgeList& Foam::edgeMesh::storedEdges()
{
return edges_;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
inline Foam::edgeMesh::edgeMesh(const edgeMesh& em)
:
fileFormats::edgeMeshFormatsCore(),
points_(em.points_),
edges_(em.edges_),
pointEdgesPtr_(nullptr)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline const Foam::pointField& Foam::edgeMesh::points() const
{
return points_;
}
inline const Foam::edgeList& Foam::edgeMesh::edges() const
{
return edges_;
}
inline const Foam::labelListList& Foam::edgeMesh::pointEdges() const
{
if (pointEdgesPtr_.empty())
{
calcPointEdges();
}
return pointEdgesPtr_();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
void Foam::edgeMesh::operator=(const edgeMesh& rhs)
{
points_ = rhs.points_;
edges_ = rhs.edges_;
pointEdgesPtr_.clear();
}
// ************************************************************************* //

View File

@ -0,0 +1,151 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "edgeMesh.H"
#include "boundBox.H"
#include "edgeMeshFormat.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::edgeMesh::edgeMesh
(
const fileName& name,
const word& ext
)
:
points_(0),
edges_(0),
pointEdgesPtr_(nullptr)
{
read(name, ext);
}
Foam::edgeMesh::edgeMesh(const fileName& name)
:
points_(0),
edges_(0),
pointEdgesPtr_(nullptr)
{
read(name);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::edgeMesh::read(const fileName& name)
{
word ext = name.ext();
if (ext == "gz")
{
fileName unzipName = name.lessExt();
return read(unzipName, unzipName.ext());
}
else
{
return read(name, ext);
}
}
// Read from file in given format
bool Foam::edgeMesh::read
(
const fileName& name,
const word& ext
)
{
// read via selector mechanism
transfer(New(name, ext)());
return true;
}
void Foam::edgeMesh::write
(
const fileName& name,
const edgeMesh& mesh
)
{
if (debug)
{
InfoInFunction << "Writing to " << name << endl;
}
const word ext = name.ext();
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->sortedToc()
<< exit(FatalError);
}
else
{
mfIter()(name, mesh);
}
}
void Foam::edgeMesh::writeStats(Ostream& os) const
{
os << indent << "points : " << points().size() << nl;
os << indent << "edges : " << edges().size() << nl;
os << indent << "boundingBox : " << boundBox(this->points()) << endl;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const edgeMesh& em)
{
fileFormats::edgeMeshFormat::write(os, em.points_, em.edges_);
// Check state of Ostream
os.check("Ostream& operator<<(Ostream&, const edgeMesh&)");
return os;
}
Foam::Istream& Foam::operator>>(Istream& is, edgeMesh& em)
{
fileFormats::edgeMeshFormat::read(is, em.points_, em.edges_);
em.pointEdgesPtr_.clear();
// Check state of Istream
is.check("Istream& operator>>(Istream&, edgeMesh&)");
return is;
}
// ************************************************************************* //

View File

@ -0,0 +1,64 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "edgeMesh.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::edgeMesh> Foam::edgeMesh::New
(
const fileName& name,
const word& ext
)
{
fileExtensionConstructorTable::iterator cstrIter =
fileExtensionConstructorTablePtr_->find(ext);
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown file extension " << ext
<< " for file " << name << nl << nl
<< "Valid extensions are :" << nl
<< fileExtensionConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<edgeMesh>(cstrIter()(name));
}
Foam::autoPtr<Foam::edgeMesh> Foam::edgeMesh::New(const fileName& name)
{
word ext = name.ext();
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return New(name, ext);
}
// ************************************************************************* //

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,641 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / 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.
-------------------------------------------------------------------------------
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::extendedEdgeMesh
Description
Description of feature edges and points.
Feature points are a sorted subset at the start of the overall points list:
0 .. concaveStart_-1 : convex points (w.r.t normals)
concaveStart_ .. mixedStart_-1 : concave points
mixedStart_ .. nonFeatureStart_-1 : mixed internal/external points
nonFeatureStart_ .. size-1 : non-feature points
Feature edges are the edgeList of the edgeMesh and are sorted:
0 .. internalStart_-1 : external edges (convex w.r.t normals)
internalStart_ .. flatStart_-1 : internal edges (concave)
flatStart_ .. openStart_-1 : flat edges (neither concave or convex)
can arise from region interfaces on
flat surfaces
openStart_ .. multipleStart_-1 : open edges (e.g. from baffle surfaces)
multipleStart_ .. size-1 : multiply connected edges
The edge direction and feature edge and feature point adjacent normals
are stored.
SourceFiles
extendedEdgeMeshI.H
extendedEdgeMesh.C
extendedEdgeMeshNew.C
\*---------------------------------------------------------------------------*/
#ifndef extendedEdgeMesh_H
#define extendedEdgeMesh_H
#include "edgeMesh.H"
#include "indexedOctree.H"
#include "treeDataEdge.H"
#include "treeDataPoint.H"
#include "PrimitivePatch.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class surfaceFeatures;
class searchableSurface;
// Forward declaration of friend functions and operators
class extendedEdgeMesh;
Istream& operator>>(Istream&, extendedEdgeMesh&);
Ostream& operator<<(Ostream&, const extendedEdgeMesh&);
/*---------------------------------------------------------------------------*\
Class extendedEdgeMesh Declaration
\*---------------------------------------------------------------------------*/
class extendedEdgeMesh
:
public edgeMesh
{
public:
//- Runtime type information
TypeName("extendedEdgeMesh");
enum pointStatus
{
CONVEX, // Fully convex point (w.r.t normals)
CONCAVE, // Fully concave point
MIXED, // A point surrounded by both convex and concave edges
NONFEATURE // Not a feature point
};
static const Foam::NamedEnum<pointStatus, 4> pointStatusNames_;
enum edgeStatus
{
EXTERNAL, // "Convex" edge
INTERNAL, // "Concave" edge
FLAT, // Neither concave or convex, on a flat surface
OPEN, // i.e. only connected to one face
MULTIPLE, // Multiply connected (connected to more than two faces)
NONE // Not a classified feature edge (consistency with
// surfaceFeatures)
};
static const Foam::NamedEnum<edgeStatus, 6> edgeStatusNames_;
//- Normals point to the outside
enum sideVolumeType
{
INSIDE = 0, // mesh inside
OUTSIDE = 1, // mesh outside
BOTH = 2, // e.g. a baffle
NEITHER = 3 // not sure when this may be used
};
static const Foam::NamedEnum<sideVolumeType, 4> sideVolumeTypeNames_;
//- Angular closeness tolerance for treating normals as the same
static scalar cosNormalAngleTol_;
protected:
// Static data
//- Index of the start of the convex feature points - static as 0
static label convexStart_;
//- Index of the start of the external feature edges - static as 0
static label externalStart_;
// Protected data
//- Index of the start of the concave feature points
label concaveStart_;
//- Index of the start of the mixed type feature points
label mixedStart_;
//- Index of the start of the non-feature points
label nonFeatureStart_;
//- Index of the start of the internal feature edges
label internalStart_;
//- Index of the start of the flat feature edges
label flatStart_;
//- Index of the start of the open feature edges
label openStart_;
//- Index of the start of the multiply-connected feature edges
label multipleStart_;
//- Normals of the features, to be referred to by index by both feature
// points and edges, unsorted
vectorField normals_;
//- Type per normal: which side of normal to mesh
List<sideVolumeType> normalVolumeTypes_;
//- Flat and open edges require the direction of the edge
vectorField edgeDirections_;
//- Starting directions for the edges.
// This vector points to the half of the plane defined by the first
// edge normal.
labelListList normalDirections_;
//- Indices of the normals that are adjacent to the feature edges
labelListList edgeNormals_;
//- Indices of the normals that are adjacent to the feature points
// (only valid for 0..nonFeatureStart_-1)
labelListList featurePointNormals_;
//- Indices of feature edges attached to feature points. The edges are
// ordered so that they can be circulated.
labelListList featurePointEdges_;
//- Feature edges which are on the boundary between regions
labelList regionEdges_;
//- Search tree for all feature points
mutable autoPtr<indexedOctree<treeDataPoint>> pointTree_;
//- Search tree for all edges
mutable autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
//- Individual search trees for each type of edge
mutable PtrList<indexedOctree<treeDataEdge>> edgeTreesByType_;
// Protected Member Functions
//- Classify the type of feature point. Requires valid stored member
// data for edges and normals.
pointStatus classifyFeaturePoint(label ptI) const;
//- Cut edges with surface. Return map from cut points&edges back
// to original
void cut
(
const searchableSurface&,
labelList& pMap,
labelList& eMap,
labelList& pointsFromEdge, // new points created by cutting
labelList& oldEdge, // the orginal edge
labelList& surfTri // the surface triangle index
);
//- Remove outside/inside edges. volType denotes which side to keep
void select
(
const searchableSurface& surf,
const volumeType volType,
labelList& pMap,
labelList& eMap
);
template<class Patch>
void sortPointsAndEdges
(
const Patch&,
const labelList& featureEdges,
const labelList& regionFeatureEdges,
const labelList& feaurePoints
);
public:
// Static data
//- Number of possible point types (i.e. number of slices)
static label nPointTypes;
//- Number of possible feature edge types (i.e. number of slices)
static label nEdgeTypes;
//- Can we read this file format?
static bool canRead(const fileName&, const bool verbose=false);
//- Can we read this file format?
static bool canReadType(const word& ext, const bool verbose=false);
//- Can we write this file format type?
static bool canWriteType(const word& ext, const bool verbose=false);
static wordHashSet readTypes();
static wordHashSet writeTypes();
// Constructors
//- Construct null
extendedEdgeMesh();
//- Construct as copy
explicit extendedEdgeMesh(const extendedEdgeMesh&);
//- Construct from file name (uses extension to determine type)
extendedEdgeMesh(const fileName&);
//- Construct from file name (uses extension to determine type)
extendedEdgeMesh(const fileName&, const word& ext);
//- Construct from Istream
extendedEdgeMesh(Istream&);
//- Construct by transferring components (points, edges)
extendedEdgeMesh
(
const Xfer<pointField>&,
const Xfer<edgeList>&
);
//- Construct given a surface with selected edges,points
// (surfaceFeatures)
// Extracts, classifies and reorders the data from surfaceFeatures.
extendedEdgeMesh
(
const surfaceFeatures& sFeat,
const boolList& surfBaffleRegions
);
//- Construct from PrimitivePatch
extendedEdgeMesh
(
const PrimitivePatch<face, List, pointField, point>& surf,
const labelList& featureEdges,
const labelList& regionFeatureEdges,
const labelList& featurePoints
);
//- Construct from all components
extendedEdgeMesh
(
const pointField& pts,
const edgeList& eds,
label concaveStart,
label mixedStart,
label nonFeatureStart,
label internalStart,
label flatStart,
label openStart,
label multipleStart,
const vectorField& normals,
const List<sideVolumeType>& normalVolumeTypes,
const vectorField& edgeDirections,
const labelListList& normalDirections,
const labelListList& edgeNormals,
const labelListList& featurePointNormals,
const labelListList& featurePointEdges,
const labelList& regionEdges
);
// Declare run-time constructor selection table
declareRunTimeSelectionTable
(
autoPtr,
extendedEdgeMesh,
fileExtension,
(
const fileName& name
),
(name)
);
// Selectors
//- Select constructed from filename (explicit extension)
static autoPtr<extendedEdgeMesh> New
(
const fileName&,
const word& ext
);
//- Select constructed from filename (implicit extension)
static autoPtr<extendedEdgeMesh> New(const fileName&);
//- Destructor
~extendedEdgeMesh();
// Member Functions
// Find
//- Find nearest surface edge for the sample point.
void nearestFeaturePoint
(
const point& sample,
scalar searchDistSqr,
pointIndexHit& info
) const;
//- Find nearest surface edge for the sample point.
void nearestFeatureEdge
(
const point& sample,
scalar searchDistSqr,
pointIndexHit& info
) const;
//- Find nearest surface edge for each sample point.
void nearestFeatureEdge
(
const pointField& samples,
const scalarField& searchDistSqr,
List<pointIndexHit>& info
) const;
//- Find the nearest point on each type of feature edge
void nearestFeatureEdgeByType
(
const point& sample,
const scalarField& searchDistSqr,
List<pointIndexHit>& info
) const;
//- Find all the feature points within searchDistSqr of sample
void allNearestFeaturePoints
(
const point& sample,
scalar searchRadiusSqr,
List<pointIndexHit>& info
) const;
//- Find all the feature edges within searchDistSqr of sample
void allNearestFeatureEdges
(
const point& sample,
const scalar searchRadiusSqr,
List<pointIndexHit>& info
) const;
// Access
//- Return the index of the start of the convex feature points
inline label convexStart() const;
//- Return the index of the start of the concave feature points
inline label concaveStart() const;
//- Return the index of the start of the mixed type feature points
inline label mixedStart() const;
//- Return the index of the start of the non-feature points
inline label nonFeatureStart() const;
//- Return the index of the start of the external feature edges
inline label externalStart() const;
//- Return the index of the start of the internal feature edges
inline label internalStart() const;
//- Return the index of the start of the flat feature edges
inline label flatStart() const;
//- Return the index of the start of the open feature edges
inline label openStart() const;
//- Return the index of the start of the multiply-connected feature
// edges
inline label multipleStart() const;
//- Return whether or not the point index is a feature point
inline bool featurePoint(label ptI) const;
//- Return the normals of the surfaces adjacent to the feature edges
// and points
inline const vectorField& normals() const;
//- Return
inline const List<sideVolumeType>& normalVolumeTypes() const;
//- Return the edgeDirection vectors
inline const vectorField& edgeDirections() const;
//-
inline const labelListList& normalDirections() const;
//- Return the direction of edgeI, pointing away from ptI
inline vector edgeDirection(label edgeI, label ptI) const;
//- Return the indices of the normals that are adjacent to the
// feature edges
inline const labelListList& edgeNormals() const;
//- Return the normal vectors for a given set of normal indices
inline vectorField edgeNormals(const labelList& edgeNormIs) const;
//- Return the normal vectors for a given edge
inline vectorField edgeNormals(label edgeI) const;
//- Return the indices of the normals that are adjacent to the
// feature points
inline const labelListList& featurePointNormals() const;
//- Return the normal vectors for a given feature point
inline vectorField featurePointNormals(label ptI) const;
//- Return the edge labels for a given feature point. Edges are
// ordered by the faces that they share. The edge labels
// correspond to the entry in edges().
inline const labelListList& featurePointEdges() const;
//- Return the feature edges which are on the boundary between
// regions
inline const labelList& regionEdges() const;
//- Return the pointStatus of a specified point
inline pointStatus getPointStatus(label ptI) const;
//- Return the edgeStatus of a specified edge
inline edgeStatus getEdgeStatus(label edgeI) const;
//- Return the baffle faces of a specified edge
inline PackedList<2> edgeBaffles(label edgeI) const;
//- Demand driven construction of octree for feature points
const indexedOctree<treeDataPoint>& pointTree() const;
//- Demand driven construction of octree for boundary edges
const indexedOctree<treeDataEdge>& edgeTree() const;
//- Demand driven construction of octree for boundary edges by type
const PtrList<indexedOctree<treeDataEdge>>&
edgeTreesByType() const;
// Edit
//- Transfer the contents of the argument and annul the argument
void transfer(extendedEdgeMesh&);
//- Transfer contents to the Xfer container
Xfer<extendedEdgeMesh > xfer();
//- Clear all storage
virtual void clear();
//- Add extendedEdgeMesh. No filtering of duplicates.
void add(const extendedEdgeMesh&);
//- Flip normals. All concave become convex, all internal external
// etc.
void flipNormals();
//- Update with derived geometry
void autoMap
(
const pointField&,
const edgeList&,
const labelList& pointMap,
const labelList& edgeMap
);
//- Trim to surface. Keep volType side. Return map from current back
// to original points (-1 for newly introduced points), edges
void trim
(
const searchableSurface& surf,
const volumeType volType,
labelList& pointMap,
labelList& edgeMap
);
//- Order according to point and edge status
void setFromStatus
(
const List<extendedEdgeMesh::pointStatus>& pointStat,
const List<extendedEdgeMesh::edgeStatus>& edgeStat,
labelList& sortedToOriginalPoint,
labelList& sortedToOriginalEdge
);
//- Geometric merge points. Returns true if any points merged.
// Return maps from new back to original points/edges.
bool mergePointsAndSort
(
const scalar mergeDist,
labelList& pointMap,
labelList& edgeMap
);
// Read
//- Read from file. Chooses reader based on explicit extension
bool read(const fileName&, const word& ext);
//- Read from file. Chooses reader based on detected extension
virtual bool read(const fileName&);
// Write
//- Write all components of the extendedEdgeMesh as obj files
void writeObj(const fileName& prefix) const;
//- Dump some information
virtual void writeStats(Ostream& os) const;
friend Istream& operator>>(Istream& is, sideVolumeType& vt);
friend Ostream& operator<<(Ostream& os, const sideVolumeType& vt);
//- Classify the type of feature edge. Requires face centre 0 to face
// centre 1 vector to distinguish internal from external
static edgeStatus classifyEdge
(
const List<vector>& norms,
const labelList& edNorms,
const vector& fC0tofC1
);
//- Determine the ordering
static void sortedOrder
(
const List<extendedEdgeMesh::pointStatus>& pointStat,
const List<extendedEdgeMesh::edgeStatus>& edgeStat,
labelList& sortedToOriginalPoint,
labelList& sortedToOriginalEdge,
label& pointConcaveStart,
label& pointMixedStart,
label& pointNonFeatStart,
label& edgeInternalStart,
label& edgeFlatStart,
label& edgeOpenStart,
label& edgeMultipleStart
);
// Ostream Operator
friend Ostream& operator<<(Ostream&, const extendedEdgeMesh&);
friend Istream& operator>>(Istream&, extendedEdgeMesh&);
};
Istream& operator>>(Istream& is, extendedEdgeMesh::sideVolumeType& vt);
Ostream& operator<<(Ostream& os, const extendedEdgeMesh::sideVolumeType& vt);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "extendedEdgeMeshI.H"
#ifdef NoRepository
#include "extendedEdgeMeshTemplates.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,104 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "extendedEdgeMeshFormat.H"
#include "IFstream.H"
#include "Time.H"
#include "extendedFeatureEdgeMesh.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::extendedEdgeMeshFormat::extendedEdgeMeshFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::extendedEdgeMeshFormat::read
(
const fileName& filename
)
{
clear();
fileName dir = filename.path();
fileName caseName = dir.name();
fileName rootPath = dir.path();
// Construct dummy time to use as an objectRegistry
Time dummyTime
(
".", //rootPath,
".", //caseName,
"system", //systemName,
"constant", //constantName,
false //enableFunctionObjects
);
// Construct IOobject to re-use the headerOk & readHeader
// (so we can read ascii and binary)
IOobject io
(
filename,
dummyTime,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
);
if (!io.typeHeaderOk<extendedFeatureEdgeMesh>(false))
{
FatalErrorInFunction
<< "Cannot read file " << filename
<< exit(FatalError);
}
const fileName fName(typeFilePath<extendedFeatureEdgeMesh>(io));
autoPtr<IFstream> isPtr(new IFstream(fName));
bool ok = false;
if (isPtr().good())
{
Istream& is = isPtr();
ok = io.readHeader(is);
if (ok)
{
// Use extendedEdgeMesh IO
is >> *this;
ok = is.good();
}
}
return ok;
}
// ************************************************************************* //

View File

@ -0,0 +1,95 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 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/>.
Class
Foam::fileFormats::extendedEdgeMeshFormat
Description
Provide a means of reading/writing the single-file OpenFOAM
extendedEdgeMesh format
SourceFiles
extendedEdgeMeshFormat.C
\*---------------------------------------------------------------------------*/
#ifndef extendedEdgeMeshFormat_H
#define extendedEdgeMeshFormat_H
#include "extendedEdgeMesh.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class extendedEdgeMeshFormat Declaration
\*---------------------------------------------------------------------------*/
class extendedEdgeMeshFormat
:
public extendedEdgeMesh
{
// Private Member Functions
//- Disallow default bitwise copy construct
extendedEdgeMeshFormat(const extendedEdgeMeshFormat&);
//- Disallow default bitwise assignment
void operator=(const extendedEdgeMeshFormat&);
public:
// Constructors
//- Construct from file name
extendedEdgeMeshFormat(const fileName&);
//- Destructor
virtual ~extendedEdgeMeshFormat()
{}
// Member Functions
//- Read from file
virtual bool read(const fileName&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,51 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "extendedEdgeMeshFormat.H"
#include "extendedEdgeMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
// read extendedEdgeMesh
addNamedToRunTimeSelectionTable
(
extendedEdgeMesh,
extendedEdgeMeshFormat,
fileExtension,
extendedFeatureEdgeMesh // extension
);
}
}
// ************************************************************************* //

View File

@ -0,0 +1,293 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::extendedEdgeMesh::convexStart() const
{
return convexStart_;
}
inline Foam::label Foam::extendedEdgeMesh::concaveStart() const
{
return concaveStart_;
}
inline Foam::label Foam::extendedEdgeMesh::mixedStart() const
{
return mixedStart_;
}
inline Foam::label Foam::extendedEdgeMesh::nonFeatureStart() const
{
return nonFeatureStart_;
}
inline Foam::label Foam::extendedEdgeMesh::externalStart() const
{
return externalStart_;
}
inline Foam::label Foam::extendedEdgeMesh::internalStart() const
{
return internalStart_;
}
inline Foam::label Foam::extendedEdgeMesh::flatStart() const
{
return flatStart_;
}
inline Foam::label Foam::extendedEdgeMesh::openStart() const
{
return openStart_;
}
inline Foam::label Foam::extendedEdgeMesh::multipleStart() const
{
return multipleStart_;
}
inline bool Foam::extendedEdgeMesh::featurePoint(label ptI) const
{
return ptI < nonFeatureStart_;
}
inline const Foam::vectorField& Foam::extendedEdgeMesh::normals() const
{
return normals_;
}
inline const Foam::List<Foam::extendedEdgeMesh::sideVolumeType>&
Foam::extendedEdgeMesh::normalVolumeTypes() const
{
return normalVolumeTypes_;
}
inline const Foam::vectorField& Foam::extendedEdgeMesh::edgeDirections()
const
{
return edgeDirections_;
}
inline const Foam::labelListList&
Foam::extendedEdgeMesh::normalDirections() const
{
return normalDirections_;
}
inline Foam::vector Foam::extendedEdgeMesh::edgeDirection
(
label edgeI,
label ptI
) const
{
const edge& e = edges()[edgeI];
if (ptI == e.start())
{
return edgeDirections()[edgeI];
}
else if (ptI == e.end())
{
return -edgeDirections()[edgeI];
}
else
{
FatalErrorInFunction
<< "Requested ptI " << ptI << " is not a point on the requested "
<< "edgeI " << edgeI << ". edgeI start and end: "
<< e.start() << " " << e.end()
<< exit(FatalError);
return Zero;
}
}
inline const Foam::labelListList& Foam::extendedEdgeMesh::edgeNormals()
const
{
return edgeNormals_;
}
inline Foam::vectorField Foam::extendedEdgeMesh::edgeNormals
(
const labelList& edgeNormIs
) const
{
vectorField norms(edgeNormIs.size());
forAll(edgeNormIs, i)
{
norms[i] = normals_[edgeNormIs[i]];
}
return norms;
}
inline Foam::vectorField Foam::extendedEdgeMesh::edgeNormals(label edgeI)
const
{
return edgeNormals(edgeNormals_[edgeI]);
}
inline const Foam::labelListList&
Foam::extendedEdgeMesh::featurePointNormals() const
{
return featurePointNormals_;
}
inline Foam::vectorField Foam::extendedEdgeMesh::featurePointNormals
(
label ptI
) const
{
if (!featurePoint(ptI))
{
WarningInFunction
<< "Requesting the normals of a non-feature point. "
<< "Returned zero length vectorField."
<< endl;
return vectorField(0);
}
labelList featPtNormIs(featurePointNormals_[ptI]);
vectorField norms(featPtNormIs.size());
forAll(featPtNormIs, i)
{
norms[i] = normals_[featPtNormIs[i]];
}
return norms;
}
inline const Foam::labelListList&
Foam::extendedEdgeMesh::featurePointEdges() const
{
return featurePointEdges_;
}
inline const Foam::labelList& Foam::extendedEdgeMesh::regionEdges() const
{
return regionEdges_;
}
inline Foam::extendedEdgeMesh::pointStatus
Foam::extendedEdgeMesh::getPointStatus(label ptI) const
{
if (ptI < concaveStart_)
{
return CONVEX;
}
else if (ptI < mixedStart_)
{
return CONCAVE;
}
else if (ptI < nonFeatureStart_)
{
return MIXED;
}
else
{
return NONFEATURE;
}
}
inline Foam::extendedEdgeMesh::edgeStatus
Foam::extendedEdgeMesh::getEdgeStatus(label edgeI) const
{
if (edgeI < internalStart_)
{
return EXTERNAL;
}
else if (edgeI < flatStart_)
{
return INTERNAL;
}
else if (edgeI < openStart_)
{
return FLAT;
}
else if (edgeI < multipleStart_)
{
return OPEN;
}
else
{
return MULTIPLE;
}
}
inline Foam::PackedList<2> Foam::extendedEdgeMesh::edgeBaffles
(
label edgeI
) const
{
const labelList& eNormals = edgeNormals_[edgeI];
DynamicList<label> edgeBaffles(eNormals.size());
forAll(eNormals, enI)
{
const label normI = eNormals[enI];
if (normalVolumeTypes_[normI])
{
edgeBaffles.append(normI);
}
}
return PackedList<2>(edgeBaffles);
}
// ************************************************************************* //

View File

@ -0,0 +1,76 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2013-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "extendedEdgeMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineRunTimeSelectionTable(extendedEdgeMesh, fileExtension);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::autoPtr<Foam::extendedEdgeMesh> Foam::extendedEdgeMesh::New
(
const fileName& name,
const word& ext
)
{
fileExtensionConstructorTable::iterator cstrIter =
fileExtensionConstructorTablePtr_->find(ext);
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
FatalErrorInFunction
<< "Unknown file extension " << ext
<< " for file " << name << nl << nl
<< "Valid extensions are :" << nl
<< fileExtensionConstructorTablePtr_->sortedToc()
<< exit(FatalError);
}
return autoPtr<extendedEdgeMesh>(cstrIter()(name));
}
Foam::autoPtr<Foam::extendedEdgeMesh> Foam::extendedEdgeMesh::New
(
const fileName& name
)
{
word ext = name.ext();
if (ext == "gz")
{
ext = name.lessExt().ext();
}
return New(name, ext);
}
// ************************************************************************* //

View File

@ -0,0 +1,418 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "extendedEdgeMesh.H"
#include "ListListOps.H"
#include "unitConversion.H"
#include "PackedBoolList.H"
#include "PatchTools.H"
#include "searchableBox.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Patch>
void Foam::extendedEdgeMesh::sortPointsAndEdges
(
const Patch& surf,
const labelList& featureEdges,
const labelList& regionFeatureEdges,// subset of featureEdges: inter-region
const labelList& featurePoints
)
{
const pointField& sFeatLocalPts(surf.localPoints());
const edgeList& sFeatEds(surf.edges());
const labelListList edgeFaces = PatchTools::sortedEdgeFaces(surf);
const vectorField& faceNormals = surf.faceNormals();
const labelListList pointEdges = PatchTools::sortedPointEdges(surf);
// Extract and reorder the data from surfaceFeatures
// References to the surfaceFeatures data
// Filling the extendedEdgeMesh with the raw geometrical data.
label nFeatEds = featureEdges.size();
label nFeatPts = featurePoints.size();
DynamicList<point> tmpPts;
edgeList eds(nFeatEds);
DynamicList<vector> norms;
vectorField edgeDirections(nFeatEds);
labelListList edgeNormals(nFeatEds);
labelListList normalDirections(nFeatEds);
DynamicList<label> regionEdges;
// Keep track of the ordered feature point feature edges
labelListList featurePointFeatureEdges(nFeatPts);
forAll(featurePointFeatureEdges, pI)
{
featurePointFeatureEdges[pI] = pointEdges[featurePoints[pI]];
}
// Mapping between old and new indices, there is entry in the map for each
// of surf.localPoints, -1 means that this point hasn't been used (yet),
// >= 0 corresponds to the index
labelList pointMap(sFeatLocalPts.size(), -1);
// Mapping between surface edge index and its feature edge index. -1 if it
// is not a feature edge
labelList edgeMap(sFeatEds.size(), -1);
// Noting when the normal of a face has been used so not to duplicate
labelList faceMap(surf.size(), -1);
// Collecting the status of edge for subsequent sorting
List<edgeStatus> edStatus(nFeatEds, NONE);
forAll(featurePoints, i)
{
label sFPI = featurePoints[i];
tmpPts.append(sFeatLocalPts[sFPI]);
pointMap[sFPI] = tmpPts.size() - 1;
}
// All feature points have been added
nonFeatureStart_ = tmpPts.size();
PackedBoolList isRegionFeatureEdge(regionFeatureEdges);
forAll(featureEdges, i)
{
label sFEI = featureEdges[i];
edgeMap[sFEI] = i;
const edge& fE = sFeatEds[sFEI];
edgeDirections[i] = fE.vec(sFeatLocalPts);
// Check to see if the points have been already used
if (pointMap[fE.start()] == -1)
{
tmpPts.append(sFeatLocalPts[fE.start()]);
pointMap[fE.start()] = tmpPts.size() - 1;
}
eds[i].start() = pointMap[fE.start()];
if (pointMap[fE.end()] == -1)
{
tmpPts.append(sFeatLocalPts[fE.end()]);
pointMap[fE.end()] = tmpPts.size() - 1;
}
eds[i].end() = pointMap[fE.end()];
// Pick up the faces adjacent to the feature edge
const labelList& eFaces = edgeFaces[sFEI];
edgeNormals[i].setSize(eFaces.size());
normalDirections[i].setSize(eFaces.size());
forAll(eFaces, j)
{
label eFI = eFaces[j];
// Check to see if the points have been already used
if (faceMap[eFI] == -1)
{
norms.append(faceNormals[eFI]);
faceMap[eFI] = norms.size() - 1;
}
edgeNormals[i][j] = faceMap[eFI];
const vector cross = (faceNormals[eFI] ^ edgeDirections[i]);
const vector fC0tofE0 =
surf[eFI].centre(surf.points())
- sFeatLocalPts[fE.start()];
normalDirections[i][j] =
(
(
(cross/(mag(cross) + VSMALL))
& (fC0tofE0/(mag(fC0tofE0)+ VSMALL))
)
> 0.0
? 1
: -1
);
}
vector fC0tofC1(Zero);
if (eFaces.size() == 2)
{
fC0tofC1 =
surf[eFaces[1]].centre(surf.points())
- surf[eFaces[0]].centre(surf.points());
}
edStatus[i] = classifyEdge(norms, edgeNormals[i], fC0tofC1);
if (isRegionFeatureEdge[i])
{
regionEdges.append(i);
}
}
// Populate feature point feature edges
DynamicList<label> newFeatureEdges;
forAll(featurePointFeatureEdges, pI)
{
const labelList& fpfe = featurePointFeatureEdges[pI];
newFeatureEdges.setCapacity(fpfe.size());
forAll(fpfe, eI)
{
const label oldEdgeIndex = fpfe[eI];
const label newFeatureEdgeIndex = edgeMap[oldEdgeIndex];
if (newFeatureEdgeIndex != -1)
{
newFeatureEdges.append(newFeatureEdgeIndex);
}
}
featurePointFeatureEdges[pI].transfer(newFeatureEdges);
}
// Reorder the edges by classification
List<DynamicList<label>> allEds(nEdgeTypes);
DynamicList<label>& externalEds(allEds[0]);
DynamicList<label>& internalEds(allEds[1]);
DynamicList<label>& flatEds(allEds[2]);
DynamicList<label>& openEds(allEds[3]);
DynamicList<label>& multipleEds(allEds[4]);
forAll(eds, i)
{
edgeStatus eStat = edStatus[i];
if (eStat == EXTERNAL)
{
externalEds.append(i);
}
else if (eStat == INTERNAL)
{
internalEds.append(i);
}
else if (eStat == FLAT)
{
flatEds.append(i);
}
else if (eStat == OPEN)
{
openEds.append(i);
}
else if (eStat == MULTIPLE)
{
multipleEds.append(i);
}
else if (eStat == NONE)
{
FatalErrorInFunction
<< nl << "classifyEdge returned NONE on edge "
<< eds[i]
<< ". There is a problem with definition of this edge."
<< nl << abort(FatalError);
}
}
internalStart_ = externalEds.size();
flatStart_ = internalStart_ + internalEds.size();
openStart_ = flatStart_ + flatEds.size();
multipleStart_ = openStart_ + openEds.size();
labelList edMap
(
ListListOps::combine<labelList>
(
allEds,
accessOp<labelList>()
)
);
edMap = invert(edMap.size(), edMap);
inplaceReorder(edMap, eds);
inplaceReorder(edMap, edStatus);
inplaceReorder(edMap, edgeDirections);
inplaceReorder(edMap, edgeNormals);
inplaceReorder(edMap, normalDirections);
inplaceRenumber(edMap, regionEdges);
forAll(featurePointFeatureEdges, pI)
{
inplaceRenumber(edMap, featurePointFeatureEdges[pI]);
}
pointField pts(tmpPts);
// Initialise the edgeMesh
edgeMesh::operator=(edgeMesh(pts, eds));
// Initialise sorted edge related data
edgeDirections_ = edgeDirections/(mag(edgeDirections) + VSMALL);
edgeNormals_ = edgeNormals;
normalDirections_ = normalDirections;
regionEdges_ = regionEdges;
// Normals are all now found and indirectly addressed, can also be stored
normals_ = vectorField(norms);
// Reorder the feature points by classification
List<DynamicList<label>> allPts(3);
DynamicList<label>& convexPts(allPts[0]);
DynamicList<label>& concavePts(allPts[1]);
DynamicList<label>& mixedPts(allPts[2]);
for (label i = 0; i < nonFeatureStart_; i++)
{
pointStatus ptStatus = classifyFeaturePoint(i);
if (ptStatus == CONVEX)
{
convexPts.append(i);
}
else if (ptStatus == CONCAVE)
{
concavePts.append(i);
}
else if (ptStatus == MIXED)
{
mixedPts.append(i);
}
else if (ptStatus == NONFEATURE)
{
FatalErrorInFunction
<< nl << "classifyFeaturePoint returned NONFEATURE on point at "
<< points()[i]
<< ". There is a problem with definition of this feature point."
<< nl << abort(FatalError);
}
}
concaveStart_ = convexPts.size();
mixedStart_ = concaveStart_ + concavePts.size();
labelList ftPtMap
(
ListListOps::combine<labelList>
(
allPts,
accessOp<labelList>()
)
);
ftPtMap = invert(ftPtMap.size(), ftPtMap);
// Creating the ptMap from the ftPtMap with identity values up to the size
// of pts to create an oldToNew map for inplaceReorder
labelList ptMap(identity(pts.size()));
forAll(ftPtMap, i)
{
ptMap[i] = ftPtMap[i];
}
inplaceReorder(ptMap, pts);
inplaceReorder(ptMap, featurePointFeatureEdges);
forAll(eds, i)
{
inplaceRenumber(ptMap, eds[i]);
}
// Reinitialise the edgeMesh with sorted feature points and
// renumbered edges
reset(xferMove(pts), xferMove(eds));
// Generate the featurePointNormals
labelListList featurePointNormals(nonFeatureStart_);
for (label i = 0; i < nonFeatureStart_; i++)
{
DynamicList<label> tmpFtPtNorms;
const labelList& ptEds = edgeMesh::pointEdges()[i];
forAll(ptEds, j)
{
const labelList& ptEdNorms(edgeNormals[ptEds[j]]);
forAll(ptEdNorms, k)
{
if (findIndex(tmpFtPtNorms, ptEdNorms[k]) == -1)
{
bool addNormal = true;
// Check that the normal direction is unique at this feature
forAll(tmpFtPtNorms, q)
{
if
(
(normals_[ptEdNorms[k]] & normals_[tmpFtPtNorms[q]])
> cosNormalAngleTol_
)
{
// Parallel to an existing normal, do not add
addNormal = false;
break;
}
}
if (addNormal)
{
tmpFtPtNorms.append(ptEdNorms[k]);
}
}
}
}
featurePointNormals[i] = tmpFtPtNorms;
}
featurePointNormals_ = featurePointNormals;
featurePointEdges_ = featurePointFeatureEdges;
}
// ************************************************************************* //

View File

@ -0,0 +1,272 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "extendedFeatureEdgeMesh.H"
#include "Time.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(extendedFeatureEdgeMesh, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::extendedFeatureEdgeMesh::extendedFeatureEdgeMesh(const IOobject& io)
:
regIOobject(io),
extendedEdgeMesh()
{
if
(
io.readOpt() == IOobject::MUST_READ
|| io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
// Warn for MUST_READ_IF_MODIFIED
warnNoRereading<extendedFeatureEdgeMesh>();
readStream(typeName) >> *this;
close();
{
// Calculate edgeDirections
const edgeList& eds(edges());
const pointField& pts(points());
edgeDirections_.setSize(eds.size());
forAll(eds, eI)
{
edgeDirections_[eI] = eds[eI].vec(pts);
}
edgeDirections_ /= (mag(edgeDirections_) + SMALL);
}
}
if (debug)
{
Pout<< "extendedFeatureEdgeMesh::extendedFeatureEdgeMesh :"
<< " constructed from IOobject :"
<< " points:" << points().size()
<< " edges:" << edges().size()
<< endl;
}
}
Foam::extendedFeatureEdgeMesh::extendedFeatureEdgeMesh
(
const IOobject& io,
const extendedEdgeMesh& em
)
:
regIOobject(io),
extendedEdgeMesh(em)
{}
Foam::extendedFeatureEdgeMesh::extendedFeatureEdgeMesh
(
const surfaceFeatures& sFeat,
const objectRegistry& obr,
const fileName& sFeatFileName,
const boolList& surfBaffleRegions
)
:
regIOobject
(
IOobject
(
sFeatFileName,
obr.time().constant(),
"extendedFeatureEdgeMesh",
obr,
IOobject::NO_READ,
IOobject::NO_WRITE
)
),
extendedEdgeMesh(sFeat, surfBaffleRegions)
{}
Foam::extendedFeatureEdgeMesh::extendedFeatureEdgeMesh
(
const IOobject& io,
const PrimitivePatch<face, List, pointField, point>& surf,
const labelList& featureEdges,
const labelList& regionFeatureEdges,
const labelList& featurePoints
)
:
regIOobject(io),
extendedEdgeMesh(surf, featureEdges, regionFeatureEdges, featurePoints)
{}
Foam::extendedFeatureEdgeMesh::extendedFeatureEdgeMesh
(
const IOobject& io,
const pointField& pts,
const edgeList& eds,
label concaveStart,
label mixedStart,
label nonFeatureStart,
label internalStart,
label flatStart,
label openStart,
label multipleStart,
const vectorField& normals,
const List<sideVolumeType>& normalVolumeTypes,
const vectorField& edgeDirections,
const labelListList& normalDirections,
const labelListList& edgeNormals,
const labelListList& featurePointNormals,
const labelListList& featurePointEdges,
const labelList& regionEdges
)
:
regIOobject(io),
extendedEdgeMesh
(
pts,
eds,
concaveStart,
mixedStart,
nonFeatureStart,
internalStart,
flatStart,
openStart,
multipleStart,
normals,
normalVolumeTypes,
edgeDirections,
normalDirections,
edgeNormals,
featurePointNormals,
featurePointEdges,
regionEdges
)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::extendedFeatureEdgeMesh::~extendedFeatureEdgeMesh()
{}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
bool Foam::extendedFeatureEdgeMesh::readData(Istream& is)
{
is >> *this;
return !is.bad();
}
bool Foam::extendedFeatureEdgeMesh::writeData(Ostream& os) const
{
os << *this;
return os.good();
}
//bool Foam::extendedFeatureEdgeMesh::writeData(Ostream& os) const
//{
// os << "// points" << nl
// << points() << nl
// << "// edges" << nl
// << edges() << nl
// << "// concaveStart mixedStart nonFeatureStart" << nl
// << concaveStart_ << token::SPACE
// << mixedStart_ << token::SPACE
// << nonFeatureStart_ << nl
// << "// internalStart flatStart openStart multipleStart" << nl
// << internalStart_ << token::SPACE
// << flatStart_ << token::SPACE
// << openStart_ << token::SPACE
// << multipleStart_ << nl
// << "// normals" << nl
// << normals_ << nl
// << "// normal volume types" << nl
// << normalVolumeTypes_ << nl
// << "// normalDirections" << nl
// << normalDirections_ << nl
// << "// edgeNormals" << nl
// << edgeNormals_ << nl
// << "// featurePointNormals" << nl
// << featurePointNormals_ << nl
// << "// featurePointEdges" << nl
// << featurePointEdges_ << nl
// << "// regionEdges" << nl
// << regionEdges_
// << endl;
//
// return os.good();
//}
//
//Foam::Istream& Foam::operator>>
//(
// Istream& is,
// Foam::extendedFeatureEdgeMesh::sideVolumeType& vt
//)
//{
// label type;
// is >> type;
//
// vt = static_cast<Foam::extendedFeatureEdgeMesh::sideVolumeType>(type);
//
// // Check state of Istream
// is.check("operator>>(Istream&, sideVolumeType&)");
//
// return is;
//}
//
//
//Foam::Ostream& Foam::operator<<
//(
// Ostream& os,
// const Foam::extendedFeatureEdgeMesh::sideVolumeType& vt
//)
//{
// os << static_cast<label>(vt);
//
// return os;
//}
//
// ************************************************************************* //

View File

@ -0,0 +1,170 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2014 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/>.
Class
Foam::extendedFeatureEdgeMesh
Description
extendedEdgeMesh + IO.
SourceFiles
extendedFeatureEdgeMesh.C
\*---------------------------------------------------------------------------*/
#ifndef extendedFeatureEdgeMesh_H
#define extendedFeatureEdgeMesh_H
#include "extendedEdgeMesh.H"
#include "regIOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
class objectRegistry;
/*---------------------------------------------------------------------------*\
Class extendedFeatureEdgeMesh Declaration
\*---------------------------------------------------------------------------*/
class extendedFeatureEdgeMesh
:
public regIOobject,
public extendedEdgeMesh
{
public:
//- Runtime type information
TypeName("extendedFeatureEdgeMesh");
// Constructors
//- Construct (read) given an IOobject
extendedFeatureEdgeMesh(const IOobject&);
//- Construct as copy
extendedFeatureEdgeMesh
(
const IOobject&,
const extendedEdgeMesh&
);
//- Construct given a surface with selected edges,point
// (surfaceFeatures), an objectRegistry and a
// fileName to write to.
// Extracts, classifies and reorders the data from surfaceFeatures.
extendedFeatureEdgeMesh
(
const surfaceFeatures& sFeat,
const objectRegistry& obr,
const fileName& sFeatFileName,
const boolList& surfBaffleRegions
);
//- Construct from PrimitivePatch
extendedFeatureEdgeMesh
(
const IOobject&,
const PrimitivePatch<face, List, pointField, point>& surf,
const labelList& featureEdges,
const labelList& regionFeatureEdges,
const labelList& featurePoints
);
//- Construct from all components
extendedFeatureEdgeMesh
(
const IOobject& io,
const pointField& pts,
const edgeList& eds,
label concaveStart,
label mixedStart,
label nonFeatureStart,
label internalStart,
label flatStart,
label openStart,
label multipleStart,
const vectorField& normals,
const List<sideVolumeType>& normalVolumeTypes,
const vectorField& edgeDirections,
const labelListList& normalDirections,
const labelListList& edgeNormals,
const labelListList& featurePointNormals,
const labelListList& featurePointEdges,
const labelList& regionEdges
);
//- Destructor
virtual ~extendedFeatureEdgeMesh();
// IO
//- Give precedence to the regIOobject write
using regIOobject::write;
//- ReadData function required for regIOobject read operation
virtual bool readData(Istream&);
//- WriteData function required for regIOobject write operation
virtual bool writeData(Ostream&) const;
//- Is object global
virtual bool global() const
{
return true;
}
//- Return complete path + object name if the file exists
// either in the case/processor or case otherwise null
virtual fileName filePath() const
{
return globalFilePath();
}
};
//- Template function for obtaining global status
template<>
inline bool typeGlobal<extendedFeatureEdgeMesh>()
{
return true;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,290 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline Foam::label Foam::extendedFeatureEdgeMesh::convexStart() const
{
return convexStart_;
}
inline Foam::label Foam::extendedFeatureEdgeMesh::concaveStart() const
{
return concaveStart_;
}
inline Foam::label Foam::extendedFeatureEdgeMesh::mixedStart() const
{
return mixedStart_;
}
inline Foam::label Foam::extendedFeatureEdgeMesh::nonFeatureStart() const
{
return nonFeatureStart_;
}
inline Foam::label Foam::extendedFeatureEdgeMesh::externalStart() const
{
return externalStart_;
}
inline Foam::label Foam::extendedFeatureEdgeMesh::internalStart() const
{
return internalStart_;
}
inline Foam::label Foam::extendedFeatureEdgeMesh::flatStart() const
{
return flatStart_;
}
inline Foam::label Foam::extendedFeatureEdgeMesh::openStart() const
{
return openStart_;
}
inline Foam::label Foam::extendedFeatureEdgeMesh::multipleStart() const
{
return multipleStart_;
}
inline bool Foam::extendedFeatureEdgeMesh::featurePoint(label ptI) const
{
return ptI < nonFeatureStart_;
}
inline const Foam::vectorField& Foam::extendedFeatureEdgeMesh::normals() const
{
return normals_;
}
inline const Foam::List<Foam::extendedFeatureEdgeMesh::sideVolumeType>&
Foam::extendedFeatureEdgeMesh::normalVolumeTypes() const
{
return normalVolumeTypes_;
}
inline const Foam::vectorField& Foam::extendedFeatureEdgeMesh::edgeDirections()
const
{
return edgeDirections_;
}
inline const Foam::labelListList&
Foam::extendedFeatureEdgeMesh::normalDirections() const
{
return normalDirections_;
}
inline Foam::vector Foam::extendedFeatureEdgeMesh::edgeDirection
(
label edgeI,
label ptI
) const
{
const edge& e = edges()[edgeI];
if (ptI == e.start())
{
return edgeDirections()[edgeI];
}
else if (ptI == e.end())
{
return -edgeDirections()[edgeI];
}
else
{
FatalErrorInFunction
<< "Requested ptI " << ptI << " is not a point on the requested "
<< "edgeI " << edgeI << ". edgeI start and end: "
<< e.start() << " " << e.end()
<< exit(FatalError);
return Zero;
}
}
inline const Foam::labelListList& Foam::extendedFeatureEdgeMesh::edgeNormals()
const
{
return edgeNormals_;
}
inline Foam::vectorField Foam::extendedFeatureEdgeMesh::edgeNormals
(
const labelList& edgeNormIs
) const
{
vectorField norms(edgeNormIs.size());
forAll(edgeNormIs, i)
{
norms[i] = normals_[edgeNormIs[i]];
}
return norms;
}
inline Foam::vectorField Foam::extendedFeatureEdgeMesh::edgeNormals(label edgeI)
const
{
return edgeNormals(edgeNormals_[edgeI]);
}
inline const Foam::labelListList&
Foam::extendedFeatureEdgeMesh::featurePointNormals() const
{
return featurePointNormals_;
}
inline Foam::vectorField Foam::extendedFeatureEdgeMesh::featurePointNormals
(
label ptI
) const
{
if (!featurePoint(ptI))
{
WarningInFunction
<< "Requesting the normals of a non-feature point. "
<< "Returned zero length vectorField."
<< endl;
return vectorField(0);
}
labelList featPtNormIs(featurePointNormals_[ptI]);
vectorField norms(featPtNormIs.size());
forAll(featPtNormIs, i)
{
norms[i] = normals_[featPtNormIs[i]];
}
return norms;
}
inline const Foam::labelListList&
Foam::extendedFeatureEdgeMesh::featurePointEdges() const
{
return featurePointEdges_;
}
inline const Foam::labelList& Foam::extendedFeatureEdgeMesh::regionEdges() const
{
return regionEdges_;
}
inline Foam::extendedFeatureEdgeMesh::pointStatus
Foam::extendedFeatureEdgeMesh::getPointStatus(label ptI) const
{
if (ptI < concaveStart_)
{
return CONVEX;
}
else if (ptI < mixedStart_)
{
return CONCAVE;
}
else if (ptI < nonFeatureStart_)
{
return MIXED;
}
else
{
return NONFEATURE;
}
}
inline Foam::extendedFeatureEdgeMesh::edgeStatus
Foam::extendedFeatureEdgeMesh::getEdgeStatus(label edgeI) const
{
if (edgeI < internalStart_)
{
return EXTERNAL;
}
else if (edgeI < flatStart_)
{
return INTERNAL;
}
else if (edgeI < openStart_)
{
return FLAT;
}
else if (edgeI < multipleStart_)
{
return OPEN;
}
else
{
return MULTIPLE;
}
}
inline Foam::PackedList<2> Foam::extendedFeatureEdgeMesh::edgeBaffles
(
label edgeI
) const
{
const labelList& eNormals = edgeNormals_[edgeI];
DynamicList<label> edgeBaffles(eNormals.size());
forAll(eNormals, enI)
{
const label normI = eNormals[enI];
if (normalVolumeTypes_[normI])
{
edgeBaffles.append(normI);
}
}
return PackedList<2>(edgeBaffles);
}
// ************************************************************************* //

View File

@ -0,0 +1,418 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "extendedFeatureEdgeMesh.H"
#include "ListListOps.H"
#include "unitConversion.H"
#include "PackedBoolList.H"
#include "PatchTools.H"
#include "searchableBox.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Patch>
void Foam::extendedFeatureEdgeMesh::sortPointsAndEdges
(
const Patch& surf,
const labelList& featureEdges,
const labelList& regionFeatureEdges,// subset of featureEdges: inter-region
const labelList& featurePoints
)
{
const pointField& sFeatLocalPts(surf.localPoints());
const edgeList& sFeatEds(surf.edges());
const labelListList edgeFaces = PatchTools::sortedEdgeFaces(surf);
const vectorField& faceNormals = surf.faceNormals();
const labelListList pointEdges = PatchTools::sortedPointEdges(surf);
// Extract and reorder the data from surfaceFeatures
// References to the surfaceFeatures data
// Filling the extendedFeatureEdgeMesh with the raw geometrical data.
label nFeatEds = featureEdges.size();
label nFeatPts = featurePoints.size();
DynamicList<point> tmpPts;
edgeList eds(nFeatEds);
DynamicList<vector> norms;
vectorField edgeDirections(nFeatEds);
labelListList edgeNormals(nFeatEds);
labelListList normalDirections(nFeatEds);
DynamicList<label> regionEdges;
// Keep track of the ordered feature point feature edges
labelListList featurePointFeatureEdges(nFeatPts);
forAll(featurePointFeatureEdges, pI)
{
featurePointFeatureEdges[pI] = pointEdges[featurePoints[pI]];
}
// Mapping between old and new indices, there is entry in the map for each
// of surf.localPoints, -1 means that this point hasn't been used (yet),
// >= 0 corresponds to the index
labelList pointMap(sFeatLocalPts.size(), -1);
// Mapping between surface edge index and its feature edge index. -1 if it
// is not a feature edge
labelList edgeMap(sFeatEds.size(), -1);
// Noting when the normal of a face has been used so not to duplicate
labelList faceMap(surf.size(), -1);
// Collecting the status of edge for subsequent sorting
List<edgeStatus> edStatus(nFeatEds, NONE);
forAll(featurePoints, i)
{
label sFPI = featurePoints[i];
tmpPts.append(sFeatLocalPts[sFPI]);
pointMap[sFPI] = tmpPts.size() - 1;
}
// All feature points have been added
nonFeatureStart_ = tmpPts.size();
PackedBoolList isRegionFeatureEdge(regionFeatureEdges);
forAll(featureEdges, i)
{
label sFEI = featureEdges[i];
edgeMap[sFEI] = i;
const edge& fE = sFeatEds[sFEI];
edgeDirections[i] = fE.vec(sFeatLocalPts);
// Check to see if the points have been already used
if (pointMap[fE.start()] == -1)
{
tmpPts.append(sFeatLocalPts[fE.start()]);
pointMap[fE.start()] = tmpPts.size() - 1;
}
eds[i].start() = pointMap[fE.start()];
if (pointMap[fE.end()] == -1)
{
tmpPts.append(sFeatLocalPts[fE.end()]);
pointMap[fE.end()] = tmpPts.size() - 1;
}
eds[i].end() = pointMap[fE.end()];
// Pick up the faces adjacent to the feature edge
const labelList& eFaces = edgeFaces[sFEI];
edgeNormals[i].setSize(eFaces.size());
normalDirections[i].setSize(eFaces.size());
forAll(eFaces, j)
{
label eFI = eFaces[j];
// Check to see if the points have been already used
if (faceMap[eFI] == -1)
{
norms.append(faceNormals[eFI]);
faceMap[eFI] = norms.size() - 1;
}
edgeNormals[i][j] = faceMap[eFI];
const vector cross = (faceNormals[eFI] ^ edgeDirections[i]);
const vector fC0tofE0 =
surf[eFI].centre(surf.points())
- sFeatLocalPts[fE.start()];
normalDirections[i][j] =
(
(
(cross/(mag(cross) + VSMALL))
& (fC0tofE0/(mag(fC0tofE0)+ VSMALL))
)
> 0.0
? 1
: -1
);
}
vector fC0tofC1(Zero);
if (eFaces.size() == 2)
{
fC0tofC1 =
surf[eFaces[1]].centre(surf.points())
- surf[eFaces[0]].centre(surf.points());
}
edStatus[i] = classifyEdge(norms, edgeNormals[i], fC0tofC1);
if (isRegionFeatureEdge[i])
{
regionEdges.append(i);
}
}
// Populate feature point feature edges
DynamicList<label> newFeatureEdges;
forAll(featurePointFeatureEdges, pI)
{
const labelList& fpfe = featurePointFeatureEdges[pI];
newFeatureEdges.setCapacity(fpfe.size());
forAll(fpfe, eI)
{
const label oldEdgeIndex = fpfe[eI];
const label newFeatureEdgeIndex = edgeMap[oldEdgeIndex];
if (newFeatureEdgeIndex != -1)
{
newFeatureEdges.append(newFeatureEdgeIndex);
}
}
featurePointFeatureEdges[pI].transfer(newFeatureEdges);
}
// Reorder the edges by classification
List<DynamicList<label>> allEds(nEdgeTypes);
DynamicList<label>& externalEds(allEds[0]);
DynamicList<label>& internalEds(allEds[1]);
DynamicList<label>& flatEds(allEds[2]);
DynamicList<label>& openEds(allEds[3]);
DynamicList<label>& multipleEds(allEds[4]);
forAll(eds, i)
{
edgeStatus eStat = edStatus[i];
if (eStat == EXTERNAL)
{
externalEds.append(i);
}
else if (eStat == INTERNAL)
{
internalEds.append(i);
}
else if (eStat == FLAT)
{
flatEds.append(i);
}
else if (eStat == OPEN)
{
openEds.append(i);
}
else if (eStat == MULTIPLE)
{
multipleEds.append(i);
}
else if (eStat == NONE)
{
FatalErrorInFunction
<< nl << "classifyEdge returned NONE on edge "
<< eds[i]
<< ". There is a problem with definition of this edge."
<< nl << abort(FatalError);
}
}
internalStart_ = externalEds.size();
flatStart_ = internalStart_ + internalEds.size();
openStart_ = flatStart_ + flatEds.size();
multipleStart_ = openStart_ + openEds.size();
labelList edMap
(
ListListOps::combine<labelList>
(
allEds,
accessOp<labelList>()
)
);
edMap = invert(edMap.size(), edMap);
inplaceReorder(edMap, eds);
inplaceReorder(edMap, edStatus);
inplaceReorder(edMap, edgeDirections);
inplaceReorder(edMap, edgeNormals);
inplaceReorder(edMap, normalDirections);
inplaceRenumber(edMap, regionEdges);
forAll(featurePointFeatureEdges, pI)
{
inplaceRenumber(edMap, featurePointFeatureEdges[pI]);
}
pointField pts(tmpPts);
// Initialise the edgeMesh
edgeMesh::operator=(edgeMesh(pts, eds));
// Initialise sorted edge related data
edgeDirections_ = edgeDirections/(mag(edgeDirections) + VSMALL);
edgeNormals_ = edgeNormals;
normalDirections_ = normalDirections;
regionEdges_ = regionEdges;
// Normals are all now found and indirectly addressed, can also be stored
normals_ = vectorField(norms);
// Reorder the feature points by classification
List<DynamicList<label>> allPts(3);
DynamicList<label>& convexPts(allPts[0]);
DynamicList<label>& concavePts(allPts[1]);
DynamicList<label>& mixedPts(allPts[2]);
for (label i = 0; i < nonFeatureStart_; i++)
{
pointStatus ptStatus = classifyFeaturePoint(i);
if (ptStatus == CONVEX)
{
convexPts.append(i);
}
else if (ptStatus == CONCAVE)
{
concavePts.append(i);
}
else if (ptStatus == MIXED)
{
mixedPts.append(i);
}
else if (ptStatus == NONFEATURE)
{
FatalErrorInFunction
<< nl << "classifyFeaturePoint returned NONFEATURE on point at "
<< points()[i]
<< ". There is a problem with definition of this feature point."
<< nl << abort(FatalError);
}
}
concaveStart_ = convexPts.size();
mixedStart_ = concaveStart_ + concavePts.size();
labelList ftPtMap
(
ListListOps::combine<labelList>
(
allPts,
accessOp<labelList>()
)
);
ftPtMap = invert(ftPtMap.size(), ftPtMap);
// Creating the ptMap from the ftPtMap with identity values up to the size
// of pts to create an oldToNew map for inplaceReorder
labelList ptMap(identity(pts.size()));
forAll(ftPtMap, i)
{
ptMap[i] = ftPtMap[i];
}
inplaceReorder(ptMap, pts);
inplaceReorder(ptMap, featurePointFeatureEdges);
forAll(eds, i)
{
inplaceRenumber(ptMap, eds[i]);
}
// Reinitialise the edgeMesh with sorted feature points and
// renumbered edges
reset(xferMove(pts), xferMove(eds));
// Generate the featurePointNormals
labelListList featurePointNormals(nonFeatureStart_);
for (label i = 0; i < nonFeatureStart_; i++)
{
DynamicList<label> tmpFtPtNorms;
const labelList& ptEds = edgeMesh::pointEdges()[i];
forAll(ptEds, j)
{
const labelList& ptEdNorms(edgeNormals[ptEds[j]]);
forAll(ptEdNorms, k)
{
if (findIndex(tmpFtPtNorms, ptEdNorms[k]) == -1)
{
bool addNormal = true;
// Check that the normal direction is unique at this feature
forAll(tmpFtPtNorms, q)
{
if
(
(normals_[ptEdNorms[k]] & normals_[tmpFtPtNorms[q]])
> cosNormalAngleTol_
)
{
// Parallel to an existing normal, do not add
addNormal = false;
break;
}
}
if (addNormal)
{
tmpFtPtNorms.append(ptEdNorms[k]);
}
}
}
}
featurePointNormals[i] = tmpFtPtNorms;
}
featurePointNormals_ = featurePointNormals;
featurePointEdges_ = featurePointFeatureEdges;
}
// ************************************************************************* //

View File

@ -0,0 +1,106 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "featureEdgeMesh.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(featureEdgeMesh, 0);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::featureEdgeMesh::featureEdgeMesh(const IOobject& io)
:
regIOobject(io),
edgeMesh(pointField(0), edgeList(0))
{
if
(
io.readOpt() == IOobject::MUST_READ
|| io.readOpt() == IOobject::MUST_READ_IF_MODIFIED
|| (io.readOpt() == IOobject::READ_IF_PRESENT && headerOk())
)
{
readStream(typeName) >> *this;
close();
}
if (debug)
{
Pout<< "featureEdgeMesh::featureEdgeMesh :"
<< " constructed from IOobject :"
<< " points:" << points().size()
<< " edges:" << edges().size()
<< endl;
}
}
Foam::featureEdgeMesh::featureEdgeMesh
(
const IOobject& io,
const pointField& points,
const edgeList& edges
)
:
regIOobject(io),
edgeMesh(points, edges)
{}
// Construct as copy
Foam::featureEdgeMesh::featureEdgeMesh
(
const IOobject& io,
const featureEdgeMesh& em
)
:
regIOobject(io),
edgeMesh(em)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::featureEdgeMesh::readData(Istream& is)
{
is >> *this;
return !is.bad();
}
bool Foam::featureEdgeMesh::writeData(Ostream& os) const
{
os << *this;
return os.good();
}
// ************************************************************************* //

View File

@ -0,0 +1,120 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2017 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/>.
Class
Foam::featureEdgeMesh
Description
edgeMesh + IO.
See also
Foam::extendedFeatureEdgeMesh
SourceFiles
featureEdgeMesh.C
\*---------------------------------------------------------------------------*/
#ifndef featureEdgeMesh_H
#define featureEdgeMesh_H
#include "edgeMesh.H"
#include "regIOobject.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class featureEdgeMesh Declaration
\*---------------------------------------------------------------------------*/
class featureEdgeMesh
:
public regIOobject,
public edgeMesh
{
public:
TypeName("featureEdgeMesh");
// Constructors
//- Construct (read) given an IOobject
featureEdgeMesh(const IOobject&);
//- Construct from featureEdgeMesh data
featureEdgeMesh
(
const IOobject&,
const pointField&,
const edgeList&
);
//- Construct as copy
featureEdgeMesh(const IOobject&, const featureEdgeMesh&);
// IO
//- ReadData function required for regIOobject read operation
virtual bool readData(Istream&);
//- WriteData function required for regIOobject write operation
virtual bool writeData(Ostream&) const;
//- Is object global
virtual bool global() const
{
return true;
}
//- Return complete path + object name if the file exists
// either in the case/processor or case otherwise null
virtual fileName filePath() const
{
return globalFilePath();
}
};
//- Template function for obtaining global status
template<>
inline bool typeGlobal<featureEdgeMesh>()
{
return true;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -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

View File

@ -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 | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2014-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2014-2016 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2014-2017 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License

View File

@ -0,0 +1,437 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 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/>.
\*---------------------------------------------------------------------------*/
#include "searchableExtrudedCircle.H"
#include "addToRunTimeSelectionTable.H"
#include "Time.H"
#include "edgeMesh.H"
#include "indexedOctree.H"
#include "treeDataEdge.H"
#include "linearInterpolationWeights.H"
#include "quaternion.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
defineTypeNameAndDebug(searchableExtrudedCircle, 0);
addToRunTimeSelectionTable
(
searchableSurface,
searchableExtrudedCircle,
dict
);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::searchableExtrudedCircle::searchableExtrudedCircle
(
const IOobject& io,
const dictionary& dict
)
:
searchableSurface(io),
eMeshPtr_
(
edgeMesh::New
(
IOobject
(
dict.lookup("file"), // name
io.time().constant(), // instance
"geometry", // local
io.time(), // registry
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
).objectPath()
)
),
radius_(readScalar(dict.lookup("radius")))
{
const edgeMesh& eMesh = eMeshPtr_();
const pointField& points = eMesh.points();
const edgeList& edges = eMesh.edges();
bounds() = boundBox(points, false);
vector halfSpan(0.5*bounds().span());
point ctr(bounds().midpoint());
bounds().min() = ctr - mag(halfSpan)*vector(1, 1, 1);
bounds().max() = ctr + mag(halfSpan)*vector(1, 1, 1);
// Calculate bb of all points
treeBoundBox bb(bounds());
// Slightly extended bb. Slightly off-centred just so on symmetric
// geometry there are less face/edge aligned items.
bb.min() -= point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
bb.max() += point(ROOTVSMALL, ROOTVSMALL, ROOTVSMALL);
edgeTree_.reset
(
new indexedOctree<treeDataEdge>
(
treeDataEdge
(
false, // do not cache bb
edges,
points,
identity(edges.size())
),
bb, // overall search domain
8, // maxLevel
10, // leafsize
3.0 // duplicity
)
);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::searchableExtrudedCircle::~searchableExtrudedCircle()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
const Foam::wordList& Foam::searchableExtrudedCircle::regions() const
{
if (regions_.empty())
{
regions_.setSize(1);
regions_[0] = "region0";
}
return regions_;
}
Foam::label Foam::searchableExtrudedCircle::size() const
{
return eMeshPtr_().points().size();
}
Foam::tmp<Foam::pointField> Foam::searchableExtrudedCircle::coordinates() const
{
return eMeshPtr_().points();
}
void Foam::searchableExtrudedCircle::boundingSpheres
(
pointField& centres,
scalarField& radiusSqr
) const
{
centres = eMeshPtr_().points();
radiusSqr.setSize(centres.size());
radiusSqr = Foam::sqr(radius_);
// Add a bit to make sure all points are tested inside
radiusSqr += Foam::sqr(SMALL);
}
void Foam::searchableExtrudedCircle::findNearest
(
const pointField& samples,
const scalarField& nearestDistSqr,
List<pointIndexHit>& info
) const
{
const indexedOctree<treeDataEdge>& tree = edgeTree_();
info.setSize(samples.size());
forAll(samples, i)
{
info[i] = tree.findNearest(samples[i], nearestDistSqr[i]);
if (info[i].hit())
{
vector d(samples[i]-info[i].hitPoint());
info[i].setPoint(info[i].hitPoint() + d/mag(d)*radius_);
}
}
}
void Foam::searchableExtrudedCircle::findParametricNearest
(
const point& start,
const point& end,
const scalarField& rawLambdas,
const scalarField& nearestDistSqr,
List<pointIndexHit>& info
) const
{
const edgeMesh& mesh = eMeshPtr_();
const indexedOctree<treeDataEdge>& tree = edgeTree_();
const edgeList& edges = mesh.edges();
const pointField& points = mesh.points();
const labelListList& pointEdges = mesh.pointEdges();
const scalar maxDistSqr(Foam::magSqr(bounds().span()));
// Normalise lambdas
const scalarField lambdas
(
(rawLambdas-rawLambdas[0])
/(rawLambdas.last()-rawLambdas[0])
);
// Nearest point on curve and local axis direction
pointField curvePoints(lambdas.size());
vectorField axialVecs(lambdas.size());
const pointIndexHit startInfo = tree.findNearest(start, maxDistSqr);
curvePoints[0] = startInfo.hitPoint();
axialVecs[0] = edges[startInfo.index()].vec(points);
const pointIndexHit endInfo = tree.findNearest(end, maxDistSqr);
curvePoints.last() = endInfo.hitPoint();
axialVecs.last() = edges[endInfo.index()].vec(points);
scalarField curveLambdas(points.size(), -1.0);
{
scalar endDistance = -1.0;
// Determine edge lengths walking from start to end.
const point& start = curvePoints[0];
const point& end = curvePoints.last();
label edgei = startInfo.index();
const edge& startE = edges[edgei];
label pointi = startE[0];
if ((startE.vec(points)&(end-start)) > 0)
{
pointi = startE[1];
}
curveLambdas[pointi] = mag(points[pointi]-curvePoints[0]);
label otherPointi = startE.otherVertex(pointi);
curveLambdas[otherPointi] = -mag(points[otherPointi]-curvePoints[0]);
//Pout<< "for point:" << points[pointi] << " have distance "
// << curveLambdas[pointi] << endl;
while (true)
{
const labelList& pEdges = pointEdges[pointi];
if (pEdges.size() == 1)
{
break;
}
else if (pEdges.size() != 2)
{
FatalErrorInFunction << "Curve " << name()
<< " is not a single path. This is not supported"
<< exit(FatalError);
break;
}
label oldEdgei = edgei;
if (pEdges[0] == oldEdgei)
{
edgei = pEdges[1];
}
else
{
edgei = pEdges[0];
}
if (edgei == endInfo.index())
{
endDistance = curveLambdas[pointi] + mag(end-points[pointi]);
//Pout<< "Found end edge:" << edges[edgei].centre(points)
// << " endPt:" << end
// << " point before:" << points[pointi]
// << " accumulated length:" << endDistance << endl;
}
label oldPointi = pointi;
pointi = edges[edgei].otherVertex(oldPointi);
if (curveLambdas[pointi] >= 0)
{
break;
}
curveLambdas[pointi] =
curveLambdas[oldPointi] + edges[edgei].mag(points);
}
// Normalise curveLambdas
forAll(curveLambdas, i)
{
if (curveLambdas[i] >= 0)
{
curveLambdas[i] /= endDistance;
}
}
}
// Interpolation engine
linearInterpolationWeights interpolator(curveLambdas);
// Find wanted location along curve
labelList indices;
scalarField weights;
for (label i = 1; i < curvePoints.size()-1; i++)
{
interpolator.valueWeights(lambdas[i], indices, weights);
if (indices.size() == 1)
{
// On outside of curve. Choose one of the connected edges.
label pointi = indices[0];
const point& p0 = points[pointi];
label edge0 = pointEdges[pointi][0];
const edge& e0 = edges[edge0];
axialVecs[i] = e0.vec(points);
curvePoints[i] = weights[0]*p0;
}
else if (indices.size() == 2)
{
const point& p0 = points[indices[0]];
const point& p1 = points[indices[1]];
axialVecs[i] = p1-p0;
curvePoints[i] = weights[0]*p0+weights[1]*p1;
}
}
axialVecs /= mag(axialVecs);
// Now we have the lambdas, curvePoints and axialVecs.
info.setSize(lambdas.size());
info = pointIndexHit();
// Given the current lambdas interpolate radial direction inbetween
// endpoints (all projected onto the starting coordinate system)
quaternion qStart;
vector radialStart;
{
radialStart = start-curvePoints[0];
radialStart -= (radialStart&axialVecs[0])*axialVecs[0];
radialStart /= mag(radialStart);
qStart = quaternion(radialStart, 0.0);
info[0] = pointIndexHit(true, start, 0);
}
quaternion qProjectedEnd;
{
vector radialEnd(end-curvePoints.last());
radialEnd -= (radialEnd&axialVecs.last())*axialVecs.last();
radialEnd /= mag(radialEnd);
vector projectedEnd = radialEnd;
projectedEnd -= (projectedEnd&axialVecs[0])*axialVecs[0];
projectedEnd /= mag(projectedEnd);
qProjectedEnd = quaternion(projectedEnd, 0.0);
info.last() = pointIndexHit(true, end, 0);
}
for (label i = 1; i < lambdas.size()-1; i++)
{
quaternion q(slerp(qStart, qProjectedEnd, lambdas[i]));
vector radialDir(q.transform(radialStart));
radialDir -= (radialDir&axialVecs[i])*axialVecs.last();
radialDir /= mag(radialDir);
info[i] = pointIndexHit(true, curvePoints[i]+radius_*radialDir, 0);
}
}
void Foam::searchableExtrudedCircle::getRegion
(
const List<pointIndexHit>& info,
labelList& region
) const
{
region.setSize(info.size());
region = 0;
}
void Foam::searchableExtrudedCircle::getNormal
(
const List<pointIndexHit>& info,
vectorField& normal
) const
{
const edgeMesh& mesh = eMeshPtr_();
const indexedOctree<treeDataEdge>& tree = edgeTree_();
const edgeList& edges = mesh.edges();
const pointField& points = mesh.points();
normal.setSize(info.size());
normal = Zero;
forAll(info, i)
{
if (info[i].hit())
{
// Find nearest on curve
pointIndexHit curvePt = tree.findNearest
(
info[i].hitPoint(),
Foam::magSqr(bounds().span())
);
normal[i] = info[i].hitPoint()-curvePt.hitPoint();
// Subtract axial direction
vector axialVec = edges[curvePt.index()].vec(points);
axialVec /= mag(axialVec);
normal[i] -= (normal[i]&axialVec)*axialVec;
normal[i] /= mag(normal[i]);
}
}
}
// ************************************************************************* //

View File

@ -0,0 +1,236 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016-2017 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/>.
Class
Foam::searchableExtrudedCircle
Description
Searching on edgemesh with constant radius
SourceFiles
searchableExtrudedCircle.C
\*---------------------------------------------------------------------------*/
#ifndef searchableExtrudedCircle_H
#define searchableExtrudedCircle_H
#include "treeBoundBox.H"
#include "searchableSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class edgeMesh;
class treeDataEdge;
template <class Type> class indexedOctree;
/*---------------------------------------------------------------------------*\
Class searchableExtrudedCircle Declaration
\*---------------------------------------------------------------------------*/
class searchableExtrudedCircle
:
public searchableSurface
{
// Private Member Data
//- Feature
autoPtr<edgeMesh> eMeshPtr_;
//- Search structure
autoPtr<indexedOctree<treeDataEdge>> edgeTree_;
//- Radius
const scalar radius_;
//- Names of regions
mutable wordList regions_;
// Private Member Functions
//- Disallow default bitwise copy construct
searchableExtrudedCircle(const searchableExtrudedCircle&);
//- Disallow default bitwise assignment
void operator=(const searchableExtrudedCircle&);
public:
//- Runtime type information
TypeName("searchableExtrudedCircle");
// Constructors
//- Construct from dictionary (used by searchableSurface)
searchableExtrudedCircle
(
const IOobject& io,
const dictionary& dict
);
//- Destructor
virtual ~searchableExtrudedCircle();
// Member Functions
virtual const wordList& regions() const;
//- Whether supports volume type below
virtual bool hasVolumeType() const
{
return true;
}
//- Range of local indices that can be returned.
virtual label size() const;
//- Get representative set of element coordinates
// Usually the element centres (should be of length size()).
virtual tmp<pointField> coordinates() const;
//- Get bounding spheres (centre and radius squared), one per element.
// Any point on element is guaranteed to be inside.
virtual void boundingSpheres
(
pointField& centres,
scalarField& radiusSqr
) const;
//- Get the points that define the surface.
virtual tmp<pointField> points() const
{
return coordinates();
}
//- Does any part of the surface overlap the supplied bound box?
virtual bool overlaps(const boundBox& bb) const
{
NotImplemented;
return false;
}
// Multiple point queries.
virtual void findNearest
(
const pointField& sample,
const scalarField& nearestDistSqr,
List<pointIndexHit>&
) const;
//- Unique to parametric geometry: given points find
// an interpolated (along the curve) point on the surface.
// The lambdas[0] is equivalent for start, lambdas.last()
// is equivalent for end.
virtual void findParametricNearest
(
const point& start,
const point& end,
const scalarField& lambdas,
const scalarField& nearestDistSqr,
List<pointIndexHit>&
) const;
virtual void findLine
(
const pointField& start,
const pointField& end,
List<pointIndexHit>&
) const
{
NotImplemented;
}
virtual void findLineAny
(
const pointField& start,
const pointField& end,
List<pointIndexHit>&
) const
{
NotImplemented;
}
//- Get all intersections in order from start to end.
virtual void findLineAll
(
const pointField& start,
const pointField& end,
List<List<pointIndexHit>>&
) const
{
NotImplemented;
}
//- From a set of points and indices get the region
virtual void getRegion
(
const List<pointIndexHit>&,
labelList& region
) const;
//- From a set of points and indices get the normal
virtual void getNormal
(
const List<pointIndexHit>&,
vectorField& normal
) const;
//- Determine type (inside/outside/mixed) for point. unknown if
// cannot be determined (e.g. non-manifold surface)
virtual void getVolumeType
(
const pointField&,
List<volumeType>&
) const
{
NotImplemented;
}
bool writeData(Ostream&) const
{
NotImplemented;
return false;
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -61,7 +61,7 @@ class mapDistribute;
class treeBoundBox;
/*---------------------------------------------------------------------------*\
Class searchableSurface Declaration
Class searchableSurface Declaration
\*---------------------------------------------------------------------------*/
class searchableSurface
@ -74,6 +74,7 @@ class searchableSurface
boundBox bounds_;
// Private Member Functions
//- Disallow default bitwise copy construct

View File

@ -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 | Copyright (C) 2016-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License

View File

@ -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 | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License

View File

@ -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

View File

@ -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

View File

@ -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 | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License

View File

@ -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

View File

@ -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 | Copyright (C) 2015-2017 OpenCFD Ltd.
-------------------------------------------------------------------------------
License

View File

@ -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