FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

gnuplotSetWriter.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 \*---------------------------------------------------------------------------*/
00025 
00026 #include "gnuplotSetWriter.H"
00027 #include <OpenFOAM/clock.H>
00028 #include <sampling/coordSet.H>
00029 #include <OpenFOAM/fileName.H>
00030 #include <OpenFOAM/OFstream.H>
00031 #include <OpenFOAM/addToRunTimeSelectionTable.H>
00032 
00033 
00034 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00035 
00036 template<class Type>
00037 Foam::gnuplotSetWriter<Type>::gnuplotSetWriter()
00038 :
00039     writer<Type>()
00040 {}
00041 
00042 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
00043 
00044 template<class Type>
00045 Foam::gnuplotSetWriter<Type>::~gnuplotSetWriter()
00046 {}
00047 
00048 
00049 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00050 
00051 template<class Type>
00052 Foam::fileName Foam::gnuplotSetWriter<Type>::getFileName
00053 (
00054     const coordSet& points,
00055     const wordList& valueSetNames
00056 ) const
00057 {
00058     return this->getBaseName(points, valueSetNames) + ".gplt";
00059 }
00060 
00061 
00062 template<class Type>
00063 void Foam::gnuplotSetWriter<Type>::write
00064 (
00065     const coordSet& points,
00066     const wordList& valueSetNames,
00067     const List<const Field<Type>*>& valueSets,
00068     Ostream& os
00069 ) const
00070 {
00071     os  << "set term postscript color" << nl
00072         << "set output \"" << points.name() << ".ps\"" << nl
00073         << "plot";
00074 
00075     forAll(valueSets, i)
00076     {
00077         if (i != 0)
00078         {
00079             os << ',';
00080         }
00081 
00082         os  << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
00083     }
00084     os  << nl;
00085 
00086 
00087     forAll(valueSets, i)
00088     {
00089         this->writeTable(points, *valueSets[i], os);
00090         os  << "e" << nl;
00091     }
00092 }
00093 
00094 
00095 template<class Type>
00096 void Foam::gnuplotSetWriter<Type>::write
00097 (
00098     const bool writeTracks,
00099     const PtrList<coordSet>& trackPoints,
00100     const wordList& valueSetNames,
00101     const List<List<Field<Type> > >& valueSets,
00102     Ostream& os
00103 ) const
00104 {
00105     if (valueSets.size() != valueSetNames.size())
00106     {
00107         FatalErrorIn("gnuplotSetWriter<Type>::write(..)")
00108             << "Number of variables:" << valueSetNames.size() << endl
00109             << "Number of valueSets:" << valueSets.size()
00110             << exit(FatalError);
00111     }
00112     if (trackPoints.size() > 0)
00113     {
00114         os  << "set term postscript color" << nl
00115             << "set output \"" << trackPoints[0].name() << ".ps\"" << nl;
00116 
00117         forAll(trackPoints, trackI)
00118         {
00119             os  << "plot";
00120 
00121             forAll(valueSets, i)
00122             {
00123                 if (i != 0)
00124                 {
00125                     os << ',';
00126                 }
00127 
00128                 os  << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
00129             }
00130             os << nl;
00131 
00132             forAll(valueSets, i)
00133             {
00134                 this->writeTable
00135                 (
00136                     trackPoints[trackI],
00137                     valueSets[i][trackI],
00138                     os
00139                 );
00140                 os  << "e" << nl;
00141             }
00142         }
00143     }
00144 }
00145 
00146 
00147 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines