sampling reworking

- write geometry file if no fields would be sampled
- write geometry file only once for obj, stl formats and use MeshedSurfaceProxy
  for writing
This commit is contained in:
Mark Olesen 2009-03-16 17:37:58 +01:00
parent fadf428091
commit ba771d1901
36 changed files with 384 additions and 506 deletions

View File

@ -81,7 +81,7 @@ public:
const coordSet&,
const wordList&,
const List<const Field<Type>*>&,
Ostream& os
Ostream&
) const;
};

View File

@ -32,7 +32,7 @@ License
namespace Foam
{
makeSetWriters(gnuplotSetWriter)
makeSetWriters(gnuplotSetWriter);
}
// ************************************************************************* //

View File

@ -54,7 +54,7 @@ class jplotSetWriter
// Private Member Functions
//- Write header
Ostream& writeHeader(Ostream& os) const;
Ostream& writeHeader(Ostream&) const;
public:
@ -85,7 +85,7 @@ public:
const coordSet&,
const wordList&,
const List<const Field<Type>*>&,
Ostream& os
Ostream&
) const;
};

View File

@ -32,7 +32,7 @@ License
namespace Foam
{
makeSetWriters(jplotSetWriter)
makeSetWriters(jplotSetWriter);
}
// ************************************************************************* //

View File

@ -81,7 +81,7 @@ public:
const coordSet&,
const wordList&,
const List<const Field<Type>*>&,
Ostream& os
Ostream&
) const;
};

View File

@ -32,7 +32,7 @@ License
namespace Foam
{
makeSetWriters(rawSetWriter)
makeSetWriters(rawSetWriter);
}
// ************************************************************************* //

View File

@ -91,22 +91,12 @@ protected:
//- Generates filename from coordSet and sampled fields
fileName getBaseName(const coordSet&, const wordList&) const;
void writeCoord
(
const coordSet& samples,
const label sampleI,
Ostream& os
) const;
void writeCoord(const coordSet&, const label sampleI, Ostream&) const;
//- Writes single-column ascii write. Column 1 is coordSet coordinate,
// columns 2 is the value. Uses write() function
// to write coordinate in correct format.
void writeTable
(
const coordSet&,
const List<Type>&,
Ostream& os
) const;
void writeTable(const coordSet&, const List<Type>&, Ostream&) const;
//- Writes multi-column ascii write. Column 1 is coordSet coordinate,
// columns 2..n are the values. Uses write() function
@ -139,10 +129,7 @@ public:
// Selectors
//- Return a reference to the selected writer
static autoPtr<writer> New
(
const word& writeFormat
);
static autoPtr<writer> New(const word& writeFormat);
// Constructors
@ -165,8 +152,8 @@ public:
) const = 0;
//- General entry point for writing.
// The data is organized in a set of point with one or
// more values per point
// The data is organized in a set of point with one or more values
// per point
virtual void write
(
const coordSet&,
@ -179,7 +166,7 @@ public:
virtual Ostream& write(const scalar, Ostream&) const;
template<class VSType>
Ostream& writeVS(const VSType& value, Ostream& os) const;
Ostream& writeVS(const VSType&, Ostream&) const;
//- Write vector. Tab separated ascii
virtual Ostream& write(const vector&, Ostream&) const;

View File

@ -40,27 +40,27 @@ SourceFiles
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Only used internally
#define makeTypeSetWritersTypeName(typeWriter, dataType) \
\
defineNamedTemplateTypeNameAndDebug(typeWriter<dataType >, 0);
#define makeTypeSetWritersTypeName(typeWriter, dataType) \
\
defineNamedTemplateTypeNameAndDebug(typeWriter< dataType >, 0)
// Sometimes used externally
#define makeSetWritersTypeName(typeWriter) \
\
makeTypeSetWritersTypeName(typeWriter, scalar); \
makeTypeSetWritersTypeName(typeWriter, vector); \
makeTypeSetWritersTypeName(typeWriter, sphericalTensor); \
makeTypeSetWritersTypeName(typeWriter, symmTensor); \
makeTypeSetWritersTypeName(typeWriter, tensor);
#define makeSetWritersTypeName(typeWriter) \
\
makeTypeSetWritersTypeName(typeWriter, scalar); \
makeTypeSetWritersTypeName(typeWriter, vector); \
makeTypeSetWritersTypeName(typeWriter, sphericalTensor); \
makeTypeSetWritersTypeName(typeWriter, symmTensor); \
makeTypeSetWritersTypeName(typeWriter, tensor)
// Define type info for single dataType template instantiation (eg, vector)
#define makeSetWriterType(typeWriter, dataType) \
\
defineNamedTemplateTypeNameAndDebug(typeWriter<dataType >, 0); \
addTemplatedToRunTimeSelectionTable \
( \
writer, typeWriter, dataType, word \
);
#define makeSetWriterType(typeWriter, dataType) \
\
defineNamedTemplateTypeNameAndDebug(typeWriter< dataType >, 0); \
addTemplatedToRunTimeSelectionTable \
( \
writer, typeWriter, dataType, word \
)
// Define type info for scalar, vector etc. instantiations
@ -70,7 +70,7 @@ SourceFiles
makeSetWriterType(typeWriter, vector); \
makeSetWriterType(typeWriter, sphericalTensor); \
makeSetWriterType(typeWriter, symmTensor); \
makeSetWriterType(typeWriter, tensor);
makeSetWriterType(typeWriter, tensor)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -81,7 +81,7 @@ public:
const coordSet&,
const wordList&,
const List<const Field<Type>*>&,
Ostream& os
Ostream&
) const;
};

