MERGE: Merging surface writers

This commit is contained in:
Hrvoje Jasak 2018-05-15 16:32:42 +01:00
parent 7a54aeb99b
commit ee130abd3b
12 changed files with 876 additions and 667 deletions

View file

@ -154,7 +154,7 @@ void Foam::sampledPatch::remapFaces
) )
{ {
// recalculate the cells cut // recalculate the cells cut
if (!faceMap.empty()) if (&faceMap && faceMap.size())
{ {
MeshStorage::remapFaces(faceMap); MeshStorage::remapFaces(faceMap);
} }

View file

@ -28,10 +28,19 @@ License
#include "OFstream.H" #include "OFstream.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "makeSurfaceWriterMethods.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
makeSurfaceWriterType(dxSurfaceWriter);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type> void Foam::dxSurfaceWriter::writeGeometry
void Foam::dxSurfaceWriter<Type>::writeGeometry
( (
Ostream& os, Ostream& os,
const pointField& points, const pointField& points,
@ -54,7 +63,6 @@ void Foam::dxSurfaceWriter<Type>::writeGeometry
os << nl; os << nl;
// Write triangles // Write triangles
os << "# The irregular connections (triangles)" << nl os << "# The irregular connections (triangles)" << nl
<< "object 2 class array type int rank 1 shape 3 items " << "object 2 class array type int rank 1 shape 3 items "
<< faces.size() << " data follows" << nl; << faces.size() << " data follows" << nl;
@ -80,17 +88,41 @@ void Foam::dxSurfaceWriter<Type>::writeGeometry
} }
void Foam::dxSurfaceWriter::writeTrailer(Ostream& os, const bool isNodeValues)
{
if (isNodeValues)
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
}
else
{
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
}
os << "# the field, with three components: \"positions\","
<< " \"connections\", and \"data\"" << nl
<< "object \"irregular positions irregular "
<< "connections\" class field"
<< nl
<< "component \"positions\" value 1" << nl
<< "component \"connections\" value 2" << nl
<< "component \"data\" value 3" << nl;
os << "end" << endl;
}
namespace Foam namespace Foam
{ {
// Write scalarField in DX format
template<> template<>
void Foam::dxSurfaceWriter<Foam::scalar>::writeData void Foam::dxSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<scalar>& values const Field<scalar>& values
) )
{ {
// Write data
os << "object 3 class array type float rank 0 items " os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl; << values.size() << " data follows" << nl;
@ -101,15 +133,13 @@ namespace Foam
} }
// Write vectorField in DX format
template<> template<>
void Foam::dxSurfaceWriter<Foam::vector>::writeData void Foam::dxSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<vector>& values const Field<vector>& values
) )
{ {
// Write data
os << "object 3 class array type float rank 1 shape 3 items " os << "object 3 class array type float rank 1 shape 3 items "
<< values.size() << " data follows" << nl; << values.size() << " data follows" << nl;
@ -122,15 +152,13 @@ namespace Foam
} }
// Write sphericalTensorField in DX format
template<> template<>
void Foam::dxSurfaceWriter<Foam::sphericalTensor>::writeData void Foam::dxSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<sphericalTensor>& values const Field<sphericalTensor>& values
) )
{ {
// Write data
os << "object 3 class array type float rank 0 items " os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl; << values.size() << " data follows" << nl;
@ -141,15 +169,13 @@ namespace Foam
} }
// Write symmTensorField in DX format
template<> template<>
void Foam::dxSurfaceWriter<Foam::symmTensor>::writeData void Foam::dxSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<symmTensor>& values const Field<symmTensor>& values
) )
{ {
// Write data
os << "object 3 class array type float rank 2 shape 3 items " os << "object 3 class array type float rank 2 shape 3 items "
<< values.size() << " data follows" << nl; << values.size() << " data follows" << nl;
@ -165,15 +191,14 @@ namespace Foam
} }
// Write tensorField in DX format // Write Field<tensor> in DX format
template<> template<>
void Foam::dxSurfaceWriter<Foam::tensor>::writeData inline void Foam::dxSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<tensor>& values const Field<tensor>& values
) )
{ {
// Write data
os << "object 3 class array type float rank 2 shape 3 items " os << "object 3 class array type float rank 2 shape 3 items "
<< values.size() << " data follows" << nl; << values.size() << " data follows" << nl;
@ -189,15 +214,15 @@ namespace Foam
} }
} }
// Write tensorField in DX format
// arbitrary field
template<class Type> template<class Type>
void Foam::dxSurfaceWriter<Type>::writeData inline void Foam::dxSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<Type>& values const Field<Type>& values
) )
{ {
// Write data
os << "object 3 class array type float rank 0 items " os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl; << values.size() << " data follows" << nl;
@ -208,49 +233,16 @@ void Foam::dxSurfaceWriter<Type>::writeData
} }
// Write trailer in DX format
template<class Type> template<class Type>
void Foam::dxSurfaceWriter<Type>::writeTrailer(Ostream& os) void Foam::dxSurfaceWriter::writeTemplate
{
os << "# the field, with three components: \"positions\","
<< " \"connections\", and \"data\"" << nl
<< "object \"irregular positions irregular "
<< "connections\" class field"
<< nl
<< "component \"positions\" value 1" << nl
<< "component \"connections\" value 2" << nl
<< "component \"data\" value 3" << nl;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::dxSurfaceWriter<Type>::dxSurfaceWriter()
:
surfaceWriter<Type>()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::dxSurfaceWriter<Type>::~dxSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::dxSurfaceWriter<Type>::write
( (
const fileName& outputDir, const fileName& outputDir,
const fileName& surfaceName, const fileName& surfaceName,
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
const fileName& fieldName, const word& fieldName,
const Field<Type>& values, const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType, const bool isNodeValues,
const bool verbose const bool verbose
) const ) const
{ {
@ -270,42 +262,29 @@ void Foam::dxSurfaceWriter<Type>::write
} }
writeGeometry(os, points, faces); writeGeometry(os, points, faces);
writeData(os, values); writeData(os, values);
writeTrailer(os, isNodeValues);
switch (sdType)
{
case surfaceWriterBase::POINT_DATA:
// writing point data
if (values.size() != points.size())
{
FatalErrorIn("void dxSurfaceWriter<Type>::write(...)")
<< "Data size does not match the number of points. "
<< "Points: " << points.size() << " data: " << values.size()
<< abort(FatalError);
}
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
break;
case surfaceWriterBase::FACE_DATA:
// writing face data
if (values.size() != faces.size())
{
FatalErrorIn("void dxSurfaceWriter<Type>::write(...)")
<< "Data size does not match the number of faces. "
<< "Faces: " << faces.size() << " data: " << values.size()
<< abort(FatalError);
}
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
break;
}
writeTrailer(os);
os << "end" << nl;
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::dxSurfaceWriter::dxSurfaceWriter()
:
surfaceWriter()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::dxSurfaceWriter::~dxSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// create write methods
defineSurfaceWriterWriteFields(Foam::dxSurfaceWriter);
// ************************************************************************* // // ************************************************************************* //

View file

@ -25,6 +25,7 @@ Class
Foam::dxSurfaceWriter Foam::dxSurfaceWriter
Description Description
A surfaceWriter for OpenDX format.
SourceFiles SourceFiles
dxSurfaceWriter.C dxSurfaceWriter.C
@ -42,22 +43,36 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class dxSurfaceWriter Declaration Class dxSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type>
class dxSurfaceWriter class dxSurfaceWriter
: :
public surfaceWriter<Type> public surfaceWriter
{ {
// Private Member Functions // Private Member Functions
static void writeGeometry(Ostream&, const pointField&, const faceList&); static void writeGeometry(Ostream&, const pointField&, const faceList&);
static void writeTrailer(Ostream&, const bool isNodeValues);
static void writeData(Ostream&, const Field<Type>& values); template<class Type>
static void writeData(Ostream&, const Field<Type>&);
//- Templated write operation
template<class Type>
void writeTemplate
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const;
static void writeTrailer(Ostream&);
public: public:
@ -71,26 +86,110 @@ public:
dxSurfaceWriter(); dxSurfaceWriter();
// Destructor //- Destructor
virtual ~dxSurfaceWriter(); virtual ~dxSurfaceWriter();
// Member Functions // Member Functions
// Write //- Write scalarField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
//- Writes single surface to file.
virtual void write virtual void write
( (
const fileName& outputDir, const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, const fileName& surfaceName, // name of surface
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
const fileName& fieldName, const word& fieldName, // name of field
const Field<Type>& values, const Field<scalar>& values,
const surfaceWriterBase::surfaceData sdType, const bool isNodeValues,
const bool verbose = false const bool verbose = false
) const; ) const;
//- Write vectorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<vector>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write sphericalTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<sphericalTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor4thOrder>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<diagTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write tensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<tensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
}; };
@ -100,12 +199,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "dxSurfaceWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View file

@ -28,26 +28,76 @@ License
#include "OFstream.H" #include "OFstream.H"
#include "OSspecific.H" #include "OSspecific.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // #include "makeSurfaceWriterMethods.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
makeSurfaceWriterType(foamFileSurfaceWriter);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type> template<class Type>
Foam::foamFileSurfaceWriter<Type>::foamFileSurfaceWriter() void Foam::foamFileSurfaceWriter::writeTemplate
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const
{
fileName surfaceDir(outputDir/surfaceName);
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
if (verbose)
{
Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
}
// geometry should already have been written
// Values to separate directory (e.g. "scalarField/p")
fileName foamName(pTraits<Type>::typeName);
fileName valuesDir(surfaceDir / (foamName + Field<Type>::typeName));
if (!isDir(valuesDir))
{
mkDir(valuesDir);
}
// values
OFstream(valuesDir/fieldName)() << values;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::foamFileSurfaceWriter::foamFileSurfaceWriter()
: :
surfaceWriter<Type>() surfaceWriter()
{} {}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type> Foam::foamFileSurfaceWriter::~foamFileSurfaceWriter()
Foam::foamFileSurfaceWriter<Type>::~foamFileSurfaceWriter()
{} {}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> void Foam::foamFileSurfaceWriter::write
void Foam::foamFileSurfaceWriter<Type>::write
( (
const fileName& outputDir, const fileName& outputDir,
const fileName& surfaceName, const fileName& surfaceName,
@ -68,54 +118,28 @@ void Foam::foamFileSurfaceWriter<Type>::write
Info<< "Writing geometry to " << surfaceDir << endl; Info<< "Writing geometry to " << surfaceDir << endl;
} }
// Points // Points
OFstream(surfaceDir/"points")() << points; OFstream(surfaceDir/"points")() << points;
// Faces // Faces
OFstream(surfaceDir/"faces")() << faces; OFstream(surfaceDir/"faces")() << faces;
// Face centers. Not really necessary but very handy when reusing as inputs
// for e.g. timeVaryingMapped bc.
pointField faceCentres(faces.size(),point::zero);
forAll(faces, faceI)
{
faceCentres[faceI] = faces[faceI].centre(points);
}
OFstream(surfaceDir/"faceCentres")() << faceCentres;
} }
template<class Type> // create write methods
void Foam::foamFileSurfaceWriter<Type>::write defineSurfaceWriterWriteFields(Foam::foamFileSurfaceWriter);
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const bool verbose
) const
{
fileName surfaceDir(outputDir/surfaceName);
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
if (verbose)
{
Info<< "Writing field " << fieldName << " to " << surfaceDir << endl;
}
// geometry should already have been written
// Values to separate directory (e.g. "scalarField/p")
fileName foamName(pTraits<Type>::typeName);
fileName valuesDir(surfaceDir / (foamName + Field<Type>::typeName));
if (!isDir(valuesDir))
{
mkDir(valuesDir);
}
// values
OFstream(valuesDir/fieldName)() << values;
}
// ************************************************************************* // // ************************************************************************* //

