xmgraceSetWriter.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "xmgraceSetWriter.H"
29 #include "coordSet.H"
30 #include "fileName.H"
31 #include "OFstream.H"
32 
33 
34 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35 
36 template<class Type>
38 :
39  writer<Type>()
40 {}
41 
42 
43 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
44 
45 template<class Type>
47 {}
48 
49 
50 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
51 
52 template<class Type>
54 (
55  const coordSet& points,
56  const wordList& valueSetNames
57 ) const
58 {
59  return this->getBaseName(points, valueSetNames) + ".agr";
60 }
61 
62 
63 template<class Type>
65 (
66  const coordSet& points,
67  const wordList& valueSetNames,
68  const List<const Field<Type>*>& valueSets,
69  Ostream& os
70 ) const
71 {
72  os << "@g0 on" << nl
73  << "@with g0" << nl
74  << "@ title \"" << points.name() << '"' << nl
75  << "@ xaxis label " << '"' << points.axis() << '"' << nl;
76 
77  forAll(valueSets, i)
78  {
79  os << "@ s" << i << " legend " << '"'
80  << valueSetNames[i] << '"' << nl
81  << "@target G0.S" << i << nl;
82 
83  this->writeTable(points, *valueSets[i], os);
84 
85  os << '&' << nl;
86  }
87 }
88 
89 
90 template<class Type>
92 (
93  const bool writeTracks,
94  const PtrList<coordSet>& trackPoints,
95  const wordList& valueSetNames,
96  const List<List<Field<Type>>>& valueSets,
97  Ostream& os
98 ) const
99 {
100  if (valueSets.size() != valueSetNames.size())
101  {
103  << "Number of variables:" << valueSetNames.size() << endl
104  << "Number of valueSets:" << valueSets.size()
105  << exit(FatalError);
106  }
107  if (trackPoints.size() > 0)
108  {
109  os << "@g0 on" << nl
110  << "@with g0" << nl
111  << "@ title \"" << trackPoints[0].name() << '"' << nl
112  << "@ xaxis label " << '"' << trackPoints[0].axis() << '"' << nl;
113 
114  // Data index.
115  label sI = 0;
116 
117  forAll(trackPoints, trackI)
118  {
119  forAll(valueSets, i)
120  {
121  os << "@ s" << sI << " legend " << '"'
122  << valueSetNames[i] << "_track" << i << '"' << nl
123  << "@target G0.S" << sI << nl;
124  this->writeTable(trackPoints[trackI], valueSets[i][trackI], os);
125  os << '&' << nl;
126 
127  sI++;
128  }
129  }
130  }
131 }
132 
133 // ************************************************************************* //
Foam::xmgraceSetWriter::xmgraceSetWriter
xmgraceSetWriter()
Construct null.
Definition: xmgraceSetWriter.C:37
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::xmgraceSetWriter::write
virtual void write(const coordSet &, const wordList &, const List< const Field< Type > * > &, Ostream &) const
General entry point for writing.
Definition: xmgraceSetWriter.C:65
coordSet.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
Foam::Field
Generic templated field type.
Definition: Field.H:63
fileName.H
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
Foam::xmgraceSetWriter::~xmgraceSetWriter
virtual ~xmgraceSetWriter()
Destructor.
Definition: xmgraceSetWriter.C:46
Foam::xmgraceSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
Definition: xmgraceSetWriter.C:54
Foam::FatalError
error FatalError
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:80
Foam::coordSet
Holds list of sampling positions.
Definition: coordSet.H:53
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::List< word >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:56
xmgraceSetWriter.H