surfMesh consistency updates, added read() member throughout etc.

This commit is contained in:
Mark Olesen
2008-11-11 22:18:52 +01:00
parent c8de1c150d
commit d4fcd2d9c4
26 changed files with 899 additions and 699 deletions

View File

@ -152,8 +152,7 @@ Foam::string Foam::fileFormats::AC3DfileFormat::cueToOrDie
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
"fileFormats::AC3DfileFormat::read(const fileName&)"
)
<< "Cannot find command " << cmd
<< " " << errorMsg
@ -164,6 +163,51 @@ Foam::string Foam::fileFormats::AC3DfileFormat::cueToOrDie
}
void Foam::fileFormats::AC3DfileFormat::writeHeader
(
Ostream& os,
const List<surfGroup>& patchLst
)
{
// Write with patches as separate objects under "world" object.
// Header is taken over from sample file.
// Defines separate materials for all patches. Recycle colours.
// Define 8 standard colours as r,g,b components
static scalar colourMap[] =
{
1, 1, 1,
1, 0, 0,
0, 1, 0,
0, 0, 1,
1, 1, 0,
0, 1, 1,
1, 0, 1,
0.5, 0.5, 1
};
// Write header. Define materials.
os << "AC3Db" << nl;
forAll(patchLst, patchI)
{
const word& pName = patchLst[patchI].name();
label colourI = patchI % 8;
label colourCompI = 3 * colourI;
os << "MATERIAL \"" << pName << "Mat\" rgb "
<< colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
<< ' ' << colourMap[colourCompI+2]
<< " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
<< " trans 0"
<< nl;
}
os << "OBJECT world" << nl
<< "kids " << patchLst.size() << endl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -181,14 +225,25 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
:
Foam::keyedSurface()
{
read(fName,triangulate);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::AC3DfileFormat::read
(
const fileName& fName,
const bool triangulate
)
{
clear();
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
"fileFormats::AC3DfileFormat::read(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
@ -219,8 +274,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
"fileFormats::AC3DfileFormat::read(const fileName&)"
)
<< "Cannot find \"OBJECT world\" in file " << fName
<< exit(FatalError);
@ -260,8 +314,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
"fileFormats::AC3DfileFormat::read(const fileName&)"
)
<< "Did not read up to \"kids 0\" while reading patch "
<< patchI << " from file " << fName
@ -289,7 +342,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
WarningIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"fileFormats::AC3DfileFormat::read"
"(const fileName&)"
)
<< "rot (rotation tensor) command not implemented"
@ -388,8 +441,7 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
{
FatalErrorIn
(
"fileFormats::AC3DfileFormat::AC3DfileFormat"
"(const fileName&)"
"fileFormats::AC3DfileFormat::read(const fileName&)"
)
<< "Can only read objects without kids."
<< " Encountered " << nKids << " kids when"
@ -411,54 +463,8 @@ Foam::fileFormats::AC3DfileFormat::AC3DfileFormat
setPatches(regionNames);
stitchFaces(SMALL);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::AC3DfileFormat::writeHeader
(
Ostream& os,
const List<surfGroup>& patchLst
)
{
// Write with patches as separate objects under "world" object.
// Header is taken over from sample file.
// Defines separate materials for all patches. Recycle colours.
// Define 8 standard colours as r,g,b components
static scalar colourMap[] =
{
1, 1, 1,
1, 0, 0,
0, 1, 0,
0, 0, 1,
1, 1, 0,
0, 1, 1,
1, 0, 1,
0.5, 0.5, 1
};
// Write header. Define materials.
os << "AC3Db" << nl;
forAll(patchLst, patchI)
{
const word& pName = patchLst[patchI].name();
label colourI = patchI % 8;
label colourCompI = 3 * colourI;
os << "MATERIAL \"" << pName << "Mat\" rgb "
<< colourMap[colourCompI] << ' ' << colourMap[colourCompI+1]
<< ' ' << colourMap[colourCompI+2]
<< " amb 0.2 0.2 0.2 emis 0 0 0 spec 0.5 0.5 0.5 shi 10"
<< " trans 0"
<< nl;
}
os << "OBJECT world" << nl
<< "kids " << patchLst.size() << endl;
return true;
}

View File

@ -116,7 +116,7 @@ public:
{
return autoPtr<keyedSurface>
(
new AC3DfileFormat(fName, triangulate)
new AC3DfileFormat(fName,triangulate)
);
}
@ -124,7 +124,8 @@ public:
// Member Functions
// Write
//- Read from file
virtual bool read(const fileName&, const bool triangulate);
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);

View File

@ -25,7 +25,8 @@ License
\*---------------------------------------------------------------------------*/
#include "FTRfileFormat.H"
#include "clock.H"
#include "Keyed.H"
#include "triFace.H"
#include "IFstream.H"
#include "IStringStream.H"
#include "addToRunTimeSelectionTable.H"
@ -64,13 +65,26 @@ Foam::fileFormats::FTRfileFormat::FTRfileFormat
:
Foam::keyedSurface()
{
read(fName,true);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::FTRfileFormat::read
(
const fileName& fName,
const bool
)
{
clear();
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::FTRfileFormat::FTRfileFormat(const fileName&)"
"fileFormats::FTRfileFormat::read(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
@ -82,16 +96,17 @@ Foam::fileFormats::FTRfileFormat::FTRfileFormat
// transfer to normal list
points().transfer(pointLst);
// read face with keys
List<keyedFace> readFaces(is);
// read faces with keys
List<Keyed<triFace> > readFaces(is);
List<face> faceLst(readFaces.size());
List<label> regionLst(readFaces.size());
List<FaceType> faceLst(readFaces.size());
List<label> regionLst(readFaces.size());
// disentangle faces/keys - already triangulated
forAll(readFaces, faceI)
{
faceLst[faceI].transfer(readFaces[faceI]);
// unfortunately cannot transfer to save memory
faceLst[faceI] = readFaces[faceI];
regionLst[faceI] = readFaces[faceI].key();
}
@ -105,6 +120,8 @@ Foam::fileFormats::FTRfileFormat::FTRfileFormat
}
setPatches(regionNames, readPatches.size() - 1);
return true;
}
// ************************************************************************* //

View File

@ -84,7 +84,6 @@ class FTRfileFormat
friend Istream& operator>>(Istream& is, ftrPatch& p)
{
is >> p.name_ >> p.type_;
return is;
}
};
@ -110,10 +109,15 @@ public:
{
return autoPtr<keyedSurface>
(
new FTRfileFormat(fName, triangulate)
new FTRfileFormat(fName,true)
);
}
// Member Functions
//- Read from file
virtual bool read(const fileName&, const bool triangulate);
};

View File

