mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
surfMesh - reader delegation between MeshedSurface <-> UnsortedMeshedSurface
This commit is contained in:
@ -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
|
||||
typename fileExtensionConstructorTable::iterator cstrIter =
|
||||
fileExtensionConstructorTablePtr_->find(ext);
|
||||
|
||||
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( UnsortedMeshedSurface<Face>::New(fName,ext)() );
|
||||
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"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
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,6 +115,23 @@ public:
|
||||
//- Read from file
|
||||
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
|
||||
// The output is sorted by region.
|
||||
static void write
|
||||
@ -134,23 +151,6 @@ public:
|
||||
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
|
||||
virtual void write(Ostream& os) const
|
||||
{
|
||||
|
||||
@ -38,7 +38,7 @@ namespace fileFormats
|
||||
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
face,
|
||||
fileExtension,
|
||||
@ -46,7 +46,7 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
);
|
||||
addNamedTemplatedToRunTimeSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
MeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
triFace,
|
||||
fileExtension,
|
||||
@ -54,26 +54,6 @@ addNamedTemplatedToRunTimeSelectionTable
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
MeshedSurface,
|
||||
@ -93,6 +73,26 @@ addNamedTemplatedToMemberFunctionSelectionTable
|
||||
off
|
||||
);
|
||||
|
||||
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
face,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
addNamedTemplatedToMemberFunctionSelectionTable
|
||||
(
|
||||
UnsortedMeshedSurface,
|
||||
OFFsurfaceFormat,
|
||||
triFace,
|
||||
write,
|
||||
fileExtension,
|
||||
off
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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 * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::fileFormats::surfaceFormatsCore::surfaceFormatsCore()
|
||||
|
||||
@ -40,6 +40,7 @@ SourceFiles
|
||||
#include "surfGroupList.H"
|
||||
#include "labelList.H"
|
||||
#include "Map.H"
|
||||
#include "HashSet.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -99,6 +100,14 @@ public:
|
||||
labelList& faceMap
|
||||
);
|
||||
|
||||
static bool checkSupport
|
||||
(
|
||||
const wordHashSet& available,
|
||||
const word& ext,
|
||||
const bool verbose,
|
||||
const word& functionName
|
||||
);
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
|
||||
@ -190,13 +190,8 @@ bool Foam::fileFormats::TRIsurfaceFormat<Face>::read
|
||||
label ptI = 0;
|
||||
forAll(faceLst, faceI)
|
||||
{
|
||||
triFace fTri;
|
||||
|
||||
fTri[0] = ptI++;
|
||||
fTri[1] = ptI++;
|
||||
fTri[2] = ptI++;
|
||||
|
||||
faceLst[faceI] = fTri;
|
||||
const label startPt = 3 * faceI;
|
||||
faceLst[faceI] = triFace(startPt, startPt+1, startPt+2);
|
||||
}
|
||||
|
||||
this->setPatches(groupToPatch);
|
||||
|
||||
Reference in New Issue
Block a user