View file

@ -43,14 +43,29 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class foamFileSurfaceWriter Declaration Class foamFileSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type>
class foamFileSurfaceWriter class foamFileSurfaceWriter
: :
public surfaceWriter<Type> public surfaceWriter
{ {
// Private Member Functions
//- Templated write operation
template<class Type>
void writeTemplate
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const;
public: public:
@ -64,19 +79,20 @@ public:
foamFileSurfaceWriter(); foamFileSurfaceWriter();
// Destructor //- Destructor
virtual ~foamFileSurfaceWriter(); virtual ~foamFileSurfaceWriter();
// Member Functions // Member Functions
//- Return true if the surface format supports separate files //- True if the surface format supports geometry in a separate file.
virtual bool separateFiles() // False if geometry and field must be in a single file
virtual bool separateGeometry()
{ {
return true; return true;
} }
//- Write geometry to file. //- Write single surface geometry to file.
virtual void write virtual void write
( (
const fileName& outputDir, const fileName& outputDir,
@ -86,18 +102,105 @@ public:
const bool verbose = false const bool verbose = false
) const; ) const;
//- Writes single surface to file.
//- Write scalarField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write virtual void write
( (
const fileName& outputDir, const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, const fileName& surfaceName, // name of surface
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
const fileName& fieldName, const word& fieldName, // name of field
const Field<Type>& values, const Field<scalar>& values,
const surfaceWriterBase::surfaceData sdType, const bool isNodeValues,
const bool verbose = false const bool verbose = false
) const; ) const;
//- Write vectorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<vector>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write sphericalTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<sphericalTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField4thOrder for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write diagTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor4thOrder>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<diagTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write tensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<tensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
}; };
@ -107,12 +210,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "foamFileSurfaceWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View file

