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