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
if (!faceMap.empty())
if (&faceMap && faceMap.size())
{
MeshStorage::remapFaces(faceMap);
}

View file

@ -28,10 +28,19 @@ License
#include "OFstream.H"
#include "OSspecific.H"
#include "makeSurfaceWriterMethods.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
makeSurfaceWriterType(dxSurfaceWriter);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeGeometry
void Foam::dxSurfaceWriter::writeGeometry
(
Ostream& os,
const pointField& points,
@ -54,7 +63,6 @@ void Foam::dxSurfaceWriter<Type>::writeGeometry
os << nl;
// Write triangles
os << "# The irregular connections (triangles)" << nl
<< "object 2 class array type int rank 1 shape 3 items "
<< 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
{
// Write scalarField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::scalar>::writeData
void Foam::dxSurfaceWriter::writeData
(
Ostream& os,
const Field<scalar>& values
)
{
// Write data
os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl;
@ -101,15 +133,13 @@ namespace Foam
}
// Write vectorField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::vector>::writeData
void Foam::dxSurfaceWriter::writeData
(
Ostream& os,
const Field<vector>& values
)
{
// Write data
os << "object 3 class array type float rank 1 shape 3 items "
<< values.size() << " data follows" << nl;
@ -122,15 +152,13 @@ namespace Foam
}
// Write sphericalTensorField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::sphericalTensor>::writeData
void Foam::dxSurfaceWriter::writeData
(
Ostream& os,
const Field<sphericalTensor>& values
)
{
// Write data
os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl;
@ -141,15 +169,13 @@ namespace Foam
}
// Write symmTensorField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::symmTensor>::writeData
void Foam::dxSurfaceWriter::writeData
(
Ostream& os,
const Field<symmTensor>& values
)
{
// Write data
os << "object 3 class array type float rank 2 shape 3 items "
<< values.size() << " data follows" << nl;
@ -165,15 +191,14 @@ namespace Foam
}
// Write tensorField in DX format
// Write Field<tensor> in DX format
template<>
void Foam::dxSurfaceWriter<Foam::tensor>::writeData
inline void Foam::dxSurfaceWriter::writeData
(
Ostream& os,
const Field<tensor>& values
)
{
// Write data
os << "object 3 class array type float rank 2 shape 3 items "
<< values.size() << " data follows" << nl;
@ -189,15 +214,15 @@ namespace Foam
}
}
// Write tensorField in DX format
// arbitrary field
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeData
inline void Foam::dxSurfaceWriter::writeData
(
Ostream& os,
const Field<Type>& values
)
{
// Write data
os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl;
@ -208,49 +233,16 @@ void Foam::dxSurfaceWriter<Type>::writeData
}
// Write trailer in DX format
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeTrailer(Ostream& os)
{
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
void Foam::dxSurfaceWriter::writeTemplate
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const word& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const bool isNodeValues,
const bool verbose
) const
{
@ -270,42 +262,29 @@ void Foam::dxSurfaceWriter<Type>::write
}
writeGeometry(os, points, faces);
writeData(os, values);
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;
writeTrailer(os, isNodeValues);
}
// * * * * * * * * * * * * * * * * 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
Description
A surfaceWriter for OpenDX format.
SourceFiles
dxSurfaceWriter.C
@ -45,19 +46,33 @@ namespace Foam
Class dxSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class dxSurfaceWriter
:
public surfaceWriter<Type>
public surfaceWriter
{
// Private Member Functions
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:
@ -71,26 +86,110 @@ public:
dxSurfaceWriter();
// Destructor
//- Destructor
virtual ~dxSurfaceWriter();
// Member Functions
// Write
//- Writes single surface to file.
//- Write scalarField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir,
const fileName& surfaceName,
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const word& fieldName, // name of field
const Field<scalar>& values,
const bool isNodeValues,
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 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
// ************************************************************************* //

View file

@ -28,26 +28,76 @@ License
#include "OFstream.H"
#include "OSspecific.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
#include "makeSurfaceWriterMethods.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
makeSurfaceWriterType(foamFileSurfaceWriter);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
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 * * * * * * * * * * * * * * * //
template<class Type>
Foam::foamFileSurfaceWriter<Type>::~foamFileSurfaceWriter()
Foam::foamFileSurfaceWriter::~foamFileSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::foamFileSurfaceWriter<Type>::write
void Foam::foamFileSurfaceWriter::write
(
const fileName& outputDir,
const fileName& surfaceName,
@ -68,54 +118,28 @@ void Foam::foamFileSurfaceWriter<Type>::write
Info<< "Writing geometry to " << surfaceDir << endl;
}
// Points
OFstream(surfaceDir/"points")() << points;
// 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>
void Foam::foamFileSurfaceWriter<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
{
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;
}
// create write methods
defineSurfaceWriterWriteFields(Foam::foamFileSurfaceWriter);
// ************************************************************************* //

View file

@ -46,11 +46,26 @@ namespace Foam
Class foamFileSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
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:
@ -64,19 +79,20 @@ public:
foamFileSurfaceWriter();
// Destructor
//- Destructor
virtual ~foamFileSurfaceWriter();
// Member Functions
//- Return true if the surface format supports separate files
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;
}
//- Write geometry to file.
//- Write single surface geometry to file.
virtual void write
(
const fileName& outputDir,
@ -86,18 +102,105 @@ public:
const bool verbose = false
) 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
(
const fileName& outputDir,
const fileName& surfaceName,
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const word& fieldName, // name of field
const Field<scalar>& values,
const bool isNodeValues,
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 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
// ************************************************************************* //

View file

@ -25,6 +25,8 @@ Class
Foam::proxySurfaceWriter
Description
A surfaceWriter that writes the geometry via the MeshedSurfaceProxy, but
which does not support any fields.
SourceFiles
proxySurfaceWriter.C
@ -45,10 +47,9 @@ namespace Foam
Class proxySurfaceWriter Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class proxySurfaceWriter
:
public surfaceWriter<Type>
public surfaceWriter
{
// Private data
@ -74,15 +75,16 @@ public:
// 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;
}
// Write
//- Write geometry to file.
//- Write single surface geometry to file.
virtual void write
(
const fileName& outputDir,
@ -92,20 +94,6 @@ public:
const bool verbose = false
) 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
// ************************************************************************* //

View file

@ -381,92 +381,8 @@ void Foam::rawSurfaceWriter::write
}
<<<<<<< HEAD
// create write methods
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
Description
A surfaceWriter for raw output.
SourceFiles
rawSurfaceWriter.C
@ -36,6 +37,7 @@ SourceFiles
#include "surfaceWriter.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
@ -45,90 +47,52 @@ namespace Foam
Class rawSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class rawSurfaceWriter
:
public surfaceWriter<Type>
public surfaceWriter
{
// Private Member Functions
static void writeGeometry
static inline void writeLocation
(
const pointField& points,
const label pointI,
Ostream& os
Ostream&,
const pointField&,
const label pointI
);
static void writeGeometry
static inline void writeLocation
(
const pointField& points,
const faceList& faces,
const label faceI,
Ostream& os
Ostream&,
const pointField&,
const faceList&,
const label faceI
);
static void writeData
template<class Type>
static void writeHeader
(
const fileName& fieldName,
const pointField& points,
const faceList& faces,
const scalarField& values,
Ostream& os
Ostream&,
const word& fieldName,
const Field<Type>&
);
static void writeData
(
const fileName& fieldName,
const pointField& points,
const faceList& faces,
const vectorField& values,
Ostream& os
);
template<class Type>
static inline void writeData(Ostream&, const Type&);
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 faceList& faces,
const diagTensorField& values,
Ostream& os
);
static void writeData
(
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
);
const word& fieldName,
const Field<Type>& values,
const bool isNodeValues,
const bool verbose
) const;
public:
@ -143,15 +107,13 @@ public:
rawSurfaceWriter();
// Destructor
//- Destructor
virtual ~rawSurfaceWriter();
// Member Functions
// Write
//- Write geometry to file.
//- Write single surface geometry to file.
virtual void write
(
const fileName& outputDir,
@ -161,18 +123,105 @@ public:
const bool verbose = false
) 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
(
const fileName& outputDir,
const fileName& surfaceName,
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const word& fieldName, // name of field
const Field<scalar>& values,
const bool isNodeValues,
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
// ************************************************************************* //

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
#define surfaceWriter_H
#include "Field.H"
#include "typeInfo.H"
#include "autoPtr.H"
#include "pointField.H"
@ -49,47 +48,12 @@ SourceFiles
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
\*---------------------------------------------------------------------------*/
template<class Type>
class surfaceWriter
:
public surfaceWriterBase
{
//- Friendship between writer data types
template<class Type2> friend class surfaceWriter;
public:
//- Runtime type information
@ -106,11 +70,30 @@ public:
()
);
declareRunTimeSelectionTable
(
autoPtr,
surfaceWriter,
wordDict,
(
const dictionary& optDict
),
(optDict)
);
// Selectors
//- 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
@ -126,16 +109,15 @@ public:
// Member Functions
//- Return true if the surface format supports separate files
virtual bool separateFiles()
virtual bool separateGeometry()
{
return false;
}
//- Writes single surface geometry to file.
//- Write single surface geometry to file.
virtual void write
(
const fileName& outputDir, // <root>/<case>/surface/TIME
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
@ -143,32 +125,110 @@ public:
) const
{}
//- Writes single surface to file. Either one value per vertex or
// one value per face (detected by values.size()==faces.size())
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
//- Write scalarField for a single surface to file.
// One value per face or vertex (isNodeValues = true)
virtual void write
(
const fileName& outputDir, // <root>/<case>/surface/TIME
const fileName& outputDir, // <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 surfaceWriterBase::surfaceData sdType,
const word& fieldName, // name of field
const Field<scalar>& values,
const bool isNodeValues,
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
// ************************************************************************* //

View file

@ -28,10 +28,19 @@ License
#include "OFstream.H"
#include "OSspecific.H"
#include "makeSurfaceWriterMethods.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
makeSurfaceWriterType(vtkSurfaceWriter);
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::vtkSurfaceWriter<Type>::writeGeometry
void Foam::vtkSurfaceWriter::writeGeometry
(
Ostream& os,
const pointField& points,
@ -46,7 +55,7 @@ void Foam::vtkSurfaceWriter<Type>::writeGeometry
<< "DATASET POLYDATA" << nl;
// Write vertex coords
os << "POINTS " << points.size() << " float" << nl;
os << "POINTS " << points.size() << " double" << nl;
forAll(points, pointI)
{
const point& pt = points[pointI];
@ -84,15 +93,14 @@ void Foam::vtkSurfaceWriter<Type>::writeGeometry
namespace Foam
{
// Write scalarField in vtk format
template<>
void Foam::vtkSurfaceWriter<Foam::scalar>::writeData
void Foam::vtkSurfaceWriter::writeData
(
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)
{
@ -108,21 +116,20 @@ namespace Foam
}
}
const scalar& v = values[elemI];
os << float(v);
os << float(values[elemI]);
}
os << nl;
}
// Write vectorField in vtk format
template<>
void Foam::vtkSurfaceWriter<Foam::vector>::writeData
void Foam::vtkSurfaceWriter::writeData
(
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)
{
@ -133,15 +140,14 @@ namespace Foam
}
// Write sphericalTensorField in vtk format
template<>
void Foam::vtkSurfaceWriter<Foam::sphericalTensor>::writeData
void Foam::vtkSurfaceWriter::writeData
(
Ostream& os,
const Field<sphericalTensor>& values
)
{
os << "1 " << values.size() << " float" << nl;
os << "1 " << values.size() << " double" << nl;
forAll(values, elemI)
{
@ -151,20 +157,20 @@ namespace Foam
}
// Write symmTensorField in vtk format
template<>
void Foam::vtkSurfaceWriter<Foam::symmTensor>::writeData
void Foam::vtkSurfaceWriter::writeData
(
Ostream& os,
const Field<symmTensor>& values
)
{
os << "6 " << values.size() << " float" << nl;
os << "6 " << values.size() << " double" << nl;
forAll(values, elemI)
{
const symmTensor& v = values[elemI];
os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
<< ' '
<< float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
<< nl;
@ -172,21 +178,22 @@ namespace Foam
}
// Write tensorField in vtk format
template<>
void Foam::vtkSurfaceWriter<Foam::tensor>::writeData
void Foam::vtkSurfaceWriter::writeData
(
Ostream& os,
const Field<tensor>& values
)
{
os << "9 " << values.size() << " float" << nl;
os << "9 " << values.size() << " double" << nl;
forAll(values, elemI)
{
const tensor& v = values[elemI];
os << float(v[0]) << ' ' << float(v[1]) << ' ' << float(v[2])
<< ' '
<< float(v[3]) << ' ' << float(v[4]) << ' ' << float(v[5])
<< ' '
<< float(v[6]) << ' ' << float(v[7]) << ' ' << float(v[8])
<< nl;
}
@ -197,13 +204,13 @@ namespace Foam
// Write generic field in vtk format
template<class Type>
void Foam::vtkSurfaceWriter<Type>::writeData
void Foam::vtkSurfaceWriter::writeData
(
Ostream& os,
const Field<Type>& values
)
{
os << "1 " << values.size() << " float" << nl;
os << "1 " << values.size() << " double" << nl;
forAll(values, elemI)
{
@ -212,62 +219,16 @@ void Foam::vtkSurfaceWriter<Type>::writeData
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from components
template<class Type>
Foam::vtkSurfaceWriter<Type>::vtkSurfaceWriter()
:
surfaceWriter<Type>()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::vtkSurfaceWriter<Type>::~vtkSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
void Foam::vtkSurfaceWriter<Type>::write
void Foam::vtkSurfaceWriter::writeTemplate
(
const fileName& outputDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const bool verbose
) 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 word& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const bool isNodeValues,
const bool verbose
) const
{
@ -276,10 +237,7 @@ void Foam::vtkSurfaceWriter<Type>::write
mkDir(outputDir);
}
OFstream os
(
outputDir/fieldName + '_' + surfaceName + ".vtk"
);
OFstream os(outputDir/fieldName + '_' + surfaceName + ".vtk");
if (verbose)
{
@ -288,45 +246,68 @@ void Foam::vtkSurfaceWriter<Type>::write
writeGeometry(os, points, faces);
switch (sdType)
// start writing data
if (isNodeValues)
{
case surfaceWriterBase::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 ";
}
os << "POINT_DATA "
<< values.size() << nl
else
{
os << "CELL_DATA ";
}
os << values.size() << nl
<< "FIELD attributes 1" << nl
<< fieldName.c_str() << " ";
<< fieldName << " ";
// 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;
}
}
// * * * * * * * * * * * * * * * * 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
Description
A surfaceWriter for VTK legacy format.
SourceFiles
vtkSurfaceWriter.C
@ -45,18 +46,32 @@ namespace Foam
Class vtkSurfaceWriter Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class vtkSurfaceWriter
:
public surfaceWriter<Type>
public surfaceWriter
{
// Private Member Functions
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:
//- Runtime type information
@ -69,15 +84,13 @@ public:
vtkSurfaceWriter();
// Destructor
//- Destructor
virtual ~vtkSurfaceWriter();
// Member Functions
// Write
//- Write geometry to file.
//- Write single surface geometry to file.
virtual void write
(
const fileName& outputDir,
@ -87,18 +100,105 @@ public:
const bool verbose = false
) 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
(
const fileName& outputDir,
const fileName& surfaceName,
const fileName& outputDir, // <case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Type>& values,
const surfaceWriterBase::surfaceData sdType,
const word& fieldName, // name of field
const Field<scalar>& values,
const bool isNodeValues,
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
// ************************************************************************* //