@ -25,6 +25,8 @@ Class
Foam::proxySurfaceWriter Foam::proxySurfaceWriter
Description Description
A surfaceWriter that writes the geometry via the MeshedSurfaceProxy, but
which does not support any fields.
SourceFiles SourceFiles
proxySurfaceWriter.C proxySurfaceWriter.C
@ -42,13 +44,12 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class proxySurfaceWriter Declaration Class proxySurfaceWriter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type>
class proxySurfaceWriter class proxySurfaceWriter
: :
public surfaceWriter<Type> public surfaceWriter
{ {
// Private data // Private data
@ -74,38 +75,25 @@ public:
// Member Functions // Member Functions
//- Always write separate geometry file
virtual bool separateFiles() //- True if the surface format supports geometry in a separate file.
// False if geometry and field must be in a single file
virtual bool separateGeometry()
{ {
return true; return true;
} }
// Write
//- Write geometry to file. //- Write single surface geometry to file.
virtual void write virtual void write
( (
const fileName& outputDir, const fileName& outputDir,
const fileName& surfaceName, const fileName& surfaceName,
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
const bool verbose = false const bool verbose = false
) const; ) const;
//- Writes single surface to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const bool verbose = false
) const
{}
}; };
@ -115,12 +103,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "proxySurfaceWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View file

