gnuplotSetWriter.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 "coordSet.H"
28 #include "fileName.H"
29 #include "OFstream.H"
31 
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 :
38  writer<Type>()
39 {}
40 
41 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
42 
43 template<class Type>
45 {}
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
50 template<class Type>
52 (
53  const coordSet& points,
54  const wordList& valueSetNames
55 ) const
56 {
57  return this->getBaseName(points, valueSetNames) + ".gplt";
58 }
59 
60 
61 template<class Type>
63 (
64  const coordSet& points,
65  const wordList& valueSetNames,
66  const List<const Field<Type>*>& valueSets,
67  Ostream& os
68 ) const
69 {
70  os << "set term postscript color" << nl
71  << "set output \"" << points.name() << ".ps\"" << nl
72  << "plot";
73 
74  forAll(valueSets, i)
75  {
76  if (i != 0)
77  {
78  os << ',';
79  }
80 
81  os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
82  }
83  os << nl;
84 
85 
86  forAll(valueSets, i)
87  {
88  this->writeTable(points, *valueSets[i], os);
89  os << "e" << nl;
90  }
91 }
92 
93 
94 template<class Type>
96 (
97  const bool writeTracks,
98  const PtrList<coordSet>& trackPoints,
99  const wordList& valueSetNames,
100  const List<List<Field<Type>>>& valueSets,
101  Ostream& os
102 ) const
103 {
104  if (valueSets.size() != valueSetNames.size())
105  {
107  << "Number of variables:" << valueSetNames.size() << endl
108  << "Number of valueSets:" << valueSets.size()
109  << exit(FatalError);
110  }
111  if (trackPoints.size() > 0)
112  {
113  os << "set term postscript color" << nl
114  << "set output \"" << trackPoints[0].name() << ".ps\"" << nl;
115 
116  forAll(trackPoints, trackI)
117  {
118  os << "plot";
119 
120  forAll(valueSets, i)
121  {
122  if (i != 0)
123  {
124  os << ',';
125  }
126 
127  os << " \"-\" title \"" << valueSetNames[i] << "\" with lines";
128  }
129  os << nl;
130 
131  forAll(valueSets, i)
132  {
133  this->writeTable(trackPoints[trackI], valueSets[i][trackI], os);
134  os << "e" << nl;
135  }
136  }
137  }
138 }
139 
140 
141 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:428
fileName getBaseName(const coordSet &, const wordList &) const
Generates filename from coordSet and sampled fields.
Definition: writer.C:60
A class for handling file names.
Definition: fileName.H:69
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > *> &, Ostream &) const
General entry point for writing.
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:163
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:256
Base class for graphics format writing. Entry points are.
Definition: writer.H:78
Macros for easy insertion into run-time selection tables.
Holds list of sampling positions.
Definition: coordSet.H:49
virtual ~gnuplotSetWriter()
Destructor.
Pre-declare SubField and related Field type.
Definition: Field.H:57
void writeTable(const coordSet &, const List< Type > &, Ostream &) const
Writes single-column ascii write. Column 1 is coordSet coordinate,.
Definition: writer.C:97
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:53
static const char nl
Definition: Ostream.H:265
const word & name() const
Definition: coordSet.H:111
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:63
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
gnuplotSetWriter()
Construct null.