Commit c9373ba1 authored by Mark Olesen's avatar Mark Olesen
Browse files

surfMesh - reader delegation between MeshedSurface <-> UnsortedMeshedSurface

parent 1c9102da
......@@ -39,6 +39,43 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
template<class Face>
Foam::wordHashSet Foam::MeshedSurface<Face>::readTypes()
{
wordHashSet known(2*fileExtensionConstructorTablePtr_->size());
forAllIter
(
typename fileExtensionConstructorTable::iterator,
*fileExtensionConstructorTablePtr_,
iter
)
{
known.insert(iter.key());
}
return known;
}
template<class Face>
Foam::wordHashSet Foam::MeshedSurface<Face>::writeTypes()
{
wordHashSet supported(2*writefileExtensionMemberFunctionTablePtr_->size());
forAllIter
(
typename writefileExtensionMemberFunctionTable::iterator,
*writefileExtensionMemberFunctionTablePtr_,
iter
)
{
supported.insert(iter.key());
}
return supported;
}
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
......@@ -55,7 +92,10 @@ bool Foam::MeshedSurface<Face>::canReadType
return true;
}
return UnsortedMeshedSurface<Face>::canReadType(ext, verbose);
wordHashSet available = readTypes();
available += SiblingType::readTypes();
return checkSupport(available, ext, verbose, "reading");
}
......@@ -72,32 +112,7 @@ bool Foam::MeshedSurface<Face>::canWriteType
return true;
}
typename writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
if (verbose)
{
SortableList<word> known
(
writefileExtensionMemberFunctionTablePtr_->toc()
);
Info<<"Unknown file extension for writing: " << ext << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
return checkSupport(writeTypes(), ext, verbose, "writing");
}
......@@ -150,7 +165,7 @@ void Foam::MeshedSurface<Face>::write
"MeshedSurface::write(const fileName&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc()
<< writeTypes()
<< exit(FatalError);
}
......
......@@ -49,6 +49,7 @@ SourceFiles
#include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -83,6 +84,7 @@ private:
//- Private typedefs for convenience
typedef PrimitiveMeshedSurface<Face> ParentType;
typedef UnsortedMeshedSurface<Face> SiblingType;
// Private Member Data
......@@ -92,12 +94,6 @@ private:
// Private member functions
//- set a single patch
void onePatch();
//- basic sanity check on patches
void checkPatches();
//- Sort faces by regionIds and set patches
void sortFacesByRegion(const UList<label>&, const Map<word>&);
......@@ -107,6 +103,16 @@ private:
//- Read OpenFOAM Surface format
bool read(Istream&);
protected:
// Protected Member functions
//- set a single patch
void onePatch();
//- basic sanity check on patches
void checkPatches();
public:
//- Runtime type information
......@@ -123,6 +129,8 @@ public:
//- Can we write this file format?
static bool canWriteType(const word& ext, const bool verbose=false);
static wordHashSet readTypes();
static wordHashSet writeTypes();
// Constructors
......
......@@ -45,11 +45,38 @@ Foam::MeshedSurface<Face>::New
<< endl;
}
// created indirectly via UnsortedMeshedSurface
autoPtr<MeshedSurface<Face> > surf(new MeshedSurface<Face>);
surf().transfer( UnsortedMeshedSurface<Face>::New(fName,ext)() );
typename fileExtensionConstructorTable::iterator cstrIter =
fileExtensionConstructorTablePtr_->find(ext);
return surf;
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
// no direct reader, delegate if possible
wordHashSet supported = SiblingType::readTypes();
if (supported.found(ext))
{
// create indirectly
autoPtr<MeshedSurface<Face> > surf(new MeshedSurface<Face>);
surf().transfer(SiblingType::New(fName, ext)());
return surf;
}
// nothing left to try, issue error
supported += readTypes();
supported.insert(nativeExt);
FatalErrorIn
(
"MeshedSurface<Face>::New"
"(const fileName&, const word&) : "
"constructing UnsortedMeshedSurface"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << nl
<< supported
<< exit(FatalError);
}
return autoPtr<MeshedSurface<Face> >(cstrIter()(fName));
}
......
......@@ -39,6 +39,44 @@ License
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
template<class Face>
Foam::wordHashSet Foam::UnsortedMeshedSurface<Face>::readTypes()
{
wordHashSet supported(2*fileExtensionConstructorTablePtr_->size());
forAllIter
(
typename fileExtensionConstructorTable::iterator,
*fileExtensionConstructorTablePtr_,
iter
)
{
supported.insert(iter.key());
}
return supported;
}
template<class Face>
Foam::wordHashSet Foam::UnsortedMeshedSurface<Face>::writeTypes()
{
wordHashSet supported(2*writefileExtensionMemberFunctionTablePtr_->size());
forAllIter
(
typename writefileExtensionMemberFunctionTable::iterator,
*writefileExtensionMemberFunctionTablePtr_,
iter
)
{
supported.insert(iter.key());
}
return supported;
}
template<class Face>
bool Foam::UnsortedMeshedSurface<Face>::canReadType
(
......@@ -52,32 +90,10 @@ bool Foam::UnsortedMeshedSurface<Face>::canReadType
return true;
}
typename fileExtensionConstructorTable::iterator cstrIter =
fileExtensionConstructorTablePtr_->find(ext);
wordHashSet available = readTypes();
available += SiblingType::readTypes();;
// would be nice to have information about which format this actually is
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
if (verbose)
{
SortableList<word> known
(
fileExtensionConstructorTablePtr_->toc()
);
Info<<"Unknown file extension for reading: " << ext << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
return checkSupport(available, ext, verbose, "reading");
}
......@@ -94,32 +110,7 @@ bool Foam::UnsortedMeshedSurface<Face>::canWriteType
return true;
}
typename writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
if (verbose)
{
SortableList<word> known
(
writefileExtensionMemberFunctionTablePtr_->toc()
);
Info<<"Unknown file extension for writing: " << ext << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
return checkSupport(writeTypes(), ext, verbose, "writing");
}
......@@ -173,7 +164,7 @@ void Foam::UnsortedMeshedSurface<Face>::write
"(const fileName&, const UnsortedMeshedSurface&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc()
<< writeTypes()
<< exit(FatalError);
}
......
......@@ -53,6 +53,7 @@ SourceFiles
#include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......@@ -73,7 +74,7 @@ template<class Face>
/*---------------------------------------------------------------------------*\
Class UnsortedMeshedSurface Declaration
Class UnsortedMeshedSurface Declaration
\*---------------------------------------------------------------------------*/
template<class Face>
......@@ -88,6 +89,7 @@ private:
//- Typedefs for convenience
typedef PrimitiveMeshedSurface<Face> ParentType;
typedef MeshedSurface<Face> SiblingType;
//- Typedef for type holding the region (patch) informationm
typedef surfPatchIdentifier PatchRegionType;
......@@ -157,6 +159,9 @@ public:
//- Can we write this file format?
static bool canWriteType(const word& ext, const bool verbose=false);
static wordHashSet readTypes();
static wordHashSet writeTypes();
// Constructors
//- Construct null
......@@ -325,7 +330,7 @@ public:
// Returns true if any points merged
virtual bool stitchFaces
(
const scalar tol=SMALL,
const scalar tol=SMALL,
const bool verbose=false
);
......
......@@ -50,6 +50,24 @@ Foam::UnsortedMeshedSurface<Face>::New
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
// no direct reader, delegate if possible
wordHashSet supported = SiblingType::readTypes();
if (supported.found(ext))
{
// create indirectly
autoPtr<UnsortedMeshedSurface<Face> > surf
(
new UnsortedMeshedSurface<Face>
);
surf().transfer(SiblingType::New(fName, ext)());
return surf;
}
// nothing left but to issue an error
supported += readTypes();
supported.insert(nativeExt);
FatalErrorIn
(
"UnsortedMeshedSurface<Face>::New"
......@@ -57,14 +75,11 @@ Foam::UnsortedMeshedSurface<Face>::New
"constructing UnsortedMeshedSurface"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << nl
<< fileExtensionConstructorTablePtr_->toc()
<< supported
<< exit(FatalError);
}
return autoPtr<UnsortedMeshedSurface<Face> >
(
cstrIter()(fName)
);
return autoPtr<UnsortedMeshedSurface<Face> >(cstrIter()(fName));
}
......
......@@ -257,21 +257,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
if (mustTriangulate)
{
triFace fTri;
// simple face triangulation about f[0].
// cannot use face::triangulation since points are incomplete
fTri[0] = f[0];
for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{
label fp2 = (fp1 + 1) % f.size();
fTri[1] = f[fp1];
fTri[2] = f[fp2];
faceLst.append(fTri);
regionLst.append(patchI);
}
faceLst.append(triFace(f[0], f[1], f[2]));
faceLst.append(triFace(f[0], f[2], f[3]));
regionLst.append(patchI);
regionLst.append(patchI);
}
else
{
......
......@@ -80,7 +80,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
// get dimensions
label nPoints, nEdges, nElems;
label nPoints, nElems, nEdges;
string line = this->getLineNoComment(is);
{
......@@ -105,9 +105,10 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
// use a DynamicList for possible on-the-fly triangulation
DynamicList<Face> faceLst(nElems);
forAll(faceLst, faceI)
for (label faceI = 0; faceI < nElems; ++faceI)
{
line = this->getLineNoComment(is);
{
IStringStream lineStream(line);
......@@ -128,7 +129,6 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
triFace fTri;
// simple face triangulation about f[0].
// cannot use face::triangulation since points are incomplete
fTri[0] = f[0];
for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{
......
......@@ -66,7 +66,7 @@ namespace fileFormats
template<class Face>
class OFFsurfaceFormat
:
public UnsortedMeshedSurface<Face>,
public MeshedSurface<Face>,
public OFFsurfaceFormatCore
{
// Private Member Functions
......@@ -95,12 +95,12 @@ public:
// Selectors
//- Read file and return surface
static autoPtr<UnsortedMeshedSurface<Face> > New
static autoPtr<MeshedSurface<Face> > New
(
const fileName& fName
)
{
return autoPtr<UnsortedMeshedSurface<Face> >
return autoPtr<MeshedSurface<Face> >
(
new OFFsurfaceFormat(fName)
);
......@@ -115,37 +115,37 @@ public:
//- Read from file
virtual bool read(const fileName&);
//- Write UnsortedMeshedSurface
// The output is sorted by region.
//- Write MeshedSurface
static void write
(
Ostream&,
const UnsortedMeshedSurface<Face>&
const MeshedSurface<Face>&
);
//- Write UnsortedMeshedSurface
// The output is sorted by region.
//- Write MeshedSurface
static void write
(
const fileName& fName,
const UnsortedMeshedSurface<Face>& surf
const MeshedSurface<Face>& surf
)
{
write(OFstream(fName)(), surf);
}
//- Write MeshedSurface
//- Write UnsortedMeshedSurface
// The output is sorted by region.
static void write
(
Ostream&,
const MeshedSurface<Face>&
const UnsortedMeshedSurface<Face>&
);
//- Write MeshedSurface
//- Write UnsortedMeshedSurface
// The output is sorted by region.
static void write
(
const fileName& fName,
const MeshedSurface<Face>& surf
const UnsortedMeshedSurface<Face>& surf
)
{
write(OFstream(fName)(), surf);
......
......@@ -38,7 +38,7 @@ namespace fileFormats
addNamedTemplatedToRunTimeSelectionTable
(
UnsortedMeshedSurface,
MeshedSurface,
OFFsurfaceFormat,
face,
fileExtension,
......@@ -46,7 +46,7 @@ addNamedTemplatedToRunTimeSelectionTable
);
addNamedTemplatedToRunTimeSelectionTable
(
UnsortedMeshedSurface,
MeshedSurface,
OFFsurfaceFormat,
triFace,
fileExtension,
......@@ -56,7 +56,7 @@ addNamedTemplatedToRunTimeSelectionTable
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
MeshedSurface,
OFFsurfaceFormat,
face,
write,
......@@ -65,7 +65,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
MeshedSurface,
OFFsurfaceFormat,
triFace,
write,
......@@ -76,7 +76,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
UnsortedMeshedSurface,
OFFsurfaceFormat,
face,
write,
......@@ -85,7 +85,7 @@ addNamedTemplatedToMemberFunctionSelectionTable
);
addNamedTemplatedToMemberFunctionSelectionTable
(
MeshedSurface,
UnsortedMeshedSurface,
OFFsurfaceFormat,
triFace,
write,
......
......@@ -250,6 +250,40 @@ Foam::fileFormats::surfaceFormatsCore::sortedPatchRegions
}
bool
Foam::fileFormats::surfaceFormatsCore::checkSupport
(
const wordHashSet& available,
const word& ext,
const bool verbose,
const word& functionName
)
{
if (available.found(ext))
{
return true;
}
else if (verbose)
{
wordList toc = available.toc();
SortableList<word> known(xferMove(toc));
Info<<"Unknown file extension for " << functionName
<< " : " << ext << nl
<<"Valid types: ( " << nativeExt;
// compact output:
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}