@ -381,92 +381,8 @@ void Foam::rawSurfaceWriter::write
} }
<<<<<<< HEAD
// create write methods // create write methods
defineSurfaceWriterWriteFields(Foam::rawSurfaceWriter); defineSurfaceWriterWriteFields(Foam::rawSurfaceWriter);
=======
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 surfaceWriterBase::surfaceData sdType,
const bool verbose
) const
{}
}
template<class Type>
void Foam::rawSurfaceWriter<Type>::write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const bool verbose
) const
{
if (!isDir(outputDir))
{
mkDir(outputDir);
}
OFstream os
(
outputDir/fieldName + '_' + surfaceName + ".raw"
);
if (verbose)
{
Info<< "Writing field " << fieldName << " to " << os.name() << endl;
}
// header
os << "# " << fieldName;
switch (sdType)
{
case surfaceWriterBase::POINT_DATA:
// writing point data
if (values.size() != points.size())
{
FatalErrorIn("void rawSurfaceWriter<Type>::write(...)")
<< "Data size does not match the number of points. "
<< "Points: " << points.size() << " data: " << values.size()
<< abort(FatalError);
}
os << "POINT_DATA ";
break;
case surfaceWriterBase::FACE_DATA:
// writing face data
if (values.size() != faces.size())
{
FatalErrorIn("void rawSurfaceWriter<Type>::write(...)")
<< "Data size does not match the number of faces. "
<< "Faces: " << faces.size() << " data: " << values.size()
<< abort(FatalError);
}
os << "FACE_DATA ";
break;
}
os << values.size() << nl;
writeData(fieldName, points, faces, values, os);
}
>>>>>>> feature/JasakDevelopment
// ************************************************************************* // // ************************************************************************* //

View file

