Commit 34da7318 authored by Mark Olesen's avatar Mark Olesen
Browse files

sampledSurface hacking proof-of-concept

- using 'nil' type to write geometry only, in the future we could fallback to 'null'
  writer and hook in arbitrary formats from surfMesh

- IOobject gets writeEndDivider() static method
parent ce3d79de
......@@ -359,6 +359,10 @@ public:
template<class Stream>
static inline Stream& writeDivider(Stream& os);
//- Write the standard end file divider
template<class Stream>
static inline Stream& writeEndDivider(Stream& os);
//- Write header
bool writeHeader(Ostream&) const;
......
......@@ -82,5 +82,14 @@ inline Stream& Foam::IOobject::writeDivider(Stream& os)
return os;
}
template<class Stream>
inline Stream& Foam::IOobject::writeEndDivider(Stream& os)
{
os << "\n\n"
"// ************************************************************************* //\n";
return os;
}
// ************************************************************************* //
......@@ -103,9 +103,7 @@ bool Foam::regIOobject::writeObject
return false;
}
os << "\n\n"
"// ************************************************************************* //"
<< endl;
writeEndDivider(os);
osGood = os.good();
}
......
......@@ -97,10 +97,8 @@ void Foam::meshReader::writeInterfaces(const objectRegistry& registry) const
OFstream os(ioObj.objectPath());
ioObj.writeHeader(os);
os << interfaces_
<< "// *************************************"
<< "************************************ //"
<< endl;
os << interfaces_;
io.writeEndDivider(os);
}
......
......@@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "dxSurfaceWriter.H"
#include "fileName.H"
#include "OFstream.H"
#include "faceList.H"
......@@ -33,12 +34,12 @@ License
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeDXGeometry
void Foam::dxSurfaceWriter<Type>::writeGeometry
(
Ostream& os,
const pointField& points,
const faceList& faces,
Ostream& os
) const
const faceList& faces
)
{
// Write vertex coordinates
......@@ -69,7 +70,7 @@ void Foam::dxSurfaceWriter<Type>::writeDXGeometry
{
FatalErrorIn
(
"writeDXGeometry(Ostream&, const pointField&, const faceList&)"
"writeGeometry(Ostream&, const pointField&, const faceList&)"
) << "Face " << faceI << " vertices " << f
<< " is not a triangle."
<< exit(FatalError);
......@@ -82,181 +83,137 @@ void Foam::dxSurfaceWriter<Type>::writeDXGeometry
}
// Write scalarField in DX format
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeDXData
(
const pointField& points,
const scalarField& values,
Ostream& os
) const
namespace Foam
{
// Write data
os << "object 3 class array type float rank 0 items "
<< values.size()
<< " data follows" << nl;
forAll(values, elemI)
// Write scalarField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::scalar>::writeData
(
Ostream& os,
const Field<scalar>& values
)
{
os << float(values[elemI]) << nl;
}
// Write data
os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl;
if (values.size() == points.size())
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
}
else
{
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
forAll(values, elemI)
{
os << float(values[elemI]) << nl;
}
}
}
// Write vectorField in DX format
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeDXData
(
const pointField& points,
const vectorField& values,
Ostream& os
) const
{
// Write data
os << "object 3 class array type float rank 1 shape 3 items "
<< values.size()
<< " data follows" << nl;
forAll(values, elemI)
// Write vectorField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::vector>::writeData
(
Ostream& os,
const Field<vector>& values
)
{
os << float(values[elemI].x()) << ' '
<< float(values[elemI].y()) << ' '
<< float(values[elemI].z()) << nl;
}
// Write data
os << "object 3 class array type float rank 1 shape 3 items "
<< values.size() << " data follows" << nl;
if (values.size() == points.size())
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
}
else
{
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
forAll(values, elemI)
{
os << float(values[elemI].x()) << ' '
<< float(values[elemI].y()) << ' '
<< float(values[elemI].z()) << nl;
}
}
}
// Write sphericalTensorField in DX format
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeDXData
(
const pointField& points,
const sphericalTensorField& values,
Ostream& os
) const
{
// Write data
os << "object 3 class array type float rank 0 items "
<< values.size()
<< " data follows" << nl;
forAll(values, elemI)
// Write sphericalTensorField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::sphericalTensor>::writeData
(
Ostream& os,
const Field<sphericalTensor>& values
)
{
os << float(values[elemI][0]) << nl;
}
// Write data
os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl;
if (values.size() == points.size())
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
}
else
{
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
forAll(values, elemI)
{
os << float(values[elemI][0]) << nl;
}
}
}
// Write symmTensorField in DX format
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeDXData
(
const pointField& points,
const symmTensorField& values,
Ostream& os
) const
{
// Write data
os << "object 3 class array type float rank 2 shape 3 items "
<< values.size()
<< " data follows" << nl;
forAll(values, elemI)
// Write symmTensorField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::symmTensor>::writeData
(
Ostream& os,
const Field<symmTensor>& values
)
{
const symmTensor& t = values[elemI];
// Write data
os << "object 3 class array type float rank 2 shape 3 items "
<< values.size() << " data follows" << nl;
os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
<< float(t.xy()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
<< float(t.xz()) << ' ' << float(t.yz()) << ' ' << float(t.zz())
<< nl;
}
forAll(values, elemI)
{
const symmTensor& t = values[elemI];
if (values.size() == points.size())
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
<< float(t.xy()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
<< float(t.xz()) << ' ' << float(t.yz()) << ' ' << float(t.zz())
<< nl;
}
}
else
// Write tensorField in DX format
template<>
void Foam::dxSurfaceWriter<Foam::tensor>::writeData
(
Ostream& os,
const Field<tensor>& values
)
{
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
// Write data
os << "object 3 class array type float rank 2 shape 3 items "
<< values.size() << " data follows" << nl;
forAll(values, elemI)
{
const tensor& t = values[elemI];
os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
<< float(t.yx()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
<< float(t.zx()) << ' ' << float(t.zy()) << ' ' << float(t.zz())
<< nl;
}
}
}
// Write tensorField in DX format
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeDXData
void Foam::dxSurfaceWriter<Type>::writeData
(
const pointField& points,
const tensorField& values,
Ostream& os
) const
Ostream& os,
const Field<Type>& values
)
{
// Write data
os << "object 3 class array type float rank 2 shape 3 items "
<< values.size()
<< " data follows" << nl;
os << "object 3 class array type float rank 0 items "
<< values.size() << " data follows" << nl;
forAll(values, elemI)
{
const tensor& t = values[elemI];
os << float(t.xx()) << ' ' << float(t.xy()) << ' ' << float(t.xz())
<< float(t.yx()) << ' ' << float(t.yy()) << ' ' << float(t.yz())
<< float(t.zx()) << ' ' << float(t.zy()) << ' ' << float(t.zz())
<< nl;
}
if (values.size() == points.size())
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
}
else
{
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
os << float(0.0) << nl;
}
}
// Write trailer in DX format
template<class Type>
void Foam::dxSurfaceWriter<Type>::writeDXTrailer(Ostream& os) const
void Foam::dxSurfaceWriter<Type>::writeTrailer(Ostream& os)
{
os << "# the field, with three components: \"positions\","
<< " \"connections\", and \"data\"" << nl
......@@ -316,11 +273,22 @@ void Foam::dxSurfaceWriter<Type>::write
OFstream os(fName);
writeDXGeometry(points, faces, os);
writeGeometry(os, points, faces);
writeDXData(points, values, os);
writeData(os, values);
if (values.size() == points.size())
{
os << nl << "attribute \"dep\" string \"positions\""
<< nl << nl;
}
else
{
os << nl << "attribute \"dep\" string \"connections\""
<< nl << nl;
}
writeDXTrailer(os);
writeTrailer(os);
os << "end" << nl;
}
......
......@@ -54,49 +54,11 @@ class dxSurfaceWriter
// Private Member Functions
void writeDXGeometry
(
const pointField& points,
const faceList& faces,
Ostream& os
) const;
void writeDXData
(
const pointField& points,
const scalarField& values,
Ostream& os
) const;
void writeDXData
(
const pointField& points,
const vectorField& values,
Ostream& os
) const;
static void writeGeometry(Ostream&, const pointField&, const faceList&);
void writeDXData
(
const pointField& points,
const sphericalTensorField& values,
Ostream& os
) const;
void writeDXData
(
const pointField& points,
const symmTensorField& values,
Ostream& os
) const;
void writeDXData
(
const pointField& points,
const tensorField& values,
Ostream& os
) const;
static void writeData(Ostream&, const Field<Type>& values);
void writeDXTrailer(Ostream& os) const;
static void writeTrailer(Ostream&);
public:
......
......@@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "foamFileSurfaceWriter.H"
#include "fileName.H"
#include "OFstream.H"
#include "faceList.H"
......@@ -48,6 +49,43 @@ Foam::foamFileSurfaceWriter<Type>::~foamFileSurfaceWriter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::foamFileSurfaceWriter<Foam::nil>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Foam::nil>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir/surfaceName);
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
if (verbose)
{
Info<< "Writing nil to " << surfaceDir << endl;
}
// Points
OFstream(surfaceDir/"points")() << points;
// Faces
OFstream(surfaceDir/"faces")() << faces;
}
}
template<class Type>
void Foam::foamFileSurfaceWriter<Type>::write
(
......
......@@ -35,6 +35,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(foamFileSurfaceWriter, nil);
makeSurfaceWriters(foamFileSurfaceWriter);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -35,6 +35,7 @@ namespace Foam
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
makeSurfaceWriterType(nullSurfaceWriter, nil);
makeSurfaceWriters(nullSurfaceWriter);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -25,6 +25,7 @@ License
\*---------------------------------------------------------------------------*/
#include "objSurfaceWriter.H"
#include "fileName.H"
#include "OFstream.H"
#include "faceList.H"
......@@ -48,6 +49,80 @@ Foam::objSurfaceWriter<Type>::~objSurfaceWriter()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
namespace Foam
{
template<>
void Foam::objSurfaceWriter<Foam::nil>::write
(
const fileName& samplePath,
const fileName& timeDir,
const fileName& surfaceName,
const pointField& points,
const faceList& faces,
const fileName& fieldName,
const Field<Foam::nil>& values,
const bool verbose
) const
{
fileName surfaceDir(samplePath/timeDir);
if (!isDir(surfaceDir))
{
mkDir(surfaceDir);
}
fileName fName(surfaceDir/surfaceName + ".obj");
if (verbose)
{
Info<< "Writing nil to " << fName << endl;
}
// this is a quick hack
OFstream os(fName);
os << "# Wavefront OBJ file" << nl
<< "o " << os.name().lessExt().name() << nl
<< nl
<< "# points : " << points.size() << nl
<< "# faces : " << faces.size() << nl
<< "# no zones " << nl;
os << nl
<< "# <points count=\"" << points.size() << "\">" << endl;
// Write vertex coords
forAll(points, ptI)
{
os << "v " << points[ptI].x()
<< ' ' << points[ptI].y()
<< ' ' << points[ptI].z() << nl;
}
os << "# </points>" << nl
<< nl
<< "# <faces count=\"" << faces.size() << "\">" << endl;
forAll(faces, i)
{
const face& f = faces[i];
os << 'f';
forAll(f, fp)
{
os << ' ' << f[fp] + 1;
}
os << nl;
}
os << "# </faces>" << endl;
}
}
template<class Type>
void Foam::objSurfaceWriter<Type>::write