diff --git a/applications/utilities/postProcessing/sampling/sample/sampleDict b/applications/utilities/postProcessing/sampling/sample/sampleDict index f3659e728a..4571c924df 100644 --- a/applications/utilities/postProcessing/sampling/sample/sampleDict +++ b/applications/utilities/postProcessing/sampling/sample/sampleDict @@ -22,6 +22,7 @@ FoamFile // jplot // gnuplot // raw +// vtk setFormat raw; // Surface output format. Choice of diff --git a/src/sampling/Make/files b/src/sampling/Make/files index 57306e542b..a6d16a0f1e 100644 --- a/src/sampling/Make/files +++ b/src/sampling/Make/files @@ -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 diff --git a/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.C b/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.C index 9905d54411..9f34a59197 100644 --- a/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.C +++ b/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.C @@ -69,29 +69,73 @@ void Foam::gnuplotSetWriter::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 +void Foam::gnuplotSetWriter::write +( + const bool writeTracks, + const PtrList& trackPoints, + const wordList& valueSetNames, + const List > >& valueSets, + Ostream& os +) const +{ + if (valueSets.size() != valueSetNames.size()) + { + FatalErrorIn("gnuplotSetWriter::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; + } + } } } diff --git a/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.H b/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.H index 1096f64519..6d575b8aa2 100644 --- a/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.H +++ b/src/sampling/sampledSet/writers/gnuplot/gnuplotSetWriter.H @@ -76,13 +76,22 @@ public: const wordList& ) const; - void write + virtual void write ( const coordSet&, const wordList&, const List*>&, Ostream& ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList&, + const wordList& valueSetNames, + const List > >&, + Ostream& + ) const; }; diff --git a/src/sampling/sampledSet/writers/jplot/jplotSetWriter.C b/src/sampling/sampledSet/writers/jplot/jplotSetWriter.C index 53b0d5e08b..560f626c1e 100644 --- a/src/sampling/sampledSet/writers/jplot/jplotSetWriter.C +++ b/src/sampling/sampledSet/writers/jplot/jplotSetWriter.C @@ -39,7 +39,7 @@ Foam::Ostream& Foam::jplotSetWriter::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::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 diff --git a/src/sampling/sampledSet/writers/jplot/jplotSetWriter.H b/src/sampling/sampledSet/writers/jplot/jplotSetWriter.H index 940dec2abe..d9f6f1bf76 100644 --- a/src/sampling/sampledSet/writers/jplot/jplotSetWriter.H +++ b/src/sampling/sampledSet/writers/jplot/jplotSetWriter.H @@ -80,13 +80,35 @@ public: const wordList& ) const; - void write + virtual void write ( const coordSet&, const wordList&, const List*>&, Ostream& ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList&, + const wordList& valueSetNames, + const List > >&, + Ostream& + ) const + { + notImplemented + ( + "jplotSetWriter::write\n" + "(\n" + " const bool,\n" + " const PtrList&,\n" + " const wordList&,\n" + " const List > >&,\n" + " Ostream&\n" + ") const" + ); + } }; diff --git a/src/sampling/sampledSet/writers/raw/rawSetWriter.C b/src/sampling/sampledSet/writers/raw/rawSetWriter.C index a3b42d6da0..1934071aec 100644 --- a/src/sampling/sampledSet/writers/raw/rawSetWriter.C +++ b/src/sampling/sampledSet/writers/raw/rawSetWriter.C @@ -79,4 +79,38 @@ void Foam::rawSetWriter::write } +template +void Foam::rawSetWriter::write +( + const bool writeTracks, + const PtrList& points, + const wordList& valueSetNames, + const List > >& valueSets, + Ostream& os +) const +{ + if (valueSets.size() != valueSetNames.size()) + { + FatalErrorIn("rawSetWriter::write(..)") + << "Number of variables:" << valueSetNames.size() << endl + << "Number of valueSets:" << valueSets.size() + << exit(FatalError); + } + + List*> 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; + } +} + + // ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/raw/rawSetWriter.H b/src/sampling/sampledSet/writers/raw/rawSetWriter.H index 346813d941..b2852b5a0d 100644 --- a/src/sampling/sampledSet/writers/raw/rawSetWriter.H +++ b/src/sampling/sampledSet/writers/raw/rawSetWriter.H @@ -83,6 +83,15 @@ public: const List*>&, Ostream& ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList&, + const wordList& valueSetNames, + const List > >&, + Ostream& + ) const; }; diff --git a/src/sampling/sampledSet/writers/vtk/vtkSetWriter.C b/src/sampling/sampledSet/writers/vtk/vtkSetWriter.C new file mode 100644 index 0000000000..f8172ea5b3 --- /dev/null +++ b/src/sampling/sampledSet/writers/vtk/vtkSetWriter.C @@ -0,0 +1,196 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 +Foam::vtkSetWriter::vtkSetWriter() +: + writer() +{} + +// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * // + +template +Foam::vtkSetWriter::~vtkSetWriter() +{} + + +// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // + +template +Foam::fileName Foam::vtkSetWriter::getFileName +( + const coordSet& points, + const wordList& valueSetNames +) const +{ + return this->getBaseName(points, valueSetNames) + ".vtk"; +} + + +template +void Foam::vtkSetWriter::write +( + const coordSet& points, + const wordList& valueSetNames, + const List*>& 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::nComponents << ' ' + << points.size() << " float" << nl; + + const Field& fld = *valueSets[setI]; + + forAll(fld, pointI) + { + if (pointI != 0) + { + os << ' '; + } + writer::write(fld[pointI], os); + } + os << nl; + } +} + + +template +void Foam::vtkSetWriter::write +( + const bool writeTracks, + const PtrList& tracks, + const wordList& valueSetNames, + const List > >& valueSets, + Ostream& os +) const +{ + if (valueSets.size() != valueSetNames.size()) + { + FatalErrorIn("vtkSetWriter::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::nComponents << ' ' + << nPoints << " float" << nl; + + const List >& fieldVals = valueSets[setI]; + + forAll(fieldVals, i) + { + const Field& vals = fieldVals[i]; + + forAll(vals, j) + { + if (j != 0) + { + os << ' '; + } + writer::write(vals[j], os); + } + os << nl; + } + } +} + + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/vtk/vtkSetWriter.H b/src/sampling/sampledSet/writers/vtk/vtkSetWriter.H new file mode 100644 index 0000000000..59401c1e03 --- /dev/null +++ b/src/sampling/sampledSet/writers/vtk/vtkSetWriter.H @@ -0,0 +1,112 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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 vtkSetWriter +: + public writer +{ + +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*>&, + Ostream& + ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList&, + const wordList& valueSetNames, + const List > >&, + Ostream& + ) const; +}; + + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +} // End namespace Foam + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#ifdef NoRepository +# include "vtkSetWriter.C" +#endif + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +#endif + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/vtk/vtkSetWriterRunTime.C b/src/sampling/sampledSet/writers/vtk/vtkSetWriterRunTime.C new file mode 100644 index 0000000000..bb180036f8 --- /dev/null +++ b/src/sampling/sampledSet/writers/vtk/vtkSetWriterRunTime.C @@ -0,0 +1,38 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / 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); +} + +// ************************************************************************* // diff --git a/src/sampling/sampledSet/writers/writer.C b/src/sampling/sampledSet/writers/writer.C index b16966d3a1..cde178041d 100644 --- a/src/sampling/sampledSet/writers/writer.C +++ b/src/sampling/sampledSet/writers/writer.C @@ -110,7 +110,7 @@ void Foam::writer::writeTable os << token::SPACE; write(values[pointI], os); - os << endl; + os << nl; } } @@ -133,7 +133,7 @@ void Foam::writer::writeTable const List& values = *valuesPtrList[i]; write(values[pointI], os); } - os << endl; + os << nl; } } @@ -179,7 +179,7 @@ Foam::Ostream& Foam::writer::writeVS if (d <= VSType::nComponents-1) { - os << token::TAB; + os << ' ' << token::TAB; } } return os; diff --git a/src/sampling/sampledSet/writers/writer.H b/src/sampling/sampledSet/writers/writer.H index e450d07c32..52cf03482a 100644 --- a/src/sampling/sampledSet/writers/writer.H +++ b/src/sampling/sampledSet/writers/writer.H @@ -162,6 +162,19 @@ public: Ostream& ) const = 0; + //- General entry point for writing of multiple coordSets. + // Each coordSet (track) has same data variables. + // The data is per variable, per track, per point of track. + // If writeTracks adds connecting lines (wherever applicable) + virtual void write + ( + const bool writeTracks, + const PtrList&, + const wordList& valueSetNames, + const List > >&, + Ostream& + ) const = 0; + //- Write scalar as ascii virtual Ostream& write(const scalar, Ostream&) const; diff --git a/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.C b/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.C index b1da1cb651..1ddeda9c3f 100644 --- a/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.C +++ b/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.C @@ -68,19 +68,64 @@ void Foam::xmgraceSetWriter::write Ostream& os ) const { - os << "@title \"" << points.name() << '"' << endl - << "@xaxis label " << '"' << points.axis() << '"' << endl; + os << "@g0 on" << nl + << "@with g0" << nl + << "@ title \"" << points.name() << '"' << nl + << "@ xaxis label " << '"' << points.axis() << '"' << nl; forAll(valueSets, i) { - os << "@s" << i << " legend " << '"' - << valueSetNames[i] << '"' << endl - << "@target G0.S" << i << endl - << "@type xy" << endl; + os << "@ s" << i << " legend " << '"' + << valueSetNames[i] << '"' << nl + << "@target G0.S" << i << nl; writeTable(points, *valueSets[i], os); - os << endl; + os << '&' << nl; + } +} + + +template +void Foam::xmgraceSetWriter::write +( + const bool writeTracks, + const PtrList& trackPoints, + const wordList& valueSetNames, + const List > >& valueSets, + Ostream& os +) const +{ + if (valueSets.size() != valueSetNames.size()) + { + FatalErrorIn("gnuplotSetWriter::write(..)") + << "Number of variables:" << valueSetNames.size() << endl + << "Number of valueSets:" << valueSets.size() + << exit(FatalError); + } + if (trackPoints.size() > 0) + { + os << "@g0 on" << nl + << "@with g0" << nl + << "@ title \"" << trackPoints[0].name() << '"' << nl + << "@ xaxis label " << '"' << trackPoints[0].axis() << '"' << nl; + + // Data index. + label sI = 0; + + forAll(trackPoints, trackI) + { + forAll(valueSets, i) + { + os << "@ s" << sI << " legend " << '"' + << valueSetNames[i] << "_track" << i << '"' << nl + << "@target G0.S" << sI << nl; + writeTable(trackPoints[trackI], valueSets[i][trackI], os); + os << '&' << nl; + + sI++; + } + } } } diff --git a/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.H b/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.H index b5abab73b5..e959121d99 100644 --- a/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.H +++ b/src/sampling/sampledSet/writers/xmgrace/xmgraceSetWriter.H @@ -76,13 +76,22 @@ public: const wordList& ) const; - void write + virtual void write ( const coordSet&, const wordList&, const List*>&, Ostream& ) const; + + virtual void write + ( + const bool writeTracks, + const PtrList&, + const wordList& valueSetNames, + const List > >&, + Ostream& + ) const; };