@ -25,6 +25,7 @@ Class
Foam::rawSurfaceWriter Foam::rawSurfaceWriter
Description Description
A surfaceWriter for raw output.
SourceFiles SourceFiles
rawSurfaceWriter.C rawSurfaceWriter.C
@ -36,99 +37,62 @@ SourceFiles
#include "surfaceWriter.H" #include "surfaceWriter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class rawSurfaceWriter Declaration Class rawSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type>
class rawSurfaceWriter class rawSurfaceWriter
: :
public surfaceWriter<Type> public surfaceWriter
{ {
// Private Member Functions // Private Member Functions
static void writeGeometry static inline void writeLocation
( (
const pointField& points, Ostream&,
const label pointI, const pointField&,
Ostream& os const label pointI
); );
static void writeGeometry static inline void writeLocation
( (
const pointField& points, Ostream&,
const faceList& faces, const pointField&,
const label faceI, const faceList&,
Ostream& os const label faceI
); );
static void writeData template<class Type>
static void writeHeader
( (
const fileName& fieldName, Ostream&,
const pointField& points, const word& fieldName,
const faceList& faces, const Field<Type>&
const scalarField& values,
Ostream& os
); );
static void writeData template<class Type>
( static inline void writeData(Ostream&, const Type&);
const fileName& fieldName,
const pointField& points,
const faceList& faces,
const vectorField& values,
Ostream& os
);
static void writeData
(
const fileName& fieldName,
const pointField& points,
const faceList& faces,
const sphericalTensorField& values,
Ostream& os
);
static void writeData //- Templated write operation
template<class Type>
void writeTemplate
( (
const fileName& fieldName, const fileName& outputDir,
const fileName& surfaceName,
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
const diagTensorField& values, const word& fieldName,
Ostream& os const Field<Type>& values,
); const bool isNodeValues,
const bool verbose
static void writeData ) const;
(
const fileName& fieldName,
const pointField& points,
const faceList& faces,
const symmTensorField& values,
Ostream& os
);
static void writeData
(
const fileName& fieldName,
const pointField& points,
const faceList& faces,
const symmTensor4thOrderField& values,
Ostream& os
);
static void writeData
(
const fileName& fieldName,
const pointField& points,
const faceList& faces,
const tensorField& values,
Ostream& os
);
public: public:
@ -143,36 +107,121 @@ public:
rawSurfaceWriter(); rawSurfaceWriter();
// Destructor //- Destructor
virtual ~rawSurfaceWriter(); virtual ~rawSurfaceWriter();
// Member Functions // Member Functions
// Write //- Write single surface geometry to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose = false
) const;
//- 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. //- Write scalarField for a single surface to file.
virtual void write // One value per face or vertex (isNodeValues = true)
( virtual void write
const fileName& outputDir, (
const fileName& surfaceName, const fileName& outputDir, // <case>/surface/TIME
const pointField& points, const fileName& surfaceName, // name of surface
const faceList& faces, const pointField& points,
const fileName& fieldName, const faceList& faces,
const Field<Type>& values, const word& fieldName, // name of field
const surfaceWriterBase::surfaceData sdType, const Field<scalar>& values,
const bool verbose = false const bool isNodeValues,
) const; const bool verbose = false
) const;
//- Write vectorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<vector>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write sphericalTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<sphericalTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField4thOrder for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor4thOrder>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write diagTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<diagTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write tensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<tensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
}; };
@ -182,12 +231,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "rawSurfaceWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View file

@ -113,58 +113,4 @@ Foam::surfaceWriter::~surfaceWriter()
{} {}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class Type>
void Foam::surfaceWriter<Type>::write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const bool verbose
) const
{
if (points.size() == faces.size())
{
WarningIn("void surfaceWriter<Type>::write(...)")
<< "Writing unknown data type and the number of points "
<< "and faces is the same. Defaulting to point data" << nl
<< "Please specify data type in reader."
<< endl;
}
if (values.size() == points.size())
{
this->write
(
outputDir,
surfaceName,
points,
faces,
fieldName,
values,
surfaceWriterBase::POINT_DATA,
verbose
);
}
else
{
this->write
(
outputDir,
surfaceName,
points,
faces,
fieldName,
values,
surfaceWriterBase::FACE_DATA,
verbose
);
}
}
// ************************************************************************* // // ************************************************************************* //

View file

