Commit e7b3ede7 authored by mattijs's avatar mattijs
Browse files

multiple line writing; vtk output

parent c58af4fc
......@@ -22,6 +22,7 @@ FoamFile
// jplot
// gnuplot
// raw
// vtk
setFormat raw;
// Surface output format. Choice of
......
......@@ -18,6 +18,7 @@ $(setWriters)/writers.C
$(setWriters)/gnuplot/gnuplotSetWriterRunTime.C
$(setWriters)/jplot/jplotSetWriterRunTime.C
$(setWriters)/raw/rawSetWriterRunTime.C
$(setWriters)/vtk/vtkSetWriterRunTime.C
$(setWriters)/xmgrace/xmgraceSetWriterRunTime.C
cuttingPlane/cuttingPlane.C
......
......@@ -69,29 +69,73 @@ void Foam::gnuplotSetWriter<Type>::write
Ostream& os
) const
{
os << "set term postscript color" << endl
<< "set output \"" << points.name() << ".ps\"" << endl
os << "set term postscript color" << nl
<< "set output \"" << points.name() << ".ps\"" << nl
<< "plot";
bool firstField = true;
forAll(valueSets, i)
{
if (!firstField)
if (i != 0)
{
os << ',';
}
firstField = false;
os << "'-' title \"" << valueSetNames[i] << "\" with lines";
os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
}
os << endl;
os << nl;
forAll(valueSets, i)
{
os << endl;
writeTable(points, *valueSets[i], os);
os << "e" << nl;
}
}
template<class Type>
void Foam::gnuplotSetWriter<Type>::write
(
const bool writeTracks,
const PtrList<coordSet>& trackPoints,
const wordList& valueSetNames,
const List<List<Field<Type> > >& valueSets,
Ostream& os
) const
{
if (valueSets.size() != valueSetNames.size())
{
FatalErrorIn("gnuplotSetWriter<Type>::write(..)")
<< "Number of variables:" << valueSetNames.size() << endl
<< "Number of valueSets:" << valueSets.size()
<< exit(FatalError);
}
if (trackPoints.size() > 0)
{
os << "set term postscript color" << nl
<< "set output \"" << trackPoints[0].name() << ".ps\"" << nl;
forAll(trackPoints, trackI)
{
os << "plot";
forAll(valueSets, i)
{
if (i != 0)
{
os << ',';
}
os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
}
os << nl;
forAll(valueSets, i)
{
writeTable(trackPoints[trackI], valueSets[i][trackI], os);
os << "e" << nl;
}
}
}
}
......
......@@ -76,13 +76,22 @@ public:
const wordList&
) const;
void write
virtual void write
(
const coordSet&,
const wordList&,
const List<const Field<Type>*>&,
Ostream&
) const;
virtual void write
(
const bool writeTracks,
const PtrList<coordSet>&,
const wordList& valueSetNames,
const List<List<Field<Type> > >&,
Ostream&
) const;
};
......
......@@ -39,7 +39,7 @@ Foam::Ostream& Foam::jplotSetWriter<Type>::writeHeader(Ostream& os) const
return os
<< "# JPlot input file" << nl
<< "#" << nl << nl
<< "# Generated by sample on " << clock::date().c_str() << endl;
<< "# Generated by sample on " << clock::date().c_str() << nl;
}
......@@ -82,11 +82,11 @@ void Foam::jplotSetWriter<Type>::write
) const
{
os << "# JPlot file" << nl
<< "# column 1: " << points.name() << endl;
<< "# column 1: " << points.name() << nl;
forAll(valueSets, i)
{
os << "# column " << i + 2 << ": " << valueSetNames[i] << endl;
os << "# column " << i + 2 << ": " << valueSetNames[i] << nl;
}
// Collect sets into columns
......
......@@ -80,13 +80,35 @@ public:
const wordList&
) const;
void write
virtual void write
(
const coordSet&,
const wordList&,
const List<const Field<Type>*>&,
Ostream&
) const;
virtual void write
(
const bool writeTracks,
const PtrList<coordSet>&,
const wordList& valueSetNames,
const List<List<Field<Type> > >&,
Ostream&
) const
{
notImplemented
(
"jplotSetWriter<Type>::write\n"
"(\n"
" const bool,\n"
" const PtrList<coordSet>&,\n"
" const wordList&,\n"
" const List<List<Field<Type> > >&,\n"
" Ostream&\n"
") const"
);
}
};
......
......@@ -79,4 +79,38 @@ void Foam::rawSetWriter<Type>::write
}
template<class Type>
void Foam::rawSetWriter<Type>::write
(
const bool writeTracks,
const PtrList<coordSet>& points,
const wordList& valueSetNames,
const List<List<Field<Type> > >& valueSets,
Ostream& os
) const
{
if (valueSets.size() != valueSetNames.size())
{
FatalErrorIn("rawSetWriter<Type>::write(..)")
<< "Number of variables:" << valueSetNames.size() << endl
<< "Number of valueSets:" << valueSets.size()
<< exit(FatalError);
}
List<const List<Type>*> columns(valueSets.size());
forAll(points, trackI)
{
// Collect sets into columns
forAll(valueSets, i)
{
columns[i] = &valueSets[i][trackI];
}
writeTable(points[trackI], columns, os);
os << nl << nl;
}
}
// ************************************************************************* //
......@@ -83,6 +83,15 @@ public:
const List<const Field<Type>*>&,
Ostream&
) const;
virtual void write
(
const bool writeTracks,
const PtrList<coordSet>&,
const wordList& valueSetNames,
const List<List<Field<Type> > >&,
Ostream&
) const;
};
......
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "vtkSetWriter.H"
#include "coordSet.H"
#include "fileName.H"
#include "OFstream.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Type>
Foam::vtkSetWriter<Type>::vtkSetWriter()
:
writer<Type>()
{}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class Type>
Foam::vtkSetWriter<Type>::~vtkSetWriter()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type>
Foam::fileName Foam::vtkSetWriter<Type>::getFileName
(
const coordSet& points,
const wordList& valueSetNames
) const
{
return this->getBaseName(points, valueSetNames) + ".vtk";
}
template<class Type>
void Foam::vtkSetWriter<Type>::write
(
const coordSet& points,
const wordList& valueSetNames,
const List<const Field<Type>*>& valueSets,
Ostream& os
) const
{
os << "# vtk DataFile Version 2.0" << nl
<< points.name() << nl
<< "ASCII" << nl
<< "DATASET POLYDATA" << nl
<< "POINTS " << points.size() << " float" << nl;
forAll(points, i)
{
const vector& pt = points[i];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
os << "POINT_DATA " << points.size() << nl
<< " FIELD attributes " << valueSetNames.size() << nl;
forAll(valueSetNames, setI)
{
os << valueSetNames[setI] << ' ' << pTraits<Type>::nComponents << ' '
<< points.size() << " float" << nl;
const Field<Type>& fld = *valueSets[setI];
forAll(fld, pointI)
{
if (pointI != 0)
{
os << ' ';
}
writer<Type>::write(fld[pointI], os);
}
os << nl;
}
}
template<class Type>
void Foam::vtkSetWriter<Type>::write
(
const bool writeTracks,
const PtrList<coordSet>& tracks,
const wordList& valueSetNames,
const List<List<Field<Type> > >& valueSets,
Ostream& os
) const
{
if (valueSets.size() != valueSetNames.size())
{
FatalErrorIn("vtkSetWriter<Type>::write(..)")
<< "Number of variables:" << valueSetNames.size() << endl
<< "Number of valueSets:" << valueSets.size()
<< exit(FatalError);
}
label nTracks = tracks.size();
label nPoints = 0;
forAll(tracks, i)
{
nPoints += tracks[i].size();
}
os << "# vtk DataFile Version 2.0" << nl
<< tracks[0].name() << nl
<< "ASCII" << nl
<< "DATASET POLYDATA" << nl
<< "POINTS " << nPoints << " float" << nl;
forAll(tracks, trackI)
{
const coordSet& points = tracks[trackI];
forAll(points, i)
{
const vector& pt = points[i];
os << pt.x() << ' ' << pt.y() << ' ' << pt.z() << nl;
}
}
if (writeTracks)
{
os << "LINES " << nTracks << ' ' << nPoints+nTracks << nl;
// Write ids of track points to file
label globalPtI = 0;
forAll(tracks, trackI)
{
const coordSet& points = tracks[trackI];
os << points.size();
forAll(points, i)
{
os << ' ' << globalPtI;
globalPtI++;
}
os << nl;
}
}
os << "POINT_DATA " << nPoints << nl
<< " FIELD attributes " << valueSetNames.size() << nl;
forAll(valueSetNames, setI)
{
os << valueSetNames[setI] << ' ' << pTraits<Type>::nComponents << ' '
<< nPoints << " float" << nl;
const List<Field<Type> >& fieldVals = valueSets[setI];
forAll(fieldVals, i)
{
const Field<Type>& vals = fieldVals[i];
forAll(vals, j)
{
if (j != 0)
{
os << ' ';
}
writer<Type>::write(vals[j], os);
}
os << nl;
}
}
}
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
Foam::vtkSetWriter
Description
SourceFiles
vtkSetWriter.C
\*---------------------------------------------------------------------------*/
#ifndef vtkSetWriter_H
#define vtkSetWriter_H
#include "writer.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class vtkSetWriter Declaration
\*---------------------------------------------------------------------------*/
template<class Type>
class vtkSetWriter
:
public writer<Type>
{
public:
//- Runtime type information
TypeName("vtk");
// Constructors
//- Construct null
vtkSetWriter();
//- Destructor
virtual ~vtkSetWriter();
// Member Functions
virtual fileName getFileName
(
const coordSet&,
const wordList&
) const;
virtual void write
(
const coordSet&,
const wordList&,
const List<const Field<Type>*>&,
Ostream&
) const;
virtual void write
(
const bool writeTracks,
const PtrList<coordSet>&,
const wordList& valueSetNames,
const List<List<Field<Type> > >&,
Ostream&
) const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "vtkSetWriter.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\*---------------------------------------------------------------------------*/
#include "vtkSetWriter.H"
#include "writers.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makeSetWriters(vtkSetWriter);
}
// ************************************************************************* //
......@@ -110,7 +110,7 @@ void Foam::writer<Type>::writeTable
os << token::SPACE;
write(values[pointI], os);
os << endl;
os << nl;
}
}
......@@ -133,7 +133,7 @@ void Foam::writer<Type>::writeTable
const List<Type>& values = *valuesPtrList[i];
write(values[pointI], os);
}
os << endl;