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() 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 surfMesh surfOut
( (
IOobject IOobject
( (
"mySurf", "mySurf",
runTime.instance(), runTime.instance(),
runTime runTime,
IOobject::NO_READ,
IOobject::NO_WRITE,
false
), ),
surf.xfer() surf.xfer()
); );
@ -299,6 +326,25 @@ int main(int argc, char *argv[])
dimless 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(); const surfZoneList& zones = surfOut.surfZones();
forAll(zones, zoneI) forAll(zones, zoneI)
{ {
@ -318,9 +364,10 @@ int main(int argc, char *argv[])
( (
IOobject IOobject
( (
"pointIds", "zoneIds.",
// "pointIds",
surfOut.instance(), surfOut.instance(),
"pointFields", // "pointFields",
surfOut, surfOut,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
@ -337,6 +384,10 @@ int main(int argc, char *argv[])
Info<< "write pointIds (for testing only): " Info<< "write pointIds (for testing only): "
<< pointIds.objectPath() << endl; << pointIds.objectPath() << endl;
pointIds.write(); pointIds.write();
Info<<"surfMesh with these names: " << surfOut.names() << endl;
#endif
} }
} }

View File

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

View File

@ -50,11 +50,11 @@ namespace Foam
class sampledPatch class sampledPatch
: :
public BasicMeshedSurface<face>, public MeshedSurface<face>,
public sampledSurface public sampledSurface
{ {
//- Private typedefs for convenience //- Private typedefs for convenience
typedef BasicMeshedSurface<face> MeshStorage; typedef MeshedSurface<face> MeshStorage;
// Private data // 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/surfZone/surfZoneIOList.C
surfZone/surfZoneIdentifier/surfZoneIdentifier.C surfZone/surfZoneIdentifier/surfZoneIdentifier.C
MeshedSurfaceAllocator/MeshedSurfaceIOAllocator.C
MeshedSurface/MeshedSurfaceCore.C MeshedSurface/MeshedSurfaceCore.C
MeshedSurface/MeshedSurfaces.C MeshedSurface/MeshedSurfaces.C
UnsortedMeshedSurface/UnsortedMeshedSurfaces.C UnsortedMeshedSurface/UnsortedMeshedSurfaces.C
MeshedSurfaceProxy/MeshedSurfaceProxyCore.C
surfaceRegistry/surfaceRegistry.C surfaceRegistry/surfaceRegistry.C
surfFields/surfFields.C
surfPointFields/surfPointFields.C
surfMesh/surfMesh.C surfMesh/surfMesh.C
surfMesh/surfMeshClear.C surfMesh/surfMeshClear.C
surfMesh/surfMeshIO.C surfMesh/surfMeshIO.C
surfFields/surfFields/surfFields.C
surfFields/surfPointFields/surfPointFields.C
surfaceFormats = surfaceFormats surfaceFormats = surfaceFormats
$(surfaceFormats)/surfaceFormatsCore.C $(surfaceFormats)/surfaceFormatsCore.C
@ -22,11 +26,10 @@ $(surfaceFormats)/ftr/FTRsurfaceFormatRunTime.C
$(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C $(surfaceFormats)/gts/GTSsurfaceFormatRunTime.C
$(surfaceFormats)/nas/NASsurfaceFormatCore.C $(surfaceFormats)/nas/NASsurfaceFormatCore.C
$(surfaceFormats)/nas/NASsurfaceFormatRunTime.C $(surfaceFormats)/nas/NASsurfaceFormatRunTime.C
$(surfaceFormats)/obj/OBJsurfaceFormatCore.C
$(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C $(surfaceFormats)/obj/OBJsurfaceFormatRunTime.C
$(surfaceFormats)/off/OFFsurfaceFormatCore.C
$(surfaceFormats)/off/OFFsurfaceFormatRunTime.C $(surfaceFormats)/off/OFFsurfaceFormatRunTime.C
$(surfaceFormats)/smesh/SMESHsurfaceFormatCore.C $(surfaceFormats)/ofs/OFSsurfaceFormatCore.C
$(surfaceFormats)/ofs/OFSsurfaceFormatRunTime.C
$(surfaceFormats)/smesh/SMESHsurfaceFormatRunTime.C $(surfaceFormats)/smesh/SMESHsurfaceFormatRunTime.C
$(surfaceFormats)/starcd/STARCDsurfaceFormatCore.C $(surfaceFormats)/starcd/STARCDsurfaceFormatCore.C
$(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C $(surfaceFormats)/starcd/STARCDsurfaceFormatRunTime.C

File diff suppressed because it is too large Load Diff

View File

@ -26,15 +26,19 @@ Class
Foam::MeshedSurface Foam::MeshedSurface
Description Description
A surface geometry mesh with zone information, not to be confused A surface geometry mesh with zone information, not to be confused with
with a similarily named surfaceMesh, which actually refers to the similarly named surfaceMesh, which actually refers to the cell faces
the cell faces of a volume mesh. of a volume mesh.
The MeshedSurface is intended for surfaces from a variety of sources. A MeshedSurface can have zero or more surface zones (roughly equivalent
- A set of points and faces without any surface zone information. to faceZones for a polyMesh). If surface zones are defined, they must
- A set of points and faces with randomly ordered zone information. be contiguous and cover all of the faces.
This could arise, for example, from reading external file formats
such as STL, etc. The MeshedSurface is intended for surfaces from a variety of sources.
- A set of points and faces without any surface zone information.
- A set of points and faces with randomly ordered zone information.
This could arise, for example, from reading external file formats
such as STL, etc.
SourceFiles SourceFiles
MeshedSurface.C MeshedSurface.C
@ -44,7 +48,12 @@ SourceFiles
#ifndef MeshedSurface_H #ifndef MeshedSurface_H
#define 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 "surfZoneList.H"
#include "surfaceFormatsCore.H" #include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
@ -60,14 +69,11 @@ namespace Foam
class Time; class Time;
class surfMesh; class surfMesh;
template<class Face> class MeshedSurface;
template<class Face> class UnsortedMeshedSurface;
class polyBoundaryMesh; class polyBoundaryMesh;
class surfMesh;
template<class Face> template<class Face> class MeshedSurface;
Ostream& operator<<(Ostream&, const MeshedSurface<Face>&); template<class Face> class MeshedSurfaceProxy;
template<class Face> class UnsortedMeshedSurface;
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class MeshedSurface Declaration Class MeshedSurface Declaration
@ -76,7 +82,7 @@ Ostream& operator<<(Ostream&, const MeshedSurface<Face>&);
template<class Face> template<class Face>
class MeshedSurface class MeshedSurface
: :
public BasicMeshedSurface<Face>, public PrimitivePatch<Face, ::Foam::List, pointField, point>,
public fileFormats::surfaceFormatsCore public fileFormats::surfaceFormatsCore
{ {
// friends despite different faces // friends despite different faces
@ -92,8 +98,18 @@ class MeshedSurface
private: private:
//- Private typedefs for convenience //- 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 // Private Member Data
@ -101,21 +117,31 @@ private:
// (face ordering nFaces/startFace only used during reading/writing) // (face ordering nFaces/startFace only used during reading/writing)
List<surfZone> zones_; List<surfZone> zones_;
// Private member functions // Private member functions
//- Read OpenFOAM Surface format
bool read(Istream&);
//- Transfer points/zones and transcribe face -> triFace
void transcribe(MeshedSurface<face>&);
protected: protected:
// Protected Member functions // Protected Member functions
//- Transfer points/zones and transcribe face -> triFace
void transcribe(MeshedSurface<face>&);
//- basic sanity check on zones //- basic sanity check on zones
void checkZones(); 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 //- Non-const access to the zones
surfZoneList& storedZones() surfZoneList& storedZones()
{ {
@ -125,8 +151,8 @@ protected:
//- sort faces by zones and store sorted faces //- sort faces by zones and store sorted faces
void sortFacesAndStore void sortFacesAndStore
( (
const Xfer<List<Face> >& unsortedFaces, const Xfer< List<Face> >& unsortedFaces,
const Xfer<List<label> >& zoneIds, const Xfer< List<label> >& zoneIds,
const bool sorted const bool sorted
); );
@ -140,6 +166,9 @@ public:
// Static // Static
//- Face storage only handles triangulated faces
inline static bool isTri();
//- Can we read this file format? //- Can we read this file format?
static bool canRead(const fileName&, const bool verbose=false); static bool canRead(const fileName&, const bool verbose=false);
@ -160,21 +189,27 @@ public:
//- Construct by transferring components (points, faces, zones). //- Construct by transferring components (points, faces, zones).
MeshedSurface MeshedSurface
( (
const Xfer<pointField>&, const Xfer< pointField >&,
const Xfer<List<Face> >&, const Xfer< List<Face> >&,
const Xfer<surfZoneList>& const Xfer< surfZoneList >&
); );
//- Construct by transferring points, faces. //- Construct by transferring components (points, faces).
// Use zone information, or set single default zone. // Use zone information if available
MeshedSurface MeshedSurface
( (
const Xfer<pointField>&, const Xfer< pointField >&,
const Xfer<List<Face> >&, const Xfer< List<Face> >&,
const UList<label>& zoneSizes = UList<label>::null(), const UList<label>& zoneSizes = UList<label>(),
const UList<word>& zoneNames = UList<word>::null() 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 //- Construct from a boundary mesh with local points/faces
MeshedSurface MeshedSurface
( (
@ -182,9 +217,6 @@ public:
const bool globalPoints=false const bool globalPoints=false
); );
//- Construct from a UnsortedMeshedSurface
MeshedSurface(const UnsortedMeshedSurface<Face>&);
//- Construct from a surfMesh //- Construct from a surfMesh
MeshedSurface(const surfMesh&); MeshedSurface(const surfMesh&);
@ -200,15 +232,9 @@ public:
//- Construct from file name (uses extension to determine type) //- Construct from file name (uses extension to determine type)
MeshedSurface(const fileName&, const word& ext); MeshedSurface(const fileName&, const word& ext);
//- Construct from Istream
MeshedSurface(Istream&);
//- Construct from objectRegistry //- Construct from objectRegistry
MeshedSurface(const Time&, const word& surfName=""); MeshedSurface(const Time&, const word& surfName="");
//- Construct as copy
MeshedSurface(const MeshedSurface&);
// Declare run-time constructor selection table // Declare run-time constructor selection table
declareRunTimeSelectionTable declareRunTimeSelectionTable
@ -244,7 +270,7 @@ public:
declareMemberFunctionSelectionTable declareMemberFunctionSelectionTable
( (
void, void,
MeshedSurface, UnsortedMeshedSurface,
write, write,
fileExtension, fileExtension,
( (
@ -268,41 +294,98 @@ public:
return ParentType::size(); 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_; return zones_;
} }
//- set a single zone, optionally with a specific name //- Add surface zones
void oneZone(const word& name = word::null); virtual void addZones
//- Add zones
void addZones
( (
const UList<surfZone>&, const UList<surfZone>&,
const bool cullEmpty=false const bool cullEmpty=false
); );
//- Add zones //- Add surface zones
void addZones virtual void addZones
( (
const UList<label>& sizes, const UList<label>& sizes,
const UList<word>& names, const UList<word>& names,
const bool cullEmpty=false const bool cullEmpty=false
); );
//- Add zones //- Add surface zones
void addZones virtual void addZones
( (
const UList<label>& sizes, const UList<label>& sizes,
const bool cullEmpty=false const bool cullEmpty=false
); );
//- Remove surface zones
virtual void removeZones();
// Edit // Edit
//- Clear all storage //- Clear all storage
virtual void clear(); 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. //- Return new surface.
// Returns return pointMap, faceMap from subsetMeshMap // Returns return pointMap, faceMap from subsetMeshMap
MeshedSurface subsetMesh MeshedSurface subsetMesh
@ -338,8 +421,7 @@ public:
// Write // Write
//- Write to Ostream in simple FOAM format void writeStats(Ostream& os) const;
virtual void write(Ostream&) const;
//- Generic write routine. Chooses writer based on extension. //- Generic write routine. Chooses writer based on extension.
virtual void write(const fileName& name) const virtual void write(const fileName& name) const
@ -355,17 +437,37 @@ public:
void operator=(const MeshedSurface<Face>&); 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 } // End namespace Foam

View File

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

View File

@ -25,117 +25,44 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H" #include "boundBox.H"
#include "IFstream.H" #include "Ostream.H"
#include "OFstream.H"
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// Read surf grouping, points, faces directly from Istream
template<class Face> template<class Face>
bool Foam::MeshedSurface<Face>::read(Istream& is) void Foam::MeshedSurface<Face>::writeStats(Ostream& os) const
{ {
clear(); os << "points : " << this->points().size() << nl;
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?
if (this->isTri()) if (this->isTri())
{ {
List<face> faceLst(is); os << "triangles : " << this->size() << nl;
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);
} }
else else
{ {
// read faces: label nTri = 0;
is >> this->storedFaces(); 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;
} }
return is.good(); os << "boundingBox : " << boundBox(this->points()) << endl;
} }
template<class Face>
void Foam::MeshedSurface<Face>::write(Ostream& os) const
{
// 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;
forAll(zones_, zoneI)
{
zones_[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 << 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
)
{
surf.write(os);
return os;
}
// ************************************************************************* // // ************************************************************************* //

View File

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

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, along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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 #include "MeshedSurfaceProxy.H"
#define OFFsurfaceFormatCore_H #include "addToRunTimeSelectionTable.H"
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
namespace fileFormats
{
/*---------------------------------------------------------------------------*\ // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
Class OFFsurfaceFormatCore Declaration
\*---------------------------------------------------------------------------*/
class OFFsurfaceFormatCore #define makeSurface(surfType, faceType) \
{ defineNamedTemplateTypeNameAndDebug(surfType<faceType>, 0); \
protected: defineTemplatedMemberFunctionSelectionTable(surfType,write,fileExtension,faceType);
// Protected Member Functions
//- 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 } // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -57,21 +57,13 @@ bool Foam::UnsortedMeshedSurface<Face>::canReadType
const bool verbose const bool verbose
) )
{ {
// handle 'native' format directly return checkSupport
if (isNative(ext)) (
{ readTypes() | ParentType::readTypes(),
return true; ext,
} verbose,
else "reading"
{ );
return checkSupport
(
readTypes() | SiblingType::readTypes(),
ext,
verbose,
"reading"
);
}
} }
@ -82,13 +74,13 @@ bool Foam::UnsortedMeshedSurface<Face>::canWriteType
const bool verbose const bool verbose
) )
{ {
// handle 'native' format directly return checkSupport
if (isNative(ext)) (
{ writeTypes(),
return true; ext,
} verbose,
"writing"
return checkSupport(writeTypes(), ext, verbose, "writing"); );
} }
@ -125,29 +117,43 @@ void Foam::UnsortedMeshedSurface<Face>::write
const word ext = name.ext(); const word ext = name.ext();
// handle 'native' format directly
if (isNative(ext))
{
surf.write(OFstream(name)());
return;
}
typename writefileExtensionMemberFunctionTable::iterator mfIter = typename writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext); writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end()) if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{ {
FatalErrorIn // no direct writer, delegate to proxy if possible
( wordHashSet supported = ProxyType::writeTypes();
"UnsortedMeshedSurface::write"
"(const fileName&, const UnsortedMeshedSurface&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writeTypes()
<< exit(FatalError);
}
mfIter()(name, surf); if (supported.found(ext))
{
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
MeshedSurfaceProxy<Face>
(
surf.points(),
surf.faces(),
zoneLst,
faceMap
).write(name);
}
else
{
FatalErrorIn
(
"UnsortedMeshedSurface::write"
"(const fileName&, const UnsortedMeshedSurface&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< (supported | writeTypes())
<< exit(FatalError);
}
}
else
{
mfIter()(name, surf);
}
} }
@ -155,16 +161,18 @@ void Foam::UnsortedMeshedSurface<Face>::write
template<class Face> template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface() Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface()
:
ParentType()
{} {}
template<class Face> template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
( (
const Xfer<pointField>& pointLst, const Xfer< pointField >& pointLst,
const Xfer<List<Face> >& faceLst, const Xfer< List<Face> >& faceLst,
const Xfer<List<label> >& zoneIds, const Xfer< List<label> >& zoneIds,
const Xfer<surfZoneIdentifierList>& zoneTofc const Xfer< surfZoneIdentifierList >& zoneTofc
) )
: :
ParentType(pointLst, faceLst), ParentType(pointLst, faceLst),
@ -176,17 +184,17 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
template<class Face> template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
( (
const Xfer<pointField>& pointLst, const Xfer< pointField >& pointLst,
const Xfer<List<Face> >& faceLst, const Xfer< List<Face> >& faceLst,
const UList<label>& zoneSizes, const UList<label>& zoneSizes,
const UList<word>& zoneNames const UList<word>& zoneNames
) )
: :
ParentType(pointLst, faceLst) ParentType(pointLst, faceLst)
{ {
if (&zoneSizes) if (zoneSizes.size())
{ {
if (&zoneNames) if (zoneNames.size())
{ {
setZones(zoneSizes, zoneNames); setZones(zoneSizes, zoneNames);
} }
@ -197,89 +205,50 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
} }
else 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> template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
( (
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf
) )
: :
ParentType(xferCopy(surf.points()), xferCopy(surf.faces())), ParentType
zoneIds_(surf.zoneIds_), (
zoneToc_(surf.zoneToc_) xferCopy(surf.points()),
xferCopy(surf.faces())
),
zoneIds_(surf.zoneIds()),
zoneToc_(surf.zoneToc())
{} {}
template<class Face> template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
( (
const Xfer<UnsortedMeshedSurface<Face> >& surf 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()); transfer(surf());
} }
@ -288,12 +257,50 @@ Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
template<class Face> template<class Face>
Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface Foam::UnsortedMeshedSurface<Face>::UnsortedMeshedSurface
( (
const Xfer<MeshedSurface<Face> >& surf const Xfer< MeshedSurface<Face> >& surf
) )
:
ParentType()
{ {
transfer(surf()); 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 * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Face> template<class Face>
@ -308,22 +315,19 @@ Foam::UnsortedMeshedSurface<Face>::~UnsortedMeshedSurface()
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
template<class Face> template<class Face>
void Foam::UnsortedMeshedSurface<Face>::oneZone(const word& name) void Foam::UnsortedMeshedSurface<Face>::setOneZone()
{ {
zoneIds_.setSize(size()); zoneIds_.setSize(size());
zoneIds_ = 0; zoneIds_ = 0;
word zoneName(name); word zoneName;
if (zoneToc_.size())
{
zoneName = zoneToc_[0].name();
}
if (zoneName.empty()) if (zoneName.empty())
{ {
if (zoneToc_.size()) zoneName = "zone0";
{
zoneName = zoneToc_[0].name();
}
if (zoneName.empty())
{
zoneName = "zone0";
}
} }
// set single default zone // set single default zone
@ -344,7 +348,6 @@ void Foam::UnsortedMeshedSurface<Face>::setZones
forAll(zoneToc_, zoneI) forAll(zoneToc_, zoneI)
{ {
const surfZone& zone = zoneLst[zoneI]; const surfZone& zone = zoneLst[zoneI];
zoneToc_[zoneI] = zone; zoneToc_[zoneI] = zone;
// assign sub-zone Ids // assign sub-zone Ids
@ -416,7 +419,7 @@ void Foam::UnsortedMeshedSurface<Face>::remapFaces
{ {
if (zoneToc_.empty()) if (zoneToc_.empty())
{ {
oneZone(); setOneZone();
} }
else if (zoneToc_.size() == 1) else if (zoneToc_.size() == 1)
{ {
@ -442,7 +445,7 @@ void Foam::UnsortedMeshedSurface<Face>::remapFaces
template<class Face> template<class Face>
void Foam::UnsortedMeshedSurface<Face>::setSize(const label s) void Foam::UnsortedMeshedSurface<Face>::setSize(const label s)
{ {
ParentType::setSize(s); this->storedFaces().setSize(s);
// if zones extend: set with last zoneId // if zones extend: set with last zoneId
zoneIds_.setSize(s, zoneToc_.size() - 1); zoneIds_.setSize(s, zoneToc_.size() - 1);
} }
@ -470,12 +473,13 @@ Foam::surfZoneList Foam::UnsortedMeshedSurface<Face>::sortedZones
zoneNames.insert(zoneI, zoneToc_[zoneI].name()); zoneNames.insert(zoneI, zoneToc_[zoneI].name());
} }
return sortedZonesById(zoneIds_, zoneNames, faceMap); return this->sortedZonesById(zoneIds_, zoneNames, faceMap);
} }
template<class Face> template<class Face>
Foam::UnsortedMeshedSurface<Face> Foam::UnsortedMeshedSurface<Face>::subsetMesh Foam::UnsortedMeshedSurface<Face>
Foam::UnsortedMeshedSurface<Face>::subsetMesh
( (
const labelHashSet& include, const labelHashSet& include,
labelList& pointMap, labelList& pointMap,
@ -542,12 +546,39 @@ Foam::UnsortedMeshedSurface<Face> Foam::UnsortedMeshedSurface<Face>::subsetMesh
template<class Face> template<class Face>
void Foam::UnsortedMeshedSurface<Face>::reset void Foam::UnsortedMeshedSurface<Face>::reset
( (
const Xfer<pointField>& pointLst, const Xfer< pointField >& pointLst,
const Xfer<List<Face> >& faceLst, const Xfer< List<Face> >& faceLst,
const Xfer<List<label> >& zoneIds 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) if (&zoneIds)
{ {
@ -562,12 +593,14 @@ void Foam::UnsortedMeshedSurface<Face>::transfer
UnsortedMeshedSurface<Face>& surf UnsortedMeshedSurface<Face>& surf
) )
{ {
reset ParentType::reset
( (
xferMove(surf.storedPoints()), xferMove(surf.storedPoints()),
xferMove(surf.storedFaces()), xferMove(surf.storedFaces()),
xferMove(surf.zoneIds_) Xfer<surfZoneList>()
); );
zoneIds_.transfer(surf.zoneIds_);
zoneToc_.transfer(surf.zoneToc_); zoneToc_.transfer(surf.zoneToc_);
surf.clear(); surf.clear();
@ -580,8 +613,14 @@ void Foam::UnsortedMeshedSurface<Face>::transfer
MeshedSurface<Face>& surf MeshedSurface<Face>& surf
) )
{ {
reset(xferMove(surf.storedPoints()), xferMove(surf.storedFaces())); ParentType::reset
setZones(surf.zones()); (
xferMove(surf.storedPoints()),
xferMove(surf.storedFaces()),
Xfer<surfZoneList>()
);
setZones(surf.surfZones());
surf.clear(); surf.clear();
} }
@ -620,17 +659,11 @@ bool Foam::UnsortedMeshedSurface<Face>::read
const word& ext const word& ext
) )
{ {
// handle 'native' format directly clear();
if (isNative(ext))
{ // read via use selector mechanism
return read(IFstream(name)()); transfer(New(name, ext)());
} return true;
else
{
// use selector mechanism
transfer(New(name, ext)());
return true;
}
} }
@ -641,7 +674,7 @@ void Foam::UnsortedMeshedSurface<Face>::write
const word& surfName const word& surfName
) const ) 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" #include "UnsortedMeshedSurfaceNew.C"
// ************************************************************************* // // ************************************************************************* //

View File

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

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

View File

@ -25,6 +25,8 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "surfMesh.H" #include "surfMesh.H"
#include "MeshedSurfaceProxy.H"
#include "Time.H" #include "Time.H"
#include "cellIOList.H" #include "cellIOList.H"
#include "SubList.H" #include "SubList.H"
@ -40,29 +42,30 @@ Foam::word Foam::surfMesh::meshSubDir = "surfMesh";
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::surfMesh::oneZone() // void Foam::surfMesh::oneZone()
{ // {
word zoneName; // word zoneName;
//
if (surfZones_.size()) // surfZoneList& zones = Allocator::storedIOZones();
{ // if (zones.size())
zoneName = surfZones_[0].name(); // {
} // zoneName = zones[0].name();
if (zoneName.empty()) // }
{ // if (zoneName.empty())
zoneName = "zone0"; // {
} // zoneName = "zone0";
// }
// set single default zone //
surfZones_.setSize(1); // // set single default zone
surfZones_[0] = surfZone // zones.setSize(1);
( // zones[0] = surfZone
zoneName, // (
nFaces(), // zone size // zoneName,
0, // zone start // nFaces(), // zone size
0 // zone index // 0, // zone start
); // 0 // zone index
} // );
// }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -71,7 +74,7 @@ void Foam::surfMesh::oneZone()
Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName) Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
: :
surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())), surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
surfMeshAllocator Allocator
( (
IOobject IOobject
( (
@ -90,11 +93,7 @@ Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
*this, *this,
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
) ),
),
MeshReference(storedFaces_, storedPoints_),
surfZones_
(
IOobject IOobject
( (
"surfZones", "surfZones",
@ -104,20 +103,21 @@ Foam::surfMesh::surfMesh(const IOobject& io, const word& surfName)
IOobject::MUST_READ, IOobject::MUST_READ,
IOobject::NO_WRITE IOobject::NO_WRITE
) )
) ),
MeshReference(this->storedIOFaces(), this->storedIOPoints())
{} {}
Foam::surfMesh::surfMesh Foam::surfMesh::surfMesh
( (
const IOobject& io, const IOobject& io,
const Xfer<pointField>& pointLst, const Xfer< pointField >& pointLst,
const Xfer<faceList>& faceLst, const Xfer< faceList >& faceLst,
const word& surfName const word& surfName
) )
: :
surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())), surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
surfMeshAllocator Allocator
( (
IOobject IOobject
( (
@ -138,11 +138,7 @@ Foam::surfMesh::surfMesh
IOobject::NO_READ, IOobject::NO_READ,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE
), ),
faceLst faceLst,
),
MeshReference(storedFaces_, storedPoints_),
surfZones_
(
IOobject IOobject
( (
"surfZones", "surfZones",
@ -151,8 +147,10 @@ Foam::surfMesh::surfMesh
*this, *this,
IOobject::NO_READ, IOobject::NO_READ,
IOobject::AUTO_WRITE 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())), surfaceRegistry(io.db(), (surfName.size() ? surfName : io.name())),
surfMeshAllocator Allocator
( (
IOobject IOobject
( (
@ -185,11 +183,7 @@ Foam::surfMesh::surfMesh
IOobject::NO_READ, IOobject::NO_READ,
IOobject::AUTO_WRITE IOobject::AUTO_WRITE
), ),
faceList() faceList(),
),
MeshReference(storedFaces_, storedPoints_),
surfZones_
(
IOobject IOobject
( (
"surfZones", "surfZones",
@ -200,9 +194,21 @@ Foam::surfMesh::surfMesh
IOobject::AUTO_WRITE IOobject::AUTO_WRITE
), ),
surfZoneList() 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) if (&surf)
{ {
transfer(surf()); transfer(surf());
@ -213,40 +219,50 @@ Foam::surfMesh::surfMesh
Foam::surfMesh::~surfMesh() Foam::surfMesh::~surfMesh()
{ {
// clearOut(); // clearOut();
// resetMotion(); // resetMotion();
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * 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 void Foam::surfMesh::resetPrimitives
( (
const Xfer<pointField>& points, const Xfer< pointField >& points,
const Xfer<faceList>& faces, const Xfer< faceList >& faces,
const Xfer<surfZoneList>& zones, const Xfer< surfZoneList >& zones,
const bool validate const bool validate
) )
{ {
// Clear addressing. // Clear addressing.
MeshReference::clearGeom(); MeshReference::clearGeom();
// Take over new primitive data. Allocator::reset(points, faces, zones);
// Optimized to avoid overwriting data at all this->updateRefs();
if (&points)
{
storedPoints_.transfer(points());
}
if (&faces)
{
storedFaces_.transfer(faces());
}
if (&zones)
{
surfZones_.transfer(zones());
}
if (validate) if (validate)
{ {
@ -255,6 +271,7 @@ void Foam::surfMesh::resetPrimitives
} }
void Foam::surfMesh::transfer void Foam::surfMesh::transfer
( (
MeshedSurface<face>& surf MeshedSurface<face>& surf
@ -263,9 +280,11 @@ void Foam::surfMesh::transfer
// Clear addressing. // Clear addressing.
MeshReference::clearGeom(); MeshReference::clearGeom();
storedPoints_.transfer(surf.storedPoints()); this->storedIOPoints().transfer(surf.storedPoints());
storedFaces_.transfer(surf.storedFaces()); this->storedIOFaces().transfer(surf.storedFaces());
surfZones_.transfer(surf.storedZones()); this->storedIOZones().transfer(surf.storedZones());
this->updateRefs();
} }
@ -274,9 +293,12 @@ Foam::surfMesh::xfer()
{ {
Xfer< MeshedSurface<face> > xf; Xfer< MeshedSurface<face> > xf;
xf().storedPoints().transfer(storedPoints_); xf().storedPoints().transfer(this->storedPoints());
xf().storedFaces().transfer(storedFaces_); xf().storedFaces().transfer(this->storedFaces());
xf().storedZones().transfer(surfZones_); xf().storedZones().transfer(this->storedZones());
// is this needed?
this->updateRefs();
// Clear addressing. // Clear addressing.
MeshReference::clearGeom(); 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 Foam::fileName Foam::surfMesh::meshDir() const
{ {
return dbDir()/meshSubDir; return dbDir()/meshSubDir;
@ -304,51 +315,53 @@ Foam::fileName Foam::surfMesh::meshDir() const
const Foam::fileName& Foam::surfMesh::pointsInstance() const const Foam::fileName& Foam::surfMesh::pointsInstance() const
{ {
return storedPoints_.instance(); return this->storedIOPoints().instance();
} }
const Foam::fileName& Foam::surfMesh::facesInstance() const const Foam::fileName& Foam::surfMesh::facesInstance() const
{ {
return storedFaces_.instance(); return this->storedIOFaces().instance();
} }
Foam::label Foam::surfMesh::nPoints() const Foam::label Foam::surfMesh::nPoints() const
{ {
return storedPoints_.size(); return this->points().size();
} }
Foam::label Foam::surfMesh::nFaces() const Foam::label Foam::surfMesh::nFaces() const
{ {
return storedFaces_.size(); return this->faces().size();
} }
const Foam::pointField& Foam::surfMesh::points() const const Foam::pointField& Foam::surfMesh::points() const
{ {
return storedPoints_; return this->storedIOPoints();
} }
const Foam::faceList& Foam::surfMesh::faces() const const Foam::faceList& Foam::surfMesh::faces() const
{ {
return storedFaces_; return this->storedIOFaces();
} }
void Foam::surfMesh::checkZones() void Foam::surfMesh::checkZones()
{ {
// extra safety, ensure we have at some zones // extra safety, ensure we have at some zones
// and they cover all the faces - fix start silently // and they cover all the faces - fix start silently
if (surfZones_.size() <= 1) surfZoneList& zones = Allocator::storedIOZones();
if (zones.size() <= 1)
{ {
oneZone(); removeZones();
} }
else else
{ {
label count = 0; label count = 0;
forAll(surfZones_, zoneI) forAll(zones, zoneI)
{ {
surfZones_[zoneI].start() = count; zones[zoneI].start() = count;
count += surfZones_[zoneI].size(); count += zones[zoneI].size();
} }
if (count < nFaces()) if (count < nFaces())
@ -361,7 +374,7 @@ void Foam::surfMesh::checkZones()
<< " ... extending final zone" << " ... extending final zone"
<< endl; << endl;
surfZones_[surfZones_.size()-1].size() += count - nFaces(); zones[zones.size()-1].size() += count - nFaces();
} }
else if (count > size()) else if (count > size())
{ {
@ -379,15 +392,15 @@ void Foam::surfMesh::checkZones()
// Add boundary patches. Constructor helper // Add boundary patches. Constructor helper
void Foam::surfMesh::addZones void Foam::surfMesh::addZones
( (
const surfZoneList& zones, const surfZoneList& srfZones,
const bool validate 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) if (validate)
@ -412,4 +425,22 @@ void Foam::surfMesh::removeFiles() const
removeFiles(instance()); 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 #define surfMesh_H
#include "surfaceRegistry.H" #include "surfaceRegistry.H"
#include "MeshedSurfaceIOAllocator.H"
#include "PrimitivePatch.H" #include "PrimitivePatch.H"
#include "pointField.H" #include "SubField.H"
#include "faceList.H"
#include "pointIOField.H"
#include "faceIOList.H"
#include "labelIOList.H"
#include "surfZoneIOList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
template<class Face> template<class Face> class MeshedSurface;
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)
{}
};
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class surfMesh Declaration Class surfMesh Declaration
@ -106,9 +56,9 @@ protected:
class surfMesh class surfMesh
: :
public surfaceRegistry, public surfaceRegistry,
public surfMeshAllocator, private MeshedSurfaceIOAllocator,
public PrimitivePatch<face, ::Foam::UList, const pointField&, point> public PrimitivePatch<face, ::Foam::UList, ::Foam::SubField<point>, point>
{ {
public: public:
@ -117,8 +67,7 @@ public:
//- Enumeration defining the state of the mesh after a read update. //- Enumeration defining the state of the mesh after a read update.
// Used for post-processing applications, where the mesh // Used for post-processing applications, where the mesh
// needs to update based on the files written in time // needs to update based on the files written in time directores
// directores
enum readUpdateState enum readUpdateState
{ {
UNCHANGED, UNCHANGED,
@ -132,28 +81,23 @@ private:
// Private typedefs // Private typedefs
typedef MeshedSurfaceIOAllocator Allocator;
typedef PrimitivePatch typedef PrimitivePatch
< <
face, face,
::Foam::UList, ::Foam::UList,
const pointField&, ::Foam::SubField<point>,
point point
> >
MeshReference; MeshReference;
// Permanent data // Permanent data
// Zoning information
//- Face zones
surfZoneIOList surfZones_;
// Private member functions // Private member functions
//- Set a single zone
void oneZone();
//- Disallow construct as copy //- Disallow construct as copy
surfMesh(const surfMesh&); surfMesh(const surfMesh&);
@ -165,23 +109,33 @@ protected:
// Protected Member Functions // Protected Member Functions
//- Non-const access to global points //- Non-const access to global points
pointIOField& storedPoints() pointField& storedPoints()
{ {
return surfMeshAllocator::storedPoints_; return Allocator::storedIOPoints();
} }
//- Non-const access to the faces //- Non-const access to the faces
faceIOList& storedFaces() faceList& storedFaces()
{ {
return surfMeshAllocator::storedFaces_; return Allocator::storedIOFaces();
} }
//- Non-const access to the zones //- 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:
// Public typedefs // Public typedefs
@ -247,10 +201,10 @@ public:
// Access // Access
//- Return raw points //- Return the number of raw points
virtual label nPoints() const; virtual label nPoints() const;
//- Return raw faces //- Return the number of raw faces
virtual label nFaces() const; virtual label nFaces() const;
//- Return number of faces //- Return number of faces
@ -260,28 +214,22 @@ public:
} }
//- Return raw points //- Return points
virtual const pointField& points() const; virtual const pointField& points() const;
//- Return raw faces //- Return faces
virtual const faceList& faces() const; virtual const faceList& faces() const;
//- Return surface zones //- Return surface zones
const surfZoneList& surfZones() const virtual const surfZoneList& surfZones() const
{ {
return surfZones_; return Allocator::storedIOZones();
}
//- Return non-const access to the zones
surfZoneList& surfZones()
{
return surfZones_;
} }
//- Check the surface zone definitions //- Check the surface zone definitions
void checkZones(); void checkZones();
//- Add surface zones patches //- Add surface zones
void addZones void addZones
( (
const List<surfZone>&, const List<surfZone>&,
@ -297,15 +245,12 @@ public:
//- Remove surface zones //- Remove surface zones
void removeZones(); void removeZones();
//- Rename surface
virtual void rename(const word&);
//- Reset mesh primitive data. //- Reset mesh primitive data.
void resetPrimitives void resetPrimitives
( (
const Xfer<pointField>& points, const Xfer< pointField >& points,
const Xfer<faceList>& faces, const Xfer< faceList >& faces,
const Xfer<surfZoneList>& zones, const Xfer< surfZoneList >& zones,
const bool validate = true const bool validate = true
); );
@ -313,6 +258,18 @@ public:
//- Transfer the contents of the argument and annull the argument //- Transfer the contents of the argument and annull the argument
void transfer(MeshedSurface<face>&); 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 // Storage management
//- Transfer contents to the Xfer container as a MeshedSurface //- Transfer contents to the Xfer container as a MeshedSurface

View File

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

View File

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

View File

@ -26,7 +26,6 @@ License
#include "AC3DsurfaceFormat.H" #include "AC3DsurfaceFormat.H"
#include "clock.H" #include "clock.H"
#include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "tensor.H" #include "tensor.H"
#include "primitivePatch.H" #include "primitivePatch.H"
@ -281,26 +280,65 @@ bool Foam::fileFormats::AC3DsurfaceFormat<Face>::read
template<class Face> template<class Face>
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
( (
Ostream& os, const fileName& filename,
const pointField& pointLst, const MeshedSurfaceProxy<Face>& surf
const List<Face>& faceLst,
const List<surfZone>& zoneLst
) )
{ {
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 os << "OBJECT poly" << nl
<< "name \"" << zone.name() << '"' << endl; << "name \"" << zone.name() << "\"\n";
// Temporary PrimitivePatch to calculate compact points & faces // Temporary PrimitivePatch to calculate compact points & faces
// use 'UList' to avoid allocations! // use 'UList' to avoid allocations!
PrimitivePatch<Face, UList, const pointField&> patch PrimitivePatch<Face, UList, const pointField&> patch
( (
faceLst, SubList<Face>
(
faceLst,
zone.size(),
zone.start()
),
pointLst pointLst
); );
@ -310,7 +348,7 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
{ {
const point& pt = patch.localPoints()[ptI]; 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; os << "numsurf " << patch.localFaces().size() << endl;
@ -337,72 +375,89 @@ void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
template<class Face> template<class Face>
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
( (
Ostream& os, const fileName& filename,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::AC3DsurfaceFormat<Face>::write
(
Ostream& os,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf
) )
{ {
labelList faceMap; labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap); List<surfZone> zoneLst = surf.sortedZones(faceMap);
writeHeader(os, zoneLst); if (zoneLst.size() <= 1)
label faceIndex = 0;
forAll(zoneLst, zoneI)
{ {
const surfZone& zone = zoneLst[zoneI]; write
(
os << "OBJECT poly" << nl filename,
<< "name \"" << zone.name() << '"' << endl; MeshedSurfaceProxy<Face>
(
// Create zone with only zone faces included for ease of addressing surf.points(),
labelHashSet include(surf.size()); surf.faces(),
zoneLst
forAll(zone, localFaceI) )
);
}
else
{
OFstream os(filename);
if (!os.good())
{ {
const label faceI = faceMap[faceIndex++]; FatalErrorIn
include.insert(faceI); (
"fileFormats::AC3DsurfaceFormat::write"
"(const fileName&, const MeshedSurfaceProxy<Face>&)"
)
<< "Cannot open file for writing " << filename
<< exit(FatalError);
} }
UnsortedMeshedSurface<Face> subm = surf.subsetMesh(include); writeHeader(os, zoneLst);
// Now we have isolated surface for this patch alone. Write it. label faceIndex = 0;
os << "numvert " << subm.nPoints() << endl; forAll(zoneLst, zoneI)
forAll(subm.localPoints(), ptI)
{ {
const point& pt = subm.localPoints()[ptI]; const surfZone& zone = zoneLst[zoneI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl; os << "OBJECT poly" << nl
} << "name \"" << zone.name() << "\"\n";
os << "numsurf " << subm.localFaces().size() << endl; // Create zone with only zone faces included for ease of addressing
labelHashSet include(surf.size());
forAll(subm.localFaces(), localFaceI) forAll(zone, localFaceI)
{
const Face& f = subm.localFaces()[localFaceI];
os << "SURF 0x20" << nl // polygon
<< "mat " << zoneI << nl
<< "refs " << f.size() << nl;
forAll(f, fp)
{ {
os << f[fp] << " 0 0" << nl; const label faceI = faceMap[faceIndex++];
include.insert(faceI);
} }
}
os << "kids 0" << endl; UnsortedMeshedSurface<Face> subm = surf.subsetMesh(include);
// Now we have isolated surface for this patch alone. Write it.
os << "numvert " << subm.nPoints() << endl;
forAll(subm.localPoints(), ptI)
{
const point& pt = subm.localPoints()[ptI];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << endl;
}
os << "numsurf " << subm.localFaces().size() << endl;
forAll(subm.localFaces(), localFaceI)
{
const Face& f = subm.localFaces()[localFaceI];
os << "SURF 0x20" << nl // polygon
<< "mat " << zoneI << nl
<< "refs " << f.size() << nl;
forAll(f, fp)
{
os << f[fp] << " 0 0" << nl;
}
}
os << "kids 0" << endl;
}
} }
} }

View File

@ -31,8 +31,9 @@ Description
http://www.inivis.com/ac3d/man/ac3dfileformat.html http://www.inivis.com/ac3d/man/ac3dfileformat.html
Note Note
The faces are already organized as zones. On input, the faces are already organized as zones.
The output is always sorted by zones. The output is always sorted by zones.
In the absence of zones, a single zone will be assigned.
SourceFiles SourceFiles
AC3DsurfaceFormat.C AC3DsurfaceFormat.C
@ -42,9 +43,8 @@ SourceFiles
#ifndef AC3DsurfaceFormat_H #ifndef AC3DsurfaceFormat_H
#define AC3DsurfaceFormat_H #define AC3DsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
#include "AC3DsurfaceFormatCore.H" #include "AC3DsurfaceFormatCore.H"
@ -99,58 +99,20 @@ public:
// Member Functions // 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 //- Read from file
virtual bool read(const fileName&); 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 //- 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 #ifndef AC3DsurfaceFormatCore_H
#define AC3DsurfaceFormatCore_H #define AC3DsurfaceFormatCore_H
#include "IFstream.H"
#include "Ostream.H" #include "Ostream.H"
#include "OFstream.H" #include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

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

View File

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

View File

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

View File

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

View File

@ -27,7 +27,8 @@ Class
Description Description
Provide a means of reading/writing GTS format. 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 SourceFiles
GTSsurfaceFormat.C GTSsurfaceFormat.C
@ -37,9 +38,8 @@ SourceFiles
#ifndef GTSsurfaceFormat_H #ifndef GTSsurfaceFormat_H
#define GTSsurfaceFormat_H #define GTSsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -90,49 +90,20 @@ public:
// Member Functions // 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 //- Read from file
virtual bool read(const fileName&); 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 //- 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 "GTSsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H" #include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats namespace fileFormats
{ {
// read UnsortedMeshedSurface
addNamedTemplatedToRunTimeSelectionTable addNamedTemplatedToRunTimeSelectionTable
( (
UnsortedMeshedSurface, UnsortedMeshedSurface,
@ -53,6 +53,7 @@ addNamedTemplatedToRunTimeSelectionTable
gts gts
); );
// write MeshedSurface
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
MeshedSurface, MeshedSurface,
@ -72,6 +73,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
gts gts
); );
// write UnsortedMeshedSurface
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
UnsortedMeshedSurface, UnsortedMeshedSurface,

View File

@ -76,6 +76,7 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
Map<label> lookup; Map<label> lookup;
// assume the types are not intermixed // assume the types are not intermixed
// leave faces that didn't have a group in 0
bool sorted = true; bool sorted = true;
label zoneI = 0; label zoneI = 0;
@ -89,10 +90,6 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
label ansaId = -1; label ansaId = -1;
word ansaType, ansaName; 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 // A single warning per unrecognized command
HashSet<word> unhandledCmd; HashSet<word> unhandledCmd;
@ -374,8 +371,8 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
List<word> names(dynSizes.size()); List<word> names(dynSizes.size());
forAllConstIter(Map<label>, lookup, iter) forAllConstIter(Map<label>, lookup, iter)
{ {
const label zoneI = iter(); const label zoneI = iter();
const label groupI = iter.key(); const label groupI = iter.key();
Map<word>::const_iterator fnd = nameLookup.find(groupI); Map<word>::const_iterator fnd = nameLookup.find(groupI);
if (fnd != nameLookup.end()) if (fnd != nameLookup.end())
@ -388,7 +385,6 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
} }
} }
sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted); sortFacesAndStore(dynFaces.xfer(), dynZones.xfer(), sorted);
// add zones, culling empty ones // add zones, culling empty ones

View File

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

View File

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

View File

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

View File

@ -25,8 +25,11 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "OBJsurfaceFormat.H" #include "OBJsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H" #include "IFstream.H"
#include "IStringStream.H" #include "IStringStream.H"
#include "Ostream.H"
#include "OFstream.H"
#include "ListOps.H" #include "ListOps.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -213,84 +216,108 @@ bool Foam::fileFormats::OBJsurfaceFormat<Face>::read
template<class Face> template<class Face>
void Foam::fileFormats::OBJsurfaceFormat<Face>::write void Foam::fileFormats::OBJsurfaceFormat<Face>::write
( (
Ostream& os, const fileName& filename,
const pointField& pointLst, const MeshedSurfaceProxy<Face>& surf
const List<Face>& faceLst,
const List<surfZone>& zoneLst
) )
{ {
writeHeader(os, pointLst, faceLst.size(), zoneLst); const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
const List<label>& faceMap = surf.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;
label faceIndex = 0; label faceIndex = 0;
forAll(zoneLst, zoneI) forAll(zones, zoneI)
{ {
const surfZone& zone = zoneLst[zoneI]; const surfZone& zone = zones[zoneI];
os << "g " << zone.name() << endl; if (zone.name().size())
forAll(zone, localFaceI)
{ {
const Face& f = faceLst[faceIndex++]; os << "g " << zone.name() << endl;
}
os << 'f'; if (useFaceMap)
forAll(f, fp) {
forAll(zone, localFaceI)
{ {
os << ' ' << f[fp] + 1; const Face& f = faceLst[faceMap[faceIndex++]];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << endl;
}
}
else
{
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceIndex++];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << endl;
} }
os << endl;
} }
} }
os << "# </faces>" << 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 List<Face>& faceLst = surf.faces();
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
writeHeader(os, surf.points(), faceLst.size(), zoneLst);
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
// Print all faces belonging to this zone
const surfZone& zone = zoneLst[zoneI];
os << "g " << zone.name() << endl;
forAll(zone, localFaceI)
{
const Face& f = faceLst[faceMap[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 #ifndef OBJsurfaceFormat_H
#define OBJsurfaceFormat_H #define OBJsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
#include "OBJsurfaceFormatCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -58,8 +56,7 @@ namespace fileFormats
template<class Face> template<class Face>
class OBJsurfaceFormat class OBJsurfaceFormat
: :
public MeshedSurface<Face>, public MeshedSurface<Face>
public OBJsurfaceFormatCore
{ {
// Private Member Functions // Private Member Functions
@ -95,58 +92,16 @@ public:
// Member Functions // Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write surface mesh components //- Write object file
static void write virtual void write(const fileName& name) const
(
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(name, MeshedSurfaceProxy<Face>(*this));
}
//- 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);
} }
}; };

View File

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

View File

@ -46,11 +46,9 @@ SourceFiles
#ifndef OFFsurfaceFormat_H #ifndef OFFsurfaceFormat_H
#define OFFsurfaceFormat_H #define OFFsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
#include "OFFsurfaceFormatCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -66,8 +64,7 @@ namespace fileFormats
template<class Face> template<class Face>
class OFFsurfaceFormat class OFFsurfaceFormat
: :
public MeshedSurface<Face>, public MeshedSurface<Face>
public OFFsurfaceFormatCore
{ {
// Private Member Functions // Private Member Functions
@ -101,58 +98,17 @@ public:
// Member Functions // Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Read from file //- Read from file
virtual bool read(const fileName&); 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 //- 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 "OFFsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H" #include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats namespace fileFormats
{ {
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable addNamedTemplatedToRunTimeSelectionTable
( (
MeshedSurface, MeshedSurface,
@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable
off off
); );
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
MeshedSurface, MeshedSurfaceProxy,
OFFsurfaceFormat, OFFsurfaceFormat,
face, face,
write, write,
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
); );
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
MeshedSurface, MeshedSurfaceProxy,
OFFsurfaceFormat, OFFsurfaceFormat,
triFace, triFace,
write, 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,51 +24,53 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "OBJsurfaceFormatCore.H" #include "OFSsurfaceFormatCore.H"
#include "clock.H" #include "clock.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::fileFormats::OBJsurfaceFormatCore::writeHeader void Foam::fileFormats::OFSsurfaceFormatCore::writeHeader
( (
Ostream& os, Ostream& os,
const pointField& pointLst, const pointField& pointLst,
const label nFaces,
const UList<surfZone>& zoneLst const UList<surfZone>& zoneLst
) )
{ {
os << "# Wavefront OBJ file written " << clock::dateTime().c_str() << nl // just emit some information until we get a nice IOobject
<< "o " << os.name().lessExt().name() << nl IOobject::writeBanner(os)
<< nl << "// OpenFOAM Surface Format - written "
<< "# points : " << pointLst.size() << nl << clock::dateTime().c_str() << nl
<< "# faces : " << nFaces << nl << "// ~~~~~~~~~~~~~~~~~~~~~~~" << nl << nl
<< "# zones : " << zoneLst.size() << nl; << "// surfZones:" << nl;
// Print zone names as comment
forAll(zoneLst, zoneI) // treat a single zone as being unzoned
if (zoneLst.size() <= 1)
{ {
os << "# " << zoneI << " " << zoneLst[zoneI].name() os << "0" << token::BEGIN_LIST << token::END_LIST << nl << nl;
<< " (nFaces: " << zoneLst[zoneI].size() << ")" << nl; }
else
{
os << zoneLst.size() << nl << token::BEGIN_LIST << incrIndent << nl;
forAll(zoneLst, zoneI)
{
zoneLst[zoneI].writeDict(os);
}
os << decrIndent << token::END_LIST << nl << nl;
} }
os << nl // Note: write with global point numbering
<< "# <points count=\"" << pointLst.size() << "\">" << endl;
// Write vertex coords IOobject::writeDivider(os)
forAll(pointLst, ptI) << "\n// points:" << nl << pointLst << nl;
{
os << "v " << pointLst[ptI].x()
<< ' ' << pointLst[ptI].y()
<< ' ' << pointLst[ptI].z() << nl;
}
os << "# </points>" << nl IOobject::writeDivider(os);
<< nl
<< "# <faces count=\"" << nFaces << "\">" << endl;
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* // // ************************************************************************* //

View File

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

View File

@ -22,61 +22,60 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation, along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 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 #include "OFSsurfaceFormat.H"
#define SMESHsurfaceFormatCore_H
#include "Ostream.H" #include "addToRunTimeSelectionTable.H"
#include "MeshedSurface.H" #include "addToMemberFunctionSelectionTable.H"
#include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
namespace fileFormats namespace fileFormats
{ {
/*---------------------------------------------------------------------------*\ // read MeshedSurface
Class SMESHsurfaceFormatCore Declaration addNamedTemplatedToRunTimeSelectionTable
\*---------------------------------------------------------------------------*/ (
MeshedSurface,
class SMESHsurfaceFormatCore OFSsurfaceFormat,
{ face,
protected: fileExtension,
// Protected Member Functions ofs
);
//- Write header information with points addNamedTemplatedToRunTimeSelectionTable
static void writeHeader (
( MeshedSurface,
Ostream&, OFSsurfaceFormat,
const pointField&, triFace,
const label nFaces 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 "SMESHsurfaceFormat.H"
#include "clock.H"
#include "IFstream.H"
#include "OFstream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -41,76 +45,98 @@ Foam::fileFormats::SMESHsurfaceFormat<Face>::SMESHsurfaceFormat()
template<class Face> template<class Face>
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write void Foam::fileFormats::SMESHsurfaceFormat<Face>::write
( (
Ostream& os, const fileName& filename,
const pointField& pointLst, const MeshedSurfaceProxy<Face>& surf
const List<Face>& faceLst,
const List<surfZone>& zoneLst
) )
{ {
writeHeader(os, pointLst, faceLst.size()); 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::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
label faceIndex = 0; label faceIndex = 0;
forAll(zoneLst, zoneI) forAll(zones, zoneI)
{ {
forAll(zoneLst[zoneI], localFaceI) const surfZone& zone = zones[zoneI];
{
const Face& f = faceLst[faceIndex++];
os << f.size(); if (useFaceMap)
forAll(f, fp) {
forAll(zone, localFaceI)
{ {
os << ' ' << f[fp]; const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << zoneI << endl;
}
}
else
{
forAll(zones[zoneI], localFaceI)
{
const Face& f = faceLst[faceIndex++];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << zoneI << endl;
} }
os << ' ' << zoneI << endl;
} }
} }
writeTail(os); // write tail
}
os << "# </faces>" << nl
template<class Face> << nl
void Foam::fileFormats::SMESHsurfaceFormat<Face>::write << "# no holes or regions:" << nl
( << '0' << nl // holes
Ostream& os, << '0' << endl; // regions
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 List<Face>& faceLst = surf.faces();
writeHeader(os, surf.points(), faceLst.size());
labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap);
label faceIndex = 0;
forAll(zoneLst, zoneI)
{
forAll(zoneLst[zoneI], localFaceI)
{
const Face& f = faceLst[faceMap[faceIndex++]];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << zoneI << endl;
}
}
writeTail(os);
} }

View File

@ -42,12 +42,9 @@ SourceFiles
#ifndef SMESHsurfaceFormat_H #ifndef SMESHsurfaceFormat_H
#define SMESHsurfaceFormat_H #define SMESHsurfaceFormat_H
#include "IFstream.H"
#include "OFstream.H"
#include "Ostream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
#include "SMESHsurfaceFormatCore.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,8 +60,7 @@ namespace fileFormats
template<class Face> template<class Face>
class SMESHsurfaceFormat class SMESHsurfaceFormat
: :
public MeshedSurface<Face>, public MeshedSurface<Face>
public SMESHsurfaceFormatCore
{ {
// Private Member Functions // Private Member Functions
@ -91,55 +87,14 @@ public:
// Member Functions // Member Functions
//- Write surface mesh components //- Write surface mesh components by proxy
static void write static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
(
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 //- 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 "SMESHsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H" #include "addToMemberFunctionSelectionTable.H"
@ -36,9 +35,10 @@ namespace Foam
namespace fileFormats namespace fileFormats
{ {
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
MeshedSurface, MeshedSurfaceProxy,
SMESHsurfaceFormat, SMESHsurfaceFormat,
face, face,
write, write,
@ -47,26 +47,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
); );
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
MeshedSurface, MeshedSurfaceProxy,
SMESHsurfaceFormat,
triFace,
write,
fileExtension,
smesh
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
SMESHsurfaceFormat,
face,
write,
fileExtension,
smesh
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
SMESHsurfaceFormat, SMESHsurfaceFormat,
triFace, triFace,
write, write,

View File

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

View File

@ -42,9 +42,8 @@ SourceFiles
#ifndef STARCDsurfaceFormat_H #ifndef STARCDsurfaceFormat_H
#define STARCDsurfaceFormat_H #define STARCDsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
#include "STARCDsurfaceFormatCore.H" #include "STARCDsurfaceFormatCore.H"
@ -114,37 +113,17 @@ public:
// Member Functions // Member Functions
//- Write surface mesh components by proxy
static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
//- Read from file //- Read from file
virtual bool read(const fileName&); virtual bool read(const fileName&);
//- Write surface mesh components //- Write object
static void write virtual void write(const fileName& name) const
(
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
{ {
notImplemented("fileFormats::STARCDsurfaceFormat::write(Ostream&)"); write(name, MeshedSurfaceProxy<Face>(*this));
} }
}; };

View File

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

View File

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

View File

@ -25,8 +25,7 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "STARCDsurfaceFormat.H" #include "STARCDsurfaceFormat.H"
#include "MeshedSurface.H"
#include "UnsortedMeshedSurface.H"
#include "addToRunTimeSelectionTable.H" #include "addToRunTimeSelectionTable.H"
#include "addToMemberFunctionSelectionTable.H" #include "addToMemberFunctionSelectionTable.H"
@ -36,6 +35,7 @@ namespace Foam
namespace fileFormats namespace fileFormats
{ {
// read MeshedSurface
addNamedTemplatedToRunTimeSelectionTable addNamedTemplatedToRunTimeSelectionTable
( (
MeshedSurface, MeshedSurface,
@ -53,10 +53,10 @@ addNamedTemplatedToRunTimeSelectionTable
inp inp
); );
// write MeshedSurfaceProxy
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
MeshedSurface, MeshedSurfaceProxy,
STARCDsurfaceFormat, STARCDsurfaceFormat,
face, face,
write, write,
@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
); );
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
MeshedSurface, MeshedSurfaceProxy,
STARCDsurfaceFormat, STARCDsurfaceFormat,
triFace, triFace,
write, 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 * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Face> template<class Face>
@ -274,25 +189,61 @@ bool Foam::fileFormats::STLsurfaceFormat<Face>::read
} }
template<class Face> template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
( (
Ostream& os, const fileName& filename,
const pointField& pointLst, const MeshedSurfaceProxy<Face>& surf
const List<Face>& faceLst,
const List<surfZone>& zoneLst
) )
{ {
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; label faceIndex = 0;
forAll(zoneLst, zoneI) forAll(zones, zoneI)
{ {
// Print all faces belonging to this zone // 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;
forAll(zone, localFaceI)
if (useFaceMap)
{ {
writeShell(os, pointLst, faceLst[faceIndex++]); 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; os << "endsolid " << zone.name() << endl;
} }
@ -300,29 +251,116 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
template<class Face> template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write void Foam::fileFormats::STLsurfaceFormat<Face>::writeBinary
( (
Ostream& os, const fileName& filename,
const MeshedSurface<Face>& surf 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> template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write void Foam::fileFormats::STLsurfaceFormat<Face>::writeAscii
( (
Ostream& os, const fileName& filename,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf
) )
{ {
const pointField& pointLst = surf.points(); OFstream os(filename);
const List<Face>& faceLst = surf.faces(); 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) if (surf.zoneToc().size() == 1)
{ {
// a single zone - we can skip sorting const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces();
os << "solid " << surf.zoneToc()[0].name() << endl; os << "solid " << surf.zoneToc()[0].name() << endl;
forAll(faceLst, faceI) forAll(faceLst, faceI)
{ {
@ -332,32 +370,82 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
} }
else else
{ {
labelList faceMap; labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(faceMap); List<surfZone> zoneLst = surf.sortedZones(faceMap);
label faceIndex = 0; writeAscii
forAll(zoneLst, zoneI) (
{ filename,
// Print all faces belonging to this zone MeshedSurfaceProxy<Face>
const surfZone& zone = zoneLst[zoneI]; (
surf.points(),
os << "solid " << zone.name() << endl; surf.faces(),
forAll(zone, localFaceI) zoneLst,
{ faceMap
const label faceI = faceMap[faceIndex++]; )
writeShell(os, pointLst, faceLst[faceI]); );
}
os << "endsolid " << zone.name() << endl;
}
} }
} }
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> template<class Face>
void Foam::fileFormats::STLsurfaceFormat<Face>::write void Foam::fileFormats::STLsurfaceFormat<Face>::write
( (
const fileName& filename, const fileName& filename,
const MeshedSurface<Face>& surf const MeshedSurfaceProxy<Face>& surf
) )
{ {
const word ext = filename.ext(); const word ext = filename.ext();
@ -365,18 +453,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
// handle 'stlb' as binary directly // handle 'stlb' as binary directly
if (ext == "stlb") if (ext == "stlb")
{ {
std::ofstream ofs(filename.c_str(), std::ios::binary); writeBinary(filename, surf);
writeBINARY(ofs, surf);
} }
else else
{ {
write writeAscii(filename, surf);
(
OFstream(filename)(),
surf.points(),
surf.faces(),
surf.zones()
);
} }
} }
@ -393,12 +474,11 @@ void Foam::fileFormats::STLsurfaceFormat<Face>::write
// handle 'stlb' as binary directly // handle 'stlb' as binary directly
if (ext == "stlb") if (ext == "stlb")
{ {
std::ofstream ofs(filename.c_str(), std::ios::binary); writeBinary(filename, surf);
writeBINARY(ofs, surf);
} }
else else
{ {
write(OFstream(filename)(), surf); writeAscii(filename, surf);
} }
} }

View File

@ -43,6 +43,7 @@ SourceFiles
#include "STLsurfaceFormatCore.H" #include "STLsurfaceFormatCore.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -63,7 +64,7 @@ class STLsurfaceFormat
{ {
// Private Member Functions // Private Member Functions
//- Write Face in ASCII //- Write Face (ASCII)
static inline void writeShell static inline void writeShell
( (
Ostream&, Ostream&,
@ -71,7 +72,7 @@ class STLsurfaceFormat
const Face& const Face&
); );
//- Write Face in BINARY //- Write Face (BINARY)
static inline void writeShell static inline void writeShell
( (
ostream&, ostream&,
@ -80,19 +81,6 @@ class STLsurfaceFormat
const label zoneI 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 //- Disallow default bitwise copy construct
STLsurfaceFormat(const STLsurfaceFormat<Face>&); STLsurfaceFormat(const STLsurfaceFormat<Face>&);
@ -122,51 +110,50 @@ public:
// Member Functions // Member Functions
//- Read from file //- Write surface mesh components by proxy (as ASCII)
virtual bool read(const fileName&); static void writeAscii
//- 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
( (
const fileName&, const fileName&,
const MeshedSurface<Face>& const MeshedSurfaceProxy<Face>&
); );
//- Write UnsortedMeshedSurface (as ASCII) sorted by zone //- Write surface mesh components by proxy (as BINARY)
static void write 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>& const UnsortedMeshedSurface<Face>&
); );
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// ASCII output is sorted by zone; binary output is unsorted // as ASCII or BINARY, depending on the extension
static void write static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
(
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 bool Foam::fileFormats::STLsurfaceFormatCore::readASCII
( (
IFstream& ifs, istream& is,
const off_t dataFileSize const off_t dataFileSize
) )
{ {
// Create the lexer with the approximate number of vertices in the STL // Create the lexer with the approximate number of vertices in the STL
// from the file size // from the file size
STLASCIILexer lexer(&ifs.stdStream(), dataFileSize/400); STLASCIILexer lexer(&is, dataFileSize/400);
while (lexer.lex() != 0) {} while (lexer.lex() != 0) {}
sorted_ = lexer.sorted(); sorted_ = lexer.sorted();

View File

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

View File

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

View File

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

View File

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

View File

@ -61,30 +61,19 @@ namespace fileFormats
class surfaceFormatsCore class surfaceFormatsCore
{ {
public: protected:
// Static Data //- Return a list with a single entry,
// the size corresponds to that of the container
//- The file extension corresponding to 'native' surface format template<class Container>
// Normally "ofs" (mnemonic: OF = OpenFOAM, S = Surface) static List<surfZone> oneZone
static word nativeExt; (
const Container& container,
// Static Member Functions const word& name = "zone0"
)
//- Check if file extension corresponds to 'native' surface format {
static bool isNative(const word&); return List<surfZone>(1, surfZone(name, container.size(), 0, 0));
}
//- Read non-comment line
static string getLineNoComment(IFstream&);
//- Return the local file name (within time directory)
static fileName localMeshFileName(const word& surfName="");
//- Find instance with surfName
static fileName findMeshInstance(const Time&, const word& surfName="");
//- Find mesh file with surfName
static fileName findMeshFile(const Time&, const word& surfName="");
//- Determine the sort order from the zone ids. //- Determine the sort order from the zone ids.
// Returns zone list and sets faceMap to indices within faceLst // Returns zone list and sets faceMap to indices within faceLst
@ -95,6 +84,31 @@ public:
labelList& faceMap labelList& faceMap
); );
//- Read non-comment line
static string getLineNoComment(IFstream&);
public:
// Static Data
//- The file extension corresponding to 'native' surface format
// Normally "ofs" (mnemonic: OF = OpenFOAM, S = Surface)
static word nativeExt;
// Static Member Functions
//- Check if file extension corresponds to 'native' surface format
static bool isNative(const word&);
//- Return the local file name (within time directory)
static fileName localMeshFileName(const word& surfName="");
//- Find instance with surfName
static fileName findMeshInstance(const Time&, const word& surfName="");
//- Find mesh file with surfName
static fileName findMeshFile(const Time&, const word& surfName="");
static bool checkSupport static bool checkSupport
( (
const wordHashSet& available, const wordHashSet& available,
@ -103,6 +117,7 @@ public:
const word& functionName const word& functionName
); );
// Constructors // Constructors
//- Construct null //- Construct null

View File

@ -131,19 +131,55 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
template<class Face> template<class Face>
void Foam::fileFormats::TRIsurfaceFormat<Face>::write void Foam::fileFormats::TRIsurfaceFormat<Face>::write
( (
Ostream& os, const fileName& filename,
const pointField& pointLst, const MeshedSurfaceProxy<Face>& surf
const List<Face>& faceLst,
const List<surfZone>& zoneLst
) )
{ {
label faceIndex = 0; const pointField& pointLst = surf.points();
forAll(zoneLst, zoneI) 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)
{ {
const Face& f = faceLst[faceIndex++]; forAll(zone, localFaceI)
writeShell(os, pointLst, f, zoneI); {
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);
}
} }
} }
} }
@ -152,32 +188,37 @@ void Foam::fileFormats::TRIsurfaceFormat<Face>::write
template<class Face> template<class Face>
void Foam::fileFormats::TRIsurfaceFormat<Face>::write void Foam::fileFormats::TRIsurfaceFormat<Face>::write
( (
Ostream& os, const fileName& filename,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::TRIsurfaceFormat<Face>::write
(
Ostream& os,
const UnsortedMeshedSurface<Face>& surf const UnsortedMeshedSurface<Face>& surf
) )
{ {
const pointField& pointLst = surf.points(); const pointField& pointLst = surf.points();
const List<Face>& faceLst = surf.faces(); 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 // a single zone needs no sorting
if (surf.zoneToc().size() == 1) 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; labelList faceMap;
List<surfZone> zoneLst = surf.sortedZones(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 #define TRIsurfaceFormat_H
#include "TRIsurfaceFormatCore.H" #include "TRIsurfaceFormatCore.H"
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -102,58 +101,21 @@ public:
// Member Functions // 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 //- Read from file
virtual bool read(const fileName&); 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 //- 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 "surfaceFormatsCore.H"
#include "triFace.H" #include "triFace.H"
#include "IFstream.H" #include "IFstream.H"
#include "Ostream.H" #include "Ostream.H"
#include "OFstream.H" #include "OFstream.H"

View File

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

View File

@ -61,53 +61,98 @@ Foam::fileFormats::VTKsurfaceFormat<Face>::VTKsurfaceFormat()
template<class Face> template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write void Foam::fileFormats::VTKsurfaceFormat<Face>::write
( (
Ostream& os, const fileName& filename,
const pointField& pointLst, const MeshedSurfaceProxy<Face>& surf
const List<Face>& faceLst,
const List<surfZone>& zoneLst
) )
{ {
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); writeHeader(os, pointLst);
writeHeaderPolygons(os, faceLst); writeHeaderPolygons(os, faceLst);
label faceIndex = 0; label faceIndex = 0;
forAll(zoneLst, zoneI) forAll(zones, zoneI)
{ {
forAll(zoneLst[zoneI], localFaceI) const surfZone& zone = zones[zoneI];
{
const Face& f = faceLst[faceIndex++];
os << f.size(); if (useFaceMap)
forAll(f, fp) {
forAll(zone, localFaceI)
{ {
os << ' ' << f[fp]; 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++];
os << f.size();
forAll(f, fp)
{
os << ' ' << f[fp];
}
os << ' ' << nl;
} }
os << ' ' << nl;
} }
} }
writeTail(os, zoneLst); writeTail(os, zones);
} }
template<class Face> template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write void Foam::fileFormats::VTKsurfaceFormat<Face>::write
( (
Ostream& os, const fileName& filename,
const MeshedSurface<Face>& surf
)
{
write(os, surf.points(), surf.faces(), surf.zones());
}
template<class Face>
void Foam::fileFormats::VTKsurfaceFormat<Face>::write
(
Ostream& os,
const UnsortedMeshedSurface<Face>& surf 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(); const List<Face>& faceLst = surf.faces();
writeHeader(os, surf.points()); writeHeader(os, surf.points());

View File

@ -37,9 +37,8 @@ SourceFiles
#ifndef VTKsurfaceFormat_H #ifndef VTKsurfaceFormat_H
#define VTKsurfaceFormat_H #define VTKsurfaceFormat_H
#include "Ostream.H"
#include "OFstream.H"
#include "MeshedSurface.H" #include "MeshedSurface.H"
#include "MeshedSurfaceProxy.H"
#include "UnsortedMeshedSurface.H" #include "UnsortedMeshedSurface.H"
#include "VTKsurfaceFormatCore.H" #include "VTKsurfaceFormatCore.H"
@ -89,55 +88,17 @@ public:
// Write // Write
//- Write surface mesh components //- Write surface mesh components by proxy
static void write static void write(const fileName&, const MeshedSurfaceProxy<Face>&);
(
Ostream&,
const pointField&,
const List<Face>&,
const List<surfZone>&
);
//- Write MeshedSurface //- Write UnsortedMeshedSurface, the output remains unsorted
static void write static void write(const fileName&, const UnsortedMeshedSurface<Face>&);
(
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 //- Write object
virtual void write(Ostream& os) const 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; os << "POINTS " << pointLst.size() << " float" << nl;
forAll(pointLst, ptI) forAll(pointLst, ptI)
{ {
os << pointLst[ptI].x() << ' ' const point& pt = pointLst[ptI];
<< pointLst[ptI].y() << ' '
<< pointLst[ptI].z() << nl; os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
} }
} }

View File

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

View File

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