surfMesh - reader delegation between MeshedSurface <-> UnsortedMeshedSurface

This commit is contained in:
Mark Olesen
2008-11-19 01:08:27 +01:00
parent 1c9102dada
commit c9373ba12f
13 changed files with 252 additions and 164 deletions

View File

@ -39,6 +39,43 @@ License
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // // * * * * * * * * * * * * * * 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 * * * * * * * * * * * * // // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
@ -55,7 +92,10 @@ bool Foam::MeshedSurface<Face>::canReadType
return true; 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; return true;
} }
typename writefileExtensionMemberFunctionTable::iterator mfIter = return checkSupport(writeTypes(), ext, verbose, "writing");
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;
} }
@ -150,7 +165,7 @@ void Foam::MeshedSurface<Face>::write
"MeshedSurface::write(const fileName&)" "MeshedSurface::write(const fileName&)"
) << "Unknown file extension " << ext << nl << nl ) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl << "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc() << writeTypes()
<< exit(FatalError); << exit(FatalError);
} }

View File

@ -49,6 +49,7 @@ SourceFiles
#include "surfaceFormatsCore.H" #include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H" #include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -83,6 +84,7 @@ private:
//- Private typedefs for convenience //- Private typedefs for convenience
typedef PrimitiveMeshedSurface<Face> ParentType; typedef PrimitiveMeshedSurface<Face> ParentType;
typedef UnsortedMeshedSurface<Face> SiblingType;
// Private Member Data // Private Member Data
@ -92,12 +94,6 @@ private:
// Private member functions // Private member functions
//- set a single patch
void onePatch();
//- basic sanity check on patches
void checkPatches();
//- Sort faces by regionIds and set patches //- Sort faces by regionIds and set patches
void sortFacesByRegion(const UList<label>&, const Map<word>&); void sortFacesByRegion(const UList<label>&, const Map<word>&);
@ -107,6 +103,16 @@ private:
//- Read OpenFOAM Surface format //- Read OpenFOAM Surface format
bool read(Istream&); bool read(Istream&);
protected:
// Protected Member functions
//- set a single patch
void onePatch();
//- basic sanity check on patches
void checkPatches();
public: public:
//- Runtime type information //- Runtime type information
@ -123,6 +129,8 @@ public:
//- Can we write this file format? //- Can we write this file format?
static bool canWriteType(const word& ext, const bool verbose=false); static bool canWriteType(const word& ext, const bool verbose=false);
static wordHashSet readTypes();
static wordHashSet writeTypes();
// Constructors // Constructors

View File

@ -45,11 +45,38 @@ Foam::MeshedSurface<Face>::New
<< endl; << endl;
} }
// created indirectly via UnsortedMeshedSurface typename fileExtensionConstructorTable::iterator cstrIter =
autoPtr<MeshedSurface<Face> > surf(new MeshedSurface<Face>); fileExtensionConstructorTablePtr_->find(ext);
surf().transfer( UnsortedMeshedSurface<Face>::New(fName,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));
} }

View File

@ -39,6 +39,44 @@ License
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * 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> template<class Face>
bool Foam::UnsortedMeshedSurface<Face>::canReadType bool Foam::UnsortedMeshedSurface<Face>::canReadType
( (
@ -52,32 +90,10 @@ bool Foam::UnsortedMeshedSurface<Face>::canReadType
return true; return true;
} }
typename fileExtensionConstructorTable::iterator cstrIter = wordHashSet available = readTypes();
fileExtensionConstructorTablePtr_->find(ext); available += SiblingType::readTypes();;
// would be nice to have information about which format this actually is return checkSupport(available, ext, verbose, "reading");
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;
} }
@ -94,32 +110,7 @@ bool Foam::UnsortedMeshedSurface<Face>::canWriteType
return true; return true;
} }
typename writefileExtensionMemberFunctionTable::iterator mfIter = return checkSupport(writeTypes(), ext, verbose, "writing");
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;
} }
@ -173,7 +164,7 @@ void Foam::UnsortedMeshedSurface<Face>::write
"(const fileName&, const UnsortedMeshedSurface&)" "(const fileName&, const UnsortedMeshedSurface&)"
) << "Unknown file extension " << ext << nl << nl ) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl << "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc() << writeTypes()
<< exit(FatalError); << exit(FatalError);
} }