@ -35,7 +35,6 @@ SourceFiles
#ifndef surfaceWriter_H #ifndef surfaceWriter_H
#define surfaceWriter_H #define surfaceWriter_H
#include "Field.H"
#include "typeInfo.H" #include "typeInfo.H"
#include "autoPtr.H" #include "autoPtr.H"
#include "pointField.H" #include "pointField.H"
@ -49,47 +48,12 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of friend functions and operators
template<class Type> class surfaceWriter;
template<class Type> class nullSurfaceWriter;
template<class Type> class proxySurfaceWriter;
class surfaceWriterBase
{
public:
// Public enumerations
//- Surface data type
enum surfaceData
{
POINT_DATA,
FACE_DATA
};
// Constructors
//- Construct null
surfaceWriterBase()
{}
};
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class surfaceWriter Declaration Class surfaceWriter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type>
class surfaceWriter class surfaceWriter
:
public surfaceWriterBase
{ {
//- Friendship between writer data types
template<class Type2> friend class surfaceWriter;
public: public:
//- Runtime type information //- Runtime type information
@ -106,11 +70,30 @@ public:
() ()
); );
declareRunTimeSelectionTable
(
autoPtr,
surfaceWriter,
wordDict,
(
const dictionary& optDict
),
(optDict)
);
// Selectors // Selectors
//- Return a reference to the selected surfaceWriter //- Return a reference to the selected surfaceWriter
static autoPtr<surfaceWriter> New(const word& writeFormat); static autoPtr<surfaceWriter> New(const word& writeType);
//- Return a reference to the selected surfaceWriter
// Select with extra write option
static autoPtr<surfaceWriter> New
(
const word& writeType,
const dictionary& writeOptions
);
// Constructors // Constructors
@ -126,16 +109,15 @@ public:
// Member Functions // Member Functions
//- Return true if the surface format supports separate files //- Return true if the surface format supports separate files
virtual bool separateFiles() virtual bool separateGeometry()
{ {
return false; return false;
} }
//- Write single surface geometry to file.
//- Writes single surface geometry to file.
virtual void write virtual void write
( (
const fileName& outputDir, // <root>/<case>/surface/TIME const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface const fileName& surfaceName, // name of surface
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
@ -143,32 +125,110 @@ public:
) const ) const
{} {}
//- Writes single surface to file. Either one value per vertex or //- Write scalarField for a single surface to file.
// one value per face (detected by values.size()==faces.size()) // One value per face or vertex (isNodeValues = true)
void write
(
const fileName& outputDir, // <root>/<case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const fileName& fieldName, // name of field
const Field<Type>& values,
const bool verbose = false
) const;
//- Writes single surface to file. Either one value per vertex or
// one value per face, defined by type
virtual void write virtual void write
( (
const fileName& outputDir, // <root>/<case>/surface/TIME const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface const fileName& surfaceName, // name of surface
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
const fileName& fieldName, // name of field const word& fieldName, // name of field
const Field<Type>& values, const Field<scalar>& values,
const surfaceWriterBase::surfaceData sdType, const bool isNodeValues,
const bool verbose = false const bool verbose = false
) const = 0; ) const
{}
//- Write vectorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<vector>& values,
const bool isNodeValues,
const bool verbose = false
) const
{}
//- Write sphericalTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<sphericalTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const
{}
//- Write symmTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const
{}
//- Write symmTensorField4thOrder for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor4thOrder>& values,
const bool isNodeValues,
const bool verbose = false
) const
{}
//- Write diagTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<diagTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const
{}
//- Write tensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<tensor>& values,
const bool isNodeValues,
const bool verbose = false
) const
{}
}; };
@ -178,12 +238,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "surfaceWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View file

