surfMesh reworked

- treat 'ofs' IO just like any other format
- dropped BasicMeshedSurface, since MeshedSurface can now also have zero or
  more zones
- UnsortedMeshedSurface is a special type of MeshedSurface with zero zones,
  but with additional zoneId labels
- use MeshedSurfaceProxy for writing surfaces with points/faces/zones and
  optional faceMap - provides output interface for MeshedSurface,
  UnsortedMeshedSurface and surfMesh.
- simplify output to filenames only, I can't see that the Ostream
  is needed anywhere
- surfMesh renaming now works, after the objectRegistry fix
This commit is contained in:
Mark Olesen
2009-03-08 00:59:33 +01:00
parent b968e62ef9
commit 6309810e2e
84 changed files with 3800 additions and 3224 deletions

View File

@ -271,13 +271,40 @@ int main(int argc, char *argv[])
args.caseName()
);
// start with "constant"
runTime.setTime(instant(0, runTime.constant()), 0);
Info<< "runTime.instance() = " << runTime.instance() << endl;
Info<< "runTime.timeName() = " << runTime.timeName() << endl;
surfMesh surfIn
(
IOobject
(
"default",
runTime.timeName(),
runTime,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
);
Info<< "surfIn = " << surfIn.nFaces() << endl;
Info<< "runTime.instance() = " << runTime.instance() << endl;
surfMesh surfOut
(
IOobject
(
"mySurf",
runTime.instance(),
runTime
runTime,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
),
surf.xfer()
);
@ -299,6 +326,25 @@ int main(int argc, char *argv[])
dimless
);
Info<<" surf name= " << surfOut.name() <<nl;
Info<< "rename to anotherSurf" << endl;
surfOut.rename("anotherSurf");
Info<<" surf name= " << surfOut.name() <<nl;
// advance time to 1
runTime.setTime(instant(1), 1);
surfOut.setInstance(runTime.timeName());
Info<< "writing surfMesh again well: " << surfOut.objectPath() << endl;
surfOut.write();
// write directly
surfOut.write("someName.ofs");
#if 1
const surfZoneList& zones = surfOut.surfZones();
forAll(zones, zoneI)
{
@ -318,9 +364,10 @@ int main(int argc, char *argv[])
(
IOobject
(
"pointIds",
"zoneIds.",
// "pointIds",
surfOut.instance(),
"pointFields",
// "pointFields",
surfOut,
IOobject::NO_READ,
IOobject::NO_WRITE
@ -337,6 +384,10 @@ int main(int argc, char *argv[])
Info<< "write pointIds (for testing only): "
<< pointIds.objectPath() << endl;
pointIds.write();
Info<<"surfMesh with these names: " << surfOut.names() << endl;
#endif
}
}

View File

@ -62,10 +62,10 @@ class primitiveMesh;
class cuttingPlane
:
public plane,
public BasicMeshedSurface<face>
public MeshedSurface<face>
{
//- Private typedefs for convenience
typedef BasicMeshedSurface<face> MeshStorage;
typedef MeshedSurface<face> MeshStorage;
// Private data

View File

@ -50,11 +50,11 @@ namespace Foam
class sampledPatch
:
public BasicMeshedSurface<face>,
public MeshedSurface<face>,
public sampledSurface
{
//- Private typedefs for convenience
typedef BasicMeshedSurface<face> MeshStorage;
typedef MeshedSurface<face> MeshStorage;
// Private data

View File

@ -1,572 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "BasicMeshedSurface.H"
#include "boundBox.H"
#include "mergePoints.H"
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Face>
inline bool Foam::BasicMeshedSurface<Face>::isTri()
{
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::BasicMeshedSurface<Face>::BasicMeshedSurface()
:
ParentType(List<Face>(), pointField())
{}
template<class Face>
Foam::BasicMeshedSurface<Face>::BasicMeshedSurface
(
const Xfer< pointField >& pointLst,
const Xfer< List<Face> >& faceLst
)
:
ParentType(List<Face>(), pointField())
{
reset(pointLst, faceLst);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Face>
Foam::BasicMeshedSurface<Face>::~BasicMeshedSurface()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face>
void Foam::BasicMeshedSurface<Face>::clear()
{
ParentType::clearOut();
storedPoints().clear();
storedFaces().clear();
}
template<class Face>
void Foam::BasicMeshedSurface<Face>::movePoints(const pointField& newPoints)
{
// Remove all geometry dependent data
ParentType::clearTopology();
// Adapt for new point position
ParentType::movePoints(newPoints);
// Copy new points
storedPoints() = newPoints;
}
template<class Face>
void Foam::BasicMeshedSurface<Face>::scalePoints(const scalar& scaleFactor)
{
// avoid bad scaling
if (scaleFactor > 0 && scaleFactor != 1.0)
{
// Remove all geometry dependent data
ParentType::clearTopology();
// Adapt for new point position
ParentType::movePoints(pointField());
storedPoints() *= scaleFactor;
}
}
template<class Face>
void Foam::BasicMeshedSurface<Face>::reset
(
const Xfer< pointField >& pointLst,
const Xfer< List<Face> >& faceLst
)
{
ParentType::clearOut();
// Take over new primitive data.
// Optimized to avoid overwriting data at all
if (&pointLst)
{
storedPoints().transfer(pointLst());
}
if (&faceLst)
{
storedFaces().transfer(faceLst());
}
}
template<class Face>
void Foam::BasicMeshedSurface<Face>::reset
(
const Xfer< List<point> >& pointLst,
const Xfer< List<Face> >& faceLst
)
{
ParentType::clearOut();
// Take over new primitive data.
// Optimized to avoid overwriting data at all
if (&pointLst)
{
storedPoints().transfer(pointLst());
}
if (&faceLst)
{
storedFaces().transfer(faceLst());
}
}
// Remove badly degenerate faces, double faces.
template<class Face>
void Foam::BasicMeshedSurface<Face>::cleanup(const bool verbose)
{
// merge points (already done for STL, TRI)
stitchFaces(SMALL, verbose);
checkFaces(verbose);
this->checkTopology(verbose);
}
template<class Face>
bool Foam::BasicMeshedSurface<Face>::stitchFaces
(
const scalar tol,
const bool verbose
)
{
pointField& pointLst = this->storedPoints();
// Merge points
labelList pointMap(pointLst.size());
pointField newPoints(pointLst.size());
bool hasMerged = mergePoints(pointLst, tol, verbose, pointMap, newPoints);
if (!hasMerged)
{
return false;
}
if (verbose)
{
Info<< "BasicMeshedSurface::stitchFaces : Renumbering all faces"
<< endl;
}
// Set the coordinates to the merged ones
pointLst.transfer(newPoints);
List<Face>& faceLst = this->storedFaces();
List<label> faceMap(faceLst.size());
// Reset the point labels to the unique points array
label newFaceI = 0;
forAll(faceLst, faceI)
{
Face& f = faceLst[faceI];
forAll(f, fp)
{
f[fp] = pointMap[f[fp]];
}
// for extra safety: collapse face as well
if (f.collapse() >= 3)
{
if (newFaceI != faceI)
{
faceLst[newFaceI] = f;
}
faceMap[newFaceI] = faceI;
newFaceI++;
}
else if (verbose)
{
Pout<< "BasicMeshedSurface::stitchFaces : "
<< "Removing collapsed face " << faceI << endl
<< " vertices :" << f << endl;
}
}
pointMap.clear();
if (newFaceI != faceLst.size())
{
if (verbose)
{
Pout<< "BasicMeshedSurface::stitchFaces : "
<< "Removed " << faceLst.size() - newFaceI
<< " faces" << endl;
}
faceLst.setSize(newFaceI);
remapFaces(faceMap);
}
faceMap.clear();
// Merging points might have changed geometric factors
ParentType::clearOut();
return true;
}
// Remove badly degenerate faces and double faces.
template<class Face>
bool Foam::BasicMeshedSurface<Face>::checkFaces
(
const bool verbose
)
{
bool changed = false;
List<Face>& faceLst = this->storedFaces();
List<label> faceMap(faceLst.size());
label newFaceI = 0;
// Detect badly labelled faces and mark degenerate faces
const label maxPointI = this->points().size() - 1;
forAll(faceLst, faceI)
{
Face& f = faceLst[faceI];
// avoid degenerate faces
if (f.collapse() >= 3)
{
forAll(f, fp)
{
if (f[fp] < 0 || f[fp] > maxPointI)
{
FatalErrorIn("BasicMeshedSurface::checkFaces(bool)")
<< "face " << f
<< " uses point indices outside point range 0.."
<< maxPointI
<< exit(FatalError);
}
}
faceMap[faceI] = faceI;
newFaceI++;
}
else
{
// mark as bad face
faceMap[faceI] = -1;
changed = true;
if (verbose)
{
WarningIn
(
"BasicMeshedSurface::checkFaces(bool verbose)"
) << "face[" << faceI << "] = " << f
<< " does not have three unique vertices" << endl;
}
}
}
// Detect doubled faces
// do not touch the faces
const labelListList& fFaces = this->faceFaces();
newFaceI = 0;
forAll(faceLst, faceI)
{
// skip already collapsed faces:
if (faceMap[faceI] < 0)
{
continue;
}
const Face& f = faceLst[faceI];
// duplicate face check
bool okay = true;
const labelList& neighbours = fFaces[faceI];
// Check if faceNeighbours use same points as this face.
// Note: discards normal information - sides of baffle are merged.
forAll(neighbours, neighI)
{
const label neiFaceI = neighbours[neighI];
if (neiFaceI <= faceI || faceMap[neiFaceI] < 0)
{
// lower numbered faces already checked
// skip neighbours that are themselves collapsed
continue;
}
const Face& nei = faceLst[neiFaceI];
if (f == nei)
{
okay = false;
if (verbose)
{
WarningIn
(
"BasicMeshedSurface::checkFaces(bool verbose)"
) << "faces share the same vertices:" << nl
<< " face[" << faceI << "] : " << f << nl
<< " face[" << neiFaceI << "] : " << nei << endl;
// printFace(Warning, " ", f, points());
// printFace(Warning, " ", nei, points());
}
break;
}
}
if (okay)
{
faceMap[faceI] = faceI;
newFaceI++;
}
else
{
faceMap[faceI] = -1;
}
}
// Phase 1: pack
// Done to keep numbering constant in phase 1
if (changed || newFaceI < faceLst.size())
{
changed = true;
if (verbose)
{
WarningIn
(
"BasicMeshedSurface::checkFaces(bool verbose)"
) << "Removed " << faceLst.size() - newFaceI
<< " illegal faces." << endl;
}
// compress the face list
newFaceI = 0;
forAll(faceLst, faceI)
{
if (faceMap[faceI] >= 0)
{
if (newFaceI != faceI)
{
faceLst[newFaceI] = faceLst[faceI];
}
faceMap[newFaceI] = faceI;
newFaceI++;
}
}
faceLst.setSize(newFaceI);
remapFaces(faceMap);
}
faceMap.clear();
// Topology can change because of renumbering
ParentType::clearOut();
return changed;
}
template<class Face>
Foam::label Foam::BasicMeshedSurface<Face>::triangulate()
{
return triangulate
(
const_cast<List<label>&>(List<label>::null())
);
}
template<class Face>
Foam::label Foam::BasicMeshedSurface<Face>::triangulate
(
List<label>& faceMapOut
)
{
label nTri = 0;
label maxTri = 0; // the maximum number of triangles for any single face
List<Face>& faceLst = this->storedFaces();
// determine how many triangles will be needed
forAll(faceLst, faceI)
{
const label n = faceLst[faceI].nTriangles();
if (maxTri < n)
{
maxTri = n;
}
nTri += n;
}
// nothing to do
if (nTri <= faceLst.size())
{
if (&faceMapOut)
{
faceMapOut.clear();
}
return 0;
}
List<Face> newFaces(nTri);
List<label> faceMap;
// reuse storage from optional faceMap
if (&faceMapOut)
{
faceMap.transfer(faceMapOut);
}
faceMap.setSize(nTri);
// remember the number of *additional* faces
nTri -= faceLst.size();
if (this->points().empty())
{
// triangulate without points
// simple face triangulation around f[0]
label newFaceI = 0;
forAll(faceLst, faceI)
{
const Face& f = faceLst[faceI];
for (label fp = 1; fp < f.size() - 1; ++fp)
{
label fp1 = f.fcIndex(fp);
newFaces[newFaceI] = triFace(f[0], f[fp], f[fp1]);
faceMap[newFaceI] = faceI;
newFaceI++;
}
}
}
else
{
// triangulate with points
List<face> tmpTri(maxTri);
label newFaceI = 0;
forAll(faceLst, faceI)
{
// 'face' not '<Face>'
const face& f = faceLst[faceI];
label nTmp;
f.triangles(this->points(), nTmp, tmpTri);
for (label triI = 0; triI < nTmp; triI++)
{
newFaces[newFaceI] = Face
(
static_cast<UList<label>&>(tmpTri[triI])
);
faceMap[newFaceI] = faceI;
newFaceI++;
}
}
}
faceLst.transfer(newFaces);
remapFaces(faceMap);
// optionally return the faceMap
if (&faceMapOut)
{
faceMapOut.transfer(faceMap);
}
faceMap.clear();
// Topology can change because of renumbering
ParentType::clearOut();
return nTri;
}
// dummy implementation to avoid a pure virtual class
template<class Face>
void Foam::BasicMeshedSurface<Face>::remapFaces(const UList<label>&)
{
}
template<class Face>
void Foam::BasicMeshedSurface<Face>::writeStats(Ostream& os) const
{
os << "points : " << this->points().size() << nl;
if (this->isTri())
{
os << "triangles : " << this->size() << nl;
}
else
{
label nTri = 0;
label nQuad = 0;
forAll(*this, i)
{
const label n = this->operator[](i).size();
if (n == 3)
{
nTri++;
}
else if (n == 4)
{
nQuad++;
}
}
os << "faces : " << this->size()
<< " (tri:" << nTri << " quad:" << nQuad
<< " poly:" << (this->size() - nTri - nQuad ) << ")" << nl;
}
os << "boundingBox : " << boundBox(this->points()) << endl;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -1,223 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::BasicMeshedSurface
Description
Holds surfaces without any zone information
SourceFiles
BasicMeshedSurface.C
\*---------------------------------------------------------------------------*/
#ifndef BasicMeshedSurface_H
#define BasicMeshedSurface_H
#include "PrimitivePatch.H"
#include "PatchTools.H"
#include "pointField.H"
#include "face.H"
#include "triFace.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
/*---------------------------------------------------------------------------*\
Class BasicMeshedSurface Declaration
\*---------------------------------------------------------------------------*/
template<class Face>
class BasicMeshedSurface
:
public PrimitivePatch<Face, ::Foam::List, pointField, point>
{
// Private typedefs
typedef PrimitivePatch
<
Face,
::Foam::List,
pointField,
point
>
ParentType;
protected:
// Protected Member Functions
//- Non-const access to global points
pointField& storedPoints()
{
return const_cast<pointField&>(ParentType::points());
}
//- Non-const access to the faces
List<Face>& storedFaces()
{
return static_cast<List<Face> &>(*this);
}
//- Set new zones from faceMap
virtual void remapFaces(const UList<label>& faceMap);
public:
// Static
//- Face storage only handles triangulated faces
inline static bool isTri();
// Constructors
//- Construct null
BasicMeshedSurface();
//- Construct by transferring components (points, faces).
BasicMeshedSurface
(
const Xfer< pointField >&,
const Xfer< List<Face> >&
);
// Destructor
virtual ~BasicMeshedSurface();
// Member Functions
// Access
//- Return const access to the faces
inline const List<Face>& faces() const
{
return static_cast<const List<Face> &>(*this);
}
// Edit
//- Clear all storage
virtual void clear();
//- Move points
virtual void movePoints(const pointField&);
//- Scale points. A non-positive factor is ignored
virtual void scalePoints(const scalar&);
//- Transfer components (points, faces).
virtual void reset
(
const Xfer< pointField >&,
const Xfer< List<Face> >&
);
//- Transfer components (points, faces).
virtual void reset
(
const Xfer< List<point> >&,
const Xfer< List<Face> >&
);
//- Remove invalid faces
virtual void cleanup(const bool verbose);
virtual bool stitchFaces
(
const scalar tol=SMALL,
const bool verbose=false
);
virtual bool checkFaces
(
const bool verbose=false
);
//- Triangulate in-place, returning the number of triangles added
virtual label triangulate();
//- Triangulate in-place, returning the number of triangles added
// and setting a map of original face Ids.
// The faceMap is zero-sized when no triangulation was done.
virtual label triangulate(List<label>& faceMap);
// Write
void writeStats(Ostream& os) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Specialization for holding triangulated information
template<>
inline bool BasicMeshedSurface<triFace>::isTri()
{
return true;
}
//- Specialization for holding triangulated information
template<>
inline label BasicMeshedSurface<triFace>::triangulate()
{
return 0;
}
//- Specialization for holding triangulated information
template<>
inline label BasicMeshedSurface<triFace>::triangulate(List<label>& faceMap)
{
if (&faceMap)
{
faceMap.clear();
}
return 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "BasicMeshedSurface.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -2,16 +2,20 @@ surfZone/surfZone/surfZone.C
surfZone/surfZone/surfZoneIOList.C
surfZone/surfZoneIdentifier/surfZoneIdentifier.C
MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C
MeshedSurface/MeshedSurfaceCore.C
MeshedSurface/MeshedSurfaces.C
UnsortedMeshedSurface/UnsortedMeshedSurfaces.C
MeshedSurfaceProxy/MeshedSurfaceProxyCore.C
surfaceRegistry/surfaceRegistry.C
surfFields/surfFields.C
surfPointFields/surfPointFields.C
surfMesh/surfMesh.C
surfMesh/surfMeshClear.C
surfMesh/surfMeshIO.C
surfFields/surfFields/surfFields.C
surfFields/surfPointFields/surfPointFields.C
surfaceFormats = surfaceFormats
$(surfaceFormats)/surfaceFormatsCore.C
@ -22,11 +26,10 @@ $(surfaceFormats)/ftr/FTRsurfaceFormatRunTime.C
$(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C
$(surfaceFormats)/nas/NASsurfaceFormatCore.C
$(surfaceFormats)/nas/NASsurfaceFormatRunTime.C
$(surfaceFormats)/obj/OBJsurfaceFormatCore.C
$(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C
$(surfaceFormats)/off/OFFsurfaceFormatCore.C
$(surfaceFormats)/off/OFFsurfaceFormatRunTime.C
$(surfaceFormats)/smesh/SMESHsurfaceFormatCore.C
$(surfaceFormats)/ofs/OFSsurfaceFormatCore.C
$(surfaceFormats)/ofs/OFSsurfaceFormatRunTime.C
$(surfaceFormats)/smesh/SMESHsurfaceFormatRunTime.C
$(surfaceFormats)/starcd/STARCDsurfaceFormatCore.C
$(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C

File diff suppressed because it is too large Load Diff

View File

@ -26,9 +26,13 @@ Class
Foam::MeshedSurface
Description
A surface geometry mesh with zone information, not to be confused
with a similarily named surfaceMesh, which actually refers to
the cell faces of a volume mesh.
A surface geometry mesh with zone information, not to be confused with
the similarly named surfaceMesh, which actually refers to the cell faces
of a volume mesh.
A MeshedSurface can have zero or more surface zones (roughly equivalent
to faceZones for a polyMesh). If surface zones are defined, they must
be contiguous and cover all of the faces.
The MeshedSurface is intended for surfaces from a variety of sources.
- A set of points and faces without any surface zone information.
@ -44,7 +48,12 @@ SourceFiles
#ifndef MeshedSurface_H
#define MeshedSurface_H
#include "BasicMeshedSurface.H"
#include "PrimitivePatch.H"
#include "PatchTools.H"
#include "pointField.H"
#include "face.H"
#include "triFace.H"
#include "surfZoneList.H"
#include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H"
@ -60,14 +69,11 @@ namespace Foam
class Time;
class surfMesh;
template<class Face> class MeshedSurface;
template<class Face> class UnsortedMeshedSurface;
class polyBoundaryMesh;
class surfMesh;
template<class Face>
Ostream& operator<<(Ostream&, const MeshedSurface<Face>&);
template<class Face> class MeshedSurface;
template<class Face> class MeshedSurfaceProxy;
template<class Face> class UnsortedMeshedSurface;
/*---------------------------------------------------------------------------*\
Class MeshedSurface Declaration
@ -76,7 +82,7 @@ Ostream& operator<<(Ostream&, const MeshedSurface<Face>&);
template<class Face>
class MeshedSurface
:
public BasicMeshedSurface<Face>,
public PrimitivePatch<Face, ::Foam::List, pointField, point>,
public fileFormats::surfaceFormatsCore
{
// friends despite different faces
@ -92,8 +98,18 @@ class MeshedSurface
private:
//- Private typedefs for convenience
typedef BasicMeshedSurface<Face> ParentType;
typedef UnsortedMeshedSurface<Face> SiblingType;
typedef PrimitivePatch
<
Face,
::Foam::List,
pointField,
point
>
ParentType;
typedef UnsortedMeshedSurface<Face> FriendType;
typedef MeshedSurfaceProxy<Face> ProxyType;
// Private Member Data
@ -101,21 +117,31 @@ private:
// (face ordering nFaces/startFace only used during reading/writing)
List<surfZone> zones_;
// Private member functions
//- Read OpenFOAM Surface format
bool read(Istream&);
//- Transfer points/zones and transcribe face -> triFace
void transcribe(MeshedSurface<face>&);
protected:
// Protected Member functions
//- Transfer points/zones and transcribe face -> triFace
void transcribe(MeshedSurface<face>&);
//- basic sanity check on zones
void checkZones();
//- Non-const access to global points
pointField& storedPoints()
{
return const_cast<pointField&>(ParentType::points());
}
//- Non-const access to the faces
List<Face>& storedFaces()
{
return static_cast<List<Face> &>(*this);
}
//- Non-const access to the zones
surfZoneList& storedZones()
{
@ -140,6 +166,9 @@ public:
// Static
//- Face storage only handles triangulated faces
inline static bool isTri();
//- Can we read this file format?
static bool canRead(const fileName&, const bool verbose=false);
@ -165,16 +194,22 @@ public:
const Xfer< surfZoneList >&
);
//- Construct by transferring points, faces.
// Use zone information, or set single default zone.
//- Construct by transferring components (points, faces).
// Use zone information if available
MeshedSurface
(
const Xfer< pointField >&,
const Xfer< List<Face> >&,
const UList<label>& zoneSizes = UList<label>::null(),
const UList<word>& zoneNames = UList<word>::null()
const UList<label>& zoneSizes = UList<label>(),
const UList<word>& zoneNames = UList<word>()
);
//- Construct as copy
MeshedSurface(const MeshedSurface&);
//- Construct from a UnsortedMeshedSurface
MeshedSurface(const UnsortedMeshedSurface<Face>&);
//- Construct from a boundary mesh with local points/faces
MeshedSurface
(
@ -182,9 +217,6 @@ public:
const bool globalPoints=false
);
//- Construct from a UnsortedMeshedSurface
MeshedSurface(const UnsortedMeshedSurface<Face>&);
//- Construct from a surfMesh
MeshedSurface(const surfMesh&);
@ -200,15 +232,9 @@ public:
//- Construct from file name (uses extension to determine type)
MeshedSurface(const fileName&, const word& ext);
//- Construct from Istream
MeshedSurface(Istream&);
//- Construct from objectRegistry
MeshedSurface(const Time&, const word& surfName="");
//- Construct as copy
MeshedSurface(const MeshedSurface&);
// Declare run-time constructor selection table
declareRunTimeSelectionTable
@ -244,7 +270,7 @@ public:
declareMemberFunctionSelectionTable
(
void,
MeshedSurface,
UnsortedMeshedSurface,
write,
fileExtension,
(
@ -268,41 +294,98 @@ public:
return ParentType::size();
}
const List<surfZone>& zones() const
//- Return const access to the faces
inline const List<Face>& faces() const
{
return static_cast<const List<Face> &>(*this);
}
//- Const access to the surface zones.
// If zones are defined, they must be contiguous and cover the entire
// surface.
const List<surfZone>& surfZones() const
{
return zones_;
}
//- set a single zone, optionally with a specific name
void oneZone(const word& name = word::null);
//- Add zones
void addZones
//- Add surface zones
virtual void addZones
(
const UList<surfZone>&,
const bool cullEmpty=false
);
//- Add zones
void addZones
//- Add surface zones
virtual void addZones
(
const UList<label>& sizes,
const UList<word>& names,
const bool cullEmpty=false
);
//- Add zones
void addZones
//- Add surface zones
virtual void addZones
(
const UList<label>& sizes,
const bool cullEmpty=false
);
//- Remove surface zones
virtual void removeZones();
// Edit
//- Clear all storage
virtual void clear();
//- Move points
virtual void movePoints(const pointField&);
//- Scale points. A non-positive factor is ignored
virtual void scalePoints(const scalar&);
//- Reset primitive data (points, faces and zones)
// Note, optimized to avoid overwriting data (with Xfer::null)
virtual void reset
(
const Xfer< pointField >& points,
const Xfer< List<Face> >& faces,
const Xfer< surfZoneList >& zones
);
//- Reset primitive data (points, faces and zones)
// Note, optimized to avoid overwriting data (with Xfer::null)
virtual void reset
(
const Xfer< List<point> >& points,
const Xfer< List<Face> >& faces,
const Xfer< surfZoneList >& zones
);
//- Remove invalid faces
virtual void cleanup(const bool verbose);
virtual bool stitchFaces
(
const scalar tol=SMALL,
const bool verbose=false
);
virtual bool checkFaces
(
const bool verbose=false
);
//- Triangulate in-place, returning the number of triangles added
virtual label triangulate();
//- Triangulate in-place, returning the number of triangles added
// and setting a map of original face Ids.
// The faceMap is zero-sized when no triangulation was done.
virtual label triangulate(List<label>& faceMap);
//- Return new surface.
// Returns return pointMap, faceMap from subsetMeshMap
MeshedSurface subsetMesh
@ -338,8 +421,7 @@ public:
// Write
//- Write to Ostream in simple FOAM format
virtual void write(Ostream&) const;
void writeStats(Ostream& os) const;
//- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& name) const
@ -355,17 +437,37 @@ public:
void operator=(const MeshedSurface<Face>&);
// Ostream Operator
friend Ostream& operator<<
<Face>
(
Ostream&,
const MeshedSurface<Face>&
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
//- Specialization for holding triangulated information
template<>
inline bool MeshedSurface<triFace>::isTri()
{
return true;
}
//- Specialization for holding triangulated information
template<>
inline label MeshedSurface<triFace>::triangulate()
{
return 0;
}
//- Specialization for holding triangulated information
template<>
inline label MeshedSurface<triFace>::triangulate(List<label>& faceMap)
{
if (&faceMap)
{
faceMap.clear();
}
return 0;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam

View File

@ -38,7 +38,7 @@ namespace Foam
// first triangulate
surf.triangulate();
this->storedPoints().transfer(surf.storedPoints());
zones_.transfer(surf.zones_);
this->storedZones().transfer(surf.storedZones());
// transcribe from face -> triFace
List<face>& origFaces = surf.storedFaces();

View File

@ -25,117 +25,44 @@ License
\*---------------------------------------------------------------------------*/
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "IFstream.H"
#include "OFstream.H"
#include "boundBox.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Read surf grouping, points, faces directly from Istream
template<class Face>
bool Foam::MeshedSurface<Face>::read(Istream& is)
void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const
{
clear();
List<surfZone> newZones(is);
// copy and set the indices
zones_.setSize(newZones.size());
forAll(newZones, zoneI)
{
zones_[zoneI] = surfZone
(
newZones[zoneI],
zoneI
);
}
// read points:
is >> this->storedPoints();
// must triangulate?
os << "points : " << this->points().size() << nl;
if (this->isTri())
{
List<face> faceLst(is);
MeshedSurface<face> surf;
surf.reset
(
Xfer<pointField>::null(),
faceLst.xfer()
);
surf.addZones(zones_);
// this will break if the triangulation needed points
surf.triangulate();
zones_ = surf.zones();
// transcribe from face -> triFace (Face)
const List<face>& origFaces = surf.faces();
List<Face> newFaces(origFaces.size());
forAll(origFaces, faceI)
{
newFaces[faceI] = Face
(
static_cast<const UList<label>&>(origFaces[faceI])
);
}
surf.clear();
this->storedFaces().transfer(newFaces);
os << "triangles : " << this->size() << nl;
}
else
{
// read faces:
is >> this->storedFaces();
}
return is.good();
}
template<class Face>
void Foam::MeshedSurface<Face>::write(Ostream& os) const
label nTri = 0;
label nQuad = 0;
forAll(*this, i)
{
// just emit some information until we get a nice IOobject
IOobject::writeBanner(os);
os << "// OpenFOAM Surface Format" << nl
<< "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl
<< "// zones:" << nl
<< zones_.size() << nl << token::BEGIN_LIST << incrIndent << nl;
const label n = this->operator[](i).size();
forAll(zones_, zoneI)
if (n == 3)
{
zones_[zoneI].writeDict(os);
nTri++;
}
os << decrIndent << token::END_LIST << nl;
IOobject::writeDivider(os);
// Note: Write with global point numbering
os << "\n// points:" << nl << this->points() << nl;
IOobject::writeDivider(os);
os << "\n// faces:" << nl << this->faces() << nl;
IOobject::writeDivider(os);
// Check state of Ostream
os.check("MeshedSurface::write(Ostream&)");
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class Face>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const MeshedSurface<Face>& surf
)
else if (n == 4)
{
surf.write(os);
return os;
nQuad++;
}
}
os << "faces : " << this->size()
<< " (tri:" << nTri << " quad:" << nQuad
<< " poly:" << (this->size() - nTri - nQuad ) << ")" << nl;
}
os << "boundingBox : " << boundBox(this->points()) << endl;
}
// ************************************************************************* //

View File

@ -47,19 +47,18 @@ Foam::MeshedSurface<Face>::New(const fileName& name, const word& ext)
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
// no direct reader, delegate if possible
wordHashSet supported = SiblingType::readTypes();
wordHashSet supported = FriendType::readTypes();
if (supported.found(ext))
{
// create indirectly
autoPtr<MeshedSurface<Face> > surf(new MeshedSurface<Face>);
surf().transfer(SiblingType::New(name, ext)());
surf().transfer(FriendType::New(name, ext)());
return surf;
}
// nothing left to try, issue error
supported += readTypes();
supported.insert(nativeExt);
FatalErrorIn
(

View File

@ -0,0 +1,214 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "MeshedSurface.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Face>
void Foam::MeshedSurface<Face>::checkZones()
{
// extra safety, ensure we have at some zones
// and they cover all the faces - fix start silently
surfZoneList& zones = storedZones();
if (zones.size())
{
label count = 0;
forAll(zones, zoneI)
{
zones[zoneI].start() = count;
count += zones[zoneI].size();
}
if (count < size())
{
WarningIn
(
"MeshedSurface::checkZones()\n"
)
<< "more faces " << size() << " than zones " << count
<< " ... extending final zone"
<< endl;
zones[zones.size()-1].size() += count - size();
}
else if (count > size())
{
FatalErrorIn
(
"MeshedSurface::checkZones()\n"
)
<< "more zones " << count << " than faces " << size()
<< exit(FatalError);
}
}
}
template<class Face>
void Foam::MeshedSurface<Face>::sortFacesAndStore
(
const Xfer< List<Face> >& unsortedFaces,
const Xfer< List<label> >& zoneIds,
const bool sorted
)
{
List<Face> oldFaces(unsortedFaces);
List<label> zones(zoneIds);
if (sorted)
{
// already sorted - simply transfer faces
this->storedFaces().transfer(oldFaces);
}
else
{
// unsorted - determine the sorted order:
// avoid SortableList since we discard the main list anyhow
List<label> faceMap;
sortedOrder(zones, faceMap);
zones.clear();
// sorted faces
List<Face> newFaces(faceMap.size());
forAll(faceMap, faceI)
{
// use transfer to recover memory if possible
newFaces[faceI].transfer(oldFaces[faceMap[faceI]]);
}
this->storedFaces().transfer(newFaces);
}
zones.clear();
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face>
void Foam::MeshedSurface<Face>::addZones
(
const UList<surfZone>& srfZones,
const bool cullEmpty
)
{
label nZone = 0;
surfZoneList& zones = this->storedZones();
zones.setSize(zones.size());
forAll(zones, zoneI)
{
if (srfZones[zoneI].size() || !cullEmpty)
{
zones[nZone] = surfZone(srfZones[zoneI], nZone);
nZone++;
}
}
zones.setSize(nZone);
}
template<class Face>
void Foam::MeshedSurface<Face>::addZones
(
const UList<label>& sizes,
const UList<word>& names,
const bool cullEmpty
)
{
label start = 0;
label nZone = 0;
surfZoneList& zones = this->storedZones();
zones.setSize(sizes.size());
forAll(zones, zoneI)
{
if (sizes[zoneI] || !cullEmpty)
{
zones[nZone] = surfZone
(
names[zoneI],
sizes[zoneI],
start,
nZone
);
start += sizes[zoneI];
nZone++;
}
}
zones.setSize(nZone);
}
template<class Face>
void Foam::MeshedSurface<Face>::addZones
(
const UList<label>& sizes,
const bool cullEmpty
)
{
label start = 0;
label nZone = 0;
surfZoneList& zones = this->storedZones();
zones.setSize(sizes.size());
forAll(zones, zoneI)
{
if (sizes[zoneI] || !cullEmpty)
{
zones[nZone] = surfZone
(
word("zone") + ::Foam::name(nZone),
sizes[zoneI],
start,
nZone
);
start += sizes[zoneI];
nZone++;
}
}
zones.setSize(nZone);
}
template<class Face>
void Foam::MeshedSurface<Face>::removeZones()
{
this->storedZones().clear();
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,147 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "MeshedSurfaceIOAllocator.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
(
const IOobject& ioPoints,
const IOobject& ioFaces,
const IOobject& ioZones
)
:
points_(ioPoints),
faces_(ioFaces),
zones_(ioZones)
{}
Foam::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
(
const IOobject& ioPoints,
const pointField& points,
const IOobject& ioFaces,
const faceList& faces,
const IOobject& ioZones,
const surfZoneList& zones
)
:
points_(ioPoints, points),
faces_(ioFaces, faces),
zones_(ioZones, zones)
{}
Foam::MeshedSurfaceIOAllocator::MeshedSurfaceIOAllocator
(
const IOobject& ioPoints,
const Xfer< pointField >& points,
const IOobject& ioFaces,
const Xfer< faceList >& faces,
const IOobject& ioZones,
const Xfer< surfZoneList >& zones
)
:
points_(ioPoints, points),
faces_(ioFaces, faces),
zones_(ioZones, zones)
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::MeshedSurfaceIOAllocator::clear()
{
points_.clear();
faces_.clear();
zones_.clear();
}
void Foam::MeshedSurfaceIOAllocator::resetFaces
(
const Xfer< List<face> >& faces,
const Xfer< surfZoneList >& zones
)
{
if (&faces)
{
faces_.transfer(faces());
}
if (&zones)
{
zones_.transfer(zones());
}
}
void Foam::MeshedSurfaceIOAllocator::reset
(
const Xfer< pointField >& points,
const Xfer< faceList >& faces,
const Xfer< surfZoneList >& zones
)
{
// Take over new primitive data.
// Optimized to avoid overwriting data at all
if (&points)
{
points_.transfer(points());
}
resetFaces(faces, zones);
}
void Foam::MeshedSurfaceIOAllocator::reset
(
const Xfer< List<point> >& points,
const Xfer< faceList >& faces,
const Xfer< surfZoneList >& zones
)
{
// Take over new primitive data.
// Optimized to avoid overwriting data at all
if (&points)
{
points_.transfer(points());
}
resetFaces(faces, zones);
}
// ************************************************************************* //

View File

@ -0,0 +1,194 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::MeshedSurfaceIOAllocator
Description
A helper class for storing points, faces and zones with IO capabilities.
SourceFiles
MeshedSurfaceIOAllocator.C
\*---------------------------------------------------------------------------*/
#ifndef MeshedSurfaceIOAllocator_H
#define MeshedSurfaceIOAllocator_H
#include "pointIOField.H"
#include "faceIOList.H"
#include "surfZoneIOList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class MeshedSurfaceIOAllocator Declaration
\*---------------------------------------------------------------------------*/
//- A helper class for storing points, faces and zones
class MeshedSurfaceIOAllocator
{
// Private data
//- Points
pointIOField points_;
//- Faces
faceIOList faces_;
//- Surface zones
surfZoneIOList zones_;
// Private Member Functions
//- Disallow default bitwise copy construct
MeshedSurfaceIOAllocator(const MeshedSurfaceIOAllocator&);
//- Disallow default bitwise assignment
void operator=(const MeshedSurfaceIOAllocator&);
public:
// Constructors
//- Read construct from IOobjects
MeshedSurfaceIOAllocator
(
const IOobject& ioPoints,
const IOobject& ioFaces,
const IOobject& ioZones
);
//- Construct from IOobjects, copying components
MeshedSurfaceIOAllocator
(
const IOobject& ioPoints,
const pointField& points,
const IOobject& ioFaces,
const faceList& faces,
const IOobject& ioZones,
const surfZoneList& zones
);
//- Construct from IOobjects, possibly transferring components
MeshedSurfaceIOAllocator
(
const IOobject& ioPoints,
const Xfer< pointField >& points,
const IOobject& ioFaces,
const Xfer< faceList >& faces,
const IOobject& ioZones,
const Xfer< surfZoneList >& zones
);
// Destructor
// Member Functions
// Access
//- Non-const access to the points
pointIOField& storedIOPoints()
{
return points_;
}
//- Non-const access to the faces
faceIOList& storedIOFaces()
{
return faces_;
}
//- Non-const access to the zones
surfZoneIOList& storedIOZones()
{
return zones_;
}
//- Const access to the points
const pointIOField& storedIOPoints() const
{
return points_;
}
//- Const access to the faces
const faceIOList& storedIOFaces() const
{
return faces_;
}
//- Const access to the zones
const surfZoneIOList& storedIOZones() const
{
return zones_;
}
// Storage management
//- Clear primitive data (points, faces and zones)
void clear();
//- Reset primitive data (points, faces and zones)
// Note, optimized to avoid overwriting data (with Xfer::null)
void resetFaces
(
const Xfer< faceList >& faces,
const Xfer< surfZoneList >& zones
);
//- Reset primitive data (points, faces and zones)
// Note, optimized to avoid overwriting data (with Xfer::null)
void reset
(
const Xfer< pointField >& points,
const Xfer< faceList >& faces,
const Xfer< surfZoneList >& zones
);
//- Reset primitive data (points, faces and zones)
// Note, optimized to avoid overwriting data (with Xfer::null)
void reset
(
const Xfer< List<point> >& points,
const Xfer< faceList >& faces,
const Xfer< surfZoneList >& zones
);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -0,0 +1,153 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "MeshedSurfaceProxy.H"
#include "Time.H"
#include "surfMesh.H"
#include "MeshedSurface.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class Face>
Foam::wordHashSet Foam::MeshedSurfaceProxy<Face>::writeTypes()
{
return wordHashSet(*writefileExtensionMemberFunctionTablePtr_);
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Face>
bool Foam::MeshedSurfaceProxy<Face>::canWriteType
(
const word& ext,
const bool verbose
)
{
return checkSupport(writeTypes(), ext, verbose, "writing");
}
template<class Face>
void Foam::MeshedSurfaceProxy<Face>::write
(
const fileName& name,
const MeshedSurfaceProxy& surf
)
{
if (debug)
{
Info<< "MeshedSurfaceProxy::write"
"(const fileName&, const MeshedSurfaceProxy&) : "
"writing to " << name
<< endl;
}
word ext = name.ext();
typename writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
FatalErrorIn
(
"MeshedSurfaceProxy::write(const fileName&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writeTypes()
<< exit(FatalError);
}
mfIter()(name, surf);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy
(
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst,
const List<label>& faceMap
)
:
points_(pointLst),
faces_(faceLst),
zones_(zoneLst),
faceMap_(faceMap)
{}
template<class Face>
Foam::MeshedSurfaceProxy<Face>::MeshedSurfaceProxy
(
const MeshedSurface<Face>& surf
)
:
points_(surf.points()),
faces_(surf.faces()),
zones_(surf.surfZones()),
faceMap_(List<label>())
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Face>
Foam::MeshedSurfaceProxy<Face>::~MeshedSurfaceProxy()
{}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// template<class Face>
// void Foam::MeshedSurfaceProxy<Face>::write
// (
// const Time& d,
// const word& surfName
// ) const
// {
// write(findMeshFile(d, surfName)());
// }
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -0,0 +1,207 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::MeshedSurfaceProxy
Description
A proxy for writing MeshedSurface, UnsortedMeshedSurface and surfMesh
to various file formats.
SourceFiles
MeshedSurfaceProxy.C
MeshedSurfaceProxyCore.C
\*---------------------------------------------------------------------------*/
#ifndef MeshedSurfaceProxy_H
#define MeshedSurfaceProxy_H
#include "pointField.H"
#include "face.H"
#include "triFace.H"
#include "surfZoneList.H"
#include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
template<class Face> class MeshedSurface;
/*---------------------------------------------------------------------------*\
Class MeshedSurfaceProxy Declaration
\*---------------------------------------------------------------------------*/
template<class Face>
class MeshedSurfaceProxy
:
public fileFormats::surfaceFormatsCore
{
//- Private data
const pointField& points_;
const List<Face>& faces_;
const List<surfZone>& zones_;
const List<label>& faceMap_;
// Private Member Functions
//- Disallow default bitwise copy construct
MeshedSurfaceProxy(const MeshedSurfaceProxy&);
//- Disallow default bitwise assignment
void operator=(const MeshedSurfaceProxy&);
public:
//- Runtime type information
ClassName("MeshedSurfaceProxy");
// Static
//- Can we write this file format?
static bool canWriteType(const word& ext, const bool verbose=false);
static wordHashSet writeTypes();
// Constructors
//- Construct from component references
MeshedSurfaceProxy
(
const pointField&,
const List<Face>&,
const List<surfZone>&,
const List<label>& faceMap = List<label>()
);
//- Construct from MeshedSurface
explicit MeshedSurfaceProxy
(
const MeshedSurface<Face>&
);
// Destructor
virtual ~MeshedSurfaceProxy();
// Member Function Selectors
declareMemberFunctionSelectionTable
(
void,
MeshedSurfaceProxy,
write,
fileExtension,
(
const fileName& name,
const MeshedSurfaceProxy<Face>& surf
),
(name, surf)
);
//- Write to file
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
// Member Functions
// Access
//- Return const access to the points
inline const pointField& points() const
{
return points_;
}
//- Return const access to the faces
inline const List<Face>& faces() const
{
return faces_;
}
//- Const access to the surface zones.
// If zones are defined, they must be contiguous and cover the entire
// surface.
inline const List<surfZone>& surfZones() const
{
return zones_;
}
//- Const access to the faceMap, zero-sized when unused
inline const List<label>& faceMap() const
{
return faceMap_;
}
//- Use faceMap?
inline bool useFaceMap() const
{
return faceMap_.size() == faces_.size();
}
// Write
//?? void writeStats(Ostream& os) const;
//- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& name) const
{
write(name, *this);
}
//- Write to database
//?? void write(const Time&, const word& surfName="") const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "MeshedSurfaceProxy.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -22,60 +22,28 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::OFFsurfaceFormatCore
Description
Internal class used by the OFFsurfaceFormat
SourceFiles
OFFsurfaceFormatCore.C
\*---------------------------------------------------------------------------*/
#ifndef OFFsurfaceFormatCore_H
#define OFFsurfaceFormatCore_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class OFFsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
class OFFsurfaceFormatCore
{
protected:
// Protected Member Functions
#define makeSurface(surfType, faceType) \
defineNamedTemplateTypeNameAndDebug(surfType<faceType>, 0); \
defineTemplatedMemberFunctionSelectionTable(surfType,write,fileExtension,faceType);
//- Write header information with points
static void writeHeader
(
Ostream&,
const pointField&,
const label nFaces,
const UList<surfZone>&
);
};
makeSurface(MeshedSurfaceProxy, face)
makeSurface(MeshedSurfaceProxy, triFace)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -56,23 +56,15 @@ bool Foam::UnsortedMeshedSurface<Face>::canReadType
const word& ext,
const bool verbose
)
{
// handle 'native' format directly
if (isNative(ext))
{
return true;
}
else
{
return checkSupport
(
readTypes() | SiblingType::readTypes(),
readTypes() | ParentType::readTypes(),
ext,
verbose,
"reading"
);
}
}
template<class Face>
@ -82,13 +74,13 @@ bool Foam::UnsortedMeshedSurface<Face>::canWriteType
const bool verbose
)
{
// handle 'native' format directly
if (isNative(ext))
{
return true;
}
return checkSupport(writeTypes(), ext, verbose, "writing");
return checkSupport
(
writeTypes(),
ext,
verbose,
"writing"
);
}
@ -125,17 +117,28 @@ void Foam::UnsortedMeshedSurface<Face>::write
const word ext = name.ext();
// handle 'native' format directly
if (isNative(ext))
{
surf.write(OFstream(name)());
return;
}
typename writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
// no direct writer, delegate to proxy if possible
wordHashSet supported = ProxyType::writeTypes();
if (supported.found(ext))
{
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
MeshedSurfaceProxy<Face>
(
surf.points(),
surf.faces(),
zoneLst,
faceMap
).write(name);
}
else
{
FatalErrorIn
(
@ -143,18 +146,23 @@ void Foam::UnsortedMeshedSurface<Face>::write
"(const fileName&, const UnsortedMeshedSurface&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writeTypes()
<< (supported | writeTypes())
<< exit(FatalError);
}
}
else
{
mfIter()(name, surf);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface()
:
ParentType()
{}
@ -184,9 +192,9 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
:
ParentType(pointLst, faceLst)
{
if (&zoneSizes)
if (zoneSizes.size())
{
if (&zoneNames)
if (zoneNames.size())
{
setZones(zoneSizes, zoneNames);
}
@ -197,89 +205,50 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
}
else
{
oneZone();
setOneZone();
}
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const polyBoundaryMesh& bMesh,
const bool useGlobalPoints
)
{
// creating via MeshedSurface is the easiest
MeshedSurface<Face> surf(bMesh, useGlobalPoints);
transfer(surf);
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const MeshedSurface<Face>& surf
)
:
ParentType(xferCopy(surf.points()), xferCopy(surf.faces()))
{
setZones(surf.zones());
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const fileName& name,
const word& ext
)
{
read(name, ext);
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(const fileName& name)
{
read(name);
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(Istream& is)
{
read(is);
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const Time& d,
const word& surfName
)
{
read(IFstream(findMeshFile(d, surfName))());
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const UnsortedMeshedSurface<Face>& surf
)
:
ParentType(xferCopy(surf.points()), xferCopy(surf.faces())),
zoneIds_(surf.zoneIds_),
zoneToc_(surf.zoneToc_)
ParentType
(
xferCopy(surf.points()),
xferCopy(surf.faces())
),
zoneIds_(surf.zoneIds()),
zoneToc_(surf.zoneToc())
{}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const MeshedSurface<Face>& surf
)
:
ParentType
(
xferCopy(surf.points()),
xferCopy(surf.faces())
)
{
setZones(surf.surfZones());
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const Xfer< UnsortedMeshedSurface<Face> >& surf
)
:
ParentType()
{
transfer(surf());
}
@ -290,10 +259,48 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const Xfer< MeshedSurface<Face> >& surf
)
:
ParentType()
{
transfer(surf());
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const fileName& name,
const word& ext
)
:
ParentType()
{
read(name, ext);
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface(const fileName& name)
:
ParentType()
{
read(name);
}
template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
(
const Time& d,
const word& surfName
)
:
ParentType()
{
read(this->findMeshFile(d, surfName));
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Face>
@ -308,14 +315,12 @@ Foam::UnsortedMeshedSurface<Face>::~UnsortedMeshedSurface()
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Face>
void Foam::UnsortedMeshedSurface<Face>::oneZone(const word& name)
void Foam::UnsortedMeshedSurface<Face>::setOneZone()
{
zoneIds_.setSize(size());
zoneIds_ = 0;
word zoneName(name);
if (zoneName.empty())
{
word zoneName;
if (zoneToc_.size())
{
zoneName = zoneToc_[0].name();
@ -324,7 +329,6 @@ void Foam::UnsortedMeshedSurface<Face>::oneZone(const word& name)
{
zoneName = "zone0";
}
}
// set single default zone
zoneToc_.setSize(1);
@ -344,7 +348,6 @@ void Foam::UnsortedMeshedSurface<Face>::setZones
forAll(zoneToc_, zoneI)
{
const surfZone& zone = zoneLst[zoneI];
zoneToc_[zoneI] = zone;
// assign sub-zone Ids
@ -416,7 +419,7 @@ void Foam::UnsortedMeshedSurface<Face>::remapFaces
{
if (zoneToc_.empty())
{
oneZone();
setOneZone();
}
else if (zoneToc_.size() == 1)
{
@ -442,7 +445,7 @@ void Foam::UnsortedMeshedSurface<Face>::remapFaces
template<class Face>
void Foam::UnsortedMeshedSurface<Face>::setSize(const label s)
{
ParentType::setSize(s);
this->storedFaces().setSize(s);
// if zones extend: set with last zoneId
zoneIds_.setSize(s, zoneToc_.size() - 1);
}
@ -470,12 +473,13 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones
zoneNames.insert(zoneI, zoneToc_[zoneI].name());
}
return sortedZonesById(zoneIds_, zoneNames, faceMap);
return this->sortedZonesById(zoneIds_, zoneNames, faceMap);
}
template<class Face>
Foam::UnsortedMeshedSurface<Face> Foam::UnsortedMeshedSurface<Face>::subsetMesh
Foam::UnsortedMeshedSurface<Face>
Foam::UnsortedMeshedSurface<Face>::subsetMesh
(
const labelHashSet& include,
labelList& pointMap,
@ -547,7 +551,34 @@ void Foam::UnsortedMeshedSurface<Face>::reset
const Xfer< List<label> >& zoneIds
)
{
ParentType::reset(pointLst, faceLst);
ParentType::reset
(
pointLst,
faceLst,
Xfer<surfZoneList>()
);
if (&zoneIds)
{
zoneIds_.transfer(zoneIds());
}
}
template<class Face>
void Foam::UnsortedMeshedSurface<Face>::reset
(
const Xfer< List<point> >& pointLst,
const Xfer< List<Face> >& faceLst,
const Xfer< List<label> >& zoneIds
)
{
ParentType::reset
(
pointLst,
faceLst,
Xfer<surfZoneList>()
);
if (&zoneIds)
{
@ -562,12 +593,14 @@ void Foam::UnsortedMeshedSurface<Face>::transfer
UnsortedMeshedSurface<Face>& surf
)
{
reset
ParentType::reset
(
xferMove(surf.storedPoints()),
xferMove(surf.storedFaces()),
xferMove(surf.zoneIds_)
Xfer<surfZoneList>()
);
zoneIds_.transfer(surf.zoneIds_);
zoneToc_.transfer(surf.zoneToc_);
surf.clear();
@ -580,8 +613,14 @@ void Foam::UnsortedMeshedSurface<Face>::transfer
MeshedSurface<Face>& surf
)
{
reset(xferMove(surf.storedPoints()), xferMove(surf.storedFaces()));
setZones(surf.zones());
ParentType::reset
(
xferMove(surf.storedPoints()),
xferMove(surf.storedFaces()),
Xfer<surfZoneList>()
);
setZones(surf.surfZones());
surf.clear();
}
@ -620,18 +659,12 @@ bool Foam::UnsortedMeshedSurface<Face>::read
const word& ext
)
{
// handle 'native' format directly
if (isNative(ext))
{
return read(IFstream(name)());
}
else
{
// use selector mechanism
clear();
// read via use selector mechanism
transfer(New(name, ext)());
return true;
}
}
template<class Face>
@ -641,7 +674,7 @@ void Foam::UnsortedMeshedSurface<Face>::write
const word& surfName
) const
{
write(OFstream(findMeshFile(d, surfName))());
write(OFstream(this->findMeshFile(d, surfName))());
}
@ -668,7 +701,6 @@ void Foam::UnsortedMeshedSurface<Face>::operator=
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "UnsortedMeshedSurfaceIO.C"
#include "UnsortedMeshedSurfaceNew.C"
// ************************************************************************* //

View File

@ -47,7 +47,7 @@ SourceFiles
#ifndef UnsortedMeshedSurface_H
#define UnsortedMeshedSurface_H
#include "BasicMeshedSurface.H"
#include "MeshedSurface.H"
#include "surfZoneIdentifierList.H"
#include "surfZoneList.H"
#include "surfaceFormatsCore.H"
@ -64,14 +64,10 @@ namespace Foam
class Time;
class IFstream;
template<class Face> class UnsortedMeshedSurface;
template<class Face> class MeshedSurface;
class polyBoundaryMesh;
template<class Face>
Ostream& operator<<(Ostream&, const UnsortedMeshedSurface<Face>&);
template<class Face> class MeshedSurfaceProxy;
template<class Face> class UnsortedMeshedSurface;
/*---------------------------------------------------------------------------*\
Class UnsortedMeshedSurface Declaration
@ -80,8 +76,7 @@ Ostream& operator<<(Ostream&, const UnsortedMeshedSurface<Face>&);
template<class Face>
class UnsortedMeshedSurface
:
public BasicMeshedSurface<Face>,
public fileFormats::surfaceFormatsCore
public MeshedSurface<Face>
{
// friends despite different faces
template<class Face2>
@ -95,9 +90,11 @@ class UnsortedMeshedSurface
private:
//- Typedefs for convenience
typedef BasicMeshedSurface<Face> ParentType;
typedef MeshedSurface<Face> SiblingType;
//- Private typedefs for convenience
typedef MeshedSurface<Face> ParentType;
typedef MeshedSurface<Face> FriendType;
typedef MeshedSurfaceProxy<Face> ProxyType;
// Private Member Data
@ -178,16 +175,12 @@ public:
(
const Xfer<pointField>&,
const Xfer<List<Face> >&,
const UList<label>& zoneSizes = UList<label>::null(),
const UList<word>& zoneNames = UList<word>::null()
const UList<label>& zoneSizes = UList<label>(),
const UList<word>& zoneNames = UList<word>()
);
//- Construct from a boundary mesh with local points/faces
UnsortedMeshedSurface
(
const polyBoundaryMesh&,
const bool globalPoints=false
);
//- Construct as copy
UnsortedMeshedSurface(const UnsortedMeshedSurface<Face>&);
//- Construct from a meshedSurface
UnsortedMeshedSurface(const MeshedSurface<Face>&);
@ -210,9 +203,6 @@ public:
//- Construct from objectRegistry
UnsortedMeshedSurface(const Time&, const word& surfName="");
//- Construct as copy
UnsortedMeshedSurface(const UnsortedMeshedSurface<Face>&);
// Declare run-time constructor selection table
declareRunTimeSelectionTable
@ -292,8 +282,7 @@ public:
surfZoneList sortedZones(labelList& faceMap) const;
//- Set zones to 0 and set a single zone
// Optionally with a specific name
void oneZone(const word& name = word::null);
void setOneZone();
//- Set zone ids and zones
void setZones(const surfZoneList&);
@ -330,7 +319,15 @@ public:
(
const Xfer< pointField >&,
const Xfer< List<Face> >&,
const Xfer<List<label> >& zoneIds = Xfer<List<label> >::null()
const Xfer< List<label> >& zoneIds
);
//- Transfer components (points, faces, zone ids).
virtual void reset
(
const Xfer< List<point> >&,
const Xfer< List<Face> >&,
const Xfer< List<label> >& zoneIds
);
//- Transfer the contents of the argument and annull the argument
@ -354,9 +351,6 @@ public:
// Write
//- Write to Ostream in simple FOAM format
virtual void write(Ostream&) const;
//- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& name) const
{
@ -372,15 +366,6 @@ public:
void operator=(const UnsortedMeshedSurface<Face>&);
// Ostream Operator
friend Ostream& operator<<
<Face>
(
Ostream&,
const UnsortedMeshedSurface<Face>&
);
};

View File

@ -1,108 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "IFstream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Read surf grouping, points, faces directly from Istream
template<class Face>
bool Foam::UnsortedMeshedSurface<Face>::read(Istream& is)
{
MeshedSurface<Face> surf(is);
transfer(surf);
return is.good();
}
// write (sorted)
template<class Face>
void Foam::UnsortedMeshedSurface<Face>::write(Ostream& os) const
{
const List<Face>& faceLst = this->faces();
labelList faceMap;
surfZoneList zoneLst = sortedZones(faceMap);
// just emit some information until we get a nice IOobject
IOobject::writeBanner(os);
os << "// OpenFOAM Surface Format" << nl
<< "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl
<< "// zones:" << nl
<< zoneLst.size() << nl << token::BEGIN_LIST << incrIndent << nl;
forAll(zoneLst, zoneI)
{
zoneLst[zoneI].writeDict(os);
}
os << decrIndent << token::END_LIST << nl;
IOobject::writeDivider(os);
// Note: Write with global point numbering
os << "\n// points:" << nl << this->points() << nl;
IOobject::writeDivider(os);
os << "\n// faces:" << nl;
os << faceLst.size() << nl << token::BEGIN_LIST << nl;
label faceI = 0;
forAll(zoneLst, zoneI)
{
// Print all faces belonging to this zone
const surfZone& zone = zoneLst[zoneI];
forAll(zone, localFaceI)
{
os << faceLst[faceMap[faceI++]] << nl;
}
}
os << token::END_LIST << nl;
IOobject::writeDivider(os);
// Check state of Ostream
os.check("UnsortedMeshedSurface::write(Ostream&)");
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class Face>
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const UnsortedMeshedSurface<Face>& surf
)
{
surf.write(os);
return os;
}
// ************************************************************************* //

View File

@ -45,8 +45,8 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext)
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
// no direct reader, delegate if possible
wordHashSet supported = SiblingType::readTypes();
// no direct reader, use the parent if possible
wordHashSet supported = ParentType::readTypes();
if (supported.found(ext))
{
// create indirectly
@ -54,14 +54,13 @@ Foam::UnsortedMeshedSurface<Face>::New(const fileName& name, const word& ext)
(
new UnsortedMeshedSurface<Face>
);
surf().transfer(SiblingType::New(name, ext)());
surf().transfer(ParentType::New(name, ext)());
return surf;
}
// nothing left but to issue an error
supported += readTypes();
supported.insert(nativeExt);
FatalErrorIn
(

View File

@ -25,6 +25,8 @@ License
\*---------------------------------------------------------------------------*/
#include "surfMesh.H"
#include "MeshedSurfaceProxy.H"
#include "Time.H"
#include "cellIOList.H"
#include "SubList.H"
@ -40,29 +42,30 @@ Foam::word Foam::surfMesh::meshSubDir = "surfMesh";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::surfMesh::oneZone()
{
word zoneName;
if (surfZones_.size())
{
zoneName = surfZones_[0].name();
}
if (zoneName.empty())
{
zoneName = "zone0";
}
// set single default zone
surfZones_.setSize(1);
surfZones_[0] = surfZone
(
zoneName,
nFaces(), // zone size
0, // zone start
0 // zone index
);
}
// void Foam::surfMesh::oneZone()
// {
// word zoneName;
//
// surfZoneList& zones = Allocator::storedIOZones();
// if (zones.size())
// {
// zoneName = zones[0].name();
// }
// if (zoneName.empty())
// {
// zoneName = "zone0";
// }
//
// // set single default zone
// zones.setSize(1);
// zones[0] = surfZone
// (
// zoneName,
// nFaces(), // zone size
// 0, // zone start
// 0 // zone index
// );
// }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -71,7 +74,7 @@ void Foam::surfMesh::oneZone()
Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
:
surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
surfMeshAllocator
Allocator
(
IOobject
(
@ -90,11 +93,7 @@ Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
*this,
IOobject::MUST_READ,
IOobject::NO_WRITE
)
),
MeshReference(storedFaces_, storedPoints_),
surfZones_
(
IOobject
(
"surfZones",
@ -104,7 +103,8 @@ Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
IOobject::MUST_READ,
IOobject::NO_WRITE
)
)
),
MeshReference(this->storedIOFaces(), this->storedIOPoints())
{}
@ -117,7 +117,7 @@ Foam::surfMesh::surfMesh
)
:
surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
surfMeshAllocator
Allocator
(
IOobject
(
@ -138,11 +138,7 @@ Foam::surfMesh::surfMesh
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
faceLst
),
MeshReference(storedFaces_, storedPoints_),
surfZones_
(
faceLst,
IOobject
(
"surfZones",
@ -151,8 +147,10 @@ Foam::surfMesh::surfMesh
*this,
IOobject::NO_READ,
IOobject::AUTO_WRITE
)
)
),
Xfer<surfZoneList>()
),
MeshReference(this->storedIOFaces(), this->storedIOPoints())
{}
@ -164,7 +162,7 @@ Foam::surfMesh::surfMesh
)
:
surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
surfMeshAllocator
Allocator
(
IOobject
(
@ -185,11 +183,7 @@ Foam::surfMesh::surfMesh
IOobject::NO_READ,
IOobject::AUTO_WRITE
),
faceList()
),
MeshReference(storedFaces_, storedPoints_),
surfZones_
(
faceList(),
IOobject
(
"surfZones",
@ -200,9 +194,21 @@ Foam::surfMesh::surfMesh
IOobject::AUTO_WRITE
),
surfZoneList()
)
),
MeshReference(this->storedIOFaces(), this->storedIOPoints())
{
// We can also send Xfer<..>::null just to force initialization
if (debug)
{
Info<<"IOobject: " << io.path() << nl
<<" name: " << io.name()
<<" instance: " << io.instance()
<<" local: " << io.local()
<<" dbDir: " << io.db().dbDir() << endl;
Info<<"creating surfMesh at instance " << instance() << endl;
Info<<"timeName: " << instance() << endl;
}
// We can also send Xfer<..>::null just to initialize without allocating
if (&surf)
{
transfer(surf());
@ -220,6 +226,30 @@ Foam::surfMesh::~surfMesh()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::surfMesh::updatePointsRef()
{
// assign the reference to the points (this is truly ugly)
reinterpret_cast<SubField<point>&>
(
const_cast<Field<point>&>(MeshReference::points())
) = reinterpret_cast<SubField<point>&>(this->storedPoints());
}
void Foam::surfMesh::updateFacesRef()
{
// assign the reference to the faces
static_cast<UList<face>&>(*this) = this->storedFaces();
}
void Foam::surfMesh::updateRefs()
{
this->updatePointsRef();
this->updateFacesRef();
}
void Foam::surfMesh::resetPrimitives
(
const Xfer< pointField >& points,
@ -231,22 +261,8 @@ void Foam::surfMesh::resetPrimitives
// Clear addressing.
MeshReference::clearGeom();
// Take over new primitive data.
// Optimized to avoid overwriting data at all
if (&points)
{
storedPoints_.transfer(points());
}
if (&faces)
{
storedFaces_.transfer(faces());
}
if (&zones)
{
surfZones_.transfer(zones());
}
Allocator::reset(points, faces, zones);
this->updateRefs();
if (validate)
{
@ -255,6 +271,7 @@ void Foam::surfMesh::resetPrimitives
}
void Foam::surfMesh::transfer
(
MeshedSurface<face>& surf
@ -263,9 +280,11 @@ void Foam::surfMesh::transfer
// Clear addressing.
MeshReference::clearGeom();
storedPoints_.transfer(surf.storedPoints());
storedFaces_.transfer(surf.storedFaces());
surfZones_.transfer(surf.storedZones());
this->storedIOPoints().transfer(surf.storedPoints());
this->storedIOFaces().transfer(surf.storedFaces());
this->storedIOZones().transfer(surf.storedZones());
this->updateRefs();
}
@ -274,9 +293,12 @@ Foam::surfMesh::xfer()
{
Xfer< MeshedSurface<face> > xf;
xf().storedPoints().transfer(storedPoints_);
xf().storedFaces().transfer(storedFaces_);
xf().storedZones().transfer(surfZones_);
xf().storedPoints().transfer(this->storedPoints());
xf().storedFaces().transfer(this->storedFaces());
xf().storedZones().transfer(this->storedZones());
// is this needed?
this->updateRefs();
// Clear addressing.
MeshReference::clearGeom();
@ -285,17 +307,6 @@ Foam::surfMesh::xfer()
}
void Foam::surfMesh::rename(const word& newName)
{
FatalErrorIn
(
"surfMesh::rename(const word&)\n"
)
<< "rename does not work correctly\n";
}
Foam::fileName Foam::surfMesh::meshDir() const
{
return dbDir()/meshSubDir;
@ -304,51 +315,53 @@ Foam::fileName Foam::surfMesh::meshDir() const
const Foam::fileName& Foam::surfMesh::pointsInstance() const
{
return storedPoints_.instance();
return this->storedIOPoints().instance();
}
const Foam::fileName& Foam::surfMesh::facesInstance() const
{
return storedFaces_.instance();
return this->storedIOFaces().instance();
}
Foam::label Foam::surfMesh::nPoints() const
{
return storedPoints_.size();
return this->points().size();
}
Foam::label Foam::surfMesh::nFaces() const
{
return storedFaces_.size();
return this->faces().size();
}
const Foam::pointField& Foam::surfMesh::points() const
{
return storedPoints_;
return this->storedIOPoints();
}
const Foam::faceList& Foam::surfMesh::faces() const
{
return storedFaces_;
return this->storedIOFaces();
}
void Foam::surfMesh::checkZones()
{
// extra safety, ensure we have at some zones
// and they cover all the faces - fix start silently
if (surfZones_.size() <= 1)
surfZoneList& zones = Allocator::storedIOZones();
if (zones.size() <= 1)
{
oneZone();
removeZones();
}
else
{
label count = 0;
forAll(surfZones_, zoneI)
forAll(zones, zoneI)
{
surfZones_[zoneI].start() = count;
count += surfZones_[zoneI].size();
zones[zoneI].start() = count;
count += zones[zoneI].size();
}
if (count < nFaces())
@ -361,7 +374,7 @@ void Foam::surfMesh::checkZones()
<< " ... extending final zone"
<< endl;
surfZones_[surfZones_.size()-1].size() += count - nFaces();
zones[zones.size()-1].size() += count - nFaces();
}
else if (count > size())
{
@ -379,15 +392,15 @@ void Foam::surfMesh::checkZones()
// Add boundary patches. Constructor helper
void Foam::surfMesh::addZones
(
const surfZoneList& zones,
const surfZoneList& srfZones,
const bool validate
)
{
surfZones_.setSize(zones.size());
surfZoneList& zones = Allocator::storedIOZones();
forAll(surfZones_, zoneI)
forAll(zones, zoneI)
{
surfZones_[zoneI] = surfZone(zones[zoneI], zoneI);
zones[zoneI] = surfZone(srfZones[zoneI], zoneI);
}
if (validate)
@ -412,4 +425,22 @@ void Foam::surfMesh::removeFiles() const
removeFiles(instance());
}
void Foam::surfMesh::write(const fileName& name, const surfMesh& surf)
{
MeshedSurfaceProxy<face>
(
surf.points(),
surf.faces(),
surf.surfZones()
).write(name);
}
void Foam::surfMesh::write(const fileName& name)
{
write(name, *this);
}
// ************************************************************************* //

View File

@ -39,66 +39,16 @@ SourceFiles
#define surfMesh_H
#include "surfaceRegistry.H"
#include "MeshedSurfaceIOAllocator.H"
#include "PrimitivePatch.H"
#include "pointField.H"
#include "faceList.H"
#include "pointIOField.H"
#include "faceIOList.H"
#include "labelIOList.H"
#include "surfZoneIOList.H"
#include "SubField.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
template<class Face>
class MeshedSurface;
/*---------------------------------------------------------------------------*\
Class surfMeshAllocator Declaration
\*---------------------------------------------------------------------------*/
//- A helper class for storing points and faces
class surfMeshAllocator
{
protected:
pointIOField storedPoints_;
faceIOList storedFaces_;
surfMeshAllocator(const IOobject& ioPoints, const IOobject& ioFaces)
:
storedPoints_(ioPoints),
storedFaces_(ioFaces)
{}
surfMeshAllocator
(
const IOobject& ioPoints,
const pointField& points,
const IOobject& ioFaces,
const faceList& faces
)
:
storedPoints_(ioPoints, points),
storedFaces_(ioFaces, faces)
{}
surfMeshAllocator
(
const IOobject& ioPoints,
const Xfer<pointField>& points,
const IOobject& ioFaces,
const Xfer<faceList>& faces
)
:
storedPoints_(ioPoints, points),
storedFaces_(ioFaces, faces)
{}
};
template<class Face> class MeshedSurface;
/*---------------------------------------------------------------------------*\
Class surfMesh Declaration
@ -107,8 +57,8 @@ protected:
class surfMesh
:
public surfaceRegistry,
public surfMeshAllocator,
public PrimitivePatch<face, ::Foam::UList, const pointField&, point>
private MeshedSurfaceIOAllocator,
public PrimitivePatch<face, ::Foam::UList, ::Foam::SubField<point>, point>
{
public:
@ -117,8 +67,7 @@ public:
//- Enumeration defining the state of the mesh after a read update.
// Used for post-processing applications, where the mesh
// needs to update based on the files written in time
// directores
// needs to update based on the files written in time directores
enum readUpdateState
{
UNCHANGED,
@ -132,28 +81,23 @@ private:
// Private typedefs
typedef MeshedSurfaceIOAllocator Allocator;
typedef PrimitivePatch
<
face,
::Foam::UList,
const pointField&,
::Foam::SubField<point>,
point
>
MeshReference;
// Permanent data
// Zoning information
//- Face zones
surfZoneIOList surfZones_;
// Private member functions
//- Set a single zone
void oneZone();
//- Disallow construct as copy
surfMesh(const surfMesh&);
@ -165,23 +109,33 @@ protected:
// Protected Member Functions
//- Non-const access to global points
pointIOField& storedPoints()
pointField& storedPoints()
{
return surfMeshAllocator::storedPoints_;
return Allocator::storedIOPoints();
}
//- Non-const access to the faces
faceIOList& storedFaces()
faceList& storedFaces()
{
return surfMeshAllocator::storedFaces_;
return Allocator::storedIOFaces();
}
//- Non-const access to the zones
surfZoneIOList& storedZones()
surfZoneList& storedZones()
{
return surfZones_;
return Allocator::storedIOZones();
}
//- Update references to storedFaces
virtual void updateFacesRef();
//- Update references to storedPoints
virtual void updatePointsRef();
//- Update references to storedPoints/storedFaces
virtual void updateRefs();
public:
// Public typedefs
@ -247,10 +201,10 @@ public:
// Access
//- Return raw points
//- Return the number of raw points
virtual label nPoints() const;
//- Return raw faces
//- Return the number of raw faces
virtual label nFaces() const;
//- Return number of faces
@ -260,28 +214,22 @@ public:
}
//- Return raw points
//- Return points
virtual const pointField& points() const;
//- Return raw faces
//- Return faces
virtual const faceList& faces() const;
//- Return surface zones
const surfZoneList& surfZones() const
virtual const surfZoneList& surfZones() const
{
return surfZones_;
}
//- Return non-const access to the zones
surfZoneList& surfZones()
{
return surfZones_;
return Allocator::storedIOZones();
}
//- Check the surface zone definitions
void checkZones();
//- Add surface zones patches
//- Add surface zones
void addZones
(
const List<surfZone>&,
@ -297,9 +245,6 @@ public:
//- Remove surface zones
void removeZones();
//- Rename surface
virtual void rename(const word&);
//- Reset mesh primitive data.
void resetPrimitives
(
@ -313,6 +258,18 @@ public:
//- Transfer the contents of the argument and annull the argument
void transfer(MeshedSurface<face>&);
using surfaceRegistry::write;
//- Write to file
static void write(const fileName&, const surfMesh&);
//- Write to file
void write(const fileName&);
// Storage management
//- Transfer contents to the Xfer container as a MeshedSurface

View File

@ -40,7 +40,7 @@ void Foam::surfMesh::removeZones()
}
// Remove the surface zones
surfZones_.clear();
storedZones().clear();
clearOut();
}

View File

@ -31,20 +31,22 @@ License
void Foam::surfMesh::setInstance(const fileName& inst)
{
if (debug)
if (debug or true)
{
Info<< "void surfMesh::setInstance(const fileName& inst) : "
<< "Resetting file instance to " << inst << endl;
}
storedPoints_.writeOpt() = IOobject::AUTO_WRITE;
storedPoints_.instance() = inst;
instance() = inst;
storedFaces_.writeOpt() = IOobject::AUTO_WRITE;
storedFaces_.instance() = inst;
storedIOPoints().writeOpt() = IOobject::AUTO_WRITE;
storedIOPoints().instance() = inst;
surfZones_.writeOpt() = IOobject::AUTO_WRITE;
surfZones_.instance() = inst;
storedIOFaces().writeOpt() = IOobject::AUTO_WRITE;
storedIOFaces().instance() = inst;
storedIOZones().writeOpt() = IOobject::AUTO_WRITE;
storedIOZones().instance() = inst;
}
@ -81,9 +83,9 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
// Set instance to new instance.
// Note points instance can differ from faces instance.
setInstance(facesInst);
storedPoints_.instance() = pointsInst;
storedIOPoints().instance() = pointsInst;
storedPoints_ = pointIOField
storedIOPoints() = pointIOField
(
IOobject
(
@ -97,7 +99,7 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
)
);
storedFaces_ = faceIOList
storedFaces() = faceIOList
(
IOobject
(
@ -111,9 +113,6 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
)
);
// synchronize sizes and references?
// MeshReference::operator=(MeshReference(storedFaces_, storedPoints_));
// Reset the surface zones
surfZoneIOList newZones
(
@ -132,15 +131,16 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
// Check that zone types and names are unchanged
bool zonesChanged = false;
if (surfZones_.size() != newZones.size())
surfZoneList& zones = this->storedIOZones();
if (zones.size() != newZones.size())
{
zonesChanged = true;
}
else
{
forAll (surfZones_, zoneI)
forAll(zones, zoneI)
{
if (surfZones_[zoneI].name() != newZones[zoneI].name())
if (zones[zoneI].name() != newZones[zoneI].name())
{
zonesChanged = true;
break;
@ -148,7 +148,7 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
}
}
surfZones_.transfer(newZones);
zones.transfer(newZones);
if (zonesChanged)
{
@ -173,10 +173,9 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
}
clearGeom();
storedIOPoints().instance() = pointsInst;
storedPoints_.instance() = pointsInst;
storedPoints_ = pointIOField
storedIOPoints() = pointIOField
(
IOobject
(
@ -204,4 +203,6 @@ Foam::surfMesh::readUpdateState Foam::surfMesh::readUpdate()
}
// ************************************************************************* //

View File

@ -26,7 +26,6 @@ License
#include "AC3DsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "tensor.H"
#include "primitivePatch.H"
@ -281,26 +280,65 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
template<class Face>
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
(
Ostream& os,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
writeHeader(os, zoneLst);
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
forAll(zoneLst, zoneI)
const List<surfZone>& zones =
(
surf.surfZones().size()
? surf.surfZones()
: oneZone(faceLst)
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
if (useFaceMap)
{
const surfZone& zone = zoneLst[zoneI];
FatalErrorIn
(
"fileFormats::AC3DsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "output with faceMap is not supported " << filename
<< exit(FatalError);
}
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::AC3DsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
writeHeader(os, zones);
forAll(zones, zoneI)
{
const surfZone& zone = zones[zoneI];
os << "OBJECT poly" << nl
<< "name \"" << zone.name() << '"' << endl;
<< "name \"" << zone.name() << "\"\n";
// Temporary PrimitivePatch to calculate compact points & faces
// use 'UList' to avoid allocations!
PrimitivePatch<Face, UList, const pointField&> patch
(
SubList<Face>
(
faceLst,
zone.size(),
zone.start()
),
pointLst
);
@ -310,7 +348,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
{
const point& pt = patch.localPoints()[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
os << "numsurf " << patch.localFaces().size() << endl;
@ -337,24 +375,40 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
template<class Face>
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
(
Ostream& os,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
(
Ostream& os,
const fileName& filename,
const UnsortedMeshedSurface<Face>& surf
)
{
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
if (zoneLst.size() <= 1)
{
write
(
filename,
MeshedSurfaceProxy<Face>
(
surf.points(),
surf.faces(),
zoneLst
)
);
}
else
{
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::AC3DsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
writeHeader(os, zoneLst);
label faceIndex = 0;
@ -363,7 +417,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
const surfZone& zone = zoneLst[zoneI];
os << "OBJECT poly" << nl
<< "name \"" << zone.name() << '"' << endl;
<< "name \"" << zone.name() << "\"\n";
// Create zone with only zone faces included for ease of addressing
labelHashSet include(surf.size());
@ -405,6 +459,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
os << "kids 0" << endl;
}
}
}
// ************************************************************************* //

View File

@ -31,8 +31,9 @@ Description
http://www.inivis.com/ac3d/man/ac3dfileformat.html
Note
The faces are already organized as zones.
On input, the faces are already organized as zones.
The output is always sorted by zones.
In the absence of zones, a single zone will be assigned.
SourceFiles
AC3DsurfaceFormat.C
@ -42,9 +43,8 @@ SourceFiles
#ifndef AC3DsurfaceFormat_H
#define AC3DsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "AC3DsurfaceFormatCore.H"
@ -99,58 +99,20 @@ public:
// Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Write UnsortedMeshedSurface, the output is always sorted by zones.
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
//- Read from file
virtual bool read(const fileName&);
//- Write surface mesh components
static void write
(
Ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write MeshedSurface
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write MeshedSurface
static void write
(
const fileName& name,
const MeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write UnsortedMeshedSurface
// The output is always sorted by zones.
static void write
(
Ostream&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// The output is always sorted by zones.
static void write
(
const fileName& name,
const UnsortedMeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
virtual void write(const fileName& name) const
{
write(os, *this);
write(name, MeshedSurfaceProxy<Face>(*this));
}
};

View File

@ -36,10 +36,10 @@ SourceFiles
#ifndef AC3DsurfaceFormatCore_H
#define AC3DsurfaceFormatCore_H
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "AC3DsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats
{
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable
ac
);
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
AC3DsurfaceFormat,
face,
write,
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
AC3DsurfaceFormat,
triFace,
write,
@ -74,6 +74,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
// write UnsortedMeshedSurface
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,

View File

@ -26,7 +26,8 @@ Class
Foam::fileFormats::FTRsurfaceFormat
Description
Reading of the (now deprecated and barely used) Foam Trisurface Format.
Reading of the (now deprecated and infrequently used)
Foam Trisurface Format.
SourceFiles
FTRsurfaceFormat.C

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "FTRsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats
{
// read UnsortedMeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
UnsortedMeshedSurface,

View File

@ -25,9 +25,12 @@ License
\*---------------------------------------------------------------------------*/
#include "GTSsurfaceFormat.H"
#include "surfaceFormatsCore.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "Ostream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -217,6 +220,7 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
}
this->storedZoneToc().transfer(newZones);
return true;
}
@ -224,19 +228,24 @@ bool Foam::fileFormats::GTSsurfaceFormat<Face>::read
template<class Face>
void Foam::fileFormats::GTSsurfaceFormat<Face>::write
(
Ostream& os,
const fileName& filename,
const MeshedSurface<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<surfZone>& zoneLst = surf.zones();
const List<surfZone>& zones =
(
surf.surfZones().size()
? surf.surfZones()
: surfaceFormatsCore::oneZone(faceLst)
);
// check if output triangulation would be required
// It is too annoying to triangulate on-the-fly
// just issue a warning and get out
if (!surf.isTri())
if (!MeshedSurface<Face>::isTri())
{
label nNonTris = 0;
forAll(faceLst, faceI)
@ -252,7 +261,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
FatalErrorIn
(
"fileFormats::GTSsurfaceFormat::write"
"(Ostream&, const MeshedSurface<Face>&)"
"(const fileName&, const MeshedSurface<Face>&)"
)
<< "Surface has " << nNonTris << "/" << faceLst.size()
<< " non-triangulated faces - not writing!" << endl;
@ -260,16 +269,30 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
}
}
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::GTSsurfaceFormat::write"
"(const fileName&, const MeshedSurface<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
// Write header, print zone names as comment
os << "# GTS file" << nl
<< "# Zones:" << nl;
forAll(zoneLst, zoneI)
forAll(zones, zoneI)
{
os << "# " << zoneI << " "
<< zoneLst[zoneI].name() << nl;
<< zones[zoneI].name() << nl;
}
os << "#" << endl;
os << "#" << nl;
os << "# nPoints nEdges nTriangles" << nl
<< pointLst.size() << ' ' << surf.nEdges() << ' '
@ -279,9 +302,9 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
// Write vertex coords
forAll(pointLst, pointI)
{
os << pointLst[pointI].x() << ' '
<< pointLst[pointI].y() << ' '
<< pointLst[pointI].z() << endl;
const point& pt = pointLst[pointI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
@ -300,9 +323,9 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
const labelListList& faceEs = surf.faceEdges();
label faceIndex = 0;
forAll(zoneLst, zoneI)
forAll(zones, zoneI)
{
const surfZone& zone = zoneLst[zoneI];
const surfZone& zone = zones[zoneI];
forAll(zone, localFaceI)
{
@ -320,7 +343,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
template<class Face>
void Foam::fileFormats::GTSsurfaceFormat<Face>::write
(
Ostream& os,
const fileName& filename,
const UnsortedMeshedSurface<Face>& surf
)
{
@ -332,7 +355,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
// check if output triangulation would be required
// It is too annoying to triangulate on-the-fly
// just issue a warning and get out
if (!surf.isTri())
if (!MeshedSurface<Face>::isTri())
{
label nNonTris = 0;
forAll(faceLst, faceI)
@ -348,7 +371,7 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
FatalErrorIn
(
"fileFormats::GTSsurfaceFormat::write"
"(Ostream&, const UnsortedMeshedSurfaces<Face>&)"
"(const fileName&, const UnsortedMeshedSurfaces<Face>&)"
)
<< "Surface has " << nNonTris << "/" << faceLst.size()
<< " non-triangulated faces - not writing!" << endl;
@ -356,6 +379,20 @@ void Foam::fileFormats::GTSsurfaceFormat<Face>::write
}
}
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::GTSsurfaceFormat::write"
"(const fileName&, const UnsortedMeshedSurface<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
// Write header, print zone names as comment
os << "# GTS file" << nl
<< "# Zones:" << nl;

View File

@ -27,7 +27,8 @@ Class
Description
Provide a means of reading/writing GTS format.
The output is never sorted by zone.
The output is never sorted by zone and is only written if it consists
entirely of triangles.
SourceFiles
GTSsurfaceFormat.C
@ -37,9 +38,8 @@ SourceFiles
#ifndef GTSsurfaceFormat_H
#define GTSsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -90,49 +90,20 @@ public:
// Member Functions
//- Write MeshedSurface
static void write(const fileName&, const MeshedSurface<Face>&);
//- Write UnsortedMeshedSurface, the output remains unsorted
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
//- Read from file
virtual bool read(const fileName&);
//- Write MeshedSurface
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write MeshedSurface
static void write
(
const fileName& name,
const MeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write UnsortedMeshedSurface
// The output remains unsorted
static void write
(
Ostream&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// The output remains unsorted
static void write
(
const fileName& name,
const UnsortedMeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
virtual void write(const fileName& name) const
{
write(os, *this);
write(name, *this);
}
};

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "GTSsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats
{
// read UnsortedMeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
UnsortedMeshedSurface,
@ -53,6 +53,7 @@ addNamedTemplatedToRunTimeSelectionTable
gts
);
// write MeshedSurface
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
@ -72,6 +73,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
gts
);
// write UnsortedMeshedSurface
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,

View File

@ -76,6 +76,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
Map<label> lookup;
// assume the types are not intermixed
// leave faces that didn't have a group in 0
bool sorted = true;
label zoneI = 0;
@ -89,10 +90,6 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
label ansaId = -1;
word ansaType, ansaName;
// leave faces that didn't have a group in 0
// label groupID = 0;
// label maxGroupID = -1;
// A single warning per unrecognized command
HashSet<word> unhandledCmd;
@ -388,7 +385,6 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
}
}
sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
// add zones, culling empty ones

View File

@ -44,9 +44,8 @@ SourceFiles
#ifndef NASsurfaceFormat_H
#define NASsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "NASsurfaceFormatCore.H"

View File

@ -25,14 +25,13 @@ License
\*---------------------------------------------------------------------------*/
#include "NASsurfaceFormatCore.H"
#include "IFstream.H"
#include "IStringStream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// Do weird things to extract number
// Do weird things to extract a floating point number
Foam::scalar Foam::fileFormats::NASsurfaceFormatCore::parseNASCoord
(
const string& s

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "NASsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,8 +35,7 @@ namespace Foam
namespace fileFormats
{
// .bdf (Bulk Data Format)
// .nas (Nastran)
// read MeshedSurface - .bdf (Bulk Data Format)
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
@ -55,6 +53,7 @@ addNamedTemplatedToRunTimeSelectionTable
nas
);
// read MeshedSurface - .nas (Nastran)
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,

View File

@ -25,8 +25,11 @@ License
\*---------------------------------------------------------------------------*/
#include "OBJsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "Ostream.H"
#include "OFstream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -213,70 +216,79 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
template<class Face>
void Foam::fileFormats::OBJsurfaceFormat<Face>::write
(
Ostream& os,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
)
{
writeHeader(os, pointLst, faceLst.size(), zoneLst);
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
const surfZone& zone = zoneLst[zoneI];
os << "g " << zone.name() << endl;
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceIndex++];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << endl;
}
}
os << "# </faces>" << endl;
}
template<class Face>
void Foam::fileFormats::OBJsurfaceFormat<Face>::write
(
Ostream& os,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::OBJsurfaceFormat<Face>::write
(
Ostream& os,
const UnsortedMeshedSurface<Face>& surf
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
// for no zones, suppress the group name
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst, "")
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::OBJsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
<< "o " << os.name().lessExt().name() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << faceLst.size() << nl
<< "# zones : " << zones.size() << nl;
// Print zone names as comment
forAll(zones, zoneI)
{
os << "# " << zoneI << " " << zones[zoneI].name()
<< " (nFaces: " << zones[zoneI].size() << ")" << nl;
}
os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << nl;
// Write vertex coords
forAll(pointLst, ptI)
{
const point& pt = pointLst[ptI];
os << "v " << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
writeHeader(os, surf.points(), faceLst.size(), zoneLst);
label faceIndex = 0;
forAll(zoneLst, zoneI)
forAll(zones, zoneI)
{
// Print all faces belonging to this zone
const surfZone& zone = zoneLst[zoneI];
const surfZone& zone = zones[zoneI];
if (zone.name().size())
{
os << "g " << zone.name() << endl;
}
if (useFaceMap)
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
@ -289,8 +301,23 @@ void Foam::fileFormats::OBJsurfaceFormat<Face>::write
os << endl;
}
}
else
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceIndex++];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << endl;
}
}
}
os << "# </faces>" << endl;
}
// ************************************************************************* //

View File

@ -38,11 +38,9 @@ SourceFiles
#ifndef OBJsurfaceFormat_H
#define OBJsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "OBJsurfaceFormatCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,8 +56,7 @@ namespace fileFormats
template<class Face>
class OBJsurfaceFormat
:
public MeshedSurface<Face>,
public OBJsurfaceFormatCore
public MeshedSurface<Face>
{
// Private Member Functions
@ -95,58 +92,16 @@ public:
// Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Read from file
virtual bool read(const fileName&);
//- Write surface mesh components
static void write
(
Ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write MeshedSurface
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write MeshedSurface
static void write
(
const fileName& name,
const MeshedSurface<Face>& surf
)
//- Write object file
virtual void write(const fileName& name) const
{
write(OFstream(name)(), surf);
}
//- Write UnsortedMeshedSurface
// The output is sorted by zones
static void write
(
Ostream&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// The output is sorted by zones
static void write
(
const fileName& name,
const UnsortedMeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
write(name, MeshedSurfaceProxy<Face>(*this));
}
};

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "OBJsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats
{
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable
obj
);
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
OBJsurfaceFormat,
face,
write,
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
OBJsurfaceFormat,
triFace,
write,
@ -73,26 +73,6 @@ addNamedTemplatedToMemberFunctionSelectionTable
obj
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
OBJsurfaceFormat,
face,
write,
fileExtension,
obj
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
OBJsurfaceFormat,
triFace,
write,
fileExtension,
obj
);
}
}

View File

@ -25,8 +25,11 @@ License
\*---------------------------------------------------------------------------*/
#include "OFFsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "Ostream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -60,7 +63,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
{
FatalErrorIn
(
"fileFormats::OFFsurfaceFormat<Face>::read(const fileName&)"
"fileFormats::OFFsurfaceFormat::read(const fileName&)"
)
<< "Cannot read file " << filename
<< exit(FatalError);
@ -72,7 +75,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
{
FatalErrorIn
(
"fileFormats::OFFsurfaceFormat<Face>::read(const fileName&)"
"fileFormats::OFFsurfaceFormat::read(const fileName&)"
)
<< "OFF file " << filename << " does not start with 'OFF'"
<< exit(FatalError);
@ -142,11 +145,9 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
}
}
// transfer to normal lists
reset(pointLst.xfer(), dynFaces.xfer());
// transfer to normal lists, no zone information
reset(pointLst.xfer(), dynFaces.xfer(), Xfer<surfZoneList>());
// no zone information
this->oneZone();
return true;
}
@ -154,68 +155,67 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
template<class Face>
void Foam::fileFormats::OFFsurfaceFormat<Face>::write
(
Ostream& os,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
)
{
writeHeader(os, pointLst, faceLst.size(), zoneLst);
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
os << "# <zone name=\"" << zoneLst[zoneI].name() << "\">" << endl;
forAll(zoneLst[zoneI], localFaceI)
{
const Face& f = faceLst[faceIndex++];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
// add optional zone information
os << ' ' << zoneI << endl;
}
os << "# </zone>" << endl;
}
os << "# </faces>" << endl;
}
template<class Face>
void Foam::fileFormats::OFFsurfaceFormat<Face>::write
(
Ostream& os,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::OFFsurfaceFormat<Face>::write
(
Ostream& os,
const UnsortedMeshedSurface<Face>& surf
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
const List<surfZone>& zoneLst = surf.surfZones();
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::OFFsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
writeHeader(os, surf.points(), faceLst.size(), zoneLst);
// Write header
os << "OFF" << endl
<< "# Geomview OFF file written " << clock::dateTime().c_str() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << faceLst.size() << nl
<< "# zones : " << zoneLst.size() << nl;
// Print zone names as comment
forAll(zoneLst, zoneI)
{
os << "# " << zoneI << " " << zoneLst[zoneI].name()
<< " (nFaces: " << zoneLst[zoneI].size() << ")" << nl;
}
os << nl
<< "# nPoints nFaces nEdges" << nl
<< pointLst.size() << ' ' << faceLst.size() << ' ' << 0 << nl
<< nl
<< "# <points count=\"" << pointLst.size() << "\">" << endl;
// Write vertex coords
forAll(pointLst, ptI)
{
os << pointLst[ptI].x() << ' '
<< pointLst[ptI].y() << ' '
<< pointLst[ptI].z() << " #" << ptI << endl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
os << "# <zone name=\"" << zoneLst[zoneI].name() << "\">" << endl;
if (surf.useFaceMap())
{
forAll(zoneLst[zoneI], localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
@ -229,6 +229,23 @@ void Foam::fileFormats::OFFsurfaceFormat<Face>::write
// add optional zone information
os << ' ' << zoneI << endl;
}
}
else
{
forAll(zoneLst[zoneI], localFaceI)
{
const Face& f = faceLst[faceIndex++];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
// add optional zone information
os << ' ' << zoneI << endl;
}
}
os << "# </zone>" << endl;
}
os << "# </faces>" << endl;

View File

@ -46,11 +46,9 @@ SourceFiles
#ifndef OFFsurfaceFormat_H
#define OFFsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "OFFsurfaceFormatCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -66,8 +64,7 @@ namespace fileFormats
template<class Face>
class OFFsurfaceFormat
:
public MeshedSurface<Face>,
public OFFsurfaceFormatCore
public MeshedSurface<Face>
{
// Private Member Functions
@ -101,58 +98,17 @@ public:
// Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Read from file
virtual bool read(const fileName&);
//- Write surface mesh components
static void write
(
Ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write MeshedSurface
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write MeshedSurface
static void write
(
const fileName& name,
const MeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write UnsortedMeshedSurface
// The output is sorted by zone.
static void write
(
Ostream&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// The output is sorted by zone.
static void write
(
const fileName& name,
const UnsortedMeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
virtual void write(const fileName& name) const
{
write(os, *this);
write(name, MeshedSurfaceProxy<Face>(*this));
}
};

View File

@ -1,78 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "OFFsurfaceFormatCore.H"
#include "clock.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fileFormats::OFFsurfaceFormatCore::writeHeader
(
Ostream& os,
const pointField& pointLst,
const label nFaces,
const UList<surfZone>& zoneLst
)
{
// Write header
os << "OFF" << endl
<< "# Geomview OFF file written " << clock::dateTime().c_str() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << nFaces << nl
<< "# zones : " << zoneLst.size() << nl;
// Print zone names as comment
forAll(zoneLst, zoneI)
{
os << "# " << zoneI << " " << zoneLst[zoneI].name()
<< " (nFaces: " << zoneLst[zoneI].size() << ")" << nl;
}
os << nl
<< "# nPoints nFaces nEdges" << nl
<< pointLst.size() << ' ' << nFaces << ' ' << 0 << nl;
os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << endl;
// Write vertex coords
forAll(pointLst, ptI)
{
os << pointLst[ptI].x() << ' '
<< pointLst[ptI].y() << ' '
<< pointLst[ptI].z() << " #" << ptI << endl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << nFaces << "\">" << endl;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "OFFsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats
{
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable
off
);
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
OFFsurfaceFormat,
face,
write,
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
OFFsurfaceFormat,
triFace,
write,
@ -74,25 +74,6 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
OFFsurfaceFormat,
face,
write,
fileExtension,
off
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
OFFsurfaceFormat,
triFace,
write,
fileExtension,
off
);
}
}

View File

@ -0,0 +1,260 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "OFSsurfaceFormat.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "ListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
Foam::fileFormats::OFSsurfaceFormat<Face>::OFSsurfaceFormat
(
const fileName& filename
)
{
read(filename);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Face>
bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
(
const fileName& filename
)
{
this->clear();
IFstream is(filename);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::OFSsurfaceFormat::read(const fileName&)"
)
<< "Cannot read file " << filename
<< exit(FatalError);
}
// read surfZones:
is >> this->storedZones();
// read points:
is >> this->storedPoints();
// must triangulate?
if (MeshedSurface<Face>::isTri())
{
// read faces as 'face' and transcribe to 'triFace'
List<face> faceLst(is);
MeshedSurface<face> surf
(
xferMove(this->storedPoints()),
xferMove(faceLst),
xferMove(this->storedZones())
);
this->transcribe(surf);
}
else
{
// read faces directly
is >> this->storedFaces();
}
return true;
}
template<class Face>
bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
(
Istream& is,
pointField& pointLst,
List<Face>& faceLst,
List<surfZone>& zoneLst
)
{
if (!is.good())
{
FatalErrorIn
(
"fileFormats::OFSsurfaceFormat::read"
"(Istream&, pointField&, List<Face>&, List<surfZone>&)"
)
<< "read error "
<< exit(FatalError);
}
// read surfZones:
is >> zoneLst;
// read points:
is >> pointLst;
// must triangulate?
if (MeshedSurface<Face>::isTri())
{
// read faces as 'face' and transcribe to 'triFace'
List<face> origFaces(is);
MeshedSurface<face> origSurf
(
xferMove(pointLst),
xferMove(origFaces),
xferMove(zoneLst)
);
MeshedSurface<Face> surf;
surf.transcribe(origSurf);
}
else
{
// read faces directly
is >> faceLst;
}
return true;
}
template<class Face>
bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
(
Istream& is,
MeshedSurface<Face>& surf
)
{
surf.clear();
if (!is.good())
{
FatalErrorIn
(
"fileFormats::OFSsurfaceFormat::read"
"(Istream&, MeshedSurface<Face>&)"
)
<< "read error "
<< exit(FatalError);
}
pointField pointLst;
List<Face> faceLst;
List<surfZone> zoneLst;
read(is, pointLst, faceLst, zoneLst);
surf.reset
(
xferMove(pointLst),
xferMove(faceLst),
xferMove(zoneLst)
);
return true;
}
template<class Face>
bool Foam::fileFormats::OFSsurfaceFormat<Face>::read
(
Istream& is,
UnsortedMeshedSurface<Face>& surf
)
{
surf.clear();
MeshedSurface<Face> origSurf(is);
surf.transfer(origSurf);
return true;
}
template<class Face>
void Foam::fileFormats::OFSsurfaceFormat<Face>::write
(
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::OFSsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
OFSsurfaceFormatCore::writeHeader(os, surf.points(), surf.surfZones());
const List<surfZone>& zones = surf.surfZones();
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
if (useFaceMap)
{
os << "\n// faces:" << nl
<< faceLst.size() << token::BEGIN_LIST << nl;
label faceI = 0;
forAll(zones, zoneI)
{
// Print all faces belonging to this zone
const surfZone& zone = zones[zoneI];
forAll(zone, localFaceI)
{
os << faceLst[faceMap[faceI++]] << nl;
}
}
os << token::END_LIST << nl;
}
else
{
os << "\n// faces:" << nl << faceLst << nl;
}
IOobject::writeDivider(os);
// Check state of Ostream
os.check("OFSsurfaceFormat<Face>::write(Ostream&)");
}
// ************************************************************************* //

View File

@ -0,0 +1,155 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::OFSsurfaceFormat
Description
Provide a means of reading/writing the single-file OpenFOAM surface format.
Note
This class provides more methods than the regular surface format interface.x
SourceFiles
OFSsurfaceFormat.C
\*---------------------------------------------------------------------------*/
#ifndef OFSsurfaceFormat_H
#define OFSsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "OFSsurfaceFormatCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class OFSsurfaceFormat Declaration
\*---------------------------------------------------------------------------*/
template<class Face>
class OFSsurfaceFormat
:
public MeshedSurface<Face>,
public OFSsurfaceFormatCore
{
// Private Member Functions
//- Disallow default bitwise copy construct
OFSsurfaceFormat(const OFSsurfaceFormat<Face>&);
//- Disallow default bitwise assignment
void operator=(const OFSsurfaceFormat<Face>&);
public:
// Constructors
//- Construct from file name
OFSsurfaceFormat(const fileName&);
// Selectors
//- Read file and return surface
static autoPtr<MeshedSurface<Face> > New(const fileName& name)
{
return autoPtr<MeshedSurface<Face> >
(
new OFSsurfaceFormat<Face>(name)
);
}
// Destructor
virtual ~OFSsurfaceFormat()
{}
// Member Functions
//- Read surface mesh components
static bool read
(
Istream&,
pointField&,
List<Face>&,
List<surfZone>&
);
//- Read MeshedSurface
static bool read
(
Istream&,
MeshedSurface<Face>&
);
//- Read UnsortedMeshedSurface
// The output is sorted by zones
static bool read
(
Istream&,
UnsortedMeshedSurface<Face>&
);
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Read from file
virtual bool read(const fileName&);
//- Write object
virtual void write(const fileName& name) const
{
write(name, MeshedSurfaceProxy<Face>(*this));
}
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "OFSsurfaceFormat.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View File

@ -24,50 +24,52 @@ License
\*---------------------------------------------------------------------------*/
#include "OBJsurfaceFormatCore.H"
#include "OFSsurfaceFormatCore.H"
#include "clock.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fileFormats::OBJsurfaceFormatCore::writeHeader
void Foam::fileFormats::OFSsurfaceFormatCore::writeHeader
(
Ostream& os,
const pointField& pointLst,
const label nFaces,
const UList<surfZone>& zoneLst
)
{
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl
<< "o " << os.name().lessExt().name() << nl
<< nl
<< "# points : " << pointLst.size() << nl
<< "# faces : " << nFaces << nl
<< "# zones : " << zoneLst.size() << nl;
// just emit some information until we get a nice IOobject
IOobject::writeBanner(os)
<< "// OpenFOAM Surface Format - written "
<< clock::dateTime().c_str() << nl
<< "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl << nl
<< "// surfZones:" << nl;
// treat a single zone as being unzoned
if (zoneLst.size() <= 1)
{
os << "0" << token::BEGIN_LIST << token::END_LIST << nl << nl;
}
else
{
os << zoneLst.size() << nl << token::BEGIN_LIST << incrIndent << nl;
// Print zone names as comment
forAll(zoneLst, zoneI)
{
os << "# " << zoneI << " " << zoneLst[zoneI].name()
<< " (nFaces: " << zoneLst[zoneI].size() << ")" << nl;
zoneLst[zoneI].writeDict(os);
}
os << decrIndent << token::END_LIST << nl << nl;
}
os << nl
<< "# <points count=\"" << pointLst.size() << "\">" << endl;
// Note: write with global point numbering
// Write vertex coords
forAll(pointLst, ptI)
{
os << "v " << pointLst[ptI].x()
<< ' ' << pointLst[ptI].y()
<< ' ' << pointLst[ptI].z() << nl;
IOobject::writeDivider(os)
<< "\n// points:" << nl << pointLst << nl;
IOobject::writeDivider(os);
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << nFaces << "\">" << endl;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //

View File

@ -23,18 +23,18 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::OBJsurfaceFormatCore
Foam::fileFormats::OFSsurfaceFormatCore
Description
Internal class used by the OBJsurfaceFormat
Internal class used by the OFSsurfaceFormat
SourceFiles
OBJsurfaceFormatCore.C
OFSsurfaceFormatCore.C
\*---------------------------------------------------------------------------*/
#ifndef OBJsurfaceFormatCore_H
#define OBJsurfaceFormatCore_H
#ifndef OFSsurfaceFormatCore_H
#define OFSsurfaceFormatCore_H
#include "Ostream.H"
#include "OFstream.H"
@ -49,20 +49,19 @@ namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class OBJsurfaceFormatCore Declaration
Class OFSsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/
class OBJsurfaceFormatCore
class OFSsurfaceFormatCore
{
protected:
// Protected Member Functions
//- Write header information with points
//- Write header information and surfZoneList
static void writeHeader
(
Ostream&,
const pointField&,
const label nFaces,
const UList<surfZone>&
);

View File

@ -22,61 +22,60 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::fileFormats::SMESHsurfaceFormatCore
Description
Internal class used by the SMESHsurfaceFormat
SourceFiles
SMESHsurfaceFormatCore.C
\*---------------------------------------------------------------------------*/
#ifndef SMESHsurfaceFormatCore_H
#define SMESHsurfaceFormatCore_H
#include "OFSsurfaceFormat.H"
#include "Ostream.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace fileFormats
{
/*---------------------------------------------------------------------------*\
Class SMESHsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/
class SMESHsurfaceFormatCore
{
protected:
// Protected Member Functions
//- Write header information with points
static void writeHeader
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
Ostream&,
const pointField&,
const label nFaces
MeshedSurface,
OFSsurfaceFormat,
face,
fileExtension,
ofs
);
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
OFSsurfaceFormat,
triFace,
fileExtension,
ofs
);
//- Write tail information
static void writeTail(Ostream&);
};
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurfaceProxy,
OFSsurfaceFormat,
face,
write,
fileExtension,
ofs
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurfaceProxy,
OFSsurfaceFormat,
triFace,
write,
fileExtension,
ofs
);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace fileFormats
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
}
}
// ************************************************************************* //

View File

@ -25,6 +25,10 @@ License
\*---------------------------------------------------------------------------*/
#include "SMESHsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "OFstream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -41,63 +45,64 @@ Foam::fileFormats::SMESHsurfaceFormat<Face>::SMESHsurfaceFormat()
template<class Face>
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
(
Ostream& os,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
)
{
writeHeader(os, pointLst, faceLst.size());
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
forAll(zoneLst[zoneI], localFaceI)
{
const Face& f = faceLst[faceIndex++];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << zoneI << endl;
}
}
writeTail(os);
}
template<class Face>
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
(
Ostream& os,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
(
Ostream& os,
const UnsortedMeshedSurface<Face>& surf
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
writeHeader(os, surf.points(), faceLst.size());
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst)
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::SMESHsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
// Write header
os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl
<< "# <points count=\"" << pointLst.size() << "\">" << nl
<< pointLst.size() << " 3" << nl; // 3: dimensions
// Write vertex coords
forAll(pointLst, ptI)
{
const point& pt = pointLst[ptI];
os << ptI << ' ' << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faceLst.size() << "\">" << endl;
os << faceLst.size() << " 1" << endl; // one attribute: zone number
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
label faceIndex = 0;
forAll(zoneLst, zoneI)
forAll(zones, zoneI)
{
forAll(zoneLst[zoneI], localFaceI)
const surfZone& zone = zones[zoneI];
if (useFaceMap)
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
@ -109,8 +114,29 @@ void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
os << ' ' << zoneI << endl;
}
}
else
{
forAll(zones[zoneI], localFaceI)
{
const Face& f = faceLst[faceIndex++];
writeTail(os);
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << zoneI << endl;
}
}
}
// write tail
os << "# </faces>" << nl
<< nl
<< "# no holes or regions:" << nl
<< '0' << nl // holes
<< '0' << endl; // regions
}

View File

@ -42,12 +42,9 @@ SourceFiles
#ifndef SMESHsurfaceFormat_H
#define SMESHsurfaceFormat_H
#include "IFstream.H"
#include "OFstream.H"
#include "Ostream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "SMESHsurfaceFormatCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,8 +60,7 @@ namespace fileFormats
template<class Face>
class SMESHsurfaceFormat
:
public MeshedSurface<Face>,
public SMESHsurfaceFormatCore
public MeshedSurface<Face>
{
// Private Member Functions
@ -91,55 +87,14 @@ public:
// Member Functions
//- Write surface mesh components
static void write
(
Ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Write MeshedSurface
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write MeshedSurface
static void write
(
const fileName& name,
const MeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write UnsortedMeshedSurface
// The output is sorted by zone.
static void write
(
Ostream&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// The output is sorted by zone.
static void write
(
const fileName& name,
const UnsortedMeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
virtual void write(const fileName& name) const
{
write(os, *this);
write(name, MeshedSurfaceProxy<Face>(*this));
}
};

View File

@ -1,71 +0,0 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 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, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "SMESHsurfaceFormatCore.H"
#include "clock.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fileFormats::SMESHsurfaceFormatCore::writeHeader
(
Ostream& os,
const pointField& pointLst,
const label nFaces
)
{
// Write header
os << "# tetgen .smesh file written " << clock::dateTime().c_str() << nl;
os << "# <points count=\"" << pointLst.size() << "\">" << endl;
os << pointLst.size() << " 3" << nl; // 3: dimensions
// Write vertex coords
forAll(pointLst, ptI)
{
os << ptI
<< ' ' << pointLst[ptI].x()
<< ' ' << pointLst[ptI].y()
<< ' ' << pointLst[ptI].z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << nFaces << "\">" << endl;
os << nFaces << " 1" << endl; // one attribute: zone number
}
void Foam::fileFormats::SMESHsurfaceFormatCore::writeTail(Ostream& os)
{
os << "# </faces>" << nl
<< nl
<< "# no holes or regions:" << nl
<< '0' << nl // holes
<< '0' << endl; // regions
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "SMESHsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,9 +35,10 @@ namespace Foam
namespace fileFormats
{
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
SMESHsurfaceFormat,
face,
write,
@ -47,26 +47,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
SMESHsurfaceFormat,
triFace,
write,
fileExtension,
smesh
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
SMESHsurfaceFormat,
face,
write,
fileExtension,
smesh
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
MeshedSurfaceProxy,
SMESHsurfaceFormat,
triFace,
write,

View File

@ -41,10 +41,10 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
)
{
os << cellId // includes 1 offset
<< " " << starcdShellShape_ // 3(shell) shape
<< " " << f.size()
<< " " << cellTableId
<< " " << starcdShellType_; // 4(shell)
<< ' ' << starcdShellShape_ // 3(shell) shape
<< ' ' << f.size()
<< ' ' << cellTableId
<< ' ' << starcdShellType_; // 4(shell)
// primitives have <= 8 vertices, but prevent overrun anyhow
// indent following lines for ease of reading
@ -55,7 +55,7 @@ inline void Foam::fileFormats::STARCDsurfaceFormat<Face>::writeShell
{
os << nl << " " << cellId;
}
os << " " << f[fp] + 1;
os << ' ' << f[fp] + 1;
count++;
}
os << endl;
@ -221,11 +221,23 @@ template<class Face>
void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
(
const fileName& filename,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
const MeshedSurfaceProxy<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst)
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
fileName baseName = filename.lessExt();
writePoints(OFstream(baseName + ".vrt")(), pointLst);
@ -233,16 +245,27 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
writeHeader(os, "CELL");
label faceIndex = 0;
forAll(zoneLst, zoneI)
forAll(zones, zoneI)
{
const surfZone& zone = zoneLst[zoneI];
const surfZone& zone = zones[zoneI];
if (useFaceMap)
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, f, faceIndex, zoneI + 1);
}
}
else
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceIndex++];
writeShell(os, f, faceIndex, zoneI + 1);
}
}
}
// write simple .inp file
writeCase
@ -250,60 +273,9 @@ void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
OFstream(baseName + ".inp")(),
pointLst,
faceLst.size(),
zoneLst
);
}
template<class Face>
void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
(
const fileName& filename,
const MeshedSurface<Face>& surf
)
{
write(filename, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::STARCDsurfaceFormat<Face>::write
(
const fileName& filename,
const UnsortedMeshedSurface<Face>& surf
)
{
fileName baseName = filename.lessExt();
writePoints(OFstream(baseName + ".vrt")(), surf.points());
OFstream os(baseName + ".cel");
writeHeader(os, "CELL");
const List<Face>& faceLst = surf.faces();
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
const surfZone& zone = zoneLst[zoneI];
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, f, faceIndex, zoneI + 1);
}
}
// write simple .inp file
writeCase
(
OFstream(baseName + ".inp")(),
surf.points(),
surf.size(),
zoneLst
zones
);
}
// ************************************************************************* //

View File

@ -42,9 +42,8 @@ SourceFiles
#ifndef STARCDsurfaceFormat_H
#define STARCDsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "STARCDsurfaceFormatCore.H"
@ -114,37 +113,17 @@ public:
// Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Read from file
virtual bool read(const fileName&);
//- Write surface mesh components
static void write
(
const fileName&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write MeshedSurface
static void write
(
const fileName&,
const MeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// The output is sorted by zones
static void write
(
const fileName&,
const UnsortedMeshedSurface<Face>&
);
//- Write to Ostream as one large file - not really useful
virtual void write(Ostream&) const
//- Write object
virtual void write(const fileName& name) const
{
notImplemented("fileFormats::STARCDsurfaceFormat::write(Ostream&)");
write(name, MeshedSurfaceProxy<Face>(*this));
}
};

View File

@ -104,7 +104,7 @@ bool Foam::fileFormats::STARCDsurfaceFormatCore::readPoints
{
FatalErrorIn
(
"fileFormats::STARCDsurfaceFormatCore::readPoints(const fileName&)"
"fileFormats::STARCDsurfaceFormatCore::readPoints(...)"
)
<< "Cannot read file " << is.name()
<< exit(FatalError);

View File

@ -38,8 +38,8 @@ SourceFiles
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "STARCDsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats
{
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable
inp
);
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
STARCDsurfaceFormat,
face,
write,
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
STARCDsurfaceFormat,
triFace,
write,
@ -74,25 +74,6 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
STARCDsurfaceFormat,
face,
write,
fileExtension,
inp
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
STARCDsurfaceFormat,
triFace,
write,
fileExtension,
inp
);
}
}

View File

@ -111,91 +111,6 @@ inline void Foam::fileFormats::STLsurfaceFormat<Face>::writeShell
}
template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY
(
ostream& os,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
)
{
unsigned int nTris = 0;
if (BasicMeshedSurface<Face>::isTri())
{
nTris = faceLst.size();
}
else
{
// count triangles for on-the-fly triangulation
forAll(faceLst, faceI)
{
nTris += faceLst[faceI].size() - 2;
}
}
// Write the STL header
STLsurfaceFormatCore::writeHeaderBINARY(os, nTris);
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
forAll(zoneLst[zoneI], localFaceI)
{
writeShell
(
os,
pointLst,
faceLst[faceIndex++],
zoneI
);
}
}
}
template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::writeBINARY
(
ostream& os,
const UnsortedMeshedSurface<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& zoneIds = surf.zoneIds();
unsigned int nTris = 0;
if (surf.isTri())
{
nTris = faceLst.size();
}
else
{
// count triangles for on-the-fly triangulation
forAll(faceLst, faceI)
{
nTris += faceLst[faceI].size() - 2;
}
}
// Write the STL header
STLsurfaceFormatCore::writeHeaderBINARY(os, nTris);
// always write unsorted
forAll(faceLst, faceI)
{
writeShell
(
os,
pointLst,
faceLst[faceI],
zoneIds[faceI]
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face>
@ -274,55 +189,178 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
}
template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write
void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
(
Ostream& os,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::STLsurfaceFormat::writeAscii"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst)
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
label faceIndex = 0;
forAll(zoneLst, zoneI)
forAll(zones, zoneI)
{
// Print all faces belonging to this zone
const surfZone& zone = zoneLst[zoneI];
const surfZone& zone = zones[zoneI];
os << "solid " << zone.name() << endl;
os << "solid " << zone.name() << nl;
if (useFaceMap)
{
forAll(zone, localFaceI)
{
const label faceI = faceMap[faceIndex++];
writeShell(os, pointLst, faceLst[faceI]);
}
}
else
{
forAll(zone, localFaceI)
{
writeShell(os, pointLst, faceLst[faceIndex++]);
}
}
os << "endsolid " << zone.name() << endl;
}
}
template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write
void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary
(
Ostream& os,
const MeshedSurface<Face>& surf
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
std::ofstream os(filename.c_str(), std::ios::binary);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::STLsurfaceFormat::writeBinary"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst)
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
unsigned int nTris = 0;
if (MeshedSurface<Face>::isTri())
{
nTris = faceLst.size();
}
else
{
// count triangles for on-the-fly triangulation
forAll(faceLst, faceI)
{
nTris += faceLst[faceI].size() - 2;
}
}
// Write the STL header
STLsurfaceFormatCore::writeHeaderBINARY(os, nTris);
label faceIndex = 0;
forAll(zones, zoneI)
{
const surfZone& zone = zones[zoneI];
if (useFaceMap)
{
forAll(zone, localFaceI)
{
writeShell
(
os,
pointLst,
faceLst[faceMap[faceIndex++]],
zoneI
);
}
}
else
{
forAll(zone, localFaceI)
{
writeShell
(
os,
pointLst,
faceLst[faceIndex++],
zoneI
);
}
}
}
}
template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write
void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
(
Ostream& os,
const fileName& filename,
const UnsortedMeshedSurface<Face>& surf
)
{
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::STLsurfaceFormat::writeAscii"
"(const fileName&, const UnsortedMeshedSurface<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
// a single zone - we can skip sorting
if (surf.zoneToc().size() == 1)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
if (surf.zoneToc().size() == 1)
{
// a single zone - we can skip sorting
os << "solid " << surf.zoneToc()[0].name() << endl;
forAll(faceLst, faceI)
{
@ -335,29 +373,79 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
// Print all faces belonging to this zone
const surfZone& zone = zoneLst[zoneI];
os << "solid " << zone.name() << endl;
forAll(zone, localFaceI)
{
const label faceI = faceMap[faceIndex++];
writeShell(os, pointLst, faceLst[faceI]);
}
os << "endsolid " << zone.name() << endl;
}
writeAscii
(
filename,
MeshedSurfaceProxy<Face>
(
surf.points(),
surf.faces(),
zoneLst,
faceMap
)
);
}
}
template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary
(
const fileName& filename,
const UnsortedMeshedSurface<Face>& surf
)
{
std::ofstream os(filename.c_str(), std::ios::binary);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::STLsurfaceFormat::writeBinary"
"(const fileName&, const UnsortedMeshedSurface<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& zoneIds = surf.zoneIds();
unsigned int nTris = 0;
if (surf.isTri())
{
nTris = faceLst.size();
}
else
{
// count triangles for on-the-fly triangulation
forAll(faceLst, faceI)
{
nTris += faceLst[faceI].size() - 2;
}
}
// Write the STL header
STLsurfaceFormatCore::writeHeaderBINARY(os, nTris);
// always write unsorted
forAll(faceLst, faceI)
{
writeShell
(
os,
pointLst,
faceLst[faceI],
zoneIds[faceI]
);
}
}
template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write
(
const fileName& filename,
const MeshedSurface<Face>& surf
const MeshedSurfaceProxy<Face>& surf
)
{
const word ext = filename.ext();
@ -365,18 +453,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
// handle 'stlb' as binary directly
if (ext == "stlb")
{
std::ofstream ofs(filename.c_str(), std::ios::binary);
writeBINARY(ofs, surf);
writeBinary(filename, surf);
}
else
{
write
(
OFstream(filename)(),
surf.points(),
surf.faces(),
surf.zones()
);
writeAscii(filename, surf);
}
}
@ -393,12 +474,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
// handle 'stlb' as binary directly
if (ext == "stlb")
{
std::ofstream ofs(filename.c_str(), std::ios::binary);
writeBINARY(ofs, surf);
writeBinary(filename, surf);
}
else
{
write(OFstream(filename)(), surf);
writeAscii(filename, surf);
}
}

View File

@ -43,6 +43,7 @@ SourceFiles
#include "STLsurfaceFormatCore.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,7 +64,7 @@ class STLsurfaceFormat
{
// Private Member Functions
//- Write Face in ASCII
//- Write Face (ASCII)
static inline void writeShell
(
Ostream&,
@ -71,7 +72,7 @@ class STLsurfaceFormat
const Face&
);
//- Write Face in BINARY
//- Write Face (BINARY)
static inline void writeShell
(
ostream&,
@ -80,19 +81,6 @@ class STLsurfaceFormat
const label zoneI
);
//- Write surface mesh components (as BINARY)
static void writeBINARY
(
ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write UnsortedMeshedSurface
static void writeBINARY(ostream&, const UnsortedMeshedSurface<Face>&);
//- Disallow default bitwise copy construct
STLsurfaceFormat(const STLsurfaceFormat<Face>&);
@ -122,51 +110,50 @@ public:
// Member Functions
//- Read from file
virtual bool read(const fileName&);
//- Write surface mesh components (as ASCII)
static void write
(
Ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write MeshedSurface (as ASCII)
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write MeshedSurface (ASCII or BINARY, depending on the extension)
static void write
//- Write surface mesh components by proxy (as ASCII)
static void writeAscii
(
const fileName&,
const MeshedSurface<Face>&
const MeshedSurfaceProxy<Face>&
);
//- Write UnsortedMeshedSurface (as ASCII) sorted by zone
static void write
//- Write surface mesh components by proxy (as BINARY)
static void writeBinary
(
Ostream&,
const fileName&,
const MeshedSurfaceProxy<Face>&
);
//- Write surface mesh components by proxy
// as ASCII or BINARY, depending on the extension
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Write UnsortedMeshedSurface (as ASCII) sorted by zone
static void writeAscii
(
const fileName&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface (as BINARY) unsorted by zone
static void writeBinary
(
const fileName&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// ASCII output is sorted by zone; binary output is unsorted
static void write
(
const fileName&,
const UnsortedMeshedSurface<Face>&
);
// as ASCII or BINARY, depending on the extension
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
//- Write object (only ASCII output)
virtual void write(Ostream& os) const
//- Read from file
virtual bool read(const fileName&);
//- Write object
virtual void write(const fileName& name) const
{
write(os, *this);
write(name, MeshedSurfaceProxy<Face>(*this));
}
};

View File

@ -403,13 +403,13 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
//
bool Foam::fileFormats::STLsurfaceFormatCore::readASCII
(
IFstream& ifs,
istream& is,
const off_t dataFileSize
)
{
// Create the lexer with the approximate number of vertices in the STL
// from the file size
STLASCIILexer lexer(&ifs.stdStream(), dataFileSize/400);
STLASCIILexer lexer(&is, dataFileSize/400);
while (lexer.lex() != 0) {}
sorted_ = lexer.sorted();

View File

@ -28,6 +28,8 @@ License
#include "gzstream.h"
#include "OSspecific.H"
#include "Map.H"
#include "IFstream.H"
#include "Ostream.H"
#undef DEBUG_STLBINARY
@ -48,8 +50,7 @@ int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY
{
off_t dataFileSize = Foam::fileSize(filename);
IFstream ifs(filename, IOstream::BINARY);
istream& is = ifs.stdStream();
istream& is = IFstream(filename, IOstream::BINARY)().stdStream();
// Read the STL header
char header[headerSize];
@ -89,12 +90,11 @@ int Foam::fileFormats::STLsurfaceFormatCore::detectBINARY
bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
(
IFstream& ifs,
istream& is,
const off_t dataFileSize
)
{
sorted_ = true;
istream& is = ifs.stdStream();
// Read the STL header
char header[headerSize];
@ -131,7 +131,7 @@ bool Foam::fileFormats::STLsurfaceFormatCore::readBINARY
{
FatalErrorIn
(
"fileFormats::STLsurfaceFormatCore::readBINARY(IFstream&)"
"fileFormats::STLsurfaceFormatCore::readBINARY(istream&)"
)
<< "problem reading number of triangles, perhaps file is not binary"
<< exit(FatalError);
@ -230,11 +230,19 @@ Foam::fileFormats::STLsurfaceFormatCore::STLsurfaceFormatCore
// auto-detect ascii/binary
if (detectBINARY(filename))
{
readBINARY(IFstream(filename, IOstream::BINARY)(), dataFileSize);
readBINARY
(
IFstream(filename, IOstream::BINARY)().stdStream(),
dataFileSize
);
}
else
{
readASCII(IFstream(filename)(), dataFileSize);
readASCII
(
IFstream(filename)().stdStream(),
dataFileSize
);
}
}

View File

@ -41,7 +41,6 @@ SourceFiles
#include "triFace.H"
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -84,10 +83,10 @@ class STLsurfaceFormatCore
static int detectBINARY(const fileName&);
//- Read ASCII
bool readASCII(IFstream&, const off_t);
bool readASCII(istream&, const off_t);
//- Read BINARY
bool readBINARY(IFstream&, const off_t);
bool readBINARY(istream&, const off_t);
public:

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "STLsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats
{
// read MeshedSurface (ascii)
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
@ -53,6 +53,7 @@ addNamedTemplatedToRunTimeSelectionTable
stl
);
// read MeshedSurface (binary)
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
@ -71,9 +72,10 @@ addNamedTemplatedToRunTimeSelectionTable
);
// write MeshedSurfaceProxy (ascii)
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
STLsurfaceFormat,
face,
write,
@ -82,7 +84,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
STLsurfaceFormat,
triFace,
write,
@ -90,9 +92,10 @@ addNamedTemplatedToMemberFunctionSelectionTable
stl
);
// write MeshedSurfaceProxy (binary)
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
STLsurfaceFormat,
face,
write,
@ -101,7 +104,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
STLsurfaceFormat,
triFace,
write,
@ -109,6 +112,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
stlb
);
// write UnsortedMeshedSurface (ascii)
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
@ -128,6 +132,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
stl
);
// write UnsortedMeshedSurface (binary)
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,

View File

@ -267,7 +267,7 @@ Foam::fileFormats::surfaceFormatsCore::checkSupport
Info<<"Unknown file extension for " << functionName
<< " : " << ext << nl
<<"Valid types: ( " << nativeExt;
<<"Valid types: (";
// compact output:
forAll(known, i)
{

View File

@ -61,6 +61,32 @@ namespace fileFormats
class surfaceFormatsCore
{
protected:
//- Return a list with a single entry,
// the size corresponds to that of the container
template<class Container>
static List<surfZone> oneZone
(
const Container& container,
const word& name = "zone0"
)
{
return List<surfZone>(1, surfZone(name, container.size(), 0, 0));
}
//- Determine the sort order from the zone ids.
// Returns zone list and sets faceMap to indices within faceLst
static surfZoneList sortedZonesById
(
const UList<label>& zoneIds,
const Map<word>& zoneNames,
labelList& faceMap
);
//- Read non-comment line
static string getLineNoComment(IFstream&);
public:
// Static Data
@ -74,9 +100,6 @@ public:
//- Check if file extension corresponds to 'native' surface format
static bool isNative(const word&);
//- Read non-comment line
static string getLineNoComment(IFstream&);
//- Return the local file name (within time directory)
static fileName localMeshFileName(const word& surfName="");
@ -86,15 +109,6 @@ public:
//- Find mesh file with surfName
static fileName findMeshFile(const Time&, const word& surfName="");
//- Determine the sort order from the zone ids.
// Returns zone list and sets faceMap to indices within faceLst
static surfZoneList sortedZonesById
(
const UList<label>& zoneIds,
const Map<word>& zoneNames,
labelList& faceMap
);
static bool checkSupport
(
const wordHashSet& available,
@ -103,6 +117,7 @@ public:
const word& functionName
);
// Constructors
//- Construct null

View File

@ -131,53 +131,94 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
template<class Face>
void Foam::fileFormats::TRIsurfaceFormat<Face>::write
(
Ostream& os,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
label faceIndex = 0;
forAll(zoneLst, zoneI)
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst)
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
OFstream os(filename);
if (!os.good())
{
forAll(zoneLst[zoneI], localFaceI)
FatalErrorIn
(
"fileFormats::TRIsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
label faceIndex = 0;
forAll(zones, zoneI)
{
const surfZone& zone = zones[zoneI];
if (useFaceMap)
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
writeShell(os, pointLst, f, zoneI);
}
}
else
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceIndex++];
writeShell(os, pointLst, f, zoneI);
}
}
}
template<class Face>
void Foam::fileFormats::TRIsurfaceFormat<Face>::write
(
Ostream& os,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::TRIsurfaceFormat<Face>::write
(
Ostream& os,
const fileName& filename,
const UnsortedMeshedSurface<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
bool doSort = false;
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::TRIsurfaceFormat::write"
"(const fileName&, const UnsortedMeshedSurface<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
// a single zone needs no sorting
if (surf.zoneToc().size() == 1)
{
doSort = false;
}
const List<label>& zoneIds = surf.zoneIds();
if (doSort)
forAll(faceLst, faceI)
{
writeShell(os, pointLst, faceLst[faceI], zoneIds[faceI]);
}
}
else
{
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
@ -192,15 +233,6 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write
}
}
}
else
{
const List<label>& zoneIds = surf.zoneIds();
forAll(faceLst, faceI)
{
writeShell(os, pointLst, faceLst[faceI], zoneIds[faceI]);
}
}
}
// ************************************************************************* //

View File

@ -41,9 +41,8 @@ SourceFiles
#define TRIsurfaceFormat_H
#include "TRIsurfaceFormatCore.H"
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -102,58 +101,21 @@ public:
// Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Write UnsortedMeshedSurface,
// by default the output is not sorted by zones
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
//- Read from file
virtual bool read(const fileName&);
//- Write surface mesh components
static void write
(
Ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write MeshedSurface
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write MeshedSurface
static void write
(
const fileName& name,
const MeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write UnsortedMeshedSurface
// By default, the output is not sorted by zones
static void write
(
Ostream&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// By default, the output is not sorted by zones
static void write
(
const fileName& name,
const UnsortedMeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
virtual void write(const fileName& name) const
{
write(os, *this);
write(name, MeshedSurfaceProxy<Face>(*this));
}
};

View File

@ -38,6 +38,7 @@ SourceFiles
#include "surfaceFormatsCore.H"
#include "triFace.H"
#include "IFstream.H"
#include "Ostream.H"
#include "OFstream.H"

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "TRIsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats
{
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable
(
MeshedSurface,
@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable
tri
);
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
TRIsurfaceFormat,
face,
write,
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
TRIsurfaceFormat,
triFace,
write,
@ -73,6 +73,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
tri
);
// write UnsortedMeshedSurface
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,

View File

@ -61,19 +61,61 @@ Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat()
template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
(
Ostream& os,
const pointField& pointLst,
const List<Face>& faceLst,
const List<surfZone>& zoneLst
const fileName& filename,
const MeshedSurfaceProxy<Face>& surf
)
{
const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.faceMap();
const List<surfZone>& zones =
(
surf.surfZones().size() > 1
? surf.surfZones()
: oneZone(faceLst)
);
const bool useFaceMap = (surf.useFaceMap() && zones.size() > 1);
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::VTKsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
writeHeader(os, pointLst);
writeHeaderPolygons(os, faceLst);
label faceIndex = 0;
forAll(zoneLst, zoneI)
forAll(zones, zoneI)
{
forAll(zoneLst[zoneI], localFaceI)
const surfZone& zone = zones[zoneI];
if (useFaceMap)
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << nl;
}
}
else
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceIndex++];
@ -85,29 +127,32 @@ void Foam::fileFormats::VTKsurfaceFormat<Face>::write
os << ' ' << nl;
}
}
}
writeTail(os, zoneLst);
writeTail(os, zones);
}
template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
(
Ostream& os,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
(
Ostream& os,
const fileName& filename,
const UnsortedMeshedSurface<Face>& surf
)
{
OFstream os(filename);
if (!os.good())
{
FatalErrorIn
(
"fileFormats::VTKsurfaceFormat::write"
"(const fileName&, const UnsortedMeshedSurface<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
}
const List<Face>& faceLst = surf.faces();
writeHeader(os, surf.points());

View File

@ -37,9 +37,8 @@ SourceFiles
#ifndef VTKsurfaceFormat_H
#define VTKsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H"
#include "VTKsurfaceFormatCore.H"
@ -89,55 +88,17 @@ public:
// Write
//- Write surface mesh components
static void write
(
Ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Write MeshedSurface
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface, the output remains unsorted
static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
//- Write MeshedSurface
static void write
(
const fileName& name,
const MeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write UnsortedMeshedSurface
// The output remains unsorted
static void write
(
Ostream&,
const UnsortedMeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// The output remains unsorted
static void write
(
const fileName& name,
const UnsortedMeshedSurface<Face>& surf
)
{
write(OFstream(name)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{
write(os, *this);
write(os, MeshedSurfaceProxy<Face>(*this));
}
};

View File

@ -48,9 +48,9 @@ void Foam::fileFormats::VTKsurfaceFormatCore::writeHeader
os << "POINTS " << pointLst.size() << " float" << nl;
forAll(pointLst, ptI)
{
os << pointLst[ptI].x() << ' '
<< pointLst[ptI].y() << ' '
<< pointLst[ptI].z() << nl;
const point& pt = pointLst[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
}

View File

@ -39,7 +39,6 @@ SourceFiles
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "VTKsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H"
@ -36,9 +35,10 @@ namespace Foam
namespace fileFormats
{
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
VTKsurfaceFormat,
face,
write,
@ -47,7 +47,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
MeshedSurfaceProxy,
VTKsurfaceFormat,
triFace,
write,
@ -55,6 +55,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
vtk
);
// write UnsortedMeshedSurface
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,