View File

@ -32,7 +32,7 @@ License
namespace Foam
{
makeSetWriters(xmgraceSetWriter)
makeSetWriters(xmgraceSetWriter);
}
// ************************************************************************* //

View File

@ -70,18 +70,27 @@ Foam::scalar Foam::sampledSurfaces::mergeTol_(1e-10);
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
bool Foam::sampledSurfaces::checkFieldTypes()
Foam::label Foam::sampledSurfaces::classifyFieldTypes()
{
wordList fieldTypes(fieldNames_.size());
label nFields = 0;
// check files for a particular time
if (loadFromFiles_)
scalarFields_.clear();
vectorFields_.clear();
sphericalTensorFields_.clear();
symmTensorFields_.clear();
tensorFields_.clear();
forAll(fieldNames_, fieldI)
{
forAll(fieldNames_, fieldI)
const word& fieldName = fieldNames_[fieldI];
word fieldType = "";
// check files for a particular time
if (loadFromFiles_)
{
IOobject io
(
fieldNames_[fieldI],
fieldName,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
@ -91,69 +100,96 @@ bool Foam::sampledSurfaces::checkFieldTypes()
if (io.headerOk())
{
fieldTypes[fieldI] = io.headerClassName();
fieldType = io.headerClassName();
}
else
{
fieldTypes[fieldI] = "(notFound)";
continue;
}
}
}
else
{
// check objectRegistry
forAll(fieldNames_, fieldI)
else
{
objectRegistry::const_iterator iter =
mesh_.find(fieldNames_[fieldI]);
// check objectRegistry
objectRegistry::const_iterator iter = mesh_.find(fieldName);
if (iter != mesh_.objectRegistry::end())
{
fieldTypes[fieldI] = iter()->type();
fieldType = iter()->type();
}
else
{
fieldTypes[fieldI] = "(notFound)";
continue;
}
}
if (fieldType == volScalarField::typeName)
{
scalarFields_.append(fieldName);
nFields++;
}
else if (fieldType == volVectorField::typeName)
{
vectorFields_.append(fieldName);
nFields++;
}
else if (fieldType == volSphericalTensorField::typeName)
{
sphericalTensorFields_.append(fieldName);
nFields++;
}
else if (fieldType == volSymmTensorField::typeName)
{
symmTensorFields_.append(fieldName);
nFields++;
}
else if (fieldType == volTensorField::typeName)
{
tensorFields_.append(fieldName);
nFields++;
}
}
return nFields;
}
label nFields = 0;
// classify fieldTypes
nFields += grep(scalarFields_, fieldTypes);
nFields += grep(vectorFields_, fieldTypes);
nFields += grep(sphericalTensorFields_, fieldTypes);
nFields += grep(symmTensorFields_, fieldTypes);
nFields += grep(tensorFields_, fieldTypes);
void Foam::sampledSurfaces::writeGeometry() const
{
// Write to time directory under outputPath_
// skip surface without faces (eg, a failed cut-plane)
if (Pstream::master())
const fileName outputDir = outputPath_/mesh_.time().timeName();
forAll(*this, surfI)
{
if (debug)
{
Pout<< "timeName = " << mesh_.time().timeName() << nl
<< "scalarFields " << scalarFields_ << nl
<< "vectorFields " << vectorFields_ << nl
<< "sphTensorFields " << sphericalTensorFields_ << nl
<< "symTensorFields " << symmTensorFields_ <<nl
<< "tensorFields " << tensorFields_ <<nl;
}
const sampledSurface& s = operator[](surfI);
if (nFields > 0)
if (Pstream::parRun())
{
if (debug)
if (Pstream::master() && mergeList_[surfI].faces.size())
{
Pout<< "Creating directory "
<< outputPath_/mesh_.time().timeName()
<< nl << endl;
genericFormatter_->write
(
outputDir,
s.name(),
mergeList_[surfI].points,
mergeList_[surfI].faces
);
}
mkDir(outputPath_/mesh_.time().timeName());
}
else if (s.faces().size())
{
genericFormatter_->write
(
outputDir,
s.name(),
s.points(),
s.faces()
);
}
}
return nFields > 0;
}
@ -176,6 +212,7 @@ Foam::sampledSurfaces::sampledSurfaces
interpolationScheme_(word::null),
writeFormat_(word::null),
mergeList_(),
genericFormatter_(NULL),
scalarFields_(),
vectorFields_(),
sphericalTensorFields_(),
@ -223,11 +260,39 @@ void Foam::sampledSurfaces::end()
void Foam::sampledSurfaces::write()
{
if (size() && checkFieldTypes())
if (size())
{
// finalize surfaces, merge points etc.
update();
const label nFields = classifyFieldTypes();
if (Pstream::master())
{
if (debug)
{
Pout<< "timeName = " << mesh_.time().timeName() << nl
<< "scalarFields " << scalarFields_ << nl
<< "vectorFields " << vectorFields_ << nl
<< "sphTensorFields " << sphericalTensorFields_ << nl
<< "symTensorFields " << symmTensorFields_ <<nl
<< "tensorFields " << tensorFields_ <<nl;
Pout<< "Creating directory "
<< outputPath_/mesh_.time().timeName() << nl << endl;
}
mkDir(outputPath_/mesh_.time().timeName());
}
// write geometry first if required, or when no fields would otherwise
// be written
if (nFields == 0 || genericFormatter_->separateFiles())
{
writeGeometry();
}
sampleAndWrite(scalarFields_);
sampleAndWrite(vectorFields_);
sampleAndWrite(sphericalTensorFields_);
@ -241,6 +306,14 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
{
fieldNames_ = wordList(dict.lookup("fields"));
const label nFields = fieldNames_.size();
scalarFields_.reset(nFields);
vectorFields_.reset(nFields);
sphericalTensorFields_.reset(nFields);
symmTensorFields_.reset(nFields);
tensorFields_.reset(nFields);
interpolationScheme_ = dict.lookupOrDefault<word>
(
"interpolationScheme",
@ -252,6 +325,11 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
"null"
);
// define the generic (geometry) writer
genericFormatter_ = surfaceWriter<bool>::New(writeFormat_);
PtrList<sampledSurface> newList
(
dict.lookup("surfaces"),

View File

@ -64,24 +64,24 @@ class sampledSurfaces
template<class Type>
class fieldGroup
:
public wordList
public DynamicList<word>
{
public:
//- Surface formatter
autoPtr<surfaceWriter<Type> > formatter;
autoPtr< surfaceWriter<Type> > formatter;
//- Construct null
fieldGroup()
:
wordList(0),
DynamicList<word>(0),
formatter(NULL)
{}
//- Construct for a particular surface format
fieldGroup(const word& writeFormat)
:
wordList(0),
DynamicList<word>(0),
formatter(surfaceWriter<Type>::New(writeFormat))
{}
@ -93,10 +93,17 @@ class sampledSurfaces
const wordList& fieldNames
)
:
wordList(fieldNames),
DynamicList<word>(fieldNames),
formatter(surfaceWriter<Type>::New(writeFormat))
{}
void reset(const label nElem)
{
formatter.clear();
DynamicList<word>::setCapacity(nElem);
DynamicList<word>::clear();
}
void operator=(const word& writeFormat)
{
formatter = surfaceWriter<Type>::New(writeFormat);
@ -104,7 +111,7 @@ class sampledSurfaces
void operator=(const wordList& fieldNames)
{
wordList::operator=(fieldNames);
DynamicList<word>::operator=(fieldNames);
}
};
@ -171,6 +178,9 @@ class sampledSurfaces
// Calculated
//- Generic surface formatter
autoPtr< surfaceWriter<bool> > genericFormatter_;
//- Categorized scalar/vector/tensor fields
fieldGroup<scalar> scalarFields_;
fieldGroup<vector> vectorFields_;
@ -181,16 +191,11 @@ class sampledSurfaces
// Private Member Functions
//- Classify field types, return true if nFields > 0
bool checkFieldTypes();
//- Classify field types, returns the number of fields
label classifyFieldTypes();
//- Find the fields in the list of the given type, return count
template<class Type>
label grep
(
fieldGroup<Type>& fieldList,
const wordList& fieldTypes
) const;
//- Write geometry only
void writeGeometry() const;
//- Sample and write a particular volume field
template<class Type>

View File

@ -30,35 +30,6 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
Foam::label Foam::sampledSurfaces::grep
(
fieldGroup<Type>& fieldList,
const wordList& fieldTypes
) const
{
fieldList.setSize(fieldNames_.size());
label nFields = 0;
forAll(fieldNames_, fieldI)
{
if
(
fieldTypes[fieldI]
== GeometricField<Type, fvPatchField, volMesh>::typeName
)
{
fieldList[nFields] = fieldNames_[fieldI];
nFields++;
}
}
fieldList.setSize(nFields);
return nFields;
}
template<class Type>
void Foam::sampledSurfaces::sampleAndWrite
(
@ -67,10 +38,10 @@ void Foam::sampledSurfaces::sampleAndWrite
)
{
// interpolator for this field
autoPtr<interpolation<Type> > interpolator;
autoPtr< interpolation<Type> > interpolator;
const word& fieldName = vField.name();
const fileName& timeDir = vField.time().timeName();
const fileName outputDir = outputPath_/vField.time().timeName();
forAll(*this, surfI)
{
@ -128,8 +99,7 @@ void Foam::sampledSurfaces::sampleAndWrite
{
formatter.write
(
outputPath_,
timeDir,
outputDir,
s.name(),
mergeList_[surfI].points,
mergeList_[surfI].faces,
@ -147,8 +117,7 @@ void Foam::sampledSurfaces::sampleAndWrite
{
formatter.write
(
outputPath_,
timeDir,
outputDir,
s.name(),
s.points(),
s.faces(),
@ -217,7 +186,7 @@ void Foam::sampledSurfaces::sampleAndWrite
sampleAndWrite
(
mesh_.lookupObject
<GeometricField<Type, fvPatchField, volMesh> >
<GeometricField<Type, fvPatchField, volMesh> >
(
fields[fieldI]
),

View File

@ -26,9 +26,7 @@ License
#include "dxSurfaceWriter.H"
#include "fileName.H"
#include "OFstream.H"
#include "faceList.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -247,8 +245,7 @@ Foam::dxSurfaceWriter<Type>::~dxSurfaceWriter()
template<class Type>
void Foam::dxSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
@ -257,22 +254,21 @@ void Foam::dxSurfaceWriter<Type>::write
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
if (!isDir(outputDir))
{
mkDir(surfaceDir);
mkDir(outputDir);
}
fileName fName(surfaceDir/fieldName + '_' + surfaceName + ".dx");
OFstream os
(
outputDir/fieldName + '_' + surfaceName + ".dx"
);
if (verbose)
{
Info<< "Writing field " << fieldName << " to " << fName << endl;
Info<< "Writing field " << fieldName << " to " << os.name() << endl;
}
OFstream os(fName);
writeGeometry(os, points, faces);
writeData(os, values);

View File

@ -84,8 +84,7 @@ public:
//- Writes single surface to file.
virtual void write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,

View File

@ -26,9 +26,7 @@ License
#include "foamFileSurfaceWriter.H"
#include "fileName.H"
#include "OFstream.H"
#include "faceList.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -49,22 +47,17 @@ Foam::foamFileSurfaceWriter<Type>::~foamFileSurfaceWriter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::foamFileSurfaceWriter<Foam::nil>::write
template<class Type>
void Foam::foamFileSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Foam::nil>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir/surfaceName);
fileName surfaceDir(outputDir/surfaceName);
if (!isDir(surfaceDir))
{
@ -73,7 +66,7 @@ void Foam::foamFileSurfaceWriter<Foam::nil>::write
if (verbose)
{
Info<< "Writing nil to " << surfaceDir << endl;
Info<< "Writing geometry to " << surfaceDir << endl;
}
// Points
@ -83,14 +76,11 @@ void Foam::foamFileSurfaceWriter<Foam::nil>::write
OFstream(surfaceDir/"faces")() << faces;
}
}
template<class Type>
void Foam::foamFileSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
@ -99,7 +89,7 @@ void Foam::foamFileSurfaceWriter<Type>::write
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir/surfaceName);
fileName surfaceDir(outputDir/surfaceName);
if (!isDir(surfaceDir))
{
@ -111,11 +101,7 @@ void Foam::foamFileSurfaceWriter<Type>::write
Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
}
// Points
OFstream(surfaceDir/"points")() << points;
// Faces
OFstream(surfaceDir/"faces")() << faces;
// geometry should already have been written
// Values to separate directory (e.g. "scalarField/p")

View File

@ -72,13 +72,26 @@ public:
// Member Functions
// Write
//- Return true if the surface format supports separate files
virtual bool separateFiles()
{
return true;
}
//- Write geometry to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose = false
) const;
//- Writes single surface to file.
virtual void write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,

View File

@ -35,7 +35,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(foamFileSurfaceWriter, nil);
makeSurfaceWriterType(foamFileSurfaceWriter, bool);
makeSurfaceWriters(foamFileSurfaceWriter);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -25,10 +25,6 @@ License
\*---------------------------------------------------------------------------*/
#include "nullSurfaceWriter.H"
#include "fileName.H"
#include "OFstream.H"
#include "faceList.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -53,8 +49,7 @@ Foam::nullSurfaceWriter<Type>::~nullSurfaceWriter()
template<class Type>
void Foam::nullSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,

View File

@ -76,8 +76,7 @@ public:
//- Writes single surface to file.
virtual void write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,

View File

@ -35,7 +35,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(nullSurfaceWriter, nil);
makeSurfaceWriterType(nullSurfaceWriter, bool);
makeSurfaceWriters(nullSurfaceWriter);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -26,9 +26,8 @@ License
#include "objSurfaceWriter.H"
#include "fileName.H"
#include "MeshedSurfaceProxy.H"
#include "OFstream.H"
#include "faceList.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -49,146 +48,33 @@ Foam::objSurfaceWriter<Type>::~objSurfaceWriter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::objSurfaceWriter<Foam::nil>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Foam::nil>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
fileName fName(surfaceDir/surfaceName + ".obj");
if (verbose)
{
Info<< "Writing nil to " << fName << endl;
}
// this is a quick hack
OFstream os(fName);
os << "# Wavefront OBJ file" << nl
<< "o " << os.name().lessExt().name() << nl
<< nl
<< "# points : " << points.size() << nl
<< "# faces : " << faces.size() << nl
<< "# no zones " << nl;
os << nl
<< "# <points count=\"" << points.size() << "\">" << endl;
// Write vertex coords
forAll(points, ptI)
{
os << "v " << points[ptI].x()
<< ' ' << points[ptI].y()
<< ' ' << points[ptI].z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faces.size() << "\">" << endl;
forAll(faces, i)
{
const face& f = faces[i];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << nl;
}
os << "# </faces>" << endl;
}
}
template<class Type>
void Foam::objSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
if (!isDir(outputDir))
{
mkDir(surfaceDir);
mkDir(outputDir);
}
fileName fName(surfaceDir/surfaceName + ".obj");
fileName fName(outputDir/surfaceName + ".obj");
if (verbose)
{
Info<< "Writing field " << fieldName << " to " << fName << endl;
Info<< "Writing geometry to " << fName << endl;
}
// this is a quick hack
OFstream os(fName);
os << "# Wavefront OBJ file" << nl
<< "o " << os.name().lessExt().name() << nl
<< nl
<< "# points : " << points.size() << nl
<< "# faces : " << faces.size() << nl
<< "# no zones " << nl;
os << nl
<< "# <points count=\"" << points.size() << "\">" << endl;
// Write vertex coords
forAll(points, ptI)
{
os << "v " << points[ptI].x()
<< ' ' << points[ptI].y()
<< ' ' << points[ptI].z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faces.size() << "\">" << endl;
forAll(faces, i)
{
const face& f = faces[i];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << nl;
}
os << "# </faces>" << endl;
MeshedSurfaceProxy<face>
(
points,
faces
).write(fName);
}

View File

@ -71,20 +71,37 @@ public:
// Member Functions
//- Always write separate geometry file
virtual bool separateFiles()
{
return true;
}
// Write
//- Write geometry to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose = false
) const;
//- Writes single surface to file.
virtual void write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const bool verbose = false
) const;
) const
{}
};

View File

@ -35,8 +35,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(objSurfaceWriter, nil);
makeSurfaceWriters(objSurfaceWriter);
makeSurfaceWriterType(objSurfaceWriter, bool);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -26,9 +26,7 @@ License
#include "rawSurfaceWriter.H"
#include "fileName.H"
#include "OFstream.H"
#include "faceList.H"
#include "OSspecific.H"
#include "IOmanip.H"
@ -295,37 +293,31 @@ Foam::rawSurfaceWriter<Type>::~rawSurfaceWriter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::rawSurfaceWriter<Foam::nil>::write
template<class Type>
void Foam::rawSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Foam::nil>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
if (!isDir(outputDir))
{
mkDir(surfaceDir);
mkDir(outputDir);
}
fileName fName(surfaceDir/surfaceName + ".raw");
OFstream os
(
outputDir/surfaceName + ".raw"
);
if (verbose)
{
Info<< "Writing nil to " << fName << endl;
Info<< "Writing geometry to " << os.name() << endl;
}
OFstream os(fName);
// header
os << "# geometry NO_DATA " << faces.size() << nl
@ -341,14 +333,29 @@ void Foam::rawSurfaceWriter<Foam::nil>::write
os << nl;
}
namespace Foam
{
// bool fields aren't supported
template<>
void Foam::rawSurfaceWriter<bool>::write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<bool>& values,
const bool verbose
) const
{}
}
template<class Type>
void Foam::rawSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
@ -357,21 +364,21 @@ void Foam::rawSurfaceWriter<Type>::write
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
if (!isDir(outputDir))
{
mkDir(surfaceDir);
mkDir(outputDir);
}
fileName fName(surfaceDir/fieldName + '_' + surfaceName + ".raw");
OFstream os
(
outputDir/fieldName + '_' + surfaceName + ".raw"
);
if (verbose)
{
Info<< "Writing field " << fieldName << " to " << fName << endl;
Info<< "Writing field " << fieldName << " to " << os.name() << endl;
}
OFstream os(fName);
// header
os << "# " << fieldName;

View File

@ -135,11 +135,20 @@ public:
// Write
//- Write geometry to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose = false
) const;
//- Writes single surface to file.
virtual void write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,