@ -28,10 +28,19 @@ License
#include "OFstream.H" #include "OFstream.H"
#include "OSspecific.H" #include "OSspecific.H"
#include "makeSurfaceWriterMethods.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
makeSurfaceWriterType(vtkSurfaceWriter);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type> void Foam::vtkSurfaceWriter::writeGeometry
void Foam::vtkSurfaceWriter<Type>::writeGeometry
( (
Ostream& os, Ostream& os,
const pointField& points, const pointField& points,
@ -46,7 +55,7 @@ void Foam::vtkSurfaceWriter<Type>::writeGeometry
<< "DATASET POLYDATA" << nl; << "DATASET POLYDATA" << nl;
// Write vertex coords // Write vertex coords
os << "POINTS " << points.size() << " float" << nl; os << "POINTS " << points.size() << " double" << nl;
forAll(points, pointI) forAll(points, pointI)
{ {
const point& pt = points[pointI]; const point& pt = points[pointI];
@ -71,12 +80,12 @@ void Foam::vtkSurfaceWriter<Type>::writeGeometry
{ {
const face& f = faces[faceI]; const face& f = faces[faceI];
os << f.size(); os << f.size();
forAll(f, fp) forAll(f, fp)
{ {
os << ' ' << f[fp]; os << ' ' << f[fp];
} }
os << nl; os << nl;
} }
} }
@ -84,15 +93,14 @@ void Foam::vtkSurfaceWriter<Type>::writeGeometry
namespace Foam namespace Foam
{ {
// Write scalarField in vtk format
template<> template<>
void Foam::vtkSurfaceWriter<Foam::scalar>::writeData void Foam::vtkSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<Foam::scalar>& values const Field<scalar>& values
) )
{ {
os << "1 " << values.size() << " float" << nl; os << "1 " << values.size() << " double" << nl;
forAll(values, elemI) forAll(values, elemI)
{ {
@ -100,29 +108,28 @@ namespace Foam
{ {
if (elemI % 10) if (elemI % 10)
{ {
os << ' '; os << ' ';
} }
else else
{ {
os << nl; os << nl;
} }
} }
const scalar& v = values[elemI]; os << float(values[elemI]);
os << float(v);
} }
os << nl; os << nl;
} }
// Write vectorField in vtk format
template<> template<>
void Foam::vtkSurfaceWriter<Foam::vector>::writeData void Foam::vtkSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<Foam::vector>& values const Field<vector>& values
) )
{ {
os << "3 " << values.size() << " float" << nl; os << "3 " << values.size() << " double" << nl;
forAll(values, elemI) forAll(values, elemI)
{ {
@ -133,38 +140,37 @@ namespace Foam
} }
// Write sphericalTensorField in vtk format
template<> template<>
void Foam::vtkSurfaceWriter<Foam::sphericalTensor>::writeData void Foam::vtkSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<sphericalTensor>& values const Field<sphericalTensor>& values
) )
{ {
os << "1 " << values.size() << " float" << nl; os << "1 " << values.size() << " double" << nl;
forAll(values, elemI) forAll(values, elemI)
{ {
const sphericalTensor& v = values[elemI]; const sphericalTensor& v = values[elemI];
os << float(v[0]) << nl; os << float(v[0]) << nl;
} }
} }
// Write symmTensorField in vtk format
template<> template<>
void Foam::vtkSurfaceWriter<Foam::symmTensor>::writeData void Foam::vtkSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<symmTensor>& values const Field<symmTensor>& values
) )
{ {
os << "6 " << values.size() << " float" << nl; os << "6 " << values.size() << " double" << nl;
forAll(values, elemI) forAll(values, elemI)
{ {
const symmTensor& v = values[elemI]; const symmTensor& v = values[elemI];
os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
<< ' '
<< float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5]) << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
<< nl; << nl;
@ -172,21 +178,22 @@ namespace Foam
} }
// Write tensorField in vtk format
template<> template<>
void Foam::vtkSurfaceWriter<Foam::tensor>::writeData void Foam::vtkSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<tensor>& values const Field<tensor>& values
) )
{ {
os << "9 " << values.size() << " float" << nl; os << "9 " << values.size() << " double" << nl;
forAll(values, elemI) forAll(values, elemI)
{ {
const tensor& v = values[elemI]; const tensor& v = values[elemI];
os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2]) os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
<< ' '
<< float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5]) << float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
<< ' '
<< float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8]) << float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8])
<< nl; << nl;
} }
@ -197,77 +204,31 @@ namespace Foam
// Write generic field in vtk format // Write generic field in vtk format
template<class Type> template<class Type>
void Foam::vtkSurfaceWriter<Type>::writeData void Foam::vtkSurfaceWriter::writeData
( (
Ostream& os, Ostream& os,
const Field<Type>& values const Field<Type>& values
) )
{ {
os << "1 " << values.size() << " float" << nl; os << "1 " << values.size() << " double" << nl;
forAll(values, elemI) forAll(values, elemI)
{ {
os << float(0) << nl; os << float(0) << nl;
} }
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
template<class Type> template<class Type>
Foam::vtkSurfaceWriter<Type>::vtkSurfaceWriter() void Foam::vtkSurfaceWriter::writeTemplate
:
surfaceWriter<Type>()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::vtkSurfaceWriter<Type>::~vtkSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkSurfaceWriter<Type>::write
( (
const fileName& outputDir, const fileName& outputDir,
const fileName& surfaceName, const fileName& surfaceName,
const pointField& points, const pointField& points,
const faceList& faces, const faceList& faces,
const bool verbose const word& fieldName,
) const
{
if (!isDir(outputDir))
{
mkDir(outputDir);
}
fileName fName(outputDir/surfaceName + ".vtk");
if (verbose)
{
Info<< "Writing geometry to " << fName << endl;
}
OFstream os(fName);
writeGeometry(os, points, faces);
}
template<class Type>
void Foam::vtkSurfaceWriter<Type>::write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values, const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType, const bool isNodeValues,
const bool verbose const bool verbose
) const ) const
{ {
@ -276,10 +237,7 @@ void Foam::vtkSurfaceWriter<Type>::write
mkDir(outputDir); mkDir(outputDir);
} }
OFstream os OFstream os(outputDir/fieldName + '_' + surfaceName + ".vtk");
(
outputDir/fieldName + '_' + surfaceName + ".vtk"
);
if (verbose) if (verbose)
{ {
@ -288,45 +246,68 @@ void Foam::vtkSurfaceWriter<Type>::write
writeGeometry(os, points, faces); writeGeometry(os, points, faces);
switch (sdType) // start writing data
if (isNodeValues)
{ {
case surfaceWriterBase::POINT_DATA: os << "POINT_DATA ";
// writing point data
if (values.size() != points.size())
{
FatalErrorIn("void vtkSurfaceWriter<Type>::write(...)")
<< "Data size does not match the number of points. "
<< "Points: " << points.size() << " data: " << values.size()
<< abort(FatalError);
}
os << "POINT_DATA "
<< values.size() << nl
<< "FIELD attributes 1" << nl
<< fieldName.c_str() << " ";
// Write data
writeData(os, values);
break;
case surfaceWriterBase::FACE_DATA:
// writing face data
if (values.size() != faces.size())
{
FatalErrorIn("void vtkSurfaceWriter<Type>::write(...)")
<< "Data size does not match the number of faces. "
<< "Faces: " << faces.size() << " data: " << values.size()
<< abort(FatalError);
}
os << "CELL_DATA "
<< values.size() << nl
<< "FIELD attributes 1" << nl
<< fieldName.c_str() << " ";
// Write data
writeData(os, values);
break;
} }
else
{
os << "CELL_DATA ";
}
os << values.size() << nl
<< "FIELD attributes 1" << nl
<< fieldName << " ";
// Write data
writeData(os, values);
} }
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::vtkSurfaceWriter::vtkSurfaceWriter()
:
surfaceWriter()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::vtkSurfaceWriter::~vtkSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::vtkSurfaceWriter::write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose
) const
{
if (!isDir(outputDir))
{
mkDir(outputDir);
}
OFstream os(outputDir/surfaceName + ".vtk");
if (verbose)
{
Info<< "Writing geometry to " << os.name() << endl;
}
writeGeometry(os, points, faces);
}
// create write methods
defineSurfaceWriterWriteFields(Foam::vtkSurfaceWriter);
// ************************************************************************* // // ************************************************************************* //