@ -79,23 +79,34 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat()
Foam::keyedSurface()
{}
Foam::fileFormats::GTSfileFormat::GTSfileFormat
(
const fileName& fName,
const bool triangulate
const bool
)
:
Foam::keyedSurface()
{
read(fName,true);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::GTSfileFormat::read
(
const fileName& fName,
const bool
)
{
clear();
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::GTSfileFormat"
"(const fileName&)"
"fileFormats::GTSfileFormat::read(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
@ -195,8 +206,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::GTSfileFormat"
"(const fileName&)"
"fileFormats::GTSfileFormat::read(const fileName&)"
)
<< "Edges 0 and 1 of triangle " << faceI
<< " do not share a point.\n"
@ -213,8 +223,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::GTSfileFormat"
"(const fileName&)"
"fileFormats::GTSfileFormat::read(const fileName&)"
)
<< "Edges 1 and 2 of triangle " << faceI
<< " do not share a point.\n"
@ -229,8 +238,7 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
{
FatalErrorIn
(
"fileFormats::GTSfileFormat::GTSfileFormat"
"(const fileName&)"
"fileFormats::GTSfileFormat::read(const fileName&)"
)
<< "Edges of triangle " << faceI
<< " reference more than three points.\n"
@ -246,11 +254,11 @@ Foam::fileFormats::GTSfileFormat::GTSfileFormat
setPatches(maxPatch);
// stitchFaces(SMALL);
return true;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::GTSfileFormat::write
(
Ostream& os,

View File

@ -88,7 +88,7 @@ public:
{
return autoPtr<keyedSurface>
(
new GTSfileFormat(fName, triangulate)
new GTSfileFormat(fName,true)
);
}
@ -96,7 +96,8 @@ public:
// Member Functions
// Write
//- Read from file
virtual bool read(const fileName&, const bool triangulate);
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);

View File

@ -117,13 +117,26 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
:
Foam::keyedSurface()
{
read(fName,triangulate);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::NASfileFormat::read
(
const fileName& fName,
const bool triangulate
)
{
clear();
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::NASfileFormat::NASfileFormat(const fileName&)"
"fileFormats::NASfileFormat::read(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
@ -378,8 +391,7 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
{
FatalErrorIn
(
"fileFormats::NASfileFormat::NASfileFormat"
"(const fileName&)"
"fileFormats::NASfileFormat::read(const fileName&)"
)
<< "Expected continuation symbol '*' when reading GRID*"
<< " (double precision coordinate) output" << nl
@ -452,8 +464,8 @@ Foam::fileFormats::NASfileFormat::NASfileFormat
faces().transfer(faceLst);
setPatches(regionNames);
return true;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -105,6 +105,9 @@ public:
// Member Functions
//- Read from a file
virtual bool read(const fileName&, const bool triangulate);
};

View File

@ -125,13 +125,26 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
:
Foam::keyedSurface()
{
read(fName,triangulate);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::OBJfileFormat::read
(
const fileName& fName,
const bool triangulate
)
{
clear();
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::OBJfileFormat::OBJfileFormat(const fileName&)"
"fileFormats::OBJfileFormat::read(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
@ -274,11 +287,11 @@ Foam::fileFormats::OBJfileFormat::OBJfileFormat
regions().transfer(regionLst);
setPatches(groupToPatch);
return true;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::OBJfileFormat::write
(
Ostream& os,

View File

@ -91,12 +91,12 @@ public:
static autoPtr<keyedSurface> New
(
const fileName& fName,
const bool triangulate = false
const bool triangulate=false
)
{
return autoPtr<keyedSurface>
(
new OBJfileFormat(fName, triangulate)
new OBJfileFormat(fName,triangulate)
);
}
@ -104,7 +104,8 @@ public:
// Member Functions
// Write
//- Read from file
virtual bool read(const fileName&, const bool triangulate);
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);

View File

@ -130,13 +130,26 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
:
keyedSurface()
{
read(fName,triangulate);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::OFFfileFormat::read
(
const fileName& fName,
const bool triangulate
)
{
clear();
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::OFFfileFormat(const fileName&)"
"fileFormats::OFFfileFormat::read(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
@ -148,7 +161,7 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
{
FatalErrorIn
(
"fileFormats::OFFfileFormat(const fileName&)"
"fileFormats::OFFfileFormat::read(const fileName&)"
)
<< "OFF file " << fName << " does not start with 'OFF'"
<< exit(FatalError);
@ -230,12 +243,10 @@ Foam::fileFormats::OFFfileFormat::OFFfileFormat
regions() = 0;
setPatches(0);
return true;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::OFFfileFormat::write
(
Ostream& os,

View File

@ -76,8 +76,8 @@ class OFFfileFormat
static void writeHead
(
Ostream&,
const pointField&,
Ostream&,
const pointField&,
const List<FaceType>&,
const List<surfGroup>&
);
@ -111,7 +111,8 @@ public:
// Member Functions
// Write
//- Read from file
virtual bool read(const fileName&, const bool triangulate);
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);

View File

@ -107,7 +107,6 @@ public:
write(OFstream(fName)(), surf);
}
//- Write object
virtual void write(Ostream& os) const
{

View File

@ -84,7 +84,7 @@ bool Foam::fileFormats::STARCDfileFormat::readHeader
{
FatalErrorIn
(
"fileFormats::STARCDfileFormat::readHeader()"
"fileFormats::STARCDfileFormat::readHeader(...)"
)
<< "cannot read " << signature << " " << is.name()
<< abort(FatalError);
@ -214,11 +214,25 @@ Body:
Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
(
const fileName& fName,
const bool triangulation
const bool triangulate
)
:
Foam::keyedSurface()
{
read(fName, triangulate);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::STARCDfileFormat::read
(
const fileName& fName,
const bool triangulate
)
{
clear();
fileName baseName = fName.lessExt();
autoPtr<IFstream> isPtr;
@ -236,7 +250,7 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
{
FatalErrorIn
(
"fileFormats::STARCDfileFormat::STARCDfileFormat(const fileName&)"
"fileFormats::STARCDfileFormat::read(const fileName&)"
)
<< "Cannot read file " << (baseName + ".vrt")
<< exit(FatalError);
@ -286,7 +300,7 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
{
FatalErrorIn
(
"fileFormats::STARCDfileFormat::STARCDfileFormat(const fileName&)"
"fileFormats::STARCDfileFormat::read(const fileName&)"
)
<< "Cannot read file " << (baseName + ".cel")
<< exit(FatalError);
@ -342,7 +356,7 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
starLabels[i] = mapToFoamPointId[starLabels[i]];
}
if (triangulation && nLabels > 3)
if (triangulate && nLabels > 3)
{
face f
(
@ -388,9 +402,10 @@ Foam::fileFormats::STARCDfileFormat::STARCDfileFormat
regions().transfer(regionLst);
setPatches(regionNames);
return true;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::STARCDfileFormat::write
(

View File

@ -118,7 +118,8 @@ public:
// Member Functions
// Write
//- Read from file
virtual bool read(const fileName&, const bool triangulate);
//- Write keyedSurface
static void write(const fileName&, const keyedSurface&);

View File

@ -154,6 +154,8 @@ bool Foam::fileFormats::STLfileFormat::readBINARY
const off_t fileSize
)
{
clear();
istream& is = ifs.stdStream();
// Read the STL header
@ -517,24 +519,34 @@ Foam::fileFormats::STLfileFormat::STLfileFormat
)
:
Foam::keyedSurface()
{
read(fName, true);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::STLfileFormat::read
(
const fileName& fName,
const bool
)
{
off_t fileSize = Foam::size(fName);
// auto-detect ascii/binary
if (detectBINARY(fName))
{
readBINARY(IFstream(fName, IOstream::BINARY)(), fileSize);
return readBINARY(IFstream(fName, IOstream::BINARY)(), fileSize);
}
else
{
readASCII(IFstream(fName)(), fileSize);
return readASCII(IFstream(fName)(), fileSize);
}
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::STLfileFormat::write
(
Ostream& os,

View File

@ -72,11 +72,11 @@ class STLfileFormat
//- Disallow default bitwise assignment
void operator=(const STLfileFormat&);
bool detectBINARY(const fileName&);
bool readASCII(IFstream&, const off_t);
bool readBINARY(IFstream&, const off_t);
static bool detectBINARY(const fileName&);
//- write face in ASCII
static inline void writeShell
(
@ -130,7 +130,7 @@ public:
{
return autoPtr<keyedSurface>
(
new STLfileFormat(fName,triangulate)
new STLfileFormat(fName,true)
);
}
@ -138,7 +138,8 @@ public:
// Member Functions
// Write
//- Read from file
virtual bool read(const fileName&, const bool triangulate);
//- Write keyedSurface
// The ASCII output is sorted by patch, the binary output is unsorted

View File

@ -360,7 +360,7 @@ endsolid {space}("endsolid"|"ENDSOLID")({some_space}{word})*
yy_pop_state();
FatalErrorIn
(
"fileFormats::STLfileFormat::readASCII(const fileName& STLfileName)"
"fileFormats::STLfileFormat::readASCII(const fileName&)"
) << "while " << stateNames[YY_START] << " on line " << lineNo_ << nl
<< " expected " << stateExpects[YY_START]
<< " but found '" << startError_.c_str() << YYText() << "'"
@ -386,6 +386,8 @@ Foam::fileFormats::STLfileFormat::readASCII
const off_t fileSize
)
{
clear();
// Create the lexer with the approximate number of vertices in the STL
// from the file size
STLASCIILexer lexer(&ifs.stdStream(), fileSize/400);

View File

@ -108,18 +108,31 @@ Foam::fileFormats::TRIfileFormat::TRIfileFormat()
Foam::fileFormats::TRIfileFormat::TRIfileFormat
(
const fileName& fName,
const bool triangulate
const bool
)
:
Foam::keyedSurface()
{
read(fName, true);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::fileFormats::TRIfileFormat::read
(
const fileName& fName,
const bool
)
{
clear();
IFstream is(fName);
if (!is.good())
{
FatalErrorIn
(
"fileFormats::TRIfileFormat(const fileName&)"
"fileFormats::TRIfileFormat::read(const fileName&)"
)
<< "Cannot read file " << fName
<< exit(FatalError);
@ -232,11 +245,11 @@ Foam::fileFormats::TRIfileFormat::TRIfileFormat
setPatches(groupToPatch);
stitchFaces(SMALL);
return true;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::fileFormats::TRIfileFormat::write
(
Ostream& os,

View File

@ -94,7 +94,7 @@ public:
{
return autoPtr<keyedSurface>
(
new TRIfileFormat(fName, triangulate)
new TRIfileFormat(fName,true)
);
}
@ -102,7 +102,8 @@ public:
// Member Functions
// Write
//- Read from file
virtual bool read(const fileName&, const bool triangulate);
//- Write keyedSurface
static void write(Ostream&, const keyedSurface&);

View File

@ -37,8 +37,6 @@ License
#include "primitivePatch.H"
#include "SortableList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
@ -59,7 +57,20 @@ defineMemberFunctionSelectionTable
const char * const nativeExt = "ofs";
//! @endcond localscope
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::string Foam::keyedSurface::getLineNoComment(IFstream& is)
{
string line;
do
{
is.getLine(line);
}
while ((line.size() == 0 || line[0] == '#') && is.good());
return line;
}
Foam::fileName Foam::keyedSurface::triSurfInstance(const Time& d)
{
@ -165,158 +176,136 @@ Foam::fileName Foam::keyedSurface::triSurfName(const Time& d)
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::string Foam::keyedSurface::getLineNoComment(IFstream& is)
bool Foam::keyedSurface::canRead(const word& ext, const bool verbose)
{
string line;
do
// perhaps sent an entire name
word fExt(ext);
string::size_type dot = fExt.find_last_of(".");
if (dot != string::npos)
{
is.getLine(line);
fExt = fExt.substr(dot+1);
}
while ((line.size() == 0 || line[0] == '#') && is.good());
return line;
}
void Foam::keyedSurface::setPatches(const label maxPatch)
{
patches_.setSize(maxPatch+1);
forAll(patches_, patchI)
// handle 'native' format directly
if (fExt == nativeExt)
{
patches_[patchI] = PatchRegionType
(
"patch" + ::Foam::name(patchI),
patchI
);
return true;
}
}
fileExtensionConstructorTable::iterator cstrIter =
fileExtensionConstructorTablePtr_->find(fExt);
void Foam::keyedSurface::setPatches()
{
label maxPatch = 0;
// find the max region that occurs
forAll(regions_, faceI)
// would be nice to have information about which format this actually is
if (cstrIter == fileExtensionConstructorTablePtr_->end())
{
const label regId = regions_[faceI];
if (maxPatch < regId)
if (verbose)
{
maxPatch = regId;
}
}
SortableList<word> known
(
fileExtensionConstructorTablePtr_->toc()
);
setPatches(maxPatch);
}
void Foam::keyedSurface::setPatches
(
const Map<word>& regionNames,
const label maxPatchHint
)
{
label maxPatch = maxPatchHint;
// determine max patch ID if required
if (maxPatchHint < 0)
{
maxPatch = 0;
forAllConstIter(Map<word>, regionNames, iter)
{
if (maxPatch < iter.key())
Info<<"Unknown file extension for reading: " << fExt << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
maxPatch = iter.key();
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
// Info<< "setPatches with maxPatch: " << maxPatch << endl;
patches_.setSize(maxPatch+1);
forAll(patches_, patchI)
{
Map<word>::const_iterator findPatch = regionNames.find(patchI);
word patchName;
if (findPatch != regionNames.end())
{
patchName = findPatch();
}
else
{
patchName = "patch" + ::Foam::name(patchI);
}
patches_[patchI] = PatchRegionType
(
patchName,
patchI
);
}
return true;
}
void Foam::keyedSurface::setPatches
bool Foam::keyedSurface::canWrite(const word& ext, const bool verbose)
{
// perhaps sent an entire name
word fExt(ext);
string::size_type dot = ext.find_last_of(".");
if (dot != string::npos)
{
fExt = ext.substr(dot+1);
}
// handle 'native' format directly
if (fExt == nativeExt)
{
return true;
}
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(fExt);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
if (verbose)
{
SortableList<word> known
(
writefileExtensionMemberFunctionTablePtr_->toc()
);
Info<<"Unknown file extension for writing: " << fExt << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
}
void Foam::keyedSurface::write
(
const HashTable<label>& groupToPatch
const fileName& fName,
const keyedSurface& surf
)
{
// determine max patch Id
label maxPatch = 0;
Map<word> regionNames;
forAllConstIter(HashTable<label>, groupToPatch, iter)
if (debug)
{
regionNames.insert(iter(), iter.key());
if (maxPatch < iter())
Info<< "keyedSurface::write(const fileName&, const keyedSurface&) : "
"writing keyedSurface to " << fName
<< endl;
}
const word ext = fName.ext();
// handle 'native' format directly
if (ext == nativeExt)
{
surf.write(OFstream(fName)());
}
else
{
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
maxPatch = iter();
FatalErrorIn
(
"keyedSurface::write(const fileName&, const keyedSurface&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc()
<< exit(FatalError);
}
mfIter()(fName, surf);
}
setPatches(regionNames, maxPatch);
}
// Read surf grouping, points, faces directly from Istream
bool Foam::keyedSurface::read(Istream& is, const bool doTriangulate)
{
List<surfGroup> patchLst(is);
is >> points() >> faces();
patches_.setSize(patchLst.size());
regions_.setSize(size());
// copy patch info and set regions:
label faceIndex = 0;
forAll(patchLst, patchI)
{
patches_[patchI] = PatchRegionType
(
patchLst[patchI],
patchI
);
forAll(patchLst[patchI], patchFaceI)
{
regions_[faceIndex++] = patchI;
}
}
if (doTriangulate)
{
triangulate();
}
return is.good();
}
@ -325,7 +314,7 @@ bool Foam::keyedSurface::read(Istream& is, const bool doTriangulate)
// Patch numbers start at 0.
Foam::surfGroupList Foam::keyedSurface::sortedRegions
(
const List<label>& regionLst,
const UList<label>& regionLst,
const Map<word>& patchNames,
labelList& faceMap
)
@ -333,6 +322,8 @@ Foam::surfGroupList Foam::keyedSurface::sortedRegions
// determine sort order according to region numbers
// std::sort() really seems to mix up the order.
// and std::stable_sort() might take too long / too much memory
// Assuming that we have relatively fewer regions compared to the
// number of items, just do it ourselves
@ -403,22 +394,6 @@ Foam::surfGroupList Foam::keyedSurface::sortedRegions
}
Foam::surfGroupList Foam::keyedSurface::sortedRegions
(
labelList& faceMap
) const
{
// supply some patch names
Map<word> patchNames;
forAll(patches_, patchI)
{
patchNames.insert(patchI, patches_[patchI].name());
}
return sortedRegions(regions_, patchNames, faceMap);
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::keyedSurface::keyedSurface()
@ -685,8 +660,151 @@ Foam::keyedSurface::keyedSurface(const xfer<meshedSurface>& surf)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::keyedSurface::~keyedSurface()
{}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
// Read surf grouping, points, faces directly from Istream
bool Foam::keyedSurface::read(Istream& is, const bool doTriangulate)
{
// Info<<"~keyedSurface()" << endl;
clear();
List<surfGroup> patchLst(is);
is >> points() >> faces();
patches_.setSize(patchLst.size());
regions_.setSize(size());
// copy patch info and set regions:
label faceIndex = 0;
forAll(patchLst, patchI)
{
patches_[patchI] = PatchRegionType
(
patchLst[patchI],
patchI
);
forAll(patchLst[patchI], patchFaceI)
{
regions_[faceIndex++] = patchI;
}
}
if (doTriangulate)
{
triangulate();
}
return is.good();
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
void Foam::keyedSurface::setPatches(const label maxPatch)
{
patches_.setSize(maxPatch+1);
forAll(patches_, patchI)
{
patches_[patchI] = PatchRegionType
(
"patch" + ::Foam::name(patchI),
patchI
);
}
}
void Foam::keyedSurface::setPatches()
{
label maxPatch = 0;
// find the max region that occurs
forAll(regions_, faceI)
{
const label regId = regions_[faceI];
if (maxPatch < regId)
{
maxPatch = regId;
}
}
setPatches(maxPatch);
}
void Foam::keyedSurface::setPatches
(
const Map<word>& regionNames,
const label maxPatchHint
)
{
label maxPatch = maxPatchHint;
// determine max patch ID if required
if (maxPatchHint < 0)
{
maxPatch = 0;
forAllConstIter(Map<word>, regionNames, iter)
{
if (maxPatch < iter.key())
{
maxPatch = iter.key();
}
}
}
// Info<< "setPatches with maxPatch: " << maxPatch << endl;
patches_.setSize(maxPatch+1);
forAll(patches_, patchI)
{
Map<word>::const_iterator findPatch = regionNames.find(patchI);
word patchName;
if (findPatch != regionNames.end())
{
patchName = findPatch();
}
else
{
patchName = "patch" + ::Foam::name(patchI);
}
patches_[patchI] = PatchRegionType
(
patchName,
patchI
);
}
}
void Foam::keyedSurface::setPatches
(
const HashTable<label>& groupToPatch
)
{
// determine max patch Id
label maxPatch = 0;
Map<word> regionNames;
forAllConstIter(HashTable<label>, groupToPatch, iter)
{
regionNames.insert(iter(), iter.key());
if (maxPatch < iter())
{
maxPatch = iter();
}
}
setPatches(regionNames, maxPatch);
}
@ -699,11 +817,37 @@ void Foam::keyedSurface::setSize(const label s)
}
//- Move points
void Foam::keyedSurface::clear()
{
MeshStorage::clearOut();
points().clear();
faces().clear();
regions_.clear();
patches_.clear();
}
Foam::surfGroupList Foam::keyedSurface::sortedRegions
(
labelList& faceMap
) const
{
// supply some patch names
Map<word> patchNames;
forAll(patches_, patchI)
{
patchNames.insert(patchI, patches_[patchI].name());
}
return sortedRegions(regions_, patchNames, faceMap);
}
void Foam::keyedSurface::movePoints(const pointField& newPoints)
{
// Remove all geometry dependent data
clearTopology();
MeshStorage::clearTopology();
// Adapt for new point position
MeshStorage::movePoints(newPoints);
@ -713,14 +857,13 @@ void Foam::keyedSurface::movePoints(const pointField& newPoints)
}
//- scale points
void Foam::keyedSurface::scalePoints(const scalar& scaleFactor)
{
// avoid bad scaling
if (scaleFactor > 0 && scaleFactor != 1.0)
{
// Remove all geometry dependent data
clearTopology();
MeshStorage::clearTopology();
// Adapt for new point position
MeshStorage::movePoints(pointField());
@ -733,7 +876,7 @@ void Foam::keyedSurface::scalePoints(const scalar& scaleFactor)
Foam::keyedSurface Foam::keyedSurface::subsetMesh
(
const boolList& include,
const UList<bool>& include,
labelList& pointMap,
labelList& faceMap
) const
@ -771,15 +914,13 @@ Foam::keyedSurface Foam::keyedSurface::subsetMesh
}
}
// Construct an empty subsurface and fill
// construct a sub-surface
keyedSurface subSurf;
// transfer
subSurf.points().transfer(newPoints);
subSurf.faces().transfer(newFaces);
// copy
subSurf.patches_ = patches_;
(
xferMove(newPoints),
xferMove(newFaces),
xferCopy(patches_)
);
return subSurf;
}
@ -787,12 +928,14 @@ Foam::keyedSurface Foam::keyedSurface::subsetMesh
void Foam::keyedSurface::transfer(keyedSurface& surf)
{
clearOut();
clear();
faces().transfer(surf.faces());
points().transfer(surf.points());
regions_.transfer(surf.regions_);
patches_.transfer(surf.patches_);
surf.clearOut();
surf.clear();
}
@ -800,7 +943,8 @@ void Foam::keyedSurface::transfer(meshedSurface& surf)
{
surfGroupList& patchLst = surf.patches();
clearOut();
clear();
points().transfer(surf.points());
faces().transfer(surf.faces());
regions_.setSize(size());
@ -819,102 +963,7 @@ void Foam::keyedSurface::transfer(meshedSurface& surf)
}
patchLst.clear();
surf.clearOut();
}
bool Foam::keyedSurface::canRead(const word& ext, const bool verbose)
{
// FIXME: this looks horrible, but I don't have my STL docs here
// perhaps we got sent an entire name
word fExt(ext);
string::size_type dot = fExt.find_last_of(".");
if (dot != string::npos)
{
fExt = fExt.substr(dot+1);
}
// handle 'native' format directly
if (fExt == nativeExt)
{
return true;
}
fileExtensionConstructorTable::iterator cstrIter =
fileExtensionConstructorTablePtr_->find(fExt);
// 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: " << fExt << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
}
bool Foam::keyedSurface::canWrite(const word& ext, const bool verbose)
{
// perhaps we got sent an entire name
word fExt(ext);
// FIXME: this looks horrible, but I don't have STL docs here
string::size_type dot = ext.find_last_of(".");
if (dot != string::npos)
{
fExt = ext.substr(dot+1);
}
// handle 'native' format directly
if (fExt == nativeExt)
{
return true;
}
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(fExt);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
if (verbose)
{
SortableList<word> known
(
writefileExtensionMemberFunctionTablePtr_->toc()
);
Info<<"Unknown file extension for writing: " << fExt << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
surf.clear();
}
@ -922,10 +971,12 @@ bool Foam::keyedSurface::canWrite(const word& ext, const bool verbose)
bool Foam::keyedSurface::read
(
const fileName& fName,
const word& ext,
const bool triangulate
)
{
clear();
const word ext = fName.ext();
// handle 'native' format directly
if (ext == nativeExt)
{
@ -940,48 +991,31 @@ bool Foam::keyedSurface::read
}
void Foam::keyedSurface::write
// Read from file in given format
bool Foam::keyedSurface::read
(
const fileName& fName,
const keyedSurface& surf
const word& ext,
const bool triangulate
)
{
if (debug)
{
Info<< "keyedSurface::write(const fileName&, const keyedSurface&) : "
"writing keyedSurface to " << fName
<< endl;
}
const word ext = fName.ext();
clear();
// handle 'native' format directly
if (ext == nativeExt)
{
surf.write(OFstream(fName)());
return read(IFstream(fName)(), triangulate);
}
else
{
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
FatalErrorIn
(
"keyedSurface::write(const fileName&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc()
<< exit(FatalError);
}
mfIter()(fName, surf);
// use selector mechanism
transfer(New(fName, ext, triangulate)());
return true;
}
}
// write sorted
// write (sorted)
void Foam::keyedSurface::write(Ostream& os) const
{
const List<face>& faceLst = faces();
@ -1051,9 +1085,10 @@ void Foam::keyedSurface::writeStats(Ostream& os) const
void Foam::keyedSurface::operator=(const keyedSurface& surf)
{
clearOut();
clear();
faces() = surf.faces();
points() = surf.points();
regions_ = surf.regions_;
patches_ = surf.patches_;
}

View File

@ -53,7 +53,6 @@ SourceFiles
#include "surfPatchIdentifierList.H"
#include "surfGroupList.H"
#include "face.H"
#include "Keyed.H"
#include "xfer.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
@ -71,7 +70,6 @@ class keyedSurface;
class meshedSurface;
class polyBoundaryMesh;
// Istream& operator>>(Istream&, keyedSurface&);
Ostream& operator<<(Ostream&, const keyedSurface&);
@ -89,9 +87,6 @@ protected:
// Protected Member Data
//- Typedef if this type has not already been defined
typedef Keyed<face> keyedFace;
//- Typedef for similar code in keyedSurface and meshedSurface
typedef face FaceType;
@ -122,12 +117,12 @@ private:
// Private member functions
//- Read OpenFOAM Surface format
bool read(Istream&, const bool triangulate=false);
//- Disable setSize with value
void setSize(const label, const FaceType&);
//- Read OpenFOAM Surface format
bool read(Istream&, const bool triangulate=false);
protected:
// Static protected functions
@ -184,6 +179,20 @@ public:
//- Name of keyedSurface directory to use.
static fileName triSurfName(const Time&);
//- Can we read this file format?
static bool canRead(const word& ext, const bool verbose=false);
//- Can we write this file format?
static bool canWrite(const word& ext, const bool verbose=false);
//- Determine the sort order from the region list.
// Returns patch list and sets faceMap to indices within faceLst
static surfGroupList sortedRegions
(
const UList<label>& regionLst,
const Map<word>& patchNames,
labelList& faceMap
);
// Constructors
@ -244,7 +253,6 @@ public:
//- Construct by transferring the contents from a meshedSurface
keyedSurface(const xfer<meshedSurface>&);
//- Construct from file name (uses extension to determine type)
keyedSurface
(
@ -262,13 +270,13 @@ public:
//- Construct from Istream
keyedSurface(Istream&, const bool triangulate=false);
//- Construct from objectRegistry
keyedSurface(const Time&);
//- Construct as copy
keyedSurface(const keyedSurface&);
// Declare run-time constructor selection table
declareRunTimeSelectionTable
@ -323,12 +331,6 @@ public:
//- Write to file
static void write(const fileName&, const keyedSurface&);
//- Can we read this file format?
static bool canRead(const word& ext, const bool verbose=false);
//- Can we write this file format?
static bool canWrite(const word& ext, const bool verbose=false);
// Member Functions
@ -383,45 +385,39 @@ public:
return patches_;
}
//- Determine the sort order from the region list.
// Returns patch list and sets faceMap to indices within faceLst
static surfGroupList sortedRegions
(
const List<label>& regionLst,
const Map<word>& patchNames,
labelList& faceMap
);
//- Sort faces according to region.
// Returns patch list and sets faceMap to index within faces()
surfGroupList sortedRegions(labelList& faceMap) const;
// 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&);
//- Triangulate the surface, return the number of added faces.
label triangulate();
//- Remove invalid faces
void cleanup(const bool verbose);
//- Check/fix duplicate/degenerate faces
void checkFaces(const bool verbose);
//- Join the faces by removing duplicate points.
// Returns true if any points merged
bool stitchFaces(const scalar tol=SMALL, const bool verbose=false);
//- Check/fix duplicate/degenerate faces
void checkFaces(const bool verbose);
//- Remove invalid faces
void cleanup(const bool verbose);
//- Triangulate the surface, return the number of added faces.
label triangulate();
//- Return new surface. Returns pointMap, faceMap from
// subsetMeshMap
keyedSurface subsetMesh
(
const boolList& include,
const UList<bool>& include,
labelList& pointMap,
labelList& faceMap
) const;
@ -434,14 +430,20 @@ public:
// Read
//- Read from file. Chooses reader based on extension
//- Read from file. Chooses reader based on explicit extension
bool read
(
const fileName&,
const word& ext,
const bool triangulate=false
const bool triangulate
);
//- Read from file. Chooses reader based on detected extension
virtual bool read
(
const fileName&,
const bool triangulate=false
);
// Write

View File

@ -107,7 +107,7 @@ bool Foam::keyedSurface::stitchFaces(const scalar tol, const bool verbose)
}
// Merging points might have changed geometric factors
clearOut();
MeshStorage::clearOut();
return true;
}
@ -227,7 +227,7 @@ void Foam::keyedSurface::checkFaces(const bool verbose)
regions_.setSize(newFaceI);
// Topology can change because of renumbering
clearOut();
MeshStorage::clearOut();
}
}

View File

@ -43,16 +43,13 @@ License
namespace Foam
{
defineTypeNameAndDebug(meshedSurface, 0);
defineMemberFunctionSelectionTable
(
meshedSurface,
write,
fileExtension
);
}
// File extension for 'native' raw format
@ -60,7 +57,7 @@ defineMemberFunctionSelectionTable
const char * const nativeExt = "ofs";
//! @endcond localscope
// * * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
Foam::fileName Foam::meshedSurface::triSurfInstance(const Time& d)
{
@ -165,140 +162,99 @@ Foam::fileName Foam::meshedSurface::triSurfName(const Time& d)
return d.path()/"constant"/typeName/foamName;
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::meshedSurface::onePatch()
bool Foam::meshedSurface::canRead(const word& ext, const bool verbose)
{
// set single default patch
patches_.setSize(1);
patches_[0] = surfGroup
(
"patch0",
size(), // patch size
0, // patch start
0 // patch index
);
return keyedSurface::canRead(ext, verbose);
}
void Foam::meshedSurface::checkPatches()
bool Foam::meshedSurface::canWrite(const word& ext, const bool verbose)
{
// extra safety, ensure we have at some patches,
// and they cover all the faces
// fix start silently
if (patches_.size() > 1)
// perhaps sent an entire name
word fExt(ext);
string::size_type dot = ext.find_last_of(".");
if (dot != string::npos)
{
label count = 0;
forAll(patches_, patchI)
{
patches_[patchI].start() = count;
count += patches_[patchI].size();
}
if (count < size())
{
WarningIn
(
"meshedSurface::checkPatches()\n"
)
<< "more nFaces " << size()
<< " than patches " << count
<< " ... extending final patch"
<< endl;
patches_[patches_.size()-1].size() += count - size();
}
else if (count > size())
{
FatalErrorIn
(
"meshedSurface::checkPatches()\n"
)
<< "more patches " << count
<< " than nFaces " << size()
<< exit(FatalError);
}
fExt = ext.substr(dot+1);
}
else if (patches_.size() == 1)
// handle 'native' format directly
if (fExt == nativeExt)
{
// like onePatch, but preserve the name
patches_[0].start() = 0;
patches_[0].size() = size();
if (!patches_[0].name().size())
return true;
}
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(fExt);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
if (verbose)
{
patches_[0].name() = "patch0";
SortableList<word> known
(
writefileExtensionMemberFunctionTablePtr_->toc()
);
Info<<"Unknown file extension for writing: " << fExt << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
}
void Foam::meshedSurface::write
(
const fileName& fName,
const meshedSurface& surf
)
{
if (debug)
{
Info<< "meshedSurface::write(const fileName&, const meshedSurface&) : "
"writing meshedSurface to " << fName
<< endl;
}
const word ext = fName.ext();
// handle 'native' format directly
if (ext == nativeExt)
{
surf.write(OFstream(fName)());
}
else
{
onePatch();
}
}
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
void Foam::meshedSurface::sortFacesByRegion
(
const List<label>& regionIds,
const Map<word>& regionNames
)
{
const List<FaceType>& unsortedFaces = faces();
if (!&regionNames || !&regionIds || regionIds.size() == 0)
{
onePatch();
}
else if (regionIds.size() == unsortedFaces.size())
{
labelList faceMap;
surfGroupList newPatches = keyedSurface::sortedRegions
(
regionIds,
regionNames,
faceMap
);
patches_.transfer(newPatches);
// this is somewhat like ListOps reorder and/or IndirectList
List<FaceType> newFaces(unsortedFaces.size());
forAll(newFaces, faceI)
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
newFaces[faceI] = unsortedFaces[faceMap[faceI]];
FatalErrorIn
(
"meshedSurface::write(const fileName&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc()
<< exit(FatalError);
}
faceMap.clear();
faces().transfer(newFaces);
mfIter()(fName, surf);
}
}
// Read surf grouping, points, faces directly from Istream
bool Foam::meshedSurface::read(Istream& is, const bool doTriangulate)
{
List<surfGroup> patchLst(is);
is >> points() >> faces();
// copy patch info:
patches_.setSize(patchLst.size());
forAll(patchLst, patchI)
{
patches_[patchI] = surfGroup
(
patchLst[patchI],
patchI
);
}
if (doTriangulate)
{
triangulate();
}
return is.good();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::meshedSurface::meshedSurface()
@ -326,9 +282,9 @@ Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const xfer<List<FaceType> >& faceLst,
const List<label>& patchSizes,
const List<word>& patchNames,
const List<word>& patchTypes
const UList<label>& patchSizes,
const UList<word>& patchNames,
const UList<word>& patchTypes
)
:
MeshStorage(List<FaceType>(), pointField())
@ -360,7 +316,7 @@ Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const xfer<List<FaceType> >& faceLst,
const List<label>& regionIds,
const UList<label>& regionIds,
const Map<word>& regionNames
)
:
@ -382,7 +338,7 @@ Foam::meshedSurface::meshedSurface
"(\n"
" const xfer<pointField>&,\n"
" const xfer<List<FaceType> >&,\n"
" const List<label>& regionIds,\n"
" const UList<label>& regionIds,\n"
" const Map<word>& regionNames\n"
" )\n"
)
@ -400,7 +356,7 @@ Foam::meshedSurface::meshedSurface
(
const xfer<pointField>& pointLst,
const xfer<List<FaceType> >& faceLst,
const List<label>& regionIds,
const UList<label>& regionIds,
const HashTable<label>& nameToRegionMapping
)
:
@ -417,7 +373,7 @@ Foam::meshedSurface::meshedSurface
"(\n"
" const xfer<pointField>&,\n"
" const xfer<List<FaceType> >&,\n"
" const List<label>& regionIds,\n"
" const UList<label>& regionIds,\n"
" const HashTable<label>& nameToRegionMapping\n"
" )\n"
)
@ -628,14 +584,158 @@ Foam::meshedSurface::~meshedSurface()
{}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
void Foam::meshedSurface::onePatch()
{
// set single default patch
patches_.setSize(1);
patches_[0] = surfGroup
(
"patch0",
size(), // patch size
0, // patch start
0 // patch index
);
}
void Foam::meshedSurface::checkPatches()
{
// extra safety, ensure we have at some patches,
// and they cover all the faces
// fix start silently
if (patches_.size() > 1)
{
label count = 0;
forAll(patches_, patchI)
{
patches_[patchI].start() = count;
count += patches_[patchI].size();
}
if (count < size())
{
WarningIn
(
"meshedSurface::checkPatches()\n"
)
<< "more nFaces " << size()
<< " than patches " << count
<< " ... extending final patch"
<< endl;
patches_[patches_.size()-1].size() += count - size();
}
else if (count > size())
{
FatalErrorIn
(
"meshedSurface::checkPatches()\n"
)
<< "more patches " << count
<< " than nFaces " << size()
<< exit(FatalError);
}
}
else if (patches_.size() == 1)
{
// like onePatch, but preserve the name
patches_[0].start() = 0;
patches_[0].size() = size();
if (!patches_[0].name().size())
{
patches_[0].name() = "patch0";
}
}
else
{
onePatch();
}
}
void Foam::meshedSurface::sortFacesByRegion
(
const UList<label>& regionIds,
const Map<word>& regionNames
)
{
const List<FaceType>& unsortedFaces = faces();
if (!&regionNames || !&regionIds || regionIds.size() == 0)
{
onePatch();
}
else if (regionIds.size() == unsortedFaces.size())
{
labelList faceMap;
surfGroupList newPatches = keyedSurface::sortedRegions
(
regionIds,
regionNames,
faceMap
);
patches_.transfer(newPatches);
// this is somewhat like ListOps reorder and/or IndirectList
List<FaceType> newFaces(unsortedFaces.size());
forAll(newFaces, faceI)
{
newFaces[faceI] = unsortedFaces[faceMap[faceI]];
}
faceMap.clear();
faces().transfer(newFaces);
}
}
// Read surf grouping, points, faces directly from Istream
bool Foam::meshedSurface::read(Istream& is, const bool doTriangulate)
{
List<surfGroup> patchLst(is);
is >> points() >> faces();
// copy patch info:
patches_.setSize(patchLst.size());
forAll(patchLst, patchI)
{
patches_[patchI] = surfGroup
(
patchLst[patchI],
patchI
);
}
if (doTriangulate)
{
triangulate();
}
return is.good();
}
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::meshedSurface::clear()
{
MeshStorage::clearOut();
points().clear();
faces().clear();
patches_.clear();
}
//- Move points
void Foam::meshedSurface::movePoints(const pointField& newPoints)
{
// Remove all geometry dependent data
clearTopology();
MeshStorage::clearTopology();
// Adapt for new point position
MeshStorage::movePoints(newPoints);
@ -645,14 +745,13 @@ void Foam::meshedSurface::movePoints(const pointField& newPoints)
}
//- scale points
void Foam::meshedSurface::scalePoints(const scalar& scaleFactor)
{
// avoid bad scaling
if (scaleFactor > 0 && scaleFactor != 1.0)
{
// Remove all geometry dependent data
clearTopology();
MeshStorage::clearTopology();
// Adapt for new point position
MeshStorage::movePoints(pointField());
@ -664,7 +763,7 @@ void Foam::meshedSurface::scalePoints(const scalar& scaleFactor)
Foam::meshedSurface Foam::meshedSurface::subsetMesh
(
const boolList& include,
const UList<bool>& include,
labelList& pointMap,
labelList& faceMap
) const
@ -725,6 +824,8 @@ Foam::meshedSurface Foam::meshedSurface::subsetMesh
}
}
oldToNew.clear();
// adjust patch start
label startFaceI = 0;
forAll(newPatches, patchI)
@ -733,12 +834,13 @@ Foam::meshedSurface Foam::meshedSurface::subsetMesh
startFaceI += newPatches[patchI].size();
}
// Construct an empty subsurface and fill
meshedSurface subSurf;
subSurf.patches_.transfer(newPatches);
subSurf.points().transfer(newPoints);
subSurf.faces().transfer(newFaces);
// construct a sub-surface
meshedSurface subSurf
(
xferMove(newPoints),
xferMove(newFaces),
xferMove(newPatches)
);
return subSurf;
}
@ -746,28 +848,30 @@ Foam::meshedSurface Foam::meshedSurface::subsetMesh
void Foam::meshedSurface::transfer(meshedSurface& surf)
{
clearOut();
clear();
points().transfer(surf.points());
faces().transfer(surf.faces());
patches_.transfer(surf.patches_);
surf.clearOut();
surf.clear();
}
void Foam::meshedSurface::transfer(keyedSurface& surf)
{
clearOut();
clear();
points().transfer(surf.points());
faces().clear();
labelList faceMap;
surfGroupList patchLst = surf.sortedRegions(faceMap);
patches_.transfer(patchLst);
surf.regions().clear();
surf.regions_.clear();
surf.patches_.clear();
List<FaceType>& oldFaces = surf.faces();
List<FaceType> newFaces(oldFaces.size());
List<FaceType> newFaces(oldFaces.size());
// this is somewhat like ListOps reorder and/or IndirectList
forAll(newFaces, faceI)
@ -776,61 +880,8 @@ void Foam::meshedSurface::transfer(keyedSurface& surf)
}
faces().transfer(newFaces);
surf.faces().clear();
surf.clearOut();
}
bool Foam::meshedSurface::canRead(const word& ext, const bool verbose)
{
return keyedSurface::canRead(ext, verbose);
}
bool Foam::meshedSurface::canWrite(const word& ext, const bool verbose)
{
// perhaps we got sent an entire name
word fExt(ext);
// FIXME: this looks horrible, but I don't have STL docs here
string::size_type dot = ext.find_last_of(".");
if (dot != string::npos)
{
fExt = ext.substr(dot+1);
}
// handle 'native' format directly
if (fExt == nativeExt)
{
return true;
}
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(fExt);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
if (verbose)
{
SortableList<word> known
(
writefileExtensionMemberFunctionTablePtr_->toc()
);
Info<<"Unknown file extension for writing: " << fExt << nl;
// compact output:
Info<<"Valid types: ( " << nativeExt;
forAll(known, i)
{
Info<<" " << known[i];
}
Info<<" )" << endl;
}
return false;
}
return true;
surf.clear();
}
@ -838,10 +889,12 @@ bool Foam::meshedSurface::canWrite(const word& ext, const bool verbose)
bool Foam::meshedSurface::read
(
const fileName& fName,
const word& ext,
const bool triangulate
)
{
clear();
const word ext = fName.ext();
// handle 'native' format directly
if (ext == nativeExt)
{
@ -856,43 +909,26 @@ bool Foam::meshedSurface::read
}
void Foam::meshedSurface::write
// Read from file in given format
bool Foam::meshedSurface::read
(
const fileName& fName,
const meshedSurface& surf
const word& ext,
const bool triangulate
)
{
if (debug)
{
Info<< "meshedSurface::write(const fileName&, const meshedSurface&) : "
"writing meshedSurface to " << fName
<< endl;
}
const word ext = fName.ext();
clear();
// handle 'native' format directly
if (ext == nativeExt)
{
surf.write(OFstream(fName)());
return read(IFstream(fName)(), triangulate);
}
else
{
writefileExtensionMemberFunctionTable::iterator mfIter =
writefileExtensionMemberFunctionTablePtr_->find(ext);
if (mfIter == writefileExtensionMemberFunctionTablePtr_->end())
{
FatalErrorIn
(
"meshedSurface::write(const fileName&)"
) << "Unknown file extension " << ext << nl << nl
<< "Valid types are :" << endl
<< writefileExtensionMemberFunctionTablePtr_->toc()
<< exit(FatalError);
}
mfIter()(fName, surf);
// use selector mechanism
transfer(New(fName, ext, triangulate)());
return true;
}
}
@ -946,7 +982,8 @@ void Foam::meshedSurface::writeStats(Ostream& os) const
void Foam::meshedSurface::operator=(const meshedSurface& surf)
{
clearOut();
clear();
faces() = surf.faces();
points() = surf.points();
patches_ = surf.patches_;

View File

@ -49,7 +49,6 @@ SourceFiles
#include "boolList.H"
#include "surfGroupList.H"
#include "face.H"
#include "Keyed.H"
#include "xfer.H"
#include "runTimeSelectionTables.H"
#include "memberFunctionSelectionTables.H"
@ -67,7 +66,6 @@ class meshedSurface;
class polyBoundaryMesh;
class surfMesh;
Istream& operator>>(Istream&, meshedSurface&);
Ostream& operator<<(Ostream&, const meshedSurface&);
/*---------------------------------------------------------------------------*\
@ -84,9 +82,6 @@ protected:
// Protected Member Data
//- Typedef if this type has not already been defined
typedef Keyed<face> keyedFace;
//- Typedef for similar code in keyedSurface and meshedSurface
typedef face FaceType;
@ -113,15 +108,15 @@ private:
// Private member functions
//- Sort faces by regionIds and set patches
void sortFacesByRegion(const List<label>&, const Map<word>&);
//- 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>&);
//- Read OpenFOAM Surface format
bool read(Istream&, const bool triangulate=false);
@ -155,6 +150,12 @@ public:
//- Name of meshedSurface directory to use.
static fileName triSurfName(const Time&);
//- Can we read this file format?
static bool canRead(const word& ext, const bool verbose=false);
//- Can we write this file format?
static bool canWrite(const word& ext, const bool verbose=false);
// Constructors
@ -175,9 +176,9 @@ public:
(
const xfer<pointField>&,
const xfer<List<face> >&,
const List<label>& patchSizes,
const List<word>& patchNames,
const List<word>& patchTypes
const UList<label>& patchSizes,
const UList<word>& patchNames,
const UList<word>& patchTypes
);
//- Construct by transferring points, faces.
@ -187,7 +188,7 @@ public:
(
const xfer<pointField>&,
const xfer<List<face> >&,
const List<label>& regionIds = List<label>::null(),
const UList<label>& regionIds = UList<label>::null(),
const Map<word>& regionNames = Map<word>::null()
);
@ -197,7 +198,7 @@ public:
(
const xfer<pointField>&,
const xfer<List<face> >&,
const List<label>& regionIds,
const UList<label>& regionIds,
const HashTable<label>& nameToRegionMapping
);
@ -220,7 +221,6 @@ public:
//- Construct by transferring the contents from a meshedSurface
meshedSurface(const xfer<meshedSurface>&);
//- Construct from file name (uses extension to determine type)
meshedSurface
(
@ -286,12 +286,6 @@ public:
//- Write to file
static void write(const fileName&, const meshedSurface&);
//- Can we read this file format?
static bool canRead(const word& ext, const bool verbose=false);
//- Can we write this file format?
static bool canWrite(const word& ext, const bool verbose=false);
// Member Functions
@ -339,6 +333,9 @@ public:
// Edit
//- Clear all storage
virtual void clear();
//- Move points
virtual void movePoints(const pointField&);
@ -363,7 +360,7 @@ public:
// Returns pointMap, faceMap from subsetMeshMap
meshedSurface subsetMesh
(
const boolList& include,
const UList<bool>& include,
labelList& pointMap,
labelList& faceMap
) const;
@ -377,7 +374,7 @@ public:
// Read
//- Read from file. Chooses reader based on extension
//- Read from file. Chooses reader based on explicit extension
bool read
(
const fileName&,
@ -386,6 +383,14 @@ public:
);
//- Read from file. Chooses reader based on detected extension
virtual bool read
(
const fileName&,
const bool triangulate=false
);
// Write
//- Write to Ostream in simple FOAM format
@ -410,7 +415,6 @@ public:
// Ostream Operator
// friend Istream& operator>>(Istream&, meshedSurface&);
friend Ostream& operator<<(Ostream&, const meshedSurface&);
};

View File

@ -122,7 +122,7 @@ bool Foam::meshedSurface::stitchFaces(const scalar tol, const bool verbose)
// Merging points might have changed geometric factors
clearOut();
MeshStorage::clearOut();
return true;
}
@ -256,7 +256,7 @@ void Foam::meshedSurface::checkFaces(const bool verbose)
faceLst.setSize(newFaceI);
// Topology can change because of renumbering
clearOut();
MeshStorage::clearOut();
}
}