graph.H
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-2013 OpenFOAM Foundation
9 Copyright (C) 2019 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
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
27Class
28 Foam::graph
29
30Description
31 Class to create, store and output qgraph files.
32
33SourceFiles
34 graph.C
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_graph_H
39#define Foam_graph_H
40
41#include "string.H"
42#include "point.H"
43#include "curve.H"
44#include "HashPtrTable.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
50
51// Forward Declaration
52class graph;
53Ostream& operator<<(Ostream&, const graph&);
54
55
56/*---------------------------------------------------------------------------*\
57 Class graph Declaration
58\*---------------------------------------------------------------------------*/
60class graph
61:
62 public HashPtrTable<curve>
63{
64 // Private Data
65
66 string title_;
67 string xName_;
68 string yName_;
69
70 scalarField x_;
71
72 struct xy
73 {
74 scalar x_, y_;
75
76
77 // Friend Operators
78
79 friend bool operator==(const xy& a, const xy& b)
80 {
81 return equal(a.x_, b.x_) && equal(a.y_, b.y_);
82 }
83
84 friend bool operator!=(const xy& a, const xy& b)
85 {
86 return !(a == b);
87 }
88
89 friend Istream& operator>>(Istream& is, xy& xyd)
90 {
91 is >> xyd.x_ >> xyd.y_;
92 return is;
93 }
94
95 friend Ostream& operator<<(Ostream& os, const xy& xyd)
96 {
97 os << xyd.x_ << ' ' << xyd.y_;
98 return os;
99 }
100 };
101
102
103 // Private Member Functions
104
105 void readCurves(Istream&);
106
107
108public:
109
110 // Constructors
111
112 //- Construct from title and labels (no curves)
113 graph
114 (
115 const string& title,
116 const string& xName,
117 const string& yName,
118 const scalarField& x
119 );
120
121 //- Construct from title, labels and y data for 1 curve
122 graph
123 (
124 const string& title,
125 const string& xName,
126 const string& yName,
127 const scalarField& x,
128 const scalarField& y
129 );
130
131 //- Construct from Istream given title and labels
132 graph
133 (
134 const string& title,
135 const string& xName,
136 const string& yName,
137 Istream& is
138 );
139
140 //- Construct from Istream
141 explicit graph(Istream& is);
142
143
144 // Member Functions
145
146 // Access
148 const string& title() const
149 {
150 return title_;
151 }
153 const string& xName() const
154 {
155 return xName_;
156 }
158 const string& yName() const
159 {
160 return yName_;
161 }
162
164 const scalarField& x() const
165 {
166 return x_;
167 }
169 scalarField& x()
170 {
171 return x_;
172 }
173
174
175 const scalarField& y() const;
176
177 scalarField& y();
178
179 // Limit the data for all axes based on x-limits
180 void setXRange(const scalar x0, const scalar x1);
181
182
183 // Write
184
185 //- Abstract base class for a graph writer
186 class writer
187 {
188 protected:
189
190 void writeXY
191 (
192 const scalarField& x,
193 const scalarField& y,
194 Ostream&
195 ) const;
196
197 public:
198
199 //- Runtime type information
200 TypeName("writer");
201
202 //- Declare run-time constructor selection table
204 (
205 autoPtr,
206 writer,
207 word,
208 (),
209 ()
210 );
211
212
213 // Selectors
214
215 //- Return a reference to the selected writer
216 static autoPtr<writer> New(const word& writeFormat);
217
218
219 // Constructors
220
221 //- Default construct
222 writer() = default;
223
224
225 //- Destructor
226 virtual ~writer() = default;
227
228
229 // Member Functions
230
231 //- The fileName extension for this graph format
232 virtual word ext() const = 0;
233
234 //- Write graph in appropriate format
235 virtual void write(const graph&, Ostream&) const = 0;
236 };
237
238
239 //- Write out graph data as a simple table
240 void writeTable(Ostream&) const;
241
242 //- Write graph to stream in given format
243 void write(Ostream&, const word& format) const;
244
245 //- Write graph to file in given path-name and format
246 void write(const fileName& pName, const word& format) const;
247
248 //- Write graph to file in given path, name and format
249 void write
250 (
251 const fileName& path,
252 const word& name,
253 const word& format
254 ) const;
255
256 //- Helper function to convert string name into appropriate word
257 static word wordify(const string& sname);
258
259
260 // Friend Operators
261
262 //- Ostream Operator
263 friend Ostream& operator<<(Ostream&, const graph&);
264};
265
266
267// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268
269} // End namespace Foam
270
271// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272
273#endif
274
275// ************************************************************************* //
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
Definition: HashPtrTable.H:68
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
A class for handling file names.
Definition: fileName.H:76
Abstract base class for a graph writer.
Definition: graph.H:186
void writeXY(const scalarField &x, const scalarField &y, Ostream &) const
Definition: graph.C:238
declareRunTimeSelectionTable(autoPtr, writer, word,(),())
Declare run-time constructor selection table.
writer()=default
Default construct.
virtual ~writer()=default
Destructor.
static autoPtr< writer > New(const word &writeFormat)
Return a reference to the selected writer.
Definition: graph.C:210
virtual void write(const graph &, Ostream &) const =0
Write graph in appropriate format.
TypeName("writer")
Runtime type information.
virtual word ext() const =0
The fileName extension for this graph format.
Class to create, store and output qgraph files.
Definition: graph.H:62
const string & yName() const
Definition: graph.H:157
const string & xName() const
Definition: graph.H:152
const scalarField & y() const
Definition: graph.C:144
const string & title() const
Definition: graph.H:147
friend Ostream & operator<<(Ostream &, const graph &)
Ostream Operator.
scalarField & x()
Definition: graph.H:168
void writeTable(Ostream &) const
Write out graph data as a simple table.
Definition: graph.C:251
static word wordify(const string &sname)
Helper function to convert string name into appropriate word.
Definition: graph.C:47
void setXRange(const scalar x0, const scalar x1)
Definition: graph.C:170
const scalarField & x() const
Definition: graph.H:163
A class for handling words, derived from Foam::string.
Definition: word.H:68
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
bool operator!=(const eddy &a, const eddy &b)
Definition: eddy.H:239
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:83
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46
tmp< faMatrix< Type > > operator==(const faMatrix< Type > &, const faMatrix< Type > &)
Istream & operator>>(Istream &, directionInfo &)
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
runTime write()
word format(conversionProperties.get< word >("format"))
#define declareRunTimeSelectionTable(ptrWrapper, baseType, argNames, argList, parList)
Declare a run-time selection (variables and adder classes)
volScalarField & b
Definition: createFields.H:27
#define TypeName(TypeNameString)
Declare a ClassName() with extra virtual type info.
Definition: typeInfo.H:73