View File

@ -35,7 +35,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(rawSurfaceWriter, nil);
makeSurfaceWriterType(rawSurfaceWriter, bool);
makeSurfaceWriters(rawSurfaceWriter);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -25,11 +25,10 @@ License
\*---------------------------------------------------------------------------*/
#include "stlSurfaceWriter.H"
#include "fileName.H"
#include "MeshedSurfaceProxy.H"
#include "OFstream.H"
#include "faceList.H"
#include "OSspecific.H"
#include "triSurface.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -49,134 +48,34 @@ Foam::stlSurfaceWriter<Type>::~stlSurfaceWriter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::stlSurfaceWriter<Foam::nil>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Foam::nil>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
fileName fName(surfaceDir/surfaceName + ".stl");
if (verbose)
{
Info<< "Writing nil to " << fName << endl;
}
// Convert faces to triangles.
DynamicList<labelledTri> tris(faces.size());
forAll(faces, i)
{
const face& f = faces[i];
faceList triFaces(f.nTriangles(points));
label nTris = 0;
f.triangles(points, nTris, triFaces);
forAll(triFaces, triI)
{
const face& tri = triFaces[triI];
tris.append(labelledTri(tri[0], tri[1], tri[2], 0));
}
}
triSurface
(
tris.shrink(),
geometricSurfacePatchList
(
1,
geometricSurfacePatch
(
"patch", // geometricType
"patch0", // fieldName
0 // index
)
),
points
).write(fName);
}
}
template<class Type>
void Foam::stlSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
if (!isDir(outputDir))
{
mkDir(surfaceDir);
mkDir(outputDir);
}
fileName fName(surfaceDir/surfaceName + ".stl");
fileName fName(outputDir/surfaceName + ".stl");
if (verbose)
{
Info<< "Writing field " << fieldName << " to " << fName << endl;
Info<< "Writing geometry to " << fName << endl;
}
// Convert faces to triangles.
DynamicList<labelledTri> tris(faces.size());
forAll(faces, i)
{
const face& f = faces[i];
faceList triFaces(f.nTriangles(points));
label nTris = 0;
f.triangles(points, nTris, triFaces);
forAll(triFaces, triI)
{
const face& tri = triFaces[triI];
tris.append(labelledTri(tri[0], tri[1], tri[2], 0));
}
}
triSurface
MeshedSurfaceProxy<face>
(
tris.shrink(),
geometricSurfacePatchList
(
1,
geometricSurfacePatch
(
"patch", // geometricType
string::validate<word>(fieldName), // fieldName
0 // index
)
),
points
points,
faces
).write(fName);
}

