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