View file

@ -25,6 +25,7 @@ Class
Foam::vtkSurfaceWriter Foam::vtkSurfaceWriter
Description Description
A surfaceWriter for VTK legacy format.
SourceFiles SourceFiles
vtkSurfaceWriter.C vtkSurfaceWriter.C
@ -42,21 +43,35 @@ namespace Foam
{ {
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class vtkSurfaceWriter Declaration Class vtkSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class Type>
class vtkSurfaceWriter class vtkSurfaceWriter
: :
public surfaceWriter<Type> public surfaceWriter
{ {
// Private Member Functions // Private Member Functions
static void writeGeometry(Ostream&, const pointField&, const faceList&); static void writeGeometry(Ostream&, const pointField&, const faceList&);
static void writeData(Ostream&, const Field<Type>& values); template<class Type>
static void writeData(Ostream&, const Field<Type>&);
//- Templated write operation
template<class Type>
void writeTemplate
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const;
public: public:
//- Runtime type information //- Runtime type information
@ -69,36 +84,121 @@ public:
vtkSurfaceWriter(); vtkSurfaceWriter();
// Destructor //- Destructor
virtual ~vtkSurfaceWriter(); virtual ~vtkSurfaceWriter();
// Member Functions // Member Functions
// Write //- Write single surface geometry to file.
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose = false
) const;
//- 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. //- Write scalarField for a single surface to file.
virtual void write // One value per face or vertex (isNodeValues = true)
( virtual void write
const fileName& outputDir, (
const fileName& surfaceName, const fileName& outputDir, // <case>/surface/TIME
const pointField& points, const fileName& surfaceName, // name of surface
const faceList& faces, const pointField& points,
const fileName& fieldName, const faceList& faces,
const Field<Type>& values, const word& fieldName, // name of field
const surfaceWriterBase::surfaceData sdType, const Field<scalar>& values,
const bool verbose = false const bool isNodeValues,
) const; const bool verbose = false
) const;
//- Write vectorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<vector>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write sphericalTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<sphericalTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write symmTensorField4thOrder for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<symmTensor4thOrder>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write diagTensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<diagTensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Write tensorField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<tensor>& values,
const bool isNodeValues,
const bool verbose = false
) const;
}; };
@ -108,12 +208,6 @@ public:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "vtkSurfaceWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif #endif
// ************************************************************************* // // ************************************************************************* //