FreeFOAM The Cross-Platform CFD Toolkit
gnuplotSetWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "gnuplotSetWriter.H"
27 #include <OpenFOAM/clock.H>
28 #include <sampling/coordSet.H>
29 #include <OpenFOAM/fileName.H>
30 #include <OpenFOAM/OFstream.H>
32 
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 template<class Type>
38 :
39  writer<Type>()
40 {}
41 
42 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
43 
44 template<class Type>
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
50 
51 template<class Type>
53 (
54  const coordSet& points,
55  const wordList& valueSetNames
56 ) const
57 {
58  return this->getBaseName(points, valueSetNames) + ".gplt";
59 }
60 
61 
62 template<class Type>
64 (
65  const coordSet& points,
66  const wordList& valueSetNames,
67  const List<const Field<Type>*>& valueSets,
68  Ostream& os
69 ) const
70 {
71  os << "set term postscript color" << nl
72  << "set output \"" << points.name() << ".ps\"" << nl
73  << "plot";
74 
75  forAll(valueSets, i)
76  {
77  if (i != 0)
78  {
79  os << ',';
80  }
81 
82  os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
83  }
84  os << nl;
85 
86 
87  forAll(valueSets, i)
88  {
89  writeTable(points, *valueSets[i], os);
90  os << "e" << nl;
91  }
92 }
93 
94 
95 template<class Type>
97 (
98  const bool writeTracks,
99  const PtrList<coordSet>& trackPoints,
100  const wordList& valueSetNames,
101  const List<List<Field<Type> > >& valueSets,
102  Ostream& os
103 ) const
104 {
105  if (valueSets.size() != valueSetNames.size())
106  {
107  FatalErrorIn("gnuplotSetWriter<Type>::write(..)")
108  << "Number of variables:" << valueSetNames.size() << endl
109  << "Number of valueSets:" << valueSets.size()
110  << exit(FatalError);
111  }
112  if (trackPoints.size() > 0)
113  {
114  os << "set term postscript color" << nl
115  << "set output \"" << trackPoints[0].name() << ".ps\"" << nl;
116 
117  forAll(trackPoints, trackI)
118  {
119  os << "plot";
120 
121  forAll(valueSets, i)
122  {
123  if (i != 0)
124  {
125  os << ',';
126  }
127 
128  os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
129  }
130  os << nl;
131 
132  forAll(valueSets, i)
133  {
134  writeTable(trackPoints[trackI], valueSets[i][trackI], os);
135  os << "e" << nl;
136  }
137  }
138  }
139 }
140 
141 
142 // ************************ vim: set sw=4 sts=4 et: ************************ //