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 Foam_graph_H
39 #define Foam_graph_H
40 
41 #include "curve.H"
42 #include "HashPtrTable.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 // Forward Declaration
50 class graph;
51 Ostream& operator<<(Ostream&, const graph&);
52 
53 
54 /*---------------------------------------------------------------------------*\
55  Class graph Declaration
56 \*---------------------------------------------------------------------------*/
57 
58 class 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 
106 public:
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_;
149  }
150 
151  const string& xName() const
152  {
153  return xName_;
154  }
155 
156  const string& yName() const
157  {
158  return yName_;
159  }
160 
161 
162  const scalarField& x() const
163  {
164  return x_;
165  }
166 
167  scalarField& x()
168  {
169  return x_;
170  }
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
189  (
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,
205  word,
206  (),
207  ()
208  );
209 
210 
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;
239 
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 // ************************************************************************* //
TypeName("writer")
Runtime type information.
friend Ostream & operator<<(Ostream &, const graph &)
Ostream Operator.
A class for handling file names.
Definition: fileName.H:72
bool operator!=(const this_type &rhs) const
The opposite of the equality operation.
Definition: HashTable.C:987
void write(Ostream &, const word &format) const
Write graph to stream in given format.
Definition: graph.C:259
virtual void write(const graph &, Ostream &) const =0
Write graph in appropriate format.
vtk::lineWriter writer(edgeCentres, edgeList::null(), fileName(aMesh.time().globalPath()/"finiteArea-edgesCentres"))
bool equal(const T &a, const T &b)
Compare two values for equality.
Definition: label.H:164
const scalarField & y() const
Definition: graph.C:137
virtual word ext() const =0
The fileName extension for this graph format.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers...
Definition: HashPtrTable.H:51
void writeTable(Ostream &) const
Write out graph data as a simple table.
Definition: graph.C:244
Abstract base class for a graph writer.
Definition: graph.H:189
bool operator==(const this_type &rhs) const
Equality. Tables are equal if all keys and values are equal, independent of order or underlying stora...
Definition: HashTable.C:961
Class to create, store and output qgraph files.
Definition: graph.H:53
friend Istream & operator>>(Istream &is, HashPtrTable< curve, word, Foam::Hash< word > > &tbl)
Clear table and read from Istream.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
void setXRange(const scalar x0, const scalar x1)
Definition: graph.C:163
declareRunTimeSelectionTable(autoPtr, writer, word,(),())
Declare run-time constructor selection table.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
A class for handling words, derived from Foam::string.
Definition: word.H:63
const string & xName() const
Definition: graph.H:154
graph(const string &title, const string &xName, const string &yName, const scalarField &x)
Construct from title and labels (no curves)
Definition: graph.C:75
void writeXY(const scalarField &x, const scalarField &y, Ostream &) const
Definition: graph.C:231
static word wordify(const string &sname)
Helper function to convert string name into appropriate word.
Definition: graph.C:40
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
fileName path(UMean.rootPath()/UMean.caseName()/"graphs"/UMean.instance())
writer()=default
Default construct.
virtual ~writer()=default
Destructor.
word format(conversionProperties.get< word >("format"))
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
Definition: boundaryPatch.C:77
Pointer management similar to std::unique_ptr, with some additional methods and type checking...
Definition: HashPtrTable.H:48
const string & yName() const
Definition: graph.H:159
const string & title() const
Definition: graph.H:149
const scalarField & x() const
Definition: graph.H:165
Namespace for OpenFOAM.
static autoPtr< writer > New(const word &writeFormat)
Return a reference to the selected writer.
Definition: graph.C:203