View File

@ -53,6 +53,7 @@ SourceFiles
#include "surfaceFormatsCore.H" #include "surfaceFormatsCore.H"
#include "runTimeSelectionTables.H" #include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H" #include "memberFunctionSelectionTables.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -73,7 +74,7 @@ template<class Face>
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class UnsortedMeshedSurface Declaration Class UnsortedMeshedSurface Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Face> template<class Face>
@ -88,6 +89,7 @@ private:
//- Typedefs for convenience //- Typedefs for convenience
typedef PrimitiveMeshedSurface<Face> ParentType; typedef PrimitiveMeshedSurface<Face> ParentType;
typedef MeshedSurface<Face> SiblingType;
//- Typedef for type holding the region (patch) informationm //- Typedef for type holding the region (patch) informationm
typedef surfPatchIdentifier PatchRegionType; typedef surfPatchIdentifier PatchRegionType;
@ -157,6 +159,9 @@ public:
//- Can we write this file format? //- Can we write this file format?
static bool canWriteType(const word& ext, const bool verbose=false); static bool canWriteType(const word& ext, const bool verbose=false);
static wordHashSet readTypes();
static wordHashSet writeTypes();
// Constructors // Constructors
//- Construct null //- Construct null
@ -325,7 +330,7 @@ public:
// Returns true if any points merged // Returns true if any points merged
virtual bool stitchFaces virtual bool stitchFaces
( (
const scalar tol=SMALL, const scalar tol=SMALL,
const bool verbose=false const bool verbose=false
); );

View File

@ -50,6 +50,24 @@ Foam::UnsortedMeshedSurface<Face>::New
if (cstrIter == fileExtensionConstructorTablePtr_->end()) 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 FatalErrorIn
( (
"UnsortedMeshedSurface<Face>::New" "UnsortedMeshedSurface<Face>::New"
@ -57,14 +75,11 @@ Foam::UnsortedMeshedSurface<Face>::New
"constructing UnsortedMeshedSurface" "constructing UnsortedMeshedSurface"
) << "Unknown file extension " << ext << nl << nl ) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << nl << "Valid types are :" << nl
<< fileExtensionConstructorTablePtr_->toc() << supported
<< exit(FatalError); << exit(FatalError);
} }
return autoPtr<UnsortedMeshedSurface<Face> > return autoPtr<UnsortedMeshedSurface<Face> >(cstrIter()(fName));
(
cstrIter()(fName)
);
} }

View File

