Commit 51df389d authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: rework surface writers as non-templated classes

- easier (more logical) when adding a new writer

ENH: add surface field  writer for 'starcd' format

- creates *.usr files, which can be read in proSTAR with the 'getuser'
  command, but which can also be parsed directly since the format is
  extremely primitive
parent 232c13ee
......@@ -46,14 +46,14 @@ sampledSurface/thresholdCellFaces/sampledThresholdCellFaces.C
surfWriters = sampledSurface/writers
$(surfWriters)/surfaceWriters.C
$(surfWriters)/dx/dxSurfaceWriterRunTime.C
$(surfWriters)/ensight/ensightSurfaceWriterRunTime.C
$(surfWriters)/foamFile/foamFileSurfaceWriterRunTime.C
$(surfWriters)/null/nullSurfaceWriterRunTime.C
$(surfWriters)/proxy/proxySurfaceWriterRunTime.C
$(surfWriters)/raw/rawSurfaceWriterRunTime.C
$(surfWriters)/vtk/vtkSurfaceWriterRunTime.C
$(surfWriters)/surfaceWriter.C
$(surfWriters)/dx/dxSurfaceWriter.C
$(surfWriters)/ensight/ensightSurfaceWriter.C
$(surfWriters)/foamFile/foamFileSurfaceWriter.C
$(surfWriters)/proxy/proxySurfaceWriter.C
$(surfWriters)/raw/rawSurfaceWriter.C
$(surfWriters)/starcd/starcdSurfaceWriter.C
$(surfWriters)/vtk/vtkSurfaceWriter.C
graphField/writePatchGraph.C
graphField/writeCellGraph.C
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -83,7 +83,7 @@ void Foam::sampledSurfaces::writeGeometry() const
{
if (Pstream::master() && mergeList_[surfI].faces.size())
{
genericFormatter_->write
formatter_->write
(
outputDir,
s.name(),
......@@ -94,7 +94,7 @@ void Foam::sampledSurfaces::writeGeometry() const
}
else if (s.faces().size())
{
genericFormatter_->write
formatter_->write
(
outputDir,
s.name(),
......@@ -123,9 +123,8 @@ Foam::sampledSurfaces::sampledSurfaces
outputPath_(fileName::null),
fieldSelection_(),
interpolationScheme_(word::null),
writeFormat_(word::null),
mergeList_(),
genericFormatter_(NULL),
formatter_(NULL),
scalarFields_(),
vectorFields_(),
sphericalTensorFields_(),
......@@ -201,7 +200,7 @@ void Foam::sampledSurfaces::write()
// write geometry first if required,
// or when no fields would otherwise be written
if (nFields == 0 || genericFormatter_->separateFiles())
if (nFields == 0 || formatter_->separateGeometry())
{
writeGeometry();
}
......@@ -221,11 +220,11 @@ void Foam::sampledSurfaces::read(const dictionary& dict)
clearFieldGroups();
dict.lookup("interpolationScheme") >> interpolationScheme_;
dict.lookup("surfaceFormat") >> writeFormat_;
// define the generic (geometry) writer
genericFormatter_ = surfaceWriter<bool>::New(writeFormat_);
word writeFormat(dict.lookup("surfaceFormat"));
// define the surface formatter
formatter_ = surfaceWriter::New(writeFormat);
PtrList<sampledSurface> newList
(
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -68,36 +68,11 @@ class sampledSurfaces
{
public:
//- The surface formatter
autoPtr< surfaceWriter<Type> > formatter;
//- Construct null
fieldGroup()
:
DynamicList<word>(0),
formatter(NULL)
DynamicList<word>(0)
{}
//- Construct for a particular surface format
fieldGroup(const word& writeFormat)
:
DynamicList<word>(0),
formatter(surfaceWriter<Type>::New(writeFormat))
{}
//- Reset format and field list
void clear()
{
DynamicList<word>::clear();
formatter.clear();
}
//- Assign a new formatter
void operator=(const word& writeFormat)
{
formatter = surfaceWriter<Type>::New(writeFormat);
}
};
......@@ -151,10 +126,6 @@ class sampledSurfaces
//- Interpolation scheme to use
word interpolationScheme_;
//- Output format to use
word writeFormat_;
// surfaces
//- Information for merging surfaces
......@@ -163,8 +134,8 @@ class sampledSurfaces
// Calculated
//- Generic surface formatter
autoPtr< surfaceWriter<bool> > genericFormatter_;
//- Surface formatter
autoPtr<surfaceWriter> formatter_;
//- Categorized scalar/vector/tensor fields
fieldGroup<scalar> scalarFields_;
......@@ -190,14 +161,10 @@ class sampledSurfaces
//- Sample and write a particular volume field
template<class Type>
void sampleAndWrite
(
const GeometricField<Type, fvPatchField, volMesh>&,
const surfaceWriter<Type>& formatter
);
void sampleAndWrite(const GeometricField<Type, fvPatchField, volMesh>&);
//- Sample and write all the fields of the given type
template <class Type>
template<class Type>
void sampleAndWrite(fieldGroup<Type>&);
//- Disallow default bitwise copy construct and assignment
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -32,8 +32,7 @@ License
template<class Type>
void Foam::sampledSurfaces::sampleAndWrite
(
const GeometricField<Type, fvPatchField, volMesh>& vField,
const surfaceWriter<Type>& formatter
const GeometricField<Type, fvPatchField, volMesh>& vField
)
{
// interpolator for this field
......@@ -96,7 +95,7 @@ void Foam::sampledSurfaces::sampleAndWrite
// skip surface without faces (eg, a failed cut-plane)
if (mergeList_[surfI].faces.size())
{
formatter.write
formatter_->write
(
outputDir,
s.name(),
......@@ -115,7 +114,7 @@ void Foam::sampledSurfaces::sampleAndWrite
// skip surface without faces (eg, a failed cut-plane)
if (s.faces().size())
{
formatter.write
formatter_->write
(
outputDir,
s.name(),
......@@ -139,12 +138,6 @@ void Foam::sampledSurfaces::sampleAndWrite
{
if (fields.size())
{
// create or use existing surfaceWriter
if (fields.formatter.empty())
{
fields.formatter = surfaceWriter<Type>::New(writeFormat_);
}
forAll(fields, fieldI)
{
if (Pstream::master() && verbose_)
......@@ -168,8 +161,7 @@ void Foam::sampledSurfaces::sampleAndWrite
false
),
mesh_
),
fields.formatter()
)
);
}
else
......@@ -190,8 +182,7 @@ void Foam::sampledSurfaces::sampleAndWrite
<GeometricField<Type, fvPatchField, volMesh> >
(
fields[fieldI]
),
fields.formatter()
)
);
}
}
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -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,41 +233,8 @@ 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,
......@@ -270,24 +262,29 @@ void Foam::dxSurfaceWriter<Type>::write
}
writeGeometry(os, points, faces);
writeData(os, values);
writeTrailer(os, isNodeValues);
}
if (isNodeValues)
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
}
else
{
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
}
writeTrailer(os);
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
os << "end" << nl;
}
Foam::dxSurfaceWriter::dxSurfaceWriter()
:
surfaceWriter()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::dxSurfaceWriter::~dxSurfaceWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
// create write methods
defineSurfaceWriterWriteFields(Foam::dxSurfaceWriter);
// ************************************************************************* //
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2004-2010 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2004-2011 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -25,6 +25,7 @@ Class
Foam::dxSurfaceWriter
Description
A surfaceWriter for OpenDX format.
SourceFiles
dxSurfaceWriter.C
......@@ -42,22 +43,36 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class dxSurfaceWriter Declaration
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:
......@@ -77,32 +92,82 @@ public:
// Member Functions
// Write
//- 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& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName, // name of field
const Field<scalar>& values,
const bool isNodeValues,
const bool verbose = false
) const;
//- Writes single surface to file.
//- Write vectorField 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, // <root>/<case>/surface/TIME
const fileName& surfaceName, // name of surface
const pointField& points,
const faceList& faces,
const word& fieldName,
const Field<Type>& values,
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, // <root>/<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, // <root>/<case>/surface/TIME