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  Copyright (C) 2021 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "xmgraceSetWriter.H"
30 #include "coordSet.H"
31 #include "fileName.H"
32 #include "OFstream.H"
33 
34 
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
36 
37 template<class Type>
39 :
40  writer<Type>()
41 {}
42 
43 
44 template<class Type>
46 :
47  writer<Type>(dict)
48 {}
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
53 template<class Type>
55 (
56  const coordSet& points,
57  const wordList& valueSetNames
58 ) const
59 {
60  return this->getBaseName(points, valueSetNames) + ".agr";
61 }
62 
63 
64 template<class Type>
66 (
67  const coordSet& points,
68  const wordList& valueSetNames,
69  const List<const Field<Type>*>& valueSets,
70  Ostream& os
71 ) const
72 {
73  os << "@g0 on" << nl
74  << "@with g0" << nl
75  << "@ title \"" << points.name() << '"' << nl
76  << "@ xaxis label " << '"' << points.axis() << '"' << nl;
77 
78  forAll(valueSets, i)
79  {
80  os << "@ s" << i << " legend " << '"'
81  << valueSetNames[i] << '"' << nl
82  << "@target G0.S" << i << nl;
83 
84  this->writeTable(points, *valueSets[i], os);
85 
86  os << '&' << nl;
87  }
88 }
89 
90 
91 template<class Type>
93 (
94  const bool writeTracks,
95  const List<scalarField>& times,
96  const PtrList<coordSet>& tracks,
97  const wordList& valueSetNames,
98  const List<List<Field<Type>>>& valueSets,
99  Ostream& os
100 ) const
101 {
102  if (valueSets.size() != valueSetNames.size())
103  {
105  << "Number of variables:" << valueSetNames.size() << endl
106  << "Number of valueSets:" << valueSets.size()
107  << exit(FatalError);
108  }
109  if (tracks.size() > 0)
110  {
111  os << "@g0 on" << nl
112  << "@with g0" << nl
113  << "@ title \"" << tracks[0].name() << '"' << nl
114  << "@ xaxis label " << '"' << tracks[0].axis() << '"' << nl;
115 
116  // Data index.
117  label sI = 0;
118 
119  forAll(tracks, trackI)
120  {
121  forAll(valueSets, i)
122  {
123  os << "@ s" << sI << " legend " << '"'
124  << valueSetNames[i] << "_track" << i << '"' << nl
125  << "@target G0.S" << sI << nl;
126  this->writeTable(tracks[trackI], valueSets[i][trackI], os);
127  os << '&' << nl;
128 
129  sI++;
130  }
131  }
132  }
133 }
134 
135 // ************************************************************************* //
Foam::xmgraceSetWriter::xmgraceSetWriter
xmgraceSetWriter()
Default construct.
Definition: xmgraceSetWriter.C:38
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
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:66
coordSet.H
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
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:59
Foam::xmgraceSetWriter::getFileName
virtual fileName getFileName(const coordSet &, const wordList &) const
Generate file name with correct extension.
Definition: xmgraceSetWriter.C:55
dict
dictionary dict
Definition: searchingEngine.H:14
Foam::FatalError
error FatalError
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
os
OBJstream os(runTime.globalPath()/outputName)
Foam::writer
Base class for graphics format writing. Entry points are.
Definition: writer.H:81
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:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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