@ -257,21 +257,10 @@ bool Foam::fileFormats::NASsurfaceFormat<Face>::read
if (mustTriangulate) if (mustTriangulate)
{ {
triFace fTri; faceLst.append(triFace(f[0], f[1], f[2]));
faceLst.append(triFace(f[0], f[2], f[3]));
// simple face triangulation about f[0]. regionLst.append(patchI);
// cannot use face::triangulation since points are incomplete regionLst.append(patchI);
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);
}
} }
else else
{ {

View File

@ -80,7 +80,7 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
// get dimensions // get dimensions
label nPoints, nEdges, nElems; label nPoints, nElems, nEdges;
string line = this->getLineNoComment(is); string line = this->getLineNoComment(is);
{ {
@ -105,9 +105,10 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
// use a DynamicList for possible on-the-fly triangulation // use a DynamicList for possible on-the-fly triangulation
DynamicList<Face> faceLst(nElems); DynamicList<Face> faceLst(nElems);
forAll(faceLst, faceI) for (label faceI = 0; faceI < nElems; ++faceI)
{ {
line = this->getLineNoComment(is); line = this->getLineNoComment(is);
{ {
IStringStream lineStream(line); IStringStream lineStream(line);
@ -128,7 +129,6 @@ bool Foam::fileFormats::OFFsurfaceFormat<Face>::read
triFace fTri; triFace fTri;
// simple face triangulation about f[0]. // simple face triangulation about f[0].
// cannot use face::triangulation since points are incomplete
fTri[0] = f[0]; fTri[0] = f[0];
for (label fp1 = 1; fp1 < f.size() - 1; fp1++) for (label fp1 = 1; fp1 < f.size() - 1; fp1++)
{ {

View File

@ -66,7 +66,7 @@ namespace fileFormats
template<class Face> template<class Face>
class OFFsurfaceFormat class OFFsurfaceFormat
: :
public UnsortedMeshedSurface<Face>, public MeshedSurface<Face>,
public OFFsurfaceFormatCore public OFFsurfaceFormatCore
{ {
// Private Member Functions // Private Member Functions
@ -95,12 +95,12 @@ public:
// Selectors // Selectors
//- Read file and return surface //- Read file and return surface
static autoPtr<UnsortedMeshedSurface<Face> > New static autoPtr<MeshedSurface<Face> > New
( (
const fileName& fName const fileName& fName
) )
{ {
return autoPtr<UnsortedMeshedSurface<Face> > return autoPtr<MeshedSurface<Face> >
( (
new OFFsurfaceFormat(fName) new OFFsurfaceFormat(fName)
); );
@ -115,6 +115,23 @@ public:
//- 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& fName,
const MeshedSurface<Face>& surf
)
{
write(OFstream(fName)(), surf);
}
//- Write UnsortedMeshedSurface //- Write UnsortedMeshedSurface
// The output is sorted by region. // The output is sorted by region.
static void write static void write
@ -134,23 +151,6 @@ public:
write(OFstream(fName)(), surf); write(OFstream(fName)(), surf);
} }
//- Write MeshedSurface
static void write
(
Ostream&,
const MeshedSurface<Face>&
);
//- Write MeshedSurface
static void write
(
const fileName& fName,
const MeshedSurface<Face>& surf
)
{
write(OFstream(fName)(), surf);
}
//- Write object //- Write object
virtual void write(Ostream& os) const virtual void write(Ostream& os) const
{ {

View File

@ -38,7 +38,7 @@ namespace fileFormats
addNamedTemplatedToRunTimeSelectionTable addNamedTemplatedToRunTimeSelectionTable
( (
UnsortedMeshedSurface, MeshedSurface,
OFFsurfaceFormat, OFFsurfaceFormat,
face, face,
fileExtension, fileExtension,
@ -46,7 +46,7 @@ addNamedTemplatedToRunTimeSelectionTable
); );
addNamedTemplatedToRunTimeSelectionTable addNamedTemplatedToRunTimeSelectionTable
( (
UnsortedMeshedSurface, MeshedSurface,
OFFsurfaceFormat, OFFsurfaceFormat,
triFace, triFace,
fileExtension, fileExtension,
@ -54,26 +54,6 @@ addNamedTemplatedToRunTimeSelectionTable
); );
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
OFFsurfaceFormat,
face,
write,
fileExtension,
off
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
OFFsurfaceFormat,
triFace,
write,
fileExtension,
off
);
addNamedTemplatedToMemberFunctionSelectionTable addNamedTemplatedToMemberFunctionSelectionTable
( (
MeshedSurface, MeshedSurface,
@ -93,6 +73,26 @@ addNamedTemplatedToMemberFunctionSelectionTable
off off
); );
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
OFFsurfaceFormat,
face,
write,
fileExtension,
off
);
addNamedTemplatedToMemberFunctionSelectionTable
(
UnsortedMeshedSurface,
OFFsurfaceFormat,
triFace,
write,
fileExtension,
off
);
} }
} }

View File

@ -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;
}
return false;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore() Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore()

View File

@ -40,6 +40,7 @@ SourceFiles
#include "surfGroupList.H" #include "surfGroupList.H"
#include "labelList.H" #include "labelList.H"
#include "Map.H" #include "Map.H"
#include "HashSet.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -99,6 +100,14 @@ public:
labelList& faceMap labelList& faceMap
); );
static bool checkSupport
(
const wordHashSet& available,
const word& ext,
const bool verbose,
const word& functionName
);
// Constructors // Constructors
//- Construct null //- Construct null

View File

@ -190,13 +190,8 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
label ptI = 0; label ptI = 0;
forAll(faceLst, faceI) forAll(faceLst, faceI)
{ {
triFace fTri; const label startPt = 3 * faceI;
faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
fTri[0] = ptI++;
fTri[1] = ptI++;
fTri[2] = ptI++;
faceLst[faceI] = fTri;
} }
this->setPatches(groupToPatch); this->setPatches(groupToPatch);