View File

@ -71,20 +71,37 @@ public:
// Member Functions
//- Always write separate geometry file
virtual bool separateFiles()
{
return true;
}
// Write
//- Write geometry to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose = false
) const;
//- Writes single surface to file.
virtual void write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const bool verbose = false
) const;
) const
{}
};

View File

@ -35,8 +35,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(stlSurfaceWriter, nil);
makeSurfaceWriters(stlSurfaceWriter);
makeSurfaceWriterType(stlSurfaceWriter, bool);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -27,7 +27,6 @@ License
#include "surfaceWriter.H"
#include "HashTable.H"
#include "word.H"
#include "fileName.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
@ -40,13 +39,13 @@ Foam::surfaceWriter<Type>::New(const word& writeType)
if (cstrIter == wordConstructorTablePtr_->end())
{
// unknown, check if it can handle Foam::nil specialization
// unknown, check if it can handle 'bool' specialization
// (ie, geometry write)
// generally supported, but not for this data type
if
(
Foam::surfaceWriter<Foam::nil>::wordConstructorTablePtr_->found
Foam::surfaceWriter<bool>::wordConstructorTablePtr_->found
(
writeType
)
@ -88,4 +87,6 @@ Foam::surfaceWriter<Type>::~surfaceWriter()
{}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
// ************************************************************************* //

View File

@ -37,11 +37,12 @@ SourceFiles
#include "Field.H"
#include "typeInfo.H"
#include "runTimeSelectionTables.H"
#include "autoPtr.H"
#include "pointField.H"
#include "faceList.H"
#include "nil.H"
#include "fileName.H"
#include "runTimeSelectionTables.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -98,12 +99,30 @@ public:
// Member Functions
//- Return true if the surface format supports separate files
virtual bool separateFiles()
{
return false;
}
//- Writes single surface geometry to file.
virtual void write
(
const fileName& outputDir, // <root>/<case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const bool verbose = false
) const
{}
//- Writes single surface to file. Either one value per vertex or
// one value per face (detected by values.size()==faces.size())
virtual void write
(
const fileName& samplePath, // <root>/<case>/sampleSurfaces
const fileName& timeDir, // time directory
const fileName& outputDir, // <root>/<case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,

View File

@ -36,7 +36,7 @@ namespace Foam
defineNamedTemplateTypeNameAndDebug(surfaceWriter< dataType >, 0); \
defineTemplatedRunTimeSelectionTable(surfaceWriter, word, dataType)
defineSurfaceWriterType(nil);
defineSurfaceWriterType(bool);
defineSurfaceWriterType(scalar);
defineSurfaceWriterType(vector);

View File

@ -26,9 +26,7 @@ License
#include "vtkSurfaceWriter.H"
#include "fileName.H"
#include "OFstream.H"
#include "faceList.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
@ -198,7 +196,7 @@ namespace Foam
}
// Write tensorField in vtk format
// Write generic field in vtk format
template<class Type>
void Foam::vtkSurfaceWriter<Type>::writeData
(
@ -234,47 +232,37 @@ Foam::vtkSurfaceWriter<Type>::~vtkSurfaceWriter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::vtkSurfaceWriter<Foam::nil>::write
template<class Type>
void Foam::vtkSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Foam::nil>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
if (!isDir(outputDir))
{
mkDir(surfaceDir);
mkDir(outputDir);
}
fileName fName(surfaceDir/surfaceName + ".vtk");
fileName fName(outputDir/surfaceName + ".vtk");
if (verbose)
{
Info<< "Writing nil to " << fName << endl;
Info<< "Writing geometry to " << fName << endl;
}
OFstream os(fName);
writeGeometry(os, points, faces);
}
}
template<class Type>
void Foam::vtkSurfaceWriter<Type>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
@ -283,21 +271,21 @@ void Foam::vtkSurfaceWriter<Type>::write
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
if (!isDir(outputDir))
{
mkDir(surfaceDir);
mkDir(outputDir);
}
fileName fName(surfaceDir/fieldName + '_' + surfaceName + ".vtk");
OFstream os
(
outputDir/fieldName + '_' + surfaceName + ".vtk"
);
if (verbose)
{
Info<< "Writing field " << fieldName << " to " << fName << endl;
Info<< "Writing field " << fieldName << " to " << os.name() << endl;
}
OFstream os(fName);
writeGeometry(os, points, faces);
// start writing data

View File

@ -79,11 +79,21 @@ public:
// Write
//- Write geometry to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose = false
) const;
//- Writes single surface to file.
virtual void write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,

View File

@ -35,7 +35,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(vtkSurfaceWriter, nil);
makeSurfaceWriterType(vtkSurfaceWriter, bool);
makeSurfaceWriters(vtkSurfaceWriter);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //